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] Extract biot coefficient calculation #12398

Merged
merged 18 commits into from
May 24, 2024

Conversation

rfaasse
Copy link
Contributor

@rfaasse rfaasse commented May 23, 2024

📝 Description
This PR extracts pre-calculated lists for the biot coefficients and creates a utility function (used by diff order and non-diff order) to calculate the biot modulus inverse for a single integration point (including unit tests). In a next PR, the extraction of the element-wide list for the biot modulus inverse will be done, that is out of scope for this one.

Changes:

  • Removing redundant hasBiotCoefficient flag
  • Extracted lists for the biot coefficients
  • Added utility function for biot modulus inverse with unit tests and used in diff and non-diff order elements
  • Extracting Bulk Modulus calculation with tests
  • Extract utility function for calculating the biot coefficients with tests and used in diff and non-diff order elements

@rfaasse rfaasse marked this pull request as ready for review May 23, 2024 11:42
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It might be a point of discussion if we want all transport_equation_utilities tests in a single file

@rfaasse rfaasse requested review from avdg81 and WPK4FEM May 23, 2024 11:49
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.

A clean and clear extraction of functionality, which makes the code more readable and easier to understand. Well done! I have a few minor suggestions and a question for you.

const double derivative_of_saturation = 0.2;

const double expected_value = -0.09999992485;
KRATOS_EXPECT_DOUBLE_EQ(GeoTransportEquationUtilities::CalculateBiotModulusInverse(
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't KRATOS_EXPECT_NEAR be more robust?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Depends on the tolerance of course, under the hood this macro does: KRATOS_EXPECT_NEAR(a,b,std::numeric_limits<double>::epsilon(). Do we prefer a different tolerance? Problem is, with the currnet numbers we need to be quite precise to check that the results are actually okay (no 1e-16, but 1e-9 is needed).

biot_coefficient, degree_of_saturation, derivative_of_saturation, properties) > large_number)
}

KRATOS_TEST_CASE_IN_SUITE(CalculateBiotModulusInverse_DoesNotThrow_ForEmptyProperties, KratosGeoMechanicsFastSuite)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this desired behavior, since it would require me to test the returned value before actually using it ...?

Copy link
Contributor Author

@rfaasse rfaasse May 23, 2024

Choose a reason for hiding this comment

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

This question is exactly the reason I wanted to make the current behavior (this has just moved) explicit in this test. I don't know exactly what the desired behavior is. E.g. do we want to always check if all the properties are set with physical values inside this function, or do we assume it's okay? It is user input though (via the MaterialParameters), so it could indeed result in NaN now if the wrong inputs are given.

I can of course add checks and throw (and UT for that), what's your opinion?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest to not change the behavior yet, since that would be beyond the scope of this PR. However, I would like you to add an issue to the product backlog about it, so we can revisit it later. Now it has been documented through a unit test, which is a first step in the right direction, so thanks for that.

@rfaasse rfaasse self-assigned this May 23, 2024
@rfaasse rfaasse added GeoMechanics Issues related to the GeoMechanicsApplication Refactor When code is moved or rewrote keeping the same behavior labels May 23, 2024
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.

Dear Richard,

The purpose of creating lists for the BiotCoefficient alpha and Biot Modulus Inverse 1/Q is fulfilled here. Good. However, I strongly think that the computation should be done directly on given material input and not on a constitutive matrix.

We can discuss whether that should be in this PR or in a next one.

Regards, Wijtze Pieter

(rVariables.BiotCoefficient - rProp[POROSITY]) / rProp[BULK_MODULUS_SOLID] +
rProp[POROSITY] / rProp[BULK_MODULUS_FLUID];
// calculate Bulk modulus from stiffness matrix
return 1.0 - CalculateBulkModulus(rConstitutiveMatrix) / rProp[BULK_MODULUS_SOLID];
Copy link
Contributor

Choose a reason for hiding this comment

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

Contents of CalculateBUlkModulus:
return ConstitutiveMatrix(0, 0) - (4.0 / 3.0) * ConstitutiveMatrix(IndexG, IndexG);
The ConstitutiveMatrix is computed (relevant entries only)as:
const Properties& r_material_properties = rValues.GetMaterialProperties();
const auto E = r_material_properties[YOUNG_MODULUS];
const auto NU = r_material_properties[POISSON_RATIO];
const double c1 = (1.0 - NU) * c0;
const double c3 = this->GetConsiderDiagonalEntriesOnlyAndNoShear() ? 0.0 : (0.5 - NU) * c0;
C(INDEX_2D_PLANE_STRAIN_XX, INDEX_2D_PLANE_STRAIN_XX) = c1;
C(INDEX_2D_PLANE_STRAIN_XY, INDEX_2D_PLANE_STRAIN_XY) = c3;

I strongly think that the input of CalculateBulkModulus should be rProp and no a constitutive matrix. That changed the argument lists of all functions calling CalculateBulkModulus. Further CalculateBulkModulus should be in a utility thing and functionality like CalculateBiotCoefficient as well. E.g. both in the transport equation utilities.

You may argue that it is out of scope for this PR, but the above indicates where I would like to end.

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 completely agree that here it is a lot of overkill to go through all the calculations (the b matrices, deformation gradients, strains and constitutive matrix), in some cases just to calculate a bulk modulus that we could derive from the material.

I will move the CalculateBulkModulus and CalculateBiotCoefficient(s) to the transport equation utilities (and add some tests), I agree we should make this more generic and not have more than one implementation and it shouldn't be a lot of work.

However, taking a simpler approach for deriving the bulk modulus out of material parameters and also do the testing that this works for all constitutive laws (and not only for this linear elastic example) is in my opinion indeed out of scope for this refactoring PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

I took the elastic constitutive thing, because I think that it is always the elastic matrix and not some plastic or otherwise nonlinear thing. That is why I'm hammering on taking it from material parameters. There are no objections against doing that in a different PR.

WPK4FEM
WPK4FEM previously approved these changes May 23, 2024
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.

Thank you for all efforts, I can live with this implementation

avdg81
avdg81 previously approved these changes May 23, 2024
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 one is good to go.

biot_coefficient, degree_of_saturation, derivative_of_saturation, properties) > large_number)
}

KRATOS_TEST_CASE_IN_SUITE(CalculateBiotModulusInverse_DoesNotThrow_ForEmptyProperties, KratosGeoMechanicsFastSuite)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest to not change the behavior yet, since that would be beyond the scope of this PR. However, I would like you to add an issue to the product backlog about it, so we can revisit it later. Now it has been documented through a unit test, which is a first step in the right direction, so thanks for that.

@rfaasse rfaasse dismissed stale reviews from avdg81 and WPK4FEM via 8e8cc45 May 23, 2024 15:47
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.

Remains good to go.

@rfaasse rfaasse requested a review from avdg81 May 24, 2024 07:10
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.

I'm very satisfied with the result of this PR. Let's merge it.

@rfaasse rfaasse merged commit 281c6d3 into master May 24, 2024
11 checks passed
@rfaasse rfaasse deleted the geo/12319-extract-biot-coefficient-calculation branch May 24, 2024 08:42
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 Refactor When code is moved or rewrote keeping the same behavior
Projects
None yet
3 participants