C++ mpi module for stochmagnet_main Package
SM_VTK.h
1 #ifndef SM_VTK_H
2 #define SM_VTK_H
3 
4 //base header class
5 #include "CORE_Object.h"
6 
7 //LL system header
8 #include "SM_System.h"
9 //network header
10 #include "SM_Network.h"
11 
20 template<class VTK_Impl>
21 class SM_VTK : public SM_Object {
22 
23  // ATTRIBUTES
24 public:
27  static const tFlag CELL;
30  static const tFlag POINT;
31 
32 
33 private:
34 
35  //the absolute file name without extension
36  tString mFileName;
37 
38 
39  //cell data
40  std::vector<tString> mScalarFieldOnCellNames;//scalar field on cell
41  std::vector<tString> mVectorFieldOnCellNames;//vector field on cell
42 
43  //point data
44  std::vector<tString> mScalarFieldOnPointNames;//scalar field on point
45  std::vector<tString> mVectorFieldOnPointNames;//vector field on point
46 
47  //indicates if the fiel is opened
48  tBoolean mIsFileOpened;
49 public:
50  // METHODS
51 
52  // CONSTRUCTORS
53 
56  SM_VTK(void) {
57  mIsFileOpened=false;
58  mFileName="";
59  }
60 
61 
62 
63  // DESTRUCTORS
64 
65 
68  virtual ~SM_VTK(void) {
69  }
70 
71 
72 
73 public:
74 
75  //MEMORY
76 
90  virtual tMemSize getMemorySize() const {
91  return sizeof(*this)+getContentsMemorySize();
92  }
93 
102  virtual tMemSize getContentsMemorySize() const {
103  tMemSize mem=SM_Object::getContentsMemorySize();
104  mem+=mFileName.size();
105  for(const auto& name: mScalarFieldOnPointNames) mem+=name.size()*sizeof(unsigned char);
106  for(const auto& name: mScalarFieldOnCellNames) mem+=name.size()*sizeof(unsigned char);
107  for(const auto& name: mVectorFieldOnPointNames) mem+=name.size()*sizeof(unsigned char);
108  for(const auto& name: mVectorFieldOnCellNames) mem+=name.size()*sizeof(unsigned char);
109  return mem;
110 
111  }
112 
121  template<class T>
122  tString getVTKType() const {
123  return getVTKType(functions_type::getTypeName<T>());
124  }
140  tString getVTKType(const tString& typeName) const;
141 
142 
146  inline void setFileName(const tString& fn) {
147  tIndex iPt=fn.rfind(".");
148  if (iPt!=tString::npos) {
149  mFileName=fn.substr(0,iPt);
150  }else {
151  mFileName=fn;
152  }
153  }
154 
158  inline const tString& getFileName() const {
159  return mFileName;
160  }
161 
167  inline void setFields(const tUCInt& dim,
168  const tFlag& support,
169  const std::vector<tString>& names) {
170  switch(dim) {
171  case 1:
172  switch(support) {
173  case POINT:
174  mScalarFieldOnPointNames.clear();
175  for(const auto& name : names) {
176  mScalarFieldOnPointNames.push_back(name);
177  }
178  break;
179  case CELL:
180  mScalarFieldOnCellNames.clear();
181  for(const auto& name : names) {
182  mScalarFieldOnCellNames.push_back(name);
183  }
184  break;
185  }
186  break;
187  default:
188  switch(support) {
189  case POINT:
190  mVectorFieldOnPointNames.clear();
191  for(const auto& name : names) {
192  mVectorFieldOnPointNames.push_back(name);
193  }
194  break;
195  case CELL:
196  mVectorFieldOnCellNames.clear();
197  for(const auto& name : names) {
198  mVectorFieldOnCellNames.push_back(name);
199  }
200  break;
201  }
202  }
203  }
204 
205 
206 
207 
210  inline const tBoolean& isFileOpened() const {
211  return mIsFileOpened;
212  }
213 
214 protected:
217  inline void setIsFileOpened(const tBoolean& v) {
218  mIsFileOpened=v;
219  }
220 
221 public:
222 
228  inline tBoolean save(const SM_Network& network,const tIndex& it,const tReal& time) {
229  tBoolean ok=true;
230  if (mIsFileOpened) {
231  ok=ok && open(it);
232  //write the geometry header
233  ok=ok && writeGeometryHeader(it,network);
234  //write the network
235  ok=ok && writeGeometryData(it,network);
236  //write the header of point data
237  ok=ok && writeContentHeader(it,POINT,mScalarFieldOnPointNames,mVectorFieldOnPointNames);
238 
239  //wrtite the footer of point data
240  ok=ok && writeContentFooter(it,POINT);
241 
242  //write the header of cell data
243  ok=ok && writeContentHeader(it,CELL,mScalarFieldOnCellNames,mVectorFieldOnCellNames);
244  //no cell data to write
245  //write the footer of cell data
246  ok=ok && writeContentFooter(it,CELL);
247 
248  //write the footer of the geometry
249  ok=ok && writeGeometryFooter(it);
250 
251  //clse for writing the time step
252  ok=ok && close(it);
253  }
254  return ok;
255 
256 
257  }
258 
264  inline tBoolean save(const SM_System& system,const tIndex& it,const tReal& time) {
265  return save(system.getNetwork(),"S",1,system.getMagneticMomentDirections(),it,time);
266  }
274  inline tBoolean save(const tString& vtkFileName,
275  const SM_Network& network,
276  const tString& Sname,const tReal& alpha,SM_RealField& S) {
277  tBoolean ok=true;
278  setFileName(vtkFileName);
279  setFields(3,POINT,{Sname});
280  ok=ok && open();
281  ok=ok && save(network,Sname,alpha,S,0,0);
282  ok=ok & close();
283  return ok;
284  }
285 
294  inline tBoolean save(const SM_Network& network,const tString& Sname,const tReal& alpha,
295  const SM_RealField& S,const tIndex& it,const tReal& time) {
296  tBoolean ok=true;
297  if (mIsFileOpened) {
298  ok=ok && open(it);
299  //write the geometry header
300  ok=ok && writeGeometryHeader(it,network);
301  //write the network
302  ok=ok && writeGeometryData(it,network);
303  //write the header of point data
304  ok=ok && writeContentHeader(it,POINT,mScalarFieldOnPointNames,mVectorFieldOnPointNames);
305  //write magnetic moment
306  ok=ok && writeContentData(time,
307  network,
308  POINT,
309  Sname,alpha,
310  S.getValues());
311 
312  //wrtite the footer of point data
313  ok=ok && writeContentFooter(it,POINT);
314 
315  //write the header of cell data
316  ok=ok && writeContentHeader(it,CELL,mScalarFieldOnCellNames,mVectorFieldOnCellNames);
317  //no cell data to write
318  //write the footer of cell data
319  ok=ok && writeContentFooter(it,CELL);
320 
321  //write the footer of the geometry
322  ok=ok && writeGeometryFooter(it);
323 
324  //clse for writing the time step
325  ok=ok && close(it);
326  }
327  return ok;
328 
329 
330  }
331  //Virtual templated classes for writing VTK files
332  //=================================================
333 
334 public:
338  inline tBoolean open() {
339  return static_cast<VTK_Impl*>(this)->open();
340  }
341 
346  inline tBoolean open(const tIndex& t) {
347  return static_cast<VTK_Impl*>(this)->open(t);
348  }
349 
355  inline tBoolean writeGeometryHeader(const tIndex& t,const SM_Network& network) {
356  return static_cast<VTK_Impl*>(this)->writeGeometryHeader(t,network);
357  }
358 
364  inline tBoolean writeGeometryData(const tIndex& t,const SM_Network& network) {
365  return static_cast<VTK_Impl*>(this)->writeGeometryData(t,network);
366  }
367 
375  inline tBoolean writeContentHeader(const tIndex& t,
376  const tFlag& support,
377  const std::vector<tString>& scalarNames,
378  const std::vector<tString>& vectorNames) {
379  return static_cast<VTK_Impl*>(this)->writeContentHeader(t,support,scalarNames,vectorNames);
380  }
381 
392  inline tBoolean writeContentData(const tReal& t,
393  const SM_Network& network,
394  const tFlag& support,
395  const tString& name,const tReal& alpha,
396  const tReal* f) {
397  return static_cast<VTK_Impl*>(this)->writeContentData(t,network,support,name,alpha,f);
398  }
399 
405  inline tBoolean writeContentFooter(const tIndex& t,const tFlag& support) {
406  return static_cast<VTK_Impl*>(this)->writeContentFooter(t,support);
407  }
408 
409 
414  inline tBoolean writeGeometryFooter(const tIndex& t) {
415  return static_cast<VTK_Impl*>(this)->writeGeometryFooter(t);
416  }
417 
422  inline tBoolean close(const tIndex& t) {
423  return static_cast<VTK_Impl*>(this)->close(t);
424  }
425 
429  inline tBoolean close() {
430  return static_cast<VTK_Impl*>(this)->close();
431  }
432 
433 };
434 
435 #include "SM_VTK.hpp"
436 
437 #endif
const T * getValues() const
get the values of the array for reading
Definition: CORE_Field.h:323
virtual tMemSize getContentsMemorySize() const
return nthe memory size of the included associations
Definition: CORE_Object.h:278
This class is describes a network composed by.
Definition: SM_Network.h:66
This class is a base class for Stoch Microm package.
Definition: SM_Object.h:36
This class is a one simulation of a beam for Stoch Magnet package.
Definition: SM_System.h:53
const SM_RealField & getMagneticMomentDirections() const
get the unit direction of spins at time
Definition: SM_System.h:267
const SM_Network & getNetwork() const
get the network
Definition: SM_System.h:170
This class is a beam output interface for VTK / Paraview software.
Definition: SM_VTK.h:21
tBoolean writeContentHeader(const tIndex &t, const tFlag &support, const std::vector< tString > &scalarNames, const std::vector< tString > &vectorNames)
write a content header
Definition: SM_VTK.h:375
tString getVTKType() const
return the VTK type of the template Type
Definition: SM_VTK.h:122
tBoolean writeGeometryHeader(const tIndex &t, const SM_Network &network)
write the geometry header corresponding to the network
Definition: SM_VTK.h:355
void setFileName(const tString &fn)
set the file name without extension
Definition: SM_VTK.h:146
tBoolean save(const tString &vtkFileName, const SM_Network &network, const tString &Sname, const tReal &alpha, SM_RealField &S)
save the system at time
Definition: SM_VTK.h:274
const tString & getFileName() const
get the file name without extension
Definition: SM_VTK.h:158
tBoolean writeContentFooter(const tIndex &t, const tFlag &support)
write a content footer
Definition: SM_VTK.h:405
virtual tMemSize getMemorySize() const
return the memory size of the class and the memory size of all its attributes/associations
Definition: SM_VTK.h:90
tBoolean writeGeometryData(const tIndex &t, const SM_Network &network)
write the geometry data of the network
Definition: SM_VTK.h:364
tBoolean writeGeometryFooter(const tIndex &t)
write the geometry footer
Definition: SM_VTK.h:414
tBoolean open()
open the vtkfile
Definition: SM_VTK.h:338
void setFields(const tUCInt &dim, const tFlag &support, const std::vector< tString > &names)
initialize fields
Definition: SM_VTK.h:167
virtual tMemSize getContentsMemorySize() const
return the memory size of the included associations
Definition: SM_VTK.h:102
tBoolean close()
close the file
Definition: SM_VTK.h:429
tBoolean save(const SM_Network &network, const tString &Sname, const tReal &alpha, const SM_RealField &S, const tIndex &it, const tReal &time)
save the system at time
Definition: SM_VTK.h:294
virtual ~SM_VTK(void)
destroy
Definition: SM_VTK.h:68
tBoolean writeContentData(const tReal &t, const SM_Network &network, const tFlag &support, const tString &name, const tReal &alpha, const tReal *f)
write a content data
Definition: SM_VTK.h:392
static const tFlag POINT
point tag
Definition: SM_VTK.h:30
tBoolean close(const tIndex &t)
close the file for the time step t
Definition: SM_VTK.h:422
void setIsFileOpened(const tBoolean &v)
set true is the file is opened
Definition: SM_VTK.h:217
static const tFlag CELL
cell tag
Definition: SM_VTK.h:27
const tBoolean & isFileOpened() const
return true if the file is open
Definition: SM_VTK.h:210
tBoolean open(const tIndex &t)
open the vtk field for writing or appending at the time step
Definition: SM_VTK.h:346
tBoolean save(const SM_Network &network, const tIndex &it, const tReal &time)
save the system at time
Definition: SM_VTK.h:228
tBoolean save(const SM_System &system, const tIndex &it, const tReal &time)
save the system at time
Definition: SM_VTK.h:264
SM_VTK(void)
create
Definition: SM_VTK.h:56