[GeoMechanicsApplication] Move normal load logic to cpp#11711
[GeoMechanicsApplication] Move normal load logic to cpp#11711
Conversation
- Corrected the return type of a copy assignment operator. - Added a missing default destructor for class `ApplyNormalLoadTableProcess`. - Added a missing `KRATOS_API(GEO_MECHANICS_APPLICATION)` (to export the class and make it available to the Python interface). - Added a missing pointer definition. - Removed an incorrect `return` statement from a Python script. - Fixed an incorrect condition (we missed the comparison to 0).
moved free functions from apply_scalar_constraint_table_process to a new class FunctionsForParameters added apply_normal_load_table_process in dgeosettlement
# Conflicts: # applications/GeoMechanicsApplication/custom_processes/apply_scalar_constraint_table_process.cpp
rfaasse
left a comment
There was a problem hiding this comment.
Nice clean and readable code! I only have 2 minor style related comments.
applications/GeoMechanicsApplication/custom_utilities/functions_for_parameters.cpp
Outdated
Show resolved
Hide resolved
applications/GeoMechanicsApplication/custom_utilities/functions_for_parameters.h
Outdated
Show resolved
Hide resolved
avdg81
left a comment
There was a problem hiding this comment.
Overall, your changes look nice and clean. I have several minor suggestions and a few things that need to be checked. Could you please take care of that? Thanks!
There was a problem hiding this comment.
To be consistent with the other files in the custom_utilities directory, I would suggest to rename this file to parameters_utilities.h. What do you think?
There was a problem hiding this comment.
Fully agreed, so the files are renamed etc.
|
|
||
| namespace Kratos { | ||
|
|
||
| class FunctonsForParameters |
There was a problem hiding this comment.
And perhaps rename the class to ParametersUtilities? Otherwise, I would at least correct a typo: FunctionsForParameters (note the missing i in Functons).
There was a problem hiding this comment.
the class is renamed as yo usuggested.
| { | ||
| auto normal_parameters = FunctonsForParameters::ExtractParameters(rProcessSettings, | ||
| NamesOfSettingsToCopy); | ||
| normal_parameters.AddValue("value", rProcessSettings["value"][0]); |
There was a problem hiding this comment.
I was just wandering whether the index here (0) also refers to the normal component of value...? If yes, then we might consider to define that index in a wider scope (e.g. as a class constant) and then replace those indices by the new constant. You have done that already in member functions IsNormalComponentActive and IsTangentialComponentActive, but perhaps we can use it here as well. What do you think?
There was a problem hiding this comment.
Indeed 0 and 1 are used in normal and tangential components. The constants are used now instead of the numbers.
| "second_reference_coordinate", | ||
| "specific_weight"}); | ||
| if (FunctonsForParameters::HasTableAttached(rProcessSettings)) { | ||
| NamesOfSettingsToCopy.insert(NamesOfSettingsToCopy.end(), { "table" }); |
There was a problem hiding this comment.
Although correct, I would simplify this to:
| NamesOfSettingsToCopy.insert(NamesOfSettingsToCopy.end(), { "table" }); | |
| NamesOfSettingsToCopy.emplace_back("table"); |
There was a problem hiding this comment.
Thank you. It is modified now.
| "third_reference_coordinate", | ||
| "specific_weight" }); | ||
| if (FunctonsForParameters::HasTableAttached(rProcessSettings)) { | ||
| NamesOfSettingsToCopy.insert(NamesOfSettingsToCopy.end(), { "table" }); |
There was a problem hiding this comment.
| NamesOfSettingsToCopy.insert(NamesOfSettingsToCopy.end(), { "table" }); | |
| NamesOfSettingsToCopy.emplace_back("table"); |
| //#include <memory> | ||
| //#include <vector> |
There was a problem hiding this comment.
Although strictly speaking these #includes could be left out (they are indirectly included through processes/process.h), I would insist to actually include them, since the class declares a data member (mProcesses) that requires them. We don't want to rely on accidental includes from other includes.
|
|
||
| void ExecuteInitialize() override; | ||
| void ExecuteInitializeSolutionStep() override; | ||
|
|
There was a problem hiding this comment.
Recently, we have added an override for member function Info() to class ApplyScalarConstraintTableProcess, which comes in really handy during debugging. I would suggest you to add a similar override here too.
There was a problem hiding this comment.
Thank you. Info() is added now.
| if (rSettings["table"][component].IsNumber()) { | ||
| return rSettings["table"][component].GetInt() != 0; | ||
| } | ||
|
|
||
| KRATOS_ERROR_IF_NOT(rSettings["table"][component].IsArray()) << "'table' is neither a single number nor an array of numbers"; | ||
|
|
||
| const auto& table = rSettings["table"][component]; | ||
| return std::any_of(table.begin(), table.end(), | ||
| [](const auto& value) {return value.GetInt() != 0; }); | ||
| } |
There was a problem hiding this comment.
I doubt whether this is correct. My understanding is that table either has a single number or an array of numbers. Now this new overload checks one particular element from the array variant of table. By inspecting the original Python code, I don't have the impression that we might have a table which is an array, where each element contains an array in turn (which would require two indices to access a number). Therefore, I believe we can simplify this function body to:
| if (rSettings["table"][component].IsNumber()) { | |
| return rSettings["table"][component].GetInt() != 0; | |
| } | |
| KRATOS_ERROR_IF_NOT(rSettings["table"][component].IsArray()) << "'table' is neither a single number nor an array of numbers"; | |
| const auto& table = rSettings["table"][component]; | |
| return std::any_of(table.begin(), table.end(), | |
| [](const auto& value) {return value.GetInt() != 0; }); | |
| } | |
| return rSettings["table"][component].GetInt() != 0; |
Could you please verify whether my understanding is correct? And if yes, please correct the implementation as suggested above. Thanks!
There was a problem hiding this comment.
Thank you for pointing. I also found only [ "table"].GetInt() and ["table"][0/1/2].GetInt(). The check is removed now.
- removed unnecessary indentation
- renamed functions_for_parameters to parameters_utilities
- used normal/tangential component instead of 0/1
- used emplace_back("table")
- reverted #include of <memory> and <vector>
- added Info()
- removed check if (rSettings["table"][component].IsNumber())
- removed KRATOS_ERROR_IF_NOT etc. for multi-component table
- Made a few member functions `const`. - Pass an object by reference to const rather than by value when it is not being modified.
rfaasse
left a comment
There was a problem hiding this comment.
Thanks for making the improvements, looks good!
📝 Description
🆕 Changelog