diff --git a/Applications/DataExplorer/DataView/GMSHPrefsDialog.cpp b/Applications/DataExplorer/DataView/GMSHPrefsDialog.cpp index 88b2f6d32f9e11a14b19e29751fa3c318ffd4b3d..17798f71a7e5ba473aedf0b00c16a1c9a6e28848 100644 --- a/Applications/DataExplorer/DataView/GMSHPrefsDialog.cpp +++ b/Applications/DataExplorer/DataView/GMSHPrefsDialog.cpp @@ -50,8 +50,7 @@ GMSHPrefsDialog::GMSHPrefsDialog(GeoLib::GEOObjects const& geoObjects, QDialog* new StrictDoubleValidator(0, 1, 5, this->param3)); param3->setValidator (mesh_density_scaling_stations_validator); - std::vector<std::string> geoNames; - geoObjects.getGeometryNames(geoNames); + auto geoNames = geoObjects.getGeometryNames(); // get station names std::vector<std::string> geo_station_names; diff --git a/Applications/DataExplorer/DataView/MergeGeometriesDialog.cpp b/Applications/DataExplorer/DataView/MergeGeometriesDialog.cpp index 1b180cd56354cc16c2e1b056dc184dd87b3cad0e..e146d9ce294ff71049c75b955c950d16b9d4df26 100644 --- a/Applications/DataExplorer/DataView/MergeGeometriesDialog.cpp +++ b/Applications/DataExplorer/DataView/MergeGeometriesDialog.cpp @@ -25,8 +25,7 @@ MergeGeometriesDialog::MergeGeometriesDialog(GeoLib::GEOObjects& geoObjects, QDi { setupUi(this); - std::vector<std::string> geoNames; - _geo_objects.getGeometryNames(geoNames); + auto const geoNames = _geo_objects.getGeometryNames(); // get station names std::vector<std::string> geo_station_names; diff --git a/Applications/DataExplorer/mainwindow.cpp b/Applications/DataExplorer/mainwindow.cpp index 6e2f36965993c8a99571531c1951011d871da563..ec1fb1eb6bb9f5ba3e318d2c9c7fe569ed5ac2b0 100644 --- a/Applications/DataExplorer/mainwindow.cpp +++ b/Applications/DataExplorer/mainwindow.cpp @@ -482,8 +482,8 @@ void MainWindow::save() } else if (fi.suffix().toLower() == "geo") { - std::vector<std::string> selected_geometries; - _project.getGEOObjects().getGeometryNames(selected_geometries); + auto const selected_geometries = + _project.getGEOObjects().getGeometryNames(); // values necessary also for the adaptive meshing const double point_density = 0; diff --git a/Applications/FileIO/Legacy/OGSIOVer4.cpp b/Applications/FileIO/Legacy/OGSIOVer4.cpp index 8df74e50c739cd43156b9a5f1b3596549591ac79..fe18152109faaa661fceb590f5801430a69dc2d1 100644 --- a/Applications/FileIO/Legacy/OGSIOVer4.cpp +++ b/Applications/FileIO/Legacy/OGSIOVer4.cpp @@ -671,8 +671,7 @@ void writeGLIFileV4 (const std::string& fname, void writeAllDataToGLIFileV4 (const std::string& fname, const GeoLib::GEOObjects& geo) { - std::vector<std::string> geo_names; - geo.getGeometryNames (geo_names); + auto const geo_names = geo.getGeometryNames(); // extract path for reading external files const std::string path = BaseLib::extractPath(fname); diff --git a/Applications/FileIO/Legacy/createSurface.cpp b/Applications/FileIO/Legacy/createSurface.cpp index 6e8211906e17eb4f6c1632a36d8181842b913a78..b58e67d1411b04755dd556bec0bdc53a71cceaec 100644 --- a/Applications/FileIO/Legacy/createSurface.cpp +++ b/Applications/FileIO/Legacy/createSurface.cpp @@ -72,8 +72,7 @@ bool createSurface(GeoLib::Polyline const& ply, geo.addPolylineVec(std::move(polylines), ply_name); // use GMSHInterface to create a mesh from the closed polyline - std::vector<std::string> geo_names; - geo.getGeometryNames(geo_names); + auto const geo_names = geo.getGeometryNames(); FileIO::GMSH::GMSHInterface gmsh_io( geo, false, FileIO::GMSH::MeshDensityAlgorithm::FixedMeshDensity, 0.0, 0.0, 0, geo_names, false, false); diff --git a/Applications/FileIO/XmlIO/Qt/XmlPrjInterface.cpp b/Applications/FileIO/XmlIO/Qt/XmlPrjInterface.cpp index c045fc06e1f1205da67f68e534c15bd087a73668..62dbaa30043f2ad9ad41de664007ca402f61cb56 100644 --- a/Applications/FileIO/XmlIO/Qt/XmlPrjInterface.cpp +++ b/Applications/FileIO/XmlIO/Qt/XmlPrjInterface.cpp @@ -371,9 +371,7 @@ bool XmlPrjInterface::write() } // geometries - std::vector<std::string> geo_names; - geo_objects.getGeometryNames(geo_names); - for (std::string const& name : geo_names) + for (std::string const& name : geo_objects.getGeometryNames()) { // write gml file GeoLib::IO::XmlGmlInterface gml(geo_objects); diff --git a/Applications/FileIO/readGeometryFromFile.cpp b/Applications/FileIO/readGeometryFromFile.cpp index cb4b540c3473aeab6f10f8838dbebb620cbd52cc..cd3750fbd624f1ba12e592f3aa38edcfad92d6a8 100644 --- a/Applications/FileIO/readGeometryFromFile.cpp +++ b/Applications/FileIO/readGeometryFromFile.cpp @@ -37,11 +37,11 @@ void readGeometryFromFile(std::string const& fname, fname, geo_objs, geo_name, errors, gmsh_path); } - std::vector<std::string> geo_names; - geo_objs.getGeometryNames(geo_names); - if (geo_names.empty()) { - OGS_FATAL("GEOObjects has no geometry name after reading the geometry file. " - "Something is wrong in the reading function."); + if (geo_objs.getGeometryNames().empty()) + { + OGS_FATAL( + "GEOObjects has no geometry name after reading the geometry file. " + "Something is wrong in the reading function."); } } } // namespace FileIO diff --git a/Applications/Utils/FileConverter/convertGEO.cpp b/Applications/Utils/FileConverter/convertGEO.cpp index 0c59d694193eb9b496f28830db9807b48f172aeb..fd8fe2d0e64c6d019ed066432c2969bc765bc1a5 100644 --- a/Applications/Utils/FileConverter/convertGEO.cpp +++ b/Applications/Utils/FileConverter/convertGEO.cpp @@ -49,8 +49,7 @@ int main (int argc, char* argv[]) GeoLib::GEOObjects geoObjects; FileIO::readGeometryFromFile(argInputFileName.getValue(), geoObjects, gmsh_path_arg.getValue()); - std::vector<std::string> geo_names; - geoObjects.getGeometryNames(geo_names); + auto const geo_names = geoObjects.getGeometryNames(); assert(geo_names.size() == 1); FileIO::writeGeometryToFile(geo_names[0], geoObjects, argOutputFileName.getValue()); diff --git a/Applications/Utils/GeoTools/MoveGeometry.cpp b/Applications/Utils/GeoTools/MoveGeometry.cpp index 6dc6d6e17bd0f3d877d5e7c55d4e5fed95198618..8d3958b0ff99ef8bbc19e425cb94610cb6964a28 100644 --- a/Applications/Utils/GeoTools/MoveGeometry.cpp +++ b/Applications/Utils/GeoTools/MoveGeometry.cpp @@ -80,10 +80,10 @@ int main(int argc, char *argv[]) displacement[2] = z_arg.getValue(); } - std::vector<std::string> geo_names; - geo_objects.getGeometryNames(geo_names); + auto const geo_name = geo_objects.getGeometryNames()[0]; - std::vector<GeoLib::Point*> const* point_vec = geo_objects.getPointVec(geo_names[0]); + std::vector<GeoLib::Point*> const* point_vec = + geo_objects.getPointVec(geo_name); std::size_t const n_points = point_vec->size(); for (std::size_t i = 0; i < n_points; ++i) { @@ -93,7 +93,7 @@ int main(int argc, char *argv[]) } } - xml.setNameForExport(geo_names[0]); + xml.setNameForExport(geo_name); xml.writeToFile(geo_output_arg.getValue()); return EXIT_SUCCESS; diff --git a/Applications/Utils/GeoTools/TriangulatePolyline.cpp b/Applications/Utils/GeoTools/TriangulatePolyline.cpp index fbb025dab9cb2c938f7199600ffa7d03dd1075a3..465c01b063aed3352d7e9339d3a1d18f2a8e143b 100644 --- a/Applications/Utils/GeoTools/TriangulatePolyline.cpp +++ b/Applications/Utils/GeoTools/TriangulatePolyline.cpp @@ -79,10 +79,11 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } - std::vector<std::string> geo_names; - geo_objects.getGeometryNames(geo_names); - GeoLib::PolylineVec const*const line_vec (geo_objects.getPolylineVecObj(geo_names[0])); - GeoLib::Polyline* line = const_cast<GeoLib::Polyline*>(line_vec->getElementByName(polyline_name)); + auto const geo_name = geo_objects.getGeometryNames()[0]; + GeoLib::PolylineVec const* const line_vec( + geo_objects.getPolylineVecObj(geo_name)); + GeoLib::Polyline* line = const_cast<GeoLib::Polyline*>( + line_vec->getElementByName(polyline_name)); // check if line exists if (line == nullptr) @@ -118,7 +119,7 @@ int main(int argc, char *argv[]) } INFO ("Creating a surface by triangulation of the polyline ..."); - if (FileIO::createSurface(*line, geo_objects, geo_names[0], + if (FileIO::createSurface(*line, geo_objects, geo_name, gmsh_path_arg.getValue())) { INFO("\t done"); @@ -129,8 +130,8 @@ int main(int argc, char *argv[]) "\t Creating a surface by triangulation of the polyline " "failed."); } - GeoLib::SurfaceVec* sfc_vec(geo_objects.getSurfaceVecObj(geo_names[0])); - std::size_t const sfc_id = geo_objects.getSurfaceVec(geo_names[0])->size() - 1; + GeoLib::SurfaceVec* sfc_vec(geo_objects.getSurfaceVecObj(geo_name)); + std::size_t const sfc_id = geo_objects.getSurfaceVec(geo_name)->size() - 1; std::string const surface_name (polyline_name + "_surface"); for (std::size_t i=1;;++i) { @@ -143,7 +144,7 @@ int main(int argc, char *argv[]) } // write new file - xml.setNameForExport(geo_names[0]); + xml.setNameForExport(geo_name); xml.writeToFile(output_arg.getValue()); INFO ("...done."); diff --git a/Applications/Utils/MeshEdit/CreateBoundaryConditionsAlongPolylines.cpp b/Applications/Utils/MeshEdit/CreateBoundaryConditionsAlongPolylines.cpp index c57c9c65dac93b97b86681a4378c045b8fa6cd93..773e8c4b71979cabf1688215870d9e02535ef5b9 100644 --- a/Applications/Utils/MeshEdit/CreateBoundaryConditionsAlongPolylines.cpp +++ b/Applications/Utils/MeshEdit/CreateBoundaryConditionsAlongPolylines.cpp @@ -193,12 +193,7 @@ int main (int argc, char* argv[]) FileIO::readGeometryFromFile(geometry_fname.getValue(), geometries, gmsh_path_arg.getValue()); - std::string geo_name; - { - std::vector<std::string> geo_names; - geometries.getGeometryNames(geo_names); - geo_name = geo_names[0]; - } + auto const geo_name = geometries.getGeometryNames()[0]; // *** check if the data is usable // *** get vector of polylines @@ -220,9 +215,9 @@ int main (int argc, char* argv[]) MeshGeoToolsLib::MeshNodeSearcher mesh_searcher( *surface_mesh, std::move(search_length_strategy), MeshGeoToolsLib::SearchAllNodes::Yes); - for(std::size_t k(0); k<plys->size(); k++) { - std::vector<std::size_t> ids - (mesh_searcher.getMeshNodeIDsAlongPolyline(*((*plys)[k]))); + for (std::size_t k(0); k < plys->size(); k++) + { + auto const& ids = mesh_searcher.getMeshNodeIDs(*((*plys)[k])); if (ids.empty()) { continue; @@ -233,8 +228,7 @@ int main (int argc, char* argv[]) } // merge all together - std::vector<std::string> geo_names; - geometry_sets.getGeometryNames(geo_names); + auto const geo_names = geometry_sets.getGeometryNames(); if (geo_names.empty()) { ERR("Did not find mesh nodes along polylines."); return EXIT_FAILURE; diff --git a/Applications/Utils/MeshEdit/MapGeometryToMeshSurface.cpp b/Applications/Utils/MeshEdit/MapGeometryToMeshSurface.cpp index 64613f47c9af1d926a97b792137516b4ac7d0885..855d6fafa10ae9303067e0e35e48b344c5497ee9 100644 --- a/Applications/Utils/MeshEdit/MapGeometryToMeshSurface.cpp +++ b/Applications/Utils/MeshEdit/MapGeometryToMeshSurface.cpp @@ -65,12 +65,7 @@ int main (int argc, char* argv[]) } } - std::string geo_name; - { - std::vector<std::string> geo_names; - geometries.getGeometryNames(geo_names); - geo_name = geo_names[0]; - } + auto const geo_name = geometries.getGeometryNames()[0]; MeshGeoToolsLib::GeoMapper geo_mapper(geometries, geo_name); diff --git a/Applications/Utils/MeshEdit/ResetPropertiesInPolygonalRegion.cpp b/Applications/Utils/MeshEdit/ResetPropertiesInPolygonalRegion.cpp index 92280dfe29b6de5f84c560b3652b73a85db40988..f639f929e6fc95da9f31f0630db8f4a8f12262cb 100644 --- a/Applications/Utils/MeshEdit/ResetPropertiesInPolygonalRegion.cpp +++ b/Applications/Utils/MeshEdit/ResetPropertiesInPolygonalRegion.cpp @@ -91,12 +91,7 @@ int main(int argc, char* argv[]) FileIO::readGeometryFromFile(geometry_fname.getValue(), geometries, gmsh_path_arg.getValue()); - std::string geo_name; - { - std::vector<std::string> geo_names; - geometries.getGeometryNames(geo_names); - geo_name = geo_names[0]; - } + auto const geo_name = geometries.getGeometryNames()[0]; // *** check if the data is usable // *** get vector of polylines diff --git a/Applications/Utils/MeshEdit/appendLinesAlongPolyline.cpp b/Applications/Utils/MeshEdit/appendLinesAlongPolyline.cpp index b59ea62a52b3cd343266fef9452ec0ee5804bd3d..e8021de9f39e5c80592e91406240ff62acf50aaf 100644 --- a/Applications/Utils/MeshEdit/appendLinesAlongPolyline.cpp +++ b/Applications/Utils/MeshEdit/appendLinesAlongPolyline.cpp @@ -58,9 +58,8 @@ int main (int argc, char* argv[]) FileIO::readGeometryFromFile(geoFileArg.getValue(), geo_objs, gmsh_path_arg.getValue()); - std::vector<std::string> geo_names; - geo_objs.getGeometryNames (geo_names); - if (geo_names.empty ()) + auto const geo_names = geo_objs.getGeometryNames(); + if (geo_names.empty()) { ERR("No geometries found."); return EXIT_FAILURE; diff --git a/Applications/Utils/MeshEdit/removeMeshElements.cpp b/Applications/Utils/MeshEdit/removeMeshElements.cpp index 969c4f912055e52c60c793cae5c9c7ffd4a78467..56a9e3148a4863c1aebefa71bd6f042f463e73ad 100644 --- a/Applications/Utils/MeshEdit/removeMeshElements.cpp +++ b/Applications/Utils/MeshEdit/removeMeshElements.cpp @@ -103,8 +103,15 @@ int main (int argc, char* argv[]) // Non-bounding-box params TCLAP::SwitchArg zveArg("z", "zero-volume", "remove zero volume elements", false); cmd.add(zveArg); - TCLAP::MultiArg<std::string> eleTypeArg("t", "element-type", - "element type to be removed", false, "element type"); + + std::vector<std::string> allowed_ele_types{"line", "tri", "quad", "hex", + "prism", "tet", "pyramid"}; + TCLAP::ValuesConstraint<std::string> allowedVals{allowed_ele_types}; + TCLAP::MultiArg<std::string> eleTypeArg( + "t", "element-type", + "element type to be removed: line | tri | quad | hex | prism | tet | " + "pyramid", + false, &allowedVals); cmd.add(eleTypeArg); // scalar array params diff --git a/Applications/Utils/MeshGeoTools/computeSurfaceNodeIDsInPolygonalRegion.cpp b/Applications/Utils/MeshGeoTools/computeSurfaceNodeIDsInPolygonalRegion.cpp index de732c8d839f89b95f05b2c2ce05c6b28bc4f193..671d896427c817e8dc0164dd4664d8018dee3b19 100644 --- a/Applications/Utils/MeshGeoTools/computeSurfaceNodeIDsInPolygonalRegion.cpp +++ b/Applications/Utils/MeshGeoTools/computeSurfaceNodeIDsInPolygonalRegion.cpp @@ -96,12 +96,11 @@ int main (int argc, char* argv[]) GeoLib::GEOObjects geo_objs; FileIO::readGeometryFromFile(geo_in.getValue(), geo_objs, gmsh_path_arg.getValue()); - std::vector<std::string> geo_names; - geo_objs.getGeometryNames(geo_names); + auto const geo_name = geo_objs.getGeometryNames()[0]; INFO("Geometry '{:s}' read: {:d} points, {:d} polylines.", - geo_names[0], - geo_objs.getPointVec(geo_names[0])->size(), - geo_objs.getPolylineVec(geo_names[0])->size()); + geo_name, + geo_objs.getPointVec(geo_name)->size(), + geo_objs.getPolylineVec(geo_name)->size()); MathLib::Vector3 const dir(0.0, 0.0, -1.0); double angle(90); @@ -125,7 +124,7 @@ int main (int argc, char* argv[]) std::vector<MeshLib::Node*> const& mesh_nodes(mesh->getNodes()); GeoLib::PolylineVec const* ply_vec( - geo_objs.getPolylineVecObj(geo_names[0]) + geo_objs.getPolylineVecObj(geo_name) ); std::vector<GeoLib::Polyline*> const& plys(*(ply_vec->getVector())); diff --git a/Applications/Utils/OGSFileConverter/OGSFileConverter.cpp b/Applications/Utils/OGSFileConverter/OGSFileConverter.cpp index 6e1eed426390c21b1ea616832fd11f04464837a1..1022d766cb5df0a73e345532bb601bda914f6438 100644 --- a/Applications/Utils/OGSFileConverter/OGSFileConverter.cpp +++ b/Applications/Utils/OGSFileConverter/OGSFileConverter.cpp @@ -73,12 +73,11 @@ void OGSFileConverter::convertGML2GLI(const QStringList &input, const QString &o continue; } - std::vector<std::string> geo_names; - geo_objects.getGeometryNames(geo_names); - FileIO::Legacy::writeGLIFileV4(output_str, geo_names[0], geo_objects); - geo_objects.removeSurfaceVec(geo_names[0]); - geo_objects.removePolylineVec(geo_names[0]); - geo_objects.removePointVec(geo_names[0]); + auto const geo_name = geo_objects.getGeometryNames()[0]; + FileIO::Legacy::writeGLIFileV4(output_str, geo_name, geo_objects); + geo_objects.removeSurfaceVec(geo_name); + geo_objects.removePolylineVec(geo_name); + geo_objects.removePointVec(geo_name); } OGSError::box("File conversion finished"); } diff --git a/Applications/Utils/SWMMConverter/SWMMConverter.cpp b/Applications/Utils/SWMMConverter/SWMMConverter.cpp index a751557095de47532c491618ac3510d2281dacf7..4ca87d8970e8fbbe0c65acf5c37c9cd670c8754f 100644 --- a/Applications/Utils/SWMMConverter/SWMMConverter.cpp +++ b/Applications/Utils/SWMMConverter/SWMMConverter.cpp @@ -90,7 +90,7 @@ int writeMeshOutput(std::string const& input_file, addObjectsToMesh(*swmm, mesh, FileIO::SwmmObject::LINK, i); MeshLib::IO::VtuInterface vtkio(&mesh, 0, false); - std::string name(basename + BaseLib::tostring(i) + extension); + std::string name(basename + std::to_string(i) + extension); vtkio.writeToFile(name); } return 0; diff --git a/BaseLib/Algorithm.h b/BaseLib/Algorithm.h index a01a42ad5e121dfa7d279906d5adf1f9bfb7ecb6..8c8501c24989431694e5d66f74d5dfad487c9c65 100644 --- a/BaseLib/Algorithm.h +++ b/BaseLib/Algorithm.h @@ -13,11 +13,11 @@ #include <algorithm> #include <boost/optional.hpp> #include <cassert> +#include <string> #include <typeindex> #include <typeinfo> #include "Error.h" -#include "StringTools.h" namespace BaseLib { @@ -94,7 +94,7 @@ void insertIfTypeIndexKeyUniqueElseError(Map& map, Key const& key, if (!inserted.second) { // insertion failed, i.e., key already exists OGS_FATAL("{:s} Key `{:s}' already exists.", error_message, - tostring(key.hash_code())); + std::to_string(key.hash_code())); } } @@ -110,8 +110,7 @@ void insertIfKeyUniqueElseError(Map& map, Key const& key, Value&& value, auto const inserted = map.emplace(key, std::forward<Value>(value)); if (!inserted.second) { // insertion failed, i.e., key already exists - OGS_FATAL("{:s} Key `{:s}' already exists.", error_message, - tostring(key)); + OGS_FATAL("{:s} Key `{:s}' already exists.", error_message, key); } } @@ -130,14 +129,14 @@ void insertIfKeyValueUniqueElseError(Map& map, Key const& key, Value&& value, if (std::find_if(map.cbegin(), map.cend(), value_compare) != map.cend()) { OGS_FATAL("{:s} Value `{:s}' already exists.", error_message, - tostring(value)); + std::to_string(value)); } auto const inserted = map.emplace(key, std::forward<Value>(value)); if (!inserted.second) { // insertion failed, i.e., key already exists OGS_FATAL("{:s} Key `{:s}' already exists.", error_message, - tostring(key)); + std::to_string(key)); } } @@ -153,8 +152,15 @@ typename Map::mapped_type& getOrError(Map& map, Key const& key, auto it = map.find(key); if (it == map.end()) { - OGS_FATAL("{:s} Key `{:s}' does not exist.", error_message, - tostring(key)); + if constexpr (std::is_convertible<Key, std::string>::value) + { + OGS_FATAL("{:s} Key `{:s}' does not exist.", error_message, key); + } + else + { + OGS_FATAL("{:s} Key `{:s}' does not exist.", error_message, + std::to_string(key)); + } } return it->second; @@ -167,8 +173,15 @@ typename Map::mapped_type const& getOrError(Map const& map, Key const& key, auto it = map.find(key); if (it == map.end()) { - OGS_FATAL("{:s} Key `{:s}' does not exist.", error_message, - tostring(key)); + if constexpr (std::is_convertible<Key, std::string>::value) + { + OGS_FATAL("{:s} Key `{:s}' does not exist.", error_message, key); + } + else + { + OGS_FATAL("{:s} Key `{:s}' does not exist.", error_message, + std::to_string(key)); + } } return it->second; diff --git a/BaseLib/StringTools.cpp b/BaseLib/StringTools.cpp index 6f2118640e5f6e632a47d34b711b32a367d96a63..0c00e867c1bfc7f360413d8274537330a0f69bd2 100644 --- a/BaseLib/StringTools.cpp +++ b/BaseLib/StringTools.cpp @@ -82,11 +82,6 @@ void simplify(std::string &str) ); } -std::string const& tostring(std::string const& value) -{ - return value; -} - std::string format(const char* format_str, ... ) { va_list args; @@ -124,4 +119,19 @@ std::string randomString(std::size_t const length) return s; } +std::string getUniqueName(std::vector<std::string> const& existing_names, + std::string const& input_name) +{ + std::string result_name = input_name; + std::size_t count = 1; + while (std::find(existing_names.cbegin(), + existing_names.cend(), + result_name) != existing_names.end()) + { + count++; + result_name = input_name + "-" + std::to_string(count); + } + return result_name; +} + } // end namespace BaseLib diff --git a/BaseLib/StringTools.h b/BaseLib/StringTools.h index 62f9c5600264d2d7a965899de09873da9807acfb..dfe5487710eb9c230ec280ed58bd5966555f9e59 100644 --- a/BaseLib/StringTools.h +++ b/BaseLib/StringTools.h @@ -72,15 +72,10 @@ void trim(std::string &str, char ch=' '); */ void simplify(std::string &str); -//! Method for handling conversion to string uniformly across all types and std::string; see std::string overload below. -template<typename T> std::string tostring(T const& value) -{ - return std::to_string(value); -} -//! \overload -std::string const& tostring(std::string const& value); - //! Returns a random string of the given length containing just a-z,A-Z,0-9 std::string randomString(std::size_t length); +//! Append '-' and a number such that the name is unique. +std::string getUniqueName(std::vector<std::string> const& existing_names, + std::string const& input_name); } // end namespace BaseLib diff --git a/GeoLib/GEOObjects.cpp b/GeoLib/GEOObjects.cpp index 39cc9cf110fb1832469bd1dbe4a18d130a3012b6..df1aa06efdace8f1702af96d6073157da69e55b3 100644 --- a/GeoLib/GEOObjects.cpp +++ b/GeoLib/GEOObjects.cpp @@ -15,6 +15,7 @@ #include "GEOObjects.h" #include <fstream> +#include "BaseLib/StringTools.h" #include "BaseLib/Logging.h" #include "Triangle.h" @@ -339,41 +340,15 @@ const SurfaceVec* GEOObjects::getSurfaceVecObj(const std::string &name) const bool GEOObjects::isUniquePointVecName(std::string &name) { - int count = 0; - bool isUnique = false; - std::string cpName; + std::vector<std::string> const existing_names = getGeometryNames(); + auto const& unique_name = BaseLib::getUniqueName(existing_names, name); - while (!isUnique) + if (unique_name != name) { - isUnique = true; - cpName = name; - - count++; - // 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. - // If cpName is not the original name, "name" is changed and isUnique is set to false, - // indicating that a vector with the original name already exists. - if (count > 1) - { - isUnique = false; - name = cpName; + name = unique_name; + return false; } - return isUnique; + return true; } bool GEOObjects::isPntVecUsed (const std::string &name) const @@ -408,9 +383,9 @@ void GEOObjects::getStationVectorNames(std::vector<std::string>& names) const } } -void GEOObjects::getGeometryNames (std::vector<std::string>& names) const +std::vector<std::string> GEOObjects::getGeometryNames() const { - names.clear (); + std::vector<std::string> names; for (auto point : _pnt_vecs) { if (point->getType() == PointVec::PointType::POINT) @@ -418,6 +393,7 @@ void GEOObjects::getGeometryNames (std::vector<std::string>& names) const names.push_back(point->getName()); } } + return names; } std::string GEOObjects::getElementNameByID(const std::string& geometry_name, diff --git a/GeoLib/GEOObjects.h b/GeoLib/GEOObjects.h index 599e38efd0f50f11babad1e2e08d55435df04ec8..a7dc195abb1173b039a64fefc96732dd77f800c1 100644 --- a/GeoLib/GEOObjects.h +++ b/GeoLib/GEOObjects.h @@ -221,7 +221,7 @@ public: const SurfaceVec* getSurfaceVecObj(const std::string &name) const; /// Returns the names of all geometry vectors. - void getGeometryNames (std::vector<std::string>& names) const; + std::vector<std::string> getGeometryNames() const; std::string getElementNameByID(const std::string& geometry_name, GeoLib::GEOTYPE type, std::size_t id) const; diff --git a/GeoLib/Surface.cpp b/GeoLib/Surface.cpp index 28b7638ddcc220e95f953442719e50e51f1caf00..86b93a5f21f087cb60414697df54ae28d7f95d66 100644 --- a/GeoLib/Surface.cpp +++ b/GeoLib/Surface.cpp @@ -106,4 +106,10 @@ bool Surface::isPntInSfc(MathLib::Point3d const& pnt, double eps) const } return _surface_grid->isPointInSurface(pnt, eps); } + +bool operator==(Surface const& lhs, Surface const& rhs) +{ + return &lhs == &rhs; +} + } // namespace GeoLib diff --git a/GeoLib/Surface.h b/GeoLib/Surface.h index a6b34763eafb62264bb8f26cfb4795da9ae5121d..c0002b9d8390d8a1b9da7380279cfd12f1cffec1 100644 --- a/GeoLib/Surface.h +++ b/GeoLib/Surface.h @@ -77,6 +77,7 @@ public: * @return axis aligned bounding box */ AABB const& getAABB() const { return *_bounding_volume; } + protected: /** a vector of pointers to Points */ const std::vector<Point*>& _sfc_pnts; @@ -90,4 +91,7 @@ protected: /// called and a valid surface grid is not existing. mutable std::unique_ptr<SurfaceGrid> _surface_grid; }; + +bool operator==(Surface const& lhs, Surface const& rhs); + } // namespace GeoLib diff --git a/MeshGeoToolsLib/BoundaryElementsAlongPolyline.cpp b/MeshGeoToolsLib/BoundaryElementsAlongPolyline.cpp index de87f209d97d80f6ed54a1a91b77f0818e56713e..97a524facca6921082f042bf830ac0bfbb81aed5 100644 --- a/MeshGeoToolsLib/BoundaryElementsAlongPolyline.cpp +++ b/MeshGeoToolsLib/BoundaryElementsAlongPolyline.cpp @@ -29,7 +29,7 @@ BoundaryElementsAlongPolyline::BoundaryElementsAlongPolyline( : _mesh(mesh), _ply(ply) { // search nodes and elements located along the polyline - auto node_ids_on_poly = mshNodeSearcher.getMeshNodeIDsAlongPolyline(ply); + auto node_ids_on_poly = mshNodeSearcher.getMeshNodeIDs(ply); MeshLib::ElementSearch es(_mesh); es.searchByNodeIDs(node_ids_on_poly); auto& ele_ids_near_ply = es.getSearchedElementIDs(); diff --git a/MeshGeoToolsLib/BoundaryElementsOnSurface.cpp b/MeshGeoToolsLib/BoundaryElementsOnSurface.cpp index eeb55d713952855b6b57b710f03685cc1f77f9b3..80f41b19edbe39ac18e79087a4e47c592e1e14cb 100644 --- a/MeshGeoToolsLib/BoundaryElementsOnSurface.cpp +++ b/MeshGeoToolsLib/BoundaryElementsOnSurface.cpp @@ -25,7 +25,7 @@ BoundaryElementsOnSurface::BoundaryElementsOnSurface( : _mesh(mesh), _sfc(sfc) { // search elements near the surface - auto node_ids_on_sfc = mshNodeSearcher.getMeshNodeIDsAlongSurface(sfc); + auto node_ids_on_sfc = mshNodeSearcher.getMeshNodeIDs(sfc); MeshLib::ElementSearch es(_mesh); es.searchByNodeIDs(node_ids_on_sfc); auto &ele_ids_near_sfc = es.getSearchedElementIDs(); diff --git a/MeshGeoToolsLib/BoundaryElementsSearcher.cpp b/MeshGeoToolsLib/BoundaryElementsSearcher.cpp index 05daeeee3cd408f5f69bc2ec70aabc75cf5c6199..d5e8550880bdf5ce3d5de1f93f72f0b3127a235b 100644 --- a/MeshGeoToolsLib/BoundaryElementsSearcher.cpp +++ b/MeshGeoToolsLib/BoundaryElementsSearcher.cpp @@ -47,91 +47,77 @@ BoundaryElementsSearcher::~BoundaryElementsSearcher() } } -std::vector<MeshLib::Element*> const& -BoundaryElementsSearcher::getBoundaryElements(GeoLib::GeoObject const& geoObj, - bool const multiple_nodes_allowed) +template <typename CacheType, typename GeometryType> +std::vector<MeshLib::Element*> const& getBoundaryElements( + std::vector<CacheType*>& cached_elements, + std::function<GeometryType(CacheType const&)> getCachedItem, + GeometryType const& item, MeshLib::Mesh const& mesh, + MeshNodeSearcher const& mesh_node_searcher, + [[maybe_unused]] bool const multiple_nodes_allowed) { - switch (geoObj.getGeoType()) { - case GeoLib::GEOTYPE::POINT: - return this->getBoundaryElementsAtPoint( - *dynamic_cast<const GeoLib::Point*>(&geoObj), - multiple_nodes_allowed); - break; - case GeoLib::GEOTYPE::POLYLINE: - return this->getBoundaryElementsAlongPolyline(*dynamic_cast<const GeoLib::Polyline*>(&geoObj)); - break; - case GeoLib::GEOTYPE::SURFACE: - return this->getBoundaryElementsOnSurface(*dynamic_cast<const GeoLib::Surface*>(&geoObj)); - break; - default: - const static std::vector<MeshLib::Element*> dummy(0); - return dummy; - } -} - -std::vector<MeshLib::Element*> const& -BoundaryElementsSearcher::getBoundaryElementsAtPoint( - GeoLib::Point const& point, bool const multiple_nodes_allowed) -{ - // look for already saved points and return if found. - if (auto const it = find_if(cbegin(_boundary_elements_at_point), - cend(_boundary_elements_at_point), - [&](auto const& boundary_elements) { - return boundary_elements->getPoint() == - point; + if (auto const it = find_if(cbegin(cached_elements), cend(cached_elements), + [&](auto const& element) { + return getCachedItem(*element) == item; }); - it != cend(_boundary_elements_at_point)) + it != cend(cached_elements)) { return (*it)->getBoundaryElements(); } - - // create new boundary elements at points. - _boundary_elements_at_point.push_back(new BoundaryElementsAtPoint( - _mesh, _mshNodeSearcher, point, multiple_nodes_allowed)); - return _boundary_elements_at_point.back()->getBoundaryElements(); -} - -std::vector<MeshLib::Element*> const& -BoundaryElementsSearcher::getBoundaryElementsAlongPolyline( - GeoLib::Polyline const& polyline) -{ - // look for already saved polylines and return if found. - if (auto const it = find_if(cbegin(_boundary_elements_along_polylines), - cend(_boundary_elements_along_polylines), - [&](auto const& boundary_elements) { - return &boundary_elements->getPolyline() == - &polyline; - }); - it != cend(_boundary_elements_along_polylines)) + // create new boundary elements + if constexpr (std::is_convertible<GeometryType, GeoLib::Point>::value) { - return (*it)->getBoundaryElements(); + cached_elements.push_back(new CacheType(mesh, mesh_node_searcher, item, + multiple_nodes_allowed)); } - - // create new boundary elements at points. - _boundary_elements_along_polylines.push_back( - new BoundaryElementsAlongPolyline(_mesh, _mshNodeSearcher, polyline)); - return _boundary_elements_along_polylines.back()->getBoundaryElements(); + else + { + cached_elements.push_back( + new CacheType(mesh, mesh_node_searcher, item)); + } + return cached_elements.back()->getBoundaryElements(); } std::vector<MeshLib::Element*> const& -BoundaryElementsSearcher::getBoundaryElementsOnSurface( - GeoLib::Surface const& surface) +BoundaryElementsSearcher::getBoundaryElements(GeoLib::GeoObject const& geoObj, + bool const multiple_nodes_allowed) { - // look for already saved surfaces and return if found. - if (auto const it = find_if(cbegin(_boundary_elements_along_surfaces), - cend(_boundary_elements_along_surfaces), - [&](auto const& boundary_elements) { - return &boundary_elements->getSurface() == - &surface; - }); - it != cend(_boundary_elements_along_surfaces)) + switch (geoObj.getGeoType()) { - return (*it)->getBoundaryElements(); + case GeoLib::GEOTYPE::POINT: + { + std::function<GeoLib::Point(BoundaryElementsAtPoint const&)> + get_cached_item = &BoundaryElementsAtPoint::getPoint; + return MeshGeoToolsLib::getBoundaryElements( + _boundary_elements_at_point, get_cached_item, + *dynamic_cast<const GeoLib::Point*>(&geoObj), _mesh, + _mshNodeSearcher, multiple_nodes_allowed); + } + break; + case GeoLib::GEOTYPE::POLYLINE: + { + std::function<GeoLib::Polyline( + BoundaryElementsAlongPolyline const&)> + get_cached_item = &BoundaryElementsAlongPolyline::getPolyline; + return MeshGeoToolsLib::getBoundaryElements( + _boundary_elements_along_polylines, get_cached_item, + *dynamic_cast<const GeoLib::Polyline*>(&geoObj), _mesh, + _mshNodeSearcher, false); + } + break; + case GeoLib::GEOTYPE::SURFACE: + { + std::function<GeoLib::Surface(BoundaryElementsOnSurface const&)> + get_cached_item = &BoundaryElementsOnSurface::getSurface; + return MeshGeoToolsLib::getBoundaryElements( + _boundary_elements_along_surfaces, get_cached_item, + *dynamic_cast<const GeoLib::Surface*>(&geoObj), _mesh, + _mshNodeSearcher, false); + } + break; + default: + const static std::vector<MeshLib::Element*> dummy(0); + return dummy; } - - _boundary_elements_along_surfaces.push_back( - new BoundaryElementsOnSurface(_mesh, _mshNodeSearcher, surface)); - return _boundary_elements_along_surfaces.back()->getBoundaryElements(); } } // end namespace MeshGeoToolsLib diff --git a/MeshGeoToolsLib/BoundaryElementsSearcher.h b/MeshGeoToolsLib/BoundaryElementsSearcher.h index a3b642fe726d4bc264aa5b36ece4940a8bee23b3..9ca63f261245cefd26b48f0f3457a87f3507dc29 100644 --- a/MeshGeoToolsLib/BoundaryElementsSearcher.h +++ b/MeshGeoToolsLib/BoundaryElementsSearcher.h @@ -60,34 +60,6 @@ public: std::vector<MeshLib::Element*> const& getBoundaryElements( GeoLib::GeoObject const& geoObj, bool const multiple_nodes_allowed); - /** - * generate boundary elements at the given point. - * @param point Search the mesh for given point - * @param multiple_nodes_allowed allows for finding multiple nodes within - * the given search radius - * @return a vector of boundary elements - */ - std::vector<MeshLib::Element*> const& getBoundaryElementsAtPoint( - GeoLib::Point const& point, bool const multiple_nodes_allowed); - - /** - * generate boundary elements on the given polyline. - * @param polyline the GeoLib::Polyline the nearest mesh nodes are searched - * for - * @return a vector of boundary element objects - */ - std::vector<MeshLib::Element*> const& getBoundaryElementsAlongPolyline( - GeoLib::Polyline const& polyline); - - /** - * generate boundary elements on the given surface. - * @param surface the GeoLib::Surface the nearest mesh nodes are searched - * for - * @return a vector of boundary element objects - */ - std::vector<MeshLib::Element*> const& getBoundaryElementsOnSurface( - GeoLib::Surface const& surface); - private: MeshLib::Mesh const& _mesh; MeshNodeSearcher const& _mshNodeSearcher; diff --git a/MeshGeoToolsLib/MeshNodeSearcher.cpp b/MeshGeoToolsLib/MeshNodeSearcher.cpp index 1e8feca4bf03f2ef1a38583ac03af24f02049082..0d6288d6910fee449a2ba874de4121c4e9240ae2 100644 --- a/MeshGeoToolsLib/MeshNodeSearcher.cpp +++ b/MeshGeoToolsLib/MeshNodeSearcher.cpp @@ -62,6 +62,37 @@ MeshNodeSearcher::~MeshNodeSearcher() } } +template <typename CacheType, typename GeometryType> +std::vector<std::size_t> const& getMeshNodeIDs( + std::vector<CacheType*>& cached_elements, + std::function<GeometryType(CacheType const&)> getCachedItem, + GeometryType const& item, MeshLib::Mesh const& mesh, + GeoLib::Grid<MeshLib::Node> const& mesh_grid, + double const search_length, + SearchAllNodes const search_all_nodes) +{ + if (auto const it = find_if(cbegin(cached_elements), cend(cached_elements), + [&](auto const& element) { + return getCachedItem(*element) == item; + }); + it != cend(cached_elements)) + { + return (*it)->getNodeIDs(); + } + // search IDs for geometry object + if constexpr (std::is_convertible<GeometryType, GeoLib::Point>::value) + { + cached_elements.push_back(new CacheType( + mesh, mesh_grid, item, search_length, search_all_nodes)); + } + else + { + cached_elements.push_back( + new CacheType(mesh, item, search_length, search_all_nodes)); + } + return cached_elements.back()->getNodeIDs(); +} + std::vector<std::size_t> MeshNodeSearcher::getMeshNodeIDs( GeoLib::GeoObject const& geoObj) const { @@ -70,18 +101,33 @@ std::vector<std::size_t> MeshNodeSearcher::getMeshNodeIDs( { case GeoLib::GEOTYPE::POINT: { - vec_nodes = this->getMeshNodeIDsForPoint( - *static_cast<const GeoLib::Point*>(&geoObj)); - break; + std::function<GeoLib::Point(MeshNodesOnPoint const&)> + get_cached_item_function = &MeshNodesOnPoint::getPoint; + return MeshGeoToolsLib::getMeshNodeIDs( + _mesh_nodes_on_points, get_cached_item_function, + *static_cast<const GeoLib::Point*>(&geoObj), _mesh, _mesh_grid, + _search_length_algorithm->getSearchLength(), _search_all_nodes); } case GeoLib::GEOTYPE::POLYLINE: - vec_nodes = this->getMeshNodeIDsAlongPolyline( - *static_cast<const GeoLib::Polyline*>(&geoObj)); - break; + { + std::function<GeoLib::Polyline(MeshNodesAlongPolyline const&)> + get_cached_item_function = &MeshNodesAlongPolyline::getPolyline; + return MeshGeoToolsLib::getMeshNodeIDs( + _mesh_nodes_along_polylines, get_cached_item_function, + *static_cast<const GeoLib::Polyline*>(&geoObj), _mesh, + _mesh_grid, _search_length_algorithm->getSearchLength(), + _search_all_nodes); + } case GeoLib::GEOTYPE::SURFACE: - vec_nodes = this->getMeshNodeIDsAlongSurface( - *static_cast<const GeoLib::Surface*>(&geoObj)); - break; + { + std::function<GeoLib::Surface(MeshNodesAlongSurface const&)> + get_cached_item_function = &MeshNodesAlongSurface::getSurface; + return MeshGeoToolsLib::getMeshNodeIDs( + _mesh_nodes_along_surfaces, get_cached_item_function, + *static_cast<const GeoLib::Surface*>(&geoObj), _mesh, + _mesh_grid, _search_length_algorithm->getSearchLength(), + _search_all_nodes); + } default: break; } @@ -131,85 +177,6 @@ std::vector<std::size_t> MeshNodeSearcher::getMeshNodeIDs( return node_ids; } -std::vector<std::size_t> const& MeshNodeSearcher::getMeshNodeIDsForPoint( - GeoLib::Point const& pnt) const -{ - return getMeshNodesOnPoint(pnt).getNodeIDs(); -} - -std::vector<std::size_t> const& MeshNodeSearcher::getMeshNodeIDsAlongPolyline( - GeoLib::Polyline const& ply) const -{ - return getMeshNodesAlongPolyline(ply).getNodeIDs(); -} - -std::vector<std::size_t> const& MeshNodeSearcher::getMeshNodeIDsAlongSurface( - GeoLib::Surface const& sfc) const -{ - return getMeshNodesAlongSurface(sfc).getNodeIDs(); -} - -MeshNodesOnPoint& MeshNodeSearcher::getMeshNodesOnPoint( - GeoLib::Point const& pnt) const -{ - if (auto const it = find_if( - cbegin(_mesh_nodes_on_points), - cend(_mesh_nodes_on_points), - [&](auto const& nodes) { return &(nodes->getPoint()) == &pnt; }); - it != cend(_mesh_nodes_on_points)) - { - return **it; - } - - _mesh_nodes_on_points.push_back( - new MeshNodesOnPoint(_mesh, - _mesh_grid, - pnt, - _search_length_algorithm->getSearchLength(), - _search_all_nodes)); - return *_mesh_nodes_on_points.back(); -} - -MeshNodesAlongPolyline& MeshNodeSearcher::getMeshNodesAlongPolyline( - GeoLib::Polyline const& ply) const -{ - if (auto const it = find_if( - cbegin(_mesh_nodes_along_polylines), - cend(_mesh_nodes_along_polylines), - [&](auto const& nodes) { return &(nodes->getPolyline()) == &ply; }); - it != cend(_mesh_nodes_along_polylines)) - { - return **it; - } - - // compute nodes (and supporting points) along polyline - _mesh_nodes_along_polylines.push_back(new MeshNodesAlongPolyline( - _mesh, ply, _search_length_algorithm->getSearchLength(), - _search_all_nodes)); - return *_mesh_nodes_along_polylines.back(); -} - -MeshNodesAlongSurface& MeshNodeSearcher::getMeshNodesAlongSurface( - GeoLib::Surface const& sfc) const -{ - if (auto const it = find_if( - cbegin(_mesh_nodes_along_surfaces), - cend(_mesh_nodes_along_surfaces), - [&](auto const& nodes) { return &(nodes->getSurface()) == &sfc; }); - it != cend(_mesh_nodes_along_surfaces)) - { - return **it; - } - - // compute nodes (and supporting points) on surface - _mesh_nodes_along_surfaces.push_back( - new MeshNodesAlongSurface(_mesh, - sfc, - _search_length_algorithm->getSearchLength(), - _search_all_nodes)); - return *_mesh_nodes_along_surfaces.back(); -} - MeshNodeSearcher const& MeshNodeSearcher::getMeshNodeSearcher( MeshLib::Mesh const& mesh, std::unique_ptr<MeshGeoToolsLib::SearchLength>&& search_length_algorithm) diff --git a/MeshGeoToolsLib/MeshNodeSearcher.h b/MeshGeoToolsLib/MeshNodeSearcher.h index bc16bc881d44d9d0eda8ef0da36f91fb81132408..864b4197dc442b828746349514d451ab13ff492c 100644 --- a/MeshGeoToolsLib/MeshNodeSearcher.h +++ b/MeshGeoToolsLib/MeshNodeSearcher.h @@ -85,62 +85,6 @@ public: std::vector<std::size_t> getMeshNodeIDs( std::vector<MathLib::Point3dWithID*> const& points) const; - /** - * Searches for the node nearest by the given point. If there are two nodes - * with the same distance the id of the one that was first found will be - * returned. The algorithm for the search is using GeoLib::Grid data - * structure. - * @param pnt a GeoLib::Point the nearest mesh node is searched for - * @return a vector of mesh node ids - */ - std::vector<std::size_t> const& getMeshNodeIDsForPoint( - GeoLib::Point const& pnt) const; - - /** - * Searches for the nearest mesh nodes along a GeoLib::Polyline. - * The search for mesh nodes along a specific polyline will be performed - * only once. The result ids will be stored inside an object - * (@see class MeshGeoToolsLib::MeshNodesAlongPolyline). - * @param ply the GeoLib::Polyline the nearest mesh nodes are searched for - * @return a vector of mesh node ids - */ - std::vector<std::size_t> const& getMeshNodeIDsAlongPolyline( - GeoLib::Polyline const& ply) const; - - /** - * Searches for the nearest mesh nodes along a GeoLib::Surface. - * The search for mesh nodes along a specific surface will be performed - * only once. The result ids will be stored inside an object - * (@see class MeshGeoToolsLib::MeshNodesAlongSurface). - * @param sfc the GeoLib::Surface the nearest mesh nodes are searched for - * @return a vector of mesh node ids - */ - std::vector<std::size_t> const& getMeshNodeIDsAlongSurface( - GeoLib::Surface const& sfc) const; - - /** - * Return a MeshNodesOnPoint object for the given GeoLib::Point object. - * @param pnt the GeoLib::Point the nearest mesh nodes are searched for - * @return a reference to a MeshNodesOnPoint object - */ - MeshNodesOnPoint& getMeshNodesOnPoint(GeoLib::Point const& pnt) const; - - /** - * Return a MeshNodesAlongPolyline object for the given GeoLib::Polyline object. - * @param ply the GeoLib::Polyline the nearest mesh nodes are searched for - * @return a reference to a MeshNodesAlongPolyline object - */ - MeshNodesAlongPolyline& getMeshNodesAlongPolyline( - GeoLib::Polyline const& ply) const; - - /** - * Return a MeshNodesAlongSurface object for the given GeoLib::Surface object. - * @param sfc the GeoLib::Surface the nearest mesh nodes are searched for - * @return a reference to a MeshNodesAlongSurface object - */ - MeshNodesAlongSurface& getMeshNodesAlongSurface( - GeoLib::Surface const& sfc) const; - /** * Returns a (possibly new) mesh node searcher for the mesh. * A new one will be created, if it does not already exists. diff --git a/MeshLib/MeshEditing/RasterDataToMesh.cpp b/MeshLib/MeshEditing/RasterDataToMesh.cpp index 3a3d397c7bf130b622de7931a85bf5cf955363dc..dfd66b9ef6478239708714c7f719977ee9b1d060 100644 --- a/MeshLib/MeshEditing/RasterDataToMesh.cpp +++ b/MeshLib/MeshEditing/RasterDataToMesh.cpp @@ -10,6 +10,7 @@ #include "RasterDataToMesh.h" +#include "BaseLib/StringTools.h" #include "MeshLib/Node.h" #include "MeshLib/Elements/Element.h" @@ -18,7 +19,6 @@ namespace MeshLib namespace RasterDataToMesh { - static bool checkMesh(MeshLib::Mesh const& mesh) { if (mesh.getDimension() > 2) @@ -29,20 +29,6 @@ static bool checkMesh(MeshLib::Mesh const& mesh) return true; } -static std::string getValidName(std::vector<std::string> const& vec_names, - std::string const& array_name) -{ - std::string new_name = array_name; - std::size_t count = 1; - while (std::find(vec_names.cbegin(), vec_names.cend(), new_name) != - vec_names.end()) - { - count++; - new_name = array_name + "-" + std::to_string(count); - } - return new_name; -} - static double evaluatePixel(double const value, double const no_data, double const replacement) { @@ -50,11 +36,12 @@ static double evaluatePixel(double const value, double const no_data, { return replacement; } - return value; + return value; } bool projectToNodes(MeshLib::Mesh& mesh, GeoLib::Raster const& raster, - double const def, std::string const& array_name) + double const default_replacement, + std::string const& array_name) { if (!checkMesh(mesh)) { @@ -64,19 +51,21 @@ bool projectToNodes(MeshLib::Mesh& mesh, GeoLib::Raster const& raster, auto& nodes = mesh.getNodes(); auto& props = mesh.getProperties(); std::string const name = - getValidName(props.getPropertyVectorNames(), array_name); + BaseLib::getUniqueName(props.getPropertyVectorNames(), array_name); auto vec = props.createNewPropertyVector<double>( name, MeshLib::MeshItemType::Node, 1); double const no_data = raster.getHeader().no_data; - std::transform(nodes.cbegin(), nodes.cend(), std::back_inserter(*vec), [&](auto const node) - { - return evaluatePixel(raster.getValueAtPoint(*node), no_data, def); - }); + std::transform(nodes.cbegin(), nodes.cend(), std::back_inserter(*vec), + [&](auto const node) { + return evaluatePixel(raster.getValueAtPoint(*node), + no_data, default_replacement); + }); return true; } bool projectToElements(MeshLib::Mesh& mesh, GeoLib::Raster const& raster, - double const def, std::string const& array_name) + double const default_replacement, + std::string const& array_name) { if (!checkMesh(mesh)) { @@ -86,14 +75,16 @@ bool projectToElements(MeshLib::Mesh& mesh, GeoLib::Raster const& raster, auto& elems = mesh.getElements(); auto& props = mesh.getProperties(); std::string const name = - getValidName(props.getPropertyVectorNames(), array_name); + BaseLib::getUniqueName(props.getPropertyVectorNames(), array_name); auto vec = props.createNewPropertyVector<double>( name, MeshLib::MeshItemType::Cell, 1); double const no_data = raster.getHeader().no_data; - std::transform(elems.cbegin(), elems.cend(), std::back_inserter(*vec), [&](auto const elem) { - auto node = elem->getCenterOfGravity(); - return evaluatePixel(raster.getValueAtPoint(node), no_data, def); - }); + std::transform(elems.cbegin(), elems.cend(), std::back_inserter(*vec), + [&](auto const elem) { + auto node = elem->getCenterOfGravity(); + return evaluatePixel(raster.getValueAtPoint(node), + no_data, default_replacement); + }); return true; } diff --git a/MeshLib/MeshEditing/RasterDataToMesh.h b/MeshLib/MeshEditing/RasterDataToMesh.h index f80054d129105d8943c2034c43f08de26a400174..32c3ee8d8c6444cecc92f57afe4e8ff7820cd6a9 100644 --- a/MeshLib/MeshEditing/RasterDataToMesh.h +++ b/MeshLib/MeshEditing/RasterDataToMesh.h @@ -23,9 +23,11 @@ namespace MeshLib namespace RasterDataToMesh { bool projectToNodes(MeshLib::Mesh& mesh, GeoLib::Raster const& raster, - double const def, std::string const& array_name); + double const default_replacement, + std::string const& array_name); bool projectToElements(MeshLib::Mesh& mesh, GeoLib::Raster const& raster, - double const def, std::string const& array_name); + double const default_replacement, + std::string const& array_name); } // end namespace RasterDataToMesh } // end namespace MeshLib diff --git a/ProcessLib/BoundaryCondition/ConstraintDirichletBoundaryCondition.cpp b/ProcessLib/BoundaryCondition/ConstraintDirichletBoundaryCondition.cpp index c13a3bcdd1933d2d4d855d1a9f693b9629502c30..ce9bf35a31ee290c36348b3f164575edcdf1ff42 100644 --- a/ProcessLib/BoundaryCondition/ConstraintDirichletBoundaryCondition.cpp +++ b/ProcessLib/BoundaryCondition/ConstraintDirichletBoundaryCondition.cpp @@ -56,8 +56,7 @@ ConstraintDirichletBoundaryCondition::ConstraintDirichletBoundaryCondition( std::vector<MeshLib::Node*> const& bc_nodes = _bc_mesh.getNodes(); DBUG( "Found {:d} nodes for constraint Dirichlet BCs for the variable {:d} " - "and " - "component {:d}", + "and component {:d}", bc_nodes.size(), variable_id, component_id); MeshLib::MeshSubset bc_mesh_subset{_bc_mesh, bc_nodes}; @@ -271,8 +270,7 @@ createConstraintDirichletBoundaryCondition( process_variables[variable_id].get().getName(); OGS_FATAL( "<constraining_process_variable> in process variable name '{:s}' " - "at " - "geometry 'TODO' : The constraining process variable is set as " + "at geometry 'TODO' : The constraining process variable is set as " "'{:s}', but this is not specified in the project file.", constraining_process_variable_name, constraining_process_variable); @@ -290,8 +288,7 @@ createConstraintDirichletBoundaryCondition( { OGS_FATAL( "The constraint direction is '{:s}', but has to be either " - "'greater' " - "or 'lower'.", + "'greater' or 'lower'.", constraint_direction_string); } bool const lower = constraint_direction_string == "lower"; diff --git a/ProcessLib/BoundaryCondition/NeumannBoundaryCondition.cpp b/ProcessLib/BoundaryCondition/NeumannBoundaryCondition.cpp index dcc0a9e6636b78b6fcfa500bb6a1fb82a4e67947..b7b2dd23664c1f6ec92806754b9e4bc5cc210d86 100644 --- a/ProcessLib/BoundaryCondition/NeumannBoundaryCondition.cpp +++ b/ProcessLib/BoundaryCondition/NeumannBoundaryCondition.cpp @@ -60,8 +60,7 @@ std::unique_ptr<NeumannBoundaryCondition> createNeumannBoundaryCondition( { OGS_FATAL( "The dimension ({:d}) of the given boundary mesh '{:s}' is not " - "lower " - "than the bulk dimension ({:d}).", + "lower than the bulk dimension ({:d}).", bc_mesh.getDimension(), bc_mesh.getName(), global_dim); } diff --git a/ProcessLib/BoundaryCondition/RobinBoundaryCondition.cpp b/ProcessLib/BoundaryCondition/RobinBoundaryCondition.cpp index 324febc41b4ff601c37dc9b473373e270f80430c..572ca71e5aa5a4446f9ec9c9bf18d7d510fd6eac 100644 --- a/ProcessLib/BoundaryCondition/RobinBoundaryCondition.cpp +++ b/ProcessLib/BoundaryCondition/RobinBoundaryCondition.cpp @@ -29,8 +29,7 @@ std::unique_ptr<RobinBoundaryCondition> createRobinBoundaryCondition( { OGS_FATAL( "The dimension ({:d}) of the given boundary mesh '{:s}' is not " - "lower " - "than the bulk dimension ({:d}).", + "lower than the bulk dimension ({:d}).", bc_mesh.getDimension(), bc_mesh.getName(), global_dim); } diff --git a/Tests/FileIO_Qt/TestQtPrjInterface.cpp b/Tests/FileIO_Qt/TestQtPrjInterface.cpp index b99a524ab8d9347e288acc999efd3f04535eb460..fd989a7103df3534567bc32d30b8f513dbb14ab9 100644 --- a/Tests/FileIO_Qt/TestQtPrjInterface.cpp +++ b/Tests/FileIO_Qt/TestQtPrjInterface.cpp @@ -47,8 +47,7 @@ TEST(TestQtPrjInterface, QtXmlPrjReader) int result = xml.readFile(test_file.file_name); EXPECT_EQ(1, result); - std::vector<std::string> geo_names; - project.getGEOObjects().getGeometryNames(geo_names); + auto const geo_names = project.getGEOObjects().getGeometryNames(); EXPECT_EQ(test_file.n_geo, geo_names.size()); EXPECT_EQ(test_file.n_mesh, project.getMeshObjects().size()); diff --git a/Tests/GeoLib/TestPointToStationConversion.cpp b/Tests/GeoLib/TestPointToStationConversion.cpp index d2d9e4a998230e04c84517e115dcb427e2b0422b..396b46560a48ee4e791ee81c1eaddd7bf1051550 100644 --- a/Tests/GeoLib/TestPointToStationConversion.cpp +++ b/Tests/GeoLib/TestPointToStationConversion.cpp @@ -24,9 +24,8 @@ TEST(GeoLib, PointToStationConversion) GeoLib::IO::BoostXmlGmlInterface io(geo_obj); bool const ret = io.readFile(file_name); EXPECT_TRUE(ret); - std::vector<std::string> geo_names; - geo_obj.getGeometryNames(geo_names); - auto const* const pnts = geo_obj.getPointVec(geo_names[0]); + auto const geo_name = geo_obj.getGeometryNames()[0]; + auto const* const pnts = geo_obj.getPointVec(geo_name); assert(pnts != nullptr); std::size_t const exp_all_pnts(310); EXPECT_EQ(exp_all_pnts, pnts->size()); @@ -34,7 +33,7 @@ TEST(GeoLib, PointToStationConversion) // converting only unused points std::string stn_orphaned_pnts("Orphaned Points"); int const res_orphaned_pnts = - geo_obj.geoPointsToStations(geo_names[0], stn_orphaned_pnts, true); + geo_obj.geoPointsToStations(geo_name, stn_orphaned_pnts, true); EXPECT_EQ(0, res_orphaned_pnts); auto const* const stns = geo_obj.getStationVec(stn_orphaned_pnts); assert(stns != nullptr); @@ -50,7 +49,7 @@ TEST(GeoLib, PointToStationConversion) // converting all points std::string stn_all_pnts("All Points"); int const res_all_pnts = - geo_obj.geoPointsToStations(geo_names[0], stn_all_pnts, false); + geo_obj.geoPointsToStations(geo_name, stn_all_pnts, false); EXPECT_EQ(0, res_all_pnts); EXPECT_EQ(exp_all_pnts, geo_obj.getStationVec(stn_all_pnts)->size()); } diff --git a/Tests/MeshLib/TestMeshNodeSearch.cpp b/Tests/MeshLib/TestMeshNodeSearch.cpp index 1ff2aed0e0bb28dafeefbdb2a9dd8b4ad2771274..b77fc43ad34be9e96aa72492cae7507c299ccb3e 100644 --- a/Tests/MeshLib/TestMeshNodeSearch.cpp +++ b/Tests/MeshLib/TestMeshNodeSearch.cpp @@ -71,19 +71,19 @@ TEST_F(MeshLibMeshNodeSearchInSimpleQuadMesh, PointSearchEpsHalfEdge) std::move(search_length), MeshGeoToolsLib::SearchAllNodes::Yes); GeoLib::Point p1(0.0, 0.0, 0.0); - EXPECT_EQ(1u, mesh_node_searcher.getMeshNodeIDsForPoint(p1).size()); - EXPECT_EQ(0u, mesh_node_searcher.getMeshNodeIDsForPoint(p1)[0]); + EXPECT_EQ(1u, mesh_node_searcher.getMeshNodeIDs(p1).size()); + EXPECT_EQ(0u, mesh_node_searcher.getMeshNodeIDs(p1)[0]); GeoLib::Point p2(dx_half*0.99, 0.0, 0.0); - EXPECT_EQ(1u, mesh_node_searcher.getMeshNodeIDsForPoint(p2).size()); - EXPECT_EQ(0u, mesh_node_searcher.getMeshNodeIDsForPoint(p2)[0]); + EXPECT_EQ(1u, mesh_node_searcher.getMeshNodeIDs(p2).size()); + EXPECT_EQ(0u, mesh_node_searcher.getMeshNodeIDs(p2)[0]); GeoLib::Point p3(dx_half, 0.0, 0.0); - EXPECT_EQ(0u, mesh_node_searcher.getMeshNodeIDsForPoint(p3).size()); + EXPECT_EQ(0u, mesh_node_searcher.getMeshNodeIDs(p3).size()); GeoLib::Point p4(dx_half*1.01, 0.0, 0.0); - ASSERT_EQ(1u, mesh_node_searcher.getMeshNodeIDsForPoint(p4).size()); - ASSERT_EQ(1u, mesh_node_searcher.getMeshNodeIDsForPoint(p4)[0]); + ASSERT_EQ(1u, mesh_node_searcher.getMeshNodeIDs(p4).size()); + ASSERT_EQ(1u, mesh_node_searcher.getMeshNodeIDs(p4)[0]); } TEST_F(MeshLibMeshNodeSearchInSimpleQuadMesh, PointSearchZeroEps) @@ -93,30 +93,30 @@ TEST_F(MeshLibMeshNodeSearchInSimpleQuadMesh, PointSearchZeroEps) // 2 perform search and compare results with expected vals auto search_length = std::make_unique<MeshGeoToolsLib::SearchLength>(); - MeshGeoToolsLib::MeshNodeSearcher mesh_node_searcher(*_quad_mesh, - std::move(search_length), MeshGeoToolsLib::SearchAllNodes::Yes); + MeshGeoToolsLib::MeshNodeSearcher mesh_node_searcher( + *_quad_mesh, std::move(search_length), + MeshGeoToolsLib::SearchAllNodes::Yes); // find ORIGIN GeoLib::Point pnt1(0.0, 0.0, 0.0); - ASSERT_EQ(0u, mesh_node_searcher.getMeshNodeIDsForPoint(pnt1)[0]); + ASSERT_EQ(0u, mesh_node_searcher.getMeshNodeIDs(pnt1)[0]); GeoLib::Point pnt2(0.049, 0.049, 0.0); - ASSERT_EQ(0u, mesh_node_searcher.getMeshNodeIDsForPoint(pnt2).size()); + ASSERT_EQ(0u, mesh_node_searcher.getMeshNodeIDs(pnt2).size()); GeoLib::Point pnt3(0.051, 0.049, 0.0); - ASSERT_EQ(0u, mesh_node_searcher.getMeshNodeIDsForPoint(pnt3).size()); + ASSERT_EQ(0u, mesh_node_searcher.getMeshNodeIDs(pnt3).size()); GeoLib::Point pnt4(0.049, 0.051, 0.0); - ASSERT_EQ(0u, mesh_node_searcher.getMeshNodeIDsForPoint(pnt4).size()); + ASSERT_EQ(0u, mesh_node_searcher.getMeshNodeIDs(pnt4).size()); GeoLib::Point pnt5(0.051, 0.051, 0.0); - ASSERT_EQ(0u, mesh_node_searcher.getMeshNodeIDsForPoint(pnt5).size()); + ASSERT_EQ(0u, mesh_node_searcher.getMeshNodeIDs(pnt5).size()); GeoLib::Point pnt6(10, 10, 0.0); - ASSERT_EQ(1u, mesh_node_searcher.getMeshNodeIDsForPoint(pnt6).size()); - EXPECT_EQ( - pow(_number_of_subdivisions_per_direction+1,2)-1, - mesh_node_searcher.getMeshNodeIDsForPoint(pnt6)[0]); + ASSERT_EQ(1u, mesh_node_searcher.getMeshNodeIDs(pnt6).size()); + EXPECT_EQ(pow(_number_of_subdivisions_per_direction + 1, 2) - 1, + mesh_node_searcher.getMeshNodeIDs(pnt6)[0]); } TEST_F(MeshLibMeshNodeSearchInSimpleQuadMesh, PolylineSearch) @@ -131,7 +131,8 @@ TEST_F(MeshLibMeshNodeSearchInSimpleQuadMesh, PolylineSearch) pnts.push_back(new GeoLib::Point(0.0, _geometric_size, 0.0)); pnts.push_back(new GeoLib::Point(_geometric_size, _geometric_size, 0.0)); pnts.push_back(new GeoLib::Point(0.0, _geometric_size - 0.049, 0.0)); - pnts.push_back(new GeoLib::Point(_geometric_size, _geometric_size - 0.049, 0.0)); + pnts.push_back( + new GeoLib::Point(_geometric_size, _geometric_size - 0.049, 0.0)); GeoLib::Polyline ply0(pnts); ply0.addPoint(0); @@ -140,9 +141,11 @@ TEST_F(MeshLibMeshNodeSearchInSimpleQuadMesh, PolylineSearch) // perform search and compare results with expected vals auto search_length = std::make_unique<MeshGeoToolsLib::HeuristicSearchLength>(*_quad_mesh); - MeshGeoToolsLib::MeshNodeSearcher mesh_node_searcher(*_quad_mesh, - std::move(search_length), MeshGeoToolsLib::SearchAllNodes::Yes); - std::vector<std::size_t> const& found_ids_ply0(mesh_node_searcher.getMeshNodeIDsAlongPolyline(ply0)); + MeshGeoToolsLib::MeshNodeSearcher mesh_node_searcher( + *_quad_mesh, std::move(search_length), + MeshGeoToolsLib::SearchAllNodes::Yes); + std::vector<std::size_t> const& found_ids_ply0( + mesh_node_searcher.getMeshNodeIDs(ply0)); ASSERT_EQ(100u, found_ids_ply0.size()); for (std::size_t k(0); k < found_ids_ply0.size(); k++) @@ -153,7 +156,8 @@ TEST_F(MeshLibMeshNodeSearchInSimpleQuadMesh, PolylineSearch) GeoLib::Polyline ply1(pnts); ply1.addPoint(2); ply1.addPoint(3); - std::vector<std::size_t> const& found_ids_ply1(mesh_node_searcher.getMeshNodeIDsAlongPolyline(ply1)); + std::vector<std::size_t> const& found_ids_ply1( + mesh_node_searcher.getMeshNodeIDs(ply1)); ASSERT_EQ(100u, found_ids_ply1.size()); for (std::size_t k(0); k < found_ids_ply1.size(); k++) @@ -164,9 +168,11 @@ TEST_F(MeshLibMeshNodeSearchInSimpleQuadMesh, PolylineSearch) GeoLib::Polyline ply2(pnts); ply2.addPoint(4); ply2.addPoint(5); - std::vector<std::size_t> const& found_ids_ply2(mesh_node_searcher.getMeshNodeIDsAlongPolyline(ply2)); + std::vector<std::size_t> const& found_ids_ply2( + mesh_node_searcher.getMeshNodeIDs(ply2)); - std::size_t offset((_number_of_subdivisions_per_direction+1)*_number_of_subdivisions_per_direction); + 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++) { @@ -176,7 +182,8 @@ TEST_F(MeshLibMeshNodeSearchInSimpleQuadMesh, PolylineSearch) GeoLib::Polyline ply3(pnts); ply3.addPoint(6); ply3.addPoint(7); - std::vector<std::size_t> const& found_ids_ply3(mesh_node_searcher.getMeshNodeIDsAlongPolyline(ply3)); + std::vector<std::size_t> const& found_ids_ply3( + mesh_node_searcher.getMeshNodeIDs(ply3)); ASSERT_EQ(100u, found_ids_ply3.size()); for (std::size_t k(0); k < found_ids_ply3.size(); k++) @@ -188,7 +195,8 @@ TEST_F(MeshLibMeshNodeSearchInSimpleQuadMesh, PolylineSearch) GeoLib::Polyline ply4(pnts); ply4.addPoint(0); ply4.addPoint(6); - std::vector<std::size_t> const& found_ids_ply4(mesh_node_searcher.getMeshNodeIDsAlongPolyline(ply4)); + std::vector<std::size_t> const& found_ids_ply4( + mesh_node_searcher.getMeshNodeIDs(ply4)); ASSERT_EQ(100u, found_ids_ply4.size()); for (std::size_t k(0); k < found_ids_ply4.size(); k++) @@ -201,7 +209,8 @@ TEST_F(MeshLibMeshNodeSearchInSimpleQuadMesh, PolylineSearch) GeoLib::Polyline ply5(pnts); ply5.addPoint(1); ply5.addPoint(7); - std::vector<std::size_t> const& found_ids_ply5(mesh_node_searcher.getMeshNodeIDsAlongPolyline(ply5)); + std::vector<std::size_t> const& found_ids_ply5( + mesh_node_searcher.getMeshNodeIDs(ply5)); ASSERT_EQ(100u, found_ids_ply5.size()); for (std::size_t k(0); k < found_ids_ply5.size(); k++) @@ -215,7 +224,8 @@ TEST_F(MeshLibMeshNodeSearchInSimpleQuadMesh, PolylineSearch) GeoLib::Polyline ply6(pnts); ply6.addPoint(0); ply6.addPoint(5); - std::vector<std::size_t> const& found_ids_ply6(mesh_node_searcher.getMeshNodeIDsAlongPolyline(ply6)); + std::vector<std::size_t> const& found_ids_ply6( + mesh_node_searcher.getMeshNodeIDs(ply6)); ASSERT_EQ(100u, found_ids_ply6.size()); for (std::size_t k(0); k < found_ids_ply6.size(); k++) @@ -224,7 +234,8 @@ TEST_F(MeshLibMeshNodeSearchInSimpleQuadMesh, PolylineSearch) found_ids_ply6[k]); } - std::for_each(pnts.begin(), pnts.end(), [](GeoLib::Point* pnt) { delete pnt; }); + std::for_each(pnts.begin(), pnts.end(), + [](GeoLib::Point* pnt) { delete pnt; }); } TEST_F(MeshLibMeshNodeSearchInSimpleQuadMesh, SurfaceSearch) @@ -236,12 +247,14 @@ TEST_F(MeshLibMeshNodeSearchInSimpleQuadMesh, SurfaceSearch) pnts.push_back(new GeoLib::Point(_geometric_size, 0.0, 0.0)); pnts.push_back(new GeoLib::Point(_geometric_size, _geometric_size, 0.0)); pnts.push_back(new GeoLib::Point(0.0, _geometric_size, 0.0)); - pnts.push_back(new GeoLib::Point(_geometric_size, 0.5*_geometric_size, 0.0)); - pnts.push_back(new GeoLib::Point(0.0, 0.5*_geometric_size, 0.0)); + pnts.push_back( + new GeoLib::Point(_geometric_size, 0.5 * _geometric_size, 0.0)); + pnts.push_back(new GeoLib::Point(0.0, 0.5 * _geometric_size, 0.0)); auto search_length = std::make_unique<MeshGeoToolsLib::SearchLength>(); - MeshGeoToolsLib::MeshNodeSearcher mesh_node_searcher(*_quad_mesh, - std::move(search_length), MeshGeoToolsLib::SearchAllNodes::Yes); + MeshGeoToolsLib::MeshNodeSearcher mesh_node_searcher( + *_quad_mesh, std::move(search_length), + MeshGeoToolsLib::SearchAllNodes::Yes); // entire domain GeoLib::Surface sfc0(pnts); @@ -249,7 +262,7 @@ TEST_F(MeshLibMeshNodeSearchInSimpleQuadMesh, SurfaceSearch) sfc0.addTriangle(0, 2, 3); std::vector<std::size_t> const& found_ids_sfc0( - mesh_node_searcher.getMeshNodeIDsAlongSurface(sfc0)); + mesh_node_searcher.getMeshNodeIDs(sfc0)); ASSERT_EQ(_quad_mesh->getNumberOfNodes(), found_ids_sfc0.size()); for (std::size_t k(0); k < found_ids_sfc0.size(); k++) @@ -263,15 +276,16 @@ TEST_F(MeshLibMeshNodeSearchInSimpleQuadMesh, SurfaceSearch) sfc1.addTriangle(0, 4, 5); std::vector<std::size_t> const& found_ids_sfc1( - mesh_node_searcher.getMeshNodeIDsAlongSurface(sfc1)); + mesh_node_searcher.getMeshNodeIDs(sfc1)); - ASSERT_EQ(_quad_mesh->getNumberOfNodes()/2, found_ids_sfc1.size()); + ASSERT_EQ(_quad_mesh->getNumberOfNodes() / 2, found_ids_sfc1.size()); 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; }); + std::for_each(pnts.begin(), pnts.end(), + [](GeoLib::Point* pnt) { delete pnt; }); } TEST_F(MeshLibMeshNodeSearchInSimpleHexMesh, SurfaceSearch) @@ -302,7 +316,7 @@ TEST_F(MeshLibMeshNodeSearchInSimpleHexMesh, SurfaceSearch) sfc_bottom.addTriangle(0, 2, 3); std::vector<std::size_t> const& found_ids_sfc_b( - mesh_node_searcher.getMeshNodeIDsAlongSurface(sfc_bottom)); + mesh_node_searcher.getMeshNodeIDs(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++) { @@ -315,7 +329,7 @@ TEST_F(MeshLibMeshNodeSearchInSimpleHexMesh, SurfaceSearch) sfc_top.addTriangle(4, 6, 7); std::vector<std::size_t> const& found_ids_sfc_t( - mesh_node_searcher.getMeshNodeIDsAlongSurface(sfc_top)); + mesh_node_searcher.getMeshNodeIDs(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++) @@ -329,7 +343,7 @@ TEST_F(MeshLibMeshNodeSearchInSimpleHexMesh, SurfaceSearch) sfc_front.addTriangle(0, 5, 4); std::vector<std::size_t> const& found_ids_sfc_f( - mesh_node_searcher.getMeshNodeIDsAlongSurface(sfc_front)); + mesh_node_searcher.getMeshNodeIDs(sfc_front)); 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++) { @@ -345,7 +359,7 @@ TEST_F(MeshLibMeshNodeSearchInSimpleHexMesh, SurfaceSearch) sfc_back.addTriangle(3, 6, 7); std::vector<std::size_t> const& found_ids_sfc_back( - mesh_node_searcher.getMeshNodeIDsAlongSurface(sfc_back)); + mesh_node_searcher.getMeshNodeIDs(sfc_back)); ASSERT_EQ(n_nodes_2d, found_ids_sfc_back.size()); cnt = 0; const std::size_t y_offset = n_nodes_1d*(n_nodes_1d-1); @@ -363,7 +377,7 @@ TEST_F(MeshLibMeshNodeSearchInSimpleHexMesh, SurfaceSearch) sfc_left.addTriangle(0, 7, 4); std::vector<std::size_t> const& found_ids_sfc_left( - mesh_node_searcher.getMeshNodeIDsAlongSurface(sfc_left)); + mesh_node_searcher.getMeshNodeIDs(sfc_left)); ASSERT_EQ(n_nodes_2d, found_ids_sfc_left.size()); cnt = 0; for (std::size_t k(0); k<n_nodes_1d; k++) { @@ -380,7 +394,7 @@ TEST_F(MeshLibMeshNodeSearchInSimpleHexMesh, SurfaceSearch) sfc_right.addTriangle(1, 6, 5); std::vector<std::size_t> const& found_ids_sfc_right( - mesh_node_searcher.getMeshNodeIDsAlongSurface(sfc_right)); + mesh_node_searcher.getMeshNodeIDs(sfc_right)); ASSERT_EQ(n_nodes_2d, found_ids_sfc_right.size()); cnt = 0; for (std::size_t k(0); k<n_nodes_1d; k++) { diff --git a/Tests/MeshLib/TestQuadMesh.cpp b/Tests/MeshLib/TestQuadMesh.cpp index b4047400679e7d0af6a55f4c05c3fa3a97ad333e..47eee78feaf2f051d132d690de1b5ec24a25f3d8 100644 --- a/Tests/MeshLib/TestQuadMesh.cpp +++ b/Tests/MeshLib/TestQuadMesh.cpp @@ -9,6 +9,8 @@ #include <ctime> #include <iterator> +#include <list> + #include "gtest/gtest.h" #include "MeshLib/MeshGenerators/MeshGenerator.h" diff --git a/Tests/MeshLib/TestVtkMappedMeshSource.cpp b/Tests/MeshLib/TestVtkMappedMeshSource.cpp index 1c8d8320a17de39ae8d6209ca74d4b2cc2f4f566..ac67bcdd5676a3942889d77d60ef8f175b1d42bf 100644 --- a/Tests/MeshLib/TestVtkMappedMeshSource.cpp +++ b/Tests/MeshLib/TestVtkMappedMeshSource.cpp @@ -12,29 +12,28 @@ * */ -#include "InfoLib/TestInfo.h" +#include <vtkCellData.h> +#include <vtkNew.h> +#include <vtkPointData.h> +#include <vtkSmartPointer.h> +#include <vtkUnstructuredGrid.h> +#include <vtkXMLUnstructuredGridReader.h> +#include <vtkXMLUnstructuredGridWriter.h> #include <memory> #include <numeric> -#include "filesystem.h" -#include "MeshLib/IO/VtkIO/VtuInterface.h" +#include "BaseLib/StringTools.h" +#include "InfoLib/TestInfo.h" #include "MeshLib/Elements/Element.h" +#include "MeshLib/IO/VtkIO/VtuInterface.h" #include "MeshLib/Mesh.h" #include "MeshLib/MeshGenerators/MeshGenerator.h" #include "MeshLib/MeshGenerators/VtkMeshConverter.h" #include "MeshLib/Vtk/VtkMappedMeshSource.h" - +#include "filesystem.h" #include "gtest/gtest.h" -#include <vtkNew.h> -#include <vtkUnstructuredGrid.h> -#include <vtkSmartPointer.h> -#include <vtkXMLUnstructuredGridWriter.h> -#include <vtkXMLUnstructuredGridReader.h> -#include <vtkCellData.h> -#include <vtkPointData.h> - // Creates a mesh with different types of data (double, int, etc.) and point, // cell, or integration point properties. class InSituMesh : public ::testing::Test