C++ mpi module for stochmagnet_main Package
SM_NetworkGridBuilder.h
1 #ifndef SM_NetworkGridBuidler_H
2 #define SM_NetworkGridBuilder_H
3 
4 //super class header
5 #include "SM_NetworkBuilder.h"
6 
7 //network header
8 #include "SM_Network.h"
9 
10 //crystal structure header
11 #include "SM_CrystalStructure.h"
12 
13 //utility functions header
14 #include "functions_array.h"
15 
22 
23 
24 private :
25 
26  // class name
29 
30 
31  //attributes
32  //indices move direction per hyperlan in {0,1}
33  static std::array<tUCInt,SM_Constants::HDIM> HYPERPLAN_MOVES_NUMBER;
34  //indices move diercetion in space in {0,1}
35  static std::array<tUCInt,SM_Constants::DIM> SPACE_MOVES_NUMBER;
36 
37  //indictaes if static arrays are initialized
38  static tBoolean INIT_STATIC_ARRAYS;
39 
40 public:
43  static tUCInt N_HYPERPLAN_MOVES;
46  static tUCInt N_SPACE_MOVES;
47 
48 
49 
50 protected:
51 
52  // CONSTRUCTORS
56 
57 
58  //initialize only once staic arrays
59  if (!INIT_STATIC_ARRAYS) {
61  N_SPACE_MOVES=1;
62  for(auto& Mk:SPACE_MOVES_NUMBER) {
63  Mk=2;
64  N_SPACE_MOVES*=Mk;
65  }
66  for(auto& Mk:HYPERPLAN_MOVES_NUMBER) {
67  Mk=2;
69  }
70  INIT_STATIC_ARRAYS=true;
71  }
72 
73  }
74 
75  // DESTRUCTORS
78  virtual ~SM_NetworkGridBuilder(void) {
79  }
80 
81 public :
82 
83  //Instance building
84  //=================
85 
86 
87 
88 
89  //MEMORY
90  //=====
91 
105  virtual tMemSize getMemorySize() const {
106  return sizeof(*this)+getContentsMemorySize();
107  }
108 
117  virtual tMemSize getContentsMemorySize() const {
118  tMemSize mem=SuperClass::getContentsMemorySize();
119 
120  return mem;
121  }
122 
123  //buidler grid methods
124  //=================
125 
126 
127  //IO methods
128  //==========
129 
130 protected:
131 
132 
133 
134 
135  //Grid Block methods
136  //====================
137 public:
157  static tIndex BuildBlock(const std::array<tInteger,SM_Constants::DIM>& nCs,
158  const tInteger *iBlocksNumber,
159  const tInteger *iBlockIndex,
160  const tReal& margin,
161  const tReal *iX0,
162  const tReal *iHs,
163  tInteger *iI0,
164  tInteger *iI1,
165  tReal *iBlockMinPoint,
166  tReal *iBlockMaxPoint);
167 
177  inline static tIndex GetCellsNumberInBlock(const std::array<tInteger,SM_Constants::DIM>& nCs,
178  const tInteger *iBlocksNumber,
179  const tInteger *iBlockIndex) {
180 
181  //number of Cells of the block
182  tIndex nCells=1;
183 
184  tInteger I0k,I1k;
185 
186  //iterator on total number of points per direction
187  for(const auto& Nk:nCs) {//loop on direction k
188  //Nk: number of cells in the direction k
189  //bounded index of the block
190  I0k=(*iBlockIndex);
191  I0k*=Nk;
192  I0k/=(*iBlocksNumber);
193 
194  I1k=(*iBlockIndex);
195  I1k++;
196  I1k*=Nk;
197  I1k/=(*iBlocksNumber);
198  I1k++;
199 
200  //max index must not be greater than the number of cells
201  I1k=(I1k>Nk)?Nk:I1k ;
202 
203  //number of cells
204  nCells*=I1k-I0k;
205 
206  //iterator at next coordinate
207  iBlockIndex++;
208  iBlocksNumber++;
209 
210  }
211  return nCells;
212  }
213 
228  template<tUCInt R>
229  inline static tBoolean IsPointInBlock(std::array<tInteger,SM_Constants::DIM>& I,
230  const tReal *iBlockMinPoint,
231  const tReal *iBlockMaxPoint,
232  const tReal* iX0,
233  const tReal* iHs,
234  tReal *iP) {
235 
236  //coodinate of point P=X0+I.Hs
237 
238  tBoolean isPInBlock=true;
239  for(const auto& Ik:I) {//loop on coordinate
240  (*iP)=Ik;
241  (*iP)+=R*0.5;
242  (*iP)*=(*iHs);
243  (*iP)+=(*iX0);
244  //verify the point is in the block
245  isPInBlock=isPInBlock && ((*iP)>=(*iBlockMinPoint)) && ((*iP)<(*iBlockMaxPoint));
246  //iterators at next coordinate
247  iP++;
248  iHs++;
249  iX0++;
250  iBlockMinPoint++;
251  iBlockMaxPoint++;
252  }
253  return isPInBlock;
254 
255  }
270  static tBoolean GetCenterFacePointInBlock(const tDimension& d,
271  const std::array<tDimension,SM_Constants::HDIM>& hyperplanBase,
272  const std::array<tInteger,SM_Constants::DIM>& faceElementIndices,
273  const std::array<tReal,SM_Constants::DIM>& blockMinPoint,
274  const std::array<tReal,SM_Constants::DIM>& blockMaxPoint,
275  std::array<tUCInt,SM_Constants::HDIM>& moveIndices,
276  const std::array<tReal,SM_Constants::DIM>& X0,
277  const std::array<tReal,SM_Constants::DIM>& H,
278  std::array<tReal,SM_Constants::DIM>& P);
279 
280  //Element coordinates methods
281  //============================
282 
292  template<tBoolean R>
293  inline static void GetPointWithIndices(std::array<tInteger,SM_Constants::DIM>& I,
294  const tReal* iX0,
295  const tReal* iHs,
296  tReal *iP) {
297 
298  //coodinate of point P=X0+I.Hs
299  for(const auto& Ik:I) {//loop on coordinate
300  (*iP)=Ik;
301  (*iP)+=R*0.5;
302  (*iP)*=(*iHs);
303  (*iP)+=(*iX0);
304 
305  //iterators at next coordinate
306  iP++;
307  iHs++;
308  iX0++;
309  }
310 
311 
312 
313  }
314 
324  static void GetCenterFacePoint(const tDimension& d,
325  const std::array<tDimension,SM_Constants::HDIM>& hyperplanBase,
326  const std::array<tInteger,SM_Constants::DIM>& faceElementIndices,
327  std::array<tUCInt,SM_Constants::HDIM>& movesIndices,
328  const std::array<tReal,SM_Constants::DIM>& X0,
329  const std::array<tReal,SM_Constants::DIM>& H,
330  std::array<tReal,SM_Constants::DIM>& P);
331 
332 
333 
334 
335  //Topological grid cell methods
336  //================================
337 
346  static void GetCellVertices(const std::array<tInteger,SM_Constants::DIM>& cellIndices,
347  const std::array<tInteger,SM_Constants::DIM>& nPs,
348  const std::array<tBoolean,SM_Constants::DIM>& isPeriodic,
349  std::array<tUCInt,SM_Constants::DIM>& moveIndices,//work array
350  std::array<tInteger,SM_Constants::DIM>& vertexIndices,//work array
351  std::map<tIndex,tIndex>& vertices);
363  static void GetFaceVertices(const tDimension& d,
364  const std::array<tDimension,SM_Constants::HDIM>& hyperplanBase,
365  const std::array<tInteger,SM_Constants::DIM> faceElementIndices,
366  const std::array<tInteger,SM_Constants::DIM>& nPs,
367  const std::array<tBoolean,SM_Constants::DIM>& isPeriodic,
368  std::array<tUCInt,SM_Constants::HDIM>& moveIndices,//work array
369  std::array<tInteger,SM_Constants::DIM>& vertexIndices,//work array
370  tIndex& vertexIndex,//work index
371  std::map<tIndex,tIndex>& vertices);
372 
384  static tBoolean IsFaceInDomain(const tDimension& d,
385  const std::array<tDimension,SM_Constants::HDIM>& hyperplanBase,
386  const tInteger* iFaceElementIndices,//in base (e_u,e_v,e_d)
387  const std::array<tInteger,SM_Constants::DIM>& nCs,
388  const std::array<tBoolean,SM_Constants::DIM>& isPeriodic,
389  const tBoolean& incMask,const tMask* vMask,
390  std::array<tInteger,SM_Constants::DIM>& connectedCellIndices);
391 
392  //Topological connection methods on grid structure
393  //=================================================
394 
405  static void GetConnectedDomainCellsToVertex(const std::array<tInteger,SM_Constants::DIM>& vertexIndices,
406  const std::array<tInteger,SM_Constants::DIM>& Ns,
407  const std::array<tBoolean,SM_Constants::DIM>& isPeriodic,
408  const tBoolean& incMask,const tMask* vMask,
409  std::array<tUCInt,SM_Constants::DIM>& moveIndices,//work array
410  std::array<tInteger,SM_Constants::DIM>& connectedCellIndices,//work array
411  std::map<tIndex,tIndex>& connectedCells);
412 
424  static void GetConnectedDomainCellsToFace(const tDimension& d,
425  const std::array<tDimension,SM_Constants::HDIM>& hyperplanBase,
426  const tInteger* iFaceElementIndices,//in base (e_u,e_v,e_d)
427  const std::array<tInteger,SM_Constants::DIM>& nCs,
428  const std::array<tBoolean,SM_Constants::DIM>& isPeriodic,
429  const tBoolean& incMask,const tMask* vMask,
430  std::array<tInteger,SM_Constants::DIM>& connectedCellIndices,//work array
431  std::map<tIndex,tIndex>& connectedCells);
432 
448  static void GetConnectedDomainFacesToVertex(const std::array<tInteger,SM_Constants::DIM>& vertexIndices,
449  const tDimension& d,
450  const std::array<tDimension,SM_Constants::HDIM>& hyperplanBase,
451  const std::array<tInteger,SM_Constants::DIM>& facesElementsNumber,
452  const std::array<tInteger,SM_Constants::DIM>& nCs,
453  const std::array<tBoolean,SM_Constants::DIM>& isPeriodic,
454  const tBoolean& incMask,const tMask* vMask,
455  std::array<tUCInt,SM_Constants::HDIM>& moveIndices,
456  std::array<tInteger,SM_Constants::DIM>& cellIndices,//work array
457  tIndex& index,//work index
458  std::array<tInteger,SM_Constants::DIM>& faceElementIndices,//work array
459  std::map<tIndex,tIndex>& connectedFaces);
476  static void GetConnectedDomainFacesToFace(const tDimension& p,
477  const std::array<tDimension,SM_Constants::HDIM>& pHyperplanBase,
478  const tInteger* iFaceElementIndices,//in base (e_u,e_v,e_d)
479  const tDimension& q,
480  const std::array<tDimension,SM_Constants::HDIM>& qHyperplanBase,
481  const std::array<tInteger,SM_Constants::DIM>& qFacesElementsNumber,
482  const std::array<tInteger,SM_Constants::DIM>& nCs,
483  const std::array<tBoolean,SM_Constants::DIM>& isPeriodic,
484  const tBoolean& incMask,const tMask* vMask,
485  std::array<tInteger,SM_Constants::DIM>& connectedCellIndices,//work array
486  tIndex& cellIndex,//work index
487  std::array<tInteger,SM_Constants::DIM>& connectedFaceIndices,//work array
488  std::map<tIndex,tIndex>& connectedFaces);
489 
490 
491 
492 
493  //weights methods
494  //================
495 
505  static void BuildVerticesWeight(const std::array<tInteger,SM_Constants::DIM>& nCs,
506  const std::array<tInteger,SM_Constants::DIM>& nPs,
507  const std::array<tBoolean,SM_Constants::DIM>& isPeriodic,
508  const std::valarray<tMask>& mask,
509  tReal *iVerticesWeight,
510  tUCInt *iConnectedCellsNumber,
511  tIndex *iConnectedCells);
512 
524  static void BuildFacesWeight(const tDimension& d,
525  const std::array<tDimension,SM_Constants::HDIM>& hyperplanBase,
526  const std::array<tInteger,SM_Constants::DIM>& nCs,
527  const std::array<tInteger,SM_Constants::DIM>& nPs,
528  const std::array<tBoolean,SM_Constants::DIM>& isPeriodic,
529  const std::valarray<tMask>& mask,
530  tReal *iFacesWeight,
531  tUCInt *iConnectedCellsNumber,
532  tIndex *iConnectedCells);
533 
541  static void BuildCellsWeight(const std::array<tInteger,SM_Constants::DIM>& nCs,
542  const std::valarray<tMask>& mask,
543  tReal *iCellsWeight,
544  tUCInt *iConnectedCellsNumber,
545  tIndex *iConnectedCells);
546 
554  static void BuildCellsParticlesNumber(const std::array<tInteger,SM_Constants::DIM> Ns,
555  const std::valarray<tReal>& elementsWeight,
556  const std::valarray<tUCInt>& elementsConnectedCellsNumber,
557  const std::valarray<tIndex>& elementsConnectedCells,
558  std::valarray<tReal>& cellsParticlesNumber);
566  static void BuildElementsVolume(const std::valarray<tReal>& elementsWeight,
567  const std::valarray<tUCInt>& elementsConnectedCellsNumber,
568  const std::valarray<tIndex>& elementsConnectedCells,
569  const std::valarray<tReal>& cellsParticlesNumber,
570  std::valarray<tReal>& elementsVolume);
571 
572 public:
573 
574 };
575 
576 #endif
This class is dedicated to build a network.
Definition: SM_NetworkBuilder.h:28
virtual tMemSize getContentsMemorySize() const
return the memory size of the included associations
Definition: SM_NetworkBuilder.h:86
This class build a network from unit cells defined on grid.
Definition: SM_NetworkGridBuilder.h:21
static void BuildCellsParticlesNumber(const std::array< tInteger, SM_Constants::DIM > Ns, const std::valarray< tReal > &elementsWeight, const std::valarray< tUCInt > &elementsConnectedCellsNumber, const std::valarray< tIndex > &elementsConnectedCells, std::valarray< tReal > &cellsParticlesNumber)
build the number of particles within each cell
Definition: SM_NetworkGridBuilder.cpp:997
static tIndex GetCellsNumberInBlock(const std::array< tInteger, SM_Constants::DIM > &nCs, const tInteger *iBlocksNumber, const tInteger *iBlockIndex)
buid a block within a grid domain
Definition: SM_NetworkGridBuilder.h:177
static void GetConnectedDomainCellsToFace(const tDimension &d, const std::array< tDimension, SM_Constants::HDIM > &hyperplanBase, const tInteger *iFaceElementIndices, const std::array< tInteger, SM_Constants::DIM > &nCs, const std::array< tBoolean, SM_Constants::DIM > &isPeriodic, const tBoolean &incMask, const tMask *vMask, std::array< tInteger, SM_Constants::DIM > &connectedCellIndices, std::map< tIndex, tIndex > &connectedCells)
get the cells in domain and connected to face
Definition: SM_NetworkGridBuilder.cpp:508
static void GetCenterFacePoint(const tDimension &d, const std::array< tDimension, SM_Constants::HDIM > &hyperplanBase, const std::array< tInteger, SM_Constants::DIM > &faceElementIndices, std::array< tUCInt, SM_Constants::HDIM > &movesIndices, const std::array< tReal, SM_Constants::DIM > &X0, const std::array< tReal, SM_Constants::DIM > &H, std::array< tReal, SM_Constants::DIM > &P)
get the point located at center of element of d-surface whith faceElementIndices
Definition: SM_NetworkGridBuilder.cpp:90
static void BuildVerticesWeight(const std::array< tInteger, SM_Constants::DIM > &nCs, const std::array< tInteger, SM_Constants::DIM > &nPs, const std::array< tBoolean, SM_Constants::DIM > &isPeriodic, const std::valarray< tMask > &mask, tReal *iVerticesWeight, tUCInt *iConnectedCellsNumber, tIndex *iConnectedCells)
build the weight of vertex
Definition: SM_NetworkGridBuilder.cpp:839
static void GetConnectedDomainCellsToVertex(const std::array< tInteger, SM_Constants::DIM > &vertexIndices, const std::array< tInteger, SM_Constants::DIM > &Ns, const std::array< tBoolean, SM_Constants::DIM > &isPeriodic, const tBoolean &incMask, const tMask *vMask, std::array< tUCInt, SM_Constants::DIM > &moveIndices, std::array< tInteger, SM_Constants::DIM > &connectedCellIndices, std::map< tIndex, tIndex > &connectedCells)
get the cells in domain and connected to vertex
Definition: SM_NetworkGridBuilder.cpp:425
static tBoolean GetCenterFacePointInBlock(const tDimension &d, const std::array< tDimension, SM_Constants::HDIM > &hyperplanBase, const std::array< tInteger, SM_Constants::DIM > &faceElementIndices, const std::array< tReal, SM_Constants::DIM > &blockMinPoint, const std::array< tReal, SM_Constants::DIM > &blockMaxPoint, std::array< tUCInt, SM_Constants::HDIM > &moveIndices, const std::array< tReal, SM_Constants::DIM > &X0, const std::array< tReal, SM_Constants::DIM > &H, std::array< tReal, SM_Constants::DIM > &P)
return true if the point at center of face of the d-surface is in [blockMinPoint,blockMaxPoint[
Definition: SM_NetworkGridBuilder.cpp:150
static tBoolean IsPointInBlock(std::array< tInteger, SM_Constants::DIM > &I, const tReal *iBlockMinPoint, const tReal *iBlockMaxPoint, const tReal *iX0, const tReal *iHs, tReal *iP)
return true if the point P=X0+(I+0.5R).Hs is in [blockMinPoint,blockMaxPoint[
Definition: SM_NetworkGridBuilder.h:229
static void GetCellVertices(const std::array< tInteger, SM_Constants::DIM > &cellIndices, const std::array< tInteger, SM_Constants::DIM > &nPs, const std::array< tBoolean, SM_Constants::DIM > &isPeriodic, std::array< tUCInt, SM_Constants::DIM > &moveIndices, std::array< tInteger, SM_Constants::DIM > &vertexIndices, std::map< tIndex, tIndex > &vertices)
get the vertices at summit of cells
Definition: SM_NetworkGridBuilder.cpp:225
virtual ~SM_NetworkGridBuilder(void)
destroy
Definition: SM_NetworkGridBuilder.h:78
virtual tMemSize getMemorySize() const
return the memory size of the class and the memory size of all its attributes/associations
Definition: SM_NetworkGridBuilder.h:105
static tIndex BuildBlock(const std::array< tInteger, SM_Constants::DIM > &nCs, const tInteger *iBlocksNumber, const tInteger *iBlockIndex, const tReal &margin, const tReal *iX0, const tReal *iHs, tInteger *iI0, tInteger *iI1, tReal *iBlockMinPoint, tReal *iBlockMaxPoint)
buid a block within a grid domain
Definition: SM_NetworkGridBuilder.cpp:21
static void GetConnectedDomainFacesToFace(const tDimension &p, const std::array< tDimension, SM_Constants::HDIM > &pHyperplanBase, const tInteger *iFaceElementIndices, const tDimension &q, const std::array< tDimension, SM_Constants::HDIM > &qHyperplanBase, const std::array< tInteger, SM_Constants::DIM > &qFacesElementsNumber, const std::array< tInteger, SM_Constants::DIM > &nCs, const std::array< tBoolean, SM_Constants::DIM > &isPeriodic, const tBoolean &incMask, const tMask *vMask, std::array< tInteger, SM_Constants::DIM > &connectedCellIndices, tIndex &cellIndex, std::array< tInteger, SM_Constants::DIM > &connectedFaceIndices, std::map< tIndex, tIndex > &connectedFaces)
get the faces in q-surfaces domain and connected to face in p-surface
Definition: SM_NetworkGridBuilder.cpp:703
static void BuildFacesWeight(const tDimension &d, const std::array< tDimension, SM_Constants::HDIM > &hyperplanBase, const std::array< tInteger, SM_Constants::DIM > &nCs, const std::array< tInteger, SM_Constants::DIM > &nPs, const std::array< tBoolean, SM_Constants::DIM > &isPeriodic, const std::valarray< tMask > &mask, tReal *iFacesWeight, tUCInt *iConnectedCellsNumber, tIndex *iConnectedCells)
build the weight of vertex at center of faces
Definition: SM_NetworkGridBuilder.cpp:891
static void GetFaceVertices(const tDimension &d, const std::array< tDimension, SM_Constants::HDIM > &hyperplanBase, const std::array< tInteger, SM_Constants::DIM > faceElementIndices, const std::array< tInteger, SM_Constants::DIM > &nPs, const std::array< tBoolean, SM_Constants::DIM > &isPeriodic, std::array< tUCInt, SM_Constants::HDIM > &moveIndices, std::array< tInteger, SM_Constants::DIM > &vertexIndices, tIndex &vertexIndex, std::map< tIndex, tIndex > &vertices)
get the vertices at summit of face
Definition: SM_NetworkGridBuilder.cpp:289
SM_NetworkGridBuilder(void)
create a network class
Definition: SM_NetworkGridBuilder.h:55
static tBoolean IsFaceInDomain(const tDimension &d, const std::array< tDimension, SM_Constants::HDIM > &hyperplanBase, const tInteger *iFaceElementIndices, const std::array< tInteger, SM_Constants::DIM > &nCs, const std::array< tBoolean, SM_Constants::DIM > &isPeriodic, const tBoolean &incMask, const tMask *vMask, std::array< tInteger, SM_Constants::DIM > &connectedCellIndices)
return true if the face is in domain
Definition: SM_NetworkGridBuilder.cpp:361
static void GetConnectedDomainFacesToVertex(const std::array< tInteger, SM_Constants::DIM > &vertexIndices, const tDimension &d, const std::array< tDimension, SM_Constants::HDIM > &hyperplanBase, const std::array< tInteger, SM_Constants::DIM > &facesElementsNumber, const std::array< tInteger, SM_Constants::DIM > &nCs, const std::array< tBoolean, SM_Constants::DIM > &isPeriodic, const tBoolean &incMask, const tMask *vMask, std::array< tUCInt, SM_Constants::HDIM > &moveIndices, std::array< tInteger, SM_Constants::DIM > &cellIndices, tIndex &index, std::array< tInteger, SM_Constants::DIM > &faceElementIndices, std::map< tIndex, tIndex > &connectedFaces)
get the faces in domain and connected to vertex
Definition: SM_NetworkGridBuilder.cpp:580
static tUCInt N_HYPERPLAN_MOVES
number of moves per hyperplan
Definition: SM_NetworkGridBuilder.h:43
static tUCInt N_SPACE_MOVES
number of moves in space
Definition: SM_NetworkGridBuilder.h:46
static void GetPointWithIndices(std::array< tInteger, SM_Constants::DIM > &I, const tReal *iX0, const tReal *iHs, tReal *iP)
get the point with indices within the cell of indices I with relative position R in {0,...
Definition: SM_NetworkGridBuilder.h:293
static void BuildCellsWeight(const std::array< tInteger, SM_Constants::DIM > &nCs, const std::valarray< tMask > &mask, tReal *iCellsWeight, tUCInt *iConnectedCellsNumber, tIndex *iConnectedCells)
build the weight of vertex at center of cells
Definition: SM_NetworkGridBuilder.cpp:947
virtual tMemSize getContentsMemorySize() const
return the memory size of the included associations
Definition: SM_NetworkGridBuilder.h:117
static void BuildElementsVolume(const std::valarray< tReal > &elementsWeight, const std::valarray< tUCInt > &elementsConnectedCellsNumber, const std::valarray< tIndex > &elementsConnectedCells, const std::valarray< tReal > &cellsParticlesNumber, std::valarray< tReal > &elementsVolume)
build the volume of each element
Definition: SM_NetworkGridBuilder.cpp:1038