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 a static utility function for the calculation of the Mass Matrix (M) #12299

Merged
merged 66 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
50f3582
implemented CalculateMassMatrix for small_strain_U_Pw_diff_order_element
Apr 19, 2024
ea4cc17
removed CalculateMassMatrix
Apr 19, 2024
0dd0c5a
replaced rGeom with this->GetGeometry()
Apr 19, 2024
fc82a72
added description of CalculateMassMatrix
Apr 19, 2024
83f27a1
added Np, changed from Camel to snake_case
Apr 19, 2024
122e145
removed CalculateMassMatrix
Apr 19, 2024
d1ea2e1
removed commented lines
Apr 19, 2024
27b872a
removed Np vector
Apr 19, 2024
561390d
changed in accordance SOnarCloud:
Apr 22, 2024
2802e2b
extracted CalculateMassMatrix for U_Pw_small_strain_element
Apr 24, 2024
db42ede
replaced local CalculateSoilDensity functions with the static function
Apr 24, 2024
f632a3b
fixed extracted CalculateMassMatrix for U_Pw_small_strain_element
Apr 25, 2024
1fec4e6
fixed return of MassMatrix
Apr 25, 2024
4e56457
removed unique_ptr from function parameters
Apr 25, 2024
684103f
Revert "removed CalculateMassMatrix"
Apr 25, 2024
bf235ca
extracted CalculateDegreeOfSaturation and CalculateIntegrationCoeffic…
Apr 25, 2024
d8abb63
changed MassMatrix to mass_matrix
Apr 26, 2024
1e5a696
added CalculateNuMatrix for Matrxi1&Matrix2 and clang-formatting
Apr 26, 2024
7d7ac07
changed in accordance with the review comments
Apr 26, 2024
cfd8da6
added test for CalculateSoilDensity function
Apr 26, 2024
a14951c
removed index=i-Dim
Apr 26, 2024
3d5bd1f
replaced pointer with reference
Apr 26, 2024
6417b44
replaced pointer with reference -cont
Apr 26, 2024
f59640e
removed redundant NumberPNodes
Apr 26, 2024
4d877be
changed RetentionParameters to snake_case
Apr 26, 2024
99beebb
reduced info passed into CalculateDegreeOfSaturation
Apr 26, 2024
516b822
changed rpPressureGeometry to rPressureGeometry
Apr 26, 2024
3172490
added equation_of_motion_utilities and extracted CalculateSoilDensity…
May 1, 2024
065e3ff
Merge branch 'master' into geo/12279-extract-function-mass-matrix
May 1, 2024
e418105
added test for CalculateMatrix etc functions for U_Pw_small_strain_el…
May 2, 2024
af39cf6
added a unit test for UPwDiffOrder element
May 2, 2024
5162f11
removed unnecessary includes
May 2, 2024
6738424
fixed sonarcloud smells
May 2, 2024
e865caa
added a description of Equation of Motion utilities
May 2, 2024
02cd28d
changed CalculateSoilDensityVector to CalculateSoilDensities
May 2, 2024
419de5f
updated descriptions of transport_equation_utilities.hpp and equation…
May 2, 2024
b413a81
removed a copy of CalculateIntegrationCoefficientInitialConfiguration
May 3, 2024
be659ba
removed redundant input rIntegrationPoints and updated unit tests
May 3, 2024
5e159f3
activated 1D-consolidation test
May 3, 2024
6c60525
reduced test_mass_matrix for debugging
May 3, 2024
961954c
test only for SolidDensities for DiffOrder
May 3, 2024
66551cd
commented CalculateSoilDensities in the test
May 3, 2024
3921b67
corrected size of pressure_vector
May 3, 2024
d29c4b5
moved geometry creation to model_setup_utilities function
May 3, 2024
e53ba8c
deactivated 1d_consolidation test
May 3, 2024
419bbfe
used pragma once
May 4, 2024
35d8b43
removed parentheses
May 4, 2024
1e64d18
used arithmetic operations instead the final numbers
May 4, 2024
56b5828
removed commented includes
May 4, 2024
de3af9a
Merge branch 'master' into geo/12279-extract-function-mass-matrix
May 4, 2024
500d098
renamed some local variables and removed unused includes
May 4, 2024
63cc3dd
removed unused includes in equations_of_motion_utilities.hpp
May 4, 2024
f22c8a4
added s in CalculateIntegrationCoefficientsInitialConfiguration
May 4, 2024
3c04353
fixed porosity and soil density description
May 6, 2024
5879c6b
restored CalculateMassMatrix for DiffOrder element
May 6, 2024
2e1ed28
used available elements' CalculateIntegrationCoefficients and removed…
May 7, 2024
fc15f3e
split equation_of_motion_utilities.hpp into h and cpp files
May 7, 2024
8ed6b14
removed unused includes in test_mass_matrix
May 7, 2024
7f10d5f
removed unused dN_De in equation_of_motion_utilities
May 7, 2024
99b0fba
moved getting of pressure solution vector from transport_equation_uti…
May 7, 2024
19559c6
removed extra qualification for GetPressureSolutionVector
May 7, 2024
383176a
removed private functions in transport_equation_utilities.hpp
May 7, 2024
c5c44ba
added this-> for CalculateIntegrationCoefficients call
May 7, 2024
1572298
extracted CalculateDegreesSaturation from CalculateSoilDensities
May 7, 2024
9012aeb
changed setting of properties to remove a code smell
May 7, 2024
cf9f0d9
changed include statements following the review comments
May 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -942,51 +942,9 @@ void UPwSmallStrainElement<TDim, TNumNodes>::CalculateMassMatrix(MatrixType& rMa
{
KRATOS_TRY

const IndexType N_DOF = this->GetNumberOfDOF();

if (rMassMatrix.size1() != N_DOF) rMassMatrix.resize(N_DOF, N_DOF, false);
noalias(rMassMatrix) = ZeroMatrix(N_DOF, N_DOF);

const GeometryType& rGeom = this->GetGeometry();
const GeometryType::IntegrationPointsArrayType& IntegrationPoints =
rGeom.IntegrationPoints(this->mThisIntegrationMethod);
const IndexType NumGPoints = IntegrationPoints.size();

ElementVariables Variables;
this->InitializeElementVariables(Variables, rCurrentProcessInfo);

// Create general parameters of retention law
RetentionLaw::Parameters RetentionParameters(this->GetProperties(), rCurrentProcessInfo);

// Defining shape functions at all integration points
// Defining necessary variables
BoundedMatrix<double, TDim, TNumNodes * TDim> Nut = ZeroMatrix(TDim, TNumNodes * TDim);
BoundedMatrix<double, TDim, TNumNodes * TDim> AuxDensityMatrix = ZeroMatrix(TDim, TNumNodes * TDim);
BoundedMatrix<double, TDim, TDim> DensityMatrix = ZeroMatrix(TDim, TDim);

for (unsigned int GPoint = 0; GPoint < NumGPoints; ++GPoint) {
GeoElementUtilities::CalculateNuMatrix<TDim, TNumNodes>(Nut, Variables.NContainer, GPoint);

Matrix J0, InvJ0, DNu_DX0;
this->CalculateDerivativesOnInitialConfiguration(Variables.detJInitialConfiguration, J0,
InvJ0, DNu_DX0, GPoint);

// Calculating weighting coefficient for integration
Variables.IntegrationCoefficientInitialConfiguration = this->CalculateIntegrationCoefficient(
IntegrationPoints, GPoint, Variables.detJInitialConfiguration);

CalculateRetentionResponse(Variables, RetentionParameters, GPoint);

this->CalculateSoilDensity(Variables);

GeoElementUtilities::AssembleDensityMatrix(DensityMatrix, Variables.Density);

noalias(AuxDensityMatrix) = prod(DensityMatrix, Nut);

// Adding contribution to Mass matrix
GeoElementUtilities::AssembleUUBlockMatrix(
rMassMatrix, prod(trans(Nut), AuxDensityMatrix) * Variables.IntegrationCoefficientInitialConfiguration);
}
rMassMatrix = GeoTransportEquationUtilities::CalculateMassMatrix<TDim, TNumNodes>(
Copy link
Contributor

Choose a reason for hiding this comment

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

As the mass matrix is not part of the transport equation, but part of the (displacement) equation of motion, I wonder if GeoTransportEquationUtilities is the best place to put this.
Its call I would expect after the retention law things have been computed as probably its fill depends on the saturation values in the integration points.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A very good suggestion, as a result the CalculateMassMatrix is split into three functions. This also helps to have the same functions for U_Pw and U_Pw_DiffOrder elements.

this->GetNumberOfDOF(), this->GetGeometry(), this->GetIntegrationMethod(),
this->GetStressStatePolicy(), mRetentionLawVector, this->GetProperties(), rCurrentProcessInfo);

KRATOS_CATCH("")
}
Expand Down Expand Up @@ -1358,23 +1316,13 @@ void UPwSmallStrainElement<TDim, TNumNodes>::CalculateAndAddMixBodyForce(VectorT
KRATOS_CATCH("")
}

template <unsigned int TDim, unsigned int TNumNodes>
void UPwSmallStrainElement<TDim, TNumNodes>::CalculateSoilDensity(ElementVariables& rVariables)
{
KRATOS_TRY

rVariables.Density = rVariables.DegreeOfSaturation * rVariables.Porosity * rVariables.FluidDensity +
(1.0 - rVariables.Porosity) * rVariables.SolidDensity;

KRATOS_CATCH("")
}

template <unsigned int TDim, unsigned int TNumNodes>
void UPwSmallStrainElement<TDim, TNumNodes>::CalculateSoilGamma(ElementVariables& rVariables)
{
KRATOS_TRY

this->CalculateSoilDensity(rVariables);
rVariables.Density = GeoTransportEquationUtilities::CalculateSoilDensity(
rVariables.DegreeOfSaturation, this->GetProperties());

noalias(rVariables.SoilGamma) = rVariables.Density * rVariables.BodyAcceleration;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,9 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) UPwSmallStrainElement : public UPwBa

void CalculateExtrapolationMatrix(BoundedMatrix<double, TNumNodes, TNumNodes>& rExtrapolationMatrix);

void ResetHydraulicDischarge();
void CalculateHydraulicDischarge(const ProcessInfo& rCurrentProcessInfo);
void CalculateSoilGamma(ElementVariables& rVariables);
virtual void CalculateSoilDensity(ElementVariables& rVariables);
void ResetHydraulicDischarge();
void CalculateHydraulicDischarge(const ProcessInfo& rCurrentProcessInfo);
void CalculateSoilGamma(ElementVariables& rVariables);

virtual void CalculateAndAddGeometricStiffnessMatrix(MatrixType& rLeftHandSideMatrix,
ElementVariables& rVariables,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ void UPwSmallStrainInterfaceElement<TDim, TNumNodes>::CalculateMassMatrix(Matrix

CalculateRetentionResponse(Variables, RetentionParameters, GPoint);

this->CalculateSoilDensity(Variables);
Variables.Density = GeoTransportEquationUtilities::CalculateSoilDensity(
Variables.DegreeOfSaturation, this->GetProperties());

GeoElementUtilities::AssembleDensityMatrix(DensityMatrix, Variables.Density);

Expand Down Expand Up @@ -1987,23 +1988,13 @@ void UPwSmallStrainInterfaceElement<TDim, TNumNodes>::CalculateAndAddMixBodyForc
KRATOS_CATCH("")
}

template <unsigned int TDim, unsigned int TNumNodes>
void UPwSmallStrainInterfaceElement<TDim, TNumNodes>::CalculateSoilDensity(InterfaceElementVariables& rVariables)
{
KRATOS_TRY

rVariables.Density = rVariables.DegreeOfSaturation * rVariables.Porosity * rVariables.FluidDensity +
(1.0 - rVariables.Porosity) * rVariables.SolidDensity;

KRATOS_CATCH("")
}

template <unsigned int TDim, unsigned int TNumNodes>
void UPwSmallStrainInterfaceElement<TDim, TNumNodes>::CalculateSoilGamma(InterfaceElementVariables& rVariables)
{
KRATOS_TRY

this->CalculateSoilDensity(rVariables);
rVariables.Density = GeoTransportEquationUtilities::CalculateSoilDensity(
rVariables.DegreeOfSaturation, this->GetProperties());

noalias(rVariables.SoilGamma) = rVariables.Density * rVariables.BodyAcceleration;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,7 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) UPwSmallStrainInterfaceElement
unsigned int GPoint);

void CalculateSoilGamma(InterfaceElementVariables& rVariables);

void CalculateSoilDensity(InterfaceElementVariables& rVariables);


void SetConstitutiveParameters(InterfaceElementVariables& rVariables,
ConstitutiveLaw::Parameters& rConstitutiveParameters);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,87 +429,6 @@ void SmallStrainUPwDiffOrderElement::CalculateRightHandSide(VectorType& r
KRATOS_CATCH("")
}

void SmallStrainUPwDiffOrderElement::CalculateMassMatrix(MatrixType& rMassMatrix, const ProcessInfo& rCurrentProcessInfo)
{
KRATOS_TRY

const GeometryType& rGeom = GetGeometry();
const SizeType Dim = rGeom.WorkingSpaceDimension();
const SizeType NumUNodes = rGeom.PointsNumber();
const SizeType BlockElementSize = NumUNodes * Dim;
const GeometryType::IntegrationPointsArrayType& IntegrationPoints =
rGeom.IntegrationPoints(this->GetIntegrationMethod());

ElementVariables Variables;
this->InitializeElementVariables(Variables, rCurrentProcessInfo);

// create general parameters of retention law
RetentionLaw::Parameters RetentionParameters(this->GetProperties(), rCurrentProcessInfo);

Matrix MassMatrixContribution = ZeroMatrix(BlockElementSize, BlockElementSize);

// Defining shape functions and the determinant of the jacobian at all integration points

// Loop over integration points
Matrix Nu = ZeroMatrix(Dim, NumUNodes * Dim);
Matrix AuxDensityMatrix = ZeroMatrix(Dim, NumUNodes * Dim);
Matrix DensityMatrix = ZeroMatrix(Dim, Dim);

for (unsigned int GPoint = 0; GPoint < IntegrationPoints.size(); ++GPoint) {
// compute element kinematics (Np, gradNpT, |J|, B)
this->CalculateKinematics(Variables, GPoint);

// calculating weighting coefficient for integration
Variables.IntegrationCoefficientInitialConfiguration = this->CalculateIntegrationCoefficient(
IntegrationPoints, GPoint, Variables.detJInitialConfiguration);

CalculateRetentionResponse(Variables, RetentionParameters, GPoint);

this->CalculateSoilDensity(Variables);

// Setting the shape function matrix
SizeType Index = 0;
for (SizeType i = 0; i < NumUNodes; ++i) {
for (SizeType iDim = 0; iDim < Dim; ++iDim) {
Nu(iDim, Index++) = Variables.Nu(i);
}
}

GeoElementUtilities::AssembleDensityMatrix(DensityMatrix, Variables.Density);

noalias(AuxDensityMatrix) = prod(DensityMatrix, Nu);

// Adding contribution to Mass matrix
noalias(MassMatrixContribution) +=
prod(trans(Nu), AuxDensityMatrix) * Variables.IntegrationCoefficientInitialConfiguration;
}

// Distribute mass block matrix into the elemental matrix
const SizeType NumPNodes = mpPressureGeometry->PointsNumber();

const SizeType ElementSize = BlockElementSize + NumPNodes;

if (rMassMatrix.size1() != ElementSize || rMassMatrix.size2() != ElementSize)
rMassMatrix.resize(ElementSize, ElementSize, false);
noalias(rMassMatrix) = ZeroMatrix(ElementSize, ElementSize);

for (SizeType i = 0; i < NumUNodes; ++i) {
SizeType Index_i = i * Dim;

for (SizeType j = 0; j < NumUNodes; ++j) {
SizeType Index_j = j * Dim;
for (SizeType idim = 0; idim < Dim; ++idim) {
for (SizeType jdim = 0; jdim < Dim; ++jdim) {
rMassMatrix(Index_i + idim, Index_j + jdim) +=
MassMatrixContribution(Index_i + idim, Index_j + jdim);
}
}
}
}

KRATOS_CATCH("")
}

void SmallStrainUPwDiffOrderElement::CalculateDampingMatrix(MatrixType& rDampingMatrix,
const ProcessInfo& rCurrentProcessInfo)
{
Expand All @@ -523,10 +442,9 @@ void SmallStrainUPwDiffOrderElement::CalculateDampingMatrix(MatrixType& r

const SizeType ElementSize = NumUNodes * Dim + NumPNodes;

// Compute Mass Matrix
MatrixType MassMatrix(ElementSize, ElementSize);

this->CalculateMassMatrix(MassMatrix, rCurrentProcessInfo);
MatrixType MassMatrix = GeoTransportEquationUtilities::CalculateMassMatrixDiffOrder(
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is a local variable, this should be snake case (problem of course is that it seems this class very inconsistent with that right now, maybe we can fix it only in the functions we touch?)

Suggested change
MatrixType MassMatrix = GeoTransportEquationUtilities::CalculateMassMatrixDiffOrder(
MatrixType mass_matrix = GeoTransportEquationUtilities::CalculateMassMatrixDiffOrder(

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. Yesterday I made the same comments to Mohamed ;(

this->GetGeometry(), mpPressureGeometry, this->GetIntegrationMethod(), *mpStressStatePolicy,
mRetentionLawVector, this->GetProperties(), rCurrentProcessInfo);

// Compute Stiffness matrix
MatrixType StiffnessMatrix(ElementSize, ElementSize);
Expand Down Expand Up @@ -1865,7 +1783,8 @@ void SmallStrainUPwDiffOrderElement::CalculateAndAddMixBodyForce(VectorType& rRi
const SizeType Dim = rGeom.WorkingSpaceDimension();
const SizeType NumUNodes = rGeom.PointsNumber();

this->CalculateSoilDensity(rVariables);
rVariables.Density = GeoTransportEquationUtilities::CalculateSoilDensity(
rVariables.DegreeOfSaturation, this->GetProperties());

Vector BodyAcceleration = ZeroVector(Dim);
SizeType Index = 0;
Expand All @@ -1887,18 +1806,6 @@ void SmallStrainUPwDiffOrderElement::CalculateAndAddMixBodyForce(VectorType& rRi
KRATOS_CATCH("")
}

void SmallStrainUPwDiffOrderElement::CalculateSoilDensity(ElementVariables& rVariables)
{
KRATOS_TRY

const PropertiesType& rProp = this->GetProperties();

rVariables.Density = (rVariables.DegreeOfSaturation * rProp[POROSITY] * rProp[DENSITY_WATER]) +
(1.0 - rProp[POROSITY]) * rProp[DENSITY_SOLID];

KRATOS_CATCH("")
}

void SmallStrainUPwDiffOrderElement::CalculateAndAddCouplingTerms(VectorType& rRightHandSideVector,
ElementVariables& rVariables)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) SmallStrainUPwDiffOrderElement : pub

void CalculateRightHandSide(VectorType& rRightHandSideVector, const ProcessInfo& rCurrentProcessInfo) override;

void CalculateMassMatrix(MatrixType& rMassMatrix, const ProcessInfo& rCurrentProcessInfo) override;

void EquationIdVector(EquationIdVectorType& rResult, const ProcessInfo&) const override;

void GetFirstDerivativesVector(Vector& rValues, int Step = 0) const override;
Expand Down Expand Up @@ -305,8 +303,6 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) SmallStrainUPwDiffOrderElement : pub
RetentionLaw::Parameters& rRetentionParameters,
unsigned int GPoint);

void CalculateSoilDensity(ElementVariables& rVariables);

void CalculateJacobianOnCurrentConfiguration(double& detJ, Matrix& rJ, Matrix& rInvJ, unsigned int GPoint) const;

const StressStatePolicy& GetStressStatePolicy() const;
Expand Down
14 changes: 14 additions & 0 deletions applications/GeoMechanicsApplication/custom_utilities/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,26 @@ The mathematical definition is:
$$Q = \int_\Omega B^T \alpha \xi m N_p d\Omega$$
where $B$ is the B-matrix, $\alpha$ is the Biot-alpha (relation between pressure and displacements, material parameter), $\xi$ is the Bishop coefficient, $m$ is the Voigt-vector ($[1,1,1,0,0,0]$) and $N_p$ is the pressure shape function.

### Mass Matrix (M)

The mathematical definition is:
$$M = \int_\Omega N_{u}^T \rho N_u d\Omega$$

Where $\Omega$ is the domain, $N_u$ is the displacement shape function and $\rho$ is the density matrix that holds density for all directions.

### Soil density

The soil density is calculated as
$$\rho= S_r \Phi \rho_w + \Phi \rho_s$$
where $S_r$ is the degree of saturation, $\Phi$ is the porosity, $\rho_w$ is the water density, $\rho_s$ is the solid density.

File transport_equation_utilities.hpp includes

- CalculatePermeabilityMatrix function
- CalculateCompressibilityMatrix function
- CalculateCouplingMatrix function
- CalculateMassMatrix function
- CalculateSoilDensity function
Copy link
Contributor

Choose a reason for hiding this comment

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

Currently correct, maybe we can put those in a more logical place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

README file is updated. Now CalculateMassMatrix is moved to equation_of_motion_utilities.hpp



## Stress strain utilities
Expand Down
Loading
Loading