diff --git a/Applications/ApplicationsLib/ProjectData.cpp b/Applications/ApplicationsLib/ProjectData.cpp index 28e1e84b6849d3416a9513e38adf9eeb3e760791..433f2d55372e4976b480567dd53c4ad3f9474248 100644 --- a/Applications/ApplicationsLib/ProjectData.cpp +++ b/Applications/ApplicationsLib/ProjectData.cpp @@ -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."); diff --git a/Applications/CLI/ogs.cpp b/Applications/CLI/ogs.cpp index 76fdc683bbb5082705f5b3ed225f8c9f404b2a3c..7fab427db703d29fcb7e9a5d8726a8451a6a6d55 100644 --- a/Applications/CLI/ogs.cpp +++ b/Applications/CLI/ogs.cpp @@ -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 diff --git a/Applications/DataHolderLib/BoundaryCondition.cpp b/Applications/DataHolderLib/BoundaryCondition.cpp index b6fc9e9dd55a739ebf410ef1157686c2dc7924a5..33270b870b28915b3ca0054239369ade74bd7ecb 100644 --- a/Applications/DataHolderLib/BoundaryCondition.cpp +++ b/Applications/DataHolderLib/BoundaryCondition.cpp @@ -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 ""; } diff --git a/Applications/DataHolderLib/Color.cpp b/Applications/DataHolderLib/Color.cpp index a0e3662a2325c1f9a3ca5f00ef9f062b2b0a2ab3..ebc31eb04ae8dbfbca8d0f4cd0ad426fa86e1b02 100644 --- a/Applications/DataHolderLib/Color.cpp +++ b/Applications/DataHolderLib/Color.cpp @@ -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(); diff --git a/Applications/DataHolderLib/ColorLookupTable.cpp b/Applications/DataHolderLib/ColorLookupTable.cpp index bde4cd65b377bc92017e05f3f36558e2c1c2711c..53539425d12ca3c8cada6b93232704e1258986e7 100644 --- a/Applications/DataHolderLib/ColorLookupTable.cpp +++ b/Applications/DataHolderLib/ColorLookupTable.cpp @@ -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) diff --git a/Applications/DataHolderLib/Project.cpp b/Applications/DataHolderLib/Project.cpp index 1a03bb81f59c6064954bbca402261659e7b8ec68..14ec2dd263e163098405a2102e14d3e4e1e5f601 100644 --- a/Applications/DataHolderLib/Project.cpp +++ b/Applications/DataHolderLib/Project.cpp @@ -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, diff --git a/Applications/DataHolderLib/SourceTerm.cpp b/Applications/DataHolderLib/SourceTerm.cpp index 4dc786bf22c36cde720eb0a4cbf4e3ac8b9fce32..3934ee94246411a535e1b3e675c5388a1ec808fa 100644 --- a/Applications/DataHolderLib/SourceTerm.cpp +++ b/Applications/DataHolderLib/SourceTerm.cpp @@ -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 ""; } diff --git a/Applications/FileIO/AsciiRasterInterface.cpp b/Applications/FileIO/AsciiRasterInterface.cpp index 4ef1bae1149e4fa81fb44d35a0d8e8ba7843cecd..129f7527964fb7eaeb9692eecc9651ddaab546b4 100644 --- a/Applications/FileIO/AsciiRasterInterface.cpp +++ b/Applications/FileIO/AsciiRasterInterface.cpp @@ -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 diff --git a/Applications/FileIO/CsvInterface.cpp b/Applications/FileIO/CsvInterface.cpp index 3f9cf03763ac5f11162d38de4b6fdf08c8b82503..de5f8eaace6662654a11bbe76cbf0cea003bfb75 100644 --- a/Applications/FileIO/CsvInterface.cpp +++ b/Applications/FileIO/CsvInterface.cpp @@ -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 diff --git a/Applications/FileIO/GMSInterface.cpp b/Applications/FileIO/GMSInterface.cpp index a1ef78069d5cfe307b639277e33decc9bb48b8a6..357ba8a78534d6010640bb959662cff14e682dde 100644 --- a/Applications/FileIO/GMSInterface.cpp +++ b/Applications/FileIO/GMSInterface.cpp @@ -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()); diff --git a/Applications/FileIO/Gmsh/GMSHAdaptiveMeshDensity.cpp b/Applications/FileIO/Gmsh/GMSHAdaptiveMeshDensity.cpp index 76a4752a1470d1d5e033b51e92e2fc35abac8306..061ba0ce1c468c21fa43a0ec548bb205d625fa8c 100644 --- a/Applications/FileIO/Gmsh/GMSHAdaptiveMeshDensity.cpp +++ b/Applications/FileIO/Gmsh/GMSHAdaptiveMeshDensity.cpp @@ -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(); } diff --git a/Applications/FileIO/Gmsh/GMSHInterface.cpp b/Applications/FileIO/Gmsh/GMSHInterface.cpp index d814c1b02402c9c33640477f2a5e87dda7a5b0d2..94bf289ef3c35fc818202bfae5538af3ed028406 100644 --- a/Applications/FileIO/Gmsh/GMSHInterface.cpp +++ b/Applications/FileIO/Gmsh/GMSHInterface.cpp @@ -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( diff --git a/Applications/FileIO/Gmsh/GMSHLineLoop.cpp b/Applications/FileIO/Gmsh/GMSHLineLoop.cpp index 6d357623128e9b13bf8fab902775806af9e30f5c..f18bd2a4254fb5c1ccf1060897a85da1f8a80c39 100644 --- a/Applications/FileIO/Gmsh/GMSHLineLoop.cpp +++ b/Applications/FileIO/Gmsh/GMSHLineLoop.cpp @@ -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) { diff --git a/Applications/FileIO/Gmsh/GMSHPolygonTree.cpp b/Applications/FileIO/Gmsh/GMSHPolygonTree.cpp index 873328c51ae702a18b074ef7ea486d69b71eb2e9..0502c11b867e139da4cfbf2919cc6dd54619168a 100644 --- a/Applications/FileIO/Gmsh/GMSHPolygonTree.cpp +++ b/Applications/FileIO/Gmsh/GMSHPolygonTree.cpp @@ -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, diff --git a/Applications/FileIO/Gmsh/GmshReader.cpp b/Applications/FileIO/Gmsh/GmshReader.cpp index 49d06e72af2b9fa44036d299e19287ccd2cc924e..cbbf36bd239de042f2f3ef427fadc5de493a5ae2 100644 --- a/Applications/FileIO/Gmsh/GmshReader.cpp +++ b/Applications/FileIO/Gmsh/GmshReader.cpp @@ -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 } } diff --git a/Applications/FileIO/Legacy/OGSIOVer4.cpp b/Applications/FileIO/Legacy/OGSIOVer4.cpp index 6ae7743ae04b3b3b83b7de8c2a32897daf6cba52..5b9fbfa18b644b23d7cf96529468f7a7c7589697 100644 --- a/Applications/FileIO/Legacy/OGSIOVer4.cpp +++ b/Applications/FileIO/Legacy/OGSIOVer4.cpp @@ -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"; diff --git a/Applications/FileIO/Legacy/createSurface.cpp b/Applications/FileIO/Legacy/createSurface.cpp index a45bd63c222c865e181373b7ea83e170a309d373..0a6a3a2d3c1c10c574d7488fc0ceef8266e18369 100644 --- a/Applications/FileIO/Legacy/createSurface.cpp +++ b/Applications/FileIO/Legacy/createSurface.cpp @@ -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); diff --git a/Applications/FileIO/PetrelInterface.cpp b/Applications/FileIO/PetrelInterface.cpp index 1888fd9da924e05a81d65fab2de1e228f844419e..5fbc8a43a3a0505da0411b62d95cae247845ebf5 100644 --- a/Applications/FileIO/PetrelInterface.cpp +++ b/Applications/FileIO/PetrelInterface.cpp @@ -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( diff --git a/Applications/FileIO/SHPInterface.cpp b/Applications/FileIO/SHPInterface.cpp index 32d41d0276c586d987c5e77952df232a1888cb3c..8958f4d00eeb0109715a91df16a4b9a990f02fac 100644 --- a/Applications/FileIO/SHPInterface.cpp +++ b/Applications/FileIO/SHPInterface.cpp @@ -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*>>(); diff --git a/Applications/FileIO/TetGenInterface.cpp b/Applications/FileIO/TetGenInterface.cpp index 73ad1f91eb37a6d80f21f6538fac50ba146c67d0..49ad36708674b41bf1be8018c38fc99054754b58 100644 --- a/Applications/FileIO/TetGenInterface.cpp +++ b/Applications/FileIO/TetGenInterface.cpp @@ -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"; diff --git a/Applications/Utils/FileConverter/TIN2VTK.cpp b/Applications/Utils/FileConverter/TIN2VTK.cpp index 2c3ce8cd6d0583e43cd232ef2b2d7f14df79a38a..9b5d3cbdd375083d80715ed449772c80a1db53ef 100644 --- a/Applications/Utils/FileConverter/TIN2VTK.cpp +++ b/Applications/Utils/FileConverter/TIN2VTK.cpp @@ -61,7 +61,9 @@ int main (int argc, char* argv[]) std::unique_ptr<GeoLib::Surface> sfc( GeoLib::IO::TINInterface::readTIN(tinFileName, point_vec)); if (!sfc) + { return EXIT_FAILURE; + } INFO("TIN read: %d points, %d triangles", point_vec.size(), sfc->getNumberOfTriangles()); diff --git a/Applications/Utils/FileConverter/TecPlotTools.cpp b/Applications/Utils/FileConverter/TecPlotTools.cpp index 356ddd58457640c8dbc02435bd9beffe7c926f8e..541cc570850b9e9f97a40a814071075d0fb3fe17 100644 --- a/Applications/Utils/FileConverter/TecPlotTools.cpp +++ b/Applications/Utils/FileConverter/TecPlotTools.cpp @@ -142,7 +142,9 @@ void resetDataStructures(std::size_t const& n_scalars, scalars.clear(); scalars.reserve(n_scalars); for (std::size_t i = 0; i < n_scalars; ++i) + { scalars.push_back(std::vector<double>(0)); + } val_count = 0; } @@ -231,7 +233,9 @@ void skipGeometrySection(std::ifstream& in, std::string& line) if ((line.find("TITLE") != std::string::npos) || (line.find("VARIABLES") != std::string::npos) || (line.find("ZONE") != std::string::npos)) + { return; + } } } @@ -247,7 +251,9 @@ int splitFile(std::ifstream& in, std::string file_name) if (line.find("TITLE") != std::string::npos) { if (dataCountError(out, name, val_count, val_total)) + { return -3; + } writeTecPlotSection(out, file_name, write_count, val_count, val_total); out << line << "\n"; continue; @@ -255,7 +261,9 @@ int splitFile(std::ifstream& in, std::string file_name) else if (line.find("VARIABLES") != std::string::npos) { if (dataCountError(out, name, val_count, val_total)) + { return -3; + } writeTecPlotSection(out, file_name, write_count, val_count, val_total); out << line << "\n"; continue; @@ -263,7 +271,9 @@ int splitFile(std::ifstream& in, std::string file_name) else if (line.find("ZONE") != std::string::npos) { if (dataCountError(out, name, val_count, val_total)) + { return -3; + } writeTecPlotSection(out, file_name, write_count, val_count, val_total); out << line << "\n"; name = getName(line); @@ -277,7 +287,9 @@ int splitFile(std::ifstream& in, std::string file_name) val_count++; } if (dataCountError(out, name, val_count, val_total)) + { return -3; + } INFO("Writing time step #%i", write_count); out.close(); INFO("Finished split."); @@ -296,14 +308,20 @@ int convertFile(std::ifstream& in, std::string file_name) while (std::getline(in, line)) { if (line.find("GEOMETRY") != std::string::npos) + { skipGeometrySection(in, line); + } if (line.empty()) + { continue; + } else if (line.find("TITLE") != std::string::npos) { if (dataCountError(name, val_count, val_total)) + { return -3; + } if (val_count != 0) { writeDataToMesh(file_name, write_count, var_names, scalars, dims); @@ -316,7 +334,9 @@ int convertFile(std::ifstream& in, std::string file_name) if (val_count != 0) { if (dataCountError(name, val_count, val_total)) + { return -3; + } writeDataToMesh(file_name, write_count, var_names, scalars, dims); } var_names.clear(); @@ -329,7 +349,9 @@ int convertFile(std::ifstream& in, std::string file_name) if (val_count != 0) { if (dataCountError(name, val_count, val_total)) + { return -3; + } writeDataToMesh(file_name, write_count, var_names, scalars, dims); resetDataStructures(var_names.size(), scalars, val_count); } @@ -361,7 +383,9 @@ int convertFile(std::ifstream& in, std::string file_name) val_count++; } if (dataCountError(name, val_count, val_total)) + { return -3; + } writeDataToMesh(file_name, write_count, var_names, scalars, dims); INFO("Finished conversion."); return 0; @@ -429,9 +453,13 @@ int main(int argc, char* argv[]) output_arg.getValue() : input_arg.getValue(); int return_val(0); if (split_arg.getValue()) + { return_val = splitFile(in, filename); + } else if (convert_arg.getValue()) + { return_val = convertFile(in, filename); + } in.close(); return return_val; diff --git a/Applications/Utils/FileConverter/generateMatPropsFromMatID.cpp b/Applications/Utils/FileConverter/generateMatPropsFromMatID.cpp index 5ddfc81804c3f3f4e84af5c7736316d2b357e416..c92811f33926790701a03d5f13a5133e6c0dda9c 100644 --- a/Applications/Utils/FileConverter/generateMatPropsFromMatID.cpp +++ b/Applications/Utils/FileConverter/generateMatPropsFromMatID.cpp @@ -79,7 +79,9 @@ int main (int argc, char* argv[]) if (out_prop.is_open()) { for (std::size_t i = 0; i < n_properties; ++i) + { out_prop << i << "\t" << (*materialIds)[i] << "\n"; + } out_prop.close(); } else diff --git a/Applications/Utils/MeshEdit/CreateBoundaryConditionsAlongPolylines.cpp b/Applications/Utils/MeshEdit/CreateBoundaryConditionsAlongPolylines.cpp index 5dc7be5d413bbf1604daa38ef5c3d41ae7206ad0..4924585d25559232a412206eb3607ac3f1204fa6 100644 --- a/Applications/Utils/MeshEdit/CreateBoundaryConditionsAlongPolylines.cpp +++ b/Applications/Utils/MeshEdit/CreateBoundaryConditionsAlongPolylines.cpp @@ -97,8 +97,9 @@ void writeBCsAndGeometry(GeoLib::GEOObjects& geometry_sets, bool liquid_flow(false); if (bc_type == "LIQUID_FLOW") + { liquid_flow = true; - + } GeoLib::PointVec const* pnt_vec_objs(geometry_sets.getPointVecObj(geo_name)); std::vector<GeoLib::Point*> const& pnts(*(pnt_vec_objs->getVector())); @@ -107,9 +108,13 @@ void writeBCsAndGeometry(GeoLib::GEOObjects& geometry_sets, std::string const& pnt_name(pnt_vec_objs->getItemNameByID(k)); if (!pnt_name.empty()) { if (liquid_flow) + { writeLiquidFlowPointBC(bc_out, pnt_name); + } else + { writeGroundwaterFlowPointBC(bc_out, pnt_name, (*pnts[k])[2]); + } } } bc_out << "#STOP\n"; @@ -217,7 +222,9 @@ int main (int argc, char* argv[]) std::vector<std::size_t> ids (mesh_searcher.getMeshNodeIDsAlongPolyline(*((*plys)[k]))); if (ids.empty()) + { continue; + } std::string geo_name("Polyline-"+std::to_string(k)); convertMeshNodesToGeometry(surface_mesh->getNodes(), ids, geo_name, geometry_sets); @@ -233,7 +240,9 @@ int main (int argc, char* argv[]) std::string merge_name("AllMeshNodesAlongPolylines"); if (geometry_sets.mergeGeometries(geo_names, merge_name) == 2) + { merge_name = geo_names[0]; + } GeoLib::PointVec const* pnt_vec(geometry_sets.getPointVecObj(merge_name)); std::vector<GeoLib::Point*> const* merged_pnts(pnt_vec->getVector()); diff --git a/Applications/Utils/MeshEdit/ExtractSurface.cpp b/Applications/Utils/MeshEdit/ExtractSurface.cpp index 1f2ff9598c3d967ca4108a9a871108cf5c478169..ff587b3a638813d446a609134ba3492249d2a3ff 100644 --- a/Applications/Utils/MeshEdit/ExtractSurface.cpp +++ b/Applications/Utils/MeshEdit/ExtractSurface.cpp @@ -104,7 +104,9 @@ int main (int argc, char* argv[]) std::string out_fname(mesh_out.getValue()); if (out_fname.empty()) + { out_fname = BaseLib::dropFileExtension(mesh_in.getValue()) + "_sfc.vtu"; + } MeshLib::IO::writeMeshToFile(*surface_mesh, out_fname); return EXIT_SUCCESS; diff --git a/Applications/Utils/MeshEdit/NodeReordering.cpp b/Applications/Utils/MeshEdit/NodeReordering.cpp index 8a7a5d43c02bd0c853f966dcb57930d981d44392..034d9991a052dcbd17f78f60c40eafeeafaca8d4 100644 --- a/Applications/Utils/MeshEdit/NodeReordering.cpp +++ b/Applications/Utils/MeshEdit/NodeReordering.cpp @@ -33,7 +33,9 @@ void reorderNodes(std::vector<MeshLib::Element*> &elements) for (std::size_t i=0; i<nElements; ++i) { if (elements[i]->testElementNodeOrder()) + { continue; + } n_corrected_elements++; const unsigned nElemNodes (elements[i]->getNumberOfBaseNodes()); @@ -42,12 +44,16 @@ void reorderNodes(std::vector<MeshLib::Element*> &elements) switch (elements[i]->getGeomType()) { case MeshLib::MeshElemType::TETRAHEDRON: - for(std::size_t j = 0; j < 4; ++j) - elements[i]->setNode(j, nodes[(j+1)%4]); + for (std::size_t j = 0; j < 4; ++j) + { + elements[i]->setNode(j, nodes[(j + 1) % 4]); + } break; case MeshLib::MeshElemType::PYRAMID: - for(std::size_t j = 0; j < 5; ++j) - elements[i]->setNode(j, nodes[(j+1)%5]); + for (std::size_t j = 0; j < 5; ++j) + { + elements[i]->setNode(j, nodes[(j + 1) % 5]); + } break; case MeshLib::MeshElemType::PRISM: for(std::size_t j = 0; j < 3; ++j) @@ -64,8 +70,10 @@ void reorderNodes(std::vector<MeshLib::Element*> &elements) } break; default: - for(std::size_t j = 0; j < nElemNodes; ++j) + for (std::size_t j = 0; j < nElemNodes; ++j) + { elements[i]->setNode(j, nodes[nElemNodes - j - 1]); + } } } @@ -81,7 +89,8 @@ void reorderNodes2(std::vector<MeshLib::Element*> &elements) const unsigned nElemNodes (elements[i]->getNumberOfBaseNodes()); std::vector<MeshLib::Node*> nodes(elements[i]->getNodes(), elements[i]->getNodes() + nElemNodes); - for(std::size_t j = 0; j < nElemNodes; ++j) + for (std::size_t j = 0; j < nElemNodes; ++j) + { if (elements[i]->getGeomType() == MeshLib::MeshElemType::PRISM) { for(std::size_t j = 0; j < 3; ++j) @@ -91,6 +100,7 @@ void reorderNodes2(std::vector<MeshLib::Element*> &elements) } break; } + } } } @@ -100,10 +110,16 @@ void reorderNonlinearNodes(MeshLib::Mesh &mesh) std::vector<MeshLib::Node*> nonlinear_nodes; for (MeshLib::Element const* e : mesh.getElements()) { - for (unsigned i=0; i<e->getNumberOfBaseNodes(); i++) + for (unsigned i = 0; i < e->getNumberOfBaseNodes(); i++) + { base_nodes.push_back(const_cast<MeshLib::Node*>(e->getNode(i))); - for (unsigned i=e->getNumberOfBaseNodes(); i<e->getNumberOfNodes(); i++) - nonlinear_nodes.push_back(const_cast<MeshLib::Node*>(e->getNode(i))); + } + for (unsigned i = e->getNumberOfBaseNodes(); i < e->getNumberOfNodes(); + i++) + { + nonlinear_nodes.push_back( + const_cast<MeshLib::Node*>(e->getNode(i))); + } } BaseLib::makeVectorUnique(base_nodes, @@ -159,11 +175,17 @@ int main (int argc, char* argv[]) INFO("Reordering nodes... "); if (!method_arg.isSet() || method_arg.getValue() == 1) + { reorderNodes(const_cast<std::vector<MeshLib::Element*>&>(mesh->getElements())); + } else if (method_arg.getValue() == 2) + { reorderNodes2(const_cast<std::vector<MeshLib::Element*>&>(mesh->getElements())); + } else if (method_arg.getValue() == 3) + { reorderNonlinearNodes(*mesh); + } else { ERR ("Unknown re-ordering method. Exit program..."); diff --git a/Applications/Utils/MeshEdit/UnityPreprocessing.cpp b/Applications/Utils/MeshEdit/UnityPreprocessing.cpp index 083896733b660a46b56669d2cccf7561d72ff831..8659d23c86a40c09aa251dc97a61a24d6e7a3c3b 100644 --- a/Applications/Utils/MeshEdit/UnityPreprocessing.cpp +++ b/Applications/Utils/MeshEdit/UnityPreprocessing.cpp @@ -32,7 +32,9 @@ bool containsCellVecs(MeshLib::Mesh const& mesh) MeshLib::Properties const& props (mesh.getProperties()); std::vector<std::string> const& vec_names(props.getPropertyVectorNames(MeshLib::MeshItemType::Cell)); if (vec_names.empty()) + { return false; + } return true; } @@ -61,7 +63,9 @@ bool fillPropVec(MeshLib::Properties const& props, std::size_t total_nodes) { if (!props.existsPropertyVector<T>(name)) + { return false; + } MeshLib::PropertyVector<T> const*const vec = props.getPropertyVector<T>(name); if (vec->getNumberOfComponents() != 1) @@ -81,8 +85,10 @@ bool fillPropVec(MeshLib::Properties const& props, for (std::size_t i = 0; i<n_nodes; ++i) { std::size_t const n_nodes = node_map[i].size(); - for (std::size_t j = 0; j<n_nodes; ++j) + for (std::size_t j = 0; j < n_nodes; ++j) + { (*new_vec)[node_map[i][j]] = (*vec)[i]; + } } } else if (vec->getMeshItemType() == MeshLib::MeshItemType::Cell) @@ -92,8 +98,10 @@ bool fillPropVec(MeshLib::Properties const& props, for (std::size_t i = 0; i<n_elems; ++i) { std::size_t const n_nodes = elems[i]->getNumberOfNodes(); - for (std::size_t j = 0; j<n_nodes; ++j) + for (std::size_t j = 0; j < n_nodes; ++j) + { (*new_vec)[elems[i]->getNodeIndex(j)] = (*vec)[i]; + } } } return true; @@ -109,11 +117,18 @@ MeshLib::Properties constructProperties(MeshLib::Properties const& props, for (std::string const& name : names) { if (fillPropVec<int>(props, name, new_props, elems, node_map, n_nodes)) + { continue; - if (fillPropVec<double>(props, name, new_props, elems, node_map, n_nodes)) + } + if (fillPropVec<double>(props, name, new_props, elems, node_map, + n_nodes)) + { continue; + } if (fillPropVec<long>(props, name, new_props, elems, node_map, n_nodes)) + { continue; + } } return new_props; } @@ -129,19 +144,33 @@ MeshLib::Mesh* constructMesh(MeshLib::Mesh const& mesh) for (MeshLib::Element* elem : elems) { if (elem->getGeomType() == MeshLib::MeshElemType::LINE) + { new_elems.push_back(createElement<MeshLib::Line>(*elem, new_nodes, node_map)); + } else if (elem->getGeomType() == MeshLib::MeshElemType::TRIANGLE) + { new_elems.push_back(createElement<MeshLib::Tri>(*elem, new_nodes, node_map)); + } else if (elem->getGeomType() == MeshLib::MeshElemType::QUAD) + { new_elems.push_back(createElement<MeshLib::Quad>(*elem, new_nodes, node_map)); + } else if (elem->getGeomType() == MeshLib::MeshElemType::TETRAHEDRON) + { new_elems.push_back(createElement<MeshLib::Tet>(*elem, new_nodes, node_map)); + } else if (elem->getGeomType() == MeshLib::MeshElemType::HEXAHEDRON) + { new_elems.push_back(createElement<MeshLib::Hex>(*elem, new_nodes, node_map)); + } else if (elem->getGeomType() == MeshLib::MeshElemType::PYRAMID) + { new_elems.push_back(createElement<MeshLib::Pyramid>(*elem, new_nodes, node_map)); + } else if (elem->getGeomType() == MeshLib::MeshElemType::PRISM) + { new_elems.push_back(createElement<MeshLib::Prism>(*elem, new_nodes, node_map)); + } else { ERR("Error: Unknown element type."); @@ -182,7 +211,9 @@ int main (int argc, char* argv[]) INFO("Reading mesh '%s' ... ", mesh_arg.getValue().c_str()); std::unique_ptr<MeshLib::Mesh> mesh {MeshLib::IO::readMeshFromFile(mesh_arg.getValue())}; if (!mesh) + { return EXIT_FAILURE; + } INFO("done.\n"); INFO("Checking for line elements..."); @@ -209,7 +240,9 @@ int main (int argc, char* argv[]) INFO("Checking for cell-arrays..."); if (containsCellVecs(*result)) + { result.reset(constructMesh(*result)); + } else INFO("No cell arrays found, keeping mesh structure.\n"); diff --git a/Applications/Utils/MeshEdit/checkMesh.cpp b/Applications/Utils/MeshEdit/checkMesh.cpp index d3ca67c1bdb1a4fa5371ae91ac31b522e6941a3a..4636a5b3d30e8ae25f077153f88fe6144e0a80bb 100644 --- a/Applications/Utils/MeshEdit/checkMesh.cpp +++ b/Applications/Utils/MeshEdit/checkMesh.cpp @@ -58,7 +58,9 @@ int main(int argc, char *argv[]) std::unique_ptr<MeshLib::Mesh> mesh( MeshLib::IO::readMeshFromFile(mesh_arg.getValue())); if (!mesh) + { return EXIT_FAILURE; + } const unsigned long mem_with_mesh (mem_watch.getVirtMemUsage()); if (mem_with_mesh>0) diff --git a/Applications/Utils/MeshEdit/convertToLinearMesh.cpp b/Applications/Utils/MeshEdit/convertToLinearMesh.cpp index 449054adb0405c14c1963d005da16a6c97e13c97..93333baa20a3fbc57d58193e8539af4c9b9b4aec 100644 --- a/Applications/Utils/MeshEdit/convertToLinearMesh.cpp +++ b/Applications/Utils/MeshEdit/convertToLinearMesh.cpp @@ -45,7 +45,9 @@ int main(int argc, char *argv[]) std::unique_ptr<MeshLib::Mesh> mesh( MeshLib::IO::readMeshFromFile(input_arg.getValue())); if (!mesh) + { return EXIT_FAILURE; + } if (!mesh->isNonlinear()) { ERR("The input mesh is not non-linear. Exit."); diff --git a/Applications/Utils/MeshEdit/createLayeredMeshFromRasters.cpp b/Applications/Utils/MeshEdit/createLayeredMeshFromRasters.cpp index 9c0240dac05ff6737f73871ec35757d84097ecd2..2cd9ca66ba3b6d5e65dbe9dd158743d7b46eb1fa 100644 --- a/Applications/Utils/MeshEdit/createLayeredMeshFromRasters.cpp +++ b/Applications/Utils/MeshEdit/createLayeredMeshFromRasters.cpp @@ -42,7 +42,9 @@ int readRasterPaths(std::string const& raster_list_file, std::vector<std::string while (getline(in, line)) { if (line.empty()) + { continue; + } raster_path_vec.push_back(line); } if (raster_path_vec.size()<2) @@ -115,20 +117,28 @@ int main (int argc, char* argv[]) std::vector<std::string> raster_paths; if (readRasterPaths(raster_path_arg.getValue(), raster_paths) != 0) + { return EXIT_FAILURE; + } MeshLib::MeshLayerMapper mapper; if (auto rasters = FileIO::readRasters(raster_paths)) { if (!mapper.createLayers(*sfc_mesh, *rasters, min_thickness)) + { return EXIT_FAILURE; + } } else + { return EXIT_FAILURE; + } std::string output_name (mesh_out_arg.getValue()); if (!BaseLib::hasFileExtension("vtu", output_name)) + { output_name.append(".vtu"); + } INFO("Writing mesh '%s' ... ", output_name.c_str()); MeshLib::IO::writeMeshToFile(*(mapper.getMesh("SubsurfaceMesh").release()), output_name); INFO("done."); diff --git a/Applications/Utils/MeshEdit/createQuadraticMesh.cpp b/Applications/Utils/MeshEdit/createQuadraticMesh.cpp index 26ec98ef27ed92890d09235bc9245e4d9385effd..b6af02c6a737a636947b5be38399c6eeae4620d6 100644 --- a/Applications/Utils/MeshEdit/createQuadraticMesh.cpp +++ b/Applications/Utils/MeshEdit/createQuadraticMesh.cpp @@ -45,7 +45,9 @@ int main(int argc, char *argv[]) std::unique_ptr<MeshLib::Mesh> mesh( MeshLib::IO::readMeshFromFile(input_arg.getValue())); if (!mesh) + { return EXIT_FAILURE; + } INFO("Create a quadratic order mesh"); auto new_mesh(MeshLib::createQuadraticOrderMesh(*mesh)); diff --git a/Applications/Utils/MeshEdit/moveMeshNodes.cpp b/Applications/Utils/MeshEdit/moveMeshNodes.cpp index 6eac256e0fedf27c96835efc8648fa18effcb4dd..a2d0af625ed449c7691837b294512168f1b1fd5f 100644 --- a/Applications/Utils/MeshEdit/moveMeshNodes.cpp +++ b/Applications/Utils/MeshEdit/moveMeshNodes.cpp @@ -49,8 +49,14 @@ int find_closest_point(MeshLib::Node const*const point, std::vector<MeshLib::Nod bool containsPoint(MeshLib::Node const& pnt, MathLib::Point3d const& min, MathLib::Point3d const& max) { - if (pnt[0] < min[0] || max[0] < pnt[0]) return false; - if (pnt[1] < min[1] || max[1] < pnt[1]) return false; + if (pnt[0] < min[0] || max[0] < pnt[0]) + { + return false; + } + if (pnt[1] < min[1] || max[1] < pnt[1]) + { + return false; + } return true; } @@ -94,12 +100,14 @@ int main (int argc, char* argv[]) } bool is_keyword(false); - for (auto & keyword : keywords) + for (auto& keyword : keywords) + { if (current_key == keyword) { is_keyword = true; break; } + } if (!is_keyword) { @@ -172,8 +180,10 @@ int main (int argc, char* argv[]) if (is_inside) { int idx = find_closest_point(nodes[i], ground_truth_nodes, max_dist); - if (idx>=0) - (*nodes[i])[2] = (*(ground_truth_nodes[idx]))[2]-offset; + if (idx >= 0) + { + (*nodes[i])[2] = (*(ground_truth_nodes[idx]))[2] - offset; + } } } } @@ -186,27 +196,35 @@ int main (int argc, char* argv[]) std::vector<MeshLib::Node*> nodes (mesh->getNodes()); std::vector<double> elevation(nNodes); - for (std::size_t i=0; i<nNodes; i++) + for (std::size_t i = 0; i < nNodes; i++) + { elevation[i] = (*nodes[i])[2]; + } for (std::size_t i=0; i<nNodes; i++) { const std::vector<MeshLib::Node*> conn_nodes (nodes[i]->getConnectedNodes()); const unsigned nConnNodes (conn_nodes.size()); elevation[i] = (2*(*nodes[i])[2]); - for (std::size_t j=0; j<nConnNodes; ++j) + for (std::size_t j = 0; j < nConnNodes; ++j) + { elevation[i] += (*conn_nodes[j])[2]; + } elevation[i] /= (nConnNodes+2); } - for (std::size_t i=0; i<nNodes; i++) + for (std::size_t i = 0; i < nNodes; i++) + { (*nodes[i])[2] = elevation[i]; + } } /**** add other keywords here ****/ std::string const new_mesh_name (msh_name.substr(0, msh_name.length() - 4) + "_new.vtu"); if (MeshLib::IO::writeMeshToFile(*mesh, new_mesh_name) != 0) + { return EXIT_FAILURE; + } INFO("Result successfully written."); return EXIT_SUCCESS; diff --git a/Applications/Utils/MeshEdit/queryMesh.cpp b/Applications/Utils/MeshEdit/queryMesh.cpp index 5b5d888a2823bb3db6dc07c82ad6c0e93dd77d77..3ed896685a3630876acd388bc0ba3078c8db2625 100644 --- a/Applications/Utils/MeshEdit/queryMesh.cpp +++ b/Applications/Utils/MeshEdit/queryMesh.cpp @@ -53,7 +53,9 @@ int main(int argc, char *argv[]) auto const mesh = std::unique_ptr<MeshLib::Mesh>( MeshLib::IO::readMeshFromFile(filename)); if (!mesh) + { return EXIT_FAILURE; + } std::vector<std::size_t> selected_node_ids; if (showNodeWithMaxEle_arg.getValue()) @@ -79,18 +81,27 @@ int main(int argc, char *argv[]) out << "# Element " << ele->getID() << std::endl; out << "Type : " << CellType2String(ele->getCellType()) << std::endl; if (materialIds) + { out << "Mat ID : " << (*materialIds)[ele_id] << std::endl; + } out << "Nodes: " << std::endl; - for (unsigned i=0; i<ele->getNumberOfNodes(); i++) - out << ele->getNode(i)->getID() << " " << *ele->getNode(i) << std::endl; + for (unsigned i = 0; i < ele->getNumberOfNodes(); i++) + { + out << ele->getNode(i)->getID() << " " << *ele->getNode(i) + << std::endl; + } out << "Content: " << ele->getContent() << std::endl; out << "Neighbors: "; for (unsigned i=0; i<ele->getNumberOfNeighbors(); i++) { if (ele->getNeighbor(i)) + { out << ele->getNeighbor(i)->getID() << " "; + } else + { out << "none "; + } } out << std::endl; INFO("%s", out.str().c_str()); @@ -107,11 +118,15 @@ int main(int argc, char *argv[]) out << "Coordinates: " << *node << std::endl; out << "Connected elements (" << node->getNumberOfElements() << "): "; for (auto ele : node->getElements()) + { out << ele->getID() << " "; + } out << std::endl; out << "Connected nodes (" << node->getConnectedNodes().size() << "): "; for (auto nd : node->getConnectedNodes()) + { out << nd->getID() << " "; + } out << std::endl; INFO("%s", out.str().c_str()); } diff --git a/Applications/Utils/MeshEdit/removeMeshElements.cpp b/Applications/Utils/MeshEdit/removeMeshElements.cpp index c55940490f3fa4ef500af2c0e5e6d191e980a703..648e91665bbfa7860c1f1a794bee426878acb4c2 100644 --- a/Applications/Utils/MeshEdit/removeMeshElements.cpp +++ b/Applications/Utils/MeshEdit/removeMeshElements.cpp @@ -36,8 +36,10 @@ void searchByPropertyValue(std::string const& property_name, std::size_t n_marked_elements = searcher.searchByPropertyValue<double>( property_name, property_value); if (n_marked_elements == 0) + { n_marked_elements = searcher.searchByPropertyValue<int>( property_name, property_value); + } INFO("%d elements with property value %s found.", n_marked_elements, std::to_string(property_value).c_str()); @@ -53,9 +55,11 @@ void searchByPropertyRange(std::string const& property_name, property_name, min_value, max_value, outside); if (n_marked_elements == 0) + { n_marked_elements = searcher.searchByPropertyValueRange<int>( property_name, static_cast<int>(min_value), static_cast<int>(max_value), outside); + } // add checks for other data types here (if n_marked_elements remains 0) @@ -145,7 +149,9 @@ int main (int argc, char* argv[]) std::unique_ptr<MeshLib::Mesh const> mesh( MeshLib::IO::readMeshFromFile(mesh_in.getValue())); if (mesh == nullptr) + { return EXIT_FAILURE; + } INFO("Mesh read: %d nodes, %d elements.", mesh->getNumberOfNodes(), mesh->getNumberOfElements()); MeshLib::ElementSearch searcher(*mesh); @@ -158,7 +164,10 @@ int main (int argc, char* argv[]) const std::vector<std::string> eleTypeNames = eleTypeArg.getValue(); for (const auto& typeName : eleTypeNames) { const MeshLib::MeshElemType type = MeshLib::String2MeshElemType(typeName); - if (type == MeshLib::MeshElemType::INVALID) continue; + if (type == MeshLib::MeshElemType::INVALID) + { + continue; + } INFO("%d %s elements found.", searcher.searchByElementType(type), typeName.c_str()); } @@ -230,7 +239,9 @@ int main (int argc, char* argv[]) aabb_error = true; } if (aabb_error) + { return EXIT_FAILURE; + } std::array<MathLib::Point3d, 2> extent({{ MathLib::Point3d(std::array<double,3>{{xSmallArg.getValue(), @@ -246,7 +257,9 @@ int main (int argc, char* argv[]) *mesh, searcher.getSearchedElementIDs(), mesh->getName())); if (new_mesh == nullptr) + { return EXIT_FAILURE; + } // write into a file MeshLib::IO::writeMeshToFile(*new_mesh, mesh_out.getValue()); diff --git a/Applications/Utils/MeshEdit/reviseMesh.cpp b/Applications/Utils/MeshEdit/reviseMesh.cpp index c03308af52be303a93577821361858d241f49768..dbd87f3ab37360223a0a51cc1c7fe9f81f75ba73 100644 --- a/Applications/Utils/MeshEdit/reviseMesh.cpp +++ b/Applications/Utils/MeshEdit/reviseMesh.cpp @@ -57,7 +57,9 @@ int main(int argc, char *argv[]) std::unique_ptr<MeshLib::Mesh> org_mesh( MeshLib::IO::readMeshFromFile(input_arg.getValue())); if (!org_mesh) + { return EXIT_FAILURE; + } INFO("Mesh read: %d nodes, %d elements.", org_mesh->getNumberOfNodes(), org_mesh->getNumberOfElements()); // revise the mesh diff --git a/Applications/Utils/MeshEdit/swapNodeCoordinateAxes.cpp b/Applications/Utils/MeshEdit/swapNodeCoordinateAxes.cpp index e19f5cdddefc66ff7d45154712459a42540ba9a2..3d1d145a82d94b8994a216d4e69bc9e17ac5a381 100644 --- a/Applications/Utils/MeshEdit/swapNodeCoordinateAxes.cpp +++ b/Applications/Utils/MeshEdit/swapNodeCoordinateAxes.cpp @@ -28,10 +28,14 @@ static void swapNodeCoordinateAxes(MeshLib::Mesh &mesh, std::array<int, 3> const double new_coords[3] = {}; for (MeshLib::Node* node : mesh.getNodes()) { - for (int i=0; i<3; i++) + for (int i = 0; i < 3; i++) + { new_coords[i] = (*node)[new_axes_indices[i]]; - for (int i=0; i<3; i++) + } + for (int i = 0; i < 3; i++) + { (*node)[i] = new_coords[i]; + } } } @@ -43,18 +47,27 @@ static bool parseNewOrder(std::string const& str_order, std::array<int, 3> &new_ return false; } - for (std::size_t i=0; i<new_axes_indices.size(); i++) + for (std::size_t i = 0; i < new_axes_indices.size(); i++) + { new_axes_indices[i] = -1; + } for (int i=0; i<3; i++) { if (str_order[i] == 'x') + { new_axes_indices[i] = 0; + } else if (str_order[i] == 'y') + { new_axes_indices[i] = 1; + } else if (str_order[i] == 'z') + { new_axes_indices[i] = 2; - else { + } + else + { ERR("Invalid argument for the new order. The given argument " "contains a character other than 'x', 'y', 'z'."); return false; @@ -102,12 +115,16 @@ int main(int argc, char *argv[]) const std::string str_order = new_order_arg.getValue(); std::array<int, 3> new_order = {{}}; if (!parseNewOrder(str_order, new_order)) + { return EXIT_FAILURE; + } std::unique_ptr<MeshLib::Mesh> mesh( MeshLib::IO::readMeshFromFile(input_arg.getValue())); if (!mesh) + { return EXIT_FAILURE; + } if (mesh->getDimension() == 3) { diff --git a/Applications/Utils/MeshGeoTools/ComputeSurfaceNodeIDsInPolygonalRegion.cpp b/Applications/Utils/MeshGeoTools/ComputeSurfaceNodeIDsInPolygonalRegion.cpp index 69e8f07c48b4972b20683ce127b2628a55f64402..d80629f48c6624b0ca114627ab02a62056fef0af 100644 --- a/Applications/Utils/MeshGeoTools/ComputeSurfaceNodeIDsInPolygonalRegion.cpp +++ b/Applications/Utils/MeshGeoTools/ComputeSurfaceNodeIDsInPolygonalRegion.cpp @@ -135,7 +135,9 @@ int main (int argc, char* argv[]) std::string polygon_name; ply_vec->getNameOfElement(plys[j], polygon_name); if (polygon_name.empty()) + { polygon_name = "Polygon-" + std::to_string(j); + } // create Polygon from Polyline GeoLib::Polygon const& polygon(*(plys[j])); // ids of mesh nodes on surface that are within the given polygon diff --git a/Applications/Utils/ModelPreparation/ComputeNodeAreasFromSurfaceMesh.cpp b/Applications/Utils/ModelPreparation/ComputeNodeAreasFromSurfaceMesh.cpp index 1491d7b224705bd5e8ee4f0c1aaac6571fc3cb35..3614095d5d0ea1901b6ff6339a39a4399556c029 100644 --- a/Applications/Utils/ModelPreparation/ComputeNodeAreasFromSurfaceMesh.cpp +++ b/Applications/Utils/ModelPreparation/ComputeNodeAreasFromSurfaceMesh.cpp @@ -126,7 +126,9 @@ int main (int argc, char* argv[]) // generate file names for output std::string path(out_base_fname.getValue()); if (path.empty()) + { path = BaseLib::dropFileExtension(mesh_in.getValue()); + } std::string const id_and_area_fname(path+".txt"); std::string const csv_fname(path+".csv"); diff --git a/Applications/Utils/ModelPreparation/ConvertVtkDataArrayToVtkDataArray.cpp b/Applications/Utils/ModelPreparation/ConvertVtkDataArrayToVtkDataArray.cpp index 1544ab65735e1164f270cdca1fa6511fd26463e5..1a2e6cf6560c728029a4f197a251edf695f2f5a9 100644 --- a/Applications/Utils/ModelPreparation/ConvertVtkDataArrayToVtkDataArray.cpp +++ b/Applications/Utils/ModelPreparation/ConvertVtkDataArrayToVtkDataArray.cpp @@ -33,15 +33,19 @@ std::pair<bool, std::string> castPropertyVectorToPropertyVector( auto const* const orig_pv = properties.getPropertyVector<T1>( property_vector_name_in, MeshLib::MeshItemType::Cell, 1); if (!orig_pv) + { return std::make_pair(false, "Original property vector '" + property_vector_name_in + "' not found."); + } auto* new_pv = properties.createNewPropertyVector<T2>( property_vector_name_out, MeshLib::MeshItemType::Cell, 1); if (!new_pv) + { return std::make_pair(false, "Could not create new property vector '" + property_vector_name_in + "' not found."); + } new_pv->resize(orig_pv->getNumberOfTuples()); for (std::size_t i(0); i < new_pv->getNumberOfTuples(); ++i) { @@ -129,21 +133,25 @@ int main(int argc, char* argv[]) if (mesh->getProperties().existsPropertyVector<float>( property_arg.getValue(), MeshLib::MeshItemType::Cell, 1)) + { std::tie(success, err_msg) = castPropertyVectorToPropertyVector<float, int>( mesh->getProperties(), property_arg.getValue(), new_property_arg.getValue()); + } } if (new_property_data_type_arg.getValue() == "double") { if (mesh->getProperties().existsPropertyVector<float>( property_arg.getValue(), MeshLib::MeshItemType::Cell, 1)) + { std::tie(success, err_msg) = castPropertyVectorToPropertyVector<float, double>( mesh->getProperties(), property_arg.getValue(), new_property_arg.getValue()); + } } if (!success) diff --git a/Applications/Utils/ModelPreparation/PartitionMesh/NodeWiseMeshPartitioner.cpp b/Applications/Utils/ModelPreparation/PartitionMesh/NodeWiseMeshPartitioner.cpp index b620fecfb03f20b1abf6ab28c6bdc8591c617de0..08f68c1897f25722ae22271e49496e989aa925ed 100644 --- a/Applications/Utils/ModelPreparation/PartitionMesh/NodeWiseMeshPartitioner.cpp +++ b/Applications/Utils/ModelPreparation/PartitionMesh/NodeWiseMeshPartitioner.cpp @@ -381,7 +381,9 @@ bool copyPropertyVector(MeshLib::Properties const& original_properties, std::size_t const total_number_of_tuples) { if (!original_properties.existsPropertyVector<T>(name)) + { return false; + } auto const& pv = original_properties.getPropertyVector<T>(name); auto partitioned_pv = partitioned_properties.createNewPropertyVector<T>( @@ -708,7 +710,9 @@ bool writePropertyVectorBinary( std::ostream& out_val, std::ostream& out_meta) { if (!partitioned_properties.existsPropertyVector<T>(name)) + { return false; + } MeshLib::IO::PropertyVectorMetaData pvmd; pvmd.property_name = name; diff --git a/Applications/Utils/ModelPreparation/createNeumannBc.cpp b/Applications/Utils/ModelPreparation/createNeumannBc.cpp index e03f656a584417826a36e5de1d6bcf0846d714f0..4a35bc69cac305b213e4eef7a61c1ae44b9e95a2 100644 --- a/Applications/Utils/ModelPreparation/createNeumannBc.cpp +++ b/Applications/Utils/ModelPreparation/createNeumannBc.cpp @@ -147,7 +147,9 @@ int main(int argc, char* argv[]) } }(); if (!node_id_pv) + { return EXIT_FAILURE; + } std::vector<double> integrated_values = getSurfaceIntegratedValuesForNodes( *surface_mesh, property_in_arg.getValue()); @@ -176,7 +178,9 @@ int main(int argc, char* argv[]) std::ofstream result_out(result_file.getValue() + ".txt"); result_out.precision(std::numeric_limits<double>::digits10); for (auto const& p : direct_values) + { result_out << p.first << " " << p.second << "\n"; + } return EXIT_SUCCESS; } diff --git a/Applications/Utils/PostProcessing/postLIE.cpp b/Applications/Utils/PostProcessing/postLIE.cpp index 0127f0e2f714d28832ef178cc964eb96dbf08312..01321a05898d1743c041ae8217a80c02485888f7 100644 --- a/Applications/Utils/PostProcessing/postLIE.cpp +++ b/Applications/Utils/PostProcessing/postLIE.cpp @@ -34,7 +34,9 @@ void postVTU(std::string const& int_vtu_filename, std::unique_ptr<MeshLib::Mesh const> mesh( MeshLib::IO::readMeshFromFile(int_vtu_filename)); if (mesh->isNonlinear()) + { mesh = MeshLib::convertToLinearMesh(*mesh, mesh->getName()); + } // post-process std::vector<MeshLib::Element*> vec_matrix_elements; @@ -76,7 +78,9 @@ void postPVD(std::string const& in_pvd_filename, for (auto& dataset : pt.get_child("VTKFile.Collection")) { if (dataset.first != "DataSet") + { continue; + } // get VTU file name auto const org_vtu_filename = @@ -85,7 +89,9 @@ void postPVD(std::string const& in_pvd_filename, BaseLib::extractBaseName(org_vtu_filename); auto org_vtu_dir = BaseLib::extractPath(org_vtu_filename); if (org_vtu_dir.empty()) + { org_vtu_dir = in_pvd_file_dir; + } auto const org_vtu_filepath = BaseLib::joinPaths(org_vtu_dir, org_vtu_filebasename); INFO("processing %s...", org_vtu_filepath.c_str()); @@ -133,12 +139,18 @@ int main(int argc, char* argv[]) auto const in_file_ext = BaseLib::getFileExtension(arg_in_file.getValue()); if (in_file_ext == "pvd") + { postPVD(arg_in_file.getValue(), arg_out_file.getValue()); + } else if (in_file_ext == "vtu") + { postVTU(arg_in_file.getValue(), arg_out_file.getValue()); + } else + { OGS_FATAL("The given file type (%s) is not supported.", in_file_ext.c_str()); + } return EXIT_SUCCESS; } diff --git a/Applications/Utils/SimpleMeshCreation/generateStructuredMesh.cpp b/Applications/Utils/SimpleMeshCreation/generateStructuredMesh.cpp index e660ca3cfb052ba48bf05162c050fc0ed9aa4f55..f62dcdde5b0959091989c04266059a772a1b6a08 100644 --- a/Applications/Utils/SimpleMeshCreation/generateStructuredMesh.cpp +++ b/Applications/Utils/SimpleMeshCreation/generateStructuredMesh.cpp @@ -144,8 +144,10 @@ int main (int argc, char* argv[]) const unsigned dim = getDimension(eleType); bool dim_used[3] = {false}; - for (unsigned i=0; i<dim; i++) + for (unsigned i = 0; i < dim; i++) + { dim_used[i] = true; + } std::vector<TCLAP::ValueArg<double>*> vec_lengthArg = {&lengthXArg, &lengthYArg, &lengthZArg}; std::vector<TCLAP::ValueArg<unsigned>*> vec_ndivArg = {&nsubdivXArg, &nsubdivYArg, &nsubdivZArg}; diff --git a/BaseLib/Algorithm.h b/BaseLib/Algorithm.h index 1cd7ccb3242f047fe62c18b954a362286d0bf467..4a9471bda26afacdcc759bcf1906f645e8cc6efd 100644 --- a/BaseLib/Algorithm.h +++ b/BaseLib/Algorithm.h @@ -215,7 +215,9 @@ void uniquePushBack(Container& container, { if (std::find(container.begin(), container.end(), element) == container.end()) + { container.push_back(element); + } } template <typename Container> diff --git a/BaseLib/ConfigTree-impl.h b/BaseLib/ConfigTree-impl.h index 76cb7fa5f44319311d1601ec4529714806e77bd7..9acdf51c07393bdcf350664932dd6092fcc08916 100644 --- a/BaseLib/ConfigTree-impl.h +++ b/BaseLib/ConfigTree-impl.h @@ -40,7 +40,9 @@ ConfigTree:: getConfigParameter(std::string const& param) const { if (auto p = getConfigParameterOptional<T>(param)) + { return *p; + } error("Key <" + param + "> has not been found"); } @@ -51,7 +53,9 @@ ConfigTree:: getConfigParameter(std::string const& param, T const& default_value) const { if (auto p = getConfigParameterOptional<T>(param)) + { return *p; + } return default_value; } @@ -69,7 +73,10 @@ template <typename T> boost::optional<T> ConfigTree::getConfigParameterOptionalImpl( std::string const& param, T*) const { - if (auto p = getConfigSubtreeOptional(param)) return p->getValue<T>(); + if (auto p = getConfigSubtreeOptional(param)) + { + return p->getValue<T>(); + } return boost::none; } @@ -84,7 +91,9 @@ boost::optional<std::vector<T>> ConfigTree::getConfigParameterOptionalImpl( std::vector<T> result; T value; while (sstr >> value) + { result.push_back(value); + } if (!sstr.eof()) // The stream is not read until the end, must be an // error. result contains number of read values. { @@ -185,7 +194,9 @@ ConfigTree:: getConfigAttribute(std::string const& attr) const { if (auto a = getConfigAttributeOptional<T>(attr)) + { return *a; + } error("Did not find XML attribute with name '" + attr + "'."); } @@ -195,7 +206,9 @@ T ConfigTree::getConfigAttribute(std::string const& attr, T const& default_value) const { if (auto a = getConfigAttributeOptional<T>(attr)) + { return *a; + } return default_value; } @@ -237,7 +250,10 @@ markVisited(std::string const& key, Attr const is_attr, if (!p.second) { // no insertion happened auto& v = p.first->second; if (v.type == type) { - if (!peek_only) ++v.count; + if (!peek_only) + { + ++v.count; + } } else { error("There already was an attempt to obtain key <" + key + "> with type '" + v.type.name() + "' (now: '" + type.name() + diff --git a/BaseLib/ConfigTree.cpp b/BaseLib/ConfigTree.cpp index e96d729cdeddfe0309ff1fecc68e3b961c6e2b9d..1cf8551998fc760bb65e83a691885653e2d7bb14 100644 --- a/BaseLib/ConfigTree.cpp +++ b/BaseLib/ConfigTree.cpp @@ -113,7 +113,9 @@ getConfigParameter(std::string const& root) const { auto ct = getConfigSubtree(root); if (ct.hasChildren()) + { error("Requested parameter <" + root + "> actually is a subtree."); + } return ct; } @@ -123,7 +125,9 @@ getConfigParameterOptional(std::string const& root) const { auto ct = getConfigSubtreeOptional(root); if (ct && ct->hasChildren()) + { error("Requested parameter <" + root + "> actually is a subtree."); + } return ct; } @@ -241,7 +245,9 @@ void ConfigTree::onwarning(const std::string& filename, const std::string& path, void ConfigTree::assertNoSwallowedErrors() { if (configtree_destructor_error_messages.empty()) + { return; + } ERR("ConfigTree: There have been errors when parsing the configuration " "file(s):"); @@ -257,7 +263,10 @@ std::string ConfigTree::shortString(const std::string &s) { const std::size_t maxlen = 100; - if (s.size() < maxlen) return s; + if (s.size() < maxlen) + { + return s; + } return s.substr(0, maxlen-3) + "..."; } @@ -287,7 +296,10 @@ joinPaths( const std::string &p1, const std::string &p2) const error("Second path to be joined is empty."); } - if (p1.empty()) return p2; + if (p1.empty()) + { + return p2; + } return p1 + pathseparator + p2; } @@ -313,7 +325,10 @@ void ConfigTree::checkUniqueAttr(const std::string &attr) const auto attr2 = attr; do { pos = attr2.find_first_of(":ABCDEFGHIJKLMNOPQRSTUVWXYZ", pos); - if (pos != attr.npos) attr2[pos] = 'a'; + if (pos != attr.npos) + { + attr2[pos] = 'a'; + } } while (pos != attr.npos); checkKeyname(attr2); @@ -353,10 +368,13 @@ ConfigTree::hasChildren() const { auto const& tree = *_tree; if (tree.begin() == tree.end()) - return false; // no children - if (tree.front().first == "<xmlattr>" - && (++tree.begin()) == tree.end()) - return false; // only attributes + { + return false; // no children + } + if (tree.front().first == "<xmlattr>" && (++tree.begin()) == tree.end()) + { + return false; // only attributes + } return true; } @@ -364,7 +382,10 @@ ConfigTree::hasChildren() const void ConfigTree::checkAndInvalidate() { - if (!_tree) return; + if (!_tree) + { + return; + } // Note: due to a limitation in boost::property_tree it is not possible // to discriminate between <tag></tag> and <tag/> in the input file. @@ -376,8 +397,10 @@ ConfigTree::checkAndInvalidate() // iterate over children for (auto const& p : *_tree) { - if (p.first != "<xmlattr>") // attributes are handled below + if (p.first != "<xmlattr>") + { // attributes are handled below markVisitedDecrement(Attr::TAG, p.first); + } } // iterate over attributes @@ -430,12 +453,18 @@ void checkAndInvalidate(ConfigTree &conf) void checkAndInvalidate(ConfigTree* const conf) { - if (conf) conf->checkAndInvalidate(); + if (conf) + { + conf->checkAndInvalidate(); + } } void checkAndInvalidate(std::unique_ptr<ConfigTree> const& conf) { - if (conf) conf->checkAndInvalidate(); + if (conf) + { + conf->checkAndInvalidate(); + } } } // namespace BaseLib diff --git a/BaseLib/ConfigTree.h b/BaseLib/ConfigTree.h index 1c363bee6b0939896adde6c50499de0d8e9a99fe..e4cfe1825e38bab7529ae413dd4796dda2db002f 100644 --- a/BaseLib/ConfigTree.h +++ b/BaseLib/ConfigTree.h @@ -158,8 +158,10 @@ public: ConfigTree operator*() { auto st = SubtreeIterator::operator*(); if (st.hasChildren()) - _parent.error("The requested parameter <" + _tagname + ">" - " has child elements."); + { + _parent.error("The requested parameter <" + _tagname + + "> has child elements."); + } return st; } }; diff --git a/BaseLib/DateTools.cpp b/BaseLib/DateTools.cpp index 9d2bea60c6fed0d5abe6a6d8eb2c6a37f659f6f2..fcbf8ee1b74f067b716d5a8c60432fe8e1adf3a8 100644 --- a/BaseLib/DateTools.cpp +++ b/BaseLib/DateTools.cpp @@ -48,10 +48,14 @@ std::string int2date(int date) int d = date - (y * 10000) - (m * 100); std::stringstream ss; if (d < 10) + { ss << "0"; + } ss << d << "."; if (m < 10) + { ss << "0"; + } ss << m << "." << y; return ss.str(); } @@ -79,10 +83,14 @@ std::string date2string(double ddate) std::string day = std::to_string(d); if (d < 10) + { day = "0" + day; + } std::string month = std::to_string(m); if (m < 10) + { month = "0" + month; + } std::string s = std::to_string(y) + "-" + month + "-" + day; return s; } @@ -91,7 +99,9 @@ int strDate2int(const std::string &s) { std::string str(s); if (s.length() > 10) - str = s.substr(0,10); + { + str = s.substr(0, 10); + } std::size_t sep ( str.find('.',0) ); int d ( atoi(str.substr(0, sep).c_str()) ); std::size_t sep2 ( str.find('.', sep + 1) ); diff --git a/BaseLib/FileFinder.cpp b/BaseLib/FileFinder.cpp index d05ba3760aacb7a2f570ea39896c3442f23e8967..fc0fb6672c19b1310c5a2607792e6e8bf4f0463b 100644 --- a/BaseLib/FileFinder.cpp +++ b/BaseLib/FileFinder.cpp @@ -31,18 +31,26 @@ FileFinder::FileFinder(std::initializer_list<std::string> dirs) { addDirectory("."); for (auto const& dir : dirs) + { addDirectory(dir); + } } void FileFinder::addDirectory(std::string const& dir) { if (dir.empty()) + { return; + } if (dir[dir.size() - 1] != '/') + { _directories.emplace_back(dir + "/"); + } else + { _directories.push_back(dir); + } } std::string FileFinder::getPath(std::string const& filename) const diff --git a/BaseLib/FileTools.cpp b/BaseLib/FileTools.cpp index d710c88ff4fb2b299dec9386d1d4ca8b36d903fb..0dbf77f2fefe263ce721d85aa6a9c5a787bafa03 100644 --- a/BaseLib/FileTools.cpp +++ b/BaseLib/FileTools.cpp @@ -48,11 +48,15 @@ double swapEndianness(double const& v) } a {}, b {}; a.v = v; - for (unsigned short i = 0; i < sizeof(double)/2; i++) - b.c[i] = a.c[sizeof(double)/2 - i - 1]; + for (unsigned short i = 0; i < sizeof(double) / 2; i++) + { + b.c[i] = a.c[sizeof(double) / 2 - i - 1]; + } - for (unsigned short i = sizeof(double)/2; i < sizeof(double); i++) - b.c[i] = a.c[sizeof(double)+sizeof(double)/2 - i - 1]; + for (unsigned short i = sizeof(double) / 2; i < sizeof(double); i++) + { + b.c[i] = a.c[sizeof(double) + sizeof(double) / 2 - i - 1]; + } return b.v; } @@ -95,12 +99,16 @@ std::string dropFileExtension(std::string const& filename) // Look for dots in filename. auto const p = findLastDot(filename); if (p == std::string::npos) + { return filename; + } // Check position of the last path separator. auto const s = findLastPathSeparator(filename); if (s != std::string::npos && p < s) + { return filename; + } return filename.substr(0, p); } @@ -109,7 +117,9 @@ std::string extractBaseName(std::string const& pathname) { auto const p = findLastPathSeparator(pathname); if (p == std::string::npos) + { return pathname; + } return pathname.substr(p + 1); } @@ -124,7 +134,9 @@ std::string getFileExtension(const std::string &path) const std::string str = extractBaseName(path); auto const p = findLastDot(str); if (p == std::string::npos) + { return std::string(); + } return str.substr(p + 1); } @@ -146,12 +158,18 @@ std::string copyPathToFileName(const std::string &file_name, // check if file_name already contains a full path auto const pos = findLastPathSeparator(file_name); if (pos != std::string::npos) + { return file_name; + } if (source.empty()) + { return file_name; + } if (source.back() != pathSeparator) + { return BaseLib::extractPath(source + pathSeparator).append(file_name); + } return BaseLib::extractPath(source).append(file_name); } @@ -159,24 +177,32 @@ std::string extractPath(std::string const& pathname) { auto const pos = findLastPathSeparator(pathname); if (pos == std::string::npos) + { return ""; + } return pathname.substr(0, pos + 1); } std::string appendPathSeparator(std::string const& path) { - if(findLastPathSeparator(path) == path.length() - 1) + if (findLastPathSeparator(path) == path.length() - 1) + { return path; + } return path + pathSeparator; } std::string joinPaths(std::string const& pathA, std::string const& pathB) { if (pathA.empty()) + { return pathB; + } if (pathB.empty()) + { return pathA; + } if (pathB.front() == pathSeparator) { auto const tmpB = pathB.substr(1); diff --git a/BaseLib/FileTools.h b/BaseLib/FileTools.h index 05d36edc15dc6b6d3318d14b1f85d5e37f29b964..c5613eedbbf3f789e46064cbc8cc25d5301d5f36 100644 --- a/BaseLib/FileTools.h +++ b/BaseLib/FileTools.h @@ -52,7 +52,9 @@ T swapEndianness(T const& v) a.v = v; for (unsigned short i = 0; i < sizeof(T); i++) + { b.c[i] = a.c[sizeof(T) - i - 1]; + } return b.v; } @@ -84,10 +86,14 @@ std::vector<T> readBinaryArray(std::string const& filename, std::size_t const n) result.reserve(n); for (std::size_t p = 0; in && !in.eof() && p < n; ++p) + { result.push_back(BaseLib::readBinaryValue<T>(in)); + } if (result.size() == n) + { return result; + } ERR("readBinaryArray(): Error while reading from file '%s'.", filename.c_str()); diff --git a/BaseLib/Histogram.h b/BaseLib/Histogram.h index 3561cf267e8bf27251ddec9ad721075b4fafaad4..4a6159f1495101518e86a8b6e3705d9549185a9a 100644 --- a/BaseLib/Histogram.h +++ b/BaseLib/Histogram.h @@ -81,7 +81,9 @@ public: void update() { if (!_dirty) + { return; + } _bin_width = (_max - _min) / _nr_bins; @@ -120,7 +122,9 @@ public: const int n_stars = std::ceil(line_width * ((double)_histogram[bin] / count_max)); for (int star = 0; star < n_stars; star++) + { os << "*"; + } os << "\n"; } } @@ -147,7 +151,9 @@ public: double const bin_width (this->getBinWidth()); for (std::size_t k(0); k < n_bins; k++) - out << min+k*bin_width << " " << bin_cnts[k] << "\n"; + { + out << min + k * bin_width << " " << bin_cnts[k] << "\n"; + } out.close (); return 0; } @@ -165,7 +171,9 @@ protected: _dirty = true; if (computeHistogram) + { update(); + } } Data _data; diff --git a/BaseLib/IO/Writer.cpp b/BaseLib/IO/Writer.cpp index a68ebff1f3f6f43839a42fe4a40c714b81380676..5dac385a0a45b067a379f2110d49ebe648aba4a6 100644 --- a/BaseLib/IO/Writer.cpp +++ b/BaseLib/IO/Writer.cpp @@ -36,7 +36,9 @@ std::string Writer::writeToString() _out.clear(); if (this->write()) + { return _out.str(); + } return std::string(""); } diff --git a/BaseLib/StringTools.cpp b/BaseLib/StringTools.cpp index a1e10e4a1ec141e1c0c99a7ef635accc1158a4e1..080fa99b2a8e62305d747583053c62db01787cef 100644 --- a/BaseLib/StringTools.cpp +++ b/BaseLib/StringTools.cpp @@ -40,8 +40,10 @@ std::list<std::string> splitString(const std::string &str, char delim) std::list<std::string> strList; std::stringstream ss(str); std::string item; - while(getline(ss, item, delim)) + while (getline(ss, item, delim)) + { strList.push_back(item); + } return strList; } @@ -60,11 +62,15 @@ void trim(std::string &str, char ch) { str.erase(pos + 1); pos = str.find_first_not_of(ch); - if(pos != std::string::npos) + if (pos != std::string::npos) + { str.erase(0, pos); + } } else + { str.erase(str.begin(), str.end()); + } } void simplify(std::string &str) diff --git a/BaseLib/Subdivision.cpp b/BaseLib/Subdivision.cpp index 58d1adb4d7f0cf40cc1ef7da158f2d4cf7df986a..e8655e9e64d325c4a37974eb53848af143818e8b 100644 --- a/BaseLib/Subdivision.cpp +++ b/BaseLib/Subdivision.cpp @@ -50,9 +50,13 @@ std::vector<double> GradualSubdivision::operator()() const if (vec_x.back() < _length) { double last_dx = vec_x[vec_x.size() - 1] - vec_x[vec_x.size() - 2]; if (_length - vec_x.back() < last_dx) + { vec_x[vec_x.size() - 1] = _length; + } else + { vec_x.push_back(_length); + } } return vec_x; } diff --git a/BaseLib/Subdivision.h b/BaseLib/Subdivision.h index 49ba120cf4d6ba0dc76f45e1e881d146e5c1a8d9..fc0a3552f3f577859b635ae980ac17323f2dd2f1 100644 --- a/BaseLib/Subdivision.h +++ b/BaseLib/Subdivision.h @@ -46,8 +46,10 @@ public: std::vector<double> x; x.reserve(_n_subdivision+1); const double dL = _length/static_cast<double>(_n_subdivision); - for (std::size_t i=0; i<_n_subdivision+1; i++) - x.push_back(i*dL); + for (std::size_t i = 0; i < _n_subdivision + 1; i++) + { + x.push_back(i * dL); + } return x; } diff --git a/BaseLib/TCLAPCustomOutput.h b/BaseLib/TCLAPCustomOutput.h index b4c232976846b9ff7a8fc46966175155b163c255..3c3ef0034f4c2f3a7d56b4060bcc9c7c4e6782ee 100644 --- a/BaseLib/TCLAPCustomOutput.h +++ b/BaseLib/TCLAPCustomOutput.h @@ -97,8 +97,10 @@ inline void TCLAPCustomOutput::failure( TCLAP::CmdLineInterface& _cmd, << std::endl << " " << progName << " --help" << std::endl << std::endl; } - else - usage(_cmd); + else + { + usage(_cmd); + } throw TCLAP::ExitException(1); } @@ -118,22 +120,31 @@ TCLAPCustomOutput::_shortUsage( TCLAP::CmdLineInterface& _cmd, for ( int i = 0; static_cast<unsigned int>(i) < xorList.size(); i++ ) { s += " {"; - for ( TCLAP::ArgVectorIterator it = xorList[i].begin(); - it != xorList[i].end(); it++ ) + for (TCLAP::ArgVectorIterator it = xorList[i].begin(); + it != xorList[i].end(); + it++) + { s += (*it)->shortID() + "|"; + } s[s.length()-1] = '}'; } // then the rest - for (auto it = argList.rbegin(); it != argList.rend(); ++it) // here modified - if ( !xorHandler.contains( (*it) ) ) - s += " " + (*it)->shortID(); + for (auto it = argList.rbegin(); it != argList.rend(); ++it) + { // here modified + if (!xorHandler.contains((*it))) + { + s += " " + (*it)->shortID(); + } + } // if the program name is too long, then adjust the second line offset int secondLineOffset = static_cast<int>(progName.length()) + 2; - if ( secondLineOffset > 75/2 ) - secondLineOffset = static_cast<int>(75/2); + if (secondLineOffset > 75 / 2) + { + secondLineOffset = static_cast<int>(75 / 2); + } spacePrint( os, s, 75, 3, secondLineOffset ); } @@ -157,20 +168,24 @@ TCLAPCustomOutput::_longUsage( TCLAP::CmdLineInterface& _cmd, this->spacePrint( os, (*it)->longID(), 75, 3, 3 ); spacePrint( os, (*it)->getDescription(), 75, 5, 0 ); - if ( it+1 != xorList[i].end() ) + if (it + 1 != xorList[i].end()) + { spacePrint(os, "-- OR --", 75, 9, 0); + } } os << std::endl << std::endl; } // then the rest - for (auto it = argList.rbegin(); it != argList.rend(); it++) // here modified - if ( !xorHandler.contains( (*it) ) ) + for (auto it = argList.rbegin(); it != argList.rend(); it++) + { // here modified + if (!xorHandler.contains((*it))) { spacePrint( os, (*it)->longID(), 75, 3, 3 ); spacePrint( os, (*it)->getDescription(), 75, 5, 0 ); os << std::endl; } + } os << std::endl; diff --git a/BaseLib/TemplateLogogFormatterSuppressedGCC-impl.h b/BaseLib/TemplateLogogFormatterSuppressedGCC-impl.h index 81f14f487a88260c4852a19c6ee7c088d4a62082..61ba7c48169d5cc92877d3d5d655f46e286f4923 100644 --- a/BaseLib/TemplateLogogFormatterSuppressedGCC-impl.h +++ b/BaseLib/TemplateLogogFormatterSuppressedGCC-impl.h @@ -76,8 +76,10 @@ TemplateLogogFormatterSuppressedGCC<T_SUPPPRESS_TOPIC_FLAG> m_sMessageBuffer.append( (LOGOG_CHAR)'\n' ); } - if ( target.GetNullTerminatesStrings() ) + if (target.GetNullTerminatesStrings()) + { m_sMessageBuffer.append((LOGOG_CHAR)'\0'); + } return m_sMessageBuffer; } diff --git a/GeoLib/AABB.h b/GeoLib/AABB.h index 874def54e57ce70627dac458c24ebc05a4c8a779..20380adbf9a254bf7f339bbf3662516e125c9679 100644 --- a/GeoLib/AABB.h +++ b/GeoLib/AABB.h @@ -130,19 +130,31 @@ public: bool containsPoint(T const & pnt, double eps) const { if (pnt[0] < _min_pnt[0] - eps || _max_pnt[0] + eps <= pnt[0]) + { return false; + } if (pnt[1] < _min_pnt[1] - eps || _max_pnt[1] + eps <= pnt[1]) + { return false; + } if (pnt[2] < _min_pnt[2] - eps || _max_pnt[2] + eps <= pnt[2]) + { return false; + } return true; } template <typename T> bool containsPointXY(T const & pnt) const { - if (pnt[0] < _min_pnt[0] || _max_pnt[0] <= pnt[0]) return false; - if (pnt[1] < _min_pnt[1] || _max_pnt[1] <= pnt[1]) return false; + if (pnt[0] < _min_pnt[0] || _max_pnt[0] <= pnt[0]) + { + return false; + } + if (pnt[1] < _min_pnt[1] || _max_pnt[1] <= pnt[1]) + { + return false; + } return true; } diff --git a/GeoLib/AnalyticalGeometry-impl.h b/GeoLib/AnalyticalGeometry-impl.h index 025c10dcf80f9262c0c1491b3adfe65a8c94eea0..63ccc49095ed53d9adc56bbb5ea20b47a3d17fec 100644 --- a/GeoLib/AnalyticalGeometry-impl.h +++ b/GeoLib/AnalyticalGeometry-impl.h @@ -33,7 +33,9 @@ void getNewellPlane (InputIterator pnts_begin, InputIterator pnts_end, auto n_pnts(std::distance(pnts_begin, pnts_end)); assert(n_pnts > 2); if (n_pnts > 0) + { d = MathLib::scalarProduct(centroid, plane_normal) / n_pnts; + } } template <class T_POINT> @@ -154,14 +156,22 @@ void computeRotationMatrixToXY(MathLib::Vector3 const& n, rot_mat(1,0) = 0.0; rot_mat(1,1) = 0.0; if (n[1] > 0) + { rot_mat(1,2) = -1.0; + } else - rot_mat(1,2) = 1.0; + { + rot_mat(1, 2) = 1.0; + } rot_mat(2,0) = 0.0; if (n[1] > 0) + { rot_mat(2,1) = 1.0; + } else - rot_mat(2,1) = -1.0; + { + rot_mat(2, 1) = -1.0; + } rot_mat(2,2) = 0.0; return; } @@ -189,7 +199,9 @@ void rotatePoints( for (auto it=pnts_begin; it!=pnts_end; ++it) { tmp = rot_mat * (*it)->getCoords(); for (std::size_t j(0); j < 3; j++) + { (*(*it))[j] = tmp[j]; + } delete [] tmp; } } @@ -213,8 +225,10 @@ MathLib::DenseMatrix<double> rotatePointsToXY(InputIterator1 p_pnts_begin, computeRotationMatrixToXY(plane_normal, rot_mat); rotatePoints(rot_mat, r_pnts_begin, r_pnts_end); - for (auto it=r_pnts_begin; it!=r_pnts_end; ++it) - (*(*it))[2] = 0.0; // should be -= d but there are numerical errors + for (auto it = r_pnts_begin; it != r_pnts_end; ++it) + { + (*(*it))[2] = 0.0; // should be -= d but there are numerical errors + } return rot_mat; } diff --git a/GeoLib/AnalyticalGeometry.cpp b/GeoLib/AnalyticalGeometry.cpp index dd210eb7607204a81cc9c4ad43c02b092ac694b3..3da46a907d76d961ec753f41371182263f46ec33 100644 --- a/GeoLib/AnalyticalGeometry.cpp +++ b/GeoLib/AnalyticalGeometry.cpp @@ -60,9 +60,13 @@ Orientation getOrientation(MathLib::Point3d const& p0, { double const orientation = ExactPredicates::getOrientation2d(p0, p1, p2); if (orientation > 0) + { return CCW; + } if (orientation < 0) + { return CW; + } return COLLINEAR; } @@ -73,9 +77,13 @@ Orientation getOrientationFast(MathLib::Point3d const& p0, double const orientation = ExactPredicates::getOrientation2dFast(p0, p1, p2); if (orientation > 0) + { return CCW; + } if (orientation < 0) + { return CW; + } return COLLINEAR; } @@ -85,33 +93,49 @@ bool parallel(MathLib::Vector3 v, MathLib::Vector3 w) // check degenerated cases if (v.getLength() < eps) + { return false; + } if (w.getLength() < eps) + { return false; + } v.normalize(); w.normalize(); bool parallel(true); - if (std::abs(v[0]-w[0]) > eps) + if (std::abs(v[0] - w[0]) > eps) + { parallel = false; - if (std::abs(v[1]-w[1]) > eps) + } + if (std::abs(v[1] - w[1]) > eps) + { parallel = false; - if (std::abs(v[2]-w[2]) > eps) + } + if (std::abs(v[2] - w[2]) > eps) + { parallel = false; + } if (! parallel) { parallel = true; // change sense of direction of v_normalised v *= -1.0; // check again - if (std::abs(v[0]-w[0]) > eps) + if (std::abs(v[0] - w[0]) > eps) + { parallel = false; - if (std::abs(v[1]-w[1]) > eps) + } + if (std::abs(v[1] - w[1]) > eps) + { parallel = false; - if (std::abs(v[2]-w[2]) > eps) + } + if (std::abs(v[2] - w[2]) > eps) + { parallel = false; + } } return parallel; @@ -127,7 +151,9 @@ bool lineSegmentIntersect(GeoLib::LineSegment const& s0, GeoLib::Point const& d{s1.getEndPoint()}; if (!isCoplanar(a, b, c, d)) + { return false; + } // handle special cases here to avoid computing intersection numerical if (MathLib::sqrDist(a, c) < std::numeric_limits<double>::epsilon() || @@ -297,8 +323,10 @@ void rotatePointsToXZ(std::vector<GeoLib::Point*> &pnts) rotatePoints(rot_mat, pnts); } - for (auto & pnt : pnts) - (*pnt)[1] = 0.0; // should be -= d but there are numerical errors + for (auto& pnt : pnts) + { + (*pnt)[1] = 0.0; // should be -= d but there are numerical errors + } } std::unique_ptr<GeoLib::Point> triangleLineIntersection( @@ -312,11 +340,20 @@ std::unique_ptr<GeoLib::Point> triangleLineIntersection( const MathLib::Vector3 pc(p, c); double u (MathLib::scalarTriple(pq, pc, pb)); - if (u<0) return nullptr; + if (u < 0) + { + return nullptr; + } double v (MathLib::scalarTriple(pq, pa, pc)); - if (v<0) return nullptr; + if (v < 0) + { + return nullptr; + } double w (MathLib::scalarTriple(pq, pb, pa)); - if (w<0) return nullptr; + if (w < 0) + { + return nullptr; + } const double denom (1.0/(u+v+w)); u*=denom; @@ -364,7 +401,9 @@ GeoLib::Polygon rotatePolygonToXY(GeoLib::Polygon const& polygon_in, // 1 copy all points auto* polygon_pnts(new std::vector<GeoLib::Point*>); for (std::size_t k(0); k < polygon_in.getNumberOfPoints(); k++) - polygon_pnts->push_back (new GeoLib::Point (*(polygon_in.getPoint(k)))); + { + polygon_pnts->push_back(new GeoLib::Point(*(polygon_in.getPoint(k)))); + } // 2 rotate points double d_polygon (0.0); @@ -381,7 +420,9 @@ GeoLib::Polygon rotatePolygonToXY(GeoLib::Polygon const& polygon_in, // 4 create new polygon GeoLib::Polyline rot_polyline(*polygon_pnts); for (std::size_t k(0); k < polygon_in.getNumberOfPoints(); k++) + { rot_polyline.addPoint(k); + } rot_polyline.addPoint(0); return GeoLib::Polygon(rot_polyline); } @@ -405,10 +446,14 @@ std::vector<MathLib::Point3d> lineSegmentIntersect2d( // check: (cd) and (ab) are on the same line if (orient_abc == 0.0 && orient_abd == 0.0) { double const eps(std::numeric_limits<double>::epsilon()); - if (MathLib::sqrDist2d(a,c) < eps && MathLib::sqrDist2d(b,d) < eps) - return {{ a, b }}; - if (MathLib::sqrDist2d(a,d) < eps && MathLib::sqrDist2d(b,c) < eps) - return {{ a, b }}; + if (MathLib::sqrDist2d(a, c) < eps && MathLib::sqrDist2d(b, d) < eps) + { + return {{a, b}}; + } + if (MathLib::sqrDist2d(a, d) < eps && MathLib::sqrDist2d(b, c) < eps) + { + return {{a, b}}; + } // Since orient_ab and orient_abd vanish, a, b, c, d are on the same // line and for this reason it is enough to check the x-component. @@ -499,14 +544,18 @@ std::vector<MathLib::Point3d> lineSegmentIntersect2d( }; if (orient_abc == 0.0) { - if (isCollinearPointOntoLineSegment(a,b,c)) + if (isCollinearPointOntoLineSegment(a, b, c)) + { return {{c}}; + } return std::vector<MathLib::Point3d>(); } if (orient_abd == 0.0) { - if (isCollinearPointOntoLineSegment(a,b,d)) + if (isCollinearPointOntoLineSegment(a, b, d)) + { return {{d}}; + } return std::vector<MathLib::Point3d>(); } @@ -545,12 +594,14 @@ void sortSegments( double const eps(std::numeric_limits<double>::epsilon()); auto findNextSegment = [&eps]( - MathLib::Point3d const& seg_beg_pnt, - std::vector<GeoLib::LineSegment>& sub_segments, - std::vector<GeoLib::LineSegment>::iterator& sub_seg_it) - { + MathLib::Point3d const& seg_beg_pnt, + std::vector<GeoLib::LineSegment>& sub_segments, + std::vector<GeoLib::LineSegment>::iterator& + sub_seg_it) { if (sub_seg_it == sub_segments.end()) + { return; + } // find appropriate segment for the given segment begin point auto act_beg_seg_it = std::find_if( sub_seg_it, sub_segments.end(), @@ -560,16 +611,22 @@ void sortSegments( MathLib::sqrDist(seg_beg_pnt, seg.getEndPoint()) < eps; }); if (act_beg_seg_it == sub_segments.end()) + { return; + } // if necessary correct orientation of segment, i.e. swap beg and end if (MathLib::sqrDist(seg_beg_pnt, act_beg_seg_it->getEndPoint()) < MathLib::sqrDist(seg_beg_pnt, act_beg_seg_it->getBeginPoint())) + { std::swap(act_beg_seg_it->getBeginPoint(), act_beg_seg_it->getEndPoint()); + } assert(sub_seg_it != sub_segments.end()); // exchange segments within the container if (sub_seg_it != act_beg_seg_it) + { std::swap(*sub_seg_it, *act_beg_seg_it); + } }; // find start segment @@ -581,7 +638,9 @@ void sortSegments( MathLib::Point3d & new_seg_beg_pnt(seg_it->getEndPoint()); seg_it++; if (seg_it != sub_segments.end()) + { findNextSegment(new_seg_beg_pnt, sub_segments, seg_it); + } } } diff --git a/GeoLib/DuplicateGeometry.cpp b/GeoLib/DuplicateGeometry.cpp index ddfa0ca0df210513244a9b52af40c09a93586d5a..2b6ec49db82ad0da9945ba47809a93e48d4a7dac 100644 --- a/GeoLib/DuplicateGeometry.cpp +++ b/GeoLib/DuplicateGeometry.cpp @@ -69,11 +69,15 @@ std::unique_ptr<std::vector<GeoLib::Polyline*>> DuplicateGeometry::copyPolylines for (std::size_t i=0; i<n_plys; ++i) { if (polylines[i] == nullptr) + { continue; + } (*new_lines)[i] = new GeoLib::Polyline(*_geo_objects.getPointVec(_output_name)); std::size_t const nLinePnts (polylines[i]->getNumberOfPoints()); - for (std::size_t j=0; j<nLinePnts; ++j) + for (std::size_t j = 0; j < nLinePnts; ++j) + { (*new_lines)[i]->addPoint(polylines[i]->getPointID(j)); + } } return new_lines; } @@ -88,7 +92,9 @@ std::unique_ptr<std::vector<Surface*>> DuplicateGeometry::copySurfacesVector( for (std::size_t i=0; i<n_sfc; ++i) { if (surfaces[i] == nullptr) + { continue; + } (*new_surfaces)[i] = new GeoLib::Surface(*_geo_objects.getPointVec(_output_name)); std::size_t const n_tris (surfaces[i]->getNumberOfTriangles()); diff --git a/GeoLib/GEOObjects.cpp b/GeoLib/GEOObjects.cpp index d353b5522adc04b309920c1492d1a122d014f0f9..23809f0e63bf0d2cd46934a53ae87742c571daf3 100644 --- a/GeoLib/GEOObjects.cpp +++ b/GeoLib/GEOObjects.cpp @@ -27,13 +27,19 @@ GEOObjects::~GEOObjects() { // delete surfaces for (auto& surface : _sfc_vecs) + { delete surface; + } // delete polylines for (auto& polyline : _ply_vecs) + { delete polyline; + } // delete points for (auto& point : _pnt_vecs) + { delete point; + } } void GEOObjects::addPointVec(std::unique_ptr<std::vector<Point*>> points, @@ -58,7 +64,9 @@ const std::vector<Point*>* GEOObjects::getPointVec(const std::string &name) cons { std::size_t const idx = this->exists(name); if (idx != std::numeric_limits<std::size_t>::max()) + { return _pnt_vecs[idx]->getVector(); + } DBUG("GEOObjects::getPointVec() - No entry found with name '%s'.", name.c_str()); @@ -69,7 +77,9 @@ const PointVec* GEOObjects::getPointVecObj(const std::string &name) const { std::size_t const idx = this->exists(name); if (idx != std::numeric_limits<std::size_t>::max()) + { return _pnt_vecs[idx]; + } DBUG("GEOObjects::getPointVecObj() - No entry found with name '%s'.", name.c_str()); @@ -85,6 +95,7 @@ bool GEOObjects::removePointVec(std::string const& name) } for (auto it(_pnt_vecs.begin()); it != _pnt_vecs.end(); ++it) + { if ((*it)->getName() == name) { _callbacks->removePointVec(name); @@ -92,6 +103,7 @@ bool GEOObjects::removePointVec(std::string const& name) _pnt_vecs.erase(it); return true; } + } DBUG("GEOObjects::removePointVec() - No entry found with name '%s'.", name.c_str()); return false; @@ -136,11 +148,15 @@ void GEOObjects::addPolylineVec( it = lines->erase (it_erase); } else + { ++it; + } } if (lines->empty()) + { return; + } _ply_vecs.push_back( new PolylineVec(name, std::move(lines), std::move(ply_names))); @@ -154,8 +170,12 @@ bool GEOObjects::appendPolylineVec(const std::vector<Polyline*>& polylines, std::size_t idx (0); bool nfound (true); for (idx = 0; idx < _ply_vecs.size() && nfound; idx++) + { if (_ply_vecs[idx]->getName() == name) + { nfound = false; + } + } if (!nfound) { @@ -163,7 +183,9 @@ bool GEOObjects::appendPolylineVec(const std::vector<Polyline*>& polylines, std::size_t n_plys (polylines.size()); // append lines for (std::size_t k(0); k < n_plys; k++) - _ply_vecs[idx]->push_back (polylines[k]); + { + _ply_vecs[idx]->push_back(polylines[k]); + } _callbacks->appendPolylineVec(name); return true; } @@ -175,8 +197,12 @@ const std::vector<Polyline*>* GEOObjects::getPolylineVec(const std::string &name { std::size_t size (_ply_vecs.size()); for (std::size_t i = 0; i < size; i++) + { if (_ply_vecs[i]->getName() == name) + { return _ply_vecs[i]->getVector(); + } + } DBUG("GEOObjects::getPolylineVec() - No entry found with name '%s'.", name.c_str()); @@ -187,8 +213,12 @@ const PolylineVec* GEOObjects::getPolylineVecObj(const std::string &name) const { std::size_t size (_ply_vecs.size()); for (std::size_t i = 0; i < size; i++) + { if (_ply_vecs[i]->getName() == name) + { return _ply_vecs[i]; + } + } DBUG("GEOObjects::getPolylineVecObj() - No entry found with name '%s'.", name.c_str()); @@ -199,12 +229,14 @@ bool GEOObjects::removePolylineVec(std::string const& name) { _callbacks->removePolylineVec(name); for (auto it = _ply_vecs.begin(); it != _ply_vecs.end(); ++it) + { if ((*it)->getName() == name) { delete *it; _ply_vecs.erase(it); return true; } + } DBUG("GEOObjects::removePolylineVec() - No entry found with name '%s'.", name.c_str()); @@ -229,8 +261,12 @@ bool GEOObjects::appendSurfaceVec(const std::vector<Surface*>& surfaces, std::size_t idx (0); bool nfound (true); for (idx = 0; idx < _sfc_vecs.size() && nfound; idx++) + { if (_sfc_vecs[idx]->getName() == name) + { nfound = false; + } + } if (!nfound) { @@ -238,7 +274,9 @@ bool GEOObjects::appendSurfaceVec(const std::vector<Surface*>& surfaces, std::size_t n_sfcs (surfaces.size()); // append surfaces for (std::size_t k(0); k < n_sfcs; k++) - _sfc_vecs[idx]->push_back (surfaces[k]); + { + _sfc_vecs[idx]->push_back(surfaces[k]); + } _callbacks->appendSurfaceVec(name); return true; } @@ -247,7 +285,9 @@ bool GEOObjects::appendSurfaceVec(const std::vector<Surface*>& surfaces, // ctor, which needs write access to the surface vector. auto sfc = std::make_unique<std::vector<GeoLib::Surface*>>(); for (auto surface : surfaces) + { sfc->push_back(surface); + } addSurfaceVec(std::move(sfc), name); return false; } @@ -256,8 +296,12 @@ const std::vector<Surface*>* GEOObjects::getSurfaceVec(const std::string &name) { std::size_t size (_sfc_vecs.size()); for (std::size_t i = 0; i < size; i++) + { if (_sfc_vecs[i]->getName() == name) + { return _sfc_vecs[i]->getVector(); + } + } DBUG("GEOObjects::getSurfaceVec() - No entry found with name '%s'.", name.c_str()); return nullptr; @@ -267,12 +311,14 @@ bool GEOObjects::removeSurfaceVec(const std::string &name) { _callbacks->removeSurfaceVec(name); for (auto it(_sfc_vecs.begin()); it != _sfc_vecs.end(); ++it) + { if ((*it)->getName() == name) { delete *it; _sfc_vecs.erase (it); return true; } + } DBUG("GEOObjects::removeSurfaceVec() - No entry found with name '%s'.", name.c_str()); @@ -283,8 +329,12 @@ const SurfaceVec* GEOObjects::getSurfaceVecObj(const std::string &name) const { std::size_t size (_sfc_vecs.size()); for (std::size_t i = 0; i < size; i++) + { if (_sfc_vecs[i]->getName() == name) + { return _sfc_vecs[i]; + } + } DBUG("GEOObjects::getSurfaceVecObj() - No entry found with name '%s'.", name.c_str()); return nullptr; @@ -305,11 +355,17 @@ bool GEOObjects::isUniquePointVecName(std::string &name) // 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& point : _pnt_vecs) + { if (cpName == point->getName()) + { isUnique = false; + } + } } // At this point cpName is a unique name and isUnique is true. @@ -329,12 +385,16 @@ bool GEOObjects::isPntVecUsed (const std::string &name) const for (auto polyline : _ply_vecs) { if (polyline->getName() == name) + { return true; + } } for (auto surface : _sfc_vecs) { if (surface->getName() == name) + { return true; + } } return false; @@ -343,16 +403,24 @@ bool GEOObjects::isPntVecUsed (const std::string &name) const void GEOObjects::getStationVectorNames(std::vector<std::string>& names) const { for (auto point : _pnt_vecs) + { if (point->getType() == PointVec::PointType::STATION) + { names.push_back(point->getName()); + } + } } void GEOObjects::getGeometryNames (std::vector<std::string>& names) const { names.clear (); for (auto point : _pnt_vecs) + { if (point->getType() == PointVec::PointType::POINT) + { names.push_back(point->getName()); + } + } } const std::string GEOObjects::getElementNameByID(const std::string &geometry_name, GeoLib::GEOTYPE type, std::size_t id) const @@ -378,12 +446,16 @@ int GEOObjects::mergeGeometries (std::vector<std::string> const & geo_names, const std::size_t n_geo_names(geo_names.size()); if (n_geo_names < 2) + { return 2; + } std::vector<std::size_t> pnt_offsets(n_geo_names, 0); - if (! mergePoints(geo_names, merged_geo_name, pnt_offsets)) + if (!mergePoints(geo_names, merged_geo_name, pnt_offsets)) + { return 1; + } mergePolylines(geo_names, merged_geo_name, pnt_offsets); @@ -404,7 +476,9 @@ bool GEOObjects::mergePoints(std::vector<std::string> const & geo_names, for (std::size_t j(0); j < n_geo_names; ++j) { GeoLib::PointVec const*const pnt_vec(this->getPointVecObj(geo_names[j])); if (pnt_vec == nullptr) + { continue; + } const std::vector<GeoLib::Point*>* pnts(pnt_vec->getVector()); if (pnts == nullptr) { return false; @@ -635,25 +709,31 @@ const GeoLib::GeoObject* GEOObjects::getGeoObject( case GeoLib::GEOTYPE::POINT: { GeoLib::PointVec const* pnt_vec(getPointVecObj(geo_name)); if (pnt_vec) + { geo_obj = const_cast<GeoLib::GeoObject*>( - dynamic_cast<GeoLib::GeoObject const*>( - pnt_vec->getElementByName(geo_obj_name))); + dynamic_cast<GeoLib::GeoObject const*>( + pnt_vec->getElementByName(geo_obj_name))); + } break; } case GeoLib::GEOTYPE::POLYLINE: { GeoLib::PolylineVec const* ply_vec(getPolylineVecObj(geo_name)); if (ply_vec) + { geo_obj = const_cast<GeoLib::GeoObject*>( - dynamic_cast<GeoLib::GeoObject const*>( - ply_vec->getElementByName(geo_obj_name))); + dynamic_cast<GeoLib::GeoObject const*>( + ply_vec->getElementByName(geo_obj_name))); + } break; } case GeoLib::GEOTYPE::SURFACE: { GeoLib::SurfaceVec const* sfc_vec(getSurfaceVecObj(geo_name)); if (sfc_vec) + { geo_obj = const_cast<GeoLib::GeoObject*>( - dynamic_cast<GeoLib::GeoObject const*>( - sfc_vec->getElementByName(geo_obj_name))); + dynamic_cast<GeoLib::GeoObject const*>( + sfc_vec->getElementByName(geo_obj_name))); + } break; } default: @@ -677,11 +757,17 @@ GeoLib::GeoObject const* GEOObjects::getGeoObject( getGeoObject(geo_name, GeoLib::GEOTYPE::POINT, geo_obj_name) ); - if(!geo_obj) - geo_obj = getGeoObject(geo_name, GeoLib::GEOTYPE::POLYLINE, geo_obj_name); + if (!geo_obj) + { + geo_obj = + getGeoObject(geo_name, GeoLib::GEOTYPE::POLYLINE, geo_obj_name); + } - if(!geo_obj) - geo_obj = getGeoObject(geo_name, GeoLib::GEOTYPE::SURFACE, geo_obj_name); + if (!geo_obj) + { + geo_obj = + getGeoObject(geo_name, GeoLib::GEOTYPE::SURFACE, geo_obj_name); + } if (!geo_obj) { DBUG("GEOObjects::getGeoObject(): Could not find '%s' in geometry %s.", @@ -694,12 +780,18 @@ std::size_t GEOObjects::exists(const std::string &geometry_name) const { std::size_t const size (_pnt_vecs.size()); for (std::size_t i = 0; i < size; i++) + { if (_pnt_vecs[i]->getName() == geometry_name) + { return i; + } + } // HACK for enabling conversion of files without loading the associated geometry if (size > 0 && _pnt_vecs[0]->getName() == "conversionTestRun#1") + { return 1; + } return std::numeric_limits<std::size_t>::max(); } diff --git a/GeoLib/IO/TINInterface.cpp b/GeoLib/IO/TINInterface.cpp index 125446e923625404af8b8b8f7452eab71136c64b..b92a59f30c64b1d8df30d20ef4efb84ff76b7d38 100644 --- a/GeoLib/IO/TINInterface.cpp +++ b/GeoLib/IO/TINInterface.cpp @@ -36,7 +36,9 @@ GeoLib::Surface* TINInterface::readTIN(std::string const& fname, if (!in) { WARN("readTIN(): could not open stream from %s.", fname.c_str()); if (errors) - errors->push_back ("readTINFile error opening stream from " + fname); + { + errors->push_back("readTINFile error opening stream from " + fname); + } return nullptr; } @@ -48,7 +50,9 @@ GeoLib::Surface* TINInterface::readTIN(std::string const& fname, { // allow empty lines if (line.empty()) + { continue; + } // parse line std::stringstream input(line); @@ -62,9 +66,13 @@ GeoLib::Surface* TINInterface::readTIN(std::string const& fname, if (!(input >> p0[0] >> p0[1] >> p0[2])) { ERR("Could not read coords of 1st point of triangle %d.", id); if (errors) - errors->push_back (std::string("readTIN error: ") + - std::string("Could not read coords of 1st point in triangle ") + + { + errors->push_back( + std::string("readTIN error: ") + + std::string( + "Could not read coords of 1st point in triangle ") + std::to_string(id)); + } in.close(); delete sfc; return nullptr; @@ -73,9 +81,13 @@ GeoLib::Surface* TINInterface::readTIN(std::string const& fname, if (!(input >> p1[0] >> p1[1] >> p1[2])) { ERR("Could not read coords of 2nd point of triangle %d.", id); if (errors) - errors->push_back (std::string("readTIN error: ") + - std::string("Could not read coords of 2nd point in triangle ") + + { + errors->push_back( + std::string("readTIN error: ") + + std::string( + "Could not read coords of 2nd point in triangle ") + std::to_string(id)); + } in.close(); delete sfc; return nullptr; @@ -84,9 +96,13 @@ GeoLib::Surface* TINInterface::readTIN(std::string const& fname, if (!(input >> p2[0] >> p2[1] >> p2[2])) { ERR("Could not read coords of 3rd point of triangle %d.", id); if (errors) - errors->push_back (std::string("readTIN error: ") + - std::string("Could not read coords of 3rd point in triangle ") + + { + errors->push_back( + std::string("readTIN error: ") + + std::string( + "Could not read coords of 3rd point in triangle ") + std::to_string(id)); + } in.close(); delete sfc; return nullptr; @@ -97,8 +113,11 @@ GeoLib::Surface* TINInterface::readTIN(std::string const& fname, if (MathLib::calcTriangleArea(p0, p1, p2) < d_eps) { ERR("readTIN: Triangle %d has zero area.", id); if (errors) - errors->push_back (std::string("readTIN: Triangle ") - + std::to_string(id) + std::string(" has zero area.")); + { + errors->push_back(std::string("readTIN: Triangle ") + + std::to_string(id) + + std::string(" has zero area.")); + } delete sfc; return nullptr; } @@ -121,7 +140,9 @@ GeoLib::Surface* TINInterface::readTIN(std::string const& fname, if (sfc->getNumberOfTriangles() == 0) { WARN("readTIN(): No triangle found.", fname.c_str()); if (errors) - errors->push_back ("readTIN error because of no triangle found"); + { + errors->push_back("readTIN error because of no triangle found"); + } delete sfc; return nullptr; } diff --git a/GeoLib/IO/XmlIO/Boost/BoostXmlGmlInterface.cpp b/GeoLib/IO/XmlIO/Boost/BoostXmlGmlInterface.cpp index 48c45298b2a7feac21a3e1018fb1cb1f7658116e..5c40bacbf05898dba26566f4642b9bb9dabf1ae9 100644 --- a/GeoLib/IO/XmlIO/Boost/BoostXmlGmlInterface.cpp +++ b/GeoLib/IO/XmlIO/Boost/BoostXmlGmlInterface.cpp @@ -299,7 +299,9 @@ bool BoostXmlGmlInterface::write() pnt_tag.put("<xmlattr>.z", (*((*pnts)[k]))[2]); std::string const& point_name(pnt_vec->getItemNameByID(k)); if (!point_name.empty()) + { pnt_tag.put("<xmlattr>.name", point_name); + } } addPolylinesToPropertyTree(geometry_set); @@ -341,7 +343,9 @@ void BoostXmlGmlInterface::addSurfacesToPropertyTree( auto& surface_tag = surfaces_tag.add("surface", ""); surface_tag.put("<xmlattr>.id", i); if (!sfc_name.empty()) + { surface_tag.put("<xmlattr>.name", sfc_name); + } for (std::size_t j=0; j<surface->getNumberOfTriangles(); ++j) { auto& element_tag = surface_tag.add("element", ""); element_tag.put("<xmlattr>.p1", (*(*surface)[j])[0]); @@ -381,7 +385,9 @@ void BoostXmlGmlInterface::addPolylinesToPropertyTree( auto& polyline_tag = polylines_tag.add("polyline", ""); polyline_tag.put("<xmlattr>.id", i); if (!ply_name.empty()) + { polyline_tag.put("<xmlattr>.name", ply_name); + } for (std::size_t j=0; j<polyline->getNumberOfPoints(); ++j) { polyline_tag.add("pnt", polyline->getPointID(j)); } diff --git a/GeoLib/IO/XmlIO/Rapid/RapidStnInterface.cpp b/GeoLib/IO/XmlIO/Rapid/RapidStnInterface.cpp index 0ffb4f8fea61b87e0bbe12ac93799529c09eabc5..5b3e4cce983cb1a361af439f4b6b411522074b6d 100644 --- a/GeoLib/IO/XmlIO/Rapid/RapidStnInterface.cpp +++ b/GeoLib/IO/XmlIO/Rapid/RapidStnInterface.cpp @@ -66,9 +66,13 @@ std::vector<GeoLib::Point*> *RapidStnInterface::readStationFile(const std::strin { std::string b(list_item->name()); if (b == "stations") + { RapidStnInterface::readStations(list_item, stations, fileName); + } if (b == "boreholes") + { RapidStnInterface::readStations(list_item, stations, fileName); + } } } @@ -144,18 +148,27 @@ void RapidStnInterface::readStations(const rapidxml::xml_node<>* station_root, s { double zVal(0.0); if (station_node->first_attribute("z")) + { zVal = strtod(station_node->first_attribute("z")->value(), nullptr); + } std::string station_name(""), sensor_data_file_name(""), bdate_str("0000-00-00"); double station_value(0.0), borehole_depth(0.0); if (station_node->first_node("name")) + { station_name = station_node->first_node("name")->value(); + } if (station_node->first_node("sensordata")) - sensor_data_file_name = station_node->first_node("sensordata")->value(); + { + sensor_data_file_name = + station_node->first_node("sensordata")->value(); + } if (station_node->first_node("value")) + { station_value = strtod(station_node->first_node("value")->value(), nullptr); + } /* add other station features here */ if (std::string(station_node->name()) == "station") @@ -169,16 +182,23 @@ void RapidStnInterface::readStations(const rapidxml::xml_node<>* station_root, s station_name); s->setStationValue(station_value); if (!sensor_data_file_name.empty()) - s->addSensorDataFromCSV(BaseLib::copyPathToFileName(sensor_data_file_name, file_name)); + { + s->addSensorDataFromCSV(BaseLib::copyPathToFileName( + sensor_data_file_name, file_name)); + } stations->push_back(s); } else if (std::string(station_node->name()) == "borehole") { if (station_node->first_node("bdepth")) + { borehole_depth = strtod( station_node->first_node("bdepth")->value(), nullptr); + } if (station_node->first_node("bdate")) + { bdate_str = station_node->first_node("bdate")->value(); + } /* add other borehole features here */ GeoLib::StationBorehole* s = @@ -194,7 +214,10 @@ void RapidStnInterface::readStations(const rapidxml::xml_node<>* station_root, s s->setStationValue(station_value); if (station_node->first_node("strat")) - RapidStnInterface::readStratigraphy(station_node->first_node("strat"), s); + { + RapidStnInterface::readStratigraphy( + station_node->first_node("strat"), s); + } stations->push_back(s); @@ -220,7 +243,9 @@ void RapidStnInterface::readStratigraphy( const rapidxml::xml_node<>* strat_root { std::string horizon_name("[NN]"); if (horizon_node->first_node("name")) + { horizon_name = horizon_node->first_node("name")->value(); + } /* add other horizon features here */ double depth( diff --git a/GeoLib/MinimalBoundingSphere.cpp b/GeoLib/MinimalBoundingSphere.cpp index 05568ca7146259a836414b4d085c44385032e6e1..8f0ebc47611ec3871cefc263e91647aa554184cf 100644 --- a/GeoLib/MinimalBoundingSphere.cpp +++ b/GeoLib/MinimalBoundingSphere.cpp @@ -68,9 +68,13 @@ MinimalBoundingSphere::MinimalBoundingSphere(MathLib::Point3d const& p, { MinimalBoundingSphere two_pnts_sphere; if (a.getLength() > b.getLength()) + { two_pnts_sphere = MinimalBoundingSphere(p,r); + } else - two_pnts_sphere = MinimalBoundingSphere(p,q); + { + two_pnts_sphere = MinimalBoundingSphere(p, q); + } _radius = two_pnts_sphere.getRadius(); _center = two_pnts_sphere.getCenter(); } diff --git a/GeoLib/OctTree-impl.h b/GeoLib/OctTree-impl.h index 3c29d9dddcd31c5149484f1a5a80d2dedc39539c..eeeaf203b926acd13ae3ae5c4320b31df8372408 100644 --- a/GeoLib/OctTree-impl.h +++ b/GeoLib/OctTree-impl.h @@ -40,7 +40,9 @@ OctTree<POINT, MAX_POINTS>* OctTree<POINT, MAX_POINTS>::createOctTree(T ll, T ur } } if (eps == 0.0) + { eps = std::numeric_limits<double>::epsilon(); + } for (std::size_t k(0); k<3; ++k) { if (ur[k] - ll[k] > 0.0) { ur[k] += (ur[k] - ll[k]) * 1e-6; @@ -55,7 +57,9 @@ template <typename POINT, std::size_t MAX_POINTS> OctTree<POINT, MAX_POINTS>::~OctTree() { for (auto c : _children) + { delete c; + } } template <typename POINT, std::size_t MAX_POINTS> @@ -91,7 +95,9 @@ bool OctTree<POINT, MAX_POINTS>::addPoint(POINT * pnt, POINT *& ret_pnt) return true; } if (ret_pnt != nullptr) + { return false; + } } } @@ -112,17 +118,22 @@ void OctTree<POINT, MAX_POINTS>::getPointsInRange(T const& min, T const& max, std::vector<POINT*> &pnts) const { if (_ur[0] < min[0] || _ur[1] < min[1] || _ur[2] < min[2]) + { return; + } if (max[0] < _ll[0] || max[1] < _ll[1] || max[2] < _ll[2]) + { return; + } if (_is_leaf) { for (auto p : _pnts) { - if (min[0] <= (*p)[0] && (*p)[0] < max[0] - && min[1] <= (*p)[1] && (*p)[1] < max[1] - && min[2] <= (*p)[2] && (*p)[2] < max[2]) + if (min[0] <= (*p)[0] && (*p)[0] < max[0] && min[1] <= (*p)[1] && + (*p)[1] < max[1] && min[2] <= (*p)[2] && (*p)[2] < max[2]) + { pnts.push_back(p); + } } } else { for (std::size_t k(0); k<8; k++) { @@ -154,7 +165,9 @@ bool OctTree<POINT, MAX_POINTS>::addPoint_(POINT * pnt, POINT *& ret_pnt) return true; } if (ret_pnt != nullptr) + { return false; + } } } @@ -172,7 +185,9 @@ template <typename POINT, std::size_t MAX_POINTS> bool OctTree<POINT, MAX_POINTS>::addPointToChild(POINT * pnt) { if (isOutside(pnt)) + { return false; + } if (_pnts.size() < MAX_POINTS) { _pnts.push_back(pnt); @@ -245,7 +260,9 @@ void OctTree<POINT, MAX_POINTS>::splitNode(POINT * pnt) // add the passed point pnt to the childs at first for (std::size_t k(0); k < 8; k++) { if (_children[k]->addPointToChild(pnt)) + { break; + } } // distribute points to sub quadtrees @@ -264,9 +281,13 @@ template <typename POINT, std::size_t MAX_POINTS> bool OctTree<POINT, MAX_POINTS>::isOutside(POINT * pnt) const { if ((*pnt)[0] < _ll[0] || (*pnt)[1] < _ll[1] || (*pnt)[2] < _ll[2]) + { return true; + } if ((*pnt)[0] >= _ur[0] || (*pnt)[1] >= _ur[1] || (*pnt)[2] >= _ur[2]) + { return true; + } return false; } } // end namespace GeoLib diff --git a/GeoLib/PointVec.cpp b/GeoLib/PointVec.cpp index 0f7611e9230cd9b613ba4deec8e531d177fc913f..4d7540ca4f65eea2e1aa0de7eb994b0ad5858ada 100644 --- a/GeoLib/PointVec.cpp +++ b/GeoLib/PointVec.cpp @@ -98,13 +98,17 @@ PointVec::PointVec( std::size_t cnt(0); for (cnt = 0; cnt < rm_pos.size() && _pnt_id_map[rm_pos[k]] > rm_pos[cnt];) + { cnt++; + } _pnt_id_map[rm_pos[k]] -= cnt; } // set value of the point id to the position of the point within _data_vec for (std::size_t k(0); k < _data_vec->size(); ++k) + { (*_data_vec)[k]->setID(k); + } if (number_of_all_input_pnts > _data_vec->size()) WARN("PointVec::PointVec(): there are %d double points.", @@ -116,7 +120,10 @@ PointVec::PointVec( // fetch the names from the name id map for (auto p : *_name_id_map) { - if (p.second >= _id_to_name_map.size()) continue; + if (p.second >= _id_to_name_map.size()) + { + continue; + } _id_to_name_map[p.second] = p.first; } } diff --git a/GeoLib/Polygon.cpp b/GeoLib/Polygon.cpp index a0c3276a81965807edff8ea0cdee2fd6ea3de5d1..f9c326c24d42d5321678aef1a39b2cc8faee1a80 100644 --- a/GeoLib/Polygon.cpp +++ b/GeoLib/Polygon.cpp @@ -27,7 +27,9 @@ Polygon::Polygon(const Polyline &ply, bool init) : Polyline(ply), _aabb(ply.getPointsVec(), ply._ply_pnt_ids) { if (init) - initialise (); + { + initialise(); + } _simple_polygon_list.push_back(this); } @@ -49,9 +51,13 @@ Polygon::~Polygon() { // remove polygons from list for (auto& polygon : _simple_polygon_list) + { // the first entry of the list can be a pointer the object itself if (polygon != this) + { delete polygon; + } + } } bool Polygon::initialise () @@ -69,9 +75,11 @@ bool Polygon::isPntInPolygon (GeoLib::Point const & pnt) const MathLib::Point3d const& min_aabb_pnt(_aabb.getMinPoint()); MathLib::Point3d const& max_aabb_pnt(_aabb.getMaxPoint()); - if (pnt[0] < min_aabb_pnt[0] || max_aabb_pnt[0] < pnt[0] || pnt[1] < min_aabb_pnt[1] || - max_aabb_pnt[1] < pnt[1]) + if (pnt[0] < min_aabb_pnt[0] || max_aabb_pnt[0] < pnt[0] || + pnt[1] < min_aabb_pnt[1] || max_aabb_pnt[1] < pnt[1]) + { return false; + } std::size_t n_intersections (0); GeoLib::Point s; @@ -97,14 +105,18 @@ bool Polygon::isPntInPolygon (GeoLib::Point const & pnt) const } } if (n_intersections % 2 == 1) + { return true; + } } else { for (auto it(_simple_polygon_list.begin()++); it != _simple_polygon_list.end(); ++it) { - if ((*it)->isPntInPolygon (pnt)) + if ((*it)->isPntInPolygon(pnt)) + { return true; + } } return false; } @@ -176,12 +188,20 @@ bool Polygon::containsSegment(GeoLib::LineSegment const& segment) const } // Check if all sub segments are within the polygon. - if (!isPntInPolygon(GeoLib::Point(0.5*(a[0]+s[0][0]), 0.5*(a[1]+s[0][1]), 0.5*(a[2]+s[0][2])))) + if (!isPntInPolygon(GeoLib::Point(0.5 * (a[0] + s[0][0]), + 0.5 * (a[1] + s[0][1]), + 0.5 * (a[2] + s[0][2])))) + { return false; + } const std::size_t n_sub_segs(s.size()-1); for (std::size_t k(0); k<n_sub_segs; k++) { - if (!isPntInPolygon(GeoLib::Point(0.5*(s[k][0]+s[k+1][0]), 0.5*(s[k][1]+s[k+1][1]), 0.5*(s[k][2]+s[k+1][2])))) - return false; + if (!isPntInPolygon(GeoLib::Point(0.5 * (s[k][0] + s[k + 1][0]), + 0.5 * (s[k][1] + s[k + 1][1]), + 0.5 * (s[k][2] + s[k + 1][2])))) + { + return false; + } } return isPntInPolygon(GeoLib::Point(0.5 * (s[0][0] + b[0]), 0.5 * (s[0][1] + b[1]), @@ -258,7 +278,9 @@ void Polygon::computeListOfSimplePolygons () splitPolygonAtIntersection (_simple_polygon_list.begin()); for (auto& polygon : _simple_polygon_list) + { polygon->initialise(); + } } EdgeType Polygon::getEdgeType (std::size_t k, GeoLib::Point const & pnt) const @@ -269,7 +291,9 @@ EdgeType Polygon::getEdgeType (std::size_t k, GeoLib::Point const & pnt) const const GeoLib::Point & v (*(getPoint(k))); const GeoLib::Point & w (*(getPoint(k + 1))); if (v[1] < pnt[1] && pnt[1] <= w[1]) + { return EdgeType::CROSSING; + } return EdgeType::INESSENTIAL; } @@ -277,7 +301,9 @@ EdgeType Polygon::getEdgeType (std::size_t k, GeoLib::Point const & pnt) const const GeoLib::Point & v (*(getPoint(k))); const GeoLib::Point & w (*(getPoint(k + 1))); if (w[1] < pnt[1] && pnt[1] <= v[1]) + { return EdgeType::CROSSING; + } return EdgeType::INESSENTIAL; } @@ -297,26 +323,37 @@ void Polygon::ensureCCWOrientation () std::size_t n_pnts (this->getNumberOfPoints() - 1); std::vector<GeoLib::Point*> tmp_polygon_pnts; for (std::size_t k(0); k < n_pnts; k++) - tmp_polygon_pnts.push_back (new GeoLib::Point (*(this->getPoint(k)))); + { + tmp_polygon_pnts.push_back(new GeoLib::Point(*(this->getPoint(k)))); + } // rotate copied points into x-y-plane GeoLib::rotatePointsToXY(tmp_polygon_pnts); - for (auto & tmp_polygon_pnt : tmp_polygon_pnts) - (*tmp_polygon_pnt)[2] = 0.0; // should be -= d but there are numerical errors + for (auto& tmp_polygon_pnt : tmp_polygon_pnts) + { + (*tmp_polygon_pnt)[2] = + 0.0; // should be -= d but there are numerical errors + } // *** get the left most upper point std::size_t min_x_max_y_idx (0); // for orientation check for (std::size_t k(0); k < n_pnts; k++) + { if ((*(tmp_polygon_pnts[k]))[0] <= (*(tmp_polygon_pnts[min_x_max_y_idx]))[0]) { - if ((*(tmp_polygon_pnts[k]))[0] < (*(tmp_polygon_pnts[min_x_max_y_idx]))[0]) + if ((*(tmp_polygon_pnts[k]))[0] < + (*(tmp_polygon_pnts[min_x_max_y_idx]))[0]) + { min_x_max_y_idx = k; + } else if ((*(tmp_polygon_pnts[k]))[1] > (*(tmp_polygon_pnts[min_x_max_y_idx]))[1]) + { min_x_max_y_idx = k; - + } } + } // *** determine orientation GeoLib::Orientation orient; if (0 < min_x_max_y_idx && min_x_max_y_idx < n_pnts - 2) @@ -347,11 +384,15 @@ void Polygon::ensureCCWOrientation () std::size_t tmp_n_pnts (n_pnts); tmp_n_pnts++; // include last point of polygon (which is identical to the first) for (std::size_t k(0); k < tmp_n_pnts / 2; k++) - std::swap (_ply_pnt_ids[k], _ply_pnt_ids[tmp_n_pnts - 1 - k]); + { + std::swap(_ply_pnt_ids[k], _ply_pnt_ids[tmp_n_pnts - 1 - k]); + } } for (std::size_t k(0); k < n_pnts; k++) + { delete tmp_polygon_pnts[k]; + } } #if __GNUC__ <= 4 && (__GNUC_MINOR__ < 9) @@ -367,7 +408,9 @@ void Polygon::splitPolygonAtIntersection( GeoLib::Point intersection_pnt; if (!GeoLib::lineSegmentsIntersect(*polygon_it, seg_it0, seg_it1, intersection_pnt)) + { return; + } std::size_t idx0(seg_it0.getSegmentNumber()); std::size_t idx1(seg_it1.getSegmentNumber()); @@ -378,24 +421,34 @@ void Polygon::splitPolygonAtIntersection( // split Polygon if (idx0 > idx1) - std::swap (idx0, idx1); + { + std::swap(idx0, idx1); + } GeoLib::Polyline polyline0{(*polygon_it)->getPointsVec()}; for (std::size_t k(0); k <= idx0; k++) + { polyline0.addPoint((*polygon_it)->getPointID(k)); + } polyline0.addPoint(intersection_pnt_id); for (std::size_t k(idx1 + 1); k < (*polygon_it)->getNumberOfPoints(); k++) + { polyline0.addPoint((*polygon_it)->getPointID(k)); + } GeoLib::Polyline polyline1{(*polygon_it)->getPointsVec()}; polyline1.addPoint(intersection_pnt_id); for (std::size_t k(idx0 + 1); k <= idx1; k++) + { polyline1.addPoint((*polygon_it)->getPointID(k)); + } polyline1.addPoint(intersection_pnt_id); // remove the polygon except the first if (*polygon_it != this) + { delete *polygon_it; + } // erase polygon_it and add two new polylines auto polygon1_it = _simple_polygon_list.insert( _simple_polygon_list.erase(polygon_it), new GeoLib::Polygon(polyline1)); @@ -420,29 +473,41 @@ void Polygon::splitPolygonAtPoint (const std::list<GeoLib::Polygon*>::iterator& BaseLib::quicksort (id_vec, 0, n, perm); for (std::size_t k(0); k < n - 1; k++) + { if (id_vec[k] == id_vec[k + 1]) { idx0 = perm[k]; idx1 = perm[k + 1]; if (idx0 > idx1) - std::swap (idx0, idx1); + { + std::swap(idx0, idx1); + } // create two closed polylines GeoLib::Polyline polyline0{*(*polygon_it)}; for (std::size_t j(0); j <= idx0; j++) + { polyline0.addPoint((*polygon_it)->getPointID(j)); + } for (std::size_t j(idx1 + 1); - j < (*polygon_it)->getNumberOfPoints(); j++) + j < (*polygon_it)->getNumberOfPoints(); + j++) + { polyline0.addPoint((*polygon_it)->getPointID(j)); + } GeoLib::Polyline polyline1{*(*polygon_it)}; for (std::size_t j(idx0); j <= idx1; j++) + { polyline1.addPoint((*polygon_it)->getPointID(j)); + } // remove the polygon except the first if (*polygon_it != this) + { delete *polygon_it; + } // erase polygon_it and add two new polygons auto polygon1_it = _simple_polygon_list.insert( _simple_polygon_list.erase(polygon_it), new Polygon(polyline1)); @@ -454,6 +519,7 @@ void Polygon::splitPolygonAtPoint (const std::list<GeoLib::Polygon*>::iterator& return; } + } } GeoLib::Polygon* createPolygonFromCircle (GeoLib::Point const& middle_pnt, double radius, @@ -473,7 +539,9 @@ GeoLib::Polygon* createPolygonFromCircle (GeoLib::Point const& middle_pnt, doubl // create polygon GeoLib::Polygon* polygon (new GeoLib::Polygon (pnts, false)); for (std::size_t k(0); k < resolution; k++) - polygon->addPoint (k + off_set); + { + polygon->addPoint(k + off_set); + } polygon->addPoint (off_set); return polygon; @@ -482,7 +550,9 @@ GeoLib::Polygon* createPolygonFromCircle (GeoLib::Point const& middle_pnt, doubl bool operator==(Polygon const& lhs, Polygon const& rhs) { if (lhs.getNumberOfPoints() != rhs.getNumberOfPoints()) + { return false; + } const std::size_t n(lhs.getNumberOfPoints()); const std::size_t start_pnt(lhs.getPointID(0)); @@ -498,7 +568,10 @@ bool operator==(Polygon const& lhs, Polygon const& rhs) } // case: start point not found in second polygon - if (nfound) return false; + if (nfound) + { + return false; + } // *** determine direction // opposite direction diff --git a/GeoLib/Polyline.cpp b/GeoLib/Polyline.cpp index f2ec9c673d1581ad8c890f9b087e2ef812e69112..c85f32f5a8a9004488e769774bb70c9b3a131eaf 100644 --- a/GeoLib/Polyline.cpp +++ b/GeoLib/Polyline.cpp @@ -39,7 +39,9 @@ void Polyline::write(std::ostream &os) const { std::size_t size(_ply_pnt_ids.size()); for (std::size_t k(0); k < size; k++) + { os << *(_ply_pnts[_ply_pnt_ids[k]]) << "\n"; + } } bool Polyline::addPoint(std::size_t pnt_id) @@ -49,7 +51,9 @@ bool Polyline::addPoint(std::size_t pnt_id) // don't insert point if this would result in identical IDs for two adjacent points if (n_pnts > 0 && _ply_pnt_ids.back() == pnt_id) + { return false; + } _ply_pnt_ids.push_back(pnt_id); @@ -59,7 +63,9 @@ bool Polyline::addPoint(std::size_t pnt_id) *_ply_pnts[_ply_pnt_ids[n_pnts-1]], *_ply_pnts[pnt_id]))); double dist_until_now(0.0); if (n_pnts > 1) + { dist_until_now = _length[n_pnts - 1]; + } _length.push_back(dist_until_now + act_dist); } @@ -105,7 +111,9 @@ bool Polyline::insertPoint(std::size_t pos, std::size_t pnt_id) _length.insert(_length.begin() + 1, act_dist); const std::size_t s(_length.size()); for (std::size_t k(2); k < s; k++) + { _length[k] += _length[1]; + } } else { if (pos == _ply_pnt_ids.size() - 1) { // insert at last position @@ -114,7 +122,9 @@ bool Polyline::insertPoint(std::size_t pos, std::size_t pnt_id) *_ply_pnts[pnt_id]))); double dist_until_now (0.0); if (_ply_pnt_ids.size() > 2) + { dist_until_now = _length[_ply_pnt_ids.size() - 2]; + } _length.insert(_length.begin() + pos_dt, dist_until_now + act_dist); @@ -122,7 +132,9 @@ bool Polyline::insertPoint(std::size_t pos, std::size_t pnt_id) // insert at arbitrary position within the vector double dist_until_now (0.0); if (pos > 1) + { dist_until_now = _length[pos - 1]; + } double len_seg0(std::sqrt(MathLib::sqrDist( *_ply_pnts[_ply_pnt_ids[pos - 1]], *_ply_pnts[pnt_id]))); @@ -136,7 +148,9 @@ bool Polyline::insertPoint(std::size_t pos, std::size_t pnt_id) _length.insert(it1, _length[pos] + len_seg1); for (it1 = _length.begin() + pos_dt + 2; it1 != _length.end(); ++it1) + { *it1 += update_dist; + } } } } @@ -146,7 +160,9 @@ bool Polyline::insertPoint(std::size_t pos, std::size_t pnt_id) void Polyline::removePoint(std::size_t pos) { if (pos >= _ply_pnt_ids.size()) + { return; + } auto const pos_dt( static_cast<std::vector<std::size_t>::difference_type>(pos)); @@ -162,7 +178,9 @@ void Polyline::removePoint(std::size_t pos) if (pos == 0) { double seg_length(_length[0]); for (std::size_t k(0); k < n_ply_pnt_ids; k++) + { _length[k] = _length[k + 1] - seg_length; + } _length.pop_back(); } else { const double len_seg0(_length[pos] - _length[pos - 1]); @@ -173,7 +191,9 @@ void Polyline::removePoint(std::size_t pos) double seg_length_diff(len_new_seg - len_seg0 - len_seg1); for (std::size_t k(pos); k < n_ply_pnt_ids; k++) + { _length[k] += seg_length_diff; + } } } @@ -190,7 +210,9 @@ std::size_t Polyline::getNumberOfSegments() const bool Polyline::isClosed() const { if (_ply_pnt_ids.size() < 3) + { return false; + } return _ply_pnt_ids.front() == _ply_pnt_ids.back(); } @@ -199,7 +221,9 @@ bool Polyline::isCoplanar() const { std::size_t const n_points (_ply_pnt_ids.size()); if (n_points < 4) + { return true; + } GeoLib::Point const& p0 (*this->getPoint(0)); GeoLib::Point const& p1 (*this->getPoint(1)); @@ -273,7 +297,9 @@ Polyline* Polyline::constructPolylineFromSegments(const std::vector<Polyline*> & std::vector<Polyline*> local_ply_vec; for (std::size_t i = 1; i < nLines; i++) + { local_ply_vec.push_back(ply_vec[i]); + } while (!local_ply_vec.empty()) { @@ -291,11 +317,15 @@ Polyline* Polyline::constructPolylineFromSegments(const std::vector<Polyline*> & { auto* tmp = new Polyline((*it)->getPointsVec()); for (std::size_t k = 0; k < nPoints; k++) + { tmp->addPoint((*it)->getPointID(nPoints - k - 1)); + } std::size_t new_ply_size(new_ply->getNumberOfPoints()); for (std::size_t k = 1; k < new_ply_size; k++) + { tmp->addPoint(new_ply->getPointID(k)); + } delete new_ply; new_ply = tmp; ply_found = true; @@ -307,7 +337,9 @@ Polyline* Polyline::constructPolylineFromSegments(const std::vector<Polyline*> & auto* tmp = new Polyline(**it); std::size_t new_ply_size(new_ply->getNumberOfPoints()); for (std::size_t k = 1; k < new_ply_size; k++) + { tmp->addPoint(new_ply->getPointID(k)); + } delete new_ply; new_ply = tmp; ply_found = true; @@ -320,7 +352,9 @@ Polyline* Polyline::constructPolylineFromSegments(const std::vector<Polyline*> & (*it)->getPointID(0), prox)) { for (std::size_t k = 1; k < nPoints; k++) + { new_ply->addPoint((*it)->getPointID(k)); + } ply_found = true; } //else if (new_ply->getPointID(new_ply->getNumberOfPoints()-1) == (*it)->getPointID(nPoints-1)) @@ -331,7 +365,9 @@ Polyline* Polyline::constructPolylineFromSegments(const std::vector<Polyline*> & (*it)->getPointID(nPoints - 1), prox)) { for (std::size_t k = 1; k < nPoints; k++) + { new_ply->addPoint((*it)->getPointID(nPoints - k - 1)); + } ply_found = true; } if (ply_found) @@ -377,20 +413,31 @@ Location Polyline::getLocationOfPoint (std::size_t k, GeoLib::Point const & pnt) long double det_2x2 (a[0] * b[1] - a[1] * b[0]); if (det_2x2 > std::numeric_limits<double>::epsilon()) + { return Location::LEFT; + } if (std::numeric_limits<double>::epsilon() < std::abs(det_2x2)) + { return Location::RIGHT; + } if (a[0] * b[0] < 0.0 || a[1] * b[1] < 0.0) + { return Location::BEHIND; + } if (a[0] * a[0] + a[1] * a[1] < b[0] * b[0] + b[1] * b[1]) + { return Location::BEYOND; - if (MathLib::sqrDist (pnt, - *_ply_pnts[_ply_pnt_ids[k]]) < pow(std::numeric_limits<double>::epsilon(),2)) + } + if (MathLib::sqrDist(pnt, *_ply_pnts[_ply_pnt_ids[k]]) < + pow(std::numeric_limits<double>::epsilon(), 2)) + { return Location::SOURCE; - if (MathLib::sqrDist (pnt, - *_ply_pnts[_ply_pnt_ids[k + 1]]) < + } + if (MathLib::sqrDist(pnt, *_ply_pnts[_ply_pnt_ids[k + 1]]) < std::sqrt(std::numeric_limits<double>::epsilon())) + { return Location::DESTINATION; + } return Location::BETWEEN; } @@ -400,8 +447,11 @@ void Polyline::updatePointIDs(const std::vector<std::size_t> &pnt_ids) { if (pnt_ids[*it] != *it) { - if (it!=this->_ply_pnt_ids.begin() && (pnt_ids[*it] == pnt_ids[*(it-1)])) + if (it != this->_ply_pnt_ids.begin() && + (pnt_ids[*it] == pnt_ids[*(it - 1)])) + { it = this->_ply_pnt_ids.erase(it); + } else { *it = pnt_ids[*it]; @@ -409,7 +459,9 @@ void Polyline::updatePointIDs(const std::vector<std::size_t> &pnt_ids) } } else + { ++it; + } } } @@ -440,8 +492,10 @@ double Polyline::getDistanceAlongPolyline(const MathLib::Point3d& pnt, } } // end line segment loop - if (! found) + if (!found) + { dist = -1.0; + } return dist; } @@ -460,7 +514,9 @@ Polyline::SegmentIterator& Polyline::SegmentIterator::operator=( SegmentIterator const& rhs) { if (&rhs == this) + { return *this; + } _polyline = rhs._polyline; _segment_number = rhs._segment_number; @@ -510,7 +566,9 @@ Polyline::SegmentIterator& Polyline::SegmentIterator::operator+=( static_cast<std::vector<GeoLib::Point>::size_type>(n); } if (_segment_number > _polyline->getNumberOfSegments()) + { OGS_FATAL(""); + } return *this; } @@ -533,7 +591,9 @@ Polyline::SegmentIterator& Polyline::SegmentIterator::operator-=( static_cast<std::vector<GeoLib::Point>::size_type>(-n); } if (_segment_number > _polyline->getNumberOfSegments()) + { OGS_FATAL(""); + } return *this; } @@ -559,16 +619,22 @@ bool containsEdge (const Polyline& ply, std::size_t id0, std::size_t id1) return false; } if (id0 > id1) - std::swap (id0,id1); + { + std::swap(id0, id1); + } const std::size_t n (ply.getNumberOfPoints() - 1); for (std::size_t k(0); k < n; k++) { std::size_t ply_pnt0 (ply.getPointID (k)); std::size_t ply_pnt1 (ply.getPointID (k + 1)); if (ply_pnt0 > ply_pnt1) - std::swap (ply_pnt0, ply_pnt1); + { + std::swap(ply_pnt0, ply_pnt1); + } if (ply_pnt0 == id0 && ply_pnt1 == id1) + { return true; + } } return false; } @@ -576,12 +642,18 @@ bool containsEdge (const Polyline& ply, std::size_t id0, std::size_t id1) bool operator==(Polyline const& lhs, Polyline const& rhs) { if (lhs.getNumberOfPoints() != rhs.getNumberOfPoints()) + { return false; + } const std::size_t n(lhs.getNumberOfPoints()); for (std::size_t k(0); k < n; k++) + { if (lhs.getPointID(k) != rhs.getPointID(k)) + { return false; + } + } return true; } @@ -592,7 +664,9 @@ bool pointsAreIdentical(const std::vector<Point*> &pnt_vec, double prox) { if (i == j) + { return true; + } return MathLib::sqrDist(*pnt_vec[i], *pnt_vec[j]) < prox; } } // end namespace GeoLib diff --git a/GeoLib/QuadTree.h b/GeoLib/QuadTree.h index 3583aab1d637d733f51f9a6e74ffea9798a428fa..650e39748b17192f049e4b508a83859fe33d2384 100644 --- a/GeoLib/QuadTree.h +++ b/GeoLib/QuadTree.h @@ -61,12 +61,18 @@ public: // init children for (auto& child : _children) + { child = nullptr; + } if ((_ur[0] - _ll[0]) > (_ur[1] - _ll[1])) + { _ur[1] = _ll[1] + _ur[0] - _ll[0]; + } else + { _ur[0] = _ll[0] + _ur[1] - _ll[1]; + } DBUG("QuadTree(): lower left: (%f,%f,%f), upper right: (%f,%f,%f), depth: %d", _ll[0], _ll[1], _ll[2], _ur[0], _ur[1], _ur[2], _depth); } @@ -90,16 +96,30 @@ public: */ bool addPoint (POINT const* pnt) { - if ((*pnt)[0] < _ll[0]) return false; - if ((*pnt)[0] >= _ur[0]) return false; - if ((*pnt)[1] < _ll[1]) return false; - if ((*pnt)[1] >= _ur[1]) return false; + if ((*pnt)[0] < _ll[0]) + { + return false; + } + if ((*pnt)[0] >= _ur[0]) + { + return false; + } + if ((*pnt)[1] < _ll[1]) + { + return false; + } + if ((*pnt)[1] >= _ur[1]) + { + return false; + } if (!_is_leaf) { for (auto& child : _children) { if (child->addPoint(pnt)) + { return true; + } } return false; } @@ -111,15 +131,23 @@ public: const double v1((*(_pnts[k]))[1] - (*pnt)[1]); const double sqr_dist (v0*v0 + v1*v1); if (sqr_dist < std::numeric_limits<double>::epsilon()) + { pnt_in_quadtree = true; + } } if (!pnt_in_quadtree) + { _pnts.push_back (pnt); + } else + { return false; + } - if (_pnts.size () > _max_points_per_leaf) - splitNode (); + if (_pnts.size() > _max_points_per_leaf) + { + splitNode(); + } return true; } @@ -141,6 +169,7 @@ public: leaf_list.pop_front (); if (node->isLeaf()) + { if (needToRefine (node)) { node->splitNode (); @@ -152,32 +181,56 @@ public: // check if north neighbor has to be refined QuadTree<POINT>* north_neighbor (node->getNorthNeighbor()); if (north_neighbor != nullptr) - if (north_neighbor->getDepth() < node->getDepth ()) + { + if (north_neighbor->getDepth() < node->getDepth()) + { if (north_neighbor->isLeaf()) - leaf_list.push_back (north_neighbor); + { + leaf_list.push_back(north_neighbor); + } + } + } // check if west neighbor has to be refined QuadTree<POINT>* west_neighbor (node->getWestNeighbor()); if (west_neighbor != nullptr) - if (west_neighbor->getDepth() < node->getDepth ()) + { + if (west_neighbor->getDepth() < node->getDepth()) + { if (west_neighbor->isLeaf()) - leaf_list.push_back (west_neighbor); + { + leaf_list.push_back(west_neighbor); + } + } + } // check if south neighbor has to be refined QuadTree<POINT>* south_neighbor (node->getSouthNeighbor()); if (south_neighbor != nullptr) - if (south_neighbor->getDepth() < node->getDepth ()) + { + if (south_neighbor->getDepth() < node->getDepth()) + { if (south_neighbor->isLeaf()) - leaf_list.push_back (south_neighbor); + { + leaf_list.push_back(south_neighbor); + } + } + } // check if east neighbor has to be refined QuadTree<POINT>* east_neighbor (node->getEastNeighbor()); if (east_neighbor != nullptr) - if (east_neighbor->getDepth() < node->getDepth ()) + { + if (east_neighbor->getDepth() < node->getDepth()) + { if (east_neighbor->isLeaf()) - leaf_list.push_back (east_neighbor); - + { + leaf_list.push_back(east_neighbor); + } + } + } } + } } } @@ -188,10 +241,16 @@ public: void getLeafs (std::list<QuadTree<POINT>*>& leaf_list) { if (_is_leaf) + { leaf_list.push_back (this); + } else + { for (auto& child : _children) + { child->getLeafs(leaf_list); + } + } } const std::vector<POINT const*>& getPoints () const { return _pnts; } @@ -213,17 +272,27 @@ public: { if (pnt[0] <= 0.5 * (_ur[0] + _ll[0])) // WEST { - if (pnt[1] <= 0.5 * (_ur[1] + _ll[1])) // SOUTH + if (pnt[1] <= 0.5 * (_ur[1] + _ll[1])) + { // SOUTH _children[static_cast<int>(Quadrant::SW)]->getLeaf (pnt, ll, ur); - else // NORTH - _children[static_cast<int>(Quadrant::NW)]->getLeaf (pnt, ll, ur); + } + else + { // NORTH + _children[static_cast<int>(Quadrant::NW)]->getLeaf( + pnt, ll, ur); + } } else // EAST { - if (pnt[1] <= 0.5 * (_ur[1] + _ll[1])) // SOUTH + if (pnt[1] <= 0.5 * (_ur[1] + _ll[1])) + { // SOUTH _children[static_cast<int>(Quadrant::SE)]->getLeaf (pnt, ll, ur); - else // NORTH - _children[static_cast<int>(Quadrant::NE)]->getLeaf (pnt, ll, ur); + } + else + { // NORTH + _children[static_cast<int>(Quadrant::NE)]->getLeaf( + pnt, ll, ur); + } } } } @@ -246,7 +315,9 @@ public: void getMaxDepth (std::size_t &max_depth) const { if (max_depth < _depth) + { max_depth = _depth; + } for (auto& child : _children) { @@ -273,94 +344,145 @@ private: bool isChild (QuadTree<POINT> const* const tree, Quadrant quadrant) const { - if (_children[static_cast<int>(quadrant)] == tree) return true; + if (_children[static_cast<int>(quadrant)] == tree) + { + return true; + } return false; } QuadTree<POINT>* getNorthNeighbor () const { - if (this->_father == nullptr) // root of QuadTree + if (this->_father == nullptr) + { // root of QuadTree return nullptr; + } - if (this->_father->isChild (this, Quadrant::SW)) - return this->_father->getChild (Quadrant::NW); - if (this->_father->isChild (this, Quadrant::SE)) - return this->_father->getChild (Quadrant::NE); + if (this->_father->isChild(this, Quadrant::SW)) + { + return this->_father->getChild(Quadrant::NW); + } + if (this->_father->isChild(this, Quadrant::SE)) + { + return this->_father->getChild(Quadrant::NE); + } QuadTree<POINT>* north_neighbor (this->_father->getNorthNeighbor ()); if (north_neighbor == nullptr) + { return nullptr; + } if (north_neighbor->isLeaf()) + { return north_neighbor; + } - if (this->_father->isChild (this, Quadrant::NW)) - return north_neighbor->getChild (Quadrant::SW); + if (this->_father->isChild(this, Quadrant::NW)) + { + return north_neighbor->getChild(Quadrant::SW); + } return north_neighbor->getChild(Quadrant::SE); } QuadTree<POINT>* getSouthNeighbor () const { - if (this->_father == nullptr) // root of QuadTree + if (this->_father == nullptr) + { // root of QuadTree return nullptr; + } - if (this->_father->isChild (this, Quadrant::NW)) - return this->_father->getChild (Quadrant::SW); - if (this->_father->isChild (this, Quadrant::NE)) - return this->_father->getChild (Quadrant::SE); + if (this->_father->isChild(this, Quadrant::NW)) + { + return this->_father->getChild(Quadrant::SW); + } + if (this->_father->isChild(this, Quadrant::NE)) + { + return this->_father->getChild(Quadrant::SE); + } QuadTree<POINT>* south_neighbor (this->_father->getSouthNeighbor ()); if (south_neighbor == nullptr) + { return nullptr; + } if (south_neighbor->isLeaf()) + { return south_neighbor; + } - if (this->_father->isChild (this, Quadrant::SW)) - return south_neighbor->getChild (Quadrant::NW); + if (this->_father->isChild(this, Quadrant::SW)) + { + return south_neighbor->getChild(Quadrant::NW); + } return south_neighbor->getChild(Quadrant::NE); } QuadTree<POINT>* getEastNeighbor () const { - if (this->_father == nullptr) // root of QuadTree + if (this->_father == nullptr) + { // root of QuadTree return nullptr; + } - if (this->_father->isChild (this, Quadrant::NW)) - return this->_father->getChild (Quadrant::NE); - if (this->_father->isChild (this, Quadrant::SW)) - return this->_father->getChild (Quadrant::SE); + if (this->_father->isChild(this, Quadrant::NW)) + { + return this->_father->getChild(Quadrant::NE); + } + if (this->_father->isChild(this, Quadrant::SW)) + { + return this->_father->getChild(Quadrant::SE); + } QuadTree<POINT>* east_neighbor (this->_father->getEastNeighbor ()); if (east_neighbor == nullptr) + { return nullptr; + } if (east_neighbor->isLeaf()) + { return east_neighbor; + } - if (this->_father->isChild (this, Quadrant::SE)) - return east_neighbor->getChild (Quadrant::SW); + if (this->_father->isChild(this, Quadrant::SE)) + { + return east_neighbor->getChild(Quadrant::SW); + } return east_neighbor->getChild(Quadrant::NW); } QuadTree<POINT>* getWestNeighbor () const { - if (this->_father == nullptr) // root of QuadTree + if (this->_father == nullptr) + { // root of QuadTree return nullptr; + } - if (this->_father->isChild (this, Quadrant::NE)) - return this->_father->getChild (Quadrant::NW); - if (this->_father->isChild (this, Quadrant::SE)) - return this->_father->getChild (Quadrant::SW); + if (this->_father->isChild(this, Quadrant::NE)) + { + return this->_father->getChild(Quadrant::NW); + } + if (this->_father->isChild(this, Quadrant::SE)) + { + return this->_father->getChild(Quadrant::SW); + } QuadTree<POINT>* west_neighbor (this->_father->getWestNeighbor ()); if (west_neighbor == nullptr) + { return nullptr; + } if (west_neighbor->isLeaf()) + { return west_neighbor; + } - if (this->_father->isChild (this, Quadrant::SW)) - return west_neighbor->getChild (Quadrant::SE); + if (this->_father->isChild(this, Quadrant::SW)) + { + return west_neighbor->getChild(Quadrant::SE); + } return west_neighbor->getChild(Quadrant::NE); } @@ -388,7 +510,9 @@ private: { // init children for (auto& child : _children) + { child = nullptr; + } } void splitNode () @@ -417,8 +541,12 @@ private: for (std::size_t j(0); j < _pnts.size(); j++) { bool nfound(true); for (std::size_t k(0); k < 4 && nfound; k++) - if (_children[k]->addPoint(_pnts[j])) nfound = false; - + { + if (_children[k]->addPoint(_pnts[j])) + { + nfound = false; + } + } } _pnts.clear(); _is_leaf = false; @@ -430,52 +558,76 @@ private: if (north_neighbor != nullptr) { if (north_neighbor->getDepth() == node->getDepth()) + { if (!north_neighbor->isLeaf ()) { if (!(north_neighbor->getChild(Quadrant::SW))->isLeaf()) + { return true; + } if (!(north_neighbor->getChild(Quadrant::SE))->isLeaf()) + { return true; + } } + } } QuadTree<POINT>* west_neighbor (node->getWestNeighbor ()); if (west_neighbor != nullptr) { if (west_neighbor->getDepth() == node->getDepth()) + { if (!west_neighbor->isLeaf ()) { if (!(west_neighbor->getChild(Quadrant::SE))->isLeaf()) + { return true; + } if (!(west_neighbor->getChild(Quadrant::NE))->isLeaf()) + { return true; + } } + } } QuadTree<POINT>* south_neighbor (node->getSouthNeighbor ()); if (south_neighbor != nullptr) { if (south_neighbor->getDepth() == node->getDepth()) + { if (!south_neighbor->isLeaf()) { if (!(south_neighbor->getChild(Quadrant::NE))->isLeaf()) + { return true; + } if (!(south_neighbor->getChild(Quadrant::NW))->isLeaf()) + { return true; + } } + } } QuadTree<POINT>* east_neighbor (node->getEastNeighbor ()); if (east_neighbor != nullptr) { if (east_neighbor->getDepth() == node->getDepth()) + { if (!east_neighbor->isLeaf ()) { if (!(east_neighbor->getChild(Quadrant::NW))->isLeaf()) + { return true; + } if (!(east_neighbor->getChild(Quadrant::SW))->isLeaf()) + { return true; + } } + } } return false; } diff --git a/GeoLib/Raster.cpp b/GeoLib/Raster.cpp index a30a7f9afaadfcc9af6ef4e297641438482c34e1..04d06c1b9d68c4553cae724bd96560333f80528a 100644 --- a/GeoLib/Raster.cpp +++ b/GeoLib/Raster.cpp @@ -142,15 +142,18 @@ double Raster::interpolateValueAtPoint(MathLib::Point3d const& pnt) const { // check if neighbour pixel is still on the raster, otherwise substitute // a no data value. This also allows the cast to unsigned type. - if ( (xIdx + x_nb[j]) < 0 || - (yIdx + y_nb[j]) < 0 || - (xIdx + x_nb[j]) > (_header.n_cols-1) || - (yIdx + y_nb[j]) > (_header.n_rows-1) ) + if ((xIdx + x_nb[j]) < 0 || (yIdx + y_nb[j]) < 0 || + (xIdx + x_nb[j]) > (_header.n_cols - 1) || + (yIdx + y_nb[j]) > (_header.n_rows - 1)) + { pix_val[j] = _header.no_data; + } else - pix_val[j] = _raster_data[ - static_cast<std::size_t>(yIdx + y_nb[j]) * _header.n_cols + - static_cast<std::size_t>(xIdx + x_nb[j])]; + { + pix_val[j] = _raster_data[static_cast<std::size_t>(yIdx + y_nb[j]) * + _header.n_cols + + static_cast<std::size_t>(xIdx + x_nb[j])]; + } // remove no data values if (std::fabs(pix_val[j] - _header.no_data) < std::numeric_limits<double>::epsilon()) @@ -163,8 +166,10 @@ double Raster::interpolateValueAtPoint(MathLib::Point3d const& pnt) const // adjust weights if necessary if (no_data_count > 0) { - if (no_data_count == 4) // if there is absolutely no data just use the default value + if (no_data_count == 4) + { // if there is absolutely no data just use the default value return _header.no_data; + } const double norm = 1.0 / (weight[0]+weight[1]+weight[2]+weight[3]); std::for_each(weight.begin(), weight.end(), [&norm](double &val){val*=norm;}); diff --git a/GeoLib/SensorData.cpp b/GeoLib/SensorData.cpp index 4961fac8faa6ee664737cf1e3f124fe0caca04f8..39fb1894248ab5cef7345c97049a600877d71bad 100644 --- a/GeoLib/SensorData.cpp +++ b/GeoLib/SensorData.cpp @@ -46,7 +46,9 @@ SensorData::SensorData(std::size_t first_timestep, std::size_t last_timestep, st SensorData::~SensorData() { for (std::vector<float>* vec : _data_vecs) + { delete vec; + } } @@ -79,7 +81,9 @@ const std::vector<float>* SensorData::getTimeSeries(SensorDataType time_series_n for (std::size_t i=0; i<_vec_names.size(); i++) { if (time_series_name == _vec_names[i]) + { return _data_vecs[i]; + } } ERR("Error in SensorData::getTimeSeries() - Time series '%d' not found.", time_series_name); @@ -91,7 +95,9 @@ std::string SensorData::getDataUnit(SensorDataType time_series_name) const for (std::size_t i=0; i<_vec_names.size(); i++) { if (time_series_name == _vec_names[i]) + { return _data_unit_string[i]; + } } ERR("Error in SensorData::getDataUnit() - Time series '%d' not found.", time_series_name); @@ -116,8 +122,10 @@ int SensorData::readDataFromFile(const std::string &file_name) std::list<std::string>::const_iterator it (fields.begin()); std::size_t nFields = fields.size(); - if (nFields<2) + if (nFields < 2) + { return 0; + } std::size_t nDataArrays(nFields-1); @@ -141,12 +149,16 @@ int SensorData::readDataFromFile(const std::string &file_name) std::size_t current_time_step = (pos == std::string::npos) ? atoi((it++)->c_str()) : BaseLib::strDate2int(*it++); this->_time_steps.push_back(current_time_step); - for (std::size_t i=0; i<nDataArrays; i++) + for (std::size_t i = 0; i < nDataArrays; i++) + { this->_data_vecs[i]->push_back( static_cast<float>(strtod((it++)->c_str(), nullptr))); + } } else + { return 0; + } } in.close(); @@ -159,11 +171,18 @@ int SensorData::readDataFromFile(const std::string &file_name) std::string SensorData::convertSensorDataType2String(SensorDataType t) { - if (SensorDataType::EVAPORATION == t) return "Evaporation"; + if (SensorDataType::EVAPORATION == t) + { + return "Evaporation"; + } if (SensorDataType::PRECIPITATION == t) + { return "Precipitation"; + } if (SensorDataType::TEMPERATURE == t) + { return "Temperature"; + } // pls leave this as last choice return "Unknown"; } @@ -171,11 +190,17 @@ std::string SensorData::convertSensorDataType2String(SensorDataType t) SensorDataType SensorData::convertString2SensorDataType(const std::string &s) { if (s == "Evaporation" || s == "EVAPORATION") + { return SensorDataType::EVAPORATION; + } if (s == "Precipitation" || s == "PRECIPITATION") + { return SensorDataType::PRECIPITATION; + } if (s == "Temperature" || s == "TEMPERATURE") + { return SensorDataType::TEMPERATURE; + } return SensorDataType::OTHER; } diff --git a/GeoLib/SimplePolygonTree.h b/GeoLib/SimplePolygonTree.h index 6847716ee40db2d713637430283c8e352a445f34..893416e599e271f325092a2c959c3945174d6cf5 100644 --- a/GeoLib/SimplePolygonTree.h +++ b/GeoLib/SimplePolygonTree.h @@ -95,7 +95,9 @@ void createPolygonTrees (std::list<POLYGONTREETYPE*>& list_of_simple_polygon_hie ++it1; // skip test if it1 points to the end after increment if (it1 == list_of_simple_polygon_hierarchies.end()) + { break; + } } if ((*it0)->isPolygonInside(*it1)) { (*it0)->insertSimplePolygonTree(*it1); diff --git a/GeoLib/Station.cpp b/GeoLib/Station.cpp index d2c53953c003481396169f48e67732b179c9c2cd..ecd98fd41b894a0b81d07c8fb40bd7ee83ed094a 100644 --- a/GeoLib/Station.cpp +++ b/GeoLib/Station.cpp @@ -61,7 +61,10 @@ Station* Station::createStation(const std::string & line) (*station)[0] = std::strtod((BaseLib::replaceString(",", ".", *(++it))).c_str(), nullptr); (*station)[1] = std::strtod((BaseLib::replaceString(",", ".", *(++it))).c_str(), nullptr); if (++it != fields.end()) - (*station)[2] = std::strtod((BaseLib::replaceString(",", ".", *it)).c_str(), nullptr); + { + (*station)[2] = std::strtod( + (BaseLib::replaceString(",", ".", *it)).c_str(), nullptr); + } } else { diff --git a/GeoLib/StationBorehole.cpp b/GeoLib/StationBorehole.cpp index b3ff212f945f0cdc3dd6a910df1e4584bd85b541..ceb00bb4d93b36efd1df093fcea19d587ccb0ee1 100644 --- a/GeoLib/StationBorehole.cpp +++ b/GeoLib/StationBorehole.cpp @@ -45,15 +45,21 @@ StationBorehole::~StationBorehole(void) // deletes profile vector of borehole, starting at layer 1 // the first point is NOT deleted as it points to the station object itself for (std::size_t k(1); k < _profilePntVec.size(); k++) + { delete _profilePntVec[k]; + } } int StationBorehole::find(const std::string &str) { std::size_t size = _soilName.size(); for (std::size_t i = 0; i < size; i++) + { if (_soilName[i].find(str) == 0) + { return 1; + } + } return 0; } @@ -87,7 +93,9 @@ int StationBorehole::addStratigraphy(const std::string &path, StationBorehole* b { std::size_t size = data.size(); for (std::size_t i = 0; i < size; i++) + { addLayer(data[i], borehole); + } // check if a layer is missing // size = borehole->_soilName.size(); @@ -106,7 +114,9 @@ int StationBorehole::addStratigraphy(const std::string &path, StationBorehole* b // } } else + { borehole->addSoilLayer(borehole->getDepth(), "depth"); + } return 1; } @@ -176,8 +186,12 @@ int StationBorehole::addStratigraphies(const std::string &path, std::vector<Poin { name = static_cast<StationBorehole*>((*boreholes)[it])->_name; if (fields.front() != name) + { if (it < boreholes->size() - 1) + { it++; + } + } fields.pop_front(); //the method just assumes that layers are read in correct order @@ -198,7 +212,9 @@ int StationBorehole::addStratigraphies(const std::string &path, std::vector<Poin } } else + { createSurrogateStratigraphies(boreholes); + } return 1; } @@ -221,7 +237,9 @@ StationBorehole* StationBorehole::createStation(const std::string &line) borehole->_depth = strtod(BaseLib::replaceString(",", ".", fields.front()).c_str(), nullptr); fields.pop_front(); if (fields.empty()) + { borehole->_date = 0; + } else { borehole->_date = BaseLib::strDate2int(fields.front()); @@ -251,7 +269,9 @@ StationBorehole* StationBorehole::createStation(const std::string &name, (*station)[2] = z; station->_depth = depth; if (date != "0000-00-00") - station->_date = BaseLib::xmlDate2int(date); + { + station->_date = BaseLib::xmlDate2int(date); + } return station; } @@ -283,7 +303,9 @@ void StationBorehole::addSoilLayer ( double thickness, const std::string &soil_n // KR - Bode if (_profilePntVec.empty()) - addSoilLayer ((*this)[0], (*this)[1], (*this)[2], ""); + { + addSoilLayer((*this)[0], (*this)[1], (*this)[2], ""); + } std::size_t idx (_profilePntVec.size()); double x((*_profilePntVec[idx - 1])[0]); diff --git a/GeoLib/Surface.cpp b/GeoLib/Surface.cpp index b56ccf24096eabd4c0f224b57590d365d180315d..83e1ed6bcab91a4f901e06b4bc96efbe96723ea1 100644 --- a/GeoLib/Surface.cpp +++ b/GeoLib/Surface.cpp @@ -48,8 +48,10 @@ Surface::Surface(Surface const& src) Surface::~Surface() { - for (auto & _sfc_triangle : _sfc_triangles) + for (auto& _sfc_triangle : _sfc_triangles) + { delete _sfc_triangle; + } } void Surface::addTriangle(std::size_t pnt_a, @@ -61,7 +63,9 @@ void Surface::addTriangle(std::size_t pnt_a, // Check if two points of the triangle have identical IDs if (pnt_a == pnt_b || pnt_a == pnt_c || pnt_b == pnt_c) + { return; + } // Adding a new triangle invalides the surface grid. _surface_grid.reset(); diff --git a/GeoLib/SurfaceGrid.cpp b/GeoLib/SurfaceGrid.cpp index 8bf219b1f4a46b1734465b504010e5add5bcdcb9..00849d4013042f353c0809cc7745039f544e9c8c 100644 --- a/GeoLib/SurfaceGrid.cpp +++ b/GeoLib/SurfaceGrid.cpp @@ -64,9 +64,13 @@ SurfaceGrid::SurfaceGrid(Surface const*const sfc) : const std::size_t n_tris_per_cell(5); std::bitset<3> dim; // all bits are set to zero. - for (std::size_t k(0); k<3; ++k) + for (std::size_t k(0); k < 3; ++k) + { if (std::abs(delta[k]) >= std::numeric_limits<double>::epsilon()) + { dim[k] = true; + } + } // *** condition: n_tris / n_cells < n_tris_per_cell // where n_cells = _n_steps[0] * _n_steps[1] * _n_steps[2] @@ -137,15 +141,21 @@ bool SurfaceGrid::sortTriangleInGridCells(Triangle const*const triangle) boost::optional<std::array<std::size_t, 3> const> c_p0( getGridCellCoordinates(*(triangle->getPoint(0)))); if (!c_p0) + { return false; + } boost::optional<std::array<std::size_t, 3> const> c_p1( getGridCellCoordinates(*(triangle->getPoint(1)))); if (!c_p1) + { return false; + } boost::optional<std::array<std::size_t, 3> const> c_p2( getGridCellCoordinates(*(triangle->getPoint(2)))); if (!c_p2) + { return false; + } // determine interval in grid (grid cells the triangle will be inserted) std::size_t const i_min(std::min(std::min((*c_p0)[0], (*c_p1)[0]), (*c_p2)[0])); diff --git a/GeoLib/TemplateVec.h b/GeoLib/TemplateVec.h index 158be41006ac05e94b8eea291bd7b4259b3ade2a..2894f75358dd8398987de7b5d7d79f9b2a048e00 100644 --- a/GeoLib/TemplateVec.h +++ b/GeoLib/TemplateVec.h @@ -69,7 +69,9 @@ public: } if (!_name_id_map) + { _name_id_map = std::make_unique<NameIdMap>(); + } } /** @@ -77,7 +79,10 @@ public: */ virtual ~TemplateVec () { - for (std::size_t k(0); k < size(); k++) delete (*_data_vec)[k]; + for (std::size_t k(0); k < size(); k++) + { + delete (*_data_vec)[k]; + } } /** sets the name of the vector of geometric objects @@ -130,7 +135,9 @@ public: std::size_t id; bool ret (getElementIDByName (name, id)); if (ret) + { return (*_data_vec)[id]; + } return nullptr; } @@ -172,8 +179,12 @@ public: bool getNameOfElement (const T* data, std::string& name) const { for (std::size_t k(0); k < _data_vec->size(); k++) + { if ((*_data_vec)[k] == data) - return getNameOfElementByID (k, name); + { + return getNameOfElementByID(k, name); + } + } return false; } @@ -183,7 +194,9 @@ public: { _data_vec->push_back (data_element); if (!name || name->empty()) + { return; + } std::map<std::string, std::size_t>::const_iterator it( _name_id_map->find(*name) @@ -204,7 +217,9 @@ public: // Erase id if found in map. auto it = findFirstElementByID(id); if (it != _name_id_map->end()) + { _name_id_map->erase(it); + } if (!name.empty()) { //insert new or revised name diff --git a/MaterialLib/Adsorption/Adsorption.cpp b/MaterialLib/Adsorption/Adsorption.cpp index d6ceb5d7c529ce632d746c69ca93c3b719a8e19e..315c4c2c5c283b0f02289deb095af80daccdddb5 100644 --- a/MaterialLib/Adsorption/Adsorption.cpp +++ b/MaterialLib/Adsorption/Adsorption.cpp @@ -49,16 +49,20 @@ double AdsorptionReaction::getEvaporationEnthalpy(double T_Ads) // in kJ/kg if (T_Ads <= 10.){ const double c[] = {2.50052e3,-2.1068,-3.57500e-1,1.905843e-1,-5.11041e-2,7.52511e-3,-6.14313e-4,2.59674e-5,-4.421e-7}; double hv = 0.; - for (size_t i=0; i< sizeof(c)/sizeof(c[0]);i++) - hv += c[i] * pow(T_Ads,i); + for (size_t i = 0; i < sizeof(c) / sizeof(c[0]); i++) + { + hv += c[i] * pow(T_Ads, i); + } return hv; } if (T_Ads <= 300.) { const double c[] = {2.50043e3,-2.35209,1.91685e-4,-1.94824e-5,2.89539e-7,-3.51199e-9,2.06926e-11,-6.4067e-14,8.518e-17,1.558e-20,-1.122e-22}; double hv = 0.; - for (size_t i=0; i< sizeof(c)/sizeof(c[0]);i++) - hv += c[i] * pow(T_Ads,i); + for (size_t i = 0; i < sizeof(c) / sizeof(c[0]); i++) + { + hv += c[i] * pow(T_Ads, i); + } return hv; } const double c[] = {2.99866e3, -3.1837e-3, -1.566964e1, @@ -73,8 +77,10 @@ double AdsorptionReaction::getSpecificHeatCapacity(const double T_Ads) { const double c[] = {4.224,-3.716e-3,9.351e-5,-7.1786e-7,-9.1266e-9,2.69247e-10,-2.773104e-12,1.553177e-14,-4.982795e-17,8.578e-20,-6.12423e-23}; double cp = 0.; - for (unsigned i=0; i< sizeof(c)/sizeof(c[0]);i++) - cp += c[i] * pow(T_Ads,i); + for (unsigned i = 0; i < sizeof(c) / sizeof(c[0]); i++) + { + cp += c[i] * pow(T_Ads, i); + } return cp; // kJ/(kg*K) } @@ -103,7 +109,10 @@ double AdsorptionReaction::getReactionRate(const double p_Ads, const double T_Ad { const double A = getPotential(p_Ads, T_Ads, M_Ads); double C_eq = getAdsorbateDensity(T_Ads) * characteristicCurve(A); - if (C_eq < 0.0) C_eq = 0.0; + if (C_eq < 0.0) + { + C_eq = 0.0; + } return k_rate * (C_eq - loading); // scaled with mass fraction // this the rate in terms of loading! diff --git a/MaterialLib/Adsorption/Reaction.cpp b/MaterialLib/Adsorption/Reaction.cpp index 9544834ce8793e6b407bdc23ce5b84859f9d6309..a91172ed102658dc32765808ad5db933d4f58a60 100644 --- a/MaterialLib/Adsorption/Reaction.cpp +++ b/MaterialLib/Adsorption/Reaction.cpp @@ -38,27 +38,49 @@ newInstance(BaseLib::ConfigTree const& conf) auto const type = conf.getConfigParameter<std::string>("type"); if (type == "Z13XBF") + { return std::make_unique<DensityLegacy>(); + } if (type == "Z13XBF_100MPa") + { return std::make_unique<Density100MPa>(); + } if (type == "Z13XBF_Const") + { return std::make_unique<DensityConst>(); + } if (type == "Z13XBF_Cook") + { return std::make_unique<DensityCook>(); + } if (type == "Z13XBF_Dubinin") + { return std::make_unique<DensityDubinin>(); + } if (type == "Z13XBF_Hauer") + { return std::make_unique<DensityHauer>(); + } if (type == "Z13XBF_Mette") + { return std::make_unique<DensityMette>(); + } if (type == "Z13XBF_Nunez") + { return std::make_unique<DensityNunez>(); + } if (type == "Inert") + { return std::make_unique<ReactionInert>(); + } if (type == "Sinusoidal") + { return std::make_unique<ReactionSinusoidal>(conf); + } if (type == "CaOH2") + { return std::make_unique<ReactionCaOH2>(conf); + } OGS_FATAL("Unknown reactive system: %s.", type.c_str()); diff --git a/MaterialLib/Adsorption/ReactionCaOH2.cpp b/MaterialLib/Adsorption/ReactionCaOH2.cpp index fed12383bf0630f0f8d5e28f30da9c8ec7015fb9..94f7f99e0b022d34d3705848171145fda5ed0997 100644 --- a/MaterialLib/Adsorption/ReactionCaOH2.cpp +++ b/MaterialLib/Adsorption/ReactionCaOH2.cpp @@ -109,11 +109,18 @@ double ReactionCaOH2::CaHydration() dXdt = -1.0*(1.0-X_H) * (T_s - T_eq) / T_eq * 0.2 * conversion_rate::x_react; #else //this is from Schaube if (_X_H == _tol_u || _rho_s == rho_up) + { dXdt = 0.0; - else if ( (_T_eq-_T_s) >= 50.0) + } + else if ((_T_eq - _T_s) >= 50.0) + { dXdt = 13945.0 * exp(-89486.0/R/_T_s) * std::pow(_p_r_g/_p_eq - 1.0,0.83) * 3.0 * (_X_D) * std::pow(-1.0*log(_X_D),0.666); + } else - dXdt = 1.0004e-34 * exp(5.3332e4/_T_s) * std::pow(_p_r_g, 6.0) * (_X_D); + { + dXdt = 1.0004e-34 * exp(5.3332e4 / _T_s) * std::pow(_p_r_g, 6.0) * + (_X_D); + } #endif } else // dehydration @@ -123,11 +130,19 @@ double ReactionCaOH2::CaHydration() dXdt = -1.0* (1.0-X_D) * (T_s - T_eq) / T_eq * 0.05; #else if (_X_D == _tol_u || _rho_s == rho_low) + { dXdt = 0.0; + } else if (_X_D < 0.2) + { dXdt = -1.9425e12 * exp( -1.8788e5/R/_T_s ) * std::pow(1.0-_p_r_g/_p_eq,3.0)*(_X_H); + } else - dXdt = -8.9588e9 * exp( -1.6262e5/R/_T_s ) * std::pow(1.0-_p_r_g/_p_eq,3.0)*2.0 * std::pow(_X_H, 0.5); + { + dXdt = -8.9588e9 * exp(-1.6262e5 / R / _T_s) * + std::pow(1.0 - _p_r_g / _p_eq, 3.0) * 2.0 * + std::pow(_X_H, 0.5); + } #endif } return dXdt; diff --git a/MaterialLib/Fluid/Density/CreateFluidDensityModel.cpp b/MaterialLib/Fluid/Density/CreateFluidDensityModel.cpp index cdd515217c376f5af556196180f9b6320ca4bcf6..b603f09f306ac638161e1234b3f5a058aec41600 100644 --- a/MaterialLib/Fluid/Density/CreateFluidDensityModel.cpp +++ b/MaterialLib/Fluid/Density/CreateFluidDensityModel.cpp @@ -139,13 +139,21 @@ std::unique_ptr<FluidProperty> createFluidDensityModel( config.getConfigParameter<double>("value")); } if (type == "LiquidDensity") + { return createLiquidDensity(config); + } if (type == "TemperatureDependent") + { return createLinearTemperatureDependentDensity(config); + } if (type == "ConcentrationDependent") + { return createLinearConcentrationDependentDensity(config); + } if (type == "ConcentrationAndPressureDependent") + { return createLinearConcentrationAndPressureDependentDensity(config); + } if (type == "IdealGasLaw") { //! \ogs_file_param{material__fluid__density__type} diff --git a/MaterialLib/Fluid/Density/LinearConcentrationDependentDensity.h b/MaterialLib/Fluid/Density/LinearConcentrationDependentDensity.h index c806eb97f5bd131bbb7cac1f509240a53c0a0167..1943e202d09527c6da90f2133cea22837e4a46f1 100644 --- a/MaterialLib/Fluid/Density/LinearConcentrationDependentDensity.h +++ b/MaterialLib/Fluid/Density/LinearConcentrationDependentDensity.h @@ -72,7 +72,9 @@ public: { (void)var_vals; if (var != PropertyVariableType::C) + { return 0.0; + } return _reference_density * _fluid_density_difference_ratio; } diff --git a/MaterialLib/Fluid/Density/LinearTemperatureDependentDensity.h b/MaterialLib/Fluid/Density/LinearTemperatureDependentDensity.h index 5bc2f9bf1a7b1104a2f9d1e0e887a30cd9768b41..b92bfa40a2bd4c9fab91f7e681161e1fc7a30e45 100644 --- a/MaterialLib/Fluid/Density/LinearTemperatureDependentDensity.h +++ b/MaterialLib/Fluid/Density/LinearTemperatureDependentDensity.h @@ -62,7 +62,9 @@ public: { (void)var_vals; if (var != PropertyVariableType::T) + { return 0.0; + } return -_rho0 * _beta; } diff --git a/MaterialLib/Fluid/FluidProperties/CreateFluidProperties.cpp b/MaterialLib/Fluid/FluidProperties/CreateFluidProperties.cpp index 3fe6d034af47cd2990ef521b60767f721f3e12d9..8a364d28a49863d10bf7b2b46e4a47207a758d5d 100644 --- a/MaterialLib/Fluid/FluidProperties/CreateFluidProperties.cpp +++ b/MaterialLib/Fluid/FluidProperties/CreateFluidProperties.cpp @@ -76,12 +76,14 @@ std::unique_ptr<FluidProperties> createFluidProperties( if (is_mu_density_dependent || is_cp_density_dependent || is_KT_density_dependent) + { return std::make_unique< MaterialLib::Fluid::FluidPropertiesWithDensityDependentModels>( std::move(liquid_density), std::move(viscosity), std::move(specific_heat_capacity), std::move(thermal_conductivity), is_mu_density_dependent, is_cp_density_dependent, is_KT_density_dependent); + } return std::make_unique< MaterialLib::Fluid::PrimaryVariableDependentFluidProperties>( diff --git a/MaterialLib/Fluid/SpecificHeatCapacity/CreateSpecificFluidHeatCapacityModel.cpp b/MaterialLib/Fluid/SpecificHeatCapacity/CreateSpecificFluidHeatCapacityModel.cpp index aa7982aa7c352adbc1c9525b41c6a15b62e5eb95..18f901d8526186e328a5c00bd30034e037c37d05 100644 --- a/MaterialLib/Fluid/SpecificHeatCapacity/CreateSpecificFluidHeatCapacityModel.cpp +++ b/MaterialLib/Fluid/SpecificHeatCapacity/CreateSpecificFluidHeatCapacityModel.cpp @@ -30,9 +30,11 @@ std::unique_ptr<FluidProperty> createSpecificFluidHeatCapacityModel( auto const type = config.getConfigParameter<std::string>("type"); if (type == "Constant") + { return std::make_unique<ConstantFluidProperty>( //! \ogs_file_param{material__fluid__specific_heat_capacity__Constant__value} config.getConfigParameter<double>("value")); + } // TODO: add more models OGS_FATAL( diff --git a/MaterialLib/Fluid/ThermalConductivity/CreateFluidThermalConductivityModel.cpp b/MaterialLib/Fluid/ThermalConductivity/CreateFluidThermalConductivityModel.cpp index ef984a45f9d357c5e3fc8911b61035270f872ec9..8b1a64b87c93f8755f4f96fee2959c0e07272ec7 100644 --- a/MaterialLib/Fluid/ThermalConductivity/CreateFluidThermalConductivityModel.cpp +++ b/MaterialLib/Fluid/ThermalConductivity/CreateFluidThermalConductivityModel.cpp @@ -30,9 +30,11 @@ std::unique_ptr<FluidProperty> createFluidThermalConductivityModel( auto const type = config.getConfigParameter<std::string>("type"); if (type == "Constant") + { return std::make_unique<ConstantFluidProperty>( //! \ogs_file_param{material__fluid__thermal_conductivity__Constant__value} config.getConfigParameter<double>("value")); + } // TODO: add more models OGS_FATAL( diff --git a/MaterialLib/Fluid/Viscosity/CreateViscosityModel.cpp b/MaterialLib/Fluid/Viscosity/CreateViscosityModel.cpp index dfeb268d75987bff63dc1c9fc87e05472f6daf68..36f56e451d23c09942f5bd869572c395776b1448 100644 --- a/MaterialLib/Fluid/Viscosity/CreateViscosityModel.cpp +++ b/MaterialLib/Fluid/Viscosity/CreateViscosityModel.cpp @@ -86,9 +86,13 @@ std::unique_ptr<FluidProperty> createViscosityModel( config.getConfigParameter<double>("value")); } if (type == "LinearPressure") + { return createLinearPressureDependentViscosity(config); + } if (type == "TemperatureDependent") + { return createTemperatureDependentViscosity(config); + } if (type == "Vogels") { //! \ogs_file_param{material__fluid__viscosity__type} diff --git a/MaterialLib/FractureModels/CohesiveZoneModeI.cpp b/MaterialLib/FractureModels/CohesiveZoneModeI.cpp index 48838487b3642cd28db6e2e07970c8fbb2bfc667..efb029d3794858bb8864e7f2ea563fea18483851 100644 --- a/MaterialLib/FractureModels/CohesiveZoneModeI.cpp +++ b/MaterialLib/FractureModels/CohesiveZoneModeI.cpp @@ -73,7 +73,9 @@ void CohesiveZoneModeI<DisplacementDim>::computeConstitutiveRelation( const int index_ns = DisplacementDim - 1; double const w_n = w[index_ns]; for (int i = 0; i < index_ns; i++) + { C(i, i) = mp.Ks; + } sigma.noalias() = C * w; diff --git a/MaterialLib/FractureModels/LinearElasticIsotropic.cpp b/MaterialLib/FractureModels/LinearElasticIsotropic.cpp index 21448e43b38f885a24bcf0ca8a0f4cf8d4168fc9..dbc3b4339900a79b0b3488a4c9176e04d8491220 100644 --- a/MaterialLib/FractureModels/LinearElasticIsotropic.cpp +++ b/MaterialLib/FractureModels/LinearElasticIsotropic.cpp @@ -40,7 +40,9 @@ void LinearElasticIsotropic<DisplacementDim>::computeConstitutiveRelation( const int index_ns = DisplacementDim - 1; C.setZero(); for (int i = 0; i < index_ns; i++) + { C(i, i) = _mp.shear_stiffness(t, x)[0]; + } sigma.noalias() = C * w; diff --git a/MaterialLib/FractureModels/LogPenalty.h b/MaterialLib/FractureModels/LogPenalty.h index 5d6ac5c53cec1ce65e60f36b7e084ddd1ca67285..ebe06de8698184df2dd9be787beb69362558d6d3 100644 --- a/MaterialLib/FractureModels/LogPenalty.h +++ b/MaterialLib/FractureModels/LogPenalty.h @@ -25,7 +25,9 @@ inline double logPenaltyDerivative(double const aperture0, double const aperture_cutoff) { if (aperture >= aperture0) + { return 1; + } // Logarithmic penalty if (aperture > aperture_cutoff) @@ -49,7 +51,9 @@ inline double logPenalty(double const aperture0, double const aperture_cutoff) { if (aperture >= aperture0) + { return 1; + } // Logarithmic penalty if (aperture > aperture_cutoff) diff --git a/MaterialLib/FractureModels/MohrCoulomb.cpp b/MaterialLib/FractureModels/MohrCoulomb.cpp index c19c0fbb94360c5ba2f19dd2d1249684fa88dbf4..1e86063670c244cf1c86f4ecdd38cb567790b3b6 100644 --- a/MaterialLib/FractureModels/MohrCoulomb.cpp +++ b/MaterialLib/FractureModels/MohrCoulomb.cpp @@ -78,7 +78,9 @@ void MohrCoulomb<DisplacementDim>::computeConstitutiveRelation( { // Elastic tangent stiffness Ke = Eigen::MatrixXd::Zero(DisplacementDim, DisplacementDim); for (int i = 0; i < index_ns; i++) + { Ke(i, i) = mat.Ks; + } Ke(index_ns, index_ns) = mat.Kn * @@ -89,7 +91,9 @@ void MohrCoulomb<DisplacementDim>::computeConstitutiveRelation( { // Elastic tangent stiffness at w_prev Ke_prev = Eigen::MatrixXd::Zero(DisplacementDim, DisplacementDim); for (int i = 0; i < index_ns; i++) + { Ke_prev(i, i) = mat.Ks; + } Ke_prev(index_ns, index_ns) = mat.Kn * logPenaltyDerivative( diff --git a/MaterialLib/PorousMedium/CreatePorousMediaProperties.cpp b/MaterialLib/PorousMedium/CreatePorousMediaProperties.cpp index b21edcd02376327026fd07648e889d142b954e63..27651ac36925715d1d97326ef93bbd9bb6c92eb4 100644 --- a/MaterialLib/PorousMedium/CreatePorousMediaProperties.cpp +++ b/MaterialLib/PorousMedium/CreatePorousMediaProperties.cpp @@ -83,12 +83,14 @@ PorousMediaProperties createPorousMediaProperties( : *std::max_element(begin(*material_ids), end(*material_ids)); if (max_material_id > static_cast<int>(mat_ids.size() - 1)) + { OGS_FATAL( "The maximum value of MaterialIDs in mesh is %d. As the " "given number of porous media definitions in the project " "file is %d, the maximum value of MaterialIDs in mesh must be %d " "(index starts with zero).", max_material_id, mat_ids.size(), max_material_id - 1); + } if (max_material_id < static_cast<int>(mat_ids.size() - 1)) WARN( @@ -98,9 +100,11 @@ PorousMediaProperties createPorousMediaProperties( mat_ids.size(), max_material_id - 1); if (mat_ids.back() != static_cast<int>(mat_ids.size()) - 1) + { OGS_FATAL( "The ids in the porous media definitions in the project file have " "to be sequential, starting with the id zero."); + } return PorousMediaProperties{std::move(porosity_models), std::move(intrinsic_permeability_models), diff --git a/MaterialLib/PorousMedium/Storage/createStorageModel.cpp b/MaterialLib/PorousMedium/Storage/createStorageModel.cpp index 0c553ec1ddcad8ff5941744c41999a1df451b8cd..6cdaa9ed3d10706941af77df915e52171338d685 100644 --- a/MaterialLib/PorousMedium/Storage/createStorageModel.cpp +++ b/MaterialLib/PorousMedium/Storage/createStorageModel.cpp @@ -28,9 +28,11 @@ std::unique_ptr<Storage> createStorageModel(BaseLib::ConfigTree const& config) auto const type = config.getConfigParameter<std::string>("type"); if (type == "Constant") + { return std::make_unique<ConstantStorage>( //! \ogs_file_param{material__porous_medium__storage__Constant__value} config.getConfigParameter<double>("value")); + } OGS_FATAL("The storage type %s is unavailable.\n", type.data(), "The available type is Constant."); diff --git a/MaterialLib/PorousMedium/UnsaturatedProperty/CapillaryPressure/VanGenuchtenCapillaryPressureSaturation.cpp b/MaterialLib/PorousMedium/UnsaturatedProperty/CapillaryPressure/VanGenuchtenCapillaryPressureSaturation.cpp index 4e4177c387c5f7981f3511e1ef53344752a08b44..e337aaf1f5432e66b4d7cee6bb9b8877819035f3 100644 --- a/MaterialLib/PorousMedium/UnsaturatedProperty/CapillaryPressure/VanGenuchtenCapillaryPressureSaturation.cpp +++ b/MaterialLib/PorousMedium/UnsaturatedProperty/CapillaryPressure/VanGenuchtenCapillaryPressureSaturation.cpp @@ -77,9 +77,13 @@ double VanGenuchtenCapillaryPressureSaturation::getdPcdS( return -getdPcdSvGBar(1 - _saturation_r); } if (saturation < _saturation_r) + { return 0; + } if (saturation > _saturation_max) + { return 0; + } const double S = MathLib::limitValueInInterval(saturation, _saturation_r + _minor_offset, @@ -100,9 +104,13 @@ double VanGenuchtenCapillaryPressureSaturation::getd2PcdS2( "pressure relation is not implemented."); } if (saturation < _saturation_r) + { return 0; + } if (saturation > _saturation_max) + { return 0; + } const double S = MathLib::limitValueInInterval(saturation, _saturation_r + _minor_offset, diff --git a/MaterialLib/SolidModels/CreepBGRa.cpp b/MaterialLib/SolidModels/CreepBGRa.cpp index 94c7f5e99eb3f297501313277b0686e963d8cd4b..0c58a8469f5277ed0d964b4ca526a83b214a192e 100644 --- a/MaterialLib/SolidModels/CreepBGRa.cpp +++ b/MaterialLib/SolidModels/CreepBGRa.cpp @@ -118,7 +118,9 @@ CreepBGRa<DisplacementDim>::integrateStress( auto const success_iterations = newton_solver.solve(jacobian); if (!success_iterations) + { return {}; + } // If *success_iterations>0, tangentStiffness = J_(sigma)^{-1}C // where J_(sigma) is the Jacobian of the last local Newton-Raphson diff --git a/MaterialLib/SolidModels/Ehlers.cpp b/MaterialLib/SolidModels/Ehlers.cpp index cba52ae5e120838c3a441a1a571f87811e9b88bc..efece2a3756a84a2403c6c99087dff88f68e7d87 100644 --- a/MaterialLib/SolidModels/Ehlers.cpp +++ b/MaterialLib/SolidModels/Ehlers.cpp @@ -629,14 +629,18 @@ SolidEhlers<DisplacementDim>::integrateStress( auto const success_iterations = newton_solver.solve(jacobian); if (!success_iterations) + { return {}; + } // If the Newton loop didn't run, the linear solver will not be // initialized. // This happens usually for the first iteration of the first // timestep. if (*success_iterations == 0) + { linear_solver.compute(jacobian); + } std::tie(sigma, state.eps_p, std::ignore) = splitSolutionVector<ResidualVectorType, KelvinVector>(solution); diff --git a/MaterialLib/SolidModels/Ehlers.h b/MaterialLib/SolidModels/Ehlers.h index a8ee5d325fa6348115fc15a6f66e2665837a9983..3734d0fb2831f3c2962f06745ecdc08366c17ecd 100644 --- a/MaterialLib/SolidModels/Ehlers.h +++ b/MaterialLib/SolidModels/Ehlers.h @@ -44,11 +44,17 @@ enum class TangentType inline TangentType makeTangentType(std::string const& s) { if (s == "Elastic") + { return TangentType::Elastic; + } if (s == "PlasticDamageSecant") + { return TangentType::PlasticDamageSecant; + } if (s == "Plastic") + { return TangentType::Plastic; + } OGS_FATAL("Not valid string '%s' to create a tangent type from.", s.c_str()); } diff --git a/MaterialLib/SolidModels/Lubby2.cpp b/MaterialLib/SolidModels/Lubby2.cpp index bcfe915b72759be211d81755de8703a62c29010a..f804c9d8da1d6a23bc4826e5043aba5a8521b07a 100644 --- a/MaterialLib/SolidModels/Lubby2.cpp +++ b/MaterialLib/SolidModels/Lubby2.cpp @@ -165,13 +165,17 @@ Lubby2<DisplacementDim>::integrateStress( auto const success_iterations = newton_solver.solve(K_loc); if (!success_iterations) + { return {}; + } // If the Newton loop didn't run, the linear solver will not be // initialized. // This happens usually for the first iteration of the first timestep. if (*success_iterations == 0) + { linear_solver.compute(K_loc); + } } KelvinMatrix C = diff --git a/MaterialLib/TwoPhaseModels/TwoPhaseFlowWithPPMaterialProperties.cpp b/MaterialLib/TwoPhaseModels/TwoPhaseFlowWithPPMaterialProperties.cpp index f8a9b5a2d99c2751eb1f0ab571244dc958047aa1..b7a71d1922954c9eb4cb6f807bbc3583120509f3 100644 --- a/MaterialLib/TwoPhaseModels/TwoPhaseFlowWithPPMaterialProperties.cpp +++ b/MaterialLib/TwoPhaseModels/TwoPhaseFlowWithPPMaterialProperties.cpp @@ -166,9 +166,13 @@ double TwoPhaseFlowWithPPMaterialProperties::getNonwetRelativePermeability( const double /*p*/, const double /*T*/, const double saturation) const { if (saturation < 0.) + { return 1.0; + } if (saturation > 1) + { return 0.0; + } return boost::math::pow<3>(1 - saturation); } @@ -177,9 +181,13 @@ double TwoPhaseFlowWithPPMaterialProperties::getWetRelativePermeability( const double /*p*/, const double /*T*/, const double saturation) const { if (saturation < 0) + { return 0.0; + } if (saturation > 1) + { return 1.0; + } return boost::math::pow<3>(saturation); } } // namespace TwoPhaseFlowWithPP diff --git a/MathLib/Curve/PiecewiseLinearMonotonicCurve.cpp b/MathLib/Curve/PiecewiseLinearMonotonicCurve.cpp index a6e9de4af8f5b84d26081abff03dcc7ab4fd8064..d669e6e491185f9f2e749476cd05dd245688b92e 100644 --- a/MathLib/Curve/PiecewiseLinearMonotonicCurve.cpp +++ b/MathLib/Curve/PiecewiseLinearMonotonicCurve.cpp @@ -35,7 +35,9 @@ bool PiecewiseLinearMonotonicCurve::isStrongMonotonic() const const double gradient0 = getDerivative(_supp_pnts[0]); if (std::fabs(gradient0) < std::numeric_limits<double>::min()) + { return false; + } return std::none_of(_supp_pnts.begin(), _supp_pnts.end(), [&](const double p) { diff --git a/MathLib/GeometricBasics.cpp b/MathLib/GeometricBasics.cpp index 6b53384973de7b1c4a11a357eff53c39c9550760..94cdeffa879e73883b22cffc0c91705d8d997b2a 100644 --- a/MathLib/GeometricBasics.cpp +++ b/MathLib/GeometricBasics.cpp @@ -61,16 +61,22 @@ bool isPointInTetrahedron(MathLib::Point3d const& p, MathLib::Point3d const& a, bool const d0_sign (d0>0); // if p is on the same side of bcd as a double const d1 (MathLib::orientation3d(d, p, b, c)); - if (!(d0_sign == (d1>=0) || std::abs(d1) < eps)) + if (!(d0_sign == (d1 >= 0) || std::abs(d1) < eps)) + { return false; + } // if p is on the same side of acd as b double const d2 (MathLib::orientation3d(d, a, p, c)); - if (!(d0_sign == (d2>=0) || std::abs(d2) < eps)) + if (!(d0_sign == (d2 >= 0) || std::abs(d2) < eps)) + { return false; + } // if p is on the same side of abd as c double const d3 (MathLib::orientation3d(d, a, b, p)); - if (!(d0_sign == (d3>=0) || std::abs(d3) < eps)) + if (!(d0_sign == (d3 >= 0) || std::abs(d3) < eps)) + { return false; + } // if p is on the same side of abc as d double const d4 (MathLib::orientation3d(p, a, b, c)); return d0_sign == (d4 >= 0) || std::abs(d4) < eps; @@ -133,7 +139,9 @@ bool gaussPointInTriangle(MathLib::Point3d const& q, {a[0] + y[0] * v[0] + y[1] * w[0], a[1] + y[0] * v[1] + y[1] * w[1], a[2] + y[0] * v[2] + y[1] * w[2]}}); if (MathLib::sqrDist(q, q_projected) <= eps_pnt_out_of_plane) + { return true; + } } return false; @@ -147,7 +155,9 @@ bool barycentricPointInTriangle(MathLib::Point3d const& p, double eps_pnt_out_of_tri) { if (std::abs(MathLib::orientation3d(p, a, b, c)) > eps_pnt_out_of_plane) + { return false; + } MathLib::Vector3 const pa(p, a); MathLib::Vector3 const pb(p, b); @@ -156,10 +166,14 @@ bool barycentricPointInTriangle(MathLib::Point3d const& p, double const alpha((MathLib::crossProduct(pb, pc).getLength()) / area_x_2); if (alpha < -eps_pnt_out_of_tri || alpha > 1 + eps_pnt_out_of_tri) + { return false; + } double const beta((MathLib::crossProduct(pc, pa).getLength()) / area_x_2); if (beta < -eps_pnt_out_of_tri || beta > 1 + eps_pnt_out_of_tri) + { return false; + } double const gamma(1 - alpha - beta); return !(gamma < -eps_pnt_out_of_tri || gamma > 1 + eps_pnt_out_of_tri); } @@ -196,7 +210,9 @@ bool dividedByPlane(const MathLib::Point3d& a, const MathLib::Point3d& b, (b[x] - a[x]) * (d[y] - a[y]) - (b[y] - a[y]) * (d[x] - a[x]); if ((abc > 0 && abd < 0) || (abc < 0 && abd > 0)) + { return true; + } } return false; } diff --git a/MathLib/LinAlg/Dense/DenseMatrix-impl.h b/MathLib/LinAlg/Dense/DenseMatrix-impl.h index ce34f55bc785294c747c3a005933df6739aea193..0c899ee21cc9328e7b22bddf0681caf609d74197 100644 --- a/MathLib/LinAlg/Dense/DenseMatrix-impl.h +++ b/MathLib/LinAlg/Dense/DenseMatrix-impl.h @@ -28,7 +28,9 @@ DenseMatrix<FP_TYPE, IDX_TYPE>::DenseMatrix(IDX_TYPE rows, IDX_TYPE cols, { const IDX_TYPE n(_n_rows * _n_cols); for (IDX_TYPE k(0); k < n; k++) + { _data[k] = initial_value; + } } template<typename FP_TYPE, typename IDX_TYPE> @@ -60,7 +62,9 @@ DenseMatrix<FP_TYPE, IDX_TYPE>& DenseMatrix<FP_TYPE, IDX_TYPE>::operator=(DenseMatrix<FP_TYPE, IDX_TYPE> const& rhs) { if (this == &rhs) + { return *this; + } if (_n_rows != rhs.getNumberOfRows() || _n_cols != rhs.getNumberOfColumns()) { std::string msg("DenseMatrix::operator=(DenseMatrix const& rhs), Dimension mismatch, "); @@ -169,7 +173,9 @@ DenseMatrix<FP_TYPE, IDX_TYPE>::operator+(const DenseMatrix<FP_TYPE, IDX_TYPE>& { // make sure the two matrices have the same dimension. if (_n_rows != mat.getNumberOfRows() || _n_cols != mat.getNumberOfColumns()) + { throw std::range_error("DenseMatrix::operator+, illegal matrix size!"); + } DenseMatrix<FP_TYPE, IDX_TYPE>* y(new DenseMatrix<FP_TYPE, IDX_TYPE>(_n_rows, _n_cols)); for (IDX_TYPE i = 0; i < _n_rows; i++) { @@ -187,7 +193,9 @@ DenseMatrix<FP_TYPE, IDX_TYPE>::operator-(const DenseMatrix<FP_TYPE, IDX_TYPE>& { // make sure the two matrices have the same dimension. if (_n_rows != mat.getNumberOfRows() || _n_cols != mat.getNumberOfColumns()) + { throw std::range_error("DenseMatrix::operator-, illegal matrix size!"); + } DenseMatrix<FP_TYPE, IDX_TYPE>* y(new DenseMatrix<FP_TYPE, IDX_TYPE>(_n_rows, _n_cols)); for (IDX_TYPE i = 0; i < _n_rows; i++) { @@ -205,8 +213,11 @@ DenseMatrix<FP_TYPE, IDX_TYPE>::operator*(const DenseMatrix<FP_TYPE, IDX_TYPE>& { // make sure the two matrices have the same dimension. if (_n_cols != mat.getNumberOfRows()) + { throw std::range_error( - "DenseMatrix::operator*, number of rows and cols should be the same!"); + "DenseMatrix::operator*, number of rows and cols should be the " + "same!"); + } IDX_TYPE y_cols(mat.getNumberOfColumns()); DenseMatrix<FP_TYPE, IDX_TYPE>* y( @@ -215,7 +226,9 @@ DenseMatrix<FP_TYPE, IDX_TYPE>::operator*(const DenseMatrix<FP_TYPE, IDX_TYPE>& for (IDX_TYPE i = 0; i < _n_rows; i++) { for (IDX_TYPE j = 0; j < y_cols; j++) { for (IDX_TYPE k = 0; k < _n_cols; k++) + { (*y)(i, j) += _data[address(i, k)] * mat(k, j); + } } } @@ -242,8 +255,12 @@ DenseMatrix<FP_TYPE, IDX_TYPE>::transposeInPlace() { if (_n_rows==_n_cols) { // square matrix for (IDX_TYPE i = 0; i < _n_rows; i++) - for (IDX_TYPE j = i+1; j < _n_cols; j++) + { + for (IDX_TYPE j = i + 1; j < _n_cols; j++) + { std::swap(_data[address(i, j)], _data[address(j, i)]); + } + } } else { // non-square matrix const DenseMatrix<FP_TYPE, IDX_TYPE> org(*this); std::swap(_n_rows, _n_cols); @@ -263,9 +280,15 @@ DenseMatrix<FP_TYPE, IDX_TYPE>::getSubMatrix( IDX_TYPE e_row, IDX_TYPE e_col) const { if (b_row >= e_row | b_col >= e_col) - throw std::range_error("DenseMatrix::getSubMatrix() illegal sub matrix"); + { + throw std::range_error( + "DenseMatrix::getSubMatrix() illegal sub matrix"); + } if (e_row > _n_rows | e_col > _n_cols) - throw std::range_error("DenseMatrix::getSubMatrix() illegal sub matrix"); + { + throw std::range_error( + "DenseMatrix::getSubMatrix() illegal sub matrix"); + } DenseMatrix<FP_TYPE, IDX_TYPE>* y( new DenseMatrix<FP_TYPE, IDX_TYPE>(e_row - b_row, e_col - b_col)); @@ -282,8 +305,11 @@ void DenseMatrix<FP_TYPE, IDX_TYPE>::setSubMatrix(IDX_TYPE b_row, IDX_TYPE b_col, const DenseMatrix<FP_TYPE, IDX_TYPE>& sub_mat) { - if (b_row + sub_mat.getNumberOfRows() > _n_rows | b_col + sub_mat.getNumberOfColumns() > _n_cols) + if (b_row + sub_mat.getNumberOfRows() > _n_rows | + b_col + sub_mat.getNumberOfColumns() > _n_cols) + { throw std::range_error("DenseMatrix::setSubMatrix() sub matrix to big"); + } for (IDX_TYPE i = 0; i < sub_mat.getNumberOfRows(); i++) { for (IDX_TYPE j = 0; j < sub_mat.getNumberOfColumns(); j++) { @@ -328,8 +354,10 @@ DenseMatrix<FP_TYPE, IDX_TYPE>::setIdentity() { (*this) = 0.0; const IDX_TYPE n_square_rows = std::min(_n_rows, _n_cols); - for (IDX_TYPE i=0; i<n_square_rows; i++) - _data[address(i,i)] = 1.0; + for (IDX_TYPE i = 0; i < n_square_rows; i++) + { + _data[address(i, i)] = 1.0; + } } template <typename FP_TYPE, typename IDX_TYPE> @@ -339,8 +367,12 @@ sqrFrobNrm (const DenseMatrix<FP_TYPE, IDX_TYPE> &mat) FP_TYPE nrm(static_cast<FP_TYPE>(0)); IDX_TYPE i, j; for (j = 0; j < mat.getNumberOfColumns(); j++) + { for (i = 0; i < mat.getNumberOfRows(); i++) + { nrm += mat(i, j) * mat(i, j); + } + } return nrm; } diff --git a/MathLib/LinAlg/Eigen/EigenLinearSolver.cpp b/MathLib/LinAlg/Eigen/EigenLinearSolver.cpp index fb00cd508686af3b9e84a20ae08c5b0fc01d1e07..bf204a4aa81fa23bff1df59a83091ab69c2455f9 100644 --- a/MathLib/LinAlg/Eigen/EigenLinearSolver.cpp +++ b/MathLib/LinAlg/Eigen/EigenLinearSolver.cpp @@ -56,7 +56,10 @@ public: { INFO("-> solve with %s", EigenOption::getSolverName(opt.solver_type).c_str()); - if (!A.isCompressed()) A.makeCompressed(); + if (!A.isCompressed()) + { + A.makeCompressed(); + } _solver.compute(A); if(_solver.info()!=Eigen::Success) { @@ -91,7 +94,9 @@ public: _solver.setMaxIterations(opt.max_iterations); if (!A.isCompressed()) + { A.makeCompressed(); + } _solver.compute(A); if(_solver.info()!=Eigen::Success) { @@ -180,7 +185,9 @@ EigenLinearSolver::EigenLinearSolver( using Matrix = EigenMatrix::RawMatrixType; if (option) + { setOption(*option); + } // TODO for my taste it is much too unobvious that the default solver type // currently is SparseLU. @@ -222,7 +229,9 @@ void EigenLinearSolver::setOption(BaseLib::ConfigTree const& option) //! \ogs_file_param{prj__linear_solvers__linear_solver__eigen} auto const ptSolver = option.getConfigSubtreeOptional("eigen"); if (!ptSolver) + { return; + } if (auto solver_type = //! \ogs_file_param{prj__linear_solvers__linear_solver__eigen__solver_type} @@ -277,7 +286,9 @@ bool EigenLinearSolver::solve(EigenMatrix &A, EigenVector& b, EigenVector &x) x.getRawVector(), _option); #ifdef USE_EIGEN_UNSUPPORTED if (scal) + { x.getRawVector() = scal->RightScaling().cwiseProduct(x.getRawVector()); + } #endif INFO("------------------------------------------------------------------"); diff --git a/MathLib/LinAlg/Eigen/EigenMatrix.h b/MathLib/LinAlg/Eigen/EigenMatrix.h index e0ce42ce580d04cc85ae2692b99abb8552186049..2144299a35c225b3ddcc589041bdc00f7c8b505d 100644 --- a/MathLib/LinAlg/Eigen/EigenMatrix.h +++ b/MathLib/LinAlg/Eigen/EigenMatrix.h @@ -65,8 +65,10 @@ public: void setZero() { auto const N = _mat.nonZeros(); - for (auto i = decltype(N){0}; i<N; i++) + for (auto i = decltype(N){0}; i < N; i++) + { _mat.valuePtr()[i] = 0; + } // don't use _mat.setZero(). it makes a matrix uncompressed } @@ -151,15 +153,21 @@ public: { std::ofstream of(filename); if (of) + { write(of); + } } /// printout this matrix for debugging void write(std::ostream &os) const { - for (int k=0; k<_mat.outerSize(); ++k) - for (RawMatrixType::InnerIterator it(_mat,k); it; ++it) - os << it.row() << " " << it.col() << ": " << it.value() << "\n"; + for (int k = 0; k < _mat.outerSize(); ++k) + { + for (RawMatrixType::InnerIterator it(_mat, k); it; ++it) + { + os << it.row() << " " << it.col() << ": " << it.value() << "\n"; + } + } os << std::endl; } diff --git a/MathLib/LinAlg/Eigen/EigenOption.cpp b/MathLib/LinAlg/Eigen/EigenOption.cpp index c509cf4684da1eaccbb4504f05c20d84169a250b..00ae5c414756fd0801d8e527958571d6011ddfa9 100644 --- a/MathLib/LinAlg/Eigen/EigenOption.cpp +++ b/MathLib/LinAlg/Eigen/EigenOption.cpp @@ -27,15 +27,25 @@ EigenOption::EigenOption() EigenOption::SolverType EigenOption::getSolverType(const std::string &solver_name) { if (solver_name == "CG") + { return SolverType::CG; + } if (solver_name == "BiCGSTAB") + { return SolverType::BiCGSTAB; + } if (solver_name == "SparseLU") + { return SolverType::SparseLU; + } if (solver_name == "PardisoLU") + { return SolverType::PardisoLU; + } if (solver_name == "GMRES") + { return SolverType::GMRES; + } OGS_FATAL("Unknown Eigen solver type `%s'", solver_name.c_str()); } @@ -43,11 +53,17 @@ EigenOption::SolverType EigenOption::getSolverType(const std::string &solver_nam EigenOption::PreconType EigenOption::getPreconType(const std::string &precon_name) { if (precon_name == "NONE") + { return PreconType::NONE; + } if (precon_name == "DIAGONAL") + { return PreconType::DIAGONAL; + } if (precon_name == "ILUT") + { return PreconType::ILUT; + } OGS_FATAL("Unknown Eigen preconditioner type `%s'", precon_name.c_str()); } diff --git a/MathLib/LinAlg/Eigen/EigenTools.cpp b/MathLib/LinAlg/Eigen/EigenTools.cpp index 58e08c7bf77a1304972a83664ceff41939cd6cf7..43ef0d91068aaee108cb7d8969c482a5175c2594 100644 --- a/MathLib/LinAlg/Eigen/EigenTools.cpp +++ b/MathLib/LinAlg/Eigen/EigenTools.cpp @@ -29,9 +29,14 @@ void applyKnownSolution(EigenMatrix &A_, EigenVector &b_, EigenVector &/*x*/, // A(k, j) = 0. // set row to zero for (auto row_id : vec_knownX_id) + { for (SpMat::InnerIterator it(A,row_id); it; ++it) { - if (it.col() != decltype(it.col())(row_id)) it.valueRef() = 0.0; + if (it.col() != decltype(it.col())(row_id)) + { + it.valueRef() = 0.0; + } } + } SpMat AT = A.transpose(); @@ -44,7 +49,10 @@ void applyKnownSolution(EigenMatrix &A_, EigenVector &b_, EigenVector &/*x*/, // set column to zero, subtract from rhs for (SpMat::InnerIterator it(AT, row_id); it; ++it) { - if (it.col() == row_id) continue; + if (it.col() == row_id) + { + continue; + } b[it.col()] -= it.value()*x; it.valueRef() = 0.0; diff --git a/MathLib/LinAlg/LinAlgEnums.cpp b/MathLib/LinAlg/LinAlgEnums.cpp index 08d59424a531d06b453eb8fe08312cb0a742e063..848a9a9faaf6f2b3a99e346c49e9bcf82a0cf5ac 100644 --- a/MathLib/LinAlg/LinAlgEnums.cpp +++ b/MathLib/LinAlg/LinAlgEnums.cpp @@ -27,9 +27,18 @@ std::string convertVecNormTypeToString(VecNormType normType) VecNormType convertStringToVecNormType(const std::string &str) { - if (str == "NORM1") return VecNormType::NORM1; - if (str == "NORM2") return VecNormType::NORM2; - if (str == "INFINITY_N") return VecNormType::INFINITY_N; + if (str == "NORM1") + { + return VecNormType::NORM1; + } + if (str == "NORM2") + { + return VecNormType::NORM2; + } + if (str == "INFINITY_N") + { + return VecNormType::INFINITY_N; + } return VecNormType::INVALID; } diff --git a/MathLib/LinAlg/LinearSolverOptions.cpp b/MathLib/LinAlg/LinearSolverOptions.cpp index 0f5a5158472d0908dc34b84adb33eba649d0e2db..fc1e1b9a6341680b066f90d28a9113a9f112536f 100644 --- a/MathLib/LinAlg/LinearSolverOptions.cpp +++ b/MathLib/LinAlg/LinearSolverOptions.cpp @@ -18,7 +18,10 @@ ignoreOtherLinearSolvers(const BaseLib::ConfigTree &config, const std::string &solver_name) { for (auto const& s : known_linear_solvers) { - if (s!=solver_name) config.ignoreConfigParameter(s); + if (s != solver_name) + { + config.ignoreConfigParameter(s); + } } } diff --git a/MathLib/LinAlg/MatrixVectorTraits.cpp b/MathLib/LinAlg/MatrixVectorTraits.cpp index a3501d72d64e4f5661a7c45d8fd7cb55253ee409..fd11aef995189fbe0b7d762d37a914e3fb62d8b8 100644 --- a/MathLib/LinAlg/MatrixVectorTraits.cpp +++ b/MathLib/LinAlg/MatrixVectorTraits.cpp @@ -110,7 +110,9 @@ newInstance(MatrixSpecifications const& spec) auto A = std::make_unique<EigenMatrix>(spec.nrows); if (spec.sparsity_pattern) + { setMatrixSparsity(*A, *spec.sparsity_pattern); + } return A; } diff --git a/MathLib/LinAlg/UnifiedMatrixSetters.cpp b/MathLib/LinAlg/UnifiedMatrixSetters.cpp index 0ba7ed525b5f9ee3dcce99dacac3f187b731e5c8..4b0211d35b83c37aa3ec9238b3610f0c0247ae70 100644 --- a/MathLib/LinAlg/UnifiedMatrixSetters.cpp +++ b/MathLib/LinAlg/UnifiedMatrixSetters.cpp @@ -113,7 +113,9 @@ void setVector(EigenVector& v_, assert((std::size_t)v.size() == values.size()); auto it = values.begin(); for (std::size_t i = 0; i < values.size(); ++i) + { v[i] = *(it++); + } } void setVector(EigenVector& v, MatrixVectorTraits<EigenVector>::Index const index, diff --git a/MathLib/MathTools.cpp b/MathLib/MathTools.cpp index f26f016694a0d4e4278b3d9f100e0b5cc089abb8..c8e5061fdf8e33a44ea39084b895c02e5c544aac 100644 --- a/MathLib/MathTools.cpp +++ b/MathLib/MathTools.cpp @@ -27,7 +27,9 @@ double calcProjPntToLineAndDists(const double p[3], const double a[3], // compute projected point double proj_pnt[3]; for (std::size_t k(0); k < 3; k++) + { proj_pnt[k] = a[k] + lambda * v[k]; + } d0 = std::sqrt (sqrDist (proj_pnt, a)); diff --git a/MathLib/MathTools.h b/MathLib/MathTools.h index 623f2984e8b26bfe5667ecd1e394ccb4684a2ccc..1ca850028a0e6d7e600d55ea09eb6a01bd38266a 100644 --- a/MathLib/MathTools.h +++ b/MathLib/MathTools.h @@ -31,7 +31,9 @@ T scalarProduct(T const * const v0, T const * const v1) #pragma omp parallel for reduction (+:res) for (int k = 1; k < N; k++) + { res += v0[k] * v1[k]; + } return res; } @@ -40,7 +42,9 @@ double scalarProduct<double,3>(double const * const v0, double const * const v1) { double res (v0[0] * v1[0]); for (std::size_t k(1); k < 3; k++) + { res += v0[k] * v1[k]; + } return res; } @@ -51,7 +55,9 @@ inline T scalarProduct(T const* const v0, T const* const v1, int const n) #pragma omp parallel for reduction (+:res) for (int k = 1; k < n; k++) + { res += v0[k] * v1[k]; + } return res; } @@ -100,9 +106,13 @@ template<typename Type> Type limitValueInInterval(const Type variable, const Type upper_bound) { if (variable < lower_bound) + { return lower_bound; + } if (variable > upper_bound) + { return upper_bound; + } return variable; } } // namespace MathLib diff --git a/MathLib/Nonlinear/Root1D.h b/MathLib/Nonlinear/Root1D.h index 7da425ff2f720925880db391f78b94c547ef2fb4..0040226d61b3cfef132630638ef1dbb99a07279d 100644 --- a/MathLib/Nonlinear/Root1D.h +++ b/MathLib/Nonlinear/Root1D.h @@ -71,7 +71,10 @@ public: { for (unsigned i=0; i<num_steps; ++i) { - if (_a == _b) return; + if (_a == _b) + { + return; + } const double s = (_fb - _fa)/(_b - _a); const double c = _a - _fa/s; @@ -97,7 +100,10 @@ public: //! Returns the current estimate of the root. double getResult() const { - if (_a == _b) return _a; + if (_a == _b) + { + return _a; + } const double s = (_fb - _fa)/(_b - _a); const double c = _a - _fa/s; diff --git a/MathLib/Vector3.h b/MathLib/Vector3.h index aedfa32660264f00d31ff5b0b1632dce8499c7d1..7b084776d03d97312ef2a07d6944878d9af4eae2 100644 --- a/MathLib/Vector3.h +++ b/MathLib/Vector3.h @@ -80,20 +80,28 @@ public: TemplateVector3& operator+=(TemplateVector3 const& v) { - for (std::size_t i(0); i < 3; i++) this->_x[i] += v[i]; + for (std::size_t i(0); i < 3; i++) + { + this->_x[i] += v[i]; + } return *this; } TemplateVector3& operator-=(const TemplateVector3 & pV) { - for (std::size_t i(0); i < 3; i++) this->_x[i] -= pV[i]; + for (std::size_t i(0); i < 3; i++) + { + this->_x[i] -= pV[i]; + } return *this; } TemplateVector3& operator*=(double s) { for (std::size_t i(0); i < 3; i++) + { this->_x[i] *= s; + } return *this; } @@ -104,14 +112,18 @@ public: { const double s(1/getLength()); for (std::size_t i(0); i < 3; i++) + { this->_x[i] *= s; + } } /// Returns a normalized version of this vector TemplateVector3<double> getNormalizedVector() const { if (getSqrLength() == 0) - return TemplateVector3<double>(0,0,0); + { + return TemplateVector3<double>(0, 0, 0); + } TemplateVector3<double> norm_vec (this->_x[0], this->_x[1], this->_x[2]); norm_vec.normalize(); return norm_vec; diff --git a/MeshGeoToolsLib/BoundaryElementsAlongPolyline.cpp b/MeshGeoToolsLib/BoundaryElementsAlongPolyline.cpp index 28d0c716a4d6e56f6013df08ada6fe6e773f01d0..b6f693d4bb0319758c70d0a26010f91433fd727c 100644 --- a/MeshGeoToolsLib/BoundaryElementsAlongPolyline.cpp +++ b/MeshGeoToolsLib/BoundaryElementsAlongPolyline.cpp @@ -40,10 +40,14 @@ BoundaryElementsAlongPolyline::BoundaryElementsAlongPolyline( auto* e = _mesh.getElement(ele_id); // skip line elements if (e->getDimension() == 1) + { continue; + } // skip internal elements if (!e->isBoundaryElement()) + { continue; + } // find edges on the polyline for (unsigned i=0; i<e->getNumberOfEdges(); i++) { auto* edge = e->getEdge(i); @@ -56,7 +60,9 @@ BoundaryElementsAlongPolyline::BoundaryElementsAlongPolyline( *edge, ply, edge_node_distances_along_ply, node_ids_on_poly); if (edge != new_edge) + { delete edge; + } _boundary_elements.push_back(new_edge); } else { delete edge; @@ -86,7 +92,9 @@ BoundaryElementsAlongPolyline::BoundaryElementsAlongPolyline( BoundaryElementsAlongPolyline::~BoundaryElementsAlongPolyline() { for (auto p : _boundary_elements) + { delete p; + } } bool BoundaryElementsAlongPolyline::includesAllEdgeNodeIDs(const std::vector<std::size_t> &vec_node_ids, const MeshLib::Element &edge, std::vector<std::size_t> &edge_node_distances) const @@ -95,9 +103,13 @@ bool BoundaryElementsAlongPolyline::includesAllEdgeNodeIDs(const std::vector<std for (; j<edge.getNumberOfBaseNodes(); j++) { auto itr = std::find(vec_node_ids.begin(), vec_node_ids.end(), edge.getNodeIndex(j)); if (itr != vec_node_ids.end()) + { edge_node_distances.push_back(std::distance(vec_node_ids.begin(), itr)); + } else + { break; + } } return (j==edge.getNumberOfBaseNodes()); } @@ -127,7 +139,10 @@ MeshLib::Element* BoundaryElementsAlongPolyline::modifyEdgeNodeOrdering( new_nodes[2] = const_cast<MeshLib::Node*>(e->getNode(2)); } else - OGS_FATAL("Not implemented for element type %s", typeid(edge).name()); + { + OGS_FATAL("Not implemented for element type %s", + typeid(edge).name()); + } return edge.clone(new_nodes, edge.getID()); } diff --git a/MeshGeoToolsLib/BoundaryElementsAtPoint.cpp b/MeshGeoToolsLib/BoundaryElementsAtPoint.cpp index 588219f3ea1a3a9f754993aac7be44cd40d6652f..8f65f65cc05e5703c49f493a1b4a9101380d862a 100644 --- a/MeshGeoToolsLib/BoundaryElementsAtPoint.cpp +++ b/MeshGeoToolsLib/BoundaryElementsAtPoint.cpp @@ -26,16 +26,20 @@ BoundaryElementsAtPoint::BoundaryElementsAtPoint( { auto const node_ids = mshNodeSearcher.getMeshNodeIDs(_point); if (node_ids.empty()) + { OGS_FATAL( "BoundaryElementsAtPoint: the mesh node searcher was unable to " "locate the point (%f, %f, %f) in the mesh.", _point[0], _point[1], _point[2]); + } if (node_ids.size() > 1) + { OGS_FATAL( "BoundaryElementsAtPoint: the mesh node searcher found %d points " "near the requested point (%f, %f, %f) in the mesh, while exactly " "one is expected.", node_ids.size(), _point[0], _point[1], _point[2]); + } std::array<MeshLib::Node*, 1> const nodes = {{ const_cast<MeshLib::Node*>(_mesh.getNode(node_ids[0]))}}; @@ -46,6 +50,8 @@ BoundaryElementsAtPoint::BoundaryElementsAtPoint( BoundaryElementsAtPoint::~BoundaryElementsAtPoint() { for (auto p : _boundary_elements) + { delete p; + } } } // namespace MeshGeoToolsLib diff --git a/MeshGeoToolsLib/BoundaryElementsOnSurface.cpp b/MeshGeoToolsLib/BoundaryElementsOnSurface.cpp index bc5e83d5b74414bd694d3655b6f4045dcd442ffe..35101d38f873c9072c4e41fc5e9de3abe11c3da6 100644 --- a/MeshGeoToolsLib/BoundaryElementsOnSurface.cpp +++ b/MeshGeoToolsLib/BoundaryElementsOnSurface.cpp @@ -34,17 +34,24 @@ BoundaryElementsOnSurface::BoundaryElementsOnSurface( auto* e = _mesh.getElement(ele_id); // skip internal elements if (!e->isBoundaryElement()) + { continue; + } // find faces on surface for (unsigned i=0; i<e->getNumberOfFaces(); i++) { auto* face = e->getFace(i); // check std::size_t cnt_match = 0; for (std::size_t j=0; j<face->getNumberOfBaseNodes(); j++) { - if (std::find(node_ids_on_sfc.begin(), node_ids_on_sfc.end(), face->getNodeIndex(j)) != node_ids_on_sfc.end()) + if (std::find(node_ids_on_sfc.begin(), node_ids_on_sfc.end(), + face->getNodeIndex(j)) != node_ids_on_sfc.end()) + { cnt_match++; + } else + { break; + } } // update the list if (cnt_match==face->getNumberOfBaseNodes()) @@ -52,7 +59,9 @@ BoundaryElementsOnSurface::BoundaryElementsOnSurface( _boundary_elements.push_back(const_cast<MeshLib::Element*>(face)); } else + { delete face; + } } } } @@ -60,7 +69,9 @@ BoundaryElementsOnSurface::BoundaryElementsOnSurface( BoundaryElementsOnSurface::~BoundaryElementsOnSurface() { for (auto p : _boundary_elements) + { delete p; + } } } // end namespace MeshGeoToolsLib diff --git a/MeshGeoToolsLib/BoundaryElementsSearcher.cpp b/MeshGeoToolsLib/BoundaryElementsSearcher.cpp index 0237dd85da82e860c812fb3086e60db1851e080a..58d7f133bd84710a613da3bbed8cd65eaf8708dc 100644 --- a/MeshGeoToolsLib/BoundaryElementsSearcher.cpp +++ b/MeshGeoToolsLib/BoundaryElementsSearcher.cpp @@ -33,11 +33,17 @@ BoundaryElementsSearcher::BoundaryElementsSearcher( BoundaryElementsSearcher::~BoundaryElementsSearcher() { for (auto p : _boundary_elements_at_point) + { delete p; + } for (auto p : _boundary_elements_along_polylines) + { delete p; + } for (auto p : _boundary_elements_along_surfaces) + { delete p; + } } std::vector<MeshLib::Element*> const& BoundaryElementsSearcher::getBoundaryElements(GeoLib::GeoObject const& geoObj) @@ -65,7 +71,9 @@ BoundaryElementsSearcher::getBoundaryElementsAtPoint(GeoLib::Point const& point) for (auto const& boundaryElements : _boundary_elements_at_point) { if (boundaryElements->getPoint() == point) + { return boundaryElements->getBoundaryElements(); + } } // create new boundary elements at points. diff --git a/MeshGeoToolsLib/GeoMapper.cpp b/MeshGeoToolsLib/GeoMapper.cpp index 8881fcb06e8c1246cd28ef2f51700d448649ab13..21ebfc6da48969869f5bbd8185d227ff5bd39287 100644 --- a/MeshGeoToolsLib/GeoMapper.cpp +++ b/MeshGeoToolsLib/GeoMapper.cpp @@ -76,10 +76,14 @@ void GeoMapper::mapOnMesh(MeshLib::Mesh const*const mesh) // the variable _surface_mesh is reused below, so first the existing // _surface_mesh has to be cleaned up if (_surface_mesh) + { delete _surface_mesh; + } - if (mesh->getDimension()<3) + if (mesh->getDimension() < 3) + { _surface_mesh = new MeshLib::Mesh(*mesh); + } else { const MathLib::Vector3 dir(0,0,-1); @@ -139,7 +143,9 @@ void GeoMapper::mapStationData(std::vector<GeoLib::Point*> const& points) : getDemElevation(*pnt); if (!GeoLib::isBorehole(pnt)) + { continue; + } auto const& layers = static_cast<GeoLib::StationBorehole*>(pnt)->getProfile(); for (auto * layer_pnt : layers) { (*layer_pnt)[2] = (*layer_pnt)[2] + offset; @@ -168,9 +174,13 @@ void GeoMapper::mapPointDataToMeshSurface(std::vector<GeoLib::Point*> const& pnt // projected onto the y-x plane GeoLib::Point &p(*pnt); if (p[0] < aabb.getMinPoint()[0] || aabb.getMaxPoint()[0] < p[0]) + { continue; + } if (p[1] < aabb.getMinPoint()[1] || aabb.getMaxPoint()[1] < p[1]) + { continue; + } p[2] = getMeshElevation(p[0], p[1], min_val, max_val); } @@ -179,8 +189,11 @@ void GeoMapper::mapPointDataToMeshSurface(std::vector<GeoLib::Point*> const& pnt float GeoMapper::getDemElevation(GeoLib::Point const& pnt) const { double const elevation (_raster->getValueAtPoint(pnt)); - if (std::abs(elevation-_raster->getHeader().no_data) < std::numeric_limits<double>::epsilon()) + if (std::abs(elevation - _raster->getHeader().no_data) < + std::numeric_limits<double>::epsilon()) + { return 0.0; + } return static_cast<float>(elevation); } @@ -197,20 +210,26 @@ double GeoMapper::getMeshElevation( { if (intersection == nullptr && element->getGeomType() != MeshLib::MeshElemType::LINE) + { intersection = GeoLib::triangleLineIntersection( *element->getNode(0), *element->getNode(1), *element->getNode(2), GeoLib::Point(x, y, max_val), GeoLib::Point(x, y, min_val)); + } if (intersection == nullptr && element->getGeomType() == MeshLib::MeshElemType::QUAD) + { intersection = GeoLib::triangleLineIntersection( *element->getNode(0), *element->getNode(2), *element->getNode(3), GeoLib::Point(x, y, max_val), GeoLib::Point(x, y, min_val)); + } } if (intersection) + { return (*intersection)[2]; + } // if something goes wrong, simply take the elevation of the nearest mesh node return (*(_surface_mesh->getNode(pnt->getID())))[2]; } @@ -267,7 +286,9 @@ static std::vector<MathLib::Point3d> computeElementSegmentIntersections( std::vector<MathLib::Point3d> const intersections( GeoLib::lineSegmentIntersect2d(segment, elem_segment)); for (auto const& p : intersections) + { element_intersections.push_back(std::move(p)); + } } return element_intersections; } @@ -283,9 +304,10 @@ static std::vector<GeoLib::LineSegment> createSubSegmentsForElement( std::stringstream out; out << "element with id " << elem->getID() << " and seg " << " intersecting at more than two edges\n"; - for (std::size_t k(0); k<intersections.size(); ++k) - out << k << " " << intersections[k] - << "\n"; + for (std::size_t k(0); k < intersections.size(); ++k) + { + out << k << " " << intersections[k] << "\n"; + } out << "Could not map segment on element. Aborting.\n"; OGS_FATAL("%s", out.str().c_str()); } @@ -297,9 +319,11 @@ static std::vector<GeoLib::LineSegment> createSubSegmentsForElement( // added. if (MathLib::sqrDist(beg_pnt, intersections[0]) > std::numeric_limits<double>::epsilon()) + { sub_segments.emplace_back(new GeoLib::Point{beg_pnt, 0}, new GeoLib::Point{intersections[0], 0}, true); + } } if (intersections.size() == 1 && elem == end_elem) @@ -309,8 +333,10 @@ static std::vector<GeoLib::LineSegment> createSubSegmentsForElement( // added. if (MathLib::sqrDist(end_pnt, intersections[0]) > std::numeric_limits<double>::epsilon()) + { sub_segments.emplace_back(new GeoLib::Point{intersections[0], 0}, new GeoLib::Point{end_pnt, 0}, true); + } } if (intersections.size() == 1 && (elem != beg_elem && elem != end_elem)) @@ -344,7 +370,9 @@ static std::vector<GeoLib::LineSegment> mapLineSegment( std::vector<MathLib::Point3d> element_intersections( computeElementSegmentIntersections(*elem, segment)); if (element_intersections.empty()) + { continue; + } BaseLib::makeVectorUnique(element_intersections); @@ -470,11 +498,15 @@ static void insertSubSegments( auto const begin_id(points.push_back( new GeoLib::Point(segment.getBeginPoint(), points.size()))); if (ply.insertPoint(j + new_pnts_cnt + 1, begin_id)) + { new_pnts_cnt++; + } auto const end_id(points.push_back( new GeoLib::Point(segment.getEndPoint(), points.size()))); if (ply.insertPoint(j + new_pnts_cnt + 1, end_id)) + { new_pnts_cnt++; + } } segment_it += new_pnts_cnt; } @@ -496,7 +528,9 @@ static void mapPolylineOnSurfaceMesh( if (elem) { if (!snapPointToElementNode(p, *elem, 1e-3)) + { mapPointOnSurfaceElement(*elem, p); + } } return elem; }; @@ -527,7 +561,9 @@ static void mapPolylineOnSurfaceMesh( *segment_it, candidate_elements, beg_elem, end_elem)); if (sub_segments.empty()) + { continue; + } // The case sub_segment.size() == 1 is already handled above. @@ -542,7 +578,9 @@ void GeoMapper::advancedMapOnMesh(MeshLib::Mesh const& mesh) { // 1. extract surface if (_surface_mesh) + { delete _surface_mesh; + } if (mesh.getDimension()<3) { _surface_mesh = new MeshLib::Mesh(mesh); } else { diff --git a/MeshGeoToolsLib/HeuristicSearchLength.cpp b/MeshGeoToolsLib/HeuristicSearchLength.cpp index d629706a57e75b26fab0b89df4c73586fc268c72..ae9e5a221dfa04f7a60900e91f4265230f9c29ac 100644 --- a/MeshGeoToolsLib/HeuristicSearchLength.cpp +++ b/MeshGeoToolsLib/HeuristicSearchLength.cpp @@ -59,10 +59,14 @@ HeuristicSearchLength::HeuristicSearchLength(MeshLib::Mesh const& mesh, LengthTy _search_length = mean/2; if (variance > 0) { - if (variance < mean*mean/4) + if (variance < mean * mean / 4) + { _search_length -= std::sqrt(variance); + } else + { _search_length = std::numeric_limits<double>::epsilon(); + } } DBUG( diff --git a/MeshGeoToolsLib/MeshEditing/MarkNodesOutsideOfPolygon.h b/MeshGeoToolsLib/MeshEditing/MarkNodesOutsideOfPolygon.h index ff78efe45158ba539f7b0794292a4869a2bd2840..b5ed5f882fa802ce23020cfeb2f9fcad1fc31a5a 100644 --- a/MeshGeoToolsLib/MeshEditing/MarkNodesOutsideOfPolygon.h +++ b/MeshGeoToolsLib/MeshEditing/MarkNodesOutsideOfPolygon.h @@ -33,7 +33,9 @@ std::vector<bool> markNodesOutSideOfPolygon( // 1 copy all mesh nodes to GeoLib::Points std::vector<GeoLib::Point*> rotated_nodes; for (auto node : nodes) + { rotated_nodes.push_back(new GeoLib::Point(*node, node->getID())); + } // 2 rotate the Points MathLib::DenseMatrix<double> rot_mat(3,3); GeoLib::computeRotationMatrixToXY(normal, rot_mat); @@ -51,16 +53,20 @@ std::vector<bool> markNodesOutSideOfPolygon( } } - for (auto & rotated_node : rotated_nodes) + for (auto& rotated_node : rotated_nodes) + { delete rotated_node; + } std::vector<GeoLib::Point*> & rot_polygon_pnts( const_cast<std::vector<GeoLib::Point*> &>( rot_polygon.getPointsVec() ) ); - for (auto & rot_polygon_pnt : rot_polygon_pnts) + for (auto& rot_polygon_pnt : rot_polygon_pnts) + { delete rot_polygon_pnt; + } return outside; } diff --git a/MeshGeoToolsLib/MeshNodeSearcher.cpp b/MeshGeoToolsLib/MeshNodeSearcher.cpp index a1cd2e97e6b091e6795d730f3b9ccd730ae68724..561779b63faa1ebeef4de56d406ed2867253a0e5 100644 --- a/MeshGeoToolsLib/MeshNodeSearcher.cpp +++ b/MeshGeoToolsLib/MeshNodeSearcher.cpp @@ -47,11 +47,17 @@ MeshNodeSearcher::MeshNodeSearcher( MeshNodeSearcher::~MeshNodeSearcher() { for (auto pointer : _mesh_nodes_on_points) + { delete pointer; + } for (auto pointer : _mesh_nodes_along_polylines) + { delete pointer; + } for (auto pointer : _mesh_nodes_along_surfaces) + { delete pointer; + } } std::vector<std::size_t> MeshNodeSearcher::getMeshNodeIDs( @@ -191,8 +197,10 @@ MeshNodeSearcher const& MeshNodeSearcher::getMeshNodeSearcher( std::unique_ptr<MeshGeoToolsLib::SearchLength>&& search_length_algorithm) { std::size_t const mesh_id = mesh.getID(); - if (_mesh_node_searchers.size() < mesh_id+1) - _mesh_node_searchers.resize(mesh_id+1); + if (_mesh_node_searchers.size() < mesh_id + 1) + { + _mesh_node_searchers.resize(mesh_id + 1); + } if (_mesh_node_searchers[mesh_id]) { diff --git a/MeshGeoToolsLib/MeshNodesAlongSurface.cpp b/MeshGeoToolsLib/MeshNodesAlongSurface.cpp index 23f3e5a4a8f04776c07f412e11a785bb2e22ab29..7d5ca05b4c425688533673b009535e658d5931f1 100644 --- a/MeshGeoToolsLib/MeshNodesAlongSurface.cpp +++ b/MeshGeoToolsLib/MeshNodesAlongSurface.cpp @@ -36,7 +36,9 @@ MeshNodesAlongSurface::MeshNodesAlongSurface(MeshLib::Mesh const& mesh, for (std::size_t i = 0; i < n_nodes; i++) { auto* node = mesh_nodes[i]; if (!sfc.isPntInBoundingVolume(*node, epsilon_radius)) + { continue; + } if (sfc.isPntInSfc(*node, epsilon_radius)) { _msh_node_ids.push_back(node->getID()); } diff --git a/MeshGeoToolsLib/MeshNodesOnPoint.cpp b/MeshGeoToolsLib/MeshNodesOnPoint.cpp index f8f56b5bfebaf7ed4c18adbc9d80f2c505fb8c3a..b530f08ad18cf1861b0181078cb9be027e177f43 100644 --- a/MeshGeoToolsLib/MeshNodesOnPoint.cpp +++ b/MeshGeoToolsLib/MeshNodesOnPoint.cpp @@ -20,11 +20,18 @@ MeshNodesOnPoint::MeshNodesOnPoint( { std::vector<std::size_t> vec_ids(mesh_grid.getPointsInEpsilonEnvironment(pnt, epsilon_radius)); if (search_all_nodes == SearchAllNodes::Yes) + { _msh_node_ids = vec_ids; - else { + } + else + { for (auto id : vec_ids) + { if (mesh.isBaseNode(id)) + { _msh_node_ids.push_back(id); + } + } } } diff --git a/MeshLib/CoordinateSystem.cpp b/MeshLib/CoordinateSystem.cpp index c018788fb2726052770a95047502716967073875..bd0d8e04d7a68bab211e8cfce060b34f43457185 100644 --- a/MeshLib/CoordinateSystem.cpp +++ b/MeshLib/CoordinateSystem.cpp @@ -21,12 +21,18 @@ CoordinateSystem::CoordinateSystem(const Element &ele) if (bboxCoordSys.getDimension() >= ele.getDimension()) { _type = bboxCoordSys.getType(); } else { // e.g. zero volume elements - if (ele.getDimension()>=1) + if (ele.getDimension() >= 1) + { _type = CoordinateSystemType::X; - if (ele.getDimension()>=2) + } + if (ele.getDimension() >= 2) + { _type |= CoordinateSystemType::Y; - if (ele.getDimension()==3) + } + if (ele.getDimension() == 3) + { _type |= CoordinateSystemType::Z; + } } } @@ -40,11 +46,17 @@ unsigned char CoordinateSystem::getCoordinateSystem(const GeoLib::AABB &bbox) co // Therefore, the difference between the particular coordinates of the // points is modified by the unit in the last place towards zero. if (std::nexttoward(std::abs(pt_diff[0]), 0.0) > .0) + { coords |= CoordinateSystemType::X; + } if (std::nexttoward(std::abs(pt_diff[1]), 0.0) > .0) + { coords |= CoordinateSystemType::Y; + } if (std::nexttoward(std::abs(pt_diff[2]), 0.0) > .0) + { coords |= CoordinateSystemType::Z; + } return coords; } diff --git a/MeshLib/ElementCoordinatesMappingLocal.cpp b/MeshLib/ElementCoordinatesMappingLocal.cpp index bd98db7fdd23ed2b6dc0d269a4a8981f1f250c9b..a0241ba4b54a5557d5d0c757949221a25d0c12bb 100644 --- a/MeshLib/ElementCoordinatesMappingLocal.cpp +++ b/MeshLib/ElementCoordinatesMappingLocal.cpp @@ -26,7 +26,9 @@ void rotateToLocal(const MeshLib::RotationMatrix& matR2local, std::vector<MathLib::Point3d>& points) { for (auto& p : points) + { p = matR2local * p; + } } /// get a rotation matrix to the global coordinates @@ -44,9 +46,13 @@ void getRotationMatrixToGlobal(const unsigned element_dimension, MathLib::Vector3 xx(points[0], points[1]); xx.normalize(); if (global_dim == 2) + { GeoLib::compute2DRotationMatrixToX(xx, matR); + } else + { GeoLib::compute3DRotationMatrixToX(xx, matR); + } matR.transposeInPlace(); } else if (global_dim == 3 && element_dimension == 2) @@ -72,8 +78,10 @@ ElementCoordinatesMappingLocal::ElementCoordinatesMappingLocal( { assert(e.getDimension() <= global_dim); _points.reserve(e.getNumberOfNodes()); - for(unsigned i = 0; i < e.getNumberOfNodes(); i++) + for (unsigned i = 0; i < e.getNumberOfNodes(); i++) + { _points.emplace_back(*(e.getNode(i))); + } auto const element_dim = e.getDimension(); diff --git a/MeshLib/ElementStatus.cpp b/MeshLib/ElementStatus.cpp index 0b56d5661a8ab66bbf9dbf76c286da0fa34267f3..29bdff5e67e7b4c40ed63d2ac465add2a413a3b7 100644 --- a/MeshLib/ElementStatus.cpp +++ b/MeshLib/ElementStatus.cpp @@ -27,7 +27,9 @@ ElementStatus::ElementStatus(Mesh const* const mesh, bool hasAnyInactive) { const std::vector<MeshLib::Node*>& nodes(_mesh->getNodes()); for (auto node : nodes) + { _active_nodes.push_back(node->getNumberOfElements()); + } } ElementStatus::ElementStatus(Mesh const* const mesh, @@ -49,15 +51,25 @@ ElementStatus::ElementStatus(Mesh const* const mesh, _vec_active_eles.reserve(getNumberOfActiveElements()); const std::size_t nElems (_mesh->getNumberOfElements()); - for (std::size_t i=0; i<nElems; ++i) + for (std::size_t i = 0; i < nElems; ++i) + { if (_element_status[i]) - _vec_active_eles.push_back(const_cast<MeshLib::Element*>(_mesh->getElement(i))); + { + _vec_active_eles.push_back( + const_cast<MeshLib::Element*>(_mesh->getElement(i))); + } + } _vec_active_nodes.reserve(this->getNumberOfActiveNodes()); const std::size_t nNodes (_mesh->getNumberOfNodes()); - for (std::size_t i=0; i<nNodes; ++i) - if (_active_nodes[i]>0) - _vec_active_nodes.push_back(const_cast<MeshLib::Node*>(_mesh->getNode(i))); + for (std::size_t i = 0; i < nNodes; ++i) + { + if (_active_nodes[i] > 0) + { + _vec_active_nodes.push_back( + const_cast<MeshLib::Node*>(_mesh->getNode(i))); + } + } DBUG( "Deactivated %d materials and resulting active %d nodes and %d " @@ -70,7 +82,9 @@ ElementStatus::ElementStatus(Mesh const* const mesh, std::vector<MeshLib::Element*> const& ElementStatus::getActiveElements() const { if (_hasAnyInactive) + { return _vec_active_eles; + } return _mesh->getElements(); } @@ -78,7 +92,9 @@ std::vector<MeshLib::Element*> const& ElementStatus::getActiveElements() const std::vector<MeshLib::Node*> const& ElementStatus::getActiveNodes() const { if (_hasAnyInactive) + { return _vec_active_nodes; + } return _mesh->getNodes(); } @@ -91,9 +107,13 @@ std::vector<MeshLib::Element*> ElementStatus::getActiveElementsAtNode(std::size_ for (auto elem : _mesh->getNode(node_id)->getElements()) { if (active_elements.size() == nActiveElements) + { return active_elements; + } if (_element_status[elem->getID()]) + { active_elements.push_back(elem); + } } return active_elements; } diff --git a/MeshLib/Elements/CellRule.cpp b/MeshLib/Elements/CellRule.cpp index 3b617588fb671c86116fc79c333db81093ce6dc5..3407bcdadd0bad7786820e71594f3283b8888ac5 100644 --- a/MeshLib/Elements/CellRule.cpp +++ b/MeshLib/Elements/CellRule.cpp @@ -32,7 +32,9 @@ bool CellRule::testElementNodeOrder(const Element* e) const double s = MathLib::scalarProduct(FaceRule::getSurfaceNormal(face), cx); delete face; if (s >= 0) + { return false; + } } return true; } diff --git a/MeshLib/Elements/Element.cpp b/MeshLib/Elements/Element.cpp index bf911e8f23e53ac26f8e9f38ae610c60443792cb..214fef1d6af9abb6bdd5c34c5a6c2298e1e6aa91 100644 --- a/MeshLib/Elements/Element.cpp +++ b/MeshLib/Elements/Element.cpp @@ -38,20 +38,24 @@ Element::~Element() void Element::setNeighbor(Element* neighbor, unsigned const face_id) { if (neighbor == this) + { return; + } this->_neighbors[face_id] = neighbor; } boost::optional<unsigned> Element::addNeighbor(Element* e) { - if (e == this || - e == nullptr || - e->getDimension() != this->getDimension()) + if (e == this || e == nullptr || e->getDimension() != this->getDimension()) + { return boost::optional<unsigned>(); + } if (this->hasNeighbor(e)) + { return boost::optional<unsigned>(); + } Node* face_nodes[3]; const unsigned nNodes (this->getNumberOfBaseNodes()); @@ -59,8 +63,10 @@ boost::optional<unsigned> Element::addNeighbor(Element* e) const Node* const* e_nodes = e->getNodes(); unsigned count(0); const unsigned dim (this->getDimension()); - for (unsigned i(0); i<nNodes; i++) - for (unsigned j(0); j<eNodes; j++) + for (unsigned i(0); i < nNodes; i++) + { + for (unsigned j(0); j < eNodes; j++) + { if (_nodes[i] == e_nodes[j]) { face_nodes[count] = _nodes[i]; @@ -71,6 +77,8 @@ boost::optional<unsigned> Element::addNeighbor(Element* e) return boost::optional<unsigned>(e->identifyFace(face_nodes)); } } + } + } return boost::optional<unsigned>(); } @@ -135,9 +143,13 @@ const Element* Element::getNeighbor(unsigned i) const unsigned Element::getNodeIDinElement(const MeshLib::Node* node) const { const unsigned nNodes (this->getNumberOfNodes()); - for (unsigned i(0); i<nNodes; i++) + for (unsigned i(0); i < nNodes; i++) + { if (node == _nodes[i]) + { return i; + } + } return std::numeric_limits<unsigned>::max(); } @@ -176,9 +188,13 @@ std::size_t Element::getNodeIndex(unsigned i) const bool Element::hasNeighbor(Element* elem) const { unsigned nNeighbors (this->getNumberOfNeighbors()); - for (unsigned i=0; i<nNeighbors; i++) - if (this->_neighbors[i]==elem) + for (unsigned i = 0; i < nNeighbors; i++) + { + if (this->_neighbors[i] == elem) + { return true; + } + } return false; } diff --git a/MeshLib/Elements/ElementErrorCode.h b/MeshLib/Elements/ElementErrorCode.h index 33d64dceea321c3cd02a5e29859ccc9ba0c40166..d3839ceebe203ba855cd17f1abd2ae0148dae88e 100644 --- a/MeshLib/Elements/ElementErrorCode.h +++ b/MeshLib/Elements/ElementErrorCode.h @@ -47,13 +47,21 @@ public: static std::string toString(const ElementErrorFlag e) { if (e == ElementErrorFlag::ZeroVolume) + { return "zero volume"; + } if (e == ElementErrorFlag::NonCoplanar) + { return "non coplanar nodes"; + } if (e == ElementErrorFlag::NonConvex) + { return "non-convex geometry"; + } if (e == ElementErrorFlag::NodeOrder) + { return "wrong node order"; + } return "nonspecified error"; } diff --git a/MeshLib/Elements/HexRule20.cpp b/MeshLib/Elements/HexRule20.cpp index fff23b23ed1e90f07561348de2665b4acc7a4037..186d083d0699dbdd732d78531a6a58c1dcc8f2fa 100644 --- a/MeshLib/Elements/HexRule20.cpp +++ b/MeshLib/Elements/HexRule20.cpp @@ -48,8 +48,10 @@ const Element* HexRule20::getFace(const Element* e, unsigned i) if (i < n_faces) { std::array<Node*, 8> nodes; - for (unsigned j=0; j<8; j++) + for (unsigned j = 0; j < 8; j++) + { nodes[j] = const_cast<Node*>(e->getNode(face_nodes[i][j])); + } return new Quad8(nodes, e->getID()); } ERR("Error in MeshLib::Element::getFace() - Index %d does not exist.", i); diff --git a/MeshLib/Elements/HexRule8.cpp b/MeshLib/Elements/HexRule8.cpp index 80f082d4599d9a3f05ea74434b014eef379058fa..3ca24117f89a285ce4b4920d2b798abd4e306bd8 100644 --- a/MeshLib/Elements/HexRule8.cpp +++ b/MeshLib/Elements/HexRule8.cpp @@ -52,8 +52,10 @@ const Element* HexRule8::getFace(const Element* e, unsigned i) if (i < n_faces) { std::array<Node*, 4> nodes; - for (unsigned j=0; j<4; j++) + for (unsigned j = 0; j < 4; j++) + { nodes[j] = const_cast<Node*>(e->getNode(face_nodes[i][j])); + } return new Quad(nodes, e->getID()); } ERR("Error in MeshLib::Element::getFace() - Index %d does not exist.", i); @@ -93,12 +95,20 @@ unsigned HexRule8::identifyFace(Node const* const* _nodes, Node* nodes[3]) for (unsigned i=0; i<6; i++) { unsigned flag(0); - for (unsigned j=0; j<4; j++) - for (unsigned k=0; k<3; k++) + for (unsigned j = 0; j < 4; j++) + { + for (unsigned k = 0; k < 3; k++) + { if (_nodes[face_nodes[i][j]] == nodes[k]) + { flag++; - if (flag==3) + } + } + } + if (flag == 3) + { return i; + } } return std::numeric_limits<unsigned>::max(); } @@ -111,7 +121,9 @@ ElementErrorCode HexRule8::validate(const Element* e) for (unsigned i=0; i<6; ++i) { if (error_code.all()) + { break; + } const MeshLib::Element* quad (e->getFace(i)); error_code |= quad->validate(); diff --git a/MeshLib/Elements/LineRule2.cpp b/MeshLib/Elements/LineRule2.cpp index b07f735d9d4fee501ec5ffc9087ad724c2393d29..bce51c7847a933ec8bc6dfb4d87186d501d88ba3 100644 --- a/MeshLib/Elements/LineRule2.cpp +++ b/MeshLib/Elements/LineRule2.cpp @@ -39,9 +39,13 @@ bool LineRule2::isPntInElement(Node const* const* nodes, unsigned LineRule2::identifyFace(Node const* const* _nodes, Node* nodes[1]) { if (nodes[0] == _nodes[0]) + { return 0; + } if (nodes[0] == _nodes[1]) + { return 1; + } return std::numeric_limits<unsigned>::max(); } diff --git a/MeshLib/Elements/PointRule1.cpp b/MeshLib/Elements/PointRule1.cpp index 2d99977118dabf0c5a3041372fa317b05ea2ad5c..9b150994edfd2a7b877460ca19dedb1f2be839d2 100644 --- a/MeshLib/Elements/PointRule1.cpp +++ b/MeshLib/Elements/PointRule1.cpp @@ -34,7 +34,9 @@ bool PointRule1::isPntInElement(Node const* const* nodes, unsigned PointRule1::identifyFace(Node const* const* _nodes, Node* nodes[1]) { if (nodes[0] == _nodes[0]) + { return 0; + } return std::numeric_limits<unsigned>::max(); } diff --git a/MeshLib/Elements/PrismRule15.cpp b/MeshLib/Elements/PrismRule15.cpp index b5f595ce86244ec9b231d2eb5d27aefecc2bfedb..abf33926aaa1fc3ff8bfd269cee883399298be3b 100644 --- a/MeshLib/Elements/PrismRule15.cpp +++ b/MeshLib/Elements/PrismRule15.cpp @@ -47,11 +47,15 @@ const Element* PrismRule15::getFace(const Element* e, unsigned i) { unsigned nFaceNodes(PrismRule15::n_face_nodes[i]); auto** nodes = new Node*[nFaceNodes]; - for (unsigned j=0; j<nFaceNodes; j++) + for (unsigned j = 0; j < nFaceNodes; j++) + { nodes[j] = const_cast<Node*>(e->getNode(face_nodes[i][j])); + } if (i == 0 || i == 4) + { return new Tri6(nodes, e->getID()); + } return new Quad8(nodes); } diff --git a/MeshLib/Elements/PrismRule6.cpp b/MeshLib/Elements/PrismRule6.cpp index 0e958401dccee5cfb39d16c8ddd55b0108bb36ca..e6ed02e3657e8af64934ba50826fa6951504dcb2 100644 --- a/MeshLib/Elements/PrismRule6.cpp +++ b/MeshLib/Elements/PrismRule6.cpp @@ -49,11 +49,15 @@ const Element* PrismRule6::getFace(const Element* e, unsigned i) { unsigned nFaceNodes(PrismRule6::n_face_nodes[i]); auto** nodes = new Node*[nFaceNodes]; - for (unsigned j=0; j<nFaceNodes; j++) + for (unsigned j = 0; j < nFaceNodes; j++) + { nodes[j] = const_cast<Node*>(e->getNode(face_nodes[i][j])); + } if (i == 0 || i == 4) + { return new Tri(nodes, e->getID()); + } return new Quad(nodes); } @@ -85,12 +89,21 @@ unsigned PrismRule6::identifyFace(Node const* const* _nodes, Node* nodes[3]) for (unsigned i=0; i<5; i++) { unsigned flag(0); - for (unsigned j=0; j<4; j++) - for (unsigned k=0; k<3; k++) - if (face_nodes[i][j] != 99 && _nodes[face_nodes[i][j]] == nodes[k]) + for (unsigned j = 0; j < 4; j++) + { + for (unsigned k = 0; k < 3; k++) + { + if (face_nodes[i][j] != 99 && + _nodes[face_nodes[i][j]] == nodes[k]) + { flag++; - if (flag==3) + } + } + } + if (flag == 3) + { return i; + } } return std::numeric_limits<unsigned>::max(); } @@ -104,9 +117,13 @@ ElementErrorCode PrismRule6::validate(const Element* e) { const auto* quad(dynamic_cast<const MeshLib::Quad*>(e->getFace(i))); if (quad) + { error_code |= quad->validate(); + } else + { error_code.set(ElementErrorFlag::NodeOrder); + } delete quad; } error_code[ElementErrorFlag::NodeOrder] = !e->testElementNodeOrder(); diff --git a/MeshLib/Elements/PyramidRule13.cpp b/MeshLib/Elements/PyramidRule13.cpp index ab4765f931eee17bb1ac63b814e8c0aa5953a003..d3a8390bf65d997f3b9397cff06f4a8b4442ed06 100644 --- a/MeshLib/Elements/PyramidRule13.cpp +++ b/MeshLib/Elements/PyramidRule13.cpp @@ -46,11 +46,15 @@ const Element* PyramidRule13::getFace(const Element* e, unsigned i) { unsigned nFaceNodes(PyramidRule13::n_face_nodes[i]); auto** nodes = new Node*[nFaceNodes]; - for (unsigned j=0; j<nFaceNodes; j++) + for (unsigned j = 0; j < nFaceNodes; j++) + { nodes[j] = const_cast<Node*>(e->getNode(face_nodes[i][j])); + } if (i < 4) + { return new Tri6(nodes, e->getID()); + } return new Quad8(nodes, e->getID()); } diff --git a/MeshLib/Elements/PyramidRule5.cpp b/MeshLib/Elements/PyramidRule5.cpp index 5f6c2b9992fa378c059a8bb406a3deb8c5488da6..292cc7a4a9c3d60ceeffd75f14a8f1fc826f11ee 100644 --- a/MeshLib/Elements/PyramidRule5.cpp +++ b/MeshLib/Elements/PyramidRule5.cpp @@ -48,11 +48,15 @@ const Element* PyramidRule5::getFace(const Element* e, unsigned i) { unsigned nFaceNodes(PyramidRule5::n_face_nodes[i]); auto** nodes = new Node*[nFaceNodes]; - for (unsigned j=0; j<nFaceNodes; j++) + for (unsigned j = 0; j < nFaceNodes; j++) + { nodes[j] = const_cast<Node*>(e->getNode(face_nodes[i][j])); + } if (i < 4) + { return new Tri(nodes, e->getID()); + } return new Quad(nodes, e->getID()); } @@ -81,12 +85,21 @@ unsigned PyramidRule5::identifyFace(Node const* const* _nodes, Node* nodes[3]) for (unsigned i=0; i<5; i++) { unsigned flag(0); - for (unsigned j=0; j<4; j++) - for (unsigned k=0; k<3; k++) - if (face_nodes[i][j] != 99 && _nodes[face_nodes[i][j]] == nodes[k]) + for (unsigned j = 0; j < 4; j++) + { + for (unsigned k = 0; k < 3; k++) + { + if (face_nodes[i][j] != 99 && + _nodes[face_nodes[i][j]] == nodes[k]) + { flag++; - if (flag==3) + } + } + } + if (flag == 3) + { return i; + } } return std::numeric_limits<unsigned>::max(); } @@ -103,7 +116,9 @@ ElementErrorCode PyramidRule5::validate(const Element* e) error_code[ElementErrorFlag::NodeOrder] = !e->testElementNodeOrder(); } else + { error_code.set(ElementErrorFlag::NodeOrder); + } delete base; return error_code; diff --git a/MeshLib/Elements/QuadRule4.cpp b/MeshLib/Elements/QuadRule4.cpp index 5b3202b3f9b2d7edf52196a064ae7fbcf23ea989..5bc4e82e39e8af77536e62d0f0678d59369048ec 100644 --- a/MeshLib/Elements/QuadRule4.cpp +++ b/MeshLib/Elements/QuadRule4.cpp @@ -45,12 +45,20 @@ unsigned QuadRule4::identifyFace(Node const* const* _nodes, Node* nodes[3]) for (unsigned i=0; i<4; i++) { unsigned flag(0); - for (unsigned j=0; j<2; j++) - for (unsigned k=0; k<2; k++) + for (unsigned j = 0; j < 2; j++) + { + for (unsigned k = 0; k < 2; k++) + { if (_nodes[edge_nodes[i][j]] == nodes[k]) + { flag++; - if (flag==2) + } + } + } + if (flag == 2) + { return i; + } } return std::numeric_limits<unsigned>::max(); } @@ -65,11 +73,13 @@ ElementErrorCode QuadRule4::validate(const Element* e) // for collapsed quads (i.e. reduced to a line) this test might result // "false" as all four points are actually located on a line. if (!error_code[ElementErrorFlag::ZeroVolume]) + { error_code[ElementErrorFlag::NonConvex] = (!(MathLib::dividedByPlane( *_nodes[0], *_nodes[2], *_nodes[1], *_nodes[3]) && MathLib::dividedByPlane( *_nodes[1], *_nodes[3], *_nodes[0], *_nodes[2]))); + } error_code[ElementErrorFlag::NodeOrder] = !e->testElementNodeOrder(); return error_code; } diff --git a/MeshLib/Elements/TemplateElement-impl.h b/MeshLib/Elements/TemplateElement-impl.h index 7f3cc733adffdfb76a83f53021d918f516e33c1e..72114bb14f1717e078f570ff1fde505ff72e32d9 100644 --- a/MeshLib/Elements/TemplateElement-impl.h +++ b/MeshLib/Elements/TemplateElement-impl.h @@ -38,11 +38,15 @@ TemplateElement<ELEMENT_RULE>::TemplateElement(const TemplateElement &e) : Element(e.getID()) { this->_nodes = new Node*[n_all_nodes]; - for (unsigned i=0; i<n_all_nodes; i++) + for (unsigned i = 0; i < n_all_nodes; i++) + { this->_nodes[i] = e._nodes[i]; + } this->_neighbors = new Element*[getNumberOfNeighbors()]; - for (unsigned i=0; i<getNumberOfNeighbors(); i++) + for (unsigned i = 0; i < getNumberOfNeighbors(); i++) + { this->_neighbors[i] = e._neighbors[i]; + } this->_content = e.getContent(); } @@ -53,9 +57,14 @@ namespace detail template<unsigned N> bool isEdge(unsigned const (&edge_nodes)[N], unsigned idx1, unsigned idx2) { - - if (edge_nodes[0]==idx1 && edge_nodes[1]==idx2) return true; - if (edge_nodes[1]==idx1 && edge_nodes[0]==idx2) return true; + if (edge_nodes[0] == idx1 && edge_nodes[1] == idx2) + { + return true; + } + if (edge_nodes[1] == idx1 && edge_nodes[0] == idx2) + { + return true; + } return false; } @@ -74,7 +83,10 @@ bool TemplateElement<ELEMENT_RULE>::isEdge(unsigned idx1, unsigned idx2) const { for (unsigned i(0); i<getNumberOfEdges(); i++) { - if (detail::isEdge(ELEMENT_RULE::edge_nodes[i], idx1, idx2)) return true; + if (detail::isEdge(ELEMENT_RULE::edge_nodes[i], idx1, idx2)) + { + return true; + } } return false; } diff --git a/MeshLib/Elements/TemplateElement.h b/MeshLib/Elements/TemplateElement.h index c4e2783e3dbf7fad1ebf8da47268f8d64506111b..ef7d53d33f8404747ea330e12247f175371b3c50 100644 --- a/MeshLib/Elements/TemplateElement.h +++ b/MeshLib/Elements/TemplateElement.h @@ -142,8 +142,10 @@ public: inline Node* getEdgeNode(unsigned edge_id, unsigned node_id) const override { if (getNumberOfEdges() > 0) + { return const_cast<Node*>( this->_nodes[ELEMENT_RULE::edge_nodes[edge_id][node_id]]); + } return nullptr; } diff --git a/MeshLib/Elements/TetRule10.cpp b/MeshLib/Elements/TetRule10.cpp index be50ad3bb0341beb1d06c56d5d664ebfef842e5e..cb67eeda4b118a3ec34ca0b341a6db4bc97eb1a4 100644 --- a/MeshLib/Elements/TetRule10.cpp +++ b/MeshLib/Elements/TetRule10.cpp @@ -42,8 +42,10 @@ const Element* TetRule10::getFace(const Element* e, unsigned i) if (i<n_faces) { std::array<Node*,6> nodes; - for (unsigned j=0; j<6; j++) + for (unsigned j = 0; j < 6; j++) + { nodes[j] = const_cast<Node*>(e->getNode(face_nodes[i][j])); + } return new Tri6(nodes, e->getID()); } ERR("Error in MeshLib::Element::getFace() - Index %d does not exist.", i); diff --git a/MeshLib/Elements/TetRule4.cpp b/MeshLib/Elements/TetRule4.cpp index 694dbb78d5b09a5c09d3718806c2116b0f2a73d7..dbac2ef6eebaebc5b7896e5632bb90702174349e 100644 --- a/MeshLib/Elements/TetRule4.cpp +++ b/MeshLib/Elements/TetRule4.cpp @@ -44,8 +44,10 @@ const Element* TetRule4::getFace(const Element* e, unsigned i) if (i<n_faces) { std::array<Node*,3> nodes; - for (unsigned j=0; j<3; j++) + for (unsigned j = 0; j < 3; j++) + { nodes[j] = const_cast<Node*>(e->getNode(face_nodes[i][j])); + } return new Tri(nodes, e->getID()); } ERR("Error in MeshLib::Element::getFace() - Index %d does not exist.", i); @@ -69,12 +71,20 @@ unsigned TetRule4::identifyFace(Node const* const* _nodes, Node* nodes[3]) for (unsigned i=0; i<4; i++) { unsigned flag(0); - for (unsigned j=0; j<3; j++) - for (unsigned k=0; k<3; k++) + for (unsigned j = 0; j < 3; j++) + { + for (unsigned k = 0; k < 3; k++) + { if (_nodes[face_nodes[i][j]] == nodes[k]) + { flag++; - if (flag==3) + } + } + } + if (flag == 3) + { return i; + } } return std::numeric_limits<unsigned>::max(); } diff --git a/MeshLib/Elements/TriRule3.cpp b/MeshLib/Elements/TriRule3.cpp index 0b836b16c5cb39b5081bde401536eca383d66b4f..605bafc4a8d5539ae9d9251e2266f9a049329c28 100644 --- a/MeshLib/Elements/TriRule3.cpp +++ b/MeshLib/Elements/TriRule3.cpp @@ -41,12 +41,20 @@ unsigned TriRule3::identifyFace(Node const* const* _nodes, Node* nodes[3]) for (unsigned i=0; i<3; i++) { unsigned flag(0); - for (unsigned j=0; j<2; j++) - for (unsigned k=0; k<2; k++) + for (unsigned j = 0; j < 2; j++) + { + for (unsigned k = 0; k < 2; k++) + { if (_nodes[edge_nodes[i][j]] == nodes[k]) + { flag++; - if (flag==2) + } + } + } + if (flag == 2) + { return i; + } } return std::numeric_limits<unsigned>::max(); } diff --git a/MeshLib/IO/Legacy/MeshIO.cpp b/MeshLib/IO/Legacy/MeshIO.cpp index 74d3407ba85101ef6c2fafdd664b7b1804ebbca8..a238f0a422ab1782d62a03909068a7aa2d22d09c 100644 --- a/MeshLib/IO/Legacy/MeshIO.cpp +++ b/MeshLib/IO/Legacy/MeshIO.cpp @@ -69,7 +69,9 @@ MeshLib::Mesh* MeshIO::loadMeshFromFile(const std::string& file_name) // check keywords if (line_string.find("#STOP") != std::string::npos) + { break; + } if (line_string.find("$NODES") != std::string::npos) { double x, y, z, double_dummy; @@ -87,7 +89,9 @@ MeshLib::Mesh* MeshIO::loadMeshFromFile(const std::string& file_name) nodes.push_back(node); iss >> s; if (s.find("$AREA") != std::string::npos) + { iss >> double_dummy; + } } } else if (line_string.find("$ELEMENTS") != std::string::npos) @@ -121,7 +125,9 @@ MeshLib::Mesh* MeshIO::loadMeshFromFile(const std::string& file_name) { ERR ("MeshIO::loadMeshFromFile() - File did not contain element information."); for (auto& node : nodes) + { delete node; + } return nullptr; } @@ -156,7 +162,9 @@ std::size_t MeshIO::readMaterialID(std::istream & in) const { unsigned index, material_id; if (!(in >> index >> material_id)) + { return std::numeric_limits<std::size_t>::max(); + } return material_id; } @@ -168,7 +176,9 @@ MeshLib::Element* MeshIO::readElement(std::istream& in, do { if (!(in >> elem_type_str)) + { return nullptr; + } elem_type = MeshLib::String2MeshElemType(elem_type_str); } while (elem_type == MeshLib::MeshElemType::INVALID); @@ -179,72 +189,114 @@ MeshLib::Element* MeshIO::readElement(std::istream& in, { case MeshLib::MeshElemType::LINE: { for (int i = 0; i < 2; ++i) + { if (!(in >> idx[i])) + { return nullptr; + } + } // edge_nodes array will be deleted from Line object auto** edge_nodes = new MeshLib::Node*[2]; for (unsigned k(0); k < 2; ++k) + { edge_nodes[k] = nodes[idx[k]]; + } elem = new MeshLib::Line(edge_nodes); break; } case MeshLib::MeshElemType::TRIANGLE: { for (int i = 0; i < 3; ++i) + { if (!(in >> idx[i])) + { return nullptr; + } + } auto** tri_nodes = new MeshLib::Node*[3]; for (unsigned k(0); k < 3; ++k) + { tri_nodes[k] = nodes[idx[k]]; + } elem = new MeshLib::Tri(tri_nodes); break; } case MeshLib::MeshElemType::QUAD: { for (int i = 0; i < 4; ++i) + { if (!(in >> idx[i])) + { return nullptr; + } + } auto** quad_nodes = new MeshLib::Node*[4]; for (unsigned k(0); k < 4; ++k) + { quad_nodes[k] = nodes[idx[k]]; + } elem = new MeshLib::Quad(quad_nodes); break; } case MeshLib::MeshElemType::TETRAHEDRON: { for (int i = 0; i < 4; ++i) + { if (!(in >> idx[i])) + { return nullptr; + } + } auto** tet_nodes = new MeshLib::Node*[4]; for (unsigned k(0); k < 4; ++k) + { tet_nodes[k] = nodes[idx[k]]; + } elem = new MeshLib::Tet(tet_nodes); break; } case MeshLib::MeshElemType::HEXAHEDRON: { for (int i = 0; i < 8; ++i) + { if (!(in >> idx[i])) + { return nullptr; + } + } auto** hex_nodes = new MeshLib::Node*[8]; for (unsigned k(0); k < 8; ++k) + { hex_nodes[k] = nodes[idx[k]]; + } elem = new MeshLib::Hex(hex_nodes); break; } case MeshLib::MeshElemType::PYRAMID: { for (int i = 0; i < 5; ++i) + { if (!(in >> idx[i])) + { return nullptr; + } + } auto** pyramid_nodes = new MeshLib::Node*[5]; for (unsigned k(0); k < 5; ++k) + { pyramid_nodes[k] = nodes[idx[k]]; + } elem = new MeshLib::Pyramid(pyramid_nodes); break; } case MeshLib::MeshElemType::PRISM: { for (int i = 0; i < 6; ++i) + { if (!(in >> idx[i])) + { return nullptr; + } + } auto** prism_nodes = new MeshLib::Node*[6]; for (unsigned k(0); k < 6; ++k) + { prism_nodes[k] = nodes[idx[k]]; + } elem = new MeshLib::Prism(prism_nodes); break; } @@ -309,14 +361,20 @@ void MeshIO::writeElements( out << ele_vector_size << "\n"; for (std::size_t i(0); i < ele_vector_size; ++i) { out << i << " "; - if (! material_ids) + if (!material_ids) + { out << "0 "; + } else + { out << (*material_ids)[i] << " "; + } out << this->ElemType2StringOutput(ele_vec[i]->getGeomType()) << " "; unsigned nElemNodes (ele_vec[i]->getNumberOfBaseNodes()); - for(std::size_t j = 0; j < nElemNodes; ++j) + for (std::size_t j = 0; j < nElemNodes; ++j) + { out << ele_vec[i]->getNode(j)->getID() << " "; + } out << "\n"; } } @@ -324,19 +382,33 @@ void MeshIO::writeElements( std::string MeshIO::ElemType2StringOutput(const MeshLib::MeshElemType t) const { if (t == MeshLib::MeshElemType::LINE) + { return "line"; + } if (t == MeshLib::MeshElemType::QUAD) + { return "quad"; + } if (t == MeshLib::MeshElemType::HEXAHEDRON) + { return "hex"; + } if (t == MeshLib::MeshElemType::TRIANGLE) + { return "tri"; + } if (t == MeshLib::MeshElemType::TETRAHEDRON) + { return "tet"; + } if (t == MeshLib::MeshElemType::PRISM) + { return "pris"; + } if (t == MeshLib::MeshElemType::PYRAMID) + { return "pyra"; + } return "none"; } diff --git a/MeshLib/IO/MPI_IO/PropertyVectorMetaData.h b/MeshLib/IO/MPI_IO/PropertyVectorMetaData.h index 28459a129819c41ef01036ad5ff4665677fce2c6..301a79334255d9278c1076a60478c6d7c7871b97 100644 --- a/MeshLib/IO/MPI_IO/PropertyVectorMetaData.h +++ b/MeshLib/IO/MPI_IO/PropertyVectorMetaData.h @@ -84,12 +84,16 @@ inline boost::optional<PropertyVectorMetaData> readPropertyVectorMetaData( // read the size of the name of the PropertyVector std::string::size_type s = 0; if (!is.read(reinterpret_cast<char*>(&s), sizeof(std::string::size_type))) + { return boost::optional<PropertyVectorMetaData>(); + } PropertyVectorMetaData pvmd; char *dummy = new char[s]; if (!is.read(dummy, s)) + { return boost::none; + } pvmd.property_name = std::string(dummy, s); delete [] dummy; @@ -132,12 +136,15 @@ inline boost::optional<PropertyVectorPartitionMetaData> readPropertyVectorPartitionMetaData(std::istream& is) { PropertyVectorPartitionMetaData pvpmd; - if (!is.read(reinterpret_cast<char*>(&pvpmd.offset), - sizeof(unsigned long))) + if (!is.read(reinterpret_cast<char*>(&pvpmd.offset), sizeof(unsigned long))) + { return boost::optional<PropertyVectorPartitionMetaData>(); + } if (!is.read(reinterpret_cast<char*>(&pvpmd.number_of_tuples), sizeof(unsigned long))) + { return boost::optional<PropertyVectorPartitionMetaData>(); + } return boost::optional<PropertyVectorPartitionMetaData>(pvpmd); } } // namespace IO diff --git a/MeshLib/IO/VtkIO/PVDFile.cpp b/MeshLib/IO/VtkIO/PVDFile.cpp index 7aa484d1baeae0d57dc7817cb22534dc3b8a2e6c..897b157fb39ee103ce88d65fe55bb2990b3214e2 100644 --- a/MeshLib/IO/VtkIO/PVDFile.cpp +++ b/MeshLib/IO/VtkIO/PVDFile.cpp @@ -37,7 +37,10 @@ void PVDFile::addVTUFile(const std::string &vtu_fname, double timestep) " <Collection>\n"; for (auto const& pair : _datasets) - fh << " <DataSet timestep=\"" << pair.first << "\" group=\"\" part=\"0\" file=\"" << pair.second << "\"/>\n"; + { + fh << " <DataSet timestep=\"" << pair.first + << "\" group=\"\" part=\"0\" file=\"" << pair.second << "\"/>\n"; + } fh << " </Collection>\n</VTKFile>\n"; } diff --git a/MeshLib/IO/readMeshFromFile.cpp b/MeshLib/IO/readMeshFromFile.cpp index eeccf095ff6dd63d0239ceb08b74954e7e309995..fdd4d70eec53c5434782ee34d5182f57ba2689a8 100644 --- a/MeshLib/IO/readMeshFromFile.cpp +++ b/MeshLib/IO/readMeshFromFile.cpp @@ -76,7 +76,9 @@ MeshLib::Mesh* readMeshFromFileSerial(const std::string &file_name) } if (BaseLib::hasFileExtension("vtu", file_name)) + { return MeshLib::IO::VtuInterface::readVTUFile(file_name); + } ERR("readMeshFromFile(): Unknown mesh file format in file %s.", file_name.c_str()); return nullptr; diff --git a/MeshLib/Location.h b/MeshLib/Location.h index b73b4ffe385bcdf78a7e3bc926cf5e722a390487..83b6a8fff6d93e7ea8a6268899bb01438f915a97 100644 --- a/MeshLib/Location.h +++ b/MeshLib/Location.h @@ -50,8 +50,14 @@ struct Location inline bool operator<(const Location& left, const Location& right) { - if (left.mesh_id != right.mesh_id) return left.mesh_id < right.mesh_id; - if (left.item_type != right.item_type) return left.item_type < right.item_type; + if (left.mesh_id != right.mesh_id) + { + return left.mesh_id < right.mesh_id; + } + if (left.item_type != right.item_type) + { + return left.item_type < right.item_type; + } return left.item_id < right.item_id; } diff --git a/MeshLib/Mesh.cpp b/MeshLib/Mesh.cpp index c5a3c79d7beea0b4cb02b4a8ab06d17d2a05520e..3c8ec24b80f8c3a7c984a291f33c61582613acb1 100644 --- a/MeshLib/Mesh.cpp +++ b/MeshLib/Mesh.cpp @@ -55,7 +55,9 @@ Mesh::Mesh(std::string name, recalculateMaxBaseNodeId(); } if ((_n_base_nodes == 0 && hasNonlinearElement()) || isNonlinear()) + { this->checkNonlinearNodeIDs(); + } this->setDimension(); this->setElementsConnectedToNodes(); //this->setNodesConnectedByEdges(); @@ -75,8 +77,10 @@ Mesh::Mesh(const Mesh &mesh) { const std::vector<Node*>& nodes (mesh.getNodes()); const std::size_t nNodes (nodes.size()); - for (unsigned i=0; i<nNodes; ++i) + for (unsigned i = 0; i < nNodes; ++i) + { _nodes[i] = new Node(*nodes[i]); + } const std::vector<Element*>& elements (mesh.getElements()); const std::size_t nElements (elements.size()); @@ -84,11 +88,16 @@ Mesh::Mesh(const Mesh &mesh) { const std::size_t nElemNodes = elements[i]->getNumberOfNodes(); _elements[i] = elements[i]->clone(); - for (unsigned j=0; j<nElemNodes; ++j) + for (unsigned j = 0; j < nElemNodes; ++j) + { _elements[i]->_nodes[j] = _nodes[elements[i]->getNode(j)->getID()]; + } } - if (_mesh_dimension==0) this->setDimension(); + if (_mesh_dimension == 0) + { + this->setDimension(); + } this->setElementsConnectedToNodes(); //this->setNodesConnectedByEdges(); //this->setNodesConnectedByElements(); @@ -98,12 +107,16 @@ Mesh::Mesh(const Mesh &mesh) Mesh::~Mesh() { const std::size_t nElements (_elements.size()); - for (std::size_t i=0; i<nElements; ++i) + for (std::size_t i = 0; i < nElements; ++i) + { delete _elements[i]; + } const std::size_t nNodes (_nodes.size()); - for (std::size_t i=0; i<nNodes; ++i) + for (std::size_t i = 0; i < nNodes; ++i) + { delete _nodes[i]; + } } void Mesh::addNode(Node* node) @@ -117,8 +130,10 @@ void Mesh::addElement(Element* elem) // add element information to nodes unsigned nNodes (elem->getNumberOfNodes()); - for (unsigned i=0; i<nNodes; ++i) + for (unsigned i = 0; i < nNodes; ++i) + { elem->_nodes[i]->addElement(elem); + } } void Mesh::resetNodeIDs() @@ -146,16 +161,22 @@ void Mesh::recalculateMaxBaseNodeId() void Mesh::resetElementIDs() { const std::size_t nElements (this->_elements.size()); - for (unsigned i=0; i<nElements; ++i) + for (unsigned i = 0; i < nElements; ++i) + { _elements[i]->setID(i); + } } void Mesh::setDimension() { const std::size_t nElements (_elements.size()); - for (unsigned i=0; i<nElements; ++i) + for (unsigned i = 0; i < nElements; ++i) + { if (_elements[i]->getDimension() > _mesh_dimension) + { _mesh_dimension = _elements[i]->getDimension(); + } + } } void Mesh::setElementsConnectedToNodes() @@ -163,16 +184,22 @@ void Mesh::setElementsConnectedToNodes() for (auto& element : _elements) { const unsigned nNodes(element->getNumberOfNodes()); - for (unsigned j=0; j<nNodes; ++j) + for (unsigned j = 0; j < nNodes; ++j) + { element->_nodes[j]->addElement(element); + } } } void Mesh::resetElementsConnectedToNodes() { for (auto& node : _nodes) + { if (node) + { node->clearElements(); + } + } this->setElementsConnectedToNodes(); } @@ -239,15 +266,24 @@ void Mesh::setNodesConnectedByEdges() MeshLib::Node const* node_k = conn_ele->getNode(k); bool is_in_vector (false); const std::size_t nConnNodes (conn_set.size()); - for (unsigned l(0); l<nConnNodes; ++l) + for (unsigned l(0); l < nConnNodes; ++l) + { if (node_k == conn_set[l]) + { is_in_vector = true; - if (is_in_vector) continue; + } + } + if (is_in_vector) + { + continue; + } if (conn_ele->getNumberOfBaseNodes() == conn_ele->getNumberOfNodes()) { if (conn_ele->isEdge(idx, k)) + { conn_set.push_back(const_cast<MeshLib::Node*>(node_k)); + } } else { @@ -259,13 +295,22 @@ void Mesh::setNodesConnectedByEdges() { auto edge_node = edge->getNode(m); if (edge_node == node || edge_node == node_k) + { match++; + } } if (match != 2) + { continue; + } conn_set.push_back(const_cast<MeshLib::Node*>(node_k)); - for (unsigned m=edge->getNumberOfBaseNodes(); m<edge->getNumberOfNodes(); m++) - conn_set.push_back(const_cast<MeshLib::Node*>(edge->getNode(m))); + for (unsigned m = edge->getNumberOfBaseNodes(); + m < edge->getNumberOfNodes(); + m++) + { + conn_set.push_back( + const_cast<MeshLib::Node*>(edge->getNode(m))); + } break; } } @@ -293,7 +338,9 @@ void Mesh::setNodesConnectedByElements() Node* const* const single_elem_nodes = element->getNodes(); std::size_t const nnodes = element->getNumberOfNodes(); for (std::size_t n = 0; n < nnodes; n++) + { adjacent_nodes.push_back(single_elem_nodes[n]); + } } // Make nodes unique and sorted by their ids. @@ -314,7 +361,9 @@ void Mesh::checkNonlinearNodeIDs() const for (unsigned i=e->getNumberOfBaseNodes(); i<e->getNumberOfNodes(); i++) { if (e->getNodeIndex(i) >= getNumberOfBaseNodes()) + { continue; + } WARN( "Found a nonlinear node whose ID (%d) is smaller than the " @@ -346,7 +395,9 @@ void scaleMeshPropertyVector(MeshLib::Mesh & mesh, } for (auto& v : *mesh.getProperties().getPropertyVector<double>(property_name)) + { v *= factor; + } } PropertyVector<int> const* materialIDs(Mesh const& mesh) diff --git a/MeshLib/Mesh.h b/MeshLib/Mesh.h index 1349d2a75120a8ce0e2bf742c0666ccc736616d9..44d0059239ed2f5cec76dcc62a56f4278830e7b2 100644 --- a/MeshLib/Mesh.h +++ b/MeshLib/Mesh.h @@ -212,18 +212,26 @@ void addPropertyToMesh(MeshLib::Mesh& mesh, std::string const& name, std::vector<T> const& values) { if (item_type == MeshLib::MeshItemType::Node) + { if (mesh.getNumberOfNodes() != values.size() / number_of_components) + { OGS_FATAL( "Error number of nodes (%u) does not match the number of " "tuples (%u).", mesh.getNumberOfNodes(), values.size() / number_of_components); + } + } if (item_type == MeshLib::MeshItemType::Cell) + { if (mesh.getNumberOfElements() != values.size() / number_of_components) + { OGS_FATAL( "Error number of elements (%u) does not match the number of " "tuples (%u).", mesh.getNumberOfElements(), values.size() / number_of_components); + } + } auto* const property = mesh.getProperties().createNewPropertyVector<T>( name, item_type, number_of_components); @@ -246,8 +254,10 @@ PropertyVector<T>* getOrCreateMeshProperty(Mesh& mesh, int const number_of_components) { if (property_name.empty()) + { OGS_FATAL( "Trying to get or to create a mesh property with empty name."); + } auto numberOfMeshItems = [&mesh, &item_type]() -> std::size_t { switch (item_type) diff --git a/MeshLib/MeshEditing/AddLayerToMesh.cpp b/MeshLib/MeshEditing/AddLayerToMesh.cpp index 5b80d7e719f0692c158e22812b36d4ce76fa51a4..c36313f87676da5702911f0a6fd0c1acea6614bb 100644 --- a/MeshLib/MeshEditing/AddLayerToMesh.cpp +++ b/MeshLib/MeshEditing/AddLayerToMesh.cpp @@ -50,7 +50,9 @@ MeshLib::Element* extrudeElement(std::vector<MeshLib::Node*> const& subsfc_nodes std::map<std::size_t, std::size_t> const& subsfc_sfc_id_map) { if (sfc_elem.getDimension() > 2) + { return nullptr; + } const unsigned nElemNodes(sfc_elem.getNumberOfBaseNodes()); auto new_nodes = std::unique_ptr<MeshLib::Node* []> { @@ -67,11 +69,17 @@ MeshLib::Element* extrudeElement(std::vector<MeshLib::Node*> const& subsfc_nodes } if (sfc_elem.getGeomType() == MeshLib::MeshElemType::LINE) + { return new MeshLib::Quad(new_nodes.release()); + } if (sfc_elem.getGeomType() == MeshLib::MeshElemType::TRIANGLE) + { return new MeshLib::Prism(new_nodes.release()); + } if (sfc_elem.getGeomType() == MeshLib::MeshElemType::QUAD) + { return new MeshLib::Hex(new_nodes.release()); + } return nullptr; } @@ -103,9 +111,12 @@ MeshLib::Mesh* addLayerToMesh(MeshLib::Mesh const& mesh, double thickness, std::string const prop_name("bulk_node_ids"); if (mesh.getDimension() == 3) + { sfc_mesh.reset(MeshLib::MeshSurfaceExtraction::getMeshSurface( mesh, dir, angle, prop_name)); - else { + } + else + { sfc_mesh = (on_top) ? std::make_unique<MeshLib::Mesh>(mesh) : std::unique_ptr<MeshLib::Mesh>( MeshLib::createFlippedMesh(mesh)); @@ -159,9 +170,11 @@ MeshLib::Mesh* addLayerToMesh(MeshLib::Mesh const& mesh, double thickness, // *** insert new layer elements into subsfc_mesh std::vector<MeshLib::Element*> const& sfc_elements(sfc_mesh->getElements()); std::size_t const n_sfc_elements(sfc_elements.size()); - for (std::size_t k(0); k<n_sfc_elements; ++k) + for (std::size_t k(0); k < n_sfc_elements; ++k) + { subsfc_elements.push_back(extrudeElement( subsfc_nodes, *sfc_elements[k], *node_id_pv, subsfc_sfc_id_map)); + } auto new_mesh = new MeshLib::Mesh(name, subsfc_nodes, subsfc_elements); diff --git a/MeshLib/MeshEditing/ConvertToLinearMesh.cpp b/MeshLib/MeshEditing/ConvertToLinearMesh.cpp index a1106a992c1a178c2abcf0eab0219209347ea074..06cc122804a5646865ec1f301d4e15f460eba604 100644 --- a/MeshLib/MeshEditing/ConvertToLinearMesh.cpp +++ b/MeshLib/MeshEditing/ConvertToLinearMesh.cpp @@ -35,8 +35,11 @@ T_ELEMENT* createLinearElement(MeshLib::Element const* e, { auto const n_base_nodes = T_ELEMENT::n_base_nodes; auto** nodes = new MeshLib::Node*[n_base_nodes]; - for (unsigned i=0; i<e->getNumberOfBaseNodes(); i++) - nodes[i] = const_cast<MeshLib::Node*>(vec_new_nodes[e->getNode(i)->getID()]); + for (unsigned i = 0; i < e->getNumberOfBaseNodes(); i++) + { + nodes[i] = + const_cast<MeshLib::Node*>(vec_new_nodes[e->getNode(i)->getID()]); + } return new T_ELEMENT(nodes); } @@ -93,10 +96,14 @@ std::unique_ptr<MeshLib::Mesh> convertToLinearMesh(MeshLib::Mesh const& org_mesh for (auto name : src_properties.getPropertyVectorNames()) { if (!src_properties.existsPropertyVector<double>(name)) + { continue; + } auto const* src_prop = src_properties.getPropertyVector<double>(name); if (src_prop->getMeshItemType() != MeshLib::MeshItemType::Node) + { continue; + } auto const n_src_comp = src_prop->getNumberOfComponents(); auto new_prop = @@ -108,7 +115,10 @@ std::unique_ptr<MeshLib::Mesh> convertToLinearMesh(MeshLib::Mesh const& org_mesh for (unsigned i=0; i<org_mesh.getNumberOfBaseNodes(); i++) { for (int j = 0; j < n_src_comp; j++) - (*new_prop)[i*n_src_comp+j] = (*src_prop)[i*n_src_comp+j]; + { + (*new_prop)[i * n_src_comp + j] = + (*src_prop)[i * n_src_comp + j]; + } } } diff --git a/MeshLib/MeshEditing/DuplicateMeshComponents.cpp b/MeshLib/MeshEditing/DuplicateMeshComponents.cpp index eb8a3e8ebc9999f702af049b597efbdb217b74c3..6039697280f9cc8b093a2579068b059a72f5e530 100644 --- a/MeshLib/MeshEditing/DuplicateMeshComponents.cpp +++ b/MeshLib/MeshEditing/DuplicateMeshComponents.cpp @@ -26,7 +26,10 @@ std::vector<MeshLib::Node*> copyNodeVector(const std::vector<MeshLib::Node*> &no std::vector<MeshLib::Node*> new_nodes; new_nodes.reserve(nNodes); for (std::size_t k = 0; k < nNodes; ++k) - new_nodes.push_back(new MeshLib::Node(nodes[k]->getCoords(), new_nodes.size())); + { + new_nodes.push_back( + new MeshLib::Node(nodes[k]->getCoords(), new_nodes.size())); + } return new_nodes; } @@ -36,26 +39,42 @@ std::vector<MeshLib::Element*> copyElementVector(const std::vector<MeshLib::Elem std::vector<MeshLib::Element*> new_elements; new_elements.reserve(nElements); for (std::size_t k = 0; k < nElements; ++k) + { new_elements.push_back(copyElement(elements[k], nodes)); + } return new_elements; } MeshLib::Element* copyElement(MeshLib::Element const*const element, const std::vector<MeshLib::Node*> &nodes) { if (element->getGeomType() == MeshElemType::LINE) + { return copyElement<MeshLib::Line>(element, nodes); + } if (element->getGeomType() == MeshElemType::TRIANGLE) + { return copyElement<MeshLib::Tri>(element, nodes); + } if (element->getGeomType() == MeshElemType::QUAD) + { return copyElement<MeshLib::Quad>(element, nodes); + } if (element->getGeomType() == MeshElemType::TETRAHEDRON) + { return copyElement<MeshLib::Tet>(element, nodes); + } if (element->getGeomType() == MeshElemType::HEXAHEDRON) + { return copyElement<MeshLib::Hex>(element, nodes); + } if (element->getGeomType() == MeshElemType::PYRAMID) + { return copyElement<MeshLib::Pyramid>(element, nodes); + } if (element->getGeomType() == MeshElemType::PRISM) + { return copyElement<MeshLib::Prism>(element, nodes); + } ERR ("Error: Unknown element type."); return nullptr; @@ -65,8 +84,10 @@ template <typename E> MeshLib::Element* copyElement(MeshLib::Element const*const element, const std::vector<MeshLib::Node*> &nodes) { auto** new_nodes = new MeshLib::Node*[element->getNumberOfNodes()]; - for (unsigned i=0; i<element->getNumberOfNodes(); ++i) + for (unsigned i = 0; i < element->getNumberOfNodes(); ++i) + { new_nodes[i] = nodes[element->getNode(i)->getID()]; + } return new E(new_nodes); } diff --git a/MeshLib/MeshEditing/ElementValueModification.cpp b/MeshLib/MeshEditing/ElementValueModification.cpp index 20bcd5cb2f2b44716abc20ec90a95b34574ad37a..14e81677322fb83ac0a76ff24e3f88ec99868102 100644 --- a/MeshLib/MeshEditing/ElementValueModification.cpp +++ b/MeshLib/MeshEditing/ElementValueModification.cpp @@ -62,7 +62,9 @@ bool ElementValueModification::replace(MeshLib::Mesh &mesh, for (std::size_t i = 0; i < n_property_tuples; ++i) { if ((*property_value_vec)[i] == old_value) + { (*property_value_vec)[i] = new_value; + } } return true; @@ -94,12 +96,16 @@ std::size_t ElementValueModification::condense(MeshLib::Mesh &mesh) std::vector<int> reverse_mapping(value_mapping.back() + 1, 0); std::size_t const nValues(value_mapping.size()); for (std::size_t i = 0; i < nValues; ++i) + { reverse_mapping[value_mapping[i]] = i; + } std::size_t const n_property_values(property_value_vector->size()); for (std::size_t i = 0; i < n_property_values; ++i) + { (*property_value_vector)[i] = reverse_mapping[(*property_value_vector)[i]]; + } return nValues; } @@ -123,7 +129,9 @@ std::size_t ElementValueModification::setByElementType(MeshLib::Mesh &mesh, Mesh for (std::size_t k(0); k < elements.size(); k++) { if (elements[k]->getGeomType() != ele_type) + { continue; + } (*property_value_vector)[k] = new_value; cnt++; } diff --git a/MeshLib/MeshEditing/FlipElements.cpp b/MeshLib/MeshEditing/FlipElements.cpp index 38b03b229231eab7b0c6f671b7c3e83afbaac63b..ef3f62359cc8f19c3c71f8ab48395eefc937edc8 100644 --- a/MeshLib/MeshEditing/FlipElements.cpp +++ b/MeshLib/MeshEditing/FlipElements.cpp @@ -22,20 +22,28 @@ std::unique_ptr<MeshLib::Element> createFlippedElement( MeshLib::Element const& elem, std::vector<MeshLib::Node*> const& nodes) { if (elem.getDimension() > 2) + { return nullptr; + } unsigned const n_nodes(elem.getNumberOfNodes()); auto elem_nodes = std::make_unique<MeshLib::Node* []>(n_nodes); for (unsigned i = 0; i < n_nodes; ++i) + { elem_nodes[i] = nodes[elem.getNode(i)->getID()]; + } std::swap(elem_nodes[0], elem_nodes[1]); if (elem.getGeomType() == MeshElemType::LINE) + { return std::make_unique<MeshLib::Line>(elem_nodes.release(), elem.getID()); + } if (elem.getGeomType() == MeshElemType::TRIANGLE) + { return std::make_unique<MeshLib::Tri>(elem_nodes.release(), elem.getID()); + } if (elem.getGeomType() == MeshElemType::QUAD) { std::swap(elem_nodes[2], elem_nodes[3]); @@ -48,7 +56,9 @@ std::unique_ptr<MeshLib::Element> createFlippedElement( std::unique_ptr<MeshLib::Mesh> createFlippedMesh(MeshLib::Mesh const& mesh) { if (mesh.getDimension() > 2) + { return nullptr; + } std::vector<MeshLib::Node*> new_nodes (MeshLib::copyNodeVector(mesh.getNodes())); std::vector<MeshLib::Element*> const& elems (mesh.getElements()); @@ -56,8 +66,11 @@ std::unique_ptr<MeshLib::Mesh> createFlippedMesh(MeshLib::Mesh const& mesh) std::size_t n_elems (mesh.getNumberOfElements()); new_elems.reserve(n_elems); - for (std::size_t i=0; i<n_elems; ++i) - new_elems.push_back(createFlippedElement(*elems[i], new_nodes).release()); + for (std::size_t i = 0; i < n_elems; ++i) + { + new_elems.push_back( + createFlippedElement(*elems[i], new_nodes).release()); + } return std::make_unique<MeshLib::Mesh>("FlippedElementMesh", new_nodes, new_elems, mesh.getProperties()); diff --git a/MeshLib/MeshEditing/Mesh2MeshPropertyInterpolation.cpp b/MeshLib/MeshEditing/Mesh2MeshPropertyInterpolation.cpp index 2967602299de38ca0733322fadd7be9fc28780f8..4f8c3fb5fd9f38fc023b1bb920c250fda53edf46 100644 --- a/MeshLib/MeshEditing/Mesh2MeshPropertyInterpolation.cpp +++ b/MeshLib/MeshEditing/Mesh2MeshPropertyInterpolation.cpp @@ -74,7 +74,9 @@ bool Mesh2MeshPropertyInterpolation::setPropertiesForMesh(Mesh& dest_mesh) const } } if (dest_properties->size() != dest_mesh.getNumberOfElements()) + { dest_properties->resize(dest_mesh.getNumberOfElements()); + } interpolatePropertiesForMesh(dest_mesh, *dest_properties); @@ -102,7 +104,9 @@ void Mesh2MeshPropertyInterpolation::interpolatePropertiesForMesh( { MeshLib::Element& dest_element(*dest_elements[k]); if (dest_element.getGeomType() == MeshElemType::LINE) + { continue; + } // compute axis aligned bounding box around the current element const GeoLib::AABB elem_aabb( @@ -132,10 +136,12 @@ void Mesh2MeshPropertyInterpolation::interpolatePropertiesForMesh( } if (cnt == 0) + { OGS_FATAL( "Mesh2MeshInterpolation: Could not find values in source mesh " "for the element %d.", k); + } dest_properties[k] = average_value / cnt; } } diff --git a/MeshLib/MeshEditing/MeshRevision.cpp b/MeshLib/MeshEditing/MeshRevision.cpp index cf31521da71082738e9d1186ac0227a3f8be93d7..6a7fbbe704389ed14ebdb4f986e544a0c288e062 100644 --- a/MeshLib/MeshEditing/MeshRevision.cpp +++ b/MeshLib/MeshEditing/MeshRevision.cpp @@ -49,8 +49,12 @@ unsigned MeshRevision::getNumberOfCollapsableNodes(double eps) const std::size_t nNodes(id_map.size()); unsigned count(0); for (std::size_t i = 0; i < nNodes; ++i) + { if (i != id_map[i]) + { count++; + } + } return count; } @@ -58,7 +62,9 @@ MeshLib::Mesh* MeshRevision::simplifyMesh(const std::string &new_mesh_name, double eps, unsigned min_elem_dim) { if (this->_mesh.getNumberOfElements() == 0) + { return nullptr; + } // original data std::vector<MeshLib::Element*> const& elements(this->_mesh.getElements()); @@ -96,14 +102,18 @@ MeshLib::Mesh* MeshRevision::simplifyMesh(const std::string &new_mesh_name, return nullptr; } if (material_vec) + { new_material_vec->insert(new_material_vec->end(), n_new_elements, (*material_vec)[k]); + } } else { new_elements.push_back(MeshLib::copyElement(elem, new_nodes)); // copy material values if (material_vec) + { new_material_vec->push_back((*material_vec)[k]); + } } } else if (n_unique_nodes < elem->getNumberOfBaseNodes() && n_unique_nodes>1) { @@ -111,7 +121,9 @@ MeshLib::Mesh* MeshRevision::simplifyMesh(const std::string &new_mesh_name, elem, n_unique_nodes, new_nodes, new_elements, min_elem_dim) ); if (!material_vec) + { continue; + } new_material_vec->insert(new_material_vec->end(), n_new_elements, (*material_vec)[k]); } else @@ -120,8 +132,10 @@ MeshLib::Mesh* MeshRevision::simplifyMesh(const std::string &new_mesh_name, this->resetNodeIDs(); if (!new_elements.empty()) - return new MeshLib::Mesh( - new_mesh_name, new_nodes, new_elements, new_properties); + { + return new MeshLib::Mesh(new_mesh_name, new_nodes, new_elements, + new_properties); + } this->cleanUp(new_nodes, new_elements); return nullptr; @@ -130,7 +144,9 @@ MeshLib::Mesh* MeshRevision::simplifyMesh(const std::string &new_mesh_name, MeshLib::Mesh* MeshRevision::subdivideMesh(const std::string &new_mesh_name) const { if (this->_mesh.getNumberOfElements() == 0) + { return nullptr; + } // original data std::vector<MeshLib::Element*> const& elements(this->_mesh.getElements()); @@ -163,20 +179,26 @@ MeshLib::Mesh* MeshRevision::subdivideMesh(const std::string &new_mesh_name) con } // copy material values if (!material_vec) + { continue; + } new_material_vec->insert(new_material_vec->end(), n_new_elements, (*material_vec)[k]); } else { new_elements.push_back(MeshLib::copyElement(elem, new_nodes)); // copy material values if (material_vec) + { new_material_vec->push_back((*material_vec)[k]); + } } } if (!new_elements.empty()) - return new MeshLib::Mesh( - new_mesh_name, new_nodes, new_elements, new_properties); + { + return new MeshLib::Mesh(new_mesh_name, new_nodes, new_elements, + new_properties); + } this->cleanUp(new_nodes, new_elements); return nullptr; @@ -197,7 +219,9 @@ std::vector<std::size_t> MeshRevision::collapseNodeIndices(double eps) const { MeshLib::Node const*const node(nodes[k]); if (node->getID() != k) + { continue; + } std::vector<std::vector<MeshLib::Node*> const*> node_vectors( grid.getPntVecsOfGridCellsIntersectingCube(*node, half_eps)); @@ -211,16 +235,23 @@ std::vector<std::size_t> MeshRevision::collapseNodeIndices(double eps) const MeshLib::Node const*const test_node(cell_vector[j]); // are node indices already identical (i.e. nodes will be collapsed) if (id_map[node->getID()] == id_map[test_node->getID()]) + { continue; + } // if test_node has already been collapsed to another node x, ignore it // (if the current node would need to be collapsed with x it would already have happened when x was tested) if (test_node->getID() != id_map[test_node->getID()]) + { continue; + } // calc distance - if (MathLib::sqrDist(node->getCoords(), test_node->getCoords()) < sqr_eps) + if (MathLib::sqrDist(node->getCoords(), + test_node->getCoords()) < sqr_eps) + { id_map[test_node->getID()] = node->getID(); + } } } } @@ -244,7 +275,9 @@ std::vector<MeshLib::Node*> MeshRevision::constructNewNodesArray(const std::vect } // the other nodes are not copied and get the index of the nodes they will have been collapsed with else + { nodes[k]->setID(nodes[id_map[k]]->getID()); + } } return new_nodes; } @@ -255,12 +288,16 @@ unsigned MeshRevision::getNumberOfUniqueNodes(MeshLib::Element const*const eleme unsigned count(nNodes); for (unsigned i = 0; i < nNodes - 1; ++i) + { for (unsigned j = i + 1; j < nNodes; ++j) + { if (element->getNode(i)->getID() == element->getNode(j)->getID()) { count--; break; } + } + } return count; } @@ -269,7 +306,9 @@ void MeshRevision::resetNodeIDs() const std::size_t nNodes(this->_mesh.getNumberOfNodes()); const std::vector<MeshLib::Node*> &nodes(_mesh.getNodes()); for (std::size_t i = 0; i < nNodes; ++i) + { nodes[i]->setID(i); + } } std::size_t MeshRevision::subdivideElement( @@ -278,13 +317,21 @@ std::size_t MeshRevision::subdivideElement( std::vector<MeshLib::Element*> & elements) const { if (element->getGeomType() == MeshElemType::QUAD) + { return this->subdivideQuad(element, nodes, elements); + } if (element->getGeomType() == MeshElemType::HEXAHEDRON) + { return this->subdivideHex(element, nodes, elements); + } if (element->getGeomType() == MeshElemType::PYRAMID) + { return this->subdividePyramid(element, nodes, elements); + } if (element->getGeomType() == MeshElemType::PRISM) + { return this->subdividePrism(element, nodes, elements); + } return 0; } @@ -306,9 +353,13 @@ std::size_t MeshRevision::reduceElement(MeshLib::Element const*const element, (element->getGeomType() == MeshElemType::TETRAHEDRON)) { if (n_unique_nodes == 3 && min_elem_dim < 3) + { elements.push_back (this->constructTri(element, nodes)); + } else if (min_elem_dim == 1) - elements.push_back (this->constructLine(element, nodes)); + { + elements.push_back(this->constructLine(element, nodes)); + } return 1; } if (element->getGeomType() == MeshElemType::HEXAHEDRON) @@ -434,8 +485,10 @@ unsigned MeshRevision::reduceHex(MeshLib::Element const*const org_elem, if (n_unique_nodes == 7) { // reduce to prism + pyramid - for (unsigned i=0; i<7; ++i) - for (unsigned j=i+1; j<8; ++j) + for (unsigned i = 0; i < 7; ++i) + { + for (unsigned j = i + 1; j < 8; ++j) + { if (org_elem->getNode(i)->getID() == org_elem->getNode(j)->getID()) { const std::array<unsigned,4> base_nodes (this->lutHexCuttingQuadNodes(i,j)); @@ -447,7 +500,10 @@ unsigned MeshRevision::reduceHex(MeshLib::Element const*const org_elem, pyr_nodes[4] = nodes[org_elem->getNode(i)->getID()]; new_elements.push_back (new MeshLib::Pyramid(pyr_nodes)); - if (i<4 && j>=4) std::swap(i,j); + if (i < 4 && j >= 4) + { + std::swap(i, j); + } auto** prism_nodes = new MeshLib::Node*[6]; prism_nodes[0] = nodes[org_elem->getNode(base_nodes[0])->getID()]; prism_nodes[1] = nodes[org_elem->getNode(base_nodes[3])->getID()]; @@ -458,6 +514,8 @@ unsigned MeshRevision::reduceHex(MeshLib::Element const*const org_elem, new_elements.push_back (new MeshLib::Prism(prism_nodes)); return 2; } + } + } } else if (n_unique_nodes == 6) { @@ -494,12 +552,16 @@ unsigned MeshRevision::reduceHex(MeshLib::Element const*const org_elem, delete face; } // reduce to four tets -> divide into 2 prisms such that each has one collapsed node - for (unsigned i=0; i<7; ++i) - for (unsigned j=i+1; j<8; ++j) + for (unsigned i = 0; i < 7; ++i) + { + for (unsigned j = i + 1; j < 8; ++j) + { if (org_elem->getNode(i)->getID() == org_elem->getNode(j)->getID()) { - for (unsigned k=i; k<7; ++k) - for (unsigned l=k+1; l<8; ++l) + for (unsigned k = i; k < 7; ++k) + { + for (unsigned l = k + 1; l < 8; ++l) + { if (!(i==k && j==l) && org_elem->isEdge(i,j) && org_elem->isEdge(k,l) && org_elem->getNode(k)->getID() == org_elem->getNode(l)->getID()) { @@ -534,7 +596,11 @@ unsigned MeshRevision::reduceHex(MeshLib::Element const*const org_elem, delete prism2; return nNewElements; } + } + } } + } + } } else if (n_unique_nodes == 5) { @@ -555,7 +621,9 @@ unsigned MeshRevision::reduceHex(MeshLib::Element const*const org_elem, new_elements.push_back(new MeshLib::Tet(tet1_nodes)); } else + { new_elements.push_back(tet1); + } auto** tet2_nodes = new MeshLib::Node*[4]; tet2_nodes[0] = (tet_changed) ? nodes[first_four_nodes[0]] : nodes[first_four_nodes[1]]; @@ -597,12 +665,18 @@ void MeshRevision::reducePyramid(MeshLib::Element const*const org_elem, { MeshLib::Element* elem (this->constructFourNodeElement(org_elem, nodes, min_elem_dim)); if (elem) - new_elements.push_back (elem); + { + new_elements.push_back(elem); + } } else if (n_unique_nodes == 3 && min_elem_dim < 3) + { new_elements.push_back (this->constructTri(org_elem, nodes)); + } else if (n_unique_nodes == 2 && min_elem_dim == 1) - new_elements.push_back (this->constructLine(org_elem, nodes)); + { + new_elements.push_back(this->constructLine(org_elem, nodes)); + } return; } @@ -631,8 +705,10 @@ unsigned MeshRevision::reducePrism(MeshLib::Element const*const org_elem, // pyramid, otherwise it will be two tets if (n_unique_nodes == 5) { - for (unsigned i=0; i<5; ++i) - for (unsigned j=i+1; j<6; ++j) + for (unsigned i = 0; i < 5; ++i) + { + for (unsigned j = i + 1; j < 6; ++j) + { if (i!=j && org_elem->getNode(i)->getID() == org_elem->getNode(j)->getID()) { // non triangle edge collapsed @@ -669,17 +745,25 @@ unsigned MeshRevision::reducePrism(MeshLib::Element const*const org_elem, addTetrahedron(l_offset, k_offset, i, k); return 2; } + } + } } else if (n_unique_nodes == 4) { MeshLib::Element* elem (this->constructFourNodeElement(org_elem, nodes, min_elem_dim)); if (elem) - new_elements.push_back (elem); + { + new_elements.push_back(elem); + } } else if (n_unique_nodes == 3 && min_elem_dim < 3) + { new_elements.push_back (this->constructTri(org_elem, nodes)); + } else if (n_unique_nodes == 2 && min_elem_dim == 1) - new_elements.push_back (this->constructLine(org_elem, nodes)); + { + new_elements.push_back(this->constructLine(org_elem, nodes)); + } return 1; } @@ -723,7 +807,10 @@ MeshLib::Element* MeshRevision::constructTri(MeshLib::Element const*const elemen break; } } - if (tri_nodes[2]) break; + if (tri_nodes[2]) + { + break; + } } } assert(tri_nodes[2] != nullptr); @@ -740,8 +827,10 @@ MeshLib::Element* MeshRevision::constructFourNodeElement( new_nodes[count++] = nodes[element->getNode(0)->getID()]; for (unsigned i=1; i<element->getNumberOfBaseNodes(); ++i) { - if (count>3) + if (count > 3) + { break; + } bool unique_node (true); for (unsigned j=0; j<i; ++j) { @@ -752,7 +841,9 @@ MeshLib::Element* MeshRevision::constructFourNodeElement( } } if (unique_node) - new_nodes[count++] = nodes[element->getNode(i)->getID()];; + { + new_nodes[count++] = nodes[element->getNode(i)->getID()]; + }; } // test if quad or tet @@ -764,7 +855,9 @@ MeshLib::Element* MeshRevision::constructFourNodeElement( for (unsigned i=1; i<3; ++i) { if (elem->validate().none()) + { return elem; + } // change node order if not convex MeshLib::Node* tmp = new_nodes[i + 1]; @@ -774,7 +867,9 @@ MeshLib::Element* MeshRevision::constructFourNodeElement( return elem; } if (!isQuad) + { return new MeshLib::Tet(new_nodes); + } // is quad but min elem dim == 3 return nullptr; } @@ -786,11 +881,17 @@ unsigned MeshRevision::findPyramidTopNode(MeshLib::Element const& element, for (std::size_t i=0; i<nNodes; ++i) { bool top_node=true; - for (unsigned j=0; j<4; ++j) + for (unsigned j = 0; j < 4; ++j) + { if (element.getNode(i)->getID() == base_node_ids[j]) - top_node=false; + { + top_node = false; + } + } if (top_node) + { return i; + } } return std::numeric_limits<unsigned>::max(); // should never be reached if called correctly } @@ -852,27 +953,43 @@ const std::pair<unsigned, unsigned> MeshRevision::lutHexBackNodes( unsigned MeshRevision::lutPrismThirdNode(unsigned id1, unsigned id2) const { if ((id1 == 0 && id2 == 1) || (id1 == 1 && id2 == 2)) + { return 2; + } if ((id1 == 1 && id2 == 2) || (id1 == 2 && id2 == 1)) + { return 0; + } if ((id1 == 0 && id2 == 2) || (id1 == 2 && id2 == 0)) + { return 1; + } if ((id1 == 3 && id2 == 4) || (id1 == 4 && id2 == 3)) + { return 5; + } if ((id1 == 4 && id2 == 5) || (id1 == 5 && id2 == 4)) + { return 3; + } if ((id1 == 3 && id2 == 5) || (id1 == 5 && id2 == 3)) + { return 4; + } return std::numeric_limits<unsigned>::max(); } void MeshRevision::cleanUp(std::vector<MeshLib::Node*> &new_nodes, std::vector<MeshLib::Element*> &new_elements) const { for (auto& new_element : new_elements) + { delete new_element; + } for (auto& new_node : new_nodes) + { delete new_node; + } } } // end namespace MeshLib diff --git a/MeshLib/MeshEditing/RemoveMeshComponents.cpp b/MeshLib/MeshEditing/RemoveMeshComponents.cpp index 409776d7e4735d6ae6ec61011a3e3f963433d4db..8432fe2248fa0409214cba541d8f7fb7bdc72696 100644 --- a/MeshLib/MeshEditing/RemoveMeshComponents.cpp +++ b/MeshLib/MeshEditing/RemoveMeshComponents.cpp @@ -28,13 +28,21 @@ std::vector<MeshLib::Element*> excludeElementCopy( std::vector<MeshLib::Element*> vec_dest_eles(vec_src_eles.size()-vec_removed.size()); unsigned cnt (0); - for (std::size_t i=0; i<vec_removed[0]; ++i) + for (std::size_t i = 0; i < vec_removed[0]; ++i) + { vec_dest_eles[cnt++] = vec_src_eles[i]; - for (std::size_t i=1; i<vec_removed.size(); ++i) - for (std::size_t j=vec_removed[i-1]+1; j<vec_removed[i]; ++j) + } + for (std::size_t i = 1; i < vec_removed.size(); ++i) + { + for (std::size_t j = vec_removed[i - 1] + 1; j < vec_removed[i]; ++j) + { vec_dest_eles[cnt++] = vec_src_eles[j]; - for (std::size_t i=vec_removed.back()+1; i<vec_src_eles.size(); ++i) + } + } + for (std::size_t i = vec_removed.back() + 1; i < vec_src_eles.size(); ++i) + { vec_dest_eles[cnt++] = vec_src_eles[i]; + } return vec_dest_eles; } @@ -88,7 +96,9 @@ MeshLib::Mesh* removeElements(const MeshLib::Mesh& mesh, const std::vector<std:: MeshLib::Mesh* removeNodes(const MeshLib::Mesh &mesh, const std::vector<std::size_t> &del_nodes_idx, const std::string &new_mesh_name) { if (del_nodes_idx.empty()) + { return nullptr; + } // copy node and element objects std::vector<MeshLib::Node*> new_nodes = MeshLib::copyNodeVector(mesh.getNodes()); @@ -108,14 +118,19 @@ MeshLib::Mesh* removeNodes(const MeshLib::Mesh &mesh, const std::vector<std::siz // check unused nodes due to element deletion std::vector<bool> node_delete_flag(new_nodes.size(), true); for (auto e : new_elems) { - for (unsigned i=0; i<e->getNumberOfNodes(); i++) + for (unsigned i = 0; i < e->getNumberOfNodes(); i++) + { node_delete_flag[e->getNodeIndex(i)] = false; + } } // delete unused nodes for (std::size_t i=0; i<new_nodes.size(); i++) { - if (!node_delete_flag[i]) continue; + if (!node_delete_flag[i]) + { + continue; + } delete new_nodes[i]; new_nodes[i] = nullptr; } diff --git a/MeshLib/MeshEnums.cpp b/MeshLib/MeshEnums.cpp index 7090a3b0f49b9b34c28433c37d61e2b943c56573..0f7ddefbaa6edb3c95a8de6a28d2e4adea90bb5d 100644 --- a/MeshLib/MeshEnums.cpp +++ b/MeshLib/MeshEnums.cpp @@ -19,63 +19,111 @@ namespace MeshLib { const std::string MeshElemType2String(const MeshElemType t) { if (t == MeshElemType::POINT) + { return "Point"; + } if (t == MeshElemType::LINE) + { return "Line"; + } if (t == MeshElemType::QUAD) + { return "Quad"; + } if (t == MeshElemType::HEXAHEDRON) + { return "Hexahedron"; + } if (t == MeshElemType::TRIANGLE) + { return "Triangle"; + } if (t == MeshElemType::TETRAHEDRON) + { return "Tetrahedron"; + } if (t == MeshElemType::PRISM) + { return "Prism"; + } if (t == MeshElemType::PYRAMID) + { return "Pyramid"; + } return "none"; } const std::string MeshElemType2StringShort(const MeshElemType t) { if (t == MeshElemType::POINT) + { return "point"; + } if (t == MeshElemType::LINE) + { return "line"; + } if (t == MeshElemType::QUAD) + { return "quad"; + } if (t == MeshElemType::HEXAHEDRON) + { return "hex"; + } if (t == MeshElemType::TRIANGLE) + { return "tri"; + } if (t == MeshElemType::TETRAHEDRON) + { return "tet"; + } if (t == MeshElemType::PRISM) + { return "pris"; + } if (t == MeshElemType::PYRAMID) + { return "pyra"; + } return "none"; } MeshElemType String2MeshElemType(const std::string &s) { if (s == "point" || s == "Point") + { return MeshElemType::POINT; + } if (s == "line" || s == "Line") + { return MeshElemType::LINE; + } if (s == "quad" || s == "Quadrilateral") + { return MeshElemType::QUAD; + } if (s == "hex" || s == "Hexahedron") + { return MeshElemType::HEXAHEDRON; + } if (s == "tri" || s == "Triangle") + { return MeshElemType::TRIANGLE; + } if (s == "tet" || s == "Tetrahedron") + { return MeshElemType::TETRAHEDRON; + } if (s == "pris" || s == "Prism") + { return MeshElemType::PRISM; + } if (s == "pyra" || s == "Pyramid") + { return MeshElemType::PYRAMID; + } return MeshElemType::INVALID; } @@ -97,7 +145,9 @@ std::vector<std::string> getMeshElemTypeStringsShort() { std::vector<std::string> vec; for (MeshElemType eleType : getMeshElemTypes()) + { vec.push_back(MeshElemType2StringShort(eleType)); + } return vec; } @@ -133,15 +183,25 @@ const std::string CellType2String(const CellType t) const std::string MeshQualityType2String(const MeshQualityType t) { if (t == MeshQualityType::ELEMENTSIZE) + { return "ElementSize"; + } if (t == MeshQualityType::EDGERATIO) + { return "EdgeRatio"; + } if (t == MeshQualityType::EQUIANGLESKEW) + { return "EquiAngleSkew"; + } if (t == MeshQualityType::RADIUSEDGERATIO) + { return "RadiusEdgeRatio"; + } if (t == MeshQualityType::SIZEDIFFERENCE) + { return "SizeDifference"; + } return "none"; } diff --git a/MeshLib/MeshGenerators/LayeredMeshGenerator.cpp b/MeshLib/MeshGenerators/LayeredMeshGenerator.cpp index 16c563cb0486d7dab9697d07799758358d21c531..2e9a038571a8667505980f851fae364f8564a9b2 100644 --- a/MeshLib/MeshGenerators/LayeredMeshGenerator.cpp +++ b/MeshLib/MeshGenerators/LayeredMeshGenerator.cpp @@ -41,7 +41,9 @@ bool LayeredMeshGenerator::createLayers( double noDataReplacementValue) { if (mesh.getDimension() != 2) + { return false; + } bool result = createRasterLayers(mesh, rasters, minimum_thickness, noDataReplacementValue); std::for_each(rasters.begin(), rasters.end(), [](GeoLib::Raster const*const raster){ delete raster; }); @@ -52,7 +54,9 @@ std::unique_ptr<MeshLib::Mesh> LayeredMeshGenerator::getMesh(std::string const& mesh_name) const { if (_nodes.empty() || _elements.empty()) + { return nullptr; + } MeshLib::Properties properties; if (_materials.size() == _elements.size()) @@ -95,7 +99,9 @@ MeshLib::Node* LayeredMeshGenerator::getNewLayerNode(MeshLib::Node const& dem_no if ((std::abs(elevation - raster.getHeader().no_data) < std::numeric_limits<double>::epsilon()) || (elevation - last_layer_node[2] < _minimum_thickness)) + { return new MeshLib::Node(last_layer_node); + } return new MeshLib::Node(dem_node[0], dem_node[1], elevation, new_node_id); } diff --git a/MeshLib/MeshGenerators/LayeredVolume.cpp b/MeshLib/MeshGenerators/LayeredVolume.cpp index 48d766a7cec85ffeb5180ad6994cf6f36a51f8e1..633d49b1c01d9ee5e2f3589c58976b603943825b 100644 --- a/MeshLib/MeshGenerators/LayeredVolume.cpp +++ b/MeshLib/MeshGenerators/LayeredVolume.cpp @@ -33,27 +33,37 @@ bool LayeredVolume::createRasterLayers(const MeshLib::Mesh &mesh, double noDataReplacementValue) { if (mesh.getDimension() != 2) + { return false; + } _elevation_epsilon = calcEpsilon(*rasters[0], *rasters.back()); if (_elevation_epsilon <= 0) + { return false; + } // remove line elements, only tri + quad remain MeshLib::ElementSearch ex(mesh); ex.searchByElementType(MeshLib::MeshElemType::LINE); std::unique_ptr<MeshLib::Mesh> top( removeElements(mesh, ex.getSearchedElementIDs(), "MeshLayer")); - if (top==nullptr) + if (top == nullptr) + { top = std::make_unique<MeshLib::Mesh>(mesh); + } if (!MeshLib::MeshLayerMapper::layerMapping( *top, *rasters.back(), noDataReplacementValue)) + { return false; + } std::unique_ptr<MeshLib::Mesh> bottom(new MeshLib::Mesh(*top)); if (!MeshLib::MeshLayerMapper::layerMapping(*bottom, *rasters[0], 0)) + { return false; + } this->_minimum_thickness = minimum_thickness; _nodes = MeshLib::copyNodeVector(bottom->getNodes()); @@ -67,8 +77,10 @@ bool LayeredVolume::createRasterLayers(const MeshLib::Mesh &mesh, // map each layer and attach to subsurface mesh const std::size_t nRasters (rasters.size()); - for (std::size_t i=1; i<nRasters; ++i) + for (std::size_t i = 1; i < nRasters; ++i) + { this->addLayerToMesh(*top, i, *rasters[i]); + } // close boundaries between layers this->addLayerBoundaries(*top, nRasters); @@ -84,8 +96,13 @@ void LayeredVolume::addLayerToMesh(const MeshLib::Mesh &dem_mesh, unsigned layer const std::size_t node_id_offset (_nodes.size()); const std::size_t last_layer_node_offset (node_id_offset-nNodes); - for (std::size_t i=0; i<nNodes; ++i) - _nodes.push_back(getNewLayerNode(*nodes[i], *_nodes[last_layer_node_offset + i], raster, _nodes.size())); + for (std::size_t i = 0; i < nNodes; ++i) + { + _nodes.push_back(getNewLayerNode(*nodes[i], + *_nodes[last_layer_node_offset + i], + raster, + _nodes.size())); + } const std::vector<MeshLib::Element*> &layer_elements (dem_mesh.getElements()); for (MeshLib::Element* elem : layer_elements) @@ -118,8 +135,10 @@ void LayeredVolume::addLayerBoundaries(const MeshLib::Mesh &layer, std::size_t n for (MeshLib::Element* elem : layer_elements) { const std::size_t nElemNodes (elem->getNumberOfBaseNodes()); - for (unsigned i=0; i<nElemNodes; ++i) + for (unsigned i = 0; i < nElemNodes; ++i) + { if (elem->getNeighbor(i) == nullptr) + { for (unsigned j=0; j<nLayerBoundaries; ++j) { const std::size_t offset (j*nNodes); @@ -141,6 +160,8 @@ void LayeredVolume::addLayerBoundaries(const MeshLib::Mesh &layer, std::size_t n _materials.push_back(nLayers+j); } } + } + } } } @@ -157,12 +178,14 @@ void LayeredVolume::removeCongruentElements(std::size_t nLayers, std::size_t nEl unsigned count(0); const std::size_t nElemNodes (low->getNumberOfBaseNodes()); - for (std::size_t k=0; k<nElemNodes; ++k) + for (std::size_t k = 0; k < nElemNodes; ++k) + { if (high->getNodeIndex(k) == low->getNodeIndex(k)) { low->setNode(k, _nodes[high->getNodeIndex(k)]); count++; } + } if (count == nElemNodes) { diff --git a/MeshLib/MeshGenerators/MeshGenerator.cpp b/MeshLib/MeshGenerators/MeshGenerator.cpp index 85794fb4f266bae76b4b7ced7535536bc81f6add..b9e307f6184a5c5cbe099f3ef32c63476a28d2c0 100644 --- a/MeshLib/MeshGenerators/MeshGenerator.cpp +++ b/MeshLib/MeshGenerators/MeshGenerator.cpp @@ -53,8 +53,10 @@ std::vector<MeshLib::Node*> MeshGenerator::generateRegularNodes( std::vector<const std::vector<double>*> vec_xyz_coords; vec_xyz_coords.push_back(&vec_x_coords); std::vector<double> dummy(1,0.0); - for (unsigned i=vec_xyz_coords.size()-1; i<3u; i++) + for (unsigned i = vec_xyz_coords.size() - 1; i < 3u; i++) + { vec_xyz_coords.push_back(&dummy); + } return generateRegularNodes(vec_xyz_coords, origin); } @@ -67,8 +69,10 @@ std::vector<MeshLib::Node*> MeshGenerator::generateRegularNodes( vec_xyz_coords.push_back(&vec_x_coords); vec_xyz_coords.push_back(&vec_y_coords); std::vector<double> dummy(1,0.0); - for (unsigned i=vec_xyz_coords.size()-1; i<3u; i++) + for (unsigned i = vec_xyz_coords.size() - 1; i < 3u; i++) + { vec_xyz_coords.push_back(&dummy); + } return generateRegularNodes(vec_xyz_coords, origin); } @@ -454,8 +458,10 @@ Mesh* MeshGenerator::generateRegularPrismMesh( std::unique_ptr<MeshLib::Mesh> mesh ( generateRegularTriMesh(n_x_cells, n_y_cells, cell_size_x, cell_size_y, origin, mesh_name)); std::size_t const n_tris (mesh->getNumberOfElements()); - for (std::size_t i=0; i<n_z_cells; ++i) + for (std::size_t i = 0; i < n_z_cells; ++i) + { mesh.reset(MeshLib::addTopLayerToMesh(*mesh, cell_size_z, mesh_name)); + } std::vector<std::size_t> elem_ids (n_tris); std::iota(elem_ids.begin(), elem_ids.end(), 0); return MeshLib::removeElements(*mesh, elem_ids, mesh_name); diff --git a/MeshLib/MeshGenerators/MeshLayerMapper.cpp b/MeshLib/MeshGenerators/MeshLayerMapper.cpp index 11ce03cd14ae1376ba26c2fcca7c802745d9b7d1..84ce5900ad10268106d8b7cf2b98fdb7c051a3df 100644 --- a/MeshLib/MeshGenerators/MeshLayerMapper.cpp +++ b/MeshLib/MeshGenerators/MeshLayerMapper.cpp @@ -35,11 +35,16 @@ namespace MeshLib MeshLib::Mesh* MeshLayerMapper::createStaticLayers(MeshLib::Mesh const& mesh, std::vector<float> const& layer_thickness_vector, std::string const& mesh_name) { std::vector<float> thickness; - for (std::size_t i=0; i<layer_thickness_vector.size(); ++i) + for (std::size_t i = 0; i < layer_thickness_vector.size(); ++i) + { if (layer_thickness_vector[i] > std::numeric_limits<float>::epsilon()) + { thickness.push_back(layer_thickness_vector[i]); + } else - WARN ("Ignoring layer %d with thickness %f.", i, layer_thickness_vector[i]); + WARN("Ignoring layer %d with thickness %f.", i, + layer_thickness_vector[i]); + } const std::size_t nLayers(thickness.size()); if (nLayers < 1 || mesh.getDimension() != 2) @@ -75,14 +80,19 @@ MeshLib::Mesh* MeshLayerMapper::createStaticLayers(MeshLib::Mesh const& mesh, st { // add nodes for new layer unsigned node_offset (nNodes * layer_id); - if (layer_id > 0) z_offset += thickness[layer_id-1]; + if (layer_id > 0) + { + z_offset += thickness[layer_id - 1]; + } std::transform(nodes.cbegin(), nodes.cend(), new_nodes.begin() + node_offset, [&z_offset](MeshLib::Node* node){ return new MeshLib::Node((*node)[0], (*node)[1], (*node)[2]-z_offset); }); // starting with 2nd layer create prism or hex elements connecting the last layer with the current one if (layer_id == 0) + { continue; + } node_offset -= nNodes; const unsigned mat_id (nLayers - layer_id); @@ -90,8 +100,10 @@ MeshLib::Mesh* MeshLayerMapper::createStaticLayers(MeshLib::Mesh const& mesh, st for (unsigned i = 0; i < nOrgElems; ++i) { const MeshLib::Element* sfc_elem( elems[i] ); - if (sfc_elem->getDimension() < 2) // ignore line-elements + if (sfc_elem->getDimension() < 2) + { // ignore line-elements continue; + } const unsigned nElemNodes(sfc_elem->getNumberOfBaseNodes()); auto** e_nodes = new MeshLib::Node*[2 * nElemNodes]; @@ -137,7 +149,9 @@ bool MeshLayerMapper::createRasterLayers( auto top = std::make_unique<MeshLib::Mesh>(mesh); if (!layerMapping(*top, *rasters.back(), noDataReplacementValue)) + { return false; + } auto bottom = std::make_unique<MeshLib::Mesh>(mesh); if (!layerMapping(*bottom, *rasters[0], 0)) @@ -159,11 +173,15 @@ bool MeshLayerMapper::createRasterLayers( // add bottom layer std::vector<MeshLib::Node*> const& nodes = bottom->getNodes(); for (MeshLib::Node* node : nodes) + { _nodes.push_back(new MeshLib::Node(*node)); + } // add the other layers - for (std::size_t i=0; i<nLayers-1; ++i) - addLayerToMesh(*top, i, *rasters[i+1]); + for (std::size_t i = 0; i < nLayers - 1; ++i) + { + addLayerToMesh(*top, i, *rasters[i + 1]); + } return true; } @@ -182,8 +200,12 @@ void MeshLayerMapper::addLayerToMesh(const MeshLib::Mesh &dem_mesh, unsigned lay int const last_layer_node_offset = layer_id * nNodes; // add nodes for new layer - for (std::size_t i=0; i<nNodes; ++i) - _nodes.push_back(getNewLayerNode(*nodes[i], *_nodes[last_layer_node_offset + i], raster, _nodes.size())); + for (std::size_t i = 0; i < nNodes; ++i) + { + _nodes.push_back(getNewLayerNode(*nodes[i], + *_nodes[last_layer_node_offset + i], + raster, _nodes.size())); + } std::vector<MeshLib::Element*> const& elems = dem_mesh.getElements(); std::size_t const nElems (dem_mesh.getNumberOfElements()); @@ -192,17 +214,24 @@ void MeshLayerMapper::addLayerToMesh(const MeshLib::Mesh &dem_mesh, unsigned lay { MeshLib::Element* elem (elems[i]); if (elem->getGeomType() != MeshLib::MeshElemType::TRIANGLE) + { continue; + } unsigned node_counter(3), missing_idx(0); std::array<MeshLib::Node*, 6> new_elem_nodes; for (unsigned j=0; j<3; ++j) { new_elem_nodes[j] = _nodes[_nodes[last_layer_node_offset + elem->getNodeIndex(j)]->getID()]; new_elem_nodes[node_counter] = (_nodes[last_layer_node_offset + elem->getNodeIndex(j) + nNodes]); - if (new_elem_nodes[j]->getID() != new_elem_nodes[node_counter]->getID()) + if (new_elem_nodes[j]->getID() != + new_elem_nodes[node_counter]->getID()) + { node_counter++; + } else + { missing_idx = j; + } } switch (node_counter) @@ -261,8 +290,11 @@ bool MeshLayerMapper::layerMapping(MeshLib::Mesh &new_mesh, GeoLib::Raster const } double elevation (raster.interpolateValueAtPoint(*nodes[i])); - if (std::abs(elevation - header.no_data) < std::numeric_limits<double>::epsilon()) + if (std::abs(elevation - header.no_data) < + std::numeric_limits<double>::epsilon()) + { elevation = noDataReplacementValue; + } nodes[i]->updateCoordinates((*nodes[i])[0], (*nodes[i])[1], elevation); } @@ -279,7 +311,9 @@ bool MeshLayerMapper::mapToStaticValue(MeshLib::Mesh &mesh, double value) std::vector<MeshLib::Node*> const& nodes (mesh.getNodes()); for (MeshLib::Node* node : nodes) + { node->updateCoordinates((*node)[0], (*node)[1], value); + } return true; } diff --git a/MeshLib/MeshGenerators/QuadraticMeshGenerator.cpp b/MeshLib/MeshGenerators/QuadraticMeshGenerator.cpp index 23c3eb7257889346b181f69be8d8a42398dbac09..3a740e6538c7c25c5582d36f25caa9e2c7e8a181 100644 --- a/MeshLib/MeshGenerators/QuadraticMeshGenerator.cpp +++ b/MeshLib/MeshGenerators/QuadraticMeshGenerator.cpp @@ -31,7 +31,9 @@ std::unique_ptr<QuadraticElement> convertLinearToQuadratic( // Copy base nodes of element to the quadratic element new nodes'. std::array<MeshLib::Node*, n_all_nodes> nodes; for (int i = 0; i < n_base_nodes; i++) + { nodes[i] = const_cast<MeshLib::Node*>(e.getNode(i)); + } // For each edge create a middle node. int const number_of_edges = e.getNumberOfEdges(); diff --git a/MeshLib/MeshGenerators/RasterToMesh.cpp b/MeshLib/MeshGenerators/RasterToMesh.cpp index 05f83caca4e10db38229304c7a8ed625499ed401..661f190936838f96dcfe514a4959d7195a7d9c4d 100644 --- a/MeshLib/MeshGenerators/RasterToMesh.cpp +++ b/MeshLib/MeshGenerators/RasterToMesh.cpp @@ -89,11 +89,15 @@ MeshLib::Mesh* RasterToMesh::convert( double* colour = pixelData->GetTuple(idx + j); bool const visible = (nTuple == 2 || nTuple == 4) ? (colour[nTuple - 1] != 0) : true; if (!visible) + { pix[idx + j] = header.no_data; + } else - pix[idx + j] = (nTuple < 3) ? - colour[0] : // grey (+ alpha) - (0.3 * colour[0] + 0.6 * colour[1] + 0.1 * colour[2]); // rgb(a) + { + pix[idx + j] = (nTuple < 3) ? colour[0] : // grey (+ alpha) + (0.3 * colour[0] + 0.6 * colour[1] + + 0.1 * colour[2]); // rgb(a) + } } } } @@ -137,20 +141,25 @@ MeshLib::Mesh* RasterToMesh::convert( header.origin[1] - (header.cell_size / 2.0), header.origin[2]}}); std::unique_ptr<MeshLib::Mesh> mesh (nullptr); if (elem_type == MeshElemType::TRIANGLE) + { mesh.reset( MeshLib::MeshGenerator::generateRegularTriMesh(header.n_cols, header.n_rows, header.cell_size, mesh_origin, "RasterDataMesh")); + } else if (elem_type == MeshElemType::QUAD) + { mesh.reset( MeshLib::MeshGenerator::generateRegularQuadMesh(header.n_cols, header.n_rows, header.cell_size, mesh_origin, "RasterDataMesh")); + } else if (elem_type == MeshElemType::PRISM) + { mesh.reset( MeshLib::MeshGenerator::generateRegularPrismMesh(header.n_cols, header.n_rows, @@ -158,7 +167,9 @@ MeshLib::Mesh* RasterToMesh::convert( header.cell_size, mesh_origin, "RasterDataMesh")); + } else if (elem_type == MeshElemType::HEXAHEDRON) + { mesh.reset( MeshLib::MeshGenerator::generateRegularHexMesh(header.n_cols, header.n_rows, @@ -166,6 +177,7 @@ MeshLib::Mesh* RasterToMesh::convert( header.cell_size, mesh_origin, "RasterDataMesh")); + } MeshLib::Mesh* new_mesh(nullptr); std::vector<std::size_t> elements_to_remove; @@ -189,14 +201,19 @@ MeshLib::Mesh* RasterToMesh::convert( { elements_to_remove.push_back(m * (idx + j)); if (double_idx) + { elements_to_remove.push_back(m * (idx + j) + 1); + } continue; } for (std::size_t n = 0; n < n_nodes; ++n) { (*(nodes[elems[m * (idx + j)]->getNodeIndex(n)]))[2] = val; if (double_idx) - (*(nodes[elems[m * (idx + j) + 1]->getNodeIndex(n)]))[2] = val; + { + (*(nodes[elems[m * (idx + j) + 1]->getNodeIndex( + n)]))[2] = val; + } } } } @@ -223,12 +240,18 @@ MeshLib::Mesh* RasterToMesh::convert( elements_to_remove = ex.getSearchedElementIDs(); } if (!elements_to_remove.empty()) + { new_mesh = MeshLib::removeElements(*mesh, elements_to_remove, mesh->getName()); + } else + { new_mesh = mesh.release(); + } if (intensity_type == UseIntensityAs::NONE) + { new_mesh->getProperties().removePropertyVector(array_name); + } return new_mesh; } diff --git a/MeshLib/MeshGenerators/VtkMeshConverter.cpp b/MeshLib/MeshGenerators/VtkMeshConverter.cpp index 9c26daec86d6b6d8def084ad1760d087d365c867..7def6a68af62f01a7f2a1ed3736da10c6ab978c7 100644 --- a/MeshLib/MeshGenerators/VtkMeshConverter.cpp +++ b/MeshLib/MeshGenerators/VtkMeshConverter.cpp @@ -48,7 +48,9 @@ MeshLib::Element* createElementWithSameNodeOrder( { auto** ele_nodes = new MeshLib::Node*[T_ELEMENT::n_all_nodes]; for (unsigned k(0); k < T_ELEMENT::n_all_nodes; k++) + { ele_nodes[k] = nodes[node_ids->GetId(k)]; + } return new T_ELEMENT(ele_nodes, element_id); } } // namespace detail @@ -57,7 +59,9 @@ MeshLib::Mesh* VtkMeshConverter::convertUnstructuredGrid( vtkUnstructuredGrid* grid, std::string const& mesh_name) { if (!grid) + { return nullptr; + } // set mesh nodes const std::size_t nNodes = grid->GetPoints()->GetNumberOfPoints(); @@ -210,12 +214,16 @@ MeshLib::Mesh* VtkMeshConverter::convertUnstructuredGrid( prism_nodes[i + 3] = nodes[node_ids->GetId(i)]; } for (unsigned i = 0; i < 3; ++i) + { prism_nodes[6 + i] = nodes[node_ids->GetId(8 - i)]; + } prism_nodes[9] = nodes[node_ids->GetId(12)]; prism_nodes[10] = nodes[node_ids->GetId(14)]; prism_nodes[11] = nodes[node_ids->GetId(13)]; for (unsigned i = 0; i < 3; ++i) + { prism_nodes[12 + i] = nodes[node_ids->GetId(11 - i)]; + } elem = new MeshLib::Prism15(prism_nodes, i); break; } @@ -242,26 +250,32 @@ void VtkMeshConverter::convertScalarArrays(vtkUnstructuredGrid& grid, auto const n_point_arrays = static_cast<unsigned>(point_data->GetNumberOfArrays()); for (unsigned i = 0; i < n_point_arrays; ++i) + { convertArray(*point_data->GetArray(i), mesh.getProperties(), MeshLib::MeshItemType::Node); + } vtkCellData* cell_data = grid.GetCellData(); auto const n_cell_arrays = static_cast<unsigned>(cell_data->GetNumberOfArrays()); for (unsigned i = 0; i < n_cell_arrays; ++i) + { convertArray(*cell_data->GetArray(i), mesh.getProperties(), MeshLib::MeshItemType::Cell); + } vtkFieldData* field_data = grid.GetFieldData(); auto const n_field_arrays = static_cast<unsigned>(field_data->GetNumberOfArrays()); for (unsigned i = 0; i < n_field_arrays; ++i) + { convertArray( *vtkDataArray::SafeDownCast(field_data->GetAbstractArray(i)), mesh.getProperties(), MeshLib::MeshItemType::IntegrationPoint); + } } void VtkMeshConverter::convertArray(vtkDataArray& array, @@ -316,10 +330,14 @@ void VtkMeshConverter::convertArray(vtkDataArray& array, { // MaterialIDs are assumed to be integers if (std::strncmp(array.GetName(), "MaterialIDs", 11) == 0) + { VtkMeshConverter::convertTypedArray<int>(array, properties, type); + } else - VtkMeshConverter::convertTypedArray<unsigned>( - array, properties, type); + { + VtkMeshConverter::convertTypedArray<unsigned>(array, properties, + type); + } return; } diff --git a/MeshLib/MeshGenerators/VtkMeshConverter.h b/MeshLib/MeshGenerators/VtkMeshConverter.h index 8c75411ec8b7b41ff85876660bce2f6b2e87566f..f5a00aaa0c18e9c215557e693f867ef9d1c3b401 100644 --- a/MeshLib/MeshGenerators/VtkMeshConverter.h +++ b/MeshLib/MeshGenerators/VtkMeshConverter.h @@ -76,6 +76,7 @@ private: MeshElemType elem_type) { for (std::size_t i = 0; i < imgHeight; i++) + { for (std::size_t j = 0; j < imgWidth; j++) { if (!pix_vis[i * imgWidth + j]) @@ -89,6 +90,7 @@ private: else if (elem_type == MeshElemType::QUAD) prop_vec.push_back(val); } + } } static void convertArray(vtkDataArray& array, diff --git a/MeshLib/MeshInformation.cpp b/MeshLib/MeshInformation.cpp index eb7188c408da1e8515c8815800e328ebaffba4cf..57b1f31ec6b13f946c03e1cbcf927572d67f3f93 100644 --- a/MeshLib/MeshInformation.cpp +++ b/MeshLib/MeshInformation.cpp @@ -31,13 +31,34 @@ const std::array<unsigned, 7> MeshInformation::getNumberOfElementTypes(const Mes for (auto element : elements) { MeshElemType t = element->getGeomType(); - if (t == MeshElemType::LINE) n_element_types[0]++; - if (t == MeshElemType::TRIANGLE) n_element_types[1]++; - if (t == MeshElemType::QUAD) n_element_types[2]++; - if (t == MeshElemType::TETRAHEDRON) n_element_types[3]++; - if (t == MeshElemType::HEXAHEDRON) n_element_types[4]++; - if (t == MeshElemType::PYRAMID) n_element_types[5]++; - if (t == MeshElemType::PRISM) n_element_types[6]++; + if (t == MeshElemType::LINE) + { + n_element_types[0]++; + } + if (t == MeshElemType::TRIANGLE) + { + n_element_types[1]++; + } + if (t == MeshElemType::QUAD) + { + n_element_types[2]++; + } + if (t == MeshElemType::TETRAHEDRON) + { + n_element_types[3]++; + } + if (t == MeshElemType::HEXAHEDRON) + { + n_element_types[4]++; + } + if (t == MeshElemType::PYRAMID) + { + n_element_types[5]++; + } + if (t == MeshElemType::PRISM) + { + n_element_types[6]++; + } } return n_element_types; } diff --git a/MeshLib/MeshQuality/EdgeRatioMetric.cpp b/MeshLib/MeshQuality/EdgeRatioMetric.cpp index 04842a352d962559051db8a38f36ef5ecf2e0533..d1d63de5b6c6c5c256086dafb43a245cb274316d 100644 --- a/MeshLib/MeshQuality/EdgeRatioMetric.cpp +++ b/MeshLib/MeshQuality/EdgeRatioMetric.cpp @@ -52,21 +52,27 @@ void EdgeRatioMetric::calculateQuality() case MeshElemType::PRISM: { std::vector<const MathLib::Point3d*> pnts; for (std::size_t j(0); j < 6; j++) + { pnts.push_back(elem.getNode(j)); + } _element_quality_metric[k] = checkPrism(pnts); break; } case MeshElemType::PYRAMID: { std::vector<const MathLib::Point3d*> pnts; for (std::size_t j(0); j < 5; j++) + { pnts.push_back(elem.getNode(j)); + } _element_quality_metric[k] = checkPyramid(pnts); break; } case MeshElemType::HEXAHEDRON: { std::vector<const MathLib::Point3d*> pnts; for (std::size_t j(0); j < 8; j++) + { pnts.push_back(elem.getNode(j)); + } _element_quality_metric[k] = checkHexahedron(pnts); break; } @@ -88,7 +94,9 @@ double EdgeRatioMetric::checkTriangle (MathLib::Point3d const& a, if (len0 < len1 && len0 < len2) { if (len1 < len2) + { return len0 / len2; + } return len0 / len1; } @@ -96,13 +104,17 @@ double EdgeRatioMetric::checkTriangle (MathLib::Point3d const& a, if (len1 < len2) { if (len0 < len2) + { return len1 / len2; + } return len1 / len0; } if (len0 < len1) + { return len2 / len1; + } return len2 / len0; } @@ -119,9 +131,15 @@ double EdgeRatioMetric::checkQuad (MathLib::Point3d const& a, // sort lengths - since this is a very small array we use bubble sort for (std::size_t i(0); i < 4; i++) + { for (std::size_t j(i + 1); j < 4; j++) + { if (sqr_lengths[i] >= sqr_lengths[j]) - std::swap (sqr_lengths[i], sqr_lengths[j]); + { + std::swap(sqr_lengths[i], sqr_lengths[j]); + } + } + } return sqrt(sqr_lengths[0]) / sqrt(sqr_lengths[3]); } @@ -137,9 +155,15 @@ double EdgeRatioMetric::checkTetrahedron (MathLib::Point3d const& a, // sort lengths - since this is a very small array we use bubble sort for (std::size_t i(0); i < 6; i++) + { for (std::size_t j(i + 1); j < 6; j++) + { if (sqr_lengths[i] >= sqr_lengths[j]) - std::swap (sqr_lengths[i], sqr_lengths[j]); + { + std::swap(sqr_lengths[i], sqr_lengths[j]); + } + } + } return sqrt(sqr_lengths[0]) / sqrt(sqr_lengths[5]); } @@ -158,9 +182,15 @@ double EdgeRatioMetric::checkPrism (std::vector<const MathLib::Point3d*> const& // sort lengths - since this is a very small array we use bubble sort for (std::size_t i(0); i < 9; i++) + { for (std::size_t j(i + 1); j < 9; j++) + { if (sqr_lengths[i] >= sqr_lengths[j]) - std::swap (sqr_lengths[i], sqr_lengths[j]); + { + std::swap(sqr_lengths[i], sqr_lengths[j]); + } + } + } return sqrt(sqr_lengths[0]) / sqrt(sqr_lengths[8]); } @@ -178,9 +208,15 @@ double EdgeRatioMetric::checkPyramid (std::vector<const MathLib::Point3d*> const // sort lengths - since this is a very small array we use bubble sort for (std::size_t i(0); i < 8; i++) + { for (std::size_t j(i + 1); j < 8; j++) + { if (sqr_lengths[i] >= sqr_lengths[j]) - std::swap (sqr_lengths[i], sqr_lengths[j]); + { + std::swap(sqr_lengths[i], sqr_lengths[j]); + } + } + } return sqrt(sqr_lengths[0]) / sqrt(sqr_lengths[7]); } @@ -202,9 +238,15 @@ double EdgeRatioMetric::checkHexahedron (std::vector<const MathLib::Point3d*> co // sort lengths - since this is a very small array we use bubble sort for (std::size_t i(0); i < 12; i++) + { for (std::size_t j(i + 1); j < 12; j++) + { if (sqr_lengths[i] >= sqr_lengths[j]) - std::swap (sqr_lengths[i], sqr_lengths[j]); + { + std::swap(sqr_lengths[i], sqr_lengths[j]); + } + } + } return sqrt(sqr_lengths[0]) / sqrt(sqr_lengths[11]); } diff --git a/MeshLib/MeshQuality/ElementQualityMetric.cpp b/MeshLib/MeshQuality/ElementQualityMetric.cpp index 754ebee8e9fe1d4ff96a8746ffaf070ea5458e8a..f827acaaa52c1d986ff48fa1306e260050c21a03 100644 --- a/MeshLib/MeshQuality/ElementQualityMetric.cpp +++ b/MeshLib/MeshQuality/ElementQualityMetric.cpp @@ -29,7 +29,10 @@ ElementQualityMetric::ElementQualityMetric(Mesh const& mesh) : BaseLib::Histogram<double> ElementQualityMetric::getHistogram (std::size_t n_bins) const { if (n_bins == 0) - n_bins = static_cast<std::size_t>(1 + 3.3 * log (static_cast<float>((_mesh.getNumberOfElements())))); + { + n_bins = static_cast<std::size_t>( + 1 + 3.3 * log(static_cast<float>((_mesh.getNumberOfElements())))); + } return BaseLib::Histogram<double>(getElementQuality(), n_bins, true); } diff --git a/MeshLib/MeshQuality/ElementSizeMetric.cpp b/MeshLib/MeshQuality/ElementSizeMetric.cpp index 5ae9f76c3e2d7cc41896552a48500883bed29d26..dae6f3eb73001c3a07545eac17986077ba9bf7e5 100644 --- a/MeshLib/MeshQuality/ElementSizeMetric.cpp +++ b/MeshLib/MeshQuality/ElementSizeMetric.cpp @@ -26,11 +26,17 @@ void ElementSizeMetric::calculateQuality() { std::size_t error_count(0); if (_mesh.getDimension() == 1) + { error_count = calc1dQuality(); + } else if (_mesh.getDimension() == 2) + { error_count = calc2dQuality(); + } else if (_mesh.getDimension() == 3) + { error_count = calc3dQuality(); + } INFO ("ElementSizeMetric::calculateQuality() minimum: %f, max_volume: %f", _min, _max); if (error_count > 0) @@ -47,12 +53,21 @@ std::size_t ElementSizeMetric::calc1dQuality() { double area(std::numeric_limits<double>::max()); _element_quality_metric[k] = elements[k]->getContent(); - if (_element_quality_metric[k] < sqrt(fabs(std::numeric_limits<double>::epsilon()))) + if (_element_quality_metric[k] < + sqrt(fabs(std::numeric_limits<double>::epsilon()))) + { error_count++; + } // update _min and _max values - if (_min > area) _min = area; - if (_max < area) _max = area; + if (_min > area) + { + _min = area; + } + if (_max < area) + { + _max = area; + } } return error_count; } @@ -74,11 +89,19 @@ std::size_t ElementSizeMetric::calc2dQuality() } double const area = elem.getContent(); if (area < sqrt(fabs(std::numeric_limits<double>::epsilon()))) + { error_count++; + } // update _min and _max values - if (_min > area) _min = area; - if (_max < area) _max = area; + if (_min > area) + { + _min = area; + } + if (_max < area) + { + _max = area; + } _element_quality_metric[k] = area; } return error_count; @@ -101,10 +124,18 @@ std::size_t ElementSizeMetric::calc3dQuality() double const volume (elem.getContent()); if (volume < sqrt(fabs(std::numeric_limits<double>::epsilon()))) + { error_count++; + } - if (_min > volume) _min = volume; - if (_max < volume) _max = volume; + if (_min > volume) + { + _min = volume; + } + if (_max < volume) + { + _max = volume; + } _element_quality_metric[k] = volume; } return error_count; diff --git a/MeshLib/MeshQuality/MeshValidation.cpp b/MeshLib/MeshQuality/MeshValidation.cpp index 30e79e567ebe72f5cc927594f492b0755dce3c4a..b17ba5f48678360b1bf1fbe40ef906cc23763d07 100644 --- a/MeshLib/MeshQuality/MeshValidation.cpp +++ b/MeshLib/MeshQuality/MeshValidation.cpp @@ -64,19 +64,29 @@ std::vector<ElementErrorCode> MeshValidation::testElementGeometry(const MeshLib: const ElementErrorCode e = elements[i]->validate(); error_code_vector.push_back(e); if (e.none()) + { continue; + } // increment error statistics const std::bitset< static_cast<std::size_t>(ElementErrorFlag::MaxValue) > flags (static_cast< std::bitset<static_cast<std::size_t>(ElementErrorFlag::MaxValue)> >(e)); - for (unsigned j=0; j<nErrorCodes; ++j) + for (unsigned j = 0; j < nErrorCodes; ++j) + { error_count[j] += flags[j]; + } } // if a larger volume threshold is given, evaluate elements again to add them even if they are formally okay if (min_volume > std::numeric_limits<double>::epsilon()) - for (std::size_t i=0; i<nElements; ++i) + { + for (std::size_t i = 0; i < nElements; ++i) + { if (elements[i]->getContent() < min_volume) + { error_code_vector[i].set(ElementErrorFlag::ZeroVolume); + } + } + } // output const auto error_sum(static_cast<unsigned>( @@ -85,9 +95,13 @@ std::vector<ElementErrorCode> MeshValidation::testElementGeometry(const MeshLib: { ElementErrorFlag flags[nErrorCodes] = { ElementErrorFlag::ZeroVolume, ElementErrorFlag::NonCoplanar, ElementErrorFlag::NonConvex, ElementErrorFlag::NodeOrder }; - for (std::size_t i=0; i<nErrorCodes; ++i) + for (std::size_t i = 0; i < nErrorCodes; ++i) + { if (error_count[i]) - INFO ("%d elements found with %s.", error_count[i], ElementErrorCode::toString(flags[i]).c_str()); + INFO("%d elements found with %s.", + error_count[i], + ElementErrorCode::toString(flags[i]).c_str()); + } } else INFO ("No errors found."); @@ -125,7 +139,9 @@ MeshValidation::ElementErrorCodeOutput(const std::vector<ElementErrorCode> &erro ElementErrorCode::toString(flags[i]) + ".\n"); if (count) + { output[i] += ("ElementIDs: " + elementIdStr + "\n"); + } } return output; } @@ -133,7 +149,9 @@ MeshValidation::ElementErrorCodeOutput(const std::vector<ElementErrorCode> &erro unsigned MeshValidation::detectHoles(MeshLib::Mesh const& mesh) { if (mesh.getDimension() == 1) + { return 0; + } MeshLib::Mesh* boundary_mesh (MeshSurfaceExtraction::getMeshBoundary(mesh)); std::vector<MeshLib::Element*> const& elements (boundary_mesh->getElements()); @@ -167,8 +185,11 @@ void MeshValidation::trackSurface(MeshLib::Element const* element, std::vector<u for (std::size_t i=0; i<n_neighbors; ++i) { MeshLib::Element const* neighbor (elem->getNeighbor(i)); - if ( neighbor != nullptr && sfc_idx[neighbor->getID()] == std::numeric_limits<unsigned>::max()) + if (neighbor != nullptr && sfc_idx[neighbor->getID()] == + std::numeric_limits<unsigned>::max()) + { elem_stack.push(neighbor); + } } } } diff --git a/MeshLib/MeshQuality/SizeDifferenceMetric.cpp b/MeshLib/MeshQuality/SizeDifferenceMetric.cpp index 7c9b5e8bcc7b0a673e5542a208ffdc16fb92fb5e..2f4950c73f8a00c453664370f4bec732340e5ef1 100644 --- a/MeshLib/MeshQuality/SizeDifferenceMetric.cpp +++ b/MeshLib/MeshQuality/SizeDifferenceMetric.cpp @@ -46,11 +46,15 @@ void SizeDifferenceMetric::calculateQuality() { MeshLib::Element const*const neighbor (elem.getNeighbor(i)); if (neighbor == nullptr) + { continue; + } double const vol_b (neighbor->getContent()); double const ratio = (vol_a > vol_b) ? vol_b / vol_a : vol_a / vol_b; if (ratio < worst_ratio) + { worst_ratio = ratio; + } } _element_quality_metric[k] = worst_ratio; } diff --git a/MeshLib/MeshSearch/ElementSearch.cpp b/MeshLib/MeshSearch/ElementSearch.cpp index 267d73f2d5c690adaab5d48cd526c1b350718547..2fb71a0697452e8a76ab5f6d7d315dd07b20f357 100644 --- a/MeshLib/MeshSearch/ElementSearch.cpp +++ b/MeshLib/MeshSearch/ElementSearch.cpp @@ -29,7 +29,9 @@ std::vector<std::size_t> filter(Container const& container, Predicate const& p) std::size_t i = 0; for (auto value : container) { if (p(value)) + { matchedIDs.push_back(i); + } i++; } return matchedIDs; @@ -59,9 +61,13 @@ std::size_t ElementSearch::searchByBoundingBox( auto matchedIDs = filter(_mesh.getElements(), [&aabb](MeshLib::Element* e) { std::size_t const nElemNodes (e->getNumberOfBaseNodes()); - for (std::size_t n=0; n < nElemNodes; ++n) + for (std::size_t n = 0; n < nElemNodes; ++n) + { if (aabb.containsPoint(*e->getNode(n), 0)) - return true; // any node of element is in aabb. + { + return true; // any node of element is in aabb. + } + } return false; // no nodes of element are in aabb. }); diff --git a/MeshLib/MeshSearch/MeshElementGrid.cpp b/MeshLib/MeshSearch/MeshElementGrid.cpp index 6b0d352b35751ebd4dc43a1d17f761e4c9d09f4a..d575dc13ab9255176881a09e99b2c03b0fd62cb6 100644 --- a/MeshLib/MeshSearch/MeshElementGrid.cpp +++ b/MeshLib/MeshSearch/MeshElementGrid.cpp @@ -35,8 +35,10 @@ MeshElementGrid::MeshElementGrid(MeshLib::Mesh const& sfc_mesh) : for (std::size_t k(0); k < 3; ++k) { double const tolerance( std::nexttoward(max[k],std::numeric_limits<double>::max())-max[k]); - if (std::abs(max[k]-min[k]) > tolerance) + if (std::abs(max[k] - min[k]) > tolerance) + { dim[k] = true; + } } return dim; }; @@ -138,14 +140,20 @@ bool MeshElementGrid::sortElementInGridCells(MeshLib::Element const& element) // compute coordinates of the grid for each node of the element c = getGridCellCoordinates(*(static_cast<MathLib::Point3d const*>(element.getNode(k)))); if (!c.first) + { return false; + } for (std::size_t j(0); j < 3; ++j) { if (min[j] > c.second[j]) + { min[j] = c.second[j]; + } if (max[j] < c.second[j]) + { max[j] = c.second[j]; + } } } @@ -155,8 +163,10 @@ bool MeshElementGrid::sortElementInGridCells(MeshLib::Element const& element) // AABB the grid cell coordinates computed by getGridCellCoordintes() could // be to large (due to numerical errors). The following lines ensure that // the grid cell coordinates are in the valid range. - for (std::size_t k(0); k<3; ++k) - max[k] = std::min(_n_steps[k]-1, max[k]); + for (std::size_t k(0); k < 3; ++k) + { + max[k] = std::min(_n_steps[k] - 1, max[k]); + } // insert the element into the grid cells for (std::size_t i(min[0]); i<=max[0]; i++) { diff --git a/MeshLib/MeshSearch/NodeSearch.cpp b/MeshLib/MeshSearch/NodeSearch.cpp index 0fbb077e3719bdb725207a261dfce038383792c8..5a805af04dca667586c73ba22a91c78d63462412 100644 --- a/MeshLib/MeshSearch/NodeSearch.cpp +++ b/MeshLib/MeshSearch/NodeSearch.cpp @@ -49,7 +49,9 @@ std::size_t NodeSearch::searchNodesConnectedToOnlyGivenElements( for (std::size_t i=0; i<node_marked_counts.size(); i++) { if (node_marked_counts[i] == _mesh.getNode(i)->getElements().size()) + { connected_nodes.push_back(i); + } } this->updateUnion(connected_nodes); @@ -62,9 +64,13 @@ std::size_t NodeSearch::searchUnused() const std::vector<MeshLib::Node*> &nodes (_mesh.getNodes()); std::vector<std::size_t> del_node_idx; - for (unsigned i=0; i<nNodes; ++i) + for (unsigned i = 0; i < nNodes; ++i) + { if (nodes[i]->getNumberOfElements() == 0) + { del_node_idx.push_back(i); + } + } this->updateUnion(del_node_idx); return del_node_idx.size(); @@ -76,26 +82,38 @@ std::size_t NodeSearch::searchBoundaryNodes() if (_mesh.getDimension() == 1) { for (MeshLib::Node const* n : _mesh.getNodes()) + { if (n->getElements().size() == 1) + { vec_boundary_nodes.push_back(n->getID()); + } + } } else if (_mesh.getDimension() == 2) { for (MeshLib::Element const* elem : _mesh.getElements()) { if (elem->getDimension() < _mesh.getDimension()) + { continue; + } if (!elem->isBoundaryElement()) + { continue; + } std::size_t const n_edges (elem->getNumberOfEdges()); for (std::size_t i=0; i<n_edges; ++i) { if (elem->getNeighbor(i) != nullptr) + { continue; + } std::unique_ptr<MeshLib::Element const> edge(elem->getEdge(i)); - for (unsigned j=0; j<edge->getNumberOfNodes(); j++) + for (unsigned j = 0; j < edge->getNumberOfNodes(); j++) + { vec_boundary_nodes.push_back(edge->getNode(j)->getID()); + } } } } @@ -104,18 +122,26 @@ std::size_t NodeSearch::searchBoundaryNodes() for (MeshLib::Element const* elem : _mesh.getElements()) { if (elem->getDimension() < _mesh.getDimension()) + { continue; + } if (!elem->isBoundaryElement()) + { continue; + } std::size_t const n_faces (elem->getNumberOfFaces()); for (std::size_t i=0; i<n_faces; ++i) { if (elem->getNeighbor(i) != nullptr) + { continue; + } std::unique_ptr<MeshLib::Element const> face(elem->getFace(i)); - for (unsigned j=0; j<face->getNumberOfNodes(); j++) + for (unsigned j = 0; j < face->getNumberOfNodes(); j++) + { vec_boundary_nodes.push_back(face->getNode(j)->getID()); + } } } } diff --git a/MeshLib/MeshSurfaceExtraction.cpp b/MeshLib/MeshSurfaceExtraction.cpp index 8e0de43d3fd61f097b4f2ba56067b502fd9e8d4d..e480b4e7373ad83c608330b2b20336e486249950 100644 --- a/MeshLib/MeshSurfaceExtraction.cpp +++ b/MeshLib/MeshSurfaceExtraction.cpp @@ -90,7 +90,9 @@ MeshLib::Mesh* MeshSurfaceExtraction::getMeshSurface( subsfc_mesh.getDimension()); if (sfc_elements.empty()) + { return nullptr; + } std::vector<MeshLib::Node*> sfc_nodes; std::vector<std::size_t> node_id_map(subsfc_mesh.getNumberOfNodes()); @@ -104,12 +106,17 @@ MeshLib::Mesh* MeshSurfaceExtraction::getMeshSurface( { unsigned const n_elem_nodes(sfc_element->getNumberOfBaseNodes()); auto** new_nodes = new MeshLib::Node*[n_elem_nodes]; - for (unsigned k(0); k<n_elem_nodes; k++) + for (unsigned k(0); k < n_elem_nodes; k++) + { new_nodes[k] = sfc_nodes[node_id_map[sfc_element->getNode(k)->getID()]]; + } if (sfc_element->getGeomType() == MeshElemType::TRIANGLE) + { new_elements.push_back(new MeshLib::Tri(new_nodes)); - else { + } + else + { assert(sfc_element->getGeomType() == MeshElemType::QUAD); new_elements.push_back(new MeshLib::Quad(new_nodes)); } @@ -121,7 +128,9 @@ MeshLib::Mesh* MeshSurfaceExtraction::getMeshSurface( { id_map.reserve(sfc_nodes.size()); for (auto const* node : sfc_nodes) + { id_map.push_back(node->getID()); + } } MeshLib::Mesh* result( new Mesh(subsfc_mesh.getName() + "-Surface", sfc_nodes, new_elements)); @@ -152,8 +161,10 @@ MeshLib::Mesh* MeshSurfaceExtraction::getMeshSurface( MeshLib::Mesh* MeshSurfaceExtraction::getMeshBoundary(const MeshLib::Mesh &mesh) { - if (mesh.getDimension()==1) + if (mesh.getDimension() == 1) + { return nullptr; + } // For 3D meshes return the 2D surface if (mesh.getDimension()==3) @@ -170,13 +181,15 @@ MeshLib::Mesh* MeshSurfaceExtraction::getMeshBoundary(const MeshLib::Mesh &mesh) for (auto elem : org_elems) { std::size_t const n_edges (elem->getNumberOfEdges()); - for (std::size_t i=0; i<n_edges; ++i) + for (std::size_t i = 0; i < n_edges; ++i) + { if (elem->getNeighbor(i) == nullptr) { MeshLib::Element const*const edge (elem->getEdge(i)); boundary_elements.push_back(MeshLib::copyElement(edge, nodes)); delete edge; } + } } MeshLib::Mesh* result = new MeshLib::Mesh("Boundary Mesh", nodes, boundary_elements); MeshLib::NodeSearch ns(*result); @@ -209,7 +222,9 @@ void MeshSurfaceExtraction::get2DSurfaceElements( { const unsigned element_dimension(elem->getDimension()); if (element_dimension < mesh_dimension) + { continue; + } if (element_dimension == 2) { @@ -219,7 +234,9 @@ void MeshSurfaceExtraction::get2DSurfaceElements( if (MathLib::scalarProduct( FaceRule::getSurfaceNormal(face).getNormalizedVector(), norm_dir) > cos_theta) + { continue; + } } sfc_elements.push_back(elem->clone()); element_to_bulk_element_id_map.push_back(elem->getID()); @@ -228,12 +245,16 @@ void MeshSurfaceExtraction::get2DSurfaceElements( else { if (!elem->isBoundaryElement()) + { continue; + } const unsigned nFaces(elem->getNumberOfFaces()); for (unsigned j = 0; j < nFaces; ++j) { if (elem->getNeighbor(j) != nullptr) + { continue; + } auto const face = std::unique_ptr<MeshLib::Element const>{elem->getFace(j)}; @@ -248,11 +269,15 @@ void MeshSurfaceExtraction::get2DSurfaceElements( } } if (face->getGeomType() == MeshElemType::TRIANGLE) + { sfc_elements.push_back(new MeshLib::Tri( *static_cast<const MeshLib::Tri*>(face.get()))); + } else + { sfc_elements.push_back(new MeshLib::Quad( *static_cast<const MeshLib::Quad*>(face.get()))); + } element_to_bulk_element_id_map.push_back(elem->getID()); element_to_bulk_face_id_map.push_back(j); } @@ -302,7 +327,9 @@ std::vector<MeshLib::Node*> MeshSurfaceExtraction::getSurfaceNodes( node_id_map); for (auto e : sfc_elements) + { delete e; + } return sfc_nodes; } diff --git a/MeshLib/Node.cpp b/MeshLib/Node.cpp index fbe4f712caef382870d03bf18e32f62c91ba2554..29ad1d2fe4ac8af337271fe33bc1e791a8d55f3e 100644 --- a/MeshLib/Node.cpp +++ b/MeshLib/Node.cpp @@ -45,15 +45,19 @@ void Node::updateCoordinates(double x, double y, double z) _x[2] = z; const std::size_t nElements (this->_elements.size()); - for (std::size_t i=0; i<nElements; i++) + for (std::size_t i = 0; i < nElements; i++) + { _elements[i]->computeVolume(); + } } bool isBaseNode(Node const& node) { // Check if node is connected. if (node.getNumberOfElements() == 0) + { return true; + } // In a mesh a node always belongs to at least one element. auto const e = node.getElement(0); diff --git a/MeshLib/NodeAdjacencyTable.h b/MeshLib/NodeAdjacencyTable.h index 832c42541d7a4f1b5cac0d728a686166ff75860c..65150ce0c524b944eb11f3ac3481d241b8ab5b73 100644 --- a/MeshLib/NodeAdjacencyTable.h +++ b/MeshLib/NodeAdjacencyTable.h @@ -61,7 +61,9 @@ public: void createTable(std::vector<Node*> const& nodes) { if (_data.size() != nodes.size()) + { _data.resize(nodes.size()); + } for (auto n_ptr : nodes) { diff --git a/MeshLib/Properties.cpp b/MeshLib/Properties.cpp index 556f5ec80e893662e02b1f92f0ffa2156fd78869..60d0fe32530358402dcc742c20839c497b18aeae 100644 --- a/MeshLib/Properties.cpp +++ b/MeshLib/Properties.cpp @@ -38,7 +38,9 @@ std::vector<std::string> Properties::getPropertyVectorNames() const { std::vector<std::string> names; for (auto p : _properties) + { names.push_back(p.first); + } return names; } @@ -49,7 +51,9 @@ std::vector<std::string> Properties::getPropertyVectorNames( for (auto p : _properties) { if (p.second->getMeshItemType() == t) + { names.push_back(p.first); + } } return names; } @@ -88,7 +92,9 @@ Properties Properties::excludeCopyProperties( exclude_mesh_item_types.end(), name_vector_pair.second->getMeshItemType()) != exclude_mesh_item_types.end()) + { continue; + } std::vector<std::size_t> const exclude_positions{}; new_properties._properties.insert( diff --git a/MeshLib/PropertyVector.h b/MeshLib/PropertyVector.h index 41f1eef2d984d220ac043bf72953720c195a9f6d..4b695c5f63f886ac195056782b27af6ea77dd487 100644 --- a/MeshLib/PropertyVector.h +++ b/MeshLib/PropertyVector.h @@ -146,7 +146,9 @@ public: ~PropertyVector() override { for (auto v : _values) - delete [] v; + { + delete[] v; + } } /// The operator[] uses the item to group property map to access to the @@ -164,8 +166,11 @@ public: void initPropertyValue(std::size_t group_id, T const& value) { if (_n_components != 1) - OGS_FATAL("Single-component version of initPropertyValue() is called " - "for a multi-components PropertyVector<T*>"); + { + OGS_FATAL( + "Single-component version of initPropertyValue() is called " + "for a multi-components PropertyVector<T*>"); + } auto* p = new T[1]; p[0] = value; _values[group_id] = p; @@ -174,12 +179,17 @@ public: void initPropertyValue(std::size_t group_id, std::vector<T> const& values) { if (_n_components != static_cast<int>(values.size())) - OGS_FATAL("The size of provided values in initPropertyValue() is " - "not same as the number of components in PropertyVector<T*>"); + { + OGS_FATAL( + "The size of provided values in initPropertyValue() is " + "not same as the number of components in PropertyVector<T*>"); + } auto* p = new T[values.size()]; - for (unsigned i=0; i<values.size(); i++) + for (unsigned i = 0; i < values.size(); i++) + { p[i] = values[i]; + } _values[group_id] = p; } @@ -220,9 +230,12 @@ public: assert(tuple_index < getNumberOfTuples()); const double* p = this->operator[](tuple_index); if (p == nullptr) - OGS_FATAL("No data found in the property vector %s " - "for the tuple index %d and component %d", - getPropertyName().c_str(), tuple_index, component); + { + OGS_FATAL( + "No data found in the property vector %s " + "for the tuple index %d and component %d", + getPropertyName().c_str(), tuple_index, component); + } return p[component]; } diff --git a/MeshLib/Vtk/VtkMappedMeshSource.cpp b/MeshLib/Vtk/VtkMappedMeshSource.cpp index 8ea8d5816e99f31a50ce4990c74f866a308b7496..01e8f1161a73347c78bfba4e120b5f100ccda6ed 100644 --- a/MeshLib/Vtk/VtkMappedMeshSource.cpp +++ b/MeshLib/Vtk/VtkMappedMeshSource.cpp @@ -48,10 +48,14 @@ int VtkMappedMeshSource::ProcessRequest(vtkInformation* request, vtkInformationVector* outputVector) { if (request->Has(vtkDemandDrivenPipeline::REQUEST_DATA())) + { return this->RequestData(request, inputVector, outputVector); + } if (request->Has(vtkDemandDrivenPipeline::REQUEST_INFORMATION())) + { return this->RequestInformation(request, inputVector, outputVector); + } return this->Superclass::ProcessRequest(request, inputVector, outputVector); } @@ -68,7 +72,9 @@ int VtkMappedMeshSource::RequestData(vtkInformation*, if (outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER()) > 0) + { return 1; + } // Points this->Points->Reset(); @@ -92,7 +98,9 @@ int VtkMappedMeshSource::RequestData(vtkInformation*, ptIds->SetNumberOfIds(numNodes); for (unsigned i = 0; i < numNodes; ++i) + { ptIds->SetId(i, nodes[i]->getID()); + } if (cellType == VTK_WEDGE) { @@ -107,16 +115,22 @@ int VtkMappedMeshSource::RequestData(vtkInformation*, { std::array<vtkIdType, 15> ogs_nodeIds; for (unsigned i = 0; i < 15; ++i) + { ogs_nodeIds[i] = ptIds->GetId(i); + } for (unsigned i = 0; i < 3; ++i) { ptIds->SetId(i, ogs_nodeIds[i + 3]); ptIds->SetId(i + 3, ogs_nodeIds[i]); } for (unsigned i = 0; i < 3; ++i) + { ptIds->SetId(6 + i, ogs_nodeIds[8 - i]); + } for (unsigned i = 0; i < 3; ++i) + { ptIds->SetId(9 + i, ogs_nodeIds[14 - i]); + } ptIds->SetId(12, ogs_nodeIds[9]); ptIds->SetId(13, ogs_nodeIds[11]); ptIds->SetId(14, ogs_nodeIds[10]); @@ -134,17 +148,29 @@ int VtkMappedMeshSource::RequestData(vtkInformation*, ++name) { if (addProperty<double>(properties, *name)) + { continue; + } if (addProperty<float>(properties, *name)) + { continue; + } if (addProperty<int>(properties, *name)) + { continue; + } if (addProperty<unsigned>(properties, *name)) + { continue; + } if (addProperty<std::size_t>(properties, *name)) + { continue; + } if (addProperty<char>(properties, *name)) + { continue; + } DBUG("Mesh property '%s' with unknown data type.", *name->c_str()); } @@ -170,12 +196,16 @@ bool VtkMappedMeshSource::addProperty(MeshLib::Properties const& properties, std::string const& prop_name) const { if (!properties.existsPropertyVector<T>(prop_name)) + { return false; + } // TODO: Hack removing const auto* propertyVector = const_cast<MeshLib::PropertyVector<T>*>( properties.getPropertyVector<T>(prop_name)); if (!propertyVector) + { return false; + } vtkNew<vtkAOSDataArrayTemplate<T>> dataArray; const bool hasArrayOwnership = false; @@ -186,12 +216,18 @@ bool VtkMappedMeshSource::addProperty(MeshLib::Properties const& properties, dataArray->SetName(prop_name.c_str()); if (propertyVector->getMeshItemType() == MeshLib::MeshItemType::Node) + { this->PointData->AddArray(dataArray.GetPointer()); + } else if (propertyVector->getMeshItemType() == MeshLib::MeshItemType::Cell) + { this->CellData->AddArray(dataArray.GetPointer()); + } else if (propertyVector->getMeshItemType() == MeshLib::MeshItemType::IntegrationPoint) + { this->FieldData->AddArray(dataArray.GetPointer()); + } return true; } diff --git a/MeshLib/Vtk/VtkMeshNodalCoordinatesTemplate-impl.h b/MeshLib/Vtk/VtkMeshNodalCoordinatesTemplate-impl.h index d4b399ca961032d0c345be52b87b3a79401de922..d42a5e7235de046c51f5fb410f01fd138d9e4a60 100644 --- a/MeshLib/Vtk/VtkMeshNodalCoordinatesTemplate-impl.h +++ b/MeshLib/Vtk/VtkMeshNodalCoordinatesTemplate-impl.h @@ -80,8 +80,10 @@ template <class Scalar> void VtkMeshNodalCoordinatesTemplate<Scalar> outArray->SetNumberOfTuples(numTuples); const vtkIdType numPoints = ptIds->GetNumberOfIds(); - for(vtkIdType i = 0; i < numPoints; i++) + for (vtkIdType i = 0; i < numPoints; i++) + { outArray->SetTuple(i, this->GetTuple(ptIds->GetId(i))); + } } template <class Scalar> void VtkMeshNodalCoordinatesTemplate<Scalar> @@ -100,8 +102,10 @@ template <class Scalar> void VtkMeshNodalCoordinatesTemplate<Scalar> return; } - for(vtkIdType daTubleId = 0; p1 <= p2; ++p1) + for (vtkIdType daTubleId = 0; p1 <= p2; ++p1) + { da->SetTuple(daTubleId++, this->GetTuple(p1)); + } } template <class Scalar> void VtkMeshNodalCoordinatesTemplate<Scalar> @@ -122,8 +126,10 @@ template <class Scalar> vtkIdType VtkMeshNodalCoordinatesTemplate<Scalar> { bool valid = true; Scalar val = vtkVariantCast<Scalar>(value, &valid); - if(valid) + if (valid) + { return this->Lookup(val, 0); + } return -1; } @@ -136,8 +142,10 @@ template <class Scalar> void VtkMeshNodalCoordinatesTemplate<Scalar> if(valid) { vtkIdType index = 0; - while((index = this->Lookup(val, index)) >= 0) + while ((index = this->Lookup(val, index)) >= 0) + { ids->InsertNextId(index++); + } } } @@ -179,8 +187,10 @@ template <class Scalar> void VtkMeshNodalCoordinatesTemplate<Scalar> { ids->Reset(); vtkIdType index = 0; - while((index = this->Lookup(value, index)) >= 0) + while ((index = this->Lookup(value, index)) >= 0) + { ids->InsertNextId(index++); + } } template <class Scalar> Scalar& VtkMeshNodalCoordinatesTemplate<Scalar> @@ -391,8 +401,10 @@ template <class Scalar> vtkIdType VtkMeshNodalCoordinatesTemplate<Scalar> { while(index <= this->MaxId) { - if(this->GetValueReference(index++) == val) + if (this->GetValueReference(index++) == val) + { return index; + } } return -1; } diff --git a/MeshLib/convertMeshToGeo.cpp b/MeshLib/convertMeshToGeo.cpp index 90bea97582218a5a0afc3b653977a830044ef40d..6f8f56db4a14565a0b429f6f5036ef09a40c585d 100644 --- a/MeshLib/convertMeshToGeo.cpp +++ b/MeshLib/convertMeshToGeo.cpp @@ -43,7 +43,9 @@ bool convertMeshToGeo(const MeshLib::Mesh &mesh, GeoLib::GEOObjects &geo_objects points->reserve(mesh.getNumberOfNodes()); for (auto node_ptr : mesh.getNodes()) + { points->push_back(new GeoLib::Point(*node_ptr, node_ptr->getID())); + } geo_objects.addPointVec(std::move(points), mesh_name, nullptr, eps); } @@ -56,8 +58,10 @@ bool convertMeshToGeo(const MeshLib::Mesh &mesh, GeoLib::GEOObjects &geo_objects auto sfcs = std::make_unique<std::vector<GeoLib::Surface*>>(); sfcs->reserve(nMatGroups); auto const& points = *geo_objects.getPointVec(mesh_name); - for (unsigned i=0; i<nMatGroups; ++i) + for (unsigned i = 0; i < nMatGroups; ++i) + { sfcs->push_back(new GeoLib::Surface(points)); + } const std::vector<MeshLib::Element*> &elements = mesh.getElements(); const std::size_t nElems (mesh.getNumberOfElements()); @@ -72,7 +76,11 @@ bool convertMeshToGeo(const MeshLib::Mesh &mesh, GeoLib::GEOObjects &geo_objects auto surfaceId = !materialIds ? 0 : ((*materialIds)[i] - bounds.first); MeshLib::Element* e (elements[i]); if (e->getGeomType() == MeshElemType::TRIANGLE) - (*sfcs)[surfaceId]->addTriangle(id_map[e->getNodeIndex(0)], id_map[e->getNodeIndex(1)], id_map[e->getNodeIndex(2)]); + { + (*sfcs)[surfaceId]->addTriangle(id_map[e->getNodeIndex(0)], + id_map[e->getNodeIndex(1)], + id_map[e->getNodeIndex(2)]); + } if (e->getGeomType() == MeshElemType::QUAD) { (*sfcs)[surfaceId]->addTriangle(id_map[e->getNodeIndex(0)], id_map[e->getNodeIndex(1)], id_map[e->getNodeIndex(2)]); @@ -81,7 +89,13 @@ bool convertMeshToGeo(const MeshLib::Mesh &mesh, GeoLib::GEOObjects &geo_objects // all other element types are ignored (i.e. lines) } - std::for_each(sfcs->begin(), sfcs->end(), [](GeoLib::Surface* sfc){ if (sfc->getNumberOfTriangles()==0) delete sfc; sfc = nullptr;}); + std::for_each(sfcs->begin(), sfcs->end(), [](GeoLib::Surface* sfc) { + if (sfc->getNumberOfTriangles() == 0) + { + delete sfc; + } + sfc = nullptr; + }); auto sfcs_end = std::remove(sfcs->begin(), sfcs->end(), nullptr); sfcs->erase(sfcs_end, sfcs->end()); @@ -99,11 +113,16 @@ MeshLib::Mesh* convertSurfaceToMesh(const GeoLib::Surface &sfc, const std::strin { auto* tri = sfc[i]; auto** tri_nodes = new MeshLib::Node*[3]; - for (unsigned j=0; j<3; j++) - tri_nodes[j] = new MeshLib::Node(tri->getPoint(j)->getCoords(), nodeId++); + for (unsigned j = 0; j < 3; j++) + { + tri_nodes[j] = + new MeshLib::Node(tri->getPoint(j)->getCoords(), nodeId++); + } elements.push_back(new MeshLib::Tri(tri_nodes, i)); - for (unsigned j=0; j<3; j++) + for (unsigned j = 0; j < 3; j++) + { nodes.push_back(tri_nodes[j]); + } } MeshLib::Mesh mesh_with_duplicated_nodes(mesh_name, nodes, elements); diff --git a/MeshLib/findElementsWithinRadius.cpp b/MeshLib/findElementsWithinRadius.cpp index 7d146be077e3ab718a9401fa3f758573e90bc736..15963656f6c3314a9b70f07f95ce20b0efb6183c 100644 --- a/MeshLib/findElementsWithinRadius.cpp +++ b/MeshLib/findElementsWithinRadius.cpp @@ -26,7 +26,9 @@ std::vector<std::size_t> findElementsWithinRadius(Element const& start_element, // Special case for 0 radius. All other radii will include at least one // neighbor of the start element. if (radius_squared == 0.) + { return {start_element.getID()}; + } // Collect start element node coordinates into local contigiuos memory. std::vector<MathLib::Point3d> start_element_nodes; @@ -34,7 +36,9 @@ std::vector<std::size_t> findElementsWithinRadius(Element const& start_element, auto const start_element_n_nodes = start_element.getNumberOfNodes(); start_element_nodes.reserve(start_element_n_nodes); for (unsigned n = 0; n < start_element_n_nodes; ++n) + { start_element_nodes.push_back(*start_element.getNode(n)); + } } // Returns true if the test node is inside the radius of any of the @@ -44,7 +48,9 @@ std::vector<std::size_t> findElementsWithinRadius(Element const& start_element, for (auto const& n : start_element_nodes) { if (MathLib::sqrDist(*test_node, n) <= radius_squared) + { return true; + } } return false; }; @@ -56,7 +62,9 @@ std::vector<std::size_t> findElementsWithinRadius(Element const& start_element, for (unsigned i = 0; i < n_nodes; ++i) { if (node_inside_radius(element.getNode(i))) + { return true; + } } return false; }; @@ -75,10 +83,14 @@ std::vector<std::size_t> findElementsWithinRadius(Element const& start_element, { auto neighbor = element.getNeighbor(n); if (neighbor == nullptr) + { continue; + } auto x = visited_elements.find(neighbor->getID()); if (x != visited_elements.end()) + { continue; + } neighbors_to_visit.push_back(neighbor); @@ -96,7 +108,9 @@ std::vector<std::size_t> findElementsWithinRadius(Element const& start_element, // If any node is inside the radius, all neighbors are visited. if (element_in_radius(current_element)) + { mark_visited_and_add_neighbors(current_element); + } } return {std::begin(found_elements), std::end(found_elements)}; diff --git a/NumLib/Assembler/SerialExecutor.h b/NumLib/Assembler/SerialExecutor.h index eb2f2096ac6d1352d2cffe675832d8adc90d776e..2856d502824888a6890fdd43e72879d07a265037 100644 --- a/NumLib/Assembler/SerialExecutor.h +++ b/NumLib/Assembler/SerialExecutor.h @@ -53,7 +53,9 @@ struct SerialExecutor #endif { for (std::size_t i = 0; i < c.size(); i++) + { f(i, *c[i], std::forward<Args_>(args)...); + } } /// Executes the given \c method of the given \c object for each element @@ -199,7 +201,9 @@ struct SerialExecutor assert(c.size() == data.size()); for (std::size_t i = 0; i < c.size(); i++) + { f(i, *c[i], data[i], std::forward<Args_>(args)...); + } } }; diff --git a/NumLib/DOF/ComponentGlobalIndexDict.h b/NumLib/DOF/ComponentGlobalIndexDict.h index e752595a1c94a213a1bf2394385aaeeeb7b403e7..1d0c302b7722a8d90a130a717a7bc561ea09f7b9 100644 --- a/NumLib/DOF/ComponentGlobalIndexDict.h +++ b/NumLib/DOF/ComponentGlobalIndexDict.h @@ -75,9 +75,13 @@ struct LineByLocationAndComponentComparator bool operator()(Line const& a, Line const& b) const { if (a.location < b.location) + { return true; + } if (b.location < a.location) + { return false; + } // a.loc == b.loc return a.comp_id < b.comp_id; diff --git a/NumLib/DOF/ComputeSparsityPattern.cpp b/NumLib/DOF/ComputeSparsityPattern.cpp index 7bbe2f4541e8a1825e90e914c8ebb917f287c554..b3ab5c551b503bf25aec5e9b0e7de146831ba137 100644 --- a/NumLib/DOF/ComputeSparsityPattern.cpp +++ b/NumLib/DOF/ComputeSparsityPattern.cpp @@ -55,9 +55,13 @@ GlobalSparsityPattern computeSparsityPatternNonPETSc( { unsigned n_connected_dof = 0; for (auto an : node_adjacency_table.getAdjacentNodes(n)) + { n_connected_dof += global_idcs[an].size(); + } for (auto global_index : global_idcs[n]) + { sparsity_pattern[global_index] = n_connected_dof; + } } return sparsity_pattern; diff --git a/NumLib/DOF/DOFTableUtil.cpp b/NumLib/DOF/DOFTableUtil.cpp index a4bb14b296a6620f9f8401e563627a9c295827a4..ec8e7fd80d2ceb6f4eae01f1605b08bf05f8bc0f 100644 --- a/NumLib/DOF/DOFTableUtil.cpp +++ b/NumLib/DOF/DOFTableUtil.cpp @@ -98,8 +98,10 @@ double getNonGhostNodalValue(GlobalVector const& x, MeshLib::Mesh const& mesh, auto const index = dof_table.getGlobalIndex(l, global_component_id); assert (index != NumLib::MeshComponentMap::nop); - if (index < 0) // ghost node value + if (index < 0) + { // ghost node value return 0.0; + } return x.get(index); } diff --git a/NumLib/DOF/LocalToGlobalIndexMap.cpp b/NumLib/DOF/LocalToGlobalIndexMap.cpp index c23e28d1a6ef7d61052271dc1e177f6619b2ba45..51844d49a06cc62da5513fbfffae1da6e03867e1 100644 --- a/NumLib/DOF/LocalToGlobalIndexMap.cpp +++ b/NumLib/DOF/LocalToGlobalIndexMap.cpp @@ -56,8 +56,10 @@ void LocalToGlobalIndexMap::findGlobalIndicesWithElementID( n < (*e)->getNodes()+(*e)->getNumberOfNodes(); ++n) { // Check if the element's node is in the given list of nodes. - if (set_nodes.find(*n)==set_nodes.end()) + if (set_nodes.find(*n) == set_nodes.end()) + { continue; + } MeshLib::Location l( mesh_id, MeshLib::MeshItemType::Node, (*n)->getID()); indices.push_back(_mesh_component_map.getGlobalIndex(l, comp_id)); @@ -90,8 +92,10 @@ void LocalToGlobalIndexMap::findGlobalIndices( n < (*e)->getNodes() + (*e)->getNumberOfNodes(); ++n) { // Check if the element's node is in the given list of nodes. - if (set_nodes.find(*n)==set_nodes.end()) + if (set_nodes.find(*n) == set_nodes.end()) + { continue; + } MeshLib::Location l( mesh_id, MeshLib::MeshItemType::Node, (*n)->getID()); auto const global_index = @@ -165,7 +169,9 @@ LocalToGlobalIndexMap::LocalToGlobalIndexMap( for (std::vector<MeshLib::Element*>const* eles : vec_var_elements) { for (auto e : *eles) + { max_elem_id = std::max(max_elem_id, e->getID()); + } } _rows.resize(max_elem_id + 1, _mesh_subsets.size()); @@ -205,10 +211,12 @@ LocalToGlobalIndexMap::LocalToGlobalIndexMap( { // Each subset in the mesh_subsets represents a single component. if (_mesh_subsets.size() != global_component_ids.size()) + { OGS_FATAL( "Number of mesh subsets is not equal to number of components. " "There are %d mesh subsets and %d components.", _mesh_subsets.size(), global_component_ids.size()); + } for (int i = 0; i < static_cast<int>(global_component_ids.size()); ++i) { @@ -231,7 +239,9 @@ LocalToGlobalIndexMap* LocalToGlobalIndexMap::deriveBoundaryConstrainedMap( DBUG("Construct reduced local to global index map."); if (component_ids.empty()) + { OGS_FATAL("Expected non-empty vector of component ids."); + } // Elements of the new_mesh_subset's mesh. std::vector<MeshLib::Element*> const& elements = @@ -241,8 +251,10 @@ LocalToGlobalIndexMap* LocalToGlobalIndexMap::deriveBoundaryConstrainedMap( std::vector<int> global_component_ids; for (auto component_id : component_ids) + { global_component_ids.push_back( getGlobalComponent(variable_id, component_id)); + } auto mesh_component_map = _mesh_component_map.getSubset( _mesh_subsets, new_mesh_subset, global_component_ids); @@ -251,7 +263,9 @@ LocalToGlobalIndexMap* LocalToGlobalIndexMap::deriveBoundaryConstrainedMap( // The last component is moved after the for-loop. std::vector<MeshLib::MeshSubset> all_mesh_subsets; for (int i = 0; i < static_cast<int>(global_component_ids.size()) - 1; ++i) + { all_mesh_subsets.emplace_back(new_mesh_subset); + } all_mesh_subsets.emplace_back(std::move(new_mesh_subset)); return new LocalToGlobalIndexMap( @@ -285,7 +299,9 @@ LocalToGlobalIndexMap::deriveBoundaryConstrainedMap( // The last component is moved after the for-loop. std::vector<MeshLib::MeshSubset> all_mesh_subsets; for (int i = 0; i < static_cast<int>(global_component_ids.size()) - 1; ++i) + { all_mesh_subsets.emplace_back(new_mesh_subset); + } all_mesh_subsets.emplace_back(std::move(new_mesh_subset)); return std::make_unique<LocalToGlobalIndexMap>( @@ -353,7 +369,9 @@ LocalToGlobalIndexMap::getNumberOfElementComponents(std::size_t const mesh_item_ for (Table::Index c = 0; c < _rows.cols(); ++c) { if (!_rows(mesh_item_id, c).empty()) + { n++; + } } return n; } @@ -368,7 +386,9 @@ std::vector<int> LocalToGlobalIndexMap::getElementVariableIDs( { auto comp_id = getGlobalComponent(i, j); if (!_rows(mesh_item_id, comp_id).empty()) + { vec.push_back(i); + } } } std::sort(vec.begin(), vec.end()); diff --git a/NumLib/DOF/MeshComponentMap.cpp b/NumLib/DOF/MeshComponentMap.cpp index 16c86273c24fece6075787b7ed96996be0221239..14f45525205c10f8ca686e564bb07d04b2271c60 100644 --- a/NumLib/DOF/MeshComponentMap.cpp +++ b/NumLib/DOF/MeshComponentMap.cpp @@ -102,15 +102,19 @@ MeshComponentMap::MeshComponentMap( std::size_t const mesh_id = c.getMeshID(); // mesh items are ordered first by node, cell, .... for (std::size_t j = 0; j < c.getNumberOfNodes(); j++) + { _dict.insert(Line( Location(mesh_id, MeshLib::MeshItemType::Node, c.getNodeID(j)), comp_id, global_index++)); + } comp_id++; } _num_local_dof = _dict.size(); if (order == ComponentOrder::BY_LOCATION) + { renumberByLocation(); + } } #endif // end of USE_PETSC @@ -217,8 +221,10 @@ std::vector<int> MeshComponentMap::getComponentIDs(const Location& l) const auto const &m = _dict.get<ByLocation>(); auto const p = m.equal_range(Line(l)); std::vector<int> vec_compID; - for (auto itr=p.first; itr!=p.second; ++itr) + for (auto itr = p.first; itr != p.second; ++itr) + { vec_compID.push_back(itr->comp_id); + } return vec_compID; } @@ -243,8 +249,10 @@ std::vector<GlobalIndexType> MeshComponentMap::getGlobalIndices(const Location & auto const &m = _dict.get<ByLocation>(); auto const p = m.equal_range(Line(l)); std::vector<GlobalIndexType> global_indices; - for (auto itr=p.first; itr!=p.second; ++itr) + for (auto itr = p.first; itr != p.second; ++itr) + { global_indices.push_back(itr->global_index); + } return global_indices; } @@ -262,7 +270,9 @@ std::vector<GlobalIndexType> MeshComponentMap::getGlobalIndicesByLocation( { auto const p = m.equal_range(Line(l)); for (auto itr = p.first; itr != p.second; ++itr) + { global_indices.push_back(itr->global_index); + } } return global_indices; @@ -282,7 +292,9 @@ std::vector<GlobalIndexType> MeshComponentMap::getGlobalIndicesByComponent( { auto const p = m.equal_range(Line(l)); for (auto itr = p.first; itr != p.second; ++itr) + { pairs.emplace_back(itr->comp_id, itr->global_index); + } } auto CIPairLess = [](CIPair const& a, CIPair const& b) @@ -292,12 +304,16 @@ std::vector<GlobalIndexType> MeshComponentMap::getGlobalIndicesByComponent( // Create vector of global indices from sub dictionary sorting by component. if (!std::is_sorted(pairs.begin(), pairs.end(), CIPairLess)) + { std::stable_sort(pairs.begin(), pairs.end(), CIPairLess); + } std::vector<GlobalIndexType> global_indices; global_indices.reserve(pairs.size()); for (const auto& pair : pairs) + { global_indices.push_back(pair.second); + } return global_indices; } diff --git a/NumLib/DOF/SimpleMatrixVectorProvider.cpp b/NumLib/DOF/SimpleMatrixVectorProvider.cpp index 914aecb84a336aa78cf83331d5e76716ba35e7a9..cf343d8f30d99d37baa6fae06d6110eee6358810 100644 --- a/NumLib/DOF/SimpleMatrixVectorProvider.cpp +++ b/NumLib/DOF/SimpleMatrixVectorProvider.cpp @@ -74,8 +74,10 @@ get_(std::size_t& id, if (do_search) { auto it = unused_map.find(id); - if (it != unused_map.end()) // unused matrix/vector found - return { ::detail::transfer(unused_map, used_map, it), false }; + if (it != unused_map.end()) + { // unused matrix/vector found + return {::detail::transfer(unused_map, used_map, it), false}; + } } // not searched or not found, so create a new one @@ -134,8 +136,10 @@ getMatrix(GlobalMatrix const& A) { std::size_t id = 0u; auto const& res = getMatrix_<false>(id, A); - if (!res.second) // no new object has been created + if (!res.second) + { // no new object has been created LinAlg::copy(A, *res.first); + } return *res.first; } @@ -144,8 +148,10 @@ SimpleMatrixVectorProvider:: getMatrix(GlobalMatrix const& A, std::size_t& id) { auto const& res = getMatrix_<true>(id, A); - if (!res.second) // no new object has been created + if (!res.second) + { // no new object has been created LinAlg::copy(A, *res.first); + } return *res.first; } @@ -208,8 +214,10 @@ getVector(GlobalVector const& x) { std::size_t id = 0u; auto const& res = getVector_<false>(id, x); - if (!res.second) // no new object has been created + if (!res.second) + { // no new object has been created LinAlg::copy(x, *res.first); + } return *res.first; } @@ -218,8 +226,10 @@ SimpleMatrixVectorProvider:: getVector(GlobalVector const& x, std::size_t& id) { auto const& res = getVector_<true>(id, x); - if (!res.second) // no new object has been created + if (!res.second) + { // no new object has been created LinAlg::copy(x, *res.first); + } return *res.first; } @@ -244,16 +254,24 @@ SimpleMatrixVectorProvider:: } for (auto& id_ptr : _unused_matrices) + { delete id_ptr.second; + } for (auto& ptr_id : _used_matrices) + { delete ptr_id.first; + } for (auto& id_ptr : _unused_vectors) + { delete id_ptr.second; + } for (auto& ptr_id : _used_vectors) + { delete ptr_id.first; + } } } // namespace NumLib diff --git a/NumLib/Extrapolation/LocalLinearLeastSquaresExtrapolator.cpp b/NumLib/Extrapolation/LocalLinearLeastSquaresExtrapolator.cpp index c769f32e99eefbf1ca4a57840bd8dbb1d529c387..f0b5689f404eed6c290714ae026dc4808b087e53 100644 --- a/NumLib/Extrapolation/LocalLinearLeastSquaresExtrapolator.cpp +++ b/NumLib/Extrapolation/LocalLinearLeastSquaresExtrapolator.cpp @@ -33,9 +33,11 @@ LocalLinearLeastSquaresExtrapolator::LocalLinearLeastSquaresExtrapolator( * some more advanced process, like the TES process. */ if (dof_table.getNumberOfComponents() != 1) + { OGS_FATAL( "The d.o.f. table passed must be for one variable that has " "only one component!"); + } } void LocalLinearLeastSquaresExtrapolator::extrapolate( @@ -154,19 +156,23 @@ void LocalLinearLeastSquaresExtrapolator::extrapolateElement( static_cast<unsigned>(integration_point_values.size()); if (num_values % num_components != 0) + { OGS_FATAL( "The number of computed integration point values is not divisable " "by the number of num_components. Maybe the computed property is " "not a %d-component vector for each integration point.", num_components); + } // number of integration points in the element const auto num_int_pts = num_values / num_components; if (num_int_pts < num_nodes) + { OGS_FATAL( "Least squares is not possible if there are more nodes than" "integration points."); + } auto const pair_it_inserted = _qr_decomposition_cache.emplace( std::make_pair(num_nodes, num_int_pts), CachedData{}); @@ -280,11 +286,13 @@ void LocalLinearLeastSquaresExtrapolator::calculateResidualElement( auto const num_values = static_cast<unsigned>(int_pt_vals.size()); if (num_values % num_components != 0) + { OGS_FATAL( "The number of computed integration point values is not divisable " "by the number of num_components. Maybe the computed property is " "not a %d-component vector for each integration point.", num_components); + } // number of integration points in the element const auto num_int_pts = num_values / num_components; diff --git a/NumLib/Fem/CoordinatesMapping/NaturalCoordinatesMapping.cpp b/NumLib/Fem/CoordinatesMapping/NaturalCoordinatesMapping.cpp index b74e572e4f3bfb8e658ac8ca4aad43142297f5e6..6147fbbccf65e834a3f207e4f06dfc2677a33aa3 100644 --- a/NumLib/Fem/CoordinatesMapping/NaturalCoordinatesMapping.cpp +++ b/NumLib/Fem/CoordinatesMapping/NaturalCoordinatesMapping.cpp @@ -102,8 +102,10 @@ computeMappingMatrices( static void checkJacobianDeterminant(const double detJ, MeshLib::Element const& element) { - if (detJ > 0) // The usual case + if (detJ > 0) + { // The usual case return; + } if (detJ < 0) { diff --git a/NumLib/Fem/CoordinatesMapping/ShapeMatrices-impl.h b/NumLib/Fem/CoordinatesMapping/ShapeMatrices-impl.h index 8172ed31b6bb23d935015628e4d6d32dbc725840..e3ef9f6eb83e79a0ea15d7b6b5cef1e439a058d6 100644 --- a/NumLib/Fem/CoordinatesMapping/ShapeMatrices-impl.h +++ b/NumLib/Fem/CoordinatesMapping/ShapeMatrices-impl.h @@ -25,8 +25,10 @@ void setMatrixZero(T &mat) //mat.setZero(); const std::size_t n = mat.rows()*mat.cols(); auto* v = mat.data(); - for (std::size_t i=0; i<n; i++) + for (std::size_t i = 0; i < n; i++) + { v[i] = .0; + } } template<class T> @@ -35,8 +37,10 @@ void setVectorZero(T &vec) //vec.setZero(); const std::size_t n = vec.size(); auto* v = vec.data(); - for (std::size_t i=0; i<n; i++) + for (std::size_t i = 0; i < n; i++) + { v[i] = .0; + } } /* diff --git a/NumLib/Function/LinearInterpolationAlongPolyline.cpp b/NumLib/Function/LinearInterpolationAlongPolyline.cpp index 281435abd18625a90f93b5bf2f63122b3b71ffe6..8eff055a784e4c53aa51107ccc35ab7f7dcee7ab 100644 --- a/NumLib/Function/LinearInterpolationAlongPolyline.cpp +++ b/NumLib/Function/LinearInterpolationAlongPolyline.cpp @@ -42,7 +42,9 @@ MathLib::PiecewiseLinearInterpolation LinearInterpolationAlongPolyline::createIn { const std::size_t pnt_id = vec_interpolate_point_ids[i]; if (!ply.isPointIDInPolyline(pnt_id)) + { continue; + } for (std::size_t j=0; j<ply.getNumberOfPoints(); j++) { diff --git a/NumLib/Function/LinearInterpolationOnSurface.cpp b/NumLib/Function/LinearInterpolationOnSurface.cpp index a04630323955f498721750cdc0f0a7005b347b41..67e653cf5fc03f6d4ec8306a3ba9d5b082fb9934 100644 --- a/NumLib/Function/LinearInterpolationOnSurface.cpp +++ b/NumLib/Function/LinearInterpolationOnSurface.cpp @@ -43,10 +43,14 @@ LinearInterpolationOnSurface::LinearInterpolationOnSurface( double LinearInterpolationOnSurface::operator()(const MathLib::Point3d& pnt) const { if (!_sfc.isPntInBoundingVolume(pnt, 0)) + { return _default_value; + } auto* tri = _sfc.findTriangle(pnt); if (tri == nullptr) + { return _default_value; + } std::array<double, 3> pnt_values; for (unsigned j=0; j<3; j++) { @@ -68,8 +72,10 @@ double LinearInterpolationOnSurface::interpolateInTri( MathLib::Point3d const& pnt) const { std::vector<GeoLib::Point> pnts; - for (unsigned i=0; i<3; i++) + for (unsigned i = 0; i < 3; i++) + { pnts.emplace_back(*tri.getPoint(i)); + } pnts.emplace_back(pnt, -1); std::vector<GeoLib::Point*> p_pnts = {{&pnts[0], &pnts[1], &pnts[2], &pnts[3]}}; GeoLib::rotatePointsToXY(p_pnts.begin(), p_pnts.begin()+3, p_pnts.begin(), p_pnts.end()); @@ -104,8 +110,10 @@ double LinearInterpolationOnSurface::interpolateInTri( c[2] = 0.5/area*(v2[0]-v1[0]); double val = .0; - for (unsigned i=0; i<3; i++) - val += (a[i]+b[i]*v_pnt[0]+c[i]*v_pnt[1]) * vertex_values[i]; + for (unsigned i = 0; i < 3; i++) + { + val += (a[i] + b[i] * v_pnt[0] + c[i] * v_pnt[1]) * vertex_values[i]; + } return val; } diff --git a/NumLib/NamedFunctionCaller.cpp b/NumLib/NamedFunctionCaller.cpp index d4eeb01793b184ae56fca7ab2d7ffd456f62d0cb..50c2d58b9757347d5f039faaa40914cc55f9ff07 100644 --- a/NumLib/NamedFunctionCaller.cpp +++ b/NumLib/NamedFunctionCaller.cpp @@ -33,8 +33,10 @@ bool hasTopologicalOrdering(std::vector<std::vector<int>> const& graph) { for (int node_j : node_i_adjacencies) { - if (node_j >= 0) // ignore negative indices. + if (node_j >= 0) + { // ignore negative indices. ++number_incoming_edges[node_j]; + } } } @@ -61,7 +63,9 @@ bool hasTopologicalOrdering(std::vector<std::vector<int>> const& graph) for (int node_j : graph[node_i]) { if (node_j < 0) + { continue; // ignore negative indices + } if (--number_incoming_edges[node_j] == 0) { // Add a node without incoming edges to the queue. q.push_back(node_j); @@ -89,13 +93,17 @@ void traverse(std::vector<std::vector<int>> const& map_sink_source, callback(sink_fct, TraversePosition::StartNode); if (sink_fct < 0) + { return; + } auto const& si_so = map_sink_source[sink_fct]; std::size_t const num_args = si_so.size(); for (std::size_t sink_arg = 0; sink_arg != num_args; ++sink_arg) { if (sink_arg != 0) + { callback(sink_fct, TraversePosition::BetweenChildren); + } traverse(map_sink_source, si_so[sink_arg], callback); } diff --git a/NumLib/NewtonRaphson.h b/NumLib/NewtonRaphson.h index cff66487247f3138c110e994ed379da9afefe932..719b9dae759deecfe0e4cecced5a3742ea239e83 100644 --- a/NumLib/NewtonRaphson.h +++ b/NumLib/NewtonRaphson.h @@ -64,7 +64,9 @@ public: _residual_update(residual); if (residual.squaredNorm() < _tolerance_squared) + { break; // convergence criteria fulfilled. + } increment.noalias() = _linear_solver.compute(jacobian).solve(-residual); diff --git a/NumLib/ODESolver/ConvergenceCriterionDeltaX.cpp b/NumLib/ODESolver/ConvergenceCriterionDeltaX.cpp index 50a5e55ec867a118b4333993d8c25f51662161cf..efc95b5ef217b8b3dd8e00c88c51c39400a66041 100644 --- a/NumLib/ODESolver/ConvergenceCriterionDeltaX.cpp +++ b/NumLib/ODESolver/ConvergenceCriterionDeltaX.cpp @@ -24,9 +24,11 @@ ConvergenceCriterionDeltaX::ConvergenceCriterionDeltaX( _reltol(std::move(relative_tolerance)) { if ((!_abstol) && (!_reltol)) + { OGS_FATAL( "At least one of absolute or relative tolerance has to be " "specified."); + } } void ConvergenceCriterionDeltaX::checkDeltaX(const GlobalVector& minus_delta_x, @@ -69,7 +71,9 @@ std::unique_ptr<ConvergenceCriterionDeltaX> createConvergenceCriterionDeltaX( auto const norm_type = MathLib::convertStringToVecNormType(norm_type_str); if (norm_type == MathLib::VecNormType::INVALID) + { OGS_FATAL("Unknown vector norm type `%s'.", norm_type_str.c_str()); + } return std::make_unique<ConvergenceCriterionDeltaX>( std::move(abstol), std::move(reltol), norm_type); diff --git a/NumLib/ODESolver/ConvergenceCriterionPerComponentDeltaX.cpp b/NumLib/ODESolver/ConvergenceCriterionPerComponentDeltaX.cpp index 17df667db5ffb8ce53de3611823b6b169f5437ae..0a087016cf2f980d06dd19fbef73e4fdf979f3f6 100644 --- a/NumLib/ODESolver/ConvergenceCriterionPerComponentDeltaX.cpp +++ b/NumLib/ODESolver/ConvergenceCriterionPerComponentDeltaX.cpp @@ -26,19 +26,25 @@ ConvergenceCriterionPerComponentDeltaX::ConvergenceCriterionPerComponentDeltaX( _reltols(std::move(relative_tolerances)) { if (_abstols.size() != _reltols.size()) + { OGS_FATAL( "The number of absolute and relative tolerances given must be the " "same."); + } if (_abstols.empty()) + { OGS_FATAL("The given tolerances vector is empty."); + } } void ConvergenceCriterionPerComponentDeltaX::checkDeltaX( const GlobalVector& minus_delta_x, GlobalVector const& x) { if ((!_dof_table) || (!_mesh)) + { OGS_FATAL("D.o.f. table or mesh have not been set."); + } bool satisfied_abs = true; bool satisfied_rel = true; @@ -76,9 +82,11 @@ void ConvergenceCriterionPerComponentDeltaX::setDOFTable( if (_dof_table->getNumberOfComponents() != static_cast<int>(_abstols.size())) + { OGS_FATAL( "The number of components in the DOF table and the number of " "tolerances given do not match."); + } } std::unique_ptr<ConvergenceCriterionPerComponentDeltaX> @@ -98,9 +106,11 @@ createConvergenceCriterionPerComponentDeltaX(const BaseLib::ConfigTree& config) config.getConfigParameter<std::string>("norm_type"); if ((!abstols) && (!reltols)) + { OGS_FATAL( "At least one of absolute or relative tolerance has to be " "specified."); + } if (!abstols) { abstols = std::vector<double>(reltols->size()); } else if (!reltols) { @@ -110,7 +120,9 @@ createConvergenceCriterionPerComponentDeltaX(const BaseLib::ConfigTree& config) auto const norm_type = MathLib::convertStringToVecNormType(norm_type_str); if (norm_type == MathLib::VecNormType::INVALID) + { OGS_FATAL("Unknown vector norm type `%s'.", norm_type_str.c_str()); + } return std::make_unique<ConvergenceCriterionPerComponentDeltaX>( std::move(*abstols), std::move(*reltols), norm_type); diff --git a/NumLib/ODESolver/ConvergenceCriterionPerComponentResidual.cpp b/NumLib/ODESolver/ConvergenceCriterionPerComponentResidual.cpp index a9c5d71a920255cb6562bc22191129f2ed10c398..95fe6ef7a0a1afb6ba6082f06d378d86621e437d 100644 --- a/NumLib/ODESolver/ConvergenceCriterionPerComponentResidual.cpp +++ b/NumLib/ODESolver/ConvergenceCriterionPerComponentResidual.cpp @@ -27,12 +27,16 @@ ConvergenceCriterionPerComponentResidual:: _residual_norms_0(_abstols.size()) { if (_abstols.size() != _reltols.size()) + { OGS_FATAL( "The number of absolute and relative tolerances given must be the " "same."); + } if (_abstols.empty()) + { OGS_FATAL("The given tolerances vector is empty."); + } } @@ -40,7 +44,9 @@ void ConvergenceCriterionPerComponentResidual::checkDeltaX( const GlobalVector& minus_delta_x, GlobalVector const& x) { if ((!_dof_table) || (!_mesh)) + { OGS_FATAL("D.o.f. table or mesh have not been set."); + } for (unsigned global_component = 0; global_component < _abstols.size(); ++global_component) @@ -65,7 +71,9 @@ void ConvergenceCriterionPerComponentResidual::checkResidual( const GlobalVector& residual) { if ((!_dof_table) || (!_mesh)) + { OGS_FATAL("D.o.f. table or mesh have not been set."); + } bool satisfied_abs = true; // Make sure that in the first iteration the relative residual tolerance is @@ -110,9 +118,11 @@ void ConvergenceCriterionPerComponentResidual::setDOFTable( if (_dof_table->getNumberOfComponents() != static_cast<int>(_abstols.size())) + { OGS_FATAL( "The number of components in the DOF table and the number of " "tolerances given do not match."); + } } std::unique_ptr<ConvergenceCriterionPerComponentResidual> @@ -133,9 +143,11 @@ createConvergenceCriterionPerComponentResidual( config.getConfigParameter<std::string>("norm_type"); if ((!abstols) && (!reltols)) + { OGS_FATAL( "At least one of absolute or relative tolerance has to be " "specified."); + } if (!abstols) { abstols = std::vector<double>(reltols->size()); } else if (!reltols) { @@ -145,7 +157,9 @@ createConvergenceCriterionPerComponentResidual( auto const norm_type = MathLib::convertStringToVecNormType(norm_type_str); if (norm_type == MathLib::VecNormType::INVALID) + { OGS_FATAL("Unknown vector norm type `%s'.", norm_type_str.c_str()); + } return std::make_unique<ConvergenceCriterionPerComponentResidual>( std::move(*abstols), std::move(*reltols), norm_type); diff --git a/NumLib/ODESolver/ConvergenceCriterionResidual.cpp b/NumLib/ODESolver/ConvergenceCriterionResidual.cpp index a2641d7cb50bf26b6f3935273e38c4554cfbc59b..8d2d61957f60ae661b29c782491168ebfa22c802 100644 --- a/NumLib/ODESolver/ConvergenceCriterionResidual.cpp +++ b/NumLib/ODESolver/ConvergenceCriterionResidual.cpp @@ -24,9 +24,11 @@ ConvergenceCriterionResidual::ConvergenceCriterionResidual( _reltol(std::move(relative_tolerance)) { if ((!_abstol) && (!_reltol)) + { OGS_FATAL( "At least one of absolute or relative tolerance has to be " "specified."); + } } void ConvergenceCriterionResidual::checkDeltaX( @@ -103,7 +105,9 @@ createConvergenceCriterionResidual(const BaseLib::ConfigTree& config) auto const norm_type = MathLib::convertStringToVecNormType(norm_type_str); if (norm_type == MathLib::VecNormType::INVALID) + { OGS_FATAL("Unknown vector norm type `%s'.", norm_type_str.c_str()); + } return std::make_unique<ConvergenceCriterionResidual>( std::move(abstol), std::move(reltol), norm_type); diff --git a/NumLib/ODESolver/NonlinearSolver.cpp b/NumLib/ODESolver/NonlinearSolver.cpp index 5a8eb8f63998030d6b5963007ae5666b9014619b..93dd4b71c46da5a2f0e61b1d8944f2e8f4eb58c7 100644 --- a/NumLib/ODESolver/NonlinearSolver.cpp +++ b/NumLib/ODESolver/NonlinearSolver.cpp @@ -94,7 +94,9 @@ NonlinearSolverStatus NonlinearSolver<NonlinearSolverTag::Picard>::solve( else { if (postIterationCallback) + { postIterationCallback(iteration, x_new); + } switch (sys.postIteration(x_new)) { @@ -147,12 +149,16 @@ NonlinearSolverStatus NonlinearSolver<NonlinearSolverTag::Picard>::solve( time_iteration.elapsed()); if (error_norms_met) + { break; + } // Avoid increment of the 'iteration' if the error norms are not met, // but maximum number of iterations is reached. if (iteration >= _maxiter) + { break; + } } if (iteration > _maxiter) @@ -234,7 +240,9 @@ NonlinearSolverStatus NonlinearSolver<NonlinearSolverTag::Newton>::solve( INFO("[time] Applying Dirichlet BCs took %g s.", time_dirichlet); if (!sys.isLinear() && _convergence_criterion->hasResidualCheck()) + { _convergence_criterion->checkResidual(res); + } BaseLib::RunTime time_linear_solver; time_linear_solver.start(); @@ -255,7 +263,9 @@ NonlinearSolverStatus NonlinearSolver<NonlinearSolverTag::Newton>::solve( LinAlg::axpy(x_new, -_damping, minus_delta_x); if (postIterationCallback) + { postIterationCallback(iteration, x_new); + } switch(sys.postIteration(x_new)) { @@ -302,12 +312,16 @@ NonlinearSolverStatus NonlinearSolver<NonlinearSolverTag::Newton>::solve( time_iteration.elapsed()); if (error_norms_met) + { break; + } // Avoid increment of the 'iteration' if the error norms are not met, // but maximum number of iterations is reached. if (iteration >= _maxiter) + { break; + } } if (iteration > _maxiter) diff --git a/NumLib/ODESolver/TimeDiscretization.cpp b/NumLib/ODESolver/TimeDiscretization.cpp index 3df5e23d2929174b25679f8fcc4d02760904c22f..264db390acd010c3a4a94b9fe45fff0a925142c8 100644 --- a/NumLib/ODESolver/TimeDiscretization.cpp +++ b/NumLib/ODESolver/TimeDiscretization.cpp @@ -26,7 +26,9 @@ double TimeDiscretization::computeRelativeChangeFromPreviousTimestep( } if (!_dx) + { _dx = MathLib::MatrixVectorTraits<GlobalVector>::newInstance(x); + } auto& dx = *_dx; MathLib::LinAlg::copy(x, dx); // copy x to dx. @@ -37,11 +39,15 @@ double TimeDiscretization::computeRelativeChangeFromPreviousTimestep( const double norm_x = MathLib::LinAlg::norm(x, norm_type); if (norm_x > std::numeric_limits<double>::epsilon()) + { return norm_dx / norm_x; + } // Both of norm_x and norm_dx are close to zero if (norm_dx < std::numeric_limits<double>::epsilon()) + { return 1.0; + } // Only norm_x is close to zero return norm_dx / std::numeric_limits<double>::epsilon(); diff --git a/NumLib/ODESolver/TimeDiscretization.h b/NumLib/ODESolver/TimeDiscretization.h index c1b5db164c9e5c62d74757512b0c5ca03ca67882..32303aeb5b7c6742c6c38d127c8b710b25d47170 100644 --- a/NumLib/ODESolver/TimeDiscretization.h +++ b/NumLib/ODESolver/TimeDiscretization.h @@ -474,7 +474,9 @@ public: ~BackwardDifferentiationFormula() override { for (auto* x : _xs_old) + { NumLib::GlobalVectorProvider::provider.releaseVector(*x); + } } void setInitialState(const double t0, GlobalVector const& x0) override diff --git a/NumLib/ODESolver/TimeDiscretizedODESystem.cpp b/NumLib/ODESolver/TimeDiscretizedODESystem.cpp index c352440db0b47b2e2667c00ebd345b172ca12492..5c0b725f06d733a0039a782d27dea75c43427322 100644 --- a/NumLib/ODESolver/TimeDiscretizedODESystem.cpp +++ b/NumLib/ODESolver/TimeDiscretizedODESystem.cpp @@ -21,7 +21,9 @@ void applyKnownSolutions(std::vector<Solutions> const* const known_solutions, Vector& x) { if (!known_solutions) + { return; + } for (auto const& bc : *known_solutions) { @@ -140,7 +142,9 @@ void TimeDiscretizedODESystem<ODESystemTag::FirstOrderImplicitQuasilinear, GlobalVector& minus_delta_x) const { if (!_known_solutions) + { return; + } using IndexType = MathLib::MatrixVectorTraits<GlobalMatrix>::Index; std::vector<IndexType> ids; @@ -221,7 +225,9 @@ void TimeDiscretizedODESystem<ODESystemTag::FirstOrderImplicitQuasilinear, GlobalVector& x) const { if (!_known_solutions) + { return; + } using IndexType = MathLib::MatrixVectorTraits<GlobalMatrix>::Index; std::vector<IndexType> ids; diff --git a/NumLib/TimeStepping/Algorithms/EvolutionaryPIDcontroller.cpp b/NumLib/TimeStepping/Algorithms/EvolutionaryPIDcontroller.cpp index ca5103224da9055d1f73d1145f625fd4d403f43c..21e54d04033f5d22c8beb85927b274cacd30ffa9 100644 --- a/NumLib/TimeStepping/Algorithms/EvolutionaryPIDcontroller.cpp +++ b/NumLib/TimeStepping/Algorithms/EvolutionaryPIDcontroller.cpp @@ -127,7 +127,9 @@ double EvolutionaryPIDcontroller::limitStepSize( // step size is then reduced by half. if (std::fabs(limited_h - _ts_current.dt()) < std::numeric_limits<double>::min()) + { limited_h = std::max(_h_min, 0.5 * limited_h); + } // If the last time step was rejected and the new predicted time step // size is larger than the step size of the rejected step, the new step @@ -136,7 +138,9 @@ double EvolutionaryPIDcontroller::limitStepSize( // solver. In such case, this algorithm may give a large time step size // by using the diverged solution. if (limited_h > _ts_current.dt()) + { limited_h = std::max(_h_min, 0.5 * _ts_current.dt()); + } } return limited_h; } @@ -144,7 +148,9 @@ double EvolutionaryPIDcontroller::limitStepSize( double EvolutionaryPIDcontroller::checkSpecificTimeReached(const double h_new) { if (_fixed_output_times.empty()) + { return h_new; + } const double specific_time = _fixed_output_times.back(); if ((specific_time > _ts_current.current()) && diff --git a/NumLib/TimeStepping/Algorithms/FixedTimeStepping.cpp b/NumLib/TimeStepping/Algorithms/FixedTimeStepping.cpp index 52dda10f01934d95304c616ad29cbe9bb64b6b1f..159635a2bb369732501d3b6cc356e4fbe02017b7 100644 --- a/NumLib/TimeStepping/Algorithms/FixedTimeStepping.cpp +++ b/NumLib/TimeStepping/Algorithms/FixedTimeStepping.cpp @@ -37,17 +37,23 @@ bool FixedTimeStepping::next(double const /*solution_error*/, if (_ts_current.steps() == _dt_vector.size() || std::abs(_ts_current.current() - _t_end) < std::numeric_limits<double>::epsilon()) + { return false; + } // confirm current time and move to the next if accepted if (accepted()) + { _ts_prev = _ts_current; + } // prepare the next time step info _ts_current = _ts_prev; double dt = _dt_vector[_ts_prev.steps()]; - if (_ts_prev.current() + dt > _t_end) // upper bound by t_end + if (_ts_prev.current() + dt > _t_end) + { // upper bound by t_end dt = _t_end - _ts_prev.current(); + } _ts_current += dt; return true; diff --git a/ProcessLib/BoundaryCondition/BoundaryConditionCollection.cpp b/ProcessLib/BoundaryCondition/BoundaryConditionCollection.cpp index 629d65334bff79e455c3e0cb865bf485030818c4..9fa65d6d983da45a302d5c925cdca8f3a26042d4 100644 --- a/ProcessLib/BoundaryCondition/BoundaryConditionCollection.cpp +++ b/ProcessLib/BoundaryCondition/BoundaryConditionCollection.cpp @@ -18,7 +18,9 @@ void BoundaryConditionCollection::applyNaturalBC(const double t, GlobalMatrix* Jac) { for (auto const& bc : _boundary_conditions) + { bc->applyNaturalBC(t, x, K, b, Jac); + } } void BoundaryConditionCollection::addBCsForProcessVariables( diff --git a/ProcessLib/BoundaryCondition/ConstraintDirichletBoundaryCondition.cpp b/ProcessLib/BoundaryCondition/ConstraintDirichletBoundaryCondition.cpp index a81ca8489860f8151855bf548578af49093e212e..51e87faf7f4151c20bb5298abeef28fdad698510 100644 --- a/ProcessLib/BoundaryCondition/ConstraintDirichletBoundaryCondition.cpp +++ b/ProcessLib/BoundaryCondition/ConstraintDirichletBoundaryCondition.cpp @@ -161,7 +161,9 @@ void ConstraintDirichletBoundaryCondition::getEssentialBCValues( const auto g_idx = _dof_table_boundary->getGlobalIndex( l, _variable_id, _component_id); if (g_idx == NumLib::MeshComponentMap::nop) + { continue; + } // For the DDC approach (e.g. with PETSc option), the negative // index of g_idx means that the entry by that index is a ghost one, // which should be dropped. Especially for PETSc routines diff --git a/ProcessLib/BoundaryCondition/DirichletBoundaryConditionAuxiliaryFunctions.cpp b/ProcessLib/BoundaryCondition/DirichletBoundaryConditionAuxiliaryFunctions.cpp index 0e16093b5b61c7c4aa14c9868e08a5571eeb3b2f..58f9714b057c4008a2969dbff16a060679bf70b3 100644 --- a/ProcessLib/BoundaryCondition/DirichletBoundaryConditionAuxiliaryFunctions.cpp +++ b/ProcessLib/BoundaryCondition/DirichletBoundaryConditionAuxiliaryFunctions.cpp @@ -80,7 +80,9 @@ void getEssentialBCValuesLocal( {bc_mesh.getID(), MeshLib::MeshItemType::Node, id}, variable_id, component_id); if (global_index == NumLib::MeshComponentMap::nop) + { continue; + } // For the DDC approach (e.g. with PETSc option), the negative // index of global_index means that the entry by that index is a ghost // one, which should be dropped. Especially for PETSc routines diff --git a/ProcessLib/BoundaryCondition/NonuniformDirichletBoundaryCondition.h b/ProcessLib/BoundaryCondition/NonuniformDirichletBoundaryCondition.h index 4d81295cf729077a4afe1c387371510b8732d95e..ba67cb886f3236a3089ce0f421a5140486f857f8 100644 --- a/ProcessLib/BoundaryCondition/NonuniformDirichletBoundaryCondition.h +++ b/ProcessLib/BoundaryCondition/NonuniformDirichletBoundaryCondition.h @@ -94,7 +94,9 @@ public: {_boundary_mesh.getID(), MeshLib::MeshItemType::Node, node_id}, _variable_id, _component_id); if (global_index == NumLib::MeshComponentMap::nop) + { continue; + } // For the DDC approach (e.g. with PETSc option), the negative index // of global_index means that the entry by that index is a ghost // one, which should be dropped. Especially for PETSc routines diff --git a/ProcessLib/BoundaryCondition/NormalTractionBoundaryConditionLocalAssembler.h b/ProcessLib/BoundaryCondition/NormalTractionBoundaryConditionLocalAssembler.h index 2356f22692679c57f9dbe066d395d6eedbdc0358..7f1315dced38b34461fd55ae631de1b4d8e2687d 100644 --- a/ProcessLib/BoundaryCondition/NormalTractionBoundaryConditionLocalAssembler.h +++ b/ProcessLib/BoundaryCondition/NormalTractionBoundaryConditionLocalAssembler.h @@ -110,9 +110,11 @@ public: GlobalDim, displacement_size>::Zero(GlobalDim, displacement_size); for (int i = 0; i < static_cast<int>(GlobalDim); ++i) + { N_u.template block<1, displacement_size / GlobalDim>( i, i * displacement_size / GlobalDim) .noalias() = shape_matrices_u[ip].N; + } double const integration_weight = _integration_method.getWeightedPoint(ip).getWeight() * diff --git a/ProcessLib/CentralDifferencesJacobianAssembler.cpp b/ProcessLib/CentralDifferencesJacobianAssembler.cpp index bed278a60f443935f2aaf143e42d7e4e1a9cef77..4e48ce4acc883b52603e5a367be2076605342eb2 100644 --- a/ProcessLib/CentralDifferencesJacobianAssembler.cpp +++ b/ProcessLib/CentralDifferencesJacobianAssembler.cpp @@ -19,7 +19,9 @@ CentralDifferencesJacobianAssembler::CentralDifferencesJacobianAssembler( : _absolute_epsilons(std::move(absolute_epsilons)) { if (_absolute_epsilons.empty()) + { OGS_FATAL("No values for the absolute epsilons have been given."); + } } void CentralDifferencesJacobianAssembler::assembleWithJacobian( diff --git a/ProcessLib/ComponentTransport/ComponentTransportFEM.h b/ProcessLib/ComponentTransport/ComponentTransportFEM.h index 3a3196da2f9050e7ebfdd657f46b5f7577a63ded..6f036701cb8c174d40cff1499a19f010757ff684 100644 --- a/ProcessLib/ComponentTransport/ComponentTransportFEM.h +++ b/ProcessLib/ComponentTransport/ComponentTransportFEM.h @@ -362,8 +362,10 @@ public: w * dNdx.transpose() * density * K_over_mu * dNdx; if (_process_data.has_gravity) + { Bp += w * density * density * dNdx.transpose() * K_over_mu * b; + } } } } diff --git a/ProcessLib/ComponentTransport/CreateComponentTransportProcess.cpp b/ProcessLib/ComponentTransport/CreateComponentTransportProcess.cpp index db2ecd3bca8c04cf174f35f96e1cdb7c36000463..640fb0cd63127cfec1cc0692ec7debf9e4e1c970 100644 --- a/ProcessLib/ComponentTransport/CreateComponentTransportProcess.cpp +++ b/ProcessLib/ComponentTransport/CreateComponentTransportProcess.cpp @@ -73,11 +73,13 @@ std::unique_ptr<Process> createComponentTransportProcess( }); if (it != collected_process_variables.end()) + { OGS_FATAL( "Number of components for process variable '%s' should be 1 rather " "than %d.", it->get().getName().c_str(), it->get().getNumberOfComponents()); + } // Allocate the collected process variables into a two-dimensional vector, // depending on what scheme is adopted @@ -134,10 +136,12 @@ std::unique_ptr<Process> createComponentTransportProcess( config.getConfigParameter<std::vector<double>>("specific_body_force"); assert(b.size() > 0 && b.size() < 4); if (b.size() < mesh.getDimension()) + { OGS_FATAL( "specific body force (gravity vector) has %d components, mesh " "dimension is %d", b.size(), mesh.getDimension()); + } bool const has_gravity = MathLib::toVector(b).norm() > 0; if (has_gravity) { diff --git a/ProcessLib/CoupledSolutionsForStaggeredScheme.cpp b/ProcessLib/CoupledSolutionsForStaggeredScheme.cpp index 287d26bf71b62be0be3c35c4d4c9ad84d9c2447d..366ebfc7cd15ef258e8258539a68b3e74ac20ced 100644 --- a/ProcessLib/CoupledSolutionsForStaggeredScheme.cpp +++ b/ProcessLib/CoupledSolutionsForStaggeredScheme.cpp @@ -33,7 +33,9 @@ std::vector<std::vector<double>> getPreviousLocalSolutions( const std::vector<std::vector<GlobalIndexType>>& indices) { if (cpl_xs.coupled_xs_t0.empty()) + { return {}; + } const auto number_of_coupled_solutions = cpl_xs.coupled_xs.size(); std::vector<std::vector<double>> local_xs_t0; @@ -53,7 +55,9 @@ std::vector<std::vector<double>> getCurrentLocalSolutions( const std::vector<std::vector<GlobalIndexType>>& indices) { if (cpl_xs.coupled_xs.empty()) + { return {}; + } const auto number_of_coupled_solutions = cpl_xs.coupled_xs.size(); std::vector<std::vector<double>> local_xs_t1; diff --git a/ProcessLib/CreateJacobianAssembler.cpp b/ProcessLib/CreateJacobianAssembler.cpp index b149987e13e0cf392ef9c9c420c61bfa2d0c1ce5..898f18efad4f4313aab69222cec3be89e853ebb5 100644 --- a/ProcessLib/CreateJacobianAssembler.cpp +++ b/ProcessLib/CreateJacobianAssembler.cpp @@ -20,7 +20,9 @@ std::unique_ptr<AbstractJacobianAssembler> createJacobianAssembler( boost::optional<BaseLib::ConfigTree> const& config) { if (!config) + { return std::make_unique<AnalyticalJacobianAssembler>(); + } //! \ogs_file_param{prj__processes__process__jacobian_assembler__type} auto const type = config->peekConfigParameter<std::string>("type"); diff --git a/ProcessLib/DeactivatedSubdomain.cpp b/ProcessLib/DeactivatedSubdomain.cpp index 82a715609663545487f12dfbe80103b342d982fe..26487b9ef304f39499d3eea6c16b5897f8f4f43f 100644 --- a/ProcessLib/DeactivatedSubdomain.cpp +++ b/ProcessLib/DeactivatedSubdomain.cpp @@ -99,7 +99,9 @@ std::unique_ptr<DeactivatedSubdomain const> createDeactivatedSubdomain( for (std::size_t i = 0; i < mesh.getNumberOfElements(); i++) { if (ids != (*material_ids)[i]) + { continue; + } auto* element = mesh.getElement(i); deactivated_elements.push_back( @@ -111,7 +113,9 @@ std::unique_ptr<DeactivatedSubdomain const> createDeactivatedSubdomain( const auto& connected_elements = node->getElements(); if (deactivation_flag_of_nodes[node->getID()]) + { continue; + } // Check whether this node is in an activated element. if (std::find_if( @@ -121,7 +125,9 @@ std::unique_ptr<DeactivatedSubdomain const> createDeactivatedSubdomain( return ids != (*material_ids)[connected_elem->getID()]; }) != connected_elements.end()) + { continue; + } deactivated_nodes.push_back(const_cast<MeshLib::Node*>(node)); deactivation_flag_of_nodes[node->getID()] = true; diff --git a/ProcessLib/Deformation/MaterialForces.h b/ProcessLib/Deformation/MaterialForces.h index 12a7693d6055bff86f6a73341195c2f4d961886b..2ab9460cc58877da3fab83bf5e4e95df3bde4c5a 100644 --- a/ProcessLib/Deformation/MaterialForces.h +++ b/ProcessLib/Deformation/MaterialForces.h @@ -141,9 +141,12 @@ std::vector<double> const& getMaterialForces( eshelby_stress[4] -= sigma[2] * grad_u[4]; } else + { OGS_FATAL( - "Material forces not implemented for displacement dimension " + "Material forces not implemented for displacement " + "dimension " "other than 2 and 3."); + } auto const& w = _ip_data[ip].integration_weight; local_b += G.transpose() * eshelby_stress * w; diff --git a/ProcessLib/HT/HTFEM.h b/ProcessLib/HT/HTFEM.h index f96585ca9bd3493de65bdb30279b27dbe4988256..a08ff5af5d564529853ad0e910bcfc413613617a 100644 --- a/ProcessLib/HT/HTFEM.h +++ b/ProcessLib/HT/HTFEM.h @@ -192,7 +192,9 @@ protected: thermal_conductivity_fluid * porosity; if (!_material_properties.has_fluid_thermal_dispersivity) + { return thermal_conductivity * I; + } double const thermal_dispersivity_longitudinal = _material_properties.thermal_dispersivity_longitudinal(t, pos)[0]; diff --git a/ProcessLib/HT/MonolithicHTFEM.h b/ProcessLib/HT/MonolithicHTFEM.h index bdeab13a09b23fc5b5d55e2718f81ce99c4e2efa..a9a7e20bf6d1c66c2deb7e293d8290d1d2ae5b85 100644 --- a/ProcessLib/HT/MonolithicHTFEM.h +++ b/ProcessLib/HT/MonolithicHTFEM.h @@ -178,7 +178,9 @@ public: N.transpose() * N; Mpp.noalias() += w * N.transpose() * specific_storage * N; if (process_data.has_gravity) + { Bp += w * fluid_density * dNdx.transpose() * K_over_mu * b; + } /* with Oberbeck-Boussing assumption density difference only exists * in buoyancy effects */ } diff --git a/ProcessLib/HT/StaggeredHTFEM-impl.h b/ProcessLib/HT/StaggeredHTFEM-impl.h index d9b257a5dcbeb1c0f14ea5a1dc60c0dfd8cdd258..0308f8608bc07d9c7bda5d103c2e6d75c2e74310 100644 --- a/ProcessLib/HT/StaggeredHTFEM-impl.h +++ b/ProcessLib/HT/StaggeredHTFEM-impl.h @@ -142,7 +142,9 @@ void StaggeredHTFEM<ShapeFunction, IntegrationMethod, GlobalDim>:: } if (!material_properties.has_fluid_thermal_expansion) + { return; + } // Add the thermal expansion term { diff --git a/ProcessLib/HydroMechanics/HydroMechanicsFEM-impl.h b/ProcessLib/HydroMechanics/HydroMechanicsFEM-impl.h index 28a8ebe49b2da6c6811fa8aa59fa26cc84897e18..1e730badd8dde31195cfa1f4edb93d11a56b3025 100644 --- a/ProcessLib/HydroMechanics/HydroMechanicsFEM-impl.h +++ b/ProcessLib/HydroMechanics/HydroMechanicsFEM-impl.h @@ -83,10 +83,12 @@ HydroMechanicsLocalAssembler<ShapeFunctionDisplacement, ShapeFunctionPressure, DisplacementDim, displacement_size>::Zero(DisplacementDim, displacement_size); for (int i = 0; i < DisplacementDim; ++i) + { ip_data.N_u_op .template block<1, displacement_size / DisplacementDim>( i, i * displacement_size / DisplacementDim) .noalias() = sm_u.N; + } ip_data.N_u = sm_u.N; ip_data.dNdx_u = sm_u.dNdx; diff --git a/ProcessLib/HydroMechanics/HydroMechanicsFEM.h b/ProcessLib/HydroMechanics/HydroMechanicsFEM.h index 910c3f6f0705f9d3fc6c9af676fc6e5b9332d1dc..e56ae1a01dbf56c59e6a99ed399a72f585bf2cd7 100644 --- a/ProcessLib/HydroMechanics/HydroMechanicsFEM.h +++ b/ProcessLib/HydroMechanics/HydroMechanicsFEM.h @@ -82,7 +82,9 @@ struct IntegrationPointData final *material_state_variables, T); if (!solution) + { OGS_FATAL("Computation of local constitutive relation failed."); + } MathLib::KelvinVector::KelvinMatrixType<DisplacementDim> C; std::tie(sigma_eff, material_state_variables, C) = std::move(*solution); @@ -308,10 +310,14 @@ private: for (auto const& ip_data : _ip_data) { - if (component < 3) // xx, yy, zz components + if (component < 3) + { // xx, yy, zz components cache.push_back(ip_data.sigma_eff[component]); - else // mixed xy, yz, xz components + } + else + { // mixed xy, yz, xz components cache.push_back(ip_data.sigma_eff[component] / std::sqrt(2)); + } } return cache; diff --git a/ProcessLib/HydroMechanics/LocalDataInitializer.h b/ProcessLib/HydroMechanics/LocalDataInitializer.h index a5a6c94749e8f20f98267a5bd9d37302363b1884..123de39a53c53672309c6e72ce3bcf00cb2619ac 100644 --- a/ProcessLib/HydroMechanics/LocalDataInitializer.h +++ b/ProcessLib/HydroMechanics/LocalDataInitializer.h @@ -130,10 +130,12 @@ public: : _dof_table(dof_table) { if (shapefunction_order != 2) + { OGS_FATAL( "The given shape function order %d is not supported.\nOnly " "shape functions of order 2 are supported.", shapefunction_order); + } // /// Quads and Hexahedra /////////////////////////////////// #if (OGS_ENABLED_ELEMENTS & ENABLED_ELEMENT_TYPE_QUAD) != 0 && \ diff --git a/ProcessLib/LIE/Common/LevelSetFunction.cpp b/ProcessLib/LIE/Common/LevelSetFunction.cpp index 1ca4e5e4740ba3151ad94d1c904d767f2ea437d2..3ce37d764f4b9b25309d3442043889e99fec7a07 100644 --- a/ProcessLib/LIE/Common/LevelSetFunction.cpp +++ b/ProcessLib/LIE/Common/LevelSetFunction.cpp @@ -51,7 +51,9 @@ std::vector<double> uGlobalEnrichments( // pre-calculate levelsets for all fractures std::vector<double> levelsets(frac_props.size()); for (std::size_t i = 0; i < frac_props.size(); i++) + { levelsets[i] = Heaviside(levelsetFracture(*frac_props[i], x)); + } std::vector<double> enrichments(frac_props.size() + junction_props.size()); // fractures possibly with branches @@ -60,7 +62,9 @@ std::vector<double> uGlobalEnrichments( auto const* frac = frac_props[i]; double enrich = levelsets[i]; for (std::size_t j = 0; j < frac->branches_slave.size(); j++) + { enrich *= Heaviside(levelsetBranch(frac->branches_slave[j], x)); + } enrichments[i] = enrich; } @@ -89,7 +93,9 @@ std::vector<double> duGlobalEnrichments( // pre-calculate levelsets for all fractures std::vector<double> levelsets(frac_props.size()); for (std::size_t i = 0; i < frac_props.size(); i++) + { levelsets[i] = Heaviside(levelsetFracture(*frac_props[i], x)); + } std::vector<double> enrichments(frac_props.size() + junction_props.size()); enrichments[this_frac_local_index] = 1.0; @@ -100,11 +106,15 @@ std::vector<double> duGlobalEnrichments( for (auto const& branch : this_frac.branches_master) { if (branch.master_fracture_id != this_frac.fracture_id) + { continue; + } if (fracID_to_local.find(branch.slave_fracture_id) == fracID_to_local.end()) + { continue; + } double singned = boost::math::sign( this_frac.normal_vector.dot(branch.normal_vector_branch)); @@ -119,7 +129,9 @@ std::vector<double> duGlobalEnrichments( { auto const* junction = junction_props[i]; if (!BaseLib::contains(junction->fracture_ids, this_frac.fracture_id)) + { continue; + } auto another_frac_id = (junction->fracture_ids[0] == this_frac.fracture_id) diff --git a/ProcessLib/LIE/Common/MeshUtils.cpp b/ProcessLib/LIE/Common/MeshUtils.cpp index f2ce2311a9313536daffaa3d9a77b57a23b1fbd6..b66276a059ad8116df9fb7b428f9081abc1e70bb 100644 --- a/ProcessLib/LIE/Common/MeshUtils.cpp +++ b/ProcessLib/LIE/Common/MeshUtils.cpp @@ -35,18 +35,26 @@ public: MeshLib::NodeSearch nodeSearch(mesh); nodeSearch.searchBoundaryNodes(); for (auto i : nodeSearch.getSearchedNodeIDs()) + { _is_internal_node[i] = false; + } } bool operator()(MeshLib::Node const& node) const { if (!_is_internal_node[node.getID()] || !_mesh.isBaseNode(node.getID())) + { return false; + } unsigned n_connected_fracture_elements = 0; for (MeshLib::Element const* e : node.getElements()) + { if (e->getDimension() == _fracture_element_dim) + { n_connected_fracture_elements++; + } + } assert(n_connected_fracture_elements > 0); return (n_connected_fracture_elements == 1); @@ -71,20 +79,30 @@ void findFracutreIntersections( auto const n_fractures = vec_fracture_mat_IDs.size(); std::map<unsigned, unsigned> matID_to_fid; for (unsigned i = 0; i < n_fractures; i++) + { matID_to_fid[vec_fracture_mat_IDs[i]] = i; + } // make a vector all fracture nodes std::vector<std::size_t> all_fracture_nodes; for (auto& vec : vec_fracture_nodes) + { for (auto* node : vec) + { all_fracture_nodes.push_back(node->getID()); + } + } // create a table of a node id and connected material IDs std::map<std::size_t, std::vector<std::size_t>> frac_nodeID_to_matIDs; for (unsigned i = 0; i < n_fractures; i++) + { for (auto* node : vec_fracture_nodes[i]) + { frac_nodeID_to_matIDs[node->getID()].push_back( vec_fracture_mat_IDs[i]); + } + } auto const* const opt_material_ids = MeshLib::materialIDs(mesh); @@ -96,20 +114,28 @@ void findFracutreIntersections( auto const* node = mesh.getNode(entry.first); auto const& matIDs = entry.second; if (matIDs.size() < 2) + { continue; // no intersection + } std::vector<MeshLib::Element*> conn_fracture_elements; { for (auto const* e : node->getElements()) + { if (e->getDimension() == (mesh.getDimension() - 1)) + { conn_fracture_elements.push_back( const_cast<MeshLib::Element*>(e)); + } + } } std::map<int, int> vec_matID_counts; { for (auto matid : matIDs) + { vec_matID_counts[matid] = 0; + } for (auto const* e : conn_fracture_elements) { @@ -124,8 +150,10 @@ void findFracutreIntersections( for (auto* e : conn_fracture_elements) { auto e_matid = (*opt_material_ids)[e->getID()]; - if (matID_to_fid[e_matid] != fid) // only slave elements + if (matID_to_fid[e_matid] != fid) + { // only slave elements intersected_fracture_elements[fid].push_back(e); + } } } @@ -173,7 +201,9 @@ void findFracutreIntersections( } for (auto& eles : intersected_fracture_elements) + { BaseLib::makeVectorUnique(eles); + } DBUG("-> found %d branchs and %d junctions", vec_branch_nodeID_matIDs.size(), vec_junction_nodeID_matIDs.size()); @@ -201,9 +231,13 @@ void getFractureMatrixDataInMesh( for (MeshLib::Element* e : mesh.getElements()) { if (e->getDimension() == mesh.getDimension()) + { vec_matrix_elements.push_back(e); + } else + { all_fracture_elements.push_back(e); + } } DBUG("-> found total %d matrix elements and %d fracture elements", vec_matrix_elements.size(), all_fracture_elements.size()); @@ -215,7 +249,9 @@ void getFractureMatrixDataInMesh( OGS_FATAL("Could not access MaterialIDs property from mesh."); } for (MeshLib::Element* e : all_fracture_elements) + { vec_fracture_mat_IDs.push_back((*material_ids)[e->getID()]); + } BaseLib::makeVectorUnique(vec_fracture_mat_IDs); DBUG("-> found %d fracture material groups", vec_fracture_mat_IDs.size()); @@ -245,7 +281,9 @@ void getFractureMatrixDataInMesh( for (unsigned i = 0; i < e->getNumberOfNodes(); i++) { if (isCrackTip(*e->getNode(i))) + { continue; + } vec_nodes.push_back(const_cast<MeshLib::Node*>(e->getNode(i))); } } @@ -278,13 +316,17 @@ void getFractureMatrixDataInMesh( { MeshLib::Node const* node = e->getNode(i); if (isCrackTip(*node)) + { continue; + } for (unsigned j = 0; j < node->getNumberOfElements(); j++) { // only matrix elements if (node->getElement(j)->getDimension() < mesh.getDimension()) + { continue; + } vec_ele.push_back( const_cast<MeshLib::Element*>(node->getElement(j))); } diff --git a/ProcessLib/LIE/Common/PostUtils.cpp b/ProcessLib/LIE/Common/PostUtils.cpp index d929da00a7432b6c060a26b58d78f1644947844a..eaa7a56409d831e771417e77381694aa0bb3db11 100644 --- a/ProcessLib/LIE/Common/PostUtils.cpp +++ b/ProcessLib/LIE/Common/PostUtils.cpp @@ -105,12 +105,16 @@ PostProcessTool::PostProcessTool( { // only matrix elements if (org_e->getDimension() != org_mesh.getDimension()) + { continue; + } auto const eid = org_e->getID(); // keep original if the element has levelset=0 if ((*prop_levelset)[eid] == 0) + { continue; + } // replace fracture nodes with duplicated ones MeshLib::Element* e = new_eles[eid]; @@ -118,12 +122,16 @@ PostProcessTool::PostProcessTool( { const auto node_id = e->getNodeIndex(i); if (!includesNodeID(vec_fracture_nodes, node_id)) + { continue; + } // list of duplicated node IDs auto itr = _map_dup_newNodeIDs.find(node_id); if (itr == _map_dup_newNodeIDs.end()) + { continue; + } const auto& dup_newNodeIDs = itr->second; // choose new node id @@ -216,7 +224,9 @@ void PostProcessTool::createProperties() for (auto name : src_properties.getPropertyVectorNames()) { if (!src_properties.existsPropertyVector<T>(name)) + { continue; + } auto const* src_prop = src_properties.getPropertyVector<T>(name); auto const n_src_comp = src_prop->getNumberOfComponents(); @@ -255,7 +265,9 @@ void PostProcessTool::copyProperties() for (auto name : src_properties.getPropertyVectorNames()) { if (!src_properties.existsPropertyVector<T>(name)) + { continue; + } auto const* src_prop = src_properties.getPropertyVector<T>(name); auto* dest_prop = _output_mesh->getProperties().getPropertyVector<T>(name); @@ -268,19 +280,27 @@ void PostProcessTool::copyProperties() for (unsigned i = 0; i < _org_mesh.getNumberOfNodes(); i++) { for (int j = 0; j < n_src_comp; j++) + { (*dest_prop)[i * n_dest_comp + j] = (*src_prop)[i * n_src_comp + j]; + } // set zero for components not existing in the original for (int j = n_src_comp; j < n_dest_comp; j++) + { (*dest_prop)[i * n_dest_comp + j] = 0; + } } // copy duplicated for (auto itr : _map_dup_newNodeIDs) { for (int j = 0; j < n_dest_comp; j++) + { for (unsigned k = 0; k < itr.second.size(); k++) + { (*dest_prop)[itr.second[k] * n_dest_comp + j] = (*dest_prop)[itr.first * n_dest_comp + j]; + } + } } } else if (src_prop->getMeshItemType() == MeshLib::MeshItemType::Cell) @@ -311,7 +331,9 @@ void PostProcessTool::calculateTotalDisplacement(unsigned const n_fractures, for (unsigned i = 0; i < _output_mesh->getNodes().size(); i++) { for (int j = 0; j < n_u_comp; j++) + { total_u[i * n_u_comp + j] = u[i * n_u_comp + j]; + } } for (unsigned enrich_id = 0; enrich_id < n_fractures + n_junctions; @@ -326,13 +348,19 @@ void PostProcessTool::calculateTotalDisplacement(unsigned const n_fractures, for (MeshLib::Element const* e : _output_mesh->getElements()) { if (e->getDimension() != _output_mesh->getDimension()) + { continue; + } const double e_levelset = ele_levelset[e->getID()]; if (e_levelset == 0) + { continue; + } for (unsigned i = 0; i < e->getNumberOfNodes(); i++) + { nodal_levelset[e->getNodeIndex(i)] = e_levelset; + } } // update total displacements @@ -342,8 +370,10 @@ void PostProcessTool::calculateTotalDisplacement(unsigned const n_fractures, for (unsigned i = 0; i < _output_mesh->getNodes().size(); i++) { for (int j = 0; j < n_u_comp; j++) + { total_u[i * n_u_comp + j] += nodal_levelset[i] * g[i * n_u_comp + j]; + } } } } diff --git a/ProcessLib/LiquidFlow/LiquidFlowLocalAssembler-impl.h b/ProcessLib/LiquidFlow/LiquidFlowLocalAssembler-impl.h index c12919c33284197813d20c8ce2000de6b6459def..eeff64bb5309618883c3c923c6204f1f99ce1cb0 100644 --- a/ProcessLib/LiquidFlow/LiquidFlowLocalAssembler-impl.h +++ b/ProcessLib/LiquidFlow/LiquidFlowLocalAssembler-impl.h @@ -39,14 +39,18 @@ void LiquidFlowLocalAssembler<ShapeFunction, IntegrationMethod, GlobalDim>:: // _element->getDimension() assert(permeability.rows() == GlobalDim || permeability.rows() == 1); - if (permeability.size() == 1) // isotropic or 1D problem. + if (permeability.size() == 1) + { // isotropic or 1D problem. assembleMatrixAndVector<IsotropicCalculator>( material_id, t, local_x, local_M_data, local_K_data, local_b_data, pos, permeability); + } else + { assembleMatrixAndVector<AnisotropicCalculator>( material_id, t, local_x, local_M_data, local_K_data, local_b_data, pos, permeability); + } } template <typename ShapeFunction, typename IntegrationMethod, @@ -134,12 +138,16 @@ LiquidFlowLocalAssembler<ShapeFunction, IntegrationMethod, GlobalDim>:: // the assert must be changed to perm.rows() == _element->getDimension() assert(permeability.rows() == GlobalDim || permeability.rows() == 1); - if (permeability.size() == 1) // isotropic or 1D problem. + if (permeability.size() == 1) + { // isotropic or 1D problem. computeDarcyVelocityLocal<IsotropicCalculator>(local_x, permeability, velocity_cache_vectors); + } else + { computeDarcyVelocityLocal<AnisotropicCalculator>( local_x, permeability, velocity_cache_vectors); + } return velocity_cache; } @@ -222,7 +230,9 @@ void LiquidFlowLocalAssembler<ShapeFunction, IntegrationMethod, GlobalDim>:: darcy_velocity_at_ips.col(ip).noalias() = -K * ip_data.dNdx * local_p; // gravity term if (gravitational_axis_id >= 0) + { darcy_velocity_at_ips.col(ip)[gravitational_axis_id] -= K * rho_g; + } } template <typename ShapeFunction, typename IntegrationMethod, diff --git a/ProcessLib/LocalAssemblerInterface.cpp b/ProcessLib/LocalAssemblerInterface.cpp index d243cba625eb6672ad47e4803d3ee0f7ddde5367..adc706ab2138a5d64f3995fb23931147c7b3a8d6 100644 --- a/ProcessLib/LocalAssemblerInterface.cpp +++ b/ProcessLib/LocalAssemblerInterface.cpp @@ -72,7 +72,9 @@ void LocalAssemblerInterface::computeSecondaryVariable( auto const indices = NumLib::getIndices(mesh_item_id, dof_table); if (coupled_xs != nullptr) + { return; + } auto const local_x = x.get(indices); computeSecondaryVariableConcrete(t, local_x); diff --git a/ProcessLib/Output/CachedSecondaryVariable.cpp b/ProcessLib/Output/CachedSecondaryVariable.cpp index 91eb0ca0d4412a482045307876bca2e40c826e49..0e586ec44b6a0c583623994424f07816a6736273 100644 --- a/ProcessLib/Output/CachedSecondaryVariable.cpp +++ b/ProcessLib/Output/CachedSecondaryVariable.cpp @@ -23,7 +23,9 @@ std::vector<NumLib::NamedFunction> CachedSecondaryVariable::getNamedFunctions() double CachedSecondaryVariable::getValue() const { if (_needs_recomputation) + { evalFieldNoArgs(); + } return _cached_nodal_values.get(_context.index); } diff --git a/ProcessLib/Output/CreateSecondaryVariables.cpp b/ProcessLib/Output/CreateSecondaryVariables.cpp index cc966f3c07c472ba1dcc496f0143de4982cdbd13..57d583d05fa9aea47d0b3ea9d893e982b1f7dd39 100644 --- a/ProcessLib/Output/CreateSecondaryVariables.cpp +++ b/ProcessLib/Output/CreateSecondaryVariables.cpp @@ -25,7 +25,9 @@ void createSecondaryVariables( //! \ogs_file_param{prj__processes__process__secondary_variables} config.getConfigSubtreeOptional("secondary_variables"); if (!sec_vars_config) + { return; + } for ( auto sec_var_config : diff --git a/ProcessLib/Output/Output.cpp b/ProcessLib/Output/Output.cpp index 3d2f7cf2638d5ebdae7b0e5af8fcc3906414e780..588c6546379424e3128cca98c3be62af4d100b93 100644 --- a/ProcessLib/Output/Output.cpp +++ b/ProcessLib/Output/Output.cpp @@ -77,7 +77,9 @@ bool Output::shallDoOutput(unsigned timestep, double const t) bool make_output = timestep % each_steps == 0; if (_fixed_output_times.empty()) + { return make_output; + } const double specific_time = _fixed_output_times.back(); const double zero_threshold = std::numeric_limits<double>::min(); @@ -170,7 +172,9 @@ void Output::doOutputAlways(Process const& process, // output. if (!(process_id == static_cast<int>(_process_to_process_data.size()) - 1 || process.isMonolithicSchemeUsed())) + { return; + } std::string const output_file_name = constructFileName(_output_file_prefix, process_id, timestep, t) + @@ -189,7 +193,9 @@ void Output::doOutputAlways(Process const& process, for (auto const& mesh_output_name : _mesh_names_for_output) { if (process.getMesh().getName() == mesh_output_name) + { continue; + } auto& mesh = *BaseLib::findElementOrError( begin(_meshes), end(_meshes), [&mesh_output_name](auto const& m) { @@ -290,7 +296,9 @@ void Output::doOutputNonlinearIteration(Process const& process, // output. if (!(process_id == static_cast<int>(_process_to_process_data.size()) - 1 || process.isMonolithicSchemeUsed())) + { return; + } // Only check whether a process data is available for output. findProcessData(process, process_id); diff --git a/ProcessLib/Output/ProcessOutput.cpp b/ProcessLib/Output/ProcessOutput.cpp index 9f2b575c1cafeed64458d8b797aca50a69255404..34630fba305190b506998b88e8b501399cb37000 100644 --- a/ProcessLib/Output/ProcessOutput.cpp +++ b/ProcessLib/Output/ProcessOutput.cpp @@ -82,7 +82,9 @@ static void addSecondaryVariableResiduals( MeshLib::Mesh& mesh) { if (!var.fcts.eval_residuals) + { return; + } DBUG(" secondary variable %s residual", output_name.c_str()); auto const& property_name_res = output_name + "_residual"; diff --git a/ProcessLib/Parameter/ConstantParameter.cpp b/ProcessLib/Parameter/ConstantParameter.cpp index 018b2ad07f668082351d5ce6ae58d8b7c2007061..5ccaab1592aa49d332a435957a832c4de3fa302c 100644 --- a/ProcessLib/Parameter/ConstantParameter.cpp +++ b/ProcessLib/Parameter/ConstantParameter.cpp @@ -48,7 +48,9 @@ std::unique_ptr<ParameterBase> createConstantParameter( config.getConfigParameter<std::vector<double>>("values"); if (values.empty()) + { OGS_FATAL("No value available for constant parameter."); + } DBUG("Using following values for the constant parameter:"); for (double const v : values) diff --git a/ProcessLib/Parameter/CurveScaledParameter.cpp b/ProcessLib/Parameter/CurveScaledParameter.cpp index a73b48e365fd23ff639a64618107b189e1ea0402..0f941c7d7fdc0ed45c1b46d90749fb30b75c9f66 100644 --- a/ProcessLib/Parameter/CurveScaledParameter.cpp +++ b/ProcessLib/Parameter/CurveScaledParameter.cpp @@ -28,7 +28,9 @@ std::unique_ptr<ParameterBase> createCurveScaledParameter( auto const curve_it = curves.find(curve_name); if (curve_it == curves.end()) + { OGS_FATAL("Curve `%s' does not exists.", curve_name.c_str()); + } auto referenced_parameter_name = //! \ogs_file_param{prj__parameters__parameter__CurveScaled__parameter} diff --git a/ProcessLib/Parameter/FunctionParameter.h b/ProcessLib/Parameter/FunctionParameter.h index e90f998362f12f789efb165d9eff578cc6ca1131..82b84338d58f7148e239bf91dc610e3d99968928 100644 --- a/ProcessLib/Parameter/FunctionParameter.h +++ b/ProcessLib/Parameter/FunctionParameter.h @@ -96,8 +96,10 @@ struct FunctionParameter final : public Parameter<T> z = node[2]; } - for (unsigned i=0; i<_vec_expression.size(); i++) + for (unsigned i = 0; i < _vec_expression.size(); i++) + { cache[i] = _vec_expression[i].value(); + } return cache; } diff --git a/ProcessLib/Parameter/GroupBasedParameter.cpp b/ProcessLib/Parameter/GroupBasedParameter.cpp index d4eea5abf4c1019ba21722cc3f259c27dbc4040a..f6b256b233530dc06c5439f4af8291fb023d10fe 100644 --- a/ProcessLib/Parameter/GroupBasedParameter.cpp +++ b/ProcessLib/Parameter/GroupBasedParameter.cpp @@ -56,7 +56,9 @@ std::unique_ptr<ParameterBase> createGroupBasedParameter( Values const values = p.getConfigParameter<Values>("values"); if (values.empty()) + { OGS_FATAL("No value available for constant parameter."); + } vec_index_values.emplace_back(index, values); } @@ -67,13 +69,21 @@ std::unique_ptr<ParameterBase> createGroupBasedParameter( { auto itr = std::find(group_id_property->begin(), group_id_property->end(), p.first); if (itr == group_id_property->end()) - OGS_FATAL("Specified property index %d does not exist in the property vector %s", - p.first, group_id_property_name.c_str()); + { + OGS_FATAL( + "Specified property index %d does not exist in the property " + "vector %s", + p.first, group_id_property_name.c_str()); + } if (p.second.size() != n_values) - OGS_FATAL("The length of some values (%d) is different from the first one (%d). " - "The length should be same for all index_values.", - p.second.size(), n_values); + { + OGS_FATAL( + "The length of some values (%d) is different from the first " + "one (%d). " + "The length should be same for all index_values.", + p.second.size(), n_values); + } } // create a mapping table @@ -81,16 +91,22 @@ std::unique_ptr<ParameterBase> createGroupBasedParameter( *std::max_element(group_id_property->begin(), group_id_property->end()); std::vector<Values> vec_values(max_index + 1); for (auto p : vec_index_values) + { vec_values[p.first] = p.second; + } if (group_id_property->getMeshItemType() == MeshLib::MeshItemType::Node) + { return std::make_unique< GroupBasedParameter<double, MeshLib::MeshItemType::Node>>( name, *group_id_property, vec_values); + } if (group_id_property->getMeshItemType() == MeshLib::MeshItemType::Cell) + { return std::make_unique< GroupBasedParameter<double, MeshLib::MeshItemType::Cell>>( name, *group_id_property, vec_values); + } OGS_FATAL("Mesh item type of the specified property is not supported."); } diff --git a/ProcessLib/Parameter/GroupBasedParameter.h b/ProcessLib/Parameter/GroupBasedParameter.h index 86a51e7cfd92f952e5a3f5c6e71b6207f3b54978..67b7ecfcf6fead611e5dfd18bb42f3cfeaba7ece 100644 --- a/ProcessLib/Parameter/GroupBasedParameter.h +++ b/ProcessLib/Parameter/GroupBasedParameter.h @@ -66,7 +66,9 @@ struct GroupBasedParameter final int const index = _property_index[item_id.get()]; auto const& values = _vec_values[index]; if (values.empty()) + { OGS_FATAL("No data found for the group index %d", index); + } return values; } diff --git a/ProcessLib/PhaseField/CreatePhaseFieldProcess.cpp b/ProcessLib/PhaseField/CreatePhaseFieldProcess.cpp index 87f69ab3419c73cae2b2ac4824b740a61ef25f0a..f885a13e97d0286c83b15f5b2caf2e1d8af6da3a 100644 --- a/ProcessLib/PhaseField/CreatePhaseFieldProcess.cpp +++ b/ProcessLib/PhaseField/CreatePhaseFieldProcess.cpp @@ -150,11 +150,13 @@ std::unique_ptr<Process> createPhaseFieldProcess( config.getConfigParameter<std::vector<double>>( "specific_body_force"); if (b.size() != DisplacementDim) + { OGS_FATAL( "The size of the specific body force vector does not match the " "displacement dimension. Vector size is %d, displacement " "dimension is %d", b.size(), DisplacementDim); + } std::copy_n(b.data(), b.size(), specific_body_force.data()); } diff --git a/ProcessLib/PhaseField/PhaseFieldFEM-impl.h b/ProcessLib/PhaseField/PhaseFieldFEM-impl.h index c024ae5345a254a7f3d99a0a813823abb36c9414..f0140afa87d89c027667731afae3ccf82a37ba37 100644 --- a/ProcessLib/PhaseField/PhaseFieldFEM-impl.h +++ b/ProcessLib/PhaseField/PhaseFieldFEM-impl.h @@ -87,7 +87,9 @@ void PhaseFieldLocalAssembler<ShapeFunction, IntegrationMethod, auto local_pressure = 0.0; if (_process_data.crack_pressure) + { local_pressure = _process_data.unity_pressure; + } int const n_integration_points = _integration_method.getNumberOfPoints(); for (int ip = 0; ip < n_integration_points; ip++) @@ -126,9 +128,11 @@ void PhaseFieldLocalAssembler<ShapeFunction, IntegrationMethod, displacement_size); for (int i = 0; i < DisplacementDim; ++i) + { N_u.template block<1, displacement_size / DisplacementDim>( i, i * displacement_size / DisplacementDim) .noalias() = N; + } auto const rho_sr = _process_data.solid_density(t, x_position)[0]; auto const& b = _process_data.specific_body_force; @@ -185,9 +189,13 @@ void PhaseFieldLocalAssembler<ShapeFunction, IntegrationMethod, auto local_pressure = 0.0; if (_process_data.crack_pressure) + { local_pressure = _process_data.unity_pressure; + } else if (_process_data.propagating_crack) + { local_pressure = _process_data.pressure; + } int const n_integration_points = _integration_method.getNumberOfPoints(); for (int ip = 0; ip < n_integration_points; ip++) @@ -232,9 +240,11 @@ void PhaseFieldLocalAssembler<ShapeFunction, IntegrationMethod, displacement_size); for (int i = 0; i < DisplacementDim; ++i) + { N_u.template block<1, displacement_size / DisplacementDim>( i, i * displacement_size / DisplacementDim) .noalias() = N; + } local_Jac.noalias() += (2 * N.transpose() * N * strain_energy_tensile + @@ -306,9 +316,11 @@ void PhaseFieldLocalAssembler<ShapeFunction, IntegrationMethod, displacement_size); for (int i = 0; i < DisplacementDim; ++i) + { N_u.template block<1, displacement_size / DisplacementDim>( i, i * displacement_size / DisplacementDim) .noalias() = N; + } crack_volume += (N_u * u).dot(dNdx * d) * w; } @@ -376,9 +388,11 @@ void PhaseFieldLocalAssembler<ShapeFunction, IntegrationMethod, displacement_size); for (int i = 0; i < DisplacementDim; ++i) + { N_u.template block<1, displacement_size / DisplacementDim>( i, i * displacement_size / DisplacementDim) .noalias() = N; + } elastic_energy += _ip_data[ip].elastic_energy * w; @@ -388,8 +402,10 @@ void PhaseFieldLocalAssembler<ShapeFunction, IntegrationMethod, w; if (_process_data.crack_pressure) + { pressure_work += pressure_ip * (N_u * u_corrected).dot(dNdx * d) * w; + } } } } // namespace PhaseField diff --git a/ProcessLib/ProcessVariable.cpp b/ProcessLib/ProcessVariable.cpp index 30a7889613f35d68ce9b8e3130938ba5f7dda32d..dac2b422919cbbdc1676e9c505c77f40b2d9ed95 100644 --- a/ProcessLib/ProcessVariable.cpp +++ b/ProcessLib/ProcessVariable.cpp @@ -112,8 +112,10 @@ ProcessVariable::ProcessVariable( DBUG("Constructing process variable %s", _name.c_str()); if (_shapefunction_order < 1 || 2 < _shapefunction_order) + { OGS_FATAL("The given shape function order %d is not supported", _shapefunction_order); + } // Boundary conditions if (auto bcs_config = @@ -131,8 +133,10 @@ ProcessVariable::ProcessVariable( bc_config.getConfigParameterOptional<int>("component"); if (!component_id && _n_components == 1) + { // default value for single component vars. component_id = 0; + } _bc_configs.emplace_back(std::move(bc_config), mesh, component_id); } @@ -158,8 +162,10 @@ ProcessVariable::ProcessVariable( st_config.getConfigParameterOptional<int>("component"); if (!component_id && _n_components == 1) + { // default value for single component vars. component_id = 0; + } _source_term_configs.emplace_back(std::move(st_config), mesh, component_id); @@ -219,7 +225,9 @@ ProcessVariable::createBoundaryConditions( } if (_deactivated_subdomains.empty()) + { return bcs; + } createBoundaryConditionsForDeactivatedSubDomains(dof_table, variable_id, parameters, bcs); @@ -293,7 +301,9 @@ void ProcessVariable::updateDeactivatedSubdomains(double const time) // Already initialized. if (!_ids_of_active_elements.empty()) + { return; + } auto const& deactivated_materialIDs = (*found_a_set)->materialIDs; @@ -306,7 +316,9 @@ void ProcessVariable::updateDeactivatedSubdomains(double const time) if (std::binary_search(deactivated_materialIDs.begin(), deactivated_materialIDs.end(), (*material_ids)[i])) + { continue; + } _ids_of_active_elements.push_back(_mesh.getElement(i)->getID()); } } @@ -320,9 +332,11 @@ std::vector<std::unique_ptr<SourceTerm>> ProcessVariable::createSourceTerms( std::vector<std::unique_ptr<SourceTerm>> source_terms; for (auto& config : _source_term_configs) + { source_terms.emplace_back(createSourceTerm( config, dof_table, config.mesh, variable_id, integration_order, _shapefunction_order, parameters)); + } return source_terms; } diff --git a/ProcessLib/RichardsComponentTransport/CreateRichardsComponentTransportProcess.cpp b/ProcessLib/RichardsComponentTransport/CreateRichardsComponentTransportProcess.cpp index eb145ecc0484cad0fc5d787cb1063df5fdfe4a51..fa960ea873d194a26d3a5dab70aaf2e69a53b01a 100644 --- a/ProcessLib/RichardsComponentTransport/CreateRichardsComponentTransportProcess.cpp +++ b/ProcessLib/RichardsComponentTransport/CreateRichardsComponentTransportProcess.cpp @@ -134,10 +134,12 @@ std::unique_ptr<Process> createRichardsComponentTransportProcess( config.getConfigParameter<std::vector<double>>("specific_body_force"); assert(b.size() > 0 && b.size() < 4); if (b.size() < mesh.getDimension()) + { OGS_FATAL( "specific body force (gravity vector) has %d components, mesh " "dimension is %d", b.size(), mesh.getDimension()); + } bool const has_gravity = MathLib::toVector(b).norm() > 0; if (has_gravity) { diff --git a/ProcessLib/RichardsComponentTransport/RichardsComponentTransportFEM-impl.h b/ProcessLib/RichardsComponentTransport/RichardsComponentTransportFEM-impl.h index 379e2c7a76256ac5c784210478a9d22b9ea71f55..b8f236f4734d161a4a829e19c7982dd3591b761b 100644 --- a/ProcessLib/RichardsComponentTransport/RichardsComponentTransportFEM-impl.h +++ b/ProcessLib/RichardsComponentTransport/RichardsComponentTransportFEM-impl.h @@ -203,7 +203,9 @@ void LocalAssemblerData<ShapeFunction, IntegrationMethod, GlobalDim>::assemble( ip_data.mass_operator; if (_process_data.has_gravity) + { Bp += w * density * dNdx.transpose() * K_times_k_rel_over_mu * b; + } /* with Oberbeck-Boussing assumption density difference only exists * in buoyancy effects */ } diff --git a/ProcessLib/RichardsFlow/CreateRichardsFlowProcess.cpp b/ProcessLib/RichardsFlow/CreateRichardsFlowProcess.cpp index 1b0018ba310d4d893a25eea3085c30cea73c980b..24d1d4593a1205b6db57dca04a46b2ed88b6b4e6 100644 --- a/ProcessLib/RichardsFlow/CreateRichardsFlowProcess.cpp +++ b/ProcessLib/RichardsFlow/CreateRichardsFlowProcess.cpp @@ -66,7 +66,9 @@ std::unique_ptr<Process> createRichardsFlowProcess( Eigen::VectorXd specific_body_force(b.size()); bool const has_gravity = MathLib::toVector(b).norm() > 0; if (has_gravity) + { std::copy_n(b.data(), b.size(), specific_body_force.data()); + } // has mass lumping //! \ogs_file_param{prj__processes__process__RICHARDS_FLOW__mass_lumping} diff --git a/ProcessLib/RichardsFlow/RichardsFlowFEM.h b/ProcessLib/RichardsFlow/RichardsFlowFEM.h index f1e802d0ff8c7abb4da6633d2f028f08fc79ee63..47faea78cd1edfc48a3c78e605adcdb57b9832ae 100644 --- a/ProcessLib/RichardsFlow/RichardsFlowFEM.h +++ b/ProcessLib/RichardsFlow/RichardsFlowFEM.h @@ -156,9 +156,13 @@ public: GlobalDimMatrixType permeability = GlobalDimMatrixType::Zero( _element.getDimension(), _element.getDimension()); if (perm.rows() == _element.getDimension()) + { permeability = perm; + } else if (perm.rows() == 1) + { permeability.diagonal().setConstant(perm(0, 0)); + } for (unsigned ip = 0; ip < n_integration_points; ip++) { @@ -268,9 +272,13 @@ public: GlobalDimMatrixType permeability = GlobalDimMatrixType::Zero( _element.getDimension(), _element.getDimension()); if (perm.rows() == _element.getDimension()) + { permeability = perm; + } else if (perm.rows() == 1) + { permeability.diagonal().setConstant(perm(0, 0)); + } unsigned const n_integration_points = _integration_method.getNumberOfPoints(); diff --git a/ProcessLib/RichardsMechanics/IntegrationPointData.h b/ProcessLib/RichardsMechanics/IntegrationPointData.h index 1bf68252a87f111412aba1f0f5e06a0888651d8e..207a6276c74c2beb75d6eb000cfd0500be3adde0 100644 --- a/ProcessLib/RichardsMechanics/IntegrationPointData.h +++ b/ProcessLib/RichardsMechanics/IntegrationPointData.h @@ -82,7 +82,9 @@ struct IntegrationPointData final *material_state_variables, temperature); if (!solution) + { OGS_FATAL("Computation of local constitutive relation failed."); + } MathLib::KelvinVector::KelvinMatrixType<DisplacementDim> C; std::tie(sigma_eff, material_state_variables, C) = std::move(*solution); diff --git a/ProcessLib/RichardsMechanics/LocalDataInitializer.h b/ProcessLib/RichardsMechanics/LocalDataInitializer.h index 5e34224bd36136af7740579d39c57084428916c9..b6a4eb63db8b809d70a36e6d28a5804631c13c97 100644 --- a/ProcessLib/RichardsMechanics/LocalDataInitializer.h +++ b/ProcessLib/RichardsMechanics/LocalDataInitializer.h @@ -130,10 +130,12 @@ public: : _dof_table(dof_table) { if (shapefunction_order != 2) + { OGS_FATAL( "The given shape function order %d is not supported.\nOnly " "shape functions of order 2 are supported.", shapefunction_order); + } // /// Quads and Hexahedra /////////////////////////////////// #if (OGS_ENABLED_ELEMENTS & ENABLED_ELEMENT_TYPE_QUAD) != 0 && \ diff --git a/ProcessLib/RichardsMechanics/RichardsMechanicsFEM-impl.h b/ProcessLib/RichardsMechanics/RichardsMechanicsFEM-impl.h index dc0f58a397f7e664a4285c1fafeb6da13c9b14a1..0e6b8b81285d7c1672b00faaf305fdac370a88d2 100644 --- a/ProcessLib/RichardsMechanics/RichardsMechanicsFEM-impl.h +++ b/ProcessLib/RichardsMechanics/RichardsMechanicsFEM-impl.h @@ -98,10 +98,12 @@ RichardsMechanicsLocalAssembler<ShapeFunctionDisplacement, DisplacementDim, displacement_size>::Zero(DisplacementDim, displacement_size); for (int i = 0; i < DisplacementDim; ++i) + { ip_data.N_u_op .template block<1, displacement_size / DisplacementDim>( i, i * displacement_size / DisplacementDim) .noalias() = sm_u.N; + } ip_data.N_u = sm_u.N; ip_data.dNdx_u = sm_u.dNdx; diff --git a/ProcessLib/SmallDeformation/CreateSmallDeformationProcess.cpp b/ProcessLib/SmallDeformation/CreateSmallDeformationProcess.cpp index db5deddaafdf8f3136781e901f9c6b1148f83f97..5835471f4b252157ab5e221d8fbd037207697bae 100644 --- a/ProcessLib/SmallDeformation/CreateSmallDeformationProcess.cpp +++ b/ProcessLib/SmallDeformation/CreateSmallDeformationProcess.cpp @@ -83,11 +83,13 @@ createSmallDeformationProcess( config.getConfigParameter<std::vector<double>>( "specific_body_force"); if (b.size() != DisplacementDim) + { OGS_FATAL( "The size of the specific body force vector does not match the " "displacement dimension. Vector size is %d, displacement " "dimension is %d", b.size(), DisplacementDim); + } std::copy_n(b.data(), b.size(), specific_body_force.data()); } diff --git a/ProcessLib/SmallDeformation/SmallDeformationFEM.h b/ProcessLib/SmallDeformation/SmallDeformationFEM.h index 04042b4aede8e48d80990f1125912a374c6b72b0..3c5724bc7e28a9762579b3297ab6867daf1bb959 100644 --- a/ProcessLib/SmallDeformation/SmallDeformationFEM.h +++ b/ProcessLib/SmallDeformation/SmallDeformationFEM.h @@ -229,10 +229,12 @@ public: displacement_size>::Zero(DisplacementDim, displacement_size); for (int i = 0; i < DisplacementDim; ++i) + { N_u_op .template block<1, displacement_size / DisplacementDim>( i, i * displacement_size / DisplacementDim) .noalias() = N; + } auto const x_coord = interpolateXCoordinate<ShapeFunction, ShapeMatricesType>( @@ -259,7 +261,9 @@ public: *state, _process_data.reference_temperature); if (!solution) + { OGS_FATAL("Computation of local constitutive relation failed."); + } MathLib::KelvinVector::KelvinMatrixType<DisplacementDim> C; std::tie(sigma, state, C) = std::move(*solution); diff --git a/ProcessLib/SmallDeformationNonlocal/CreateSmallDeformationNonlocalProcess.cpp b/ProcessLib/SmallDeformationNonlocal/CreateSmallDeformationNonlocalProcess.cpp index a9a75fcdc90f9b1eda030a4c6406e0d3c2c52482..9459c48d64d685d3e764a6920d4d3cbcf05abe92 100644 --- a/ProcessLib/SmallDeformationNonlocal/CreateSmallDeformationNonlocalProcess.cpp +++ b/ProcessLib/SmallDeformationNonlocal/CreateSmallDeformationNonlocalProcess.cpp @@ -83,11 +83,13 @@ std::unique_ptr<Process> createSmallDeformationNonlocalProcess( config.getConfigParameter<std::vector<double>>( "specific_body_force"); if (b.size() != DisplacementDim) + { OGS_FATAL( "The size of the specific body force vector does not match the " "displacement dimension. Vector size is %d, displacement " "dimension is %d", b.size(), DisplacementDim); + } std::copy_n(b.data(), b.size(), specific_body_force.data()); } diff --git a/ProcessLib/SmallDeformationNonlocal/SmallDeformationNonlocalFEM.h b/ProcessLib/SmallDeformationNonlocal/SmallDeformationNonlocalFEM.h index 12471bd169324bf6da8f719652dd5e563a68d8f9..30a243b0d462a0b67f9f53345dbf87c1e4d7dcab 100644 --- a/ProcessLib/SmallDeformationNonlocal/SmallDeformationNonlocalFEM.h +++ b/ProcessLib/SmallDeformationNonlocal/SmallDeformationNonlocalFEM.h @@ -228,7 +228,9 @@ public: for (int ip = 0; ip < static_cast<int>(distances.size()); ++ip) { if (distances[ip] >= _process_data.internal_length_squared) + { continue; + } // save into current ip_k _ip_data[k].non_local_assemblers.push_back( {la->getIPDataPtr(ip), @@ -371,7 +373,9 @@ public: *state, _process_data.reference_temperature); if (!solution) + { OGS_FATAL("Computation of local constitutive relation failed."); + } std::tie(sigma, state, C) = std::move(*solution); @@ -815,10 +819,14 @@ private: for (auto const& ip_data : _ip_data) { - if (component < 3) // xx, yy, zz components + if (component < 3) + { // xx, yy, zz components cache.push_back(ip_data.sigma[component]); - else // mixed xy, yz, xz components + } + else + { // mixed xy, yz, xz components cache.push_back(ip_data.sigma[component] / std::sqrt(2)); + } } return cache; diff --git a/ProcessLib/SourceTerms/SourceTermCollection.cpp b/ProcessLib/SourceTerms/SourceTermCollection.cpp index 83622d076b67f1f5e37945dd2c0b04756a6e8ead..8b48d84ee0700d6dcca61fd517bd74b187abc57c 100644 --- a/ProcessLib/SourceTerms/SourceTermCollection.cpp +++ b/ProcessLib/SourceTerms/SourceTermCollection.cpp @@ -33,7 +33,9 @@ void SourceTermCollection::integrate(const double t, GlobalVector const& x, GlobalVector& b, GlobalMatrix* jac) const { for (auto const& st : _source_terms) + { st->integrate(t, x, b, jac); + } } } // namespace ProcessLib diff --git a/ProcessLib/TES/TESLocalAssembler-impl.h b/ProcessLib/TES/TESLocalAssembler-impl.h index 966688a1e8eba1b771a5c0e58d4cb480a1ace5b1..c6ebc9ff1aa424137441f4743a10d85a8dadb433 100644 --- a/ProcessLib/TES/TESLocalAssembler-impl.h +++ b/ProcessLib/TES/TESLocalAssembler-impl.h @@ -39,12 +39,16 @@ void ogs5OutMat(const Mat& mat) { case MatOutType::OGS5: if (r != 0) + { std::printf("\n"); + } std::printf("|"); break; case MatOutType::PYTHON: if (r != 0) + { std::printf(",\n"); + } std::printf("["); break; } @@ -58,7 +62,9 @@ void ogs5OutMat(const Mat& mat) break; case MatOutType::PYTHON: if (c != 0) + { std::printf(","); + } std::printf(" %23.16g", mat(r, c)); break; } @@ -86,12 +92,16 @@ void ogs5OutVec(const Vec& vec) { case MatOutType::OGS5: if (r != 0) + { std::printf("\n"); + } std::printf("| %.16e | ", vec[r]); break; case MatOutType::PYTHON: if (r != 0) + { std::printf(",\n"); + } std::printf("[ %23.16g ]", vec[r]); break; } diff --git a/ProcessLib/TES/TESOGS5MaterialModels.h b/ProcessLib/TES/TESOGS5MaterialModels.h index 19bded3c007af4d07989f5e721d9f8b307378581..0036cf94fa347fc0827eb806ae8bb7960407a15d 100644 --- a/ProcessLib/TES/TESOGS5MaterialModels.h +++ b/ProcessLib/TES/TESOGS5MaterialModels.h @@ -338,9 +338,13 @@ struct FluidHeatConductivityH2O Q = 2 + (C[4] / dT_pow_3_5); if (T >= 1) + { S = 1 / dT; + } else + { S = C[5] / dT_pow_3_5; + } const double rho_pow_9_5 = std::pow(rho, 9. / 5.); const double rho_pow_Q = std::pow(rho, Q); diff --git a/ProcessLib/TES/TESProcess.cpp b/ProcessLib/TES/TESProcess.cpp index c04f685f1ca2bc0d0db5abf38fc29a4f89ad4b59..9fbc3bd3844a0cd07037d26cd339a5ba4e6a2ec3 100644 --- a/ProcessLib/TES/TESProcess.cpp +++ b/ProcessLib/TES/TESProcess.cpp @@ -197,7 +197,9 @@ void TESProcess::initializeSecondaryVariables() _secondary_variable_context); for (auto&& fct : solid_density->getNamedFunctions()) + { _named_function_caller.addNamedFunction(std::move(fct)); + } add2nd("solid_density", solid_density->getExtrapolator()); @@ -310,7 +312,9 @@ NumLib::IterationResult TESProcess::postIterationConcreteProcess( local_x_prev_ts_cache = _x_previous_timestep->get(r_c_indices.rows); if (!loc_asm.checkBounds(local_x_cache, local_x_prev_ts_cache)) + { check_passed = false; + } }; GlobalExecutor::executeDereferenced(check_variable_bounds, @@ -318,7 +322,9 @@ NumLib::IterationResult TESProcess::postIterationConcreteProcess( } if (!check_passed) + { return NumLib::IterationResult::REPEAT_ITERATION; + } // TODO remove DBUG("ts %lu iteration %lu (in current ts: %lu) try %u accepted", diff --git a/ProcessLib/TES/TESReactionAdaptor.cpp b/ProcessLib/TES/TESReactionAdaptor.cpp index e39c47f1e8530dc4cf744ce015765f76925c1fe8..d1fe25da245f0ff8f10ea8b7e6696526c50fabac 100644 --- a/ProcessLib/TES/TESReactionAdaptor.cpp +++ b/ProcessLib/TES/TESReactionAdaptor.cpp @@ -232,9 +232,13 @@ bool TESFEMReactionAdaptorAdsorption::checkBounds( if (alpha != 1.0) { if (alpha > 0.5) + { alpha = 0.5; + } if (alpha < 0.05) + { alpha = 0.05; + } if (_d.ap.number_of_try_of_iteration <= 3) { @@ -252,7 +256,9 @@ bool TESFEMReactionAdaptorAdsorption::checkBounds( void TESFEMReactionAdaptorAdsorption::preZerothTryAssemble() { if (_reaction_damping_factor < 1e-3) + { _reaction_damping_factor = 1e-3; + } _reaction_damping_factor = std::min(std::sqrt(_reaction_damping_factor), 10.0 * _reaction_damping_factor); @@ -356,11 +362,17 @@ ReactionRate TESFEMReactionAdaptorCaOH2::initReaction(const unsigned int int_pt) // cut off when limits are reached if (y_new[0] < _react.rho_low) + { rho_react = _react.rho_low; + } else if (y_new[0] > _react.rho_up) + { rho_react = _react.rho_up; + } else + { rho_react = y_new[0]; + } return {y_dot_new[0] * (1.0 - xv_NR), (1.0 - xv_NR) * rho_react + xv_NR * rho_NR}; diff --git a/ProcessLib/ThermalTwoPhaseFlowWithPP/CreateThermalTwoPhaseFlowWithPPProcess.cpp b/ProcessLib/ThermalTwoPhaseFlowWithPP/CreateThermalTwoPhaseFlowWithPPProcess.cpp index 42ad27fc7960b024fcc4f180f9cf73bde6003808..cbe14e348f5adcc04733552aedacb75ff4590acf 100644 --- a/ProcessLib/ThermalTwoPhaseFlowWithPP/CreateThermalTwoPhaseFlowWithPPProcess.cpp +++ b/ProcessLib/ThermalTwoPhaseFlowWithPP/CreateThermalTwoPhaseFlowWithPPProcess.cpp @@ -70,7 +70,9 @@ std::unique_ptr<Process> createThermalTwoPhaseFlowWithPPProcess( Eigen::VectorXd specific_body_force(b.size()); bool const has_gravity = MathLib::toVector(b).norm() > 0; if (has_gravity) + { std::copy_n(b.data(), b.size(), specific_body_force.data()); + } //! \ogs_file_param{prj__processes__process__TWOPHASE_FLOW_THERMAL__mass_lumping} auto mass_lumping = config.getConfigParameter<bool>("mass_lumping"); diff --git a/ProcessLib/ThermalTwoPhaseFlowWithPP/ThermalTwoPhaseFlowWithPPLocalAssembler-impl.h b/ProcessLib/ThermalTwoPhaseFlowWithPP/ThermalTwoPhaseFlowWithPPLocalAssembler-impl.h index 27c39c433f38cb97d6b28feafb376a95fdd4c314..97ae3dd571699e26a2f48df4c9c5581f06cc3c58 100644 --- a/ProcessLib/ThermalTwoPhaseFlowWithPP/ThermalTwoPhaseFlowWithPPLocalAssembler-impl.h +++ b/ProcessLib/ThermalTwoPhaseFlowWithPP/ThermalTwoPhaseFlowWithPPLocalAssembler-impl.h @@ -154,9 +154,13 @@ void ThermalTwoPhaseFlowWithPPLocalAssembler< GlobalDimMatrixType permeability = GlobalDimMatrixType::Zero( _element.getDimension(), _element.getDimension()); if (perm.rows() == _element.getDimension()) + { permeability = perm; + } else if (perm.rows() == 1) + { permeability.diagonal().setConstant(perm(0, 0)); + } for (unsigned ip = 0; ip < n_integration_points; ip++) { diff --git a/ProcessLib/ThermalTwoPhaseFlowWithPP/ThermalTwoPhaseFlowWithPPMaterialProperties.cpp b/ProcessLib/ThermalTwoPhaseFlowWithPP/ThermalTwoPhaseFlowWithPPMaterialProperties.cpp index 52e4dc7d8a938991b6b173d0be15d62eedfccdfa..aa8fa51f48af57afa72f4e746e35dfdc3a946856 100644 --- a/ProcessLib/ThermalTwoPhaseFlowWithPP/ThermalTwoPhaseFlowWithPPMaterialProperties.cpp +++ b/ProcessLib/ThermalTwoPhaseFlowWithPP/ThermalTwoPhaseFlowWithPPMaterialProperties.cpp @@ -134,9 +134,13 @@ ThermalTwoPhaseFlowWithPPMaterialProperties::calculateUnsatHeatConductivity( double lambda_pm = lambda_pm_dry + std::sqrt(Sw) * (lambda_pm_wet - lambda_pm_dry); if (Sw > 1) + { lambda_pm = lambda_pm_wet; + } else if (Sw < 0) + { lambda_pm = lambda_pm_dry; + } return lambda_pm; } diff --git a/ProcessLib/ThermoMechanicalPhaseField/CreateThermoMechanicalPhaseFieldProcess.cpp b/ProcessLib/ThermoMechanicalPhaseField/CreateThermoMechanicalPhaseFieldProcess.cpp index b7fbd947bf252b443a1f9c9911819a988419c434..aef959058351cc5be07e0be588a56ab3cf98e3b1 100644 --- a/ProcessLib/ThermoMechanicalPhaseField/CreateThermoMechanicalPhaseFieldProcess.cpp +++ b/ProcessLib/ThermoMechanicalPhaseField/CreateThermoMechanicalPhaseFieldProcess.cpp @@ -199,11 +199,13 @@ std::unique_ptr<Process> createThermoMechanicalPhaseFieldProcess( config.getConfigParameter<std::vector<double>>( "specific_body_force"); if (specific_body_force.size() != DisplacementDim) + { OGS_FATAL( "The size of the specific body force vector does not match the " "displacement dimension. Vector size is %d, displacement " "dimension is %d", specific_body_force.size(), DisplacementDim); + } std::copy_n(b.data(), b.size(), specific_body_force.data()); } diff --git a/ProcessLib/ThermoMechanicalPhaseField/ThermoMechanicalPhaseFieldFEM-impl.h b/ProcessLib/ThermoMechanicalPhaseField/ThermoMechanicalPhaseFieldFEM-impl.h index e935ccf674caa17bbfa54a7d281357ef66592d6e..a8d23a00acd37e1a1394c0e20bedcad1b038e946 100644 --- a/ProcessLib/ThermoMechanicalPhaseField/ThermoMechanicalPhaseFieldFEM-impl.h +++ b/ProcessLib/ThermoMechanicalPhaseField/ThermoMechanicalPhaseFieldFEM-impl.h @@ -149,9 +149,11 @@ void ThermoMechanicalPhaseFieldLocalAssembler<ShapeFunction, IntegrationMethod, displacement_size); for (int i = 0; i < DisplacementDim; ++i) + { N_u.template block<1, displacement_size / DisplacementDim>( i, i * displacement_size / DisplacementDim) .noalias() = N; + } local_Jac.noalias() += B.transpose() * C_eff * B * w; diff --git a/ProcessLib/ThermoMechanics/CreateThermoMechanicsProcess.cpp b/ProcessLib/ThermoMechanics/CreateThermoMechanicsProcess.cpp index 1555af12000ab76d319e3cef19e8ae5525b6a4c0..6e62d363d128a3ee25f9315730167eab25a4d2bc 100644 --- a/ProcessLib/ThermoMechanics/CreateThermoMechanicsProcess.cpp +++ b/ProcessLib/ThermoMechanics/CreateThermoMechanicsProcess.cpp @@ -144,11 +144,13 @@ std::unique_ptr<Process> createThermoMechanicsProcess( config.getConfigParameter<std::vector<double>>( "specific_body_force"); if (b.size() != DisplacementDim) + { OGS_FATAL( "The size of the specific body force vector does not match the " "displacement dimension. Vector size is %d, displacement " "dimension is %d", b.size(), DisplacementDim); + } std::copy_n(b.data(), b.size(), specific_body_force.data()); } diff --git a/ProcessLib/ThermoMechanics/ThermoMechanicsFEM.h b/ProcessLib/ThermoMechanics/ThermoMechanicsFEM.h index 82080cbc3767d999ca8e66caf8bbfe0eae1cbf0b..384b9246be685e00b0bc09c5a2dda9f9ed465033 100644 --- a/ProcessLib/ThermoMechanics/ThermoMechanicsFEM.h +++ b/ProcessLib/ThermoMechanics/ThermoMechanicsFEM.h @@ -310,7 +310,9 @@ public: t, x_position, dt, eps_m_prev, eps_m, sigma_prev, *state, T_ip); if (!solution) + { OGS_FATAL("Computation of local constitutive relation failed."); + } MathLib::KelvinVector::KelvinMatrixType<DisplacementDim> C; std::tie(sigma, state, C) = std::move(*solution); @@ -328,9 +330,11 @@ public: displacement_size); for (int i = 0; i < DisplacementDim; ++i) + { N_u.template block<1, displacement_size / DisplacementDim>( i, i * displacement_size / DisplacementDim) .noalias() = N; + } // calculate real density // rho_s_{n+1} * (V_{n} + dV) = rho_s_n * V_n diff --git a/ProcessLib/TwoPhaseFlowWithPP/CreateTwoPhaseFlowWithPPProcess.cpp b/ProcessLib/TwoPhaseFlowWithPP/CreateTwoPhaseFlowWithPPProcess.cpp index e39c4e559e06a07885f5e0647619a4bf7a970258..d4395852be655d130733f5029c58d801f962c000 100644 --- a/ProcessLib/TwoPhaseFlowWithPP/CreateTwoPhaseFlowWithPPProcess.cpp +++ b/ProcessLib/TwoPhaseFlowWithPP/CreateTwoPhaseFlowWithPPProcess.cpp @@ -65,7 +65,9 @@ std::unique_ptr<Process> createTwoPhaseFlowWithPPProcess( Eigen::VectorXd specific_body_force(b.size()); bool const has_gravity = MathLib::toVector(b).norm() > 0; if (has_gravity) + { std::copy_n(b.data(), b.size(), specific_body_force.data()); + } //! \ogs_file_param{prj__processes__process__TWOPHASE_FLOW_PP__mass_lumping} auto const mass_lumping = config.getConfigParameter<bool>("mass_lumping"); diff --git a/ProcessLib/TwoPhaseFlowWithPP/TwoPhaseFlowWithPPLocalAssembler-impl.h b/ProcessLib/TwoPhaseFlowWithPP/TwoPhaseFlowWithPPLocalAssembler-impl.h index b8afab6c800f6eff14fabced9e9954f5566bbce7..0b417f257f7e16eeda01547fe8c4432e37e6d0e1 100644 --- a/ProcessLib/TwoPhaseFlowWithPP/TwoPhaseFlowWithPPLocalAssembler-impl.h +++ b/ProcessLib/TwoPhaseFlowWithPP/TwoPhaseFlowWithPPLocalAssembler-impl.h @@ -102,9 +102,13 @@ void TwoPhaseFlowWithPPLocalAssembler< GlobalDimMatrixType permeability = GlobalDimMatrixType::Zero( _element.getDimension(), _element.getDimension()); if (perm.rows() == _element.getDimension()) + { permeability = perm; + } else if (perm.rows() == 1) + { permeability.diagonal().setConstant(perm(0, 0)); + } for (unsigned ip = 0; ip < n_integration_points; ip++) { diff --git a/ProcessLib/TwoPhaseFlowWithPrho/CreateTwoPhaseFlowWithPrhoProcess.cpp b/ProcessLib/TwoPhaseFlowWithPrho/CreateTwoPhaseFlowWithPrhoProcess.cpp index 14a64c323b3a4ba13647dca8d11f5edfd92e7d15..d99cafe6698c46ab238a036b111e1b8cb6217b71 100644 --- a/ProcessLib/TwoPhaseFlowWithPrho/CreateTwoPhaseFlowWithPrhoProcess.cpp +++ b/ProcessLib/TwoPhaseFlowWithPrho/CreateTwoPhaseFlowWithPrhoProcess.cpp @@ -65,7 +65,9 @@ std::unique_ptr<Process> createTwoPhaseFlowWithPrhoProcess( Eigen::VectorXd specific_body_force(b.size()); bool const has_gravity = MathLib::toVector(b).norm() > 0; if (has_gravity) + { std::copy_n(b.data(), b.size(), specific_body_force.data()); + } //! \ogs_file_param{prj__processes__process__TWOPHASE_FLOW_PRHO__mass_lumping} auto const mass_lumping = config.getConfigParameter<bool>("mass_lumping"); diff --git a/ProcessLib/TwoPhaseFlowWithPrho/TwoPhaseFlowWithPrhoLocalAssembler-impl.h b/ProcessLib/TwoPhaseFlowWithPrho/TwoPhaseFlowWithPrhoLocalAssembler-impl.h index 16c72c1050be4bf8ead8b4cd19395ec3e39fb974..126cda9130bc17bed5647f43d208f1b36d7d34a5 100644 --- a/ProcessLib/TwoPhaseFlowWithPrho/TwoPhaseFlowWithPrhoLocalAssembler-impl.h +++ b/ProcessLib/TwoPhaseFlowWithPrho/TwoPhaseFlowWithPrhoLocalAssembler-impl.h @@ -87,9 +87,13 @@ void TwoPhaseFlowWithPrhoLocalAssembler< GlobalDimMatrixType permeability = GlobalDimMatrixType::Zero( _element.getDimension(), _element.getDimension()); if (perm.rows() == _element.getDimension()) + { permeability = perm; + } else if (perm.rows() == 1) + { permeability.diagonal().setConstant(perm(0, 0)); + } for (unsigned ip = 0; ip < n_integration_points; ip++) { @@ -129,7 +133,9 @@ void TwoPhaseFlowWithPrhoLocalAssembler< dSwdrho, drhoh2wet, drhoh2wet_drho)) + { OGS_FATAL("Computation of local constitutive relation failed."); + } double const pc = _process_data._material->getCapillaryPressure( material_id, t, pos, pl_int_pt, temperature, Sw); diff --git a/ProcessLib/TwoPhaseFlowWithPrho/TwoPhaseFlowWithPrhoMaterialProperties.cpp b/ProcessLib/TwoPhaseFlowWithPrho/TwoPhaseFlowWithPrhoMaterialProperties.cpp index 3af15e53b8a02f9862d3629eef023e4c12d686cc..42d4c975b41a78bc8be0888c22ac0d1b73752576 100644 --- a/ProcessLib/TwoPhaseFlowWithPrho/TwoPhaseFlowWithPrhoMaterialProperties.cpp +++ b/ProcessLib/TwoPhaseFlowWithPrho/TwoPhaseFlowWithPrhoMaterialProperties.cpp @@ -226,7 +226,9 @@ bool TwoPhaseFlowWithPrhoMaterialProperties::computeConstitutiveRelation( auto const success_iterations = newton_solver.solve(J_loc); if (!success_iterations) + { return false; + } } dsw_dpg = calculatedSwdP(pg, Sw, X_m, T, material_id); dsw_dX = calculatedSwdX(pg, X, Sw, X_m, T, material_id); @@ -362,7 +364,9 @@ double TwoPhaseFlowWithPrhoMaterialProperties::calculatedXmdX( double const dPC_dSw = _capillary_pressure_models[current_material_id]->getdPcdS(Sw); if ((1 - Sw) < (rho_equilibrium_wet_h2 - rho_wet_h2)) + { return 1.0; + } return HenryConstantH2 * H2 * dPC_dSw * dSwdX; } /** @@ -380,7 +384,9 @@ double TwoPhaseFlowWithPrhoMaterialProperties::calculatedXmdP( double const dPC_dSw = _capillary_pressure_models[current_material_id]->getdPcdS(Sw); if ((1 - Sw) < (rho_equilibrium_wet_h2 - rho_wet_h2)) + { return 0.0; + } return HenryConstantH2 * H2 * (1 + dPC_dSw * dSwdP); } } // namespace TwoPhaseFlowWithPrho diff --git a/ProcessLib/Utils/ProcessUtils.cpp b/ProcessLib/Utils/ProcessUtils.cpp index a2c36ae98862ad903f11facc6b95924b07c25fb4..4e1a78210b1d122dfeaceac76bfd8ad5667860cf 100644 --- a/ProcessLib/Utils/ProcessUtils.cpp +++ b/ProcessLib/Utils/ProcessUtils.cpp @@ -82,7 +82,9 @@ std::vector<std::reference_wrapper<ProcessVariable>> findProcessVariables( auto var_names = pv_config.getConfigParameterList<std::string>(tag); if (var_names.empty()) + { OGS_FATAL("No entity is found with config tag <%s>.", tag.c_str()); + } std::vector<std::string> cached_var_names; @@ -96,7 +98,9 @@ std::vector<std::reference_wrapper<ProcessVariable>> findProcessVariables( BaseLib::makeVectorUnique(cached_var_names); if (cached_var_names.size() != var_names.size()) + { OGS_FATAL("Found duplicates with config tag <%s>.", tag.c_str()); + } return vars; } diff --git a/Tests/BaseLib/TestAlgorithm.cpp b/Tests/BaseLib/TestAlgorithm.cpp index 47acd45e97561da6e318464dbb63bd22eab41533..e8b445f150c897407a757e4ed7040df94162a863 100644 --- a/Tests/BaseLib/TestAlgorithm.cpp +++ b/Tests/BaseLib/TestAlgorithm.cpp @@ -51,7 +51,9 @@ TEST(BaseLibAlgorithm, excludeObjectCopy) ASSERT_EQ(size - ex_positions.size(), c1.size()); for (std::size_t i(0); i < c1.size(); i++) + { ASSERT_EQ(c1[i], v[size / 10 + i]); + } // do not copy element 0, 2, 4, 6, 8, 10, 12, 14, 16, 18 std::transform(ex_positions.begin(), ex_positions.end(), @@ -62,9 +64,13 @@ TEST(BaseLibAlgorithm, excludeObjectCopy) ASSERT_EQ(size - ex_positions.size(), c2.size()); for (std::size_t i(0); i < ex_positions.size(); i++) + { ASSERT_EQ(c2[i], v[2 * i + 1]); + } for (std::size_t i(ex_positions.size()); i < c2.size(); i++) + { ASSERT_EQ(c2[i], v[ex_positions.size() + i]); + } // do not copy the last element ex_positions.clear(); @@ -74,5 +80,7 @@ TEST(BaseLibAlgorithm, excludeObjectCopy) ASSERT_EQ(size - ex_positions.size(), c3.size()); for (std::size_t i(0); i < c3.size(); i++) + { ASSERT_EQ(c3[i], v[i]); + } } diff --git a/Tests/BaseLib/TestQuicksort.cpp b/Tests/BaseLib/TestQuicksort.cpp index 6839986dda3c1de8e392c4a9d2e789c0b4ce2083..8dc82631299e3ce3e55223eb07caaf77bec6efc4 100644 --- a/Tests/BaseLib/TestQuicksort.cpp +++ b/Tests/BaseLib/TestQuicksort.cpp @@ -60,7 +60,9 @@ TEST_F(BaseLibQuicksort, SortsAsSTLSort) { std::vector<std::size_t> perm(xs.size()); if (!xs.empty()) + { BaseLib::quicksort(xs, 0, xs.size(), perm); + } return std::is_sorted(xs.begin(), xs.end()); }; @@ -100,11 +102,13 @@ TEST_F(BaseLibQuicksort, ReportCorrectPermutations) BaseLib::quicksort(xs, 0, xs.size(), perm); for (std::size_t i = 0; i < perm.size(); ++i) + { if (perm[i] != i) { std::cerr << i << " " << perm[i] << "\n"; return false; } + } return true; }; @@ -127,17 +131,21 @@ TEST_F(BaseLibQuicksort, ReportCorrectPermutationsWithPointer) std::iota(perm.begin(), perm.end(), 0); std::vector<int*> p_xs; - for (int & x : xs) + for (int& x : xs) + { p_xs.push_back(&x); + } BaseLib::quicksort(p_xs, 0, p_xs.size(), perm); for (std::size_t i = 0; i < perm.size(); ++i) + { if (perm[i] != i) { std::cerr << i << " " << perm[i] << "\n"; return false; } + } return true; }; @@ -169,7 +177,12 @@ TEST_F(BaseLibQuicksort, ReportCorrectPermutationsReverse) BaseLib::quicksort(xs, 0, xs.size(), perm); for (std::size_t i = 0; i < perm.size(); ++i) - if (perm[i] != perm.size() - i - 1) return false; + { + if (perm[i] != perm.size() - i - 1) + { + return false; + } + } return true; }; @@ -199,13 +212,20 @@ TEST_F(BaseLibQuicksort, ReportCorrectPermutationsReverseWithPointer) std::iota(perm.begin(), perm.end(), 0); std::vector<int*> p_xs; - for (int & x : xs) + for (int& x : xs) + { p_xs.push_back(&x); + } BaseLib::quicksort(p_xs, 0, p_xs.size(), perm); for (std::size_t i = 0; i < perm.size(); ++i) - if (perm[i] != perm.size() - i - 1) return false; + { + if (perm[i] != perm.size() - i - 1) + { + return false; + } + } return true; }; @@ -227,7 +247,9 @@ struct randomSortedPairGenerator { auto p = std::make_tuple(source(), source()); if (std::get<0>(p) > std::get<1>(p)) + { std::swap(std::get<0>(p), std::get<1>(p)); + } return p; } @@ -235,11 +257,13 @@ struct randomSortedPairGenerator TEST_F(BaseLibQuicksort, SortsRangeAsSTLSort) { - auto quicksortSortsRangeAsSTLSort = [](std::vector<int>& xs, - std::tuple<std::size_t, std::size_t> const& range) -> bool - { + auto quicksortSortsRangeAsSTLSort = + [](std::vector<int>& xs, + std::tuple<std::size_t, std::size_t> const& range) -> bool { if (xs.empty()) + { return true; + } std::vector<std::size_t> perm(xs.size()); std::iota(perm.begin(), perm.end(), 0); diff --git a/Tests/FileIO/TestCsvReader.cpp b/Tests/FileIO/TestCsvReader.cpp index 02a93ce919f79df372c066aa1e31de7984b9c00b..fd12ecb4dacfe85aa0290030b56cc33bb0b0e144 100644 --- a/Tests/FileIO/TestCsvReader.cpp +++ b/Tests/FileIO/TestCsvReader.cpp @@ -65,9 +65,13 @@ TEST_F(CsvInterfaceTest, SimpleReadPoints) ASSERT_TRUE((*points[i])[2] == (*points2[i])[1]); } for (auto p : points) + { delete p; + } for (auto p : points2) + { delete p; + } } /// Dealing with unconvertable data types @@ -101,7 +105,9 @@ TEST_F(CsvInterfaceTest, MissingValues) ASSERT_EQ(7, points.size()); ASSERT_NEAR(437.539, (*points[4])[2], std::numeric_limits<double>::epsilon()); for (auto p : points) + { delete p; + } } /// Reading 2D points @@ -111,10 +117,14 @@ TEST_F(CsvInterfaceTest, Points2D) _result = FileIO::CsvInterface::readPoints(_file_name, '\t', points, "x", "y"); ASSERT_EQ(0, _result); ASSERT_EQ(10, points.size()); - for (auto & point : points) + for (auto& point : points) + { ASSERT_NEAR(0, (*point)[2], std::numeric_limits<double>::epsilon()); + } for (auto p : points) + { delete p; + } } /// Dealing with non-sequential column order @@ -142,11 +152,17 @@ TEST_F(CsvInterfaceTest, CoordinateOrder) ASSERT_EQ((*points1[i])[1], (*points3[i])[0]); } for (auto p : points1) + { delete p; + } for (auto p : points2) + { delete p; + } for (auto p : points3) + { delete p; + } } /// Getting single columns diff --git a/Tests/FileIO/TestCsvWriter.cpp b/Tests/FileIO/TestCsvWriter.cpp index 02df8afabf0185c3759164ac204049003495afab..a27f5038a143f6ab1add8c45e750151c18873194 100644 --- a/Tests/FileIO/TestCsvWriter.cpp +++ b/Tests/FileIO/TestCsvWriter.cpp @@ -26,8 +26,10 @@ TEST(CsvWriter, WriteReadTest) std::vector<int> int_vec { 1, 2, 4, 8, 16, 32, 64 }; std::vector<double> dbl_vec; std::srand ( static_cast<unsigned>(std::time(nullptr)) ); - for (std::size_t i=0; i<int_vec.size(); ++i) + for (std::size_t i = 0; i < int_vec.size(); ++i) + { dbl_vec.push_back(static_cast<double>(std::rand()) / RAND_MAX); + } FileIO::CsvInterface csv; bool added; diff --git a/Tests/FileIO/TestGmlInterface.h b/Tests/FileIO/TestGmlInterface.h index 17c7c900681f44a1891e92416d29a222abfc3a27..3ecb41c5eedfdaa7baab5b77e5a2b1ce97f9760b 100644 --- a/Tests/FileIO/TestGmlInterface.h +++ b/Tests/FileIO/TestGmlInterface.h @@ -106,7 +106,9 @@ public: } if (!name.empty()) + { line_name_map.insert(std::make_pair(name, line_id)); + } }; auto const& pnt_vec = *(geo_objects.getPointVecObj(geo_name)); @@ -136,8 +138,10 @@ public: auto const lines = geo_objects.getPolylineVec(geo_name); GeoLib::Polyline* line = (*lines)[ply_id]; EXPECT_EQ(pnt_ids.size(), line->getNumberOfPoints()); - for (std::size_t k(0); k<pnt_ids.size(); ++k) + for (std::size_t k(0); k < pnt_ids.size(); ++k) + { EXPECT_EQ(pnt_ids[k], line->getPointID(k)); + } std::string line_name; line_vec->getNameOfElementByID(ply_id, line_name); EXPECT_EQ(name, line_name); @@ -189,8 +193,10 @@ public: auto const& sfc_vec = *(sfcs.getVector()); auto const& sfc = *(sfc_vec[sfc_id]); EXPECT_EQ(tri_ids.size(), sfc.getNumberOfTriangles()); - for (std::size_t k(0); k<tri_ids.size(); ++k) + for (std::size_t k(0); k < tri_ids.size(); ++k) + { checkTriangleIDs(*(sfc[k]), tri_ids[k]); + } std::string sfc_name; sfcs.getNameOfElementByID(sfc_id, sfc_name); diff --git a/Tests/FileIO/TestTetGenInterface.cpp b/Tests/FileIO/TestTetGenInterface.cpp index 660b42273f63e0021276c58c4fb024180e4e8bcc..67bc16078ceb513583ff21fcb75e3c0bdf1ddebc 100644 --- a/Tests/FileIO/TestTetGenInterface.cpp +++ b/Tests/FileIO/TestTetGenInterface.cpp @@ -75,8 +75,11 @@ TEST(FileIO, DISABLED_TetGenSmeshInterface) std::vector<GeoLib::Surface*> const& new_sfc (*geo_objects.getSurfaceVec(tg_new_name)); ASSERT_EQ(ref_sfc.size(), new_sfc.size()); - for (std::size_t i=0; i<ref_sfc.size(); ++i) - ASSERT_EQ(ref_sfc[i]->getNumberOfTriangles(), new_sfc[i]->getNumberOfTriangles()); + for (std::size_t i = 0; i < ref_sfc.size(); ++i) + { + ASSERT_EQ(ref_sfc[i]->getNumberOfTriangles(), + new_sfc[i]->getNumberOfTriangles()); + } std::remove(output_name.c_str()); } diff --git a/Tests/GeoLib/AutoCheckGenerators.cpp b/Tests/GeoLib/AutoCheckGenerators.cpp index 02373fef674ff96a1e3f8b31fb9077c80d8e3d53..67d27c2b67e4083b0c6b5edd440ad25384b277ef 100644 --- a/Tests/GeoLib/AutoCheckGenerators.cpp +++ b/Tests/GeoLib/AutoCheckGenerators.cpp @@ -23,10 +23,14 @@ GeoLib::LineSegment translate(MathLib::Vector3 const& translation, { auto a = std::make_unique<GeoLib::Point>(line_seg.getBeginPoint()); auto b = std::make_unique<GeoLib::Point>(line_seg.getEndPoint()); - for (std::size_t k(0); k<3; ++k) + for (std::size_t k(0); k < 3; ++k) + { (*a)[k] += translation[k]; - for (std::size_t k(0); k<3; ++k) + } + for (std::size_t k(0); k < 3; ++k) + { (*b)[k] += translation[k]; + } return GeoLib::LineSegment{a.release(), b.release(), true}; } diff --git a/Tests/GeoLib/TestAABB.cpp b/Tests/GeoLib/TestAABB.cpp index 39c9a1e797fe79d776346bdb8c9eb71bb9f90308..e9c269be7fe3e8ace5a7c56316aab54ed2f35410 100644 --- a/Tests/GeoLib/TestAABB.cpp +++ b/Tests/GeoLib/TestAABB.cpp @@ -225,7 +225,9 @@ TEST(GeoLib, AABBAllPointsWithNegativeCoordinatesI) ASSERT_NEAR(-1.0, max_pnt[2], std::numeric_limits<double>::epsilon()); for (auto p : pnts) + { delete p; + } } TEST(GeoLib, AABBAllPointsWithNegativeCoordinatesII) @@ -270,23 +272,54 @@ TEST(GeoLib, AABBSinglePoint) // points around the aabb are also checked. for (int i(-1); i<2; ++i) { // Modify the first coordinate of p. - if (i==-1) p[0] = std::nextafter(pnts.front()[0], to_lowest); - else if (i==0) p[0] = pnts.front()[0]; - else p[0] = std::nextafter(pnts.front()[0], to_max); + if (i == -1) + { + p[0] = std::nextafter(pnts.front()[0], to_lowest); + } + else if (i == 0) + { + p[0] = pnts.front()[0]; + } + else + { + p[0] = std::nextafter(pnts.front()[0], to_max); + } for (int j(-1); j<2; ++j) { // Modify the second coordinate of p. - if (j==-1) p[1] = std::nextafter(pnts.front()[1], to_lowest); - else if (j==0) p[1] = pnts.front()[1]; - else p[1] = std::nextafter(pnts.front()[1], to_max); + if (j == -1) + { + p[1] = std::nextafter(pnts.front()[1], to_lowest); + } + else if (j == 0) + { + p[1] = pnts.front()[1]; + } + else + { + p[1] = std::nextafter(pnts.front()[1], to_max); + } for (int k(-1); k<2; ++k) { // Modify the third coordinate of p. - if (k==-1) p[2] = std::nextafter(pnts.front()[2], to_lowest); - else if (k==0) p[2] = pnts.front()[2]; - else p[2] = std::nextafter(pnts.front()[2], to_max); + if (k == -1) + { + p[2] = std::nextafter(pnts.front()[2], to_lowest); + } + else if (k == 0) + { + p[2] = pnts.front()[2]; + } + else + { + p[2] = std::nextafter(pnts.front()[2], to_max); + } if (i == 0 && j == 0 && k == 0) + { ASSERT_TRUE(aabb.containsPoint(p, 0)); + } else + { ASSERT_FALSE(aabb.containsPoint(p, 0)); + } } } } diff --git a/Tests/GeoLib/TestBoundingSphere.cpp b/Tests/GeoLib/TestBoundingSphere.cpp index 18ef1ffb8df8a188aa326724db700eceed4d920b..cc09d2c865be302ef94e3ab6c4b87fcfaa75fa20 100644 --- a/Tests/GeoLib/TestBoundingSphere.cpp +++ b/Tests/GeoLib/TestBoundingSphere.cpp @@ -117,7 +117,9 @@ TEST(GeoLib, TestBoundingSphere) std::vector<MathLib::Point3d*>>(s.getRandomSpherePoints(1000)); GeoLib::MinimalBoundingSphere t(*sphere_points); for (auto p : *sphere_points) + { delete p; + } MathLib::Point3d center = s.getCenter(); ASSERT_NEAR(0.5, center[0], std::numeric_limits<double>::epsilon()); ASSERT_NEAR(0.5, center[1], std::numeric_limits<double>::epsilon()); diff --git a/Tests/GeoLib/TestComputeAndInsertAllIntersectionPoints.cpp b/Tests/GeoLib/TestComputeAndInsertAllIntersectionPoints.cpp index 0a87a17669b26cb326b888fe95a7a6f81f13d247..ba0f15adc5552df178265f16498340e570b10802 100644 --- a/Tests/GeoLib/TestComputeAndInsertAllIntersectionPoints.cpp +++ b/Tests/GeoLib/TestComputeAndInsertAllIntersectionPoints.cpp @@ -52,8 +52,10 @@ TEST(GeoLib, TestComputeAndInsertAllIntersectionPoints) ply0->addPoint(0); ply0->addPoint(1); auto* ply1(new GeoLib::Polyline(pnts)); - for (std::size_t k(2); k<pnts.size(); ++k) + for (std::size_t k(2); k < pnts.size(); ++k) + { ply1->addPoint(k); + } auto* plys(new std::vector<GeoLib::Polyline*>); plys->push_back(ply0); plys->push_back(ply1); diff --git a/Tests/GeoLib/TestDuplicateGeometry.cpp b/Tests/GeoLib/TestDuplicateGeometry.cpp index e40f66ec26459bdb8edead4f1436be583e07d702..51dea32e6114365bdab137e2b1478f2049f13895 100644 --- a/Tests/GeoLib/TestDuplicateGeometry.cpp +++ b/Tests/GeoLib/TestDuplicateGeometry.cpp @@ -73,8 +73,10 @@ TEST(GeoLib, DuplicateGeometry) { int n_ply_pnts (rand() % 100 + 2); auto* line = new GeoLib::Polyline(*geo.getPointVec(input_name)); - for (std::size_t j=0; j<static_cast<std::size_t>(n_ply_pnts); ++j) + for (std::size_t j = 0; j < static_cast<std::size_t>(n_ply_pnts); ++j) + { line->addPoint(rand() % n_pnts); + } plys->push_back(line); } geo.addPolylineVec(std::move(plys), input_name); @@ -94,8 +96,11 @@ TEST(GeoLib, DuplicateGeometry) std::size_t const n_ply_pnts ((*new_plys)[i]->getNumberOfPoints()); ASSERT_EQ(n_ply_pnts, (*plys)[i]->getNumberOfPoints()); ASSERT_EQ((*new_plys)[i]->getNumberOfSegments(), (*plys)[i]->getNumberOfSegments()); - for (std::size_t j=0; j<n_ply_pnts; ++j) - ASSERT_EQ((*plys)[i]->getPointID(j), (*new_plys)[i]->getPointID(j)); + for (std::size_t j = 0; j < n_ply_pnts; ++j) + { + ASSERT_EQ((*plys)[i]->getPointID(j), + (*new_plys)[i]->getPointID(j)); + } } std::vector<GeoLib::Polyline*>& mod_plys (dup.getPolylineVectorCopy()); @@ -111,12 +116,18 @@ TEST(GeoLib, DuplicateGeometry) { int n_tris (rand() % 10); auto* sfc = new GeoLib::Surface(*geo.getPointVec(input_name)); - for (std::size_t j=0; j<static_cast<std::size_t>(n_tris); ++j) + for (std::size_t j = 0; j < static_cast<std::size_t>(n_tris); ++j) + { sfc->addTriangle(rand() % n_pnts, rand() % n_pnts, rand() % n_pnts); + } if (sfc->getNumberOfTriangles() > 0) + { sfcs->push_back(sfc); + } else + { delete sfc; + } } n_sfcs = sfcs->size(); geo.addSurfaceVec(std::move(sfcs), input_name); @@ -135,9 +146,14 @@ TEST(GeoLib, DuplicateGeometry) { std::size_t const n_tris ((*new_sfcs)[i]->getNumberOfTriangles()); ASSERT_EQ(n_tris, (*sfcs)[i]->getNumberOfTriangles()); - for (std::size_t j=0; j<n_tris; ++j) - for (std::size_t k=0; k<3; ++k) - ASSERT_EQ((*(*(*sfcs)[i])[j])[k], (*(*(*new_sfcs)[i])[j])[k]); + for (std::size_t j = 0; j < n_tris; ++j) + { + for (std::size_t k = 0; k < 3; ++k) + { + ASSERT_EQ((*(*(*sfcs)[i])[j])[k], + (*(*(*new_sfcs)[i])[j])[k]); + } + } } std::vector<GeoLib::Point*>& mod_pnts (dup.getPointVectorCopy()); diff --git a/Tests/GeoLib/TestOctTree.cpp b/Tests/GeoLib/TestOctTree.cpp index e064e0852ba861530144d55abbec32ada575a726..05f557f0b04c63b7e6df9036e1c29d2bab36fc04 100644 --- a/Tests/GeoLib/TestOctTree.cpp +++ b/Tests/GeoLib/TestOctTree.cpp @@ -184,16 +184,20 @@ TEST_F(GeoLibOctTree, TestWithEquidistantPoints3d) ASSERT_EQ(static_cast<std::size_t>(3), result.size()); // insert some points not resulting in a further refinement of SWL - for (std::size_t k(4); k<11; ++k) + for (std::size_t k(4); k < 11; ++k) + { ASSERT_TRUE(oct_tree->addPoint(ps_ptr[k], ret_pnt)); + } result.clear(); oct_tree->getPointsInRange(range_query_ll, range_query_ur, result); ASSERT_EQ(static_cast<std::size_t>(3), result.size()); // insert some points *resulting* in a further refinement of SWL - for (std::size_t k(11); k<25; ++k) + for (std::size_t k(11); k < 25; ++k) + { ASSERT_TRUE(oct_tree->addPoint(ps_ptr[k], ret_pnt)); + } result.clear(); oct_tree->getPointsInRange(range_query_ll, range_query_ur, result); @@ -201,8 +205,10 @@ TEST_F(GeoLibOctTree, TestWithEquidistantPoints3d) // insert all points with z = -5.0 - this does not result in a further // refinement of SWL - for (std::size_t k(25); k<121; ++k) + for (std::size_t k(25); k < 121; ++k) + { ASSERT_TRUE(oct_tree->addPoint(ps_ptr[k], ret_pnt)); + } result.clear(); oct_tree->getPointsInRange(range_query_ll, range_query_ur, result); @@ -228,7 +234,9 @@ TEST_F(GeoLibOctTree, TestWithEquidistantPoints3d) range_query_ll[2] = -4.75; oct_tree->getPointsInRange(range_query_ll, range_query_ur, result); for (auto p : result) + { std::cout << *p << "\n"; + } ASSERT_EQ(static_cast<std::size_t>(0), result.size()); result.clear(); diff --git a/Tests/GeoLib/TestPolygon.cpp b/Tests/GeoLib/TestPolygon.cpp index c4d69f1718b000c4652a0fcf057b21ec21d3348c..8f14534b5eb3f6f6ab04f89be384a7919ca789ba 100644 --- a/Tests/GeoLib/TestPolygon.cpp +++ b/Tests/GeoLib/TestPolygon.cpp @@ -67,8 +67,10 @@ public: ~PolygonTest() override { delete _polygon; - for (auto & _pnt : _pnts) + for (auto& _pnt : _pnts) + { delete _pnt; + } } protected: @@ -78,8 +80,10 @@ protected: TEST_F(PolygonTest, isPntInPolygonCheckCorners) { - for (auto & _pnt : _pnts) + for (auto& _pnt : _pnts) + { EXPECT_TRUE(_polygon->isPntInPolygon(*_pnt)); + } } TEST_F(PolygonTest, isPntInPolygonCheckPointsRestOnPolygonEdges) @@ -190,8 +194,10 @@ TEST_F(PolygonTest, isPolylineInPolygon) outer_ply.addPoint(0); outer_ply.addPoint(1); ASSERT_FALSE(_polygon->isPolylineInPolygon(outer_ply)); - for (auto & pnt : pnts) + for (auto& pnt : pnts) + { delete pnt; + } pnts.clear(); pnts.push_back(new GeoLib::Point(-1.0,2.0,0.0)); // 3 @@ -200,8 +206,10 @@ TEST_F(PolygonTest, isPolylineInPolygon) inner_ply.addPoint(0); inner_ply.addPoint(1); ASSERT_TRUE(_polygon->isPolylineInPolygon(inner_ply)); - for (auto & pnt : pnts) + for (auto& pnt : pnts) + { delete pnt; + } } TEST_F(PolygonTest, CopyConstructor) @@ -212,5 +220,7 @@ TEST_F(PolygonTest, CopyConstructor) // Check if all line segments of the original polygon are contained in the // copy for (auto const& segment : *_polygon) + { ASSERT_TRUE(polygon_copy.containsSegment(segment)); + } } diff --git a/Tests/GeoLib/TestPolyline.cpp b/Tests/GeoLib/TestPolyline.cpp index 4faa70e255ea57134666d1ab50c08b8e2ad8dcb7..75e4305c3006c049f34be838e971028fbc9d8c89 100644 --- a/Tests/GeoLib/TestPolyline.cpp +++ b/Tests/GeoLib/TestPolyline.cpp @@ -109,6 +109,8 @@ TEST(GeoLib, PolylineTest) } ASSERT_EQ(ply.getNumberOfSegments(), segment_cnt); - for (auto & ply_pnt : ply_pnts) + for (auto& ply_pnt : ply_pnts) + { delete ply_pnt; + } } diff --git a/Tests/GeoLib/TestSimplePolygonTree.cpp b/Tests/GeoLib/TestSimplePolygonTree.cpp index 6b29a86da1820a711088c2da7148920dc55dc966..c631c8a3f3d249b9077528b2f281ff1b4659aa82 100644 --- a/Tests/GeoLib/TestSimplePolygonTree.cpp +++ b/Tests/GeoLib/TestSimplePolygonTree.cpp @@ -92,8 +92,10 @@ public: delete _p1; delete _p2; delete _p3; - for (auto & _pnt : _pnts) + for (auto& _pnt : _pnts) + { delete _pnt; + } } protected: diff --git a/Tests/GeoLib/TestSortSegments.cpp b/Tests/GeoLib/TestSortSegments.cpp index af79ae76d46ee7a2a866a2bb090d3831e442bd1c..7e2a05d8f72b1d1ba11b4af6cd4d52502f3900b1 100644 --- a/Tests/GeoLib/TestSortSegments.cpp +++ b/Tests/GeoLib/TestSortSegments.cpp @@ -71,15 +71,21 @@ TEST_F(GeoLibSortLineSegments, SortSubSegments) double eps(std::numeric_limits<double>::epsilon()); if (MathLib::sqrDist(s0.getBeginPoint(), sub_segments.front().getBeginPoint()) >= eps) + { return false; + } if (MathLib::sqrDist(s0.getEndPoint(), sub_segments.back().getEndPoint()) >= eps) + { return false; + } for (std::size_t k(0); k < sub_segments.size() - 1; ++k) { if (MathLib::sqrDist(sub_segments[k].getEndPoint(), sub_segments[k + 1].getBeginPoint()) >= eps) + { return false; + } } return true; }; @@ -96,7 +102,10 @@ TEST_F(GeoLibSortLineSegments, SortSubSegments) std::vector<GeoLib::LineSegment> sub_segments; partitionSegment(s0, sub_seg_ids, dt, sub_segments); GeoLib::sortSegments(s0.getBeginPoint(), sub_segments); - if (!checkSortedSubSegments(s0, sub_segments)) return false; + if (!checkSortedSubSegments(s0, sub_segments)) + { + return false; + } } while (std::next_permutation(sub_seg_ids.begin(), sub_seg_ids.end())); return true; }; diff --git a/Tests/GeoLib/TestSurfaceIsPointInSurface.cpp b/Tests/GeoLib/TestSurfaceIsPointInSurface.cpp index 11fd33e8c64f71096e155f6d9730b3e0037dc4c9..b686161f3abaeff5abc543e856b08b4e379fd496 100644 --- a/Tests/GeoLib/TestSurfaceIsPointInSurface.cpp +++ b/Tests/GeoLib/TestSurfaceIsPointInSurface.cpp @@ -96,9 +96,13 @@ TEST(GeoLib, SurfaceIsPointInSurface) normal_dist_ur(random_engine_mt19937), normal_dist_ur(random_engine_mt19937), 0.0}})); - for (std::size_t k(0); k<3; ++k) + for (std::size_t k(0); k < 3; ++k) + { if (ll[k] > ur[k]) + { std::swap(ll[k], ur[k]); + } + } // random discretization of the domain std::default_random_engine re(rd()); @@ -144,8 +148,10 @@ TEST(GeoLib, SurfaceIsPointInSurface) for (auto const p : pnts) { EXPECT_TRUE(sfc->isPntInSfc(*p, eps)); MathLib::Point3d q(*p); - for (std::size_t k(0); k<3; ++k) + for (std::size_t k(0); k < 3; ++k) + { q[k] += displacement[k]; + } EXPECT_FALSE(sfc->isPntInSfc(q, eps)); } // test edge middle points of the triangles diff --git a/Tests/MaterialLib/TestCapillaryPressureSaturationModel.cpp b/Tests/MaterialLib/TestCapillaryPressureSaturationModel.cpp index cbcc039937edb6766b6180e07c0f3b537513fb56..94d93cc0554d7f4ddf335cd3691f70896ccfe3f8 100644 --- a/Tests/MaterialLib/TestCapillaryPressureSaturationModel.cpp +++ b/Tests/MaterialLib/TestCapillaryPressureSaturationModel.cpp @@ -126,9 +126,13 @@ TEST(MaterialPorousMedium, checkCapillaryPressureCurve) ASSERT_NEAR(dpc_dS[i], pc_model->getdPcdS(S[i]), 1.e-5); if (i == S.size() - 1) + { // Minimum Pc to maximum saturation ASSERT_NEAR(0.9, pc_model->getSaturation(pc[i]), 1.e-5); + } else + { ASSERT_NEAR(S[i], pc_model->getSaturation(pc[i]), 1.e-5); + } } } diff --git a/Tests/MaterialLib/TestRelativePermeabilityModel.cpp b/Tests/MaterialLib/TestRelativePermeabilityModel.cpp index cf1e2ec527a6678ce2e79404e670881d80050e1d..df05d51a27aee8e24235c3cea3a2281256458f2f 100644 --- a/Tests/MaterialLib/TestRelativePermeabilityModel.cpp +++ b/Tests/MaterialLib/TestRelativePermeabilityModel.cpp @@ -127,7 +127,9 @@ TEST(MaterialPorousMedium, checkWettingPhaseBrooksCoreyOilGas) // i == S.size() -1, S(=0.85) is limited to 0.8, and the numerical // derivative of krel is unavailable. if (i == S.size() - 1) + { continue; + } // Compare the derivative with numerical one. ASSERT_NEAR((perm_model->getValue(S[i] + perturbation) - perm_model->getValue(S[i])) / diff --git a/Tests/MathLib/TestDenseMatrix.cpp b/Tests/MathLib/TestDenseMatrix.cpp index 1139d1b1f495f847c7a9778d66c895e4d6094e47..d199904e6caf778219a3ebcddd5470f8e8c55b87 100644 --- a/Tests/MathLib/TestDenseMatrix.cpp +++ b/Tests/MathLib/TestDenseMatrix.cpp @@ -20,9 +20,13 @@ TEST(MathLib, DenseMatrixTransposeInPlace) // square matrix DenseMatrix<double> m1(3,3); unsigned cnt = 0; - for (unsigned i=0; i<m1.getNumberOfRows(); i++) - for (unsigned j=0; j<m1.getNumberOfColumns(); j++) - m1(i,j) = cnt++; + for (unsigned i = 0; i < m1.getNumberOfRows(); i++) + { + for (unsigned j = 0; j < m1.getNumberOfColumns(); j++) + { + m1(i, j) = cnt++; + } + } double expected_m1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8}; ASSERT_EQ(3u, m1.getNumberOfRows()); ASSERT_EQ(3u, m1.getNumberOfColumns()); @@ -36,9 +40,13 @@ TEST(MathLib, DenseMatrixTransposeInPlace) // non-square matrix 1 DenseMatrix<double> m2(2,3); cnt = 0; - for (unsigned i=0; i<m2.getNumberOfRows(); i++) - for (unsigned j=0; j<m2.getNumberOfColumns(); j++) - m2(i,j) = cnt++; + for (unsigned i = 0; i < m2.getNumberOfRows(); i++) + { + for (unsigned j = 0; j < m2.getNumberOfColumns(); j++) + { + m2(i, j) = cnt++; + } + } ASSERT_EQ(2u, m2.getNumberOfRows()); ASSERT_EQ(3u, m2.getNumberOfColumns()); double expected_m2[] = {0, 1, 2, 3, 4, 5}; @@ -52,9 +60,13 @@ TEST(MathLib, DenseMatrixTransposeInPlace) // non-square matrix 2 DenseMatrix<double> m3(3,2); cnt = 0; - for (unsigned i=0; i<m3.getNumberOfRows(); i++) - for (unsigned j=0; j<m3.getNumberOfColumns(); j++) - m3(i,j) = cnt++; + for (unsigned i = 0; i < m3.getNumberOfRows(); i++) + { + for (unsigned j = 0; j < m3.getNumberOfColumns(); j++) + { + m3(i, j) = cnt++; + } + } ASSERT_EQ(3u, m3.getNumberOfRows()); ASSERT_EQ(2u, m3.getNumberOfColumns()); double expected_m3[] = {0, 1, 2, 3, 4, 5}; diff --git a/Tests/MathLib/TestEigenCSR.cpp b/Tests/MathLib/TestEigenCSR.cpp index a70ad78a02f56ab2dc059fb5ff28c726342cec51..9fb4a852f2a17c8f6367b2b5fbae1f623d3ba11f 100644 --- a/Tests/MathLib/TestEigenCSR.cpp +++ b/Tests/MathLib/TestEigenCSR.cpp @@ -58,7 +58,10 @@ TEST(MathLibEigen, Eigen2CSR) for (int row=0; row<nrows; ++row) { for (int col = -1; col<=1; ++col) { int cidx = row + col; - if (cidx < 0 || cidx >= ncols) continue; + if (cidx < 0 || cidx >= ncols) + { + continue; + } const double val = (col == 0) ? 2.0 : -1.0; values.push_back(val); @@ -71,13 +74,19 @@ TEST(MathLibEigen, Eigen2CSR) for (int row=0; row<nrows; ++row) { for (int col = -1; col<=1; ++col) { int cidx = row + col; - if (cidx < 0 || cidx >= ncols) continue; + if (cidx < 0 || cidx >= ncols) + { + continue; + } mat.coeffRef(row, cidx) = 4.0 * mat.coeff(row, cidx); } } // adapt entries of CSR matrix - for (auto& v : values) v *= 4.0; + for (auto& v : values) + { + v *= 4.0; + } mat.makeCompressed(); diff --git a/Tests/MathLib/TestGaussLegendreIntegration.cpp b/Tests/MathLib/TestGaussLegendreIntegration.cpp index f5526c0cdb3057b6386f8c192ec9eb9c2b01f7f3..aa74b68729751dce88ec5ba994b3a543de710cae 100644 --- a/Tests/MathLib/TestGaussLegendreIntegration.cpp +++ b/Tests/MathLib/TestGaussLegendreIntegration.cpp @@ -77,7 +77,9 @@ public: : _e(e) { if (is_axially_symmetric) + { OGS_FATAL("Only testing Cartesian meshes!"); + } } double integrate(const Function& f, @@ -457,7 +459,9 @@ OGS_DONT_TEST_THIS_IF_PETSC(MathLib, IntegrationGaussLegendreTet) for (unsigned polynomial_order : {0, 1, 2}) { if (polynomial_order > 2 * integration_order - 1) + { break; + } DBUG(" == polynomial order: %u.", polynomial_order); auto f = GaussLegendreTest::getF(polynomial_order); @@ -484,7 +488,9 @@ OGS_DONT_TEST_THIS_IF_PETSC(MathLib, IntegrationGaussLegendreHex) for (unsigned polynomial_order : {0, 1, 2}) { if (polynomial_order > 2 * integration_order - 1) + { break; + } DBUG(" == polynomial order: %u.", polynomial_order); auto f = GaussLegendreTest::getF(polynomial_order); diff --git a/Tests/MathLib/TestLinearSolver.cpp b/Tests/MathLib/TestLinearSolver.cpp index 462bf5273415fbf16ec175da7d2c267c96b0ba06..7fe0c4ddbacd1bc36bd08dfb79a8206ddae1d1a3 100644 --- a/Tests/MathLib/TestLinearSolver.cpp +++ b/Tests/MathLib/TestLinearSolver.cpp @@ -62,8 +62,12 @@ void setMatrix9x9(T_Mat &mat) 0, 0, 0, 0, -3.33333e-012, -1.66667e-012, 0, -1.66667e-012, 6.66667e-012 }; for (unsigned i = 0; i < 9; i++) + { for (unsigned j = 0; j < 9; j++) - mat.setValue(i, j, d_mat[i*9+j]); + { + mat.setValue(i, j, d_mat[i * 9 + j]); + } + } } template<typename IntType> struct Example1 @@ -85,9 +89,18 @@ template<typename IntType> struct Example1 std::fill(vec_dirichlet_bc_value.begin()+3, vec_dirichlet_bc_value.end(), 1.0); for (std::size_t i=0; i<9; i++) { - if (i%3==0) exH[i] = 1.0; - if (i%3==1) exH[i] = 0.5; - if (i%3==2) exH[i] = 0.; + if (i % 3 == 0) + { + exH[i] = 1.0; + } + if (i % 3 == 1) + { + exH[i] = 0.5; + } + if (i % 3 == 2) + { + exH[i] = 0.; + } } } @@ -109,8 +122,10 @@ void checkLinearSolverInterface(T_MATRIX &A, BaseLib::ConfigTree const& ls_optio for (std::size_t j=0; j<ex1.dim_eqs; j++) { double v = ex1.mat.get(i, j); - if (v!=.0) + if (v != .0) + { A.add(i, j, v); + } } } diff --git a/Tests/MathLib/TestNonlinear1D.cpp b/Tests/MathLib/TestNonlinear1D.cpp index 1f4e99803ace6dde278569a414c4dee7c43a3af3..8dcb62bc8c497a2149563854d1b1645132d5f7d3 100644 --- a/Tests/MathLib/TestNonlinear1D.cpp +++ b/Tests/MathLib/TestNonlinear1D.cpp @@ -44,7 +44,10 @@ TYPED_TEST(MathLibRegulaFalsi, QuadraticFunction) old_range = range; DBUG("%2i -- x ~ %23.16g, range = %23.16g", n+1, rf.getResult(), range); - if (range < std::numeric_limits<double>::epsilon()) break; + if (range < std::numeric_limits<double>::epsilon()) + { + break; + } } auto const error = std::abs(f(rf.getResult())); diff --git a/Tests/MathLib/TestODESolver.cpp b/Tests/MathLib/TestODESolver.cpp index 012eb39802407595baad31198913c86090cbc26b..1efffb440b22d5e70849dfafb1ffd714368f1d5d 100644 --- a/Tests/MathLib/TestODESolver.cpp +++ b/Tests/MathLib/TestODESolver.cpp @@ -20,7 +20,10 @@ bool f(const double, MathLib::ODE::MappedConstVector<1> const& y, MathLib::ODE::MappedVector<1>& ydot) { - if (y[0] <= 0.0) return false; + if (y[0] <= 0.0) + { + return false; + } ydot[0] = -15.0 * y[0]; return true; @@ -31,7 +34,10 @@ bool df(const double /*t*/, MathLib::ODE::MappedConstVector<1> const& /*ydot*/, MathLib::ODE::MappedMatrix<1, 1>& jac) { - if (y[0] <= 0.0) return false; + if (y[0] <= 0.0) + { + return false; + } jac(0, 0) = -15.0; return true; @@ -47,7 +53,10 @@ bool f_extra(const double, MathLib::ODE::MappedVector<1>& ydot, ExtraData& data) { - if (y[0] <= 0.0) return false; + if (y[0] <= 0.0) + { + return false; + } ydot[0] = -data.value * y[0]; return true; @@ -121,7 +130,10 @@ TEST(MathLibCVodeTest, Exponential) ASSERT_EQ(any_ode_solver_libs_available(), !!ode_solver); // Don't run the test if the ODE solver could not be constructed. - if (!ode_solver) return; + if (!ode_solver) + { + return; + } ode_solver->setFunction(f, nullptr); ode_solver->setTolerance(abs_tol, rel_tol); @@ -160,7 +172,10 @@ TEST(MathLibCVodeTest, ExponentialExtraData) ASSERT_EQ(any_ode_solver_libs_available(), !!ode_solver); // Don't run the test if the ODE solver could not be constructed. - if (!ode_solver) return; + if (!ode_solver) + { + return; + } ExtraData data; auto f_lambda = [&](double t, @@ -224,7 +239,10 @@ TEST(MathLibCVodeTest, ExponentialWithJacobian) ASSERT_EQ(any_ode_solver_libs_available(), !!ode_solver); // Don't run the test if the ODE solver could not be constructed. - if (!ode_solver) return; + if (!ode_solver) + { + return; + } ode_solver->setFunction(f, df); ode_solver->setTolerance(abs_tol, rel_tol); @@ -265,7 +283,10 @@ TEST(MathLibCVodeTest, ExponentialWithJacobianNewton) ASSERT_EQ(any_ode_solver_libs_available(), !!ode_solver); // Don't run the test if the ODE solver could not be constructed. - if (!ode_solver) return; + if (!ode_solver) + { + return; + } ode_solver->setFunction(f, df); ode_solver->setTolerance(abs_tol, rel_tol); diff --git a/Tests/MeshLib/MeshProperties.cpp b/Tests/MeshLib/MeshProperties.cpp index f3ef3fea4930060c6f161205a80f21be793e5668..b23c5e27be5d87bcdbf2ebbfbe5d27ed046552e9 100644 --- a/Tests/MeshLib/MeshProperties.cpp +++ b/Tests/MeshLib/MeshProperties.cpp @@ -89,13 +89,17 @@ TEST_F(MeshLibProperties, PropertyVectorTestIntegrationPoint) std::size_t const size = offsets[i + 1] - offsets[i]; ASSERT_EQ(n_integration_points, size); for (int ip = 0; ip < n_integration_points; ++ip) + { ASSERT_EQ(i + ip * 0.01, p[offsets[i] + ip]); + } } { // Last element std::size_t const size = p.size() - offsets[i]; ASSERT_EQ(n_integration_points, size); for (int ip = 0; ip < n_integration_points; ++ip) + { ASSERT_EQ(i + ip * 0.01, p[offsets[i] + ip]); + } } } diff --git a/Tests/MeshLib/TestAddLayerToMesh.cpp b/Tests/MeshLib/TestAddLayerToMesh.cpp index 048039aa0a6fccf51ce33ca3b87fde89bed14732..cf050321c262dfbf197ab38e7f089d48cfe8cdfc 100644 --- a/Tests/MeshLib/TestAddLayerToMesh.cpp +++ b/Tests/MeshLib/TestAddLayerToMesh.cpp @@ -33,8 +33,12 @@ namespace AddLayerValidation ElementErrorFlag::NonCoplanar, ElementErrorFlag::NonConvex, ElementErrorFlag::NodeOrder}; std::vector<ElementErrorCode> const codes (MeshLib::MeshValidation::testElementGeometry(mesh)); for (auto code : codes) - for (std::size_t j=0; j<nErrorFlags-reduce_tests; ++j) + { + for (std::size_t j = 0; j < nErrorFlags - reduce_tests; ++j) + { ASSERT_FALSE(code[flags[j]]); + } + } } void testZCoords2D(MeshLib::Mesh const& input, MeshLib::Mesh const& output, double height) @@ -50,8 +54,10 @@ namespace AddLayerValidation void testZCoords3D(MeshLib::Mesh const& input, MeshLib::Mesh const& output, double height) { std::size_t const nNodes (input.getNumberOfNodes()); - for (std::size_t i=0; i<nNodes; ++i) + for (std::size_t i = 0; i < nNodes; ++i) + { ASSERT_EQ((*input.getNode(i))[2] + height, (*output.getNode(i))[2]); + } } } // namespace AddLayerValidation diff --git a/Tests/MeshLib/TestBoundaryElementSearch.cpp b/Tests/MeshLib/TestBoundaryElementSearch.cpp index 90dbd22939e3af95333dd5ba59ad3f2fb14081c5..801cbc2905caf8ec06f7055f90eac808a6051e7d 100644 --- a/Tests/MeshLib/TestBoundaryElementSearch.cpp +++ b/Tests/MeshLib/TestBoundaryElementSearch.cpp @@ -37,7 +37,9 @@ public: ~MeshLibBoundaryElementSearchInSimpleQuadMesh() override { for (auto p : _pnts) + { delete p; + } } protected: @@ -68,7 +70,9 @@ public: ~MeshLibBoundaryElementSearchInSimpleHexMesh() override { for (auto p : _pnts) + { delete p; + } } void TestHexSurfacesBoundaryElementSearcher( @@ -170,7 +174,9 @@ void MeshLibBoundaryElementSearchInSimpleHexMesh:: auto connected_nodes_b = MeshLib::getUniqueNodes(found_faces_sfc_b); ASSERT_EQ(n_nodes_2d, connected_nodes_b.size()); for (auto node : connected_nodes_b) + { ASSERT_EQ(0.0, (*node)[2]); // check z coordinates + } // perform search on the front surface GeoLib::Surface sfc_front(_pnts); @@ -186,7 +192,9 @@ void MeshLibBoundaryElementSearchInSimpleHexMesh:: auto connected_nodes_f = MeshLib::getUniqueNodes(found_faces_sfc_f); ASSERT_EQ(n_nodes_2d, connected_nodes_f.size()); for (auto node : connected_nodes_f) + { ASSERT_EQ(0.0, (*node)[1]); // check y coordinates + } } TEST_F(MeshLibBoundaryElementSearchInSimpleHexMesh, SurfaceSearch) diff --git a/Tests/MeshLib/TestCoordinatesMappingLocal.cpp b/Tests/MeshLib/TestCoordinatesMappingLocal.cpp index c69faf423e01c2e3f0313504c3f74bc2bd9d50ed..c69d37beb0bf4decb0a8c1d22bd5303519a035c7 100644 --- a/Tests/MeshLib/TestCoordinatesMappingLocal.cpp +++ b/Tests/MeshLib/TestCoordinatesMappingLocal.cpp @@ -169,7 +169,9 @@ TEST(MeshLib, CoordinatesMappingLocalLowerDimLineY) CHECK_COORDS(ele,mapping); for (std::size_t n = 0; n < ele->getNumberOfNodes(); ++n) + { delete ele->getNode(n); + } } TEST(MeshLib, CoordinatesMappingLocalLowerDimLineZ) @@ -188,7 +190,9 @@ TEST(MeshLib, CoordinatesMappingLocalLowerDimLineZ) CHECK_COORDS(ele,mapping); for (std::size_t n = 0; n < ele->getNumberOfNodes(); ++n) + { delete ele->getNode(n); + } } TEST(MeshLib, CoordinatesMappingLocalLowerDimLineXY) @@ -207,7 +211,9 @@ TEST(MeshLib, CoordinatesMappingLocalLowerDimLineXY) CHECK_COORDS(ele,mapping); for (std::size_t n = 0; n < ele->getNumberOfNodes(); ++n) + { delete ele->getNode(n); + } } TEST(MeshLib, CoordinatesMappingLocalLowerDimLineXYZ) @@ -226,7 +232,9 @@ TEST(MeshLib, CoordinatesMappingLocalLowerDimLineXYZ) CHECK_COORDS(ele,mapping); for (std::size_t n = 0; n < ele->getNumberOfNodes(); ++n) + { delete ele->getNode(n); + } } TEST(MeshLib, CoordinatesMappingLocalLowerDimQuadXZ) @@ -247,7 +255,9 @@ TEST(MeshLib, CoordinatesMappingLocalLowerDimQuadXZ) CHECK_COORDS(ele,mapping); for (std::size_t n = 0; n < ele->getNumberOfNodes(); ++n) + { delete ele->getNode(n); + } } TEST(MeshLib, CoordinatesMappingLocalLowerDimQuadYZ) @@ -268,7 +278,9 @@ TEST(MeshLib, CoordinatesMappingLocalLowerDimQuadYZ) CHECK_COORDS(ele,mapping); for (std::size_t n = 0; n < ele->getNumberOfNodes(); ++n) + { delete ele->getNode(n); + } } TEST(MeshLib, CoordinatesMappingLocalLowerDimQuadXYZ) @@ -289,6 +301,8 @@ TEST(MeshLib, CoordinatesMappingLocalLowerDimQuadXYZ) CHECK_COORDS(ele,mapping); for (std::size_t n = 0; n < ele->getNumberOfNodes(); ++n) + { delete ele->getNode(n); + } } diff --git a/Tests/MeshLib/TestElementConstants.cpp b/Tests/MeshLib/TestElementConstants.cpp index f16fb963c3074735ceb7fa4ea6cc73297704b39b..7d2e91b70a837747214a14529173cecba84ee5a8 100644 --- a/Tests/MeshLib/TestElementConstants.cpp +++ b/Tests/MeshLib/TestElementConstants.cpp @@ -32,7 +32,9 @@ TEST(MeshLib, ElementConstantsQuad4) ASSERT_EQ(4u, quad.getNumberOfBaseNodes()); for (auto n : nodes) + { delete n; + } } TEST(MeshLib, ElementConstantsQuad8) @@ -59,7 +61,9 @@ TEST(MeshLib, ElementConstantsQuad8) ASSERT_EQ(4u, quad8.getNumberOfBaseNodes()); for (auto n : nodes) + { delete n; + } } TEST(MeshLib, ElementConstantsQuad9) @@ -87,7 +91,9 @@ TEST(MeshLib, ElementConstantsQuad9) ASSERT_EQ(4u, quad9.getNumberOfBaseNodes()); for (auto n : nodes) + { delete n; + } } TEST(MeshLib, ElementConstantsHex8) @@ -112,7 +118,9 @@ TEST(MeshLib, ElementConstantsHex8) ASSERT_EQ(8u, ele.getNumberOfBaseNodes()); for (auto n : nodes) + { delete n; + } } TEST(MeshLib, ElementConstantsHex20) @@ -149,7 +157,9 @@ TEST(MeshLib, ElementConstantsHex20) ASSERT_EQ( 8u, ele.getNumberOfBaseNodes()); for (auto n : nodes) + { delete n; + } } TEST(MeshLib, ElementConstantsTet4) @@ -170,7 +180,9 @@ TEST(MeshLib, ElementConstantsTet4) ASSERT_EQ(4u, ele.getNumberOfBaseNodes()); for (auto n : nodes) + { delete n; + } } TEST(MeshLib, ElementConstantsTet10) @@ -198,6 +210,8 @@ TEST(MeshLib, ElementConstantsTet10) ASSERT_EQ( 4u, ele.getNumberOfBaseNodes()); for (auto n : nodes) + { delete n; + } } diff --git a/Tests/MeshLib/TestElementStatus.cpp b/Tests/MeshLib/TestElementStatus.cpp index bcdcc900557885755bded436ab726f93a2f860a1..5abc688ede292b9aa66ec2017a62caae0d53fb59 100644 --- a/Tests/MeshLib/TestElementStatus.cpp +++ b/Tests/MeshLib/TestElementStatus.cpp @@ -39,8 +39,11 @@ TEST(MeshLib, ElementStatus) for (unsigned i=0; i<elements_per_side; ++i) { - for (unsigned j=0; j<elements_per_side; ++j) - (*material_id_properties)[elements[i*elements_per_side + j]->getID()] = i; + for (unsigned j = 0; j < elements_per_side; ++j) + { + (*material_id_properties)[elements[i * elements_per_side + j] + ->getID()] = i; + } } { diff --git a/Tests/MeshLib/TestFindElementsWithinRadius.cpp b/Tests/MeshLib/TestFindElementsWithinRadius.cpp index 00684cee6761ea48e5d5cf392864bf782802dfb3..c9c946db16916a8a2376740aac07eceec2fb466f 100644 --- a/Tests/MeshLib/TestFindElementsWithinRadius.cpp +++ b/Tests/MeshLib/TestFindElementsWithinRadius.cpp @@ -83,7 +83,9 @@ std::vector<Node const*> findNodesWithinRadius(Mesh const& mesh, auto const* n = mesh.getNode(i); auto const distance_squared = MathLib::sqrDist(node, *n); if (distance_squared > radius * radius) + { continue; + } nodes.push_back(n); } diff --git a/Tests/MeshLib/TestFlipElements.cpp b/Tests/MeshLib/TestFlipElements.cpp index 953ee224a577c4a2bd48d39a6dcef78a67e64581..b65ab7164786e8d1de6a967b71be9a8db3a87955 100644 --- a/Tests/MeshLib/TestFlipElements.cpp +++ b/Tests/MeshLib/TestFlipElements.cpp @@ -80,12 +80,16 @@ TEST(MeshLib, FlipHexMesh) ASSERT_EQ(nullptr, result); std::vector<MeshLib::Node*> nodes; - for (std::size_t i=0; i<mesh->getNumberOfNodes(); ++i) + for (std::size_t i = 0; i < mesh->getNumberOfNodes(); ++i) + { nodes.push_back(new MeshLib::Node(*mesh->getNode(i))); + } std::unique_ptr<MeshLib::Element> elem (MeshLib::createFlippedElement(*mesh->getElement(0), nodes)); ASSERT_EQ(nullptr, elem); for (MeshLib::Node* n : nodes) + { delete n; + } } TEST(MeshLib, DoubleFlipQuadMesh) @@ -96,9 +100,13 @@ TEST(MeshLib, DoubleFlipQuadMesh) ASSERT_EQ(mesh->getNumberOfNodes(), result2->getNumberOfNodes()); ASSERT_EQ(mesh->getNumberOfElements(), result2->getNumberOfElements()); - for (std::size_t i=0; i<result2->getNumberOfElements(); ++i) - for (std::size_t j=0; j<4; ++j) + for (std::size_t i = 0; i < result2->getNumberOfElements(); ++i) + { + for (std::size_t j = 0; j < 4; ++j) + { ASSERT_EQ(mesh->getElement(i)->getNode(j)->getID(), result2->getElement(i)->getNode(j)->getID()); + } + } } diff --git a/Tests/MeshLib/TestLineMesh.cpp b/Tests/MeshLib/TestLineMesh.cpp index 932e705864328d17ca1d37d419c73791f0058a36..e9e08e82c314fb0f40ded399a8e86c221a4a54ff 100644 --- a/Tests/MeshLib/TestLineMesh.cpp +++ b/Tests/MeshLib/TestLineMesh.cpp @@ -42,7 +42,9 @@ TEST_F(MeshLibLineMesh, Construction) // All elements have maximum two neighbors. std::vector<MeshLib::Element*> const& elements = mesh->getElements(); for (auto e : elements) + { ASSERT_EQ(2u, e->getNumberOfNeighbors()); + } ASSERT_NEAR(extent/mesh_size, mesh->getMinEdgeLength(),std::numeric_limits<double>::epsilon()); ASSERT_NEAR(extent/mesh_size, mesh->getMaxEdgeLength(),std::numeric_limits<double>::epsilon()); @@ -54,8 +56,12 @@ TEST_F(MeshLibLineMesh, ElementNeigbors) { unsigned count = 0; for (int i = 0; i < 2; i++) + { if (e->getNeighbor(i) != nullptr) + { count++; + } + } return count; }; diff --git a/Tests/MeshLib/TestMeshGenerator.cpp b/Tests/MeshLib/TestMeshGenerator.cpp index 42cb007fc673b6b8a0b3ca1e510f16481d02169a..5e367faf74276cf5d1e06649f29d1766627079e6 100644 --- a/Tests/MeshLib/TestMeshGenerator.cpp +++ b/Tests/MeshLib/TestMeshGenerator.cpp @@ -126,8 +126,10 @@ TEST(MeshLib, MeshGeneratorRegularPrism) ASSERT_EQ((n_x+1) * (n_y+1) * (n_z+1), mesh->getNumberOfNodes()); std::size_t count (0); - for (std::size_t k=0; k<(n_z+1); ++k) - for (std::size_t j=0; j<(n_y+1); ++j) + for (std::size_t k = 0; k < (n_z + 1); ++k) + { + for (std::size_t j = 0; j < (n_y + 1); ++j) + { for (std::size_t i=0; i<(n_x+1); ++i) { const MeshLib::Node* node (mesh->getNode(count++)); @@ -135,4 +137,6 @@ TEST(MeshLib, MeshGeneratorRegularPrism) ASSERT_DOUBLE_EQ(static_cast<double>(j*2), (*node)[1]); ASSERT_DOUBLE_EQ(static_cast<double>(k*2), (*node)[2]); } + } + } } diff --git a/Tests/MeshLib/TestMeshNodeSearch.cpp b/Tests/MeshLib/TestMeshNodeSearch.cpp index a6bfd86dfe2e265e3adad4d2d0033c997994e9c1..83a116f98c96cec1c13b54ce1ffb17f4e7ae77be 100644 --- a/Tests/MeshLib/TestMeshNodeSearch.cpp +++ b/Tests/MeshLib/TestMeshNodeSearch.cpp @@ -146,8 +146,10 @@ TEST_F(MeshLibMeshNodeSearchInSimpleQuadMesh, PolylineSearch) std::vector<std::size_t> const& found_ids_ply0(mesh_node_searcher.getMeshNodeIDsAlongPolyline(ply0)); ASSERT_EQ(100u, found_ids_ply0.size()); - for (std::size_t k(0); k<found_ids_ply0.size(); k++) + for (std::size_t k(0); k < found_ids_ply0.size(); k++) + { ASSERT_EQ(k, found_ids_ply0[k]); + } GeoLib::Polyline ply1(pnts); ply1.addPoint(2); @@ -155,8 +157,10 @@ TEST_F(MeshLibMeshNodeSearchInSimpleQuadMesh, PolylineSearch) std::vector<std::size_t> const& found_ids_ply1(mesh_node_searcher.getMeshNodeIDsAlongPolyline(ply1)); ASSERT_EQ(100u, found_ids_ply1.size()); - for (std::size_t k(0); k<found_ids_ply1.size(); k++) + for (std::size_t k(0); k < found_ids_ply1.size(); k++) + { ASSERT_EQ(k, found_ids_ply1[k]); + } GeoLib::Polyline ply2(pnts); ply2.addPoint(4); @@ -165,8 +169,10 @@ TEST_F(MeshLibMeshNodeSearchInSimpleQuadMesh, PolylineSearch) std::size_t offset((_number_of_subdivisions_per_direction+1)*_number_of_subdivisions_per_direction); ASSERT_EQ(100u, found_ids_ply2.size()); - for (std::size_t k(0); k<found_ids_ply2.size(); k++) + for (std::size_t k(0); k < found_ids_ply2.size(); k++) + { ASSERT_EQ(offset + k, found_ids_ply2[k]); + } GeoLib::Polyline ply3(pnts); ply3.addPoint(6); @@ -174,8 +180,10 @@ TEST_F(MeshLibMeshNodeSearchInSimpleQuadMesh, PolylineSearch) std::vector<std::size_t> const& found_ids_ply3(mesh_node_searcher.getMeshNodeIDsAlongPolyline(ply3)); ASSERT_EQ(100u, found_ids_ply3.size()); - for (std::size_t k(0); k<found_ids_ply3.size(); k++) + for (std::size_t k(0); k < found_ids_ply3.size(); k++) + { ASSERT_EQ(offset + k, found_ids_ply3[k]); + } // left border GeoLib::Polyline ply4(pnts); @@ -184,8 +192,11 @@ TEST_F(MeshLibMeshNodeSearchInSimpleQuadMesh, PolylineSearch) std::vector<std::size_t> const& found_ids_ply4(mesh_node_searcher.getMeshNodeIDsAlongPolyline(ply4)); ASSERT_EQ(100u, found_ids_ply4.size()); - for (std::size_t k(0); k<found_ids_ply4.size(); k++) - ASSERT_EQ(k*(_number_of_subdivisions_per_direction+1), found_ids_ply4[k]); + for (std::size_t k(0); k < found_ids_ply4.size(); k++) + { + ASSERT_EQ(k * (_number_of_subdivisions_per_direction + 1), + found_ids_ply4[k]); + } // right border GeoLib::Polyline ply5(pnts); @@ -194,8 +205,12 @@ TEST_F(MeshLibMeshNodeSearchInSimpleQuadMesh, PolylineSearch) std::vector<std::size_t> const& found_ids_ply5(mesh_node_searcher.getMeshNodeIDsAlongPolyline(ply5)); ASSERT_EQ(100u, found_ids_ply5.size()); - for (std::size_t k(0); k<found_ids_ply5.size(); k++) - ASSERT_EQ(k*(_number_of_subdivisions_per_direction+1)+_number_of_subdivisions_per_direction, found_ids_ply5[k]); + for (std::size_t k(0); k < found_ids_ply5.size(); k++) + { + ASSERT_EQ(k * (_number_of_subdivisions_per_direction + 1) + + _number_of_subdivisions_per_direction, + found_ids_ply5[k]); + } // diagonal GeoLib::Polyline ply6(pnts); @@ -204,8 +219,11 @@ TEST_F(MeshLibMeshNodeSearchInSimpleQuadMesh, PolylineSearch) std::vector<std::size_t> const& found_ids_ply6(mesh_node_searcher.getMeshNodeIDsAlongPolyline(ply6)); ASSERT_EQ(100u, found_ids_ply6.size()); - for (std::size_t k(0); k<found_ids_ply6.size(); k++) - ASSERT_EQ(k*(_number_of_subdivisions_per_direction+1)+k, found_ids_ply6[k]); + for (std::size_t k(0); k < found_ids_ply6.size(); k++) + { + ASSERT_EQ(k * (_number_of_subdivisions_per_direction + 1) + k, + found_ids_ply6[k]); + } std::for_each(pnts.begin(), pnts.end(), [](GeoLib::Point* pnt) { delete pnt; }); } @@ -235,8 +253,10 @@ TEST_F(MeshLibMeshNodeSearchInSimpleQuadMesh, SurfaceSearch) mesh_node_searcher.getMeshNodeIDsAlongSurface(sfc0)); ASSERT_EQ(_quad_mesh->getNumberOfNodes(), found_ids_sfc0.size()); - for (std::size_t k(0); k<found_ids_sfc0.size(); k++) + for (std::size_t k(0); k < found_ids_sfc0.size(); k++) + { ASSERT_EQ(k, found_ids_sfc0[k]); + } // bottom half domain GeoLib::Surface sfc1(pnts); @@ -247,8 +267,10 @@ TEST_F(MeshLibMeshNodeSearchInSimpleQuadMesh, SurfaceSearch) mesh_node_searcher.getMeshNodeIDsAlongSurface(sfc1)); ASSERT_EQ(_quad_mesh->getNumberOfNodes()/2, found_ids_sfc1.size()); - for (std::size_t k(0); k<found_ids_sfc1.size(); k++) + for (std::size_t k(0); k < found_ids_sfc1.size(); k++) + { ASSERT_EQ(k, found_ids_sfc1[k]); + } std::for_each(pnts.begin(), pnts.end(), [](GeoLib::Point* pnt) { delete pnt; }); } @@ -283,8 +305,10 @@ TEST_F(MeshLibMeshNodeSearchInSimpleHexMesh, SurfaceSearch) std::vector<std::size_t> const& found_ids_sfc_b( mesh_node_searcher.getMeshNodeIDsAlongSurface(sfc_bottom)); ASSERT_EQ(n_nodes_2d, found_ids_sfc_b.size()); - for (std::size_t k(0); k<found_ids_sfc_b.size(); k++) + for (std::size_t k(0); k < found_ids_sfc_b.size(); k++) + { ASSERT_EQ(k, found_ids_sfc_b[k]); + } // top surface GeoLib::Surface sfc_top(pnts); @@ -295,8 +319,10 @@ TEST_F(MeshLibMeshNodeSearchInSimpleHexMesh, SurfaceSearch) mesh_node_searcher.getMeshNodeIDsAlongSurface(sfc_top)); ASSERT_EQ(n_nodes_2d, found_ids_sfc_t.size()); const std::size_t offset_t = n_nodes_3d - n_nodes_2d; - for (std::size_t k(0); k<found_ids_sfc_t.size(); k++) + for (std::size_t k(0); k < found_ids_sfc_t.size(); k++) + { ASSERT_EQ(offset_t + k, found_ids_sfc_t[k]); + } // front GeoLib::Surface sfc_front(pnts); @@ -308,8 +334,10 @@ TEST_F(MeshLibMeshNodeSearchInSimpleHexMesh, SurfaceSearch) ASSERT_EQ(n_nodes_2d, found_ids_sfc_f.size()); std::size_t cnt=0; for (std::size_t k(0); k<n_nodes_1d; k++) { - for (std::size_t i(0); i<n_nodes_1d; i++) - ASSERT_EQ(k*n_nodes_2d+i, found_ids_sfc_f[cnt++]); + for (std::size_t i(0); i < n_nodes_1d; i++) + { + ASSERT_EQ(k * n_nodes_2d + i, found_ids_sfc_f[cnt++]); + } } // back @@ -324,8 +352,10 @@ TEST_F(MeshLibMeshNodeSearchInSimpleHexMesh, SurfaceSearch) const std::size_t y_offset = n_nodes_1d*(n_nodes_1d-1); for (std::size_t k(0); k<n_nodes_1d; k++) { const std::size_t z_offset = n_nodes_2d*k; - for (std::size_t i(0); i<n_nodes_1d; i++) + for (std::size_t i(0); i < n_nodes_1d; i++) + { ASSERT_EQ(z_offset + y_offset + i, found_ids_sfc_back[cnt++]); + } } // left @@ -339,8 +369,10 @@ TEST_F(MeshLibMeshNodeSearchInSimpleHexMesh, SurfaceSearch) cnt = 0; for (std::size_t k(0); k<n_nodes_1d; k++) { const std::size_t z_offset = n_nodes_2d*k; - for (std::size_t j(0); j<n_nodes_1d; j++) - ASSERT_EQ(z_offset + j*n_nodes_1d, found_ids_sfc_left[cnt++]); + for (std::size_t j(0); j < n_nodes_1d; j++) + { + ASSERT_EQ(z_offset + j * n_nodes_1d, found_ids_sfc_left[cnt++]); + } } // right @@ -354,8 +386,11 @@ TEST_F(MeshLibMeshNodeSearchInSimpleHexMesh, SurfaceSearch) cnt = 0; for (std::size_t k(0); k<n_nodes_1d; k++) { const std::size_t z_offset = n_nodes_2d*k; - for (std::size_t j(0); j<n_nodes_1d; j++) - ASSERT_EQ(z_offset + (j+1)*n_nodes_1d-1, found_ids_sfc_right[cnt++]); + for (std::size_t j(0); j < n_nodes_1d; j++) + { + ASSERT_EQ(z_offset + (j + 1) * n_nodes_1d - 1, + found_ids_sfc_right[cnt++]); + } } diff --git a/Tests/MeshLib/TestMoveMeshNodes.cpp b/Tests/MeshLib/TestMoveMeshNodes.cpp index 127efff154adc5b403795e494250304d41151445..0d8d51078961a71441d054d20a67014b9bd16719 100644 --- a/Tests/MeshLib/TestMoveMeshNodes.cpp +++ b/Tests/MeshLib/TestMoveMeshNodes.cpp @@ -56,8 +56,12 @@ TEST(MeshLib, moveMeshNodes) } for (auto n : nodes) + { delete n; + } for (auto n : nodes_copy) + { delete n; + } } diff --git a/Tests/MeshLib/TestProjectMeshOnPlane.cpp b/Tests/MeshLib/TestProjectMeshOnPlane.cpp index ad351c6bea4b9b0645740d903681084d1c0ba962..d0752bc5b444b7eec37600dd7f3b753d74da33dd 100644 --- a/Tests/MeshLib/TestProjectMeshOnPlane.cpp +++ b/Tests/MeshLib/TestProjectMeshOnPlane.cpp @@ -29,12 +29,18 @@ public: { std::size_t const n_nodes (100); std::vector<MeshLib::Node*> nodes; - for (std::size_t i=1; i<=n_nodes; i++) - nodes.push_back(new MeshLib::Node(static_cast<double>(i), static_cast<double>(i), i*0.5)); + for (std::size_t i = 1; i <= n_nodes; i++) + { + nodes.push_back(new MeshLib::Node(static_cast<double>(i), + static_cast<double>(i), i * 0.5)); + } std::vector<MeshLib::Element*> elements; - for (std::size_t i=0; i<n_nodes-1; i++) - elements.push_back(new MeshLib::Line(std::array<MeshLib::Node*,2>{{nodes[i], nodes[i+1]}})); + for (std::size_t i = 0; i < n_nodes - 1; i++) + { + elements.push_back(new MeshLib::Line( + std::array<MeshLib::Node*, 2>{{nodes[i], nodes[i + 1]}})); + } _mesh = std::make_unique<MeshLib::Mesh>("TestMesh", nodes, elements); } @@ -51,8 +57,11 @@ TEST_F(ProjectionTest, ProjectToXY) { MathLib::Point3d origin (std::array<double,3>{{0,0,static_cast<double>(p)}}); MeshLib::Mesh* result = MeshLib::projectMeshOntoPlane(*_mesh, origin, normal); - for (std::size_t i=0; i<n_nodes; i++) - ASSERT_NEAR(static_cast<double>(p), (*result->getNode(i))[2], std::numeric_limits<double>::epsilon()); + for (std::size_t i = 0; i < n_nodes; i++) + { + ASSERT_NEAR(static_cast<double>(p), (*result->getNode(i))[2], + std::numeric_limits<double>::epsilon()); + } delete result; } } @@ -66,8 +75,11 @@ TEST_F(ProjectionTest, ProjectToXZ) { MathLib::Point3d origin (std::array<double,3>{{0,static_cast<double>(p),0}}); MeshLib::Mesh* result = MeshLib::projectMeshOntoPlane(*_mesh, origin, normal); - for (std::size_t i=0; i<n_nodes; i++) - ASSERT_NEAR(static_cast<double>(p), (*result->getNode(i))[1], std::numeric_limits<double>::epsilon()); + for (std::size_t i = 0; i < n_nodes; i++) + { + ASSERT_NEAR(static_cast<double>(p), (*result->getNode(i))[1], + std::numeric_limits<double>::epsilon()); + } delete result; } } @@ -81,8 +93,11 @@ TEST_F(ProjectionTest, ProjectToYZ) { MathLib::Point3d origin (std::array<double,3>{{static_cast<double>(p),0,0}}); MeshLib::Mesh* result = MeshLib::projectMeshOntoPlane(*_mesh, origin, normal); - for (std::size_t i=0; i<n_nodes; i++) - ASSERT_NEAR(static_cast<double>(p), (*result->getNode(i))[0], std::numeric_limits<double>::epsilon()); + for (std::size_t i = 0; i < n_nodes; i++) + { + ASSERT_NEAR(static_cast<double>(p), (*result->getNode(i))[0], + std::numeric_limits<double>::epsilon()); + } delete result; } } @@ -96,8 +111,10 @@ TEST_F(ProjectionTest, NormalDirection) MathLib::Point3d origin (std::array<double,3>{{0,0,0}}); MeshLib::Mesh* result_p = MeshLib::projectMeshOntoPlane(*_mesh, origin, normal_p); MeshLib::Mesh* result_n = MeshLib::projectMeshOntoPlane(*_mesh, origin, normal_n); - for (std::size_t i=0; i<n_nodes; i++) + for (std::size_t i = 0; i < n_nodes; i++) + { ASSERT_EQ((*result_p->getNode(i))[2], (*result_n->getNode(i))[2]); + } delete result_p; delete result_n; } @@ -113,8 +130,10 @@ TEST_F(ProjectionTest, NormalLength) { normal[2] = static_cast<double>(p); MeshLib::Mesh* result_p = MeshLib::projectMeshOntoPlane(*_mesh, origin, normal); - for (std::size_t i=0; i<n_nodes; i++) + for (std::size_t i = 0; i < n_nodes; i++) + { ASSERT_EQ((*result->getNode(i))[2], (*result_p->getNode(i))[2]); + } delete result_p; } delete result; diff --git a/Tests/MeshLib/TestQuadMesh.cpp b/Tests/MeshLib/TestQuadMesh.cpp index 8690389fa5a6010de08fc90e4dee7a10cc1fd7dd..357df5b6c9b811dff662b837e41177dc41cf86d3 100644 --- a/Tests/MeshLib/TestQuadMesh.cpp +++ b/Tests/MeshLib/TestQuadMesh.cpp @@ -79,16 +79,24 @@ class MeshLibQuadMesh : public ::testing::Test { // left for (std::size_t j = 1; j < elements_stride; ++j) + { f(getElement(0, j), 0, j); + } // right for (std::size_t j = 1; j < elements_stride; ++j) + { f(getElement(elements_stride, j), elements_stride, j); + } // bottom for (std::size_t i = 1; i < elements_stride; ++i) + { f(getElement(i, 0), i, 0); + } // top for (std::size_t i = 1; i < elements_stride; ++i) + { f(getElement(i, elements_stride), i, elements_stride); + } } template <typename F> @@ -96,8 +104,12 @@ class MeshLibQuadMesh : public ::testing::Test testInsideElements(F const&& f) { for (std::size_t i = 1; i < elements_stride; ++i) + { for (std::size_t j = 1; j < elements_stride; ++j) + { f(getElement(i, j), i, j); + } + } } template <typename F> @@ -105,8 +117,12 @@ class MeshLibQuadMesh : public ::testing::Test testAllElements(F const&& f) { for (std::size_t i = 0; i < elements_stride; ++i) + { for (std::size_t j = 0; j < elements_stride; ++j) + { f(getElement(i, j), i, j); + } + } } template <typename F> @@ -126,16 +142,24 @@ class MeshLibQuadMesh : public ::testing::Test { // left for (std::size_t j = 1; j < nodes_stride; ++j) + { f(getNode(0, j), 0, j); + } // right for (std::size_t j = 1; j < nodes_stride; ++j) + { f(getNode(nodes_stride, j), nodes_stride, j); + } // bottom for (std::size_t i = 1; i < nodes_stride; ++i) + { f(getNode(i, 0), i, 0); + } // top for (std::size_t i = 1; i < nodes_stride; ++i) + { f(getNode(i, nodes_stride), i, nodes_stride); + } } template <typename F> @@ -143,8 +167,12 @@ class MeshLibQuadMesh : public ::testing::Test testInsideNodes(F const&& f) { for (std::size_t i = 1; i < nodes_stride; ++i) + { for (std::size_t j = 1; j < nodes_stride; ++j) + { f(getNode(i, j), i, j); + } + } } }; @@ -171,8 +199,12 @@ TEST_F(MeshLibQuadMesh, ElementNeighbors) { unsigned count = 0; for (int i = 0; i < 4; i++) + { if (e->getNeighbor(i) != nullptr) + { count++; + } + } return count; }; @@ -181,17 +213,19 @@ TEST_F(MeshLibQuadMesh, ElementNeighbors) return std::make_pair(getNeighbor(i), getNeighbor(j)); }; - auto testNeighbors = [this]( - MeshLib::Element const* const e, - std::size_t const i, - std::size_t const j, - std::pair<Indices, Indices> const& neighbors) - { + auto testNeighbors = [this](MeshLib::Element const* const e, + std::size_t const i, + std::size_t const j, + std::pair<Indices, Indices> const& neighbors) { for (auto i_neighbor : neighbors.first) + { ASSERT_TRUE(e->hasNeighbor(getElement(i_neighbor, j))); + } for (auto j_neighbor : neighbors.second) + { ASSERT_TRUE(e->hasNeighbor(getElement(i, j_neighbor))); + } }; // Two neighbors for corner elements. @@ -268,9 +302,13 @@ TEST_F(MeshLibQuadMesh, NodeToElementConnectivity) EXPECT_EQ(1u, node->getNumberOfElements()); if (i == nodes_stride) + { i--; + } if (j == nodes_stride) + { j--; + } EXPECT_EQ(getElement(i, j), node->getElement(0)); }); diff --git a/Tests/MeshLib/TestQuadraticMesh.cpp b/Tests/MeshLib/TestQuadraticMesh.cpp index 03f1b2b42be63b3e710dd54281d7ab37be6d5762..e4d2e9545b5e46300bab610fa27b277dbd0cdea4 100644 --- a/Tests/MeshLib/TestQuadraticMesh.cpp +++ b/Tests/MeshLib/TestQuadraticMesh.cpp @@ -38,10 +38,15 @@ TEST(MeshLib, QuadraticOrderMesh_Line) ASSERT_EQ(2u, e->getNumberOfBaseNodes()); ASSERT_EQ(3u, e->getNumberOfNodes()); - for (unsigned i=0; i<e->getNumberOfBaseNodes(); i++) + for (unsigned i = 0; i < e->getNumberOfBaseNodes(); i++) + { ASSERT_TRUE(mesh->isBaseNode(e->getNodeIndex(i))); - for (unsigned i=e->getNumberOfBaseNodes(); i<e->getNumberOfNodes(); i++) + } + for (unsigned i = e->getNumberOfBaseNodes(); i < e->getNumberOfNodes(); + i++) + { ASSERT_FALSE(mesh->isBaseNode(e->getNodeIndex(i))); + } } for (MeshLib::Node const* node : mesh->getNodes()) @@ -76,10 +81,15 @@ TEST(MeshLib, QuadraticOrderMesh_Quad) ASSERT_EQ(4u, e->getNumberOfBaseNodes()); ASSERT_EQ(8u, e->getNumberOfNodes()); - for (unsigned i=0; i<e->getNumberOfBaseNodes(); i++) + for (unsigned i = 0; i < e->getNumberOfBaseNodes(); i++) + { ASSERT_TRUE(mesh->isBaseNode(e->getNodeIndex(i))); - for (unsigned i=e->getNumberOfBaseNodes(); i<e->getNumberOfNodes(); i++) + } + for (unsigned i = e->getNumberOfBaseNodes(); i < e->getNumberOfNodes(); + i++) + { ASSERT_FALSE(mesh->isBaseNode(e->getNodeIndex(i))); + } } auto const& mesh_nodes = mesh->getNodes(); @@ -131,7 +141,9 @@ TEST(MeshLib, QuadraticOrderMesh_LineQuad) linear_mesh = MeshGeoToolsLib::appendLinesAlongPolylines(*linear_quad_mesh.get(), ply_vec); for (auto p : pnts) + { delete p; + } } ASSERT_EQ(6u, linear_mesh->getNumberOfElements()); @@ -155,10 +167,15 @@ TEST(MeshLib, QuadraticOrderMesh_LineQuad) ASSERT_EQ(3u, e->getNumberOfNodes()); } - for (unsigned i=0; i<e->getNumberOfBaseNodes(); i++) + for (unsigned i = 0; i < e->getNumberOfBaseNodes(); i++) + { ASSERT_TRUE(mesh->isBaseNode(e->getNodeIndex(i))); - for (unsigned i=e->getNumberOfBaseNodes(); i<e->getNumberOfNodes(); i++) + } + for (unsigned i = e->getNumberOfBaseNodes(); i < e->getNumberOfNodes(); + i++) + { ASSERT_FALSE(mesh->isBaseNode(e->getNodeIndex(i))); + } } auto const& mesh_nodes = mesh->getNodes(); diff --git a/Tests/MeshLib/TestRasterToMesh.cpp b/Tests/MeshLib/TestRasterToMesh.cpp index 43c0e55a564406899edbf53d2980de3b4c07c588..376530b3a78ab142bd8f1cce643f3f71746e318b 100644 --- a/Tests/MeshLib/TestRasterToMesh.cpp +++ b/Tests/MeshLib/TestRasterToMesh.cpp @@ -140,7 +140,9 @@ TEST_F(RasterToMeshTest, convertRasterToTriMeshValue) std::vector<MeshLib::Node*> const& nodes = mesh->getNodes(); for (MeshLib::Node* n : nodes) + { ASSERT_NEAR(0, (*n)[2], std::numeric_limits<double>::epsilon()); + } std::array<unsigned, 7> n_types = MeshLib::MeshInformation::getNumberOfElementTypes(*mesh); @@ -171,7 +173,9 @@ TEST_F(RasterToMeshTest, convertRasterToQuadMeshValue) std::vector<MeshLib::Node*> const& nodes = mesh->getNodes(); for (MeshLib::Node* n : nodes) + { ASSERT_TRUE((*n)[2] == 0); + } std::array<unsigned, 7> n_types = MeshLib::MeshInformation::getNumberOfElementTypes(*mesh); @@ -202,7 +206,9 @@ TEST_F(RasterToMeshTest, convertRasterToPrismMeshValue) std::vector<MeshLib::Node*> const& nodes = mesh->getNodes(); for (MeshLib::Node* n : nodes) + { ASSERT_TRUE(((*n)[2] == 0) || ((*n)[2] == _spacing)); + } std::array<unsigned, 7> n_types = MeshLib::MeshInformation::getNumberOfElementTypes(*mesh); @@ -233,7 +239,9 @@ TEST_F(RasterToMeshTest, convertRasterToHexMeshValue) std::vector<MeshLib::Node*> const& nodes = mesh->getNodes(); for (MeshLib::Node* n : nodes) + { ASSERT_TRUE(((*n)[2] == 0) || ((*n)[2] == _spacing)); + } std::array<unsigned, 7> n_types = MeshLib::MeshInformation::getNumberOfElementTypes(*mesh); @@ -255,7 +263,9 @@ TEST_F(RasterToMeshTest, convertRasterToQuadMeshNone) std::vector<MeshLib::Node*> const& nodes = mesh->getNodes(); for (MeshLib::Node* n : nodes) + { ASSERT_TRUE((*n)[2] == 0); + } std::array<unsigned, 7> n_types = MeshLib::MeshInformation::getNumberOfElementTypes(*mesh); diff --git a/Tests/MeshLib/TestRemove.cpp b/Tests/MeshLib/TestRemove.cpp index 7f1b0aed921476a4aea9aa21784109b8b3b37f45..a28a0bbe0d90cdd4845a1250039abfe34b3c2c44 100644 --- a/Tests/MeshLib/TestRemove.cpp +++ b/Tests/MeshLib/TestRemove.cpp @@ -30,8 +30,10 @@ TEST(MeshLib, RemoveNodes) MeshLib::MeshGenerator::generateLineMesh(1.0, 9)}; std::vector<std::size_t> removed_node_ids; - for (std::size_t i=0; i<5; i++) + for (std::size_t i = 0; i < 5; i++) + { removed_node_ids.push_back(i); + } auto new_mesh = std::unique_ptr<MeshLib::Mesh>{ MeshLib::removeNodes(*mesh, removed_node_ids, "")}; @@ -39,8 +41,10 @@ TEST(MeshLib, RemoveNodes) ASSERT_EQ(5u, new_mesh->getNumberOfNodes()); ASSERT_EQ(5u, new_mesh->getNumberOfBaseNodes()); ASSERT_EQ(4u, new_mesh->getNumberOfElements()); - for (std::size_t i=0; i<new_mesh->getNumberOfNodes(); i++) - ASSERT_TRUE(*mesh->getNode(5+i) == *new_mesh->getNode(i)); + for (std::size_t i = 0; i < new_mesh->getNumberOfNodes(); i++) + { + ASSERT_TRUE(*mesh->getNode(5 + i) == *new_mesh->getNode(i)); + } } TEST(MeshLib, RemoveElements) @@ -49,8 +53,10 @@ TEST(MeshLib, RemoveElements) MeshLib::MeshGenerator::generateLineMesh(1.0, 9)}; std::vector<std::size_t> removed_ele_ids; - for (std::size_t i=0; i<5; i++) + for (std::size_t i = 0; i < 5; i++) + { removed_ele_ids.push_back(i); + } auto new_mesh = std::unique_ptr<MeshLib::Mesh>{ MeshLib::removeElements(*mesh, removed_ele_ids, "")}; @@ -58,6 +64,8 @@ TEST(MeshLib, RemoveElements) ASSERT_EQ(5u, new_mesh->getNumberOfNodes()); ASSERT_EQ(5u, new_mesh->getNumberOfBaseNodes()); ASSERT_EQ(4u, new_mesh->getNumberOfElements()); - for (std::size_t i=0; i<new_mesh->getNumberOfNodes(); i++) - ASSERT_TRUE(*mesh->getNode(5+i) == *new_mesh->getNode(i)); + for (std::size_t i = 0; i < new_mesh->getNumberOfNodes(); i++) + { + ASSERT_TRUE(*mesh->getNode(5 + i) == *new_mesh->getNode(i)); + } } diff --git a/Tests/MeshLib/TestVtkMappedMeshSource.cpp b/Tests/MeshLib/TestVtkMappedMeshSource.cpp index 217bf031e50f59532114dc7c2ead283adbebb546..bde8caac0460b16bbbce316de5606add2570941e 100644 --- a/Tests/MeshLib/TestVtkMappedMeshSource.cpp +++ b/Tests/MeshLib/TestVtkMappedMeshSource.cpp @@ -239,8 +239,10 @@ TEST_F(InSituMesh, DISABLED_MappedMeshSourceRoundtrip) { for(bool compressed : { true, false }) { - if(dataMode == vtkXMLWriter::Ascii && compressed) + if (dataMode == vtkXMLWriter::Ascii && compressed) + { continue; + } MeshLib::IO::VtuInterface vtuInterface(mesh, dataMode, compressed); ASSERT_TRUE(vtuInterface.writeToFile(test_data_file)); @@ -327,7 +329,9 @@ TEST_F(InSituMesh, DISABLED_MappedMeshSourceRoundtrip) doubleProps->getNumberOfTuples()); ASSERT_EQ(newDoubleProps->size(), doubleProps->size()); for (std::size_t i = 0; i < doubleProps->size(); i++) + { ASSERT_EQ((*newDoubleProps)[i], (*doubleProps)[i]); + } auto unsignedProps = meshProperties.getPropertyVector<unsigned>( "CellUnsignedProperty"); @@ -340,7 +344,9 @@ TEST_F(InSituMesh, DISABLED_MappedMeshSourceRoundtrip) unsignedProps->getNumberOfTuples()); ASSERT_EQ(newUnsignedIds->size(), unsignedProps->size()); for (std::size_t i = 0; i < unsignedProps->size(); i++) + { ASSERT_EQ((*newUnsignedIds)[i], (*unsignedProps)[i]); + } { // Field data auto p = @@ -353,7 +359,9 @@ TEST_F(InSituMesh, DISABLED_MappedMeshSourceRoundtrip) ASSERT_EQ(new_p->getNumberOfTuples(), p->getNumberOfTuples()); ASSERT_EQ(new_p->size(), p->size()); for (std::size_t i = 0; i < unsignedProps->size(); i++) + { ASSERT_EQ((*newUnsignedIds)[i], (*unsignedProps)[i]); + } } auto const* const materialIds = @@ -366,7 +374,9 @@ TEST_F(InSituMesh, DISABLED_MappedMeshSourceRoundtrip) materialIds->getNumberOfTuples()); ASSERT_EQ(newMaterialIds->size(), materialIds->size()); for (std::size_t i = 0; i < materialIds->size(); i++) + { ASSERT_EQ((*newMaterialIds)[i], (*materialIds)[i]); + } } } } diff --git a/Tests/MeshLib/TestVtkMeshConverter.cpp b/Tests/MeshLib/TestVtkMeshConverter.cpp index abeab5b2ae7cf862c84a0782571234268a7dd430..2e7c455c3c5e5ffb5dbca9d8153700089081796b 100644 --- a/Tests/MeshLib/TestVtkMeshConverter.cpp +++ b/Tests/MeshLib/TestVtkMeshConverter.cpp @@ -76,7 +76,9 @@ public: pointIds->SetNumberOfComponents(1); pointIds->SetName("PointIDs"); for (int i = 0; i < 12; ++i) + { pointIds->InsertNextTuple1(i); + } vtu->GetPointData()->AddArray(pointIds); auto materialIds = vtkSmartPointer<vtkUnsignedIntArray>::New(); @@ -107,6 +109,8 @@ TEST_F(TestVtkMeshConverter, Conversion) ASSERT_NE(nullptr, materialIds); auto vtkMaterialIds = vtu->GetCellData()->GetArray("MaterialIDs"); ASSERT_EQ(materialIds->size(), vtkMaterialIds->GetNumberOfTuples()); - for(std::size_t i = 0; i < materialIds->size(); i++) + for (std::size_t i = 0; i < materialIds->size(); i++) + { ASSERT_EQ((*materialIds)[i], vtkMaterialIds->GetTuple1(i)); + } } diff --git a/Tests/NumLib/LocalToGlobalIndexMap.cpp b/Tests/NumLib/LocalToGlobalIndexMap.cpp index a23299869cb6a56ff7929a59fc17ce4362364491..399f728280a55db33bb3ffe78c1b3d4341b39587 100644 --- a/Tests/NumLib/LocalToGlobalIndexMap.cpp +++ b/Tests/NumLib/LocalToGlobalIndexMap.cpp @@ -96,7 +96,9 @@ TEST_F(NumLibLocalToGlobalIndexMapTest, DISABLED_SubsetByComponent) std::array<std::size_t, 3> const ids = {{ 0, 5, 8 }}; std::vector<MeshLib::Element*> some_elements; for (std::size_t id : ids) + { some_elements.push_back(mesh->getElement(id)->clone()); + } auto boundary_mesh = MeshLib::createMeshFromElementSelection("boundary_mesh", some_elements); diff --git a/Tests/NumLib/LocalToGlobalIndexMapMultiComponent.cpp b/Tests/NumLib/LocalToGlobalIndexMapMultiComponent.cpp index 28b2d9e844db1aee2066c39da0080c2f0b85d5b0..a3f8c73a64712c376180fe01631b04c358b49fac 100644 --- a/Tests/NumLib/LocalToGlobalIndexMapMultiComponent.cpp +++ b/Tests/NumLib/LocalToGlobalIndexMapMultiComponent.cpp @@ -337,9 +337,12 @@ TEST_F(NumLibLocalToGlobalIndexMapMultiDOFTest, DISABLED_TestMultiCompByComponen { int const num_components = 5; for (int c = 0; c < num_components; ++c) + { test<NL::ComponentOrder::BY_COMPONENT>( - num_components, c, ComputeGlobalIndexByComponent{ - (mesh_subdivs + 1) * (mesh_subdivs + 1)}); + num_components, c, + ComputeGlobalIndexByComponent{(mesh_subdivs + 1) * + (mesh_subdivs + 1)}); + } } #ifndef USE_PETSC @@ -350,8 +353,10 @@ TEST_F(NumLibLocalToGlobalIndexMapMultiDOFTest, DISABLED_TestMultiCompByLocation { int const num_components = 5; for (int c = 0; c < num_components; ++c) + { test<NL::ComponentOrder::BY_LOCATION>( num_components, c, ComputeGlobalIndexByLocation{num_components}); + } } #ifndef USE_PETSC diff --git a/Tests/NumLib/SteadyDiffusion2DExample1.h b/Tests/NumLib/SteadyDiffusion2DExample1.h index 2b0b828aee6f0d0dde3f3bbcf81a3057faad0047..d8f91bc10ed87b0f43055d9a7807c700c825ac7f 100644 --- a/Tests/NumLib/SteadyDiffusion2DExample1.h +++ b/Tests/NumLib/SteadyDiffusion2DExample1.h @@ -89,7 +89,9 @@ template<typename IndexType>struct SteadyDiffusion2DExample1 { msh = MeshLib::MeshGenerator::generateRegularQuadMesh(2.0, mesh_subdivs); for (auto* node : msh->getNodes()) + { vec_nodeIDs.push_back(node->getID()); + } vec_DirichletBC_id.resize(2 * mesh_stride); for (std::size_t i = 0; i < mesh_stride; i++) { @@ -109,17 +111,27 @@ template<typename IndexType>struct SteadyDiffusion2DExample1 // copy upper triangle to lower to localA for symmetry for (std::size_t i = 0; i < 4; i++) + { for (std::size_t j = 0; j < i; j++) - _localA(i,j) = _localA(j,i); + { + _localA(i, j) = _localA(j, i); + } + } //_localA *= 1.e-11/6.0; for (std::size_t i = 0; i < 4; i++) + { for (std::size_t j = 0; j < 4; j++) - _localA(i,j) *= 1.e-11 / 6.0; + { + _localA(i, j) *= 1.e-11 / 6.0; + } + } // Fill rhs with zero; for (std::size_t i = 0; i < 4; i++) + { _localRhs[i] = 0; + } } vec_DirichletBC_value.resize(2 * mesh_stride); @@ -127,8 +139,12 @@ template<typename IndexType>struct SteadyDiffusion2DExample1 std::fill_n(vec_DirichletBC_value.begin() + mesh_stride, mesh_stride, 1); exact_solutions.resize(dim_eqs); for (std::size_t i = 0; i < mesh_stride; i++) + { for (std::size_t j = 0; j < mesh_stride; j++) - exact_solutions[i*mesh_stride + j] = j * 1./mesh_subdivs; + { + exact_solutions[i * mesh_stride + j] = j * 1. / mesh_subdivs; + } + } } ~SteadyDiffusion2DExample1() diff --git a/Tests/NumLib/TestComponentNorms.cpp b/Tests/NumLib/TestComponentNorms.cpp index 0e8a15d45abc2a44d96e2d6c6381621c6beb33ff..d6d1c30223a48e554730dcef3fc64452676e6a8e 100644 --- a/Tests/NumLib/TestComponentNorms.cpp +++ b/Tests/NumLib/TestComponentNorms.cpp @@ -31,8 +31,10 @@ static std::vector<MeshLib::MeshSubset> createMeshSubsets( MeshLib::MeshSubset const& mesh_subset, unsigned const num_components) { std::vector<MeshLib::MeshSubset> mesh_subsets; - for (unsigned i=0; i<num_components; ++i) + for (unsigned i = 0; i < num_components; ++i) + { mesh_subsets.emplace_back(mesh_subset); + } return mesh_subsets; } diff --git a/Tests/NumLib/TestCoordinatesMapping.cpp b/Tests/NumLib/TestCoordinatesMapping.cpp index a6e9734eb51fc92ae52a613e4e6e0a619c8cec47..ab90bfc1b1f54be39d214b6e9f8f639561efadc3 100644 --- a/Tests/NumLib/TestCoordinatesMapping.cpp +++ b/Tests/NumLib/TestCoordinatesMapping.cpp @@ -77,16 +77,24 @@ public: vec_eles.push_back(clockwiseEle); vec_eles.push_back(zeroVolumeEle); for (auto e : vec_eles) + { for (unsigned i = 0; i < e->getNumberOfNodes(); i++) + { vec_nodes.push_back(e->getNode(i)); + } + } } ~NumLibFemNaturalCoordinatesMappingTest() override { for (auto itr = vec_nodes.begin(); itr != vec_nodes.end(); ++itr) + { delete *itr; + } for (auto itr = vec_eles.begin(); itr != vec_eles.end(); ++itr) + { delete *itr; + } } const double eps; @@ -227,7 +235,9 @@ TYPED_TEST(NumLibFemNaturalCoordinatesMappingTest, CheckNaturalShape) shape, this->global_dim); double exp_J[TestFixture::dim * TestFixture::dim] = {0.0}; for (unsigned i = 0; i < this->dim; i++) + { exp_J[i + this->dim * i] = 1.0; + } ASSERT_ARRAY_NEAR(this->nat_exp_N, shape.N.data(), shape.N.size(), this->eps); @@ -310,7 +320,9 @@ TEST(NumLib, FemNaturalCoordinatesMappingLineY) double exp_J[dim * dim] = {0.0}; for (unsigned i = 0; i < dim; i++) + { exp_J[i + dim * i] = 1.0; + } const double eps(std::numeric_limits<double>::epsilon()); ASSERT_ARRAY_NEAR(TestLine2::nat_exp_N, shape.N.data(), shape.N.size(), @@ -324,6 +336,8 @@ TEST(NumLib, FemNaturalCoordinatesMappingLineY) ASSERT_ARRAY_NEAR(exp_dNdx, shape.dNdx.data(), shape.dNdx.size(), eps); for (auto n = 0u; n < line->getNumberOfNodes(); ++n) + { delete line->getNode(n); + } delete line; } diff --git a/Tests/NumLib/TestExtrapolation.cpp b/Tests/NumLib/TestExtrapolation.cpp index 0f61a9e4c567f0807e6f45b1f7c2b386a442228a..0d247a0be1258634865133d04541e9b3e781fa37 100644 --- a/Tests/NumLib/TestExtrapolation.cpp +++ b/Tests/NumLib/TestExtrapolation.cpp @@ -120,7 +120,9 @@ public: { cache.clear(); for (auto value : _int_pt_values) + { cache.push_back(2.0 * value); + } return cache; } diff --git a/Tests/NumLib/TestFe.cpp b/Tests/NumLib/TestFe.cpp index 130da6f5dfd7b23bb22cb7d573537e950e3278e9..2d5351dffcd91c2b3e39673758ed8127a7ab446a 100644 --- a/Tests/NumLib/TestFe.cpp +++ b/Tests/NumLib/TestFe.cpp @@ -131,16 +131,24 @@ class NumLibFemIsoTest : public ::testing::Test, public T::TestFeType // for destructor vec_eles.push_back(mesh_element); for (auto e : vec_eles) + { for (unsigned i = 0; i < e->getNumberOfNodes(); i++) + { vec_nodes.push_back(e->getNode(i)); + } + } } ~NumLibFemIsoTest() override { for (auto itr = vec_nodes.begin(); itr != vec_nodes.end(); ++itr) + { delete *itr; + } for (auto itr = vec_eles.begin(); itr != vec_eles.end(); ++itr) + { delete *itr; + } } diff --git a/Tests/NumLib/TestGradShapeFunction.cpp b/Tests/NumLib/TestGradShapeFunction.cpp index a59f0c8cbd155b44a7e66650f0f300fc187c9a27..d05d1dbb4e7eb7f814b4cb52182fc696485969b8 100644 --- a/Tests/NumLib/TestGradShapeFunction.cpp +++ b/Tests/NumLib/TestGradShapeFunction.cpp @@ -134,16 +134,24 @@ public: // only for destructor because class element has nodes in pointer type. vec_eles.push_back(mesh_element); for (auto e : vec_eles) + { for (unsigned i = 0; i < e->getNumberOfNodes(); i++) + { vec_nodes.push_back(e->getNode(i)); + } + } } ~GradShapeFunctionTest() override { for (auto itr = vec_nodes.begin(); itr != vec_nodes.end(); ++itr) + { delete *itr; + } for (auto itr = vec_eles.begin(); itr != vec_eles.end(); ++itr) + { delete *itr; + } } IntegrationMethod integration_method; diff --git a/Tests/NumLib/TestMeshComponentMap.cpp b/Tests/NumLib/TestMeshComponentMap.cpp index 37b0ef185930ddcf2df683cf4a2c3e3ffddc8efc..3fdcd6f7a741e7b97b2d696c74e3cf9a326e6b1c 100644 --- a/Tests/NumLib/TestMeshComponentMap.cpp +++ b/Tests/NumLib/TestMeshComponentMap.cpp @@ -267,8 +267,10 @@ TEST_F(NumLibMeshComponentMapTest, DISABLED_MulticomponentVariable) Location const l_boundary(boundary_mesh.getID(), MeshItemType::Node, id); for (auto const& c : selected_component_ids) + { EXPECT_EQ(cmap->getGlobalIndex(l_bulk, c), cmap_subset.getGlobalIndex(l_boundary, c)); + } } } @@ -307,7 +309,9 @@ TEST_F(NumLibMeshComponentMapTest, Location const l_boundary(boundary_mesh.getID(), MeshItemType::Node, id); for (auto const& c : selected_component_ids) + { EXPECT_EQ(cmap->getGlobalIndex(l_bulk, c), cmap_subset.getGlobalIndex(l_boundary, c)); + } } } diff --git a/Tests/NumLib/TestODEInt.cpp b/Tests/NumLib/TestODEInt.cpp index bc79134f9bbcbaba3ad222ad8539770f9db95777..335b5faca35f32bf110429373f3e7cb5fca2a28f 100644 --- a/Tests/NumLib/TestODEInt.cpp +++ b/Tests/NumLib/TestODEInt.cpp @@ -107,8 +107,10 @@ public: EXPECT_TRUE(loop.loop(t0, x0, t_end, delta_t, cb).error_norms_met); } - for (auto& x : sol.solutions) + for (auto& x : sol.solutions) + { MathLib::LinAlg::setLocalAccessibleVector(x); + } return sol; } diff --git a/Tests/NumLib/TestSerialExecutor.cpp b/Tests/NumLib/TestSerialExecutor.cpp index c54aa0500984dbd9fb5b23754cbe88faa0a24123..f231c353a134d9825dd1b17f62d91e238ddc0d3d 100644 --- a/Tests/NumLib/TestSerialExecutor.cpp +++ b/Tests/NumLib/TestSerialExecutor.cpp @@ -33,7 +33,10 @@ public: PtrContainer container; container.reserve(size); - for (auto& el : container_back) container.push_back(&el); + for (auto& el : container_back) + { + container.push_back(&el); + } cb(container, reference); diff --git a/Tests/NumLib/TestSerialLinearSolver.cpp b/Tests/NumLib/TestSerialLinearSolver.cpp index bdf3425d49d77686db7aa758aade0cc590ea1145..8b1bf6a737f8adc96d39083ba175178f06500847 100644 --- a/Tests/NumLib/TestSerialLinearSolver.cpp +++ b/Tests/NumLib/TestSerialLinearSolver.cpp @@ -139,10 +139,14 @@ TEST(NumLibSerialLinearSolver, Steady2DdiffusionQuadElem) // copy solution to double vector std::vector<double> solution(x->size()); for (GlobalIndexType i = 0; i < x->size(); ++i) + { solution[i] = (*x)[i]; + } ASSERT_ARRAY_NEAR(&ex1.exact_solutions[0], &solution[0], ex1.dim_eqs, 1.e-5); for (auto p : local_assemblers) + { delete p; + } } diff --git a/Tests/NumLib/TestShapeFunctions.cpp b/Tests/NumLib/TestShapeFunctions.cpp index 029b09b3b9808c3bc4fcd539c91b53bcc80adde2..9aff183d2e12a098c4ec00d52f366de739384e79 100644 --- a/Tests/NumLib/TestShapeFunctions.cpp +++ b/Tests/NumLib/TestShapeFunctions.cpp @@ -52,7 +52,9 @@ struct NaturalPointGenerator std::is_same<ShapeFunction, NumLib::ShapeQuad9>::value || std::is_same<ShapeFunction, NumLib::ShapeHex8>::value || std::is_same<ShapeFunction, NumLib::ShapeHex20>::value) + { return tuple; + } if (std::is_same<ShapeFunction, NumLib::ShapeTri3>::value || std::is_same<ShapeFunction, NumLib::ShapeTri6>::value || std::is_same<ShapeFunction, NumLib::ShapeTet4>::value || @@ -69,9 +71,11 @@ struct NaturalPointGenerator if (std::accumulate(std::begin(mapped_tuple), std::end(mapped_tuple), 0.) > ShapeFunction::DIM / 2.) + { std::transform(std::begin(mapped_tuple), std::end(mapped_tuple), std::begin(mapped_tuple), [](double const& v) { return 1. - v; }); + } return mapped_tuple; } OGS_FATAL("NaturalPointGenerator: Unknown shape function type."); diff --git a/Tests/NumLib/TestSpatialFunction.cpp b/Tests/NumLib/TestSpatialFunction.cpp index 8aeb8e77c79f67e09e9e9381b292944ac0cdd15d..5307bd20373ecc43c3ab994ac0a5b000cdbcd746 100644 --- a/Tests/NumLib/TestSpatialFunction.cpp +++ b/Tests/NumLib/TestSpatialFunction.cpp @@ -36,7 +36,9 @@ TEST(NumLib, SpatialFunctionLinear) { GeoLib::Point pt(0, 0, 0); for (unsigned i = 0; i < 3; ++i) - pt[i] = (double) rand() - (RAND_MAX / 2.0); + { + pt[i] = (double)rand() - (RAND_MAX / 2.0); + } double expected = 1+2*pt[0]+3*pt[1]+4*pt[2]; ASSERT_DOUBLE_EQ(expected, f(pt)); } @@ -59,8 +61,10 @@ TEST(NumLib, SpatialFunctionInterpolationPolyline) ply0, vec_point_ids, vec_point_values, std::numeric_limits<double>::epsilon(), std::numeric_limits<double>::max()); // normal - for (unsigned k=0; k<10; k++) - ASSERT_DOUBLE_EQ(k*10., interpolate(GeoLib::Point(k,0,0))); + for (unsigned k = 0; k < 10; k++) + { + ASSERT_DOUBLE_EQ(k * 10., interpolate(GeoLib::Point(k, 0, 0))); + } // failure // x diff --git a/Tests/NumLib/TimeLoopSingleODE.h b/Tests/NumLib/TimeLoopSingleODE.h index 5b370a6feb50faba7c7ee56c7880ef17d6a88dbf..55bac5c8f669b95a187c2cffa4cc7e0e37e23f60 100644 --- a/Tests/NumLib/TimeLoopSingleODE.h +++ b/Tests/NumLib/TimeLoopSingleODE.h @@ -115,7 +115,9 @@ NumLib::NonlinearSolverStatus TimeLoopSingleODE<NLTag>::loop( nonlinear_solver_status = _nonlinear_solver->solve(x, nullptr); if (!nonlinear_solver_status.error_norms_met) + { break; + } time_disc.pushState(t, x, _ode_sys); diff --git a/Tests/NumLib/TimeSteppingTestingTools.h b/Tests/NumLib/TimeSteppingTestingTools.h index b499a760d421618391ea6c68b107f0498533bb47..1dd7982d4c3785209cbbe72872dd60b5bb238e10 100644 --- a/Tests/NumLib/TimeSteppingTestingTools.h +++ b/Tests/NumLib/TimeSteppingTestingTools.h @@ -44,7 +44,9 @@ std::vector<double> timeStepping(T_TIME_STEPPING& algorithm, NumLib::TimeStep t = algorithm.getTimeStep(); //INFO("t: n=%d,t=%g,dt=%g", t.steps(), t.current(), t.dt()); if (obj) - (*obj)(algorithm); // do something + { + (*obj)(algorithm); // do something + } if (algorithm.accepted()) { vec_t.push_back(t.current()); } else { diff --git a/Tests/ProcessLib/LIE/TestLIE.cpp b/Tests/ProcessLib/LIE/TestLIE.cpp index d27edb01f688f07ff5d5b835a71bf0976c26d875..ec8e8b7bb616f3ecbcfec59f838a92e366414eb0 100644 --- a/Tests/ProcessLib/LIE/TestLIE.cpp +++ b/Tests/ProcessLib/LIE/TestLIE.cpp @@ -28,7 +28,9 @@ std::unique_ptr<MeshLib::Mesh> createTriangle( { auto** nodes = new MeshLib::Node*[3]; for (std::size_t i = 0; i < points.size(); ++i) + { nodes[i] = new MeshLib::Node(points[i]); + } MeshLib::Element* e = new MeshLib::Tri(nodes); return std::make_unique<MeshLib::Mesh>( @@ -41,7 +43,9 @@ std::unique_ptr<MeshLib::Mesh> createLine( { auto** nodes = new MeshLib::Node*[2]; for (std::size_t i = 0; i < points.size(); ++i) + { nodes[i] = new MeshLib::Node(points[i]); + } MeshLib::Element* e = new MeshLib::Line(nodes); return std::make_unique<MeshLib::Mesh>( diff --git a/Tests/ProcessLib/TestJacobianAssembler.cpp b/Tests/ProcessLib/TestJacobianAssembler.cpp index bb98764cc165f7d991eb33d56babb0d719f11fc0..9b63e22baedb49a870ee050bb402b7d37ddbce5c 100644 --- a/Tests/ProcessLib/TestJacobianAssembler.cpp +++ b/Tests/ProcessLib/TestJacobianAssembler.cpp @@ -168,8 +168,10 @@ struct MatDiagXSquared auto mat = MathLib::createZeroedMatrix(mat_data, x_data.size(), x_data.size()); - for (std::size_t i=0; i<x_data.size(); ++i) + for (std::size_t i = 0; i < x_data.size(); ++i) + { mat(i, i) = x_data[i] * x_data[i]; + } } // dM/dx * y = diag(2*x*X, 2*y*Y, 2*z*Z, ...) @@ -180,8 +182,10 @@ struct MatDiagXSquared auto dMdxTy = MathLib::createZeroedMatrix(dMdxTy_data, x_data.size(), x_data.size()); - for (std::size_t i=0; i<x_data.size(); ++i) + for (std::size_t i = 0; i < x_data.size(); ++i) + { dMdxTy(i, i) = 2.0 * x_data[i] * y_data[i]; + } } }; @@ -193,7 +197,9 @@ struct VecXSquared { vec_data = x_data; for (auto& v : vec_data) + { v *= v; + } } // dv/dx = diag(2x, 2y, 2z, ...) @@ -521,22 +527,28 @@ private: if (LocAsm::asmM) { ASSERT_EQ(x.size()*x.size(), M_data_cd.size()); ASSERT_EQ(x.size()*x.size(), M_data_ana.size()); - for (std::size_t i=0; i<x.size()*x.size(); ++i) + for (std::size_t i = 0; i < x.size() * x.size(); ++i) + { EXPECT_NEAR(M_data_ana[i], M_data_cd[i], eps); + } } if (LocAsm::asmK) { ASSERT_EQ(x.size()*x.size(), K_data_cd.size()); ASSERT_EQ(x.size()*x.size(), K_data_ana.size()); - for (std::size_t i=0; i<x.size()*x.size(); ++i) + for (std::size_t i = 0; i < x.size() * x.size(); ++i) + { EXPECT_NEAR(K_data_ana[i], K_data_cd[i], eps); + } } if (LocAsm::asmb) { ASSERT_EQ(x.size(), b_data_cd.size()); ASSERT_EQ(x.size(), b_data_ana.size()); - for (std::size_t i=0; i<x.size(); ++i) + for (std::size_t i = 0; i < x.size(); ++i) + { EXPECT_NEAR(b_data_ana[i], b_data_cd[i], eps); + } } ASSERT_EQ(x.size()*x.size(), Jac_data_cd.size()); diff --git a/Tests/testrunner.cpp b/Tests/testrunner.cpp index 55f70ce13860237383d24b1e3d9d4069446cd066..8ea08406c875fe3fbbce36dabcc969cc159da80e 100644 --- a/Tests/testrunner.cpp +++ b/Tests/testrunner.cpp @@ -37,10 +37,14 @@ int main(int argc, char* argv[]) #endif for (int i = 1; i < argc; i++) { - if(i + 1 == argc) + if (i + 1 == argc) + { break; - if(std::strcmp(argv[i], "-l") == 0) + } + if (std::strcmp(argv[i], "-l") == 0) + { logLevel = argv[i + 1]; + } } setlocale(LC_ALL, "C");