Chaste  Release::2017.1
CmguiMeshWriter.hpp
1 /*
2 
3 Copyright (c) 2005-2017, 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 
339 static const char CmguiCoordinatesFileHeader1D[] = " 1) coordinates, coordinate, rectangular cartesian, #Components=1\n\
340  x. l.Lagrange, no modify, standard node based.\n\
341  #Nodes= 2\n\
342  1. #Values=1\n\
343  Value indices: 1\n\
344  Scale factor indices: 1\n\
345  2. #Values=1\n\
346  Value indices: 1\n\
347  Scale factor indices: 2\n";
348 
349 
354 static const char CmguiCoordinatesFileHeader1DQuadratic[] = " 1) coordinates, coordinate, rectangular cartesian, #Components=1\n\
355  x. q.Lagrange, no modify, standard node based.\n\
356  #Nodes= 3\n\
357  1. #Values=1\n\
358  Value indices: 1\n\
359  Scale factor indices: 1\n\
360  2. #Values=1\n\
361  Value indices: 1\n\
362  Scale factor indices: 2\n\
363  3. #Values=1\n\
364  Value indices: 1\n\
365  Scale factor indices: 3\n";
366 
371 static const char CmguiAdditionalFieldHeader3D[] = " field, rectangular cartesian, #Components=1\n\
372  x. l.simplex(2;3)*l.simplex*l.simplex, no modify, standard node based.\n\
373  #Nodes= 4\n\
374  1. #Values=1\n\
375  Value indices: 1\n\
376  Scale factor indices: 1\n\
377  2. #Values=1\n\
378  Value indices: 1\n\
379  Scale factor indices: 2\n\
380  3. #Values=1\n\
381  Value indices: 1\n\
382  Scale factor indices: 3\n\
383  4. #Values=1\n\
384  Value indices: 1\n\
385  Scale factor indices: 4\n";
386 
387 
393 static const char CmguiAdditionalFieldHeader3DQuadratic[] = " field, rectangular cartesian, #Components=1\n\
394  x. q.simplex(2;3)*q.simplex*q.simplex, no modify, standard node based.\n\
395  #Nodes= 10\n\
396  1. #Values=1\n\
397  Value indices: 1\n\
398  Scale factor indices: 1\n\
399  2. #Values=1\n\
400  Value indices: 1\n\
401  Scale factor indices: 2\n\
402  3. #Values=1\n\
403  Value indices: 1\n\
404  Scale factor indices: 3\n\
405  4. #Values=1\n\
406  Value indices: 1\n\
407  Scale factor indices: 4\n\
408  5. #Values=1\n\
409  Value indices: 1\n\
410  Scale factor indices: 5\n\
411  6. #Values=1\n\
412  Value indices: 1\n\
413  Scale factor indices: 6\n\
414  7. #Values=1\n\
415  Value indices: 1\n\
416  Scale factor indices: 7\n\
417  8. #Values=1\n\
418  Value indices: 1\n\
419  Scale factor indices: 8\n\
420  9. #Values=1\n\
421  Value indices: 1\n\
422  Scale factor indices: 9\n\
423  10. #Values=1\n\
424  Value indices: 1\n\
425  Scale factor indices: 10\n";
426 
431 static const char CmguiAdditionalFieldHeader2D[] = " field, rectangular cartesian, #Components=1\n\
432  x. l.simplex(2)*l.simplex, no modify, standard node based.\n\
433  #Nodes= 3\n\
434  1. #Values=1\n\
435  Value indices: 1\n\
436  Scale factor indices: 1\n\
437  2. #Values=1\n\
438  Value indices: 1\n\
439  Scale factor indices: 2\n\
440  3. #Values=1\n\
441  Value indices: 1\n\
442  Scale factor indices: 3\n";
443 
448 static const char CmguiAdditionalFieldHeader2DQuadratic[] = " field, rectangular cartesian, #Components=1\n\
449  x. q.simplex(2)*q.simplex, no modify, standard node based.\n\
450  #Nodes= 6\n\
451  1. #Values=1\n\
452  Value indices: 1\n\
453  Scale factor indices: 1\n\
454  2. #Values=1\n\
455  Value indices: 1\n\
456  Scale factor indices: 2\n\
457  3. #Values=1\n\
458  Value indices: 1\n\
459  Scale factor indices: 3\n\
460  4. #Values=1\n\
461  Value indices: 1\n\
462  Scale factor indices: 4\n\
463  5. #Values=1\n\
464  Value indices: 1\n\
465  Scale factor indices: 5\n\
466  6. #Values=1\n\
467  Value indices: 1\n\
468  Scale factor indices: 6\n";
469 
470 
475 static const char CmguiAdditionalFieldHeader1D[] = " field, rectangular cartesian, #Components=1\n\
476  x. l.Lagrange, no modify, standard node based.\n\
477  #Nodes= 2\n\
478  1. #Values=1\n\
479  Value indices: 1\n\
480  Scale factor indices: 1\n\
481  2. #Values=1\n\
482  Value indices: 1\n\
483  Scale factor indices: 2\n";
484 
489 static const char CmguiAdditionalFieldHeader1DQuadratic[] = " field, rectangular cartesian, #Components=1\n\
490  x. q.Lagrange, no modify, standard node based.\n\
491  #Nodes= 2\n\
492  1. #Values=1\n\
493  Value indices: 1\n\
494  Scale factor indices: 1\n\
495  2. #Values=1\n\
496  Value indices: 1\n\
497  Scale factor indices: 2\n\
498  3. #Values=1\n\
499  Value indices: 1\n\
500  Scale factor indices: 3\n";
501 
502 
514 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
515 class CmguiMeshWriter : public AbstractTetrahedralMeshWriter<ELEMENT_DIM,SPACE_DIM>
516 {
517 protected:
518 
522  std::vector<std::string> mAdditionalFieldNames;
523 
524 
529  std::vector<std::string> mRegionNames;// {tissue, bath, whatever}
530 
537  std::string mGroupName;
538 
543  std::string mElementFileHeader;
544 
551 
557 
563 
567  std::vector<unsigned> mReordering;
568 
574  std::ios_base::openmode GetOpenMode(bool append);
575 
582  out_stream OpenNodeFile(bool append = false);
583 
590  std::vector<boost::shared_ptr<std::ofstream> > OpenElementFiles(bool append = false);
591 
598  void WriteNodeFileHeader(out_stream& rpNodeFile);
599 
605  void WriteElementsFileHeader(std::vector<boost::shared_ptr<std::ofstream> >& rElemFiles);
606 
607 
611  void CreateFilesWithHeaders();
612 
616  void AppendLocalDataToFiles();
617 
621  void WriteFilesFooter();
622 
623 public:
624 
632  CmguiMeshWriter(const std::string& rDirectory,
633  const std::string& rBaseName,
634  bool cleanDirectory=true);
635 
639  void WriteFiles();
640 
646  void SetAdditionalFieldNames(std::vector<std::string>& rFieldNames);
647 
653  void SetRegionNames(std::vector<std::string>& rRegionNames);
654 
659  {}
660 
661  // A method called CompareCmguiFiles() has been removed, please use FileComparison class instead.
662 };
663 
664 #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)