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>
56 template<
typename RootMesh_>
66 std::deque<std::pair<String,String>> _meshpart_to_chart;
68 std::deque<String> _meshpart_deduct_topo;
97 _meshpart_to_chart.emplace_back(std::make_pair(meshpart, chart));
108 _meshpart_deduct_topo.emplace_back(meshpart);
119 while(!_meshpart_to_chart.empty())
121 String mpart_name = _meshpart_to_chart.front().first;
122 String chart_name = _meshpart_to_chart.front().second;
128 String msg =
String(
"Chart '") + chart_name +
"' not found for meshpart '" + mpart_name +
"'";
133 if(!
_mesh_node.set_mesh_part_chart(mpart_name, chart_name, chart))
135 String msg =
String(
"meshpart '" + mpart_name +
"' not found");
140 _meshpart_to_chart.pop_front();
144 const RootMesh_* root_mesh =
_mesh_node.get_mesh();
147 while(!_meshpart_deduct_topo.empty())
149 String mpart_name = _meshpart_deduct_topo.front();
152 if(mesh_part ==
nullptr)
154 String msg =
String(
"meshpart '" + mpart_name +
"' not found");
159 if(root_mesh ==
nullptr)
161 String msg =
String(
"Cannot deduct topology for meshpart '") + mpart_name +
"'; no root mesh found";
169 _meshpart_deduct_topo.pop_front();
178 template<
typename RootMesh_,
int world_dim>
179 struct DimensionalChartHelper;
181 template<
typename RootMesh_>
186 MeshAtlas<RootMesh_>& _atlas;
188 std::unique_ptr<Atlas::ChartBase<RootMesh_>> _chart;
191 explicit ChartParser(MeshAtlas<RootMesh_>& atlas) :
192 _atlas(atlas), _chart_name(), _chart()
196 virtual ~ChartParser()
200 virtual bool attribs(std::map<String,bool>& attrs)
const override
202 attrs.emplace(
"name",
true);
207 int iline,
const String& sline,
const String&,
208 const std::map<String, String>& attrs,
bool closed)
override
211 throw Xml::GrammarError(iline, sline,
"Invalid closed markup");
214 _chart_name = attrs.find(
"name")->second.
trim();
215 if(_chart_name.empty())
216 throw Xml::GrammarError(iline, sline,
"Empty chart name");
219 XASSERTM(_atlas.find_mesh_chart(_chart_name) ==
nullptr,
220 String(
"Chart '") + _chart_name +
"' already exists in atlas");
225 virtual void close(
int iline,
const String& sline)
override
229 throw Xml::GrammarError(iline, sline,
"Invalid empty chart");
232 _atlas.add_mesh_chart(_chart_name, std::move(_chart));
235 virtual bool content(
int,
const String&)
override
240 virtual std::shared_ptr<MarkupParser> markup(
int,
const String&,
const String& name)
override
242 return DimensionalChartHelper<RootMesh_, RootMesh_::world_dim>::markup(name, _chart);
247 template<
int num_coords_,
typename Coord_>
248 class VerticesParser :
249 public Xml::MarkupParser
252 typedef VertexSet<num_coords_, Coord_> VertexSetType;
255 VertexSetType& _vertex_set;
259 explicit VerticesParser(VertexSetType& vertex_set) :
260 _vertex_set(vertex_set),
265 virtual bool attribs(std::map<String,bool>&)
const override
270 virtual void create(
int iline,
const String& sline,
const String&,
const std::map<String, String>&,
bool closed)
override
273 throw Xml::GrammarError(iline, sline,
"Invalid closed markup");
276 virtual void close(
int iline,
const String& sline)
override
279 if(_read < _vertex_set.get_num_vertices())
280 throw Xml::GrammarError(iline, sline,
"Invalid terminator; expected point");
283 virtual std::shared_ptr<MarkupParser> markup(
int,
const String&,
const String&)
override
289 virtual bool content(
int iline,
const String& sline)
override
292 if(_read >= _vertex_set.get_num_vertices())
293 throw Xml::ContentError(iline, sline,
"Invalid content; expected terminator");
296 std::deque<String> scoords = sline.split_by_whitespaces();
299 if(scoords.size() != std::size_t(num_coords_))
300 throw Xml::ContentError(iline, sline,
"Invalid number of coordinates");
303 auto& vtx = _vertex_set[_read];
306 for(
int i(0); i < num_coords_; ++i)
308 if(!scoords.at(std::size_t(i)).parse(vtx[i]))
309 throw Xml::ContentError(iline, sline,
"Failed to parse vertex coordinate");
321 template<
typename Shape_,
int dim_ = Shape_::dimension>
322 struct TopoParseHelper
324 template<
typename TopoParser_>
325 static void init_topo(TopoParser_& tp, IndexSetHolder<Shape_>& ish,
int dim)
328 tp.init_idx_set(ish.template get_index_set<dim_, 0>(), dim_);
330 TopoParseHelper<Shape_, dim_-1>::init_topo(tp, ish, dim);
334 template<
typename Shape_>
335 struct TopoParseHelper<Shape_, 0>
337 template<
typename TopoParser_>
338 static void init_topo(TopoParser_&, IndexSetHolder<Shape_>&,
int)
340 XABORTM(
"Thou shall not arrive here");
344 template<
typename Shape_,
int dim_ = Shape_::dimension>
345 struct MappParseHelper
347 template<
typename MappParser_>
348 static void init_mapp(MappParser_& mp, TargetSetHolder<Shape_>& tsh,
int dim)
351 mp.init_trg_set(tsh.template get_target_set<dim_>(), dim_);
353 MappParseHelper<Shape_, dim_-1>::init_mapp(mp, tsh, dim);
357 template<
typename Shape_>
358 struct MappParseHelper<Shape_, 0>
360 template<
typename MappParser_>
361 static void init_mapp(MappParser_& mp, TargetSetHolder<Shape_>& tsh,
int)
363 mp.init_trg_set(tsh.template get_target_set<0>(), 0);
368 template<
typename Shape_>
369 class TopologyParser :
370 public Xml::MarkupParser
373 typedef IndexSetHolder<Shape_> TopologyType;
376 TopologyType& _topology;
377 std::deque<int>& _have_topology;
386 template<
int num_
idx_>
387 void init_idx_set(IndexSet<num_idx_>& idx_set,
int dim)
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();
398 explicit TopologyParser(TopologyType& topology, std::deque<int>& have_topology) :
400 _have_topology(have_topology),
410 virtual bool attribs(std::map<String,bool>& attrs)
const override
412 attrs.emplace(
"dim",
true);
416 virtual void create(
int iline,
const String& sline,
const String&,
const std::map<String, String>& attrs,
bool closed)
override
419 throw Xml::GrammarError(iline, sline,
"Invalid closed markup");
422 if(!attrs.find(
"dim")->second.parse(_my_dim))
423 throw Xml::ContentError(iline, sline,
"Failed to parse 'dim' attribute");
426 if((_my_dim >
Index(_have_topology.size())) || (_my_dim ==
Index(0)))
427 throw Xml::ContentError(iline, sline,
"Invalid topology dimension");
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;
435 Intern::TopoParseHelper<Shape_>::init_topo(*
this, _topology,
int(_my_dim));
438 virtual void close(
int iline,
const String& sline)
override
442 throw Xml::GrammarError(iline, sline,
"Invalid terminator; expected index tuple");
445 virtual std::shared_ptr<MarkupParser> markup(
int,
const String&,
const String&)
override
451 virtual bool content(
int iline,
const String& sline)
override
455 throw Xml::ContentError(iline, sline,
"Invalid content; expected terminator");
458 std::deque<String> sidx = sline.split_by_whitespaces();
461 if(sidx.size() != std::size_t(_num_idx))
462 throw Xml::ContentError(iline, sline,
"Invalid number of indices");
465 for(Index i(0); i < _num_idx; ++i)
467 Index& idx = _indices[_read*_num_idx+i];
470 if(!sidx.at(i).parse(idx))
471 throw Xml::ContentError(iline, sline,
"Failed to parse index");
475 throw Xml::ContentError(iline, sline,
"Index out of bounds");
485 template<
typename Shape_>
486 class MappingParser :
487 public Xml::MarkupParser
490 typedef TargetSetHolder<Shape_> MappingType;
493 MappingType& _mapping;
494 std::deque<int>& _have_mapping;
501 void init_trg_set(TargetSet& trg_set,
int dim)
503 _indices = trg_set.get_indices();
504 _my_dim =
Index(dim);
505 _count = trg_set.get_num_entities();
509 explicit MappingParser(MappingType& mapping, std::deque<int>& have_mapping) :
511 _have_mapping(have_mapping),
519 virtual bool attribs(std::map<String,bool>& attrs)
const override
521 attrs.emplace(
"dim",
true);
525 virtual void create(
int iline,
const String& sline,
const String&,
const std::map<String, String>& attrs,
bool closed)
override
528 throw Xml::GrammarError(iline, sline,
"Invalid closed markup");
531 if(!attrs.find(
"dim")->second.parse(_my_dim))
532 throw Xml::ContentError(iline, sline,
"Failed to parse 'dim' attribute");
535 if((_my_dim >
Index(_have_mapping.size())))
536 throw Xml::ContentError(iline, sline,
"Invalid mapping dimension");
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;
544 Intern::MappParseHelper<Shape_>::init_mapp(*
this, _mapping,
int(_my_dim));
547 virtual void close(
int iline,
const String& sline)
override
551 throw Xml::GrammarError(iline, sline,
"Invalid terminator; expected index");
554 virtual std::shared_ptr<MarkupParser> markup(
int,
const String&,
const String&)
override
560 virtual bool content(
int iline,
const String& sline)
override
564 throw Xml::ContentError(iline, sline,
"Invalid content; expected terminator");
567 if(!sline.parse(_indices[_read]))
568 throw Xml::ContentError(iline, sline,
"Failed to parse index");
577 template<
typename MeshPart_,
typename DataType_ =
typename MeshPart_::AttributeDataType>
578 class AttributeParser :
579 public Xml::MarkupParser
582 typedef AttributeSet<DataType_> AttribType;
585 MeshPart_& _mesh_part;
586 std::unique_ptr<AttribType> _attrib;
593 explicit AttributeParser(MeshPart_& mesh_part) :
594 _mesh_part(mesh_part),
602 virtual ~AttributeParser()
606 virtual bool attribs(std::map<String,bool>& attrs)
const override
608 attrs.emplace(
"dim",
true);
609 attrs.emplace(
"name",
true);
613 virtual void create(
int iline,
const String& sline,
const String&,
const std::map<String, String>& attrs,
bool closed)
override
616 throw Xml::GrammarError(iline, sline,
"Invalid closed markup");
619 if(!attrs.find(
"dim")->second.parse(_my_dim))
620 throw Xml::ContentError(iline, sline,
"Failed to parse 'dim' attribute");
623 if(_my_dim ==
Index(0))
624 throw Xml::ContentError(iline, sline,
"Invalid attribute dimension");
627 _my_name = attrs.find(
"name")->second;
630 _count = _mesh_part.get_num_entities(0);
631 _attrib.reset(
new AttribType(_count,
int(_my_dim)));
634 virtual void close(
int iline,
const String& sline)
override
638 throw Xml::GrammarError(iline, sline,
"Invalid terminator; expected index");
641 _mesh_part.add_attribute(std::move(_attrib), _my_name);
644 virtual std::shared_ptr<MarkupParser> markup(
int,
const String&,
const String&)
override
650 virtual bool content(
int iline,
const String& sline)
override
654 throw Xml::ContentError(iline, sline,
"Invalid content; expected terminator");
657 std::deque<String> svals = sline.split_by_whitespaces();
660 if(svals.size() != std::size_t(_my_dim))
661 throw Xml::ContentError(iline, sline,
"Invalid number of values");
664 for(
int i(0); i < int(_my_dim); ++i)
666 if(!svals.at(std::size_t(i)).parse(_attrib->operator()(_read,i)))
667 throw Xml::ContentError(iline, sline,
"Failed to parse value");
677 template<
typename Mesh_>
680 template<
typename Shape_,
int num_coords_,
typename Coord_>
681 class MeshParser<ConformalMesh<Shape_, num_coords_, Coord_>> :
682 public Xml::MarkupParser
685 typedef ConformalMesh<Shape_, num_coords_, Coord_> MeshType;
688 RootMeshNode<MeshType>& _root_node;
689 std::unique_ptr<MeshType> _mesh;
691 std::deque<int> _have_topology;
692 std::vector<Index> _sizes;
694 template<
int shape_dim_>
695 static String aux_shape_string(
const Shape::Hypercube<shape_dim_>&)
700 template<
int shape_dim_>
701 static String aux_shape_string(
const Shape::Simplex<shape_dim_>&)
707 explicit MeshParser(RootMeshNode<MeshType>& root_node) :
708 _root_node(root_node),
714 virtual ~MeshParser()
718 virtual bool attribs(std::map<String,bool>& attrs)
const override
720 attrs.emplace(
"type",
true);
721 attrs.emplace(
"size",
true);
725 virtual void create(
int iline,
const String& sline,
const String&,
const std::map<String, String>& attrs,
bool closed)
override
728 throw Xml::GrammarError(iline, sline,
"Invalid closed markup");
731 std::deque<String> stype = attrs.find(
"type")->second.split_by_string(
":");
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");
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");
759 _sizes.resize(ssize.size());
760 for(std::size_t i(0); i <= std::size_t(Shape_::dimension); ++i)
762 if(!ssize.at(i).parse(_sizes.at(i)))
763 throw Xml::ContentError(iline, sline,
"Failed to parse mesh size");
767 _mesh.reset(
new MeshType(_sizes.data()));
771 _have_topology.resize(std::size_t(Shape_::dimension), 0);
774 virtual void close(
int iline,
const String& sline)
override
778 throw Xml::GrammarError(iline, sline,
"Mesh has no Vertices");
781 for(std::size_t i(0); i < _have_topology.size(); ++i)
783 if(_have_topology.at(i) == 0)
784 throw Xml::GrammarError(iline, sline,
"Missing topology for dimension " +
stringify(i+1));
790 RedundantIndexSetBuilder<Shape_>::compute(*_mesh->get_topology());
793 _root_node.set_mesh(std::move(_mesh));
796 virtual std::shared_ptr<Xml::MarkupParser> markup(
int iline,
const String& sline,
const String& name)
override
799 if(name ==
"Vertices")
802 throw Xml::GrammarError(iline, sline,
"More than one Vertices block in mesh");
806 return std::make_shared<VerticesParser<num_coords_, Coord_>>(_mesh->get_vertex_set());
810 if(name ==
"Topology")
813 return std::make_shared<TopologyParser<Shape_>>(*_mesh->get_topology(), _have_topology);
820 virtual bool content(
int,
const String&)
override
826 template<
typename Mesh_>
827 class MeshPartParser;
829 template<
typename Shape_,
int num_coords_,
typename Coord_>
830 class MeshPartParser<ConformalMesh<Shape_, num_coords_, Coord_>> :
831 public Xml::MarkupParser
834 typedef ConformalMesh<Shape_, num_coords_, Coord_> MeshType;
835 typedef MeshPart<MeshType> MeshPartType;
836 typedef Atlas::ChartBase<MeshType> ChartType;
845 RootMeshNode<MeshType>& _root_node;
846 MeshNodeLinker<MeshType>& _linker;
847 std::unique_ptr<MeshPartType> _mesh_part;
850 String _name, _parent, _chart_name;
851 std::deque<int> _have_topology;
852 std::deque<int> _have_mapping;
853 std::vector<Index> _sizes;
856 explicit MeshPartParser(RootMeshNode<MeshType>& root_node, MeshNodeLinker<MeshType>& linker) :
857 _root_node(root_node),
861 _topo_type(TopoType::none)
865 virtual ~MeshPartParser()
869 virtual bool attribs(std::map<String,bool>& attrs)
const override
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);
879 virtual void create(
int iline,
const String& sline,
const String&,
const std::map<String, String>& attrs,
bool closed)
override
882 throw Xml::GrammarError(iline, sline,
"Invalid closed markup");
885 _name = attrs.find(
"name")->second;
886 _parent = attrs.find(
"parent")->second;
889 if(_root_node.find_mesh_part(_name) !=
nullptr)
890 throw Xml::ContentError(iline, sline, String(
"Mesh Part '") + _name +
"' already exists in mesh node");
894 auto it = attrs.find(
"chart");
895 if(it != attrs.end())
898 _chart_name = it->second;
899 _linker.meshpart_link_to_chart(_name, _chart_name);
904 if(_parent !=
"root")
905 throw Xml::ContentError(iline, sline,
"Invalid mesh part parent; only 'root' is accepted");
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")
915 _topo_type = TopoType::parent;
916 _linker.meshpart_deduct_topology(_name);
919 throw Xml::ContentError(iline, sline,
"Invalid topology attribute '" + stopo_type +
"'");
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");
927 _sizes.resize(std::size_t(Shape_::dimension+1),
Index(0));
928 for(std::size_t i(0); i < ssize.size(); ++i)
930 if(!ssize.at(i).parse(_sizes.at(i)))
931 throw Xml::ContentError(iline, sline,
"Failed to parse mesh part size");
935 _mesh_part.reset(
new MeshPartType(_sizes.data(), _topo_type != TopoType::none));
938 _have_topology.resize(std::size_t(Shape_::dimension), 0);
939 _have_mapping.resize(std::size_t(Shape_::dimension+1), 0);
942 virtual void close(
int iline,
const String& sline)
override
945 for(std::size_t i(0); i < _have_mapping.size(); ++i)
947 if((_have_mapping.at(i) == 0) && (_sizes.at(i) >
Index(0)))
948 throw Xml::GrammarError(iline, sline,
"Missing mapping for dimension " +
stringify(i));
951 if(_topo_type == TopoType::full)
955 for(std::size_t i(0); i < _have_topology.size(); ++i)
958 if(_sizes.at(i+1) > 0)
959 topo_all = topo_all && (_have_topology.at(i) != 0);
964 throw Xml::GrammarError(iline, sline,
"Incomplete topology");
968 RedundantIndexSetBuilder<Shape_>::compute(*_mesh_part->get_topology());
970 else if(_topo_type == TopoType::parent)
979 _root_node.add_mesh_part(_name, std::move(_mesh_part));
982 virtual std::shared_ptr<Xml::MarkupParser> markup(
int iline,
const String& sline,
const String& name)
override
985 if(name ==
"Mapping")
988 return std::make_shared<MappingParser<Shape_>>(_mesh_part->get_target_set_holder(), _have_mapping);
992 if(name ==
"Topology")
994 if(_topo_type == TopoType::none)
995 throw Xml::ContentError(iline, sline,
"Unexpected Topology found");
998 return std::make_shared<TopologyParser<Shape_>>(*_mesh_part->get_topology(), _have_topology);
1002 if(name ==
"Attribute")
1004 return std::make_shared<AttributeParser<MeshPartType>>(*_mesh_part);
1011 virtual bool content(
int,
const String&)
override
1018 public Xml::MarkupParser
1021 Adjacency::DynamicGraph& _patches;
1027 explicit PatchParser(Adjacency::DynamicGraph& patches) :
1035 virtual bool attribs(std::map<String,bool>& attrs)
const override
1037 attrs.emplace(
"rank",
true);
1038 attrs.emplace(
"size",
true);
1042 virtual void create(
int iline,
const String& sline,
const String&,
const std::map<String, String>& attrs,
bool)
override
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");
1051 if(_rank >= _patches.get_num_nodes_domain())
1052 throw Xml::ContentError(iline, sline,
"Patch rank index is out of bounds");
1055 virtual void close(
int iline,
const String& sline)
override
1058 throw Xml::GrammarError(iline, sline,
"Invalid terminator; expected index");
1061 virtual bool content(
int iline,
const String& sline)
override
1065 throw Xml::ContentError(iline, sline,
"Invalid content; expected terminator");
1069 if(!sline.parse(elem))
1070 throw Xml::ContentError(iline, sline,
"Failed to parse element index");
1072 if(elem >= _patches.get_num_nodes_image())
1073 throw Xml::ContentError(iline, sline,
"Patch element index is out of bounds");
1076 _patches.insert(_rank, elem);
1084 virtual std::shared_ptr<MarkupParser> markup(
int,
const String&,
const String&)
override
1090 class PartitionParser :
1091 public Xml::MarkupParser
1094 PartitionSet& _part_set;
1098 int _num_ranks, _num_elems;
1099 Adjacency::DynamicGraph _patches;
1102 explicit PartitionParser(PartitionSet& part_set) :
1103 _part_set(part_set),
1113 virtual bool attribs(std::map<String,bool>& attrs)
const override
1115 attrs.emplace(
"size",
true);
1116 attrs.emplace(
"name",
false);
1117 attrs.emplace(
"priority",
false);
1118 attrs.emplace(
"level",
false);
1122 virtual void create(
int iline,
const String& sline,
const String&,
const std::map<String, String>& attrs,
bool)
override
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");
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");
1137 auto it = attrs.find(
"name");
1138 if(it != attrs.end())
1144 auto it = attrs.find(
"priority");
1145 if(it != attrs.end())
1147 if(!it->second.parse(_prio))
1148 throw Xml::ContentError(iline, sline,
"Cannot parse partition priority");
1154 auto it = attrs.find(
"level");
1155 if(it != attrs.end())
1157 if(!it->second.parse(_level))
1158 throw Xml::ContentError(iline, sline,
"Cannot parse partition level");
1160 throw Xml::ContentError(iline, sline,
"Invalid negative partition level");
1165 _patches = Adjacency::DynamicGraph(
Index(_num_ranks),
Index(_num_elems));
1168 virtual void close(
int,
const String&)
override
1171 _part_set.add_partition(Partition(_patches, _name, _prio, _level));
1174 virtual bool content(
int,
const String&)
override
1179 virtual std::shared_ptr<MarkupParser> markup(
int,
const String&,
const String& name)
override
1182 return std::make_shared<PatchParser>(_patches);
1188 template<
typename RootMesh_>
1189 class MeshNodeParser :
1190 public Xml::MarkupParser
1193 typedef RootMesh_ RootMeshType;
1194 typedef RootMeshNode<RootMesh_> RootMeshNodeType;
1195 typedef MeshAtlas<RootMesh_> MeshAtlasType;
1199 RootMeshNodeType& _root_node;
1201 MeshAtlasType& _mesh_atlas;
1203 PartitionSet* _part_set;
1205 MeshNodeLinker<RootMesh_>& _linker;
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),
1219 virtual bool attribs(std::map<String,bool>& attrs)
const override
1221 attrs.emplace(
"version",
true);
1222 attrs.emplace(
"mesh",
false);
1226 virtual void create(
int iline,
const String& sline,
const String& name,
const std::map<String, String>& attrs,
bool)
override
1229 if(name !=
"FeatMeshFile")
1230 throw Xml::GrammarError(iline, sline,
"Invalid root markup; expected '<FeatMeshFile ...>'");
1234 if(!attrs.find(
"version")->second.parse(version))
1235 throw Xml::ContentError(iline, sline,
"Cannot parse file version");
1237 throw Xml::ContentError(iline, sline,
"Invalid file version; expected 1");
1240 auto it = attrs.find(
"mesh");
1241 if(it != attrs.end())
1244 _mesh_decl = it->second;
1248 virtual void close(
int,
const String&)
override
1252 virtual bool content(
int,
const String&)
override
1257 virtual std::shared_ptr<MarkupParser> markup(
int iline,
const String& sline,
const String& name)
override
1263 return std::make_shared<Xml::DummyParser>();
1268 return std::make_shared<ChartParser<RootMeshType>>(_mesh_atlas);
1272 if(_root_node.get_mesh() !=
nullptr)
1275 throw Xml::GrammarError(iline, sline,
"Invalid second Mesh in file");
1279 return std::make_shared<MeshParser<RootMeshType>>(_root_node);
1281 if(name ==
"MeshPart")
1284 return std::make_shared<MeshPartParser<RootMeshType>>(_root_node, _linker);
1286 if(name ==
"Partition")
1289 if(_part_set !=
nullptr)
1290 return std::make_shared<PartitionParser>(*_part_set);
1294 return std::make_shared<Xml::DummyParser>();
1328 std::deque<std::shared_ptr<std::stringstream>>
_streams;
1371 _scanners.push_back(std::make_shared<Xml::Scanner>(is));
1395 _scanners.push_back(std::make_shared<Xml::Scanner>(is));
1414 if(filenames.empty())
1418 if(!dirpath.empty())
1422 if((dirpath.back() !=
'/') && (dirpath.back() !=
'\\'))
1423 dirpath.push_back(
'\\');
1425 if(dirpath.back() !=
'/')
1426 dirpath.push_back(
'/');
1431 for(std::size_t i(0); i < filenames.size(); ++i)
1434 String filepath = dirpath + filenames.at(i);
1437 auto stream = std::make_shared<std::stringstream>();
1476 std::deque<String> filenames;
1477 filenames.push_back(filename);
1592 auto it_v = attr.find(
"version");
1593 if(it_v == attr.end())
1594 scanner.
throw_grammar(
"Mesh file is missing mandatory attribute 'version'");
1596 if(!(it_v->second.parse(iversion)))
1597 scanner.
throw_grammar(
"Failed to parse mesh file version attribute");
1602 auto it_m = attr.find(
"mesh");
1603 if(it_m != attr.end())
1619 if(mts.size() != std::size_t(4))
1620 scanner.
throw_grammar(
"Mesh file root markup has invalid 'mesh' attribute");
1623 if(mts.at(0) ==
"conformal")
1626 scanner.
throw_grammar(
"Invalid 'mesh' attribute mesh type");
1629 if(mts.at(1) ==
"simplex")
1631 else if(mts.at(1) ==
"hypercube")
1634 scanner.
throw_grammar(
"Invalid 'mesh' attribute shape type");
1637 if(!mts.at(2).parse(_shape_dim) || (_shape_dim <= 0))
1638 scanner.
throw_content(
"Invalid 'mesh' attribute shape dimension");
1641 if(!mts.at(3).parse(_world_dim) || (_world_dim <= 0))
1642 scanner.
throw_content(
"Invalid 'mesh' attribute world dimension");
1670 template<
typename RootMesh_>
1685 (*it)->set_root_parser(std::make_shared<MeshNodeParser<RootMesh_>>(root_mesh_node, mesh_atlas, part_set, linker));
1704 template<
typename RootMesh_>
1714 parse(linker, root_mesh_node, mesh_atlas, part_set);
1735 template<
typename RootMesh_>
1736 std::unique_ptr<RootMeshNode<RootMesh_>>
parse(
1741 std::unique_ptr<RootMeshNode<RootMesh_>> root_mesh_node =
1745 this->
parse(*root_mesh_node, mesh_atlas, part_set);
1748 return root_mesh_node;
1766 template<
typename RootMesh_,
int world_dim>
1769 static_assert(RootMesh_::world_dim == world_dim,
"Nonmatching world_dim.");
1789 template<
typename RootMesh_>
1790 struct DimensionalChartHelper<RootMesh_,2>
1792 static std::shared_ptr<Xml::MarkupParser>
markup(
const String& name,
1793 std::unique_ptr<Atlas::ChartBase<RootMesh_>>& chart)
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);
1804 template<
typename RootMesh_>
1805 struct DimensionalChartHelper<RootMesh_,3>
1807 static std::shared_ptr<Xml::MarkupParser>
markup(
const String& name,
1808 std::unique_ptr<Atlas::ChartBase<RootMesh_>>& chart)
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);
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>>;
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>>&,
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>>&,
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>>&,
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>>&,
#define XABORTM(msg)
Abortion macro definition with custom message.
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
static Comm world()
Returns a copy of the world communicator.
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.
Mesh Atlas class template.
MeshChartType * find_mesh_chart(const String &name)
Searches for a mesh chart.
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
MeshFileReader()
default constructor
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.
void deduct_topology(const ParentIndexSetHolderType &parent_ish)
Fills the mesh topology from parent information.
Root mesh node class template.
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.
String class implementation.
std::deque< String > split_by_string(const String &delimiter) const
Splits the string by a delimiter substring.
String trim(const String &charset) const
Trims the string.
XML Markup Parser interface.
void read_root()
Tries to read the XML root markup.
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
@ unknown
unknown mesh type
@ conformal
conformal mesh type
ParsedShapeType
shape type enumeration
@ simplex
simplex shape type
@ hypercube
hypercube shape type
@ full
full Uzawa preconditioner
double Real
Real data type.
String stringify(const T_ &item)
Converts an item into a String.
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.