CG  Version 25
trigonometricTZ.h
Go to the documentation of this file.
1 // ***********************************************************
2 // *** This macro defines the trigonometric TZ functions *****
3 // ***********************************************************
4 #beginMacro defineTrigonometricTZMacro()
5 
6 const int nc = numberOfComponents + int(useChargeDensity); // include charge density in TZ
7 
8 RealArray fx(nc),fy(nc),fz(nc),ft(nc);
9 RealArray gx(nc),gy(nc),gz(nc),gt(nc);
10 gx=0.;
11 gy=0.;
12 gz=0.;
13 gt=0.;
14 RealArray amplitude(nc), cc(nc);
16 cc=0.;
17 
18 
19 fx=omega[0];
20 fy = numberOfDimensions>1 ? omega[1] : 0.;
21 fz = numberOfDimensions>2 ? omega[2] : 0.;
22 ft = omega[3];
23 
24 if( numberOfDimensions==2 )
25 {
26  const int uc=ex, vc=ey, wc=hz;
27 
28  if( !useChargeDensity )
29  {
30  // rho=0 : create div(E)=0 TZ function
31 
32  // u=cos(pi x) cos( pi y )* .5
33  // v=sin(pi x) sin( pi y )* .5
34  // w=cos( ) sin( )* .5
35  assert( omega[0]==omega[1] );
36 
37  gx(vc)=.5/omega[0]; // shift by pi/2 to turn cos() into sin()
38  gy(vc)=.5/omega[1];
39 
40  amplitude(uc)=.5; cc(uc)=.0;
41  amplitude(vc)=.5; cc(vc)=.0;
42 
43  gy(wc)=.5/omega[1]; // turn off for testing symmetry
44  cc(wc)=.0;
45  }
46  else
47  {
48  // rho= cos(pi x) cos( pi y )* omega[0]*pi
49  //
50  // u=sin(pi x) cos( pi y )* .5
51  // v=cos(pi x) sin( pi y )* .5
52  // w=cos( ) sin( )* .5
53  assert( omega[0]==omega[1] );
54 
55  assert( rc==numberOfComponents );
56 
57  gx(uc)=.5/omega[0]; // shift by pi/2 to turn cos() into sin()
58  gy(vc)=.5/omega[1];
59 
60  amplitude(rc)=omega[0]*Pi; cc(rc)=.0;
61  amplitude(uc)=.5; cc(uc)=.0;
62  amplitude(vc)=.5; cc(vc)=.0;
63 
64  gy(wc)=.5/omega[1]; // turn off for testing symmetry
65  cc(wc)=.0;
66 
67  }
68 
69 }
70 else if( numberOfDimensions==3 )
71 {
72  if( solveForElectricField )
73  {
74  const int uc=ex, vc=ey, wc=ez;
75 
76  // u= cos(pi x) cos( pi y ) cos( pi z) // **** fix ***
77  // v=.5 sin(pi x) sin( pi y ) cos( pi z)
78  // w=.5 sin(pi x) cos( pi y ) sin( pi z)
79 
80  if( omega[0]==omega[1] && omega[0]==omega[2] )
81  {
82  gx(vc)=.5/omega[0];
83  gy(vc)=.5/omega[1];
84  amplitude(vc)=.5;
85 
86  gx(wc)=.5/omega[0];
87  gz(wc)=.5/omega[2];
88  amplitude(wc)=.5;
89  }
90  else if( omega[0]==omega[2] && omega[1]==0 )
91  {
92  // pseudo 2D case
93  gx(wc)=.5/omega[0]; // shift by pi/2 to turn cos() into sin()
94  gz(wc)=.5/omega[2];
95 
96  amplitude(uc)=.5; cc(uc)=.0;
97  amplitude(wc)=.5; cc(wc)=.0;
98  }
99  else if( omega[0]==omega[1] && omega[2]==0 )
100  {
101  // pseudo 2D case
102 
103  // u=cos(pi x) cos( pi y ) cos( 0*pi z)* .5
104  // v=sin(pi x) sin( pi y ) cos( 0*pi z)* .5
105  // w=cos(pi x) cos( pi y ) cos( 0*pi z)* .5
106 
107 
108  gx(vc)=.5/omega[0]; // shift by pi/2 to turn cos() into sin()
109  gy(vc)=.5/omega[1];
110 
111  amplitude(uc)=.5; cc(uc)=.0;
112  amplitude(vc)=.5; cc(vc)=.0;
113  amplitude(wc)=.5; cc(wc)=.0;
114  }
115  else
116  {
117  printF("Cgmx: invalid values for omega: omega[0]=%9.3e, omega[1]=%9.3e, omega[2]=%9.3e\n",
118  omega[0],omega[1],omega[2]);
119  printF("Expecting all equal values or omega[0]==omega[2] && omega[1]==0 \n"
120  " or omega[0]==omega[1] && omega[2]==0 (for divergence free field\n");
121  Overture::abort("Invalid values for omega[0..2]");
122  }
123  }
124 
125  if( solveForMagneticField )
126  {
127  const int uc=hx, vc=hy, wc=hz;
128 
129  // u= cos(pi x) cos( pi y ) cos( pi z) // **** fix ***
130  // v=.5 sin(pi x) sin( pi y ) cos( pi z)
131  // w=.5 sin(pi x) cos( pi y ) sin( pi z)
132 
133  if( omega[0]==omega[1] && omega[0]==omega[2] )
134  {
135  gx(vc)=.5/omega[0];
136  gy(vc)=.5/omega[1];
137  amplitude(vc)=.5;
138 
139  gx(wc)=.5/omega[0];
140  gz(wc)=.5/omega[2];
141  amplitude(wc)=.5;
142  }
143  else if( omega[0]==omega[2] && omega[1]==0 )
144  {
145  // pseudo 2D case
146  gx(wc)=.5/omega[0]; // shift by pi/2 to turn cos() into sin()
147  gz(wc)=.5/omega[2];
148 
149  amplitude(uc)=.5; cc(uc)=.0;
150  amplitude(wc)=.5; cc(wc)=.0;
151  }
152  else
153  {
154  Overture::abort("Invalid values for omega[0..2]");
155  }
156  }
157 
158 }
159 if( method==sosup )
160 {
161  // Set the TZ function for (ext,eyt,...) equal to the time derivative of (ex,ey,...)
162 
163  // time dependence for time-derivatives of E:
164  const int numberOfFieldComponents=3;
165  for( int n=ex, nt=ext; n<ex+numberOfFieldComponents; n++,nt++ )
166  {
167  fx(nt)=fx(n); fy(nt)=fy(n); fz(nt)=fz(n); ft(nt)=ft(n);
168  gx(nt)=gx(n); gy(nt)=gy(n); gz(nt)=gz(n);
169  gt(nt)=.5/ft(n); // shift phase by pi/2 to turn cos(Pi*ft*(t-gt)) into sin(Pi*ft*(t-gt))
170  amplitude(nt)=-amplitude(n)*ft(n)*Pi; // amplitude
171  cc(nt)=0.;
172  }
173 
174 
175 // fx(eyt)=fx(ey); gx(eyt)=gx(ey); amplitude(eyt)=-amplitude(ey); cc(eyt)=0.; ft(eyt)=ft(ey); gt(eyt)=.5/omega[3];
176 
177 // fx(hzt)=fx(hz); gx(hzt)=gx(hz); amplitude(hzt)=-amplitude(hz); cc(hzt)=0.; ft(hzt)=ft(hz); gt(hzt)=.5/omega[3];
178 
179 }
180 
181 
182 tz = new OGTrigFunction(fx,fy,fz,ft);
183 
184 ((OGTrigFunction*)tz)->setShifts(gx,gy,gz,gt);
185 ((OGTrigFunction*)tz)->setAmplitudes(amplitude);
186 ((OGTrigFunction*)tz)->setConstants(cc);
187 
188 #endMacro