-
Notifications
You must be signed in to change notification settings - Fork 248
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
[GeoMechanicsApplication] Added a helper function that converts an angle in degrees to one in radians #11112
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.
would be cool to add this to the math_utils in the Core
|
||
double DegreesToRadians(double AngleInDegrees) | ||
{ | ||
return (AngleInDegrees * M_PI) / 180.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.
return (AngleInDegrees * M_PI) / 180.0; | |
return (AngleInDegrees * Globals::Pi) / 180.0; |
namespace Kratos | ||
{ | ||
|
||
double DegreesToRadians(double AngleInDegrees) |
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.
double DegreesToRadians(double AngleInDegrees) | |
double DegreesToRadians(const double AngleInDegrees) |
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'm not sure whether this actually improves the code. I have checked the C++ Core Guidelines and there they explicitly mention this situation as an exception to the rule that objects should be immutable whenever possible. From section Con 1: By default, make objects immutable it says (under the heading Exception):
Function parameters passed by value are rarely mutated, but also rarely declared
const
. To avoid confusion and lots of false positives, don’t enforce this rule for function parameters.
Also the accompanying example illustrates this:
void g(const int i) { ... } // pedantic
Since I don't see a good reason to deviate from that recommendation here, I'd like to keep it the way it is. (Unless you have a convincing reason why we should make it immutable here.) Thanks.
@@ -1236,5 +1236,8 @@ class StructuralMechanicsMathUtilities | |||
|
|||
private: | |||
};// class StructuralMechanicsMathUtilities | |||
|
|||
KRATOS_API(GEO_MECHANICS_APPLICATION) double DegreesToRadians(double AngleInDegrees); |
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're declaring the function at the global Kratos namespace. Though this is technically possible, in Kratos we always prefer the static
but inside a class approach. As suggested by @philbucher, I'd place this within the Kratos core math utils.
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.
Thanks, I will move the function to the Kratos core math utils as suggested by @philbucher and you. However, what is the rationale behind using a static member function rather than a nonmember function? If you're trying to limit its scope (which is a fair point), I feel that using a nested namespace is a simpler and cleaner way to achieve just that.
I will follow your suggestion anyway, but I'm just asking you to think about this one and to consider whether we may want to change this policy. Thanks.
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, my point is to basically limit its scope. About how to achieve it, i.e. the class vs namespace, this is a long term discussion in Kratos. At some point we tried to provide some guidelines & conclusions in #7434.
I have looked into that, but it's not as straightforward as it may seem at first sight. Let me explain. The whole problem here stems from the fact that the template parameter is actually redundant for this particular case. To me, whichever way we go here, it will never be really elegant in my opinion (please correct me if I have overlooked a good option). Therefore, I'm inclined to keep it the way it is now and leave it up to you to move it to a more general location (say somewhere in Kratos core) in a way that you feel best fits the way Kratos does things. Any feedback is greatly appreciated. Thanks. |
sounds reasonable @rubenzorrilla @loumalouomega maybe it is time to drop the template arg for the math utils? I don't think any type other than |
I started to remove it long time ago in a branch, I can retake it |
I was about to suggest this. |
Also sounds good to me. If I can contribute in any way to get this change in, I'm more than happy to help. Thanks. |
It is already done, as I said, I had the changes in a local branch and I only needed to do some clean up and push. |
291a7a3
to
2a69cd4
Compare
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.
thanks!
applications/GeoMechanicsApplication/custom_elements/steady_state_Pw_piping_element.cpp
Outdated
Show resolved
Hide resolved
Other changes include: - Replaced `M_PI` by `Globals::Pi`. - Use the `std` variant of functions `sin` and `cos`.
2a69cd4
to
d79d904
Compare
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.
Nice!
📝 Description
Added a helper function that converts an angle in degrees to one in radians. With this function in place, the hard-coded conversions have been replaced by calls to this function.
🆕 Changelog
DegreesToRadians
.