C++ mpi module for stochmagnet_main Package
SM_StochasticXDMF.h
1 #ifndef SM_StochasticXDMF_H
2 #define SM_StochasticXDMF_H
3 
4 //stochastic data
5 #include "SM_StochasticOutput.h"
6 
7 //system data
8 #include "SM_LandauLifschitzSystem.h"
9 
10 //XDMF header
11 #include "SM_XDMF.h"
12 
13 
21 class SM_StochasticXDMF : public SM_StochasticOutput<SM_StochasticXDMF> {
22 
23  // ATTRIBUTES
24 
25 public:
26 
27 
28 
29 private:
30 
31  //type class
34 
35  //index of simulations to save
36  std::vector<tIndex> mSimulations;
37  std::vector<tIndex>::const_iterator mISimulation;
38  tRelativeInteger mLastTimeIndexSaved;
39 
40 
41  //vtk file
42  SM_XDMF mVTK;
43 
44 
45 
46 
47 public:
48  // METHODS
49 
50  // CONSTRUCTORS
51 
55 
56  //plot only first simulation by default
57  mSimulations.resize(1);
58  mSimulations[0]=0;
59  mLastTimeIndexSaved=-1;
60  }
61 
62 
63 
64  // DESTRUCTORS
65 public:
66 
69  virtual ~SM_StochasticXDMF(void) {
70  }
71 
72 
73 
74 public:
75  //MEMORY
76 
90  virtual tMemSize getMemorySize() const {
91  return sizeof(*this)+getContentsMemorySize();
92  }
93 
102  virtual tMemSize getContentsMemorySize() const {
104  mem+=mSimulations.size()*sizeof(tIndex);
105  mem+=mVTK.getContentsMemorySize();
106  return mem;
107  }
108 
112  inline static CORE_UniquePointer<SM_StochasticXDMF> New() {
113  return CORE_UniquePointer<SM_StochasticXDMF>(new SM_StochasticXDMF(),SM_StochasticXDMF::Delete());
114  }
118  inline static CORE_UniquePointer<SM_StochasticXDMF> New(const SM_StochasticXDMF& c) {
119  CORE_UniquePointer<SM_StochasticXDMF> p=New();
120  p->copy(c);
121  return p;
122  }
123  //SET & GET Methods
124  //=================
128  virtual void copy(const SM_StochasticOutputComponent& c) override {
130  const SM_StochasticXDMF *cc=dynamic_cast<const SM_StochasticXDMF*>(&c);
131  if (cc!=null) setSimulations(cc->getSimulations());
132  }
133 
134 
138  inline void setSimulations(std::initializer_list<tIndex>&& simulationIndices) {
139  mSimulations=simulationIndices;
140  }
144  inline void setSimulations(const std::vector<tIndex>& simulationIndices) {
145  mSimulations=simulationIndices;
146  }
147 
148 
151  inline const std::vector<tIndex>& getSimulations() const {
152  return mSimulations;
153  }
154 
155 
159  virtual void adimensionize(const SM_Material& material) override {
160  }
161 public:
162 
163  //implemented templated methods
164  //=============================
168  inline tBoolean open(const SM_Beam& beam) {
169  //sort the index of simulation
170  std::sort(mSimulations.begin(),mSimulations.end());
171  mISimulation=mSimulations.begin();
172  return (dynamic_cast< const SM_LandauLifschitzSystem *>(&beam.getSystem())!=null);
173  }
174 
179  inline tBoolean open(const tIndex& s,const SM_System& system) {
181  tBoolean ok=true;
182  while (mISimulation!=mSimulations.end()) {//loop on simulations index
183  if (s<(*mISimulation)) {
184  break;//simulations is not saved
185  }
186  if (s==(*mISimulation)) {
187  //save the simulation
188  if (getRootIndex()==-1) {
189  //save the S state for each stochastic output
191  "-s"+std::to_string(s)+
192  "_c"+std::to_string(getIndex())+
193  +"p"+std::to_string(getIndicesNumber()))+".xmf");
194 
195  //std::cout<<"open vtk file : "<<mVTK.getFileName()<<"\n";
196  ok=ok && mVTK.open();
197  mLastTimeIndexSaved=0;
198  mVTK.save(system,mLastTimeIndexSaved,0.0);
199  mLastTimeIndexSaved=-1;
200 
201  }
202  else if (getIndex()==getRootIndex()) {
203  //save the S only for root index stochastic output
205  "-s"+std::to_string(s)));
206  ok=ok && mVTK.open();
207  mLastTimeIndexSaved=0;
208  mVTK.save(system,mLastTimeIndexSaved,0.0);
209  }
210  break;
211  }
212 
213  //next simulation
214  mISimulation++;
215  }
216  return ok;
217  }
218 
219 
220 
224  inline tBoolean store(const SM_System& system) {
225  //write mu at time step i
226  if (mVTK.isFileOpened()) {
227  const SM_LandauLifschitzSystem *llSystem=dynamic_cast< const SM_LandauLifschitzSystem *>(&system);
228  if (((tRelativeInteger)llSystem->getTimeIndex())!=mLastTimeIndexSaved) {
229  mLastTimeIndexSaved=llSystem->getTimeIndex();
230  mVTK.save(*llSystem,mLastTimeIndexSaved,llSystem->getTime());
231  }
232  }
233  return true;
234  }
240  inline tBoolean close(const tIndex& s,const SM_System& system,const tBoolean& hasSucceeded) {
241 
242  if (mVTK.isFileOpened()) {
243  return mVTK.close();
244  }
245  return true;
246  }
250  inline tBoolean close(const SM_Beam& beam) {
251  return true;
252  }
253 
254 
261  virtual void closePackedSimulations(const SM_Beam& beam,
262  const tIndex& rawValuesNumber,
263  const std::valarray<tReal>& rawValues) override {
264 
265 
266  }
267 
268 
269 
270 public:
271  // OTHERS methods
272 
273 
274 
275 
276 };
277 
278 #endif
static tString GetAbsolutePath(const tString &path)
get the absolute path of the path
Definition: CORE_IO.h:365
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:113
This class defines a general stochastic beam of trajectories of system.
Definition: SM_Beam.h:61
const SM_System & getSystem() const
get the system
Definition: SM_Beam.h:264
This class is a simulation of one trajectory class for Stoch Magnet package.
Definition: SM_LandauLifschitzSystem.h:59
const tIndex & getTimeIndex() const
get the time index
Definition: SM_LandauLifschitzSystem.h:221
const tReal & getTime() const
get the time
Definition: SM_LandauLifschitzSystem.h:214
This class describes a materials defined by state attributes:
Definition: SM_Material.h:61
This class stores stochastic outpus computed for each trajectory of a simulation of trajectories of a...
Definition: SM_StochasticOutputComponent.h:36
const int & getRootIndex() const
get the root index of the output component
Definition: SM_StochasticOutputComponent.h:222
const tString & getPrefix() const
return the prefix
Definition: SM_StochasticOutputComponent.h:190
const int & getIndex() const
get the index of the output component
Definition: SM_StochasticOutputComponent.h:217
const tString & getOutputPath() const
return the output path
Definition: SM_StochasticOutputComponent.h:178
const int & getIndicesNumber() const
get the number of output components
Definition: SM_StochasticOutputComponent.h:227
this class implements the virtual methods of its base class SM_StochasticOutputComponent with templat...
Definition: SM_StochasticOutput.h:24
virtual tMemSize getContentsMemorySize() const
return the memory size of the included associations
Definition: SM_StochasticOutput.h:84
virtual void copy(const SM_StochasticOutputComponent &c)
copy
Definition: SM_StochasticOutput.h:94
This class stores stochastic 3D trajectory For each point of the network it stores at any time Mu(t,...
Definition: SM_StochasticXDMF.h:21
virtual void copy(const SM_StochasticOutputComponent &c) override
copy the stochastic data
Definition: SM_StochasticXDMF.h:128
tBoolean open(const tIndex &s, const SM_System &system)
open the stochastic data for simulation s
Definition: SM_StochasticXDMF.h:179
void setSimulations(std::initializer_list< tIndex > &&simulationIndices)
set the simulations index to save
Definition: SM_StochasticXDMF.h:138
virtual tMemSize getMemorySize() const
return the memory size of the class and the memory size of all its attributes/associations
Definition: SM_StochasticXDMF.h:90
void setSimulations(const std::vector< tIndex > &simulationIndices)
set the simulations index to save
Definition: SM_StochasticXDMF.h:144
tBoolean close(const tIndex &s, const SM_System &system, const tBoolean &hasSucceeded)
close the stochastic data for the simulation s
Definition: SM_StochasticXDMF.h:240
virtual ~SM_StochasticXDMF(void)
destroy
Definition: SM_StochasticXDMF.h:69
tBoolean store(const SM_System &system)
store the stochastic data during the relation method of the system
Definition: SM_StochasticXDMF.h:224
static CORE_UniquePointer< SM_StochasticXDMF > New()
build a new instance of a stochastic data
Definition: SM_StochasticXDMF.h:112
tBoolean open(const SM_Beam &beam)
open the stochastic data
Definition: SM_StochasticXDMF.h:168
virtual void closePackedSimulations(const SM_Beam &beam, const tIndex &rawValuesNumber, const std::valarray< tReal > &rawValues) override
close stochastic data at the end of all packed simulations
Definition: SM_StochasticXDMF.h:261
SM_StochasticXDMF(void)
create
Definition: SM_StochasticXDMF.h:54
tBoolean close(const SM_Beam &beam)
close stochastic data at the end of all simulations
Definition: SM_StochasticXDMF.h:250
virtual tMemSize getContentsMemorySize() const
return the memory size of the included associations
Definition: SM_StochasticXDMF.h:102
static CORE_UniquePointer< SM_StochasticXDMF > New(const SM_StochasticXDMF &c)
build a new instance of a stochastic data
Definition: SM_StochasticXDMF.h:118
virtual void adimensionize(const SM_Material &material) override
adimensionize the output compoent with material characteristic
Definition: SM_StochasticXDMF.h:159
const std::vector< tIndex > & getSimulations() const
get the simulations
Definition: SM_StochasticXDMF.h:151
This class is a one simulation of a beam for Stoch Magnet package.
Definition: SM_System.h:53
void setFileName(const tString &fn)
set the file name without extension
Definition: SM_VTK.h:146
const tBoolean & isFileOpened() const
return true if the file is open
Definition: SM_VTK.h:210
tBoolean save(const SM_Network &network, const tIndex &it, const tReal &time)
save the system at time
Definition: SM_VTK.h:228
This class is a beam interface output for XMF format for paraview visualization software.
Definition: SM_XDMF.h:22
virtual tMemSize getContentsMemorySize() const
return the memory size of the included associations
Definition: SM_XDMF.h:112
tBoolean close(const tIndex &t)
close the file for the time step t
Definition: SM_XDMF.h:337
tBoolean open()
open the vtkfile
Definition: SM_XDMF.h:161