PlasCom2  1.0
XPACC Multi-physics simluation application
MaxwellSolver.C
Go to the documentation of this file.
1 #include <iostream>
2 #include "OperatorKernels.H"
3 #include "MaxwellSolver.H"
4 
5 #define DEBUG_MAXWELL_RHS_BFIELD 0
6 #define DEBUG_MAXWELL_RHS_DFIELD 0
7 #define DEBUG_MAXWELL_ComputeRecipEpsMu 0
8 #define DEBUG_MAXWELL_CONVERT_ETODFIELD 0
9 #define DEBUG_MAXWELL_CONVERT_DTOEFIELD 0
10 #define DEBUG_MAXWELL_CONVERT_BTOHFIELD 0
11 #define DEBUG_MAXWELL_CONVERT_HTOBFIELD 0
12 
13 
14 
15 namespace Maxwell {
16 
17 
18  int ComputeCurl(int numDim, size_t *numX, int numComponents,
19  size_t numPoints, size_t *opInterval, int *stencilID,
21  double *recipDeltaX, double *inputField, double *outputField)
22  {
23 
24  /* Check no. of dimensions - it must be 3. */
25  if (numDim != 3) {
26  return 1;
27  }
28 
29  int comp1, comp2;
30  int comp1plusOne, comp2plusOne;
31  double *partDDx1 = new double [numPoints];
32  double *partDDx2 = new double [numPoints];
33 
34  for (int compCurl=0; compCurl<numDim; compCurl++) {
35 
36  comp1 = (compCurl+1)%3;
37  comp2 = (comp1+1)%3;
38 
39  comp1plusOne = comp1+1;
40  comp2plusOne = comp2+1;
41 
42  size_t comp1xnumPoints = comp1*numPoints;
43  size_t comp2xnumPoints = comp2*numPoints;
44 
46  (&numDim, numX, &numComponents, &numPoints,
47  &comp1plusOne, opInterval, &(inOperator.numStencils), inOperator.stencilSizes,
48  inOperator.stencilStarts, &(inOperator.numValues),
49  inOperator.stencilWeights, inOperator.stencilOffsets,
50  &stencilID[comp1xnumPoints],
51  &inputField[comp2xnumPoints], partDDx1);
52 
54  (&numDim, numX, &numComponents, &numPoints,
55  &comp2plusOne, opInterval, &(inOperator.numStencils), inOperator.stencilSizes,
56  inOperator.stencilStarts, &(inOperator.numValues),
57  inOperator.stencilWeights, inOperator.stencilOffsets,
58  &stencilID[comp2xnumPoints],
59  &inputField[comp1xnumPoints], partDDx2);
60 
61  size_t compCurlxnumPoints = compCurl*numPoints;
62 
63  for (size_t iPoint=0; iPoint<numPoints; iPoint++) {
64 
65  partDDx1[iPoint] *= recipDeltaX[comp1xnumPoints+iPoint];
66  partDDx2[iPoint] *= recipDeltaX[comp2xnumPoints+iPoint];
67 
68  outputField[compCurlxnumPoints+iPoint] = partDDx1[iPoint] - partDDx2[iPoint];
69 
70  }
71 
72  }
73 
74  delete [] partDDx1;
75  delete [] partDDx2;
76 
77  return 0;
78 
79  } // end ComputeCurl()
80 
81 
82  int ComputeMaxwellRHS_Bfield(int numDim, size_t *numX, int numComponents, size_t numPoints,
83  size_t *opInterval, int *stencilID,
85  double *recipDeltaX, double *Efield, double *dBdt)
86  /******************************************************************************************
87 
88  Compute RHS for B-field (Faraday's law): dBdt = -curl(E)
89 
90  ******************************************************************************************/
91  {
92 
93  if (ComputeCurl(numDim, numX, numComponents, numPoints, opInterval, stencilID,
94  inOperator, recipDeltaX, Efield, dBdt))
95  {
96  return 1;
97  }
98 
99  double negOne = -1.0;
100 
101  for (int iDim=0; iDim<numDim; iDim++) {
102  FC_MODULE(operators,xax,OPERATORS,XAX)(&numDim, &numPoints, numX, opInterval, &negOne, &dBdt[iDim*numPoints]);
103  }
104 
105 #if DEBUG_MAXWELL_RHS_BFIELD
106  // FOR DEBUGGING PURPOSES
107  for (int iDim=0; iDim<numDim; iDim++) {
108  size_t iDimxnumPoints = iDim*numPoints;
109  for (size_t iPoint=0; iPoint<numPoints; iPoint++) {
110  std::cout << "[Maxwell RHS B-field] dim=" << iDim << ", point=" << iPoint << ", Efield=" << Efield[iDimxnumPoints+iPoint] << ", dBdt=" << dBdt[iDimxnumPoints+iPoint] << std::endl;
111  }
112  }
113 #endif
114 
115  return 0;
116 
117  } // end ComputeMaxwellRHS_Bfield()
118 
119 
120  int ComputeMaxwellRHS_Dfield(int numDim, size_t *numX, int numComponents, size_t numPoints,
121  size_t *opInterval, int *stencilID,
122  plascom2::operators::sbp::base &inOperator,
123  double *recipDeltaX, double *Hfield, double *J, double *dDdt)
124  /******************************************************************************************
125 
126  Compute RHS for D-field (Ampere's law): dDdt = curl(H)-J
127 
128  ******************************************************************************************/
129  {
130 
131  if (ComputeCurl(numDim, numX, numComponents, numPoints, opInterval, stencilID,
132  inOperator, recipDeltaX, Hfield, dDdt))
133  {
134  return 1;
135  }
136 
137  double negOne = -1.0;
138 
139  for (int iDim=0; iDim<numDim; iDim++) {
140  FC_MODULE(operators,yaxpy,OPERATORS,YAXPY)(&numDim, &numPoints, numX, opInterval, &negOne, &J[iDim*numPoints], &dDdt[iDim*numPoints]);
141  }
142 
143 #if DEBUG_MAXWELL_RHS_DFIELD
144  // FOR DEBUGGING PURPOSES
145  for (int iDim=0; iDim<numDim; iDim++) {
146  size_t iDimxnumPoints = iDim*numPoints;
147  for (size_t iPoint=0; iPoint<numPoints; iPoint++) {
148  std::cout << "[Maxwell RHS D-field] dim=" << iDim << ", point=" << iPoint << ", Hfield=" << Hfield[iDimxnumPoints+iPoint] << ", J=" << J[iDimxnumPoints+iPoint] << ", dDdt=" << dDdt[iDimxnumPoints+iPoint] << std::endl;
149  }
150  }
151 #endif
152 
153  return 0;
154 
155  } // end ComputeMaxwellRHS_Dfield()
156 
157 
158  int ComputeRecipEpsMu(int numDim, size_t numPoints, size_t *numX, size_t *opInterval,
159  double *epsMu, double *recipEpsMu)
160  /************************************************************************************
161 
162  Compute reciprocals of epsilon and mu.
163 
164  ************************************************************************************/
165  {
166 
167  if (numDim != 3) {
168  return 1;
169  }
170 
171  double one = 1.0;
172 
173  FC_MODULE(operators,yaxm1,OPERATORS,YAXM1)(&numDim, &numPoints, numX, opInterval, &one, &epsMu[0], &recipEpsMu[0]);
174  FC_MODULE(operators,yaxm1,OPERATORS,YAXM1)(&numDim, &numPoints, numX, opInterval, &one, &epsMu[numPoints], &recipEpsMu[numPoints]);
175 
176 #if DEBUG_MAXWELL_ComputeRecipEpsMu
177  // FOR DEBUGGING PURPOSES
178  for (size_t iPoint=0; iPoint<numPoints; iPoint++) {
179  std::cout << "[Maxwell Compute reciprocal eps, mu] point=" << iPoint << ", eps=" << epsMu[iPoint] << ", 1/eps=" << recipEpsMu[iPoint] << ", mu=" << epsMu[numPoints+iPoint] << ", 1/mu=" << recipEpsMu[numPoints+iPoint] << std::endl;
180  }
181 #endif
182 
183  return 0;
184 
185  } // end ComputeRecipEpsMu()
186 
187 
188  int ConvertEfieldtoDfield(int numDim, size_t numPoints, size_t *numX, size_t *opInterval,
189  double *epsMu, double *Efield, double *Dfield)
190  /****************************************************************************************
191 
192  Calculate D = epsilon*E
193 
194  ****************************************************************************************/
195  {
196 
197  if (numDim != 3) {
198  return 1;
199  }
200 
201  for (int iDim=0; iDim<numDim; iDim++) {
202  FC_MODULE(operators,zxy,OPERATORS,ZXY)(&numDim, &numPoints, numX, opInterval,
203  &epsMu[0], &Efield[iDim*numPoints], &Dfield[iDim*numPoints]);
204  }
205 
206 #if DEBUG_MAXWELL_CONVERT_ETODFIELD
207  // FOR DEBUGGING PURPOSES
208  for (int iDim=0; iDim<numDim; iDim++) {
209  size_t iDimxnumPoints = iDim*numPoints;
210  for (size_t iPoint=0; iPoint<numPoints; iPoint++) {
211  std::cout << "[Maxwell Convert E->D] dim=" << iDim << ", point=" << iPoint << ", eps=" << epsMu[iPoint] << ", Efield=" << Efield[iDimxnumPoints+iPoint] << ", Dfield=" << Dfield[iDimxnumPoints+iPoint] << std::endl;
212  }
213  }
214 #endif
215 
216  return 0;
217 
218  } // end ConvertEfieldtoDfield()
219 
220 
221  int ConvertDfieldtoEfield(int numDim, size_t numPoints, size_t *numX, size_t *opInterval,
222  double *recipEpsMu, double *Dfield, double *Efield)
223  /******************************************************************************************
224 
225  Calculate E = D/epsilon
226 
227  ******************************************************************************************/
228  {
229 
230  if (numDim != 3) {
231  return 1;
232  }
233 
234  for (int iDim=0; iDim<numDim; iDim++) {
235  FC_MODULE(operators,zxy,OPERATORS,ZXY)(&numDim, &numPoints, numX, opInterval,
236  &recipEpsMu[0], &Dfield[iDim*numPoints], &Efield[iDim*numPoints]);
237  }
238 
239 #if DEBUG_MAXWELL_CONVERT_DTOEFIELD
240  // FOR DEBUGGING PURPOSES
241  for (int iDim=0; iDim<numDim; iDim++) {
242  size_t iDimxnumPoints = iDim*numPoints;
243  for (size_t iPoint=0; iPoint<numPoints; iPoint++) {
244  std::cout << "[Maxwell Convert D->E] dim=" << iDim << ", point=" << iPoint << ", 1/eps=" << recipEpsMu[iPoint] << ", Dfield=" << Dfield[iDimxnumPoints+iPoint] << ", Efield=" << Efield[iDimxnumPoints+iPoint] << std::endl;
245  }
246  }
247 #endif
248 
249  return 0;
250 
251  } // end ConvertDfieldtoEfield()
252 
253 
254  int ConvertBfieldtoHfield(int numDim, size_t numPoints, size_t *numX, size_t *opInterval,
255  double *recipEpsMu, double *Bfield, double *Hfield)
256  /******************************************************************************************
257 
258  Calculate H = B/mu
259 
260  ******************************************************************************************/
261  {
262 
263  if (numDim != 3) {
264  return 1;
265  }
266 
267  for (int iDim=0; iDim<numDim; iDim++) {
268  FC_MODULE(operators,zxy,OPERATORS,ZXY)(&numDim, &numPoints, numX, opInterval,
269  &recipEpsMu[numPoints], &Bfield[iDim*numPoints], &Hfield[iDim*numPoints]);
270  }
271 
272 #if DEBUG_MAXWELL_CONVERT_BTOHFIELD
273  // FOR DEBUGGING PURPOSES
274  for (int iDim=0; iDim<numDim; iDim++) {
275  size_t iDimxnumPoints = iDim*numPoints;
276  for (size_t iPoint=0; iPoint<numPoints; iPoint++) {
277  std::cout << "[Maxwell Convert B->H] dim=" << iDim << ", point=" << iPoint << ", 1/mu=" << recipEpsMu[numPoints+iPoint] << ", Bfield=" << Bfield[iDimxnumPoints+iPoint] << ", Hfield=" << Hfield[iDimxnumPoints+iPoint] << std::endl;
278  }
279  }
280 #endif
281 
282  return 0;
283 
284  } // end ConvertBfieldtoHfield()
285 
286 
287  int ConvertHfieldtoBfield(int numDim, size_t numPoints, size_t *numX, size_t *opInterval,
288  double *epsMu, double *Hfield, double *Bfield)
289  /******************************************************************************************
290 
291  Calculate B = mu*H
292 
293  ******************************************************************************************/
294  {
295 
296  if (numDim != 3) {
297  return 1;
298  }
299 
300  for (int iDim=0; iDim<numDim; iDim++) {
301  FC_MODULE(operators,zxy,OPERATORS,ZXY)(&numDim, &numPoints, numX, opInterval,
302  &epsMu[numPoints], &Hfield[iDim*numPoints], &Bfield[iDim*numPoints]);
303  }
304 
305 #if DEBUG_MAXWELL_CONVERT_HTOBFIELD
306  // FOR DEBUGGING PURPOSES
307  for (int iDim=0; iDim<numDim; iDim++) {
308  size_t iDimxnumPoints = iDim*numPoints;
309  for (size_t iPoint=0; iPoint<numPoints; iPoint++) {
310  std::cout << "[Maxwell Convert H->B] dim=" << iDim << ", point=" << iPoint << ", mu=" << epsMu[numPoints+iPoint] << ", Hfield=" << Hfield[iDimxnumPoints+iPoint] << ", Bfield=" << Bfield[iDimxnumPoints+iPoint] << std::endl;
311  }
312  }
313 #endif
314 
315  return 0;
316 
317  } // end ConvertHfieldtoBfield()
318 
319 
320 } // end namespace Maxwell
int ComputeMaxwellRHS_Bfield(int numDim, size_t *numX, int numComponents, size_t numPoints, size_t *opInterval, int *stencilID, plascom2::operators::sbp::base &inOperator, double *recipDeltaX, double *Efield, double *dBdt)
Definition: MaxwellSolver.C:82
int ConvertBfieldtoHfield(int numDim, size_t numPoints, size_t *numX, size_t *opInterval, double *recipEpsMu, double *Bfield, double *Hfield)
int * stencilSizes
The number of weights for each stencil.
Definition: Stencil.H:102
void const size_t * numPoints
Definition: EulerKernels.H:10
int ComputeMaxwellRHS_Dfield(int numDim, size_t *numX, int numComponents, size_t numPoints, size_t *opInterval, int *stencilID, plascom2::operators::sbp::base &inOperator, double *recipDeltaX, double *Hfield, double *J, double *dDdt)
subroutine applyoperator(numDim, dimSizes, numComponents, numPoints, opDir, opInterval, numStencils, stencilSizes, stencilStarts, numValues, stencilWeights, stencilOffsets, stencilID, U, dU)
applyoperator applies an operator specified as a stencil set to the provided state data ...
Definition: Operators.f90:36
int ComputeCurl(int numDim, size_t *numX, int numComponents, size_t numPoints, size_t *opInterval, int *stencilID, plascom2::operators::sbp::base &inOperator, double *recipDeltaX, double *inputField, double *outputField)
Definition: MaxwellSolver.C:18
int * stencilStarts
The starting index into the stencilWeight and stencilOffset arrays for each stencil.
Definition: Stencil.H:104
int * stencilOffsets
The offsets wrt the grid point at which the stencil is being applied.
Definition: Stencil.H:106
void const size_t const size_t const size_t * opInterval
Definition: EulerKernels.H:10
void size_t int size_t int size_t int int int int double int int * stencilID
int ConvertHfieldtoBfield(int numDim, size_t numPoints, size_t *numX, size_t *opInterval, double *epsMu, double *Hfield, double *Bfield)
Encapsulation for a collection of operator stencils.
Definition: Stencil.H:26
int numValues
The total number of weights for all stencils (reqd for Fortran)
Definition: Stencil.H:98
int ConvertEfieldtoDfield(int numDim, size_t numPoints, size_t *numX, size_t *opInterval, double *epsMu, double *Efield, double *Dfield)
subroutine zxy(numDim, numPoints, bufferSize, bufferInterval, X, Y, Z)
ZXY point-wise operator performing Z = XY (all vectors)
Definition: Operators.f90:679
int ComputeRecipEpsMu(int numDim, size_t numPoints, size_t *numX, size_t *opInterval, double *epsMu, double *recipEpsMu)
double * stencilWeights
The stencil weights.
Definition: Stencil.H:108
int numStencils
The number of stencils (e.g. interior + boundary)
Definition: Stencil.H:93
int ConvertDfieldtoEfield(int numDim, size_t numPoints, size_t *numX, size_t *opInterval, double *recipEpsMu, double *Dfield, double *Efield)
subroutine yaxpy(N1, N2, N3, localInterval, a, X, Y)
Definition: RKUtil.f90:113
subroutine yaxm1(numDim, numPoints, bufferSize, bufferInterval, a, X, Y)
YAXM1 point-wise operator performing Y = a/X (scalar a)
Definition: Operators.f90:1396
void size_t int * numComponents
subroutine xax(numDim, numPoints, bufferSize, bufferInterval, a, X)
XAX point-wise operator performing X = aX (scalar a)
Definition: Operators.f90:1119
void FC_MODULE(euler, flux1d, EULER, FLUX1D)(const int *numDim