C++ mpi module for stochmagnet_main Package
SM_XDMF.h
1 #ifndef SM_XDMF_H
2 #define SM_XDMF_H
3 
4 
5 //constants header
6 #include "SM_Constants.h"
7 
8 //base class header
9 #include "SM_VTK.h"
10 
11 //file header
12 #include "CORE_OutputFile.h"
13 
14 
22 class SM_XDMF : public SM_VTK<SM_XDMF> {
23 
24  // ATTRIBUTES
25 
26 public:
29  static const tFlag XML;
32  static const tFlag HDF;
33 
34 
35 private:
36  static const tString FILE_TYPES[];
37 
38  // the format of the data
39  tFlag mFormat;
40  tString mName;
41  tString mExternalFileName;
42 
43 
44  //output stream
45  CORE_UniquePointer<CORE_OutputFile> mFile;
46 
47 
48 public:
49  // METHODS
50 
51  // CONSTRUCTORS
52 
55  SM_XDMF(void);
56 
57 
58 
59  // DESTRUCTORS
60 
61 
64  virtual ~SM_XDMF(void);
65 
66 
67 
68 public:
72  inline static CORE_UniquePointer<SM_XDMF> New() {
73  return CORE_UniquePointer<SM_XDMF>(new SM_XDMF(),SM_XDMF::Delete());
74  };
79  inline static CORE_UniquePointer<SM_XDMF> New(const tFlag& format) {
80  CORE_UniquePointer<SM_XDMF> p=New();
81  p->setFormat(format);
82  return p;
83  };
84 
85  //MEMORY
86 
100  virtual tMemSize getMemorySize() const {
101  return sizeof(*this)+getContentsMemorySize();
102  }
103 
112  virtual tMemSize getContentsMemorySize() const {
113  tMemSize mem=SM_VTK::getContentsMemorySize();
114  mem+=mName.size();
115  mem+=mExternalFileName.size();
116  mem+=(mFile.get()==null)?0:mFile->getContentsMemorySize();
117  return mem;
118 
119  }
120 
121 
122  //set & get methods
123  //==================
124 public:
128  inline void setExternalFileName(const tString& f) {
129  mExternalFileName=f;
130  }
131 
135  inline void setFormat(const tFlag& f) {
136  mFormat=f;
137  }
138 
139 
143  inline const tFlag& getFormat() const {
144  return mFormat;
145  }
149  inline const tString& getExternalFileName() const {
150  return mExternalFileName;
151  }
152 
153 
154 
155  //Virtual templated classes for writing VTK files
156  //=================================================
157 public:
161  inline tBoolean open() {
162  //get the file name
163  tString fileName=getFileName();
164  //set the extension
165  tString xdmfFile=fileName+".xmf";
166 
167  //open the file
168  if (!mFile->open(xdmfFile)) return false;
169 
170  //file is open
171  setIsFileOpened(true);
172 
173  //get the file
174  CORE_OutputFile &f=*mFile.get();
175 
176  //write the header
177  f<<"<?xml version=\"1.0\" encoding=\"utf-8\"?>"<<"\n";
178  f<<"<Xdmf xmlns:xi=\"http://www.w3.org/2001/XInclude\" Version=\"3.3\">"<<"\n";
179  f<<"\t<Domain>"<<"\n";
180  f<<"\t\t<Grid CollectionType=\"Temporal\" GridType=\"Collection\" Name=\"Collection\">"<<"\n";
181 
182 
183  return true;
184  }
185 
186 
191  inline tBoolean open(const tIndex& t){
192 
193  return true;
194  }
195 
196 
202  inline tBoolean writeGeometryHeader(const tIndex& it,const SM_Network& network) {
203  tBoolean succeeds=true;
204  //write the connectivity of the mesh
205  if (it==0) {
206  //get the file
207  CORE_OutputFile &f=*mFile.get();
208 
209  tString tab="\t\t\t";
210 
211  //write the number of cellules
212 
213  //compute the number of particles without connection
214  tIndex nAloneParticles=network.computeAloneParticlesNumber();
215 
216 
217  f<<tab<<"<Topology name=\"topology\" Dimensions=\""<<nAloneParticles+network.getHaloParticlesNumber()+ network.getNeighboringParticlesList().size()<<"\" Type=\"Mixed\">"<<"\n";
218  //write the connectivity
219  succeeds = succeeds && WriteConnectivity(f,
220  mFormat,getExternalFileName(),
221  nAloneParticles,network.getHaloParticlesNumber(),
223  network.getNeighboringParticlesList(),"");
224  f<<tab<<"</Topology>"<<"\n";
225  }
226  return succeeds;
227  }
228 
234  inline tBoolean writeGeometryData(const tIndex& t,const SM_Network& network) {
235 
236  tBoolean succeeds=true;
237 
238  if (t==0) {
239  //get the file
240  CORE_OutputFile &f=*mFile.get();
241 
242  tString tab="\t\t\t";
243  f<<tab<<"<Geometry name=\"geometry\" Type=\"XYZ\">"<<"\n";
244  succeeds = succeeds && WriteVertices(f,mFormat,getExternalFileName(),network,"");
245  f<<tab<<"</Geometry>"<<"\n";
246  }
247  return succeeds;
248 
249  }
250 
258  inline tBoolean writeContentHeader(const tIndex& t,
259  const tFlag& support,
260  const std::vector<tString>& scalarNames,
261  const std::vector<tString>& vectorNames) {
262  return true;
263  }
264 
275  inline tBoolean writeContentData(const tReal& t,
276  const SM_Network& network,
277  const tFlag& support,
278  const tString& name,const tReal& alpha,
279  const tReal* f) {
280  tBoolean ok=true;
281  tString tab="\t\t\t";
282  tString tab2=tab+"\t";
283 
284  //get the file
285  CORE_OutputFile &file=*mFile.get();
286 
287  file<<tab<<"<Grid Name=\"Grid\">"<<"\n";
288 
289  file<<tab2<<"<Time Value=\""<<std::setprecision(10)<<t<<"\"/>"<<"\n";
290 
291  file<<tab2<<"<Geometry Reference=\"/Xdmf/Domain/Grid/Geometry[1]\"/>"<<"\n";
292  // file<<tab2<<"<Geometry Type=\"XYZ\">"<<"\n";
293  // ok = ok && writeVertices(file,network);
294  // file<<tab2<<"</Geometry>"<<"\n";
295 
296  file<<tab2<<"<Topology Reference=\"/Xdmf/Domain/Grid/Topology[1]\"/>"<<"\n";
297  // file<<tab2<<"<Topology Dimensions=\""<<network.getPointsNumber()<<"\" Type=\"Mixed\">"<<"\n";
298  // ok = ok && writeConnectivity(file,
299  // network.getNeighbors(),
300  // network.getNeighborIndices());
301  // file<<tab2<<"</Topology>"<<"\n";
302 
303 
304 
305  ok=WriteField(file,getFormat(),getExternalFileName(),t,support,name,"",
306  alpha,network.getParticlesNumber()+network.getHaloParticlesNumber(),SM_Constants::DIM,f);
307 
308  file<<tab<<"</Grid>"<<"\n";
309 
310  return ok;
311  }
312 
318  inline tBoolean writeContentFooter(const tIndex& t,const tFlag& support) {
319  return true;
320  }
321 
322 
327  inline tBoolean writeGeometryFooter(const tIndex& t) {
328  return true;
329  }
330 
331 
332 
337  inline tBoolean close(const tIndex& t) {
338  return true;
339  }
340 
344  inline tBoolean close() {
345 
346  //get the file
347  CORE_OutputFile &f=*mFile.get();
348 
349  //close the file at end time
350  f<<"\t\t</Grid>"<<"\n";
351  f<<"\t</Domain>"<<"\n";
352  f<<"</Xdmf>\n";
353 
354  f.close();
355  //file is open
356  setIsFileOpened(false);
357 
358  return true;
359  }
360 
361 
362 
363 
364 protected:
365 
366  //XDMF writing method
367  //===================
368 
369 
370 protected:
371 
372 
381  static tBoolean WriteVertices(CORE_OutputFile& file,
382  const tFlag& fileType,const tString& linkHDFFile,
383  const SM_Network& mesh,
384  const tString& tag);
385 
386 
398  static tBoolean WriteConnectivity(CORE_OutputFile& file,
399  const tFlag& fileType,const tString& linkHDFFile,
400  const tIndex& nAloneParticles,
401  const tIndex& nHaloParticles,
402  const std::valarray<tIndex>& neighboringParticlesListOffset,
403  const std::valarray<tIndex>& neighboringParticlesList,
404  const tString& tagN);
405 
406 
407 
422  static tBoolean WriteField(CORE_OutputFile& file,
423  const tFlag& fileType,const tString& linkHDFFile,
424  const tIndex& t,
425  const tFlag& contentType,
426  const tString& name,
427  const tString& tagName,
428  const tReal& alpha,
429  const tIndex& n,
430  const tDimension& dim,
431  const tReal* f);
432 
433 
434 
435 
436 
437 
438 
439 
440 
441 
442 };
443 
444 #endif
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:113
this class describes a writing file
Definition: CORE_OutputFile.h:16
void close()
close the file
Definition: CORE_OutputFile.h:125
static constexpr tDimension DIM
space dimension
Definition: SM_Constants.h:80
This class is describes a network composed by.
Definition: SM_Network.h:66
const std::valarray< tIndex > & getNeighboringParticlesList() const
get the neighbors indices
Definition: SM_Network.h:399
tIndex computeAloneParticlesNumber() const
return the particles number without any connection
Definition: SM_Network.h:516
const tInteger & getHaloParticlesNumber() const
return the halo particles number
Definition: SM_Network.h:355
const tInteger & getParticlesNumber() const
return the particles number
Definition: SM_Network.h:349
const std::valarray< tIndex > & getNeighboringParticlesNumberOffset() const
get the index of the array mNeighboringParticlesList of the first neighbor of the particle p
Definition: SM_Network.h:428
This class is a beam output interface for VTK / Paraview software.
Definition: SM_VTK.h:21
const tString & getFileName() const
get the file name without extension
Definition: SM_VTK.h:158
virtual tMemSize getContentsMemorySize() const
return the memory size of the included associations
Definition: SM_VTK.h:102
void setIsFileOpened(const tBoolean &v)
set true is the file is opened
Definition: SM_VTK.h:217
This class is a beam interface output for XMF format for paraview visualization software.
Definition: SM_XDMF.h:22
SM_XDMF(void)
create
Definition: SM_XDMF.cpp:9
tBoolean writeContentFooter(const tIndex &t, const tFlag &support)
write a content footer
Definition: SM_XDMF.h:318
static CORE_UniquePointer< SM_XDMF > New()
create an XDMF class
Definition: SM_XDMF.h:72
tBoolean close()
close the file
Definition: SM_XDMF.h:344
virtual ~SM_XDMF(void)
destroy
Definition: SM_XDMF.cpp:25
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_XDMF.h:275
virtual tMemSize getContentsMemorySize() const
return the memory size of the included associations
Definition: SM_XDMF.h:112
tBoolean writeGeometryData(const tIndex &t, const SM_Network &network)
write the geometry data of the network
Definition: SM_XDMF.h:234
tBoolean writeGeometryFooter(const tIndex &t)
write the geometry footer
Definition: SM_XDMF.h:327
tBoolean close(const tIndex &t)
close the file for the time step t
Definition: SM_XDMF.h:337
const tString & getExternalFileName() const
get the external file name to find data
Definition: SM_XDMF.h:149
tBoolean writeGeometryHeader(const tIndex &it, const SM_Network &network)
write the geometry header corresponding to the network
Definition: SM_XDMF.h:202
static const tFlag XML
XML file type.
Definition: SM_XDMF.h:29
void setFormat(const tFlag &f)
set the format of the data
Definition: SM_XDMF.h:135
static tBoolean WriteVertices(CORE_OutputFile &file, const tFlag &fileType, const tString &linkHDFFile, const SM_Network &mesh, const tString &tag)
write the vertices coordinates
Definition: SM_XDMF.cpp:37
virtual tMemSize getMemorySize() const
return the memory size of the class and the memory size of all its attributes/associations
Definition: SM_XDMF.h:100
static const tFlag HDF
HDF file type.
Definition: SM_XDMF.h:32
tBoolean writeContentHeader(const tIndex &t, const tFlag &support, const std::vector< tString > &scalarNames, const std::vector< tString > &vectorNames)
write a content header
Definition: SM_XDMF.h:258
const tFlag & getFormat() const
get the format of the data
Definition: SM_XDMF.h:143
tBoolean open(const tIndex &t)
open the vtk field for writing or appending at the time step
Definition: SM_XDMF.h:191
tBoolean open()
open the vtkfile
Definition: SM_XDMF.h:161
static CORE_UniquePointer< SM_XDMF > New(const tFlag &format)
create an XDMF class
Definition: SM_XDMF.h:79
void setExternalFileName(const tString &f)
set the external file to find the vector data
Definition: SM_XDMF.h:128
static tBoolean WriteField(CORE_OutputFile &file, const tFlag &fileType, const tString &linkHDFFile, const tIndex &t, const tFlag &contentType, const tString &name, const tString &tagName, const tReal &alpha, const tIndex &n, const tDimension &dim, const tReal *f)
write a field with name
Definition: SM_XDMF.cpp:198
static tBoolean WriteConnectivity(CORE_OutputFile &file, const tFlag &fileType, const tString &linkHDFFile, const tIndex &nAloneParticles, const tIndex &nHaloParticles, const std::valarray< tIndex > &neighboringParticlesListOffset, const std::valarray< tIndex > &neighboringParticlesList, const tString &tagN)
write the connectivity between vertices
Definition: SM_XDMF.cpp:85