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] Small repair of normalize NORMAL in coordinate_transformation_utilities #5287

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

Conversation

bodhinandach
Copy link
Member

@bodhinandach bodhinandach commented Jul 22, 2019

@rubenzorrilla @jcotela I make a small check to avoid division by zero when normalizing NORMAL.

@bodhinandach bodhinandach added Kratos Core FastPR This Pr is simple and / or has been already tested and the revision should be fast labels Jul 22, 2019
Norm = sqrt(Norm);
for(typename TVectorType::iterator iComponent = rThis.begin(); iComponent < rThis.end(); ++iComponent)
*iComponent /= Norm;
Norm += (*iComponent)*(*iComponent);
Copy link
Member

Choose a reason for hiding this comment

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

Please reformat this as it used to be.

Copy link
Member Author

Choose a reason for hiding this comment

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

do you mean the tab? I dont change any other than tabbing it for clarity of the loop. But sure, I can return it back.

*iComponent /= Norm;
Norm += (*iComponent)*(*iComponent);
Norm = std::sqrt(Norm);
if (Norm > std::numeric_limits<double>::epsilon()){
Copy link
Member

Choose a reason for hiding this comment

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

What happens if the Norm is 0? IMO you should at least throw a warning.

Copy link
Member Author

Choose a reason for hiding this comment

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

So, if the norm is zero, it means that all the normal vector component is zero. You should not divide by zero.

Copy link
Member Author

@bodhinandach bodhinandach Jul 22, 2019

Choose a reason for hiding this comment

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

This happens to me only for moving slip surface. Which is completely normal, and doesn't require any warning.

Copy link
Member

Choose a reason for hiding this comment

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

@bodhinandach could you please clarify when do you encounter this situation (zero normal) and what would you expect to happen in that case? I would think that a normal with (close to) zero norm is quite useless to determine the correct orientation of the slip condition so, if anything, I would either ignore the rotation (and not rotate the affected nodes) or throw an error.

Copy link
Member Author

Choose a reason for hiding this comment

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

@jcotela So, in my case, I map normal vector from some type of "boundary" particles to the background node, for some slip boundary condition imposition, by using shape functions. These boundary particles can move through different background meshes.

If, suppose that at one point the particle is exactly or very closely located to one node, and therefore, the shape functions to the other nodes go to zero, zero normals can be found in those nodes. But as it is a temporary variable, and the information will be deleted in the next time step, it is normal for me to encounter this issue, and therefore such warning is not needed.

Copy link
Member

Choose a reason for hiding this comment

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

Okay, then I will derive the Normalize() in my utilities, and add the warning in the core?

I'll derive it in your class and keep the core one as it is.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, to avoid the if overhead. But let's wait for @jcotela 's opinion.

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 returned it back to what it is, if you want to add the error, I can also add it. Waiting for your decision.

Copy link
Member

Choose a reason for hiding this comment

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

I agree that the accepting a zero normal as valid input should be specific of the derived implementation (since it would not work as expected in the general case). I think it would still be good to have some kind of check, even if it is just in debug, for the base class, but I would not block this PR for this.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can add the check only in debug mode. @bodhinandach if you want to do it, feel free to proceed. If not, we can do it in another PR.

jcotela
jcotela previously approved these changes Jul 22, 2019
Copy link
Member

@jcotela jcotela left a comment

Choose a reason for hiding this comment

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

Approving. Feel free to merge as is or, if you prefer, add the changes to the base class and I'll re-review.

@bodhinandach
Copy link
Member Author

@rubenzorrilla As discussed with @jcotela, since the function Normalize() was templated before, it cant be overridden. I then remove the template. Please have another check.
I also added the debug if error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FastPR This Pr is simple and / or has been already tested and the revision should be fast Kratos Core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants