OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
UniformCartesian.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /***************************************************************************
3  *
4  * The IPPL Framework
5  *
6  *
7  * Visit http://people.web.psi.ch/adelmann/ for more details
8  *
9  ***************************************************************************/
10 
11 #ifndef UNIFORM_CARTESIAN_H
12 #define UNIFORM_CARTESIAN_H
13 
14 // UniformCartesian.h
15 // UniformCartesian class - represents uniform-spacing cartesian meshes.
16 
17 // include files
18 #include "Meshes/Mesh.h"
19 #include "Meshes/Centering.h"
21 #include "AppTypes/Vektor.h"
22 
23 // forward declarations
24 template<class T, unsigned D> class BareField;
25 template<class T, unsigned D, class M, class C> class Field;
26 template <unsigned Dim, class MFLOAT> class UniformCartesian;
27 template <unsigned Dim, class MFLOAT>
28 std::ostream& operator<<(std::ostream&, const UniformCartesian<Dim,MFLOAT>&);
29 template <unsigned Dim, class MFLOAT>
31 
32 template <unsigned Dim, class MFLOAT=double>
33 class UniformCartesian : public Mesh<Dim>
34 {
35 public:
36  //# public typedefs
38  typedef MFLOAT MeshValue_t;
40 
41  // Default constructor (use initialize() to make valid)
43  {
44  hasSpacingFields = false;
45  };
46  // Destructor
48  {
49  if (hasSpacingFields) {
50  delete VertSpacings;
51  delete CellSpacings;
52  delete FlVert;
53  delete FlCell;
54  }
55  };
56 
57  // Non-default constructors
58  UniformCartesian(const NDIndex<Dim>& ndi);
59  UniformCartesian(const Index& I);
60  UniformCartesian(const Index& I, const Index& J);
61  UniformCartesian(const Index& I, const Index& J, const Index& K);
62  // These also take a MFLOAT* specifying the mesh spacings:
63  UniformCartesian(const NDIndex<Dim>& ndi, MFLOAT* const delX);
64  UniformCartesian(const Index& I, MFLOAT* const delX);
65  UniformCartesian(const Index& I, const Index& J, MFLOAT* const delX);
66  UniformCartesian(const Index& I, const Index& J, const Index& K,
67  MFLOAT* const delX);
68  // These further take a Vektor<MFLOAT,Dim>& specifying the origin:
69  UniformCartesian(const NDIndex<Dim>& ndi, MFLOAT* const delX,
70  const Vektor<MFLOAT,Dim>& orig);
71  UniformCartesian(const Index& I, MFLOAT* const delX,
72  const Vektor<MFLOAT,Dim>& orig);
73  UniformCartesian(const Index& I, const Index& J, MFLOAT* const delX,
74  const Vektor<MFLOAT,Dim>& orig);
75  UniformCartesian(const Index& I, const Index& J, const Index& K,
76  MFLOAT* const delX, const Vektor<MFLOAT,Dim>& orig);
77 
78  // initialize functions
79  void initialize(const NDIndex<Dim>& ndi);
80  void initialize(const Index& I);
81  void initialize(const Index& I, const Index& J);
82  void initialize(const Index& I, const Index& J, const Index& K);
83  // These also take a MFLOAT* specifying the mesh spacings:
84  void initialize(const NDIndex<Dim>& ndi, MFLOAT* const delX);
85  void initialize(const Index& I, MFLOAT* const delX);
86  void initialize(const Index& I, const Index& J, MFLOAT* const delX);
87  void initialize(const Index& I, const Index& J, const Index& K,
88  MFLOAT* const delX);
89  // These further take a Vektor<MFLOAT,Dim>& specifying the origin:
90  void initialize(const NDIndex<Dim>& ndi, MFLOAT* const delX,
91  const Vektor<MFLOAT,Dim>& orig);
92  void initialize(const Index& I, MFLOAT* const delX,
93  const Vektor<MFLOAT,Dim>& orig);
94  void initialize(const Index& I, const Index& J, MFLOAT* const delX,
95  const Vektor<MFLOAT,Dim>& orig);
96  void initialize(const Index& I, const Index& J, const Index& K,
97  MFLOAT* const delX, const Vektor<MFLOAT,Dim>& orig);
98 
99 
100 private:
101 
102  // Private member data:
103  MFLOAT meshSpacing[Dim]; // delta-x, delta-y (>1D), delta-z (>2D)
104  MFLOAT volume; // Cell length(1D), area(2D), or volume (>2D)
105  Vektor<MFLOAT,Dim> origin; // Origin of mesh coordinates (vertices)
106  FieldLayout<Dim>* FlCell; // Layouts for BareField* CellSpacings
107  FieldLayout<Dim>* FlVert; // Layouts for BareField* VertSpacings
108 
109  // Private member functions:
110  void setup(); // Private function doing tasks common to all constructors.
111  // Set only the derivative constants, using pre-set spacings:
112  void set_Dvc();
113 
114 
115 public:
116 
117  // Public member data:
118  unsigned gridSizes[Dim]; // Sizes (number of vertices)
119  Vektor<MFLOAT,Dim> Dvc[1<<Dim]; // Constants for derivatives.
120  bool hasSpacingFields; // Flags allocation of the following:
123 
124  // Public member functions:
125 
126  // Create BareField's of vertex and cell spacings; allow for specifying
127  // layouts via the FieldLayout e_dim_tag and vnodes parameters (these
128  // get passed in to construct the FieldLayout used to construct the
129  // BareField's).
130  void storeSpacingFields(); // Default; will have default layout
131  // Special cases for 1-3 dimensions, ala FieldLayout ctors:
132  void storeSpacingFields(e_dim_tag p1, int vnodes=-1);
133  void storeSpacingFields(e_dim_tag p1, e_dim_tag p2, int vnodes=-1);
135  int vnodes=-1);
136  // Next we have one for arbitrary dimension, ala FieldLayout ctor:
137  // All the others call this one internally:
138  void storeSpacingFields(e_dim_tag *p, int vnodes=-1);
139 
140  // These specify both the total number of vnodes and the numbers of vnodes
141  // along each dimension for the partitioning of the index space. Obviously
142  // this restricts the number of vnodes to be a product of the numbers along
143  // each dimension (the constructor implementation checks this): Special
144  // cases for 1-3 dimensions, ala FieldLayout ctors (see FieldLayout.h for
145  // more relevant comments, including definition of recurse):
147  unsigned vnodes1,
148  bool recurse=false,
149  int vnodes=-1);
151  unsigned vnodes1, unsigned vnodes2,
152  bool recurse=false,int vnodes=-1);
154  unsigned vnodes1, unsigned vnodes2, unsigned vnodes3,
155  bool recurse=false, int vnodes=-1);
156  // Next we have one for arbitrary dimension, ala FieldLayout ctor:
157  // All the others call this one internally:
159  unsigned* vnodesPerDirection,
160  bool recurse=false, int vnodes=-1);
161 
162  // Accessor functions for member data:
163  // Get the origin of mesh vertex positions:
165  // Get the spacings of mesh vertex positions along specified direction:
166  MFLOAT get_meshSpacing(unsigned d) const;
167  // Get the cell volume:
168  MFLOAT get_volume() const;
169 
170  // Set functions for member data:
171  // Set the origin of mesh vertex positions:
172  void set_origin(const Vektor<MFLOAT,Dim>& o);
173  // Set the spacings of mesh vertex positions (recompute Dvc, cell volume):
174  void set_meshSpacing(MFLOAT* const del);
175 
176  // Formatted output of UniformCartesian object:
177  void print(std::ostream&);
178 
179  void print(Inform &);
180 
181  //----Other UniformCartesian methods:----------------------------------------
182  // Volume of single cell indexed by input NDIndex;
183  MFLOAT getCellVolume(const NDIndex<Dim>&) const;
184  // Field of volumes of all cells:
187  // Volume of range of cells bounded by verticies specified by input NDIndex:
188  MFLOAT getVertRangeVolume(const NDIndex<Dim>&) const;
189  // Volume of range of cells spanned by input NDIndex (index of cells):
190  MFLOAT getCellRangeVolume(const NDIndex<Dim>&) const;
191  // Nearest vertex index to (x,y,z):
193  // Nearest vertex index with all vertex coordinates below (x,y,z):
195  // NDIndex for cell in cell-ctrd Field containing the point (x,y,z):
196  inline
198  {
199  return getVertexBelow(x); // I think these functions are identical. -tjw
200  }
201  // (x,y,z) coordinates of indexed vertex:
203  // Field of (x,y,z) coordinates of all vertices:
207  // (x,y,z) coordinates of indexed cell:
209  // Field of (x,y,z) coordinates of all cells:
213  // Vertex-vertex grid spacing of indexed cell:
215  // Field of vertex-vertex grid spacings of all cells:
219  // Cell-cell grid spacing of indexed vertex:
221  // Field of cell-cell grid spacings of all vertices:
225  // Array of surface normals to cells adjoining indexed cell:
227  // Array of (pointers to) Fields of surface normals to all cells:
230  // Similar functions, but specify the surface normal to a single face, using
231  // the following numbering convention: 0 means low face of 1st dim, 1 means
232  // high face of 1st dim, 2 means low face of 2nd dim, 3 means high face of
233  // 2nd dim, and so on:
234  Vektor<MFLOAT,Dim> getSurfaceNormal(const NDIndex<Dim>&, unsigned) const;
237  UniformCartesian<Dim,MFLOAT>,Cell>&, unsigned) const;
238 
239 };
240 
241 // I/O
242 
243 // Stream formatted output of UniformCartesian object:
244 template< unsigned Dim, class MFLOAT >
245 inline
246 std::ostream& operator<<(std::ostream& out, const UniformCartesian<Dim,MFLOAT>& mesh)
247 {
249  const_cast<UniformCartesian<Dim,MFLOAT>&>(mesh);
250  ncmesh.print(out);
251  return out;
252 }
253 
254 template< unsigned Dim, class MFLOAT >
255 inline
257 {
259  const_cast<UniformCartesian<Dim,MFLOAT>&>(mesh);
260  ncmesh.print(out);
261  return out;
262 }
263 
264 //*****************************************************************************
265 // Stuff taken from old Cartesian.h, which now applies to UniformCartesian:
266 //*****************************************************************************
267 
268 #ifndef CARTESIAN_STENCIL_SETUP_H
270 #endif
271 
272 //----------------------------------------------------------------------
273 //
274 //
275 // Definitions of stencils.
276 //
277 // For each one we have first we have the user level function that takes
278 // a Field argument and returns an expression template.
279 // This is the thing the user code sees.
280 // These could use some asserts to make sure the Fields have
281 // enough guard cells.
282 //
283 // Then we have the 'apply' function that gets used in the inner loop
284 // when evaluating the expression. This would be better done as a
285 // member function of the tags above, but that would require member
286 // function templates, which we are holding off on for now.
287 //
288 //----------------------------------------------------------------------
289 
290 //----------------------------------------------------------------------
291 //
292 // Divergence Vert->Cell
293 //
294 // First is the user function for any dimension and element types.
295 // it returns a unary element type.
296 //
297 //----------------------------------------------------------------------
298 
300 //
301 // Here are the old style definitions.
302 //
304 
305 //----------------------------------------------------------------------
306 // Divergence Vektor/Vert -> Scalar/Cell
307 //----------------------------------------------------------------------
308 template < class T, class MFLOAT >
312 //----------------------------------------------------------------------
313 template < class T, class MFLOAT >
317 //----------------------------------------------------------------------
318 template < class T, class MFLOAT >
322 //----------------------------------------------------------------------
323 // Divergence Vektor/Cell -> Scalar/Vert
324 //----------------------------------------------------------------------
325 template < class T, class MFLOAT >
329 //----------------------------------------------------------------------
330 template < class T, class MFLOAT >
334 //----------------------------------------------------------------------
335 template < class T, class MFLOAT >
339 //----------------------------------------------------------------------
340 // Divergence Vektor/Vert -> Scalar/Vert
341 //----------------------------------------------------------------------
342 template < class T, class MFLOAT >
346 //----------------------------------------------------------------------
347 template < class T, class MFLOAT >
351 //----------------------------------------------------------------------
352 template < class T, class MFLOAT >
356 //----------------------------------------------------------------------
357 // Divergence Vektor/Edge -> Scalar/Vert
358 //----------------------------------------------------------------------
359 template < class T, class MFLOAT >
363 //----------------------------------------------------------------------
364 template < class T, class MFLOAT >
368 //----------------------------------------------------------------------
369 template < class T, class MFLOAT >
373 //----------------------------------------------------------------------
374 // Divergence Vektor/Cell -> Scalar/Cell
375 //----------------------------------------------------------------------
376 template < class T, class MFLOAT >
380 //----------------------------------------------------------------------
381 template < class T, class MFLOAT >
385 //----------------------------------------------------------------------
386 template < class T, class MFLOAT >
390 //----------------------------------------------------------------------
391 // Divergence Tenzor/Vert -> Vektor/Cell
392 //----------------------------------------------------------------------
393 template < class T, class MFLOAT >
397 //----------------------------------------------------------------------
398 template < class T, class MFLOAT >
402 //----------------------------------------------------------------------
403 template < class T, class MFLOAT >
407 //----------------------------------------------------------------------
408 // Divergence Tenzor/Cell -> Vektor/Vert
409 //----------------------------------------------------------------------
410 template < class T, class MFLOAT >
414 //----------------------------------------------------------------------
415 template < class T, class MFLOAT >
419 //----------------------------------------------------------------------
420 template < class T, class MFLOAT >
424 
425 //----------------------------------------------------------------------
426 // Grad Scalar/Vert -> Vektor/Cell
427 //----------------------------------------------------------------------
428 template < class T, class MFLOAT >
432 //----------------------------------------------------------------------
433 template < class T, class MFLOAT >
437 //----------------------------------------------------------------------
438 
440 template < class T, class MFLOAT >
444 
446 template < class T, class MFLOAT >
450 //----------------------------------------------------------------------
451 // Grad Scalar/Vert -> Vektor/Edge
452 //----------------------------------------------------------------------
453 template < class T, class MFLOAT >
457 //----------------------------------------------------------------------
458 template < class T, class MFLOAT >
462 //----------------------------------------------------------------------
463 template < class T, class MFLOAT >
467 //----------------------------------------------------------------------
468 // Grad Scalar/Cell -> Vektor/Vert
469 //----------------------------------------------------------------------
470 template < class T, class MFLOAT >
474 //----------------------------------------------------------------------
475 template < class T, class MFLOAT >
479 //----------------------------------------------------------------------
480 template < class T, class MFLOAT >
484 //----------------------------------------------------------------------
485 // Grad Scalar/Vert -> Vektor/Vert
486 //----------------------------------------------------------------------
487 template < class T, class MFLOAT >
491 //----------------------------------------------------------------------
492 template < class T, class MFLOAT >
496 //----------------------------------------------------------------------
497 template < class T, class MFLOAT >
501 //----------------------------------------------------------------------
502 // Grad Scalar/Cell -> Vektor/Cell
503 //----------------------------------------------------------------------
504 template < class T, class MFLOAT >
508 //----------------------------------------------------------------------
509 template < class T, class MFLOAT >
513 //----------------------------------------------------------------------
514 template < class T, class MFLOAT >
518 //----------------------------------------------------------------------
519 // Grad Vektor/Vert -> Tenzor/Cell
520 //----------------------------------------------------------------------
521 template < class T, class MFLOAT >
525 //----------------------------------------------------------------------
526 template < class T, class MFLOAT >
530 //----------------------------------------------------------------------
531 template < class T, class MFLOAT >
535 //----------------------------------------------------------------------
536 // Grad Vektor/Cell -> Tenzor/Vert
537 //----------------------------------------------------------------------
538 template < class T, class MFLOAT >
542 //----------------------------------------------------------------------
543 template < class T, class MFLOAT >
547 //----------------------------------------------------------------------
548 template < class T, class MFLOAT >
552 //----------------------------------------------------------------------
553 // Divergence SymTenzor/Vert -> Vektor/Cell
554 //----------------------------------------------------------------------
555 //----------------------------------------------------------------------
556 template < class T, class MFLOAT >
560 //----------------------------------------------------------------------
561 template < class T, class MFLOAT >
565 //----------------------------------------------------------------------
566 // Divergence SymTenzor/Cell -> Vektor/Vert
567 //----------------------------------------------------------------------
568 template < class T, class MFLOAT >
572 //----------------------------------------------------------------------
573 template < class T, class MFLOAT >
577 //----------------------------------------------------------------------
578 template < class T, class MFLOAT >
582 
583 namespace IPPL {
584 
585 //----------------------------------------------------------------------
586 // Weighted average Cell to Vert
587 //----------------------------------------------------------------------
588 template < class T1, class T2, class MFLOAT >
593 //----------------------------------------------------------------------
594 template < class T1, class T2, class MFLOAT >
599 //----------------------------------------------------------------------
600 template < class T1, class T2, class MFLOAT >
605 
606 //----------------------------------------------------------------------
607 // Weighted average Vert to Cell
608 //----------------------------------------------------------------------
609 template < class T1, class T2, class MFLOAT >
614 //----------------------------------------------------------------------
615 template < class T1, class T2, class MFLOAT >
620 //----------------------------------------------------------------------
621 template < class T1, class T2, class MFLOAT >
626 
627 //----------------------------------------------------------------------
628 
629 //----------------------------------------------------------------------
630 // Unweighted average Cell to Vert
631 //----------------------------------------------------------------------
632 template < class T1, class MFLOAT >
636 //----------------------------------------------------------------------
637 template < class T1, class MFLOAT >
641 //----------------------------------------------------------------------
642 template < class T1, class MFLOAT >
646 
647 //----------------------------------------------------------------------
648 // Unweighted average Vert to Cell
649 //----------------------------------------------------------------------
650 template < class T1, class MFLOAT >
654 //----------------------------------------------------------------------
655 template < class T1, class MFLOAT >
659 //----------------------------------------------------------------------
660 template < class T1, class MFLOAT >
664 
665 //----------------------------------------------------------------------
666 }
667 
669 
670 #endif // UNIFORM_CARTESIAN_H
671 
672 /***************************************************************************
673  * $RCSfile: UniformCartesian.h,v $ $Author: adelmann $
674  * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:28 $
675  * IPPL_VERSION_ID: $Id: UniformCartesian.h,v 1.1.1.1 2003/01/23 07:40:28 adelmann Exp $
676  ***************************************************************************/
const unsigned Dim
e_dim_tag
Definition: FieldLayout.h:55
Field< T, 1U, UniformCartesian< 1U, MFLOAT >, Cell > & Div(Field< Vektor< T, 1U >, 1U, UniformCartesian< 1U, MFLOAT >, Vert > &x, Field< T, 1U, UniformCartesian< 1U, MFLOAT >, Cell > &r)
std::ostream & operator<<(std::ostream &, const UniformCartesian< Dim, MFLOAT > &)
Field< Vektor< T, 1U >, 1U, UniformCartesian< 1U, MFLOAT >, Cell > & Grad(Field< T, 1U, UniformCartesian< 1U, MFLOAT >, Vert > &x, Field< Vektor< T, 1U >, 1U, UniformCartesian< 1U, MFLOAT >, Cell > &r)
Field< Vektor< T, 3U >, 3U, UniformCartesian< 3U, MFLOAT >, Cell > & Grad1Ord(Field< T, 3U, UniformCartesian< 3U, MFLOAT >, Vert > &x, Field< Vektor< T, 3U >, 3U, UniformCartesian< 3U, MFLOAT >, Cell > &r)
Old Grad operator.
Field< T1, 1U, Cartesian< 1U, MFLOAT >, Vert > & Average(Field< T1, 1U, Cartesian< 1U, MFLOAT >, Cell > &x, Field< T2, 1U, Cartesian< 1U, MFLOAT >, Cell > &w, Field< T1, 1U, Cartesian< 1U, MFLOAT >, Vert > &r)
Definition: Cartesian.hpp:3113
Definition: Tenzor.h:35
Definition: Vektor.h:32
Definition: Field.h:33
NDIndex< Dim > getVertexBelow(const Vektor< MFLOAT, Dim > &) const
void getSurfaceNormalFields(Field< Vektor< MFLOAT, Dim >, Dim, UniformCartesian< Dim, MFLOAT >, Cell > **) const
BareField< Vektor< MFLOAT, Dim >, Dim > * CellSpacings
Field< Vektor< MFLOAT, Dim >, Dim, UniformCartesian< Dim, MFLOAT >, Vert > & getDeltaCellField(Field< Vektor< MFLOAT, Dim >, Dim, UniformCartesian< Dim, MFLOAT >, Vert > &) const
void set_origin(const Vektor< MFLOAT, Dim > &o)
Vektor< MFLOAT, Dim > * getSurfaceNormals(const NDIndex< Dim > &) const
Field< MFLOAT, Dim, UniformCartesian< Dim, MFLOAT >, Cell > & getCellVolumeField(Field< MFLOAT, Dim, UniformCartesian< Dim, MFLOAT >, Cell > &) const
Vektor< MFLOAT, Dim > getVertexPosition(const NDIndex< Dim > &) const
unsigned gridSizes[Dim]
Vektor< MFLOAT, Dim > origin
FieldLayout< Dim > * FlCell
Field< Vektor< MFLOAT, Dim >, Dim, UniformCartesian< Dim, MFLOAT >, Cell > & getDeltaVertexField(Field< Vektor< MFLOAT, Dim >, Dim, UniformCartesian< Dim, MFLOAT >, Cell > &) const
NDIndex< Dim > getCellContaining(const Vektor< MFLOAT, Dim > &x) const
MFLOAT get_meshSpacing(unsigned d) const
Vektor< MFLOAT, Dim > MeshVektor_t
Field< Vektor< MFLOAT, Dim >, Dim, UniformCartesian< Dim, MFLOAT >, Cell > & getSurfaceNormalField(Field< Vektor< MFLOAT, Dim >, Dim, UniformCartesian< Dim, MFLOAT >, Cell > &, unsigned) const
MFLOAT get_volume() const
Vektor< MFLOAT, Dim > getDeltaVertex(const NDIndex< Dim > &) const
MFLOAT getCellVolume(const NDIndex< Dim > &) const
MFLOAT getCellRangeVolume(const NDIndex< Dim > &) const
Field< Vektor< MFLOAT, Dim >, Dim, UniformCartesian< Dim, MFLOAT >, Cell > & getCellPositionField(Field< Vektor< MFLOAT, Dim >, Dim, UniformCartesian< Dim, MFLOAT >, Cell > &) const
MFLOAT meshSpacing[Dim]
Field< Vektor< MFLOAT, Dim >, Dim, UniformCartesian< Dim, MFLOAT >, Vert > & getVertexPositionField(Field< Vektor< MFLOAT, Dim >, Dim, UniformCartesian< Dim, MFLOAT >, Vert > &) const
void set_meshSpacing(MFLOAT *const del)
NDIndex< Dim > getNearestVertex(const Vektor< MFLOAT, Dim > &) const
FieldLayout< Dim > * FlVert
MFLOAT getVertRangeVolume(const NDIndex< Dim > &) const
Vektor< MFLOAT, Dim > getCellPosition(const NDIndex< Dim > &) const
void print(std::ostream &)
Vektor< MFLOAT, Dim > get_origin() const
BareField< Vektor< MFLOAT, Dim >, Dim > * VertSpacings
Vektor< MFLOAT, Dim > Dvc[1<< Dim]
Vektor< MFLOAT, Dim > getSurfaceNormal(const NDIndex< Dim > &, unsigned) const
void initialize(const NDIndex< Dim > &ndi)
Vektor< MFLOAT, Dim > getDeltaCell(const NDIndex< Dim > &) const
Definition: Index.h:237
Definition: Centering.h:32
Definition: Centering.h:43
Definition: Centering.h:50
Definition: Mesh.h:35
Definition: Inform.h:42