A super mesh is a collection of polygons, lines and points in the 2D plane and will be used for mesh generation and to define the modeling region
167{
168
169 std::ostringstream oss;
170 std::string line_string;
171 while (true)
172 {
173 std::getline(in, line_string);
175 oss << line_string << "\n";
176 if (line_string.find("</supermesh>") != std::string::npos)
177 {
178 break;
179 }
180 }
181 const std::string xml_str = oss.str();
182
183 xmlInitParser();
184 xmlDocPtr doc =
185 xmlReadMemory(xml_str.c_str(), static_cast<int>(xml_str.size()),
186 "supermesh.xml", nullptr, XML_PARSE_NOBLANKS);
187 if (doc == nullptr)
188 {
189 ERR(
"FEFLOWGeoInterface::readSuperMesh(): Illegal XML format error");
190 xmlCleanupParser();
191 return;
192 }
193
194 xmlNodePtr docElem = xmlDocGetRootElement(doc);
195 if (docElem == nullptr)
196 {
197 ERR(
"FEFLOWGeoInterface::readSuperMesh(): Error in getting XML root "
198 "element");
199 xmlFreeDoc(doc);
200 xmlCleanupParser();
201 return;
202 }
203
204 static constexpr xmlChar nodes_name[] = "nodes";
205 xmlNodePtr nodesEle =
firstChild(docElem, nodes_name);
206 if (nodesEle == nullptr)
207 {
208 ERR(
"FEFLOWGeoInterface::readSuperMesh(): Error in getting 'nodes' "
209 "element");
210 xmlFreeDoc(doc);
211 xmlCleanupParser();
212 return;
213 }
214
215 static constexpr xmlChar count_name[] = "count";
217 const std::size_t n_points = cnt.empty() ? 0u : std::stoul(cnt);
218
219
220 std::vector<GeoLib::Point*> raw_points(n_points, nullptr);
221
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),
228 raw_points);
229
230
231 std::vector<std::unique_ptr<GeoLib::Point>> temp_points(n_points);
232 for (std::size_t i = 0; i < raw_points.size(); ++i)
233 {
234 temp_points[i].reset(raw_points[i]);
235 }
236
237 static constexpr xmlChar polygons_name[] = "polygons";
238 xmlNodePtr polygonsEle =
firstChild(docElem, polygons_name);
239 if (polygonsEle == nullptr)
240 {
241
242 xmlFreeDoc(doc);
243 xmlCleanupParser();
244 return;
245 }
246
247 for (xmlNodePtr child = polygonsEle->children; child; child = child->next)
248 {
249 static constexpr xmlChar polygon_name[] = "polygon";
250 if (child->type != XML_ELEMENT_NODE ||
251 xmlStrcmp(child->name, polygon_name) != 0)
252 {
253 continue;
254 }
255
256 xmlNodePtr nodes =
firstChild(child, nodes_name);
257 if (nodes == nullptr)
258 {
259 continue;
260 }
261
262 const std::string cnt_nodes =
264 const std::size_t n_pts =
265 cnt_nodes.empty() ? 0u
266 : static_cast<std::size_t>(std::stoul(cnt_nodes));
268
269 auto line = std::make_unique<GeoLib::Polyline>(raw_points);
270
271 for (std::size_t i = 0; i < n_pts; ++i)
272 {
273 int pt_id = 0;
274 ss >> pt_id;
275 line->addPoint(pt_id - 1);
276 }
277
278 line->addPoint(line->getPointID(0));
279
280 lines.push_back(line.release());
281 }
282
283 xmlFreeDoc(doc);
284 xmlCleanupParser();
285
286
287 for (auto& pt : temp_points)
288 {
289 points.push_back(pt.release());
290 }
291}
static void readPoints(xmlNodePtr nodesEle, const xmlChar *tag, int dim, std::vector< GeoLib::Point * > &points)
void trim(std::string &str, char ch)