diff --git a/Applications/ApplicationsLib/ProjectData.cpp b/Applications/ApplicationsLib/ProjectData.cpp index d0e92051910bcdb15db524a33f597647049d1b55..c0c51678af7ebdfad859393025e93ecb631b3d93 100644 --- a/Applications/ApplicationsLib/ProjectData.cpp +++ b/Applications/ApplicationsLib/ProjectData.cpp @@ -41,7 +41,6 @@ // FileIO #include "GeoLib/IO/XmlIO/Boost/BoostXmlGmlInterface.h" #include "MeshLib/IO/readMeshFromFile.h" - #include "ParameterLib/ConstantParameter.h" #include "ParameterLib/Utils.h" #include "ProcessLib/CreateTimeLoop.h" diff --git a/Applications/ApplicationsLib/TestDefinition.cpp b/Applications/ApplicationsLib/TestDefinition.cpp index 342e58d2dee4ebe6bd11e75f8371877eb0978f1f..3fb1a415682d38ee146e061fd0246efb63252819 100644 --- a/Applications/ApplicationsLib/TestDefinition.cpp +++ b/Applications/ApplicationsLib/TestDefinition.cpp @@ -21,8 +21,9 @@ #include "BaseLib/FileTools.h" #include "filesystem.h" #ifdef USE_PETSC -#include "MeshLib/IO/VtkIO/VtuInterface.h" // For petsc file name conversion. #include <petsc.h> + +#include "MeshLib/IO/VtkIO/VtuInterface.h" // For petsc file name conversion. #endif namespace @@ -168,13 +169,14 @@ TestDefinition::TestDefinition(BaseLib::ConfigTree const& config_tree, std::vector<std::string> filenames; if (auto const regex_string = - //! \ogs_file_param{prj__test_definition__vtkdiff__regex} + //! \ogs_file_param{prj__test_definition__vtkdiff__regex} vtkdiff_config.getConfigParameterOptional<std::string>("regex")) { // TODO: insert rank into regex for mpi case DBUG("vtkdiff regex is '{}'.", *regex_string); auto const regex = std::regex(*regex_string); - for (auto const & p: fs::directory_iterator(fs::path(reference_path))) + for (auto const& p : + fs::directory_iterator(fs::path(reference_path))) { auto const filename = p.path().filename().string(); if (std::regex_match(filename, regex)) @@ -242,7 +244,7 @@ TestDefinition::TestDefinition(BaseLib::ConfigTree const& config_tree, std::string const relative_tolerance_parameter = "--rel " + relative_tolerance; - for (auto const &filename : filenames) + for (auto const& filename : filenames) { std::string const& output_filename = BaseLib::joinPaths(output_directory, filename); @@ -257,7 +259,8 @@ TestDefinition::TestDefinition(BaseLib::ConfigTree const& config_tree, vtkdiff + " -a " + safeString(field_name) + " -b " + safeString(field_name) + " " + safeString(reference_filename) + " " + safeString(output_filename) + " " + - absolute_tolerance_parameter + " " + relative_tolerance_parameter; + absolute_tolerance_parameter + " " + + relative_tolerance_parameter; INFO("Will run '{:s}'", command_line); _command_lines.emplace_back(std::move(command_line)); } diff --git a/Applications/CLI/ogs.cpp b/Applications/CLI/ogs.cpp index 72a5c732cfa4daabc6817de3f157b1ee623be8d8..acb119cc14418b4f75a4c3dbf2fd7a98250f6f87 100644 --- a/Applications/CLI/ogs.cpp +++ b/Applications/CLI/ogs.cpp @@ -29,20 +29,18 @@ #endif // BaseLib -#include "BaseLib/ConfigTreeUtil.h" -#include "BaseLib/DateTools.h" -#include "BaseLib/FileTools.h" -#include "BaseLib/RunTime.h" - #include "Applications/ApplicationsLib/LinearSolverLibrarySetup.h" #include "Applications/ApplicationsLib/ProjectData.h" #include "Applications/ApplicationsLib/TestDefinition.h" #include "Applications/InSituLib/Adaptor.h" +#include "BaseLib/ConfigTreeUtil.h" +#include "BaseLib/DateTools.h" +#include "BaseLib/FileTools.h" +#include "BaseLib/RunTime.h" #include "InfoLib/CMakeInfo.h" #include "InfoLib/GitInfo.h" -#include "ProcessLib/TimeLoop.h" - #include "NumLib/NumericsConfig.h" +#include "ProcessLib/TimeLoop.h" #ifdef OGS_USE_PYTHON #include "ogs_embedded_python.h" @@ -60,8 +58,7 @@ int main(int argc, char* argv[]) "http://www.opengeosys.org/project/license\n" "version: " + GitInfoLib::GitInfo::ogs_version + "\n" + - "CMake arguments: " + - CMakeInfoLib::CMakeInfo::cmake_args, + "CMake arguments: " + CMakeInfoLib::CMakeInfo::cmake_args, ' ', GitInfoLib::GitInfo::ogs_version); @@ -174,7 +171,7 @@ int main(int argc, char* argv[]) controller->Initialize(&argc, &argv, 1); vtkMPIController::SetGlobalController(controller); - { // Can be called only after MPI_INIT. + { // Can be called only after MPI_INIT. int mpi_rank; MPI_Comm_rank(PETSC_COMM_WORLD, &mpi_rank); spdlog::set_pattern(fmt::format("[{}] %^%l:%$ %v", mpi_rank)); @@ -205,7 +202,7 @@ int main(int argc, char* argv[]) project_config->getConfigSubtree("test_definition"), reference_path_arg.getValue(), outdir_arg.getValue()); - if( test_definition->numberOfTests() == 0) + if (test_definition->numberOfTests() == 0) { OGS_FATAL( "No tests were constructed from the test definitions, " diff --git a/Applications/CLI/ogs_embedded_python.cpp b/Applications/CLI/ogs_embedded_python.cpp index cd0c28d234d7f546e5cac8f9c3fec6cd6db245a8..5c170cfe98a2596a178b76f9b0e990e0bb7a7b50 100644 --- a/Applications/CLI/ogs_embedded_python.cpp +++ b/Applications/CLI/ogs_embedded_python.cpp @@ -12,7 +12,6 @@ #include <pybind11/embed.h> #include "BaseLib/Logging.h" - #include "ProcessLib/BoundaryCondition/Python/BHEInflowPythonBoundaryConditionModule.h" #include "ProcessLib/BoundaryCondition/Python/PythonBoundaryConditionModule.h" #include "ProcessLib/SourceTerms/Python/PythonSourceTermModule.h" diff --git a/Applications/DataHolderLib/Color.cpp b/Applications/DataHolderLib/Color.cpp index 7b57ded696021d58fff54a842518aa4b9873be84..fe1e1ae5fb7c9937f71e26a22fd8c6df458003f1 100644 --- a/Applications/DataHolderLib/Color.cpp +++ b/Applications/DataHolderLib/Color.cpp @@ -16,11 +16,14 @@ #include "BaseLib/Logging.h" -namespace DataHolderLib { - -Color createColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a) +namespace DataHolderLib +{ +Color createColor(unsigned char r, + unsigned char g, + unsigned char b, + unsigned char a) { - return Color{{r,g,b,a}}; + return Color{{r, g, b, a}}; } Color getRandomColor() diff --git a/Applications/DataHolderLib/ColorLookupTable.cpp b/Applications/DataHolderLib/ColorLookupTable.cpp index 418d4cf269a3d38915f91bf4d4a2dbaa211c9d86..4af25187674c1959f3d10ef31918d9f320bf634d 100644 --- a/Applications/DataHolderLib/ColorLookupTable.cpp +++ b/Applications/DataHolderLib/ColorLookupTable.cpp @@ -18,7 +18,8 @@ ColorLookupTable::ColorLookupTable() std::make_pair<double, double>(std::numeric_limits<double>::lowest(), std::numeric_limits<double>::max())) -{} +{ +} void ColorLookupTable::setTableRange(double min, double max) { @@ -36,7 +37,8 @@ void ColorLookupTable::setColor(double id, DataHolderLib::Color const& color) } } -void ColorLookupTable::setColor(std::string const& name, DataHolderLib::Color const& color) +void ColorLookupTable::setColor(std::string const& name, + DataHolderLib::Color const& color) { _lut.emplace_back(0, color, name); } diff --git a/Applications/DataHolderLib/Project.cpp b/Applications/DataHolderLib/Project.cpp index e4b8b2580917a01a2ae9265b0397159eced3e53b..8a365abf1a14b9d451d7952da5c05a44209c57d6 100644 --- a/Applications/DataHolderLib/Project.cpp +++ b/Applications/DataHolderLib/Project.cpp @@ -18,7 +18,6 @@ namespace DataHolderLib { - void Project::addMesh(std::unique_ptr<MeshLib::Mesh> mesh) { std::string name = mesh->getName(); @@ -33,21 +32,22 @@ Project::findMeshByName(std::string const& name) const return const_cast<Project&>(*this).findMeshByName(name); } -std::vector<std::unique_ptr<MeshLib::Mesh>>::iterator -Project::findMeshByName(std::string const& name) +std::vector<std::unique_ptr<MeshLib::Mesh>>::iterator Project::findMeshByName( + std::string const& name) { return std::find_if(_mesh_vec.begin(), _mesh_vec.end(), - [&name](std::unique_ptr<MeshLib::Mesh> & mesh) - { return mesh && (name == mesh->getName()); }); + [&name](std::unique_ptr<MeshLib::Mesh>& mesh) { + return mesh && (name == mesh->getName()); + }); } -const MeshLib::Mesh* Project::getMesh(const std::string &name) const +const MeshLib::Mesh* Project::getMesh(const std::string& name) const { auto it = findMeshByName(name); return (it == _mesh_vec.end() ? nullptr : it->get()); } -bool Project::removeMesh(const std::string &name) +bool Project::removeMesh(const std::string& name) { auto it = findMeshByName(name); if (it != _mesh_vec.end()) @@ -59,7 +59,7 @@ bool Project::removeMesh(const std::string &name) return false; } -bool Project::getUniqueName(std::string &name) const +bool Project::getUniqueName(std::string& name) const { int count(0); bool isUnique(false); @@ -71,8 +71,8 @@ bool Project::getUniqueName(std::string &name) const 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 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); @@ -88,8 +88,8 @@ bool Project::getUniqueName(std::string &name) const } // 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 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; diff --git a/Applications/FileIO/AsciiRasterInterface.cpp b/Applications/FileIO/AsciiRasterInterface.cpp index 0ccbff1fbdddffa3772dee0b5160fe7cd21f8742..feb49a25d1e4deeeb3dc25cb28d514b5fa7247a2 100644 --- a/Applications/FileIO/AsciiRasterInterface.cpp +++ b/Applications/FileIO/AsciiRasterInterface.cpp @@ -22,10 +22,9 @@ namespace FileIO { - GeoLib::Raster* AsciiRasterInterface::readRaster(std::string const& fname) { - std::string ext (BaseLib::getFileExtension(fname)); + std::string ext(BaseLib::getFileExtension(fname)); std::transform(ext.begin(), ext.end(), ext.begin(), tolower); if (ext == ".asc") { @@ -38,11 +37,13 @@ GeoLib::Raster* AsciiRasterInterface::readRaster(std::string const& fname) return nullptr; } -GeoLib::Raster* AsciiRasterInterface::getRasterFromASCFile(std::string const& fname) +GeoLib::Raster* AsciiRasterInterface::getRasterFromASCFile( + std::string const& fname) { std::ifstream in(fname.c_str()); - if (!in.is_open()) { + if (!in.is_open()) + { WARN("Raster::getRasterFromASCFile(): Could not open file {:s}.", fname); return nullptr; @@ -50,13 +51,16 @@ GeoLib::Raster* AsciiRasterInterface::getRasterFromASCFile(std::string const& fn // header information GeoLib::RasterHeader header; - if (readASCHeader(in, header)) { + if (readASCHeader(in, header)) + { std::vector<double> values(header.n_cols * header.n_rows); std::string s; // read the data into the double-array - for (std::size_t j(0); j < header.n_rows; ++j) { - const std::size_t idx ((header.n_rows - j - 1) * header.n_cols); - for (std::size_t i(0); i < header.n_cols; ++i) { + for (std::size_t j(0); j < header.n_rows; ++j) + { + const std::size_t idx((header.n_rows - j - 1) * header.n_cols); + for (std::size_t i(0); i < header.n_cols; ++i) + { in >> s; values[idx + i] = strtod( BaseLib::replaceString(",", ".", s).c_str(), nullptr); @@ -73,7 +77,8 @@ GeoLib::Raster* AsciiRasterInterface::getRasterFromASCFile(std::string const& fn return nullptr; } -bool AsciiRasterInterface::readASCHeader(std::ifstream &in, GeoLib::RasterHeader &header) +bool AsciiRasterInterface::readASCHeader(std::ifstream& in, + GeoLib::RasterHeader& header) { std::string tag; std::string value; @@ -154,11 +159,13 @@ bool AsciiRasterInterface::readASCHeader(std::ifstream &in, GeoLib::RasterHeader return true; } -GeoLib::Raster* AsciiRasterInterface::getRasterFromSurferFile(std::string const& fname) +GeoLib::Raster* AsciiRasterInterface::getRasterFromSurferFile( + std::string const& fname) { std::ifstream in(fname.c_str()); - if (!in.is_open()) { + if (!in.is_open()) + { ERR("Raster::getRasterFromSurferFile() - Could not open file {:s}", fname); return nullptr; @@ -171,19 +178,19 @@ GeoLib::Raster* AsciiRasterInterface::getRasterFromSurferFile(std::string const& if (readSurferHeader(in, header, min, max)) { - const double no_data_val (min-1); + const double no_data_val(min - 1); std::vector<double> values(header.n_cols * header.n_rows); std::string s; // read the data into the double-array for (std::size_t j(0); j < header.n_rows; ++j) { - const std::size_t idx (j * header.n_cols); + const std::size_t idx(j * header.n_cols); for (std::size_t i(0); i < header.n_cols; ++i) { in >> s; const double val(strtod( BaseLib::replaceString(",", ".", s).c_str(), nullptr)); - values[idx+i] = (val > max || val < min) ? no_data_val : val; + values[idx + i] = (val > max || val < min) ? no_data_val : val; } } in.close(); @@ -197,8 +204,9 @@ GeoLib::Raster* AsciiRasterInterface::getRasterFromSurferFile(std::string const& return nullptr; } -bool AsciiRasterInterface::readSurferHeader( - std::ifstream &in, GeoLib::RasterHeader &header, double &min, double &max) +bool AsciiRasterInterface::readSurferHeader(std::ifstream& in, + GeoLib::RasterHeader& header, + double& min, double& max) { std::string tag; @@ -236,12 +244,13 @@ bool AsciiRasterInterface::readSurferHeader( return true; } -void AsciiRasterInterface::writeRasterAsASC(GeoLib::Raster const& raster, std::string const& file_name) +void AsciiRasterInterface::writeRasterAsASC(GeoLib::Raster const& raster, + std::string const& file_name) { - GeoLib::RasterHeader header (raster.getHeader()); - MathLib::Point3d const& origin (header.origin); - unsigned const nCols (header.n_cols); - unsigned const nRows (header.n_rows); + GeoLib::RasterHeader header(raster.getHeader()); + MathLib::Point3d const& origin(header.origin); + unsigned const nCols(header.n_cols); + unsigned const nRows(header.n_rows); // write header std::ofstream out(file_name); @@ -251,15 +260,15 @@ void AsciiRasterInterface::writeRasterAsASC(GeoLib::Raster const& raster, std::s out.precision(std::numeric_limits<double>::digits10); out << "xllcorner " << origin[0] << "\n"; out << "yllcorner " << origin[1] << "\n"; - out << "cellsize " << header.cell_size << "\n"; + out << "cellsize " << header.cell_size << "\n"; out.precision(default_precision); out << "NODATA_value " << header.no_data << "\n"; // write data - double const*const elevation(raster.begin()); + double const* const elevation(raster.begin()); for (unsigned row(0); row < nRows; ++row) { - for (unsigned col(0); col < nCols-1; ++col) + for (unsigned col(0); col < nCols - 1; ++col) { out << elevation[(nRows - row - 1) * nCols + col] << " "; } @@ -268,7 +277,6 @@ void AsciiRasterInterface::writeRasterAsASC(GeoLib::Raster const& raster, std::s out.close(); } - /// Checks if all raster files actually exist static bool allRastersExist(std::vector<std::string> const& raster_paths) { @@ -300,4 +308,4 @@ std::optional<std::vector<GeoLib::Raster const*>> readRasters( }); return std::make_optional(rasters); } -} // end namespace FileIO +} // end namespace FileIO diff --git a/Applications/FileIO/FEFLOW/FEFLOWGeoInterface.cpp b/Applications/FileIO/FEFLOW/FEFLOWGeoInterface.cpp index 3bc29ae86d17a08cfcd3d6716f05699bf616ac9b..0e2ab79a91390535f03df0226316f580b4d30736 100644 --- a/Applications/FileIO/FEFLOW/FEFLOWGeoInterface.cpp +++ b/Applications/FileIO/FEFLOW/FEFLOWGeoInterface.cpp @@ -8,20 +8,16 @@ #include "FEFLOWGeoInterface.h" -#include <cctype> -#include <memory> - -#include <boost/algorithm/string/trim.hpp> - #include <QDomElement> #include <QString> #include <QtXml/QDomDocument> - -#include "BaseLib/Logging.h" +#include <boost/algorithm/string/trim.hpp> +#include <cctype> +#include <memory> #include "BaseLib/FileTools.h" +#include "BaseLib/Logging.h" #include "BaseLib/StringTools.h" - #include "GeoLib/GEOObjects.h" #include "GeoLib/Point.h" #include "GeoLib/Polygon.h" diff --git a/Applications/FileIO/FEFLOW/FEFLOWMeshInterface.cpp b/Applications/FileIO/FEFLOW/FEFLOWMeshInterface.cpp index 4d5f32195810263e2dd055e7f01e2539963db8c8..fcbbd9f1d1cbe62029c29c064c596c09a6b36d41 100644 --- a/Applications/FileIO/FEFLOW/FEFLOWMeshInterface.cpp +++ b/Applications/FileIO/FEFLOW/FEFLOWMeshInterface.cpp @@ -8,20 +8,16 @@ #include "FEFLOWMeshInterface.h" +#include <boost/algorithm/string/trim.hpp> #include <cctype> #include <memory> -#include <boost/algorithm/string/trim.hpp> - -#include "BaseLib/Logging.h" - +#include "Applications/FileIO/FEFLOW/FEFLOWGeoInterface.h" #include "BaseLib/FileTools.h" +#include "BaseLib/Logging.h" #include "BaseLib/StringTools.h" - -#include "Applications/FileIO/FEFLOW/FEFLOWGeoInterface.h" #include "GeoLib/Point.h" #include "GeoLib/Polygon.h" - #include "MeshLib/Elements/Elements.h" #include "MeshLib/Mesh.h" #include "MeshLib/Node.h" @@ -86,10 +82,9 @@ MeshLib::Mesh* FEFLOWMeshInterface::readFEFLOWFile(const std::string& filename) vec_nodes.resize(fem_dim.n_nodes); std::size_t count = 0; double dummy_coords[3] = {}; - std::generate(vec_nodes.begin(), vec_nodes.end(), [&]() - { - return new MeshLib::Node(dummy_coords, count++); - }); + std::generate(vec_nodes.begin(), vec_nodes.end(), [&]() { + return new MeshLib::Node(dummy_coords, count++); + }); line_stream.clear(); } //.................................................................... @@ -134,10 +129,7 @@ MeshLib::Mesh* FEFLOWMeshInterface::readFEFLOWFile(const std::string& filename) "type with the number of node = {:d} and dim = {:d}", fem_dim.n_nodes_of_element, fem_class.dimension); std::for_each(vec_nodes.begin(), vec_nodes.end(), - [](MeshLib::Node* nod) - { - delete nod; - }); + [](MeshLib::Node* nod) { delete nod; }); vec_nodes.clear(); return nullptr; } @@ -171,8 +163,7 @@ MeshLib::Mesh* FEFLOWMeshInterface::readFEFLOWFile(const std::string& filename) for (std::size_t i = 0; i < fem_dim.n_elements; i++) { std::getline(in, line_string); - vec_elements.push_back( - readElement(line_string, vec_nodes)); + vec_elements.push_back(readElement(line_string, vec_nodes)); } } //.................................................................... @@ -219,8 +210,8 @@ MeshLib::Mesh* FEFLOWMeshInterface::readFEFLOWFile(const std::string& filename) // SUPERMESH else if (line_string == "SUPERMESH") { - FileIO::FEFLOWGeoInterface::readSuperMesh( - in, fem_class.dimension, points, lines); + FileIO::FEFLOWGeoInterface::readSuperMesh(in, fem_class.dimension, + points, lines); } //.................................................................... } @@ -614,8 +605,7 @@ MeshLib::Element* FEFLOWMeshInterface::readElement( void FEFLOWMeshInterface::readELEMENTALSETS( std::ifstream& in, std::vector<std::vector<std::size_t>>& vec_elementsets) { - auto compressSpaces = [](std::string const& str) - { + auto compressSpaces = [](std::string const& str) { std::stringstream ss(str); std::string new_str; std::string word; @@ -716,7 +706,7 @@ void FEFLOWMeshInterface::setMaterialIDs( std::vector<MeshLib::Element*> const& vec_elements, std::vector<int>& material_ids) { - assert(material_ids.size()==vec_elements.size()); + assert(material_ids.size() == vec_elements.size()); if (!vec_elementsets.empty()) { for (std::size_t matid = 0; matid < vec_elementsets.size(); ++matid) diff --git a/Applications/FileIO/GMSInterface.cpp b/Applications/FileIO/GMSInterface.cpp index ee76ecb75bf758cf90655d88d506fefee51ba518..3bf83e2f2961af820b20cd9e64c84506e9a9de28 100644 --- a/Applications/FileIO/GMSInterface.cpp +++ b/Applications/FileIO/GMSInterface.cpp @@ -84,8 +84,7 @@ int GMSInterface::readBoreholesFromGMS(std::vector<GeoLib::Point*>* boreholes, { if (newBorehole == nullptr) OGS_FATAL("Trying to access a nullptr."); - newBorehole->addSoilLayer( - pnt[0], pnt[1], pnt[2], sName); + newBorehole->addSoilLayer(pnt[0], pnt[1], pnt[2], sName); sName = (*(++it)); depth = pnt[2]; } @@ -278,8 +277,8 @@ MeshLib::Mesh* GMSInterface::readGMS3DMMesh(const std::string& filename) mat_ids.push_back(mat_id); } else if (element_id == "ND ") - { // Node - continue; // skip because nodes have already been read + { // Node + continue; // skip because nodes have already been read } else // default { diff --git a/Applications/FileIO/Gmsh/GMSHAdaptiveMeshDensity.cpp b/Applications/FileIO/Gmsh/GMSHAdaptiveMeshDensity.cpp index 67f6072ed11100249dc8afa84e5f8cd408087c27..0c8e72e2ed2e5e4f78b103e782fee813030946f3 100644 --- a/Applications/FileIO/Gmsh/GMSHAdaptiveMeshDensity.cpp +++ b/Applications/FileIO/Gmsh/GMSHAdaptiveMeshDensity.cpp @@ -16,14 +16,12 @@ #include <list> #include "BaseLib/Logging.h" - #include "GeoLib/Point.h" #include "GeoLib/Polygon.h" #ifndef NDEBUG #include "GeoLib/Polyline.h" #endif #include "GeoLib/QuadTree.h" - #include "MathLib/MathTools.h" namespace FileIO @@ -45,15 +43,19 @@ GMSHAdaptiveMeshDensity::~GMSHAdaptiveMeshDensity() delete _quad_tree; } -void GMSHAdaptiveMeshDensity::initialize(std::vector<GeoLib::Point const*> const& pnts) +void GMSHAdaptiveMeshDensity::initialize( + std::vector<GeoLib::Point const*> const& pnts) { // *** QuadTree - determining bounding box - DBUG("GMSHAdaptiveMeshDensity::init(): computing axis aligned bounding box (2D) for quadtree."); + DBUG( + "GMSHAdaptiveMeshDensity::init(): computing axis aligned bounding box " + "(2D) for quadtree."); GeoLib::Point min(*pnts[0]); GeoLib::Point max(*pnts[0]); std::size_t n_pnts(pnts.size()); - for (std::size_t k(1); k<n_pnts; k++) { + 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]) @@ -75,14 +77,16 @@ void GMSHAdaptiveMeshDensity::initialize(std::vector<GeoLib::Point const*> const // *** QuadTree - create object DBUG("GMSHAdaptiveMeshDensity::init(): Creating quadtree."); - _quad_tree = new GeoLib::QuadTree<GeoLib::Point> (min, max, _max_pnts_per_leaf); + _quad_tree = + new GeoLib::QuadTree<GeoLib::Point>(min, max, _max_pnts_per_leaf); DBUG("GMSHAdaptiveMeshDensity::init(): \tok."); // *** QuadTree - insert points addPoints(pnts); } -void GMSHAdaptiveMeshDensity::addPoints(std::vector<GeoLib::Point const*> const& pnts) +void GMSHAdaptiveMeshDensity::addPoints( + std::vector<GeoLib::Point const*> const& pnts) { // *** QuadTree - insert points const std::size_t n_pnts(pnts.size()); @@ -98,7 +102,8 @@ void GMSHAdaptiveMeshDensity::addPoints(std::vector<GeoLib::Point const*> const& _quad_tree->balance(); } -double GMSHAdaptiveMeshDensity::getMeshDensityAtPoint(GeoLib::Point const* const pnt) const +double GMSHAdaptiveMeshDensity::getMeshDensityAtPoint( + GeoLib::Point const* const pnt) const { GeoLib::Point ll; GeoLib::Point ur; @@ -106,7 +111,8 @@ double GMSHAdaptiveMeshDensity::getMeshDensityAtPoint(GeoLib::Point const* const return _pnt_density * (ur[0] - ll[0]); } -double GMSHAdaptiveMeshDensity::getMeshDensityAtStation(GeoLib::Point const* const pnt) const +double GMSHAdaptiveMeshDensity::getMeshDensityAtStation( + GeoLib::Point const* const pnt) const { GeoLib::Point ll; GeoLib::Point ur; @@ -114,8 +120,8 @@ double GMSHAdaptiveMeshDensity::getMeshDensityAtStation(GeoLib::Point const* con return _station_density * (ur[0] - ll[0]); } -void GMSHAdaptiveMeshDensity::getSteinerPoints (std::vector<GeoLib::Point*> & pnts, - std::size_t additional_levels) const +void GMSHAdaptiveMeshDensity::getSteinerPoints( + std::vector<GeoLib::Point*>& pnts, std::size_t additional_levels) const { // get Steiner points std::size_t max_depth(0); @@ -124,49 +130,59 @@ void GMSHAdaptiveMeshDensity::getSteinerPoints (std::vector<GeoLib::Point*> & pn std::list<GeoLib::QuadTree<GeoLib::Point>*> leaf_list; _quad_tree->getLeafs(leaf_list); - for (std::list<GeoLib::QuadTree<GeoLib::Point>*>::const_iterator it(leaf_list.begin()); it - != leaf_list.end(); ++it) { - if ((*it)->getPoints().empty()) { + for (std::list<GeoLib::QuadTree<GeoLib::Point>*>::const_iterator it( + leaf_list.begin()); + it != leaf_list.end(); + ++it) + { + if ((*it)->getPoints().empty()) + { // compute point from square GeoLib::Point ll; GeoLib::Point ur; (*it)->getSquarePoints(ll, ur); - if ((*it)->getDepth() + additional_levels > max_depth) { + if ((*it)->getDepth() + additional_levels > max_depth) + { additional_levels = max_depth - (*it)->getDepth(); } const std::size_t n_pnts_per_quad_dim = static_cast<std::size_t>(1) << additional_levels; - const double delta ((ur[0] - ll[0]) / (2 * n_pnts_per_quad_dim)); - for (std::size_t i(0); i<n_pnts_per_quad_dim; i++) { - for (std::size_t j(0); j<n_pnts_per_quad_dim; j++) { + const double delta((ur[0] - ll[0]) / (2 * n_pnts_per_quad_dim)); + for (std::size_t i(0); i < n_pnts_per_quad_dim; i++) + { + for (std::size_t j(0); j < n_pnts_per_quad_dim; j++) + { pnts.push_back(new GeoLib::Point( ll[0] + (2 * i + 1) * delta, ll[1] + (2 * j + 1) * delta, 0.0, pnts.size())); } } - } } } #ifndef NDEBUG -void GMSHAdaptiveMeshDensity::getQuadTreeGeometry(std::vector<GeoLib::Point*> &pnts, - std::vector<GeoLib::Polyline*> &plys) const +void GMSHAdaptiveMeshDensity::getQuadTreeGeometry( + std::vector<GeoLib::Point*>& pnts, + std::vector<GeoLib::Polyline*>& plys) const { std::list<GeoLib::QuadTree<GeoLib::Point>*> leaf_list; _quad_tree->getLeafs(leaf_list); - for (std::list<GeoLib::QuadTree<GeoLib::Point>*>::const_iterator it(leaf_list.begin()); it - != leaf_list.end(); ++it) { + for (std::list<GeoLib::QuadTree<GeoLib::Point>*>::const_iterator it( + leaf_list.begin()); + it != leaf_list.end(); + ++it) + { // fetch corner points from leaf GeoLib::Point ll; GeoLib::Point ur; (*it)->getSquarePoints(ll, ur); - std::size_t const pnt_offset (pnts.size()); + std::size_t const pnt_offset(pnts.size()); pnts.push_back(new GeoLib::Point(ll, pnt_offset)); - pnts.push_back(new GeoLib::Point(ur[0], ll[1], 0.0, pnt_offset+1)); - pnts.push_back(new GeoLib::Point(ur, pnt_offset+2)); - pnts.push_back(new GeoLib::Point(ll[0], ur[1], 0.0, pnt_offset+3)); + pnts.push_back(new GeoLib::Point(ur[0], ll[1], 0.0, pnt_offset + 1)); + pnts.push_back(new GeoLib::Point(ur, pnt_offset + 2)); + pnts.push_back(new GeoLib::Point(ll[0], ur[1], 0.0, pnt_offset + 3)); plys.push_back(new GeoLib::Polyline(pnts)); plys[plys.size() - 1]->addPoint(pnt_offset); plys[plys.size() - 1]->addPoint(pnt_offset + 1); @@ -178,4 +194,4 @@ void GMSHAdaptiveMeshDensity::getQuadTreeGeometry(std::vector<GeoLib::Point*> &p #endif } // namespace GMSH -} // end namespace FileIO +} // end namespace FileIO diff --git a/Applications/FileIO/Gmsh/GMSHFixedMeshDensity.cpp b/Applications/FileIO/Gmsh/GMSHFixedMeshDensity.cpp index f2307c14e459e8fb825bcbc964ba504623930316..ea969359ca5035c92661de8ceae6726d73f03e0b 100644 --- a/Applications/FileIO/Gmsh/GMSHFixedMeshDensity.cpp +++ b/Applications/FileIO/Gmsh/GMSHFixedMeshDensity.cpp @@ -14,13 +14,13 @@ namespace FileIO { namespace GMSH { - -GMSHFixedMeshDensity::GMSHFixedMeshDensity(double mesh_density) : - _mesh_density(mesh_density) +GMSHFixedMeshDensity::GMSHFixedMeshDensity(double mesh_density) + : _mesh_density(mesh_density) { } -void GMSHFixedMeshDensity::initialize(std::vector<GeoLib::Point const*> const& vec) +void GMSHFixedMeshDensity::initialize( + std::vector<GeoLib::Point const*> const& vec) { // to avoid a warning here: (void)(vec); @@ -39,4 +39,4 @@ double GMSHFixedMeshDensity::getMeshDensityAtStation( } } // namespace GMSH -} // end namespace FileIO +} // end namespace FileIO diff --git a/Applications/FileIO/Gmsh/GMSHInterface.cpp b/Applications/FileIO/Gmsh/GMSHInterface.cpp index 94cc68a9cad2564820564d8b6826d54550cb5a2f..c4cd03ac19a4e7d5ddee1927fb423a9871c71a04 100644 --- a/Applications/FileIO/Gmsh/GMSHInterface.cpp +++ b/Applications/FileIO/Gmsh/GMSHInterface.cpp @@ -7,27 +7,25 @@ * http://www.opengeosys.org/project/license */ +#include "Applications/FileIO/Gmsh/GMSHInterface.h" + #include <fstream> #include <memory> #include <vector> -#include "BaseLib/Logging.h" - -#include "InfoLib/GitInfo.h" -#include "BaseLib/FileTools.h" - -#include "Applications/FileIO/Gmsh/GMSHInterface.h" #include "Applications/FileIO/Gmsh/GMSHAdaptiveMeshDensity.h" #include "Applications/FileIO/Gmsh/GMSHFixedMeshDensity.h" +#include "Applications/FileIO/Gmsh/GMSHMeshDensityStrategy.h" #include "Applications/FileIO/Gmsh/GMSHPoint.h" #include "Applications/FileIO/Gmsh/GMSHPolygonTree.h" -#include "Applications/FileIO/Gmsh/GMSHMeshDensityStrategy.h" - +#include "BaseLib/FileTools.h" +#include "BaseLib/Logging.h" #include "GeoLib/AnalyticalGeometry.h" #include "GeoLib/GEOObjects.h" #include "GeoLib/Polygon.h" -#include "GeoLib/PolylineWithSegmentMarker.h" #include "GeoLib/PolygonWithSegmentMarker.h" +#include "GeoLib/PolylineWithSegmentMarker.h" +#include "InfoLib/GitInfo.h" namespace FileIO { @@ -60,16 +58,17 @@ GMSHInterface::GMSHInterface( _rotate(rotate), _keep_preprocessed_geometry(keep_preprocessed_geometry) { - switch (mesh_density_algorithm) { - case GMSH::MeshDensityAlgorithm::FixedMeshDensity: - _mesh_density_strategy = - std::make_unique<GMSH::GMSHFixedMeshDensity>(pnt_density); - break; - case GMSH::MeshDensityAlgorithm::AdaptiveMeshDensity: - _mesh_density_strategy = - std::make_unique<GMSH::GMSHAdaptiveMeshDensity>( - pnt_density, station_density, max_pnts_per_leaf); - break; + switch (mesh_density_algorithm) + { + case GMSH::MeshDensityAlgorithm::FixedMeshDensity: + _mesh_density_strategy = + std::make_unique<GMSH::GMSHFixedMeshDensity>(pnt_density); + break; + case GMSH::MeshDensityAlgorithm::AdaptiveMeshDensity: + _mesh_density_strategy = + std::make_unique<GMSH::GMSHAdaptiveMeshDensity>( + pnt_density, station_density, max_pnts_per_leaf); + break; } } @@ -104,34 +103,41 @@ int GMSHInterface::writeGMSHInputFile(std::ostream& out) } // *** get and merge data from _geo_objs - if (_selected_geometries.size() > 1) { + if (_selected_geometries.size() > 1) + { _gmsh_geo_name = "GMSHGeometry"; if (_geo_objs.mergeGeometries(_selected_geometries, _gmsh_geo_name)) { return 2; } - } else { + } + else + { _gmsh_geo_name = _selected_geometries[0]; _keep_preprocessed_geometry = true; } auto* merged_pnts(const_cast<std::vector<GeoLib::Point*>*>( _geo_objs.getPointVec(_gmsh_geo_name))); - if (! merged_pnts) { + if (!merged_pnts) + { ERR("GMSHInterface::writeGMSHInputFile(): Did not found any points."); return 2; } - if (_rotate) { + if (_rotate) + { // Rotate points to the x-y-plane. _inverse_rot_mat = GeoLib::rotatePointsToXY(*merged_pnts); // Compute inverse rotation matrix to reverse the rotation later on. _inverse_rot_mat.transposeInPlace(); - } else { + } + else + { // project data on the x-y-plane - _inverse_rot_mat(0,0) = 1.0; - _inverse_rot_mat(1,1) = 1.0; - _inverse_rot_mat(2,2) = 1.0; + _inverse_rot_mat(0, 0) = 1.0; + _inverse_rot_mat(1, 1) = 1.0; + _inverse_rot_mat(2, 2) = 1.0; for (auto pnt : *merged_pnts) { (*pnt)[2] = 0.0; @@ -142,7 +148,8 @@ int GMSHInterface::writeGMSHInputFile(std::ostream& out) _geo_objs.getPolylineVec(_gmsh_geo_name)); DBUG("GMSHInterface::writeGMSHInputFile(): Obtained data."); - if (!merged_plys) { + if (!merged_plys) + { ERR("GMSHInterface::writeGMSHInputFile(): Did not find any polylines."); return 2; } @@ -150,12 +157,14 @@ int GMSHInterface::writeGMSHInputFile(std::ostream& out) // *** compute and insert all intersection points between polylines GeoLib::PointVec& pnt_vec(*const_cast<GeoLib::PointVec*>( _geo_objs.getPointVecObj(_gmsh_geo_name))); - GeoLib::computeAndInsertAllIntersectionPoints(pnt_vec, - *(const_cast<std::vector<GeoLib::Polyline*>*>(merged_plys))); + GeoLib::computeAndInsertAllIntersectionPoints( + pnt_vec, *(const_cast<std::vector<GeoLib::Polyline*>*>(merged_plys))); // *** compute topological hierarchy of polygons - for (auto polyline : *merged_plys) { - if (!polyline->isClosed()) { + for (auto polyline : *merged_plys) + { + if (!polyline->isClosed()) + { continue; } _polygon_tree_list.push_back(new GMSH::GMSHPolygonTree( @@ -178,35 +187,46 @@ int GMSHInterface::writeGMSHInputFile(std::ostream& out) polygon_tree->markSharedSegments(); } - // *** insert stations and polylines (except polygons) in the appropriate object of + // *** insert stations and polylines (except polygons) in the appropriate + // object of // class GMSHPolygonTree // *** insert stations auto gmsh_stations = std::make_unique<std::vector<GeoLib::Point*>>(); - for (auto const& geometry_name : _selected_geometries) { + for (auto const& geometry_name : _selected_geometries) + { auto const* stations(_geo_objs.getStationVec(geometry_name)); - if (stations) { - for (auto * station : *stations) { + if (stations) + { + for (auto* station : *stations) + { bool found(false); for (auto it(_polygon_tree_list.begin()); - it != _polygon_tree_list.end() && !found; ++it) { + it != _polygon_tree_list.end() && !found; + ++it) + { gmsh_stations->emplace_back(new GeoLib::Station( *static_cast<GeoLib::Station*>(station))); - if ((*it)->insertStation(gmsh_stations->back())) { + if ((*it)->insertStation(gmsh_stations->back())) + { found = true; } } } } } - std::string gmsh_stations_name(_gmsh_geo_name+"-Stations"); - if (! gmsh_stations->empty()) { + std::string gmsh_stations_name(_gmsh_geo_name + "-Stations"); + if (!gmsh_stations->empty()) + { _geo_objs.addStationVec(std::move(gmsh_stations), gmsh_stations_name); } // *** insert polylines - for (auto polyline : *merged_plys) { - if (!polyline->isClosed()) { - for (auto * polygon_tree : _polygon_tree_list) { + for (auto polyline : *merged_plys) + { + if (!polyline->isClosed()) + { + for (auto* polygon_tree : _polygon_tree_list) + { auto polyline_with_segment_marker = new GeoLib::PolylineWithSegmentMarker(*polyline); polygon_tree->insertPolyline(polyline_with_segment_marker); @@ -223,7 +243,8 @@ int GMSHInterface::writeGMSHInputFile(std::ostream& out) // *** create GMSH data structures const std::size_t n_merged_pnts(merged_pnts->size()); _gmsh_pnts.resize(n_merged_pnts); - for (std::size_t k(0); k<n_merged_pnts; k++) { + for (std::size_t k(0); k < n_merged_pnts; k++) + { _gmsh_pnts[k] = nullptr; } for (auto& polygon_tree : _polygon_tree_list) @@ -240,13 +261,16 @@ int GMSHInterface::writeGMSHInputFile(std::ostream& out) { polygon_tree->writeLineLoop(_n_lines, _n_plane_sfc, out, _write_physical_groups); - polygon_tree->writeSubPolygonsAsLineConstraints(_n_lines, _n_plane_sfc-1, out); - polygon_tree->writeLineConstraints(_n_lines, _n_plane_sfc-1, out); - polygon_tree->writeStations(pnt_id_offset, _n_plane_sfc-1, out); - polygon_tree->writeAdditionalPointData(pnt_id_offset, _n_plane_sfc-1, out); + polygon_tree->writeSubPolygonsAsLineConstraints(_n_lines, + _n_plane_sfc - 1, out); + polygon_tree->writeLineConstraints(_n_lines, _n_plane_sfc - 1, out); + polygon_tree->writeStations(pnt_id_offset, _n_plane_sfc - 1, out); + polygon_tree->writeAdditionalPointData(pnt_id_offset, _n_plane_sfc - 1, + out); } - if (! _keep_preprocessed_geometry) { + if (!_keep_preprocessed_geometry) + { _geo_objs.removeSurfaceVec(_gmsh_geo_name); _geo_objs.removePolylineVec(_gmsh_geo_name); _geo_objs.removePointVec(_gmsh_geo_name); @@ -256,5 +280,5 @@ int GMSHInterface::writeGMSHInputFile(std::ostream& out) return 0; } -} // end namespace GMSH -} // end namespace FileIO +} // end namespace GMSH +} // end namespace FileIO diff --git a/Applications/FileIO/Gmsh/GMSHLine.cpp b/Applications/FileIO/Gmsh/GMSHLine.cpp index 65027872f821ddc925181ecde592e4b02e1c48ff..5e467de58b01cef007901b9b0caa79b36571416b 100644 --- a/Applications/FileIO/Gmsh/GMSHLine.cpp +++ b/Applications/FileIO/Gmsh/GMSHLine.cpp @@ -8,22 +8,24 @@ * */ -#include <ostream> #include "GMSHLine.h" +#include <ostream> + namespace FileIO { namespace GMSH { +GMSHLine::GMSHLine(std::size_t start_point_id, std::size_t end_point_id) + : _start_pnt_id(start_point_id), _end_pnt_id(end_point_id) +{ +} -GMSHLine::GMSHLine(std::size_t start_point_id, std::size_t end_point_id) : - _start_pnt_id(start_point_id), _end_pnt_id(end_point_id) -{} - -void GMSHLine::write(std::ostream &os, std::size_t id) const +void GMSHLine::write(std::ostream& os, std::size_t id) const { - os << "Line(" << id << ") = {" << _start_pnt_id << "," << _end_pnt_id << "};\n"; + os << "Line(" << id << ") = {" << _start_pnt_id << "," << _end_pnt_id + << "};\n"; } -} // end namespace GMSH -} // end namespace FileIO +} // end namespace GMSH +} // end namespace FileIO diff --git a/Applications/FileIO/Gmsh/GMSHLineLoop.cpp b/Applications/FileIO/Gmsh/GMSHLineLoop.cpp index 9ab3854037ac43f72068dd0fc32866267c4d68ee..8322e9d2b1eeb06912b7481edd5b0023331933aa 100644 --- a/Applications/FileIO/Gmsh/GMSHLineLoop.cpp +++ b/Applications/FileIO/Gmsh/GMSHLineLoop.cpp @@ -8,10 +8,11 @@ * */ +#include "GMSHLineLoop.h" + #include <ostream> #include "GMSHLine.h" -#include "GMSHLineLoop.h" namespace FileIO { diff --git a/Applications/FileIO/Gmsh/GMSHPoint.cpp b/Applications/FileIO/Gmsh/GMSHPoint.cpp index 17cb737891fbf60eaa5f65f5348c2a595dc7a115..026575f8c3018f331cf3ebdb35c1434dca751bfd 100644 --- a/Applications/FileIO/Gmsh/GMSHPoint.cpp +++ b/Applications/FileIO/Gmsh/GMSHPoint.cpp @@ -8,33 +8,37 @@ * */ +#include "GMSHPoint.h" + #include <cmath> #include <limits> -#include "GMSHPoint.h" - namespace FileIO { namespace GMSH { +GMSHPoint::GMSHPoint(GeoLib::Point const& pnt, std::size_t id, + double mesh_density) + : GeoLib::Point(pnt, id), _mesh_density(mesh_density) +{ +} -GMSHPoint::GMSHPoint(GeoLib::Point const& pnt, std::size_t id, double mesh_density) : - GeoLib::Point(pnt, id), _mesh_density(mesh_density) -{} - -void GMSHPoint::write(std::ostream &os) const +void GMSHPoint::write(std::ostream& os) const { os << "Point(" << _id << ") = {" << _x[0] << ", " << _x[1] << ", " << _x[2]; - if (fabs(_mesh_density) > std::numeric_limits<double>::epsilon()) { + if (fabs(_mesh_density) > std::numeric_limits<double>::epsilon()) + { os << ", " << _mesh_density << "};"; - } else { + } + else + { os << "};"; } } -std::ostream& operator<< (std::ostream &os, GMSHPoint const& p) +std::ostream& operator<<(std::ostream& os, GMSHPoint const& p) { - p.write (os); + p.write(os); return os; } diff --git a/Applications/FileIO/Gmsh/GMSHPolygonTree.cpp b/Applications/FileIO/Gmsh/GMSHPolygonTree.cpp index 910e36cbf4f5f41db83229be2fd15fd53789f2d2..765c8c63484a672aeb7111b4046ab2b803f3d2d2 100644 --- a/Applications/FileIO/Gmsh/GMSHPolygonTree.cpp +++ b/Applications/FileIO/Gmsh/GMSHPolygonTree.cpp @@ -10,15 +10,14 @@ #include "GMSHPolygonTree.h" -#include "GMSHFixedMeshDensity.h" #include "GMSHAdaptiveMeshDensity.h" - +#include "GMSHFixedMeshDensity.h" #include "GeoLib/AnalyticalGeometry.h" #include "GeoLib/GEOObjects.h" #include "GeoLib/Point.h" #include "GeoLib/Polygon.h" -#include "GeoLib/PolylineWithSegmentMarker.h" #include "GeoLib/PolygonWithSegmentMarker.h" +#include "GeoLib/PolylineWithSegmentMarker.h" namespace FileIO { @@ -33,13 +32,15 @@ GMSHPolygonTree::GMSHPolygonTree(GeoLib::PolygonWithSegmentMarker* polygon, _geo_objs(geo_objs), _geo_name(geo_name), _mesh_density_strategy(mesh_density_strategy) -{} +{ +} GMSHPolygonTree::~GMSHPolygonTree() { // the polylines are processed also by the children, but the root is // responsible to cleanup up - if (_parent == nullptr) { // root + if (_parent == nullptr) + { // root for (auto* polyline : _plys) { delete polyline; @@ -64,7 +65,8 @@ void GMSHPolygonTree::markSharedSegments() for (auto& child : _children) { std::size_t const n_pnts(child->getPolygon()->getNumberOfPoints()); - for (std::size_t k(1); k<n_pnts; k++) { + for (std::size_t k(1); k < n_pnts; k++) + { if (GeoLib::containsEdge(*(_parent->getPolygon()), _node_polygon->getPointID(k - 1), _node_polygon->getPointID(k))) @@ -78,12 +80,18 @@ void GMSHPolygonTree::markSharedSegments() bool GMSHPolygonTree::insertStation(GeoLib::Point const* station) { - if (_node_polygon->isPntInPolygon(*station)) { + if (_node_polygon->isPntInPolygon(*station)) + { // try to insert station into the child nodes - for (std::list<SimplePolygonTree*>::const_iterator it (_children.begin()); - it != _children.end(); ++it) { - if (((*it)->getPolygon())->isPntInPolygon (*station)) { - bool rval(dynamic_cast<GMSHPolygonTree*>((*it))->insertStation (station)); + for (std::list<SimplePolygonTree*>::const_iterator it( + _children.begin()); + it != _children.end(); + ++it) + { + if (((*it)->getPolygon())->isPntInPolygon(*station)) + { + bool rval(dynamic_cast<GMSHPolygonTree*>((*it))->insertStation( + station)); // stop recursion if sub SimplePolygonTree is a leaf if (rval && (*it)->getNumberOfChildren() == 0) { @@ -92,14 +100,15 @@ bool GMSHPolygonTree::insertStation(GeoLib::Point const* station) return rval; } } - // station did not fit into child nodes -> insert the station into this node - _stations.push_back (station); + // station did not fit into child nodes -> insert the station into this + // node + _stations.push_back(station); return true; } return false; } -void GMSHPolygonTree::insertPolyline(GeoLib::PolylineWithSegmentMarker * ply) +void GMSHPolygonTree::insertPolyline(GeoLib::PolylineWithSegmentMarker* ply) { if (!_node_polygon->isPartOfPolylineInPolygon(*ply)) { @@ -108,7 +117,8 @@ void GMSHPolygonTree::insertPolyline(GeoLib::PolylineWithSegmentMarker * ply) // check if polyline segments are inside of the polygon, intersect the // polygon or are part of the boundary of the polygon - for (auto * polygon_tree : _children) { + for (auto* polygon_tree : _children) + { dynamic_cast<GMSHPolygonTree*>(polygon_tree)->insertPolyline(ply); } @@ -116,16 +126,16 @@ void GMSHPolygonTree::insertPolyline(GeoLib::PolylineWithSegmentMarker * ply) // (_node_polygon) and the given polyline ply // pay attention: loop bound is not fix! GeoLib::Point tmp_pnt; - GeoLib::PointVec & pnt_vec(*(_geo_objs.getPointVecObj(_geo_name))); - for (auto segment_it(ply->begin()); segment_it != ply->end(); - ++segment_it) + GeoLib::PointVec& pnt_vec(*(_geo_objs.getPointVecObj(_geo_name))); + for (auto segment_it(ply->begin()); segment_it != ply->end(); ++segment_it) { if (ply->isSegmentMarked(segment_it.getSegmentNumber())) { continue; } - if (_node_polygon->containsSegment(*segment_it)) { + if (_node_polygon->containsSegment(*segment_it)) + { ply->markSegment(segment_it.getSegmentNumber(), true); continue; } @@ -135,38 +145,46 @@ void GMSHPolygonTree::insertPolyline(GeoLib::PolylineWithSegmentMarker * ply) while (_node_polygon->getNextIntersectionPointPolygonLine( *segment_it, intersection_pnt, seg_num)) { - // insert the intersection point to point vector of GEOObjects instance + // insert the intersection point to point vector of GEOObjects + // instance const std::size_t pnt_vec_size(pnt_vec.size()); std::size_t pnt_id( pnt_vec.push_back(new GeoLib::Point(intersection_pnt))); - if (pnt_vec_size < pnt_vec.size()) { // case: new point + if (pnt_vec_size < pnt_vec.size()) + { // case: new point // modify the polygon - _node_polygon->insertPoint(seg_num+1, pnt_id); + _node_polygon->insertPoint(seg_num + 1, pnt_id); // modify the polyline ply->insertPoint(segment_it.getSegmentNumber(), pnt_id); - } else { // case: existing point + } + else + { // case: existing point // check if point id is within the polygon - if (! _node_polygon->isPointIDInPolyline(pnt_id)) { - _node_polygon->insertPoint(seg_num+1, pnt_id); + if (!_node_polygon->isPointIDInPolyline(pnt_id)) + { + _node_polygon->insertPoint(seg_num + 1, pnt_id); } // check if point id is in polyline - if (! ply->isPointIDInPolyline(pnt_id)) { - ply->insertPoint(segment_it.getSegmentNumber()+1, pnt_id); + if (!ply->isPointIDInPolyline(pnt_id)) + { + ply->insertPoint(segment_it.getSegmentNumber() + 1, pnt_id); } } - std::size_t tmp_seg_num(seg_num+1); + std::size_t tmp_seg_num(seg_num + 1); if (!_node_polygon->getNextIntersectionPointPolygonLine( *segment_it, tmp_pnt, tmp_seg_num)) { // check a point of the segment except the end points - for (std::size_t i(0); i<3; i++) { + for (std::size_t i(0); i < 3; i++) + { tmp_pnt[i] = ((*segment_it).getBeginPoint()[i] + (*segment_it).getEndPoint()[i]) / 2; } - if (_node_polygon->isPntInPolygon(tmp_pnt)) { + if (_node_polygon->isPntInPolygon(tmp_pnt)) + { ply->markSegment(segment_it.getSegmentNumber(), true); // insert line segment as constraint _gmsh_lines_for_constraints.push_back( @@ -177,7 +195,8 @@ void GMSHPolygonTree::insertPolyline(GeoLib::PolylineWithSegmentMarker * ply) seg_num++; // check a point of the segment except the end points - for (std::size_t i(0); i<3; i++) { + for (std::size_t i(0); i < 3; i++) + { tmp_pnt[i] = ((*segment_it).getBeginPoint()[i] + (*segment_it).getEndPoint()[i]) / 2; @@ -185,7 +204,8 @@ void GMSHPolygonTree::insertPolyline(GeoLib::PolylineWithSegmentMarker * ply) checkIntersectionsSegmentExistingPolylines(ply, segment_it); - if (_node_polygon->isPntInPolygon(tmp_pnt)) { + if (_node_polygon->isPntInPolygon(tmp_pnt)) + { ply->markSegment(segment_it.getSegmentNumber(), true); // insert line segment as constraint _gmsh_lines_for_constraints.push_back( @@ -203,30 +223,39 @@ void GMSHPolygonTree::checkIntersectionsSegmentExistingPolylines( GeoLib::Polyline::SegmentIterator const& seg_it) { std::size_t const ply_segment_number(seg_it.getSegmentNumber()); - for(GeoLib::PolylineWithSegmentMarker *const p : _plys) { - GeoLib::PointVec & pnt_vec(*(_geo_objs.getPointVecObj(_geo_name))); - for (auto seg_it_p(p->begin()); seg_it_p != p->end(); ++seg_it_p) { - GeoLib::Point s; // intersection point + for (GeoLib::PolylineWithSegmentMarker* const p : _plys) + { + GeoLib::PointVec& pnt_vec(*(_geo_objs.getPointVecObj(_geo_name))); + for (auto seg_it_p(p->begin()); seg_it_p != p->end(); ++seg_it_p) + { + GeoLib::Point s; // intersection point if (GeoLib::lineSegmentIntersect(*seg_it, *seg_it_p, s)) { const std::size_t pnt_vec_size(pnt_vec.size()); // point id of new point in GEOObjects instance - const std::size_t pnt_id(pnt_vec.push_back(new GeoLib::Point(s))); - if (pnt_vec_size < pnt_vec.size()) { // case: new point + const std::size_t pnt_id( + pnt_vec.push_back(new GeoLib::Point(s))); + if (pnt_vec_size < pnt_vec.size()) + { // case: new point // modify polyline already in this node - p->insertPoint(seg_it_p.getSegmentNumber()+1, pnt_id); + p->insertPoint(seg_it_p.getSegmentNumber() + 1, pnt_id); // modify polyline - ply->insertPoint(ply_segment_number+1, pnt_id); - } else { // case: point exists already in geometry + ply->insertPoint(ply_segment_number + 1, pnt_id); + } + else + { // case: point exists already in geometry // check if point is not already in polyline p std::size_t const k(seg_it_p.getSegmentNumber()); - if (p->getPointID(k) != pnt_id && p->getPointID(k+1) != pnt_id) { - p->insertPoint(k+1, pnt_id); + if (p->getPointID(k) != pnt_id && + p->getPointID(k + 1) != pnt_id) + { + p->insertPoint(k + 1, pnt_id); } // check if point is not already in polyline ply - if (ply->getPointID(ply_segment_number) != pnt_id - && ply->getPointID(ply_segment_number+1) != pnt_id) { - ply->insertPoint(ply_segment_number+1, pnt_id); + if (ply->getPointID(ply_segment_number) != pnt_id && + ply->getPointID(ply_segment_number + 1) != pnt_id) + { + ply->insertPoint(ply_segment_number + 1, pnt_id); } } } @@ -241,16 +270,19 @@ void GMSHPolygonTree::initMeshDensityStrategy() { // collect points std::vector<GeoLib::Point const*> pnts; - const std::size_t n_pnts_polygon (_node_polygon->getNumberOfPoints()); - for (std::size_t k(0); k<n_pnts_polygon; k++) { + const std::size_t n_pnts_polygon(_node_polygon->getNumberOfPoints()); + for (std::size_t k(0); k < n_pnts_polygon; k++) + { pnts.push_back(_node_polygon->getPoint(k)); } getPointsFromSubPolygons(pnts); - const std::size_t n_plys (_plys.size()); - for (std::size_t k(0); k<n_plys; k++) { + const std::size_t n_plys(_plys.size()); + for (std::size_t k(0); k < n_plys; k++) + { const std::size_t n_pnts_in_kth_ply(_plys[k]->getNumberOfPoints()); - for (std::size_t j(0); j<n_pnts_in_kth_ply; j++) { + for (std::size_t j(0); j < n_pnts_in_kth_ply; j++) + { pnts.push_back(_plys[k]->getPoint(j)); } } @@ -265,12 +297,13 @@ void GMSHPolygonTree::initMeshDensityStrategy() } } -void GMSHPolygonTree::createGMSHPoints(std::vector<GMSHPoint*> & gmsh_pnts) const +void GMSHPolygonTree::createGMSHPoints(std::vector<GMSHPoint*>& gmsh_pnts) const { - const std::size_t n_pnts_polygon (_node_polygon->getNumberOfPoints()); - for (std::size_t k(0); k<n_pnts_polygon-1; k++) { - const std::size_t id (_node_polygon->getPointID(k)); - GeoLib::Point const*const pnt(_node_polygon->getPoint(k)); + const std::size_t n_pnts_polygon(_node_polygon->getNumberOfPoints()); + for (std::size_t k(0); k < n_pnts_polygon - 1; k++) + { + const std::size_t id(_node_polygon->getPointID(k)); + GeoLib::Point const* const pnt(_node_polygon->getPoint(k)); // if this point was already part of another polyline if (gmsh_pnts[id] != nullptr) { @@ -281,17 +314,20 @@ void GMSHPolygonTree::createGMSHPoints(std::vector<GMSHPoint*> & gmsh_pnts) cons } const std::size_t n_plys(_plys.size()); - for (std::size_t k(0); k<n_plys; k++) { + for (std::size_t k(0); k < n_plys; k++) + { const std::size_t n_pnts_in_ply(_plys[k]->getNumberOfPoints()); - for (std::size_t j(0); j<n_pnts_in_ply; j++) { - if (_node_polygon->isPntInPolygon(*(_plys[k]->getPoint(j)))) { - const std::size_t id (_plys[k]->getPointID(j)); + for (std::size_t j(0); j < n_pnts_in_ply; j++) + { + if (_node_polygon->isPntInPolygon(*(_plys[k]->getPoint(j)))) + { + 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)); + GeoLib::Point const* const pnt(_plys[k]->getPoint(j)); gmsh_pnts[id] = new GMSHPoint( *pnt, id, _mesh_density_strategy.getMeshDensityAtPoint(pnt)); @@ -319,11 +355,12 @@ void GMSHPolygonTree::writeLineLoop(std::size_t& line_offset, << second_pnt_id << "};\n"; first_pnt_id = second_pnt_id; } - out << "Line Loop(" << line_offset + n_pnts-1 << ") = {"; - for (std::size_t k(0); k<n_pnts - 2; k++) { - out << line_offset+k << ","; + out << "Line Loop(" << line_offset + n_pnts - 1 << ") = {"; + for (std::size_t k(0); k < n_pnts - 2; k++) + { + out << line_offset + k << ","; } - out << line_offset+n_pnts-2 << "};\n"; + out << line_offset + n_pnts - 2 << "};\n"; out << "Plane Surface(" << sfc_offset << ") = {" << line_offset + n_pnts - 1 << "};\n"; if (write_physical) @@ -334,8 +371,8 @@ void GMSHPolygonTree::writeLineLoop(std::size_t& line_offset, out << line_offset + k << ","; } out << line_offset + n_pnts - 2 << "};\n"; - out << "Physical Surface(" << sfc_offset << ") = {" - << sfc_offset << "};\n"; + out << "Physical Surface(" << sfc_offset << ") = {" << sfc_offset + << "};\n"; } line_offset += n_pnts; sfc_offset++; @@ -354,7 +391,8 @@ void GMSHPolygonTree::writeLineConstraints(std::size_t& line_offset, auto const second_pnt_id = polyline->getPointID(k); if (polyline->isSegmentMarked(k - 1) && _node_polygon->isPntInPolygon(*(polyline->getPoint(k))) && - !GeoLib::containsEdge(*_node_polygon, first_pnt_id, second_pnt_id)) + !GeoLib::containsEdge(*_node_polygon, first_pnt_id, + second_pnt_id)) { out << "Line(" << line_offset + k - 1 << ") = {" << first_pnt_id << "," << second_pnt_id << "};\n"; @@ -367,7 +405,8 @@ void GMSHPolygonTree::writeLineConstraints(std::size_t& line_offset, } } -void GMSHPolygonTree::writeSubPolygonsAsLineConstraints(std::size_t &line_offset, std::size_t sfc_number, std::ostream& out) const +void GMSHPolygonTree::writeSubPolygonsAsLineConstraints( + std::size_t& line_offset, std::size_t sfc_number, std::ostream& out) const { for (auto child : _children) { @@ -379,31 +418,39 @@ void GMSHPolygonTree::writeSubPolygonsAsLineConstraints(std::size_t &line_offset { const std::size_t n_pnts(_node_polygon->getNumberOfPoints()); std::size_t first_pnt_id(_node_polygon->getPointID(0)); - for (std::size_t k(1); k<n_pnts; k++) { + for (std::size_t k(1); k < n_pnts; k++) + { auto const second_pnt_id = _node_polygon->getPointID(k); - out << "Line(" << line_offset + k-1 << ") = {" << first_pnt_id << "," << second_pnt_id << "};\n"; + out << "Line(" << line_offset + k - 1 << ") = {" << first_pnt_id + << "," << second_pnt_id << "};\n"; first_pnt_id = second_pnt_id; - out << "Line { " << line_offset+k-1 << " } In Surface { " << sfc_number << " };\n"; + out << "Line { " << line_offset + k - 1 << " } In Surface { " + << sfc_number << " };\n"; } line_offset += n_pnts; } - } -void GMSHPolygonTree::writeStations(std::size_t & pnt_id_offset, std::size_t sfc_number, std::ostream& out) const +void GMSHPolygonTree::writeStations(std::size_t& pnt_id_offset, + std::size_t sfc_number, + std::ostream& out) const { - for (auto const* station : _stations) { + for (auto const* station : _stations) + { out << "Point(" << pnt_id_offset << ") = {" << (*station)[0] << ", " << (*station)[1] << ", 0.0, " << _mesh_density_strategy.getMeshDensityAtStation(station) << "}; // Station " << static_cast<GeoLib::Station const*>(station)->getName() << " \n"; - out << "Point { " << pnt_id_offset << " } In Surface { " << sfc_number << " };\n"; + out << "Point { " << pnt_id_offset << " } In Surface { " << sfc_number + << " };\n"; ++pnt_id_offset; } } -void GMSHPolygonTree::writeAdditionalPointData(std::size_t & pnt_id_offset, std::size_t sfc_number, std::ostream& out) const +void GMSHPolygonTree::writeAdditionalPointData(std::size_t& pnt_id_offset, + std::size_t sfc_number, + std::ostream& out) const { if (auto* adaptive_mesh_density = dynamic_cast<GMSHAdaptiveMeshDensity*>(&_mesh_density_strategy)) @@ -411,13 +458,18 @@ void GMSHPolygonTree::writeAdditionalPointData(std::size_t & pnt_id_offset, std: std::vector<GeoLib::Point*> steiner_pnts; adaptive_mesh_density->getSteinerPoints(steiner_pnts, 0); const std::size_t n(steiner_pnts.size()); - for (std::size_t k(0); k<n; k++) { - if (_node_polygon->isPntInPolygon(*(steiner_pnts[k]))) { - out << "Point(" << pnt_id_offset + k << ") = {" << (*(steiner_pnts[k]))[0] << "," << (*(steiner_pnts[k]))[1] << ", 0.0, "; + for (std::size_t k(0); k < n; k++) + { + if (_node_polygon->isPntInPolygon(*(steiner_pnts[k]))) + { + out << "Point(" << pnt_id_offset + k << ") = {" + << (*(steiner_pnts[k]))[0] << "," << (*(steiner_pnts[k]))[1] + << ", 0.0, "; out << _mesh_density_strategy.getMeshDensityAtPoint( steiner_pnts[k]) << "};\n"; - out << "Point { " << pnt_id_offset + k << " } In Surface { " << sfc_number << " };\n"; + out << "Point { " << pnt_id_offset + k << " } In Surface { " + << sfc_number << " };\n"; } delete steiner_pnts[k]; } @@ -433,34 +485,45 @@ void GMSHPolygonTree::writeAdditionalPointData(std::size_t & pnt_id_offset, std: adaptive_mesh_density->getQuadTreeGeometry(*pnts, *plys); std::string quad_tree_geo("QuadTree"); _geo_objs.addPointVec(std::move(pnts), quad_tree_geo); - std::vector<std::size_t> const& id_map ((_geo_objs.getPointVecObj(quad_tree_geo))->getIDMap()); - for (std::size_t k(0); k<plys->size(); k++) { - for (std::size_t j(0); j<(*plys)[k]->getNumberOfPoints(); j++) { - ((*plys)[k])->setPointID(j, id_map[((*plys)[k])->getPointID(j)]); + std::vector<std::size_t> const& id_map( + (_geo_objs.getPointVecObj(quad_tree_geo))->getIDMap()); + for (std::size_t k(0); k < plys->size(); k++) + { + for (std::size_t j(0); j < (*plys)[k]->getNumberOfPoints(); j++) + { + ((*plys)[k]) + ->setPointID(j, id_map[((*plys)[k])->getPointID(j)]); } } _geo_objs.addPolylineVec(std::move(plys), quad_tree_geo); } #endif - } -void GMSHPolygonTree::getPointsFromSubPolygons(std::vector<GeoLib::Point const*>& pnts) +void GMSHPolygonTree::getPointsFromSubPolygons( + std::vector<GeoLib::Point const*>& pnts) { - for (std::list<SimplePolygonTree*>::const_iterator it (_children.begin()); it != _children.end(); ++it) { + for (std::list<SimplePolygonTree*>::const_iterator it(_children.begin()); + it != _children.end(); ++it) + { dynamic_cast<GMSHPolygonTree*>((*it))->getPointsFromSubPolygons(pnts); } } -void GMSHPolygonTree::getStationsInsideSubPolygons(std::vector<GeoLib::Point const*>& stations) +void GMSHPolygonTree::getStationsInsideSubPolygons( + std::vector<GeoLib::Point const*>& stations) { const std::size_t n_stations(_stations.size()); - for (std::size_t k(0); k<n_stations; k++) { + for (std::size_t k(0); k < n_stations; k++) + { stations.push_back(_stations[k]); } - for (std::list<SimplePolygonTree*>::const_iterator it (_children.begin()); it != _children.end(); ++it) { - dynamic_cast<GMSHPolygonTree*>((*it))->getStationsInsideSubPolygons(stations); + for (std::list<SimplePolygonTree*>::const_iterator it(_children.begin()); + it != _children.end(); ++it) + { + dynamic_cast<GMSHPolygonTree*>((*it))->getStationsInsideSubPolygons( + stations); } } diff --git a/Applications/FileIO/Gmsh/GmshReader.cpp b/Applications/FileIO/Gmsh/GmshReader.cpp index bcc0d4d40d37bfd66620348c0a2a7ee118c50374..1cefa6aa7593eb59bfaff6eb8df0ccffbcb092ff 100644 --- a/Applications/FileIO/Gmsh/GmshReader.cpp +++ b/Applications/FileIO/Gmsh/GmshReader.cpp @@ -9,43 +9,41 @@ #include "GmshReader.h" +#include <fstream> +#include <map> +#include <vector> + +#include "BaseLib/FileTools.h" #include "MeshLib/Elements/Element.h" -#include "MeshLib/Elements/Line.h" -#include "MeshLib/Elements/Tri.h" -#include "MeshLib/Elements/Quad.h" -#include "MeshLib/Elements/Tet.h" #include "MeshLib/Elements/Hex.h" +#include "MeshLib/Elements/Line.h" #include "MeshLib/Elements/Prism.h" #include "MeshLib/Elements/Pyramid.h" - -#include "MeshLib/Node.h" +#include "MeshLib/Elements/Quad.h" +#include "MeshLib/Elements/Tet.h" +#include "MeshLib/Elements/Tri.h" #include "MeshLib/Mesh.h" - #include "MeshLib/MeshEditing/ElementValueModification.h" - -#include "BaseLib/FileTools.h" - -#include <fstream> -#include <map> -#include <vector> +#include "MeshLib/Node.h" namespace FileIO { namespace GMSH { - bool isGMSHMeshFile(const std::string& fname) { std::ifstream input(fname.c_str()); - if (!input) { + if (!input) + { ERR("isGMSHMeshFile(): Could not open file {:s}.", fname); return false; } std::string header_first_line; input >> header_first_line; - if (header_first_line.find("$MeshFormat") != std::string::npos) { + if (header_first_line.find("$MeshFormat") != std::string::npos) + { // read version std::string version; getline(input, version); @@ -81,79 +79,86 @@ std::pair<MeshLib::Element*, int> readElement( int mat_id; std::vector<unsigned> node_ids; - //element format is structured like this: - //element-id element-type n-tags physical-entity elementary entity node-ids + // element format is structured like this: + // element-id element-type n-tags physical-entity elementary entity node-ids in >> idx >> type >> n_tags >> dummy >> mat_id; switch (type) { - case 1: { - readNodeIDs(in, 2, node_ids, id_map); - // edge_nodes array will be deleted from Line object - auto edge_nodes = new MeshLib::Node*[2]; - edge_nodes[0] = nodes[node_ids[0]]; - edge_nodes[1] = nodes[node_ids[1]]; - return std::make_pair(new MeshLib::Line(edge_nodes), mat_id); - } - case 2: { - readNodeIDs(in, 3, node_ids, id_map); - auto tri_nodes = new MeshLib::Node*[3]; - tri_nodes[0] = nodes[node_ids[2]]; - tri_nodes[1] = nodes[node_ids[1]]; - tri_nodes[2] = nodes[node_ids[0]]; - return std::make_pair(new MeshLib::Tri(tri_nodes), mat_id); - } - case 3: { - readNodeIDs(in, 4, node_ids, id_map); - auto quad_nodes = new MeshLib::Node*[4]; - for (unsigned k(0); k < 4; k++) + case 1: { - quad_nodes[k] = nodes[node_ids[k]]; + readNodeIDs(in, 2, node_ids, id_map); + // edge_nodes array will be deleted from Line object + auto edge_nodes = new MeshLib::Node*[2]; + edge_nodes[0] = nodes[node_ids[0]]; + edge_nodes[1] = nodes[node_ids[1]]; + return std::make_pair(new MeshLib::Line(edge_nodes), mat_id); } - 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++) + case 2: { - tet_nodes[k] = nodes[node_ids[k]]; + readNodeIDs(in, 3, node_ids, id_map); + auto tri_nodes = new MeshLib::Node*[3]; + tri_nodes[0] = nodes[node_ids[2]]; + tri_nodes[1] = nodes[node_ids[1]]; + tri_nodes[2] = nodes[node_ids[0]]; + return std::make_pair(new MeshLib::Tri(tri_nodes), mat_id); } - 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++) + case 3: { - hex_nodes[k] = nodes[node_ids[k]]; + 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); } - 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++) + case 4: { - prism_nodes[k] = nodes[node_ids[k]]; + 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); } - 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++) + 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: { - pyramid_nodes[k] = nodes[node_ids[k]]; + 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); } - return std::make_pair(new MeshLib::Pyramid(pyramid_nodes), mat_id); - } - case 15: - in >> dummy; // skip rest of line - break; - default: - WARN("readGMSHMesh(): Unknown element type {:d}.", type); - break; + 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: + in >> dummy; // skip rest of line + break; + default: + WARN("readGMSHMesh(): Unknown element type {:d}.", type); + break; } return std::make_pair(nullptr, -1); } @@ -168,15 +173,15 @@ MeshLib::Mesh* readGMSHMesh(std::string const& fname) return nullptr; } - getline(in, line); // $MeshFormat keyword + getline(in, line); // $MeshFormat keyword if (line.find("$MeshFormat") == std::string::npos) { in.close(); - WARN ("No GMSH file format recognized."); + WARN("No GMSH file format recognized."); return nullptr; } - getline(in, line); // version-number file-type data-size + getline(in, line); // version-number file-type data-size if (line.substr(0, 3) != "2.2") { WARN("Wrong gmsh file format version '{:s}'.", line.substr(0, 3)); @@ -188,7 +193,7 @@ MeshLib::Mesh* readGMSHMesh(std::string const& fname) WARN("Currently reading gmsh binary file type is not supported."); return nullptr; } - getline(in, line); //$EndMeshFormat + getline(in, line); //$EndMeshFormat std::vector<MeshLib::Node*> nodes; std::vector<MeshLib::Element*> elements; @@ -197,7 +202,7 @@ MeshLib::Mesh* readGMSHMesh(std::string const& fname) while (line.find("$EndElements") == std::string::npos) { // Node data - getline(in, line); //$Nodes Keywords + getline(in, line); //$Nodes Keywords if (line.find("$Nodes") != std::string::npos) { std::size_t n_nodes(0); @@ -207,19 +212,21 @@ MeshLib::Mesh* readGMSHMesh(std::string const& fname) double z; in >> n_nodes >> std::ws; nodes.resize(n_nodes); - for (std::size_t i = 0; i < n_nodes; i++) { + for (std::size_t i = 0; i < n_nodes; i++) + { in >> id >> x >> y >> z >> std::ws; id_map.insert(std::map<unsigned, unsigned>::value_type(id, i)); - nodes[i] = new MeshLib::Node(x,y,z,id); + nodes[i] = new MeshLib::Node(x, y, z, id); } - getline(in, line); // End Node keyword $EndNodes + getline(in, line); // End Node keyword $EndNodes } // Element data if (line.find("$Elements") != std::string::npos) { std::size_t n_elements(0); - if (! (in >> n_elements >> std::ws)) { // number-of-elements + if (!(in >> n_elements >> std::ws)) + { // number-of-elements ERR("Read GMSH mesh does not contain any elements"); } elements.reserve(n_elements); @@ -230,27 +237,29 @@ MeshLib::Mesh* readGMSHMesh(std::string const& fname) int mat_id(0); std::tie(elem, mat_id) = readElement(in, nodes, id_map); - if (elem) { + if (elem) + { elements.push_back(elem); materials.push_back(mat_id); } } - getline(in, line); // END keyword + getline(in, line); // END keyword } if (line.find("PhysicalNames") != std::string::npos) { std::size_t n_lines(0); - in >> n_lines >> std::ws; // number-of-lines + 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 + getline(in, line); // END keyword } } in.close(); - if (elements.empty()) { + if (elements.empty()) + { for (auto& node : nodes) { delete node; @@ -258,7 +267,7 @@ MeshLib::Mesh* readGMSHMesh(std::string const& fname) return nullptr; } - MeshLib::Mesh * mesh(new MeshLib::Mesh( + MeshLib::Mesh* mesh(new MeshLib::Mesh( BaseLib::extractBaseNameWithoutExtension(fname), nodes, elements)); auto* const material_ids = @@ -283,5 +292,5 @@ MeshLib::Mesh* readGMSHMesh(std::string const& fname) return mesh; } -} // end namespace GMSH -} // end namespace FileIO +} // end namespace GMSH +} // end namespace FileIO diff --git a/Applications/FileIO/GocadIO/CoordinateSystem.cpp b/Applications/FileIO/GocadIO/CoordinateSystem.cpp index 146133ed81fff438a13143f16595c90c54e26451..e13a7a05fcb3f6fee14bce6ab75482da2a855eeb 100644 --- a/Applications/FileIO/GocadIO/CoordinateSystem.cpp +++ b/Applications/FileIO/GocadIO/CoordinateSystem.cpp @@ -19,7 +19,6 @@ namespace FileIO { namespace Gocad { - std::string parseName(std::string const& str) { std::string name; @@ -27,7 +26,7 @@ std::string parseName(std::string const& str) if (start != std::string::npos) { std::size_t const end = str.find_last_of('\"'); - name = str.substr(start+1, end-start-1); + name = str.substr(start + 1, end - start - 1); } else { @@ -53,7 +52,7 @@ bool CoordinateSystem::parse(std::istream& in) projection = ""; datum = ""; - while ( std::getline(in, line)) + while (std::getline(in, line)) { tok.assign(line); it = tok.begin(); @@ -105,7 +104,7 @@ bool CoordinateSystem::parse(std::istream& in) line); } } - ERR ("Error: Unexpected end of file."); + ERR("Error: Unexpected end of file."); return false; } diff --git a/Applications/FileIO/GocadIO/GenerateFaceSetMeshes.cpp b/Applications/FileIO/GocadIO/GenerateFaceSetMeshes.cpp index ec7d06e33188be09c7368a1ad0a5ff2d16b1a11b..e2ac86c10bc0c621c1acc53bb871e6ef75126881 100644 --- a/Applications/FileIO/GocadIO/GenerateFaceSetMeshes.cpp +++ b/Applications/FileIO/GocadIO/GenerateFaceSetMeshes.cpp @@ -8,6 +8,7 @@ */ #include "GenerateFaceSetMeshes.h" + #include "MeshLib/Elements/Quad.h" #include "MeshLib/IO/writeMeshToFile.h" @@ -15,7 +16,6 @@ namespace FileIO { namespace Gocad { - void generateFaceSets(GocadSGridReader const& reader, std::string const& path) { for (std::size_t l(0); l < 128; l++) diff --git a/Applications/FileIO/GocadIO/GocadNode.cpp b/Applications/FileIO/GocadIO/GocadNode.cpp index 4bdfc290ce5831cc21e54b90c1be3fc739adfbfb..ca341adb39122aa5c158c9c40e745dcb6c04eec4 100644 --- a/Applications/FileIO/GocadIO/GocadNode.cpp +++ b/Applications/FileIO/GocadIO/GocadNode.cpp @@ -33,4 +33,3 @@ bool operator<=(GocadNode const& n0, GocadNode const& n1) } // end namespace Gocad } // end namespace FileIO - diff --git a/Applications/FileIO/GocadIO/GocadSGridReader.cpp b/Applications/FileIO/GocadIO/GocadSGridReader.cpp index 17c111c92333c24e2db2b9544e4ec67b4e925101..46014b1c21ca520543a339bcfe23aaa6c9e5f4f6 100644 --- a/Applications/FileIO/GocadIO/GocadSGridReader.cpp +++ b/Applications/FileIO/GocadIO/GocadSGridReader.cpp @@ -435,8 +435,7 @@ void GocadSGridReader::readNodesBinary() { const std::size_t layer_transition_idx( _index_calculator.getCoordsForID(k / 3)[2]); - _nodes[k / 3] = - new GocadNode(coords, k / 3, layer_transition_idx); + _nodes[k / 3] = new GocadNode(coords, k / 3, layer_transition_idx); } k++; } diff --git a/Applications/FileIO/GocadIO/Layer.cpp b/Applications/FileIO/GocadIO/Layer.cpp index 111b8f3f15bb9ed398c8cf51b2ec106fd315a306..b3233392645715850171563321c2f7b8ca6420e7 100644 --- a/Applications/FileIO/GocadIO/Layer.cpp +++ b/Applications/FileIO/GocadIO/Layer.cpp @@ -19,7 +19,6 @@ namespace FileIO { namespace Gocad { - std::ostream& operator<<(std::ostream& os, Layer const& l) { std::copy(l.regions.begin(), l.regions.end(), @@ -27,8 +26,8 @@ std::ostream& operator<<(std::ostream& os, Layer const& l) return os; } - -Layer parseLayer(std::string const& line, std::vector<Gocad::Region> const& regions) +Layer parseLayer(std::string const& line, + std::vector<Gocad::Region> const& regions) { std::istringstream iss(line); std::istream_iterator<std::string> it(iss); diff --git a/Applications/FileIO/GocadIO/Property.cpp b/Applications/FileIO/GocadIO/Property.cpp index 2e2146e5b3bcad14dae6309e1a19da21b881d575..d3da0a815111efa136fc677e99f4035ddaf256e8 100644 --- a/Applications/FileIO/GocadIO/Property.cpp +++ b/Applications/FileIO/GocadIO/Property.cpp @@ -7,21 +7,19 @@ * http://www.opengeosys.org/project/license */ +#include "Property.h" + #include <algorithm> +#include <boost/tokenizer.hpp> #include <iterator> #include <sstream> -#include <boost/tokenizer.hpp> - -#include "Property.h" - #include "BaseLib/StringTools.h" namespace FileIO { namespace Gocad { - std::ostream& operator<<(std::ostream& os, Property const& p) { return os << "'" << p._property_name << "' '" << p._property_id << "' '" diff --git a/Applications/FileIO/GocadIO/Region.cpp b/Applications/FileIO/GocadIO/Region.cpp index e2e8d466c3a40cdb1ae3094170251b9c6015b693..90fc1acca8622cce39cc58c374ff5f38f6c7178f 100644 --- a/Applications/FileIO/GocadIO/Region.cpp +++ b/Applications/FileIO/GocadIO/Region.cpp @@ -18,7 +18,6 @@ namespace FileIO { namespace Gocad { - std::ostream& operator<<(std::ostream& os, Region const& r) { return os << "(" << r.name << "|" << r.bit << ")"; diff --git a/Applications/FileIO/Legacy/OGSIOVer4.cpp b/Applications/FileIO/Legacy/OGSIOVer4.cpp index 1fb9af6232e91169dff2c8936ccefdfb42f3572d..f23fa6baa8aabef56d025151a2d8107af6e37994 100644 --- a/Applications/FileIO/Legacy/OGSIOVer4.cpp +++ b/Applications/FileIO/Legacy/OGSIOVer4.cpp @@ -18,15 +18,13 @@ #include <limits> #include <sstream> -#include "BaseLib/Logging.h" - #include "Applications/FileIO/Legacy/createSurface.h" - #include "BaseLib/FileTools.h" +#include "BaseLib/Logging.h" #include "BaseLib/StringTools.h" - #include "GeoLib/AnalyticalGeometry.h" #include "GeoLib/GEOObjects.h" +#include "GeoLib/IO/TINInterface.h" #include "GeoLib/Point.h" #include "GeoLib/PointVec.h" #include "GeoLib/Polygon.h" @@ -35,12 +33,10 @@ #include "GeoLib/Surface.h" #include "GeoLib/Triangle.h" -#include "GeoLib/IO/TINInterface.h" - namespace FileIO { -namespace Legacy { - +namespace Legacy +{ /************************************************************************** GeoLib- Function: readPoints Aufgabe: Lesen der GLI Points und schreiben in einen Vector @@ -49,8 +45,9 @@ namespace Legacy { **************************************************************************/ /** reads the points inclusive their names from input stream in * using the OGS-4 file format */ -std::string readPoints(std::istream &in, std::vector<GeoLib::Point*>* pnt_vec, - bool &zero_based_indexing, std::map<std::string,std::size_t>* pnt_id_name_map) +std::string readPoints(std::istream& in, std::vector<GeoLib::Point*>* pnt_vec, + bool& zero_based_indexing, + std::map<std::string, std::size_t>* pnt_id_name_map) { std::string line; std::size_t cnt(0); @@ -67,7 +64,7 @@ std::string readPoints(std::istream &in, std::vector<GeoLib::Point*>* pnt_vec, double y; double z; inss >> id >> x >> y >> z; - if (!inss.fail ()) + if (!inss.fail()) { if (cnt == 0) { @@ -85,13 +82,13 @@ std::string readPoints(std::istream &in, std::vector<GeoLib::Point*>* pnt_vec, } // read name of point - std::size_t pos (line.find("$NAME")); - if (pos != std::string::npos) //OK + std::size_t pos(line.find("$NAME")); + if (pos != std::string::npos) // OK { - std::size_t end_pos ((line.substr (pos + 6)).find(' ')); + 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; + (*pnt_id_name_map)[line.substr(pos + 6, end_pos)] = id; } else { @@ -99,7 +96,7 @@ std::string readPoints(std::istream &in, std::vector<GeoLib::Point*>* pnt_vec, } } - std::size_t id_pos (line.find("$ID")); + std::size_t id_pos(line.find("$ID")); if (id_pos != std::string::npos) { WARN( @@ -116,18 +113,20 @@ std::string readPoints(std::istream &in, std::vector<GeoLib::Point*>* pnt_vec, } /** reads points from a vector */ -void readPolylinePointVector(const std::string &fname, +void readPolylinePointVector(const std::string& fname, std::vector<GeoLib::Point*>& pnt_vec, GeoLib::Polyline* ply, - const std::string &path, - std::vector<std::string> &errors) + const std::string& path, + std::vector<std::string>& errors) { // open file std::ifstream in(BaseLib::joinPaths(path, fname).c_str()); - if (!in) { + if (!in) + { WARN("readPolylinePointVector(): error opening stream from {:s}", fname); - errors.push_back ("[readPolylinePointVector] error opening stream from " + fname); + errors.push_back( + "[readPolylinePointVector] error opening stream from " + fname); return; } @@ -155,37 +154,38 @@ void readPolylinePointVector(const std::string &fname, 01/2010 TF cleaned method from unused variables **************************************************************************/ /** read a single Polyline from stream in into the ply_vec-vector */ -std::string readPolyline(std::istream &in, +std::string readPolyline(std::istream& in, std::vector<GeoLib::Polyline*>* ply_vec, - std::map<std::string,std::size_t>& ply_vec_names, - std::vector<GeoLib::Point*> & pnt_vec, + std::map<std::string, std::size_t>& ply_vec_names, + std::vector<GeoLib::Point*>& pnt_vec, bool zero_based_indexing, const std::vector<std::size_t>& pnt_id_map, - const std::string &path, - std::vector<std::string> &errors) + const std::string& path, + std::vector<std::string>& errors) { std::string line; std::string name_of_ply; auto* ply(new GeoLib::Polyline(pnt_vec)); - std::size_t type = 2; // need an initial value + std::size_t type = 2; // need an initial value // Loop over all phases or components - do { + do + { in >> line; if (line.find("$ID") != std::string::npos) { // subkeyword found CC in >> line; // read value } //.................................................................... - if (line.find("$NAME") != std::string::npos) // subkeyword found + if (line.find("$NAME") != std::string::npos) // subkeyword found { in >> line; - name_of_ply = line; // read value + name_of_ply = line; // read value } //.................................................................... - if (line.find("$TYPE") != std::string::npos) // subkeyword found + if (line.find("$TYPE") != std::string::npos) // subkeyword found { - in >> line; // read value + in >> line; // read value type = static_cast<std::size_t>(strtol(line.c_str(), nullptr, 0)); } //.................................................................... @@ -199,8 +199,8 @@ std::string readPolyline(std::istream &in, in >> line; // read value } //.................................................................... - if (line.find("$POINTS") != std::string::npos) // subkeyword found - { // read the point ids + if (line.find("$POINTS") != std::string::npos) // subkeyword found + { // read the point ids in >> line; if (type != 100) { @@ -230,7 +230,9 @@ std::string readPolyline(std::istream &in, } else { - WARN("readPolyline(): polyline is an arc *** reading not implemented"); + WARN( + "readPolyline(): polyline is an arc *** reading not " + "implemented"); errors.emplace_back( "[readPolyline] reading polyline as an arc is not " "implemented"); @@ -238,17 +240,19 @@ std::string readPolyline(std::istream &in, // empty line or the keyword or subkeyword or end of file } //.................................................................... - if (line.find("$POINT_VECTOR") != std::string::npos) // subkeyword found + if (line.find("$POINT_VECTOR") != + std::string::npos) // subkeyword found { - in >> line; // read file name + in >> line; // read file name line = BaseLib::joinPaths(path, line); readPolylinePointVector(line, pnt_vec, ply, path, errors); - } // subkeyword found + } // subkeyword found } while (line.find('#') == std::string::npos && !line.empty() && in); if (type != 100) { - ply_vec_names.insert (std::pair<std::string,std::size_t>(name_of_ply, ply_vec->size())); + ply_vec_names.insert( + std::pair<std::string, std::size_t>(name_of_ply, ply_vec->size())); ply_vec->push_back(ply); } @@ -261,20 +265,22 @@ std::string readPolyline(std::istream &in, Programming: 03/2004 CC Implementation 05/2004 CC Modification - 04/2005 CC Modification calculate the minimal distance between points reference for - mesh density of line element calculation - 07/2005 CC read ID of polyline - 08/2005 CC parameter - 01/2010 TF changed signature of function + 04/2005 CC Modification calculate the minimal distance between points +reference for mesh density of line element calculation 07/2005 CC read ID of +polyline 08/2005 CC parameter 01/2010 TF changed signature of function **************************************************************************/ /** reads polylines */ -std::string readPolylines(std::istream &in, std::vector<GeoLib::Polyline*>* ply_vec, - std::map<std::string,std::size_t>& ply_vec_names, - std::vector<GeoLib::Point*> & pnt_vec, - bool zero_based_indexing, const std::vector<std::size_t>& pnt_id_map, - const std::string &path, std::vector<std::string>& errors) +std::string readPolylines(std::istream& in, + std::vector<GeoLib::Polyline*>* ply_vec, + std::map<std::string, std::size_t>& ply_vec_names, + std::vector<GeoLib::Point*>& pnt_vec, + bool zero_based_indexing, + const std::vector<std::size_t>& pnt_id_map, + const std::string& path, + std::vector<std::string>& errors) { - if (!in) { + if (!in) + { WARN("readPolylines(): input stream error."); return std::string(""); } @@ -312,26 +318,27 @@ std::string readSurface(std::istream& in, std::string line; GeoLib::Surface* sfc(nullptr); - int type (-1); + int type(-1); std::string name; - std::size_t ply_id (std::numeric_limits<std::size_t>::max()); + std::size_t ply_id(std::numeric_limits<std::size_t>::max()); - do { + do + { in >> line; if (line.find("$ID") != std::string::npos) { // subkeyword found CC in >> line; // read value } //.................................................................... - if (line.find("$NAME") != std::string::npos) // subkeyword found + if (line.find("$NAME") != std::string::npos) // subkeyword found { - in >> line; // read value + in >> line; // read value name = line; } //.................................................................... - if (line.find("$TYPE") != std::string::npos) // subkeyword found + if (line.find("$TYPE") != std::string::npos) // subkeyword found { - in >> line; // read value + in >> line; // read value type = strtol(line.c_str(), nullptr, 0); } //.................................................................... @@ -340,11 +347,12 @@ std::string readSurface(std::istream& in, in >> line; // read value } //.................................................................... - if (line.find("$TIN") != std::string::npos) // subkeyword found + if (line.find("$TIN") != std::string::npos) // subkeyword found { - in >> line; // read value (file name) + in >> line; // read value (file name) std::string const file_name = BaseLib::joinPaths(path, line); - sfc = GeoLib::IO::TINInterface::readTIN(file_name, pnt_vec, &errors); + sfc = + GeoLib::IO::TINInterface::readTIN(file_name, pnt_vec, &errors); } //.................................................................... if (line.find("$MAT_GROUP") != std::string::npos) @@ -352,14 +360,15 @@ std::string readSurface(std::istream& in, in >> line; // read value } //.................................................................... - if (line.find("$POLYLINES") != std::string::npos) // subkeyword found - { // read the name of the polyline(s) + if (line.find("$POLYLINES") != std::string::npos) // subkeyword found + { // read the name of the polyline(s) in >> line; while (!in.eof() && !in.fail() && !line.empty() && (line.find('#') == std::string::npos) && (line.find('$') == std::string::npos)) { - // we did read the name of a polyline -> search the id for polyline + // 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()) { @@ -370,19 +379,28 @@ std::string readSurface(std::istream& in, ply_id = ply_vec.size(); } - if (ply_id == ply_vec.size()) { + if (ply_id == ply_vec.size()) + { WARN("readSurface(): polyline for surface not found!"); errors.emplace_back( "[readSurface] polyline for surface not found!"); - } else { - if (type == 3) { - WARN("readSurface(): surface type 3: flat surface with any normal direction - reading not implemented."); + } + else + { + if (type == 3) + { + WARN( + "readSurface(): surface type 3: flat surface with " + "any normal direction - reading not implemented."); errors.emplace_back( "[readSurface] surface type 3: flat surface with " "any normal direction - reading not implemented"); } - if (type == 2) { - WARN("readSurface(): vertical surface (type 2) - reading not implemented"); + if (type == 2) + { + WARN( + "readSurface(): vertical surface (type 2) - " + "reading not implemented"); errors.emplace_back( "[readSurface] vertical surface (type 2) - reading " "not implemented"); @@ -403,16 +421,18 @@ std::string readSurface(std::istream& in, if (sfc) { // surface create by TIN - sfc_vec.push_back (sfc); + sfc_vec.push_back(sfc); } else { // surface created by polygon - if (ply_id != std::numeric_limits<std::size_t>::max() && ply_id != ply_vec.size()) + if (ply_id != std::numeric_limits<std::size_t>::max() && + ply_id != ply_vec.size()) { if (ply_vec[ply_id]->isClosed()) { - polygon_vec.push_back (new GeoLib::Polygon (*(ply_vec[ply_id]), true)); + polygon_vec.push_back( + new GeoLib::Polygon(*(ply_vec[ply_id]), true)); } else { @@ -442,8 +462,7 @@ std::string readSurfaces( const std::map<std::string, std::size_t>& ply_vec_names, GeoLib::PointVec& pnt_vec, const std::string& path, std::vector<std::string>& errors, GeoLib::GEOObjects& geo, - std::string const& unique_name, - std::string const& gmsh_path) + std::string const& unique_name, std::string const& gmsh_path) { if (!in.good()) { @@ -456,7 +475,7 @@ std::string readSurfaces( while (!in.eof() && !in.fail() && tag.find("#SURFACE") != std::string::npos) { - std::size_t n_polygons (polygon_vec.size()); + std::size_t n_polygons(polygon_vec.size()); tag = readSurface(in, polygon_vec, sfc_vec, sfc_names, ply_vec, ply_vec_names, pnt_vec, path, errors); if (n_polygons < polygon_vec.size()) @@ -492,7 +511,8 @@ bool readGLIFileV4(const std::string& fname, { INFO("GeoLib::readGLIFile(): open stream from file {:s}.", fname); std::ifstream in(fname.c_str()); - if (!in) { + if (!in) + { WARN("GeoLib::readGLIFile(): could not open file {:s}.", fname); errors.push_back("[readGLIFileV4] error opening stream from " + fname); return false; @@ -506,9 +526,8 @@ bool readGLIFileV4(const std::string& fname, } // read names of points into vector of strings - auto pnt_id_names_map = - std::unique_ptr<std::map<std::string, std::size_t>> - { new std::map<std::string, std::size_t> }; + auto pnt_id_names_map = std::unique_ptr<std::map<std::string, std::size_t>>{ + new std::map<std::string, std::size_t>}; bool zero_based_idx(true); auto pnt_vec = std::make_unique<std::vector<GeoLib::Point*>>(); @@ -529,16 +548,16 @@ bool readGLIFileV4(const std::string& fname, // read names of plys into temporary string-vec auto ply_names = std::make_unique<std::map<std::string, std::size_t>>(); auto ply_vec = std::make_unique<std::vector<GeoLib::Polyline*>>(); - GeoLib::PointVec & point_vec( + GeoLib::PointVec& point_vec( *const_cast<GeoLib::PointVec*>(geo.getPointVecObj(unique_name))); auto* geo_pnt_vec( const_cast<std::vector<GeoLib::Point*>*>(point_vec.getVector())); if (tag.find("#POLYLINE") != std::string::npos && in) { INFO("GeoLib::readGLIFile(): read polylines from stream."); - tag = readPolylines(in, ply_vec.get(), *ply_names, *geo_pnt_vec, - zero_based_idx, - geo.getPointVecObj(unique_name)->getIDMap(), path, errors); + tag = readPolylines( + in, ply_vec.get(), *ply_names, *geo_pnt_vec, zero_based_idx, + geo.getPointVecObj(unique_name)->getIDMap(), path, errors); INFO("GeoLib::readGLIFile(): \t ok, {:d} polylines read.", ply_vec->size()); } @@ -591,21 +610,32 @@ bool readGLIFileV4(const std::string& fname, return errors.empty(); } -std::size_t writeTINSurfaces(std::ofstream &os, GeoLib::SurfaceVec const* sfcs_vec, std::size_t sfc_count, std::string const& path) +std::size_t writeTINSurfaces(std::ofstream& os, + GeoLib::SurfaceVec const* sfcs_vec, + std::size_t sfc_count, std::string const& path) { - const std::vector<GeoLib::Surface*>* sfcs (sfcs_vec->getVector()); + const std::vector<GeoLib::Surface*>* sfcs(sfcs_vec->getVector()); for (auto sfc : *sfcs) { - os << "#SURFACE" << "\n"; + os << "#SURFACE" + << "\n"; std::string sfc_name; - if (sfcs_vec->getNameOfElementByID (sfc_count, sfc_name)) { - os << "\t$NAME " << "\n" << "\t\t" << sfc_name << "\n"; - } else { - os << "\t$NAME " << "\n" << "\t\t" << sfc_count << "\n"; - sfc_name = std::to_string (sfc_count); + if (sfcs_vec->getNameOfElementByID(sfc_count, sfc_name)) + { + os << "\t$NAME " + << "\n" + << "\t\t" << sfc_name << "\n"; + } + else + { + os << "\t$NAME " + << "\n" + << "\t\t" << sfc_count << "\n"; + sfc_name = std::to_string(sfc_count); } sfc_name += ".tin"; - os << "\t$TIN" << "\n"; + os << "\t$TIN" + << "\n"; os << "\t\t" << sfc_name << "\n"; // create tin file sfc_name = BaseLib::joinPaths(path, sfc_name); @@ -615,42 +645,50 @@ std::size_t writeTINSurfaces(std::ofstream &os, GeoLib::SurfaceVec const* sfcs_v return sfc_count; } -void writeGLIFileV4 (const std::string& fname, - const std::string& geo_name, - const GeoLib::GEOObjects& geo) +void writeGLIFileV4(const std::string& fname, + const std::string& geo_name, + const GeoLib::GEOObjects& geo) { GeoLib::PointVec const* const pnt_vec(geo.getPointVecObj(geo_name)); - std::vector<GeoLib::Point*> const* const pnts (pnt_vec->getVector()); - std::ofstream os (fname.c_str()); - if (pnts) { + std::vector<GeoLib::Point*> const* const pnts(pnt_vec->getVector()); + std::ofstream os(fname.c_str()); + if (pnts) + { const std::size_t n_pnts(pnts->size()); INFO("GeoLib::writeGLIFileV4(): writing {:d} points to file {:s}.", n_pnts, fname); - os << "#POINTS" << "\n"; + os << "#POINTS" + << "\n"; os.precision(std::numeric_limits<double>::digits10); - for (std::size_t k(0); k < n_pnts; k++) { + for (std::size_t k(0); k < n_pnts; k++) + { os << k << " " << *((*pnts)[k]); std::string const& pnt_name(pnt_vec->getItemNameByID(k)); - if (!pnt_name.empty()) { + if (!pnt_name.empty()) + { os << " $NAME " << pnt_name; } os << "\n"; } } - const GeoLib::PolylineVec* plys_vec (geo.getPolylineVecObj (geo_name)); + const GeoLib::PolylineVec* plys_vec(geo.getPolylineVecObj(geo_name)); if (plys_vec) { - const std::vector<GeoLib::Polyline*>* plys (plys_vec->getVector()); + const std::vector<GeoLib::Polyline*>* plys(plys_vec->getVector()); INFO("GeoLib::writeGLIFileV4(): {:d} polylines to file {:s}.", plys->size(), fname); for (auto ply : *plys) { - os << "#POLYLINE" << "\n"; + os << "#POLYLINE" + << "\n"; std::string polyline_name; plys_vec->getNameOfElement(ply, polyline_name); - os << " $NAME " << "\n" << " " << polyline_name << "\n"; - os << " $POINTS" << "\n"; + os << " $NAME " + << "\n" + << " " << polyline_name << "\n"; + os << " $POINTS" + << "\n"; for (std::size_t j(0); j < ply->getNumberOfPoints(); j++) { os << " " << ply->getPointID(j) << "\n"; @@ -659,48 +697,54 @@ void writeGLIFileV4 (const std::string& fname, } // writing surfaces as TIN files - const GeoLib::SurfaceVec* sfcs_vec (geo.getSurfaceVecObj (geo_name)); + 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 (); + os << "#STOP" + << "\n"; + os.close(); } -void writeAllDataToGLIFileV4 (const std::string& fname, const GeoLib::GEOObjects& geo) +void writeAllDataToGLIFileV4(const std::string& fname, + const GeoLib::GEOObjects& geo) { auto const geo_names = geo.getGeometryNames(); // extract path for reading external files const std::string path = BaseLib::extractPath(fname); - std::ofstream os (fname.c_str()); + std::ofstream os(fname.c_str()); - std::size_t pnts_offset (0); + std::size_t pnts_offset(0); std::vector<std::size_t> pnts_id_offset; - pnts_id_offset.push_back (0); + pnts_id_offset.push_back(0); // writing all points - os << "#POINTS" << "\n"; - for (auto & geo_name : geo_names) + os << "#POINTS" + << "\n"; + for (auto& geo_name : geo_names) { os.precision(std::numeric_limits<double>::digits10); GeoLib::PointVec const* const pnt_vec(geo.getPointVecObj(geo_name)); - std::vector<GeoLib::Point*> const* const pnts (pnt_vec->getVector()); - if (pnts) { + std::vector<GeoLib::Point*> const* const pnts(pnt_vec->getVector()); + if (pnts) + { const std::size_t n_pnts(pnts->size()); - for (std::size_t k(0); k < n_pnts; k++) { + for (std::size_t k(0); k < n_pnts; k++) + { os << pnts_offset + k << " " << *((*pnts)[k]); std::string const& pnt_name(pnt_vec->getItemNameByID(k)); - if (! pnt_name.empty()) { + if (!pnt_name.empty()) + { os << "$NAME " << pnt_name; } os << "\n"; } pnts_offset += pnts->size(); - pnts_id_offset.push_back (pnts_offset); + pnts_id_offset.push_back(pnts_offset); } } @@ -708,11 +752,11 @@ void writeAllDataToGLIFileV4 (const std::string& fname, const GeoLib::GEOObjects // writing all stations std::vector<std::string> stn_names; - geo.getStationVectorNames (stn_names); - for (auto & stn_name : stn_names) + geo.getStationVectorNames(stn_names); + for (auto& stn_name : stn_names) { os.precision(std::numeric_limits<double>::digits10); - const std::vector<GeoLib::Point*>* pnts (geo.getStationVec(stn_name)); + const std::vector<GeoLib::Point*>* pnts(geo.getStationVec(stn_name)); if (pnts) { for (std::size_t k(0); k < pnts->size(); k++) @@ -722,20 +766,24 @@ void writeAllDataToGLIFileV4 (const std::string& fname, const GeoLib::GEOObjects << "\n"; } pnts_offset += pnts->size(); - pnts_id_offset.push_back (pnts_offset); + pnts_id_offset.push_back(pnts_offset); } } - std::size_t plys_cnt (0); + std::size_t plys_cnt(0); // writing all polylines for (std::size_t j(0); j < geo_names.size(); j++) { - const GeoLib::PolylineVec* plys_vec (geo.getPolylineVecObj (geo_names[j])); - if (plys_vec) { - const std::vector<GeoLib::Polyline*>* plys (plys_vec->getVector()); - for (auto ply : *plys) { - os << "#POLYLINE" << "\n"; + const GeoLib::PolylineVec* plys_vec( + geo.getPolylineVecObj(geo_names[j])); + if (plys_vec) + { + const std::vector<GeoLib::Polyline*>* plys(plys_vec->getVector()); + for (auto ply : *plys) + { + os << "#POLYLINE" + << "\n"; std::string ply_name; os << " $NAME\n"; if (plys_vec->getNameOfElementByID(plys_cnt, ply_name)) @@ -746,7 +794,8 @@ void writeAllDataToGLIFileV4 (const std::string& fname, const GeoLib::GEOObjects { os << " " << geo_names[j] << "-" << plys_cnt << "\n"; } - os << " $POINTS" << "\n"; + os << " $POINTS" + << "\n"; for (std::size_t l(0); l < ply->getNumberOfPoints(); l++) { os << " " << pnts_id_offset[j] + ply->getPointID(l) @@ -758,19 +807,20 @@ void writeAllDataToGLIFileV4 (const std::string& fname, const GeoLib::GEOObjects } // writing surfaces as TIN files - std::size_t sfcs_cnt (0); - for (auto & geo_name : geo_names) + std::size_t sfcs_cnt(0); + for (auto& geo_name : geo_names) { - const GeoLib::SurfaceVec* sfcs_vec (geo.getSurfaceVecObj (geo_name)); + const GeoLib::SurfaceVec* sfcs_vec(geo.getSurfaceVecObj(geo_name)); if (sfcs_vec) { sfcs_cnt += writeTINSurfaces(os, sfcs_vec, sfcs_cnt, path); } } - os << "#STOP" << "\n"; - os.close (); + os << "#STOP" + << "\n"; + os.close(); } } // namespace Legacy -} // end namespace FileIO +} // end namespace FileIO diff --git a/Applications/FileIO/Legacy/createSurface.cpp b/Applications/FileIO/Legacy/createSurface.cpp index 72cb2f6bf63d6f261b8868b04dad2d2df4c2f536..bd956f3026039d37ae4ecac31b04cdfd96a79016 100644 --- a/Applications/FileIO/Legacy/createSurface.cpp +++ b/Applications/FileIO/Legacy/createSurface.cpp @@ -8,28 +8,24 @@ * */ +#include "createSurface.h" + #include <cstdio> #include <list> #include <memory> -#include "BaseLib/Logging.h" - -#include "createSurface.h" -#include "filesystem.h" - #include "Applications/FileIO/Gmsh/GMSHInterface.h" - +#include "BaseLib/Logging.h" #include "BaseLib/StringTools.h" - #include "GeoLib/GEOObjects.h" #include "GeoLib/Point.h" #include "GeoLib/Polygon.h" #include "GeoLib/Polyline.h" #include "GeoLib/Surface.h" - #include "MeshLib/IO/readMeshFromFile.h" -#include "MeshLib/convertMeshToGeo.h" #include "MeshLib/Mesh.h" +#include "MeshLib/convertMeshToGeo.h" +#include "filesystem.h" namespace FileIO { @@ -84,9 +80,9 @@ bool createSurface(GeoLib::Polyline const& ply, BaseLib::IO::writeStringToFile(gmsh_io.writeToString(), geo_file); // Using GMSH's vtk output here so we don't have to deal with GMSH and it's // various file format versions here - std::string gmsh_command = - "\"" + gmsh_binary + "\" -2 -algo meshadapt -format vtk -o " - + msh_file.string() + " " + geo_file.string(); + std::string gmsh_command = "\"" + gmsh_binary + + "\" -2 -algo meshadapt -format vtk -o " + + msh_file.string() + " " + geo_file.string(); int const gmsh_return_value = std::system(gmsh_command.c_str()); if (gmsh_return_value != 0) diff --git a/Applications/FileIO/PetrelInterface.cpp b/Applications/FileIO/PetrelInterface.cpp index 071d45679aa9b02399d56f20258869ce48ee4b52..d4d4b70eecb416dd17f91a84736255d9b115206e 100644 --- a/Applications/FileIO/PetrelInterface.cpp +++ b/Applications/FileIO/PetrelInterface.cpp @@ -20,21 +20,24 @@ #include <fstream> #include "BaseLib/Logging.h" - #include "BaseLib/StringTools.h" -#include "GeoLib/StationBorehole.h" #include "GeoLib/GEOObjects.h" +#include "GeoLib/StationBorehole.h" namespace FileIO { -PetrelInterface::PetrelInterface(std::list<std::string> &sfc_fnames, - std::list<std::string> &well_path_fnames, - std::string &unique_model_name, GeoLib::GEOObjects* geo_obj) : - _unique_name(unique_model_name), pnt_vec(new std::vector<GeoLib::Point*>), - well_vec(new std::vector<GeoLib::Point*>), ply_vec(new std::vector<GeoLib::Polyline*>) +PetrelInterface::PetrelInterface(std::list<std::string>& sfc_fnames, + std::list<std::string>& well_path_fnames, + std::string& unique_model_name, + GeoLib::GEOObjects* geo_obj) + : _unique_name(unique_model_name), + pnt_vec(new std::vector<GeoLib::Point*>), + well_vec(new std::vector<GeoLib::Point*>), + ply_vec(new std::vector<GeoLib::Polyline*>) { - for (std::list<std::string>::const_iterator it(sfc_fnames.begin()); it - != sfc_fnames.end(); ++it) + for (std::list<std::string>::const_iterator it(sfc_fnames.begin()); + it != sfc_fnames.end(); + ++it) { INFO("PetrelInterface::PetrelInterface(): open surface file."); std::ifstream in((*it).c_str()); @@ -53,8 +56,9 @@ PetrelInterface::PetrelInterface(std::list<std::string> &sfc_fnames, } } - for (std::list<std::string>::const_iterator it(well_path_fnames.begin()); it - != well_path_fnames.end(); ++it) + for (std::list<std::string>::const_iterator it(well_path_fnames.begin()); + it != well_path_fnames.end(); + ++it) { INFO("PetrelInterface::PetrelInterface(): open well path file."); std::ifstream in((*it).c_str()); @@ -90,7 +94,7 @@ PetrelInterface::PetrelInterface(std::list<std::string> &sfc_fnames, } } -void PetrelInterface::readPetrelSurface(std::istream &in) +void PetrelInterface::readPetrelSurface(std::istream& in) { char buffer[MAX_COLS_PER_ROW]; in.getline(buffer, MAX_COLS_PER_ROW); @@ -138,7 +142,7 @@ void PetrelInterface::readPetrelSurface(std::istream &in) } } -void PetrelInterface::readPetrelWellTrace(std::istream &in) +void PetrelInterface::readPetrelWellTrace(std::istream& in) { char buffer[MAX_COLS_PER_ROW]; in.getline(buffer, MAX_COLS_PER_ROW); @@ -152,7 +156,8 @@ void PetrelInterface::readPetrelWellTrace(std::istream &in) line = buffer; std::list<std::string> str_list(BaseLib::splitString(line, ' ')); std::list<std::string>::const_iterator it(str_list.begin()); - while (it != str_list.end()) { + while (it != str_list.end()) + { INFO("PetrelInterface::readPetrelWellTrace(): well name: {:s}.", it->c_str()); ++it; @@ -163,7 +168,8 @@ void PetrelInterface::readPetrelWellTrace(std::istream &in) line = buffer; str_list = BaseLib::splitString(line, ' '); it = str_list.begin(); - while (it != str_list.end()) { + while (it != str_list.end()) + { INFO( "PetrelInterface::readPetrelWellTrace(): well head x coord: " "{:s}.", @@ -180,7 +186,8 @@ void PetrelInterface::readPetrelWellTrace(std::istream &in) line = buffer; str_list = BaseLib::splitString(line, ' '); it = str_list.begin(); - while (it != str_list.end()) { + while (it != str_list.end()) + { INFO( "PetrelInterface::readPetrelWellTrace(): well head y coord: " "{:s}.", @@ -196,7 +203,8 @@ void PetrelInterface::readPetrelWellTrace(std::istream &in) line = buffer; str_list = BaseLib::splitString(line, ' '); it = str_list.begin(); - while (it != str_list.end()) { + while (it != str_list.end()) + { INFO("PetrelInterface::readPetrelWellTrace(): well kb entry: {:s}.", it->c_str()); ++it; @@ -209,17 +217,18 @@ void PetrelInterface::readPetrelWellTrace(std::istream &in) well_head_x, well_head_y, well_kb); - well_vec->push_back(new GeoLib::StationBorehole(well_head_x, well_head_y, well_kb)); + well_vec->push_back( + new GeoLib::StationBorehole(well_head_x, well_head_y, well_kb)); // read well type in.getline(buffer, MAX_COLS_PER_ROW); -// std::string type(*((str_list.end())--)); + // std::string type(*((str_list.end())--)); readPetrelWellTraceData(in); } } -void PetrelInterface::readPetrelWellTraceData(std::istream &in) +void PetrelInterface::readPetrelWellTraceData(std::istream& in) { char buffer[MAX_COLS_PER_ROW]; in.getline(buffer, MAX_COLS_PER_ROW); @@ -237,7 +246,8 @@ void PetrelInterface::readPetrelWellTraceData(std::istream &in) // read column information std::list<std::string> str_list = BaseLib::splitString(line, ' '); auto it = str_list.begin(); - while (it != str_list.end()) { + while (it != str_list.end()) + { INFO( "PetrelInterface::readPetrelWellTraceData(): column information: " "{:s}.", @@ -266,12 +276,13 @@ void PetrelInterface::readPetrelWellTraceData(std::istream &in) stream >> md; stream >> x >> y >> z; // pnt_vec->push_back (new GeoLib::Point (x,y,z)); - static_cast<GeoLib::StationBorehole*> ((*well_vec)[well_vec->size() - 1])->addSoilLayer( - x, y, z, "unknown"); + static_cast<GeoLib::StationBorehole*>( + (*well_vec)[well_vec->size() - 1]) + ->addSoilLayer(x, y, z, "unknown"); stream >> tvd >> dx >> dy >> azim >> incl >> dls; } in.getline(buffer, MAX_COLS_PER_ROW); line = buffer; } } -} // end namespace FileIO +} // end namespace FileIO diff --git a/Applications/FileIO/SHPInterface.cpp b/Applications/FileIO/SHPInterface.cpp index 5aaa0d61fa785fe753c4e2faf6b112eaca120ebc..5eddb3d215add9600fee2afb0df4a52be485bcd5 100644 --- a/Applications/FileIO/SHPInterface.cpp +++ b/Applications/FileIO/SHPInterface.cpp @@ -17,25 +17,22 @@ #include "SHPInterface.h" -#include "BaseLib/Logging.h" - #include "Applications/FileIO/Legacy/createSurface.h" - +#include "BaseLib/Logging.h" #include "GeoLib/AnalyticalGeometry.h" #include "GeoLib/GEOObjects.h" -#include "GeoLib/Polyline.h" #include "GeoLib/Point.h" - -#include "MeshLib/Mesh.h" -#include "MeshLib/Node.h" +#include "GeoLib/Polyline.h" #include "MeshLib/Elements/Element.h" -#include "MeshLib/Elements/Tri.h" #include "MeshLib/Elements/Quad.h" +#include "MeshLib/Elements/Tri.h" +#include "MeshLib/Mesh.h" +#include "MeshLib/Node.h" namespace FileIO { - -bool SHPInterface::readSHPInfo(const std::string &filename, int &shapeType, int &numberOfEntities) +bool SHPInterface::readSHPInfo(const std::string& filename, int& shapeType, + int& numberOfEntities) { SHPHandle hSHP = SHPOpen(filename.c_str(), "rb"); if (!hSHP) @@ -46,8 +43,9 @@ bool SHPInterface::readSHPInfo(const std::string &filename, int &shapeType, int double padfMinBound[4]; double padfMaxBound[4]; - // The SHPGetInfo() function retrieves various information about shapefile as a whole. - // The bounds are read from the file header, and may be inaccurate if the file was improperly generated. + // The SHPGetInfo() function retrieves various information about shapefile + // as a whole. The bounds are read from the file header, and may be + // inaccurate if the file was improperly generated. SHPGetInfo(hSHP, &numberOfEntities, &shapeType, padfMinBound, padfMaxBound); SHPClose(hSHP); @@ -87,13 +85,16 @@ void SHPInterface::readSHPFile(const std::string& filename, OGSType choice, } } -void SHPInterface::readPoints(const SHPHandle &hSHP, int numberOfElements, std::string listName) +void SHPInterface::readPoints(const SHPHandle& hSHP, int numberOfElements, + std::string listName) { - if (numberOfElements > 0) { + if (numberOfElements > 0) + { auto points = std::make_unique<std::vector<GeoLib::Point*>>(); SHPObject* hSHPObject; - for (int i = 0; i < numberOfElements; i++) { + for (int i = 0; i < numberOfElements; i++) + { hSHPObject = SHPReadObject(hSHP, i); auto* pnt = @@ -103,32 +104,37 @@ void SHPInterface::readPoints(const SHPHandle &hSHP, int numberOfElements, std:: } _geoObjects.addPointVec(std::move(points), listName); - SHPDestroyObject(hSHPObject); // de-allocate SHPObject + SHPDestroyObject(hSHPObject); // de-allocate SHPObject } } -void SHPInterface::readStations(const SHPHandle &hSHP, int numberOfElements, std::string listName) +void SHPInterface::readStations(const SHPHandle& hSHP, int numberOfElements, + std::string listName) { - if (numberOfElements > 0) { + if (numberOfElements > 0) + { auto stations = std::make_unique<std::vector<GeoLib::Point*>>(); stations->reserve(numberOfElements); SHPObject* hSHPObject; - for (int i = 0; i < numberOfElements; i++) { + for (int i = 0; i < numberOfElements; i++) + { hSHPObject = SHPReadObject(hSHP, i); - GeoLib::Station* stn = GeoLib::Station::createStation(std::to_string(i), - *(hSHPObject->padfX), - *(hSHPObject->padfY), - *(hSHPObject->padfZ)); + GeoLib::Station* stn = + GeoLib::Station::createStation(std::to_string(i), + *(hSHPObject->padfX), + *(hSHPObject->padfY), + *(hSHPObject->padfZ)); stations->push_back(stn); } _geoObjects.addStationVec(std::move(stations), listName); - SHPDestroyObject(hSHPObject); // de-allocate SHPObject + SHPDestroyObject(hSHPObject); // de-allocate SHPObject } } -void SHPInterface::readPolylines(const SHPHandle &hSHP, int numberOfElements, std::string listName) +void SHPInterface::readPolylines(const SHPHandle& hSHP, int numberOfElements, + std::string listName) { if (numberOfElements <= 0) { @@ -139,24 +145,29 @@ void SHPInterface::readPolylines(const SHPHandle &hSHP, int numberOfElements, st std::size_t pnt_id(0); // for each polyline - for (int i = 0; i < numberOfElements; ++i) { - SHPObject *hSHPObject = SHPReadObject(hSHP, i); + for (int i = 0; i < numberOfElements; ++i) + { + SHPObject* hSHPObject = SHPReadObject(hSHP, i); int const noOfPoints = hSHPObject->nVertices; int const noOfParts = hSHPObject->nParts; - for (int p = 0; p < noOfParts; ++p) { + for (int p = 0; p < noOfParts; ++p) + { int const firstPnt = *(hSHPObject->panPartStart + p); - int const lastPnt = (p<(noOfParts - 1)) ? - *(hSHPObject->panPartStart + p + 1) : noOfPoints; + int const lastPnt = (p < (noOfParts - 1)) + ? *(hSHPObject->panPartStart + p + 1) + : noOfPoints; // for each point in that polyline - for (int j = firstPnt; j < lastPnt; ++j) { - pnts->push_back(new GeoLib::Point(*(hSHPObject->padfX+j), - *(hSHPObject->padfY+j), *(hSHPObject->padfZ+j), pnt_id)); + for (int j = firstPnt; j < lastPnt; ++j) + { + pnts->push_back(new GeoLib::Point( + *(hSHPObject->padfX + j), *(hSHPObject->padfY + j), + *(hSHPObject->padfZ + j), pnt_id)); pnt_id++; } } - SHPDestroyObject(hSHPObject); // de-allocate SHPObject + SHPDestroyObject(hSHPObject); // de-allocate SHPObject } _geoObjects.addPointVec(std::move(pnts), listName); @@ -164,27 +175,31 @@ void SHPInterface::readPolylines(const SHPHandle &hSHP, int numberOfElements, st std::vector<std::size_t> const& pnt_id_map(points.getIDMap()); pnt_id = 0; - for (int i = 0; i < numberOfElements; ++i) { + for (int i = 0; i < numberOfElements; ++i) + { SHPObject* hSHPObject = SHPReadObject(hSHP, i); int const noOfPoints = hSHPObject->nVertices; int const noOfParts = hSHPObject->nParts; - for (int p = 0; p < noOfParts; ++p) { + for (int p = 0; p < noOfParts; ++p) + { int const firstPnt = *(hSHPObject->panPartStart + p); - int const lastPnt = (p<(noOfParts - 1)) ? - *(hSHPObject->panPartStart + p + 1) : noOfPoints; + int const lastPnt = (p < (noOfParts - 1)) + ? *(hSHPObject->panPartStart + p + 1) + : noOfPoints; auto* line = new GeoLib::Polyline(*points.getVector()); // create polyline - for (int j = firstPnt; j < lastPnt; ++j) { + for (int j = firstPnt; j < lastPnt; ++j) + { line->addPoint(pnt_id_map[pnt_id]); pnt_id++; } // add polyline to polyline vector lines->push_back(line); } - SHPDestroyObject(hSHPObject); // de-allocate SHPObject + SHPDestroyObject(hSHPObject); // de-allocate SHPObject } _geoObjects.addPolylineVec(std::move(lines), listName); } @@ -213,7 +228,8 @@ void SHPInterface::readPolygons(const SHPHandle& hSHP, int numberOfElements, } } -bool SHPInterface::write2dMeshToSHP(const std::string &file_name, const MeshLib::Mesh &mesh) +bool SHPInterface::write2dMeshToSHP(const std::string& file_name, + const MeshLib::Mesh& mesh) { if (mesh.getDimension() != 2) { @@ -233,7 +249,7 @@ bool SHPInterface::write2dMeshToSHP(const std::string &file_name, const MeshLib: // integer values. The exponent controls maximum number of elements and // the maximum number of digits written in the DBF file. std::size_t const max_exp = 8; - if (n_elements >= std::pow(10,max_exp)) + if (n_elements >= std::pow(10, max_exp)) { ERR("SHPInterface::write2dMeshToSHP(): Mesh contains too many elements " "for currently implemented DBF-boundaries."); @@ -242,7 +258,8 @@ bool SHPInterface::write2dMeshToSHP(const std::string &file_name, const MeshLib: SHPHandle hSHP = SHPCreate(file_name.c_str(), SHPT_POLYGON); DBFHandle hDBF = DBFCreate(file_name.c_str()); - int const elem_id_field = DBFAddField(hDBF, "Elem_ID", FTInteger, max_exp, 0); + int const elem_id_field = + DBFAddField(hDBF, "Elem_ID", FTInteger, max_exp, 0); // Writing mesh elements to shape file std::size_t shp_record(0); @@ -258,7 +275,8 @@ bool SHPInterface::write2dMeshToSHP(const std::string &file_name, const MeshLib: SHPDestroyObject(object); // write element ID to DBF-file - DBFWriteIntegerAttribute(hDBF, shp_record, elem_id_field, e->getID()); + DBFWriteIntegerAttribute(hDBF, shp_record, elem_id_field, + e->getID()); shp_record++; } } @@ -273,7 +291,8 @@ bool SHPInterface::write2dMeshToSHP(const std::string &file_name, const MeshLib: int const field = DBFAddField(hDBF, name.c_str(), FTInteger, 16, 0); for (int i = 0; i < n_recs; ++i) { - std::size_t const elem_idx = DBFReadIntegerAttribute(hDBF, i, elem_id_field); + std::size_t const elem_idx = + DBFReadIntegerAttribute(hDBF, i, elem_id_field); DBFWriteIntegerAttribute(hDBF, i, field, (*p)[elem_idx]); } } @@ -283,7 +302,8 @@ bool SHPInterface::write2dMeshToSHP(const std::string &file_name, const MeshLib: int const field = DBFAddField(hDBF, name.c_str(), FTDouble, 33, 16); for (int i = 0; i < n_recs; ++i) { - std::size_t const elem_idx = DBFReadIntegerAttribute(hDBF, i, elem_id_field); + std::size_t const elem_idx = + DBFReadIntegerAttribute(hDBF, i, elem_id_field); DBFWriteDoubleAttribute(hDBF, i, field, (*p)[elem_idx]); } } diff --git a/Applications/FileIO/SWMM/SWMMInterface.cpp b/Applications/FileIO/SWMM/SWMMInterface.cpp index 43029fc13233aec33dd5558ce77f2cfdca75a188..55b36b8ac25ad0365c953ccc64b250a36898cbea 100644 --- a/Applications/FileIO/SWMM/SWMMInterface.cpp +++ b/Applications/FileIO/SWMM/SWMMInterface.cpp @@ -8,6 +8,8 @@ #include "SwmmInterface.h" +#include <swmm5_iface.h> + #include <boost/algorithm/string/predicate.hpp> #include <cctype> #include <fstream> @@ -25,14 +27,11 @@ #include "MeshLib/Mesh.h" #include "MeshLib/Node.h" #include "MeshLib/Properties.h" -#include <swmm5_iface.h> namespace FileIO { - /// Variables that always exist for subcatchments. There might be more. -const std::array<std::string,9> subcatchment_vars = -{ +const std::array<std::string, 9> subcatchment_vars = { "rainfall", "snow depth", "evaporation loss", @@ -41,35 +40,27 @@ const std::array<std::string,9> subcatchment_vars = "groundwater outflow", "groundwater head", "moisture content", - "concentration of pollutant" -}; + "concentration of pollutant"}; /// Variables that always exist for nodes. There might be more. -const std::array<std::string,7> node_vars = -{ - "water depth", - "hydraulic head", - "volume of stored water", - "lateral inflow", - "total inflow", - "flow lost to flooding", - "concentration of pollutant" -}; +const std::array<std::string, 7> node_vars = {"water depth", + "hydraulic head", + "volume of stored water", + "lateral inflow", + "total inflow", + "flow lost to flooding", + "concentration of pollutant"}; /// Variables that always exist for links. There might be more. -const std::array<std::string,6> link_vars = -{ - "flow rate", - "flow depth", - "flow velocity", - "flow volume", - "fraction conduit/non-conduit", - "concentration of pollutant" -}; +const std::array<std::string, 6> link_vars = {"flow rate", + "flow depth", + "flow velocity", + "flow volume", + "fraction conduit/non-conduit", + "concentration of pollutant"}; /// All variables that exist for the system. -const std::array<std::string,15> system_vars = -{ +const std::array<std::string, 15> system_vars = { "air temperature", "rainfall", "snow depth", @@ -84,41 +75,43 @@ const std::array<std::string,15> system_vars = "flow leaving through outfalls", "volume of stored water", "actual evaporation rate", - "potential evaporation rate" -}; + "potential evaporation rate"}; -/// Number of base variables for the four object types (subcatchments/nodes/links/system). -std::array<std::size_t,4> const n_obj_params = { 8, 6, 5, 15 }; +/// Number of base variables for the four object types +/// (subcatchments/nodes/links/system). +std::array<std::size_t, 4> const n_obj_params = {8, 6, 5, 15}; -std::unique_ptr<SwmmInterface> SwmmInterface::create(std::string const& file_name) +std::unique_ptr<SwmmInterface> SwmmInterface::create( + std::string const& file_name) { - //The input/output methods take a base name and check if the corresponding i/o file for that base name exists. - //This check takes any swmm project file, i.e. [base name].[extension] which needs to be at least 5 chars - //because the extension is always 3 chars. + // The input/output methods take a base name and check if the corresponding + // i/o file for that base name exists. This check takes any swmm project + // file, i.e. [base name].[extension] which needs to be at least 5 chars + // because the extension is always 3 chars. if (file_name.length() < 5) return nullptr; if (!SwmmInterface::isSwmmInputFile(file_name)) return nullptr; - std::string const base_name (file_name.substr(0, file_name.length() - 4)); + std::string const base_name(file_name.substr(0, file_name.length() - 4)); SwmmInterface* swmm = new SwmmInterface(base_name); if (swmm->readSwmmInputToLineMesh()) return std::unique_ptr<SwmmInterface>(swmm); - ERR ("Error creating mesh from SWMM file."); + ERR("Error creating mesh from SWMM file."); delete swmm; return nullptr; } SwmmInterface::SwmmInterface(std::string const& swmm_base_name) -: _base_name (swmm_base_name), _mesh(nullptr) + : _base_name(swmm_base_name), _mesh(nullptr) { } SwmmInterface::~SwmmInterface() { - for (Subcatchment& sc : _subcatchments) + for (Subcatchment& sc : _subcatchments) delete sc.outline; for (GeoLib::Point* pnt : _subcatchment_points) @@ -133,7 +126,7 @@ bool SwmmInterface::isSwmmInputFile(std::string const& inp_file_name) return false; } - std::ifstream in ( inp_file_name.c_str() ); + std::ifstream in(inp_file_name.c_str()); if (!in.is_open()) { ERR("SWMMInterface: Could not open input file {:s}.", inp_file_name); @@ -141,7 +134,7 @@ bool SwmmInterface::isSwmmInputFile(std::string const& inp_file_name) } std::string line; - bool header_found (false); + bool header_found(false); std::size_t pos_end(0); while (!header_found) { @@ -152,7 +145,7 @@ bool SwmmInterface::isSwmmInputFile(std::string const& inp_file_name) pos_end = line.find_first_of(" \n", pos_beg); // skip empty or comment lines at the beginning of the file - if (line.empty() || pos_beg==pos_end || isCommentLine(line)) + if (line.empty() || pos_beg == pos_end || isCommentLine(line)) continue; if (line == "[TITLE]") @@ -171,16 +164,17 @@ bool SwmmInterface::isSwmmInputFile(std::string const& inp_file_name) bool SwmmInterface::existsSwmmOutputFile() const { - std::string const outfile (_base_name + ".out"); + std::string const outfile(_base_name + ".out"); if (OpenSwmmOutFile(const_cast<char*>(outfile.c_str())) != 0) return false; return true; } template <typename T> -bool SwmmInterface::readCoordinates(std::ifstream &in, std::vector<T*> &points, std::vector<std::string> &names) +bool SwmmInterface::readCoordinates(std::ifstream& in, std::vector<T*>& points, + std::vector<std::string>& names) { - std::size_t id (points.size()); + std::size_t id(points.size()); std::string line; while (std::getline(in, line)) @@ -191,10 +185,10 @@ bool SwmmInterface::readCoordinates(std::ifstream &in, std::vector<T*> &points, if (isCommentLine(line)) continue; - std::vector<std::string> split_str (BaseLib::splitString(line)); + std::vector<std::string> split_str(BaseLib::splitString(line)); if (split_str.size() != 3) { - ERR ("Format not recognised."); + ERR("Format not recognised."); return false; } names.push_back(split_str[0]); @@ -208,15 +202,17 @@ bool SwmmInterface::readCoordinates(std::ifstream &in, std::vector<T*> &points, return true; } -bool SwmmInterface::readPolygons(std::ifstream &in, std::vector<GeoLib::Polyline*> &lines, - std::vector<std::string> &ply_names, std::vector<GeoLib::Point*> &points, - std::vector<std::string> &pnt_names) +bool SwmmInterface::readPolygons(std::ifstream& in, + std::vector<GeoLib::Polyline*>& lines, + std::vector<std::string>& ply_names, + std::vector<GeoLib::Point*>& points, + std::vector<std::string>& pnt_names) { - bool finished (false); - std::size_t id (points.size()); + bool finished(false); + std::size_t id(points.size()); std::string line; std::string polygon_name(""); - GeoLib::Polyline* p (nullptr); + GeoLib::Polyline* p(nullptr); while (std::getline(in, line)) { if (isSectionFinished(line)) @@ -225,10 +221,10 @@ bool SwmmInterface::readPolygons(std::ifstream &in, std::vector<GeoLib::Polyline if (isCommentLine(line)) continue; - std::vector<std::string> split_str (BaseLib::splitString(line)); + std::vector<std::string> split_str(BaseLib::splitString(line)); if (split_str.size() != 3) { - ERR ("Polygon format not recognised."); + ERR("Polygon format not recognised."); delete p; return false; } @@ -250,7 +246,7 @@ bool SwmmInterface::readPolygons(std::ifstream &in, std::vector<GeoLib::Polyline double const x = BaseLib::str2number<double>(split_str[1]); double const y = BaseLib::str2number<double>(split_str[2]); points.push_back(new GeoLib::Point(x, y, 0, id)); - p->addPoint(points.size()-1); + p->addPoint(points.size() - 1); pnt_names.push_back(""); id++; } @@ -265,9 +261,9 @@ bool SwmmInterface::readPolygons(std::ifstream &in, std::vector<GeoLib::Polyline return true; } -bool SwmmInterface::addPointElevation(std::ifstream &in, - std::vector<GeoLib::Point*> &points, std::map<std::string, - std::size_t> const& name_id_map) +bool SwmmInterface::addPointElevation( + std::ifstream& in, std::vector<GeoLib::Point*>& points, + std::map<std::string, std::size_t> const& name_id_map) { std::string line; while (std::getline(in, line)) @@ -278,14 +274,14 @@ bool SwmmInterface::addPointElevation(std::ifstream &in, if (isCommentLine(line)) continue; - std::vector<std::string> const split_str (BaseLib::splitString(line)); + std::vector<std::string> const split_str(BaseLib::splitString(line)); // Junctions = 6, Outfalls = 4, Storage = 8 if (split_str.size() < 4) { - ERR ("Format not recognised."); + ERR("Format not recognised."); return false; } - std::string const current_name (split_str[0]); + std::string const current_name(split_str[0]); auto const it = name_id_map.find(current_name); if (it == name_id_map.end()) { @@ -300,9 +296,11 @@ bool SwmmInterface::addPointElevation(std::ifstream &in, return true; } -bool SwmmInterface::readLinksAsPolylines(std::ifstream &in, - std::vector<GeoLib::Polyline*> &lines, std::vector<std::string> &line_names, - std::vector<GeoLib::Point*> const& points, std::map<std::string, std::size_t> const& point_names) +bool SwmmInterface::readLinksAsPolylines( + std::ifstream& in, std::vector<GeoLib::Polyline*>& lines, + std::vector<std::string>& line_names, + std::vector<GeoLib::Point*> const& points, + std::map<std::string, std::size_t> const& point_names) { std::string line; while (std::getline(in, line)) @@ -313,15 +311,15 @@ bool SwmmInterface::readLinksAsPolylines(std::ifstream &in, if (isCommentLine(line)) continue; - std::vector<std::string> const split_str (BaseLib::splitString(line)); + std::vector<std::string> const split_str(BaseLib::splitString(line)); // Conduits = 9, Pumps = 7, Weirs = 8 if (split_str.size() < 7) { - ERR ("Conduit format not recognised."); + ERR("Conduit format not recognised."); return false; } - std::string const inlet (split_str[1]); + std::string const inlet(split_str[1]); auto const i_it = point_names.find(inlet); if (i_it == point_names.end()) { @@ -331,7 +329,7 @@ bool SwmmInterface::readLinksAsPolylines(std::ifstream &in, return false; } - std::string const outlet (split_str[2]); + std::string const outlet(split_str[2]); auto const o_it = point_names.find(outlet); if (o_it == point_names.end()) { @@ -341,7 +339,7 @@ bool SwmmInterface::readLinksAsPolylines(std::ifstream &in, return false; } GeoLib::Polyline* ply = new GeoLib::Polyline(points); - std::size_t a (i_it->second); + std::size_t a(i_it->second); ply->addPoint(i_it->second); ply->addPoint(o_it->second); lines.push_back(ply); @@ -351,12 +349,13 @@ bool SwmmInterface::readLinksAsPolylines(std::ifstream &in, } bool SwmmInterface::convertSwmmInputToGeometry(std::string const& inp_file_name, - GeoLib::GEOObjects &geo_objects, bool add_subcatchments) + GeoLib::GEOObjects& geo_objects, + bool add_subcatchments) { if (!isSwmmInputFile(inp_file_name)) return false; - std::ifstream in ( inp_file_name.c_str() ); + std::ifstream in(inp_file_name.c_str()); if (!in.is_open()) { ERR("SWMMInterface: Could not open input file {:s}.", inp_file_name); @@ -368,7 +367,8 @@ bool SwmmInterface::convertSwmmInputToGeometry(std::string const& inp_file_name, std::vector<std::string> pnt_names; std::vector<std::string> line_names; - std::string geo_name = BaseLib::extractBaseNameWithoutExtension(inp_file_name); + std::string geo_name = + BaseLib::extractBaseNameWithoutExtension(inp_file_name); std::string line; while (std::getline(in, line)) { @@ -393,7 +393,7 @@ bool SwmmInterface::convertSwmmInputToGeometry(std::string const& inp_file_name, if (points->empty()) { - ERR ("No points found in file"); + ERR("No points found in file"); return false; } if (points->size() != pnt_names.size()) @@ -421,7 +421,7 @@ bool SwmmInterface::convertSwmmInputToGeometry(std::string const& inp_file_name, { if (line == "[JUNCTIONS]") { - INFO ("Reading point elevation..."); + INFO("Reading point elevation..."); if (!addPointElevation(in, *points, *name_id_map)) { BaseLib::cleanupVectorElements(*points, *lines); @@ -430,8 +430,9 @@ bool SwmmInterface::convertSwmmInputToGeometry(std::string const& inp_file_name, } if (line == "[CONDUITS]") { - INFO ("Reading conduits..."); - if (!readLinksAsPolylines(in, *lines, line_names, *points, *name_id_map)) + INFO("Reading conduits..."); + if (!readLinksAsPolylines(in, *lines, line_names, *points, + *name_id_map)) { BaseLib::cleanupVectorElements(*points, *lines); return false; @@ -439,8 +440,9 @@ bool SwmmInterface::convertSwmmInputToGeometry(std::string const& inp_file_name, } else if (line == "[PUMPS]") { - INFO ("Reading pumps..."); - if (!readLinksAsPolylines(in, *lines, line_names, *points, *name_id_map)) + INFO("Reading pumps..."); + if (!readLinksAsPolylines(in, *lines, line_names, *points, + *name_id_map)) { BaseLib::cleanupVectorElements(*points, *lines); return false; @@ -448,8 +450,9 @@ bool SwmmInterface::convertSwmmInputToGeometry(std::string const& inp_file_name, } else if (line == "[WEIRS]") { - INFO ("Reading weirs..."); - if (!readLinksAsPolylines(in, *lines, line_names, *points, *name_id_map)) + INFO("Reading weirs..."); + if (!readLinksAsPolylines(in, *lines, line_names, *points, + *name_id_map)) { BaseLib::cleanupVectorElements(*points, *lines); return false; @@ -457,12 +460,13 @@ bool SwmmInterface::convertSwmmInputToGeometry(std::string const& inp_file_name, } } - geo_objects.addPointVec(std::move(points), geo_name, std::move(name_id_map)); + geo_objects.addPointVec(std::move(points), geo_name, + std::move(name_id_map)); if (!lines->empty()) { if (lines->size() != line_names.size()) { - ERR ("Length of line vector and line name vector do not match."); + ERR("Length of line vector and line name vector do not match."); geo_objects.removePointVec(geo_name); for (auto ply : *lines) delete ply; @@ -477,7 +481,8 @@ bool SwmmInterface::convertSwmmInputToGeometry(std::string const& inp_file_name, line_id_map->insert(std::make_pair(line_names[i], i)); } } - std::vector<std::size_t> const& pnt_id_map (geo_objects.getPointVecObj(geo_name)->getIDMap()); + std::vector<std::size_t> const& pnt_id_map( + geo_objects.getPointVecObj(geo_name)->getIDMap()); for (GeoLib::Polyline* polyline : *lines) { for (std::size_t i = 0; i < polyline->getNumberOfPoints(); ++i) @@ -503,8 +508,10 @@ bool SwmmInterface::convertSwmmInputToGeometry(std::string const& inp_file_name, return true; } -bool SwmmInterface::readNodeData(std::ifstream &in, std::vector<MeshLib::Node*> &nodes, std::map<std::string, - std::size_t> const& name_id_map, std::vector<double> &max_depth, bool read_max_depth) +bool SwmmInterface::readNodeData( + std::ifstream& in, std::vector<MeshLib::Node*>& nodes, + std::map<std::string, std::size_t> const& name_id_map, + std::vector<double>& max_depth, bool read_max_depth) { std::string line; while (std::getline(in, line)) @@ -515,14 +522,14 @@ bool SwmmInterface::readNodeData(std::ifstream &in, std::vector<MeshLib::Node*> if (isCommentLine(line)) continue; - std::vector<std::string> const split_str (BaseLib::splitString(line)); + std::vector<std::string> const split_str(BaseLib::splitString(line)); // Junctions = 6, Outfalls = 4, Storage = 8 if (split_str.size() < 3) { - ERR ("Format not recognised."); + ERR("Format not recognised."); return false; } - std::string const current_name (split_str[0]); + std::string const current_name(split_str[0]); auto const it = name_id_map.find(current_name); if (it == name_id_map.end()) { @@ -542,8 +549,10 @@ bool SwmmInterface::readNodeData(std::ifstream &in, std::vector<MeshLib::Node*> return true; } -bool SwmmInterface::readLineElements(std::ifstream &in, std::vector<MeshLib::Element*> &elements, - std::vector<MeshLib::Node*> const& nodes, std::map<std::string, std::size_t> const& name_id_map) +bool SwmmInterface::readLineElements( + std::ifstream& in, std::vector<MeshLib::Element*>& elements, + std::vector<MeshLib::Node*> const& nodes, + std::map<std::string, std::size_t> const& name_id_map) { std::string line; while (std::getline(in, line)) @@ -554,15 +563,15 @@ bool SwmmInterface::readLineElements(std::ifstream &in, std::vector<MeshLib::Ele if (isCommentLine(line)) continue; - std::vector<std::string> const split_str (BaseLib::splitString(line)); + std::vector<std::string> const split_str(BaseLib::splitString(line)); // Conduits = 9, Pumps = 7, Weirs = 8 if (split_str.size() < 7) { - ERR ("Conduit format not recognised."); + ERR("Conduit format not recognised."); return false; } - std::string const inlet (split_str[1]); + std::string const inlet(split_str[1]); auto const i_it = name_id_map.find(inlet); if (i_it == name_id_map.end()) { @@ -572,7 +581,7 @@ bool SwmmInterface::readLineElements(std::ifstream &in, std::vector<MeshLib::Ele return false; } - std::string const outlet (split_str[2]); + std::string const outlet(split_str[2]); auto const o_it = name_id_map.find(outlet); if (o_it == name_id_map.end()) { @@ -582,14 +591,16 @@ bool SwmmInterface::readLineElements(std::ifstream &in, std::vector<MeshLib::Ele return false; } - std::array<MeshLib::Node*, 2> const line_nodes = { nodes[i_it->second], nodes[o_it->second] }; + std::array<MeshLib::Node*, 2> const line_nodes = {nodes[i_it->second], + nodes[o_it->second]}; elements.push_back(new MeshLib::Line(line_nodes)); _id_linkname_map.push_back(split_str[0]); } return true; } -bool SwmmInterface::readSubcatchments(std::ifstream &in, std::map< std::string, std::size_t> const& name_id_map) +bool SwmmInterface::readSubcatchments( + std::ifstream& in, std::map<std::string, std::size_t> const& name_id_map) { std::string line; while (getline(in, line)) @@ -600,18 +611,18 @@ bool SwmmInterface::readSubcatchments(std::ifstream &in, std::map< std::string, if (isCommentLine(line)) continue; - std::vector<std::string> const split_str (BaseLib::splitString(line)); + std::vector<std::string> const split_str(BaseLib::splitString(line)); if (split_str.size() < 8) { - ERR ("Subcatchment format not recognised."); + ERR("Subcatchment format not recognised."); return false; } Subcatchment sc; sc.name = split_str[0]; sc.rain_gauge = std::numeric_limits<std::size_t>::max(); - std::size_t const n_gauges (_rain_gauges.size()); - for (std::size_t i=0; i<n_gauges; ++i) + std::size_t const n_gauges(_rain_gauges.size()); + for (std::size_t i = 0; i < n_gauges; ++i) { if (_rain_gauges[i].first.getName() == split_str[1]) { @@ -643,15 +654,15 @@ bool SwmmInterface::readSwmmInputToLineMesh() { if (_mesh != nullptr) { - ERR ("Mesh already exists."); + ERR("Mesh already exists."); return false; } - std::string const inp_file_name (_base_name + ".inp"); + std::string const inp_file_name(_base_name + ".inp"); if (!isSwmmInputFile(inp_file_name)) return false; - std::ifstream in ( inp_file_name.c_str() ); + std::ifstream in(inp_file_name.c_str()); if (!in.is_open()) { ERR("SWMMInterface: Could not open input file {:s}.", inp_file_name); @@ -659,13 +670,13 @@ bool SwmmInterface::readSwmmInputToLineMesh() } _id_nodename_map.clear(); - std::vector< MeshLib::Node* > nodes; + std::vector<MeshLib::Node*> nodes; std::string line; - while ( getline(in, line) ) + while (getline(in, line)) { if (line == "[COORDINATES]") { - INFO ("Reading coordinates..."); + INFO("Reading coordinates..."); if (!readCoordinates<MeshLib::Node>(in, nodes, _id_nodename_map)) return false; } @@ -679,15 +690,16 @@ bool SwmmInterface::readSwmmInputToLineMesh() */ else if (line == "[SYMBOLS]") { - INFO ("Reading symbols..."); + INFO("Reading symbols..."); std::vector<GeoLib::Point*> points; std::vector<std::string> names; - if (!readCoordinates(in,points, names)) + if (!readCoordinates(in, points, names)) return false; - for (std::size_t i=0; i<points.size(); ++i) + for (std::size_t i = 0; i < points.size(); ++i) { - GeoLib::Station stn (points[i], names[i]); - _rain_gauges.push_back(std::pair<GeoLib::Station, std::string>(stn, "")); + GeoLib::Station stn(points[i], names[i]); + _rain_gauges.push_back( + std::pair<GeoLib::Station, std::string>(stn, "")); } } } @@ -697,18 +709,18 @@ bool SwmmInterface::readSwmmInputToLineMesh() // After end of file is reached, create name-id-map and // start reading again to get line elements and node data. - std::map< std::string, std::size_t> name_id_map; - std::size_t const n_nodes (nodes.size()); - for (std::size_t i=0; i<n_nodes; ++i) + std::map<std::string, std::size_t> name_id_map; + std::size_t const n_nodes(nodes.size()); + for (std::size_t i = 0; i < n_nodes; ++i) name_id_map[_id_nodename_map[i]] = i; in.clear(); in.seekg(0, in.beg); - std::vector< MeshLib::Element* > elements; + std::vector<MeshLib::Element*> elements; std::vector<double> max_depth(n_nodes); std::size_t const n_types = 3; - std::array< std::size_t, n_types> n_elem_types {{0,0,0}}; - while ( getline(in, line) ) + std::array<std::size_t, n_types> n_elem_types{{0, 0, 0}}; + while (getline(in, line)) { if (line == "[RAINGAGES]") { @@ -717,7 +729,7 @@ bool SwmmInterface::readSwmmInputToLineMesh() } else if (line == "[SUBCATCHMENTS]") { - INFO ("Reading subcatchment information..."); + INFO("Reading subcatchment information..."); if (!readSubcatchments(in, name_id_map)) return false; } @@ -731,39 +743,39 @@ bool SwmmInterface::readSwmmInputToLineMesh() } else if (line == "[JUNCTIONS]") { - INFO ("Reading junctions..."); + INFO("Reading junctions..."); if (!readNodeData(in, nodes, name_id_map, max_depth, true)) return false; } else if (line == "[OUTFALLS]") { - INFO ("Reading outfalls..."); + INFO("Reading outfalls..."); if (!readNodeData(in, nodes, name_id_map, max_depth, false)) return false; } else if (line == "[STORAGE]") { - INFO ("Reading storages..."); + INFO("Reading storages..."); if (!readNodeData(in, nodes, name_id_map, max_depth, true)) return false; } else if (line == "[CONDUITS]") { - INFO ("Reading conduits..."); + INFO("Reading conduits..."); if (!readLineElements(in, elements, nodes, name_id_map)) return false; n_elem_types[0] = elements.size(); } else if (line == "[PUMPS]") { - INFO ("Reading pumps..."); + INFO("Reading pumps..."); if (!readLineElements(in, elements, nodes, name_id_map)) return false; n_elem_types[1] = elements.size(); } else if (line == "[WEIRS]") { - INFO ("Reading weirs..."); + INFO("Reading weirs..."); if (!readLineElements(in, elements, nodes, name_id_map)) return false; n_elem_types[2] = elements.size(); @@ -775,11 +787,14 @@ bool SwmmInterface::readSwmmInputToLineMesh() } else if (line == "[Polygons]") { - INFO ("Reading subcatchments..."); + INFO("Reading subcatchments..."); std::vector<GeoLib::Polyline*> lines; std::vector<std::string> line_names; - std::vector<std::string> tmp_names; // polygon points are nameless but the method requires a vector - if (!readPolygons(in, lines, line_names, _subcatchment_points, tmp_names)) + std::vector<std::string> + tmp_names; // polygon points are nameless but the method + // requires a vector + if (!readPolygons(in, lines, line_names, _subcatchment_points, + tmp_names)) return false; if (!matchSubcatchmentsWithPolygons(lines, line_names)) @@ -798,10 +813,11 @@ bool SwmmInterface::readSwmmInputToLineMesh() auto* const mat_ids = props.createNewPropertyVector<int>( "MaterialIDs", MeshLib::MeshItemType::Cell, 1); mat_ids->resize(elements.size(), 0); - for (std::size_t i=1; i<n_types; ++i) + for (std::size_t i = 1; i < n_types; ++i) { if (n_elem_types[i] > 0) - std::fill(mat_ids->begin()+n_elem_types[i-1], mat_ids->begin()+n_elem_types[i], i); + std::fill(mat_ids->begin() + n_elem_types[i - 1], + mat_ids->begin() + n_elem_types[i], i); } if (nodes.size() == max_depth.size()) @@ -809,29 +825,33 @@ bool SwmmInterface::readSwmmInputToLineMesh() auto* const depth = props.createNewPropertyVector<double>( "Max Depth", MeshLib::MeshItemType::Node, 1); depth->reserve(max_depth.size()); - std::copy(max_depth.cbegin(), max_depth.cend(), std::back_inserter(*depth)); + std::copy(max_depth.cbegin(), max_depth.cend(), + std::back_inserter(*depth)); } else - ERR ("Size of max depth array does not fit number of elements. Skipping array."); + ERR("Size of max depth array does not fit number of elements. Skipping " + "array."); _mesh.reset(new MeshLib::Mesh(_base_name, nodes, elements, props)); return true; } -bool SwmmInterface::matchSubcatchmentsWithPolygons(std::vector<GeoLib::Polyline*> const& lines, std::vector<std::string> const& names) +bool SwmmInterface::matchSubcatchmentsWithPolygons( + std::vector<GeoLib::Polyline*> const& lines, + std::vector<std::string> const& names) { - std::size_t const n_lines (lines.size()); - std::size_t const n_subcatchments (_subcatchments.size()); + std::size_t const n_lines(lines.size()); + std::size_t const n_subcatchments(_subcatchments.size()); if (n_lines != n_subcatchments) { - ERR ("Number of subcatchments does not match number of outlines."); + ERR("Number of subcatchments does not match number of outlines."); return false; } - for (std::size_t i=0; i<n_lines; ++i) + for (std::size_t i = 0; i < n_lines; ++i) { bool found = false; - for (std::size_t j=0; j<n_subcatchments; ++j) + for (std::size_t j = 0; j < n_subcatchments; ++j) { if (names[i] == _subcatchments[j].name) { @@ -863,17 +883,17 @@ std::vector<std::string> SwmmInterface::getNames(SwmmObject obj_type) const { switch (obj_type) { - case SwmmObject::NODE: - return _id_nodename_map; - case SwmmObject::LINK: - return _id_linkname_map; - case SwmmObject::SUBCATCHMENT: - return getSubcatchmentNameMap(); - case SwmmObject::SYSTEM: - std::vector<std::string> system_name { "System" }; - return system_name; + case SwmmObject::NODE: + return _id_nodename_map; + case SwmmObject::LINK: + return _id_linkname_map; + case SwmmObject::SUBCATCHMENT: + return getSubcatchmentNameMap(); + case SwmmObject::SYSTEM: + std::vector<std::string> system_name{"System"}; + return system_name; } - ERR ("Object type has no name map"); + ERR("Object type has no name map"); std::vector<std::string> empty_vec; return empty_vec; } @@ -882,26 +902,26 @@ std::string SwmmInterface::getName(SwmmObject obj_type, std::size_t idx) const { switch (obj_type) { - case SwmmObject::NODE: - if (idx < _id_nodename_map.size()) - return _id_nodename_map[idx]; - case SwmmObject::LINK: - if (idx < _id_linkname_map.size()) - return _id_linkname_map[idx]; - case SwmmObject::SUBCATCHMENT: - if (idx < _subcatchments.size()) - return _subcatchments[idx].name; - case SwmmObject::SYSTEM: - if (idx == 0) - return std::string("System"); + case SwmmObject::NODE: + if (idx < _id_nodename_map.size()) + return _id_nodename_map[idx]; + case SwmmObject::LINK: + if (idx < _id_linkname_map.size()) + return _id_linkname_map[idx]; + case SwmmObject::SUBCATCHMENT: + if (idx < _subcatchments.size()) + return _subcatchments[idx].name; + case SwmmObject::SYSTEM: + if (idx == 0) + return std::string("System"); } - ERR ("Index out of bounds."); + ERR("Index out of bounds."); return std::string(""); } std::size_t SwmmInterface::getNumberOfObjects(SwmmObject obj_type) const { - std::string const outfile (_base_name + ".out"); + std::string const outfile(_base_name + ".out"); if (OpenSwmmOutFile(const_cast<char*>(outfile.c_str())) != 0) return 0; @@ -916,7 +936,7 @@ std::size_t SwmmInterface::getNumberOfObjects(SwmmObject obj_type) const case SwmmObject::SYSTEM: return 1; default: - ERR ("Object type not recognised."); + ERR("Object type not recognised."); } CloseSwmmOutFile(); return 0; @@ -924,8 +944,8 @@ std::size_t SwmmInterface::getNumberOfObjects(SwmmObject obj_type) const std::size_t SwmmInterface::getNumberOfParameters(SwmmObject obj_type) const { - std::string const outfile (_base_name + ".out"); - std::size_t n_time_steps (std::numeric_limits<std::size_t>::max()); + std::string const outfile(_base_name + ".out"); + std::size_t n_time_steps(std::numeric_limits<std::size_t>::max()); if (OpenSwmmOutFile(const_cast<char*>(outfile.c_str())) != 0) return 0; @@ -945,7 +965,7 @@ std::size_t SwmmInterface::getNumberOfParameters(SwmmObject obj_type) const n_params = n_obj_params[3]; break; default: - ERR ("Object type not recognised."); + ERR("Object type not recognised."); } CloseSwmmOutFile(); return n_params; @@ -953,26 +973,28 @@ std::size_t SwmmInterface::getNumberOfParameters(SwmmObject obj_type) const std::size_t SwmmInterface::getNumberOfTimeSteps() const { - std::string const outfile (_base_name + ".out"); + std::string const outfile(_base_name + ".out"); if (OpenSwmmOutFile(const_cast<char*>(outfile.c_str())) != 0) return std::numeric_limits<std::size_t>::max(); - std::size_t const n_time_steps (static_cast<std::size_t>(SWMM_Nperiods)); + std::size_t const n_time_steps(static_cast<std::size_t>(SWMM_Nperiods)); CloseSwmmOutFile(); return n_time_steps; } -bool SwmmInterface::addResultsToMesh(MeshLib::Mesh &mesh, SwmmObject const swmm_type, - std::string const& vec_name, std::vector<double> const& data) +bool SwmmInterface::addResultsToMesh(MeshLib::Mesh& mesh, + SwmmObject const swmm_type, + std::string const& vec_name, + std::vector<double> const& data) { if (!(swmm_type == SwmmObject::NODE || swmm_type == SwmmObject::LINK)) { - ERR ("Information of this object type cannot be added to mesh."); + ERR("Information of this object type cannot be added to mesh."); return false; } if (data.empty()) { - ERR ("Data array is empty and cannot be added to mesh."); + ERR("Data array is empty and cannot be added to mesh."); return false; } @@ -984,7 +1006,8 @@ bool SwmmInterface::addResultsToMesh(MeshLib::Mesh &mesh, SwmmObject const swmm_ return false; } - if (swmm_type == SwmmObject::LINK && data.size() != mesh.getNumberOfElements()) + if (swmm_type == SwmmObject::LINK && + data.size() != mesh.getNumberOfElements()) { ERR("Number of mesh elements ({:d}) does not match length of array " "({:d}).", @@ -1006,10 +1029,12 @@ bool SwmmInterface::addResultsToMesh(MeshLib::Mesh &mesh, SwmmObject const swmm_ return true; } -std::vector<double> SwmmInterface::getArrayAtTimeStep(SwmmObject obj_type, std::size_t time_step, std::size_t var_idx) const +std::vector<double> SwmmInterface::getArrayAtTimeStep(SwmmObject obj_type, + std::size_t time_step, + std::size_t var_idx) const { std::vector<double> data; - std::string const outfile (_base_name + ".out"); + std::string const outfile(_base_name + ".out"); if (OpenSwmmOutFile(const_cast<char*>(outfile.c_str())) != 0) return data; @@ -1049,15 +1074,15 @@ std::vector<double> SwmmInterface::getArrayAtTimeStep(SwmmObject obj_type, std:: if (var_idx > n_obj_params[obj_type_id]) is_var_idx_okay = false; break; - default: - ERR ("Object type not recognised."); - CloseSwmmOutFile(); - return data; + default: + ERR("Object type not recognised."); + CloseSwmmOutFile(); + return data; } if (!is_var_idx_okay) { - ERR ("Requested variable does not exist."); + ERR("Requested variable does not exist."); CloseSwmmOutFile(); return data; } @@ -1065,7 +1090,7 @@ std::vector<double> SwmmInterface::getArrayAtTimeStep(SwmmObject obj_type, std:: INFO("Fetching '{:s}'-data for time step {:d}...", getArrayName(obj_type, var_idx, SWMM_Npolluts), time_step); - for (std::size_t i=0; i<n_objects; ++i) + for (std::size_t i = 0; i < n_objects; ++i) { float val; GetSwmmResult(obj_type_id, i, var_idx, time_step, &val); @@ -1076,10 +1101,12 @@ std::vector<double> SwmmInterface::getArrayAtTimeStep(SwmmObject obj_type, std:: return data; } -std::vector<double> SwmmInterface::getArrayForObject(SwmmObject obj_type, std::size_t obj_idx, std::size_t var_idx) const +std::vector<double> SwmmInterface::getArrayForObject(SwmmObject obj_type, + std::size_t obj_idx, + std::size_t var_idx) const { std::vector<double> data; - std::string const outfile (_base_name + ".out"); + std::string const outfile(_base_name + ".out"); if (OpenSwmmOutFile(const_cast<char*>(outfile.c_str())) != 0) return data; @@ -1116,31 +1143,31 @@ std::vector<double> SwmmInterface::getArrayForObject(SwmmObject obj_type, std::s if (var_idx > n_obj_params[obj_type_id]) is_var_idx_okay = false; break; - default: - ERR ("Object type not recognised."); - CloseSwmmOutFile(); - return data; + default: + ERR("Object type not recognised."); + CloseSwmmOutFile(); + return data; } if (!is_obj_idx_okay) { - ERR ("Requested object index does not exist."); + ERR("Requested object index does not exist."); CloseSwmmOutFile(); return data; } if (!is_var_idx_okay) { - ERR ("Requested variable does not exist."); + ERR("Requested variable does not exist."); CloseSwmmOutFile(); return data; } - std::size_t const n_time_steps (static_cast<std::size_t>(SWMM_Nperiods)); - for (std::size_t i=0; i<n_time_steps; ++i) + std::size_t const n_time_steps(static_cast<std::size_t>(SWMM_Nperiods)); + for (std::size_t i = 0; i < n_time_steps; ++i) { float val; - GetSwmmResult(obj_type_id , obj_idx, var_idx, i, &val); + GetSwmmResult(obj_type_id, obj_idx, var_idx, i, &val); data.push_back(static_cast<double>(val)); } @@ -1148,9 +1175,10 @@ std::vector<double> SwmmInterface::getArrayForObject(SwmmObject obj_type, std::s return data; } -std::string SwmmInterface::getArrayName(SwmmObject obj_type, std::size_t var_idx) const +std::string SwmmInterface::getArrayName(SwmmObject obj_type, + std::size_t var_idx) const { - std::string const outfile (_base_name + ".out"); + std::string const outfile(_base_name + ".out"); if (OpenSwmmOutFile(const_cast<char*>(outfile.c_str())) != 0) return std::string(""); @@ -1159,20 +1187,22 @@ std::string SwmmInterface::getArrayName(SwmmObject obj_type, std::size_t var_idx return name; } -std::string SwmmInterface::getArrayName(SwmmObject obj_type, std::size_t var_idx, std::size_t n_pollutants) const +std::string SwmmInterface::getArrayName(SwmmObject obj_type, + std::size_t var_idx, + std::size_t n_pollutants) const { if (obj_type == SwmmObject::SUBCATCHMENT) { if (var_idx < n_obj_params[0]) return subcatchment_vars[var_idx]; - if (var_idx < n_obj_params[0]+n_pollutants) - return _pollutant_names[var_idx-n_obj_params[0]]; + if (var_idx < n_obj_params[0] + n_pollutants) + return _pollutant_names[var_idx - n_obj_params[0]]; } if (obj_type == SwmmObject::NODE) { if (var_idx < n_obj_params[1]) return node_vars[var_idx]; - if (var_idx < n_obj_params[1]+n_pollutants) + if (var_idx < n_obj_params[1] + n_pollutants) return std::string("Node_" + _pollutant_names[var_idx - n_obj_params[1]]); } @@ -1180,7 +1210,7 @@ std::string SwmmInterface::getArrayName(SwmmObject obj_type, std::size_t var_idx { if (var_idx < n_obj_params[2]) return link_vars[var_idx]; - if (var_idx < n_obj_params[2]+n_pollutants) + if (var_idx < n_obj_params[2] + n_pollutants) return std::string("Link_" + _pollutant_names[var_idx - n_obj_params[2]]); } @@ -1188,11 +1218,11 @@ std::string SwmmInterface::getArrayName(SwmmObject obj_type, std::size_t var_idx { return system_vars[var_idx]; } - ERR ("SwmmInterface::getArrayName() - Index error, no name found."); + ERR("SwmmInterface::getArrayName() - Index error, no name found."); return std::string(""); } -bool SwmmInterface::addRainGaugeTimeSeriesLocations(std::ifstream &in) +bool SwmmInterface::addRainGaugeTimeSeriesLocations(std::ifstream& in) { std::string line; while (getline(in, line)) @@ -1203,17 +1233,17 @@ bool SwmmInterface::addRainGaugeTimeSeriesLocations(std::ifstream &in) if (isCommentLine(line)) continue; - std::vector<std::string> const split_str (BaseLib::splitString(line)); + std::vector<std::string> const split_str(BaseLib::splitString(line)); if (split_str.size() < 6) { - ERR ("Rain gauge parameter format not recognised."); + ERR("Rain gauge parameter format not recognised."); return false; } for (auto& stn : _rain_gauges) { if (stn.first.getName() == split_str[0] && split_str[4] == "FILE") - stn.second = split_str[5].substr(1, split_str[5].size()-2); + stn.second = split_str[5].substr(1, split_str[5].size() - 2); } } @@ -1224,7 +1254,7 @@ bool SwmmInterface::addRainGaugeTimeSeriesLocations(std::ifstream &in) return true; } -bool SwmmInterface::readPollutants(std::ifstream &in) +bool SwmmInterface::readPollutants(std::ifstream& in) { std::string line; while (getline(in, line)) @@ -1235,10 +1265,10 @@ bool SwmmInterface::readPollutants(std::ifstream &in) if (isCommentLine(line)) continue; - std::vector<std::string> split_str (BaseLib::splitString(line)); + std::vector<std::string> split_str(BaseLib::splitString(line)); if (split_str.size() < 6) { - ERR ("Parameter format for pollutants not recognised."); + ERR("Parameter format for pollutants not recognised."); return false; } _pollutant_names.push_back(split_str[0]); @@ -1260,13 +1290,15 @@ bool SwmmInterface::isSectionFinished(std::string const& str) bool SwmmInterface::isCommentLine(std::string const& str) { - return (str.compare(str.find_first_not_of(' ', 0),1,";") == 0); + return (str.compare(str.find_first_not_of(' ', 0), 1, ";") == 0); } -bool SwmmInterface::getNodeCoordinateVectors(std::vector<double> &x, std::vector<double> &y, std::vector<double> &z) const +bool SwmmInterface::getNodeCoordinateVectors(std::vector<double>& x, + std::vector<double>& y, + std::vector<double>& z) const { - std::vector<MeshLib::Node*> const& nodes (_mesh->getNodes()); - for (MeshLib::Node const*const node : nodes) + std::vector<MeshLib::Node*> const& nodes(_mesh->getNodes()); + for (MeshLib::Node const* const node : nodes) { x.push_back((*node)[0]); y.push_back((*node)[1]); @@ -1275,14 +1307,15 @@ bool SwmmInterface::getNodeCoordinateVectors(std::vector<double> &x, std::vector return true; } -bool SwmmInterface::getLinkPointIds(std::vector<std::size_t> &inlets, std::vector<std::size_t> &outlets) const +bool SwmmInterface::getLinkPointIds(std::vector<std::size_t>& inlets, + std::vector<std::size_t>& outlets) const { - std::vector<MeshLib::Element*> const& elements (_mesh->getElements()); - for (MeshLib::Element const*const elem : elements) + std::vector<MeshLib::Element*> const& elements(_mesh->getElements()); + for (MeshLib::Element const* const elem : elements) { if (elem->getGeomType() != MeshLib::MeshElemType::LINE) { - ERR ("Non line-element found in mesh."); + ERR("Non line-element found in mesh."); return false; } inlets.push_back(elem->getNodeIndex(0)); @@ -1304,13 +1337,15 @@ std::string SwmmInterface::swmmObjectTypeToString(SwmmObject const obj_type) return "undefined"; } -bool SwmmInterface::writeCsvForTimestep(std::string const& file_name, SwmmObject obj_type, std::size_t time_step) const +bool SwmmInterface::writeCsvForTimestep(std::string const& file_name, + SwmmObject obj_type, + std::size_t time_step) const { FileIO::CsvInterface csv; csv.addIndexVectorForWriting(getNumberOfObjects(obj_type)); csv.addVectorForWriting("Name", getNames(obj_type)); std::size_t const n_params(getNumberOfParameters(obj_type)); - for (std::size_t i=0; i<n_params; ++i) + for (std::size_t i = 0; i < n_params; ++i) { std::vector<double> data = getArrayAtTimeStep(obj_type, time_step, i); if (!data.empty()) @@ -1318,21 +1353,23 @@ bool SwmmInterface::writeCsvForTimestep(std::string const& file_name, SwmmObject } if (csv.getNArrays() < 2) { - ERR ("No data to write"); + ERR("No data to write"); return false; } BaseLib::IO::writeStringToFile(csv.writeToString(), file_name); return true; } -bool SwmmInterface::writeCsvForObject(std::string const& file_name, SwmmObject obj_type, std::size_t obj_idx) const +bool SwmmInterface::writeCsvForObject(std::string const& file_name, + SwmmObject obj_type, + std::size_t obj_idx) const { FileIO::CsvInterface csv; INFO("Writing data for {:s} {:d}.", swmmObjectTypeToString(obj_type), obj_idx); csv.addIndexVectorForWriting(getNumberOfTimeSteps()); - std::size_t const n_params (getNumberOfParameters(obj_type)); - for (std::size_t i=0; i<n_params; ++i) + std::size_t const n_params(getNumberOfParameters(obj_type)); + for (std::size_t i = 0; i < n_params; ++i) { std::vector<double> data = getArrayForObject(obj_type, obj_idx, i); if (!data.empty()) @@ -1340,11 +1377,11 @@ bool SwmmInterface::writeCsvForObject(std::string const& file_name, SwmmObject o } if (csv.getNArrays() < 2) { - ERR ("No data to write"); + ERR("No data to write"); return false; } BaseLib::IO::writeStringToFile(csv.writeToString(), file_name); return true; } -} // namespace FileIO +} // namespace FileIO diff --git a/Applications/FileIO/TetGenInterface.cpp b/Applications/FileIO/TetGenInterface.cpp index 133245369a10cbbb68526ab1338ea8458edb615f..81fceff00ea82f49c5dd1c16e0df2eb71f75b227 100644 --- a/Applications/FileIO/TetGenInterface.cpp +++ b/Applications/FileIO/TetGenInterface.cpp @@ -15,30 +15,27 @@ #include "TetGenInterface.h" #include <cstddef> -#include <string> #include <fstream> - -#include "BaseLib/Logging.h" +#include <string> #include "BaseLib/FileTools.h" +#include "BaseLib/Logging.h" #include "BaseLib/StringTools.h" - #include "GeoLib/Triangle.h" - -#include "MeshLib/Mesh.h" -#include "MeshLib/Node.h" #include "MeshLib/Elements/Element.h" #include "MeshLib/Elements/Tet.h" +#include "MeshLib/Mesh.h" #include "MeshLib/MeshInformation.h" +#include "MeshLib/Node.h" namespace FileIO { TetGenInterface::TetGenInterface() = default; -bool TetGenInterface::readTetGenGeometry (std::string const& geo_fname, - GeoLib::GEOObjects &geo_objects) +bool TetGenInterface::readTetGenGeometry(std::string const& geo_fname, + GeoLib::GEOObjects& geo_objects) { - std::ifstream poly_stream (geo_fname.c_str()); + std::ifstream poly_stream(geo_fname.c_str()); if (!poly_stream) { @@ -46,15 +43,16 @@ bool TetGenInterface::readTetGenGeometry (std::string const& geo_fname, geo_fname); return false; } - std::string ext (BaseLib::getFileExtension(geo_fname)); + std::string ext(BaseLib::getFileExtension(geo_fname)); if (ext != ".smesh") { - ERR ("TetGenInterface::readTetGenGeometry() - unknown file type (only *.smesh is supported)."); + ERR("TetGenInterface::readTetGenGeometry() - unknown file type (only " + "*.smesh is supported)."); return false; } std::vector<MeshLib::Node*> nodes; - if (!readNodesFromStream (poly_stream, nodes)) + if (!readNodesFromStream(poly_stream, nodes)) { // remove nodes read until now for (auto& node : nodes) @@ -63,20 +61,22 @@ bool TetGenInterface::readTetGenGeometry (std::string const& geo_fname, } return false; } - const std::size_t nNodes (nodes.size()); + const std::size_t nNodes(nodes.size()); auto points = std::make_unique<std::vector<GeoLib::Point*>>(); points->reserve(nNodes); - for (std::size_t k(0); k<nNodes; ++k) + for (std::size_t k(0); k < nNodes; ++k) { points->push_back(new GeoLib::Point(*(nodes[k]), nodes[k]->getID())); delete nodes[k]; } - std::string geo_name (BaseLib::extractBaseNameWithoutExtension(geo_fname)); + std::string geo_name(BaseLib::extractBaseNameWithoutExtension(geo_fname)); geo_objects.addPointVec(std::move(points), geo_name); - const std::vector<std::size_t> &id_map (geo_objects.getPointVecObj(geo_name)->getIDMap()); + const std::vector<std::size_t>& id_map( + geo_objects.getPointVecObj(geo_name)->getIDMap()); auto surfaces = std::make_unique<std::vector<GeoLib::Surface*>>(); - if (!parseSmeshFacets(poly_stream, *surfaces, *geo_objects.getPointVec(geo_name), id_map)) + 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++) @@ -89,15 +89,16 @@ bool TetGenInterface::readTetGenGeometry (std::string const& geo_fname, return true; } -std::size_t TetGenInterface::getNFacets(std::ifstream &input) +std::size_t TetGenInterface::getNFacets(std::ifstream& input) { std::string line; while (!input.fail()) { - getline (input, line); + getline(input, line); if (input.fail()) { - ERR("TetGenInterface::getNFacets(): Error reading number of facets."); + ERR("TetGenInterface::getNFacets(): Error reading number of " + "facets."); return 0; } @@ -119,12 +120,13 @@ std::size_t TetGenInterface::getNFacets(std::ifstream &input) return 0; } -bool TetGenInterface::parseSmeshFacets(std::ifstream &input, - std::vector<GeoLib::Surface*> &surfaces, - const std::vector<GeoLib::Point*> &points, - const std::vector<std::size_t> &pnt_id_map) +bool TetGenInterface::parseSmeshFacets( + std::ifstream& input, + std::vector<GeoLib::Surface*>& surfaces, + const std::vector<GeoLib::Point*>& points, + const std::vector<std::size_t>& pnt_id_map) { - const std::size_t nFacets (this->getNFacets(input)); + const std::size_t nFacets(this->getNFacets(input)); std::string line; surfaces.reserve(nFacets); std::list<std::string>::const_iterator it; @@ -133,9 +135,9 @@ bool TetGenInterface::parseSmeshFacets(std::ifstream &input, std::vector<std::size_t> idx_map; std::size_t k(0); - while (k<nFacets && !input.fail()) + while (k < nFacets && !input.fail()) { - getline (input, line); + getline(input, line); if (input.fail()) { ERR("TetGenInterface::parseFacets(): Error reading facet {:d}.", k); @@ -143,22 +145,25 @@ bool TetGenInterface::parseSmeshFacets(std::ifstream &input, } BaseLib::simplify(line); - if (line.empty() || line.compare(0,1,"#") == 0) + if (line.empty() || line.compare(0, 1, "#") == 0) { continue; } // read facets - const std::list<std::string> point_fields = BaseLib::splitString(line, ' '); + const std::list<std::string> point_fields = + BaseLib::splitString(line, ' '); it = point_fields.begin(); const auto nPoints = BaseLib::str2number<std::size_t>(*it); if (nPoints != 3) { - ERR ("Smesh-files are currently only supported for triangle meshes."); + ERR("Smesh-files are currently only supported for triangle " + "meshes."); return false; } std::vector<std::size_t> point_ids; - const std::size_t point_field_size = (_boundary_markers) ? nPoints+1 : nPoints; + 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) @@ -168,14 +173,19 @@ bool TetGenInterface::parseSmeshFacets(std::ifstream &input, 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(); + 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(); if (idx >= surfaces.size()) { idx_map.push_back(sfc_marker); surfaces.push_back(new GeoLib::Surface(points)); } - surfaces[idx]->addTriangle(point_ids[0], point_ids[1], point_ids[2]); + surfaces[idx]->addTriangle( + point_ids[0], point_ids[1], point_ids[2]); } else { @@ -186,10 +196,12 @@ bool TetGenInterface::parseSmeshFacets(std::ifstream &input, } ++k; } - // here the poly-file potentially defines a number of points to mark holes within the volumes defined by the facets, these are ignored for now - // here the poly-file potentially defines a number of region attributes, these are ignored for now + // here the poly-file potentially defines a number of points to mark holes + // within the volumes defined by the facets, these are ignored for now here + // the poly-file potentially defines a number of region attributes, these + // are ignored for now - std::size_t nTotalTriangles (0); + std::size_t nTotalTriangles(0); for (auto& surface : surfaces) { nTotalTriangles += surface->getNumberOfTriangles(); @@ -206,11 +218,11 @@ bool TetGenInterface::parseSmeshFacets(std::ifstream &input, return false; } -MeshLib::Mesh* TetGenInterface::readTetGenMesh (std::string const& nodes_fname, - std::string const& ele_fname) +MeshLib::Mesh* TetGenInterface::readTetGenMesh(std::string const& nodes_fname, + std::string const& ele_fname) { - std::ifstream ins_nodes (nodes_fname.c_str()); - std::ifstream ins_ele (ele_fname.c_str()); + std::ifstream ins_nodes(nodes_fname.c_str()); + std::ifstream ins_ele(ele_fname.c_str()); if (!ins_nodes || !ins_ele) { @@ -228,9 +240,11 @@ MeshLib::Mesh* TetGenInterface::readTetGenMesh (std::string const& nodes_fname, } std::vector<MeshLib::Node*> nodes; - if (!readNodesFromStream (ins_nodes, nodes)) { + if (!readNodesFromStream(ins_nodes, nodes)) + { // remove nodes read until now - for (auto & node : nodes) { + for (auto& node : nodes) + { delete node; } return nullptr; @@ -238,14 +252,16 @@ MeshLib::Mesh* TetGenInterface::readTetGenMesh (std::string const& nodes_fname, std::vector<MeshLib::Element*> elements; std::vector<int> materials; - if (!readElementsFromStream (ins_ele, elements, materials, nodes)) { + if (!readElementsFromStream(ins_ele, elements, materials, nodes)) + { BaseLib::cleanupVectorElements(nodes, elements); return nullptr; } MeshLib::Properties properties; // Transmit material values if there is any material value != 0 - if (std::any_of(materials.cbegin(), materials.cend(), [](int m){ return m != 0; })) + if (std::any_of( + materials.cbegin(), materials.cend(), [](int m) { return m != 0; })) { auto* const mat_props = properties.createNewPropertyVector<int>( "MaterialIDs", MeshLib::MeshItemType::Cell); @@ -255,15 +271,16 @@ MeshLib::Mesh* TetGenInterface::readTetGenMesh (std::string const& nodes_fname, std::back_inserter(*mat_props)); } - const std::string mesh_name (BaseLib::extractBaseNameWithoutExtension(nodes_fname)); + const std::string mesh_name( + BaseLib::extractBaseNameWithoutExtension(nodes_fname)); return new MeshLib::Mesh(mesh_name, nodes, elements, properties); } -bool TetGenInterface::readNodesFromStream (std::ifstream &ins, - std::vector<MeshLib::Node*> &nodes) +bool TetGenInterface::readNodesFromStream(std::ifstream& ins, + std::vector<MeshLib::Node*>& nodes) { std::string line; - getline (ins, line); + getline(ins, line); std::size_t n_nodes; std::size_t dim; std::size_t n_attributes; @@ -272,14 +289,15 @@ bool TetGenInterface::readNodesFromStream (std::ifstream &ins, while (!ins.fail()) { BaseLib::simplify(line); - if (line.empty() || line.compare(0,1,"#") == 0) + if (line.empty() || line.compare(0, 1, "#") == 0) { // this line is a comment - skip - getline (ins, line); + getline(ins, line); continue; } // read header line - bool header_okay = parseNodesFileHeader(line, n_nodes, dim, n_attributes, boundary_markers); + bool header_okay = parseNodesFileHeader( + line, n_nodes, dim, n_attributes, boundary_markers); if (!header_okay) { return false; @@ -302,28 +320,30 @@ bool TetGenInterface::parseNodesFileHeader(std::string const& line, std::list<std::string> pnt_header = BaseLib::splitString(line, ' '); if (pnt_header.empty()) { - ERR("TetGenInterface::parseNodesFileHeader(): could not read number of nodes specified in header."); + ERR("TetGenInterface::parseNodesFileHeader(): could not read number of " + "nodes specified in header."); return false; } auto it = pnt_header.begin(); - n_nodes = BaseLib::str2number<std::size_t> (*it); - dim = (pnt_header.size()==1) ? 3 : BaseLib::str2number<std::size_t> (*(++it)); + n_nodes = BaseLib::str2number<std::size_t>(*it); + dim = (pnt_header.size() == 1) ? 3 + : BaseLib::str2number<std::size_t>(*(++it)); - if (pnt_header.size()<4) + if (pnt_header.size() < 4) { n_attributes = 0; boundary_markers = false; return true; } - n_attributes = BaseLib::str2number<std::size_t> (*(++it)); + n_attributes = BaseLib::str2number<std::size_t>(*(++it)); boundary_markers = *(++it) == "1"; return true; } -bool TetGenInterface::parseNodes(std::ifstream &ins, - std::vector<MeshLib::Node*> &nodes, +bool TetGenInterface::parseNodes(std::ifstream& ins, + std::vector<MeshLib::Node*>& nodes, std::size_t n_nodes, std::size_t dim) { @@ -346,25 +366,31 @@ bool TetGenInterface::parseNodes(std::ifstream &ins, std::size_t pos_beg = line.find_first_not_of(' ', pos_end); pos_end = line.find_first_of(" \n", pos_beg); - if (line.empty() || pos_beg==pos_end || line.compare(pos_beg,1,"#") == 0) + if (line.empty() || pos_beg == pos_end || + line.compare(pos_beg, 1, "#") == 0) { continue; } - 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 (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 { + } + else + { ERR("TetGenInterface::parseNodes(): Error reading ID of node {:d}.", k); return false; } // read coordinates const unsigned offset = (_zero_based_idx) ? 0 : 1; - for (std::size_t i(0); i < dim; i++) { + 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) @@ -373,7 +399,8 @@ bool TetGenInterface::parseNodes(std::ifstream &ins, } if (pos_beg != std::string::npos) { - coordinates[i] = BaseLib::str2number<double>(line.substr(pos_beg, pos_end-pos_beg)); + coordinates[i] = BaseLib::str2number<double>( + line.substr(pos_beg, pos_end - pos_beg)); } else { @@ -385,8 +412,9 @@ bool TetGenInterface::parseNodes(std::ifstream &ins, } } - nodes.push_back(new MeshLib::Node(coordinates.data(), id-offset)); - // read attributes and boundary markers ... - at the moment we do not use this information + nodes.push_back(new MeshLib::Node(coordinates.data(), id - offset)); + // read attributes and boundary markers ... - at the moment we do not + // use this information ++k; } @@ -446,23 +474,26 @@ bool TetGenInterface::parseElementsFileHeader(std::string& line, std::size_t pos_end; // number of tetrahedras - pos_beg = line.find_first_not_of (' '); + 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)); + n_tets = BaseLib::str2number<std::size_t>( + line.substr(pos_beg, pos_end - pos_beg)); } else { - ERR("TetGenInterface::parseElementsFileHeader(): Could not read number of tetrahedra specified in header."); + ERR("TetGenInterface::parseElementsFileHeader(): Could not read number " + "of tetrahedra specified in header."); return false; } // nodes per tet - either 4 or 10 - pos_beg = line.find_first_not_of (" \t", pos_end); + pos_beg = line.find_first_not_of(" \t", pos_end); pos_end = line.find_first_of(" \t", pos_beg); - n_nodes_per_tet = BaseLib::str2number<std::size_t> (line.substr(pos_beg, pos_end - pos_beg)); + n_nodes_per_tet = BaseLib::str2number<std::size_t>( + line.substr(pos_beg, pos_end - pos_beg)); // region attribute at tetrahedra? - pos_beg = line.find_first_not_of (" \t", pos_end); + 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) { @@ -474,9 +505,9 @@ bool TetGenInterface::parseElementsFileHeader(std::string& line, } bool TetGenInterface::parseElements(std::ifstream& ins, - std::vector<MeshLib::Element*> &elements, - std::vector<int> &materials, - const std::vector<MeshLib::Node*> &nodes, + std::vector<MeshLib::Element*>& elements, + std::vector<int>& materials, + const std::vector<MeshLib::Node*>& nodes, std::size_t n_tets, std::size_t n_nodes_per_tet, bool region_attribute) const @@ -490,7 +521,7 @@ bool TetGenInterface::parseElements(std::ifstream& ins, const unsigned offset = (_zero_based_idx) ? 0 : 1; for (std::size_t k(0); k < n_tets && !ins.fail(); k++) { - getline (ins, line); + getline(ins, line); if (ins.fail()) { ERR("TetGenInterface::parseElements(): Error reading tetrahedron " @@ -503,7 +534,8 @@ bool TetGenInterface::parseElements(std::ifstream& ins, std::size_t pos_beg = line.find_first_not_of(' ', pos_end); pos_end = line.find_first_of(" \n", pos_beg); - if (line.empty() || pos_beg==pos_end || line.compare(pos_beg,1,"#") == 0) + if (line.empty() || pos_beg == pos_end || + line.compare(pos_beg, 1, "#") == 0) { k--; continue; @@ -528,7 +560,9 @@ bool TetGenInterface::parseElements(std::ifstream& ins, } 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; + ids[i] = BaseLib::str2number<std::size_t>( + line.substr(pos_beg, pos_end - pos_beg)) - + offset; } else { @@ -541,8 +575,9 @@ bool TetGenInterface::parseElements(std::ifstream& ins, } // read region attribute - this is something like material group - int region (0); - if (region_attribute) { + int region(0); + 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) @@ -551,7 +586,8 @@ bool TetGenInterface::parseElements(std::ifstream& ins, } if (pos_beg != std::string::npos && pos_end != std::string::npos) { - region = BaseLib::str2number<int> (line.substr(pos_beg, pos_end - pos_beg)); + region = BaseLib::str2number<int>( + line.substr(pos_beg, pos_end - pos_beg)); } else { @@ -567,7 +603,7 @@ bool TetGenInterface::parseElements(std::ifstream& ins, { tet_nodes[n] = nodes[ids[n]]; } - elements.push_back (new MeshLib::Tet(tet_nodes)); + elements.push_back(new MeshLib::Tet(tet_nodes)); materials.push_back(region); } @@ -580,24 +616,26 @@ bool TetGenInterface::writeTetGenSmesh( const std::string& geo_name, const std::vector<GeoLib::Point>& attribute_points) { - std::vector<GeoLib::Point*> const*const points = geo_objects.getPointVec(geo_name); - std::vector<GeoLib::Surface*> const*const surfaces = geo_objects.getSurfaceVec(geo_name); + std::vector<GeoLib::Point*> const* const points = + geo_objects.getPointVec(geo_name); + std::vector<GeoLib::Surface*> const* const surfaces = + geo_objects.getSurfaceVec(geo_name); - if (points==nullptr) + if (points == nullptr) { ERR("Geometry {:s} not found.", geo_name); return false; } - if (surfaces==nullptr) + if (surfaces == nullptr) { WARN("No surfaces found for geometry {:s}. Writing points only.", geo_name); } - std::ofstream out( file_name.c_str(), std::ios::out ); + std::ofstream out(file_name.c_str(), std::ios::out); out.precision(std::numeric_limits<double>::digits10); // the points header - const std::size_t nPoints (points->size()); + const std::size_t nPoints(points->size()); out << nPoints << " 3\n"; // the point list for (std::size_t i = 0; i < nPoints; ++i) @@ -607,25 +645,26 @@ bool TetGenInterface::writeTetGenSmesh( } // the surfaces header const std::size_t nSurfaces = (surfaces) ? surfaces->size() : 0; - std::size_t nTotalTriangles (0); + std::size_t nTotalTriangles(0); 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) + for (std::size_t i = 0; i < nSurfaces; ++i) { - const std::size_t nTriangles ((*surfaces)[i]->getNumberOfTriangles()); - const std::size_t marker (i+1); // must NOT be 0! + const std::size_t nTriangles((*surfaces)[i]->getNumberOfTriangles()); + const std::size_t marker(i + 1); // must NOT be 0! // the poly list - for (std::size_t j=0; j<nTriangles; ++j) + for (std::size_t j = 0; j < nTriangles; ++j) { - const GeoLib::Triangle &tri = *(*(*surfaces)[i])[j]; - out << "3 " << tri[0] << " " << tri[1] << " " << tri[2] << " " << marker << "\n"; + const GeoLib::Triangle& tri = *(*(*surfaces)[i])[j]; + out << "3 " << tri[0] << " " << tri[1] << " " << tri[2] << " " + << marker << "\n"; } } - out << "0\n"; // the polygon holes list + out << "0\n"; // the polygon holes list // the region attributes list if (attribute_points.empty()) { @@ -633,7 +672,7 @@ bool TetGenInterface::writeTetGenSmesh( } else { - const std::size_t nAttributePoints (attribute_points.size()); + const std::size_t nAttributePoints(attribute_points.size()); out << nAttributePoints << "\n"; for (std::size_t i = 0; i < nAttributePoints; ++i) { @@ -651,21 +690,22 @@ bool TetGenInterface::writeTetGenSmesh( return true; } -bool TetGenInterface::writeTetGenSmesh(const std::string &file_name, - const MeshLib::Mesh &mesh, - std::vector<MeshLib::Node> &attribute_points) const +bool TetGenInterface::writeTetGenSmesh( + const std::string& file_name, + const MeshLib::Mesh& mesh, + std::vector<MeshLib::Node>& attribute_points) const { if (mesh.getDimension() == 1) { return false; } - const std::vector<MeshLib::Node*> &nodes = mesh.getNodes(); + const std::vector<MeshLib::Node*>& nodes = mesh.getNodes(); - std::ofstream out( file_name.c_str(), std::ios::out ); + std::ofstream out(file_name.c_str(), std::ios::out); out.precision(std::numeric_limits<double>::digits10); // the points header - const std::size_t nPoints (nodes.size()); + const std::size_t nPoints(nodes.size()); out << nPoints << " 3\n"; // the point list for (std::size_t i = 0; i < nPoints; ++i) @@ -683,7 +723,7 @@ bool TetGenInterface::writeTetGenSmesh(const std::string &file_name, write3dElements(out, mesh, attribute_points); } - out << "0\n"; // the polygon holes list + out << "0\n"; // the polygon holes list // the region attributes list if (attribute_points.empty()) @@ -692,7 +732,7 @@ bool TetGenInterface::writeTetGenSmesh(const std::string &file_name, } else { - const std::size_t nAttributePoints (attribute_points.size()); + const std::size_t nAttributePoints(attribute_points.size()); out << nAttributePoints << "\n"; for (std::size_t i = 0; i < nAttributePoints; ++i) { @@ -711,65 +751,70 @@ bool TetGenInterface::writeTetGenSmesh(const std::string &file_name, return true; } -void TetGenInterface::write2dElements(std::ofstream &out, - const MeshLib::Mesh &mesh) const +void TetGenInterface::write2dElements(std::ofstream& out, + const MeshLib::Mesh& mesh) const { // the surfaces header auto const& types = MeshLib::MeshInformation::getNumberOfElementTypes(mesh); std::size_t const n_tri = (types.find(MeshLib::MeshElemType::TRIANGLE) != types.end()) - ? types.at(MeshLib::MeshElemType::TRIANGLE) : 0; + ? types.at(MeshLib::MeshElemType::TRIANGLE) + : 0; std::size_t const n_quad = (types.find(MeshLib::MeshElemType::QUAD) != types.end()) - ? types.at(MeshLib::MeshElemType::QUAD) : 0; + ? types.at(MeshLib::MeshElemType::QUAD) + : 0; unsigned const nTotalTriangles = n_tri + 2 * n_quad; out << nTotalTriangles << " 1\n"; - const std::vector<MeshLib::Element*> &elements = mesh.getElements(); - MeshLib::PropertyVector<int> const*const mat_ids = + const std::vector<MeshLib::Element*>& elements = mesh.getElements(); + MeshLib::PropertyVector<int> const* const mat_ids = mesh.getProperties().existsPropertyVector<int>("MaterialIDs") ? mesh.getProperties().getPropertyVector<int>("MaterialIDs") : nullptr; - const std::size_t nElements (elements.size()); + const std::size_t nElements(elements.size()); unsigned element_count(0); - for (std::size_t i=0; i<nElements; ++i) + for (std::size_t i = 0; i < nElements; ++i) { std::string const matId = mat_ids ? std::to_string((*mat_ids)[i]) : ""; this->writeElementToFacets(out, *elements[i], element_count, matId); } } -void TetGenInterface::write3dElements(std::ofstream &out, - const MeshLib::Mesh &mesh, - std::vector<MeshLib::Node> &attribute_points) const +void TetGenInterface::write3dElements( + std::ofstream& out, + const MeshLib::Mesh& mesh, + std::vector<MeshLib::Node>& attribute_points) const { - const std::vector<MeshLib::Element*> &elements = mesh.getElements(); - const std::size_t nElements (elements.size()); + 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()); - const unsigned n_spaces (static_cast<unsigned>(std::floor(log(nElements*8))) + 1); + // 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()); + const unsigned n_spaces( + static_cast<unsigned>(std::floor(log(nElements * 8))) + 1); out << std::string(n_spaces, ' ') << " 1\n"; auto const* const materialIds = mesh.getProperties().getPropertyVector<int>("MaterialIDs"); unsigned element_count(0); - for (std::size_t i=0; i<nElements; ++i) + for (std::size_t i = 0; i < nElements; ++i) { if (elements[i]->getDimension() < 3) { continue; } - const unsigned nFaces (elements[i]->getNumberOfNeighbors()); + const unsigned nFaces(elements[i]->getNumberOfNeighbors()); std::string const mat_id_str = materialIds ? std::to_string((*materialIds)[i]) : ""; - for (std::size_t j=0; j<nFaces; ++j) + for (std::size_t j = 0; j < nFaces; ++j) { - MeshLib::Element const*const neighbor ( elements[i]->getNeighbor(j) ); + MeshLib::Element const* const neighbor(elements[i]->getNeighbor(j)); if (neighbor && materialIds && (*materialIds)[i] <= (*materialIds)[neighbor->getID()]) @@ -777,7 +822,8 @@ void TetGenInterface::write3dElements(std::ofstream &out, continue; } - std::unique_ptr<MeshLib::Element const> const face (elements[i]->getFace(j)); + std::unique_ptr<MeshLib::Element const> const face( + elements[i]->getFace(j)); this->writeElementToFacets(out, *face, element_count, mat_id_str); } if (materialIds) @@ -788,7 +834,7 @@ void TetGenInterface::write3dElements(std::ofstream &out, } } // add number of facets at correct position and jump back - const std::streamoff after_elems_pos (out.tellp()); + const std::streamoff after_elems_pos(out.tellp()); out.seekp(before_elems_pos); out << element_count; out.seekp(after_elems_pos); @@ -802,14 +848,20 @@ void TetGenInterface::writeElementToFacets(std::ofstream& out, element_count++; if (element.getGeomType() == MeshLib::MeshElemType::TRIANGLE) { - out << "3 " << element.getNodeIndex(0) << " " << element.getNodeIndex(1) << " " << element.getNodeIndex(2) << " " << matId << " # " << element_count << "\n"; + 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"; + out << "3 " << element.getNodeIndex(0) << " " + << element.getNodeIndex(1) << " " << element.getNodeIndex(2) << " " + << matId << " # " << element_count << "\n"; element_count++; - out << "3 " << element.getNodeIndex(0) << " " << element.getNodeIndex(2) << " " << element.getNodeIndex(3) << " " << matId << " # " << element_count << "\n"; + out << "3 " << element.getNodeIndex(0) << " " + << element.getNodeIndex(2) << " " << element.getNodeIndex(3) << " " + << matId << " # " << element_count << "\n"; } } -} // end namespace FileIO +} // end namespace FileIO diff --git a/Applications/FileIO/XmlIO/Qt/XmlPrjInterface.cpp b/Applications/FileIO/XmlIO/Qt/XmlPrjInterface.cpp index 20452c12552de6ca9818a6427d39d83b08344885..8f376f65391d7324a93b85e3bbf32d2d7f3bc151 100644 --- a/Applications/FileIO/XmlIO/Qt/XmlPrjInterface.cpp +++ b/Applications/FileIO/XmlIO/Qt/XmlPrjInterface.cpp @@ -10,25 +10,20 @@ #include "XmlPrjInterface.h" -#include <iostream> -#include <vector> - #include <QFile> #include <QFileInfo> #include <QtXml/QDomDocument> -#include "BaseLib/Logging.h" +#include <iostream> +#include <vector> #include "Applications/DataExplorer/Base/OGSError.h" #include "Applications/DataHolderLib/FemCondition.h" - #include "BaseLib/FileTools.h" #include "BaseLib/IO/Writer.h" - +#include "BaseLib/Logging.h" #include "GeoLib/GEOObjects.h" - #include "GeoLib/IO/XmlIO/Qt/XmlGmlInterface.h" #include "GeoLib/IO/XmlIO/Qt/XmlStnInterface.h" - #include "MeshLib/IO/readMeshFromFile.h" #include "MeshLib/IO/writeMeshToFile.h" #include "MeshLib/Mesh.h" diff --git a/Applications/FileIO/readGeometryFromFile.cpp b/Applications/FileIO/readGeometryFromFile.cpp index 620dfc57ef91573a4c28bfac8529ae2d88bfc4f0..93f60287409da92b54fb4908b096c19c3b75a6ed 100644 --- a/Applications/FileIO/readGeometryFromFile.cpp +++ b/Applications/FileIO/readGeometryFromFile.cpp @@ -14,12 +14,10 @@ #include "BaseLib/Error.h" #include "BaseLib/FileTools.h" - +#include "GeoLib/GEOObjects.h" #include "GeoLib/IO/XmlIO/Boost/BoostXmlGmlInterface.h" #include "Legacy/OGSIOVer4.h" -#include "GeoLib/GEOObjects.h" - namespace FileIO { void readGeometryFromFile(std::string const& fname, @@ -30,9 +28,11 @@ void readGeometryFromFile(std::string const& fname, { GeoLib::IO::BoostXmlGmlInterface xml(geo_objs); xml.readFile(fname); - } else { + } + else + { std::vector<std::string> errors; - std::string geo_name; // geo_name is output of the reading function + std::string geo_name; // geo_name is output of the reading function FileIO::Legacy::readGLIFileV4( fname, geo_objs, geo_name, errors, gmsh_path); } diff --git a/Applications/FileIO/writeGeometryToFile.cpp b/Applications/FileIO/writeGeometryToFile.cpp index 23e8f25bc556399e648daa49ebee37a28826fff1..77844c49871adafeaaf839faa1ceff23732d1b00 100644 --- a/Applications/FileIO/writeGeometryToFile.cpp +++ b/Applications/FileIO/writeGeometryToFile.cpp @@ -11,25 +11,28 @@ #include "writeGeometryToFile.h" #include "BaseLib/FileTools.h" - +#include "GeoLib/GEOObjects.h" #include "GeoLib/IO/XmlIO/Boost/BoostXmlGmlInterface.h" #include "Legacy/OGSIOVer4.h" -#include "GeoLib/GEOObjects.h" - namespace FileIO { void writeGeometryToFile(std::string const& geo_name, - GeoLib::GEOObjects& geo_objs, std::string const& fname) + GeoLib::GEOObjects& geo_objs, std::string const& fname) { std::string const extension(BaseLib::getFileExtension(fname)); - if (extension == ".gml" || extension == ".GML") { + if (extension == ".gml" || extension == ".GML") + { GeoLib::IO::BoostXmlGmlInterface xml(geo_objs); xml.export_name = geo_name; BaseLib::IO::writeStringToFile(xml.writeToString(), fname); - } else if (extension == "gli" || extension == "GLI") { + } + else if (extension == "gli" || extension == "GLI") + { FileIO::Legacy::writeGLIFileV4(fname, geo_name, geo_objs); - } else { + } + else + { ERR("Writing of geometry failed, since it was not possible to determine" " the required format from file extension."); } diff --git a/Applications/Utils/FileConverter/ConvertSHPToGLI.cpp b/Applications/Utils/FileConverter/ConvertSHPToGLI.cpp index 48c7362a712d7ba9b12e20a29cd2e2837b1051fe..10c2c6f755f302c9532a2ec0e7488a27bf9a0d0b 100644 --- a/Applications/Utils/FileConverter/ConvertSHPToGLI.cpp +++ b/Applications/Utils/FileConverter/ConvertSHPToGLI.cpp @@ -13,38 +13,39 @@ */ // STL +#include <tclap/CmdLine.h> + #include <fstream> #include <vector> -#include <tclap/CmdLine.h> - // ShapeLib #include <shapefil.h> -#include "InfoLib/GitInfo.h" #include "GeoLib/GEOObjects.h" #include "GeoLib/IO/XmlIO/Qt/XmlGmlInterface.h" #include "GeoLib/IO/XmlIO/Qt/XmlStnInterface.h" #include "GeoLib/Point.h" #include "GeoLib/Station.h" +#include "InfoLib/GitInfo.h" -void convertPoints (DBFHandle dbf_handle, - std::string const& out_fname, - std::size_t x_id, - std::size_t y_id, - std::size_t z_id, - std::vector<std::size_t> const& name_component_ids, - std::string& points_group_name, - bool station) +void convertPoints(DBFHandle dbf_handle, + std::string const& out_fname, + std::size_t x_id, + std::size_t y_id, + std::size_t z_id, + std::vector<std::size_t> const& name_component_ids, + std::string& points_group_name, + bool station) { - int n_records (DBFGetRecordCount (dbf_handle)); + int n_records(DBFGetRecordCount(dbf_handle)); INFO("Reading {:d} records.", n_records); auto points = std::make_unique<std::vector<GeoLib::Point*>>(); - points->reserve (n_records); + points->reserve(n_records); std::string name; - for (int k = 0; k < n_records; k++) { + for (int k = 0; k < n_records; k++) + { double x(DBFReadDoubleAttribute(dbf_handle, k, x_id)); double y(DBFReadDoubleAttribute(dbf_handle, k, y_id)); double z(0.0); @@ -54,7 +55,8 @@ void convertPoints (DBFHandle dbf_handle, } name.clear(); - if (!name_component_ids.empty()) { + if (!name_component_ids.empty()) + { for (unsigned long name_component_id : name_component_ids) { if (name_component_id != @@ -71,10 +73,13 @@ void convertPoints (DBFHandle dbf_handle, name = std::to_string(k); } - if (station) { + if (station) + { GeoLib::Station* pnt(GeoLib::Station::createStation(name, x, y, z)); points->push_back(pnt); - } else { + } + else + { GeoLib::Point* pnt(new GeoLib::Point(x, y, z)); points->push_back(pnt); } @@ -90,18 +95,22 @@ void convertPoints (DBFHandle dbf_handle, geo_objs.addPointVec(std::move(points), points_group_name); } - if (station) { - GeoLib::IO::XmlStnInterface xml (geo_objs); + if (station) + { + GeoLib::IO::XmlStnInterface xml(geo_objs); xml.export_name = points_group_name; BaseLib::IO::writeStringToFile(xml.writeToString(), out_fname); - } else { - GeoLib::IO::XmlGmlInterface xml (geo_objs); + } + else + { + GeoLib::IO::XmlGmlInterface xml(geo_objs); xml.export_name = points_group_name; BaseLib::IO::writeStringToFile(xml.writeToString(), out_fname); } } -void printFieldInformationTable(DBFHandle const& dbf_handle, std::size_t n_fields) +void printFieldInformationTable(DBFHandle const& dbf_handle, + std::size_t n_fields) { char* field_name(new char[256]); int width(0); @@ -111,7 +120,8 @@ void printFieldInformationTable(DBFHandle const& dbf_handle, std::size_t n_field out << "************************************************" << std::endl; out << "field idx | name of field | data type of field " << std::endl; out << "------------------------------------------------" << std::endl; - for (std::size_t field_idx(0); field_idx < n_fields; field_idx++) { + for (std::size_t field_idx(0); field_idx < n_fields; field_idx++) + { DBFGetFieldInfo(dbf_handle, field_idx, field_name, &width, &n_decimals); if (field_idx < 10) { @@ -129,19 +139,20 @@ void printFieldInformationTable(DBFHandle const& dbf_handle, std::size_t n_field out << field_name_str << " |"; char native_field_type(DBFGetNativeFieldType(dbf_handle, field_idx)); - switch (native_field_type) { - case 'C': - out << " string" << std::endl; - break; - case 'F': - out << " float" << std::endl; - break; - case 'N': - out << " numeric" << std::endl; - break; - default: - out << " n_decimal " << n_decimals << std::endl; - break; + switch (native_field_type) + { + case 'C': + out << " string" << std::endl; + break; + case 'F': + out << " float" << std::endl; + break; + case 'N': + out << " numeric" << std::endl; + break; + default: + out << " n_decimal " << n_decimals << std::endl; + break; } } delete[] field_name; @@ -149,7 +160,7 @@ void printFieldInformationTable(DBFHandle const& dbf_handle, std::size_t n_field INFO("{:s}", out.str()); } -int main (int argc, char* argv[]) +int main(int argc, char* argv[]) { TCLAP::CmdLine cmd( "Converts points contained in shape file\n\n" @@ -165,23 +176,24 @@ int main (int argc, char* argv[]) true, "", "shape file"); - cmd.add( shapefile_arg ); + cmd.add(shapefile_arg); cmd.parse(argc, argv); - std::string fname (shapefile_arg.getValue()); + std::string fname(shapefile_arg.getValue()); int shape_type; int number_of_elements; - SHPHandle hSHP = SHPOpen(fname.c_str(),"rb"); - if (hSHP) { + SHPHandle hSHP = SHPOpen(fname.c_str(), "rb"); + if (hSHP) + { SHPGetInfo(hSHP, &number_of_elements, &shape_type, nullptr /*padfMinBound*/, nullptr /*padfMinBound*/); if ((shape_type - 1) % 10 == 0) INFO("Shape file contains {:d} points.", number_of_elements); - if ( ((shape_type - 3) % 10 == 0 || (shape_type - 5) % 10 == 0)) + if (((shape_type - 3) % 10 == 0 || (shape_type - 5) % 10 == 0)) { ERR("Shape file contains {:d} polylines.", number_of_elements); ERR("This programme only handles only files containing points."); @@ -189,12 +201,14 @@ int main (int argc, char* argv[]) return EXIT_SUCCESS; } SHPClose(hSHP); - } else { + } + else + { ERR("Could not open shapefile {:s}.", fname); } - DBFHandle dbf_handle = DBFOpen(fname.c_str(),"rb"); - if(dbf_handle) + DBFHandle dbf_handle = DBFOpen(fname.c_str(), "rb"); + if (dbf_handle) { std::size_t n_fields(DBFGetFieldCount(dbf_handle)); printFieldInformationTable(dbf_handle, n_fields); @@ -202,11 +216,17 @@ int main (int argc, char* argv[]) std::size_t x_id; std::size_t y_id; std::size_t z_id; - INFO("Please give the field idx that should be used for reading the x coordinate: "); + INFO( + "Please give the field idx that should be used for reading the x " + "coordinate: "); std::cin >> x_id; - INFO("Please give the field idx that should be used for reading the y coordinate: "); + INFO( + "Please give the field idx that should be used for reading the y " + "coordinate: "); std::cin >> y_id; - INFO("Please give the field idx that should be used for reading the z coordinate: "); + INFO( + "Please give the field idx that should be used for reading the z " + "coordinate: "); std::cin >> z_id; if (z_id > n_fields) @@ -218,12 +238,15 @@ int main (int argc, char* argv[]) INFO("Please give the number of fields that should be added to name: "); std::cin >> n_name_components; - std::vector<std::size_t> name_component_ids (n_name_components, - std::numeric_limits<std::size_t>::max()); - if (n_name_components != 0) { + std::vector<std::size_t> name_component_ids( + n_name_components, std::numeric_limits<std::size_t>::max()); + if (n_name_components != 0) + { for (std::size_t j(0); j < n_name_components; j++) { - INFO("- please give the field idx that should be used for reading the name: "); + INFO( + "- please give the field idx that should be used for " + "reading the name: "); std::cin >> name_component_ids[j]; } } @@ -235,9 +258,11 @@ int main (int argc, char* argv[]) } } - std::size_t station (0); + std::size_t station(0); - INFO("Should I read the information as GeoLib::Station (0) or as GeoLib::Point (1)? Please give the number: "); + INFO( + "Should I read the information as GeoLib::Station (0) or as " + "GeoLib::Point (1)? Please give the number: "); std::cin >> station; std::string fname_base(fname); @@ -259,9 +284,11 @@ int main (int argc, char* argv[]) name_component_ids, fname_base, station == 0); - DBFClose (dbf_handle); + DBFClose(dbf_handle); INFO("\tok."); - } else { + } + else + { ERR("Could not open the database file."); } diff --git a/Applications/Utils/FileConverter/FEFLOW2OGS.cpp b/Applications/Utils/FileConverter/FEFLOW2OGS.cpp index f060e7087fb0e882d51f0ee38d7e3e9be0ed4575..ac3fe6d8be76d1dbad051a6925a22c87d7abcaba 100644 --- a/Applications/Utils/FileConverter/FEFLOW2OGS.cpp +++ b/Applications/Utils/FileConverter/FEFLOW2OGS.cpp @@ -7,29 +7,28 @@ * */ -#include <string> #include <memory> +#include <string> // ThirdParty #include <tclap/CmdLine.h> // BaseLib -#include "InfoLib/GitInfo.h" #include "BaseLib/FileTools.h" #include "BaseLib/RunTime.h" +#include "InfoLib/GitInfo.h" #ifndef WIN32 #include "BaseLib/MemWatch.h" #endif // FileIO #include "Applications/FileIO/FEFLOW/FEFLOWMeshInterface.h" - -#include "MeshLib/IO/writeMeshToFile.h" #include "MeshLib/IO/Legacy/MeshIO.h" #include "MeshLib/IO/VtkIO/VtuInterface.h" +#include "MeshLib/IO/writeMeshToFile.h" #include "MeshLib/Mesh.h" -int main (int argc, char* argv[]) +int main(int argc, char* argv[]) { TCLAP::CmdLine cmd( "Converting a mesh in FEFLOW file format (ASCII, version 5.4) to a vtk " @@ -45,19 +44,15 @@ int main (int argc, char* argv[]) TCLAP::ValueArg<std::string> ogs_mesh_arg( "o", "out", - "filename for output mesh (if extension is msh, old OGS fileformat is written)", + "filename for output mesh (if extension is msh, old OGS fileformat is " + "written)", true, "", "filename as string"); cmd.add(ogs_mesh_arg); TCLAP::ValueArg<std::string> feflow_mesh_arg( - "i", - "in", - "FEFLOW input file (*.fem)", - true, - "", - "filename as string"); + "i", "in", "FEFLOW input file (*.fem)", true, "", "filename as string"); cmd.add(feflow_mesh_arg); cmd.parse(argc, argv); @@ -66,7 +61,7 @@ int main (int argc, char* argv[]) INFO("Reading {:s}.", feflow_mesh_arg.getValue()); #ifndef WIN32 BaseLib::MemWatch mem_watch; - unsigned long mem_without_mesh (mem_watch.getVirtMemUsage()); + unsigned long mem_without_mesh(mem_watch.getVirtMemUsage()); #endif BaseLib::RunTime run_time; run_time.start(); @@ -74,12 +69,13 @@ int main (int argc, char* argv[]) std::unique_ptr<MeshLib::Mesh const> mesh( feflowIO.readFEFLOWFile(feflow_mesh_arg.getValue())); - if (mesh == nullptr) { + if (mesh == nullptr) + { INFO("Could not read mesh from {:s}.", feflow_mesh_arg.getValue()); return EXIT_FAILURE; } #ifndef WIN32 - unsigned long mem_with_mesh (mem_watch.getVirtMemUsage()); + unsigned long mem_with_mesh(mem_watch.getVirtMemUsage()); INFO("Mem for mesh: {} MiB", (mem_with_mesh - mem_without_mesh) / (1024 * 1024)); #endif @@ -93,4 +89,3 @@ int main (int argc, char* argv[]) INFO("\tDone."); return EXIT_SUCCESS; } - diff --git a/Applications/Utils/FileConverter/GMSH2OGS.cpp b/Applications/Utils/FileConverter/GMSH2OGS.cpp index eea94851845e30fa67068ac7da9a9ca8da97a1d0..350be21df762209e7a0988d164772cfa5f9cb9a8 100644 --- a/Applications/Utils/FileConverter/GMSH2OGS.cpp +++ b/Applications/Utils/FileConverter/GMSH2OGS.cpp @@ -13,16 +13,16 @@ */ // STL -#include <string> #include <algorithm> +#include <string> // ThirdParty #include <tclap/CmdLine.h> // BaseLib -#include "InfoLib/GitInfo.h" #include "BaseLib/FileTools.h" #include "BaseLib/RunTime.h" +#include "InfoLib/GitInfo.h" #ifndef WIN32 #include "BaseLib/MemWatch.h" #endif @@ -131,7 +131,7 @@ static void identifyAndWriteBoundaryMeshes( } } -int main (int argc, char* argv[]) +int main(int argc, char* argv[]) { TCLAP::CmdLine cmd( "Converting meshes in gmsh file format (ASCII, version 2.2) to a vtk " @@ -147,19 +147,16 @@ int main (int argc, char* argv[]) TCLAP::ValueArg<std::string> ogs_mesh_arg( "o", "out", - "filename for output mesh (if extension is .msh, old OGS-5 fileformat is written, if extension is .vtu, a vtk unstructure grid file is written (OGS-6 mesh format))", + "filename for output mesh (if extension is .msh, old OGS-5 fileformat " + "is written, if extension is .vtu, a vtk unstructure grid file is " + "written (OGS-6 mesh format))", true, "", "filename as string"); cmd.add(ogs_mesh_arg); TCLAP::ValueArg<std::string> gmsh_mesh_arg( - "i", - "in", - "gmsh input file", - true, - "", - "filename as string"); + "i", "in", "gmsh input file", true, "", "filename as string"); cmd.add(gmsh_mesh_arg); TCLAP::SwitchArg valid_arg("v", "validation", "validate the mesh"); @@ -169,7 +166,8 @@ int main (int argc, char* argv[]) "b", "boundaries", "if set, boundary meshes will be generated"); cmd.add(create_boundary_meshes_arg); - TCLAP::SwitchArg exclude_lines_arg("e", "exclude-lines", + TCLAP::SwitchArg exclude_lines_arg( + "e", "exclude-lines", "if set, lines will not be written to the ogs mesh"); cmd.add(exclude_lines_arg); @@ -179,14 +177,14 @@ int main (int argc, char* argv[]) INFO("Reading {:s}.", gmsh_mesh_arg.getValue()); #ifndef WIN32 BaseLib::MemWatch mem_watch; - unsigned long mem_without_mesh (mem_watch.getVirtMemUsage()); + unsigned long mem_without_mesh(mem_watch.getVirtMemUsage()); #endif BaseLib::RunTime run_time; run_time.start(); - MeshLib::Mesh* mesh( - FileIO::GMSH::readGMSHMesh(gmsh_mesh_arg.getValue())); + MeshLib::Mesh* mesh(FileIO::GMSH::readGMSHMesh(gmsh_mesh_arg.getValue())); - if (mesh == nullptr) { + if (mesh == nullptr) + { INFO("Could not read mesh from {:s}.", gmsh_mesh_arg.getValue()); return -1; } @@ -278,4 +276,3 @@ int main (int argc, char* argv[]) delete mesh; } - diff --git a/Applications/Utils/FileConverter/GocadTSurfaceReader.cpp b/Applications/Utils/FileConverter/GocadTSurfaceReader.cpp index eac31c6a5a87fe1e41da179a6f58b946e84c9007..ab34df0fa9f065bc48d7ec4691fd657d90dbf7a1 100644 --- a/Applications/Utils/FileConverter/GocadTSurfaceReader.cpp +++ b/Applications/Utils/FileConverter/GocadTSurfaceReader.cpp @@ -9,10 +9,10 @@ #include <tclap/CmdLine.h> +#include "Applications/FileIO/GocadIO/GocadAsciiReader.h" #include "InfoLib/GitInfo.h" -#include "MeshLib/Mesh.h" #include "MeshLib/IO/VtkIO/VtuInterface.h" -#include "Applications/FileIO/GocadIO/GocadAsciiReader.h" +#include "MeshLib/Mesh.h" std::string getDelim(std::string const& str) { @@ -68,7 +68,7 @@ int main(int argc, char* argv[]) return 2; } - std::string const file_name (input_arg.getValue()); + std::string const file_name(input_arg.getValue()); FileIO::Gocad::DataType t(FileIO::Gocad::DataType::ALL); if (export_lines_arg.isSet()) diff --git a/Applications/Utils/FileConverter/Mesh2Raster.cpp b/Applications/Utils/FileConverter/Mesh2Raster.cpp index e2c9e8ea8877e682b0ce6f9f714d885cd05ff869..27ad44ee22b1e735c53cbb0c60d1b71aeb302afa 100644 --- a/Applications/Utils/FileConverter/Mesh2Raster.cpp +++ b/Applications/Utils/FileConverter/Mesh2Raster.cpp @@ -109,7 +109,8 @@ int main(int argc, char* argv[]) // centre of the pixel is located within a mesh element if (element != nullptr) { - out << MeshLib::ProjectPointOnMesh::getElevation(*element, node) << " "; + out << MeshLib::ProjectPointOnMesh::getElevation(*element, node) + << " "; } else { diff --git a/Applications/Utils/FileConverter/NetCdfConverter.cpp b/Applications/Utils/FileConverter/NetCdfConverter.cpp index ee414a6185321c94f41f5dcaa1b8ec679f32339a..e95e63ed6bd815e1351619f4f8f8fd55744e969c 100644 --- a/Applications/Utils/FileConverter/NetCdfConverter.cpp +++ b/Applications/Utils/FileConverter/NetCdfConverter.cpp @@ -188,7 +188,7 @@ static void flipRaster(std::vector<double>& data, std::size_t const layers, tmp_vec.reserve(length); for (std::size_t k = 0; k < layers; k++) { - std::size_t const layer_end = (k+1) * height * width; + std::size_t const layer_end = (k + 1) * height * width; for (std::size_t i = 0; i < height; i++) { std::size_t const line_idx(layer_end - (width * (i + 1))); @@ -205,7 +205,8 @@ static bool canConvert(NcVar const& var) { bool ret(var.getDimCount() < 2); if (ret) - ERR("Only 2+ dimensional variables can be converted into OGS Meshes.\n"); + ERR("Only 2+ dimensional variables can be converted into OGS " + "Meshes.\n"); return !ret; } @@ -224,7 +225,7 @@ static std::string arraySelectionLoop(NcFile const& dataset) } static bool dimensionSelectionLoop(NcVar const& var, - std::vector<std::size_t>& dim_idx_map) + std::vector<std::size_t>& dim_idx_map) { showArraysDims(var); std::size_t const n_dims(var.getDimCount()); @@ -272,9 +273,11 @@ static bool dimensionSelectionLoop(NcVar const& var, { dim_idx_map[i] = std::numeric_limits<std::size_t>::max(); - std::string const request_str("Enter ID for dimension " + std::to_string(i) + - " " + dim_comment[i - start_idx] + ": "); - std::size_t const idx = parseInput(request_str, var.getDimCount(), true); + std::string const request_str("Enter ID for dimension " + + std::to_string(i) + " " + + dim_comment[i - start_idx] + ": "); + std::size_t const idx = + parseInput(request_str, var.getDimCount(), true); if (static_cast<int>(idx) == var.getDimCount()) { @@ -297,11 +300,13 @@ static std::pair<std::size_t, std::size_t> timestepSelectionLoop( std::cout << "\nThe dataset contains " << n_time_steps << " time steps.\n"; while (bounds.first == max_val) { - bounds.first = parseInput("Specify first time step to export: ", n_time_steps, false); + bounds.first = parseInput( + "Specify first time step to export: ", n_time_steps, false); } while (bounds.first > bounds.second || bounds.second > n_time_steps) { - bounds.second = parseInput( "Specify last time step to export: ", n_time_steps, false); + bounds.second = parseInput( + "Specify last time step to export: ", n_time_steps, false); } return bounds; } @@ -352,7 +357,8 @@ static OutputType multFilesSelectionLoop( OutputType t = OutputType::INVALID; while (t == OutputType::INVALID) { - std::size_t const n_time_steps(time_bounds.second - time_bounds.first + 1); + std::size_t const n_time_steps(time_bounds.second - time_bounds.first + + 1); std::cout << "\nThe selection includes " << n_time_steps << " time steps.\n"; std::cout << "0. Save data in " << n_time_steps @@ -361,7 +367,8 @@ static OutputType multFilesSelectionLoop( << " scalar arrays.\n"; std::cout << "2. Save data as " << n_time_steps << " ASC images.\n"; - std::size_t const ret = parseInput("Select preferred method: ", 3, false); + std::size_t const ret = + parseInput("Select preferred method: ", 3, false); if (ret == 0) t = OutputType::MULTIMESH; @@ -383,7 +390,7 @@ static std::string getIterationString(std::size_t i, std::size_t max) static double getResolution(NcFile const& dataset, NcVar const& var) { std::size_t const dim_idx = var.getDimCount() - 1; - NcVar const dim_var (getDimVar(dataset, var, dim_idx)); + NcVar const dim_var(getDimVar(dataset, var, dim_idx)); auto const bounds = (dim_var.isNull()) ? getDimLength(var, dim_idx) : getBoundaries(dim_var); std::size_t const dim_size = var.getDim(dim_idx).getSize(); @@ -392,7 +399,8 @@ static double getResolution(NcFile const& dataset, NcVar const& var) OGS_FATAL("Dimension '{:s}' has size 0. Aborting...", var.getDim(dim_idx).getName()); } - return std::fabs(bounds.second - bounds.first) / static_cast<double>(dim_size); + return std::fabs(bounds.second - bounds.first) / + static_cast<double>(dim_size); } static GeoLib::RasterHeader createRasterHeader( @@ -408,10 +416,14 @@ static GeoLib::RasterHeader createRasterHeader( (n_dims - time_offset == 3) ? length[dim_idx_map.back()] : 1; return {length[dim_idx_map[0 + time_offset]], length[dim_idx_map[1 + time_offset]], - z_length, origin, res, no_data_output}; + z_length, + origin, + res, + no_data_output}; } -static std::vector<std::size_t> getLength(NcVar const& var, std::size_t const time_offset) +static std::vector<std::size_t> getLength(NcVar const& var, + std::size_t const time_offset) { std::size_t const n_dims = (var.getDimCount()); std::vector<std::size_t> length(n_dims, 1); @@ -423,9 +435,9 @@ static std::vector<std::size_t> getLength(NcVar const& var, std::size_t const ti } static std::vector<double> getData(NcFile const& dataset, NcVar const& var, - std::size_t const total_length, - std::size_t const time_step, - std::vector<std::size_t> const& length) + std::size_t const total_length, + std::size_t const time_step, + std::vector<std::size_t> const& length) { std::size_t const n_dims(var.getDimCount()); std::vector<std::size_t> offset(n_dims, 0); @@ -441,11 +453,11 @@ static std::vector<double> getData(NcFile const& dataset, NcVar const& var, } static bool assignDimParams(NcVar const& var, - std::vector<std::size_t>& dim_idx_map, - TCLAP::ValueArg<std::size_t>& arg_dim_time, - TCLAP::ValueArg<std::size_t>& arg_dim1, - TCLAP::ValueArg<std::size_t>& arg_dim2, - TCLAP::ValueArg<std::size_t>& arg_dim3) + std::vector<std::size_t>& dim_idx_map, + TCLAP::ValueArg<std::size_t>& arg_dim_time, + TCLAP::ValueArg<std::size_t>& arg_dim1, + TCLAP::ValueArg<std::size_t>& arg_dim2, + TCLAP::ValueArg<std::size_t>& arg_dim3) { std::size_t dim_param_count = 0; if (arg_dim_time.isSet()) @@ -460,7 +472,8 @@ static bool assignDimParams(NcVar const& var, std::size_t const n_dims = var.getDimCount(); if (dim_param_count != n_dims) { - ERR("Number of parameters set does not fit number of parameters for specified variable."); + ERR("Number of parameters set does not fit number of parameters for " + "specified variable."); return false; } @@ -491,7 +504,8 @@ static std::pair<std::size_t, std::size_t> assignTimeBounds( auto const bounds = getBoundaries(var); if (arg_time_start.getValue() > bounds.second) { - ERR("Start time step larger than total number of time steps. Resetting to 0."); + ERR("Start time step larger than total number of time steps. Resetting " + "to 0."); arg_time_start.reset(); } @@ -500,7 +514,8 @@ static std::pair<std::size_t, std::size_t> assignTimeBounds( if (arg_time_end.getValue() > bounds.second) { - ERR("End time step larger than total number of time steps. Resetting to starting time step"); + ERR("End time step larger than total number of time steps. Resetting " + "to starting time step"); return {arg_time_start.getValue(), arg_time_start.getValue()}; } @@ -542,8 +557,10 @@ static bool convert(NcFile const& dataset, NcVar const& var, length.cbegin(), length.cend(), 1, std::multiplies<std::size_t>()); for (std::size_t i = time_bounds.first; i <= time_bounds.second; ++i) { - std::string const step_str = (time_bounds.first != time_bounds.second) - ? std::string(" time step " + std::to_string(i)) : ""; + std::string const step_str = + (time_bounds.first != time_bounds.second) + ? std::string(" time step " + std::to_string(i)) + : ""; std::cout << "Converting" << step_str << "...\n"; std::vector<double> data_vec = getData(dataset, var, array_length, i, length); @@ -558,7 +575,8 @@ static bool convert(NcFile const& dataset, NcVar const& var, { std::size_t n_layers = (length.size() - time_offset == 3) ? length[n_dims - 3] : 1; - flipRaster(data_vec, n_layers, length[n_dims - 1], length[n_dims - 2]); + flipRaster(data_vec, n_layers, length[n_dims - 1], + length[n_dims - 2]); } GeoLib::RasterHeader const header = @@ -603,19 +621,22 @@ static bool convert(NcFile const& dataset, NcVar const& var, MeshLib::IO::VtuInterface vtu(mesh.get()); std::string const output_file_name = (BaseLib::getFileExtension(output_name) == ".vtu") - ? output_name : output_name + ".vtu"; + ? output_name + : output_name + ".vtu"; vtu.writeToFile(output_file_name); } } - else //OutputType::IMAGES + else // OutputType::IMAGES { - GeoLib::Raster const raster( - header, data_vec.data(), - data_vec.data() + header.n_cols * header.n_rows * header.n_depth); + GeoLib::Raster const raster(header, data_vec.data(), + data_vec.data() + header.n_cols * + header.n_rows * + header.n_depth); std::string const output_file_name( BaseLib::dropFileExtension(output_name) + getIterationString(i, time_bounds.second) + ".asc"); - FileIO::AsciiRasterInterface::writeRasterAsASC(raster, output_file_name); + FileIO::AsciiRasterInterface::writeRasterAsASC(raster, + output_file_name); } } return true; @@ -634,7 +655,8 @@ int main(int argc, char* argv[]) TCLAP::ValueArg<int> arg_nodata( "n", "nodata", - "explicitly specifies the no data value used in the dataset (usually it is not necessary to set this)", + "explicitly specifies the no data value used in the dataset (usually " + "it is not necessary to set this)", false, no_data_input, "integer specifying no data value"); cmd.add(arg_nodata); @@ -752,11 +774,12 @@ int main(int argc, char* argv[]) } std::vector<std::size_t> dim_idx_map(var.getDimCount(), 0); - bool is_time_dep (false); + bool is_time_dep(false); if (arg_dim1.isSet() && arg_dim2.isSet()) { is_time_dep = arg_dim_time.isSet(); - if (!assignDimParams(var, dim_idx_map, arg_dim_time, arg_dim1, arg_dim2, arg_dim3)) + if (!assignDimParams(var, dim_idx_map, arg_dim_time, arg_dim1, arg_dim2, + arg_dim3)) return EXIT_FAILURE; } else @@ -766,7 +789,8 @@ int main(int argc, char* argv[]) std::pair<std::size_t, std::size_t> time_bounds(0, 0); if (is_time_dep) - time_bounds = (arg_time_start.isSet()) + time_bounds = + (arg_time_start.isSet()) ? assignTimeBounds(getDimVar(dataset, var, dim_idx_map[0]), arg_time_start, arg_time_end) : timestepSelectionLoop(var, dim_idx_map[0]); @@ -781,7 +805,7 @@ int main(int argc, char* argv[]) output = OutputType::MULTIMESH; } else if (arg_single_file.isSet() || !is_time_dep || - time_bounds.first == time_bounds.second) + time_bounds.first == time_bounds.second) { output = OutputType::SINGLEMESH; } diff --git a/Applications/Utils/FileConverter/OGS2VTK.cpp b/Applications/Utils/FileConverter/OGS2VTK.cpp index d538783ff9544875db5fa4030f87dc47b1519c2a..3d8aa3c05f5b6744b1e04a19649e080d68e6474c 100644 --- a/Applications/Utils/FileConverter/OGS2VTK.cpp +++ b/Applications/Utils/FileConverter/OGS2VTK.cpp @@ -11,17 +11,17 @@ * http://www.opengeosys.org/project/license */ -#include <string> -#include <memory> - #include <tclap/CmdLine.h> +#include <memory> +#include <string> + #include "InfoLib/GitInfo.h" #include "MeshLib/IO/VtkIO/VtuInterface.h" #include "MeshLib/IO/readMeshFromFile.h" #include "MeshLib/Mesh.h" -int main (int argc, char* argv[]) +int main(int argc, char* argv[]) { TCLAP::CmdLine cmd( "Converts OGS mesh into VTK mesh.\n\n" diff --git a/Applications/Utils/FileConverter/TIN2VTK.cpp b/Applications/Utils/FileConverter/TIN2VTK.cpp index 2226293cd5e48dd56bdc39a4e86c987ab9ed20b3..11877aed731b29b261f130109b9470d53d0fe96a 100644 --- a/Applications/Utils/FileConverter/TIN2VTK.cpp +++ b/Applications/Utils/FileConverter/TIN2VTK.cpp @@ -8,30 +8,28 @@ */ // STL +#include <tclap/CmdLine.h> + #include <memory> #include <string> #include <vector> -#include <tclap/CmdLine.h> - // BaseLib -#include "InfoLib/GitInfo.h" #include "BaseLib/FileTools.h" +#include "InfoLib/GitInfo.h" // GeoLib +#include "GeoLib/IO/TINInterface.h" #include "GeoLib/Point.h" -#include "GeoLib/Surface.h" #include "GeoLib/PointVec.h" -#include "GeoLib/IO/TINInterface.h" - +#include "GeoLib/Surface.h" #include "MeshLib/IO/VtkIO/VtuInterface.h" // MeshLib #include "MeshLib/Mesh.h" #include "MeshLib/convertMeshToGeo.h" - -int main (int argc, char* argv[]) +int main(int argc, char* argv[]) { TCLAP::CmdLine cmd( "Converts TIN file into VTU file.\n\n" @@ -41,13 +39,13 @@ int main (int argc, char* argv[]) "Copyright (c) 2012-2021, OpenGeoSys Community " "(http://www.opengeosys.org)", ' ', GitInfoLib::GitInfo::ogs_version); - TCLAP::ValueArg<std::string> inArg("i", "input-tin-file", - "the name of the file containing the input TIN", true, - "", "string"); + TCLAP::ValueArg<std::string> inArg( + "i", "input-tin-file", "the name of the file containing the input TIN", + true, "", "string"); cmd.add(inArg); - TCLAP::ValueArg<std::string> outArg("o", "output-vtu-file", - "the name of the file the mesh will be written to", true, - "", "string"); + TCLAP::ValueArg<std::string> outArg( + "o", "output-vtu-file", + "the name of the file the mesh will be written to", true, "", "string"); cmd.add(outArg); cmd.parse(argc, argv); @@ -65,7 +63,9 @@ int main (int argc, char* argv[]) sfc->getNumberOfTriangles()); INFO("converting to mesh data"); - std::unique_ptr<MeshLib::Mesh> mesh(MeshLib::convertSurfaceToMesh(*sfc, BaseLib::extractBaseNameWithoutExtension(tinFileName), std::numeric_limits<double>::epsilon())); + std::unique_ptr<MeshLib::Mesh> mesh(MeshLib::convertSurfaceToMesh( + *sfc, BaseLib::extractBaseNameWithoutExtension(tinFileName), + std::numeric_limits<double>::epsilon())); INFO("Mesh created: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(), mesh->getNumberOfElements()); diff --git a/Applications/Utils/FileConverter/TecPlotTools.cpp b/Applications/Utils/FileConverter/TecPlotTools.cpp index bf6d1183d3a03b410c63b7081342f8fbfcaa0a6b..796e1bd9337b7b56dee0721580064edcbfda4e61 100644 --- a/Applications/Utils/FileConverter/TecPlotTools.cpp +++ b/Applications/Utils/FileConverter/TecPlotTools.cpp @@ -21,7 +21,8 @@ #include "MeshLib/Mesh.h" #include "MeshLib/MeshGenerators/RasterToMesh.h" -/// Returns the value for the given parameter name (i.e. for "x = 3" it returns "3") +/// Returns the value for the given parameter name (i.e. for "x = 3" it returns +/// "3") std::string getValue(std::string const& line, std::string const& val_name, bool is_string) @@ -111,7 +112,8 @@ std::vector<std::string> getVariables(std::string const& line) { std::string const var_str("VARIABLES"); std::size_t start(line.find(var_str)); - std::string all_vars = line.substr(start + var_str.length(), std::string::npos); + std::string all_vars = + line.substr(start + var_str.length(), std::string::npos); start = all_vars.find("="); all_vars = all_vars.substr(start + 1, std::string::npos); BaseLib::trim(all_vars); @@ -185,7 +187,8 @@ void writeTecPlotSection(std::ofstream& out, { std::size_t const delim_pos(file_name.find_last_of(".")); std::string const base_name(file_name.substr(0, delim_pos + 1)); - std::string const extension(file_name.substr(delim_pos, std::string::npos)); + std::string const extension( + file_name.substr(delim_pos, std::string::npos)); val_count = 0; val_total = 0; @@ -219,7 +222,8 @@ int writeDataToMesh(std::string const& file_name, } GeoLib::Point origin(0, 0, 0); - GeoLib::RasterHeader header{dims.first, dims.second, 1, origin, cellsize, -9999}; + GeoLib::RasterHeader header{dims.first, dims.second, 1, + origin, cellsize, -9999}; std::unique_ptr<MeshLib::Mesh> mesh( MeshLib::RasterToMesh::convert(scalars[0].data(), @@ -238,7 +242,8 @@ int writeDataToMesh(std::string const& file_name, return -5; } prop->reserve(scalars[i].size()); - std::copy(scalars[i].cbegin(), scalars[i].cend(), std::back_inserter(*prop)); + std::copy(scalars[i].cbegin(), scalars[i].cend(), + std::back_inserter(*prop)); } std::size_t const delim_pos(file_name.find_last_of(".")); @@ -282,7 +287,8 @@ int splitFile(std::ifstream& in, std::string const& file_name) { return -3; } - writeTecPlotSection(out, file_name, write_count, val_count, val_total); + writeTecPlotSection(out, file_name, write_count, val_count, + val_total); out << line << "\n"; continue; } @@ -292,7 +298,8 @@ int splitFile(std::ifstream& in, std::string const& file_name) { return -3; } - writeTecPlotSection(out, file_name, write_count, val_count, val_total); + writeTecPlotSection(out, file_name, write_count, val_count, + val_total); out << line << "\n"; continue; } @@ -302,7 +309,8 @@ int splitFile(std::ifstream& in, std::string const& file_name) { return -3; } - writeTecPlotSection(out, file_name, write_count, val_count, val_total); + writeTecPlotSection(out, file_name, write_count, val_count, + val_total); out << line << "\n"; name = getName(line); std::pair<std::size_t, std::size_t> dims = getDimensions(line); @@ -324,7 +332,8 @@ int splitFile(std::ifstream& in, std::string const& file_name) return 0; } -/// Converts a TecPlot file into one or more OGS-meshes (one mesh per section/zone) +/// Converts a TecPlot file into one or more OGS-meshes (one mesh per +/// section/zone) int convertFile(std::ifstream& in, std::string const& file_name) { std::string line; @@ -354,7 +363,8 @@ int convertFile(std::ifstream& in, std::string const& file_name) } if (val_count != 0) { - writeDataToMesh(file_name, write_count, var_names, scalars, dims); + writeDataToMesh(file_name, write_count, var_names, scalars, + dims); resetDataStructures(var_names.size(), scalars, val_count); } continue; @@ -367,7 +377,8 @@ int convertFile(std::ifstream& in, std::string const& file_name) { return -3; } - writeDataToMesh(file_name, write_count, var_names, scalars, dims); + writeDataToMesh(file_name, write_count, var_names, scalars, + dims); } var_names.clear(); var_names = getVariables(line); @@ -382,7 +393,8 @@ int convertFile(std::ifstream& in, std::string const& file_name) { return -3; } - writeDataToMesh(file_name, write_count, var_names, scalars, dims); + writeDataToMesh(file_name, write_count, var_names, scalars, + dims); resetDataStructures(var_names.size(), scalars, val_count); } name = getName(line); @@ -450,10 +462,10 @@ int main(int argc, char* argv[]) "(http://www.opengeosys.org)", ' ', GitInfoLib::GitInfo::ogs_version); TCLAP::SwitchArg split_arg("s", "split", - "split time steps into separate files"); + "split time steps into separate files"); cmd.add(split_arg); TCLAP::SwitchArg convert_arg("c", "convert", - "convert TecPlot data into OGS meshes"); + "convert TecPlot data into OGS meshes"); cmd.add(convert_arg); TCLAP::ValueArg<std::string> output_arg( "o", "output-file", "output mesh file", false, "", "string"); @@ -488,8 +500,8 @@ int main(int argc, char* argv[]) return 0; } - std::string const filename = (output_arg.isSet()) ? - output_arg.getValue() : input_arg.getValue(); + std::string const filename = + (output_arg.isSet()) ? output_arg.getValue() : input_arg.getValue(); int return_val(0); if (split_arg.getValue()) { diff --git a/Applications/Utils/FileConverter/VTK2OGS.cpp b/Applications/Utils/FileConverter/VTK2OGS.cpp index 1d1f767f931c86c02390f80e95d1b7afa19e6258..7c17c2147f43a19cc7b762db6141d78e7d9dfb4a 100644 --- a/Applications/Utils/FileConverter/VTK2OGS.cpp +++ b/Applications/Utils/FileConverter/VTK2OGS.cpp @@ -12,16 +12,16 @@ */ // STL -#include <string> - #include <tclap/CmdLine.h> +#include <string> + #include "InfoLib/GitInfo.h" #include "MeshLib/IO/Legacy/MeshIO.h" #include "MeshLib/IO/VtkIO/VtuInterface.h" #include "MeshLib/Mesh.h" -int main (int argc, char* argv[]) +int main(int argc, char* argv[]) { TCLAP::CmdLine cmd( "Converts VTK mesh into OGS mesh.\n\n" @@ -31,17 +31,20 @@ int main (int argc, char* argv[]) "Copyright (c) 2012-2021, OpenGeoSys Community " "(http://www.opengeosys.org)", ' ', GitInfoLib::GitInfo::ogs_version); - TCLAP::ValueArg<std::string> mesh_in("i", "mesh-input-file", - "the name of the file containing the input mesh", true, - "", "file name of input mesh"); + TCLAP::ValueArg<std::string> mesh_in( + "i", "mesh-input-file", + "the name of the file containing the input mesh", true, "", + "file name of input mesh"); cmd.add(mesh_in); - TCLAP::ValueArg<std::string> mesh_out("o", "mesh-output-file", - "the name of the file the mesh will be written to", true, - "", "file name of output mesh"); + TCLAP::ValueArg<std::string> mesh_out( + "o", "mesh-output-file", + "the name of the file the mesh will be written to", true, "", + "file name of output mesh"); cmd.add(mesh_out); cmd.parse(argc, argv); - MeshLib::Mesh* mesh (MeshLib::IO::VtuInterface::readVTUFile(mesh_in.getValue())); + MeshLib::Mesh* mesh( + MeshLib::IO::VtuInterface::readVTUFile(mesh_in.getValue())); INFO("Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(), mesh->getNumberOfElements()); diff --git a/Applications/Utils/FileConverter/VTK2TIN.cpp b/Applications/Utils/FileConverter/VTK2TIN.cpp index 4833a02621b6c9b8525196b695b10c4a45bd7ac0..4aec6bf6af811bd5d29216ad05158d31d206e884 100644 --- a/Applications/Utils/FileConverter/VTK2TIN.cpp +++ b/Applications/Utils/FileConverter/VTK2TIN.cpp @@ -8,31 +8,29 @@ */ // STL +#include <tclap/CmdLine.h> + +#include <fstream> #include <memory> #include <string> -#include <fstream> - -#include <tclap/CmdLine.h> // BaseLib -#include "InfoLib/GitInfo.h" #include "BaseLib/Logging.h" +#include "InfoLib/GitInfo.h" // GeoLib #include "GeoLib/GEOObjects.h" -#include "GeoLib/Surface.h" #include "GeoLib/IO/TINInterface.h" +#include "GeoLib/Surface.h" // MeshLib -#include "MeshLib/Mesh.h" #include "MeshLib/Elements/Element.h" +#include "MeshLib/IO/VtkIO/VtuInterface.h" +#include "MeshLib/Mesh.h" #include "MeshLib/Node.h" #include "MeshLib/convertMeshToGeo.h" -#include "MeshLib/IO/VtkIO/VtuInterface.h" - - -int main (int argc, char* argv[]) +int main(int argc, char* argv[]) { TCLAP::CmdLine cmd( "Converts VTK mesh into TIN file.\n\n" @@ -42,23 +40,27 @@ int main (int argc, char* argv[]) "Copyright (c) 2012-2021, OpenGeoSys Community " "(http://www.opengeosys.org)", ' ', GitInfoLib::GitInfo::ogs_version); - TCLAP::ValueArg<std::string> mesh_in("i", "mesh-input-file", - "the name of the file containing the input mesh", true, - "", "file name of input mesh"); + TCLAP::ValueArg<std::string> mesh_in( + "i", "mesh-input-file", + "the name of the file containing the input mesh", true, "", + "file name of input mesh"); cmd.add(mesh_in); - TCLAP::ValueArg<std::string> mesh_out("o", "TIN-output-file", - "the name of the file the TIN will be written to", true, - "", "file name of output TIN"); + TCLAP::ValueArg<std::string> mesh_out( + "o", "TIN-output-file", + "the name of the file the TIN will be written to", true, "", + "file name of output TIN"); cmd.add(mesh_out); cmd.parse(argc, argv); - std::unique_ptr<MeshLib::Mesh> mesh (MeshLib::IO::VtuInterface::readVTUFile(mesh_in.getValue())); + std::unique_ptr<MeshLib::Mesh> mesh( + MeshLib::IO::VtuInterface::readVTUFile(mesh_in.getValue())); INFO("Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(), mesh->getNumberOfElements()); INFO("Converting the mesh to TIN"); GeoLib::GEOObjects geo_objects; - if (MeshLib::convertMeshToGeo(*mesh, geo_objects)) { + if (MeshLib::convertMeshToGeo(*mesh, geo_objects)) + { INFO("Writing TIN into the file"); GeoLib::IO::TINInterface::writeSurfaceAsTIN( *(*geo_objects.getSurfaceVec(mesh->getName()))[0], diff --git a/Applications/Utils/FileConverter/convertGEO.cpp b/Applications/Utils/FileConverter/convertGEO.cpp index af7129bc0a82601adcbf7b66ed1b2268a94f4362..2111ecb7f9a9d3b272354b26a596b5127b3cae63 100644 --- a/Applications/Utils/FileConverter/convertGEO.cpp +++ b/Applications/Utils/FileConverter/convertGEO.cpp @@ -7,19 +7,17 @@ * */ -#include <string> -#include <vector> - #include <tclap/CmdLine.h> -#include "InfoLib/GitInfo.h" +#include <string> +#include <vector> #include "Applications/FileIO/readGeometryFromFile.h" #include "Applications/FileIO/writeGeometryToFile.h" #include "GeoLib/GEOObjects.h" +#include "InfoLib/GitInfo.h" - -int main (int argc, char* argv[]) +int main(int argc, char* argv[]) { TCLAP::CmdLine cmd( "Converts OGS geometry file into another file format. " @@ -31,18 +29,20 @@ int main (int argc, char* argv[]) "Copyright (c) 2012-2021, OpenGeoSys Community " "(http://www.opengeosys.org)", ' ', GitInfoLib::GitInfo::ogs_version); - TCLAP::ValueArg<std::string> argInputFileName("i", "input-file", - "the name of the geometry file to be converted", true, - "", "file name"); + TCLAP::ValueArg<std::string> argInputFileName( + "i", "input-file", "the name of the geometry file to be converted", + true, "", "file name"); cmd.add(argInputFileName); - TCLAP::ValueArg<std::string> argOutputFileName("o", "output-file", - "the name of the new geometry file whose file format is guessed from its file extension", true, - "", "file name"); + TCLAP::ValueArg<std::string> argOutputFileName( + "o", "output-file", + "the name of the new geometry file whose file format is guessed from " + "its file extension", + true, "", "file name"); cmd.add(argOutputFileName); TCLAP::ValueArg<std::string> gmsh_path_arg("g", "gmsh-path", - "the path to the gmsh binary", false, - "", "path as string"); + "the path to the gmsh binary", + false, "", "path as string"); cmd.add(gmsh_path_arg); cmd.parse(argc, argv); @@ -52,7 +52,8 @@ int main (int argc, char* argv[]) auto const geo_names = geoObjects.getGeometryNames(); assert(geo_names.size() == 1); - FileIO::writeGeometryToFile(geo_names[0], geoObjects, argOutputFileName.getValue()); + FileIO::writeGeometryToFile(geo_names[0], geoObjects, + argOutputFileName.getValue()); return EXIT_SUCCESS; } diff --git a/Applications/Utils/FileConverter/generateMatPropsFromMatID.cpp b/Applications/Utils/FileConverter/generateMatPropsFromMatID.cpp index ec3ca9f05a0f519fab2dbdae7748f23562f2defa..329f076326aa7d1a6cec4d2611a0b4415b5a0ea7 100644 --- a/Applications/Utils/FileConverter/generateMatPropsFromMatID.cpp +++ b/Applications/Utils/FileConverter/generateMatPropsFromMatID.cpp @@ -12,20 +12,18 @@ * */ -#include <memory> - #include <tclap/CmdLine.h> -#include "InfoLib/GitInfo.h" -#include "BaseLib/FileTools.h" +#include <memory> +#include "BaseLib/FileTools.h" +#include "InfoLib/GitInfo.h" +#include "MeshLib/Elements/Element.h" #include "MeshLib/IO/readMeshFromFile.h" #include "MeshLib/IO/writeMeshToFile.h" - #include "MeshLib/Mesh.h" -#include "MeshLib/Elements/Element.h" -int main (int argc, char* argv[]) +int main(int argc, char* argv[]) { TCLAP::CmdLine cmd( "Creates a new file for material properties and sets the material ids " @@ -38,14 +36,14 @@ int main (int argc, char* argv[]) ' ', GitInfoLib::GitInfo::ogs_version); TCLAP::ValueArg<std::string> mesh_arg("m", - "mesh", - "the mesh to open from a file", - false, - "", - "filename for mesh input"); - cmd.add( mesh_arg ); - - cmd.parse( argc, argv ); + "mesh", + "the mesh to open from a file", + false, + "", + "filename for mesh input"); + cmd.add(mesh_arg); + + cmd.parse(argc, argv); // read mesh std::unique_ptr<MeshLib::Mesh> mesh( diff --git a/Applications/Utils/GeoTools/MoveGeometry.cpp b/Applications/Utils/GeoTools/MoveGeometry.cpp index 87c60334622be7e90ce0ce56ad262529df99c24f..c0e46cd3860c3c5da809b61d1d978791f3a914b1 100644 --- a/Applications/Utils/GeoTools/MoveGeometry.cpp +++ b/Applications/Utils/GeoTools/MoveGeometry.cpp @@ -14,13 +14,13 @@ // ThirdParty #include <tclap/CmdLine.h> -#include "InfoLib/GitInfo.h" +#include <QCoreApplication> + #include "GeoLib/GEOObjects.h" #include "GeoLib/IO/XmlIO/Qt/XmlGmlInterface.h" +#include "InfoLib/GitInfo.h" -#include <QCoreApplication> - -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { QCoreApplication app(argc, argv); @@ -32,22 +32,22 @@ int main(int argc, char *argv[]) "Copyright (c) 2012-2021, OpenGeoSys Community " "(http://www.opengeosys.org)", ' ', GitInfoLib::GitInfo::ogs_version); - TCLAP::ValueArg<double> z_arg - ("z", "z", "displacement in z direction", false, 0.0, "z-displacement"); + TCLAP::ValueArg<double> z_arg("z", "z", "displacement in z direction", + false, 0.0, "z-displacement"); cmd.add(z_arg); - TCLAP::ValueArg<double> y_arg - ("y", "y", "displacement in y direction", false, 0.0, "y-displacement"); + TCLAP::ValueArg<double> y_arg("y", "y", "displacement in y direction", + false, 0.0, "y-displacement"); cmd.add(y_arg); - TCLAP::ValueArg<double> x_arg - ("x", "x", "displacement in x direction", false, 0.0, "x-displacement"); + TCLAP::ValueArg<double> x_arg("x", "x", "displacement in x direction", + false, 0.0, "x-displacement"); cmd.add(x_arg); - TCLAP::ValueArg<std::string> geo_output_arg - ("o","output", "output geometry file (*.gml)", true, "", "output file"); + TCLAP::ValueArg<std::string> geo_output_arg( + "o", "output", "output geometry file (*.gml)", true, "", "output file"); cmd.add(geo_output_arg); - TCLAP::ValueArg<std::string> geo_input_arg - ("i","input", "input geometry file (*.gml)", true, "", "input file"); + TCLAP::ValueArg<std::string> geo_input_arg( + "i", "input", "input geometry file (*.gml)", true, "", "input file"); cmd.add(geo_input_arg); - cmd.parse( argc, argv ); + cmd.parse(argc, argv); GeoLib::GEOObjects geo_objects; GeoLib::IO::XmlGmlInterface xml(geo_objects); diff --git a/Applications/Utils/GeoTools/TriangulatePolyline.cpp b/Applications/Utils/GeoTools/TriangulatePolyline.cpp index 8eeb8170aba3d8e08408c23da85d93ca904213d1..171c000b3a17ca2a3b05487c9646cd41c934fa29 100644 --- a/Applications/Utils/GeoTools/TriangulatePolyline.cpp +++ b/Applications/Utils/GeoTools/TriangulatePolyline.cpp @@ -11,31 +11,28 @@ * http://www.opengeosys.org/project/license */ -#include <string> - #include <tclap/CmdLine.h> -#include "Applications/FileIO/Legacy/createSurface.h" - -#include "InfoLib/GitInfo.h" +#include <QCoreApplication> +#include <string> -#include "GeoLib/IO/XmlIO/Qt/XmlGmlInterface.h" +#include "Applications/FileIO/Legacy/createSurface.h" #include "GeoLib/AnalyticalGeometry.h" #include "GeoLib/GEOObjects.h" +#include "GeoLib/IO/XmlIO/Qt/XmlGmlInterface.h" #include "GeoLib/Polyline.h" - -#include <QCoreApplication> +#include "InfoLib/GitInfo.h" std::string output_question() { - WARN ("Given polyline is not closed. Close polyline now?"); - WARN ("Enter (Y)es for closing the line or (N)o for abort and press ENTER."); + WARN("Given polyline is not closed. Close polyline now?"); + WARN("Enter (Y)es for closing the line or (N)o for abort and press ENTER."); std::string input; std::cin >> input; return input; } -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { QCoreApplication app(argc, argv, false); @@ -47,17 +44,20 @@ int main(int argc, char *argv[]) "Copyright (c) 2012-2021, OpenGeoSys Community " "(http://www.opengeosys.org)", ' ', GitInfoLib::GitInfo::ogs_version); - TCLAP::ValueArg<std::string> input_arg("i", "input", "GML input file (*.gml)", true, "", "string"); - TCLAP::ValueArg<std::string> output_arg("o", "output", "GML output file (*.gml)", true, "", "string"); - TCLAP::ValueArg<std::string> name_arg("n", "name", "Name of polyline in given file", true, "", "string"); + TCLAP::ValueArg<std::string> input_arg( + "i", "input", "GML input file (*.gml)", true, "", "string"); + TCLAP::ValueArg<std::string> output_arg( + "o", "output", "GML output file (*.gml)", true, "", "string"); + TCLAP::ValueArg<std::string> name_arg( + "n", "name", "Name of polyline in given file", true, "", "string"); TCLAP::ValueArg<std::string> gmsh_path_arg("g", "gmsh-path", "the path to the gmsh binary", false, "", "path as string"); - cmd.add( input_arg ); - cmd.add( name_arg ); - cmd.add( output_arg ); + cmd.add(input_arg); + cmd.add(name_arg); + cmd.add(output_arg); cmd.add(gmsh_path_arg); - cmd.parse( argc, argv ); + cmd.parse(argc, argv); std::string const& file_name(input_arg.getValue()); std::string const& polyline_name(name_arg.getValue()); @@ -95,7 +95,8 @@ int main(int argc, char *argv[]) // check if polyline can be triangulated (i.e. closed + coplanar) if (!line->isCoplanar()) { - ERR ("Polyline is not coplanar, no unambiguous triangulation possible. Aborting..."); + ERR("Polyline is not coplanar, no unambiguous triangulation possible. " + "Aborting..."); return EXIT_FAILURE; } @@ -110,7 +111,7 @@ int main(int argc, char *argv[]) if (input == "y" || input == "Y") { line->closePolyline(); - INFO ("Polyline closed."); + INFO("Polyline closed."); } else { @@ -118,7 +119,7 @@ int main(int argc, char *argv[]) } } - INFO ("Creating a surface by triangulation of the polyline ..."); + INFO("Creating a surface by triangulation of the polyline ..."); if (FileIO::createSurface(*line, geo_objects, geo_name, gmsh_path_arg.getValue())) { @@ -132,10 +133,11 @@ int main(int argc, char *argv[]) } 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) + std::string const surface_name(polyline_name + "_surface"); + for (std::size_t i = 1;; ++i) { - std::string const new_surface_name = (i>1) ? (surface_name + std::to_string(i)) : surface_name; + std::string const new_surface_name = + (i > 1) ? (surface_name + std::to_string(i)) : surface_name; if (sfc_vec->getElementByName(new_surface_name) == nullptr) { sfc_vec->setNameForElement(sfc_id, new_surface_name); @@ -146,7 +148,7 @@ int main(int argc, char *argv[]) // write new file xml.export_name = geo_name; BaseLib::IO::writeStringToFile(xml.writeToString(), output_arg.getValue()); - INFO ("...done."); + INFO("...done."); return EXIT_SUCCESS; } diff --git a/Applications/Utils/MeshEdit/AddElementQuality.cpp b/Applications/Utils/MeshEdit/AddElementQuality.cpp index 5829ed63150e494c0d0fe6f0cee13f192a957540..20f4c54fce0c9662e6f2cabc8c356cb9a3b9fe6c 100644 --- a/Applications/Utils/MeshEdit/AddElementQuality.cpp +++ b/Applications/Utils/MeshEdit/AddElementQuality.cpp @@ -20,7 +20,7 @@ #include "MeshLib/MeshEnums.h" #include "MeshLib/MeshQuality/ElementQualityInterface.h" -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { TCLAP::CmdLine cmd( "Add element quality as a mesh property.\n\n" diff --git a/Applications/Utils/MeshEdit/AddFaultToVoxelGrid.cpp b/Applications/Utils/MeshEdit/AddFaultToVoxelGrid.cpp index 7b560f6b9cb9b17eb3bcdb77f075783ec81cc4d9..17c94f70dc91e0065b3c6eb583a3cce3748bcc57 100644 --- a/Applications/Utils/MeshEdit/AddFaultToVoxelGrid.cpp +++ b/Applications/Utils/MeshEdit/AddFaultToVoxelGrid.cpp @@ -33,7 +33,6 @@ bool testAABBIntersectingPlane(Eigen::Vector3d const& aabb_centre, Eigen::Vector3d const& plane_normal, double const pd) { - double const r = aabb_extent.dot(plane_normal.cwiseAbs()); double const s = plane_normal.dot(aabb_centre) - pd; return std::abs(s) > r; @@ -205,9 +204,9 @@ int main(int argc, char* argv[]) "Copyright (c) 2012-2021, OpenGeoSys Community " "(http://www.opengeosys.org)", ' ', GitInfoLib::GitInfo::ogs_version); - TCLAP::ValueArg<int> id_arg( - "m", "material", "material id for cells intersected by fault", false, - mat_not_set, "non-negative integer"); + TCLAP::ValueArg<int> id_arg("m", "material", + "material id for cells intersected by fault", + false, mat_not_set, "non-negative integer"); cmd.add(id_arg); TCLAP::ValueArg<std::string> output_arg( diff --git a/Applications/Utils/MeshEdit/AddLayer.cpp b/Applications/Utils/MeshEdit/AddLayer.cpp index e5d01b42933e8d9fbe38aa7c9dccb23ccea909cc..eb1850cabbdfbb5ebf971ea50483320551484f70 100644 --- a/Applications/Utils/MeshEdit/AddLayer.cpp +++ b/Applications/Utils/MeshEdit/AddLayer.cpp @@ -9,18 +9,18 @@ * http://www.opengeosys.org/project/license */ -#include <memory> - #include <tclap/CmdLine.h> -#include "InfoLib/GitInfo.h" +#include <memory> + #include "BaseLib/FileTools.h" +#include "InfoLib/GitInfo.h" #include "MeshLib/IO/readMeshFromFile.h" #include "MeshLib/IO/writeMeshToFile.h" #include "MeshLib/Mesh.h" #include "MeshLib/MeshEditing/AddLayerToMesh.h" -int main (int argc, char* argv[]) +int main(int argc, char* argv[]) { TCLAP::CmdLine cmd( "Adds a layer to an existing mesh." @@ -32,18 +32,20 @@ int main (int argc, char* argv[]) "Copyright (c) 2012-2021, OpenGeoSys Community " "(http://www.opengeosys.org)", ' ', GitInfoLib::GitInfo::ogs_version); - TCLAP::ValueArg<std::string> mesh_arg("i", "input-mesh-file", - "the name of the file containing the mesh", true, - "", "file name"); + TCLAP::ValueArg<std::string> mesh_arg( + "i", "input-mesh-file", "the name of the file containing the mesh", + true, "", "file name"); cmd.add(mesh_arg); - TCLAP::ValueArg<std::string> mesh_out_arg("o", "output-mesh-file", + TCLAP::ValueArg<std::string> mesh_out_arg( + "o", "output-mesh-file", "the name of the file the mesh should be written to (vtu format)", true, "", "file name"); cmd.add(mesh_out_arg); - TCLAP::ValueArg<double> layer_thickness_arg("t", "layer-tickness", - "the thickness of the new layer", false, 10, "floating point value"); + TCLAP::ValueArg<double> layer_thickness_arg( + "t", "layer-tickness", "the thickness of the new layer", false, 10, + "floating point value"); cmd.add(layer_thickness_arg); TCLAP::SwitchArg layer_position_arg( @@ -66,7 +68,8 @@ int main (int argc, char* argv[]) INFO("Reading mesh '{:s}' ... ", mesh_arg.getValue()); auto subsfc_mesh = std::unique_ptr<MeshLib::Mesh>( MeshLib::IO::readMeshFromFile(mesh_arg.getValue())); - if (!subsfc_mesh) { + if (!subsfc_mesh) + { ERR("Error reading mesh '{:s}'.", mesh_arg.getValue()); return EXIT_FAILURE; } diff --git a/Applications/Utils/MeshEdit/CreateBoundaryConditionsAlongPolylines.cpp b/Applications/Utils/MeshEdit/CreateBoundaryConditionsAlongPolylines.cpp index ed3682d203fa307db77e6d2ac084b3288d090a9c..b28ad4d93ca858379c144e071950278e02558bf4 100644 --- a/Applications/Utils/MeshEdit/CreateBoundaryConditionsAlongPolylines.cpp +++ b/Applications/Utils/MeshEdit/CreateBoundaryConditionsAlongPolylines.cpp @@ -9,44 +9,40 @@ * http://www.opengeosys.org/project/license */ +#include <tclap/CmdLine.h> + +#include <fstream> #include <map> #include <string> #include <vector> -#include <fstream> - -#include <tclap/CmdLine.h> #include "Applications/FileIO/readGeometryFromFile.h" #include "Applications/FileIO/writeGeometryToFile.h" - -#include "InfoLib/GitInfo.h" #include "BaseLib/FileTools.h" - -#include "MeshLib/IO/readMeshFromFile.h" -#include "MeshLib/IO/writeMeshToFile.h" - #include "GeoLib/GEOObjects.h" #include "GeoLib/Point.h" - +#include "InfoLib/GitInfo.h" +#include "MeshGeoToolsLib/MeshNodeSearcher.h" +#include "MeshLib/IO/readMeshFromFile.h" +#include "MeshLib/IO/writeMeshToFile.h" #include "MeshLib/Mesh.h" -#include "MeshLib/Node.h" #include "MeshLib/MeshSurfaceExtraction.h" - -#include "MeshGeoToolsLib/MeshNodeSearcher.h" +#include "MeshLib/Node.h" void convertMeshNodesToGeometry(std::vector<MeshLib::Node*> const& nodes, - std::vector<std::size_t> const& node_ids, - std::string & geo_name, - GeoLib::GEOObjects & geometry_sets) + std::vector<std::size_t> const& node_ids, + std::string& geo_name, + GeoLib::GEOObjects& geometry_sets) { // copy data auto pnts = std::make_unique<std::vector<GeoLib::Point*>>(); auto pnt_names = std::make_unique<std::map<std::string, std::size_t>>(); std::size_t cnt(0); - for (std::size_t id: node_ids) { + for (std::size_t id : node_ids) + { pnts->push_back(new GeoLib::Point(*(nodes[id]), cnt)); pnt_names->insert(std::pair<std::string, std::size_t>( - geo_name+"-PNT-"+std::to_string(cnt), cnt)); + geo_name + "-PNT-" + std::to_string(cnt), cnt)); cnt++; } @@ -68,7 +64,7 @@ void writeGroundwaterFlowPointBC(std::ostream& bc_out, bc_out << " CONSTANT " << head_value << "\n"; } -void writeLiquidFlowPointBC(std::ostream & bc_out, std::string const& pnt_name) +void writeLiquidFlowPointBC(std::ostream& bc_out, std::string const& pnt_name) { bc_out << "#BOUNDARY_CONDITION\n"; bc_out << " $PCS_TYPE\n"; @@ -85,14 +81,17 @@ void writeLiquidFlowPointBC(std::ostream & bc_out, std::string const& pnt_name) // set on, geo_name is the name the geometry can be accessed with, out_fname is // the base file name the gli and bc as well as the gml file will be written to. void writeBCsAndGeometry(GeoLib::GEOObjects& geometry_sets, - std::string const& geo_name, std::string const& out_fname, + std::string const& geo_name, + std::string const& out_fname, std::string const& bc_type, bool const write_gml) { - if (write_gml) { + if (write_gml) + { INFO("write points to '{:s}.gml'.", geo_name); - FileIO::writeGeometryToFile(geo_name, geometry_sets, out_fname+".gml"); + FileIO::writeGeometryToFile(geo_name, geometry_sets, + out_fname + ".gml"); } - FileIO::writeGeometryToFile(geo_name, geometry_sets, out_fname+".gli"); + FileIO::writeGeometryToFile(geo_name, geometry_sets, out_fname + ".gli"); bool liquid_flow(false); if (bc_type == "LIQUID_FLOW") @@ -100,12 +99,15 @@ void writeBCsAndGeometry(GeoLib::GEOObjects& geometry_sets, liquid_flow = true; } - GeoLib::PointVec const* pnt_vec_objs(geometry_sets.getPointVecObj(geo_name)); + GeoLib::PointVec const* pnt_vec_objs( + geometry_sets.getPointVecObj(geo_name)); std::vector<GeoLib::Point*> const& pnts(*(pnt_vec_objs->getVector())); - std::ofstream bc_out (out_fname+".bc"); - for (std::size_t k(0); k<pnts.size(); k++) { + std::ofstream bc_out(out_fname + ".bc"); + for (std::size_t k(0); k < pnts.size(); k++) + { std::string const& pnt_name(pnt_vec_objs->getItemNameByID(k)); - if (!pnt_name.empty()) { + if (!pnt_name.empty()) + { if (liquid_flow) { writeLiquidFlowPointBC(bc_out, pnt_name); @@ -120,7 +122,7 @@ void writeBCsAndGeometry(GeoLib::GEOObjects& geometry_sets, bc_out.close(); } -int main (int argc, char* argv[]) +int main(int argc, char* argv[]) { TCLAP::CmdLine cmd( "Creates boundary conditions for mesh nodes along polylines." @@ -136,34 +138,38 @@ int main (int argc, char* argv[]) TCLAP::SwitchArg gml_arg("", "gml", "Write found nodes to gml file."); cmd.add(gml_arg); - TCLAP::ValueArg<std::string> output_base_fname("o", "output-base-file-name", - "the base name of the file the output (geometry (gli) and boundary"\ - "condition (bc)) will be written to", true, - "", "file name"); + TCLAP::ValueArg<std::string> output_base_fname( + "o", "output-base-file-name", + "the base name of the file the output (geometry (gli) and boundary" + "condition (bc)) will be written to", + true, "", "file name"); cmd.add(output_base_fname); - TCLAP::ValueArg<std::string> bc_type("t", "type", - "the process type the boundary condition will be written for "\ - "currently LIQUID_FLOW (primary variable PRESSURE1) and "\ - "GROUNDWATER_FLOW (primary variable HEAD, default) are supported", true, - "", + TCLAP::ValueArg<std::string> bc_type( + "t", "type", + "the process type the boundary condition will be written for " + "currently LIQUID_FLOW (primary variable PRESSURE1) and " + "GROUNDWATER_FLOW (primary variable HEAD, default) are supported", + true, "", "process type as string (LIQUID_FLOW or GROUNDWATER_FLOW (default))"); cmd.add(bc_type); - TCLAP::ValueArg<double> search_length_arg("s", "search-length", + TCLAP::ValueArg<double> search_length_arg( + "s", "search-length", "The size of the search length. The default value is " - "std::numeric_limits<double>::epsilon()", false, - std::numeric_limits<double>::epsilon(), "floating point number"); + "std::numeric_limits<double>::epsilon()", + false, std::numeric_limits<double>::epsilon(), "floating point number"); cmd.add(search_length_arg); - TCLAP::ValueArg<std::string> geometry_fname("i", "input-geometry", - "the name of the file containing the input geometry", true, - "", "file name"); + TCLAP::ValueArg<std::string> geometry_fname( + "i", "input-geometry", + "the name of the file containing the input geometry", true, "", + "file name"); cmd.add(geometry_fname); - TCLAP::ValueArg<std::string> mesh_arg("m", "mesh-file", - "the name of the file containing the mesh", true, - "", "file name"); + TCLAP::ValueArg<std::string> mesh_arg( + "m", "mesh-file", "the name of the file containing the mesh", true, "", + "file name"); cmd.add(mesh_arg); TCLAP::ValueArg<std::string> gmsh_path_arg("g", "gmsh-path", @@ -196,8 +202,10 @@ int main (int argc, char* argv[]) // *** check if the data is usable // *** get vector of polylines - std::vector<GeoLib::Polyline*> const* plys(geometries.getPolylineVec(geo_name)); - if (!plys) { + std::vector<GeoLib::Polyline*> const* plys( + geometries.getPolylineVec(geo_name)); + if (!plys) + { ERR("Could not get vector of polylines out of geometry '{:s}'.", geo_name); return EXIT_FAILURE; @@ -205,7 +213,8 @@ int main (int argc, char* argv[]) auto search_length_strategy = std::make_unique<MeshGeoToolsLib::SearchLength>(); - if (search_length_arg.isSet()) { + if (search_length_arg.isSet()) + { search_length_strategy.reset( new MeshGeoToolsLib::SearchLength(search_length_arg.getValue())); } @@ -228,7 +237,8 @@ int main (int argc, char* argv[]) // merge all together auto const geo_names = geometry_sets.getGeometryNames(); - if (geo_names.empty()) { + if (geo_names.empty()) + { ERR("Did not find mesh nodes along polylines."); return EXIT_FAILURE; } @@ -244,16 +254,17 @@ int main (int argc, char* argv[]) std::vector<GeoLib::Point> pnts_with_id; const std::size_t n_merged_pnts(merged_pnts->size()); - for(std::size_t k(0); k<n_merged_pnts; ++k) { + for (std::size_t k(0); k < n_merged_pnts; ++k) + { pnts_with_id.emplace_back(*((*merged_pnts)[k]), k); } std::sort(pnts_with_id.begin(), pnts_with_id.end(), - [](GeoLib::Point const& p0, GeoLib::Point const& p1) - { return p0 < p1; } - ); + [](GeoLib::Point const& p0, GeoLib::Point const& p1) { + return p0 < p1; + }); - double const eps (std::numeric_limits<double>::epsilon()); + double const eps(std::numeric_limits<double>::epsilon()); auto surface_pnts = std::make_unique<std::vector<GeoLib::Point*>>(); auto name_id_map = std::make_unique<std::map<std::string, std::size_t>>(); @@ -266,22 +277,23 @@ int main (int argc, char* argv[]) name_id_map->insert( std::pair<std::string, std::size_t>(element_name, 0)); } - for (std::size_t k(1); k < n_merged_pnts; ++k) { - const GeoLib::Point& p0 (pnts_with_id[k-1]); - const GeoLib::Point& p1 (pnts_with_id[k]); - if (std::abs (p0[0] - p1[0]) > eps || std::abs (p0[1] - p1[1]) > eps) { - surface_pnts->push_back(new GeoLib::Point(pnts_with_id[k], - surface_pnts->size())); + for (std::size_t k(1); k < n_merged_pnts; ++k) + { + const GeoLib::Point& p0(pnts_with_id[k - 1]); + const GeoLib::Point& p1(pnts_with_id[k]); + if (std::abs(p0[0] - p1[0]) > eps || std::abs(p0[1] - p1[1]) > eps) + { + surface_pnts->push_back( + new GeoLib::Point(pnts_with_id[k], surface_pnts->size())); std::string element_name; pnt_vec->getNameOfElementByID(k, element_name); - name_id_map->insert( - std::pair<std::string, std::size_t>(element_name, - surface_pnts->size()-1) - ); + name_id_map->insert(std::pair<std::string, std::size_t>( + element_name, surface_pnts->size() - 1)); } } - std::string surface_name(BaseLib::dropFileExtension(mesh_arg.getValue())+"-MeshNodesAlongPolylines"); + std::string surface_name(BaseLib::dropFileExtension(mesh_arg.getValue()) + + "-MeshNodesAlongPolylines"); geometry_sets.addPointVec(std::move(surface_pnts), surface_name, std::move(name_id_map), 1e-6); diff --git a/Applications/Utils/MeshEdit/ExtractBoundary.cpp b/Applications/Utils/MeshEdit/ExtractBoundary.cpp index 2941ce4849184ba0a71d0e97d9206e7d85a66e4d..751bd23f9e0bc3a08ef6719c872508e403ef1d0a 100644 --- a/Applications/Utils/MeshEdit/ExtractBoundary.cpp +++ b/Applications/Utils/MeshEdit/ExtractBoundary.cpp @@ -27,7 +27,7 @@ #include "MeshLib/MeshSurfaceExtraction.h" #include "MeshLib/Node.h" -int main (int argc, char* argv[]) +int main(int argc, char* argv[]) { TCLAP::CmdLine cmd( "Tool extracts the boundary of the given mesh. The documentation is " diff --git a/Applications/Utils/MeshEdit/ExtractMaterials.cpp b/Applications/Utils/MeshEdit/ExtractMaterials.cpp index 4684c809235790761b94fa639c03a77b7936db2f..4afe7d90c40b30842f84b556f689713ef74bbb63 100644 --- a/Applications/Utils/MeshEdit/ExtractMaterials.cpp +++ b/Applications/Utils/MeshEdit/ExtractMaterials.cpp @@ -12,12 +12,11 @@ // ThirdParty #include <tclap/CmdLine.h> -#include "InfoLib/GitInfo.h" - #include "BaseLib/FileTools.h" -#include "MeshLib/Mesh.h" -#include "MeshLib/IO/readMeshFromFile.h" +#include "InfoLib/GitInfo.h" #include "MeshLib/IO/VtkIO/VtuInterface.h" +#include "MeshLib/IO/readMeshFromFile.h" +#include "MeshLib/Mesh.h" #include "MeshLib/MeshEditing/RemoveMeshComponents.h" MeshLib::Mesh* extractMatGroup(MeshLib::Mesh const& mesh, int const mat_id) @@ -42,7 +41,6 @@ MeshLib::Mesh* extractMatGroup(MeshLib::Mesh const& mesh, int const mat_id) return MeshLib::removeElements(mesh, elem_list, "matgroup"); } - int main(int argc, char* argv[]) { TCLAP::CmdLine cmd( @@ -61,24 +59,23 @@ int main(int argc, char* argv[]) "mesh.", false, 0, "Number specifying the MaterialID"); cmd.add(arg_mat_id); - TCLAP::ValueArg<std::string> output_arg( - "o", "output", - "Name of the output mesh (*.vtu)", - true, "", "output file name"); + TCLAP::ValueArg<std::string> output_arg("o", "output", + "Name of the output mesh (*.vtu)", + true, "", "output file name"); cmd.add(output_arg); - TCLAP::ValueArg<std::string> input_arg( - "i", "input", - "Name of the input mesh (*.vtu)", - true, "", "input file name"); + TCLAP::ValueArg<std::string> input_arg("i", "input", + "Name of the input mesh (*.vtu)", + true, "", "input file name"); cmd.add(input_arg); - cmd.parse( argc, argv ); + cmd.parse(argc, argv); std::string const input_name = input_arg.getValue(); std::string const output_name = output_arg.getValue(); std::string const base_name = BaseLib::dropFileExtension(output_name); std::string const ext = BaseLib::getFileExtension(output_name); - std::unique_ptr<MeshLib::Mesh> const mesh (MeshLib::IO::readMeshFromFile(input_name)); + std::unique_ptr<MeshLib::Mesh> const mesh( + MeshLib::IO::readMeshFromFile(input_name)); if (mesh == nullptr) { ERR("Error reading input mesh. Aborting..."); @@ -124,14 +121,15 @@ int main(int argc, char* argv[]) for (int i = min_id; i <= max_id; ++i) { INFO("Extracting material group {:d}...", i); - std::unique_ptr<MeshLib::Mesh> mat_group (extractMatGroup(*mesh, i)); + std::unique_ptr<MeshLib::Mesh> mat_group(extractMatGroup(*mesh, i)); if (mat_group == nullptr) { WARN("No elements with material group {:d} found.", i); continue; } MeshLib::IO::VtuInterface vtu(mat_group.get()); - std::string const file_name(base_name + "_Layer" + std::to_string(i) + ext); + std::string const file_name(base_name + "_Layer" + std::to_string(i) + + ext); vtu.writeToFile(file_name); if (ostream.is_open()) { diff --git a/Applications/Utils/MeshEdit/ExtractSurface.cpp b/Applications/Utils/MeshEdit/ExtractSurface.cpp index 75ea332ce2119beb1c306af661fb2e448ebf631d..eea4e30c038a135cd2169e2e96b14dbba8416e5e 100644 --- a/Applications/Utils/MeshEdit/ExtractSurface.cpp +++ b/Applications/Utils/MeshEdit/ExtractSurface.cpp @@ -9,32 +9,31 @@ * http://www.opengeosys.org/project/license */ +#include <tclap/CmdLine.h> + #include <algorithm> #include <memory> #include <string> #include <vector> -#include <tclap/CmdLine.h> - -#include "InfoLib/GitInfo.h" #include "BaseLib/FileTools.h" #include "BaseLib/StringTools.h" - +#include "InfoLib/GitInfo.h" +#include "MeshLib/IO/VtkIO/VtuInterface.h" #include "MeshLib/IO/readMeshFromFile.h" #include "MeshLib/IO/writeMeshToFile.h" -#include "MeshLib/IO/VtkIO/VtuInterface.h" - #include "MeshLib/Mesh.h" #include "MeshLib/MeshSurfaceExtraction.h" -int main (int argc, char* argv[]) +int main(int argc, char* argv[]) { TCLAP::CmdLine cmd( "Extracts a 2D surface from a 3D input mesh by specifying a normal " "vector and an angle. (The surface normal (0, 0, 0) will extract the " "complete outer boundary of the 3D mesh.)\n" "An extensive documentation can be found at " - "https://docs.opengeosys.org/docs/tools/meshing-submeshes/extract-surface\n" + "https://docs.opengeosys.org/docs/tools/meshing-submeshes/" + "extract-surface\n" "OpenGeoSys-6 software, version " + GitInfoLib::GitInfo::ogs_version + ".\n" diff --git a/Applications/Utils/MeshEdit/Layers2Grid.cpp b/Applications/Utils/MeshEdit/Layers2Grid.cpp index a758e8a0a63937c14d6d403861e8a15faf57475e..12f6b6252592ec6c4681831579af2ad7678409ea 100644 --- a/Applications/Utils/MeshEdit/Layers2Grid.cpp +++ b/Applications/Utils/MeshEdit/Layers2Grid.cpp @@ -51,8 +51,8 @@ std::unique_ptr<MeshLib::Mesh> generateInitialMesh( { INFO("Creating initial mesh..."); std::array<double, 3> mesh_range{{extent.second[0] - extent.first[0], - extent.second[1] - extent.first[1], - extent.second[2] - extent.first[2]}}; + extent.second[1] - extent.first[1], + extent.second[2] - extent.first[2]}}; std::array<std::size_t, 3> const n_cells{ {static_cast<std::size_t>(std::ceil(mesh_range[0] / res[0])), static_cast<std::size_t>(std::ceil(mesh_range[1] / res[1])), diff --git a/Applications/Utils/MeshEdit/MapGeometryToMeshSurface.cpp b/Applications/Utils/MeshEdit/MapGeometryToMeshSurface.cpp index 0047666847f4bb67228368a16f051d72a3a9814a..6a3dc18ee2ac7b48fc7bbcb3b447ca7114de21ca 100644 --- a/Applications/Utils/MeshEdit/MapGeometryToMeshSurface.cpp +++ b/Applications/Utils/MeshEdit/MapGeometryToMeshSurface.cpp @@ -8,20 +8,20 @@ * See accompanying file LICENSE.txt or */ +#include <tclap/CmdLine.h> + #include <algorithm> #include <cstdlib> #include <vector> -#include <tclap/CmdLine.h> - -#include "InfoLib/GitInfo.h" #include "GeoLib/GEOObjects.h" #include "GeoLib/IO/XmlIO/Boost/BoostXmlGmlInterface.h" +#include "InfoLib/GitInfo.h" #include "MeshGeoToolsLib/GeoMapper.h" #include "MeshLib/IO/readMeshFromFile.h" #include "MeshLib/Mesh.h" -int main (int argc, char* argv[]) +int main(int argc, char* argv[]) { TCLAP::CmdLine cmd( "Maps geometric objects to the surface of a given mesh." @@ -34,22 +34,24 @@ int main (int argc, char* argv[]) "Copyright (c) 2012-2021, OpenGeoSys Community " "(http://www.opengeosys.org)", ' ', GitInfoLib::GitInfo::ogs_version); - TCLAP::ValueArg<std::string> mesh_in("m", "mesh-file", - "the name of the file containing the mesh", true, - "", "file name"); + TCLAP::ValueArg<std::string> mesh_in( + "m", "mesh-file", "the name of the file containing the mesh", true, "", + "file name"); cmd.add(mesh_in); - TCLAP::ValueArg<std::string> input_geometry_fname("i", "input-geometry", - "the name of the file containing the input geometry", true, - "", "file name"); + TCLAP::ValueArg<std::string> input_geometry_fname( + "i", "input-geometry", + "the name of the file containing the input geometry", true, "", + "file name"); cmd.add(input_geometry_fname); TCLAP::SwitchArg additional_insert_mapping( "a", "additional-insert-mapping", "Advanced mapping algorithm will be applied, i.e. a new geometry will " "be created and possibly new points will be inserted."); cmd.add(additional_insert_mapping); - TCLAP::ValueArg<std::string> output_geometry_fname("o", "output-geometry", - "the name of the file containing the input geometry", true, - "", "file name"); + TCLAP::ValueArg<std::string> output_geometry_fname( + "o", "output-geometry", + "the name of the file containing the input geometry", true, "", + "file name"); cmd.add(output_geometry_fname); cmd.parse(argc, argv); @@ -57,10 +59,13 @@ int main (int argc, char* argv[]) GeoLib::GEOObjects geometries; { GeoLib::IO::BoostXmlGmlInterface xml_io(geometries); - if (xml_io.readFile(input_geometry_fname.getValue())) { + if (xml_io.readFile(input_geometry_fname.getValue())) + { INFO("Read geometry from file '{:s}'.", input_geometry_fname.getValue()); - } else { + } + else + { return EXIT_FAILURE; } } @@ -73,9 +78,12 @@ int main (int argc, char* argv[]) std::unique_ptr<MeshLib::Mesh> mesh( MeshLib::IO::readMeshFromFile(mesh_in.getValue())); - if (additional_insert_mapping.getValue()) { + if (additional_insert_mapping.getValue()) + { geo_mapper.advancedMapOnMesh(*mesh); - } else { + } + else + { geo_mapper.mapOnMesh(mesh.get()); } diff --git a/Applications/Utils/MeshEdit/MoveMesh.cpp b/Applications/Utils/MeshEdit/MoveMesh.cpp index 3fb7b9744c17d153717ef288f4476e6332393172..b5addf760da0fe930689397ac40f3624e662b136 100644 --- a/Applications/Utils/MeshEdit/MoveMesh.cpp +++ b/Applications/Utils/MeshEdit/MoveMesh.cpp @@ -12,10 +12,10 @@ #include <tclap/CmdLine.h> -#include "InfoLib/GitInfo.h" #include "BaseLib/FileTools.h" #include "BaseLib/StringTools.h" #include "GeoLib/AABB.h" +#include "InfoLib/GitInfo.h" #include "MeshLib/Elements/Element.h" #include "MeshLib/IO/readMeshFromFile.h" #include "MeshLib/IO/writeMeshToFile.h" @@ -23,7 +23,7 @@ #include "MeshLib/MeshEditing/moveMeshNodes.h" #include "MeshLib/Node.h" -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { TCLAP::CmdLine cmd( "Moves the mesh nodes using the given displacement vector or if no " @@ -38,42 +38,54 @@ int main(int argc, char *argv[]) // Define a value argument and add it to the command line. // A value arg defines a flag and a type of value that it expects, // such as "-m meshfile". - TCLAP::ValueArg<std::string> mesh_arg("m","mesh","input mesh file",true,"","string"); + TCLAP::ValueArg<std::string> mesh_arg("m", "mesh", "input mesh file", true, + "", "string"); // Add the argument mesh_arg to the CmdLine object. The CmdLine object // uses this Arg to parse the command line. - cmd.add( mesh_arg ); + cmd.add(mesh_arg); - TCLAP::ValueArg<double> x_arg("x","x","displacement in x direction", false, 0.0,"floating point number"); + TCLAP::ValueArg<double> x_arg("x", "x", "displacement in x direction", + false, 0.0, "floating point number"); cmd.add(x_arg); - TCLAP::ValueArg<double> y_arg("y","y","displacement in y direction", false, 0.0,"floating point number"); + TCLAP::ValueArg<double> y_arg("y", "y", "displacement in y direction", + false, 0.0, "floating point number"); cmd.add(y_arg); - TCLAP::ValueArg<double> z_arg("z","z","displacement in z direction", false, 0.0,"floating point number"); + TCLAP::ValueArg<double> z_arg("z", "z", "displacement in z direction", + false, 0.0, "floating point number"); cmd.add(z_arg); - TCLAP::ValueArg<std::string> mesh_out_arg("o","output-mesh","output mesh file", false, "", "string"); + TCLAP::ValueArg<std::string> mesh_out_arg( + "o", "output-mesh", "output mesh file", false, "", "string"); cmd.add(mesh_out_arg); - cmd.parse( argc, argv ); + cmd.parse(argc, argv); - std::string fname (mesh_arg.getValue()); + std::string fname(mesh_arg.getValue()); std::unique_ptr<MeshLib::Mesh> mesh(MeshLib::IO::readMeshFromFile(fname)); - if (!mesh) { + if (!mesh) + { ERR("Could not read mesh from file '{:s}'.", fname); return EXIT_FAILURE; } MeshLib::Node displacement(0.0, 0.0, 0.0); - if (fabs(x_arg.getValue()) < std::numeric_limits<double>::epsilon() - && fabs(y_arg.getValue()) < std::numeric_limits<double>::epsilon() - && fabs(z_arg.getValue()) < std::numeric_limits<double>::epsilon()) { + if (fabs(x_arg.getValue()) < std::numeric_limits<double>::epsilon() && + fabs(y_arg.getValue()) < std::numeric_limits<double>::epsilon() && + fabs(z_arg.getValue()) < std::numeric_limits<double>::epsilon()) + { GeoLib::AABB aabb(mesh->getNodes().begin(), mesh->getNodes().end()); - displacement[0] = -(aabb.getMaxPoint()[0] + aabb.getMinPoint()[0])/2.0; - displacement[1] = -(aabb.getMaxPoint()[1] + aabb.getMinPoint()[1])/2.0; - displacement[2] = -(aabb.getMaxPoint()[2] + aabb.getMinPoint()[2])/2.0; - } else { + displacement[0] = + -(aabb.getMaxPoint()[0] + aabb.getMinPoint()[0]) / 2.0; + displacement[1] = + -(aabb.getMaxPoint()[1] + aabb.getMinPoint()[1]) / 2.0; + displacement[2] = + -(aabb.getMaxPoint()[2] + aabb.getMinPoint()[2]) / 2.0; + } + else + { displacement[0] = x_arg.getValue(); displacement[1] = y_arg.getValue(); displacement[2] = z_arg.getValue(); @@ -83,11 +95,12 @@ int main(int argc, char *argv[]) displacement[0], displacement[1], displacement[2]); - MeshLib::moveMeshNodes( - mesh->getNodes().begin(), mesh->getNodes().end(), displacement); + MeshLib::moveMeshNodes(mesh->getNodes().begin(), mesh->getNodes().end(), + displacement); std::string out_fname(mesh_out_arg.getValue()); - if (out_fname.empty()) { + if (out_fname.empty()) + { out_fname = BaseLib::dropFileExtension(mesh_out_arg.getValue()); out_fname += "_displaced.vtu"; } diff --git a/Applications/Utils/MeshEdit/NodeReordering.cpp b/Applications/Utils/MeshEdit/NodeReordering.cpp index faa7a1aad1bbee06e90ce0a03d9775ee55dc0de5..9f0bf783d0c7b8359129bc89237f12dc276926a4 100644 --- a/Applications/Utils/MeshEdit/NodeReordering.cpp +++ b/Applications/Utils/MeshEdit/NodeReordering.cpp @@ -9,13 +9,13 @@ * http://www.opengeosys.org/project/license */ -#include <array> +#include <tclap/CmdLine.h> + #include <algorithm> +#include <array> #include <memory> #include <vector> -#include <tclap/CmdLine.h> - #include "BaseLib/Algorithm.h" #include "InfoLib/GitInfo.h" #include "MeshLib/Elements/Element.h" @@ -24,7 +24,8 @@ #include "MeshLib/Mesh.h" #include "MeshLib/Node.h" -/// Re-ordering mesh elements to correct Data Explorer 5 meshes to work with Data Explorer 6. +/// Re-ordering mesh elements to correct Data Explorer 5 meshes to work with +/// Data Explorer 6. void reorderNodes(std::vector<MeshLib::Element*>& elements) { std::size_t n_corrected_elements = 0; @@ -80,7 +81,8 @@ void reorderNodes(std::vector<MeshLib::Element*>& elements) INFO("Corrected {:d} elements.", n_corrected_elements); } -/// Re-ordering prism elements to correct OGS6 meshes with and without InSitu-Lib +/// Re-ordering prism elements to correct OGS6 meshes with and without +/// InSitu-Lib void reorderNodes2(std::vector<MeshLib::Element*>& elements) { std::size_t const nElements(elements.size()); @@ -105,7 +107,7 @@ void reorderNodes2(std::vector<MeshLib::Element*>& elements) } } -void reorderNonlinearNodes(MeshLib::Mesh &mesh) +void reorderNonlinearNodes(MeshLib::Mesh& mesh) { std::vector<MeshLib::Node*> base_nodes; std::vector<MeshLib::Node*> nonlinear_nodes; @@ -137,12 +139,13 @@ void reorderNonlinearNodes(MeshLib::Mesh &mesh) allnodes.clear(); allnodes.insert(allnodes.end(), base_nodes.begin(), base_nodes.end()); - allnodes.insert(allnodes.end(), nonlinear_nodes.begin(), nonlinear_nodes.end()); + allnodes.insert(allnodes.end(), nonlinear_nodes.begin(), + nonlinear_nodes.end()); mesh.resetNodeIDs(); } -int main (int argc, char* argv[]) +int main(int argc, char* argv[]) { TCLAP::CmdLine cmd( "Reorders mesh nodes in elements to make old or incorrectly ordered " @@ -188,11 +191,13 @@ 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())); + reorderNodes( + const_cast<std::vector<MeshLib::Element*>&>(mesh->getElements())); } else if (method_arg.getValue() == 2) { - reorderNodes2(const_cast<std::vector<MeshLib::Element*>&>(mesh->getElements())); + reorderNodes2( + const_cast<std::vector<MeshLib::Element*>&>(mesh->getElements())); } else if (method_arg.getValue() == 3) { @@ -205,6 +210,3 @@ int main (int argc, char* argv[]) return EXIT_SUCCESS; } - - - diff --git a/Applications/Utils/MeshEdit/RemoveGhostData.cpp b/Applications/Utils/MeshEdit/RemoveGhostData.cpp index 6e0223a7dcfb339b30cf953e7241b9de425d3d3b..b6afaed49dfef224eb63104c5bbc691b3486f9e1 100644 --- a/Applications/Utils/MeshEdit/RemoveGhostData.cpp +++ b/Applications/Utils/MeshEdit/RemoveGhostData.cpp @@ -18,25 +18,25 @@ #include "InfoLib/GitInfo.h" #include "MeshLib/IO/writeMeshToFile.h" -int main (int argc, char* argv[]) +int main(int argc, char* argv[]) { TCLAP::CmdLine cmd( "Reads a VTK partitioned unstructured grid (*.pvtu), cleans the ghost " "information and saves the data as as a regular, connected mesh file." "\n\nOpenGeoSys-6 software, version " + - GitInfoLib::GitInfo::ogs_version + - ".\n" - "Copyright (c) 2012-2021, OpenGeoSys Community " - "(http://www.opengeosys.org)", + GitInfoLib::GitInfo::ogs_version + + ".\n" + "Copyright (c) 2012-2021, OpenGeoSys Community " + "(http://www.opengeosys.org)", ' ', GitInfoLib::GitInfo::ogs_version); TCLAP::ValueArg<std::string> output_arg( "o", "output", "the output mesh (*.vtu)", true, "", "output.vtu"); cmd.add(output_arg); - TCLAP::ValueArg<std::string> input_arg("i", "input", - "the partitioned input mesh (*.pvtu)", - true, "", "input.pvtu"); + TCLAP::ValueArg<std::string> input_arg( + "i", "input", "the partitioned input mesh (*.pvtu)", true, "", + "input.pvtu"); cmd.add(input_arg); cmd.parse(argc, argv); diff --git a/Applications/Utils/MeshEdit/Vtu2Grid.cpp b/Applications/Utils/MeshEdit/Vtu2Grid.cpp index 1db81bed240dd45628e477ecf6ffc8da16ff4892..4179fe3ad01c0e894ca5d985fa3e23279a02f7f2 100644 --- a/Applications/Utils/MeshEdit/Vtu2Grid.cpp +++ b/Applications/Utils/MeshEdit/Vtu2Grid.cpp @@ -8,15 +8,6 @@ */ #include <tclap/CmdLine.h> - -#include "InfoLib/GitInfo.h" - -#include "MeshLib/IO/writeMeshToFile.h" -#include "MeshLib/Mesh.h" -#include "MeshLib/MeshEditing/RemoveMeshComponents.h" -#include "MeshLib/MeshGenerators/MeshGenerator.h" -#include "MeshLib/MeshSearch/ElementSearch.h" - #include <vtkAbstractArray.h> #include <vtkCellData.h> #include <vtkCellLocator.h> @@ -27,18 +18,23 @@ #include <vtkUnstructuredGrid.h> #include <vtkXMLUnstructuredGridReader.h> +#include "InfoLib/GitInfo.h" +#include "MeshLib/IO/writeMeshToFile.h" +#include "MeshLib/Mesh.h" +#include "MeshLib/MeshEditing/RemoveMeshComponents.h" +#include "MeshLib/MeshGenerators/MeshGenerator.h" +#include "MeshLib/MeshSearch/ElementSearch.h" + std::string const cell_id_name = "CellIds"; std::array<std::size_t, 3> getDimensions(MathLib::Point3d const& min, MathLib::Point3d const& max, std::array<double, 3> const& cellsize) { - return - { + return { static_cast<std::size_t>(std::ceil((max[0] - min[0]) / cellsize[0])), static_cast<std::size_t>(std::ceil((max[1] - min[1]) / cellsize[1])), - static_cast<std::size_t>(std::ceil((max[2] - min[2]) / cellsize[2])) - }; + static_cast<std::size_t>(std::ceil((max[2] - min[2]) / cellsize[2]))}; } std::vector<int> assignCellIds(vtkSmartPointer<vtkUnstructuredGrid> const& mesh, @@ -51,7 +47,7 @@ std::vector<int> assignCellIds(vtkSmartPointer<vtkUnstructuredGrid> const& mesh, locator->SetDataSet(mesh); locator->Update(); - std::vector<int> cell_ids; + std::vector<int> cell_ids; cell_ids.reserve(dims[0] * dims[1] * dims[2]); std::array<double, 3> const grid_max = {min[0] + dims[0] * cellsize[0], min[1] + dims[1] * cellsize[1], @@ -82,7 +78,7 @@ bool removeUnusedGridCells(vtkSmartPointer<vtkUnstructuredGrid> const& mesh, if (n_elems_marked == grid->getNumberOfElements()) { - ERR ("No valid elements found. Aborting..."); + ERR("No valid elements found. Aborting..."); return false; } @@ -101,7 +97,7 @@ void mapArray(MeshLib::Mesh& grid, VTK_TYPE vtk_arr, std::string const& name) *grid.getProperties().getPropertyVector<int>( cell_id_name, MeshLib::MeshItemType::Cell, 1); std::vector<T>& arr = *grid.getProperties().createNewPropertyVector<T>( - name, MeshLib::MeshItemType::Cell, vtk_arr->GetNumberOfComponents()); + name, MeshLib::MeshItemType::Cell, vtk_arr->GetNumberOfComponents()); std::size_t const n_elems = cell_ids.size(); arr.resize(n_elems); for (std::size_t j = 0; j < n_elems; ++j) @@ -119,7 +115,8 @@ void mapMeshArraysOntoGrid(vtkSmartPointer<vtkUnstructuredGrid> const& mesh, dynamic_cast<vtkDoubleArray*>(cell_data->GetArray(name.c_str())); if (dbl_arr) { - mapArray<double, vtkSmartPointer<vtkDoubleArray>>(*grid, dbl_arr, name); + mapArray<double, vtkSmartPointer<vtkDoubleArray>>(*grid, dbl_arr, + name); continue; } vtkSmartPointer<vtkIntArray> const int_arr = @@ -133,7 +130,7 @@ void mapMeshArraysOntoGrid(vtkSmartPointer<vtkUnstructuredGrid> const& mesh, } } -int main (int argc, char* argv[]) +int main(int argc, char* argv[]) { TCLAP::CmdLine cmd( "Reads a 3D unstructured mesh and samples it onto a structured grid of " @@ -187,7 +184,7 @@ int main (int argc, char* argv[]) double const x_size = x_arg.getValue(); double const y_size = (y_arg.isSet()) ? y_arg.getValue() : x_arg.getValue(); double const z_size = (z_arg.isSet()) ? z_arg.getValue() : x_arg.getValue(); - std::array<double, 3> const cellsize = { x_size, y_size, z_size }; + std::array<double, 3> const cellsize = {x_size, y_size, z_size}; vtkSmartPointer<vtkXMLUnstructuredGridReader> reader = vtkSmartPointer<vtkXMLUnstructuredGridReader>::New(); @@ -196,15 +193,16 @@ int main (int argc, char* argv[]) vtkSmartPointer<vtkUnstructuredGrid> mesh = reader->GetOutput(); double* const bounds = mesh->GetBounds(); - MathLib::Point3d const min(std::array<double, 3>{bounds[0], bounds[2], bounds[4]}); - MathLib::Point3d const max(std::array<double, 3>{bounds[1], bounds[3], bounds[5]}); + MathLib::Point3d const min( + std::array<double, 3>{bounds[0], bounds[2], bounds[4]}); + MathLib::Point3d const max( + std::array<double, 3>{bounds[1], bounds[3], bounds[5]}); std::array<std::size_t, 3> const dims = getDimensions(min, max, cellsize); std::unique_ptr<MeshLib::Mesh> grid( MeshLib::MeshGenerator::generateRegularHexMesh( dims[0], dims[1], dims[2], cellsize[0], cellsize[1], cellsize[2], min, "grid")); - std::vector<int> const tmp_ids = assignCellIds(mesh, min, dims, cellsize); std::vector<int>& cell_ids = *grid->getProperties().createNewPropertyVector<int>( diff --git a/Applications/Utils/MeshEdit/appendLinesAlongPolyline.cpp b/Applications/Utils/MeshEdit/appendLinesAlongPolyline.cpp index 240fa23492a92cebb9babd7d9b2a8459200e9ad7..f34d0c7aab0e7b162c5d7f96eb699d3698dcd16d 100644 --- a/Applications/Utils/MeshEdit/appendLinesAlongPolyline.cpp +++ b/Applications/Utils/MeshEdit/appendLinesAlongPolyline.cpp @@ -7,23 +7,20 @@ * http://www.opengeosys.org/project/license */ +#include "MeshGeoToolsLib/AppendLinesAlongPolyline.h" + #include <tclap/CmdLine.h> #include "Applications/FileIO/readGeometryFromFile.h" - -#include "InfoLib/GitInfo.h" #include "BaseLib/FileTools.h" - #include "GeoLib/GEOObjects.h" #include "GeoLib/PolylineVec.h" - -#include "MeshGeoToolsLib/AppendLinesAlongPolyline.h" - -#include "MeshLib/IO/writeMeshToFile.h" +#include "InfoLib/GitInfo.h" #include "MeshLib/IO/readMeshFromFile.h" +#include "MeshLib/IO/writeMeshToFile.h" #include "MeshLib/Mesh.h" -int main (int argc, char* argv[]) +int main(int argc, char* argv[]) { TCLAP::CmdLine cmd( "Append line elements into a mesh.\n\n" @@ -33,16 +30,20 @@ int main (int argc, char* argv[]) "Copyright (c) 2012-2021, OpenGeoSys Community " "(http://www.opengeosys.org)", ' ', GitInfoLib::GitInfo::ogs_version); - TCLAP::ValueArg<std::string> mesh_in("i", "mesh-input-file", - "the name of the file containing the input mesh", true, - "", "file name of input mesh"); + TCLAP::ValueArg<std::string> mesh_in( + "i", "mesh-input-file", + "the name of the file containing the input mesh", true, "", + "file name of input mesh"); cmd.add(mesh_in); - TCLAP::ValueArg<std::string> mesh_out("o", "mesh-output-file", - "the name of the file the mesh will be written to", true, - "", "file name of output mesh"); + TCLAP::ValueArg<std::string> mesh_out( + "o", "mesh-output-file", + "the name of the file the mesh will be written to", true, "", + "file name of output mesh"); cmd.add(mesh_out); - TCLAP::ValueArg<std::string> geoFileArg("g", "geo-file", - "the name of the geometry file which contains polylines", true, "", "the name of the geometry file"); + TCLAP::ValueArg<std::string> geoFileArg( + "g", "geo-file", + "the name of the geometry file which contains polylines", true, "", + "the name of the geometry file"); cmd.add(geoFileArg); TCLAP::ValueArg<std::string> gmsh_path_arg("g", "gmsh-path", @@ -64,7 +65,8 @@ int main (int argc, char* argv[]) ERR("No geometries found."); return EXIT_FAILURE; } - const GeoLib::PolylineVec* ply_vec (geo_objs.getPolylineVecObj(geo_names[0])); + const GeoLib::PolylineVec* ply_vec( + geo_objs.getPolylineVecObj(geo_names[0])); if (!ply_vec) { ERR("Could not find polylines in geometry '{:s}'.", geo_names.front()); @@ -72,7 +74,8 @@ int main (int argc, char* argv[]) } // read a mesh - MeshLib::Mesh const*const mesh (MeshLib::IO::readMeshFromFile(mesh_in.getValue())); + MeshLib::Mesh const* const mesh( + MeshLib::IO::readMeshFromFile(mesh_in.getValue())); if (!mesh) { ERR("Mesh file '{:s}' not found", mesh_in.getValue()); diff --git a/Applications/Utils/MeshEdit/checkMesh.cpp b/Applications/Utils/MeshEdit/checkMesh.cpp index 6b7bc4c5be855cbd18c97cdc3e98487a3555b976..1d69c3aeafcdedcee5dc07bf8f53074f998718c9 100644 --- a/Applications/Utils/MeshEdit/checkMesh.cpp +++ b/Applications/Utils/MeshEdit/checkMesh.cpp @@ -7,26 +7,23 @@ * http://www.opengeosys.org/project/license */ +#include <tclap/CmdLine.h> + #include <array> #include <string> -#include <tclap/CmdLine.h> - -#include "InfoLib/GitInfo.h" -#include "BaseLib/StringTools.h" +#include "BaseLib/FileTools.h" #include "BaseLib/MemWatch.h" #include "BaseLib/RunTime.h" -#include "BaseLib/FileTools.h" - +#include "BaseLib/StringTools.h" #include "GeoLib/AABB.h" - -#include "MeshLib/Node.h" +#include "InfoLib/GitInfo.h" #include "MeshLib/Elements/Element.h" +#include "MeshLib/IO/readMeshFromFile.h" #include "MeshLib/Mesh.h" #include "MeshLib/MeshInformation.h" #include "MeshLib/MeshQuality/MeshValidation.h" - -#include "MeshLib/IO/readMeshFromFile.h" +#include "MeshLib/Node.h" int main(int argc, char* argv[]) { diff --git a/Applications/Utils/MeshEdit/convertToLinearMesh.cpp b/Applications/Utils/MeshEdit/convertToLinearMesh.cpp index 8346b2ae1aaaa369e910557741f26869d9539559..5cab4e7b29da56319779ad4eab0a7d0eea52fdc4 100644 --- a/Applications/Utils/MeshEdit/convertToLinearMesh.cpp +++ b/Applications/Utils/MeshEdit/convertToLinearMesh.cpp @@ -7,21 +7,19 @@ * http://www.opengeosys.org/project/license */ -#include <memory> -#include <string> +#include "MeshLib/MeshEditing/ConvertToLinearMesh.h" #include <tclap/CmdLine.h> -#include "InfoLib/GitInfo.h" - -#include "MeshLib/Mesh.h" -#include "MeshLib/MeshEditing/ConvertToLinearMesh.h" +#include <memory> +#include <string> +#include "InfoLib/GitInfo.h" #include "MeshLib/IO/readMeshFromFile.h" #include "MeshLib/IO/writeMeshToFile.h" +#include "MeshLib/Mesh.h" - -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { TCLAP::CmdLine cmd( "Convert a non-linear mesh to a linear mesh.\n\n" @@ -31,12 +29,14 @@ int main(int argc, char *argv[]) "Copyright (c) 2012-2021, OpenGeoSys Community " "(http://www.opengeosys.org)", ' ', GitInfoLib::GitInfo::ogs_version); - TCLAP::ValueArg<std::string> input_arg("i", "input-mesh-file","input mesh file",true,"","string"); - cmd.add( input_arg ); - TCLAP::ValueArg<std::string> output_arg("o", "output-mesh-file","output mesh file",true,"","string"); - cmd.add( output_arg ); + TCLAP::ValueArg<std::string> input_arg( + "i", "input-mesh-file", "input mesh file", true, "", "string"); + cmd.add(input_arg); + TCLAP::ValueArg<std::string> output_arg( + "o", "output-mesh-file", "output mesh file", true, "", "string"); + cmd.add(output_arg); - cmd.parse( argc, argv ); + cmd.parse(argc, argv); std::unique_ptr<MeshLib::Mesh> mesh( MeshLib::IO::readMeshFromFile(input_arg.getValue())); @@ -51,7 +51,8 @@ int main(int argc, char *argv[]) } INFO("Converting to a linear order mesh"); - std::unique_ptr<MeshLib::Mesh> new_mesh(MeshLib::convertToLinearMesh(*mesh, mesh->getName()+"_linear")); + std::unique_ptr<MeshLib::Mesh> new_mesh( + MeshLib::convertToLinearMesh(*mesh, mesh->getName() + "_linear")); INFO("Save the new mesh into a file"); MeshLib::IO::writeMeshToFile(*new_mesh, output_arg.getValue()); diff --git a/Applications/Utils/MeshEdit/createLayeredMeshFromRasters.cpp b/Applications/Utils/MeshEdit/createLayeredMeshFromRasters.cpp index 2d3c1c7144c62917dbdf5f0496dc7232a7e560ba..6603a7c3970cb4adbd8365e585820e2f6c1bc3fe 100644 --- a/Applications/Utils/MeshEdit/createLayeredMeshFromRasters.cpp +++ b/Applications/Utils/MeshEdit/createLayeredMeshFromRasters.cpp @@ -9,26 +9,24 @@ * http://www.opengeosys.org/project/license */ +#include <tclap/CmdLine.h> + #include <algorithm> #include <iterator> #include <memory> #include <string> #include <vector> -#include <tclap/CmdLine.h> - -#include "InfoLib/GitInfo.h" +#include "Applications/FileIO/AsciiRasterInterface.h" #include "BaseLib/FileTools.h" #include "BaseLib/IO/readStringListFromFile.h" - -#include "MeshLib/IO/readMeshFromFile.h" +#include "InfoLib/GitInfo.h" #include "MeshLib/IO/VtkIO/VtuInterface.h" -#include "Applications/FileIO/AsciiRasterInterface.h" - +#include "MeshLib/IO/readMeshFromFile.h" #include "MeshLib/Mesh.h" #include "MeshLib/MeshGenerators/MeshLayerMapper.h" -int main (int argc, char* argv[]) +int main(int argc, char* argv[]) { TCLAP::CmdLine cmd( "Creates a layered 3D OGS mesh from an existing 2D OGS mesh and a list " @@ -63,16 +61,14 @@ int main (int argc, char* argv[]) true, "", "file name"); cmd.add(raster_path_arg); - TCLAP::ValueArg<std::string> mesh_out_arg( - "o", "output-mesh-file", - "The file name of the resulting 3D mesh.", + TCLAP::ValueArg<std::string> mesh_out_arg( + "o", "output-mesh-file", "The file name of the resulting 3D mesh.", true, "", "file name"); cmd.add(mesh_out_arg); - TCLAP::ValueArg<std::string> mesh_arg( - "i", "input-mesh-file", - "The file name of the 2D input mesh.", true, "", - "file name"); + TCLAP::ValueArg<std::string> mesh_arg("i", "input-mesh-file", + "The file name of the 2D input mesh.", + true, "", "file name"); cmd.add(mesh_arg); cmd.parse(argc, argv); @@ -104,9 +100,9 @@ int main (int argc, char* argv[]) std::vector<std::string> raster_paths = BaseLib::IO::readStringListFromFile(raster_path_arg.getValue()); - if (raster_paths.size()<2) + if (raster_paths.size() < 2) { - ERR ("At least two raster files needed to create 3D mesh."); + ERR("At least two raster files needed to create 3D mesh."); return EXIT_FAILURE; } std::reverse(raster_paths.begin(), raster_paths.end()); diff --git a/Applications/Utils/MeshEdit/createQuadraticMesh.cpp b/Applications/Utils/MeshEdit/createQuadraticMesh.cpp index 474580c172df9578c5e8c7b7a4683d9cf780770f..9a5818a8f31713acc4c8449261c112156e363982 100644 --- a/Applications/Utils/MeshEdit/createQuadraticMesh.cpp +++ b/Applications/Utils/MeshEdit/createQuadraticMesh.cpp @@ -7,21 +7,18 @@ * http://www.opengeosys.org/project/license */ +#include <tclap/CmdLine.h> + #include <memory> #include <string> -#include <tclap/CmdLine.h> - #include "InfoLib/GitInfo.h" - -#include "MeshLib/Mesh.h" -#include "MeshLib/MeshGenerators/QuadraticMeshGenerator.h" - #include "MeshLib/IO/readMeshFromFile.h" #include "MeshLib/IO/writeMeshToFile.h" +#include "MeshLib/Mesh.h" +#include "MeshLib/MeshGenerators/QuadraticMeshGenerator.h" - -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { TCLAP::CmdLine cmd( "Create quadratic order mesh.\n\n" @@ -32,14 +29,16 @@ int main(int argc, char *argv[]) "(http://www.opengeosys.org)", ' ', GitInfoLib::GitInfo::ogs_version); - TCLAP::ValueArg<std::string> input_arg("i", "input-mesh-file","input mesh file",true,"","string"); - cmd.add( input_arg ); - TCLAP::ValueArg<std::string> output_arg("o", "output-mesh-file","output mesh file",true,"","string"); - cmd.add( output_arg ); + TCLAP::ValueArg<std::string> input_arg( + "i", "input-mesh-file", "input mesh file", true, "", "string"); + cmd.add(input_arg); + TCLAP::ValueArg<std::string> output_arg( + "o", "output-mesh-file", "output mesh file", true, "", "string"); + cmd.add(output_arg); TCLAP::SwitchArg add_centre_node_arg("c", "add-centre-node", "add centre node", false); cmd.add(add_centre_node_arg); - cmd.parse( argc, argv ); + cmd.parse(argc, argv); std::unique_ptr<MeshLib::Mesh> mesh( MeshLib::IO::readMeshFromFile(input_arg.getValue())); diff --git a/Applications/Utils/MeshEdit/editMaterialID.cpp b/Applications/Utils/MeshEdit/editMaterialID.cpp index cf318c15810fe51c860aedcd421c49940b6163ec..15763dd850399fc80eb147c2d23e99bbf15cca95 100644 --- a/Applications/Utils/MeshEdit/editMaterialID.cpp +++ b/Applications/Utils/MeshEdit/editMaterialID.cpp @@ -7,10 +7,10 @@ * http://www.opengeosys.org/project/license */ -#include <memory> - #include <tclap/CmdLine.h> +#include <memory> + #include "InfoLib/GitInfo.h" #include "MeshLib/Elements/Element.h" #include "MeshLib/IO/readMeshFromFile.h" @@ -18,7 +18,7 @@ #include "MeshLib/Mesh.h" #include "MeshLib/MeshEditing/ElementValueModification.h" -int main (int argc, char* argv[]) +int main(int argc, char* argv[]) { TCLAP::CmdLine cmd( "Edit material IDs of mesh elements.\n\n" @@ -29,36 +29,42 @@ int main (int argc, char* argv[]) "(http://www.opengeosys.org)", ' ', GitInfoLib::GitInfo::ogs_version); TCLAP::SwitchArg replaceArg("r", "replace", "replace material IDs", false); - TCLAP::SwitchArg condenseArg("c", "condense", "condense material IDs", false); - TCLAP::SwitchArg specifyArg("s", "specify", "specify material IDs by element types (-e)", false); + TCLAP::SwitchArg condenseArg("c", "condense", "condense material IDs", + false); + TCLAP::SwitchArg specifyArg( + "s", "specify", "specify material IDs by element types (-e)", false); std::vector<TCLAP::Arg*> vec_xors; vec_xors.push_back(&replaceArg); vec_xors.push_back(&condenseArg); vec_xors.push_back(&specifyArg); cmd.xorAdd(vec_xors); - TCLAP::ValueArg<std::string> mesh_in("i", "mesh-input-file", - "the name of the file containing the input mesh", true, - "", "file name"); + TCLAP::ValueArg<std::string> mesh_in( + "i", "mesh-input-file", + "the name of the file containing the input mesh", true, "", + "file name"); cmd.add(mesh_in); - TCLAP::ValueArg<std::string> mesh_out("o", "mesh-output-file", - "the name of the file the mesh will be written to", true, - "", "file name"); + TCLAP::ValueArg<std::string> mesh_out( + "o", "mesh-output-file", + "the name of the file the mesh will be written to", true, "", + "file name"); cmd.add(mesh_out); TCLAP::MultiArg<unsigned> matIDArg("m", "current-material-id", - "current material id to be replaced", false, "number"); + "current material id to be replaced", + false, "number"); cmd.add(matIDArg); TCLAP::ValueArg<unsigned> newIDArg("n", "new-material-id", - "new material id", false, 0, "number"); + "new material id", false, 0, "number"); cmd.add(newIDArg); std::vector<std::string> eleList(MeshLib::getMeshElemTypeStringsShort()); TCLAP::ValuesConstraint<std::string> allowedVals(eleList); - TCLAP::ValueArg<std::string> eleTypeArg("e", "element-type", - "element type", false, "", &allowedVals); + TCLAP::ValueArg<std::string> eleTypeArg("e", "element-type", "element type", + false, "", &allowedVals); cmd.add(eleTypeArg); cmd.parse(argc, argv); - if (!replaceArg.isSet() && !condenseArg.isSet() && !specifyArg.isSet()) { + if (!replaceArg.isSet() && !condenseArg.isSet() && !specifyArg.isSet()) + { INFO("Please select editing mode: -r or -c or -s"); return 0; } @@ -69,13 +75,21 @@ int main (int argc, char* argv[]) } if (replaceArg.isSet()) { - if (!matIDArg.isSet() || !newIDArg.isSet()) { - INFO("current and new material IDs must be provided for replacement"); + if (!matIDArg.isSet() || !newIDArg.isSet()) + { + INFO( + "current and new material IDs must be provided for " + "replacement"); return 0; } - } else if (specifyArg.isSet()) { - if (!eleTypeArg.isSet() || !newIDArg.isSet()) { - INFO("element type and new material IDs must be provided to specify elements"); + } + else if (specifyArg.isSet()) + { + if (!eleTypeArg.isSet() || !newIDArg.isSet()) + { + INFO( + "element type and new material IDs must be provided to specify " + "elements"); return 0; } } @@ -85,23 +99,32 @@ int main (int argc, char* argv[]) INFO("Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(), mesh->getNumberOfElements()); - if (condenseArg.isSet()) { + if (condenseArg.isSet()) + { INFO("Condensing material ID..."); MeshLib::ElementValueModification::condense(*mesh); - } else if (replaceArg.isSet()) { + } + else if (replaceArg.isSet()) + { INFO("Replacing material ID..."); const auto vecOldID = matIDArg.getValue(); const unsigned newID = newIDArg.getValue(); - for (auto oldID : vecOldID) { + for (auto oldID : vecOldID) + { INFO("{:d} -> {:d}", oldID, newID); - MeshLib::ElementValueModification::replace(*mesh, oldID, newID, true); + MeshLib::ElementValueModification::replace(*mesh, oldID, newID, + true); } - } else if (specifyArg.isSet()) { + } + else if (specifyArg.isSet()) + { INFO("Specifying material ID..."); const std::string eleTypeName(eleTypeArg.getValue()); - const MeshLib::MeshElemType eleType = MeshLib::String2MeshElemType(eleTypeName); + const MeshLib::MeshElemType eleType = + MeshLib::String2MeshElemType(eleTypeName); const unsigned newID = newIDArg.getValue(); - unsigned cnt = MeshLib::ElementValueModification::setByElementType(*mesh, eleType, newID); + unsigned cnt = MeshLib::ElementValueModification::setByElementType( + *mesh, eleType, newID); INFO("updated {:d} elements", cnt); } diff --git a/Applications/Utils/MeshEdit/moveMeshNodes.cpp b/Applications/Utils/MeshEdit/moveMeshNodes.cpp index 66b730645395cbf068e7dd7e450af7807aba1b99..33e13bdf7acbec74420c2705365b701828a0ed9a 100644 --- a/Applications/Utils/MeshEdit/moveMeshNodes.cpp +++ b/Applications/Utils/MeshEdit/moveMeshNodes.cpp @@ -12,23 +12,23 @@ #include <memory> #include <string> -#include "InfoLib/GitInfo.h" #include "BaseLib/FileTools.h" #include "GeoLib/AABB.h" +#include "InfoLib/GitInfo.h" #include "MathLib/MathTools.h" #include "MeshLib/IO/readMeshFromFile.h" #include "MeshLib/IO/writeMeshToFile.h" #include "MeshLib/Mesh.h" -#include "MeshLib/Node.h" -#include "MeshLib/MeshSearch/MeshElementGrid.h" #include "MeshLib/MeshEditing/ProjectPointOnMesh.h" +#include "MeshLib/MeshSearch/MeshElementGrid.h" +#include "MeshLib/Node.h" double getClosestPointElevation(MeshLib::Node const& p, - std::vector<MeshLib::Node*> const& nodes, - double const& max_dist) + std::vector<MeshLib::Node*> const& nodes, + double const& max_dist) { - double sqr_shortest_dist (max_dist); - double elevation (p[2]); + double sqr_shortest_dist(max_dist); + double elevation(p[2]); for (MeshLib::Node* node : nodes) { double sqr_dist = (p[0] - (*node)[0]) * (p[0] - (*node)[0]) + @@ -42,7 +42,7 @@ double getClosestPointElevation(MeshLib::Node const& p, return elevation; } -int main (int argc, char* argv[]) +int main(int argc, char* argv[]) { std::vector<std::string> keywords; keywords.emplace_back("-ALL"); @@ -71,7 +71,7 @@ int main (int argc, char* argv[]) const std::string msh_name(argv[1]); const std::string current_key(argv[2]); - std::string const ext (BaseLib::getFileExtension(msh_name)); + std::string const ext(BaseLib::getFileExtension(msh_name)); if (!(ext == ".msh" || ext == ".vtu")) { ERR("Error: Parameter 1 must be a mesh-file (*.msh / *.vtu)."); @@ -91,10 +91,11 @@ int main (int argc, char* argv[]) return EXIT_FAILURE; } - std::unique_ptr<MeshLib::Mesh> mesh (MeshLib::IO::readMeshFromFile(msh_name)); + std::unique_ptr<MeshLib::Mesh> mesh( + MeshLib::IO::readMeshFromFile(msh_name)); if (mesh == nullptr) { - ERR ("Error reading mesh file."); + ERR("Error reading mesh file."); return 1; } @@ -110,19 +111,20 @@ int main (int argc, char* argv[]) } const std::string dir(argv[3]); unsigned idx = (dir == "x") ? 0 : (dir == "y") ? 1 : 2; - const double value(strtod(argv[4],0)); + const double value(strtod(argv[4], 0)); INFO("Moving all mesh nodes by {:g} in direction {:d} ({:s})...", value, idx, dir); - //double value(-10); + // double value(-10); const std::size_t nNodes(mesh->getNumberOfNodes()); - std::vector<MeshLib::Node*> nodes (mesh->getNodes()); - for (std::size_t i=0; i<nNodes; i++) + std::vector<MeshLib::Node*> nodes(mesh->getNodes()); + for (std::size_t i = 0; i < nNodes; i++) { (*nodes[i])[idx] += value; } } - // maps the elevation of mesh nodes according to a ground truth mesh whenever nodes exist within max_dist + // maps the elevation of mesh nodes according to a ground truth mesh + // whenever nodes exist within max_dist if (current_key == "-MESH") { if (argc < 4) @@ -130,12 +132,13 @@ int main (int argc, char* argv[]) ERR("Missing parameter..."); return EXIT_FAILURE; } - const std::string value (argv[3]); - double max_dist(pow(strtod(argv[4],0), 2)); - std::unique_ptr<MeshLib::Mesh> ground_truth (MeshLib::IO::readMeshFromFile(value)); + const std::string value(argv[3]); + double max_dist(pow(strtod(argv[4], 0), 2)); + std::unique_ptr<MeshLib::Mesh> ground_truth( + MeshLib::IO::readMeshFromFile(value)); if (ground_truth == nullptr) { - ERR ("Error reading mesh file."); + ERR("Error reading mesh file."); return EXIT_FAILURE; } @@ -155,18 +158,21 @@ int main (int argc, char* argv[]) grid.getElementsInVolume(min_vol, max_vol); auto const* element = MeshLib::ProjectPointOnMesh::getProjectedElement(elems, *node); - (*node)[2] = (element != nullptr) - ? MeshLib::ProjectPointOnMesh::getElevation(*element, *node) - : getClosestPointElevation( *node, ground_truth->getNodes(), max_dist); + (*node)[2] = + (element != nullptr) + ? MeshLib::ProjectPointOnMesh::getElevation(*element, *node) + : getClosestPointElevation(*node, ground_truth->getNodes(), + max_dist); } } - // a simple lowpass filter for the elevation of mesh nodes using the elevation of each node - // weighted by 2 and the elevation of each connected node weighted by 1 + // a simple lowpass filter for the elevation of mesh nodes using the + // elevation of each node weighted by 2 and the elevation of each connected + // node weighted by 1 if (current_key == "-LOWPASS") { const std::size_t nNodes(mesh->getNumberOfNodes()); - std::vector<MeshLib::Node*> nodes (mesh->getNodes()); + std::vector<MeshLib::Node*> nodes(mesh->getNodes()); std::vector<double> elevation(nNodes); for (std::size_t i = 0; i < nNodes; i++) @@ -174,16 +180,17 @@ int main (int argc, char* argv[]) elevation[i] = (*nodes[i])[2]; } - for (std::size_t i=0; i<nNodes; i++) + 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]); + 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) { elevation[i] += (*conn_nodes[j])[2]; } - elevation[i] /= (nConnNodes+2); + elevation[i] /= (nConnNodes + 2); } for (std::size_t i = 0; i < nNodes; i++) @@ -193,7 +200,8 @@ int main (int argc, char* argv[]) } /**** add other keywords here ****/ - std::string const new_mesh_name (msh_name.substr(0, msh_name.length() - 4) + "_new.vtu"); + 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; diff --git a/Applications/Utils/MeshEdit/queryMesh.cpp b/Applications/Utils/MeshEdit/queryMesh.cpp index c4d6ecd7325632e94c47de8a5459b2aab67e9a75..e844ce81809c2397de7f5b0e8f8eb1bb5d778b4a 100644 --- a/Applications/Utils/MeshEdit/queryMesh.cpp +++ b/Applications/Utils/MeshEdit/queryMesh.cpp @@ -7,23 +7,22 @@ * http://www.opengeosys.org/project/license */ +#include <tclap/CmdLine.h> + #include <array> #include <memory> #include <sstream> #include <string> -#include <tclap/CmdLine.h> - -#include "InfoLib/GitInfo.h" -#include "BaseLib/StringTools.h" #include "BaseLib/FileTools.h" - -#include "MeshLib/Node.h" +#include "BaseLib/StringTools.h" +#include "InfoLib/GitInfo.h" #include "MeshLib/Elements/Element.h" -#include "MeshLib/Mesh.h" #include "MeshLib/IO/readMeshFromFile.h" +#include "MeshLib/Mesh.h" +#include "MeshLib/Node.h" -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { TCLAP::CmdLine cmd( "Query mesh information.\n\n" @@ -33,39 +32,49 @@ int main(int argc, char *argv[]) "Copyright (c) 2012-2021, OpenGeoSys Community " "(http://www.opengeosys.org)", ' ', GitInfoLib::GitInfo::ogs_version); - TCLAP::UnlabeledValueArg<std::string> mesh_arg("mesh-file","input mesh file",true,"","string"); - cmd.add( mesh_arg ); - TCLAP::MultiArg<std::size_t> eleId_arg("e","element-id","element ID",false,"number"); - cmd.add( eleId_arg ); - TCLAP::MultiArg<std::size_t> nodeId_arg("n","node-id","node ID",false,"number"); - cmd.add( nodeId_arg ); - TCLAP::SwitchArg showNodeWithMaxEle_arg("", "show-node-with-max-elements", "show a node having the max number of connected elements", false); - cmd.add( showNodeWithMaxEle_arg ); + TCLAP::UnlabeledValueArg<std::string> mesh_arg( + "mesh-file", "input mesh file", true, "", "string"); + cmd.add(mesh_arg); + TCLAP::MultiArg<std::size_t> eleId_arg("e", "element-id", "element ID", + false, "number"); + cmd.add(eleId_arg); + TCLAP::MultiArg<std::size_t> nodeId_arg("n", "node-id", "node ID", false, + "number"); + cmd.add(nodeId_arg); + TCLAP::SwitchArg showNodeWithMaxEle_arg( + "", "show-node-with-max-elements", + "show a node having the max number of connected elements", false); + cmd.add(showNodeWithMaxEle_arg); - cmd.parse( argc, argv ); + cmd.parse(argc, argv); const std::string filename(mesh_arg.getValue()); // read the mesh file - auto const mesh = std::unique_ptr<MeshLib::Mesh>( - MeshLib::IO::readMeshFromFile(filename)); + 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()) + if (showNodeWithMaxEle_arg.getValue()) { - auto itr = std::max_element(mesh->getNodes().begin(), mesh->getNodes().end(), - [](MeshLib::Node* i, MeshLib::Node* j) { return i->getNumberOfElements() < j->getNumberOfElements(); }); + auto itr = std::max_element( + mesh->getNodes().begin(), mesh->getNodes().end(), + [](MeshLib::Node* i, MeshLib::Node* j) { + return i->getNumberOfElements() < j->getNumberOfElements(); + }); if (itr != mesh->getNodes().end()) { MeshLib::Node* node = *itr; selected_node_ids.push_back(node->getID()); } } - selected_node_ids.insert(selected_node_ids.end(), nodeId_arg.getValue().begin(), nodeId_arg.getValue().end()); + selected_node_ids.insert(selected_node_ids.end(), + nodeId_arg.getValue().begin(), + nodeId_arg.getValue().end()); auto const materialIds = materialIDs(*mesh); for (auto ele_id : eleId_arg.getValue()) @@ -73,7 +82,8 @@ int main(int argc, char *argv[]) std::stringstream out; out << std::scientific << std::setprecision(std::numeric_limits<double>::digits10); - out << "--------------------------------------------------------" << std::endl; + out << "--------------------------------------------------------" + << std::endl; auto* ele = mesh->getElement(ele_id); out << "# Element " << ele->getID() << std::endl; out << "Type : " << CellType2String(ele->getCellType()) << std::endl; @@ -89,7 +99,7 @@ int main(int argc, char *argv[]) } out << "Content: " << ele->getContent() << std::endl; out << "Neighbors: "; - for (unsigned i=0; i<ele->getNumberOfNeighbors(); i++) + for (unsigned i = 0; i < ele->getNumberOfNeighbors(); i++) { if (ele->getNeighbor(i)) { @@ -109,7 +119,8 @@ int main(int argc, char *argv[]) std::stringstream out; out << std::scientific << std::setprecision(std::numeric_limits<double>::digits10); - out << "--------------------------------------------------------" << std::endl; + out << "--------------------------------------------------------" + << std::endl; MeshLib::Node const* node = mesh->getNode(node_id); out << "# Node " << node->getID() << std::endl; out << "Coordinates: " << *node << std::endl; diff --git a/Applications/Utils/MeshEdit/removeMeshElements.cpp b/Applications/Utils/MeshEdit/removeMeshElements.cpp index 6b598c4dd7c6fff4ac40bd3220593ed3525d3ee4..d9fa6d42a72678b4a70a0dbc1f63d8779b90635a 100644 --- a/Applications/Utils/MeshEdit/removeMeshElements.cpp +++ b/Applications/Utils/MeshEdit/removeMeshElements.cpp @@ -11,10 +11,10 @@ * http://www.opengeosys.org/project/license */ -#include <memory> - #include <tclap/CmdLine.h> +#include <memory> + #include "InfoLib/GitInfo.h" #include "MeshLib/Elements/Element.h" #include "MeshLib/IO/readMeshFromFile.h" @@ -66,7 +66,7 @@ void searchByPropertyRange(std::string const& property_name, std::to_string(min_value), std::to_string(max_value)); } -int main (int argc, char* argv[]) +int main(int argc, char* argv[]) { TCLAP::CmdLine cmd( "Removes mesh elements based on element type, element volume, scalar " @@ -81,27 +81,34 @@ int main (int argc, char* argv[]) ' ', GitInfoLib::GitInfo::ogs_version); // Bounding box params - TCLAP::ValueArg<double> zLargeArg("", "z-max", "largest allowed extent in z-dimension", - false, std::numeric_limits<double>::max(), "value"); + TCLAP::ValueArg<double> zLargeArg( + "", "z-max", "largest allowed extent in z-dimension", false, + std::numeric_limits<double>::max(), "value"); cmd.add(zLargeArg); - TCLAP::ValueArg<double> zSmallArg("", "z-min", "smallest allowed extent in z-dimension", - false, -1 * std::numeric_limits<double>::max(), "value"); + TCLAP::ValueArg<double> zSmallArg( + "", "z-min", "smallest allowed extent in z-dimension", false, + -1 * std::numeric_limits<double>::max(), "value"); cmd.add(zSmallArg); - TCLAP::ValueArg<double> yLargeArg("", "y-max", "largest allowed extent in y-dimension", - false, std::numeric_limits<double>::max(), "value"); + TCLAP::ValueArg<double> yLargeArg( + "", "y-max", "largest allowed extent in y-dimension", false, + std::numeric_limits<double>::max(), "value"); cmd.add(yLargeArg); - TCLAP::ValueArg<double> ySmallArg("", "y-min", "smallest allowed extent in y-dimension", - false, -1 * std::numeric_limits<double>::max(), "value"); + TCLAP::ValueArg<double> ySmallArg( + "", "y-min", "smallest allowed extent in y-dimension", false, + -1 * std::numeric_limits<double>::max(), "value"); cmd.add(ySmallArg); - TCLAP::ValueArg<double> xLargeArg("", "x-max", "largest allowed extent in x-dimension", - false, std::numeric_limits<double>::max(), "value"); + TCLAP::ValueArg<double> xLargeArg( + "", "x-max", "largest allowed extent in x-dimension", false, + std::numeric_limits<double>::max(), "value"); cmd.add(xLargeArg); - TCLAP::ValueArg<double> xSmallArg("", "x-min", "smallest allowed extent in x-dimension", - false, -1 * std::numeric_limits<double>::max(), "value"); + TCLAP::ValueArg<double> xSmallArg( + "", "x-min", "smallest allowed extent in x-dimension", false, + -1 * std::numeric_limits<double>::max(), "value"); cmd.add(xSmallArg); // Non-bounding-box params - TCLAP::SwitchArg zveArg("z", "zero-volume", "remove zero volume elements", false); + TCLAP::SwitchArg zveArg("z", "zero-volume", "remove zero volume elements", + false); cmd.add(zveArg); std::vector<std::string> allowed_ele_types{"line", "tri", "quad", "hex", @@ -116,19 +123,23 @@ int main (int argc, char* argv[]) // scalar array params TCLAP::ValueArg<std::string> property_name_arg( - "n", "property-name", "name of property in the mesh", false, "MaterialIDs", "string"); + "n", "property-name", "name of property in the mesh", false, + "MaterialIDs", "string"); cmd.add(property_name_arg); TCLAP::MultiArg<int> property_arg( - "", "property-value", "value of selected property to be removed", false, "number"); + "", "property-value", "value of selected property to be removed", false, + "number"); cmd.add(property_arg); TCLAP::ValueArg<double> min_property_arg( - "", "min-value", "minimum value of range for selected property", false, 0, "number"); + "", "min-value", "minimum value of range for selected property", false, + 0, "number"); cmd.add(min_property_arg); TCLAP::ValueArg<double> max_property_arg( - "", "max-value", "maximum value of range for selected property", false, 0, "number"); + "", "max-value", "maximum value of range for selected property", false, + 0, "number"); cmd.add(max_property_arg); TCLAP::SwitchArg outside_property_arg( @@ -140,13 +151,15 @@ int main (int argc, char* argv[]) cmd.add(inside_property_arg); // I/O params - TCLAP::ValueArg<std::string> mesh_out("o", "mesh-output-file", - "the name of the file the mesh will be written to", true, - "", "file name of output mesh"); + TCLAP::ValueArg<std::string> mesh_out( + "o", "mesh-output-file", + "the name of the file the mesh will be written to", true, "", + "file name of output mesh"); cmd.add(mesh_out); - TCLAP::ValueArg<std::string> mesh_in("i", "mesh-input-file", - "the name of the file containing the input mesh", true, - "", "file name of input mesh"); + TCLAP::ValueArg<std::string> mesh_in( + "i", "mesh-input-file", + "the name of the file containing the input mesh", true, "", + "file name of input mesh"); cmd.add(mesh_in); cmd.parse(argc, argv); @@ -162,13 +175,17 @@ int main (int argc, char* argv[]) MeshLib::ElementSearch searcher(*mesh); // search elements IDs to be removed - if (zveArg.isSet()) { + if (zveArg.isSet()) + { INFO("{:d} zero volume elements found.", searcher.searchByContent()); } - if (eleTypeArg.isSet()) { + if (eleTypeArg.isSet()) + { const std::vector<std::string> eleTypeNames = eleTypeArg.getValue(); - for (const auto& typeName : eleTypeNames) { - const MeshLib::MeshElemType type = MeshLib::String2MeshElemType(typeName); + for (const auto& typeName : eleTypeNames) + { + const MeshLib::MeshElemType type = + MeshLib::String2MeshElemType(typeName); if (type == MeshLib::MeshElemType::INVALID) { continue; @@ -181,7 +198,8 @@ int main (int argc, char* argv[]) if (property_name_arg.isSet() || property_arg.isSet() || min_property_arg.isSet() || max_property_arg.isSet()) { - if ((property_arg.isSet() || min_property_arg.isSet() || max_property_arg.isSet()) && + if ((property_arg.isSet() || min_property_arg.isSet() || + max_property_arg.isSet()) && !property_name_arg.isSet()) { ERR("Specify a property name for the value/range selected."); @@ -189,7 +207,8 @@ int main (int argc, char* argv[]) } if (property_name_arg.isSet() && - !((min_property_arg.isSet() && max_property_arg.isSet()) || property_arg.isSet())) + !((min_property_arg.isSet() && max_property_arg.isSet()) || + property_arg.isSet())) { ERR("Specify a value or range ('-min-value' and '-max_value') " "for the property selected."); @@ -223,24 +242,23 @@ int main (int argc, char* argv[]) } } - if (xSmallArg.isSet() || xLargeArg.isSet() || - ySmallArg.isSet() || yLargeArg.isSet() || - zSmallArg.isSet() || zLargeArg.isSet()) + if (xSmallArg.isSet() || xLargeArg.isSet() || ySmallArg.isSet() || + yLargeArg.isSet() || zSmallArg.isSet() || zLargeArg.isSet()) { - bool aabb_error (false); + bool aabb_error(false); if (xSmallArg.getValue() >= xLargeArg.getValue()) { - ERR ("Minimum x-extent larger than maximum x-extent."); + ERR("Minimum x-extent larger than maximum x-extent."); aabb_error = true; } if (ySmallArg.getValue() >= yLargeArg.getValue()) { - ERR ("Minimum y-extent larger than maximum y-extent."); + ERR("Minimum y-extent larger than maximum y-extent."); aabb_error = true; } if (zSmallArg.getValue() >= zLargeArg.getValue()) { - ERR ("Minimum z-extent larger than maximum z-extent."); + ERR("Minimum z-extent larger than maximum z-extent."); aabb_error = true; } if (aabb_error) @@ -248,11 +266,13 @@ int main (int argc, char* argv[]) return EXIT_FAILURE; } - std::array<MathLib::Point3d, 2> extent({{ - MathLib::Point3d(std::array<double,3>{{xSmallArg.getValue(), - ySmallArg.getValue(), zSmallArg.getValue()}}), - MathLib::Point3d(std::array<double,3>{{xLargeArg.getValue(), - yLargeArg.getValue(), zLargeArg.getValue()}})}}); + std::array<MathLib::Point3d, 2> extent( + {{MathLib::Point3d(std::array<double, 3>{{xSmallArg.getValue(), + ySmallArg.getValue(), + zSmallArg.getValue()}}), + MathLib::Point3d(std::array<double, 3>{ + {xLargeArg.getValue(), yLargeArg.getValue(), + zLargeArg.getValue()}})}}); INFO("{:d} elements found.", searcher.searchByBoundingBox( GeoLib::AABB(extent.begin(), extent.end()))); diff --git a/Applications/Utils/MeshEdit/reviseMesh.cpp b/Applications/Utils/MeshEdit/reviseMesh.cpp index 0ad872059e414957c113c247e0bd03e3cf2607bd..ff97da6b27f652f308f7008a2e14579a2326435c 100644 --- a/Applications/Utils/MeshEdit/reviseMesh.cpp +++ b/Applications/Utils/MeshEdit/reviseMesh.cpp @@ -7,25 +7,23 @@ * http://www.opengeosys.org/project/license */ +#include <tclap/CmdLine.h> + #include <array> #include <memory> #include <string> -#include <tclap/CmdLine.h> - -#include "InfoLib/GitInfo.h" -#include "BaseLib/StringTools.h" #include "BaseLib/FileTools.h" - -#include "MeshLib/Node.h" +#include "BaseLib/StringTools.h" +#include "InfoLib/GitInfo.h" #include "MeshLib/Elements/Element.h" -#include "MeshLib/Mesh.h" -#include "MeshLib/MeshEditing/MeshRevision.h" - #include "MeshLib/IO/readMeshFromFile.h" #include "MeshLib/IO/writeMeshToFile.h" +#include "MeshLib/Mesh.h" +#include "MeshLib/MeshEditing/MeshRevision.h" +#include "MeshLib/Node.h" -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { TCLAP::CmdLine cmd( "Revises meshes by collapsing duplicate nodes, (optionally) removing " @@ -55,7 +53,7 @@ int main(int argc, char *argv[]) TCLAP::ValueArg<std::string> input_arg( "i", "input-mesh-file", "input mesh file", true, "", "string"); cmd.add(input_arg); - cmd.parse( argc, argv ); + cmd.parse(argc, argv); // read a mesh file std::unique_ptr<MeshLib::Mesh> org_mesh( @@ -70,12 +68,14 @@ int main(int argc, char *argv[]) // revise the mesh INFO("Simplifying the mesh..."); MeshLib::MeshRevision const rev(const_cast<MeshLib::Mesh&>(*org_mesh)); - unsigned int minDim = (minDim_arg.isSet() ? minDim_arg.getValue() : org_mesh->getDimension()); + unsigned int minDim = + (minDim_arg.isSet() ? minDim_arg.getValue() : org_mesh->getDimension()); std::unique_ptr<MeshLib::Mesh> new_mesh( rev.simplifyMesh("revised_mesh", eps_arg.getValue(), minDim)); // write into a file - if (new_mesh) { + if (new_mesh) + { INFO("Revised mesh: {:d} nodes, {:d} elements.", new_mesh->getNumberOfNodes(), new_mesh->getNumberOfElements()); MeshLib::IO::writeMeshToFile(*new_mesh, output_arg.getValue()); diff --git a/Applications/Utils/MeshEdit/swapNodeCoordinateAxes.cpp b/Applications/Utils/MeshEdit/swapNodeCoordinateAxes.cpp index 3fd895d738fd7541c76c81f8f0a1025ba0ac1507..f049b526f60ac93e2e559853aedd6940c3958359 100644 --- a/Applications/Utils/MeshEdit/swapNodeCoordinateAxes.cpp +++ b/Applications/Utils/MeshEdit/swapNodeCoordinateAxes.cpp @@ -7,20 +7,18 @@ * http://www.opengeosys.org/project/license */ +#include <tclap/CmdLine.h> + #include <array> #include <memory> #include <string> -#include <tclap/CmdLine.h> - -#include "InfoLib/GitInfo.h" #include "BaseLib/Logging.h" - -#include "MeshLib/Mesh.h" -#include "MeshLib/Node.h" - +#include "InfoLib/GitInfo.h" #include "MeshLib/IO/readMeshFromFile.h" #include "MeshLib/IO/writeMeshToFile.h" +#include "MeshLib/Mesh.h" +#include "MeshLib/Node.h" static void swapNodeCoordinateAxes(MeshLib::Mesh const& mesh, std::array<int, 3> const& new_axes_indices) @@ -39,17 +37,19 @@ static void swapNodeCoordinateAxes(MeshLib::Mesh const& mesh, } } -static bool parseNewOrder(std::string const& str_order, std::array<int, 3> &new_axes_indices) +static bool parseNewOrder(std::string const& str_order, + std::array<int, 3>& new_axes_indices) { - if (str_order.length()!=3) + if (str_order.length() != 3) { - ERR("Invalid argument for the new order. The argument should contain three characters."); + ERR("Invalid argument for the new order. The argument should contain " + "three characters."); return false; } new_axes_indices.fill(-1); - for (int i=0; i<3; i++) + for (int i = 0; i < 3; i++) { if (str_order[i] == 'x') { @@ -76,7 +76,8 @@ static bool parseNewOrder(std::string const& str_order, std::array<int, 3> &new_ { if (isAxisSet[new_axes_indice]) { - ERR("Invalid argument for the new order. The argument contains some character used more than once."); + ERR("Invalid argument for the new order. The argument contains " + "some character used more than once."); return false; } isAxisSet[new_axes_indice] = true; @@ -85,7 +86,7 @@ static bool parseNewOrder(std::string const& str_order, std::array<int, 3> &new_ return true; } -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { TCLAP::CmdLine cmd( "Swap node coordinate values.\n\n" @@ -95,17 +96,19 @@ int main(int argc, char *argv[]) "Copyright (c) 2012-2021, OpenGeoSys Community " "(http://www.opengeosys.org)", ' ', GitInfoLib::GitInfo::ogs_version); - TCLAP::ValueArg<std::string> input_arg("i", "input-mesh-file","input mesh file",true,"","string"); - cmd.add( input_arg ); - TCLAP::ValueArg<std::string> output_arg("o", "output-mesh-file","output mesh file",true,"","string"); - cmd.add( output_arg ); + TCLAP::ValueArg<std::string> input_arg( + "i", "input-mesh-file", "input mesh file", true, "", "string"); + cmd.add(input_arg); + TCLAP::ValueArg<std::string> output_arg( + "o", "output-mesh-file", "output mesh file", true, "", "string"); + cmd.add(output_arg); TCLAP::ValueArg<std::string> new_order_arg( "n", "new-order", "the new order of swapped coordinate values " "(e.g. 'xzy' for converting XYZ values to XZY values)", true, "", "string"); - cmd.add( new_order_arg ); - cmd.parse( argc, argv ); + cmd.add(new_order_arg); + cmd.parse(argc, argv); const std::string str_order = new_order_arg.getValue(); std::array<int, 3> new_order = {{}}; @@ -123,7 +126,9 @@ int main(int argc, char *argv[]) if (mesh->getDimension() == 3) { - WARN("Swapping coordinate values of 3D elements can result in incorrect node-ordering."); + WARN( + "Swapping coordinate values of 3D elements can result in incorrect " + "node-ordering."); } INFO("Exchange node coordinates from xyz to {:s}", diff --git a/Applications/Utils/MeshGeoTools/IntegrateBoreholesIntoMesh.cpp b/Applications/Utils/MeshGeoTools/IntegrateBoreholesIntoMesh.cpp index 572b9746ed1a383ed36b15df1e40198de89aeb6c..ebfd1124b642445ea428f786fccc22501b48e48b 100644 --- a/Applications/Utils/MeshGeoTools/IntegrateBoreholesIntoMesh.cpp +++ b/Applications/Utils/MeshGeoTools/IntegrateBoreholesIntoMesh.cpp @@ -78,7 +78,8 @@ int main(int argc, char* argv[]) "via line elements. Each borehole (i.e. all points at a given " "(x,y)-location but at different depths) is assigned a unique material " "ID. Vertical limits of boreholes can be specified via Material IDs " - "and/or elevation. Point not matching any mesh nodes or located outside " + "and/or elevation. Point not matching any mesh nodes or located " + "outside " "the mesh are ignored.\n\n" "OpenGeoSys-6 software, version " + GitInfoLib::GitInfo::ogs_version + diff --git a/Applications/Utils/MeshGeoTools/Raster2Mesh.cpp b/Applications/Utils/MeshGeoTools/Raster2Mesh.cpp index 2e20dd5a76dc4fd1cca318286bcfc31ff935a0a6..d73870eb532cb287029e1af2bced1b540f0fe331 100644 --- a/Applications/Utils/MeshGeoTools/Raster2Mesh.cpp +++ b/Applications/Utils/MeshGeoTools/Raster2Mesh.cpp @@ -13,16 +13,15 @@ // ThirdParty #include <tclap/CmdLine.h> -#include "InfoLib/GitInfo.h" - +#include "Applications/FileIO/AsciiRasterInterface.h" #include "GeoLib/Raster.h" +#include "InfoLib/GitInfo.h" +#include "MeshLib/IO/VtkIO/VtuInterface.h" #include "MeshLib/Mesh.h" #include "MeshLib/MeshEnums.h" -#include "MeshLib/IO/VtkIO/VtuInterface.h" #include "MeshLib/MeshGenerators/RasterToMesh.h" -#include "Applications/FileIO/AsciiRasterInterface.h" -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { TCLAP::CmdLine cmd( "Converts an ASCII raster file (*.asc) into a 2D triangle- or " @@ -59,17 +58,15 @@ int main(int argc, char *argv[]) "e", "elem-type", "The element type used in the resulting OGS mesh.", true, "", &allowed_elem_vals); cmd.add(arg_elem_type); - TCLAP::ValueArg<std::string> output_arg( - "o", "output", - "Name of the output mesh (*.vtu)", - true, "", "output file name"); + TCLAP::ValueArg<std::string> output_arg("o", "output", + "Name of the output mesh (*.vtu)", + true, "", "output file name"); cmd.add(output_arg); - TCLAP::ValueArg<std::string> input_arg( - "i", "input", - "Name of the input raster (*.asc)", - true, "", "input file name"); + TCLAP::ValueArg<std::string> input_arg("i", "input", + "Name of the input raster (*.asc)", + true, "", "input file name"); cmd.add(input_arg); - cmd.parse( argc, argv ); + cmd.parse(argc, argv); std::string const input_name = input_arg.getValue().c_str(); std::string const output_name = output_arg.getValue().c_str(); @@ -89,7 +86,8 @@ int main(int argc, char *argv[]) intensity_type = MeshLib::UseIntensityAs::DATAVECTOR; std::string array_name = "Values"; - if (intensity_type == MeshLib::UseIntensityAs::DATAVECTOR && array_name_arg.isSet()) + if (intensity_type == MeshLib::UseIntensityAs::DATAVECTOR && + array_name_arg.isSet()) array_name = array_name_arg.getValue().c_str(); else if (intensity_type == MeshLib::UseIntensityAs::MATERIALS) array_name = "MaterialIDs"; diff --git a/Applications/Utils/MeshGeoTools/VerticalSliceFromLayers.cpp b/Applications/Utils/MeshGeoTools/VerticalSliceFromLayers.cpp index a542e141cc7432b8718290289f9640ece711ee2d..f388c91aa7993ccd4690586bd497d220071e0251 100644 --- a/Applications/Utils/MeshGeoTools/VerticalSliceFromLayers.cpp +++ b/Applications/Utils/MeshGeoTools/VerticalSliceFromLayers.cpp @@ -15,6 +15,7 @@ // ThirdParty #include <tclap/CmdLine.h> + #include <QCoreApplication> #include "Applications/FileIO/Gmsh/GMSHInterface.h" @@ -183,7 +184,8 @@ std::pair<Eigen::Matrix3d, double> rotateGeometryToXY( GeoLib::rotatePoints(rotation_matrix, points.begin(), points.end()); GeoLib::AABB aabb(points.begin(), points.end()); - double const z_shift = (aabb.getMinPoint()[2] + aabb.getMaxPoint()[2]) / 2.0; + double const z_shift = + (aabb.getMinPoint()[2] + aabb.getMaxPoint()[2]) / 2.0; std::for_each(points.begin(), points.end(), [z_shift](GeoLib::Point* p) { (*p)[2] -= z_shift; }); return {rotation_matrix, z_shift}; @@ -323,7 +325,7 @@ void extractBoundaries(MeshLib::Mesh const& mesh, continue; } // elements located at top or bottom - if (dist2.squaredNorm() < dist1.squaredNorm() ) + if (dist2.squaredNorm() < dist1.squaredNorm()) { top_bound_idx.push_back(id); left_bound_idx.push_back(id); diff --git a/Applications/Utils/MeshGeoTools/computeSurfaceNodeIDsInPolygonalRegion.cpp b/Applications/Utils/MeshGeoTools/computeSurfaceNodeIDsInPolygonalRegion.cpp index cbb08d44a623bcfe45c09e1f37a22a043359b43c..f86893798f94077b99a33022bc0d4b51ca8a396b 100644 --- a/Applications/Utils/MeshGeoTools/computeSurfaceNodeIDsInPolygonalRegion.cpp +++ b/Applications/Utils/MeshGeoTools/computeSurfaceNodeIDsInPolygonalRegion.cpp @@ -10,55 +10,62 @@ * http://www.opengeosys.org/project/license */ +#include <tclap/CmdLine.h> + #include <algorithm> #include <memory> #include <string> #include <vector> -#include <tclap/CmdLine.h> - #include "Applications/FileIO/readGeometryFromFile.h" -#include "InfoLib/GitInfo.h" #include "BaseLib/Error.h" #include "BaseLib/FileTools.h" #include "GeoLib/GEOObjects.h" #include "GeoLib/Polygon.h" +#include "InfoLib/GitInfo.h" #include "MeshLib/IO/readMeshFromFile.h" #include "MeshLib/Mesh.h" #include "MeshLib/MeshSurfaceExtraction.h" #include "MeshLib/Node.h" -void writeToFile(std::string const& id_area_fname, std::string const& csv_fname, +void writeToFile( + std::string const& id_area_fname, std::string const& csv_fname, std::vector<std::pair<std::size_t, double>> const& ids_and_areas, std::vector<MeshLib::Node*> const& mesh_nodes) { std::ofstream ids_and_area_out(id_area_fname); - if (!ids_and_area_out) { + if (!ids_and_area_out) + { OGS_FATAL("Unable to open the file '{:s}' - aborting.", id_area_fname); } std::ofstream csv_out(csv_fname); - if (!csv_out) { + if (!csv_out) + { OGS_FATAL("Unable to open the file '{:s}' - aborting.", csv_fname); } ids_and_area_out << std::setprecision(20); csv_out << std::setprecision(20); - ids_and_area_out << ids_and_areas[0].first << " " << ids_and_areas[0].second; - csv_out << "ID x y z area node_id\n"; // CSV header + ids_and_area_out << ids_and_areas[0].first << " " + << ids_and_areas[0].second; + csv_out << "ID x y z area node_id\n"; // CSV header csv_out << 0 << " " << *mesh_nodes[ids_and_areas[0].first] << ids_and_areas[0].second << " " << ids_and_areas[0].first; - for (std::size_t k(1); k<ids_and_areas.size(); k++) { + for (std::size_t k(1); k < ids_and_areas.size(); k++) + { ids_and_area_out << "\n" - << ids_and_areas[k].first << " " << ids_and_areas[k].second; - csv_out << "\n" << k << " " << *mesh_nodes[ids_and_areas[k].first] - << ids_and_areas[k].second << " " << ids_and_areas[k].first; + << ids_and_areas[k].first << " " + << ids_and_areas[k].second; + csv_out << "\n" + << k << " " << *mesh_nodes[ids_and_areas[k].first] + << ids_and_areas[k].second << " " << ids_and_areas[k].first; } ids_and_area_out << "\n"; csv_out << "\n"; } -int main (int argc, char* argv[]) +int main(int argc, char* argv[]) { TCLAP::CmdLine cmd( "Computes ids of mesh nodes that are in polygonal regions and resides " @@ -73,13 +80,14 @@ int main (int argc, char* argv[]) "Copyright (c) 2012-2021, OpenGeoSys Community " "(http://www.opengeosys.org)", ' ', GitInfoLib::GitInfo::ogs_version); - TCLAP::ValueArg<std::string> mesh_in("m", "mesh-input-file", - "the name of the file containing the input mesh", true, - "", "file name of input mesh"); + TCLAP::ValueArg<std::string> mesh_in( + "m", "mesh-input-file", + "the name of the file containing the input mesh", true, "", + "file name of input mesh"); cmd.add(mesh_in); - TCLAP::ValueArg<std::string> geo_in("g", "geo-file", - "the name of the gml file containing the polygons", true, - "", "file name of input geometry"); + TCLAP::ValueArg<std::string> geo_in( + "g", "geo-file", "the name of the gml file containing the polygons", + true, "", "file name of input geometry"); cmd.add(geo_in); TCLAP::ValueArg<std::string> gmsh_path_arg("g", "gmsh-path", @@ -88,7 +96,8 @@ int main (int argc, char* argv[]) cmd.add(gmsh_path_arg); cmd.parse(argc, argv); - std::unique_ptr<MeshLib::Mesh const> mesh(MeshLib::IO::readMeshFromFile(mesh_in.getValue())); + std::unique_ptr<MeshLib::Mesh const> mesh( + MeshLib::IO::readMeshFromFile(mesh_in.getValue())); INFO("Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(), mesh->getNumberOfElements()); @@ -104,31 +113,29 @@ int main (int argc, char* argv[]) Eigen::Vector3d const dir({0.0, 0.0, -1.0}); double angle(90); - auto computeElementTopSurfaceAreas = [](MeshLib::Mesh const& mesh, - Eigen::Vector3d const& d, double angle) - { - std::unique_ptr<MeshLib::Mesh> surface_mesh( - MeshLib::MeshSurfaceExtraction::getMeshSurface(mesh, d, angle)); - return MeshLib::MeshSurfaceExtraction::getSurfaceAreaForNodes( - *surface_mesh); - }; + auto computeElementTopSurfaceAreas = + [](MeshLib::Mesh const& mesh, Eigen::Vector3d const& d, double angle) { + std::unique_ptr<MeshLib::Mesh> surface_mesh( + MeshLib::MeshSurfaceExtraction::getMeshSurface(mesh, d, angle)); + return MeshLib::MeshSurfaceExtraction::getSurfaceAreaForNodes( + *surface_mesh); + }; std::vector<double> areas(computeElementTopSurfaceAreas(*mesh, dir, angle)); std::vector<MeshLib::Node*> all_sfc_nodes( - MeshLib::MeshSurfaceExtraction::getSurfaceNodes(*mesh, dir, angle) - ); + MeshLib::MeshSurfaceExtraction::getSurfaceNodes(*mesh, dir, angle)); std::for_each(all_sfc_nodes.begin(), all_sfc_nodes.end(), [](MeshLib::Node* p) { (*p)[2] = 0.0; }); std::vector<MeshLib::Node*> const& mesh_nodes(mesh->getNodes()); - GeoLib::PolylineVec const* ply_vec( - geo_objs.getPolylineVecObj(geo_name) - ); + GeoLib::PolylineVec const* ply_vec(geo_objs.getPolylineVecObj(geo_name)); std::vector<GeoLib::Polyline*> const& plys(*(ply_vec->getVector())); - for (std::size_t j(0); j<plys.size(); j++) { - if (! plys[j]->isClosed()) { + for (std::size_t j(0); j < plys.size(); j++) + { + if (!plys[j]->isClosed()) + { continue; } std::string polygon_name; @@ -141,13 +148,16 @@ int main (int argc, char* argv[]) GeoLib::Polygon const polygon{*plys[j]}; // ids of mesh nodes on surface that are within the given polygon std::vector<std::pair<std::size_t, double>> ids_and_areas; - for (std::size_t k(0); k<all_sfc_nodes.size(); k++) { + for (std::size_t k(0); k < all_sfc_nodes.size(); k++) + { MeshLib::Node const& pnt(*(all_sfc_nodes[k])); - if (polygon.isPntInPolygon(pnt[0], pnt[1], pnt[2])) { + if (polygon.isPntInPolygon(pnt[0], pnt[1], pnt[2])) + { ids_and_areas.emplace_back(pnt.getID(), areas[k]); } } - if (ids_and_areas.empty()) { + if (ids_and_areas.empty()) + { ERR("Polygonal part of surface '{:s}' doesn't contains nodes. No " "output will be generated.", polygon_name); diff --git a/Applications/Utils/MeshGeoTools/constructMeshesFromGeometry.cpp b/Applications/Utils/MeshGeoTools/constructMeshesFromGeometry.cpp index 78a6ab6970e3177b923eac3b7028cad8f9d32a80..53318974179d4b62799dca9ae9cdede218d3ed29 100644 --- a/Applications/Utils/MeshGeoTools/constructMeshesFromGeometry.cpp +++ b/Applications/Utils/MeshGeoTools/constructMeshesFromGeometry.cpp @@ -9,9 +9,9 @@ #include <tclap/CmdLine.h> -#include "InfoLib/GitInfo.h" #include "GeoLib/GEOObjects.h" #include "GeoLib/IO/XmlIO/Boost/BoostXmlGmlInterface.h" +#include "InfoLib/GitInfo.h" #include "MeshGeoToolsLib/ConstructMeshesFromGeometries.h" #include "MeshGeoToolsLib/SearchLength.h" #include "MeshLib/IO/readMeshFromFile.h" diff --git a/Applications/Utils/MeshGeoTools/createIntermediateRasters.cpp b/Applications/Utils/MeshGeoTools/createIntermediateRasters.cpp index d5e91c968f9ecb60a5f04a335bae9dddd143211d..719d95d6ccd0444fd2caadda31d90321a3476e89 100644 --- a/Applications/Utils/MeshGeoTools/createIntermediateRasters.cpp +++ b/Applications/Utils/MeshGeoTools/createIntermediateRasters.cpp @@ -7,15 +7,15 @@ * http://www.opengeosys.org/project/license */ +#include <tclap/CmdLine.h> + #include <memory> #include <string> -#include <tclap/CmdLine.h> - -#include "InfoLib/GitInfo.h" -#include "BaseLib/FileTools.h" #include "Applications/FileIO/AsciiRasterInterface.h" +#include "BaseLib/FileTools.h" #include "GeoLib/Raster.h" +#include "InfoLib/GitInfo.h" int main(int argc, char* argv[]) { @@ -122,7 +122,7 @@ int main(int argc, char* argv[]) double const step = (max - min) / static_cast<double>(n + 1); for (std::size_t i = 0; i < n; ++i) { - raster[i].push_back(max - ((i+1) * step)); + raster[i].push_back(max - ((i + 1) * step)); } } it2++; @@ -140,7 +140,8 @@ int main(int argc, char* argv[]) std::string const ext = BaseLib::getFileExtension(filename); GeoLib::Raster r(h1, raster[i].begin(), raster[i].end()); - FileIO::AsciiRasterInterface::writeRasterAsASC(r, basename + std::to_string(i) + ext); + FileIO::AsciiRasterInterface::writeRasterAsASC( + r, basename + std::to_string(i) + ext); INFO("Layer {:d} written.", i + 1); } return EXIT_SUCCESS; diff --git a/Applications/Utils/ModelPreparation/ComputeNodeAreasFromSurfaceMesh.cpp b/Applications/Utils/ModelPreparation/ComputeNodeAreasFromSurfaceMesh.cpp index 71808e5c8ff7447b9981235d3d3e6fe8acef5d7f..f35c3977da54fc01dec376fffccf3bec727dbdb4 100644 --- a/Applications/Utils/ModelPreparation/ComputeNodeAreasFromSurfaceMesh.cpp +++ b/Applications/Utils/ModelPreparation/ComputeNodeAreasFromSurfaceMesh.cpp @@ -9,41 +9,44 @@ * http://www.opengeosys.org/project/license */ +#include <tclap/CmdLine.h> + #include <fstream> #include <memory> #include <numeric> #include <string> #include <vector> -#include <tclap/CmdLine.h> - -#include "InfoLib/GitInfo.h" #include "BaseLib/Error.h" #include "BaseLib/FileTools.h" +#include "InfoLib/GitInfo.h" #include "MeshLib/IO/readMeshFromFile.h" #include "MeshLib/Mesh.h" #include "MeshLib/MeshSurfaceExtraction.h" #include "MeshLib/Node.h" -static -void writeToFile(std::string const& id_area_fname, std::string const& csv_fname, +static void writeToFile( + std::string const& id_area_fname, std::string const& csv_fname, std::vector<std::pair<std::size_t, double>> const& ids_and_areas, std::vector<MeshLib::Node*> const& mesh_nodes) { std::ofstream ids_and_area_out(id_area_fname); - if (!ids_and_area_out) { + if (!ids_and_area_out) + { OGS_FATAL("Unable to open the file '{:s}' - aborting.", id_area_fname); } std::ofstream csv_out(csv_fname); - if (!csv_out) { + if (!csv_out) + { OGS_FATAL("Unable to open the file '{:s}' - aborting.", csv_fname); } ids_and_area_out.precision(std::numeric_limits<double>::digits10); csv_out.precision(std::numeric_limits<double>::digits10); - csv_out << "ID x y z area node_id\n"; // CSV header - for (std::size_t k(0); k<ids_and_areas.size(); k++) { + csv_out << "ID x y z area node_id\n"; // CSV header + for (std::size_t k(0); k < ids_and_areas.size(); k++) + { ids_and_area_out << ids_and_areas[k].first << " " << ids_and_areas[k].second << "\n"; csv_out << k << " " << *(mesh_nodes[k]) << ids_and_areas[k].second @@ -53,7 +56,7 @@ void writeToFile(std::string const& id_area_fname, std::string const& csv_fname, csv_out << "\n"; } -int main (int argc, char* argv[]) +int main(int argc, char* argv[]) { TCLAP::CmdLine cmd( "The tool computes the area per node of the surface mesh and writes " @@ -64,18 +67,20 @@ int main (int argc, char* argv[]) "Copyright (c) 2012-2021, OpenGeoSys Community " "(http://www.opengeosys.org)", ' ', GitInfoLib::GitInfo::ogs_version); - TCLAP::ValueArg<std::string> mesh_in("i", "mesh-input-file", - "the name of the file containing the input mesh", true, - "", "file name of input mesh"); + TCLAP::ValueArg<std::string> mesh_in( + "i", "mesh-input-file", + "the name of the file containing the input mesh", true, "", + "file name of input mesh"); cmd.add(mesh_in); TCLAP::ValueArg<std::string> id_prop_name( "", "id-prop-name", "the name of the property containing the id information", false, "bulk_node_ids", "property name"); cmd.add(id_prop_name); - TCLAP::ValueArg<std::string> out_base_fname("p", "output-base-name", - "the path and base file name the output will be written to", false, - "", "output path and base name as one string"); + TCLAP::ValueArg<std::string> out_base_fname( + "p", "output-base-name", + "the path and base file name the output will be written to", false, "", + "output path and base name as one string"); cmd.add(out_base_fname); cmd.parse(argc, argv); @@ -125,8 +130,8 @@ int main (int argc, char* argv[]) { path = BaseLib::dropFileExtension(mesh_in.getValue()); } - std::string const id_and_area_fname(path+".txt"); - std::string const csv_fname(path+".csv"); + std::string const id_and_area_fname(path + ".txt"); + std::string const csv_fname(path + ".csv"); writeToFile(id_and_area_fname, csv_fname, ids_and_areas, surface_mesh->getNodes()); diff --git a/Applications/Utils/ModelPreparation/PartitionMesh/Metis.cpp b/Applications/Utils/ModelPreparation/PartitionMesh/Metis.cpp index d8d9fe748eeb87939be9468c572a43ae148f9d8e..3a08f783e93b413f63e3942aee1bff0078616ae3 100644 --- a/Applications/Utils/ModelPreparation/PartitionMesh/Metis.cpp +++ b/Applications/Utils/ModelPreparation/PartitionMesh/Metis.cpp @@ -63,7 +63,6 @@ std::vector<std::size_t> readMetisData(const std::string& file_name_base, std::vector<std::size_t> partition_ids(number_of_nodes); - std::size_t counter = 0; while (!npart_in.eof()) { diff --git a/Applications/Utils/ModelPreparation/PartitionMesh/NodeWiseMeshPartitioner.cpp b/Applications/Utils/ModelPreparation/PartitionMesh/NodeWiseMeshPartitioner.cpp index a9e57cfec4295be06d5e43019308469fb2a29c27..bcb9afd8096e7ee45cbcb4446735e8a9bb2557df 100644 --- a/Applications/Utils/ModelPreparation/PartitionMesh/NodeWiseMeshPartitioner.cpp +++ b/Applications/Utils/ModelPreparation/PartitionMesh/NodeWiseMeshPartitioner.cpp @@ -291,9 +291,8 @@ void NodeWiseMeshPartitioner::processPartition( _mesh->getNodes(), _nodes_partition_ids); partition.number_of_regular_base_nodes = partition.nodes.size(); - partition.number_of_regular_nodes = - partition.number_of_regular_base_nodes + - higher_order_regular_nodes.size(); + partition.number_of_regular_nodes = partition.number_of_regular_base_nodes + + higher_order_regular_nodes.size(); std::tie(partition.regular_elements, partition.ghost_elements) = findElementsInPartition(part_id, _mesh->getElements(), @@ -471,7 +470,7 @@ void addVtkGhostTypeProperty(MeshLib::Properties& partitioned_properties, vtk_ghost_type->resize(total_number_of_cells); std::size_t offset = 0; - for(auto const& partition : partitions) + for (auto const& partition : partitions) { offset += partition.regular_elements.size(); for (std::size_t i = 0; i < partition.ghost_elements.size(); ++i) @@ -484,7 +483,6 @@ void addVtkGhostTypeProperty(MeshLib::Properties& partitioned_properties, } offset += partition.ghost_elements.size(); } - } /// Partition existing properties and add vtkGhostType cell data array property. @@ -736,8 +734,7 @@ void NodeWiseMeshPartitioner::renumberNodeIndices( // -- Base nodes for (auto& partition : _partitions) { - for (std::size_t i = 0; i < partition.number_of_regular_base_nodes; - i++) + for (std::size_t i = 0; i < partition.number_of_regular_base_nodes; i++) { _nodes_global_ids[partition.nodes[i]->getID()] = node_global_id_offset; @@ -962,7 +959,8 @@ void getElementIntegerVariables( std::vector<long>& elem_info, long& counter) { - constexpr unsigned mat_id = 0; // TODO: Material ID to be set from the mesh data + constexpr unsigned mat_id = + 0; // TODO: Material ID to be set from the mesh data const long nn = elem.getNumberOfNodes(); elem_info[counter++] = mat_id; elem_info[counter++] = static_cast<long>(elem.getCellType()); diff --git a/Applications/Utils/ModelPreparation/convertVtkDataArrayToVtkDataArray.cpp b/Applications/Utils/ModelPreparation/convertVtkDataArrayToVtkDataArray.cpp index f60b120d7f6a758ecec16b65df692905a052e715..40aa9ba9a1425017edb94e614e4597c07ea75112 100644 --- a/Applications/Utils/ModelPreparation/convertVtkDataArrayToVtkDataArray.cpp +++ b/Applications/Utils/ModelPreparation/convertVtkDataArrayToVtkDataArray.cpp @@ -8,18 +8,16 @@ * */ +#include <tclap/CmdLine.h> + #include <algorithm> #include <cmath> #include <memory> #include <numeric> -#include <tclap/CmdLine.h> - #include "InfoLib/GitInfo.h" - #include "MeshLib/IO/readMeshFromFile.h" #include "MeshLib/IO/writeMeshToFile.h" - #include "MeshLib/Mesh.h" template <typename T1, typename T2> diff --git a/Applications/Utils/ModelPreparation/createNeumannBc.cpp b/Applications/Utils/ModelPreparation/createNeumannBc.cpp index 7ee126969037c29bd28a8b7035a9e1f7f4623dc0..596bfb34e572f1dabf0a5ed47a481201d4217fae 100644 --- a/Applications/Utils/ModelPreparation/createNeumannBc.cpp +++ b/Applications/Utils/ModelPreparation/createNeumannBc.cpp @@ -7,9 +7,10 @@ * */ -#include <fstream> #include <tclap/CmdLine.h> +#include <fstream> + #include "InfoLib/GitInfo.h" #include "MeshLib/Elements/Element.h" #include "MeshLib/IO/readMeshFromFile.h" @@ -124,7 +125,7 @@ int main(int argc, char* argv[]) "", "output file name"); cmd.add(result_file); - cmd.parse( argc, argv ); + cmd.parse(argc, argv); // read surface mesh std::unique_ptr<MeshLib::Mesh> surface_mesh( diff --git a/Applications/Utils/ModelPreparation/scaleProperty.cpp b/Applications/Utils/ModelPreparation/scaleProperty.cpp index 3fd5d9cb9701bd0296e446947079d0f01dd0f454..450f088b59e9bebfb44df4eb256f3c804deed119 100644 --- a/Applications/Utils/ModelPreparation/scaleProperty.cpp +++ b/Applications/Utils/ModelPreparation/scaleProperty.cpp @@ -8,13 +8,13 @@ * */ +#include <tclap/CmdLine.h> + #include <algorithm> -#include <memory> #include <cmath> +#include <memory> #include <numeric> -#include <tclap/CmdLine.h> - #include "InfoLib/GitInfo.h" #include "MeshLib/IO/readMeshFromFile.h" #include "MeshLib/IO/writeMeshToFile.h" @@ -49,15 +49,11 @@ int main(int argc, char* argv[]) "property name as string"); cmd.add(property_arg); - TCLAP::ValueArg<std::string> mesh_arg("m", - "mesh", - "the mesh is read from this file", - true, - "", - "file name"); + TCLAP::ValueArg<std::string> mesh_arg( + "m", "mesh", "the mesh is read from this file", true, "", "file name"); cmd.add(mesh_arg); - std::vector<std::string> allowed_units{ "mm/a", "mm/month", "m/s" }; + std::vector<std::string> allowed_units{"mm/a", "mm/month", "m/s"}; TCLAP::ValuesConstraint<std::string> allowed_units_constraints{ allowed_units}; TCLAP::ValueArg<std::string> unit_arg("u", diff --git a/Applications/Utils/OGSFileConverter/FileListDialog.cpp b/Applications/Utils/OGSFileConverter/FileListDialog.cpp index 2d01989732b20a0200a3449a96e1cf62dbbad2d0..c958240cdacb78a580feaca75433db510f4e318d 100644 --- a/Applications/Utils/OGSFileConverter/FileListDialog.cpp +++ b/Applications/Utils/OGSFileConverter/FileListDialog.cpp @@ -14,16 +14,19 @@ #include "FileListDialog.h" -#include <QSettings> #include <QFileInfo> #include <QFont> #include <QLineEdit> +#include <QSettings> #include "Applications/DataExplorer/Base/OGSError.h" #include "BaseLib/StringTools.h" FileListDialog::FileListDialog(FileType input, FileType output, QWidget* parent) -: QDialog(parent), _output_dir(""), _input_file_type(input), _output_file_type(output) + : QDialog(parent), + _output_dir(""), + _input_file_type(input), + _output_file_type(output) { setupUi(this); @@ -64,7 +67,8 @@ void FileListDialog::on_addButton_pressed() void FileListDialog::on_removeButton_pressed() { - QModelIndexList selected = this->listView->selectionModel()->selectedIndexes(); + QModelIndexList selected = + this->listView->selectionModel()->selectedIndexes(); for (auto& item : selected) { this->_allFiles.removeRow(item.row()); @@ -75,7 +79,8 @@ void FileListDialog::on_browseButton_pressed() { QSettings const settings("UFZ", "OpenGeoSys-5"); QFileInfo const fi(settings.value("lastOpenedOgsFileDirectory").toString()); - QString const dirName = QFileDialog::getExistingDirectory(this, "Save to", fi.absolutePath().append("/")); + QString const dirName = QFileDialog::getExistingDirectory( + this, "Save to", fi.absolutePath().append("/")); this->outputDirEdit->setText(dirName); } @@ -133,5 +138,7 @@ void FileListDialog::displayWarningLabel() const font.setBold(true); warningLabel->setFont(font); this->warningLabel->setStyleSheet("QLabel { color : red; }"); - this->warningLabel->setText("Warning: all scalar information except<br />MaterialIDs will be lost!"); + this->warningLabel->setText( + "Warning: all scalar information except<br />MaterialIDs will be " + "lost!"); } diff --git a/Applications/Utils/OGSFileConverter/OGSFileConverter.cpp b/Applications/Utils/OGSFileConverter/OGSFileConverter.cpp index f40de784429bf9bc4e41d52db608b1ba7e8ddd94..8ac13db8aa94cf39a5aeda398b31f6368c9b7ebb 100644 --- a/Applications/Utils/OGSFileConverter/OGSFileConverter.cpp +++ b/Applications/Utils/OGSFileConverter/OGSFileConverter.cpp @@ -38,7 +38,8 @@ OGSFileConverter::OGSFileConverter(std::string const& gmsh_path, OGSFileConverter::~OGSFileConverter() = default; -void OGSFileConverter::convertGML2GLI(const QStringList &input, const QString &output) const +void OGSFileConverter::convertGML2GLI(const QStringList& input, + const QString& output) const { if (input.empty()) { @@ -51,7 +52,9 @@ void OGSFileConverter::convertGML2GLI(const QStringList &input, const QString &o for (const auto& input_string : input) { const QFileInfo fi(input_string); - const std::string output_str = QString(output + "/" + fi.completeBaseName() + ".gli").toStdString(); + const std::string output_str = + QString(output + "/" + fi.completeBaseName() + ".gli") + .toStdString(); if (fileExists(output_str)) { @@ -82,7 +85,8 @@ void OGSFileConverter::convertGML2GLI(const QStringList &input, const QString &o OGSError::box("File conversion finished"); } -void OGSFileConverter::convertGLI2GML(const QStringList &input, const QString &output) const +void OGSFileConverter::convertGLI2GML(const QStringList& input, + const QString& output) const { if (input.empty()) { @@ -95,7 +99,9 @@ void OGSFileConverter::convertGLI2GML(const QStringList &input, const QString &o for (const auto& input_string : input) { const QFileInfo fi(input_string); - const std::string output_str = QString(output + "/" + fi.completeBaseName() + ".gml").toStdString(); + const std::string output_str = + QString(output + "/" + fi.completeBaseName() + ".gml") + .toStdString(); if (fileExists(output_str)) { @@ -130,7 +136,8 @@ void OGSFileConverter::convertGLI2GML(const QStringList &input, const QString &o OGSError::box("File conversion finished"); } -void OGSFileConverter::convertVTU2MSH(const QStringList &input, const QString &output) const +void OGSFileConverter::convertVTU2MSH(const QStringList& input, + const QString& output) const { if (input.empty()) { @@ -140,7 +147,9 @@ void OGSFileConverter::convertVTU2MSH(const QStringList &input, const QString &o for (const auto& input_string : input) { const QFileInfo fi(input_string); - const std::string output_str = QString(output + "/" + fi.completeBaseName() + ".msh").toStdString(); + const std::string output_str = + QString(output + "/" + fi.completeBaseName() + ".msh") + .toStdString(); if (fileExists(output_str)) { @@ -162,7 +171,8 @@ void OGSFileConverter::convertVTU2MSH(const QStringList &input, const QString &o OGSError::box("File conversion finished"); } -void OGSFileConverter::convertMSH2VTU(const QStringList &input, const QString &output) const +void OGSFileConverter::convertMSH2VTU(const QStringList& input, + const QString& output) const { if (input.empty()) { @@ -172,7 +182,9 @@ void OGSFileConverter::convertMSH2VTU(const QStringList &input, const QString &o for (const auto& input_string : input) { const QFileInfo fi(input_string); - const std::string output_str = QString(output + "/" + fi.completeBaseName() + ".vtu").toStdString(); + const std::string output_str = + QString(output + "/" + fi.completeBaseName() + ".vtu") + .toStdString(); if (fileExists(output_str)) { @@ -235,12 +247,13 @@ void OGSFileConverter::on_closeDialogButton_pressed() this->close(); } -bool OGSFileConverter::fileExists(const std::string &file_name) const +bool OGSFileConverter::fileExists(const std::string& file_name) const { std::ifstream const file(file_name.c_str()); if (file) { - QString const name = QString::fromStdString(BaseLib::extractBaseName(file_name)); + QString const name = + QString::fromStdString(BaseLib::extractBaseName(file_name)); return !OGSError::question( "The file '" + name + "' already exists.\n Do you want to overwrite it?", diff --git a/Applications/Utils/OGSFileConverter/main.cpp b/Applications/Utils/OGSFileConverter/main.cpp index d40db7bf31050e3e88925b44674b8c1cdab226ce..69d6ff5162d1b049ba7e385ecc9170abcbf81afb 100644 --- a/Applications/Utils/OGSFileConverter/main.cpp +++ b/Applications/Utils/OGSFileConverter/main.cpp @@ -7,14 +7,13 @@ * http://www.opengeosys.org/project/license */ -#include "OGSFileConverter.h" - -#include <clocale> #include <tclap/CmdLine.h> -#include "InfoLib/GitInfo.h" #include <QApplication> +#include <clocale> +#include "InfoLib/GitInfo.h" +#include "OGSFileConverter.h" int main(int argc, char* argv[]) { @@ -30,11 +29,11 @@ int main(int argc, char* argv[]) "the path to the gmsh binary", false, "", "path as string"); cmd.add(gmsh_path_arg); - cmd.parse( argc, argv ); + cmd.parse(argc, argv); QApplication app(argc, argv); - setlocale(LC_NUMERIC,"C"); + setlocale(LC_NUMERIC, "C"); auto* fc = new OGSFileConverter(gmsh_path_arg.getValue()); - fc->setWindowTitle( fc->windowTitle() ); + fc->setWindowTitle(fc->windowTitle()); fc->show(); int returncode = QApplication::exec(); delete fc; diff --git a/Applications/Utils/PostProcessing/Raster2PointCloud.cpp b/Applications/Utils/PostProcessing/Raster2PointCloud.cpp index af3238f38e273825f5ad823a88691cdabb7de664..66cc0b68a7d8c9cfb937e4d1a60911608feaa4e6 100644 --- a/Applications/Utils/PostProcessing/Raster2PointCloud.cpp +++ b/Applications/Utils/PostProcessing/Raster2PointCloud.cpp @@ -13,20 +13,17 @@ // ThirdParty #include <tclap/CmdLine.h> - -#include "InfoLib/GitInfo.h" - #include <vtkPolyDataAlgorithm.h> -#include <vtkXMLPolyDataWriter.h> #include <vtkSmartPointer.h> +#include <vtkXMLPolyDataWriter.h> -#include "BaseLib/FileTools.h" - -#include "Applications/FileIO/AsciiRasterInterface.h" #include "Applications/DataExplorer/VtkVis/VtkGeoImageSource.h" #include "Applications/DataExplorer/VtkVis/VtkImageDataToPointCloudFilter.h" +#include "Applications/FileIO/AsciiRasterInterface.h" +#include "BaseLib/FileTools.h" +#include "InfoLib/GitInfo.h" -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { TCLAP::CmdLine cmd( "Batch conversion of raster files into VTK point cloud data.\n" @@ -34,7 +31,8 @@ int main(int argc, char *argv[]) "number of random points based on the intensity value in each pixel " "(the higher the value, the more points. The [x,y]-extend of these " "random points is limited by the extent of the pixel they represent, " - "the elevation is limited by the max-elevation parameter. Likewise, the " + "the elevation is limited by the max-elevation parameter. Likewise, " + "the " "maximum number of points per pixel is limited by the max-points " "parameter. The increase of the number of points in relation to the " "pixel value is indicated by gamma, where 1 is a linear increase and " @@ -77,7 +75,7 @@ int main(int argc, char *argv[]) "'file1.asc', etc.", true, "", "input file name"); cmd.add(input_arg); - cmd.parse( argc, argv ); + cmd.parse(argc, argv); std::string const input_name = input_arg.getValue().c_str(); std::string const output_name = output_arg.getValue().c_str(); @@ -86,8 +84,7 @@ int main(int argc, char *argv[]) (max_height_arg.isSet()) ? max_height_arg.getValue() : 5000; std::size_t const max_points = (max_points_arg.isSet()) ? max_points_arg.getValue() : 1000; - double const gamma = - (gamma_arg.isSet()) ? gamma_arg.getValue() : 1; + double const gamma = (gamma_arg.isSet()) ? gamma_arg.getValue() : 1; std::string const ibase_name = BaseLib::dropFileExtension(input_name); std::string const ifile_ext = BaseLib::getFileExtension(input_name); @@ -101,9 +98,10 @@ int main(int argc, char *argv[]) double global_max = 0; std::size_t n_rasters = 0; - for (std::size_t i = 0; ; ++i) + for (std::size_t i = 0;; ++i) { - std::string const file_name = ibase_name + std::to_string(i) + ifile_ext; + std::string const file_name = + ibase_name + std::to_string(i) + ifile_ext; std::unique_ptr<GeoLib::Raster> r( FileIO::AsciiRasterInterface::getRasterFromASCFile(file_name)); if (r == nullptr) @@ -129,7 +127,7 @@ int main(int argc, char *argv[]) vtkSmartPointer<VtkGeoImageSource> geo_image = vtkSmartPointer<VtkGeoImageSource>::New(); geo_image->readImage(QString::fromStdString(file_name)); - VtkImageDataToPointCloudFilter *const point_cloud_filter = + VtkImageDataToPointCloudFilter* const point_cloud_filter = VtkImageDataToPointCloudFilter::New(); point_cloud_filter->SetInputConnection(geo_image->GetOutputPort()); geo_image->Update(); diff --git a/Applications/Utils/PostProcessing/postLIE.cpp b/Applications/Utils/PostProcessing/postLIE.cpp index 1425f83a3775357fa659400ceafe4778f92fdc11..b65803bb53054c830573a16b94fb47bd9606f87b 100644 --- a/Applications/Utils/PostProcessing/postLIE.cpp +++ b/Applications/Utils/PostProcessing/postLIE.cpp @@ -7,17 +7,16 @@ * http://www.opengeosys.org/project/license */ -#include <map> -#include <memory> -#include <vector> - #include <tclap/CmdLine.h> #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/xml_parser.hpp> +#include <map> +#include <memory> +#include <vector> -#include "InfoLib/GitInfo.h" #include "BaseLib/FileTools.h" +#include "InfoLib/GitInfo.h" #include "MeshLib/IO/readMeshFromFile.h" #include "MeshLib/IO/writeMeshToFile.h" #include "MeshLib/Mesh.h" diff --git a/Applications/Utils/SWMMConverter/SWMMConverter.cpp b/Applications/Utils/SWMMConverter/SWMMConverter.cpp index 1fa4fd9781ae57390459240b27c2af7fb7afccd1..7b3b988c3f846dbbafeab125dc5a79f13c7be23a 100644 --- a/Applications/Utils/SWMMConverter/SWMMConverter.cpp +++ b/Applications/Utils/SWMMConverter/SWMMConverter.cpp @@ -8,20 +8,16 @@ #include <tclap/CmdLine.h> +#include "Applications/FileIO/CsvInterface.h" #include "Applications/FileIO/SWMM/SWMMInterface.h" - -#include "InfoLib/GitInfo.h" #include "BaseLib/FileTools.h" #include "BaseLib/StringTools.h" - #include "GeoLib/GEOObjects.h" #include "GeoLib/IO/XmlIO/Boost/BoostXmlGmlInterface.h" - +#include "InfoLib/GitInfo.h" +#include "MeshLib/IO/VtkIO/VtuInterface.h" #include "MeshLib/Mesh.h" #include "MeshLib/Properties.h" -#include "MeshLib/IO/VtkIO/VtuInterface.h" - -#include "Applications/FileIO/CsvInterface.h" int writeGeoOutput(std::string input_file, std::string output_file) { diff --git a/Applications/Utils/SimpleMeshCreation/createMeshElemPropertiesFromASCRaster.cpp b/Applications/Utils/SimpleMeshCreation/createMeshElemPropertiesFromASCRaster.cpp index b7d5424a4de4aae9bcb02a71861fcab5422d0152..ae9b315f125c5c3d028b33cf377fa21a1cdd6bf6 100644 --- a/Applications/Utils/SimpleMeshCreation/createMeshElemPropertiesFromASCRaster.cpp +++ b/Applications/Utils/SimpleMeshCreation/createMeshElemPropertiesFromASCRaster.cpp @@ -9,18 +9,18 @@ * */ +#include <tclap/CmdLine.h> + #include <algorithm> -#include <memory> #include <cmath> +#include <memory> #include <numeric> -#include <tclap/CmdLine.h> - #include "Applications/FileIO/AsciiRasterInterface.h" -#include "InfoLib/GitInfo.h" #include "BaseLib/FileTools.h" #include "BaseLib/quicksort.h" #include "GeoLib/Raster.h" +#include "InfoLib/GitInfo.h" #include "MathLib/MathTools.h" #include "MeshLib/Elements/Element.h" #include "MeshLib/IO/readMeshFromFile.h" @@ -83,12 +83,8 @@ int main(int argc, char* argv[]) "property name as string"); cmd.add(property_arg); - TCLAP::ValueArg<std::string> mesh_arg("m", - "mesh", - "the mesh is read from this file", - true, - "", - "file name"); + TCLAP::ValueArg<std::string> mesh_arg( + "m", "mesh", "the mesh is read from this file", true, "", "file name"); cmd.add(mesh_arg); cmd.parse(argc, argv); diff --git a/Applications/Utils/SimpleMeshCreation/generateStructuredMesh.cpp b/Applications/Utils/SimpleMeshCreation/generateStructuredMesh.cpp index 37e8353b9ae44c1267628926b3214e760473f627..f75c9eb039d4aba17af8314b8036677639c78208 100644 --- a/Applications/Utils/SimpleMeshCreation/generateStructuredMesh.cpp +++ b/Applications/Utils/SimpleMeshCreation/generateStructuredMesh.cpp @@ -7,29 +7,26 @@ * http://www.opengeosys.org/project/license */ +#include <tclap/CmdLine.h> + #include <algorithm> #include <memory> #include <string> #include <vector> -#include <tclap/CmdLine.h> - -#include "InfoLib/GitInfo.h" #include "BaseLib/Error.h" #include "BaseLib/Subdivision.h" #include "BaseLib/TCLAPCustomOutput.h" - -#include "MeshLib/Mesh.h" -#include "MeshLib/Node.h" +#include "InfoLib/GitInfo.h" #include "MeshLib/Elements/Element.h" +#include "MeshLib/IO/writeMeshToFile.h" +#include "MeshLib/Mesh.h" #include "MeshLib/MeshEnums.h" #include "MeshLib/MeshGenerators/MeshGenerator.h" - -#include "MeshLib/IO/writeMeshToFile.h" +#include "MeshLib/Node.h" namespace { - /// Get dimension of the mesh element type. /// @param eleType element type unsigned getDimension(MeshLib::MeshElemType eleType) @@ -53,10 +50,9 @@ unsigned getDimension(MeshLib::MeshElemType eleType) return 0; } -} // end namespace - +} // end namespace -int main (int argc, char* argv[]) +int main(int argc, char* argv[]) { TCLAP::CmdLine cmd( "Structured mesh generator.\n" @@ -88,61 +84,69 @@ int main (int argc, char* argv[]) "pyramid", true, "line", &allowedVals); cmd.add(eleTypeArg); - TCLAP::ValueArg<std::string> mesh_out("o", "mesh-output-file", - "the name of the file the mesh will be written to", true, - "", "file name of output mesh"); + TCLAP::ValueArg<std::string> mesh_out( + "o", "mesh-output-file", + "the name of the file the mesh will be written to", true, "", + "file name of output mesh"); cmd.add(mesh_out); - TCLAP::ValueArg<double> lengthXArg("", "lx", - "length of a domain in x direction", false, 10.0, "real"); + TCLAP::ValueArg<double> lengthXArg( + "", "lx", "length of a domain in x direction", false, 10.0, "real"); cmd.add(lengthXArg); - TCLAP::ValueArg<double> lengthYArg("", "ly", - "length of a domain in y direction", false, 10.0, "real"); + TCLAP::ValueArg<double> lengthYArg( + "", "ly", "length of a domain in y direction", false, 10.0, "real"); cmd.add(lengthYArg); - TCLAP::ValueArg<double> lengthZArg("", "lz", - "length of a domain in z direction", false, 10.0, "real"); + TCLAP::ValueArg<double> lengthZArg( + "", "lz", "length of a domain in z direction", false, 10.0, "real"); cmd.add(lengthZArg); - TCLAP::ValueArg<unsigned> nsubdivXArg("", "nx", - "the number of subdivision in x direction", false, 10, "integer"); + TCLAP::ValueArg<unsigned> nsubdivXArg( + "", "nx", "the number of subdivision in x direction", false, 10, + "integer"); cmd.add(nsubdivXArg); - TCLAP::ValueArg<unsigned> nsubdivYArg("", "ny", - "the number of subdivision in y direction", false, 10, "integer"); + TCLAP::ValueArg<unsigned> nsubdivYArg( + "", "ny", "the number of subdivision in y direction", false, 10, + "integer"); cmd.add(nsubdivYArg); - TCLAP::ValueArg<unsigned> nsubdivZArg("", "nz", - "the number of subdivision in z direction", false, 10, "integer"); + TCLAP::ValueArg<unsigned> nsubdivZArg( + "", "nz", "the number of subdivision in z direction", false, 10, + "integer"); cmd.add(nsubdivZArg); // in case of gradual refinement - TCLAP::ValueArg<double> d0XArg("", "dx0", - "initial cell length in x direction", false, 1, "real"); + TCLAP::ValueArg<double> d0XArg( + "", "dx0", "initial cell length in x direction", false, 1, "real"); cmd.add(d0XArg); - TCLAP::ValueArg<double> d0YArg("", "dy0", - "initial cell length in y direction", false, 1, "real"); + TCLAP::ValueArg<double> d0YArg( + "", "dy0", "initial cell length in y direction", false, 1, "real"); cmd.add(d0YArg); - TCLAP::ValueArg<double> d0ZArg("", "dz0", - "initial cell length in z direction", false, 1, "real"); + TCLAP::ValueArg<double> d0ZArg( + "", "dz0", "initial cell length in z direction", false, 1, "real"); cmd.add(d0ZArg); - TCLAP::ValueArg<double> dmaxXArg("", "dx-max", - "maximum cell length in x direction", false, std::numeric_limits<double>::max(), "real"); + TCLAP::ValueArg<double> dmaxXArg( + "", "dx-max", "maximum cell length in x direction", false, + std::numeric_limits<double>::max(), "real"); cmd.add(dmaxXArg); - TCLAP::ValueArg<double> dmaxYArg("", "dy-max", - "maximum cell length in y direction", false, std::numeric_limits<double>::max(), "real"); + TCLAP::ValueArg<double> dmaxYArg( + "", "dy-max", "maximum cell length in y direction", false, + std::numeric_limits<double>::max(), "real"); cmd.add(dmaxYArg); - TCLAP::ValueArg<double> dmaxZArg("", "dz-max", - "maximum cell length in z direction", false, std::numeric_limits<double>::max(), "real"); + TCLAP::ValueArg<double> dmaxZArg( + "", "dz-max", "maximum cell length in z direction", false, + std::numeric_limits<double>::max(), "real"); cmd.add(dmaxZArg); - TCLAP::ValueArg<double> multiXArg("", "mx", - "multiplier in x direction", false, 1, "real"); + TCLAP::ValueArg<double> multiXArg("", "mx", "multiplier in x direction", + false, 1, "real"); cmd.add(multiXArg); - TCLAP::ValueArg<double> multiYArg("", "my", - "multiplier in y direction", false, 1, "real"); + TCLAP::ValueArg<double> multiYArg("", "my", "multiplier in y direction", + false, 1, "real"); cmd.add(multiYArg); - TCLAP::ValueArg<double> multiZArg("", "mz", - "multiplier in z direction", false, 1, "real"); + TCLAP::ValueArg<double> multiZArg("", "mz", "multiplier in z direction", + false, 1, "real"); cmd.add(multiZArg); // parse arguments cmd.parse(argc, argv); const std::string eleTypeName(eleTypeArg.getValue()); - const MeshLib::MeshElemType eleType = MeshLib::String2MeshElemType(eleTypeName); + const MeshLib::MeshElemType eleType = + MeshLib::String2MeshElemType(eleTypeName); const unsigned dim = getDimension(eleType); bool dim_used[3] = {false}; @@ -151,15 +155,22 @@ int main (int argc, char* argv[]) dim_used[i] = true; } - std::vector<TCLAP::ValueArg<double>*> vec_lengthArg = {&lengthXArg, &lengthYArg, &lengthZArg}; - std::vector<TCLAP::ValueArg<unsigned>*> vec_ndivArg = {&nsubdivXArg, &nsubdivYArg, &nsubdivZArg}; - std::vector<TCLAP::ValueArg<double>*> vec_d0Arg = {&d0XArg, &d0YArg, &d0ZArg}; - std::vector<TCLAP::ValueArg<double>*> vec_dMaxArg = {&dmaxXArg, &dmaxYArg, &dmaxZArg}; - std::vector<TCLAP::ValueArg<double>*> vec_multiArg = {&multiXArg, &multiYArg, &multiZArg}; + std::vector<TCLAP::ValueArg<double>*> vec_lengthArg = { + &lengthXArg, &lengthYArg, &lengthZArg}; + std::vector<TCLAP::ValueArg<unsigned>*> vec_ndivArg = { + &nsubdivXArg, &nsubdivYArg, &nsubdivZArg}; + std::vector<TCLAP::ValueArg<double>*> vec_d0Arg = {&d0XArg, &d0YArg, + &d0ZArg}; + std::vector<TCLAP::ValueArg<double>*> vec_dMaxArg = {&dmaxXArg, &dmaxYArg, + &dmaxZArg}; + std::vector<TCLAP::ValueArg<double>*> vec_multiArg = { + &multiXArg, &multiYArg, &multiZArg}; - const bool isLengthSet = std::any_of(vec_lengthArg.begin(), vec_lengthArg.end(), - [&](TCLAP::ValueArg<double> *arg){return arg->isSet();}); - if (!isLengthSet) { + const bool isLengthSet = + std::any_of(vec_lengthArg.begin(), vec_lengthArg.end(), + [&](TCLAP::ValueArg<double>* arg) { return arg->isSet(); }); + if (!isLengthSet) + { ERR("Missing input: Length information is not provided at all."); return EXIT_FAILURE; } @@ -177,7 +188,7 @@ int main (int argc, char* argv[]) std::vector<double> length(dim); std::vector<unsigned> n_subdivision(dim); std::vector<double> vec_dx(dim); - for (unsigned i=0; i<dim; i++) + for (unsigned i = 0; i < dim; i++) { length[i] = vec_lengthArg[i]->getValue(); n_subdivision[i] = vec_ndivArg[i]->getValue(); @@ -186,12 +197,15 @@ int main (int argc, char* argv[]) std::vector<std::unique_ptr<BaseLib::ISubdivision>> vec_div; vec_div.reserve(dim); - for (unsigned i=0; i<dim; i++) + for (unsigned i = 0; i < dim; i++) { - if (vec_multiArg[i]->isSet()) { - if (vec_ndivArg[i]->isSet()) { + if (vec_multiArg[i]->isSet()) + { + if (vec_ndivArg[i]->isSet()) + { // number of partitions in direction is specified - if (vec_d0Arg[i]->isSet()) { + if (vec_d0Arg[i]->isSet()) + { OGS_FATAL( "Specifying all of --m?, --d?0 and --n? for coordinate " "'?' is not supported."); @@ -199,13 +213,16 @@ int main (int argc, char* argv[]) vec_div.emplace_back(new BaseLib::GradualSubdivisionFixedNum( length[i], vec_ndivArg[i]->getValue(), vec_multiArg[i]->getValue())); - - } else { + } + else + { vec_div.emplace_back(new BaseLib::GradualSubdivision( length[i], vec_d0Arg[i]->getValue(), vec_dMaxArg[i]->getValue(), vec_multiArg[i]->getValue())); } - } else { + } + else + { vec_div.emplace_back( new BaseLib::UniformSubdivision(length[i], n_subdivision[i])); } @@ -215,33 +232,37 @@ int main (int argc, char* argv[]) std::unique_ptr<MeshLib::Mesh> mesh; switch (eleType) { - case MeshLib::MeshElemType::LINE: - mesh.reset(MeshLib::MeshGenerator::generateLineMesh(*vec_div[0])); - break; - case MeshLib::MeshElemType::TRIANGLE: - mesh.reset(MeshLib::MeshGenerator::generateRegularTriMesh(*vec_div[0], *vec_div[1])); - break; - case MeshLib::MeshElemType::QUAD: - mesh.reset(MeshLib::MeshGenerator::generateRegularQuadMesh(*vec_div[0], *vec_div[1])); - break; - case MeshLib::MeshElemType::HEXAHEDRON: - mesh.reset(MeshLib::MeshGenerator::generateRegularHexMesh(*vec_div[0], *vec_div[1], *vec_div[2])); - break; - case MeshLib::MeshElemType::PRISM: - mesh.reset(MeshLib::MeshGenerator::generateRegularPrismMesh( - length[0], length[1], length[2], n_subdivision[0], n_subdivision[1], - n_subdivision[2])); - break; - case MeshLib::MeshElemType::TETRAHEDRON: - mesh.reset(MeshLib::MeshGenerator::generateRegularTetMesh(*vec_div[0], *vec_div[1], *vec_div[2])); - break; - case MeshLib::MeshElemType::PYRAMID: - mesh.reset(MeshLib::MeshGenerator::generateRegularPyramidMesh( - *vec_div[0], *vec_div[1], *vec_div[2])); - break; - default: - ERR("Given element type is not supported."); - break; + case MeshLib::MeshElemType::LINE: + mesh.reset(MeshLib::MeshGenerator::generateLineMesh(*vec_div[0])); + break; + case MeshLib::MeshElemType::TRIANGLE: + mesh.reset(MeshLib::MeshGenerator::generateRegularTriMesh( + *vec_div[0], *vec_div[1])); + break; + case MeshLib::MeshElemType::QUAD: + mesh.reset(MeshLib::MeshGenerator::generateRegularQuadMesh( + *vec_div[0], *vec_div[1])); + break; + case MeshLib::MeshElemType::HEXAHEDRON: + mesh.reset(MeshLib::MeshGenerator::generateRegularHexMesh( + *vec_div[0], *vec_div[1], *vec_div[2])); + break; + case MeshLib::MeshElemType::PRISM: + mesh.reset(MeshLib::MeshGenerator::generateRegularPrismMesh( + length[0], length[1], length[2], n_subdivision[0], + n_subdivision[1], n_subdivision[2])); + break; + case MeshLib::MeshElemType::TETRAHEDRON: + mesh.reset(MeshLib::MeshGenerator::generateRegularTetMesh( + *vec_div[0], *vec_div[1], *vec_div[2])); + break; + case MeshLib::MeshElemType::PYRAMID: + mesh.reset(MeshLib::MeshGenerator::generateRegularPyramidMesh( + *vec_div[0], *vec_div[1], *vec_div[2])); + break; + default: + ERR("Given element type is not supported."); + break; } if (mesh)