-
Notifications
You must be signed in to change notification settings - Fork 249
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] Reduce duplicated functionality between schemes and refactor the inheritance structure #11808
Conversation
… geo/re-use-functionality-between-schemes
… geo/re-use-functionality-between-schemes
applications/GeoMechanicsApplication/custom_strategies/schemes/backward_euler_scheme.hpp
Outdated
Show resolved
Hide resolved
applications/GeoMechanicsApplication/custom_strategies/schemes/generalized_newmark_scheme.hpp
Outdated
Show resolved
Hide resolved
...s/GeoMechanicsApplication/custom_strategies/schemes/geomechanics_time_integration_scheme.hpp
Outdated
Show resolved
Hide resolved
...s/GeoMechanicsApplication/custom_strategies/schemes/geomechanics_time_integration_scheme.hpp
Outdated
Show resolved
Hide resolved
applications/GeoMechanicsApplication/custom_strategies/schemes/newmark_dynamic_U_Pw_scheme.hpp
Show resolved
Hide resolved
applications/GeoMechanicsApplication/tests/cpp_tests/test_generalized_newmark_T_scheme.cpp
Outdated
Show resolved
Hide resolved
applications/GeoMechanicsApplication/tests/cpp_tests/test_generalized_newmark_T_scheme.cpp
Outdated
Show resolved
Hide resolved
applications/GeoMechanicsApplication/tests/cpp_tests/test_newmark_Pw_scheme.cpp
Outdated
Show resolved
Hide resolved
applications/GeoMechanicsApplication/tests/cpp_tests/test_newmark_Pw_scheme.cpp
Outdated
Show resolved
Hide resolved
|
||
KRATOS_EXPECT_EXCEPTION_IS_THROWN( | ||
SchemeType scheme(invalid_theta, TEMPERATURE, DT_TEMPERATURE, DT_TEMPERATURE_COEFFICIENT), | ||
"Theta must be larger than zero, but got -2") |
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.
0<= Theta <= 1 ?
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 took the original restrictions here, since if theta = 0.0, we will end up with a division by 0. Is there a good reason to have 1.0 as the upper limit (same would hold then for beta and/or gamma)?
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 for the review @WPK4FEM, implemented most of the suggestions (some were a bit out of scope in my opinion, so let me know what you think)
applications/GeoMechanicsApplication/custom_strategies/schemes/newmark_dynamic_U_Pw_scheme.hpp
Show resolved
Hide resolved
using BaseType = Scheme<TSparseSpace, TDenseSpace>; | ||
using DofsArrayType = typename BaseType::DofsArrayType; | ||
using TSystemMatrixType = typename BaseType::TSystemMatrixType; | ||
using TSystemVectorType = typename BaseType::TSystemVectorType; |
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.
What I did here, is format the file using the clang-format settings that are found in the kratos wiki. However, since it's not in the style guide, I think we can still change this if we would want to
void FinalizeSolutionStep(ModelPart& rModelPart, | ||
TSystemMatrixType& A, | ||
TSystemVectorType& Dx, | ||
TSystemVectorType& b) override | ||
{ | ||
KRATOS_TRY | ||
|
||
if (rModelPart.GetProcessInfo()[NODAL_SMOOTHING]) { |
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 agree we should find a more logical place for it in the future
...ations/GeoMechanicsApplication/custom_strategies/schemes/newmark_quasistatic_U_Pw_scheme.hpp
Show resolved
Hide resolved
...GeoMechanicsApplication/custom_strategies/schemes/newmark_quasistatic_damped_U_Pw_scheme.hpp
Outdated
Show resolved
Hide resolved
noalias(rNode.FastGetSolutionStepValue(ACCELERATION)) = | ||
((rNode.FastGetSolutionStepValue(DISPLACEMENT) - | ||
rNode.FastGetSolutionStepValue(DISPLACEMENT, 1)) - | ||
this->GetDeltaTime() * rNode.FastGetSolutionStepValue(VELOCITY, 1) - | ||
(0.5 - mBeta) * this->GetDeltaTime() * this->GetDeltaTime() * | ||
rNode.FastGetSolutionStepValue(ACCELERATION, 1)) / | ||
(mBeta * this->GetDeltaTime() * this->GetDeltaTime()); | ||
|
||
noalias(rNode.FastGetSolutionStepValue(VELOCITY)) = | ||
rNode.FastGetSolutionStepValue(VELOCITY, 1) + | ||
(1.0 - mGamma) * this->GetDeltaTime() * | ||
rNode.FastGetSolutionStepValue(ACCELERATION, 1) + | ||
mGamma * this->GetDeltaTime() * rNode.FastGetSolutionStepValue(ACCELERATION); |
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 suggestion!
...s/GeoMechanicsApplication/custom_strategies/schemes/geomechanics_time_integration_scheme.hpp
Outdated
Show resolved
Hide resolved
...s/GeoMechanicsApplication/custom_strategies/schemes/geomechanics_time_integration_scheme.hpp
Outdated
Show resolved
Hide resolved
applications/GeoMechanicsApplication/custom_strategies/schemes/generalized_newmark_scheme.hpp
Outdated
Show resolved
Hide resolved
applications/GeoMechanicsApplication/custom_strategies/schemes/backward_euler_scheme.hpp
Outdated
Show resolved
Hide resolved
…e.hpp purely virtual
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 is a very nice step forwards again. Thank you very much for the hard work that you have done Richard! The structure has improved a lot and it makes much more sense now.
I only have several minor remarks, nothing blocking.
...s/GeoMechanicsApplication/custom_strategies/schemes/geomechanics_time_integration_scheme.hpp
Outdated
Show resolved
Hide resolved
{ | ||
KRATOS_TRY | ||
|
||
Scheme<TSparseSpace, TDenseSpace>::Check(rModelPart); |
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.
We can make this slightly more readable:
Scheme<TSparseSpace, TDenseSpace>::Check(rModelPart); | |
BaseType::Check(rModelPart); |
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 actually prefer to keep it like this: now it is clear at a glance (without having to look at the definition) which function is called. We could discuss (we could also delete the base check, since at this moment it just returns 0 and funnily enough has a KRATOS_TRY and CATCH around it).
...s/GeoMechanicsApplication/custom_strategies/schemes/geomechanics_time_integration_scheme.hpp
Outdated
Show resolved
Hide resolved
...s/GeoMechanicsApplication/custom_strategies/schemes/geomechanics_time_integration_scheme.hpp
Outdated
Show resolved
Hide resolved
...s/GeoMechanicsApplication/custom_strategies/schemes/geomechanics_time_integration_scheme.hpp
Show resolved
Hide resolved
KRATOS_TEST_CASE_IN_SUITE(ForMissingNodalDof_CheckBackwardEulerPwScheme_Throws, | ||
KratosGeoMechanicsFastSuite) |
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.
Just a remark: apparently, the other tests don't suffer from the fact that no water pressure degree of freedom was added to the node. It's just that when Check
is called and the DoF is missing, it will throw an exception. That surprises me a bit.
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.
Indeed, if check isn't called, it won't throw (at least when the DoF is not used in the function that's tested in that particular test). I hope everywhere these schemes are used, the check is actually done, but I don't know. I'm not sure how easy it would be to change this way of checking (apart from just doing the check at the start of every public function, which I don't know if I like)
|
||
Model model; | ||
auto& model_part = model.CreateModelPart("dummy", 2); | ||
auto p_node = model_part.CreateNewNode(0, 0.0, 0.0, 0.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.
You may want to add variable DT_TEMPERATURE
(to be consistent with test case ForMissingWaterPressureSolutionStepVariable_CheckBackwardEulerPwScheme_Throws
):
auto p_node = model_part.CreateNewNode(0, 0.0, 0.0, 0.0); | |
model_part.AddNodalSolutionStepVariable(DT_TEMPERATURE); | |
auto p_node = model_part.CreateNewNode(0, 0.0, 0.0, 0.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.
I removed this line due to the review comment of WPK, which I agree with. I prefer to remove the same line from the Pw version (and the newmark T/Pw equivalents)
applications/GeoMechanicsApplication/tests/cpp_tests/test_newmark_Pw_scheme.cpp
Outdated
Show resolved
Hide resolved
applications/GeoMechanicsApplication/tests/cpp_tests/test_newmark_Pw_scheme.cpp
Outdated
Show resolved
Hide resolved
@@ -42,7 +42,6 @@ class NewmarkQuasistaticUPwSchemeTester { | |||
void CreateValidModelPart() | |||
{ | |||
auto& result = mModel.CreateModelPart("dummy", 2); | |||
result.AddNodalSolutionStepVariable(TEMPERATURE); |
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.
Good catch!
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.
class GeneralizedNewmarkScheme | ||
: public GeoMechanicsTimeIntegrationScheme<TSparseSpace, TDenseSpace> { | ||
public: | ||
explicit GeneralizedNewmarkScheme(double theta, |
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.
Agreed, remnant from when the only parameter was theta
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.
Good suggestion, made it uniform across the schemes that implement these functions
{ | ||
KRATOS_TRY | ||
|
||
Scheme<TSparseSpace, TDenseSpace>::Check(rModelPart); |
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 actually prefer to keep it like this: now it is clear at a glance (without having to look at the definition) which function is called. We could discuss (we could also delete the base check, since at this moment it just returns 0 and funnily enough has a KRATOS_TRY and CATCH around it).
...s/GeoMechanicsApplication/custom_strategies/schemes/geomechanics_time_integration_scheme.hpp
Show resolved
Hide resolved
...s/GeoMechanicsApplication/custom_strategies/schemes/geomechanics_time_integration_scheme.hpp
Outdated
Show resolved
Hide resolved
applications/GeoMechanicsApplication/tests/cpp_tests/test_backward_euler_Pw_scheme.cpp
Outdated
Show resolved
Hide resolved
KRATOS_TEST_CASE_IN_SUITE(ForMissingNodalDof_CheckBackwardEulerPwScheme_Throws, | ||
KratosGeoMechanicsFastSuite) |
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.
Indeed, if check isn't called, it won't throw (at least when the DoF is not used in the function that's tested in that particular test). I hope everywhere these schemes are used, the check is actually done, but I don't know. I'm not sure how easy it would be to change this way of checking (apart from just doing the check at the start of every public function, which I don't know if I like)
|
||
Model model; | ||
auto& model_part = model.CreateModelPart("dummy", 2); | ||
auto p_node = model_part.CreateNewNode(0, 0.0, 0.0, 0.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.
I removed this line due to the review comment of WPK, which I agree with. I prefer to remove the same line from the Pw version (and the newmark T/Pw equivalents)
applications/GeoMechanicsApplication/tests/cpp_tests/test_newmark_Pw_scheme.cpp
Outdated
Show resolved
Hide resolved
applications/GeoMechanicsApplication/tests/cpp_tests/test_newmark_Pw_scheme.cpp
Outdated
Show resolved
Hide resolved
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.
Read through once more. Looks like a consistent set of things to me.
📝 Description
This PR aims to simplify the class structure of the schemes in the geomechanics application. This reduces the number of duplicated functionality and makes the structure more intuitive. In an earlier PR, the common functionality was extracted from the UPw scheme to the geomechanics time integration scheme, which is still the baseclass of our hierarchy. In this PR, base classes for BackwardEuler and GeneralizedNewmark schemes were created which contains al common functionality in a generalized way. This makes it a lot easier to add a new scheme with different scalar variables.
Note that not all UPw functionality is cleaned up in the same way (the backward euler upw scheme still incorrectly derives from the newmark scheme). However, when changing that part as well, the overview of what is happening in this refactoring effort might be lost. Hence, it's not included in this PR but will be part of future efforts.
Before refactoring, unit tests were put in place to make sure the functionality didn't change along the way (see the test folder in this PR)
Old class hierarchy depiction:
![image](https://private-user-images.githubusercontent.com/56549273/284261484-1d15f761-c839-40fa-b6c5-20793cab0cc1.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5ODU3NjIsIm5iZiI6MTczODk4NTQ2MiwicGF0aCI6Ii81NjU0OTI3My8yODQyNjE0ODQtMWQxNWY3NjEtYzgzOS00MGZhLWI2YzUtMjA3OTNjYWIwY2MxLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA4VDAzMzEwMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTgzMjllNTI1YTlkNDUzZmMxMjBiNTgyZmFjNjE2NDk4N2FhMWI1YWRiNGNlOGM0MzQ1Y2YxOWYxZTViYTNiYjEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.lG428quM7TJyBuLPJzMFlKtv0BBifq4dJKcHtOIxEDE)
New class hierarchy depiction:
![image](https://private-user-images.githubusercontent.com/56549273/284261272-3787e6d6-731f-45f9-94e2-2775778da9ac.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5ODU3NjIsIm5iZiI6MTczODk4NTQ2MiwicGF0aCI6Ii81NjU0OTI3My8yODQyNjEyNzItMzc4N2U2ZDYtNzMxZi00NWY5LTk0ZTItMjc3NTc3OGRhOWFjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA4VDAzMzEwMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTY3ODAxNjNhN2M2NGYzYTQ3NDljNzc2MTVhN2Q5MTc3MmMwMGMzZWEzNjE3NDM3OWQ4NGEwNzg2NjFiNDI0N2ImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.1afp4LEL6EmwfMoQulPYE12vlZ3irPr5VJyXSSp3hmY)