Skip to content

Conversation

markelov208
Copy link
Contributor

📝 Description

  • moved python class apply_normal_load_table_process to cpp

🆕 Changelog

  • created cpp class ApplyNormalLoadTableProcess
  • cleaned python script apply_normal_load_table_process .py
  • moved free functions from apply_scalar_constraint_table_process.cpp to a new class FunctionsForParameters
  • added ApplyNormalLoadTableProcess in dgeosettlement
  • added ApplyNormalLoadTableProcess in add_custom_process_to_python

rfaasse and others added 7 commits October 12, 2023 09:58
- 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
@markelov208 markelov208 requested review from avdg81 and rfaasse October 23, 2023 09:32
@markelov208 markelov208 self-assigned this Oct 23, 2023
Gennady Markelov added 2 commits October 23, 2023 13:41
# Conflicts:
#	applications/GeoMechanicsApplication/custom_processes/apply_scalar_constraint_table_process.cpp
rfaasse
rfaasse previously approved these changes Oct 23, 2023
Copy link
Contributor

@rfaasse rfaasse left a comment

Choose a reason for hiding this comment

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

Nice clean and readable code! I only have 2 minor style related comments.

Copy link
Contributor

@avdg81 avdg81 left a comment

Choose a reason for hiding this comment

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

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!

Copy link
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fully agreed, so the files are renamed etc.


namespace Kratos {

class FunctonsForParameters
Copy link
Contributor

Choose a reason for hiding this comment

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

And perhaps rename the class to ParametersUtilities? Otherwise, I would at least correct a typo: FunctionsForParameters (note the missing i in Functons).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the class is renamed as yo usuggested.

{
auto normal_parameters = FunctonsForParameters::ExtractParameters(rProcessSettings,
NamesOfSettingsToCopy);
normal_parameters.AddValue("value", rProcessSettings["value"][0]);
Copy link
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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" });
Copy link
Contributor

Choose a reason for hiding this comment

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

Although correct, I would simplify this to:

Suggested change
NamesOfSettingsToCopy.insert(NamesOfSettingsToCopy.end(), { "table" });
NamesOfSettingsToCopy.emplace_back("table");

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you. It is modified now.

"third_reference_coordinate",
"specific_weight" });
if (FunctonsForParameters::HasTableAttached(rProcessSettings)) {
NamesOfSettingsToCopy.insert(NamesOfSettingsToCopy.end(), { "table" });
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
NamesOfSettingsToCopy.insert(NamesOfSettingsToCopy.end(), { "table" });
NamesOfSettingsToCopy.emplace_back("table");

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As above.

Comment on lines 19 to 20
//#include <memory>
//#include <vector>
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

restored.


void ExecuteInitialize() override;
void ExecuteInitializeSolutionStep() override;

Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you. Info() is added now.

Comment on lines 52 to 61
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; });
}
Copy link
Contributor

Choose a reason for hiding this comment

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

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:

Suggested change
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!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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())
Gennady Markelov and others added 2 commits October 24, 2023 11:55
- 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.
Copy link
Contributor

@rfaasse rfaasse left a comment

Choose a reason for hiding this comment

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

Thanks for making the improvements, looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[GeoMechanicsApplication] Migrating the ApplyNormalLoadTableProcess From Python to C++
3 participants