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] Add new AddNodesFromOrderedContainer to model part #11503

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jrubiogonzalez
Copy link
Member

@jrubiogonzalez jrubiogonzalez commented Aug 24, 2023

📝 Description

This PR Adds a new method to the model part. This method greatly improves performance when the container to be added can be ensured to have the nodes only once and are stored ordered.

🆕 Changelog

  • Added new method to model_part.h
  • Added new test that test both previous AddNodes and new AddNodesFromOrderdContainer

@jrubiogonzalez jrubiogonzalez requested a review from a team as a code owner August 24, 2023 15:21
@jrubiogonzalez jrubiogonzalez self-assigned this Aug 24, 2023
loumalouomega
loumalouomega previously approved these changes Aug 24, 2023
Copy link
Member

@loumalouomega loumalouomega left a comment

Choose a reason for hiding this comment

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

Okay from my side

@loumalouomega loumalouomega changed the title [Core] Add new AddNodesFromOrderedContainer to model part [Core] Add new AddNodesFromOrderedContainer to model part Aug 24, 2023
@@ -399,6 +399,29 @@ class KRATOS_API(KRATOS_CORE) ModelPart final
KRATOS_CATCH("")
}

template<class TIteratorType >
void AddNodesFromOrderedContainer(TIteratorType nodes_begin, TIteratorType nodes_end, IndexType ThisIndex = 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

ThisIndex is not being used

Copy link
Member

Choose a reason for hiding this comment

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

Indeed

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, very minor, but we use camel case for parameters, and in this case they should start with "i" to indicate its an iterator

Copy link
Member

Choose a reason for hiding this comment

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

Also input should be in CammelCase format

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 was copying the interface from AddNodes, that TBH has same issue. It is not used. We can Remove both probably.

Copy link
Contributor

@matekelemen matekelemen left a comment

Choose a reason for hiding this comment

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

there are no guarantees that the output is sorted, apart from the user's good conscience that they provide a sorted input. The fact that PointerVectorSet exposes such manipulation of its underlying data structure is the exact problem detailed in #11363.

This should be handled by a range insert into PointerVectorSet and definitely not implemented from the outside.

Comment on lines +2076 to +2089
for(TIteratorType it1=bshort; it1!=eshort; it1++) {
while(it2!=elong && it2->Id()<it1->Id()) {
aux.push_back(*(it2.base()));
it2++;
}
aux.push_back(*(it1.base()) );
if(it2!=elong && (it1->Id() == it2->Id())) { //If both are the same, then we need to skip
it2++;
}
}
while(it2 != elong) {
aux.push_back(*(it2.base()));
it2++;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

this will still add duplicate nodes if it1 or it2 iterate through duplicate nodes

Copy link
Member Author

Choose a reason for hiding this comment

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

This is the exact goal of this MR.The condition is being able to provide unique and sorted nodes. It is quite common to have it as the mesh generation directly/indirectly is under our control.

Copy link
Member Author

Choose a reason for hiding this comment

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

To provide some context, we are experimenting with a voxel mesher. And for a benchmark example, with these changes it goes from 70s to 20s. Quite a lot if we want to be in the order 1min.

Copy link
Member

@rubenzorrilla rubenzorrilla left a comment

Choose a reason for hiding this comment

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

Changes in the ModelPart API need to be discussed in the @KratosMultiphysics/technical-committee.

EDIT: Though this is a justified demand, I tend to agree @matekelemen and @sunethwarna point about tackling this from the container itself, on top of the fact that there are many routines in Kratos assuming sorted and unique containers.

If we are to do this from the ModelPart as a sort of temporary patch, I think we should consider a different alternative that eases an eventual migration rather than creating a new function to an already exorbitant API.

@pooyan-dadvand
Copy link
Member

@KratosMultiphysics/technical-committee understands that the modifications proposed by #12087 can solve the problem of sort and unique and can be used as the low level implementation for this one. However, for adding the entities to the different levels of the modelpart hierarchy, we need a separate utility (not in the modelpart itself) to perform that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🏗 In progress
Development

Successfully merging this pull request may close these issues.

6 participants