Chaste Commit::1fd4e48e3990e67db148bc1bc4cf6991a0049d0c
CmguiMeshWriter.hpp
1/*
2
3Copyright (c) 2005-2024, University of Oxford.
4All rights reserved.
5
6University of Oxford means the Chancellor, Masters and Scholars of the
7University of Oxford, having an administrative office at Wellington
8Square, Oxford OX1 2JD, UK.
9
10This file is part of Chaste.
11
12Redistribution and use in source and binary forms, with or without
13modification, 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
23THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32OF 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
45static constexpr char CmguiNodeFileHeader3D[] = R"( #Fields=1
46 1) coordinates, coordinate, rectangular cartesian, #Components=3
47 x. Value index= 1, #Derivatives= 0
48 y. Value index= 2, #Derivatives= 0
49 z. Value index= 3, #Derivatives= 0
50)";
51
55static constexpr char CmguiNodeFileHeader2D[] = R"( #Fields=1
56 1) coordinates, coordinate, rectangular cartesian, #Components=2
57 x. Value index= 1, #Derivatives= 0
58 y. Value index= 2, #Derivatives= 0
59)";
60
61
65static constexpr char CmguiNodeFileHeader1D[] = R"( #Fields=1
66 1) coordinates, coordinate, rectangular cartesian, #Components=1
67 x. Value index= 1, #Derivatives= 0
68)";
69
73static constexpr char CmguiElementFileHeader3D[] = R"(Shape. Dimension=3, simplex(2;3)*simplex*simplex
74 #Scale factor sets= 0
75 #Nodes= 4
76)";
77
81static constexpr char CmguiElementFileHeader3DQuadratic[] = R"(Shape. Dimension=3, simplex(2;3)*simplex*simplex
82 #Scale factor sets= 0
83 #Nodes= 10
84)";
85
86
90static constexpr char CmguiElementFileHeader2D[] = R"(Shape. Dimension=2, simplex(2)*simplex
91 #Scale factor sets= 0
92 #Nodes= 3
93)";
94
98static constexpr char CmguiElementFileHeader2DQuadratic[] = R"(Shape. Dimension=2, simplex(2)*simplex
99 #Scale factor sets= 0
100 #Nodes= 6
101)";
102
106static constexpr char CmguiElementFileHeader1D[] = R"(Shape. Dimension=1, line
107 #Scale factor sets= 0
108 #Nodes= 2
109)";
110
114static constexpr char CmguiElementFileHeader1DQuadratic[] = R"(Shape. Dimension=1, line
115 #Scale factor sets= 0
116 #Nodes= 3
117)";
118
119
123static constexpr char CmguiCoordinatesFileHeader3D[] = R"( 1) coordinates, coordinate, rectangular cartesian, #Components=3
124 x. l.simplex(2;3)*l.simplex*l.simplex, no modify, standard node based.
125 #Nodes= 4
126 1. #Values=1
127 Value indices: 1
128 Scale factor indices: 1
129 2. #Values=1
130 Value indices: 1
131 Scale factor indices: 2
132 3. #Values=1
133 Value indices: 1
134 Scale factor indices: 3
135 4. #Values=1
136 Value indices: 1
137 Scale factor indices: 4
138 y. l.simplex(2;3)*l.simplex*l.simplex, no modify, standard node based.
139 #Nodes= 4
140 1. #Values=1
141 Value indices: 1
142 Scale factor indices: 1
143 2. #Values=1
144 Value indices: 1
145 Scale factor indices: 2
146 3. #Values=1
147 Value indices: 1
148 Scale factor indices: 3
149 4. #Values=1
150 Value indices: 1
151 Scale factor indices: 4
152 z. l.simplex(2;3)*l.simplex*l.simplex, no modify, standard node based.
153 #Nodes= 4
154 1. #Values=1
155 Value indices: 1
156 Scale factor indices: 1
157 2. #Values=1
158 Value indices: 1
159 Scale factor indices: 2
160 3. #Values=1
161 Value indices: 1
162 Scale factor indices: 3
163 4. #Values=1
164 Value indices: 1
165 Scale factor indices: 4
166)";
167
168
172static constexpr char CmguiCoordinatesFileHeader3DQuadratic[] = R"( 1) coordinates, coordinate, rectangular cartesian, #Components=3
173 x. q.simplex(2;3)*q.simplex*q.simplex, no modify, standard node based.
174 #Nodes= 10
175 1. #Values=1
176 Value indices: 1
177 Scale factor indices: 1
178 2. #Values=1
179 Value indices: 1
180 Scale factor indices: 2
181 3. #Values=1
182 Value indices: 1
183 Scale factor indices: 3
184 4. #Values=1
185 Value indices: 1
186 Scale factor indices: 4
187 5. #Values=1
188 Value indices: 1
189 Scale factor indices: 5
190 6. #Values=1
191 Value indices: 1
192 Scale factor indices: 6
193 7. #Values=1
194 Value indices: 1
195 Scale factor indices: 7
196 8. #Values=1
197 Value indices: 1
198 Scale factor indices: 8
199 9. #Values=1
200 Value indices: 1
201 Scale factor indices: 9
202 10. #Values=1
203 Value indices: 1
204 Scale factor indices: 10
205 y. q.simplex(2;3)*q.simplex*q.simplex, no modify, standard node based.
206 #Nodes= 10
207 1. #Values=1
208 Value indices: 1
209 Scale factor indices: 1
210 2. #Values=1
211 Value indices: 1
212 Scale factor indices: 2
213 3. #Values=1
214 Value indices: 1
215 Scale factor indices: 3
216 4. #Values=1
217 Value indices: 1
218 Scale factor indices: 4
219 5. #Values=1
220 Value indices: 1
221 Scale factor indices: 5
222 6. #Values=1
223 Value indices: 1
224 Scale factor indices: 6
225 7. #Values=1
226 Value indices: 1
227 Scale factor indices: 7
228 8. #Values=1
229 Value indices: 1
230 Scale factor indices: 8
231 9. #Values=1
232 Value indices: 1
233 Scale factor indices: 9
234 10. #Values=1
235 Value indices: 1
236 Scale factor indices: 10
237 z. q.simplex(2;3)*q.simplex*q.simplex, no modify, standard node based.
238 #Nodes= 10
239 1. #Values=1
240 Value indices: 1
241 Scale factor indices: 1
242 2. #Values=1
243 Value indices: 1
244 Scale factor indices: 2
245 3. #Values=1
246 Value indices: 1
247 Scale factor indices: 3
248 4. #Values=1
249 Value indices: 1
250 Scale factor indices: 4
251 5. #Values=1
252 Value indices: 1
253 Scale factor indices: 5
254 6. #Values=1
255 Value indices: 1
256 Scale factor indices: 6
257 7. #Values=1
258 Value indices: 1
259 Scale factor indices: 7
260 8. #Values=1
261 Value indices: 1
262 Scale factor indices: 8
263 9. #Values=1
264 Value indices: 1
265 Scale factor indices: 9
266 10. #Values=1
267 Value indices: 1
268 Scale factor indices: 10
269)";
270
271
275static constexpr char CmguiCoordinatesFileHeader2D[] = R"( 1) coordinates, coordinate, rectangular cartesian, #Components=2
276 x. l.simplex(2)*l.simplex, no modify, standard node based.
277 #Nodes= 3
278 1. #Values=1
279 Value indices: 1
280 Scale factor indices: 1
281 2. #Values=1
282 Value indices: 1
283 Scale factor indices: 2
284 3. #Values=1
285 Value indices: 1
286 Scale factor indices: 3
287 y. l.simplex(2)*l.simplex, no modify, standard node based.
288 #Nodes= 3
289 1. #Values=1
290 Value indices: 1
291 Scale factor indices: 1
292 2. #Values=1
293 Value indices: 1
294 Scale factor indices: 2
295 3. #Values=1
296 Value indices: 1
297 Scale factor indices: 3
298)";
299
300
305static constexpr char CmguiCoordinatesFileHeader2DQuadratic[] = R"( 1) coordinates, coordinate, rectangular cartesian, #Components=2
306 x. q.simplex(2)*q.simplex, no modify, standard node based.
307 #Nodes= 6
308 1. #Values=1
309 Value indices: 1
310 Scale factor indices: 1
311 2. #Values=1
312 Value indices: 1
313 Scale factor indices: 2
314 3. #Values=1
315 Value indices: 1
316 Scale factor indices: 3
317 4. #Values=1
318 Value indices: 1
319 Scale factor indices: 4
320 5. #Values=1
321 Value indices: 1
322 Scale factor indices: 5
323 6. #Values=1
324 Value indices: 1
325 Scale factor indices: 6
326 y. q.simplex(2)*q.simplex, no modify, standard node based.
327 #Nodes= 6
328 1. #Values=1
329 Value indices: 1
330 Scale factor indices: 1
331 2. #Values=1
332 Value indices: 1
333 Scale factor indices: 2
334 3. #Values=1
335 Value indices: 1
336 Scale factor indices: 3
337 4. #Values=1
338 Value indices: 1
339 Scale factor indices: 4
340 5. #Values=1
341 Value indices: 1
342 Scale factor indices: 5
343 6. #Values=1
344 Value indices: 1
345 Scale factor indices: 6
346)";
347
352static constexpr char CmguiCoordinatesFileHeader1D[] = R"( 1) coordinates, coordinate, rectangular cartesian, #Components=1
353 x. l.Lagrange, no modify, standard node based.
354 #Nodes= 2
355 1. #Values=1
356 Value indices: 1
357 Scale factor indices: 1
358 2. #Values=1
359 Value indices: 1
360 Scale factor indices: 2
361)";
362
363
368static constexpr char CmguiCoordinatesFileHeader1DQuadratic[] = R"( 1) coordinates, coordinate, rectangular cartesian, #Components=1
369 x. q.Lagrange, no modify, standard node based.
370 #Nodes= 3
371 1. #Values=1
372 Value indices: 1
373 Scale factor indices: 1
374 2. #Values=1
375 Value indices: 1
376 Scale factor indices: 2
377 3. #Values=1
378 Value indices: 1
379 Scale factor indices: 3
380)";
381
386static constexpr char CmguiAdditionalFieldHeader3D[] = R"( field, rectangular cartesian, #Components=1
387 x. l.simplex(2;3)*l.simplex*l.simplex, no modify, standard node based.
388 #Nodes= 4
389 1. #Values=1
390 Value indices: 1
391 Scale factor indices: 1
392 2. #Values=1
393 Value indices: 1
394 Scale factor indices: 2
395 3. #Values=1
396 Value indices: 1
397 Scale factor indices: 3
398 4. #Values=1
399 Value indices: 1
400 Scale factor indices: 4
401)";
402
403
409static constexpr char CmguiAdditionalFieldHeader3DQuadratic[] = R"( field, rectangular cartesian, #Components=1
410 x. q.simplex(2;3)*q.simplex*q.simplex, no modify, standard node based.
411 #Nodes= 10
412 1. #Values=1
413 Value indices: 1
414 Scale factor indices: 1
415 2. #Values=1
416 Value indices: 1
417 Scale factor indices: 2
418 3. #Values=1
419 Value indices: 1
420 Scale factor indices: 3
421 4. #Values=1
422 Value indices: 1
423 Scale factor indices: 4
424 5. #Values=1
425 Value indices: 1
426 Scale factor indices: 5
427 6. #Values=1
428 Value indices: 1
429 Scale factor indices: 6
430 7. #Values=1
431 Value indices: 1
432 Scale factor indices: 7
433 8. #Values=1
434 Value indices: 1
435 Scale factor indices: 8
436 9. #Values=1
437 Value indices: 1
438 Scale factor indices: 9
439 10. #Values=1
440 Value indices: 1
441 Scale factor indices: 10
442)";
443
448static constexpr char CmguiAdditionalFieldHeader2D[] = R"( field, rectangular cartesian, #Components=1
449 x. l.simplex(2)*l.simplex, no modify, standard node based.
450 #Nodes= 3
451 1. #Values=1
452 Value indices: 1
453 Scale factor indices: 1
454 2. #Values=1
455 Value indices: 1
456 Scale factor indices: 2
457 3. #Values=1
458 Value indices: 1
459 Scale factor indices: 3
460)";
461
466static constexpr char CmguiAdditionalFieldHeader2DQuadratic[] = R"( field, rectangular cartesian, #Components=1
467 x. q.simplex(2)*q.simplex, no modify, standard node based.
468 #Nodes= 6
469 1. #Values=1
470 Value indices: 1
471 Scale factor indices: 1
472 2. #Values=1
473 Value indices: 1
474 Scale factor indices: 2
475 3. #Values=1
476 Value indices: 1
477 Scale factor indices: 3
478 4. #Values=1
479 Value indices: 1
480 Scale factor indices: 4
481 5. #Values=1
482 Value indices: 1
483 Scale factor indices: 5
484 6. #Values=1
485 Value indices: 1
486 Scale factor indices: 6
487)";
488
489
494static constexpr char CmguiAdditionalFieldHeader1D[] = R"( field, rectangular cartesian, #Components=1
495 x. l.Lagrange, no modify, standard node based.
496 #Nodes= 2
497 1. #Values=1
498 Value indices: 1
499 Scale factor indices: 1
500 2. #Values=1
501 Value indices: 1
502 Scale factor indices: 2
503)";
504
509static constexpr char CmguiAdditionalFieldHeader1DQuadratic[] = R"( field, rectangular cartesian, #Components=1
510 x. q.Lagrange, no modify, standard node based.
511 #Nodes= 2
512 1. #Values=1
513 Value indices: 1
514 Scale factor indices: 1
515 2. #Values=1
516 Value indices: 1
517 Scale factor indices: 2
518 3. #Values=1
519 Value indices: 1
520 Scale factor indices: 3
521)";
522
534template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
535class CmguiMeshWriter : public AbstractTetrahedralMeshWriter<ELEMENT_DIM,SPACE_DIM>
536{
537protected:
538
542 std::vector<std::string> mAdditionalFieldNames;
543
544
549 std::vector<std::string> mRegionNames;// {tissue, bath, whatever}
550
557 std::string mGroupName;
558
564
570
576
582
586 std::vector<unsigned> mReordering;
587
593 std::ios_base::openmode GetOpenMode(bool append);
594
601 out_stream OpenNodeFile(bool append = false);
602
609 std::vector<boost::shared_ptr<std::ofstream> > OpenElementFiles(bool append = false);
610
617 void WriteNodeFileHeader(out_stream& rpNodeFile);
618
624 void WriteElementsFileHeader(std::vector<boost::shared_ptr<std::ofstream> >& rElemFiles);
625
626
631
636
640 void WriteFilesFooter();
641
642public:
643
651 CmguiMeshWriter(const std::string& rDirectory,
652 const std::string& rBaseName,
653 bool cleanDirectory=true);
654
658 void WriteFiles();
659
665 void SetAdditionalFieldNames(std::vector<std::string>& rFieldNames);
666
672 void SetRegionNames(std::vector<std::string>& rRegionNames);
673
678 {}
679
680 // A method called CompareCmguiFiles() has been removed, please use FileComparison class instead.
681};
682
683#endif /*CMGUIWRITER_HPP_*/
std::string mElementFileHeader
std::vector< std::string > mRegionNames
void WriteElementsFileHeader(std::vector< boost::shared_ptr< std::ofstream > > &rElemFiles)
std::vector< boost::shared_ptr< std::ofstream > > OpenElementFiles(bool append=false)
std::ios_base::openmode GetOpenMode(bool append)
std::vector< unsigned > mReordering
void SetAdditionalFieldNames(std::vector< std::string > &rFieldNames)
std::string mAdditionalFieldHeader
std::vector< std::string > mAdditionalFieldNames
void WriteNodeFileHeader(out_stream &rpNodeFile)
out_stream OpenNodeFile(bool append=false)
void SetRegionNames(std::vector< std::string > &rRegionNames)
std::string mCoordinatesFileHeader