31 std::ifstream in(filename.c_str());
34 ERR(
"FEFLOWMeshInterface::readFEFLOWFile(): Could not open file {:s}.",
41 std::vector<GeoLib::Point*> points;
42 std::vector<GeoLib::Polyline*> lines;
44 bool isXZplane =
false;
46 std::vector<MeshLib::Node*> vec_nodes;
47 std::vector<MeshLib::Element*> vec_elements;
49 std::vector<std::vector<std::size_t>> vec_elementsets;
51 std::string line_string;
52 std::stringstream line_stream;
55 std::getline(in, line_string);
56 boost::trim_right(line_string);
59 if (line_string.find(
"CLASS") != std::string::npos)
61 std::getline(in, line_string);
62 boost::trim_right(line_string);
63 line_stream.str(line_string);
74 else if (line_string ==
"DIMENS")
77 std::getline(in, line_string);
78 line_stream.str(line_string);
84 vec_nodes.resize(fem_dim.
n_nodes);
85 std::size_t count = 0;
86 double dummy_coords[3] = {};
87 std::generate(vec_nodes.begin(), vec_nodes.end(),
89 { return new MeshLib::Node(dummy_coords, count++); });
94 else if (line_string ==
"NODE")
96 assert(!vec_nodes.empty());
130 ERR(
"FEFLOWInterface::readFEFLOWFile(): Unsupported element "
131 "type with the number of node = {:d} and dim = {:d}",
133 std::for_each(vec_nodes.begin(), vec_nodes.end(),
140 for (std::size_t i = 0; i < fem_dim.
n_elements; i++)
142 std::getline(in, line_string);
143 vec_elements.push_back(
144 readElement(fem_dim, eleType, line_string, vec_nodes));
147 else if (line_string ==
"VARNODE")
149 assert(!vec_nodes.empty());
154 if (!std::getline(in, line_string))
156 ERR(
"FEFLOWInterface::readFEFLOWFile(): read element "
158 std::for_each(vec_nodes.begin(), vec_nodes.end(),
165 for (std::size_t i = 0; i < fem_dim.
n_elements; i++)
167 std::getline(in, line_string);
168 vec_elements.push_back(
readElement(line_string, vec_nodes));
173 else if (line_string ==
"COOR")
177 else if (line_string ==
"XYZCOOR")
182 else if (line_string ==
"ELEV_I")
192 else if (line_string ==
"GRAVITY")
194 std::getline(in, line_string);
195 line_stream.str(line_string);
197 line_stream >> vec[0] >> vec[1] >> vec[2];
198 if (vec[0] == 0.0 && vec[1] == -1.0 && vec[2] == 0.0)
207 else if (line_string ==
"ELEMENTALSETS")
213 else if (line_string ==
"SUPERMESH")
223 std::string project_name(
226 std::make_unique<MeshLib::Mesh>(project_name, vec_nodes, vec_elements));
227 INFO(
"Set values for material property.");
228 auto opt_material_ids(mesh->getProperties().createNewPropertyVector<
int>(
230 if (!opt_material_ids)
232 WARN(
"Could not create PropertyVector for MaterialIDs in Mesh.");
236 opt_material_ids->resize(mesh->getNumberOfElements());
237 setMaterialIDs(fem_class, fem_dim, lines, vec_elementsets, vec_elements,
243 for (
auto* nod : vec_nodes)
245 (*nod)[2] = (*nod)[1];
250 for (
auto* pt : points)
258 return mesh.release();
262 std::ifstream& in, std::vector<MeshLib::Node*>& vec_nodes)
264 std::string line_string;
267 for (
unsigned k = 0; k < vec_nodes.size(); ++k)
270 if (!std::getline(in, line_string))
272 ERR(
"Could not read the node '{:d}'.", k);
273 for (
auto* n : vec_nodes)
279 std::stringstream line_stream;
280 line_stream.str(line_string);
282 for (std::size_t i(0); i < 3; ++i)
284 if (!(line_stream >> (*vec_nodes[k])[i]))
286 ERR(
"Could not parse coordinate {:d} of node '{:d}'.", i, k);
287 for (
auto* n : vec_nodes)
293 if (!(line_stream >> dummy_char) && i < 2)
295 ERR(
"Could not parse node '{:d}'.", k);
296 for (
auto* n : vec_nodes)
308 std::vector<MeshLib::Node*>
const& vec_nodes)
310 const std::size_t no_nodes_per_layer =
314 assert(no_nodes_per_layer > 0);
315 const std::size_t n_lines = (no_nodes_per_layer - 1) / 12 + 1;
316 const std::size_t n_layers =
318 std::string line_string;
319 std::stringstream line_stream;
323 for (
unsigned k = 0; k < 2; k++)
326 for (std::size_t i = 0; i < n_lines; i++)
328 std::getline(in, line_string);
329 line_stream.str(line_string);
330 for (
unsigned j = 0; j < 12; j++)
332 if (i * 12 + j >= no_nodes_per_layer)
336 line_stream >> x >> dummy_char;
337 for (std::size_t l = 0; l < n_layers; l++)
339 const std::size_t n = i * 12 + l * no_nodes_per_layer + j;
399 std::vector<MeshLib::Node*>& vec_nodes)
401 const std::size_t no_nodes_per_layer =
404 std::string str_nodeList;
405 std::string line_string;
406 std::stringstream line_stream;
410 std::streamoff pos_prev_line = 0;
413 pos_prev_line = in.tellg();
414 std::getline(in, line_string);
415 boost::trim_right(line_string);
419 if (!in || std::isalpha(line_string[0]))
423 else if (line_string.empty())
427 else if (line_string[0] ==
'\t')
431 else if (columns.size() == 1)
441 if (mode != 3 && !str_nodeList.empty())
445 for (
auto n0 : vec_nodeIDs)
447 const std::size_t n = n0 - 1 + l * no_nodes_per_layer;
448 (*vec_nodes[n])[2] = z;
450 str_nodeList.clear();
466 line_stream.str(line_string);
468 std::getline(line_stream, str_nodeList);
469 boost::trim(str_nodeList);
476 str_nodeList +=
" " + line_string;
481 if (std::isalpha(line_string[0]))
483 in.seekg(pos_prev_line);
488 std::string
const& line, std::vector<MeshLib::Node*>
const& nodes)
490 std::stringstream ss(line);
496 std::size_t n_nodes_of_element;
501 n_nodes_of_element = 4;
505 n_nodes_of_element = 6;
509 n_nodes_of_element = 8;
512 WARN(
"Could not parse element type.");
517 for (std::size_t i = 0; i < n_nodes_of_element; ++i)
526 for (std::size_t k(0); k < n_nodes_of_element; ++k)
528 ele_nodes[k] = nodes[idx[k] - 1];
533 const unsigned n_half_nodes = n_nodes_of_element / 2;
534 for (
unsigned k(0); k < n_half_nodes; ++k)
536 ele_nodes[k] = nodes[idx[k + n_half_nodes] - 1];
537 ele_nodes[k + n_half_nodes] = nodes[idx[k] - 1];
608 std::ifstream& in, std::vector<std::vector<std::size_t>>& vec_elementsets)
610 auto compressSpaces = [](std::string
const& str)
612 std::stringstream ss(str);
618 new_str +=
" " + word;
623 std::string line_string;
624 std::string str_idList;
625 std::streampos pos_prev_line = 0;
628 pos_prev_line = in.tellg();
629 std::getline(in, line_string);
636 else if (line_string.empty())
640 else if (std::isalpha(line_string[0]))
644 else if (line_string[0] ==
' ')
648 else if (line_string[0] ==
'\t')
654 ERR(
"Failed during parsing of an ELEMENTALSETS section in a FEFLOW "
659 if (mode != 2 && !str_idList.empty())
672 std::string set_name;
675 if (line_string[0] ==
'"')
677 auto pos = line_string.find_last_of(
'"');
678 set_name = line_string.substr(1, pos - 1);
679 ids = line_string.substr(pos + 1);
683 auto pos = line_string.find_first_of(
' ');
684 set_name = line_string.substr(0, pos);
685 ids = line_string.substr(pos + 1);
687 INFO(
"Found an element group - {:s}", set_name.data());
688 str_idList += compressSpaces(ids);
694 str_idList += compressSpaces(line_string);
698 if (std::isalpha(line_string[0]))
700 in.seekg(pos_prev_line);
707 std::vector<GeoLib::Polyline*>
const& lines,
708 std::vector<std::vector<std::size_t>>
const& vec_elementsets,
709 std::vector<MeshLib::Element*>
const& vec_elements,
710 std::vector<int>& material_ids)
712 assert(material_ids.size() == vec_elements.size());
713 if (!vec_elementsets.empty())
715 for (std::size_t matid = 0; matid < vec_elementsets.size(); ++matid)
717 auto& eids = vec_elementsets[matid];
718 for (
auto eid : eids)
720 material_ids[eid - 1] =
725 else if (!lines.empty())
727 for (std::size_t i = 0; i < vec_elements.size(); ++i)
730 std::size_t matId = 0;
731 for (std::size_t j = 0; j < lines.size(); j++)
746 material_ids[i] = matId;
751 const std::size_t no_nodes_per_layer =
753 for (std::size_t i = 0; i < vec_elements.size(); i++)
756 std::size_t e_min_nodeID = std::numeric_limits<std::size_t>::max();
759 e_min_nodeID = std::min(e_min_nodeID, getNodeIndex(*e, j));
761 std::size_t layer_id = e_min_nodeID / no_nodes_per_layer;
762 material_ids[i] = layer_id;
void setMaterialIDs(FEM_CLASS const &fem_class, FEM_DIM const &fem_dim, std::vector< GeoLib::Polyline * > const &lines, std::vector< std::vector< std::size_t > > const &vec_elementsets, std::vector< MeshLib::Element * > const &vec_elements, std::vector< int > &material_ids)