36 template <
typename It>
39 return {std::strtod((++it)->c_str(),
nullptr),
40 std::strtod((++it)->c_str(),
nullptr),
41 std::strtod((++it)->c_str(),
nullptr)};
48 const std::string& filename)
50 std::ifstream in(filename.c_str());
53 ERR(
"GMSInterface::readBoreholeFromGMS(): Could not open file {:s}.",
58 double depth(-9999.0);
62 std::list<std::string>::const_iterator it;
66 std::getline(in, line);
69 while (std::getline(in, line))
73 if (fields.size() >= 5)
75 if (*fields.begin() == cName)
85 if (newBorehole ==
nullptr)
87 newBorehole->
addSoilLayer(pnt[0], pnt[1], pnt[2], sName);
94 "GMSInterface::readBoreholeFromGMS(): Skipped layer "
95 "'{:s}' in borehole '{:s}' because of thickness 0.0.",
101 if (newBorehole !=
nullptr)
103 newBorehole->
setDepth((*newBorehole)[2] - depth);
104 boreholes->push_back(newBorehole);
106 cName = *fields.begin();
111 cName, pnt[0], pnt[1], pnt[2], 0);
117 ERR(
"GMSInterface::readBoreholeFromGMS(): Error reading format.");
121 if (newBorehole !=
nullptr)
123 newBorehole->
setDepth((*newBorehole)[2] - depth);
124 boreholes->push_back(newBorehole);
128 if (boreholes->empty())
136 const std::vector<GeoLib::Point*>* stations,
const std::string& filename)
138 std::ofstream out(filename.c_str(), std::ios::out);
142 <<
"\t" << std::fixed <<
"X"
151 for (
auto station_as_point : *stations)
154 std::vector<GeoLib::Point*> profile = station->
getProfile();
155 std::vector<std::string> soilNames = station->getSoilNames();
157 std::string current_soil_name;
159 std::size_t nLayers = profile.size();
160 for (std::size_t i = 1; i < nLayers; i++)
162 if ((i > 1) && (soilNames[i] == soilNames[i - 1]))
166 current_soil_name = soilNames[i];
168 out << station->getName() <<
"\t" << std::fixed
169 << (*(profile[i - 1]))[0] <<
"\t" << (*(profile[i - 1]))[1]
170 <<
"\t" << (*(profile[i - 1]))[2] <<
"\t"
171 << current_soil_name <<
"\n";
173 out << station->getName() <<
"\t" << std::fixed
174 << (*(profile[nLayers - 1]))[0] <<
"\t"
175 << (*(profile[nLayers - 1]))[1] <<
"\t"
176 << (*(profile[nLayers - 1]))[2] <<
"\t" << current_soil_name
187 std::ifstream in(filename.c_str());
190 ERR(
"GMSInterface::readGMS3DMMesh(): Could not open file {:s}.",
196 std::getline(in, line);
197 if (line !=
"MESH3D")
199 ERR(
"GMSInterface::readGMS3DMMesh(): Could not read expected file "
204 INFO(
"GMSInterface::readGMS3DMMesh(): Read GMS-3DM mesh.");
205 std::vector<MeshLib::Node*> nodes;
206 std::vector<MeshLib::Element*> elements;
207 std::vector<int> mat_ids;
208 std::map<unsigned, unsigned> id_map;
217 while (std::getline(in, line))
221 std::stringstream str(line);
222 str >> dummy >>
id >> x[0] >> x[1] >> x[2];
224 id_map.insert(std::pair<unsigned, unsigned>(
id, count++));
225 nodes.push_back(node);
232 in.open(filename.c_str());
233 std::getline(in, line);
234 unsigned node_idx[6];
236 while (std::getline(in, line))
238 std::string element_id(line.substr(0, 3));
239 std::stringstream str(line);
241 if (element_id ==
"E6W")
243 str >> dummy >>
id >> node_idx[0] >> node_idx[1] >> node_idx[2] >>
244 node_idx[3] >> node_idx[4] >> node_idx[5] >> mat_id;
246 for (
unsigned k(0); k < 6; k++)
248 prism_nodes[k] = nodes[id_map.find(node_idx[k])->second];
251 mat_ids.push_back(mat_id);
253 else if (element_id ==
"E4T")
255 str >> dummy >>
id >> node_idx[0] >> node_idx[1] >> node_idx[2] >>
256 node_idx[3] >> mat_id;
258 for (
unsigned k(0); k < 4; k++)
260 tet_nodes[k] = nodes[id_map.find(node_idx[k])->second];
263 mat_ids.push_back(mat_id);
265 else if ((element_id ==
"E4P") ||
269 str >> dummy >>
id >> node_idx[0] >> node_idx[1] >> node_idx[2] >>
270 node_idx[3] >> node_idx[4] >> mat_id;
272 for (
unsigned k(0); k < 5; k++)
274 pyramid_nodes[k] = nodes[id_map.find(node_idx[k])->second];
277 mat_ids.push_back(mat_id);
279 else if (element_id ==
"ND ")
286 "GMSInterface::readGMS3DMMesh() - Element type '{:s}' not "
294 INFO(
"GMSInterface::readGMS3DMMesh(): finished.");
296 const std::string mesh_name =
299 if (mat_ids.size() == elements.size())
305 ERR(
"Could not create PropertyVector for material ids.");
309 opt_pv->reserve(mat_ids.size());
310 std::copy(mat_ids.cbegin(), mat_ids.cend(),
311 std::back_inserter(*opt_pv));
315 ERR(
"Ignoring Material IDs information (does not match number of "
318 return new MeshLib::Mesh(mesh_name, nodes, elements, properties);
Definition of the GMSInterface class.
void INFO(char const *fmt, Args const &... args)
void ERR(char const *fmt, Args const &... args)
void WARN(char const *fmt, Args const &... args)
Definition of mesh-related Enumerations.
Definition of the Mesh class.
Definition of the Node class.
Definition of the Prism class.
Definition of the Pyramid class.
Definition of the StationBorehole class.
Definition of the Tet class.
static MeshLib::Mesh * readGMS3DMMesh(const std::string &filename)
Reads a GMS *.3dm file and converts it to an CFEMesh.
static int readBoreholesFromGMS(std::vector< GeoLib::Point * > *boreholes, const std::string &filename)
Imports borehole data from a file in GMS-format.
static void writeBoreholesToGMS(const std::vector< GeoLib::Point * > *stations, const std::string &filename)
A borehole as a geometric object.
static StationBorehole * createStation(const std::string &name, double x, double y, double z, double depth, const std::string &date="")
Creates a new borehole object based on the given parameters.
void addSoilLayer(double thickness, const std::string &soil_name)
Add a soil layer to the boreholes stratigraphy.
const std::vector< Point * > & getProfile() const
void setDepth(double depth)
Sets the depth of the borehole.
Property manager on mesh items. Class Properties manages scalar, vector or matrix properties....
PropertyVector< T > * createNewPropertyVector(std::string const &name, MeshItemType mesh_item_type, std::size_t n_components=1)
std::string extractBaseNameWithoutExtension(std::string const &pathname)
std::vector< std::string > splitString(std::string const &str)
void cleanupVectorElements(std::vector< T1 * > const &items, std::vector< T2 * > const &dependent_items)
void copy(PETScVector const &x, PETScVector &y)
std::array< double, 3 > parsePointCoordinates(It &it)