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 65 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 @@ -13,6 +13,7 @@

// Application includes
#include "custom_elements/U_Pw_small_strain_element.hpp"
#include "custom_utilities/equation_of_motion_utilities.h"
#include "custom_utilities/transport_equation_utilities.hpp"

namespace Kratos
Expand Down Expand Up @@ -943,50 +944,33 @@ 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();
const GeometryType& r_geom = this->GetGeometry();
const auto integration_method = this->GetIntegrationMethod();
const GeometryType::IntegrationPointsArrayType& integration_points =
r_geom.IntegrationPoints(integration_method);
const auto N_container = r_geom.ShapeFunctionsValues(integration_method);

ElementVariables Variables;
this->InitializeElementVariables(Variables, rCurrentProcessInfo);
const auto degrees_saturation = GeoTransportEquationUtilities::CalculateDegreesSaturation(
this->GetPressureSolutionVector(), N_container, mRetentionLawVector, this->GetProperties(),
rCurrentProcessInfo);

// Create general parameters of retention law
RetentionLaw::Parameters RetentionParameters(this->GetProperties(), rCurrentProcessInfo);
const auto solid_densities =
GeoTransportEquationUtilities::CalculateSoilDensities(degrees_saturation, this->GetProperties());

// 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);
const auto det_Js_initial_configuration =
GeoEquationOfMotionUtilities::CalculateDetJsInitialConfiguration(r_geom, integration_method);

// 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);
const auto integration_coefficients =
this->CalculateIntegrationCoefficients(integration_points, det_Js_initial_configuration);

noalias(AuxDensityMatrix) = prod(DensityMatrix, Nut);
const auto mass_matrix_u = GeoEquationOfMotionUtilities::CalculateMassMatrix(
r_geom.WorkingSpaceDimension(), r_geom.PointsNumber(), integration_points.size(),
r_geom.ShapeFunctionsValues(integration_method), solid_densities, integration_coefficients);

// Adding contribution to Mass matrix
GeoElementUtilities::AssembleUUBlockMatrix(
rMassMatrix, prod(trans(Nut), AuxDensityMatrix) * Variables.IntegrationCoefficientInitialConfiguration);
}
GeoElementUtilities::AssembleUUBlockMatrix(rMassMatrix, mass_matrix_u);

KRATOS_CATCH("")
}
Expand Down Expand Up @@ -1359,23 +1343,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 Expand Up @@ -1854,6 +1828,15 @@ void UPwSmallStrainElement<3, 8>::CalculateExtrapolationMatrix(BoundedMatrix<dou
rExtrapolationMatrix(7, 7) = 2.549038105676658;
}

template <unsigned int TDim, unsigned int TNumNodes>
Vector UPwSmallStrainElement<TDim, TNumNodes>::GetPressureSolutionVector()
{
Vector result(TNumNodes);
std::transform(this->GetGeometry().begin(), this->GetGeometry().end(), result.begin(),
[](const auto& node) { return node.FastGetSolutionStepValue(WATER_PRESSURE); });
return result;
}

Comment on lines +1831 to +1839
Copy link
Contributor

Choose a reason for hiding this comment

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

Very similar (but nicer written) to the GetNodalVariableVector or Matrix functions in element_utilities.hpp

Maybe this functionality belongs there.

template class UPwSmallStrainElement<2, 3>;
template class UPwSmallStrainElement<2, 4>;
template class UPwSmallStrainElement<3, 4>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) UPwSmallStrainElement : public UPwBa

virtual void CalculateAndAddCompressibilityMatrix(MatrixType& rLeftHandSideMatrix, ElementVariables& rVariables);

virtual void CalculateAndAddPermeabilityMatrix(MatrixType& rLeftHandSideMatrix, const ElementVariables& rVariables);
virtual void CalculateAndAddPermeabilityMatrix(MatrixType& rLeftHandSideMatrix,
const ElementVariables& rVariables);

virtual void CalculateAndAddRHS(VectorType& rRightHandSideVector, ElementVariables& rVariables, unsigned int GPoint);

Expand Down Expand Up @@ -290,15 +291,16 @@ 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,
unsigned int GPoint);

VectorType GetPressureSolutionVector();

private:
friend class Serializer;

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 @@ -1988,23 +1989,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
Loading
Loading