-
Notifications
You must be signed in to change notification settings - Fork 247
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] Fixed issue with projection onto 2D2 line when input does not lie exactly on the line. #12637
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clean and clear improvement, with clear unit tests. I only have one very minor remark. Well done!
Tests are failing. What is exactly the issue? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blocking as this requires further review.
@loumalouomega This is a draft PR, we are currently looking into the issue and will request a review once the issue is solved. |
Tests passed now |
Indeed, we fixed the issue, it had to do with a tolerance which we believe should be removed at some point, but right now some functionality depends on this tolerance, meaning it is out of scope to do that now. |
I will approve as soon as @KratosMultiphysics/technical-committee agrees |
… results using a release build
kratos/geometries/line_2d_2.h
Outdated
// Project the point on the line in global space | ||
const array_1d<double, 3> vector_from_first_point_to_input = rPoint - r_first_point; | ||
const array_1d<double, 3> unity_line_direction = (r_second_point - r_first_point) / Length(); | ||
const auto projection_on_line = inner_prod(vector_from_first_point_to_input, unity_line_direction); | ||
|
||
const double length = Length(); | ||
// Conversion to local space | ||
constexpr double tolerance = 1e-14; | ||
rResult[0] = 2.0 * projection_on_line/(Length() + tolerance) - 1.0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to compute Length()
twice.
Besides, the job of that tolerance is probably to prevent division by zero errors but there's a naked division on line 1071. I'd either get rid of tolerance
completely (preferred - degenerate lines should be caught at construction) or apply it there as well to remain consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right about avoiding computing Length twice, but the tolerance is not because is degenerated, it is because the tolerance on the checks to avoid false negatives.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
False negatives?
As I understand this function doesn't do point membership tests but transforms a point from global to local space.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but that is used in the IsInside function, maybe the proper way should to check tolerance there (where Toelrance is an input)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, I like that idea better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the way IsInside
should probably be changed after this PR because an infinitely large cylinder would project to this line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, at first I removed the tolerance completely, but it failed some test cases in different applications, so it would require quite some effort to fix (simply adding the tolerance when calling IsInside didn't work unfortunately).
I can have a look again after I fixed the issue where using auto for an array1d gave issues, maybe the tolerance can now be removed safely.
However, if that's not the case and we need to change quite a bit of code, I would suggest to do that in a separate PR and keep this one focused on just fixing the projection and keep the tolerance that was already there.
Dear @loumalouomega, |
@loumalouomega: My two cents:
Thank you for your understanding and your willingness to improve the code base. |
Length is a very expensive operation (it computes sqrt, which is very expensive operation), that's why in the search implemnations the distance is not computed., the square of the distance is computed. This is a geometry, a extendently used class everywhere by everyone, performance is key.
I don't know who is this person, but sure is not working in HPC where performance is key, even is that implies hardcode and duplicate code in some situations.
I think that what here is said give me the reason.
Sorry, I will avoid that in teh future, it was a very small change and I did it in order to be less tiresome with very small changes.
I am not blocking to prevent accidental merge, here I am blockign until @KratosMultiphysics/technical-committee agrees as geometries are very important classes and can not be modified without their permision, even if that implies changes taking a lot of time (I have several PR that took 2 years to merge and one still waiting for approval because of this). |
|
Hi @KratosMultiphysics/technical-committee, would it be possible to have another look at this PR? It fixes quite a fundamental issue with projections onto a 2D2 line geometry and includes unit tests for the situations which result in incorrect results with the current code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@KratosMultiphysics/technical-committee agrees in principle, nevertheless we would observe that the tolerance is not needed at all...which i guess goes on the line of what @loumalouomega was observing
const double length_2 = std::sqrt( std::pow(rPoint[0] - r_second_point[0], 2) | ||
+ std::pow(rPoint[1] - r_second_point[1], 2)); | ||
// Conversion to local space | ||
constexpr double tolerance = 1e-14; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i understand that this tolerance was hardcoded before, but it is definitely now too nice ( for example it may fail for very small geometries).
Not telling that we should consider this as a blocker, but this is not a very robust solution.
Our point here is: why do we need the tolerance at all? anyhow you are assuming lenght to be different from zero, otherwise it would fail already in 1093
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I completely agree that we shouldn't have the tolerance here at all. I tried before to remove it, but the IsInside
function seems to expect the results from PointLocalCoordinates
to be as they are (as @loumalouomega mentioned), so tests started failing.
To keep the scope of this PR limited, I only fixed the projection itself, but kept the conversion of the projection to a
As proposed by @loumalouomega and @matekelemen, the IsInside function should be changed (i.e. the tolerance should be applied there instead of in PointLocalCoordinates
), so I would propose to investigate and change this in a separate small-scoped PR.
📝 Description
This PR aims to fix an issue found when testing the 2D2 line. When converting a point not exactly on the 2D2 Line, the projection was incorrect. By using an inner product instead of the norm2 distance to the input point to calculate the projected position on the line, we get expected results for the cases found in the added unit tests.
🆕 Changelog