OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
CenteredFieldLayout.hpp
Go to the documentation of this file.
1// -*- C++ -*-
2/***************************************************************************
3 *
4 * The IPPL Framework
5 *
6 * This program was prepared by PSI.
7 * All rights in the program are reserved by PSI.
8 * Neither PSI nor the author(s)
9 * makes any warranty, express or implied, or assumes any liability or
10 * responsibility for the use of this software
11 *
12 * Visit www.amas.web.psi for more details
13 *
14 ***************************************************************************/
15
16// -*- C++ -*-
17/***************************************************************************
18 *
19 * The IPPL Framework
20 *
21 *
22 * Visit http://people.web.psi.ch/adelmann/ for more details
23 *
24 ***************************************************************************/
25
26
27// include files
29#include "Meshes/Centering.h"
31#include "Utility/PAssert.h"
32
33
34//=============================================================================
35// Helper global functions:
36// The constructors call these specialized global functions as a workaround for
37// lack of partial specialization:
38//=============================================================================
39
40//===========================Arbitrary mesh type=============================
41
42//-----------------------------------------------------------------------------
43// These specify only a total number of vnodes, allowing the constructor
44// complete control on how to do the vnode partitioning of the index space:
45// Constructor for arbitrary dimension with parallel/serial specifier array:
46
47//------------------Cell centering---------------------------------------------
48template<unsigned Dim, class Mesh>
49inline void
51 const Mesh& mesh,
52 e_dim_tag* edt,
53 int vnodes)
54{
55 NDIndex<Dim> ndi;
56 for (unsigned int d=0; d<Dim; d++)
57 ndi[d] = Index(mesh.gridSizes[d] - 1);
58 cfl.initialize(ndi, edt, vnodes);
59}
60
61//------------------Vert centering---------------------------------------------
62template<unsigned Dim, class Mesh>
63inline void
65 const Mesh& mesh,
66 e_dim_tag* edt,
67 int vnodes)
68{
69 NDIndex<Dim> ndi;
70 for (unsigned int d=0; d<Dim; d++)
71 ndi[d] = Index(mesh.gridSizes[d]);
72 cfl.initialize(ndi, edt, vnodes);
73}
74
75//------------------Edge centering---------------------------------------------
76template<unsigned Dim, class Mesh>
77inline void
79 const Mesh& mesh,
80 e_dim_tag* edt,
81 int vnodes)
82{
83 NDIndex<Dim> ndi;
84 for (unsigned int d=0; d<Dim; d++)
85 ndi[d] = Index(mesh.gridSizes[d]);
86 cfl.initialize(ndi, edt, vnodes);
87}
88
89//------------------CartesianCentering centering-------------------------------
90template<CenteringEnum* CE, unsigned Dim, class Mesh,
91 unsigned NComponents>
92inline void
95 const Mesh& mesh,
96 e_dim_tag* edt,
97 int vnodes)
98{
99 NDIndex<Dim> ndi;
100 // For componentwise layout of Field of multicomponent object, like
101 // Field<Vektor...>, allow for maximal number of objects needed per
102 // dimension (the number for the object component requiring the maximal
103 // number):
104 unsigned npts[Dim], nGridPts;
105 unsigned int d, c;
106 for (d=0; d<Dim; d++) {
107 nGridPts = mesh.gridSizes[d];
108 npts[d] = 0;
109 for (c=0; c<NComponents; c++) {
110 if (CE[c + d*NComponents] == CELL) {
111 npts[d] = std::max(npts[d], (nGridPts - 1));
112 } else {
113 npts[d] = std::max(npts[d], nGridPts);
114 }
115 }
116 }
117 for (d=0; d<Dim; d++) ndi[d] = Index(npts[d]);
118 cfl.initialize(ndi, edt, vnodes);
119}
120
121//-----------------------------------------------------------------------------
122
123//-----------------------------------------------------------------------------
124// These specify both the total number of vnodes and the numbers of vnodes
125// along each dimension for the partitioning of the index space. Obviously this
126// restricts the number of vnodes to be a product of the numbers along each
127// dimension (the constructor implementation checks this):
128
129//------------------Cell centering---------------------------------------------
130template<unsigned Dim, class Mesh>
131inline void
133 const Mesh& mesh,
134 e_dim_tag* edt,
135 unsigned* vnodesAlongDirection,
136 bool recurse,
137 int vnodes)
138{
139 NDIndex<Dim> ndi;
140 for (unsigned int d=0; d<Dim; d++) ndi[d] = Index(mesh.gridSizes[d] - 1);
141 cfl.initialize(ndi, edt, vnodesAlongDirection, recurse, vnodes);
142}
143
144//------------------Vert centering---------------------------------------------
145template<unsigned Dim, class Mesh>
146inline void
148 const Mesh& mesh,
149 e_dim_tag* edt,
150 unsigned* vnodesAlongDirection,
151 bool recurse,
152 int vnodes)
153{
154 NDIndex<Dim> ndi;
155 for (unsigned int d=0; d<Dim; d++) ndi[d] = Index(mesh.gridSizes[d]);
156 cfl.initialize(ndi, edt, vnodesAlongDirection, recurse, vnodes);
157}
158
159//------------------Edge centering---------------------------------------------
160template<unsigned Dim, class Mesh>
161inline void
163 const Mesh& mesh,
164 e_dim_tag* edt,
165 unsigned* vnodesAlongDirection,
166 bool recurse,
167 int vnodes)
168{
169 NDIndex<Dim> ndi;
170 for (unsigned int d=0; d<Dim; d++) ndi[d] = Index(mesh.gridSizes[d]);
171 cfl.initialize(ndi, edt, vnodesAlongDirection, recurse, vnodes);
172}
173
174//------------------CartesianCentering centering-------------------------------
175template<CenteringEnum* CE, unsigned Dim, class Mesh,
176 unsigned NComponents>
177inline void
180 const Mesh& mesh,
181 e_dim_tag* edt,
182 unsigned* vnodesAlongDirection,
183 bool recurse,
184 int vnodes)
185{
186 NDIndex<Dim> ndi;
187 // For componentwise layout of Field of multicomponent object, like
188 // Field<Vektor...>, allow for maximal number of objects needed per
189 // dimension (the number for the object component requiring the maximal
190 // number):
191 unsigned npts[Dim], nGridPts;
192 unsigned int d, c;
193 for (d=0; d<Dim; d++) {
194 nGridPts = mesh.gridSizes[d];
195 npts[d] = 0;
196 for (c=0; c<NComponents; c++) {
197 if (CE[c + d*NComponents] == CELL) {
198 npts[d] = max(npts[d], (nGridPts - 1));
199 } else {
200 npts[d] = max(npts[d], nGridPts);
201 }
202 }
203 }
204 for (d=0; d<Dim; d++) ndi[d] = Index(npts[d]);
205 cfl.initialize(ndi, edt, vnodesAlongDirection, recurse, vnodes);
206}
207
208//-----------------------------------------------------------------------------
209// This initializer just specifies a completely user-provided partitioning.
210
211//------------------Cell centering---------------------------------------------
212template<unsigned Dim, class Mesh>
213inline void
215 const Mesh& mesh,
216 const NDIndex<Dim> *dombegin,
217 const NDIndex<Dim> *domend,
218 const int *nbegin,
219 const int *nend)
220{
221 NDIndex<Dim> ndi;
222 for (unsigned int d=0; d<Dim; d++) ndi[d] = Index(mesh.gridSizes[d] - 1);
223 cfl.initialize(ndi, dombegin, domend, nbegin, nend);
224}
225
226//------------------Vert centering---------------------------------------------
227template<unsigned Dim, class Mesh>
228inline void
230 const Mesh& mesh,
231 const NDIndex<Dim> *dombegin,
232 const NDIndex<Dim> *domend,
233 const int *nbegin,
234 const int *nend)
235{
236 NDIndex<Dim> ndi;
237 for (unsigned int d=0; d<Dim; d++) ndi[d] = Index(mesh.gridSizes[d]);
238 cfl.initialize(ndi, dombegin, domend, nbegin, nend);
239}
240
241//------------------Edge centering---------------------------------------------
242template<unsigned Dim, class Mesh>
243inline void
245 const Mesh& mesh,
246 const NDIndex<Dim> *dombegin,
247 const NDIndex<Dim> *domend,
248 const int *nbegin,
249 const int *nend)
250{
251 NDIndex<Dim> ndi;
252 for (unsigned int d=0; d<Dim; d++) ndi[d] = Index(mesh.gridSizes[d]);
253 cfl.initialize(ndi, dombegin, domend, nbegin, nend);
254}
255
256//------------------CartesianCentering centering-------------------------------
257template<CenteringEnum* CE, unsigned Dim, class Mesh,
258 unsigned NComponents>
259inline void
262 const Mesh& mesh,
263 const NDIndex<Dim> *dombegin,
264 const NDIndex<Dim> *domend,
265 const int *nbegin,
266 const int *nend)
267{
268 // For componentwise layout of Field of multicomponent object, like
269 // Field<Vektor...>, allow for maximal number of objects needed per
270 // dimension (the number for the object component requiring the maximal
271 // number):
272 unsigned npts[Dim], nGridPts;
273 unsigned int d, c;
274 for (d=0; d<Dim; d++) {
275 nGridPts = mesh.gridSizes[d];
276 npts[d] = 0;
277 for (c=0; c<NComponents; c++) {
278 if (CE[c + d*NComponents] == CELL) {
279 npts[d] = max(npts[d], (nGridPts - 1));
280 } else {
281 npts[d] = max(npts[d], nGridPts);
282 }
283 }
284 }
285
286 NDIndex<Dim> ndi;
287 for (d=0; d<Dim; d++) ndi[d] = Index(npts[d]);
288 cfl.initialize(ndi, dombegin, domend, nbegin, nend);
289}
290
291
292//=============================================================================
293// General ctor calls specializations of global function (workaround for lack
294// of partial specialization:
295//=============================================================================
296
297//-----------------------------------------------------------------------------
298// These specify only a total number of vnodes, allowing the constructor
299// complete control on how to do the vnode partitioning of the index space:
300// Constructor for arbitrary dimension with parallel/serial specifier array:
301
302// Constructor for arbitrary dimension with parallel/serial specifier array:
303// This one also works if nothing except mesh is specified:
304template<unsigned Dim, class Mesh, class Centering>
307 e_dim_tag *p,
308 int vnodes)
309{
310
312 "CenteredFieldLayout dimension cannot be greater than Mesh dimension!!");
313 centeredInitialize(*this, mesh, p, vnodes);
314}
315
316
317// Constructors for 1 ... 6 dimensions with parallel/serial specifiers:
318template<unsigned Dim, class Mesh, class Centering>
321 e_dim_tag p1,
322 int vnodes)
323{
324
325 PInsist(Dim==1,
326 "Number of arguments does not match dimension of CenteredFieldLayout!!");
328 "CenteredFieldLayout dimension cannot be greater than Mesh dimension!!");
329 centeredInitialize(*this, mesh, &p1, vnodes);
330}
331template<unsigned Dim, class Mesh, class Centering>
334 e_dim_tag p1, e_dim_tag p2,
335 int vnodes)
336{
337
338 PInsist(Dim==2,
339 "Number of arguments does not match dimension of CenteredFieldLayout!!");
341 "CenteredFieldLayout dimension cannot be greater than Mesh dimension!!");
342 e_dim_tag edt[2];
343 edt[0] = p1; edt[1] = p2;
344 centeredInitialize(*this, mesh, edt, vnodes);
345}
346template<unsigned Dim, class Mesh, class Centering>
349 e_dim_tag p1, e_dim_tag p2, e_dim_tag p3,
350 int vnodes)
351{
352
353 PInsist(Dim==3,
354 "Number of arguments does not match dimension of CenteredFieldLayout!!");
356 "CenteredFieldLayout dimension cannot be greater than Mesh dimension!!");
357 e_dim_tag edt[3];
358 edt[0] = p1; edt[1] = p2; edt[2] = p3;
359 centeredInitialize(*this, mesh, edt, vnodes);
360}
361template<unsigned Dim, class Mesh, class Centering>
364 e_dim_tag p1, e_dim_tag p2, e_dim_tag p3, e_dim_tag p4,
365 int vnodes)
366{
367
368 PInsist(Dim==4,
369 "Number of arguments does not match dimension of CenteredFieldLayout!!");
371 "CenteredFieldLayout dimension cannot be greater than Mesh dimension!!");
372 e_dim_tag edt[4];
373 edt[0] = p1; edt[1] = p2; edt[2] = p3; edt[3] = p4;
374 centeredInitialize(*this, mesh, edt, vnodes);
375}
376template<unsigned Dim, class Mesh, class Centering>
379 e_dim_tag p1, e_dim_tag p2, e_dim_tag p3, e_dim_tag p4,
380 e_dim_tag p5,
381 int vnodes)
382{
383
384 PInsist(Dim==5,
385 "Number of arguments does not match dimension of CenteredFieldLayout!!");
387 "CenteredFieldLayout dimension cannot be greater than Mesh dimension!!");
388 e_dim_tag edt[5];
389 edt[0] = p1; edt[1] = p2; edt[2] = p3; edt[3] = p4; edt[4] = p5;
390 centeredInitialize(*this, mesh, edt, vnodes);
391}
392template<unsigned Dim, class Mesh, class Centering>
395 e_dim_tag p1, e_dim_tag p2, e_dim_tag p3, e_dim_tag p4,
396 e_dim_tag p5, e_dim_tag p6,
397 int vnodes)
398{
399
400 PInsist(Dim==6,
401 "Number of arguments does not match dimension of CenteredFieldLayout!!");
403 "CenteredFieldLayout dimension cannot be greater than Mesh dimension!!");
404 e_dim_tag edt[6];
405 edt[0] = p1; edt[1] = p2; edt[2] = p3; edt[3] = p4; edt[4] = p5; edt[5] = p6;
406 centeredInitialize(*this, mesh, edt, vnodes);
407}
408//-----------------------------------------------------------------------------
409
410//-----------------------------------------------------------------------------
411// These specify both the total number of vnodes and the numbers of vnodes
412// along each dimension for the partitioning of the index space. Obviously this
413// restricts the number of vnodes to be a product of the numbers along each
414// dimension (the constructor implementation checks this):
415
416// Constructor for arbitrary dimension with parallel/serial specifier array:
417template<unsigned Dim, class Mesh, class Centering>
420 e_dim_tag *p,
421 unsigned* vnodesAlongDirection,
422 bool recurse,
423 int vnodes)
424{
425
427 "CenteredFieldLayout dimension cannot be greater than Mesh dimension!!");
428 centeredInitialize(*this, mesh, p, vnodesAlongDirection, recurse, vnodes);
429}
430// Constructors for 1 ... 6 dimensions with parallel/serial specifiers:
431template<unsigned Dim, class Mesh, class Centering>
434 e_dim_tag p1,
435 unsigned vnodes1,
436 bool recurse,
437 int vnodes)
438{
439
440 PInsist(Dim==1,
441 "Number of arguments does not match dimension of CenteredFieldLayout!!");
443 "CenteredFieldLayout dimension cannot be greater than Mesh dimension!!");
444 centeredInitialize(*this, mesh, &p1, &vnodes1, recurse, vnodes);
445}
446template<unsigned Dim, class Mesh, class Centering>
449 e_dim_tag p1, e_dim_tag p2,
450 unsigned vnodes1, unsigned vnodes2,
451 bool recurse,
452 int vnodes)
453{
454
455 PInsist(Dim==2,
456 "Number of arguments does not match dimension of CenteredFieldLayout!!");
458 "CenteredFieldLayout dimension cannot be greater than Mesh dimension!!");
459 e_dim_tag edt[2];
460 edt[0] = p1; edt[1] = p2;
461 unsigned vad[2];
462 vad[0] = vnodes1; vad[1] = vnodes2;
463 centeredInitialize(*this, mesh, edt, vad, recurse, vnodes);
464}
465template<unsigned Dim, class Mesh, class Centering>
468 e_dim_tag p1, e_dim_tag p2, e_dim_tag p3,
469 unsigned vnodes1, unsigned vnodes2, unsigned vnodes3,
470 bool recurse,
471 int vnodes)
472{
473
474 PInsist(Dim==3,
475 "Number of arguments does not match dimension of CenteredFieldLayout!!");
477 "CenteredFieldLayout dimension cannot be greater than Mesh dimension!!");
478 e_dim_tag edt[3];
479 edt[0] = p1; edt[1] = p2; edt[2] = p3;
480 unsigned vad[3];
481 vad[0] = vnodes1; vad[1] = vnodes2; vad[2] = vnodes3;
482 centeredInitialize(*this, mesh, edt, vad, recurse, vnodes);
483}
484template<unsigned Dim, class Mesh, class Centering>
487 e_dim_tag p1, e_dim_tag p2, e_dim_tag p3, e_dim_tag p4,
488 unsigned vnodes1, unsigned vnodes2, unsigned vnodes3,
489 unsigned vnodes4,
490 bool recurse,
491 int vnodes)
492{
493
494 PInsist(Dim==4,
495 "Number of arguments does not match dimension of CenteredFieldLayout!!");
497 "CenteredFieldLayout dimension cannot be greater than Mesh dimension!!");
498 e_dim_tag edt[4];
499 edt[0] = p1; edt[1] = p2; edt[2] = p3; edt[3] = p4;
500 unsigned vad[4];
501 vad[0] = vnodes1; vad[1] = vnodes2; vad[2] = vnodes3;
502 vad[3] = vnodes4;
503 centeredInitialize(*this, mesh, edt, vad, recurse, vnodes);
504}
505template<unsigned Dim, class Mesh, class Centering>
508 e_dim_tag p1, e_dim_tag p2, e_dim_tag p3, e_dim_tag p4,
509 e_dim_tag p5,
510 unsigned vnodes1, unsigned vnodes2, unsigned vnodes3,
511 unsigned vnodes4, unsigned vnodes5,
512 bool recurse,
513 int vnodes)
514{
515
516 PInsist(Dim==5,
517 "Number of arguments does not match dimension of CenteredFieldLayout!!");
519 "CenteredFieldLayout dimension cannot be greater than Mesh dimension!!");
520 e_dim_tag edt[5];
521 edt[0] = p1; edt[1] = p2; edt[2] = p3; edt[3] = p4; edt[4] = p5;
522 unsigned vad[5];
523 vad[0] = vnodes1; vad[1] = vnodes2; vad[2] = vnodes3;
524 vad[3] = vnodes4; vad[4] = vnodes5;
525 centeredInitialize(*this, mesh, edt, vad, recurse, vnodes);
526}
527template<unsigned Dim, class Mesh, class Centering>
530 e_dim_tag p1, e_dim_tag p2, e_dim_tag p3, e_dim_tag p4,
531 e_dim_tag p5, e_dim_tag p6,
532 unsigned vnodes1, unsigned vnodes2, unsigned vnodes3,
533 unsigned vnodes4, unsigned vnodes5, unsigned vnodes6,
534 bool recurse,
535 int vnodes)
536{
537
538 PInsist(Dim==6,
539 "Number of arguments does not match dimension of CenteredFieldLayout!!");
541 "CenteredFieldLayout dimension cannot be greater than Mesh dimension!!");
542 e_dim_tag edt[6];
543 edt[0] = p1; edt[1] = p2; edt[2] = p3; edt[3] = p4; edt[4] = p5; edt[5] = p6;
544 unsigned vad[6];
545 vad[0] = vnodes1; vad[1] = vnodes2; vad[2] = vnodes3;
546 vad[3] = vnodes4; vad[4] = vnodes5; vad[5] = vnodes6;
547 centeredInitialize(*this, mesh, edt, vad, recurse, vnodes);
548}
549
550//-----------------------------------------------------------------------------
551// A constructor for a completely user-specified partitioning of the
552// mesh space.
553
554template<unsigned Dim, class Mesh, class Centering>
557 const NDIndex<Dim> *dombegin,
558 const NDIndex<Dim> *domend,
559 const int *nbegin,
560 const int *nend)
561{
562
563 centeredInitialize(*this, mesh, dombegin, domend, nbegin, nend);
564}
565
566
567/***************************************************************************
568 * $RCSfile: CenteredFieldLayout.cpp,v $ $Author: adelmann $
569 * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:27 $
570 * IPPL_VERSION_ID: $Id: CenteredFieldLayout.cpp,v 1.1.1.1 2003/01/23 07:40:27 adelmann Exp $
571 ***************************************************************************/
const unsigned Dim
void centeredInitialize(CenteredFieldLayout< Dim, Mesh, Cell > &cfl, const Mesh &mesh, e_dim_tag *edt, int vnodes)
e_dim_tag
Definition: FieldLayout.h:55
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
Definition: ReductionLoc.h:84
CenteringEnum
@ CELL
#define PInsist(c, m)
Definition: PAssert.h:120
constexpr double c
The velocity of light in m/s.
Definition: Physics.h:45
void initialize(const Index &i1, e_dim_tag p1=PARALLEL, int vnodes=-1)
CenteredFieldLayout(Mesh &mesh, e_dim_tag *p=0, int vnodes=-1)
Definition: Index.h:237
Definition: Mesh.h:35
@ Dimension
Definition: Mesh.h:44