Chaste  Release::3.4
CmguiMeshWriter.hpp
1 /*
2 
3 Copyright (c) 2005-2016, University of Oxford.
4 All rights reserved.
5 
6 University of Oxford means the Chancellor, Masters and Scholars of the
7 University of Oxford, having an administrative office at Wellington
8 Square, Oxford OX1 2JD, UK.
9 
10 This file is part of Chaste.
11 
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions are met:
14  * Redistributions of source code must retain the above copyright notice,
15  this list of conditions and the following disclaimer.
16  * Redistributions in binary form must reproduce the above copyright notice,
17  this list of conditions and the following disclaimer in the documentation
18  and/or other materials provided with the distribution.
19  * Neither the name of the University of Oxford nor the names of its
20  contributors may be used to endorse or promote products derived from this
21  software without specific prior written permission.
22 
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 
34 */
35 
36 #ifndef CMGUIWRITER_HPP_
37 #define CMGUIWRITER_HPP_
38 
39 #include "AbstractTetrahedralMeshWriter.hpp"
40 #include "OutputFileHandler.hpp"
41 
45 static const char CmguiNodeFileHeader3D[] = " #Fields=1\n\
46  1) coordinates, coordinate, rectangular cartesian, #Components=3\n\
47  x. Value index= 1, #Derivatives= 0\n\
48  y. Value index= 2, #Derivatives= 0\n\
49  z. Value index= 3, #Derivatives= 0\n";
50 
54 static const char CmguiNodeFileHeader2D[] = " #Fields=1\n\
55  1) coordinates, coordinate, rectangular cartesian, #Components=2\n\
56  x. Value index= 1, #Derivatives= 0\n\
57  y. Value index= 2, #Derivatives= 0\n";
58 
59 
63 static const char CmguiNodeFileHeader1D[] = " #Fields=1\n\
64  1) coordinates, coordinate, rectangular cartesian, #Components=1\n\
65  x. Value index= 1, #Derivatives= 0\n";
66 
70 static const char CmguiElementFileHeader3D[] = "Shape. Dimension=3, simplex(2;3)*simplex*simplex\n\
71  #Scale factor sets= 0\n\
72  #Nodes= 4\n";
73 
77 static const char CmguiElementFileHeader3DQuadratic[] = "Shape. Dimension=3, simplex(2;3)*simplex*simplex\n\
78  #Scale factor sets= 0\n\
79  #Nodes= 10\n";
80 
81 
85 static const char CmguiElementFileHeader2D[] = "Shape. Dimension=2, simplex(2)*simplex\n\
86  #Scale factor sets= 0\n\
87  #Nodes= 3\n";
88 
92 static const char CmguiElementFileHeader2DQuadratic[] = "Shape. Dimension=2, simplex(2)*simplex\n\
93  #Scale factor sets= 0\n\
94  #Nodes= 6\n";
95 
99 static const char CmguiElementFileHeader1D[] = "Shape. Dimension=1, line\n\
100  #Scale factor sets= 0\n\
101  #Nodes= 2\n";
102 
106 static const char CmguiElementFileHeader1DQuadratic[] = "Shape. Dimension=1, line\n\
107  #Scale factor sets= 0\n\
108  #Nodes= 3\n";
109 
110 
114 static const char CmguiCoordinatesFileHeader3D[] = " 1) coordinates, coordinate, rectangular cartesian, #Components=3\n\
115  x. l.simplex(2;3)*l.simplex*l.simplex, no modify, standard node based.\n\
116  #Nodes= 4\n\
117  1. #Values=1\n\
118  Value indices: 1\n\
119  Scale factor indices: 1\n\
120  2. #Values=1\n\
121  Value indices: 1\n\
122  Scale factor indices: 2\n\
123  3. #Values=1\n\
124  Value indices: 1\n\
125  Scale factor indices: 3\n\
126  4. #Values=1\n\
127  Value indices: 1\n\
128  Scale factor indices: 4\n\
129  y. l.simplex(2;3)*l.simplex*l.simplex, no modify, standard node based.\n\
130  #Nodes= 4\n\
131  1. #Values=1\n\
132  Value indices: 1\n\
133  Scale factor indices: 1\n\
134  2. #Values=1\n\
135  Value indices: 1\n\
136  Scale factor indices: 2\n\
137  3. #Values=1\n\
138  Value indices: 1\n\
139  Scale factor indices: 3\n\
140  4. #Values=1\n\
141  Value indices: 1\n\
142  Scale factor indices: 4\n\
143  z. l.simplex(2;3)*l.simplex*l.simplex, no modify, standard node based.\n\
144  #Nodes= 4\n\
145  1. #Values=1\n\
146  Value indices: 1\n\
147  Scale factor indices: 1\n\
148  2. #Values=1\n\
149  Value indices: 1\n\
150  Scale factor indices: 2\n\
151  3. #Values=1\n\
152  Value indices: 1\n\
153  Scale factor indices: 3\n\
154  4. #Values=1\n\
155  Value indices: 1\n\
156  Scale factor indices: 4\n";
157 
158 
162 static const char CmguiCoordinatesFileHeader3DQuadratic[] = " 1) coordinates, coordinate, rectangular cartesian, #Components=3\n\
163  x. q.simplex(2;3)*q.simplex*q.simplex, no modify, standard node based.\n\
164  #Nodes= 10\n\
165  1. #Values=1\n\
166  Value indices: 1\n\
167  Scale factor indices: 1\n\
168  2. #Values=1\n\
169  Value indices: 1\n\
170  Scale factor indices: 2\n\
171  3. #Values=1\n\
172  Value indices: 1\n\
173  Scale factor indices: 3\n\
174  4. #Values=1\n\
175  Value indices: 1\n\
176  Scale factor indices: 4\n\
177  5. #Values=1\n\
178  Value indices: 1\n\
179  Scale factor indices: 5\n\
180  6. #Values=1\n\
181  Value indices: 1\n\
182  Scale factor indices: 6\n\
183  7. #Values=1\n\
184  Value indices: 1\n\
185  Scale factor indices: 7\n\
186  8. #Values=1\n\
187  Value indices: 1\n\
188  Scale factor indices: 8\n\
189  9. #Values=1\n\
190  Value indices: 1\n\
191  Scale factor indices: 9\n\
192  10. #Values=1\n\
193  Value indices: 1\n\
194  Scale factor indices: 10\n\
195  y. q.simplex(2;3)*q.simplex*q.simplex, no modify, standard node based.\n\
196  #Nodes= 10\n\
197  1. #Values=1\n\
198  Value indices: 1\n\
199  Scale factor indices: 1\n\
200  2. #Values=1\n\
201  Value indices: 1\n\
202  Scale factor indices: 2\n\
203  3. #Values=1\n\
204  Value indices: 1\n\
205  Scale factor indices: 3\n\
206  4. #Values=1\n\
207  Value indices: 1\n\
208  Scale factor indices: 4\n\
209  5. #Values=1\n\
210  Value indices: 1\n\
211  Scale factor indices: 5\n\
212  6. #Values=1\n\
213  Value indices: 1\n\
214  Scale factor indices: 6\n\
215  7. #Values=1\n\
216  Value indices: 1\n\
217  Scale factor indices: 7\n\
218  8. #Values=1\n\
219  Value indices: 1\n\
220  Scale factor indices: 8\n\
221  9. #Values=1\n\
222  Value indices: 1\n\
223  Scale factor indices: 9\n\
224  10. #Values=1\n\
225  Value indices: 1\n\
226  Scale factor indices: 10\n\
227  z. q.simplex(2;3)*q.simplex*q.simplex, no modify, standard node based.\n\
228  #Nodes= 10\n\
229  1. #Values=1\n\
230  Value indices: 1\n\
231  Scale factor indices: 1\n\
232  2. #Values=1\n\
233  Value indices: 1\n\
234  Scale factor indices: 2\n\
235  3. #Values=1\n\
236  Value indices: 1\n\
237  Scale factor indices: 3\n\
238  4. #Values=1\n\
239  Value indices: 1\n\
240  Scale factor indices: 4\n\
241  5. #Values=1\n\
242  Value indices: 1\n\
243  Scale factor indices: 5\n\
244  6. #Values=1\n\
245  Value indices: 1\n\
246  Scale factor indices: 6\n\
247  7. #Values=1\n\
248  Value indices: 1\n\
249  Scale factor indices: 7\n\
250  8. #Values=1\n\
251  Value indices: 1\n\
252  Scale factor indices: 8\n\
253  9. #Values=1\n\
254  Value indices: 1\n\
255  Scale factor indices: 9\n\
256  10. #Values=1\n\
257  Value indices: 1\n\
258  Scale factor indices: 10\n";
259 
260 
264 static const char CmguiCoordinatesFileHeader2D[] = " 1) coordinates, coordinate, rectangular cartesian, #Components=2\n\
265  x. l.simplex(2)*l.simplex, no modify, standard node based.\n\
266  #Nodes= 3\n\
267  1. #Values=1\n\
268  Value indices: 1\n\
269  Scale factor indices: 1\n\
270  2. #Values=1\n\
271  Value indices: 1\n\
272  Scale factor indices: 2\n\
273  3. #Values=1\n\
274  Value indices: 1\n\
275  Scale factor indices: 3\n\
276  y. l.simplex(2)*l.simplex, no modify, standard node based.\n\
277  #Nodes= 3\n\
278  1. #Values=1\n\
279  Value indices: 1\n\
280  Scale factor indices: 1\n\
281  2. #Values=1\n\
282  Value indices: 1\n\
283  Scale factor indices: 2\n\
284  3. #Values=1\n\
285  Value indices: 1\n\
286  Scale factor indices: 3\n";
287 
288 
293 static const char CmguiCoordinatesFileHeader2DQuadratic[] = " 1) coordinates, coordinate, rectangular cartesian, #Components=2\n\
294  x. q.simplex(2)*q.simplex, no modify, standard node based.\n\
295  #Nodes= 6\n\
296  1. #Values=1\n\
297  Value indices: 1\n\
298  Scale factor indices: 1\n\
299  2. #Values=1\n\
300  Value indices: 1\n\
301  Scale factor indices: 2\n\
302  3. #Values=1\n\
303  Value indices: 1\n\
304  Scale factor indices: 3\n\
305  4. #Values=1\n\
306  Value indices: 1\n\
307  Scale factor indices: 4\n\
308  5. #Values=1\n\
309  Value indices: 1\n\
310  Scale factor indices: 5\n\
311  6. #Values=1\n\
312  Value indices: 1\n\
313  Scale factor indices: 6\n\
314  y. q.simplex(2)*q.simplex, no modify, standard node based.\n\
315  #Nodes= 6\n\
316  1. #Values=1\n\
317  Value indices: 1\n\
318  Scale factor indices: 1\n\
319  2. #Values=1\n\
320  Value indices: 1\n\
321  Scale factor indices: 2\n\
322  3. #Values=1\n\
323  Value indices: 1\n\
324  Scale factor indices: 3\n\
325  4. #Values=1\n\
326  Value indices: 1\n\
327  Scale factor indices: 4\n\
328  5. #Values=1\n\
329  Value indices: 1\n\
330  Scale factor indices: 5\n\
331  6. #Values=1\n\
332  Value indices: 1\n\
333  Scale factor indices: 6\n";
334 
335 
336 
341 static const char CmguiCoordinatesFileHeader1D[] = " 1) coordinates, coordinate, rectangular cartesian, #Components=1\n\
342  x. l.Lagrange, no modify, standard node based.\n\
343  #Nodes= 2\n\
344  1. #Values=1\n\
345  Value indices: 1\n\
346  Scale factor indices: 1\n\
347  2. #Values=1\n\
348  Value indices: 1\n\
349  Scale factor indices: 2\n";
350 
351 
356 static const char CmguiCoordinatesFileHeader1DQuadratic[] = " 1) coordinates, coordinate, rectangular cartesian, #Components=1\n\
357  x. q.Lagrange, no modify, standard node based.\n\
358  #Nodes= 3\n\
359  1. #Values=1\n\
360  Value indices: 1\n\
361  Scale factor indices: 1\n\
362  2. #Values=1\n\
363  Value indices: 1\n\
364  Scale factor indices: 2\n\
365  3. #Values=1\n\
366  Value indices: 1\n\
367  Scale factor indices: 3\n";
368 
373 static const char CmguiAdditionalFieldHeader3D[] = " field, rectangular cartesian, #Components=1\n\
374  x. l.simplex(2;3)*l.simplex*l.simplex, no modify, standard node based.\n\
375  #Nodes= 4\n\
376  1. #Values=1\n\
377  Value indices: 1\n\
378  Scale factor indices: 1\n\
379  2. #Values=1\n\
380  Value indices: 1\n\
381  Scale factor indices: 2\n\
382  3. #Values=1\n\
383  Value indices: 1\n\
384  Scale factor indices: 3\n\
385  4. #Values=1\n\
386  Value indices: 1\n\
387  Scale factor indices: 4\n";
388 
389 
395 static const char CmguiAdditionalFieldHeader3DQuadratic[] = " field, rectangular cartesian, #Components=1\n\
396  x. q.simplex(2;3)*q.simplex*q.simplex, no modify, standard node based.\n\
397  #Nodes= 10\n\
398  1. #Values=1\n\
399  Value indices: 1\n\
400  Scale factor indices: 1\n\
401  2. #Values=1\n\
402  Value indices: 1\n\
403  Scale factor indices: 2\n\
404  3. #Values=1\n\
405  Value indices: 1\n\
406  Scale factor indices: 3\n\
407  4. #Values=1\n\
408  Value indices: 1\n\
409  Scale factor indices: 4\n\
410  5. #Values=1\n\
411  Value indices: 1\n\
412  Scale factor indices: 5\n\
413  6. #Values=1\n\
414  Value indices: 1\n\
415  Scale factor indices: 6\n\
416  7. #Values=1\n\
417  Value indices: 1\n\
418  Scale factor indices: 7\n\
419  8. #Values=1\n\
420  Value indices: 1\n\
421  Scale factor indices: 8\n\
422  9. #Values=1\n\
423  Value indices: 1\n\
424  Scale factor indices: 9\n\
425  10. #Values=1\n\
426  Value indices: 1\n\
427  Scale factor indices: 10\n";
428 
433 static const char CmguiAdditionalFieldHeader2D[] = " field, rectangular cartesian, #Components=1\n\
434  x. l.simplex(2)*l.simplex, no modify, standard node based.\n\
435  #Nodes= 3\n\
436  1. #Values=1\n\
437  Value indices: 1\n\
438  Scale factor indices: 1\n\
439  2. #Values=1\n\
440  Value indices: 1\n\
441  Scale factor indices: 2\n\
442  3. #Values=1\n\
443  Value indices: 1\n\
444  Scale factor indices: 3\n";
445 
450 static const char CmguiAdditionalFieldHeader2DQuadratic[] = " field, rectangular cartesian, #Components=1\n\
451  x. q.simplex(2)*q.simplex, no modify, standard node based.\n\
452  #Nodes= 6\n\
453  1. #Values=1\n\
454  Value indices: 1\n\
455  Scale factor indices: 1\n\
456  2. #Values=1\n\
457  Value indices: 1\n\
458  Scale factor indices: 2\n\
459  3. #Values=1\n\
460  Value indices: 1\n\
461  Scale factor indices: 3\n\
462  4. #Values=1\n\
463  Value indices: 1\n\
464  Scale factor indices: 4\n\
465  5. #Values=1\n\
466  Value indices: 1\n\
467  Scale factor indices: 5\n\
468  6. #Values=1\n\
469  Value indices: 1\n\
470  Scale factor indices: 6\n";
471 
472 
477 static const char CmguiAdditionalFieldHeader1D[] = " field, rectangular cartesian, #Components=1\n\
478  x. l.Lagrange, no modify, standard node based.\n\
479  #Nodes= 2\n\
480  1. #Values=1\n\
481  Value indices: 1\n\
482  Scale factor indices: 1\n\
483  2. #Values=1\n\
484  Value indices: 1\n\
485  Scale factor indices: 2\n";
486 
491 static const char CmguiAdditionalFieldHeader1DQuadratic[] = " field, rectangular cartesian, #Components=1\n\
492  x. q.Lagrange, no modify, standard node based.\n\
493  #Nodes= 2\n\
494  1. #Values=1\n\
495  Value indices: 1\n\
496  Scale factor indices: 1\n\
497  2. #Values=1\n\
498  Value indices: 1\n\
499  Scale factor indices: 2\n\
500  3. #Values=1\n\
501  Value indices: 1\n\
502  Scale factor indices: 3\n";
503 
504 
516 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
517 class CmguiMeshWriter : public AbstractTetrahedralMeshWriter<ELEMENT_DIM,SPACE_DIM>
518 {
519 protected:
520 
524  std::vector<std::string> mAdditionalFieldNames;
525 
526 
531  std::vector<std::string> mRegionNames;// {tissue, bath, whatever}
532 
539  std::string mGroupName;
540 
545  std::string mElementFileHeader;
546 
553 
559 
565 
569  std::vector<unsigned> mReordering;
570 
576  std::ios_base::openmode GetOpenMode(bool append);
577 
584  out_stream OpenNodeFile(bool append = false);
585 
592  std::vector<boost::shared_ptr<std::ofstream> > OpenElementFiles(bool append = false);
593 
600  void WriteNodeFileHeader(out_stream& rpNodeFile);
601 
607  void WriteElementsFileHeader(std::vector<boost::shared_ptr<std::ofstream> >& rElemFiles);
608 
609 
613  void CreateFilesWithHeaders();
614 
618  void AppendLocalDataToFiles();
619 
623  void WriteFilesFooter();
624 
625 public:
626 
634  CmguiMeshWriter(const std::string& rDirectory,
635  const std::string& rBaseName,
636  bool cleanDirectory=true);
637 
641  void WriteFiles();
642 
648  void SetAdditionalFieldNames(std::vector<std::string>& rFieldNames);
649 
655  void SetRegionNames(std::vector<std::string>& rRegionNames);
656 
661  {}
662 
663 
664  // A method called CompareCmguiFiles() has been removed, please use FileComparison class instead.
665 
666 };
667 
668 #endif /*CMGUIWRITER_HPP_*/
std::string mAdditionalFieldHeader
out_stream OpenNodeFile(bool append=false)
virtual ~CmguiMeshWriter()
void SetRegionNames(std::vector< std::string > &rRegionNames)
std::string mCoordinatesFileHeader
std::vector< boost::shared_ptr< std::ofstream > > OpenElementFiles(bool append=false)
void WriteElementsFileHeader(std::vector< boost::shared_ptr< std::ofstream > > &rElemFiles)
std::vector< std::string > mRegionNames
std::ios_base::openmode GetOpenMode(bool append)
std::string mElementFileHeader
unsigned mNumNodesPerElement
std::vector< unsigned > mReordering
std::string mGroupName
void SetAdditionalFieldNames(std::vector< std::string > &rFieldNames)
std::vector< std::string > mAdditionalFieldNames
CmguiMeshWriter(const std::string &rDirectory, const std::string &rBaseName, bool cleanDirectory=true)
void WriteNodeFileHeader(out_stream &rpNodeFile)