Skip to content
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

Merged
merged 62 commits into from
Nov 22, 2023

Conversation

rfaasse
Copy link
Contributor

@rfaasse rfaasse commented Nov 15, 2023

📝 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

New class hierarchy depiction:
image

rfaasse and others added 30 commits November 6, 2023 17:23
@rfaasse rfaasse marked this pull request as ready for review November 20, 2023 12:10
@rfaasse rfaasse added the GeoMechanics Issues related to the GeoMechanicsApplication label Nov 20, 2023
@rfaasse rfaasse requested review from avdg81 and WPK4FEM November 20, 2023 12:16
@rfaasse rfaasse changed the title [GeoMechanicsApplication] Geo/re use functionality between schemes [GeoMechanicsApplication] Reduce duplicated functionality between schemes and refactor the inheritance structure Nov 20, 2023

KRATOS_EXPECT_EXCEPTION_IS_THROWN(
SchemeType scheme(invalid_theta, TEMPERATURE, DT_TEMPERATURE, DT_TEMPERATURE_COEFFICIENT),
"Theta must be larger than zero, but got -2")
Copy link
Contributor

Choose a reason for hiding this comment

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

0<= Theta <= 1 ?

Copy link
Contributor Author

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)?

Copy link
Contributor Author

@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 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)

Comment on lines +31 to +34
using BaseType = Scheme<TSparseSpace, TDenseSpace>;
using DofsArrayType = typename BaseType::DofsArrayType;
using TSystemMatrixType = typename BaseType::TSystemMatrixType;
using TSystemVectorType = typename BaseType::TSystemVectorType;
Copy link
Contributor Author

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]) {
Copy link
Contributor Author

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

Comment on lines 159 to 171
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);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice suggestion!

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.

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.

{
KRATOS_TRY

Scheme<TSparseSpace, TDenseSpace>::Check(rModelPart);
Copy link
Contributor

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:

Suggested change
Scheme<TSparseSpace, TDenseSpace>::Check(rModelPart);
BaseType::Check(rModelPart);

Copy link
Contributor Author

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).

Comment on lines +75 to +76
KRATOS_TEST_CASE_IN_SUITE(ForMissingNodalDof_CheckBackwardEulerPwScheme_Throws,
KratosGeoMechanicsFastSuite)
Copy link
Contributor

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.

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

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):

Suggested change
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);

Copy link
Contributor Author

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)

@@ -42,7 +42,6 @@ class NewmarkQuasistaticUPwSchemeTester {
void CreateValidModelPart()
{
auto& result = mModel.CreateModelPart("dummy", 2);
result.AddNodalSolutionStepVariable(TEMPERATURE);
Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch!

Copy link
Contributor Author

@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 both @avdg81 and @WPK4FEM for the thorough reviews. I processed the comments, so should be ready for re-review!

class GeneralizedNewmarkScheme
: public GeoMechanicsTimeIntegrationScheme<TSparseSpace, TDenseSpace> {
public:
explicit GeneralizedNewmarkScheme(double theta,
Copy link
Contributor Author

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

Copy link
Contributor Author

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

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).

Comment on lines +75 to +76
KRATOS_TEST_CASE_IN_SUITE(ForMissingNodalDof_CheckBackwardEulerPwScheme_Throws,
KratosGeoMechanicsFastSuite)
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, 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);
Copy link
Contributor Author

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)

@rfaasse rfaasse requested review from avdg81 and WPK4FEM November 22, 2023 14:13
Copy link
Contributor

@WPK4FEM WPK4FEM left a 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.

@rfaasse rfaasse merged commit 2bd73d7 into master Nov 22, 2023
15 checks passed
@rfaasse rfaasse deleted the geo/re-use-functionality-between-schemes branch November 22, 2023 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GeoMechanics Issues related to the GeoMechanicsApplication
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[GeoMechanicsApplication] Improve inheritance structure of thermal and related schemes
3 participants