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

Conversation

rubenzorrilla
Copy link
Member

📝 Description
So far, the GeometryContainer used the PointerHasMapSet as internal container for the geometries. @pooyan-dadvand as we discussed the other day, this PR upgrades it to use the customary PointerVectorSet.

Making it draft until we are sure that all the suites pass (I ran the main ones that might be directly affected by this change).

@rubenzorrilla
Copy link
Member Author

@sunethwarna @mpentek as far as I understand, this shouldn't interfere with your current PVS upgrade.

@sunethwarna
Copy link
Member

FYI: @rickyaristio @tteschemacher

@sunethwarna
Copy link
Member

sunethwarna commented Nov 11, 2024

@sunethwarna @mpentek as far as I understand, this shouldn't interfere with your current PVS upgrade.

Nice, finally.... :) @matekelemen

@tteschemacher
Copy link
Contributor

I'm not sure if that works. The hash map would be indexed by the identifier, while the pointer vector by the index. This is a matter of efficiency of the model becomes large.

@rubenzorrilla rubenzorrilla marked this pull request as ready for review November 11, 2024 18:11
@rubenzorrilla rubenzorrilla requested a review from a team as a code owner November 11, 2024 18:11
@rubenzorrilla
Copy link
Member Author

rubenzorrilla commented Nov 12, 2024

I'm not sure if that works. The hash map would be indexed by the identifier, while the pointer vector by the index. This is a matter of efficiency of the model becomes large.

mmm... I'm not sure I'm getting your point at all. The PointerVectorSet has an undeliying std::vector so the indexing is immediate (provided it is sorted of course).

EDIT: also note that this is what we actually do for elements/conditions, to which your orbservation would also be important.

@sunethwarna
Copy link
Member

sunethwarna commented Nov 12, 2024

@tteschemacher, as far as I see, the geometry identifier is also an int even though it can be hashed as well, so I don't see how the use of a map could be faster because both the PointerVectorSet and PointetHashMapSet will have the same O(log(N)) complexity if you query using the Id. The complexity will be O(1) if you query using the index for PointerVectorSet and you cannot do the same for the PointerHashMapSet. Am I wrong?

Another note: PointerHashMapSet uses an std::unordered_map in the back end to store data which does not allow random access iterators, this prohibits using any parallelization loops to work on the geometry container which would be a big drawback compared to PointerVectorSet.

Copy link
Member

@sunethwarna sunethwarna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are changing this to align with the other containers, then we need to fully remove the GeometryContainer and alias it to the PointerVectorSet of the geometries.

@rubenzorrilla
Copy link
Member Author

If we are changing this to align with the other containers, then we need to fully remove the GeometryContainer and alias it to the PointerVectorSet of the geometries.

In principle, makes sense for me. But I'd do it in a second stage (just in case...).

Copy link
Member

@pooyan-dadvand pooyan-dadvand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a minor comment

@@ -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()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't be: auto& r_geometry = *it_geom_begin

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can give it a try, but I think that this will give you the content of the begin() iterator of the underlying container, which is an std::vector or, in other words, a pointer to the geometry but not a reference to the geometry.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please give it a try! The PointerVectorSet has its * operator redefined.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You were right! I didn't remember the redefinition. Thanks for the hint.

@@ -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()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -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()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -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()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member

@pooyan-dadvand pooyan-dadvand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@rubenzorrilla rubenzorrilla merged commit 04ac567 into master Nov 22, 2024
11 checks passed
@rubenzorrilla rubenzorrilla deleted the core/geometry-container-with-pvs branch November 22, 2024 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

4 participants