OGS
FileIO::FEFLOWGeoInterface Class Reference

Detailed Description

Interface to geometric data in FEFLOW files

Definition at line 29 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 27 of file FEFLOWGeoInterface.cpp.

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

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 111 of file FEFLOWGeoInterface.cpp.

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

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 145 of file FEFLOWGeoInterface.cpp.

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

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

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


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