From ab05c3c6ebe94387b5521b98a49064e381bc7750 Mon Sep 17 00:00:00 2001 From: rubenzorrilla Date: Mon, 11 Nov 2024 15:59:51 +0100 Subject: [PATCH 1/2] Use PVS as geometry container --- kratos/containers/geometry_container.h | 21 ++++++++----------- kratos/includes/model_part.h | 8 +++---- ...t_transfer_between_model_parts_process.cpp | 2 +- kratos/sources/model_part.cpp | 4 ++-- kratos/sources/model_part_io.cpp | 6 +++--- .../auxiliar_model_part_utilities.cpp | 10 ++++----- 6 files changed, 24 insertions(+), 27 deletions(-) diff --git a/kratos/containers/geometry_container.h b/kratos/containers/geometry_container.h index cfce8e5e9aa3..c26948b67b05 100644 --- a/kratos/containers/geometry_container.h +++ b/kratos/containers/geometry_container.h @@ -18,7 +18,7 @@ // Project includes #include "includes/define.h" -#include "containers/pointer_hash_map_set.h" +#include "containers/pointer_vector_set.h" namespace Kratos @@ -51,15 +51,12 @@ class GeometryContainer typedef typename TGeometryType::Pointer GeometryPointerType; - - /// Geometry Hash Map Container. - // Stores with hash of Ids to corresponding geometries. - typedef PointerHashMapSet< + /// Geometry pointer container + using GeometriesMapType = PointerVectorSet< TGeometryType, - std::hash, GetGeometryId, - GeometryPointerType - > GeometriesMapType; + std::less, + std::equal_to>; /// Geometry Iterator typedef typename GeometriesMapType::iterator GeometryIterator; @@ -152,7 +149,7 @@ class GeometryContainer auto i = mGeometries.find(GeometryId); KRATOS_ERROR_IF(i == mGeometries.end()) << " geometry index not found: " << GeometryId << "."; - return (i.base()->second); + return *(i.base()); } /// Returns the const Geometry::Pointer corresponding to its Id @@ -161,7 +158,7 @@ class GeometryContainer auto i = mGeometries.find(GeometryId); KRATOS_ERROR_IF(i == mGeometries.end()) << " geometry index not found: " << GeometryId << "."; - return (i.base()->second); + return *(i.base()); } /// Returns the Geometry::Pointer corresponding to its name @@ -171,7 +168,7 @@ class GeometryContainer auto i = mGeometries.find(hash_index); KRATOS_ERROR_IF(i == mGeometries.end()) << " geometry index not found: " << GeometryName << "."; - return (i.base()->second); + return *(i.base()); } /// Returns the Geometry::Pointer corresponding to its name @@ -181,7 +178,7 @@ class GeometryContainer auto i = mGeometries.find(hash_index); KRATOS_ERROR_IF(i == mGeometries.end()) << " geometry index not found: " << GeometryName << "."; - return (i.base()->second); + return *(i.base()); } /// Returns a reference geometry corresponding to the id diff --git a/kratos/includes/model_part.h b/kratos/includes/model_part.h index 6193db8924f8..b1b38b85efb2 100644 --- a/kratos/includes/model_part.h +++ b/kratos/includes/model_part.h @@ -1531,18 +1531,18 @@ class KRATOS_API(KRATOS_CORE) ModelPart final for(TIteratorType it = GeometryBegin; it!=GeometriesEnd; it++) { auto it_found = p_root_model_part->Geometries().find(it->Id()); if(it_found == p_root_model_part->GeometriesEnd()) { // Geometry does not exist in the top model part - aux_root.push_back( it.operator->() ); - aux.push_back( it.operator->() ); + aux_root.push_back(*(it.base())); + aux.push_back(*(it.base())); } else { // If it does exist verify it is the same geometry if (GeometryType::HasSameGeometryType(*it, *it_found)) { // Check the geometry type and connectivities for (IndexType i_pt = 0; i_pt < it->PointsNumber(); ++i_pt) { KRATOS_ERROR_IF((*it)[i_pt].Id() != (*it_found)[i_pt].Id()) << "Attempting to add a new geometry with Id: " << it->Id() << ". A same type geometry with same Id but different connectivities already exists." << std::endl; } - aux.push_back( it_found.operator->() ); // If the Id, type and connectivities are the same add the existing geometry + aux.push_back(*(it_found.base())); // If the Id, type and connectivities are the same add the existing geometry } else if(&(*it_found) != &(*it)) { // Check if the pointee coincides KRATOS_ERROR << "Attempting to add a new geometry with Id: " << it_found->Id() << ". A different geometry with the same Id already exists." << std::endl; } else { - aux.push_back( it.operator->() ); + aux.push_back(*(it.base())); } } } diff --git a/kratos/processes/fast_transfer_between_model_parts_process.cpp b/kratos/processes/fast_transfer_between_model_parts_process.cpp index 82be65a5fd50..c3cc13b2b3de 100644 --- a/kratos/processes/fast_transfer_between_model_parts_process.cpp +++ b/kratos/processes/fast_transfer_between_model_parts_process.cpp @@ -182,7 +182,7 @@ void FastTransferBetweenModelPartsProcess::TransferWithFlags() for(int i = 0; i < num_geometries; ++i) { auto it_geom = it_geom_begin; for (int j = 0; j < i; ++j) it_geom++; - geometries_buffer_vector.insert(it_geom.operator->()); + geometries_buffer_vector.insert(*(it_geom.base())); } } diff --git a/kratos/sources/model_part.cpp b/kratos/sources/model_part.cpp index 6b35160fdc92..db3f4db5e0bc 100644 --- a/kratos/sources/model_part.cpp +++ b/kratos/sources/model_part.cpp @@ -2015,14 +2015,14 @@ void ModelPart::AddGeometries(std::vector const& GeometriesIds) { KRATOS_TRY if(IsSubModelPart()) { // Does nothing if we are on the top model part - // Obtain from the root model part the corresponding list of geomnetries + // Obtain from the root model part the corresponding list of geometries ModelPart* p_root_model_part = &this->GetRootModelPart(); std::vector aux; aux.reserve(GeometriesIds.size()); for(auto& r_id : GeometriesIds) { auto it_found = p_root_model_part->Geometries().find(r_id); if(it_found != p_root_model_part->GeometriesEnd()) { - aux.push_back( it_found.operator->() ); + aux.push_back(*(it_found.base())); } else { KRATOS_ERROR << "The geometry with Id " << r_id << " does not exist in the root model part" << std::endl; } diff --git a/kratos/sources/model_part_io.cpp b/kratos/sources/model_part_io.cpp index cfb93eefb4b5..53618c624ca0 100644 --- a/kratos/sources/model_part_io.cpp +++ b/kratos/sources/model_part_io.cpp @@ -288,7 +288,7 @@ void ModelPartIO::WriteGeometries(GeometryContainerType const& rThisGeometries) (*mpStream) << "Begin Geometries\t" << geometry_name << std::endl; const auto it_geom_begin = rThisGeometries.Geometries().begin(); (*mpStream) << "\t" << it_geom_begin->Id() << "\t"; - auto& r_geometry = *(it_geom_begin.base()->second); + auto& r_geometry = *(*(it_geom_begin.base())); for (std::size_t i_node = 0; i_node < r_geometry.size(); i_node++) (*mpStream) << r_geometry[i_node].Id() << "\t"; (*mpStream) << std::endl; @@ -302,7 +302,7 @@ void ModelPartIO::WriteGeometries(GeometryContainerType const& rThisGeometries) for(std::size_t i = 1; i < rThisGeometries.NumberOfGeometries(); i++) { if(GeometryType::IsSame(*it_geom_previous, *it_geom_current)) { (*mpStream) << "\t" << it_geom_current->Id() << "\t"; - r_geometry = *(it_geom_current.base()->second); + r_geometry = *(*(it_geom_current.base())); for (std::size_t i_node = 0; i_node < r_geometry.size(); i_node++) (*mpStream) << r_geometry[i_node].Id() << "\t"; (*mpStream) << std::endl; @@ -313,7 +313,7 @@ void ModelPartIO::WriteGeometries(GeometryContainerType const& rThisGeometries) (*mpStream) << "Begin Geometries\t" << geometry_name << std::endl; (*mpStream) << "\t" << it_geom_current->Id() << "\t"; - r_geometry = *(it_geom_current.base()->second); + r_geometry = *(*(it_geom_current.base())); for (std::size_t i_node = 0; i_node < r_geometry.size(); i_node++) (*mpStream) << r_geometry[i_node].Id() << "\t"; (*mpStream) << std::endl; diff --git a/kratos/utilities/auxiliar_model_part_utilities.cpp b/kratos/utilities/auxiliar_model_part_utilities.cpp index a0d3b425e744..b7fc97eaf27b 100644 --- a/kratos/utilities/auxiliar_model_part_utilities.cpp +++ b/kratos/utilities/auxiliar_model_part_utilities.cpp @@ -473,7 +473,7 @@ void AuxiliarModelPartUtilities::RemoveOrphanNodesFromSubModelParts() } const auto& r_geometries = r_sub_model_part.Geometries(); for (auto it_geom = r_geometries.begin(); it_geom != r_geometries.end(); ++it_geom) { - auto& r_geometry = *((it_geom.base())->second); + auto& r_geometry = *(*(it_geom.base())); for (auto& r_node : r_geometry) { r_node.Set(TO_ERASE, false); } @@ -620,7 +620,7 @@ ModelPart& AuxiliarModelPartUtilities::DeepCopyModelPart( // We copy the meshes (here is the heavy work) // NOTE: From the mesh I am not going to copy neither the Flags, neither the DataValueContainer, as those are unused and I think it is needed to open a discussion about clean up of the code and remove those derivations (multiple derivations have problems of overhead https://isocpp.org/wiki/faq/multiple-inheritance) - // RecursiveEnsureModelPartOwnsProperties(); //NOTE: To be activated in case people doesn't create the model parts properly and the properties are not created in the model part before assigning tho the elements and conditions. For the moment I would not activate it because I don't like to patronize the code with this kind of stuff. + // RecursiveEnsureModelPartOwnsProperties(); //NOTE: To be activated in case people doesn't create the model parts properly and the properties are not created in the model part before assigning tho the elements and conditions. For the moment I would not activate it because I don't like to patronize the code with this kind of stuff. // Copy properties, first using the copy constructor, and then reassigning each table so it doesn't point to the original one const auto& r_reference_properties = mrModelPart.rProperties(); @@ -697,7 +697,7 @@ ModelPart& AuxiliarModelPartUtilities::DeepCopyModelPart( // The database of geometries const auto& r_reference_geometries = mrModelPart.Geometries(); for (auto it_geom = r_reference_geometries.begin(); it_geom != r_reference_geometries.end(); ++it_geom) { - auto p_old_geometry = (it_geom.base())->second; + auto p_old_geometry = *(it_geom.base()); if (geometry_pointers_database.find(p_old_geometry) == geometry_pointers_database.end()) { const auto& p_old_points = p_old_geometry->Points(); if (points_geometry.size() != p_old_points.size()) { @@ -739,7 +739,7 @@ ModelPart& AuxiliarModelPartUtilities::DeepCopyModelPart( // We copy the geometries for (auto it_geom = r_reference_geometries.begin(); it_geom != r_reference_geometries.end(); ++it_geom) { - auto p_old_geometry = (it_geom.base())->second; + auto p_old_geometry = *(it_geom.base()); r_model_part.AddGeometry(geometry_pointers_database[p_old_geometry]); } @@ -748,7 +748,7 @@ ModelPart& AuxiliarModelPartUtilities::DeepCopyModelPart( // We cannot copy the parent model part as it will break the concept of deep copy, which a priori assumes this is the parent model part, so nothing to do here - // We copy the sub model parts + // We copy the sub model parts // NOTE: It is assumed that the submodelparts that working only with Id of the different entities will be enough, as we have ensured to copy everything, including the ids DeepCopySubModelPart(mrModelPart, r_model_part); From c97fc533b117c2100022d702e827cd674565792e Mon Sep 17 00:00:00 2001 From: rubenzorrilla Date: Thu, 21 Nov 2024 17:51:28 +0100 Subject: [PATCH 2/2] @pooyan-dadvand suggestion --- kratos/sources/model_part_io.cpp | 6 +++--- kratos/utilities/auxiliar_model_part_utilities.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/kratos/sources/model_part_io.cpp b/kratos/sources/model_part_io.cpp index 53618c624ca0..58e799b0c6a4 100644 --- a/kratos/sources/model_part_io.cpp +++ b/kratos/sources/model_part_io.cpp @@ -288,7 +288,7 @@ void ModelPartIO::WriteGeometries(GeometryContainerType const& rThisGeometries) (*mpStream) << "Begin Geometries\t" << geometry_name << std::endl; const auto it_geom_begin = rThisGeometries.Geometries().begin(); (*mpStream) << "\t" << it_geom_begin->Id() << "\t"; - auto& r_geometry = *(*(it_geom_begin.base())); + auto& r_geometry = *it_geom_begin; for (std::size_t i_node = 0; i_node < r_geometry.size(); i_node++) (*mpStream) << r_geometry[i_node].Id() << "\t"; (*mpStream) << std::endl; @@ -302,7 +302,7 @@ void ModelPartIO::WriteGeometries(GeometryContainerType const& rThisGeometries) for(std::size_t i = 1; i < rThisGeometries.NumberOfGeometries(); i++) { if(GeometryType::IsSame(*it_geom_previous, *it_geom_current)) { (*mpStream) << "\t" << it_geom_current->Id() << "\t"; - r_geometry = *(*(it_geom_current.base())); + r_geometry = *it_geom_current; for (std::size_t i_node = 0; i_node < r_geometry.size(); i_node++) (*mpStream) << r_geometry[i_node].Id() << "\t"; (*mpStream) << std::endl; @@ -313,7 +313,7 @@ void ModelPartIO::WriteGeometries(GeometryContainerType const& rThisGeometries) (*mpStream) << "Begin Geometries\t" << geometry_name << std::endl; (*mpStream) << "\t" << it_geom_current->Id() << "\t"; - r_geometry = *(*(it_geom_current.base())); + r_geometry = *it_geom_current; for (std::size_t i_node = 0; i_node < r_geometry.size(); i_node++) (*mpStream) << r_geometry[i_node].Id() << "\t"; (*mpStream) << std::endl; diff --git a/kratos/utilities/auxiliar_model_part_utilities.cpp b/kratos/utilities/auxiliar_model_part_utilities.cpp index b7fc97eaf27b..03e54d199229 100644 --- a/kratos/utilities/auxiliar_model_part_utilities.cpp +++ b/kratos/utilities/auxiliar_model_part_utilities.cpp @@ -473,7 +473,7 @@ void AuxiliarModelPartUtilities::RemoveOrphanNodesFromSubModelParts() } const auto& r_geometries = r_sub_model_part.Geometries(); for (auto it_geom = r_geometries.begin(); it_geom != r_geometries.end(); ++it_geom) { - auto& r_geometry = *(*(it_geom.base())); + auto& r_geometry = *it_geom; for (auto& r_node : r_geometry) { r_node.Set(TO_ERASE, false); }