OGS
FileIO::FEFLOWGeoInterface Class Reference

Detailed Description

Interface to geometric data in FEFLOW files

Definition at line 24 of file FEFLOWGeoInterface.h.

#include <FEFLOWGeoInterface.h>

Public Member Functions

void readFEFLOWFile (const std::string &filename, GeoLib::GEOObjects &geo_objects)

Static Public Member Functions

static void readSuperMesh (std::ifstream &in, unsigned dimension, std::vector< GeoLib::Point * > &points, std::vector< GeoLib::Polyline * > &lines)

Static Private Member Functions

static void readPoints (QDomElement &nodesEle, const std::string &tag, int dim, std::vector< GeoLib::Point * > &points)

Member Function Documentation

◆ readFEFLOWFile()

void FileIO::FEFLOWGeoInterface::readFEFLOWFile ( const std::string & filename,
GeoLib::GEOObjects & geo_objects )

read a FEFLOW Model file (*.fem) in ASCII format (Version 5.4)

This function reads geometry data given in Supermesh.

Parameters
filenameFEFLOW file name
geo_objectsGeometric objects where imported geometry data are added

Definition at line 23 of file FEFLOWGeoInterface.cpp.

25{
26 std::ifstream in(filename.c_str());
27 if (!in)
28 {
29 ERR("FEFLOWGeoInterface::readFEFLOWFile(): Could not open file {:s}.",
30 filename);
31 return;
32 }
33
34 unsigned dimension = 0;
35 std::vector<GeoLib::Point*> points;
36 std::vector<GeoLib::Polyline*> lines;
37
38 bool isXZplane = false;
39
40 std::string line_string;
41 std::stringstream line_stream;
42 while (!in.eof())
43 {
44 std::getline(in, line_string);
45 //....................................................................
46 // CLASS: the version number follows afterward, e.g. CLASS (v.5.313)
47 if (line_string.find("CLASS") != std::string::npos)
48 {
49 std::getline(in, line_string);
50 line_stream.str(line_string);
51 // problem class, time mode, problem orientation, dimension, ...
52 unsigned dummy = 0;
53 for (int i = 0; i < 3; i++)
54 {
55 line_stream >> dummy;
56 }
57 line_stream >> dimension;
58 line_stream.clear();
59 }
60 //....................................................................
61 // GRAVITY
62 else if (line_string == "GRAVITY")
63 {
64 std::getline(in, line_string);
65 line_stream.str(line_string);
66 double vec[3] = {};
67 line_stream >> vec[0] >> vec[1] >> vec[2];
68 if (vec[0] == 0.0 && vec[1] == -1.0 && vec[2] == 0.0)
69 {
70 // x-z plane
71 isXZplane = true;
72 }
73 line_stream.clear();
74 }
75 //....................................................................
76 // SUPERMESH
77 else if (line_string == "SUPERMESH")
78 {
79 readSuperMesh(in, dimension, points, lines);
80 }
81 //....................................................................
82 }
83 in.close();
84
85 if (isXZplane && !points.empty())
86 {
87 for (auto* pt : points)
88 {
89 (*pt)[2] = (*pt)[1];
90 (*pt)[1] = .0;
91 }
92 }
93 std::string project_name(
95 if (!points.empty())
96 {
97 geo_objects.addPointVec(std::move(points), project_name,
99 }
100 if (!lines.empty())
101 {
102 geo_objects.addPolylineVec(std::move(lines), project_name,
104 }
105}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
static void readSuperMesh(std::ifstream &in, unsigned dimension, std::vector< GeoLib::Point * > &points, std::vector< GeoLib::Polyline * > &lines)
void addPolylineVec(std::vector< Polyline * > &&lines, std::string const &name, PolylineVec::NameIdMap &&ply_names)
void addPointVec(std::vector< Point * > &&points, std::string &name, PointVec::NameIdMap &&pnt_id_name_map, double const eps=std::sqrt(std::numeric_limits< double >::epsilon()))
std::map< std::string, std::size_t > NameIdMap
Definition TemplateVec.h:30
std::string extractBaseNameWithoutExtension(std::string const &pathname)
constexpr int dimension()
Displacement dimension of a vectorized tensor.

References GeoLib::GEOObjects::addPointVec(), GeoLib::GEOObjects::addPolylineVec(), ERR(), BaseLib::extractBaseNameWithoutExtension(), and readSuperMesh().

Referenced by MainWindow::loadFile().

◆ readPoints()

void FileIO::FEFLOWGeoInterface::readPoints ( QDomElement & nodesEle,
const std::string & tag,
int dim,
std::vector< GeoLib::Point * > & points )
staticprivate

Definition at line 107 of file FEFLOWGeoInterface.cpp.

111{
112 QDomElement xmlEle =
113 nodesEle.firstChildElement(QString::fromStdString(tag));
114 if (xmlEle.isNull())
115 {
116 return;
117 }
118 QString str_pt_list1 = xmlEle.text();
119 std::istringstream ss(str_pt_list1.toStdString());
120 std::string line_str;
121 while (!ss.eof())
122 {
123 std::getline(ss, line_str);
124 boost::trim_right(line_str);
125 if (line_str.empty())
126 {
127 continue;
128 }
129 std::istringstream line_ss(line_str);
130 std::size_t pt_id = 0;
131 std::array<double, 3> pt_xyz;
132 line_ss >> pt_id;
133 for (int i = 0; i < dim; i++)
134 {
135 line_ss >> pt_xyz[i];
136 }
137 points[pt_id - 1] = new GeoLib::Point(pt_xyz, pt_id);
138 }
139}

Referenced by readSuperMesh().

◆ readSuperMesh()

void FileIO::FEFLOWGeoInterface::readSuperMesh ( std::ifstream & in,
unsigned dimension,
std::vector< GeoLib::Point * > & points,
std::vector< GeoLib::Polyline * > & lines )
static

read points and polylines in Supermesh section

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

Definition at line 141 of file FEFLOWGeoInterface.cpp.

145{
146 // get XML strings
147 std::ostringstream oss;
148 std::string line_string;
149 while (true)
150 {
151 std::getline(in, line_string);
152 BaseLib::trim(line_string);
153 oss << line_string << "\n";
154 if (line_string.find("</supermesh>") != std::string::npos)
155 {
156 break;
157 }
158 }
159 const QString strXML(oss.str().c_str());
160
161 // convert string to XML
162 QDomDocument doc;
163 if (!doc.setContent(strXML))
164 {
165 ERR("FEFLOWGeoInterface::readSuperMesh(): Illegal XML format error");
166 return;
167 }
168
169 // get geometry data from XML
170 QDomElement docElem = doc.documentElement(); // #supermesh
171 // #nodes
172 QDomElement nodesEle = docElem.firstChildElement("nodes");
173 if (nodesEle.isNull())
174 {
175 return;
176 }
177
178 {
179 const QString str = nodesEle.attribute("count");
180 const long n_points = str.toLong();
181 points.resize(n_points);
182 // fixed
183 readPoints(nodesEle, "fixed", dimension, points);
184 readPoints(nodesEle, "linear", dimension, points);
185 readPoints(nodesEle, "parabolic", dimension, points);
186 }
187
188 // #polygons
189 QDomElement polygonsEle = docElem.firstChildElement("polygons");
190 if (polygonsEle.isNull())
191 {
192 return;
193 }
194
195 {
196 QDomNode child = polygonsEle.firstChild();
197 while (!child.isNull())
198 {
199 if (child.nodeName() != "polygon")
200 {
201 child = child.nextSibling();
202 continue;
203 }
204 QDomElement xmlEle = child.firstChildElement("nodes");
205 if (xmlEle.isNull())
206 {
207 continue;
208 }
209 const QString str = xmlEle.attribute("count");
210 const std::size_t n_points = str.toLong();
211 QString str_ptId_list = xmlEle.text().simplified();
212 {
213 auto* line = new GeoLib::Polyline(points);
214 lines.push_back(line);
215 std::istringstream ss(str_ptId_list.toStdString());
216 for (std::size_t i = 0; i < n_points; i++)
217 {
218 int pt_id = 0;
219 ss >> pt_id;
220 line->addPoint(pt_id - 1);
221 }
222 line->addPoint(line->getPointID(0));
223 }
224 child = child.nextSibling();
225 }
226 }
227}
static void readPoints(QDomElement &nodesEle, const std::string &tag, int dim, std::vector< GeoLib::Point * > &points)
void trim(std::string &str, char ch)

References ERR(), readPoints(), and BaseLib::trim().

Referenced by readFEFLOWFile(), and FileIO::FEFLOWMeshInterface::readFEFLOWFile().


The documentation for this class was generated from the following files: