C++ mpi module for stochmagnet_main Package
SM_MacroCellsNetwork.h
1 #ifndef SM_MacroCellsNetwork_H
2 #define SM_MacroCellsNetwork_H
3 
4 //base classes
5 #include "SM_Object.h"
6 
7 //field header
8 #include "SM_Field.h"
9 
10 //network header
11 #include "SM_Network.h"
12 
13 
14 //material header
15 #include "SM_Material.h"
16 
25 class SM_MacroCellsNetwork : public virtual SM_Object {
26 
27 
28 public:
29 private :
30 
31  //type class
32  typedef SM_Object SuperClass;
34 
35  //single attributes
36  //-----------------
37 
38  //margin for building macro cells
39  tReal mMargin;
40 
41 
42  //multiple attributes
43  //------------------
44 
45  //number of macro cells
46  tInteger mMacroCellsNumber;
47 
48  //macro cell size in angstrom
49  std::array<tReal,SM_Constants::DIM> mMacroCellSize;
50 
51 
52  //macro cell index at particle p of size nParticles
53  //mMacroCellsList[p]=index of the macro cell m to which the particle p belongs to
54  std::valarray<tInteger> mMacroCellsList;
55 
56  //W[m] : macro cells Weight (of size nMacroCells) i the sum of the volume of the particles in macro cells
57  std::valarray<tReal> mMacroCellsVolume;
58 
59 
60  //single associations
61  //-------------------
62 
63  //mass center of the macro cell m of size nMacroCells x dim
64  SM_RealField mC;
65 
66  //multiple associations
67  //---------------------
68 
69 
70 
71 protected:
72  // CONSTRUCTORS
76  mMargin=0;
77  }
78 
79  // DESTRUCTORS
82  virtual ~SM_MacroCellsNetwork(void) {
83  }
84 
85 
86 public :
87 
88  //Instance building
89  //=================
90 
91 
105  virtual tMemSize getMemorySize() const {
106  return sizeof(*this)+this->getContentsMemorySize();
107  }
108 
117  virtual tMemSize getContentsMemorySize() const {
118  tMemSize mem=SuperClass::getContentsMemorySize();
119 
120  mem+=mMacroCellsList.size()*sizeof(tInteger);
121  mem+=mMacroCellSize.size()*sizeof(tReal);
122  mem+=mC.getContentsMemorySize();
123  mem+=mMacroCellsVolume.size()*sizeof(tReal);
124 
125  return mem;
126  }
127 public:
128 
132  virtual CORE_UniquePointer<SM_MacroCellsNetwork> newInstance() const=0;
133 
134  //Data settting
135  //=============
136 
140  inline void setMacroCellMargin(const tReal& w) {
141  mMargin=std::max(w,(tReal)1.e-12);
142  }
146  inline const tReal& getMacroCellMargin() const {
147  return mMargin;
148  }
149 
153  inline void setMacroCellSize(const std::array<tReal,SM_Constants::DIM>& H) {
154  mMacroCellSize=H;
155  }
159  inline void setMacroCellSize(const std::vector<tReal>& H) {
160  auto iH=H.cbegin();
161  const auto eH=H.cend();
162  for(auto& Hk:mMacroCellSize) {
163  if (iH!=eH) {
164  Hk=(*iH);
165  iH++;
166  } else {
167  Hk=1;
168  }
169  }
170  }
173  inline const std::array<tReal,SM_Constants::DIM>& getMacroCellSize() const {
174  return mMacroCellSize;
175  }
176  //set & get methods
177  //==================
178 
181  inline void setMacroCellsNumber(const tInteger& n) {
182  mMacroCellsNumber=n;
183  mC.setElementsNumber(n);
184  }
185 
188  inline const tInteger& getMacroCellsNumber() const {
189  return mMacroCellsNumber;
190  }
191 
192 
195  inline const SM_RealField& getMacroCellsMassCenter() const {
196  return mC;
197  }
198 
202  return mC;
203  }
204 
205 
208  inline const std::valarray<tInteger>& getMacroCellsList() const {
209  return mMacroCellsList;
210  }
213  inline std::valarray<tInteger>& getMacroCellsList() {
214  return mMacroCellsList;
215  }
218  inline const std::valarray<tReal>& getMacroCellsVolume() const {
219  return mMacroCellsVolume;
220  }
223  inline std::valarray<tReal>& getMacroCellsVolume() {
224  return mMacroCellsVolume;
225  }
229  inline const tReal& getMacroCellVolume(const tInteger& m) const {
230  return mMacroCellsVolume[m];
231  }
232 
233 
234 
235 
236 public:
237 
242  inline const tInteger& getMacroCellIndex(const tInteger& p) const {
243  return mMacroCellsList[p];
244  }
245 
246 
247  //discretize the network
248  //======================
249 public:
250 
251 public:
252 
253 
254  //Macro cells methods
255  //======================
256 
257 public:
262  virtual void computeMacroCells(const SM_Material& material,
263  const SM_Network& network) {
264 
265 
266  //get the min & max point of the bounding box of the network
267  const std::array<tReal,SM_Constants::DIM>& bbMinPoint=network.getBoundingBoxMinPoint();
268  std::array<tReal,SM_Constants::DIM> bbMaxPoint=network.getBoundingBoxSize();
269  functions_array::add(bbMaxPoint,bbMinPoint);
270  //compute the macro cells in the bounding box
271  computeBoundingBoxMacroCells(material,network,bbMinPoint,bbMaxPoint);
272  }
273 
274 protected:
283  virtual void computeBoundingBoxMacroCells(const SM_Material& material,
284  const SM_Network& network,
285  const std::array<tReal,SM_Constants::DIM>& P,
286  const std::array<tReal,SM_Constants::DIM>& Q);
287 public:
292  virtual void computeMacroCellsMassCenter(const SM_Material& material,
293  const SM_Network& network);
294 
295 
296 
297 
298 
299 
300 
301 
302 
303 protected:
304 
305 
306 
319  static tInteger ComputeMacroCells(const SM_Material& material,
320  const SM_Network& network,
321  const std::array<tReal,SM_Constants::DIM>& P,//min point of the domain
322  const std::array<tReal,SM_Constants::DIM>& Q,//max point of the domain
323  const std::array<tReal,SM_Constants::DIM>& macroCellSize,
324  const tReal& margin,
325  const tReal& epsVW,
326  std::valarray<tReal> & MCsVolume,//volume of the macro cells
327  std::valarray<tInteger>& macroCellsList);//local indices of macro cell per particle
328 
335  static void EliminateEmptyMacroCells(const tReal& epsVM,
336  std::valarray<tReal>& gMCVolume,
337  std::valarray<tReal>& lMCVolume,
338  std::valarray<tInteger>& gMCLocalIndices);
339 
347  static void BuildParticlesListOrderedPerMacroCells(const SM_Network& network,
348  const tInteger& nMacroCells,
349  const std::valarray<tInteger>& macroCellsPList,
350  std::valarray<tInteger>& particlesMCList,
351  std::valarray<tInteger>& particlesMCListOffset);
352 
357  inline static void ConvertIndices(const std::valarray<tInteger>& indicesConverter,
358  std::valarray<tInteger>& indicesList) {
359  for(auto& i:indicesList) {
360  i=indicesConverter[i];
361  }
362  }
368  inline static void ConvertIndices(const std::valarray<tInteger>& indicesConverter,
369  const tInteger& n,tInteger* iIndicesList) {
370  const tInteger *eIndicesList=iIndicesList;
371  eIndicesList+=n;
372  while (iIndicesList!=eIndicesList) {
373  (*iIndicesList)=indicesConverter[(*iIndicesList)];
374  iIndicesList++;
375  }
376  }
384  static void ComputeMacroCellX(const tInteger& nParticles,
385  const tReal* iX,
386  const tInteger* iMacroCellsList,
387  SM_RealField& C,
388  std::valarray<tInteger>& nMCParticles);
389 
395  inline static void MeanX(const tInteger& n,
396  const tInteger* iNs,
397  tReal *iX) {
398  //make the barycenter of center of mass
399 
400  //end iterator on mass center of not empty macro cells
401  const tReal *eX=iX;
402  eX+=n*SM_Constants::DIM;
403 
404  //end iterator on last coordinate of the mass center of not empty macro cells
405  const tReal *eX_d=iX;
406 
407  tReal f;//inverse of (*iNs)
408  while (iX!=eX) {//loop on particles
409  eX_d+=SM_Constants::DIM;
410 
411  //f=1/Ns
412  f=1;
413  f/=(*iNs);
414  //X[i]/=Ns
415  while (iX!=eX_d) {//mean value of the coordinates of the n particles
416  (*iX)*=f;
417  //iterator at next coordinate of the particle
418  iX++;
419  }
420  //iterators at next particles
421  iNs++;
422  }
423 
424 
425  }
426 
427 
428 
429 
430 
431 
432 
433  // String representation
434  // =======================
435 public:
436 
437 
440  virtual tString toString() const override {
441  std::stringstream ret;
442  ret<<SuperClass::toString()<<"\n";
443  ret<<"\t macro cell size:"<<functions_array::toString(mMacroCellSize)<<"\n";
444  ret<<"\t number of macro cells: "<<mC.getElementsNumber()<<"\n";
445  ret<<"\t margin of macro cells: "<<mMargin<<"\n";
446  ret<<"\t mass centers: C:\n";
447  tInteger s=mC.getElementsNumber()/10;
448  s=(s==0)?1:s;
449  for(tInteger i=0;i<mC.getElementsNumber();i+=s) {
450  ret<<"\t ["<<i<<"]="<<functions_array::toString(SM_Constants::DIM,mC(i))<<"\n";
451  }
452  //ret<<"\t macroCellsList :"<<functions_array::toString(mMacroCellsList)<<"\n";
453  //ret<<"\t particlesList :"<<functions_array::toString(mParticlesMCList)<<"\n";
454  //ret<<"\t particlesListOffset :"<<functions_array::toString(mParticlesMCListOffset)<<"\n";
455  return ret.str();
456  }
457 
458 private:
459  // void ComputeMacroCellsVBlock(const SM_Material& material,
460  // const std::array<tReal,SM_Constants::DIM>& P,//min point of the domain
461  // const std::array<tReal,SM_Constants::DIM>& Q,//max point of the domain
462  // const SM_Network& network,
463  // const tReal& eps,
464  // const std::array<tReal,SM_Constants::DIM>& Hmc,//size of the macro cells
465  // SM_RealField& C,//centers of the macro cell
466  // std::valarray<tInteger>& mcParticlesListOffset,
467  // std::valarray<tInteger>& mcParticlesList,
468  // std::valarray<tInteger>& macroCellsList);
469  // void ComputeMacroCellsVAMPIRE(const SM_Material& material,
470  // const std::array<tReal,SM_Constants::DIM>& P,//min point of the domain
471  // const std::array<tReal,SM_Constants::DIM>& Q,//max point of the domain
472  // const SM_Network& network,
473  // const tReal& eps,
474  // const std::array<tReal,SM_Constants::DIM>& Hmc,//size of the macro cells
475  // SM_RealField& C,//centers of the macro cell
476  // std::valarray<tInteger>& mcParticlesListOffset,
477  // std::valarray<tInteger>& mcParticlesList,
478  // std::valarray<tInteger>& macroCellsList);
479 
480 
481 };
482 
483 
484 #endif
virtual tMemSize getContentsMemorySize() const override
return the memory size of the included associations
Definition: CORE_Field.h:102
tIndex getElementsNumber() const
return the number values of the container
Definition: CORE_Field.h:135
void setElementsNumber(const tInteger &n)
set the number of element of the container
Definition: CORE_Field.h:121
virtual tMemSize getContentsMemorySize() const
return nthe memory size of the included associations
Definition: CORE_Object.h:278
virtual tString toString() const
return the string representation of the object node
Definition: CORE_Object.h:333
static constexpr tDimension DIM
space dimension
Definition: SM_Constants.h:80
This class is describes a macro cell network.
Definition: SM_MacroCellsNetwork.h:25
const tReal & getMacroCellVolume(const tInteger &m) const
get volume of macro cell at index m in Angstrom
Definition: SM_MacroCellsNetwork.h:229
const std::valarray< tInteger > & getMacroCellsList() const
get the index of macro cell containing each particle p
Definition: SM_MacroCellsNetwork.h:208
static void EliminateEmptyMacroCells(const tReal &epsVM, std::valarray< tReal > &gMCVolume, std::valarray< tReal > &lMCVolume, std::valarray< tInteger > &gMCLocalIndices)
eliminate empty macro cells form lists
Definition: SM_MacroCellsNetwork.cpp:195
SM_MacroCellsNetwork(void)
create a network class
Definition: SM_MacroCellsNetwork.h:75
static tInteger ComputeMacroCells(const SM_Material &material, const SM_Network &network, const std::array< tReal, SM_Constants::DIM > &P, const std::array< tReal, SM_Constants::DIM > &Q, const std::array< tReal, SM_Constants::DIM > &macroCellSize, const tReal &margin, const tReal &epsVW, std::valarray< tReal > &MCsVolume, std::valarray< tInteger > &macroCellsList)
compute the macro cells points and magnetization
Definition: SM_MacroCellsNetwork.cpp:64
std::valarray< tReal > & getMacroCellsVolume()
get volume of macro cells in Angstrom
Definition: SM_MacroCellsNetwork.h:223
void setMacroCellSize(const std::vector< tReal > &H)
set the macro cell size in angstrom
Definition: SM_MacroCellsNetwork.h:159
virtual void computeBoundingBoxMacroCells(const SM_Material &material, const SM_Network &network, const std::array< tReal, SM_Constants::DIM > &P, const std::array< tReal, SM_Constants::DIM > &Q)
compute the macro cells of the network
Definition: SM_MacroCellsNetwork.cpp:6
void setMacroCellSize(const std::array< tReal, SM_Constants::DIM > &H)
set the macro cell size in angstrom
Definition: SM_MacroCellsNetwork.h:153
static void BuildParticlesListOrderedPerMacroCells(const SM_Network &network, const tInteger &nMacroCells, const std::valarray< tInteger > &macroCellsPList, std::valarray< tInteger > &particlesMCList, std::valarray< tInteger > &particlesMCListOffset)
build the particles list for all not empty macro cells
Definition: SM_MacroCellsNetwork.cpp:256
const tInteger & getMacroCellsNumber() const
get the number of macro cells
Definition: SM_MacroCellsNetwork.h:188
virtual tMemSize getContentsMemorySize() const
return the memory size of the included associations
Definition: SM_MacroCellsNetwork.h:117
SM_RealField & getMacroCellsMassCenter()
get the mass center of the macro cells for writing
Definition: SM_MacroCellsNetwork.h:201
const std::array< tReal, SM_Constants::DIM > & getMacroCellSize() const
get the macro cell size
Definition: SM_MacroCellsNetwork.h:173
const std::valarray< tReal > & getMacroCellsVolume() const
get volume of macro cells in Angstrom
Definition: SM_MacroCellsNetwork.h:218
virtual tMemSize getMemorySize() const
return the memory size of the class and the memory size of all its attributes/associations
Definition: SM_MacroCellsNetwork.h:105
static void ComputeMacroCellX(const tInteger &nParticles, const tReal *iX, const tInteger *iMacroCellsList, SM_RealField &C, std::valarray< tInteger > &nMCParticles)
compute the sum of coordinantes of the particles in each macro cell
Definition: SM_MacroCellsNetwork.cpp:313
std::valarray< tInteger > & getMacroCellsList()
get the index of macro cell containing each particle p
Definition: SM_MacroCellsNetwork.h:213
static void ConvertIndices(const std::valarray< tInteger > &indicesConverter, const tInteger &n, tInteger *iIndicesList)
convert indices
Definition: SM_MacroCellsNetwork.h:368
virtual CORE_UniquePointer< SM_MacroCellsNetwork > newInstance() const =0
create a New instance of this
void setMacroCellsNumber(const tInteger &n)
set the number of macro cells
Definition: SM_MacroCellsNetwork.h:181
const tInteger & getMacroCellIndex(const tInteger &p) const
get the local index of the macro cell containing particle p
Definition: SM_MacroCellsNetwork.h:242
virtual ~SM_MacroCellsNetwork(void)
destroy
Definition: SM_MacroCellsNetwork.h:82
virtual tString toString() const override
return string representaton of the operator
Definition: SM_MacroCellsNetwork.h:440
virtual void computeMacroCellsMassCenter(const SM_Material &material, const SM_Network &network)
compute the macro cells of the network
Definition: SM_MacroCellsNetwork.cpp:47
const tReal & getMacroCellMargin() const
get margin
Definition: SM_MacroCellsNetwork.h:146
virtual void computeMacroCells(const SM_Material &material, const SM_Network &network)
compute the macro cells of the network
Definition: SM_MacroCellsNetwork.h:262
void setMacroCellMargin(const tReal &w)
set margin
Definition: SM_MacroCellsNetwork.h:140
static void MeanX(const tInteger &n, const tInteger *iNs, tReal *iX)
compute the macro cells points and magnetization
Definition: SM_MacroCellsNetwork.h:395
const SM_RealField & getMacroCellsMassCenter() const
get the mass center of the macro cells for reading
Definition: SM_MacroCellsNetwork.h:195
static void ConvertIndices(const std::valarray< tInteger > &indicesConverter, std::valarray< tInteger > &indicesList)
convert indices
Definition: SM_MacroCellsNetwork.h:357
This class describes a materials defined by state attributes:
Definition: SM_Material.h:61
This class is describes a network composed by.
Definition: SM_Network.h:66
const std::array< tReal, SM_Constants::DIM > & getBoundingBoxMinPoint() const
get the min point of the boudning box
Definition: SM_Network.h:629
const std::array< tReal, SM_Constants::DIM > & getBoundingBoxSize() const
get the size of the boudning box
Definition: SM_Network.h:635
This class is a base class for Stoch Microm package.
Definition: SM_Object.h:36