-
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
Kratos Master-Slave Constraints to Neighbours Process and Utility #11129
Conversation
Needs to be cleaned from the previous functions.
e.g. ["DISPLACEMENT","PRESSURE"] -> ["DISPLACEMENT_X","DISPLACEMENT_Y","PRESSURE"]
rCloudOfDofs.resize(rVariableList.size()); | ||
|
||
// Resize rCloudOfDofs vectors to match the size of the cloud of nodes | ||
for (auto& dofs : rCloudOfDofs) |
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.
Usually we consider https://en.wikipedia.org/wiki/Indentation_style#K&R_style with Linux kernel variant
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.
At least I consider that and I ask other to use that
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.
Will update this.
// Loop over the variable list | ||
for (int j = 0; j < static_cast<int>(rVariableList.size()); j++) | ||
{ | ||
const auto& rVariable = rVariableList[j]; |
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.
Should be r_variable (snake case inside scope, cammel case for input)
NodesContainerType pSlaveNodes, | ||
double const Radius, | ||
ModelPart& rComputingModelPart, | ||
const std::vector<std::reference_wrapper<const Kratos::Variable<double>>>& rVariableList, |
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 didn't know about std::reference_wrapper, until now we were using variables raw pointers...
@rubenzorrilla I think it is now ready to check. I hope I covered all your suggestions. |
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.
minor comments
velocity_vector = MathUtils<double>::CrossProduct(angular_velocity_vector, position_vector); | ||
|
||
// Setting the node's velocity | ||
rNode.FastGetSolutionStepValue(VELOCITY_X) = velocity_vector[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.
this should be
noalias(rNode.FastGetSolutionStepValue(VELOCITY)) = velocity_vector
// Creating the angular velocity vector | ||
array_1d<double, 3> angular_velocity_vector = rOmega * rAxisOfRotation; | ||
|
||
thread_local array_1d<double, 3> position_vector; |
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.
please do not use the thread_local keyword.
in particular this is a stack array, so you can just define it there where you use it
rot_matrix(2, 1) = 2*(c*d+a*b); | ||
rot_matrix(2, 2) = a*a+d*d-b*b-c*c; | ||
|
||
thread_local array_1d<double, 3> rotated_point; |
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.
same
auto& r_point = rNode.GetInitialPosition().Coordinates(); | ||
|
||
// Shifting the rotation center to the origin | ||
auto centered_point = r_point - rCenterOfRotation; |
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.
define it here locally
|
||
// Shifting the point back and updating the node coordinates | ||
rotated_point += rCenterOfRotation; | ||
rNode.FastGetSolutionStepValue(MESH_DISPLACEMENT_X) = rotated_point[0] - rNode.X0(); |
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.
see the noalias comment above
noalias(rNode.FastGetSolutionStepValue(MESH_DISPLACEMENT)) = rotated_point - rNode.GetInitialPosition();
|
||
KRATOS_TRY; | ||
|
||
ResultNodesContainerType local_results(mMaxNumberOfNodes); |
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.
it would be better if you pass the local_results in the argument, making it a TLS variable if it is in a parallel loop
@loumalouomega if you can, please also take a look to this one. I implemented all suggestions. |
|
||
BuiltinTimer build_and_assign_mscs; | ||
|
||
// Declare thread-local storage (TLS) variables |
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.
👀
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.
My only concern would be to remove the old proceess, ia priori if in the Core is part of the API and in theory maybe someone else is using it
(I also have aestheic comments, but I am not going to be that "tocah****")
We renamed "AssignMPCsToNeighboursUtility" to "AssignMasterSlaveConstraintsToNeighboursUtility" because while "MPC" is a general term, the master-slave constraint is a specific type of MPC used in Kratos. We believe this new name provides a more accurate description. To ensure backward compatibility, we can provide an alias for the old process name that points to the new one. |
Here's my proposal to ensure we don't disrupt users relying on the old process name or settings: Process Name: I've retained the file Settings: For those using the old setting assign_mpcs_every_time_step, it'll be automatically swapped with the new reform_constraints_at_each_step, accompanied by a deprecation warning. I believe this approach ensures a smooth transition without breaking anyone's workflow. What do you think? Here's the code for the proposed changes ( import KratosMultiphysics
from KratosMultiphysics.assign_master_slave_constraints_to_neighbours_process import AssignMasterSlaveConstraintsToNeighboursProcess
def Factory(settings, model):
KratosMultiphysics.Logger.PrintWarning("assign_mpcs_to_neighbours_process", "This process is deprecated. Please use 'assign_master_slave_constraints_to_neighbours_process' instead.")
return AssignMPCsToNeighboursProcess(model, settings["Parameters"])
class AssignMPCsToNeighboursProcess(AssignMasterSlaveConstraintsToNeighboursProcess):
def __init__(self, model, settings):
# The setting 'assign_mpcs_every_time_step' was renamed to 'reform_constraints_at_each_step'
# This block ensures backward compatibility by updating the old setting to the new one and issuing a warning.
if settings.Has("assign_mpcs_every_time_step"):
KratosMultiphysics.Logger.PrintWarning("AssignMPCsToNeighboursProcess", "'assign_mpcs_every_time_step' is deprecated. Please use 'reform_constraints_at_each_step' instead.")
settings.AddValue("reform_constraints_at_each_step", settings["assign_mpcs_every_time_step"])
settings.RemoveValue("assign_mpcs_every_time_step")
super().__init__(model, settings) |
This pull request addresses the feedback and comments received on my previous pull request (#11083).
Main changes:
This approach allows the C++ code to receive the variable list and accommodates the 2D and 3D problem discussed in the previous pull request.
These changes enhance the clarity and consistency of the codebase and improve the usability of the utility. The updated tests ensure proper functionality and maintain code reliability.
I request the community to review this pull request and provide any further feedback or suggestions for improvement.
Thank you!