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

[FastPR][Core] Geometries PrintData minor improvement #11446

Merged
merged 5 commits into from
Sep 5, 2023

Conversation

rubenzorrilla
Copy link
Member

📝 Description
This adds a minor improvement to the PrintData function of the base geometry as well as to the "standard" derived ones. Basically, now it is checked whether the points pointers are null or not to avoid segfaulting when calling the method. If the pointers are null we will be informing the user of the situation. Note that we cannot throw an error as this might be a valid situation (e.g. the geometry prototypes).

@rubenzorrilla rubenzorrilla added Kratos Core FastPR This Pr is simple and / or has been already tested and the revision should be fast Bugfix labels Aug 1, 2023
@rubenzorrilla rubenzorrilla self-assigned this Aug 1, 2023
@rubenzorrilla rubenzorrilla requested a review from a team as a code owner August 1, 2023 21:21
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.

Can be improved by improving the base class and call the base class in the derived classes when required

@rubenzorrilla
Copy link
Member Author

Can be improved by improving the base class and call the base class in the derived classes when required

Not sure at all. Note that the Jacobian might not be defined for all the geometries.

for (unsigned int i = 0; i < this->size(); ++i) {
rOStream << "\tPoint " << i + 1 << "\t : ";
mPoints[i].PrintData(rOStream);
if (mPoints(i) != nullptr) {
Copy link
Member

Choose a reason for hiding this comment

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

this seems like a big change

are we sure we want to allow null-points?

I think better not, imagine all the checks we would need to introduce 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

We are already allowing them. All the prototype geometries use nullptr points.

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 mean, I don't mind dropping this, the point is that I ended up spending more time debugging this than the stuff I wanted to 😄. IMO it makes sense to do this check for the output functions as it might be quite helpful for debugging.

Copy link
Member

Choose a reason for hiding this comment

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

I see, I made another suggestion :)

Copy link
Contributor

@matekelemen matekelemen Aug 9, 2023

Choose a reason for hiding this comment

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

I know this was implemented a long time ago, but now we have C++17 so there's no point in risking segfaults because of naked raw pointers => I suggest wrapping them in an std::optional.

If you're worried about messing up the memory alignment, I can come up with a version of optional for pointers that has an identical alignment to pointers, so that's not a problem.

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 think that even though @matekelemen 's comment is a good point, it will be still good to inform developers of the null points in the PrintData. In other words, introducing the std::optional when retrieving the points doesn't exclude informing about this situation to the user.

@rubenzorrilla
Copy link
Member Author

Finally I created a protected AllPointsAreValid inquiry method in the base Geometry. This is used in the derived geometries to check if the Jacobian has to be added to the standard geometry PrintData output as suggested by @philbucher and @loumalouomega.

Note that the base geometry PrintData method still checks if the pointers are null or not. If a point is found to be null, this is reported in the output stream.

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.

Looks now Okay to me

loumalouomega
loumalouomega previously approved these changes Sep 4, 2023
kratos/geometries/geometry.h Outdated Show resolved Hide resolved
kratos/geometries/hexahedra_3d_20.h Show resolved Hide resolved
}
}
return is_valid;
return std::none_of(mPoints.ptr_begin(), mPoints.ptr_end(), [](auto& pPoint){return pPoint == nullptr;});
Copy link
Member

Choose a reason for hiding this comment

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

great!

thanks to @matekelemen I learned abt this, so much nicer 🎉

philbucher
philbucher previously approved these changes Sep 5, 2023
* @return true All points are valid
* @return false At least one point has nullptr value
*/
bool AllPointsAreValid() const
Copy link
Member

Choose a reason for hiding this comment

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

BTW covering this with a test would be amazing 👀

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 tried, but I didn't come up with a simple solution since it is protected...

Co-authored-by: Philipp Bucher <philipp.bucher@tum.de>
@rubenzorrilla rubenzorrilla merged commit 8a92759 into master Sep 5, 2023
11 checks passed
@rubenzorrilla rubenzorrilla deleted the core/geometries-print-data-minor-improvements branch September 5, 2023 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bugfix FastPR This Pr is simple and / or has been already tested and the revision should be fast Kratos Core
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

4 participants