Skip to content
Snippets Groups Projects
Commit a49e6654 authored by Dmitri Naumov's avatar Dmitri Naumov
Browse files

Fix readability-braces-around-statements.

parent edafb229
No related branches found
No related tags found
No related merge requests found
Showing
with 447 additions and 74 deletions
......@@ -278,8 +278,10 @@ void ProjectData::parseProcessVariables(
auto pv = ProcessLib::ProcessVariable{var_config, mesh, _mesh_vec,
_parameters};
if (!names.insert(pv.getName()).second)
{
OGS_FATAL("A process variable with name `%s' already exists.",
pv.getName().c_str());
}
_process_variables.push_back(std::move(pv));
}
......@@ -299,8 +301,10 @@ void ProjectData::parseParameters(BaseLib::ConfigTree const& parameters_config)
auto p =
ProcessLib::createParameter(parameter_config, _mesh_vec, _curves);
if (!names.insert(p->name).second)
{
OGS_FATAL("A parameter with name `%s' already exists.",
p->name.c_str());
}
_parameters.push_back(std::move(p));
}
......@@ -310,14 +314,18 @@ void ProjectData::parseParameters(BaseLib::ConfigTree const& parameters_config)
ProcessLib::DeactivatedSubdomain::zero_parameter_name, 0.0));
for (auto& parameter : _parameters)
{
parameter->initialize(_parameters);
}
}
void ProjectData::parseMedia(
boost::optional<BaseLib::ConfigTree> const& media_config)
{
if (!media_config)
{
return;
}
DBUG("Reading media:");
......@@ -821,7 +829,9 @@ void ProjectData::parseCurves(
boost::optional<BaseLib::ConfigTree> const& config)
{
if (!config)
{
return;
}
DBUG("Reading curves configuration.");
......
......@@ -118,7 +118,9 @@ int main(int argc, char* argv[])
// deactivate buffer for standard output if specified
if (unbuffered_cout_arg.isSet())
{
std::cout.setf(std::ios::unitbuf);
}
ApplicationsLib::LogogSetup logog_setup;
logog_setup.setLevel(log_level_arg.getValue());
......@@ -129,11 +131,13 @@ int main(int argc, char* argv[])
#ifndef _WIN32 // On windows this command line option is not present.
// Enable floating point exceptions
if (enable_fpe_arg.isSet())
{
#ifdef __APPLE__
_MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~_MM_MASK_INVALID);
#else
feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
#endif // __APPLE__
}
#endif // _WIN32
#ifdef OGS_USE_PYTHON
......
......@@ -25,15 +25,25 @@ BoundaryCondition::ConditionType BoundaryCondition::convertStringToType(
std::string const& str)
{
if (str == "Dirichlet")
{
return ConditionType::DIRICHLET;
}
else if (str == "NonuniformDirichlet")
{
return ConditionType::NONUNIFORMDIRICHLET;
}
else if (str == "Neumann")
{
return ConditionType::NEUMANN;
}
else if (str == "NonuniformNeumann")
{
return ConditionType::NONUNIFORMNEUMANN;
}
else if (str == "Robin")
{
return ConditionType::ROBIN;
}
return ConditionType::NONE;
}
......@@ -41,15 +51,25 @@ BoundaryCondition::ConditionType BoundaryCondition::convertStringToType(
std::string BoundaryCondition::convertTypeToString(ConditionType type)
{
if (type == ConditionType::DIRICHLET)
{
return "Dirichlet";
}
else if (type == ConditionType::NONUNIFORMDIRICHLET)
{
return "NonuniformDirichlet";
}
else if (type == ConditionType::NEUMANN)
{
return "Neumann";
}
else if (type == ConditionType::NONUNIFORMNEUMANN)
{
return "NonuniformNeumann";
}
else if (type == ConditionType::ROBIN)
{
return "Robin";
}
return "";
}
......
......@@ -47,7 +47,9 @@ Color const getColor(const std::string &id, std::map<std::string, Color> &colors
for (auto it = colors.begin(); it != colors.end(); ++it)
{
if (id == it->first)
{
return it->second;
}
}
WARN("Key '%s' not found in color lookup table.", id.c_str());
Color c = getRandomColor();
......
......@@ -23,14 +23,18 @@ ColorLookupTable::ColorLookupTable()
void ColorLookupTable::setTableRange(double min, double max)
{
if (min<max)
if (min < max)
{
_range = std::make_pair(min, max);
}
}
void ColorLookupTable::setColor(double id, DataHolderLib::Color const& color)
{
if ((id>_range.first) && (id<_range.second))
if ((id > _range.first) && (id < _range.second))
{
_lut.emplace_back(id, color, "");
}
}
void ColorLookupTable::setColor(std::string const& name, DataHolderLib::Color const& color)
......
......@@ -80,11 +80,17 @@ bool Project::getUniqueName(std::string &name) const
// If the original name already exists we start to add numbers to name for
// as long as it takes to make the name unique.
if (count > 1)
{
cpName = cpName + "-" + std::to_string(count);
}
for (auto & mesh : _mesh_vec)
if ( cpName == mesh->getName())
for (auto& mesh : _mesh_vec)
{
if (cpName == mesh->getName())
{
isUnique = false;
}
}
}
// At this point cpName is a unique name and isUnique is true.
......@@ -102,15 +108,23 @@ void Project::removePrimaryVariable(std::string const primary_var_name)
{
std::size_t const n_bc(_boundary_conditions.size());
for (int i = n_bc - 1; i >= 0; --i)
{
if (_boundary_conditions[i]->getProcessVarName() == primary_var_name)
{
removeBoundaryCondition(primary_var_name,
_boundary_conditions[i]->getParamName());
}
}
std::size_t const n_st(_source_terms.size());
for (int i = n_st - 1; i >= 0; --i)
{
if (_source_terms[i]->getProcessVarName() == primary_var_name)
{
removeSourceTerm(primary_var_name,
_source_terms[i]->getParamName());
}
}
}
void Project::removeBoundaryCondition(std::string const& primary_var_name,
......
......@@ -23,9 +23,13 @@ SourceTerm::ConditionType SourceTerm::convertStringToType(
std::string const& str)
{
if (str == "Nodal")
{
return ConditionType::NODAL;
}
else if (str == "Volume")
{
return ConditionType::VOLUME;
}
return ConditionType::NONE;
}
......@@ -33,9 +37,13 @@ SourceTerm::ConditionType SourceTerm::convertStringToType(
std::string SourceTerm::convertTypeToString(ConditionType type)
{
if (type == ConditionType::NODAL)
{
return "Nodal";
}
else if (type == ConditionType::VOLUME)
{
return "Volume";
}
return "";
}
......
......@@ -29,9 +29,13 @@ GeoLib::Raster* AsciiRasterInterface::readRaster(std::string const& fname)
std::string ext (BaseLib::getFileExtension(fname));
std::transform(ext.begin(), ext.end(), ext.begin(), tolower);
if (ext == "asc")
{
return getRasterFromASCFile(fname);
}
if (ext == "grd")
{
return getRasterFromSurferFile(fname);
}
return nullptr;
}
......@@ -77,14 +81,22 @@ bool AsciiRasterInterface::readASCHeader(std::ifstream &in, GeoLib::RasterHeader
{
in >> value;
header.n_cols = atoi(value.c_str());
} else return false;
}
else
{
return false;
}
in >> tag;
if (tag == "nrows")
{
in >> value;
header.n_rows = atoi(value.c_str());
} else return false;
}
else
{
return false;
}
header.n_depth = 1;
......@@ -94,7 +106,11 @@ bool AsciiRasterInterface::readASCHeader(std::ifstream &in, GeoLib::RasterHeader
in >> value;
header.origin[0] =
strtod(BaseLib::replaceString(",", ".", value).c_str(), nullptr);
} else return false;
}
else
{
return false;
}
in >> tag;
if (tag == "yllcorner" || tag == "yllcenter")
......@@ -102,7 +118,11 @@ bool AsciiRasterInterface::readASCHeader(std::ifstream &in, GeoLib::RasterHeader
in >> value;
header.origin[1] =
strtod(BaseLib::replaceString(",", ".", value).c_str(), nullptr);
} else return false;
}
else
{
return false;
}
header.origin[2] = 0;
in >> tag;
......@@ -111,7 +131,11 @@ bool AsciiRasterInterface::readASCHeader(std::ifstream &in, GeoLib::RasterHeader
in >> value;
header.cell_size =
strtod(BaseLib::replaceString(",", ".", value).c_str(), nullptr);
} else return false;
}
else
{
return false;
}
in >> tag;
if (tag == "NODATA_value" || tag == "nodata_value")
......@@ -119,7 +143,11 @@ bool AsciiRasterInterface::readASCHeader(std::ifstream &in, GeoLib::RasterHeader
in >> value;
header.no_data =
strtod(BaseLib::replaceString(",", ".", value).c_str(), nullptr);
} else return false;
}
else
{
return false;
}
return true;
}
......@@ -188,7 +216,9 @@ bool AsciiRasterInterface::readSurferHeader(
if (ceil((max - min) / static_cast<double>(header.n_rows)) ==
ceil(header.cell_size))
{
header.cell_size = ceil(header.cell_size);
}
else
{
ERR("Error in readSurferHeader() - Anisotropic cellsize detected.");
......@@ -237,7 +267,10 @@ static bool allRastersExist(std::vector<std::string> const& raster_paths)
for (const auto& raster_path : raster_paths)
{
std::ifstream file_stream(raster_path, std::ifstream::in);
if (!file_stream.good()) return false;
if (!file_stream.good())
{
return false;
}
file_stream.close();
}
return true;
......@@ -246,12 +279,17 @@ static bool allRastersExist(std::vector<std::string> const& raster_paths)
boost::optional<std::vector<GeoLib::Raster const*>> readRasters(
std::vector<std::string> const& raster_paths)
{
if (!allRastersExist(raster_paths)) return boost::none;
if (!allRastersExist(raster_paths))
{
return boost::none;
}
std::vector<GeoLib::Raster const*> rasters;
rasters.reserve(raster_paths.size());
for (auto const& path : raster_paths)
{
rasters.push_back(FileIO::AsciiRasterInterface::readRaster(path));
}
return boost::make_optional(rasters);
}
} // end namespace FileIO
......@@ -90,13 +90,15 @@ int CsvInterface::readPoints(std::string const& fname, char delim,
(z_column_name.empty()) ? CsvInterface::findColumn(line, delim, y_column_name) :
CsvInterface::findColumn(line, delim, z_column_name) }};
for (std::size_t i=0; i<3; ++i)
for (std::size_t i = 0; i < 3; ++i)
{
if (column_idx[i] == std::numeric_limits<std::size_t>::max())
{
ERR("Column '%s' not found in file header.",
column_names[i].c_str());
return -1;
}
}
return readPoints(in, delim, points, column_idx);
}
......@@ -115,7 +117,9 @@ int CsvInterface::readPoints(std::string const& fname, char delim,
}
if (z_column_idx == std::numeric_limits<std::size_t>::max())
{
z_column_idx = y_column_idx;
}
std::array<std::size_t, 3> const column_idx = {{ x_column_idx, y_column_idx, z_column_idx }};
return readPoints(in, delim, points, column_idx);
......@@ -172,19 +176,25 @@ std::size_t CsvInterface::findColumn(std::string const& line, char delim, std::s
{
std::list<std::string> const fields = BaseLib::splitString(line, delim);
if (fields.empty())
{
return std::numeric_limits<std::size_t>::max();
}
std::size_t count(0);
for (const auto& field : fields)
{
if (field == column_name)
{
break;
}
count++;
}
if (count == fields.size())
{
return std::numeric_limits<std::size_t>::max();
}
return count;
}
......@@ -210,8 +220,10 @@ bool CsvInterface::write()
if (_writeCsvHeader)
{
_out << _vec_names[0];
for (std::size_t i=1; i<n_vecs; ++i)
for (std::size_t i = 1; i < n_vecs; ++i)
{
_out << "\t" << _vec_names[i];
}
_out << "\n";
}
......@@ -231,22 +243,34 @@ bool CsvInterface::write()
std::size_t CsvInterface::getVectorSize(std::size_t idx) const
{
if (_data[idx].type() == typeid(std::vector<std::string>))
{
return boost::any_cast<std::vector<std::string>>(_data[idx]).size();
}
if (_data[idx].type() == typeid(std::vector<double>))
{
return boost::any_cast<std::vector<double>>(_data[idx]).size();
}
if (_data[idx].type() == typeid(std::vector<int>))
{
return boost::any_cast<std::vector<int>>(_data[idx]).size();
}
return 0;
}
void CsvInterface::writeValue(std::size_t vec_idx, std::size_t in_vec_idx)
{
if (_data[vec_idx].type() == typeid(std::vector<std::string>))
{
_out << boost::any_cast<std::vector<std::string>>(_data[vec_idx])[in_vec_idx];
}
else if (_data[vec_idx].type() == typeid(std::vector<double>))
{
_out << boost::any_cast<std::vector<double>>(_data[vec_idx])[in_vec_idx];
}
else if (_data[vec_idx].type() == typeid(std::vector<int>))
{
_out << boost::any_cast<std::vector<int>>(_data[vec_idx])[in_vec_idx];
}
}
} // end namespace FileIO
......@@ -117,7 +117,9 @@ int GMSInterface::readBoreholesFromGMS(std::vector<GeoLib::Point*>* boreholes,
in.close();
if (boreholes->empty())
{
return 0;
}
return 1;
}
......@@ -154,7 +156,9 @@ void GMSInterface::writeBoreholesToGMS(const std::vector<GeoLib::Point*>* statio
for (std::size_t i = 1; i < nLayers; i++)
{
if ((i > 1) && (soilNames[i] == soilNames[i - 1]))
{
continue;
}
// idx = getSoilID(soilID, soilNames[i]);
current_soil_name = soilNames[i];
......@@ -177,8 +181,12 @@ void GMSInterface::writeBoreholesToGMS(const std::vector<GeoLib::Point*>* statio
std::size_t GMSInterface::getSoilID(std::vector<std::string> &soilID, std::string &soilName)
{
for (std::size_t j = 0; j < soilID.size(); j++)
{
if (soilID[j] == soilName)
{
return j;
}
}
soilID.push_back(soilName);
return soilID.size() - 1;
}
......@@ -194,7 +202,10 @@ int GMSInterface::writeSoilIDTable(const std::vector<std::string> &soilID,
// write table
std::size_t nIDs = soilID.size();
for (std::size_t i = 0; i < nIDs; i++)
out << i << "\t" << std::fixed << soilID[i] << "\t" << "\n";
{
out << i << "\t" << std::fixed << soilID[i] << "\t"
<< "\n";
}
out.close();
return 1;
......@@ -208,11 +219,13 @@ std::vector<std::string> GMSInterface::readSoilIDfromFile(const std::string &fil
std::ifstream in( filename.c_str() );
if (in.is_open())
{
while ( getline(in, line) )
{
BaseLib::trim(line);
soilID.push_back(line);
}
}
in.close();
return soilID;
......@@ -309,10 +322,12 @@ MeshLib::Mesh* GMSInterface::readGMS3DMMesh(const std::string &filename)
elements.push_back(new MeshLib::Pyramid(pyramid_nodes));
mat_ids.push_back(mat_id);
}
else if (element_id == "ND ") // Node
else if (element_id == "ND ")
{ // Node
continue; // skip because nodes have already been read
else //default
}
else // default
{
WARN(
"GMSInterface::readGMS3DMMesh() - Element type '%s' not "
......@@ -335,9 +350,13 @@ MeshLib::Mesh* GMSInterface::readGMS3DMMesh(const std::string &filename)
{
ERR("Could not create PropertyVector for material ids.");
for (auto element : elements)
{
delete element;
}
for (auto node : nodes)
{
delete node;
}
return nullptr;
}
opt_pv->reserve(mat_ids.size());
......
......@@ -54,11 +54,19 @@ void GMSHAdaptiveMeshDensity::initialize(std::vector<GeoLib::Point const*> const
std::size_t n_pnts(pnts.size());
for (std::size_t k(1); k<n_pnts; k++) {
for (std::size_t j(0); j < 2; j++)
{
if ((*(pnts[k]))[j] < min[j])
{
min[j] = (*(pnts[k]))[j];
}
}
for (std::size_t j(0); j < 2; j++)
{
if ((*(pnts[k]))[j] > max[j])
{
max[j] = (*(pnts[k]))[j];
}
}
}
min[2] = 0.0;
max[2] = 0.0;
......@@ -79,7 +87,9 @@ void GMSHAdaptiveMeshDensity::addPoints(std::vector<GeoLib::Point const*> const&
const std::size_t n_pnts(pnts.size());
DBUG("GMSHAdaptiveMeshDensity::addPoints(): Inserting %d points into quadtree.", n_pnts);
for (std::size_t k(0); k < n_pnts; k++)
{
_quad_tree->addPoint(pnts[k]);
}
DBUG("GMSHAdaptiveMeshDensity::addPoints(): \tok.");
_quad_tree->balance();
}
......
......@@ -62,10 +62,14 @@ GMSHInterface::GMSHInterface(
GMSHInterface::~GMSHInterface()
{
for (auto * gmsh_pnt : _gmsh_pnts)
for (auto* gmsh_pnt : _gmsh_pnts)
{
delete gmsh_pnt;
for (auto * polygon_tree : _polygon_tree_list)
}
for (auto* polygon_tree : _polygon_tree_list)
{
delete polygon_tree;
}
}
bool GMSHInterface::write()
......@@ -84,13 +88,17 @@ int GMSHInterface::writeGMSHInputFile(std::ostream& out)
DBUG("GMSHInterface::writeGMSHInputFile(): get data from GEOObjects.");
if (_selected_geometries.empty())
{
return 1;
}
// *** get and merge data from _geo_objs
if (_selected_geometries.size() > 1) {
_gmsh_geo_name = "GMSHGeometry";
if (_geo_objs.mergeGeometries(_selected_geometries, _gmsh_geo_name))
{
return 2;
}
} else {
_gmsh_geo_name = _selected_geometries[0];
_keep_preprocessed_geometry = true;
......@@ -114,7 +122,9 @@ int GMSHInterface::writeGMSHInputFile(std::ostream& out)
_inverse_rot_mat(1,1) = 1.0;
_inverse_rot_mat(2,2) = 1.0;
for (auto pnt : *merged_pnts)
{
(*pnt)[2] = 0.0;
}
}
std::vector<GeoLib::Polyline*> const* merged_plys(
......
......@@ -43,7 +43,9 @@ void GMSHLineLoop::write(std::ostream &os, std::size_t line_offset, std::size_t
}
os << "Line Loop(" << line_offset+n_lines << ") = {";
for (std::size_t k(0); k < n_lines - 1; k++)
{
os << line_offset + k << ",";
}
os << line_offset + n_lines - 1 << "};\n";
if (_is_sfc) {
......
......@@ -40,8 +40,10 @@ GMSHPolygonTree::~GMSHPolygonTree()
// the polylines are processed also by the children, but the root is
// responsible to cleanup up
if (_parent == nullptr) { // root
for (auto * polyline : _plys)
for (auto* polyline : _plys)
{
delete polyline;
}
}
// member of GeoLib::SimplePolygonTree, but the ownership is not transmitted
delete _node_polygon;
......@@ -50,19 +52,26 @@ GMSHPolygonTree::~GMSHPolygonTree()
void GMSHPolygonTree::markSharedSegments()
{
if (_children.empty())
{
return;
}
if (_parent == nullptr)
{
return;
}
for (auto& child : _children)
{
std::size_t const n_pnts(child->getPolygon()->getNumberOfPoints());
for (std::size_t k(1); k<n_pnts; k++) {
if (GeoLib::containsEdge(*(_parent->getPolygon()),
_node_polygon->getPointID(k-1),
_node_polygon->getPointID(k)))
static_cast<GeoLib::PolygonWithSegmentMarker*>(_node_polygon)->markSegment(k, true);
_node_polygon->getPointID(k - 1),
_node_polygon->getPointID(k)))
{
static_cast<GeoLib::PolygonWithSegmentMarker*>(_node_polygon)
->markSegment(k, true);
}
}
}
}
......@@ -77,7 +86,9 @@ bool GMSHPolygonTree::insertStation(GeoLib::Point const* station)
bool rval(dynamic_cast<GMSHPolygonTree*>((*it))->insertStation (station));
// stop recursion if sub SimplePolygonTree is a leaf
if (rval && (*it)->getNumberOfChildren() == 0)
_stations.push_back (station);
{
_stations.push_back(station);
}
return rval;
}
}
......@@ -91,7 +102,9 @@ bool GMSHPolygonTree::insertStation(GeoLib::Point const* station)
void GMSHPolygonTree::insertPolyline(GeoLib::PolylineWithSegmentMarker * ply)
{
if (!_node_polygon->isPartOfPolylineInPolygon(*ply))
{
return;
}
// check if polyline segments are inside of the polygon, intersect the
// polygon or are part of the boundary of the polygon
......@@ -108,7 +121,9 @@ void GMSHPolygonTree::insertPolyline(GeoLib::PolylineWithSegmentMarker * ply)
++segment_it)
{
if (ply->isSegmentMarked(segment_it.getSegmentNumber()))
{
continue;
}
if (_node_polygon->containsSegment(*segment_it)) {
ply->markSegment(segment_it.getSegmentNumber(), true);
......@@ -261,7 +276,9 @@ void GMSHPolygonTree::createGMSHPoints(std::vector<GMSHPoint*> & gmsh_pnts) cons
GeoLib::Point const*const pnt(_node_polygon->getPoint(k));
// if this point was already part of another polyline
if (gmsh_pnts[id] != nullptr)
{
continue;
}
gmsh_pnts[id] = new GMSHPoint(
*pnt, id, _mesh_density_strategy.getMeshDensityAtPoint(pnt));
}
......@@ -274,7 +291,9 @@ void GMSHPolygonTree::createGMSHPoints(std::vector<GMSHPoint*> & gmsh_pnts) cons
const std::size_t id (_plys[k]->getPointID(j));
// if this point was already part of another polyline
if (gmsh_pnts[id] != nullptr)
{
continue;
}
GeoLib::Point const*const pnt(_plys[k]->getPoint(j));
gmsh_pnts[id] = new GMSHPoint(
*pnt, id,
......
......@@ -83,7 +83,9 @@ std::pair<MeshLib::Element*, int> readElement(
// skip tags
for (std::size_t j = 2; j < n_tags; j++)
{
in >> dummy;
}
switch (type)
{
......@@ -107,35 +109,45 @@ std::pair<MeshLib::Element*, int> readElement(
readNodeIDs(in, 4, node_ids, id_map);
auto quad_nodes = new MeshLib::Node*[4];
for (unsigned k(0); k < 4; k++)
{
quad_nodes[k] = nodes[node_ids[k]];
}
return std::make_pair(new MeshLib::Quad(quad_nodes), mat_id);
}
case 4: {
readNodeIDs(in, 4, node_ids, id_map);
auto tet_nodes = new MeshLib::Node*[5];
for (unsigned k(0); k < 4; k++)
{
tet_nodes[k] = nodes[node_ids[k]];
}
return std::make_pair(new MeshLib::Tet(tet_nodes), mat_id);
}
case 5: {
readNodeIDs(in, 8, node_ids, id_map);
auto hex_nodes = new MeshLib::Node*[8];
for (unsigned k(0); k < 8; k++)
{
hex_nodes[k] = nodes[node_ids[k]];
}
return std::make_pair(new MeshLib::Hex(hex_nodes), mat_id);
}
case 6: {
readNodeIDs(in, 6, node_ids, id_map);
auto prism_nodes = new MeshLib::Node*[6];
for (unsigned k(0); k < 6; k++)
{
prism_nodes[k] = nodes[node_ids[k]];
}
return std::make_pair(new MeshLib::Prism(prism_nodes), mat_id);
}
case 7: {
readNodeIDs(in, 5, node_ids, id_map);
auto pyramid_nodes = new MeshLib::Node*[5];
for (unsigned k(0); k < 5; k++)
{
pyramid_nodes[k] = nodes[node_ids[k]];
}
return std::make_pair(new MeshLib::Pyramid(pyramid_nodes), mat_id);
}
case 15:
......@@ -231,7 +243,9 @@ MeshLib::Mesh* readGMSHMesh(std::string const& fname)
std::size_t n_lines(0);
in >> n_lines >> std::ws; // number-of-lines
for (std::size_t i = 0; i < n_lines; i++)
{
getline(in, line);
}
getline(in, line); // END keyword
}
}
......
......@@ -88,9 +88,13 @@ std::string readPoints(std::istream &in, std::vector<GeoLib::Point*>* pnt_vec,
{
std::size_t end_pos ((line.substr (pos + 6)).find(' '));
if (end_pos != std::string::npos)
{
(*pnt_id_name_map)[line.substr (pos + 6, end_pos)] = id;
}
else
(*pnt_id_name_map)[line.substr (pos + 6)] = id;
{
(*pnt_id_name_map)[line.substr(pos + 6)] = id;
}
}
std::size_t id_pos (line.find("$ID"));
......@@ -157,8 +161,10 @@ std::string readPolyline(std::istream &in,
// Schleife ueber alle Phasen bzw. Komponenten
do {
in >> line;
if (line.find("$ID") != std::string::npos) // subkeyword found CC
in >> line; // read value
if (line.find("$ID") != std::string::npos)
{ // subkeyword found CC
in >> line; // read value
}
//....................................................................
if (line.find("$NAME") != std::string::npos) // subkeyword found
{
......@@ -172,34 +178,47 @@ std::string readPolyline(std::istream &in,
type = static_cast<std::size_t>(strtol(line.c_str(), nullptr, 0));
}
//....................................................................
if (line.find("$EPSILON") != std::string::npos) // subkeyword found
in >> line; // read value
if (line.find("$EPSILON") != std::string::npos)
{ // subkeyword found
in >> line; // read value
}
//....................................................................
if (line.find("$MAT_GROUP") != std::string::npos) // subkeyword found
in >> line; // read value
if (line.find("$MAT_GROUP") != std::string::npos)
{ // subkeyword found
in >> line; // read value
}
//....................................................................
if (line.find("$POINTS") != std::string::npos) // subkeyword found
{ // read the point ids
in >> line;
if (type != 100)
{
while (!in.eof() && !in.fail() && !line.empty() &&
(line.find('#') == std::string::npos) &&
(line.find('$') == std::string::npos))
{
auto pnt_id(BaseLib::str2number<std::size_t>(line));
if (!zero_based_indexing)
{
pnt_id--; // one based indexing
}
std::size_t ply_size(ply->getNumberOfPoints());
if (ply_size > 0)
{
if (ply->getPointID(ply_size - 1) != pnt_id_map[pnt_id])
{
ply->addPoint(pnt_id_map[pnt_id]);
}
}
else
{
ply->addPoint(pnt_id_map[pnt_id]);
}
in >> line;
}
else {
}
else
{
WARN("readPolyline(): polyline is an arc *** reading not implemented");
errors.emplace_back(
"[readPolyline] reading polyline as an arc is not "
......@@ -250,9 +269,12 @@ std::string readPolylines(std::istream &in, std::vector<GeoLib::Polyline*>* ply_
}
std::string tag("#POLYLINE");
while (!in.eof() && !in.fail() && tag.find("#POLYLINE") != std::string::npos)
while (!in.eof() && !in.fail() &&
tag.find("#POLYLINE") != std::string::npos)
{
tag = readPolyline(in, ply_vec, ply_vec_names, pnt_vec,
zero_based_indexing, pnt_id_map, path, errors);
}
return tag;
}
......@@ -285,8 +307,10 @@ std::string readSurface(std::istream& in,
do {
in >> line;
if (line.find("$ID") != std::string::npos) // subkeyword found CC
in >> line; // read value
if (line.find("$ID") != std::string::npos)
{ // subkeyword found CC
in >> line; // read value
}
//....................................................................
if (line.find("$NAME") != std::string::npos) // subkeyword found
{
......@@ -300,8 +324,10 @@ std::string readSurface(std::istream& in,
type = strtol(line.c_str(), nullptr, 0);
}
//....................................................................
if (line.find("$EPSILON") != std::string::npos) // subkeyword found
in >> line; // read value
if (line.find("$EPSILON") != std::string::npos)
{ // subkeyword found
in >> line; // read value
}
//....................................................................
if (line.find("$TIN") != std::string::npos) // subkeyword found
{
......@@ -310,8 +336,10 @@ std::string readSurface(std::istream& in,
sfc = GeoLib::IO::TINInterface::readTIN(file_name, pnt_vec, &errors);
}
//....................................................................
if (line.find("$MAT_GROUP") != std::string::npos) // subkeyword found
in >> line; // read value
if (line.find("$MAT_GROUP") != std::string::npos)
{ // subkeyword found
in >> line; // read value
}
//....................................................................
if (line.find("$POLYLINES") != std::string::npos) // subkeyword found
{ // read the name of the polyline(s)
......@@ -323,9 +351,13 @@ std::string readSurface(std::istream& in,
// we did read the name of a polyline -> search the id for polyline
auto it(ply_vec_names.find(line));
if (it != ply_vec_names.end())
{
ply_id = it->second;
}
else
{
ply_id = ply_vec.size();
}
if (ply_id == ply_vec.size()) {
WARN("readSurface(): polyline for surface not found!");
......@@ -352,11 +384,16 @@ std::string readSurface(std::istream& in,
} while (line.find('#') == std::string::npos && !line.empty() && in);
if (!name.empty())
sfc_names.insert(std::pair<std::string,std::size_t>(name,sfc_vec.size()));
{
sfc_names.insert(
std::pair<std::string, std::size_t>(name, sfc_vec.size()));
}
if (sfc)
{
// surface create by TIN
sfc_vec.push_back (sfc);
}
else
{
// surface created by polygon
......@@ -424,8 +461,10 @@ std::string readSurfaces(
}
}
}
for (auto & k : polygon_vec)
for (auto& k : polygon_vec)
{
delete k;
}
return tag;
}
......@@ -446,7 +485,9 @@ bool readGLIFileV4(const std::string& fname,
std::string tag;
while (tag.find("#POINTS") == std::string::npos && !in.eof())
getline (in, tag);
{
getline(in, tag);
}
// read names of points into vector of strings
auto pnt_id_names_map =
......@@ -461,8 +502,10 @@ bool readGLIFileV4(const std::string& fname,
unique_name = BaseLib::extractBaseName(fname);
if (!pnt_vec->empty())
{
geo.addPointVec(std::move(pnt_vec), unique_name,
std::move(pnt_id_names_map), 1e-6);
}
// extract path for reading external files
const std::string path = BaseLib::extractPath(fname);
......@@ -486,8 +529,10 @@ bool readGLIFileV4(const std::string& fname,
INFO("GeoLib::readGLIFile(): tag #POLYLINE not found.");
if (!ply_vec->empty())
{
geo.addPolylineVec(std::move(ply_vec), unique_name,
std::move(ply_names));
}
// Since ply_names is a unique_ptr and is given to the GEOObject instance
// geo it is not usable anymore. For this reason a copy is necessary.
......@@ -523,9 +568,11 @@ bool readGLIFileV4(const std::string& fname,
in.close();
if (!sfc_vec->empty())
{
geo.addSurfaceVec(
std::move(sfc_vec), unique_name,
std::move(sfc_names)); // KR: insert into GEOObjects if not empty
}
return errors.empty();
}
......@@ -590,14 +637,18 @@ void writeGLIFileV4 (const std::string& fname,
os << " $NAME " << "\n" << " " << polyline_name << "\n";
os << " $POINTS" << "\n";
for (std::size_t j(0); j < ply->getNumberOfPoints(); j++)
{
os << " " << ply->getPointID(j) << "\n";
}
}
}
// writing surfaces as TIN files
const GeoLib::SurfaceVec* sfcs_vec (geo.getSurfaceVecObj (geo_name));
if (sfcs_vec)
{
writeTINSurfaces(os, sfcs_vec, 0, BaseLib::extractPath(fname));
}
os << "#STOP" << "\n";
os.close ();
......@@ -652,8 +703,11 @@ void writeAllDataToGLIFileV4 (const std::string& fname, const GeoLib::GEOObjects
if (pnts)
{
for (std::size_t k(0); k < pnts->size(); k++)
os << k + pnts_offset << " " << *((*pnts)[k]) << " $NAME " <<
static_cast<GeoLib::Station*>((*pnts)[k])->getName() << "\n";
{
os << k + pnts_offset << " " << *((*pnts)[k]) << " $NAME "
<< static_cast<GeoLib::Station*>((*pnts)[k])->getName()
<< "\n";
}
pnts_offset += pnts->size();
pnts_id_offset.push_back (pnts_offset);
}
......@@ -671,14 +725,20 @@ void writeAllDataToGLIFileV4 (const std::string& fname, const GeoLib::GEOObjects
os << "#POLYLINE" << "\n";
std::string ply_name;
os << " $NAME\n";
if (plys_vec->getNameOfElementByID (plys_cnt, ply_name))
if (plys_vec->getNameOfElementByID(plys_cnt, ply_name))
{
os << " " << ply_name << "\n";
}
else
{
os << " " << geo_names[j] << "-" << plys_cnt << "\n";
}
os << " $POINTS" << "\n";
for (std::size_t l(0); l < ply->getNumberOfPoints(); l++)
os << " " << pnts_id_offset[j] +
ply->getPointID(l) << "\n";
{
os << " " << pnts_id_offset[j] + ply->getPointID(l)
<< "\n";
}
plys_cnt++;
}
}
......@@ -690,7 +750,9 @@ void writeAllDataToGLIFileV4 (const std::string& fname, const GeoLib::GEOObjects
{
const GeoLib::SurfaceVec* sfcs_vec (geo.getSurfaceVecObj (geo_name));
if (sfcs_vec)
{
sfcs_cnt += writeTINSurfaces(os, sfcs_vec, sfcs_cnt, path);
}
}
os << "#STOP" << "\n";
......
......@@ -53,13 +53,17 @@ bool createSurface(GeoLib::Polyline const& ply,
GeoLib::GEOObjects geo;
auto ply_points = ply.getPointsVec();
for (auto p : ply_points)
{
polyline_points->push_back(new GeoLib::Point(*p));
}
std::string ply_name = "temporary_polyline_name";
geo.addPointVec(std::move(polyline_points), ply_name);
auto polyline =
std::make_unique<GeoLib::Polyline>(*geo.getPointVec(ply_name));
for (std::size_t k(0); k < ply.getNumberOfPoints(); ++k)
{
polyline->addPoint(ply.getPointID(k));
}
auto polylines = std::make_unique<std::vector<GeoLib::Polyline*>>();
polylines->push_back(polyline.release());
geo.addPolylineVec(std::move(polylines), ply_name);
......
......@@ -68,13 +68,17 @@ PetrelInterface::PetrelInterface(std::list<std::string> &sfc_fnames,
geo_obj->addPointVec(std::unique_ptr<std::vector<GeoLib::Point*>>(pnt_vec),
_unique_name);
if (!well_vec->empty())
{
geo_obj->addStationVec(
std::unique_ptr<std::vector<GeoLib::Point*>>(well_vec),
_unique_name);
}
if (!ply_vec->empty())
{
geo_obj->addPolylineVec(
std::unique_ptr<std::vector<GeoLib::Polyline*>>(ply_vec),
_unique_name);
}
}
void PetrelInterface::readPetrelSurface(std::istream &in)
......@@ -113,7 +117,9 @@ void PetrelInterface::readPetrelSurface(std::istream &in)
pnt_vec->pop_back();
}
else
{
idx++;
}
}
} else
WARN(
......
......@@ -39,7 +39,9 @@ bool SHPInterface::readSHPInfo(const std::string &filename, int &shapeType, int
{
SHPHandle hSHP = SHPOpen(filename.c_str(), "rb");
if (!hSHP)
{
return false;
}
double padfMinBound[4], padfMaxBound[4];
......@@ -60,15 +62,24 @@ void SHPInterface::readSHPFile(const std::string &filename, OGSType choice, cons
SHPGetInfo(hSHP, &numberOfElements, &shapeType, padfMinBound, padfMaxBound);
if (((shapeType - 1) % 10 == 0) && (choice == SHPInterface::OGSType::POINT))
{
readPoints(hSHP, numberOfElements, listName);
if (((shapeType - 1) % 10 == 0) && (choice == SHPInterface::OGSType::STATION))
}
if (((shapeType - 1) % 10 == 0) &&
(choice == SHPInterface::OGSType::STATION))
{
readStations(hSHP, numberOfElements, listName);
if (((shapeType - 3) % 10 == 0 || (shapeType - 5) % 10 == 0) && (choice
== SHPInterface::OGSType::POLYLINE))
}
if (((shapeType - 3) % 10 == 0 || (shapeType - 5) % 10 == 0) &&
(choice == SHPInterface::OGSType::POLYLINE))
{
readPolylines(hSHP, numberOfElements, listName);
if (((shapeType - 3) % 10 == 0 || (shapeType - 5) % 10 == 0) && (choice
== SHPInterface::OGSType::POLYGON))
}
if (((shapeType - 3) % 10 == 0 || (shapeType - 5) % 10 == 0) &&
(choice == SHPInterface::OGSType::POLYGON))
{
readPolygons(hSHP, numberOfElements, listName);
}
}
void SHPInterface::readPoints(const SHPHandle &hSHP, int numberOfElements, std::string listName)
......@@ -115,7 +126,9 @@ void SHPInterface::readStations(const SHPHandle &hSHP, int numberOfElements, std
void SHPInterface::readPolylines(const SHPHandle &hSHP, int numberOfElements, std::string listName)
{
if (numberOfElements <= 0)
{
return;
}
auto pnts = std::make_unique<std::vector<GeoLib::Point*>>();
auto lines = std::make_unique<std::vector<GeoLib::Polyline*>>();
......
......@@ -59,8 +59,10 @@ bool TetGenInterface::readTetGenGeometry (std::string const& geo_fname,
if (!readNodesFromStream (poly_stream, nodes))
{
// remove nodes read until now
for (auto & node : nodes)
for (auto& node : nodes)
{
delete node;
}
return false;
}
const std::size_t nNodes (nodes.size());
......@@ -79,8 +81,10 @@ bool TetGenInterface::readTetGenGeometry (std::string const& geo_fname,
if (!parseSmeshFacets(poly_stream, *surfaces, *geo_objects.getPointVec(geo_name), id_map))
{
// remove surfaces read until now but keep the points
for (std::size_t k=0; k<surfaces->size(); k++)
for (std::size_t k = 0; k < surfaces->size(); k++)
{
delete (*surfaces)[k];
}
}
geo_objects.addSurfaceVec(std::move(surfaces), geo_name);
......@@ -100,14 +104,18 @@ std::size_t TetGenInterface::getNFacets(std::ifstream &input)
}
BaseLib::simplify(line);
if (line.empty() || line.compare(0,1,"#") == 0)
if (line.empty() || line.compare(0, 1, "#") == 0)
{
continue;
}
const std::list<std::string> fields = BaseLib::splitString(line, ' ');
auto it = fields.begin();
const auto nFacets(BaseLib::str2number<std::size_t>(*it));
if (fields.size() > 1)
{
_boundary_markers = BaseLib::str2number<std::size_t>(*(++it)) != 0;
}
return nFacets;
}
return 0;
......@@ -155,8 +163,12 @@ bool TetGenInterface::parseSmeshFacets(std::ifstream &input,
const std::size_t point_field_size = (_boundary_markers) ? nPoints+1 : nPoints;
if (point_fields.size() > point_field_size)
{
for (std::size_t j(0); j<nPoints; ++j)
point_ids.push_back(pnt_id_map[BaseLib::str2number<std::size_t>(*(++it))-offset]);
for (std::size_t j(0); j < nPoints; ++j)
{
point_ids.push_back(
pnt_id_map[BaseLib::str2number<std::size_t>(*(++it)) -
offset]);
}
const std::size_t sfc_marker = (_boundary_markers) ? BaseLib::str2number<std::size_t>(*(++it)) : 0;
const std::size_t idx = std::find(idx_map.begin(), idx_map.end(), sfc_marker) - idx_map.begin();
......@@ -178,10 +190,14 @@ bool TetGenInterface::parseSmeshFacets(std::ifstream &input,
// here the poly-file potentially defines a number of region attributes, these are ignored for now
std::size_t nTotalTriangles (0);
for (auto & surface : surfaces)
for (auto& surface : surfaces)
{
nTotalTriangles += surface->getNumberOfTriangles();
}
if (nTotalTriangles == nFacets)
{
return true;
}
ERR ("TetGenInterface::parseFacets(): Number of expected total triangles (%d) does not match number of found triangles (%d).", surfaces.size(), nTotalTriangles);
return false;
......@@ -261,9 +277,13 @@ bool TetGenInterface::readNodesFromStream (std::ifstream &ins,
// read header line
bool header_okay = parseNodesFileHeader(line, n_nodes, dim, n_attributes, boundary_markers);
if (!header_okay)
{
return false;
}
if (!parseNodes(ins, nodes, n_nodes, dim))
{
return false;
}
return true;
}
return false;
......@@ -330,7 +350,9 @@ bool TetGenInterface::parseNodes(std::ifstream &ins,
if (pos_beg != std::string::npos && pos_end != std::string::npos) {
id = BaseLib::str2number<std::size_t> (line.substr(pos_beg, pos_end - pos_beg));
if (k == 0 && id == 0)
{
_zero_based_idx = true;
}
} else {
ERR("TetGenInterface::parseNodes(): Error reading ID of node %d.", k);
delete [] coordinates;
......@@ -341,10 +363,16 @@ bool TetGenInterface::parseNodes(std::ifstream &ins,
for (std::size_t i(0); i < dim; i++) {
pos_beg = line.find_first_not_of(' ', pos_end);
pos_end = line.find_first_of(" \n", pos_beg);
if (pos_end == std::string::npos) pos_end = line.size();
if (pos_end == std::string::npos)
{
pos_end = line.size();
}
if (pos_beg != std::string::npos)
{
coordinates[i] = BaseLib::str2number<double>(line.substr(pos_beg, pos_end-pos_beg));
else {
}
else
{
ERR("TetGenInterface::parseNodes(): error reading coordinate %d of node %d.", i, k);
delete [] coordinates;
return false;
......@@ -383,9 +411,19 @@ bool TetGenInterface::readElementsFromStream(std::ifstream &ins,
// read header line
bool header_okay = parseElementsFileHeader(line, n_tets, n_nodes_per_tet, region_attributes);
if (!header_okay)
{
return false;
if (!parseElements(ins, elements, materials, nodes, n_tets, n_nodes_per_tet, region_attributes))
}
if (!parseElements(ins,
elements,
materials,
nodes,
n_tets,
n_nodes_per_tet,
region_attributes))
{
return false;
}
return true;
}
return false;
......@@ -402,8 +440,11 @@ bool TetGenInterface::parseElementsFileHeader(std::string &line,
pos_beg = line.find_first_not_of (' ');
pos_end = line.find_first_of(' ', pos_beg);
if (pos_beg != std::string::npos && pos_end != std::string::npos)
{
n_tets = BaseLib::str2number<std::size_t> (line.substr(pos_beg, pos_end - pos_beg));
else {
}
else
{
ERR("TetGenInterface::parseElementsFileHeader(): Could not read number of tetrahedra specified in header.");
return false;
}
......@@ -415,7 +456,9 @@ bool TetGenInterface::parseElementsFileHeader(std::string &line,
pos_beg = line.find_first_not_of (" \t", pos_end);
pos_end = line.find_first_of(" \t\n", pos_beg);
if (pos_end == std::string::npos)
{
pos_end = line.size();
}
region_attribute = line.substr(pos_beg, pos_end - pos_beg) == "1";
return true;
......@@ -467,9 +510,13 @@ bool TetGenInterface::parseElements(std::ifstream& ins,
pos_beg = line.find_first_not_of(' ', pos_end);
pos_end = line.find_first_of(' ', pos_beg);
if (pos_end == std::string::npos)
{
pos_end = line.size();
}
if (pos_beg != std::string::npos && pos_end != std::string::npos)
{
ids[i] = BaseLib::str2number<std::size_t>(line.substr(pos_beg, pos_end - pos_beg)) - offset;
}
else
{
ERR("TetGenInterface::parseElements(): Error reading node %d of tetrahedron %d.", i, k);
......@@ -482,10 +529,16 @@ bool TetGenInterface::parseElements(std::ifstream& ins,
if (region_attribute) {
pos_beg = line.find_first_not_of(' ', pos_end);
pos_end = line.find_first_of(' ', pos_beg);
if (pos_end == std::string::npos) pos_end = line.size();
if (pos_end == std::string::npos)
{
pos_end = line.size();
}
if (pos_beg != std::string::npos && pos_end != std::string::npos)
{
region = BaseLib::str2number<int> (line.substr(pos_beg, pos_end - pos_beg));
else {
}
else
{
ERR("TetGenInterface::parseElements(): Error reading region attribute of tetrahedron %d.", k);
return false;
}
......@@ -525,13 +578,18 @@ bool TetGenInterface::writeTetGenSmesh(const std::string &file_name,
const std::size_t nPoints (points->size());
out << nPoints << " 3\n";
// the point list
for (std::size_t i=0; i<nPoints; ++i)
out << i << " " << (*(*points)[i])[0] << " " << (*(*points)[i])[1] << " " << (*(*points)[i])[2] << "\n";
for (std::size_t i = 0; i < nPoints; ++i)
{
out << i << " " << (*(*points)[i])[0] << " " << (*(*points)[i])[1]
<< " " << (*(*points)[i])[2] << "\n";
}
// the surfaces header
const std::size_t nSurfaces = (surfaces) ? surfaces->size() : 0;
std::size_t nTotalTriangles (0);
for (std::size_t i=0; i<nSurfaces; ++i)
for (std::size_t i = 0; i < nSurfaces; ++i)
{
nTotalTriangles += (*surfaces)[i]->getNumberOfTriangles();
}
out << nTotalTriangles << " 1\n";
for (std::size_t i=0; i<nSurfaces; ++i)
......@@ -548,13 +606,19 @@ bool TetGenInterface::writeTetGenSmesh(const std::string &file_name,
out << "0\n"; // the polygon holes list
// the region attributes list
if (attribute_points.empty())
{
out << "0\n";
}
else
{
const std::size_t nAttributePoints (attribute_points.size());
out << nAttributePoints << "\n";
for (std::size_t i=0; i<nAttributePoints; ++i)
out << i+1 << " " << attribute_points[i][0] << " " << attribute_points[i][1] << " " << attribute_points[i][2] << " " << 10*attribute_points[i].getID() << "\n";
for (std::size_t i = 0; i < nAttributePoints; ++i)
{
out << i + 1 << " " << attribute_points[i][0] << " "
<< attribute_points[i][1] << " " << attribute_points[i][2]
<< " " << 10 * attribute_points[i].getID() << "\n";
}
}
INFO ("TetGenInterface::writeTetGenSmesh() - %d points and %d surfaces successfully written.", nPoints, nSurfaces);
out.close();
......@@ -566,7 +630,9 @@ bool TetGenInterface::writeTetGenSmesh(const std::string &file_name,
std::vector<MeshLib::Node> &attribute_points) const
{
if (mesh.getDimension() == 1)
{
return false;
}
const std::vector<MeshLib::Node*> &nodes = mesh.getNodes();
......@@ -576,25 +642,38 @@ bool TetGenInterface::writeTetGenSmesh(const std::string &file_name,
const std::size_t nPoints (nodes.size());
out << nPoints << " 3\n";
// the point list
for (std::size_t i=0; i<nPoints; ++i)
out << i << " " << (*nodes[i])[0] << " " << (*nodes[i])[1] << " " << (*nodes[i])[2] << "\n";
for (std::size_t i = 0; i < nPoints; ++i)
{
out << i << " " << (*nodes[i])[0] << " " << (*nodes[i])[1] << " "
<< (*nodes[i])[2] << "\n";
}
if (mesh.getDimension() == 2)
{
write2dElements(out, mesh);
}
else
{
write3dElements(out, mesh, attribute_points);
}
out << "0\n"; // the polygon holes list
// the region attributes list
if (attribute_points.empty())
{
out << "0\n";
}
else
{
const std::size_t nAttributePoints (attribute_points.size());
out << nAttributePoints << "\n";
for (std::size_t i=0; i<nAttributePoints; ++i)
out << i+1 << " " << attribute_points[i][0] << " " << attribute_points[i][1] << " " << attribute_points[i][2] << " " << 10*attribute_points[i].getID() << "\n";
for (std::size_t i = 0; i < nAttributePoints; ++i)
{
out << i + 1 << " " << attribute_points[i][0] << " "
<< attribute_points[i][1] << " " << attribute_points[i][2]
<< " " << 10 * attribute_points[i].getID() << "\n";
}
}
INFO ("TetGenInterface::writeTetGenPoly() - %d points and %d surfaces successfully written.", nPoints, mesh.getNumberOfElements());
......@@ -631,7 +710,9 @@ void TetGenInterface::write3dElements(std::ofstream &out,
const std::vector<MeshLib::Element*> &elements = mesh.getElements();
const std::size_t nElements (elements.size());
if (!attribute_points.empty())
{
attribute_points.clear();
}
// get position where number of facets need to be written and figure out worst case of chars that are needed
const std::streamoff before_elems_pos (out.tellp());
......@@ -643,7 +724,9 @@ void TetGenInterface::write3dElements(std::ofstream &out,
for (std::size_t i=0; i<nElements; ++i)
{
if (elements[i]->getDimension() < 3)
{
continue;
}
const unsigned nFaces (elements[i]->getNumberOfNeighbors());
std::string const mat_id_str =
......@@ -652,16 +735,21 @@ void TetGenInterface::write3dElements(std::ofstream &out,
{
MeshLib::Element const*const neighbor ( elements[i]->getNeighbor(j) );
if (neighbor && materialIds && (*materialIds)[i] <= (*materialIds)[neighbor->getID()])
if (neighbor && materialIds &&
(*materialIds)[i] <= (*materialIds)[neighbor->getID()])
{
continue;
}
std::unique_ptr<MeshLib::Element const> const face (elements[i]->getFace(j));
this->writeElementToFacets(out, *face, element_count, mat_id_str);
}
if (materialIds)
{
attribute_points.emplace_back(
elements[i]->getCenterOfGravity().getCoords(),
(*materialIds)[i]);
}
}
// add number of facets at correct position and jump back
const std::streamoff after_elems_pos (out.tellp());
......@@ -674,7 +762,9 @@ void TetGenInterface::writeElementToFacets(std::ofstream &out, const MeshLib::El
{
element_count++;
if (element.getGeomType() == MeshLib::MeshElemType::TRIANGLE)
{
out << "3 " << element.getNodeIndex(0) << " " << element.getNodeIndex(1) << " " << element.getNodeIndex(2) << " " << matId << " # " << element_count << "\n";
}
else if (element.getGeomType() == MeshLib::MeshElemType::QUAD)
{
out << "3 " << element.getNodeIndex(0) << " " << element.getNodeIndex(1) << " " << element.getNodeIndex(2) << " " << matId << " # " << element_count << "\n";
......
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