59 std::ifstream in(filename.c_str());
62 ERR(
"FEFLOWGeoInterface::readFEFLOWFile(): Could not open file {:s}.",
67 unsigned dimension = 0;
68 std::vector<GeoLib::Point*> points;
69 std::vector<GeoLib::Polyline*> lines;
71 bool isXZplane =
false;
73 std::string line_string;
74 std::stringstream line_stream;
77 std::getline(in, line_string);
78 if (line_string.find(
"CLASS") != std::string::npos)
80 std::getline(in, line_string);
81 line_stream.str(line_string);
83 for (
int i = 0; i < 3; i++)
87 line_stream >> dimension;
90 else if (line_string ==
"GRAVITY")
92 std::getline(in, line_string);
93 line_stream.str(line_string);
95 line_stream >> vec[0] >> vec[1] >> vec[2];
96 if (vec[0] == 0.0 && vec[1] == -1.0 && vec[2] == 0.0)
102 else if (line_string ==
"SUPERMESH")
109 if (isXZplane && !points.empty())
111 for (
auto* pt : points)
117 std::string project_name(
121 geo_objects.
addPointVec(std::move(points), project_name,
134 std::vector<GeoLib::Point*>& points)
136 xmlNodePtr xmlEle = firstChild(nodesEle, tag);
137 if (xmlEle ==
nullptr)
142 std::istringstream ss(xmlCharsToString(xmlNodeGetContent(xmlEle)));
143 std::string line_str;
144 while (std::getline(ss, line_str))
146 boost::algorithm::trim_right(line_str);
147 if (line_str.empty())
151 std::istringstream line_ss(line_str);
152 std::size_t pt_id = 0;
153 std::array<double, 3> pt_xyz{};
155 for (
int i = 0; i < dim; ++i)
157 line_ss >> pt_xyz[i];
165 std::vector<GeoLib::Point*>& points,
166 std::vector<GeoLib::Polyline*>& lines)
169 std::ostringstream oss;
170 std::string line_string;
173 std::getline(in, line_string);
175 oss << line_string <<
"\n";
176 if (line_string.find(
"</supermesh>") != std::string::npos)
181 const std::string xml_str = oss.str();
185 xmlReadMemory(xml_str.c_str(),
static_cast<int>(xml_str.size()),
186 "supermesh.xml",
nullptr, XML_PARSE_NOBLANKS);
189 ERR(
"FEFLOWGeoInterface::readSuperMesh(): Illegal XML format error");
194 xmlNodePtr docElem = xmlDocGetRootElement(doc);
195 if (docElem ==
nullptr)
197 ERR(
"FEFLOWGeoInterface::readSuperMesh(): Error in getting XML root "
204 static constexpr xmlChar nodes_name[] =
"nodes";
205 xmlNodePtr nodesEle = firstChild(docElem, nodes_name);
206 if (nodesEle ==
nullptr)
208 ERR(
"FEFLOWGeoInterface::readSuperMesh(): Error in getting 'nodes' "
215 static constexpr xmlChar count_name[] =
"count";
216 const std::string cnt = xmlCharsToString(xmlGetProp(nodesEle, count_name));
217 const std::size_t n_points = cnt.empty() ? 0u : std::stoul(cnt);
220 std::vector<GeoLib::Point*> raw_points(n_points,
nullptr);
222 static constexpr xmlChar fixed_name[] =
"fixed";
223 readPoints(nodesEle, fixed_name,
static_cast<int>(dimension), raw_points);
224 static constexpr xmlChar linear_name[] =
"linear";
225 readPoints(nodesEle, linear_name,
static_cast<int>(dimension), raw_points);
226 static constexpr xmlChar parabolic_name[] =
"parabolic";
227 readPoints(nodesEle, parabolic_name,
static_cast<int>(dimension),
231 std::vector<std::unique_ptr<GeoLib::Point>> temp_points(n_points);
232 for (std::size_t i = 0; i < raw_points.size(); ++i)
234 temp_points[i].reset(raw_points[i]);
237 static constexpr xmlChar polygons_name[] =
"polygons";
238 xmlNodePtr polygonsEle = firstChild(docElem, polygons_name);
239 if (polygonsEle ==
nullptr)
247 for (xmlNodePtr child = polygonsEle->children; child; child = child->next)
249 static constexpr xmlChar polygon_name[] =
"polygon";
250 if (child->type != XML_ELEMENT_NODE ||
251 xmlStrcmp(child->name, polygon_name) != 0)
256 xmlNodePtr nodes = firstChild(child, nodes_name);
257 if (nodes ==
nullptr)
262 const std::string cnt_nodes =
263 xmlCharsToString(xmlGetProp(nodes, count_name));
264 const std::size_t n_pts =
265 cnt_nodes.empty() ? 0u
266 :
static_cast<std::size_t
>(std::stoul(cnt_nodes));
267 std::istringstream ss(xmlCharsToString(xmlNodeGetContent(nodes)));
269 auto line = std::make_unique<GeoLib::Polyline>(raw_points);
271 for (std::size_t i = 0; i < n_pts; ++i)
275 line->addPoint(pt_id - 1);
278 line->addPoint(line->getPointID(0));
280 lines.push_back(line.release());
287 for (
auto& pt : temp_points)
289 points.push_back(pt.release());