FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
mesh_file_reader.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
8#include <kernel/adjacency/dynamic_graph.hpp>
9#include <kernel/geometry/atlas/bezier.hpp>
10#include <kernel/geometry/atlas/circle.hpp>
11#include <kernel/geometry/atlas/extrude.hpp>
12#include <kernel/geometry/atlas/sphere.hpp>
13#include <kernel/geometry/atlas/surface_mesh.hpp>
14#include <kernel/geometry/conformal_mesh.hpp>
15#include <kernel/geometry/io_common.hpp>
16#include <kernel/geometry/mesh_atlas.hpp>
17#include <kernel/geometry/mesh_node.hpp>
18#include <kernel/geometry/mesh_part.hpp>
19#include <kernel/util/dist_file_io.hpp>
21#include <kernel/util/xml_scanner.hpp>
22
23#include <deque>
24#include <vector>
25#include <memory>
26
27namespace FEAT
28{
29 namespace Geometry
30 {
39 public Exception
40 {
41 public:
42 explicit MeshNodeLinkerError(const String& msg) :
43 Exception(msg)
44 {
45 }
46 }; // class MeshNodeLinkerError
47
56 template<typename RootMesh_>
58 {
59 protected:
64
65 // link mesh-parts to charts
66 std::deque<std::pair<String,String>> _meshpart_to_chart;
67 // deduct mesh-part topologies
68 std::deque<String> _meshpart_deduct_topo;
69
70 public:
81 _mesh_node(mesh_node),
82 _atlas(atlas)
83 {
84 }
85
95 void meshpart_link_to_chart(const String& meshpart, const String& chart)
96 {
97 _meshpart_to_chart.emplace_back(std::make_pair(meshpart, chart));
98 }
99
106 void meshpart_deduct_topology(const String& meshpart)
107 {
108 _meshpart_deduct_topo.emplace_back(meshpart);
109 }
110
116 void execute()
117 {
118 // link meshparts to charts
119 while(!_meshpart_to_chart.empty())
120 {
121 String mpart_name = _meshpart_to_chart.front().first;
122 String chart_name = _meshpart_to_chart.front().second;
123
124 // try to find the chart
125 const Atlas::ChartBase<RootMesh_>* chart = _atlas.find_mesh_chart(chart_name);
126 if(chart == nullptr)
127 {
128 String msg = String("Chart '") + chart_name + "' not found for meshpart '" + mpart_name + "'";
129 throw MeshNodeLinkerError(msg);
130 }
131
132 // set the chart
133 if(!_mesh_node.set_mesh_part_chart(mpart_name, chart_name, chart))
134 {
135 String msg = String("meshpart '" + mpart_name + "' not found");
136 throw MeshNodeLinkerError(msg);
137 }
138
139 // done
140 _meshpart_to_chart.pop_front();
141 }
142
143 // get the root mesh (if it exists)
144 const RootMesh_* root_mesh = _mesh_node.get_mesh();
145
146 // deduct meshpart topologies
147 while(!_meshpart_deduct_topo.empty())
148 {
149 String mpart_name = _meshpart_deduct_topo.front();
150 MeshPart<RootMesh_>* mesh_part = _mesh_node.find_mesh_part(mpart_name);
151
152 if(mesh_part == nullptr)
153 {
154 String msg = String("meshpart '" + mpart_name + "' not found");
155 throw MeshNodeLinkerError(msg);
156 }
157
158 // make sure we have the root mesh
159 if(root_mesh == nullptr)
160 {
161 String msg = String("Cannot deduct topology for meshpart '") + mpart_name + "'; no root mesh found";
162 throw MeshNodeLinkerError(msg);
163 }
164
165 // Create the MeshPart's topology from the parent mesh's topology if told so
166 mesh_part->deduct_topology(*(root_mesh->get_topology()));
167
168 // done
169 _meshpart_deduct_topo.pop_front();
170 }
171 }
172 }; // class MeshNodeLinker
173
174 // Note: All the basic Parser classes are declared as internal.
176
177 // Forward declaration
178 template<typename RootMesh_, int world_dim>
179 struct DimensionalChartHelper;
180
181 template<typename RootMesh_>
182 class ChartParser :
183 public Xml::MarkupParser
184 {
185 protected:
186 MeshAtlas<RootMesh_>& _atlas;
187 String _chart_name;
188 std::unique_ptr<Atlas::ChartBase<RootMesh_>> _chart;
189
190 public:
191 explicit ChartParser(MeshAtlas<RootMesh_>& atlas) :
192 _atlas(atlas), _chart_name(), _chart()
193 {
194 }
195
196 virtual ~ChartParser()
197 {
198 }
199
200 virtual bool attribs(std::map<String,bool>& attrs) const override
201 {
202 attrs.emplace("name", true); // mandatory name
203 return true;
204 }
205
206 virtual void create(
207 int iline, const String& sline, const String&,
208 const std::map<String, String>& attrs, bool closed) override
209 {
210 if(closed)
211 throw Xml::GrammarError(iline, sline, "Invalid closed markup");
212
213 // get the chart name
214 _chart_name = attrs.find("name")->second.trim();
215 if(_chart_name.empty())
216 throw Xml::GrammarError(iline, sline, "Empty chart name");
217
218 // make sure that we don't have that chart yet
219 XASSERTM(_atlas.find_mesh_chart(_chart_name) == nullptr,
220 String("Chart '") + _chart_name + "' already exists in atlas");
221
222 // okay, that's all there is to check
223 }
224
225 virtual void close(int iline, const String& sline) override
226 {
227 // make sure that we have a chart here
228 if(!_chart)
229 throw Xml::GrammarError(iline, sline, "Invalid empty chart");
230
231 // insert chart into atlas
232 _atlas.add_mesh_chart(_chart_name, std::move(_chart));
233 }
234
235 virtual bool content(int, const String&) override
236 {
237 return false; // invalid content
238 }
239
240 virtual std::shared_ptr<MarkupParser> markup(int, const String&, const String& name) override
241 {
242 return DimensionalChartHelper<RootMesh_, RootMesh_::world_dim>::markup(name, _chart);
243 }
244
245 }; // class ChartParser<...>
246
247 template<int num_coords_, typename Coord_>
248 class VerticesParser :
249 public Xml::MarkupParser
250 {
251 public:
252 typedef VertexSet<num_coords_, Coord_> VertexSetType;
253
254 protected:
255 VertexSetType& _vertex_set;
256 Index _read;
257
258 public:
259 explicit VerticesParser(VertexSetType& vertex_set) :
260 _vertex_set(vertex_set),
261 _read(0)
262 {
263 }
264
265 virtual bool attribs(std::map<String,bool>&) const override
266 {
267 return true;
268 }
269
270 virtual void create(int iline, const String& sline, const String&, const std::map<String, String>&, bool closed) override
271 {
272 if(closed)
273 throw Xml::GrammarError(iline, sline, "Invalid closed markup");
274 }
275
276 virtual void close(int iline, const String& sline) override
277 {
278 // ensure that we have read all vertices
279 if(_read < _vertex_set.get_num_vertices())
280 throw Xml::GrammarError(iline, sline, "Invalid terminator; expected point");
281 }
282
283 virtual std::shared_ptr<MarkupParser> markup(int, const String&, const String&) override
284 {
285 // no children allowed
286 return nullptr;
287 }
288
289 virtual bool content(int iline, const String& sline) override
290 {
291 // make sure that we do not read more points than expected
292 if(_read >= _vertex_set.get_num_vertices())
293 throw Xml::ContentError(iline, sline, "Invalid content; expected terminator");
294
295 // split line by whitespaces
296 std::deque<String> scoords = sline.split_by_whitespaces();
297
298 // check size
299 if(scoords.size() != std::size_t(num_coords_))
300 throw Xml::ContentError(iline, sline, "Invalid number of coordinates");
301
302 // get our current vertex
303 auto& vtx = _vertex_set[_read];
304
305 // try to parse all coords
306 for(int i(0); i < num_coords_; ++i)
307 {
308 if(!scoords.at(std::size_t(i)).parse(vtx[i]))
309 throw Xml::ContentError(iline, sline, "Failed to parse vertex coordinate");
310 }
311
312 // okay, another point done
313 ++_read;
314
315 return true;
316 }
317 };
318
319 namespace Intern
320 {
321 template<typename Shape_, int dim_ = Shape_::dimension>
322 struct TopoParseHelper
323 {
324 template<typename TopoParser_>
325 static void init_topo(TopoParser_& tp, IndexSetHolder<Shape_>& ish, int dim)
326 {
327 if(dim_ == dim)
328 tp.init_idx_set(ish.template get_index_set<dim_, 0>(), dim_);
329 else
330 TopoParseHelper<Shape_, dim_-1>::init_topo(tp, ish, dim);
331 }
332 };
333
334 template<typename Shape_>
335 struct TopoParseHelper<Shape_, 0>
336 {
337 template<typename TopoParser_>
338 static void init_topo(TopoParser_&, IndexSetHolder<Shape_>&, int)
339 {
340 XABORTM("Thou shall not arrive here");
341 }
342 };
343
344 template<typename Shape_, int dim_ = Shape_::dimension>
345 struct MappParseHelper
346 {
347 template<typename MappParser_>
348 static void init_mapp(MappParser_& mp, TargetSetHolder<Shape_>& tsh, int dim)
349 {
350 if(dim_ == dim)
351 mp.init_trg_set(tsh.template get_target_set<dim_>(), dim_);
352 else
353 MappParseHelper<Shape_, dim_-1>::init_mapp(mp, tsh, dim);
354 }
355 };
356
357 template<typename Shape_>
358 struct MappParseHelper<Shape_, 0>
359 {
360 template<typename MappParser_>
361 static void init_mapp(MappParser_& mp, TargetSetHolder<Shape_>& tsh, int)
362 {
363 mp.init_trg_set(tsh.template get_target_set<0>(), 0);
364 }
365 };
366 } // namespace Intern
367
368 template<typename Shape_>
369 class TopologyParser :
370 public Xml::MarkupParser
371 {
372 public:
373 typedef IndexSetHolder<Shape_> TopologyType;
374
375 protected:
376 TopologyType& _topology;
377 std::deque<int>& _have_topology;
378 Index* _indices;
379 Index _my_dim;
380 Index _num_idx;
381 Index _bound;
382 Index _count;
383 Index _read;
384
385 public:
386 template<int num_idx_>
387 void init_idx_set(IndexSet<num_idx_>& idx_set, int dim)
388 {
389 _indices = reinterpret_cast<Index*>(idx_set.get_indices());
390 _my_dim = Index(dim);
391 _num_idx = Index(num_idx_);
392 _bound = idx_set.get_index_bound();
393 _count = idx_set.get_num_entities();
394 _read = Index(0);
395 }
396
397 public:
398 explicit TopologyParser(TopologyType& topology, std::deque<int>& have_topology) :
399 _topology(topology),
400 _have_topology(have_topology),
401 _indices(nullptr),
402 _my_dim(0),
403 _num_idx(0),
404 _bound(0),
405 _count(0),
406 _read(0)
407 {
408 }
409
410 virtual bool attribs(std::map<String,bool>& attrs) const override
411 {
412 attrs.emplace("dim", true);
413 return true;
414 }
415
416 virtual void create(int iline, const String& sline, const String&, const std::map<String, String>& attrs, bool closed) override
417 {
418 if(closed)
419 throw Xml::GrammarError(iline, sline, "Invalid closed markup");
420
421 // parse dimension
422 if(!attrs.find("dim")->second.parse(_my_dim))
423 throw Xml::ContentError(iline, sline, "Failed to parse 'dim' attribute");
424
425 // make sure that the dimension is not out-of-bounds
426 if((_my_dim > Index(_have_topology.size())) || (_my_dim == Index(0)))
427 throw Xml::ContentError(iline, sline, "Invalid topology dimension");
428
429 // make sure that we did not have that topology yet
430 if(_have_topology.at(_my_dim-1) != 0)
431 throw Xml::ContentError(iline, sline, "Multiple topology for dimension " + stringify(_my_dim));
432 _have_topology.at(_my_dim-1) = 1;
433
434 // initialize the corresponding topology:
435 Intern::TopoParseHelper<Shape_>::init_topo(*this, _topology, int(_my_dim));
436 }
437
438 virtual void close(int iline, const String& sline) override
439 {
440 // ensure that we have read all index tuples
441 if(_read < _count)
442 throw Xml::GrammarError(iline, sline, "Invalid terminator; expected index tuple");
443 }
444
445 virtual std::shared_ptr<MarkupParser> markup(int, const String&, const String&) override
446 {
447 // no children allowed
448 return nullptr;
449 }
450
451 virtual bool content(int iline, const String& sline) override
452 {
453 // make sure that we do not read more points than expected
454 if(_read >= _count)
455 throw Xml::ContentError(iline, sline, "Invalid content; expected terminator");
456
457 // split line by whitespaces
458 std::deque<String> sidx = sline.split_by_whitespaces();
459
460 // check size
461 if(sidx.size() != std::size_t(_num_idx))
462 throw Xml::ContentError(iline, sline, "Invalid number of indices");
463
464 // parse
465 for(Index i(0); i < _num_idx; ++i)
466 {
467 Index& idx = _indices[_read*_num_idx+i];
468
469 // try to parse
470 if(!sidx.at(i).parse(idx))
471 throw Xml::ContentError(iline, sline, "Failed to parse index");
472
473 // check for out-of-bounds
474 if(idx >= _bound)
475 throw Xml::ContentError(iline, sline, "Index out of bounds");
476 }
477
478 // okay, another one processed
479 ++_read;
480
481 return true;
482 }
483 };
484
485 template<typename Shape_>
486 class MappingParser :
487 public Xml::MarkupParser
488 {
489 public:
490 typedef TargetSetHolder<Shape_> MappingType;
491
492 protected:
493 MappingType& _mapping;
494 std::deque<int>& _have_mapping;
495 Index* _indices;
496 Index _my_dim;
497 Index _count;
498 Index _read;
499
500 public:
501 void init_trg_set(TargetSet& trg_set, int dim)
502 {
503 _indices = trg_set.get_indices();
504 _my_dim = Index(dim);
505 _count = trg_set.get_num_entities();
506 }
507
508 public:
509 explicit MappingParser(MappingType& mapping, std::deque<int>& have_mapping) :
510 _mapping(mapping),
511 _have_mapping(have_mapping),
512 _indices(nullptr),
513 _my_dim(0),
514 _count(0),
515 _read(0)
516 {
517 }
518
519 virtual bool attribs(std::map<String,bool>& attrs) const override
520 {
521 attrs.emplace("dim", true);
522 return true;
523 }
524
525 virtual void create(int iline, const String& sline, const String&, const std::map<String, String>& attrs, bool closed) override
526 {
527 if(closed)
528 throw Xml::GrammarError(iline, sline, "Invalid closed markup");
529
530 // parse dimension
531 if(!attrs.find("dim")->second.parse(_my_dim))
532 throw Xml::ContentError(iline, sline, "Failed to parse 'dim' attribute");
533
534 // make sure that the dimension is not out-of-bounds
535 if((_my_dim > Index(_have_mapping.size())))
536 throw Xml::ContentError(iline, sline, "Invalid mapping dimension");
537
538 // make sure that we did not have that topology yet
539 if(_have_mapping.at(_my_dim) != 0)
540 throw Xml::ContentError(iline, sline, "Multiple mapping for dimension " + stringify(_my_dim));
541 _have_mapping.at(_my_dim) = 1;
542
543 // initialize the corresponding mapping:
544 Intern::MappParseHelper<Shape_>::init_mapp(*this, _mapping, int(_my_dim));
545 }
546
547 virtual void close(int iline, const String& sline) override
548 {
549 // ensure that we have read all index tuples
550 if(_read < _count)
551 throw Xml::GrammarError(iline, sline, "Invalid terminator; expected index");
552 }
553
554 virtual std::shared_ptr<MarkupParser> markup(int, const String&, const String&) override
555 {
556 // no children allowed
557 return nullptr;
558 }
559
560 virtual bool content(int iline, const String& sline) override
561 {
562 // make sure that we do not read more points than expected
563 if(_read >= _count)
564 throw Xml::ContentError(iline, sline, "Invalid content; expected terminator");
565
566 // try to parse index
567 if(!sline.parse(_indices[_read]))
568 throw Xml::ContentError(iline, sline, "Failed to parse index");
569
570 // okay, another one processed
571 ++_read;
572
573 return true;
574 }
575 };
576
577 template<typename MeshPart_, typename DataType_ = typename MeshPart_::AttributeDataType>
578 class AttributeParser :
579 public Xml::MarkupParser
580 {
581 public:
582 typedef AttributeSet<DataType_> AttribType;
583
584 protected:
585 MeshPart_& _mesh_part;
586 std::unique_ptr<AttribType> _attrib;
587 Index _my_dim;
588 Index _count;
589 Index _read;
590 String _my_name;
591
592 public:
593 explicit AttributeParser(MeshPart_& mesh_part) :
594 _mesh_part(mesh_part),
595 _attrib(),
596 _my_dim(0),
597 _count(0),
598 _read(0)
599 {
600 }
601
602 virtual ~AttributeParser()
603 {
604 }
605
606 virtual bool attribs(std::map<String,bool>& attrs) const override
607 {
608 attrs.emplace("dim", true);
609 attrs.emplace("name", true);
610 return true;
611 }
612
613 virtual void create(int iline, const String& sline, const String&, const std::map<String, String>& attrs, bool closed) override
614 {
615 if(closed)
616 throw Xml::GrammarError(iline, sline, "Invalid closed markup");
617
618 // parse dimension
619 if(!attrs.find("dim")->second.parse(_my_dim))
620 throw Xml::ContentError(iline, sline, "Failed to parse 'dim' attribute");
621
622 // make sure that the dimension is valid
623 if(_my_dim == Index(0))
624 throw Xml::ContentError(iline, sline, "Invalid attribute dimension");
625
626 // fetch name
627 _my_name = attrs.find("name")->second;
628
629 // create mesh attribute
630 _count = _mesh_part.get_num_entities(0);
631 _attrib.reset(new AttribType(_count, int(_my_dim)));
632 }
633
634 virtual void close(int iline, const String& sline) override
635 {
636 // ensure that we have read all index tuples
637 if(_read < _count)
638 throw Xml::GrammarError(iline, sline, "Invalid terminator; expected index");
639
640 // okay, add attribute to mesh part
641 _mesh_part.add_attribute(std::move(_attrib), _my_name);
642 }
643
644 virtual std::shared_ptr<MarkupParser> markup(int, const String&, const String&) override
645 {
646 // no children allowed
647 return nullptr;
648 }
649
650 virtual bool content(int iline, const String& sline) override
651 {
652 // make sure that we do not read more points than expected
653 if(_read >= _count)
654 throw Xml::ContentError(iline, sline, "Invalid content; expected terminator");
655
656 // split line by whitespaces
657 std::deque<String> svals = sline.split_by_whitespaces();
658
659 // check size
660 if(svals.size() != std::size_t(_my_dim))
661 throw Xml::ContentError(iline, sline, "Invalid number of values");
662
663 // try to parse all coords
664 for(int i(0); i < int(_my_dim); ++i)
665 {
666 if(!svals.at(std::size_t(i)).parse(_attrib->operator()(_read,i)))
667 throw Xml::ContentError(iline, sline, "Failed to parse value");
668 }
669
670 // okay, another one processed
671 ++_read;
672
673 return true;
674 }
675 };
676
677 template<typename Mesh_>
678 class MeshParser;
679
680 template<typename Shape_, int num_coords_, typename Coord_>
681 class MeshParser<ConformalMesh<Shape_, num_coords_, Coord_>> :
682 public Xml::MarkupParser
683 {
684 public:
685 typedef ConformalMesh<Shape_, num_coords_, Coord_> MeshType;
686
687 protected:
688 RootMeshNode<MeshType>& _root_node;
689 std::unique_ptr<MeshType> _mesh;
690 bool _have_verts;
691 std::deque<int> _have_topology;
692 std::vector<Index> _sizes;
693
694 template<int shape_dim_>
695 static String aux_shape_string(const Shape::Hypercube<shape_dim_>&)
696 {
697 return "hypercube";
698 }
699
700 template<int shape_dim_>
701 static String aux_shape_string(const Shape::Simplex<shape_dim_>&)
702 {
703 return "simplex";
704 }
705
706 public:
707 explicit MeshParser(RootMeshNode<MeshType>& root_node) :
708 _root_node(root_node),
709 _mesh(nullptr),
710 _have_verts(false)
711 {
712 }
713
714 virtual ~MeshParser()
715 {
716 }
717
718 virtual bool attribs(std::map<String,bool>& attrs) const override
719 {
720 attrs.emplace("type", true);
721 attrs.emplace("size", true);
722 return true;
723 }
724
725 virtual void create(int iline, const String& sline, const String&, const std::map<String, String>& attrs, bool closed) override
726 {
727 if(closed)
728 throw Xml::GrammarError(iline, sline, "Invalid closed markup");
729
730 // fetch mesh type substrings
731 std::deque<String> stype = attrs.find("type")->second.split_by_string(":");
732
733 // validate mesh type
734 if(stype.size() != std::size_t(4))
735 throw Xml::ContentError(iline, sline, "Invalid mesh type attribue");
736 if(stype.at(0) != "conformal")
737 throw Xml::ContentError(iline, sline, "Invalid mesh type; expected 'conformal'");
738 String sshape = aux_shape_string(Shape_());
739 if(stype.at(1) != sshape)
740 throw Xml::ContentError(iline, sline, "Invalid mesh shape type; expected '" + sshape + "'");
741 int ishape_dim(0), iworld_dim(0);
742 if(!stype.at(2).parse(ishape_dim))
743 throw Xml::ContentError(iline, sline, "Failed to parse mesh shape dimension");
744 if(ishape_dim != Shape_::dimension)
745 throw Xml::ContentError(iline, sline, "Invalid mesh shape dimension");
746 if(!stype.at(3).parse(iworld_dim))
747 throw Xml::ContentError(iline, sline, "Failed to parse mesh world dimension");
748 if(iworld_dim != num_coords_)
749 throw Xml::ContentError(iline, sline, "Invalid mesh world dimension");
750
751 // okay, the mesh type seems fine
752
753 // split sizes
754 std::deque<String> ssize = attrs.find("size")->second.split_by_whitespaces();
755 if(ssize.size() != std::size_t(Shape_::dimension+1))
756 throw Xml::ContentError(iline, sline, "Invalid mesh size count");
757
758 // parse sizes
759 _sizes.resize(ssize.size());
760 for(std::size_t i(0); i <= std::size_t(Shape_::dimension); ++i)
761 {
762 if(!ssize.at(i).parse(_sizes.at(i)))
763 throw Xml::ContentError(iline, sline, "Failed to parse mesh size");
764 }
765
766 // try to create the mesh
767 _mesh.reset(new MeshType(_sizes.data()));
768
769 // initialize
770 _have_verts = false;
771 _have_topology.resize(std::size_t(Shape_::dimension), 0);
772 }
773
774 virtual void close(int iline, const String& sline) override
775 {
776 // do we have coords?
777 if(!_have_verts)
778 throw Xml::GrammarError(iline, sline, "Mesh has no Vertices");
779
780 // make sure we have the whole topology
781 for(std::size_t i(0); i < _have_topology.size(); ++i)
782 {
783 if(_have_topology.at(i) == 0)
784 throw Xml::GrammarError(iline, sline, "Missing topology for dimension " + stringify(i+1));
785 }
786
787 // okay, the mesh is complete
788
789 // compute remaining topology now
790 RedundantIndexSetBuilder<Shape_>::compute(*_mesh->get_topology());
791
792 // add to mesh node
793 _root_node.set_mesh(std::move(_mesh));
794 }
795
796 virtual std::shared_ptr<Xml::MarkupParser> markup(int iline, const String& sline, const String& name) override
797 {
798 // vertices?
799 if(name == "Vertices")
800 {
801 if(_have_verts)
802 throw Xml::GrammarError(iline, sline, "More than one Vertices block in mesh");
803
804 // okay, create a vertex parser
805 _have_verts = true;
806 return std::make_shared<VerticesParser<num_coords_, Coord_>>(_mesh->get_vertex_set());
807 }
808
809 // topology?
810 if(name == "Topology")
811 {
812 // create a topology parser
813 return std::make_shared<TopologyParser<Shape_>>(*_mesh->get_topology(), _have_topology);
814 }
815
816 // invalid
817 return nullptr;
818 }
819
820 virtual bool content(int, const String&) override
821 {
822 return false; // no content allowed
823 }
824 };
825
826 template<typename Mesh_>
827 class MeshPartParser;
828
829 template<typename Shape_, int num_coords_, typename Coord_>
830 class MeshPartParser<ConformalMesh<Shape_, num_coords_, Coord_>> :
831 public Xml::MarkupParser
832 {
833 public:
834 typedef ConformalMesh<Shape_, num_coords_, Coord_> MeshType;
835 typedef MeshPart<MeshType> MeshPartType;
836 typedef Atlas::ChartBase<MeshType> ChartType;
837 enum class TopoType
838 {
839 none,
840 full,
841 parent
842 };
843
844 protected:
845 RootMeshNode<MeshType>& _root_node;
846 MeshNodeLinker<MeshType>& _linker;
847 std::unique_ptr<MeshPartType> _mesh_part;
848 ChartType* _chart;
849 TopoType _topo_type;
850 String _name, _parent, _chart_name;
851 std::deque<int> _have_topology;
852 std::deque<int> _have_mapping;
853 std::vector<Index> _sizes;
854
855 public:
856 explicit MeshPartParser(RootMeshNode<MeshType>& root_node, MeshNodeLinker<MeshType>& linker) :
857 _root_node(root_node),
858 _linker(linker),
859 _mesh_part(),
860 _chart(nullptr),
861 _topo_type(TopoType::none)
862 {
863 }
864
865 virtual ~MeshPartParser()
866 {
867 }
868
869 virtual bool attribs(std::map<String,bool>& attrs) const override
870 {
871 attrs.emplace("name", true);
872 attrs.emplace("parent", true);
873 attrs.emplace("size", true);
874 attrs.emplace("topology", true);
875 attrs.emplace("chart", false);
876 return true;
877 }
878
879 virtual void create(int iline, const String& sline, const String&, const std::map<String, String>& attrs, bool closed) override
880 {
881 if(closed)
882 throw Xml::GrammarError(iline, sline, "Invalid closed markup");
883
884 // fetch name and parent
885 _name = attrs.find("name")->second;
886 _parent = attrs.find("parent")->second;
887
888 // make sure that the mesh part does not already exist in the mesh node
889 if(_root_node.find_mesh_part(_name) != nullptr)
890 throw Xml::ContentError(iline, sline, String("Mesh Part '") + _name + "' already exists in mesh node");
891
892 // fetch chart
893 {
894 auto it = attrs.find("chart");
895 if(it != attrs.end())
896 {
897 // try to find chart
898 _chart_name = it->second;
899 _linker.meshpart_link_to_chart(_name, _chart_name);
900 }
901 }
902
903 // make sure the parent is root
904 if(_parent != "root")
905 throw Xml::ContentError(iline, sline, "Invalid mesh part parent; only 'root' is accepted");
906
907 // get topology type
908 String stopo_type = attrs.find("topology")->second;
909 if(stopo_type == "none")
910 _topo_type = TopoType::none;
911 else if(stopo_type == "full")
912 _topo_type = TopoType::full;
913 else if(stopo_type == "parent")
914 {
915 _topo_type = TopoType::parent;
916 _linker.meshpart_deduct_topology(_name);
917 }
918 else
919 throw Xml::ContentError(iline, sline, "Invalid topology attribute '" + stopo_type + "'");
920
921 // split sizes
922 std::deque<String> ssize = attrs.find("size")->second.split_by_whitespaces();
923 if(ssize.size() > std::size_t(Shape_::dimension+1))
924 throw Xml::ContentError(iline, sline, "Invalid mesh part size count");
925
926 // parse sizes
927 _sizes.resize(std::size_t(Shape_::dimension+1), Index(0));
928 for(std::size_t i(0); i < ssize.size(); ++i)
929 {
930 if(!ssize.at(i).parse(_sizes.at(i)))
931 throw Xml::ContentError(iline, sline, "Failed to parse mesh part size");
932 }
933
934 // try to create the mesh part
935 _mesh_part.reset(new MeshPartType(_sizes.data(), _topo_type != TopoType::none));
936
937 // initialize
938 _have_topology.resize(std::size_t(Shape_::dimension), 0);
939 _have_mapping.resize(std::size_t(Shape_::dimension+1), 0);
940 }
941
942 virtual void close(int iline, const String& sline) override
943 {
944 // make sure we have all mappings
945 for(std::size_t i(0); i < _have_mapping.size(); ++i)
946 {
947 if((_have_mapping.at(i) == 0) && (_sizes.at(i) > Index(0)))
948 throw Xml::GrammarError(iline, sline, "Missing mapping for dimension " + stringify(i));
949 }
950
951 if(_topo_type == TopoType::full)
952 {
953 // make sure we have the whole topology
954 bool topo_all(true);
955 for(std::size_t i(0); i < _have_topology.size(); ++i)
956 {
957 // Note: there may be no entities of this dimension here
958 if(_sizes.at(i+1) > 0)
959 topo_all = topo_all && (_have_topology.at(i) != 0);
960 }
961
962 // Make sure we have either all or none topology entires
963 if(!topo_all)
964 throw Xml::GrammarError(iline, sline, "Incomplete topology");
965
966 // compute remaining topology now
967 if(topo_all)
968 RedundantIndexSetBuilder<Shape_>::compute(*_mesh_part->get_topology());
969 }
970 else if(_topo_type == TopoType::parent)
971 {
972 // Note: this has been outsourced to the MeshNodeLinker class!
973 // Create the MeshPart's topology from the parent mesh's topology if told so
974 //_mesh_part->deduct_topology(*(_root_node.get_mesh()->get_topology()));
975 //_linker.meshpart_deduct_topology(_name);
976 }
977
978 // Finally, insert mesh part into root node
979 _root_node.add_mesh_part(_name, std::move(_mesh_part)/*, _chart_name, _chart*/);
980 }
981
982 virtual std::shared_ptr<Xml::MarkupParser> markup(int iline, const String& sline, const String& name) override
983 {
984 // mapping?
985 if(name == "Mapping")
986 {
987 // create mapping parser
988 return std::make_shared<MappingParser<Shape_>>(_mesh_part->get_target_set_holder(), _have_mapping);
989 }
990
991 // topology?
992 if(name == "Topology")
993 {
994 if(_topo_type == TopoType::none)
995 throw Xml::ContentError(iline, sline, "Unexpected Topology found");
996
997 // create a topology parser
998 return std::make_shared<TopologyParser<Shape_>>(*_mesh_part->get_topology(), _have_topology);
999 }
1000
1001 // attribute?
1002 if(name == "Attribute")
1003 {
1004 return std::make_shared<AttributeParser<MeshPartType>>(*_mesh_part);
1005 }
1006
1007 // invalid
1008 return nullptr;
1009 }
1010
1011 virtual bool content(int, const String&) override
1012 {
1013 return false; // no content allowed
1014 }
1015 };
1016
1017 class PatchParser :
1018 public Xml::MarkupParser
1019 {
1020 protected:
1021 Adjacency::DynamicGraph& _patches;
1022 Index _rank;
1023 Index _size;
1024 Index _read;
1025
1026 public:
1027 explicit PatchParser(Adjacency::DynamicGraph& patches) :
1028 _patches(patches),
1029 _rank(~Index(0)),
1030 _size(~Index(0)),
1031 _read(Index(0))
1032 {
1033 }
1034
1035 virtual bool attribs(std::map<String,bool>& attrs) const override
1036 {
1037 attrs.emplace("rank", true);
1038 attrs.emplace("size", true);
1039 return true;
1040 }
1041
1042 virtual void create(int iline, const String& sline, const String&, const std::map<String, String>& attrs, bool) override
1043 {
1044 // try to parse rank and size
1045 if(!attrs.find("rank")->second.parse(_rank))
1046 throw Xml::ContentError(iline, sline, "Cannot parse patch rank index");
1047 if(!attrs.find("size")->second.parse(_size))
1048 throw Xml::ContentError(iline, sline, "Cannot parse patch size");
1049
1050 // ensure that the rank is valid
1051 if(_rank >= _patches.get_num_nodes_domain())
1052 throw Xml::ContentError(iline, sline, "Patch rank index is out of bounds");
1053 }
1054
1055 virtual void close(int iline, const String& sline) override
1056 {
1057 if(_read < _size)
1058 throw Xml::GrammarError(iline, sline, "Invalid terminator; expected index");
1059 }
1060
1061 virtual bool content(int iline, const String& sline) override
1062 {
1063 // make sure that we do not read more points than expected
1064 if(_read >= _size)
1065 throw Xml::ContentError(iline, sline, "Invalid content; expected terminator");
1066
1067 // try to parse element index
1068 Index elem(0);
1069 if(!sline.parse(elem))
1070 throw Xml::ContentError(iline, sline, "Failed to parse element index");
1071
1072 if(elem >= _patches.get_num_nodes_image())
1073 throw Xml::ContentError(iline, sline, "Patch element index is out of bounds");
1074
1075 // insert adjacency
1076 _patches.insert(_rank, elem);
1077
1078 // okay, another one processed
1079 ++_read;
1080
1081 return true;
1082 }
1083
1084 virtual std::shared_ptr<MarkupParser> markup(int, const String&, const String&) override
1085 {
1086 return nullptr;
1087 }
1088 }; // class PatchParser
1089
1090 class PartitionParser :
1091 public Xml::MarkupParser
1092 {
1093 protected:
1094 PartitionSet& _part_set;
1095 String _name;
1096 int _prio;
1097 int _level;
1098 int _num_ranks, _num_elems;
1099 Adjacency::DynamicGraph _patches;
1100
1101 public:
1102 explicit PartitionParser(PartitionSet& part_set) :
1103 _part_set(part_set),
1104 _name(),
1105 _prio(0),
1106 _level(0),
1107 _num_ranks(0),
1108 _num_elems(0),
1109 _patches()
1110 {
1111 }
1112
1113 virtual bool attribs(std::map<String,bool>& attrs) const override
1114 {
1115 attrs.emplace("size", true);
1116 attrs.emplace("name", false);
1117 attrs.emplace("priority", false);
1118 attrs.emplace("level", false);
1119 return true;
1120 }
1121
1122 virtual void create(int iline, const String& sline, const String&, const std::map<String, String>& attrs, bool) override
1123 {
1124 // split sizes
1125 std::deque<String> ssize = attrs.find("size")->second.split_by_whitespaces();
1126 if(ssize.size() != std::size_t(2))
1127 throw Xml::ContentError(iline, sline, "Invalid partition size");
1128
1129 // parse sizes
1130 if(!ssize.front().parse(_num_ranks))
1131 throw Xml::ContentError(iline, sline, "Failed to parse partition rank count");
1132 if(!ssize.back().parse(_num_elems))
1133 throw Xml::ContentError(iline, sline, "Failed to parse partition element count");
1134
1135 // fetch name
1136 {
1137 auto it = attrs.find("name");
1138 if(it != attrs.end())
1139 _name = it->second;
1140 }
1141
1142 // fetch priority
1143 {
1144 auto it = attrs.find("priority");
1145 if(it != attrs.end())
1146 {
1147 if(!it->second.parse(_prio))
1148 throw Xml::ContentError(iline, sline, "Cannot parse partition priority");
1149 }
1150 }
1151
1152 // fetch level
1153 {
1154 auto it = attrs.find("level");
1155 if(it != attrs.end())
1156 {
1157 if(!it->second.parse(_level))
1158 throw Xml::ContentError(iline, sline, "Cannot parse partition level");
1159 if(_level < 0)
1160 throw Xml::ContentError(iline, sline, "Invalid negative partition level");
1161 }
1162 }
1163
1164 // okay, let's create a new partition
1165 _patches = Adjacency::DynamicGraph(Index(_num_ranks), Index(_num_elems));
1166 }
1167
1168 virtual void close(int, const String&) override
1169 {
1170 // add our partition to the set
1171 _part_set.add_partition(Partition(_patches, _name, _prio, _level));
1172 }
1173
1174 virtual bool content(int, const String&) override
1175 {
1176 return false;
1177 }
1178
1179 virtual std::shared_ptr<MarkupParser> markup(int, const String&, const String& name) override
1180 {
1181 if(name == "Patch")
1182 return std::make_shared<PatchParser>(_patches);
1183
1184 return nullptr;
1185 }
1186 }; // class PartitionParser
1187
1188 template<typename RootMesh_>
1189 class MeshNodeParser :
1190 public Xml::MarkupParser
1191 {
1192 public:
1193 typedef RootMesh_ RootMeshType;
1194 typedef RootMeshNode<RootMesh_> RootMeshNodeType;
1195 typedef MeshAtlas<RootMesh_> MeshAtlasType;
1196
1197 protected:
1199 RootMeshNodeType& _root_node;
1201 MeshAtlasType& _mesh_atlas;
1203 PartitionSet* _part_set;
1205 MeshNodeLinker<RootMesh_>& _linker;
1207 String _mesh_decl;
1208
1209 public:
1210 explicit MeshNodeParser(RootMeshNodeType& root_node, MeshAtlasType& mesh_atlas, PartitionSet* part_set, MeshNodeLinker<RootMesh_>& linker) :
1211 _root_node(root_node),
1212 _mesh_atlas(mesh_atlas),
1213 _part_set(part_set),
1214 _linker(linker),
1215 _mesh_decl()
1216 {
1217 }
1218
1219 virtual bool attribs(std::map<String,bool>& attrs) const override
1220 {
1221 attrs.emplace("version", true); // mandatory
1222 attrs.emplace("mesh", false); // optional
1223 return true;
1224 }
1225
1226 virtual void create(int iline, const String& sline, const String& name, const std::map<String, String>& attrs, bool) override
1227 {
1228 // verify marker name
1229 if(name != "FeatMeshFile")
1230 throw Xml::GrammarError(iline, sline, "Invalid root markup; expected '<FeatMeshFile ...>'");
1231
1232 // verify file version
1233 int version(0);
1234 if(!attrs.find("version")->second.parse(version))
1235 throw Xml::ContentError(iline, sline, "Cannot parse file version");
1236 if(version != 1)
1237 throw Xml::ContentError(iline, sline, "Invalid file version; expected 1");
1238
1239 // have a mesh declaration?
1240 auto it = attrs.find("mesh");
1241 if(it != attrs.end())
1242 {
1243 // okay, store the declarator
1244 _mesh_decl = it->second;
1245 }
1246 }
1247
1248 virtual void close(int, const String&) override
1249 {
1250 }
1251
1252 virtual bool content(int, const String&) override
1253 {
1254 return false; // no content allowed
1255 }
1256
1257 virtual std::shared_ptr<MarkupParser> markup(int iline, const String& sline, const String& name) override
1258 {
1259 // check for valid markups
1260 if(name == "Info")
1261 {
1262 // valid info markup
1263 return std::make_shared<Xml::DummyParser>();
1264 }
1265 if(name == "Chart")
1266 {
1267 // create a chart parser
1268 return std::make_shared<ChartParser<RootMeshType>>(_mesh_atlas);
1269 }
1270 if(name == "Mesh")
1271 {
1272 if(_root_node.get_mesh() != nullptr)
1273 {
1274 // that's the second one!
1275 throw Xml::GrammarError(iline, sline, "Invalid second Mesh in file");
1276 }
1277
1278 // valid mesh markup
1279 return std::make_shared<MeshParser<RootMeshType>>(_root_node);
1280 }
1281 if(name == "MeshPart")
1282 {
1283 // valid meshpart markup
1284 return std::make_shared<MeshPartParser<RootMeshType>>(_root_node, _linker);
1285 }
1286 if(name == "Partition")
1287 {
1288 // valid partition markup
1289 if(_part_set != nullptr)
1290 return std::make_shared<PartitionParser>(*_part_set);
1291 else
1292 {
1293 // the user is not interested in partitions, so create a dummy parser
1294 return std::make_shared<Xml::DummyParser>();
1295 }
1296 }
1297
1298 // anything else is invalid
1299 return nullptr;
1300 }
1301 }; // class MeshNodeParser
1302
1304
1325 {
1326 protected:
1328 std::deque<std::shared_ptr<std::stringstream>> _streams;
1330 std::deque<std::shared_ptr<Xml::Scanner>> _scanners;
1335 // Split up mesh type
1336 ParsedMeshType _mesh_type;
1337 // Split up shape type
1338 ParsedShapeType _shape_type;
1339 // Mesh shape dimension
1340 int _shape_dim;
1341 // Mesh world dimension
1342 int _world_dim;
1343
1344 public:
1346 explicit MeshFileReader() :
1347 _have_root_markup(false),
1349 _mesh_type(ParsedMeshType::unknown),
1350 _shape_type(ParsedShapeType::unknown),
1351 _shape_dim(0),
1352 _world_dim(0)
1353 {
1354 }
1355
1362 explicit MeshFileReader(std::istream& is) :
1363 _have_root_markup(false),
1365 _mesh_type(ParsedMeshType::unknown),
1366 _shape_type(ParsedShapeType::unknown),
1367 _shape_dim(0),
1368 _world_dim(0)
1369 {
1370 // create a new scanner object
1371 _scanners.push_back(std::make_shared<Xml::Scanner>(is));
1372 }
1373
1374 MeshFileReader(const MeshFileReader&) = delete;
1375 MeshFileReader& operator=(const MeshFileReader&) = delete;
1376
1379 {
1380 _scanners.clear();
1381 _streams.clear();
1382 }
1383
1390 void add_stream(std::istream& is)
1391 {
1392 XASSERTM(!_have_root_markup, "cannot add new stream after reading root");
1393
1394 // create a new scanner object
1395 _scanners.push_back(std::make_shared<Xml::Scanner>(is));
1396 }
1397
1410 void add_mesh_files(const Dist::Comm& comm, const std::deque<String>& filenames, String dirpath = "")
1411 {
1412 XASSERTM(!_have_root_markup, "cannot add new stream after reading root");
1413
1414 if(filenames.empty())
1415 return;
1416
1417 // ensure that the directory path ends with a path separator
1418 if(!dirpath.empty())
1419 {
1421#ifdef _WIN32
1422 if((dirpath.back() != '/') && (dirpath.back() != '\\'))
1423 dirpath.push_back('\\');
1424#else
1425 if(dirpath.back() != '/')
1426 dirpath.push_back('/');
1427#endif
1428 }
1429
1430 // read all files
1431 for(std::size_t i(0); i < filenames.size(); ++i)
1432 {
1433 // build file path
1434 String filepath = dirpath + filenames.at(i);
1435
1436 // create a new stream
1437 auto stream = std::make_shared<std::stringstream>();
1438
1439 // read the stream
1440 DistFileIO::read_common(*stream, filepath, comm);
1441
1442 // add stream to deque
1443 _streams.push_back(stream);
1444
1445 // add to mesh reader
1446 add_stream(*_streams.back());
1447 }
1448 }
1449
1459 void add_mesh_files(const std::deque<String>& filenames, String dirpath = "")
1460 {
1462 add_mesh_files(comm, filenames, dirpath);
1463 }
1464
1474 void add_mesh_file(const Dist::Comm& comm, const String& filename)
1475 {
1476 std::deque<String> filenames;
1477 filenames.push_back(filename);
1478 add_mesh_files(comm, filenames);
1479 }
1480
1487 void add_mesh_file(const String& filename)
1488 {
1490 add_mesh_file(comm, filename);
1491 }
1492
1504 {
1505 return _mesh_type_string;
1506 }
1507
1519 {
1520 return _mesh_type;
1521 }
1522
1534 {
1535 return _shape_type;
1536 }
1537
1548 int get_shape_dim() const
1549 {
1550 return _shape_dim;
1551 }
1552
1563 int get_world_dim() const
1564 {
1565 return _world_dim;
1566 }
1567
1572 {
1573 XASSERTM(!_have_root_markup, "root has already been read");
1574
1575 // loop over all scanners
1576 for(auto it = _scanners.begin(); it != _scanners.end(); ++it)
1577 {
1578 // get the scanner
1579 Xml::Scanner& scanner = **it;
1580
1581 // try to read root node
1582 scanner.read_root();
1583
1584 // verify root marker
1585 if(scanner.get_cur_name() != "FeatMeshFile")
1586 scanner.throw_grammar("Invalid mesh file");
1587
1588 // get attributes
1589 const auto& attr = scanner.get_cur_attribs();
1590
1591 // check version attribute
1592 auto it_v = attr.find("version");
1593 if(it_v == attr.end())
1594 scanner.throw_grammar("Mesh file is missing mandatory attribute 'version'");
1595 int iversion(0);
1596 if(!(it_v->second.parse(iversion)))
1597 scanner.throw_grammar("Failed to parse mesh file version attribute");
1598 if(iversion != 1)
1599 scanner.throw_grammar("Invalid mesh file version");
1600
1601 // check mesh attribute
1602 auto it_m = attr.find("mesh");
1603 if(it_m != attr.end())
1604 {
1605 // did we read a mesh type already?
1606 if(!_mesh_type_string.empty())
1607 {
1608 // make sure that the mesh types are identical
1609 XASSERTM(it_m->second == _mesh_type_string, "conflicting mesh types");
1610 }
1611 else
1612 {
1613 // save the mesh type string
1614 _mesh_type_string = it_m->second;
1615
1616 // split up mesh type string
1617 std::deque<String> mts = _mesh_type_string.split_by_string(":");
1618
1619 if(mts.size() != std::size_t(4))
1620 scanner.throw_grammar("Mesh file root markup has invalid 'mesh' attribute");
1621
1622 // check mesh type
1623 if(mts.at(0) == "conformal")
1624 _mesh_type = ParsedMeshType::conformal;
1625 else
1626 scanner.throw_grammar("Invalid 'mesh' attribute mesh type");
1627
1628 // check shape type
1629 if(mts.at(1) == "simplex")
1630 _shape_type = ParsedShapeType::simplex;
1631 else if(mts.at(1) == "hypercube")
1632 _shape_type = ParsedShapeType::hypercube;
1633 else
1634 scanner.throw_grammar("Invalid 'mesh' attribute shape type");
1635
1636 // parse shape dimension
1637 if(!mts.at(2).parse(_shape_dim) || (_shape_dim <= 0))
1638 scanner.throw_content("Invalid 'mesh' attribute shape dimension");
1639
1640 // parse world dimension
1641 if(!mts.at(3).parse(_world_dim) || (_world_dim <= 0))
1642 scanner.throw_content("Invalid 'mesh' attribute world dimension");
1643 }
1644 }
1645
1646 // continue with next stream
1647 }
1648
1649 // alright, root markup read
1650 _have_root_markup = true;
1651 }
1652
1670 template<typename RootMesh_>
1671 void parse(
1673 RootMeshNode<RootMesh_>& root_mesh_node,
1674 MeshAtlas<RootMesh_>& mesh_atlas,
1675 PartitionSet* part_set = nullptr)
1676 {
1677 // read root markup unless it has already been read
1680
1681 // loop over all scanners
1682 for(auto it = _scanners.begin(); it != _scanners.end(); ++it)
1683 {
1684 // create a corresponding parser and scan
1685 (*it)->set_root_parser(std::make_shared<MeshNodeParser<RootMesh_>>(root_mesh_node, mesh_atlas, part_set, linker));
1686 (*it)->scan();
1687 }
1688 }
1689
1704 template<typename RootMesh_>
1705 void parse(
1706 RootMeshNode<RootMesh_>& root_mesh_node,
1707 MeshAtlas<RootMesh_>& mesh_atlas,
1708 PartitionSet* part_set = nullptr)
1709 {
1710 // create linker
1711 MeshNodeLinker<RootMesh_> linker(root_mesh_node, mesh_atlas);
1712
1713 // parse
1714 parse(linker, root_mesh_node, mesh_atlas, part_set);
1715
1716 // execute linker
1717 linker.execute();
1718 }
1719
1735 template<typename RootMesh_>
1736 std::unique_ptr<RootMeshNode<RootMesh_>> parse(
1737 MeshAtlas<RootMesh_>& mesh_atlas,
1738 PartitionSet* part_set = nullptr)
1739 {
1740 // create new root mesh node
1741 std::unique_ptr<RootMeshNode<RootMesh_>> root_mesh_node =
1742 RootMeshNode<RootMesh_>::make_unique(nullptr, &mesh_atlas);
1743
1744 // parse
1745 this->parse(*root_mesh_node, mesh_atlas, part_set);
1746
1747 // return root mesh node
1748 return root_mesh_node;
1749 }
1750 }; // class MeshFileReader
1751
1766 template<typename RootMesh_, int world_dim>
1768 {
1769 static_assert(RootMesh_::world_dim == world_dim, "Nonmatching world_dim.");
1770
1781 static std::shared_ptr<Xml::MarkupParser> markup(const String& DOXY(name),
1782 std::unique_ptr<Atlas::ChartBase<RootMesh_>>& DOXY(chart))
1783 {
1784 return nullptr;
1785 }
1786 };
1787
1789 template<typename RootMesh_>
1790 struct DimensionalChartHelper<RootMesh_,2>
1791 {
1792 static std::shared_ptr<Xml::MarkupParser> markup(const String& name,
1793 std::unique_ptr<Atlas::ChartBase<RootMesh_>>& chart)
1794 {
1795 if(name == "Circle")
1796 return std::make_shared<Atlas::CircleChartParser<RootMesh_>>(chart);
1797 if(name == "Bezier")
1798 return std::make_shared<Atlas::BezierChartParser<RootMesh_>>(chart);
1799
1800 return nullptr;
1801 }
1802 };
1803
1804 template<typename RootMesh_>
1805 struct DimensionalChartHelper<RootMesh_,3>
1806 {
1807 static std::shared_ptr<Xml::MarkupParser> markup(const String& name,
1808 std::unique_ptr<Atlas::ChartBase<RootMesh_>>& chart)
1809 {
1810 if(name == "Sphere")
1811 return std::make_shared<Atlas::SphereChartParser<RootMesh_>>(chart);
1812 if(name == "SurfaceMesh")
1813 return std::make_shared<Atlas::SurfaceMeshChartParser<RootMesh_>>(chart);
1814 if(name == "Extrude")
1815 return std::make_shared<Atlas::ExtrudeChartParser<RootMesh_>>(chart);
1816
1817 return nullptr;
1818 }
1819 };
1821
1822#ifdef FEAT_EICKT
1823 extern template class MeshNodeLinker<ConformalMesh<Shape::Simplex<2>, 2, Real>>;
1824 extern template class MeshNodeLinker<ConformalMesh<Shape::Simplex<3>, 3, Real>>;
1825 extern template class MeshNodeLinker<ConformalMesh<Shape::Hypercube<2>, 2, Real>>;
1826 extern template class MeshNodeLinker<ConformalMesh<Shape::Hypercube<3>, 3, Real>>;
1827
1828 extern template void MeshFileReader::parse<ConformalMesh<Shape::Simplex<2>, 2, Real>>(
1829 MeshNodeLinker<ConformalMesh<Shape::Simplex<2>, 2, Real>>&,
1830 RootMeshNode<ConformalMesh<Shape::Simplex<2>, 2, Real>>&,
1831 MeshAtlas<ConformalMesh<Shape::Simplex<2>, 2, Real>>&,
1832 PartitionSet*);
1833 extern template void MeshFileReader::parse<ConformalMesh<Shape::Simplex<3>, 3, Real>>(
1834 MeshNodeLinker<ConformalMesh<Shape::Simplex<3>, 3, Real>>&,
1835 RootMeshNode<ConformalMesh<Shape::Simplex<3>, 3, Real>>&,
1836 MeshAtlas<ConformalMesh<Shape::Simplex<3>, 3, Real>>&,
1837 PartitionSet*);
1838 extern template void MeshFileReader::parse<ConformalMesh<Shape::Hypercube<2>, 2, Real>>(
1839 MeshNodeLinker<ConformalMesh<Shape::Hypercube<2>, 2, Real>>&,
1840 RootMeshNode<ConformalMesh<Shape::Hypercube<2>, 2, Real>>&,
1841 MeshAtlas<ConformalMesh<Shape::Hypercube<2>, 2, Real>>&,
1842 PartitionSet*);
1843 extern template void MeshFileReader::parse<ConformalMesh<Shape::Hypercube<3>, 3, Real>>(
1844 MeshNodeLinker<ConformalMesh<Shape::Hypercube<3>, 3, Real>>&,
1845 RootMeshNode<ConformalMesh<Shape::Hypercube<3>, 3, Real>>&,
1846 MeshAtlas<ConformalMesh<Shape::Hypercube<3>, 3, Real>>&,
1847 PartitionSet*);
1848#endif // FEAT_EICKT
1849 } // namespace Geometry
1850} // namespace FEAT
#define XABORTM(msg)
Abortion macro definition with custom message.
Definition: assertion.hpp:192
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Definition: assertion.hpp:263
Communicator class.
Definition: dist.hpp:1657
static Comm world()
Returns a copy of the world communicator.
Definition: dist.cpp:432
static void read_common(std::stringstream &stream, const String &filename, const Dist::Comm &comm, int root_rank=0)
Reads a common text file for all ranks.
Base exception class.
Definition: exception.hpp:27
Mesh Atlas class template.
Definition: mesh_atlas.hpp:32
MeshChartType * find_mesh_chart(const String &name)
Searches for a mesh chart.
Definition: mesh_atlas.hpp:162
ParsedMeshType get_mesh_type() const
Returns the mesh-type from the root markup node.
void add_mesh_files(const Dist::Comm &comm, const std::deque< String > &filenames, String dirpath="")
Adds a list of mesh files to the list of streams to be parsed.
ParsedShapeType get_shape_type() const
Returns the shape-type from the root markup node.
void add_mesh_file(const String &filename)
Adds a single mesh file to the list of streams to be parsed.
MeshFileReader(std::istream &is)
Input-Stream constructor.
const String & get_meshtype_string() const
Returns the mesh-type string from the root markup node.
int get_shape_dim() const
Returns the shape-dimension from the root markup node.
virtual ~MeshFileReader()
virtual destructor
void parse(MeshNodeLinker< RootMesh_ > &linker, RootMeshNode< RootMesh_ > &root_mesh_node, MeshAtlas< RootMesh_ > &mesh_atlas, PartitionSet *part_set=nullptr)
Parses the mesh file into a mesh node and a mesh atlas.
void parse(RootMeshNode< RootMesh_ > &root_mesh_node, MeshAtlas< RootMesh_ > &mesh_atlas, PartitionSet *part_set=nullptr)
Parses the mesh file into a mesh node and a mesh atlas.
void add_mesh_file(const Dist::Comm &comm, const String &filename)
Adds a single mesh file to the list of streams to be parsed.
String _mesh_type_string
The parsed mesh type.
std::deque< std::shared_ptr< std::stringstream > > _streams
Our internally managed streams.
void add_mesh_files(const std::deque< String > &filenames, String dirpath="")
Adds a list of mesh files to the list of streams to be parsed.
void add_stream(std::istream &is)
Adds an input stream to the list of streams to be parsed.
int get_world_dim() const
Returns the world-dimension from the root markup node.
std::deque< std::shared_ptr< Xml::Scanner > > _scanners
Our Xml scanner objects.
std::unique_ptr< RootMeshNode< RootMesh_ > > parse(MeshAtlas< RootMesh_ > &mesh_atlas, PartitionSet *part_set=nullptr)
Parses the mesh file into a mesh node and a mesh atlas.
bool _have_root_markup
Did we read the root markup yet?
void read_root_markup()
Reads the root markup from the input stream and analyses it.
MeshNodeLinker Error class.
MeshNode liner class template.
void meshpart_deduct_topology(const String &meshpart)
Adds a task to deduct a meshpart topology from the root mesh.
MeshAtlas< RootMesh_ > & _atlas
our atlas
RootMeshNode< RootMesh_ > & _mesh_node
our mesh node
void meshpart_link_to_chart(const String &meshpart, const String &chart)
Adds a task to link a meshpart to a chart.
void execute()
Executes the linker.
MeshNodeLinker(RootMeshNode< RootMesh_ > &mesh_node, MeshAtlas< RootMesh_ > &atlas)
Constructor.
Class template for partial meshes.
Definition: mesh_part.hpp:90
void deduct_topology(const ParentIndexSetHolderType &parent_ish)
Fills the mesh topology from parent information.
Definition: mesh_part.hpp:547
Root mesh node class template.
Definition: mesh_node.hpp:748
static std::unique_ptr< RootMeshNode > make_unique(std::unique_ptr< MeshType > mesh, MeshAtlasType *atlas=nullptr)
Creates a new RootMeshNode on the heap and returns a unique pointer to it.
Definition: mesh_node.hpp:837
String class implementation.
Definition: string.hpp:47
std::deque< String > split_by_string(const String &delimiter) const
Splits the string by a delimiter substring.
Definition: string.hpp:540
String trim(const String &charset) const
Trims the string.
Definition: string.hpp:328
XML Markup Parser interface.
XML Scanner class.
void read_root()
Tries to read the XML root markup.
Definition: xml_scanner.cpp:92
void throw_content(const String &msg) const
Throws a ContentError for the current line.
void throw_grammar(const String &msg) const
Throws a GrammarError for the current line.
const std::map< String, String > & get_cur_attribs() const
const String & get_cur_name() const
@ parent
indicates that the level is a parent level
ParsedMeshType
mesh type enumeration
Definition: io_common.hpp:14
@ unknown
unknown mesh type
@ conformal
conformal mesh type
ParsedShapeType
shape type enumeration
Definition: io_common.hpp:57
@ simplex
simplex shape type
@ hypercube
hypercube shape type
@ full
full Uzawa preconditioner
FEAT namespace.
Definition: adjactor.hpp:12
double Real
Real data type.
String stringify(const T_ &item)
Converts an item into a String.
Definition: string.hpp:993
std::uint64_t Index
Index data type.
World dimension dependent helper class for parsing charts.
static std::shared_ptr< Xml::MarkupParser > markup(const String &name, std::unique_ptr< Atlas::ChartBase< RootMesh_ > > &chart)
Creates a parser for a chart, its type identified by a name String.