Skip to content
Snippets Groups Projects
Commit 439dd572 authored by Norihiro Watanabe's avatar Norihiro Watanabe
Browse files

apply clang-format to FEFLOW IO

parent d3323efd
No related branches found
No related tags found
No related merge requests found
......@@ -24,18 +24,18 @@
#include "GeoLib/Point.h"
#include "GeoLib/Polygon.h"
namespace GeoLib
{
namespace IO
{
void FEFLOWGeoInterface::readFEFLOWFile(const std::string &filename, GeoLib::GEOObjects& geoObjects)
void FEFLOWGeoInterface::readFEFLOWFile(const std::string& filename,
GeoLib::GEOObjects& geoObjects)
{
std::ifstream in(filename.c_str());
if (!in)
{
ERR("FEFLOWGeoInterface::readFEFLOWFile(): Could not open file %s.", filename.c_str());
ERR("FEFLOWGeoInterface::readFEFLOWFile(): Could not open file %s.",
filename.c_str());
return;
}
......@@ -51,14 +51,14 @@ void FEFLOWGeoInterface::readFEFLOWFile(const std::string &filename, GeoLib::GEO
{
getline(in, line_string);
//....................................................................
// CLASS
if (line_string.find("CLASS") != std::string::npos) // the version number follows afterward, e.g. CLASS (v.5.313)
// CLASS: the version number follows afterward, e.g. CLASS (v.5.313)
if (line_string.find("CLASS") != std::string::npos)
{
getline(in, line_string);
line_stream.str(line_string);
// problem class, time mode, problem orientation, dimension, ...
unsigned dummy = 0;
for (int i=0; i<3; i++)
for (int i = 0; i < 3; i++)
line_stream >> dummy;
line_stream >> dimension;
line_stream.clear();
......@@ -69,7 +69,7 @@ void FEFLOWGeoInterface::readFEFLOWFile(const std::string &filename, GeoLib::GEO
{
getline(in, line_string);
line_stream.str(line_string);
double vec[3] = { };
double vec[3] = {};
line_stream >> vec[0] >> vec[1] >> vec[2];
if (vec[0] == 0.0 && vec[1] == -1.0 && vec[2] == 0.0)
// x-z plane
......@@ -104,13 +104,15 @@ void FEFLOWGeoInterface::readFEFLOWFile(const std::string &filename, GeoLib::GEO
(*pt)[1] = .0;
}
}
}
void FEFLOWGeoInterface::readPoints(QDomElement &nodesEle, const std::string &tag, int dim, std::vector<GeoLib::Point*> &points)
void FEFLOWGeoInterface::readPoints(QDomElement& nodesEle,
const std::string& tag,
int dim,
std::vector<GeoLib::Point*>& points)
{
QDomElement xmlEle = nodesEle.firstChildElement(QString::fromStdString(tag));
QDomElement xmlEle =
nodesEle.firstChildElement(QString::fromStdString(tag));
if (xmlEle.isNull())
return;
QString str_pt_list1 = xmlEle.text();
......@@ -120,10 +122,11 @@ void FEFLOWGeoInterface::readPoints(QDomElement &nodesEle, const std::string &ta
{
std::getline(ss, line_str);
BaseLib::trim(line_str, ' ');
if (line_str.empty()) continue;
if (line_str.empty())
continue;
std::istringstream line_ss(line_str);
std::size_t pt_id = 0;
std::array<double,3> pt_xyz;
std::array<double, 3> pt_xyz;
line_ss >> pt_id;
for (int i = 0; i < dim; i++)
line_ss >> pt_xyz[i];
......@@ -131,8 +134,10 @@ void FEFLOWGeoInterface::readPoints(QDomElement &nodesEle, const std::string &ta
}
}
void FEFLOWGeoInterface::readSuperMesh(std::ifstream &in, unsigned dimension, std::vector<GeoLib::Point*>* &points, std::vector<GeoLib::Polyline*>* &lines)
void FEFLOWGeoInterface::readSuperMesh(std::ifstream& in,
unsigned dimension,
std::vector<GeoLib::Point*>*& points,
std::vector<GeoLib::Polyline*>*& lines)
{
// get XML strings
std::ostringstream oss;
......@@ -156,7 +161,7 @@ void FEFLOWGeoInterface::readSuperMesh(std::ifstream &in, unsigned dimension, st
}
// get geometry data from XML
QDomElement docElem = doc.documentElement(); // #supermesh
QDomElement docElem = doc.documentElement(); // #supermesh
// #nodes
points = new std::vector<GeoLib::Point*>();
QDomElement nodesEle = docElem.firstChildElement("nodes");
......@@ -167,7 +172,7 @@ void FEFLOWGeoInterface::readSuperMesh(std::ifstream &in, unsigned dimension, st
const QString str = nodesEle.attribute("count");
const long n_points = str.toLong();
points->resize(n_points);
//fixed
// fixed
readPoints(nodesEle, "fixed", dimension, *points);
readPoints(nodesEle, "linear", dimension, *points);
readPoints(nodesEle, "parabolic", dimension, *points);
......@@ -211,5 +216,5 @@ void FEFLOWGeoInterface::readSuperMesh(std::ifstream &in, unsigned dimension, st
}
}
} // IO
} // GeoLib
} // IO
} // GeoLib
......@@ -17,16 +17,15 @@ class QDomElement;
namespace GeoLib
{
class GEOObjects;
class Point;
class Polyline;
class GEOObjects;
class Point;
class Polyline;
}
namespace GeoLib
{
namespace IO
{
/**
* Interface to geometric data in FEFLOW files
*/
......@@ -39,22 +38,27 @@ public:
* This function reads geometry data given in Supermesh.
*
* @param filename FEFLOW file name
* @param geo_objects Geometric objects where imported geometry data are added
* @param geo_objects Geometric objects where imported geometry data are
* added
*/
void readFEFLOWFile(const std::string &filename, GeoLib::GEOObjects& geo_objects);
void readFEFLOWFile(const std::string& filename,
GeoLib::GEOObjects& geo_objects);
/// 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
static void readSuperMesh(std::ifstream &feflow_file, unsigned dimension, std::vector<GeoLib::Point*>* &points, std::vector<GeoLib::Polyline*>* &lines);
/// 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
static void readSuperMesh(std::ifstream& feflow_file, unsigned dimension,
std::vector<GeoLib::Point*>*& points,
std::vector<GeoLib::Polyline*>*& lines);
private:
//// read point data in Supermesh
static void readPoints(QDomElement &nodesEle, const std::string &tag, int dim, std::vector<GeoLib::Point*> &points);
static void readPoints(QDomElement& nodesEle, const std::string& tag,
int dim, std::vector<GeoLib::Point*>& points);
};
} // IO
} // GeoLib
} // IO
} // GeoLib
#endif /* FEFLOWGEOINTERFACE_H_ */
......@@ -28,13 +28,13 @@ namespace MeshLib
{
namespace IO
{
MeshLib::Mesh* FEFLOWMeshInterface::readFEFLOWFile(const std::string &filename)
MeshLib::Mesh* FEFLOWMeshInterface::readFEFLOWFile(const std::string& filename)
{
std::ifstream in(filename.c_str());
if (!in)
{
ERR("FEFLOWMeshInterface::readFEFLOWFile(): Could not open file %s.", filename.c_str());
ERR("FEFLOWMeshInterface::readFEFLOWFile(): Could not open file %s.",
filename.c_str());
return nullptr;
}
......@@ -56,13 +56,17 @@ MeshLib::Mesh* FEFLOWMeshInterface::readFEFLOWFile(const std::string &filename)
{
getline(in, line_string);
//....................................................................
// CLASS
if (line_string.find("CLASS") != std::string::npos) // the version number follows afterward, e.g. CLASS (v.5.313)
// CLASS: the version number follows afterward, e.g. CLASS (v.5.313)
if (line_string.find("CLASS") != std::string::npos)
{
getline(in, line_string);
line_stream.str(line_string);
// problem class, time mode, problem orientation, dimension, nr. layers for 3D, saturation switch, precision of results, precision of coordinates
line_stream >> fem_class.problem_class >> fem_class.time_mode >> fem_class.orientation >> fem_class.dimension >> fem_class.n_layers3d;
// problem class, time mode, problem orientation, dimension, nr.
// layers for 3D, saturation switch, precision of results, precision
// of coordinates
line_stream >> fem_class.problem_class >> fem_class.time_mode >>
fem_class.orientation >> fem_class.dimension >>
fem_class.n_layers3d;
line_stream.clear();
}
//....................................................................
......@@ -72,13 +76,18 @@ MeshLib::Mesh* FEFLOWMeshInterface::readFEFLOWFile(const std::string &filename)
// DIMENS
getline(in, line_string);
line_stream.str(line_string);
line_stream >> fem_dim.n_nodes >> fem_dim.n_elements >> fem_dim.n_nodes_of_element >> std::ws;
// create node pointers with dummy coordinates to create element objects.
line_stream >> fem_dim.n_nodes >> fem_dim.n_elements >>
fem_dim.n_nodes_of_element >> std::ws;
// create node pointers with dummy coordinates to create element
// objects.
// True coordinates are set later in COOR and ELEV_I.
vec_nodes.resize(fem_dim.n_nodes);
std::size_t count = 0;
double dummy_coords[3] = {};
std::generate(vec_nodes.begin(), vec_nodes.end(), [&]() { return new MeshLib::Node(dummy_coords, count++); });
std::generate(vec_nodes.begin(), vec_nodes.end(), [&]()
{
return new MeshLib::Node(dummy_coords, count++);
});
line_stream.clear();
}
//....................................................................
......@@ -92,27 +101,39 @@ MeshLib::Mesh* FEFLOWMeshInterface::readFEFLOWFile(const std::string &filename)
eleType = MeshLib::MeshElemType::LINE;
else if (fem_dim.n_nodes_of_element == 3)
eleType = MeshLib::MeshElemType::TRIANGLE;
else if (fem_dim.n_nodes_of_element == 4 && fem_class.dimension == 2)
else if (fem_dim.n_nodes_of_element == 4 &&
fem_class.dimension == 2)
eleType = MeshLib::MeshElemType::QUAD;
else if (fem_dim.n_nodes_of_element == 4 && fem_class.dimension == 3)
else if (fem_dim.n_nodes_of_element == 4 &&
fem_class.dimension == 3)
eleType = MeshLib::MeshElemType::TETRAHEDRON;
else if (fem_dim.n_nodes_of_element == 6 && fem_class.dimension == 3)
else if (fem_dim.n_nodes_of_element == 6 &&
fem_class.dimension == 3)
eleType = MeshLib::MeshElemType::PRISM;
else if (fem_dim.n_nodes_of_element == 8 && fem_class.dimension == 3)
else if (fem_dim.n_nodes_of_element == 8 &&
fem_class.dimension == 3)
eleType = MeshLib::MeshElemType::HEXAHEDRON;
if (eleType == MeshLib::MeshElemType::INVALID) {
ERR("FEFLOWInterface::readFEFLOWFile(): Unsupported element type with the number of node = %d and dim = %d", fem_dim.n_nodes_of_element, fem_class.dimension);
std::for_each(vec_nodes.begin(), vec_nodes.end(), [](MeshLib::Node* nod) { delete nod;});
if (eleType == MeshLib::MeshElemType::INVALID)
{
ERR("FEFLOWInterface::readFEFLOWFile(): Unsupported element "
"type with the number of node = %d and dim = %d",
fem_dim.n_nodes_of_element, fem_class.dimension);
std::for_each(vec_nodes.begin(), vec_nodes.end(),
[](MeshLib::Node* nod)
{
delete nod;
});
vec_nodes.clear();
return nullptr;
}
vec_elements.reserve(fem_dim.n_elements);
for (std::size_t i=0; i<fem_dim.n_elements; i++)
for (std::size_t i = 0; i < fem_dim.n_elements; i++)
{
getline(in, line_string);
vec_elements.push_back(readElement(fem_dim, eleType, line_string, vec_nodes));
vec_elements.push_back(
readElement(fem_dim, eleType, line_string, vec_nodes));
}
}
//....................................................................
......@@ -135,7 +156,7 @@ MeshLib::Mesh* FEFLOWMeshInterface::readFEFLOWFile(const std::string &filename)
{
getline(in, line_string);
line_stream.str(line_string);
double vec[3] = { };
double vec[3] = {};
line_stream >> vec[0] >> vec[1] >> vec[2];
if (vec[0] == 0.0 && vec[1] == -1.0 && vec[2] == 0.0)
// x-z plane
......@@ -152,7 +173,8 @@ MeshLib::Mesh* FEFLOWMeshInterface::readFEFLOWFile(const std::string &filename)
// SUPERMESH
else if (line_string.compare("SUPERMESH") == 0)
{
GeoLib::IO::FEFLOWGeoInterface::readSuperMesh(in, fem_class.dimension, points, lines);
GeoLib::IO::FEFLOWGeoInterface::readSuperMesh(
in, fem_class.dimension, points, lines);
}
//....................................................................
}
......@@ -165,13 +187,15 @@ MeshLib::Mesh* FEFLOWMeshInterface::readFEFLOWFile(const std::string &filename)
new MeshLib::Mesh(project_name, vec_nodes, vec_elements)));
INFO("Set values for material property.");
auto opt_material_ids(mesh->getProperties().createNewPropertyVector<int>(
"MaterialIDs", MeshLib::MeshItemType::Cell, 1)
);
if (!opt_material_ids) {
"MaterialIDs", MeshLib::MeshItemType::Cell, 1));
if (!opt_material_ids)
{
WARN("Could not create PropertyVector for MaterialIDs in Mesh.");
} else {
}
else
{
setMaterialIDs(fem_class, fem_dim, lines, vec_elementsets, vec_elements,
*opt_material_ids);
*opt_material_ids);
}
if (isXZplane)
......@@ -194,17 +218,22 @@ MeshLib::Mesh* FEFLOWMeshInterface::readFEFLOWFile(const std::string &filename)
return mesh.release();
}
void FEFLOWMeshInterface::readNodeCoordinates(std::ifstream &in, const FEM_CLASS &fem_class, const FEM_DIM &fem_dim, std::vector<MeshLib::Node*> &vec_nodes)
void FEFLOWMeshInterface::readNodeCoordinates(
std::ifstream& in, const FEM_CLASS& fem_class, const FEM_DIM& fem_dim,
std::vector<MeshLib::Node*>& vec_nodes)
{
const std::size_t no_nodes_per_layer = (fem_class.dimension == 2) ? fem_dim.n_nodes : fem_dim.n_nodes / (fem_class.n_layers3d + 1);
assert(no_nodes_per_layer>0);
const std::size_t n_lines = (no_nodes_per_layer-1) / 12 + 1;
const std::size_t n_layers = (fem_class.dimension == 3) ? fem_class.n_layers3d + 1 : 1;
const std::size_t no_nodes_per_layer =
(fem_class.dimension == 2)
? fem_dim.n_nodes
: fem_dim.n_nodes / (fem_class.n_layers3d + 1);
assert(no_nodes_per_layer > 0);
const std::size_t n_lines = (no_nodes_per_layer - 1) / 12 + 1;
const std::size_t n_layers =
(fem_class.dimension == 3) ? fem_class.n_layers3d + 1 : 1;
std::string line_string;
std::stringstream line_stream;
double x;
char dummy_char; // for comma(,)
char dummy_char; // for comma(,)
// x, y
for (unsigned k = 0; k < 2; k++)
{
......@@ -233,27 +262,34 @@ void FEFLOWMeshInterface::readNodeCoordinates(std::ifstream &in, const FEM_CLASS
}
}
std::vector<std::size_t> FEFLOWMeshInterface::getIndexList(const std::string &str_ranges)
std::vector<std::size_t> FEFLOWMeshInterface::getIndexList(
const std::string& str_ranges)
{
std::vector<std::size_t> vec_node_IDs;
// insert space before and after minus for splitting
std::string str_ranges2(BaseLib::replaceString("-", " # ", str_ranges));
std::string str_ranges2(BaseLib::replaceString("-", " # ", str_ranges));
BaseLib::trim(str_ranges2);
auto splitted_str = BaseLib::splitString(str_ranges2, ' ');
bool is_range = false;
for (auto str : splitted_str)
{
if (str.empty()) continue;
if (str[0]=='#') {
if (str.empty())
continue;
if (str[0] == '#')
{
is_range = true;
} else if (is_range) {
}
else if (is_range)
{
const std::size_t start = vec_node_IDs.back();
const std::size_t end = BaseLib::str2number<std::size_t>(str);
for (std::size_t i=start+1; i<end+1; i++)
for (std::size_t i = start + 1; i < end + 1; i++)
vec_node_IDs.push_back(i);
is_range = false;
} else {
}
else
{
BaseLib::trim(str);
vec_node_IDs.push_back(BaseLib::str2number<std::size_t>(str));
}
......@@ -262,15 +298,20 @@ std::vector<std::size_t> FEFLOWMeshInterface::getIndexList(const std::string &st
return vec_node_IDs;
}
void FEFLOWMeshInterface::readElevation(std::ifstream &in, const FEM_CLASS &fem_class, const FEM_DIM &fem_dim, std::vector<MeshLib::Node*> &vec_nodes)
void FEFLOWMeshInterface::readElevation(std::ifstream& in,
const FEM_CLASS& fem_class,
const FEM_DIM& fem_dim,
std::vector<MeshLib::Node*>& vec_nodes)
{
const std::size_t no_nodes_per_layer = fem_dim.n_nodes / (fem_class.n_layers3d + 1);
const std::size_t no_nodes_per_layer =
fem_dim.n_nodes / (fem_class.n_layers3d + 1);
double z = .0;
std::string str_nodeList;
std::string line_string;
std::stringstream line_stream;
std::size_t l = 0;
unsigned mode = 0; // 0: exit, 1: slice no, 2: elevation value, 3: continued line of mode 2
unsigned mode = 0; // 0: exit, 1: slice no, 2: elevation value, 3:
// continued line of mode 2
int pos_prev_line = 0;
while (true)
{
......@@ -283,15 +324,16 @@ void FEFLOWMeshInterface::readElevation(std::ifstream &in, const FEM_CLASS &fem_
mode = 0;
else if (line_string.empty())
continue;
else if (line_string[0]=='\t')
else if (line_string[0] == '\t')
mode = 3;
else if (columns.size()==1)
else if (columns.size() == 1)
mode = 1;
else // columns.size()>1
else // columns.size()>1
mode = 2;
// process stocked data
if (mode != 3 && !str_nodeList.empty()) {
if (mode != 3 && !str_nodeList.empty())
{
// process previous lines
auto vec_nodeIDs = getIndexList(str_nodeList);
for (auto n0 : vec_nodeIDs)
......@@ -302,20 +344,27 @@ void FEFLOWMeshInterface::readElevation(std::ifstream &in, const FEM_CLASS &fem_
str_nodeList.clear();
}
if (mode == 0) {
if (mode == 0)
{
break;
} else if (mode == 1) {
}
else if (mode == 1)
{
// slice number
l++;
assert(l+1==BaseLib::str2number<std::size_t>(columns.front()));
} else if (mode == 2) {
assert(l + 1 == BaseLib::str2number<std::size_t>(columns.front()));
}
else if (mode == 2)
{
// parse current line
line_stream.str(line_string);
line_stream >> z;
getline(line_stream, str_nodeList);
BaseLib::trim(str_nodeList, '\t');
line_stream.clear();
} else if (mode == 3) {
}
else if (mode == 3)
{
// continue reading node range
BaseLib::trim(line_string, '\t');
str_nodeList += " " + line_string;
......@@ -327,9 +376,9 @@ void FEFLOWMeshInterface::readElevation(std::ifstream &in, const FEM_CLASS &fem_
in.seekg(pos_prev_line);
}
MeshLib::Element* FEFLOWMeshInterface::readElement(const FEM_DIM &fem_dim,
const MeshLib::MeshElemType elem_type, const std::string& line,
const std::vector<MeshLib::Node*> &nodes)
MeshLib::Element* FEFLOWMeshInterface::readElement(
const FEM_DIM& fem_dim, const MeshLib::MeshElemType elem_type,
const std::string& line, const std::vector<MeshLib::Node*>& nodes)
{
std::stringstream ss(line);
......@@ -342,14 +391,15 @@ MeshLib::Element* FEFLOWMeshInterface::readElement(const FEM_DIM &fem_dim,
{
default:
for (unsigned k(0); k < fem_dim.n_nodes_of_element; ++k)
ele_nodes[k] = nodes[idx[k]-1];
ele_nodes[k] = nodes[idx[k] - 1];
break;
case MeshLib::MeshElemType::HEXAHEDRON:
case MeshLib::MeshElemType::PRISM:
const unsigned n_half_nodes = fem_dim.n_nodes_of_element/2;
for (unsigned k(0); k < n_half_nodes; ++k) {
ele_nodes[k] = nodes[idx[k+n_half_nodes]-1];
ele_nodes[k+n_half_nodes] = nodes[idx[k]-1];
const unsigned n_half_nodes = fem_dim.n_nodes_of_element / 2;
for (unsigned k(0); k < n_half_nodes; ++k)
{
ele_nodes[k] = nodes[idx[k + n_half_nodes] - 1];
ele_nodes[k + n_half_nodes] = nodes[idx[k] - 1];
}
break;
}
......@@ -374,13 +424,16 @@ MeshLib::Element* FEFLOWMeshInterface::readElement(const FEM_DIM &fem_dim,
}
}
void FEFLOWMeshInterface::readELEMENTALSETS(std::ifstream &in, std::vector<std::vector<std::size_t>> &vec_elementsets)
void FEFLOWMeshInterface::readELEMENTALSETS(
std::ifstream& in, std::vector<std::vector<std::size_t>>& vec_elementsets)
{
auto compressSpaces = [](std::string const& str) {
auto compressSpaces = [](std::string const& str)
{
std::stringstream ss(str);
std::string new_str;
std::string word;
while (ss) {
while (ss)
{
ss >> word;
new_str += " " + word;
}
......@@ -397,45 +450,55 @@ void FEFLOWMeshInterface::readELEMENTALSETS(std::ifstream &in, std::vector<std::
unsigned mode = 0;
if (!in)
mode = 0; // reached the end of the file
mode = 0; // reached the end of the file
else if (line_string.empty())
continue; // skip and see what comes next
continue; // skip and see what comes next
else if (std::isalpha(line_string[0]))
mode = 0; // reached the next section
mode = 0; // reached the next section
else if (line_string[0] == ' ')
mode = 1; // start of the element set definition
mode = 1; // start of the element set definition
else if (line_string[0] == '\t')
mode = 2; // continue the definition
mode = 2; // continue the definition
else
{
ERR("Failed during parsing of an ELEMENTALSETS section in a FEFLOW file");
ERR("Failed during parsing of an ELEMENTALSETS section in a FEFLOW "
"file");
break;
}
if (mode!=2 && !str_idList.empty()) {
if (mode != 2 && !str_idList.empty())
{
vec_elementsets.push_back(getIndexList(str_idList));
str_idList.clear();
}
if (mode == 0) {
if (mode == 0)
{
break;
} else if (mode == 1) {
}
else if (mode == 1)
{
// starting a new set
std::string set_name;
std::string ids;
BaseLib::trim(line_string, ' ');
if (line_string[0]=='"') { // multiple words
if (line_string[0] == '"')
{ // multiple words
auto pos = line_string.find_last_of('"');
set_name = line_string.substr(1, pos-1); // without quotation
ids = line_string.substr(pos+1);
} else { // single word
set_name = line_string.substr(1, pos - 1); // without quotation
ids = line_string.substr(pos + 1);
}
else
{ // single word
auto pos = line_string.find_first_of(' ');
set_name = line_string.substr(0, pos);
ids = line_string.substr(pos+1);
ids = line_string.substr(pos + 1);
}
INFO("Found an element group - %s", set_name.data());
str_idList += compressSpaces(ids);
} else {
}
else
{
// continue reading a element ids
BaseLib::trim(line_string, '\t');
str_idList += compressSpaces(line_string);
......@@ -444,23 +507,28 @@ void FEFLOWMeshInterface::readELEMENTALSETS(std::ifstream &in, std::vector<std::
// move stream position to previous line
if (std::isalpha(line_string[0]))
in.seekg(pos_prev_line);
}
void FEFLOWMeshInterface::setMaterialIDs(FEM_CLASS const& fem_class,
void FEFLOWMeshInterface::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)
std::vector<int>& material_ids)
{
if (!vec_elementsets.empty()) {
for (std::size_t matid=0; matid<vec_elementsets.size(); ++matid) {
auto &eids = vec_elementsets[matid];
if (!vec_elementsets.empty())
{
for (std::size_t matid = 0; matid < vec_elementsets.size(); ++matid)
{
auto& eids = vec_elementsets[matid];
for (auto eid : eids)
material_ids[eid-1] = matid; // Element IDs given by FEFLOW starts from one!
material_ids[eid - 1] =
matid; // Element IDs given by FEFLOW starts from one!
}
} else if (lines && !lines->empty()) {
}
else if (lines && !lines->empty())
{
for (std::size_t i = 0; i < vec_elements.size(); ++i)
{
MeshLib::Element const* e = vec_elements[i];
......@@ -481,13 +549,16 @@ void FEFLOWMeshInterface::setMaterialIDs(FEM_CLASS const& fem_class,
}
material_ids[i] = matId;
}
} else if (fem_class.n_layers3d>0) {
const std::size_t no_nodes_per_layer = fem_dim.n_nodes / (fem_class.n_layers3d + 1);
}
else if (fem_class.n_layers3d > 0)
{
const std::size_t no_nodes_per_layer =
fem_dim.n_nodes / (fem_class.n_layers3d + 1);
for (std::size_t i = 0; i < vec_elements.size(); i++)
{
MeshLib::Element* e = vec_elements[i];
unsigned e_min_nodeID = std::numeric_limits<unsigned>::max();
for (std::size_t j=0; j<e->getNBaseNodes(); j++)
for (std::size_t j = 0; j < e->getNBaseNodes(); j++)
e_min_nodeID = std::min(e_min_nodeID, e->getNodeIndex(j));
std::size_t layer_id = e_min_nodeID / no_nodes_per_layer;
material_ids[i] = layer_id;
......@@ -495,5 +566,5 @@ void FEFLOWMeshInterface::setMaterialIDs(FEM_CLASS const& fem_class,
}
}
} // IO
} // MeshLib
} // IO
} // MeshLib
......@@ -15,26 +15,25 @@
namespace GeoLib
{
class Point;
class Polyline;
class Point;
class Polyline;
}
namespace MeshLib
{
class Mesh;
class Element;
class Node;
enum class MeshElemType;
class Mesh;
class Element;
class Node;
enum class MeshElemType;
}
namespace MeshLib
{
namespace IO
{
/**
* Read FEFLOW model files (*.fem) into OGS data structure. Currently this class supports
* only import of mesh data and some geometry given in Supermesh section.
* Read FEFLOW model files (*.fem) into OGS data structure. Currently this class
* supports only import of mesh data and some geometry given in Supermesh section.
*/
class FEFLOWMeshInterface
{
......@@ -42,12 +41,13 @@ public:
/**
* read a FEFLOW Model file (*.fem) in ASCII format (Version 5.4)
*
* This function reads mesh data in addition to geometry data given in Supermesh.
* This function reads mesh data in addition to geometry data given in
* Supermesh.
*
* @param filename FEFLOW file name
* @return a pointer to a created OGS mesh
*/
MeshLib::Mesh* readFEFLOWFile(const std::string &filename);
MeshLib::Mesh* readFEFLOWFile(const std::string& filename);
private:
// CLASS
......@@ -85,28 +85,40 @@ private:
};
/// read node indices and create a mesh element
MeshLib::Element* readElement(const FEM_DIM &fem_dim, const MeshLib::MeshElemType elem_type, const std::string& line, const std::vector<MeshLib::Node*> &nodes);
MeshLib::Element* readElement(const FEM_DIM& fem_dim,
const MeshLib::MeshElemType elem_type,
const std::string& line,
const std::vector<MeshLib::Node*>& nodes);
/// read node coordinates
void readNodeCoordinates(std::ifstream &in, const FEM_CLASS &fem_class, const FEM_DIM &fem_dim, std::vector<MeshLib::Node*> &nodes);
void readNodeCoordinates(std::ifstream& in,
const FEM_CLASS& fem_class,
const FEM_DIM& fem_dim,
std::vector<MeshLib::Node*>& nodes);
/// read elevation data
void readElevation(std::ifstream &in, const FEM_CLASS &fem_class, const FEM_DIM &fem_dim, std::vector<MeshLib::Node*> &vec_nodes);
void readElevation(std::ifstream& in,
const FEM_CLASS& fem_class,
const FEM_DIM& fem_dim,
std::vector<MeshLib::Node*>& vec_nodes);
//// parse node lists
std::vector<std::size_t> getIndexList(const std::string &str_ranges);
std::vector<std::size_t> getIndexList(const std::string& str_ranges);
/// parse ELEMENTALSETS
void readELEMENTALSETS(std::ifstream &in, std::vector<std::vector<std::size_t>> &vec_elementsets);
void readELEMENTALSETS(
std::ifstream& in,
std::vector<std::vector<std::size_t>>& vec_elementsets);
void setMaterialIDs(FEM_CLASS const& fem_class,
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);
std::vector<int>& material_ids);
};
} // IO
} // MeshLib
} // IO
} // MeshLib
#endif /* FEFLOWMESHINTERFACE_H_ */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment