From 408e531daee64a21fd41814f90a32296946373a2 Mon Sep 17 00:00:00 2001 From: Dmitri Naumov <dmitri.naumov@ufz.de> Date: Tue, 21 Nov 2017 15:39:09 +0100 Subject: [PATCH] [A/U] postLIE; clang-format as prepartion. ... for following modifications. --- Applications/Utils/PostProcessing/postLIE.cpp | 50 ++++++----- ProcessLib/LIE/Common/MeshUtils.cpp | 56 ++++++------- ProcessLib/LIE/Common/MeshUtils.h | 29 +++---- ProcessLib/LIE/Common/PostUtils.cpp | 83 ++++++++++--------- ProcessLib/LIE/Common/PostUtils.h | 4 +- 5 files changed, 115 insertions(+), 107 deletions(-) diff --git a/Applications/Utils/PostProcessing/postLIE.cpp b/Applications/Utils/PostProcessing/postLIE.cpp index 70e814a9e57..290defeee42 100644 --- a/Applications/Utils/PostProcessing/postLIE.cpp +++ b/Applications/Utils/PostProcessing/postLIE.cpp @@ -30,8 +30,8 @@ namespace { - -void postVTU(std::string const& int_vtu_filename, std::string const& out_vtu_filename) +void postVTU(std::string const& int_vtu_filename, + std::string const& out_vtu_filename) { // read VTU with simulation results std::unique_ptr<MeshLib::Mesh const> mesh( @@ -49,22 +49,23 @@ void postVTU(std::string const& int_vtu_filename, std::string const& out_vtu_fil *mesh, vec_matrix_elements, vec_fracture_mat_IDs, vec_fracture_elements, vec_fracture_matrix_elements, vec_fracture_nodes); - ProcessLib::LIE::PostProcessTool post( - *mesh, vec_fracture_nodes, vec_fracture_matrix_elements); + ProcessLib::LIE::PostProcessTool post(*mesh, vec_fracture_nodes, + vec_fracture_matrix_elements); // create a new VTU file INFO("create %s", out_vtu_filename.c_str()); MeshLib::IO::writeMeshToFile(post.getOutputMesh(), out_vtu_filename); } - -void postPVD(std::string const& in_pvd_filename, std::string const& out_pvd_filename) +void postPVD(std::string const& in_pvd_filename, + std::string const& out_pvd_filename) { auto const in_pvd_file_dir = BaseLib::extractPath(in_pvd_filename); auto const out_pvd_file_dir = BaseLib::extractPath(out_pvd_filename); INFO("start reading the PVD file %s", in_pvd_filename.c_str()); boost::property_tree::ptree pt; - read_xml(in_pvd_filename, pt, boost::property_tree::xml_parser::trim_whitespace); + read_xml(in_pvd_filename, pt, + boost::property_tree::xml_parser::trim_whitespace); for (auto& dataset : pt.get_child("VTKFile.Collection")) { @@ -72,17 +73,21 @@ void postPVD(std::string const& in_pvd_filename, std::string const& out_pvd_file continue; // get VTU file name - auto const org_vtu_filename = dataset.second.get<std::string>("<xmlattr>.file"); - auto const org_vtu_filebasename = BaseLib::extractBaseName(org_vtu_filename); + auto const org_vtu_filename = + dataset.second.get<std::string>("<xmlattr>.file"); + auto const org_vtu_filebasename = + BaseLib::extractBaseName(org_vtu_filename); auto org_vtu_dir = BaseLib::extractPath(org_vtu_filename); if (org_vtu_dir.empty()) org_vtu_dir = in_pvd_file_dir; - auto const org_vtu_filepath = BaseLib::joinPaths(org_vtu_dir, org_vtu_filebasename); + auto const org_vtu_filepath = + BaseLib::joinPaths(org_vtu_dir, org_vtu_filebasename); INFO("processing %s...", org_vtu_filepath.c_str()); // post-process the VTU and save into the new file auto const dest_vtu_filename = "post_" + org_vtu_filebasename; - auto const dest_vtu_filepath = BaseLib::joinPaths(out_pvd_file_dir, dest_vtu_filename); + auto const dest_vtu_filepath = + BaseLib::joinPaths(out_pvd_file_dir, dest_vtu_filename); postVTU(org_vtu_filepath, dest_vtu_filepath); // create a new VTU file and update XML @@ -95,22 +100,20 @@ void postPVD(std::string const& in_pvd_filename, std::string const& out_pvd_file write_xml(out_pvd_filename, pt, std::locale(), settings); } -} // unnamed namespace - +} // unnamed namespace -int main (int argc, char* argv[]) +int main(int argc, char* argv[]) { ApplicationsLib::LogogSetup logog_setup; - TCLAP::CmdLine cmd("Post-process results of the LIE approach", - ' ', "0.1"); - TCLAP::ValueArg<std::string> arg_out_file("o", "output-file", - "the name of the new PVD or VTU file", true, - "", "path"); + TCLAP::CmdLine cmd("Post-process results of the LIE approach", ' ', "0.1"); + TCLAP::ValueArg<std::string> arg_out_file( + "o", "output-file", "the name of the new PVD or VTU file", true, "", + "path"); cmd.add(arg_out_file); - TCLAP::ValueArg<std::string> arg_in_file("i", "input-file", - "the original PVD or VTU file name", true, - "", "path"); + TCLAP::ValueArg<std::string> arg_in_file( + "i", "input-file", "the original PVD or VTU file name", true, "", + "path"); cmd.add(arg_in_file); cmd.parse(argc, argv); @@ -121,7 +124,8 @@ int main (int argc, char* argv[]) else if (in_file_ext == "vtu") postVTU(arg_in_file.getValue(), arg_out_file.getValue()); else - OGS_FATAL("The given file type (%s) is not supported.", in_file_ext.c_str()); + OGS_FATAL("The given file type (%s) is not supported.", + in_file_ext.c_str()); return EXIT_SUCCESS; } diff --git a/ProcessLib/LIE/Common/MeshUtils.cpp b/ProcessLib/LIE/Common/MeshUtils.cpp index 101212bdf24..a160c06c476 100644 --- a/ProcessLib/LIE/Common/MeshUtils.cpp +++ b/ProcessLib/LIE/Common/MeshUtils.cpp @@ -15,10 +15,8 @@ namespace ProcessLib { namespace LIE { - namespace { - // A class to check whether a node is located on a crack tip with // the following conditions: // - the number of connected fracture elements is one @@ -27,7 +25,7 @@ class IsCrackTip { public: explicit IsCrackTip(MeshLib::Mesh const& mesh) - : _mesh(mesh), _fracture_element_dim(mesh.getDimension()-1) + : _mesh(mesh), _fracture_element_dim(mesh.getDimension() - 1) { _is_internal_node.resize(mesh.getNumberOfNodes(), true); @@ -39,15 +37,14 @@ public: bool operator()(MeshLib::Node const& node) const { - if (!_is_internal_node[node.getID()] - || !_mesh.isBaseNode(node.getID())) + if (!_is_internal_node[node.getID()] || !_mesh.isBaseNode(node.getID())) return false; unsigned n_connected_fracture_elements = 0; for (MeshLib::Element const* e : node.getElements()) if (e->getDimension() == _fracture_element_dim) n_connected_fracture_elements++; - assert(n_connected_fracture_elements>0); + assert(n_connected_fracture_elements > 0); return (n_connected_fracture_elements == 1); } @@ -58,18 +55,15 @@ private: std::vector<bool> _is_internal_node; }; - -} // no named namespace - +} // namespace void getFractureMatrixDataInMesh( - MeshLib::Mesh const& mesh, - std::vector<MeshLib::Element*>& vec_matrix_elements, - std::vector<int>& vec_fracture_mat_IDs, - std::vector<std::vector<MeshLib::Element*>>& vec_fracture_elements, - std::vector<std::vector<MeshLib::Element*>>& vec_fracture_matrix_elements, - std::vector<std::vector<MeshLib::Node*>>& vec_fracture_nodes - ) + MeshLib::Mesh const& mesh, + std::vector<MeshLib::Element*>& vec_matrix_elements, + std::vector<int>& vec_fracture_mat_IDs, + std::vector<std::vector<MeshLib::Element*>>& vec_fracture_elements, + std::vector<std::vector<MeshLib::Element*>>& vec_fracture_matrix_elements, + std::vector<std::vector<MeshLib::Node*>>& vec_fracture_nodes) { IsCrackTip isCrackTip(mesh); @@ -96,26 +90,28 @@ void getFractureMatrixDataInMesh( // create a vector of fracture elements for each group vec_fracture_elements.resize(vec_fracture_mat_IDs.size()); - for (unsigned frac_id=0; frac_id<vec_fracture_mat_IDs.size(); frac_id++) + for (unsigned frac_id = 0; frac_id < vec_fracture_mat_IDs.size(); frac_id++) { const auto frac_mat_id = vec_fracture_mat_IDs[frac_id]; - std::vector<MeshLib::Element*> &vec_elements = vec_fracture_elements[frac_id]; + std::vector<MeshLib::Element*>& vec_elements = + vec_fracture_elements[frac_id]; std::copy_if(all_fracture_elements.begin(), all_fracture_elements.end(), std::back_inserter(vec_elements), [&](MeshLib::Element* e) { return (*opt_material_ids)[e->getID()] == frac_mat_id; }); - DBUG("-> found %d elements on the fracture %d", vec_elements.size(), frac_id); + DBUG("-> found %d elements on the fracture %d", vec_elements.size(), + frac_id); } // get a vector of fracture nodes vec_fracture_nodes.resize(vec_fracture_mat_IDs.size()); - for (unsigned frac_id=0; frac_id<vec_fracture_mat_IDs.size(); frac_id++) + for (unsigned frac_id = 0; frac_id < vec_fracture_mat_IDs.size(); frac_id++) { - std::vector<MeshLib::Node*> &vec_nodes = vec_fracture_nodes[frac_id]; + std::vector<MeshLib::Node*>& vec_nodes = vec_fracture_nodes[frac_id]; for (MeshLib::Element* e : vec_fracture_elements[frac_id]) { - for (unsigned i=0; i<e->getNumberOfNodes(); i++) + for (unsigned i = 0; i < e->getNumberOfNodes(); i++) { if (isCrackTip(*e->getNode(i))) continue; @@ -123,8 +119,7 @@ void getFractureMatrixDataInMesh( } } BaseLib::makeVectorUnique( - vec_nodes, - [](MeshLib::Node* node1, MeshLib::Node* node2) { + vec_nodes, [](MeshLib::Node* node1, MeshLib::Node* node2) { return node1->getID() < node2->getID(); }); DBUG("-> found %d nodes on the fracture %d", vec_nodes.size(), frac_id); @@ -136,7 +131,7 @@ void getFractureMatrixDataInMesh( { std::vector<MeshLib::Element*> vec_ele; // first, collect matrix elements - for (MeshLib::Element*e : fracture_elements) + for (MeshLib::Element* e : fracture_elements) { // it is sufficient to iterate over base nodes, because they are // already connected to all neighbours @@ -145,18 +140,19 @@ void getFractureMatrixDataInMesh( MeshLib::Node const* node = e->getNode(i); if (isCrackTip(*node)) continue; - for (unsigned j=0; j<node->getNumberOfElements(); j++) + for (unsigned j = 0; j < node->getNumberOfElements(); j++) { // only matrix elements - if (node->getElement(j)->getDimension() < mesh.getDimension()) + if (node->getElement(j)->getDimension() < + mesh.getDimension()) continue; - vec_ele.push_back(const_cast<MeshLib::Element*>(node->getElement(j))); + vec_ele.push_back( + const_cast<MeshLib::Element*>(node->getElement(j))); } } } BaseLib::makeVectorUnique( - vec_ele, - [](MeshLib::Element* e1, MeshLib::Element* e2) { + vec_ele, [](MeshLib::Element* e1, MeshLib::Element* e2) { return e1->getID() < e2->getID(); }); diff --git a/ProcessLib/LIE/Common/MeshUtils.h b/ProcessLib/LIE/Common/MeshUtils.h index a3235bd4853..d16bd13c78c 100644 --- a/ProcessLib/LIE/Common/MeshUtils.h +++ b/ProcessLib/LIE/Common/MeshUtils.h @@ -18,27 +18,28 @@ namespace ProcessLib { namespace LIE { - /** * get data about fracture and matrix elements/nodes from a mesh * - * @param mesh A mesh which includes fracture elements, i.e. lower-dimensional elements. - * It is assumed that elements forming a fracture have a distinct material ID. + * @param mesh A mesh which includes fracture elements, i.e. lower-dimensional + * elements. It is assumed that elements forming a fracture have a distinct + * material ID. * @param vec_matrix_elements a vector of matrix elements * @param vec_fracture_mat_IDs fracture material IDs found in the mesh - * @param vec_fracture_elements a vector of fracture elements (grouped by fracture IDs) - * @param vec_fracture_matrix_elements a vector of fracture elements and matrix elements - * connecting to the fracture (grouped by fracture IDs) - * @param vec_fracture_nodes a vector of fracture element nodes (grouped by fracture IDs) + * @param vec_fracture_elements a vector of fracture elements (grouped by + * fracture IDs) + * @param vec_fracture_matrix_elements a vector of fracture elements and matrix + * elements connecting to the fracture (grouped by fracture IDs) + * @param vec_fracture_nodes a vector of fracture element nodes (grouped by + * fracture IDs) */ void getFractureMatrixDataInMesh( - MeshLib::Mesh const& mesh, - std::vector<MeshLib::Element*>& vec_matrix_elements, - std::vector<int>& vec_fracture_mat_IDs, - std::vector<std::vector<MeshLib::Element*>>& vec_fracture_elements, - std::vector<std::vector<MeshLib::Element*>>& vec_fracture_matrix_elements, - std::vector<std::vector<MeshLib::Node*>>& vec_fracture_nodes - ); + MeshLib::Mesh const& mesh, + std::vector<MeshLib::Element*>& vec_matrix_elements, + std::vector<int>& vec_fracture_mat_IDs, + std::vector<std::vector<MeshLib::Element*>>& vec_fracture_elements, + std::vector<std::vector<MeshLib::Element*>>& vec_fracture_matrix_elements, + std::vector<std::vector<MeshLib::Node*>>& vec_fracture_nodes); } // namespace LIE } // namespace ProcessLib diff --git a/ProcessLib/LIE/Common/PostUtils.cpp b/ProcessLib/LIE/Common/PostUtils.cpp index 95db2e07caa..40b399035bc 100644 --- a/ProcessLib/LIE/Common/PostUtils.cpp +++ b/ProcessLib/LIE/Common/PostUtils.cpp @@ -12,42 +12,41 @@ #include <vector> #include "MeshLib/Elements/Element.h" -#include "MeshLib/Node.h" #include "MeshLib/MeshEditing/DuplicateMeshComponents.h" +#include "MeshLib/Node.h" namespace ProcessLib { namespace LIE { - namespace { - template <typename T> -inline void sort_unique(std::vector<T> &vec) +inline void sort_unique(std::vector<T>& vec) { std::sort(vec.begin(), vec.end()); vec.erase(std::unique(vec.begin(), vec.end()), vec.end()); } -} // no named namespace +} // namespace PostProcessTool::PostProcessTool( MeshLib::Mesh const& org_mesh, std::vector<std::vector<MeshLib::Node*>> const& vec_vec_fracture_nodes, - std::vector<std::vector<MeshLib::Element*>> const& vec_vec_fracture_matrix_elements) - :_org_mesh(org_mesh) + std::vector<std::vector<MeshLib::Element*>> const& + vec_vec_fracture_matrix_elements) + : _org_mesh(org_mesh) { - if (!org_mesh.getProperties().hasPropertyVector("displacement") - || !org_mesh.getProperties().hasPropertyVector("displacement_jump1") - || !org_mesh.getProperties().hasPropertyVector("levelset1") - ) + if (!org_mesh.getProperties().hasPropertyVector("displacement") || + !org_mesh.getProperties().hasPropertyVector("displacement_jump1") || + !org_mesh.getProperties().hasPropertyVector("levelset1")) { OGS_FATAL("The given mesh does not have relevant properties"); } // clone nodes and elements - std::vector<MeshLib::Node*> new_nodes(MeshLib::copyNodeVector(org_mesh.getNodes())); + std::vector<MeshLib::Node*> new_nodes( + MeshLib::copyNodeVector(org_mesh.getNodes())); std::vector<MeshLib::Element*> new_eles( MeshLib::copyElementVector(org_mesh.getElements(), new_nodes)); @@ -56,18 +55,22 @@ PostProcessTool::PostProcessTool( { for (auto const* org_node : vec_fracture_nodes) { - auto duplicated_node = new MeshLib::Node(org_node->getCoords(), new_nodes.size()); + auto duplicated_node = + new MeshLib::Node(org_node->getCoords(), new_nodes.size()); new_nodes.push_back(duplicated_node); - if (_map_dup_newNodeIDs.count(org_node->getID())>0) + if (_map_dup_newNodeIDs.count(org_node->getID()) > 0) OGS_FATAL("Intersection of fractures is not supported"); _map_dup_newNodeIDs[org_node->getID()] = duplicated_node->getID(); } } // split elements using the new duplicated nodes - for (unsigned fracture_id=0; fracture_id<vec_vec_fracture_matrix_elements.size(); fracture_id++) + for (unsigned fracture_id = 0; + fracture_id < vec_vec_fracture_matrix_elements.size(); + fracture_id++) { - auto const& vec_fracture_matrix_elements = vec_vec_fracture_matrix_elements[fracture_id]; + auto const& vec_fracture_matrix_elements = + vec_vec_fracture_matrix_elements[fracture_id]; auto const& vec_fracture_nodes = vec_vec_fracture_nodes[fracture_id]; auto prop_levelset = org_mesh.getProperties().getPropertyVector<double>( "levelset" + std::to_string(fracture_id + 1)); @@ -85,7 +88,7 @@ PostProcessTool::PostProcessTool( // replace fracture nodes with duplicated ones MeshLib::Element* e = new_eles[eid]; - for (unsigned i=0; i<e->getNumberOfNodes(); i++) + for (unsigned i = 0; i < e->getNumberOfNodes(); i++) { // only fracture nodes auto itr = _map_dup_newNodeIDs.find(e->getNodeIndex(i)); @@ -127,9 +130,9 @@ void PostProcessTool::createProperties() auto const* src_prop = src_properties.getPropertyVector<T>(name); auto const n_src_comp = src_prop->getNumberOfComponents(); - // convert 2D vector to 3D. Otherwise Paraview Calculator filter does not recognize - // it as a vector - auto const n_dest_comp = (n_src_comp==2) ? 3 : n_src_comp; + // convert 2D vector to 3D. Otherwise Paraview Calculator filter does + // not recognize it as a vector + auto const n_dest_comp = (n_src_comp == 2) ? 3 : n_src_comp; auto new_prop = MeshLib::getOrCreateMeshProperty<T>( *_output_mesh, name, src_prop->getMeshItemType(), n_dest_comp); @@ -138,7 +141,7 @@ void PostProcessTool::createProperties() { assert(new_prop->size() == _output_mesh->getNumberOfNodes() * n_dest_comp); - (void)(new_prop); // to avoid compilation warning. + (void)(new_prop); // to avoid compilation warning. } else if (src_prop->getMeshItemType() == MeshLib::MeshItemType::Cell) { @@ -164,25 +167,27 @@ void PostProcessTool::copyProperties() if (!src_properties.existsPropertyVector<T>(name)) continue; auto const* src_prop = src_properties.getPropertyVector<T>(name); - auto* dest_prop = _output_mesh->getProperties().getPropertyVector<T>(name); + auto* dest_prop = + _output_mesh->getProperties().getPropertyVector<T>(name); if (src_prop->getMeshItemType() == MeshLib::MeshItemType::Node) { auto const n_src_comp = src_prop->getNumberOfComponents(); auto const n_dest_comp = dest_prop->getNumberOfComponents(); // copy existing - for (unsigned i=0; i<_org_mesh.getNumberOfNodes(); i++) + for (unsigned i = 0; i < _org_mesh.getNumberOfNodes(); i++) { - for (unsigned j=0; j<n_src_comp; j++) - (*dest_prop)[i*n_dest_comp+j] = (*src_prop)[i*n_src_comp+j]; + for (unsigned j = 0; j < n_src_comp; j++) + (*dest_prop)[i * n_dest_comp + j] = + (*src_prop)[i * n_src_comp + j]; // set zero for components not existing in the original - for (unsigned j=n_src_comp; j<n_dest_comp; j++) - (*dest_prop)[i*n_dest_comp+j] = 0; + for (unsigned j = n_src_comp; j < n_dest_comp; j++) + (*dest_prop)[i * n_dest_comp + j] = 0; } // copy duplicated for (auto itr : _map_dup_newNodeIDs) { - for (unsigned j=0; j<n_dest_comp; j++) + for (unsigned j = 0; j < n_dest_comp; j++) (*dest_prop)[itr.second * n_dest_comp + j] = (*dest_prop)[itr.first * n_dest_comp + j]; } @@ -203,23 +208,25 @@ void PostProcessTool::copyProperties() void PostProcessTool::calculateTotalDisplacement(unsigned const n_fractures) { - auto const& u = *_output_mesh->getProperties().getPropertyVector<double>("displacement"); + auto const& u = *_output_mesh->getProperties().getPropertyVector<double>( + "displacement"); auto const n_u_comp = u.getNumberOfComponents(); assert(u.size() == _output_mesh->getNodes().size() * 3); auto& total_u = *_output_mesh->getProperties().createNewPropertyVector<double>( "u", MeshLib::MeshItemType::Node, n_u_comp); total_u.resize(u.size()); - for (unsigned i=0; i<_output_mesh->getNodes().size(); i++) + for (unsigned i = 0; i < _output_mesh->getNodes().size(); i++) { - for (unsigned j=0; j<n_u_comp; j++) - total_u[i*n_u_comp+j] = u[i*n_u_comp+j]; + for (unsigned j = 0; j < n_u_comp; j++) + total_u[i * n_u_comp + j] = u[i * n_u_comp + j]; } - for (unsigned fracture_id=0; fracture_id<n_fractures; fracture_id++) + for (unsigned fracture_id = 0; fracture_id < n_fractures; fracture_id++) { // nodal value of levelset - std::vector<double> nodal_levelset(_output_mesh->getNodes().size(), 0.0); + std::vector<double> nodal_levelset(_output_mesh->getNodes().size(), + 0.0); auto const& ele_levelset = *_output_mesh->getProperties().getPropertyVector<double>( "levelset" + std::to_string(fracture_id + 1)); @@ -231,7 +238,7 @@ void PostProcessTool::calculateTotalDisplacement(unsigned const n_fractures) if (e_levelset == 0) continue; - for (unsigned i=0; i<e->getNumberOfNodes(); i++) + for (unsigned i = 0; i < e->getNumberOfNodes(); i++) nodal_levelset[e->getNodeIndex(i)] = e_levelset; } @@ -241,11 +248,11 @@ void PostProcessTool::calculateTotalDisplacement(unsigned const n_fractures) "displacement_jump" + std::to_string(fracture_id + 1)); for (unsigned i = 0; i < _output_mesh->getNodes().size(); i++) { - for (unsigned j=0; j<n_u_comp; j++) - total_u[i*n_u_comp+j] += nodal_levelset[i] * g[i*n_u_comp+j]; + for (unsigned j = 0; j < n_u_comp; j++) + total_u[i * n_u_comp + j] += + nodal_levelset[i] * g[i * n_u_comp + j]; } } - } } // namespace LIE diff --git a/ProcessLib/LIE/Common/PostUtils.h b/ProcessLib/LIE/Common/PostUtils.h index 2492cd0efe1..27a3b6b3f78 100644 --- a/ProcessLib/LIE/Common/PostUtils.h +++ b/ProcessLib/LIE/Common/PostUtils.h @@ -18,7 +18,6 @@ namespace ProcessLib { namespace LIE { - /// A tool for post-processing results from the LIE approach /// /// The tool creates a new mesh containing duplicated fracture nodes @@ -29,7 +28,8 @@ public: PostProcessTool( MeshLib::Mesh const& org_mesh, std::vector<std::vector<MeshLib::Node*>> const& vec_vec_fracture_nodes, - std::vector<std::vector<MeshLib::Element*>> const& vec_vec_fracutre_matrix_elements); + std::vector<std::vector<MeshLib::Element*>> const& + vec_vec_fracutre_matrix_elements); MeshLib::Mesh const& getOutputMesh() const { return *_output_mesh; } -- GitLab