Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Use PointerVectorSet as geometry container #12843

Merged
merged 3 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions kratos/containers/geometry_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<std::size_t>,
GetGeometryId,
GeometryPointerType
> GeometriesMapType;
std::less<typename TGeometryType::IndexType>,
std::equal_to<typename TGeometryType::IndexType>>;

/// Geometry Iterator
typedef typename GeometriesMapType::iterator GeometryIterator;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions kratos/includes/model_part.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}

Expand Down
4 changes: 2 additions & 2 deletions kratos/sources/model_part.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2015,14 +2015,14 @@ void ModelPart::AddGeometries(std::vector<IndexType> 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<GeometryType::Pointer> 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;
}
Expand Down
6 changes: 3 additions & 3 deletions kratos/sources/model_part_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
for (std::size_t i_node = 0; i_node < r_geometry.size(); i_node++)
(*mpStream) << r_geometry[i_node].Id() << "\t";
(*mpStream) << std::endl;
Expand All @@ -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;
for (std::size_t i_node = 0; i_node < r_geometry.size(); i_node++)
(*mpStream) << r_geometry[i_node].Id() << "\t";
(*mpStream) << std::endl;
Expand All @@ -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;
for (std::size_t i_node = 0; i_node < r_geometry.size(); i_node++)
(*mpStream) << r_geometry[i_node].Id() << "\t";
(*mpStream) << std::endl;
Expand Down
10 changes: 5 additions & 5 deletions kratos/utilities/auxiliar_model_part_utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
for (auto& r_node : r_geometry) {
r_node.Set(TO_ERASE, false);
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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]);
}

Expand All @@ -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);

Expand Down
Loading