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 stiffness matrix utility #12388

Merged
merged 9 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -851,7 +851,6 @@ void UPwSmallStrainElement<TDim, TNumNodes>::CalculateMaterialStiffnessMatrix(Ma
const GeometryType& rGeom = this->GetGeometry();
const GeometryType::IntegrationPointsArrayType& IntegrationPoints =
rGeom.IntegrationPoints(mThisIntegrationMethod);
const IndexType NumGPoints = IntegrationPoints.size();

// Constitutive Law parameters
ConstitutiveLaw::Parameters ConstitutiveParameters(rGeom, rProp, rCurrentProcessInfo);
Expand All @@ -868,21 +867,13 @@ void UPwSmallStrainElement<TDim, TNumNodes>::CalculateMaterialStiffnessMatrix(Ma
this->CalculateAnyOfMaterialResponse(deformation_gradients, ConstitutiveParameters,
Variables.NContainer, Variables.DN_DXContainer,
strain_vectors, mStressVector, constitutive_matrices);
const auto integration_coefficients =
this->CalculateIntegrationCoefficients(IntegrationPoints, Variables.detJContainer);

for (unsigned int GPoint = 0; GPoint < NumGPoints; ++GPoint) {
this->CalculateKinematics(Variables, GPoint);
Variables.B = b_matrices[GPoint];
Variables.F = deformation_gradients[GPoint];
Variables.StrainVector = strain_vectors[GPoint];
Variables.ConstitutiveMatrix = constitutive_matrices[GPoint];

// Compute weighting coefficient for integration
Variables.IntegrationCoefficient =
this->CalculateIntegrationCoefficient(IntegrationPoints[GPoint], Variables.detJ);
const auto stiffness_matrix = GeoEquationOfMotionUtilities::CalculateStiffnessMatrix(
b_matrices, constitutive_matrices, integration_coefficients);

// Compute stiffness matrix
this->CalculateAndAddStiffnessMatrix(rStiffnessMatrix, Variables);
}
GeoElementUtilities::AssembleUUBlockMatrix(rStiffnessMatrix, stiffness_matrix);

KRATOS_CATCH("")
}
Expand Down Expand Up @@ -1243,11 +1234,9 @@ void UPwSmallStrainElement<TDim, TNumNodes>::CalculateAndAddStiffnessMatrix(Matr
{
KRATOS_TRY

noalias(rVariables.UVoigtMatrix) = prod(trans(rVariables.B), rVariables.ConstitutiveMatrix);
noalias(rVariables.UUMatrix) = prod(rVariables.UVoigtMatrix, rVariables.B) * rVariables.IntegrationCoefficient;

// Distribute stiffness block matrix into the elemental matrix
GeoElementUtilities::AssembleUUBlockMatrix(rLeftHandSideMatrix, rVariables.UUMatrix);
const auto stiffness_matrix = GeoEquationOfMotionUtilities::CalculateStiffnessMatrixGPoint(
rVariables.B, rVariables.ConstitutiveMatrix, rVariables.IntegrationCoefficient);
GeoElementUtilities::AssembleUUBlockMatrix(rLeftHandSideMatrix, stiffness_matrix);

KRATOS_CATCH("")
}
Expand Down Expand Up @@ -1343,7 +1332,6 @@ void UPwSmallStrainElement<TDim, TNumNodes>::CalculateAndAddStiffnessForce(Vecto
noalias(rVariables.UVector) =
-1.0 * prod(trans(rVariables.B), mStressVector[GPoint]) * rVariables.IntegrationCoefficient;

// Distribute stiffness block vector into elemental vector
GeoElementUtilities::AssembleUBlockVector(rRightHandSideVector, rVariables.UVector);

KRATOS_CATCH("")
Expand Down
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment at line 1334 no longer makes sense. Please remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

Original file line number Diff line number Diff line change
Expand Up @@ -1343,24 +1343,13 @@ void SmallStrainUPwDiffOrderElement::CalculateMaterialStiffnessMatrix(MatrixType
this->CalculateAnyOfMaterialResponse(deformation_gradients, ConstitutiveParameters,
Variables.NuContainer, Variables.DNu_DXContainer,
strain_vectors, mStressVector, constitutive_matrices);
const auto integration_coefficients =
CalculateIntegrationCoefficients(IntegrationPoints, Variables.detJuContainer);

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

// Compute infinitesimal strain
Variables.F = deformation_gradients[GPoint];
Variables.StrainVector = strain_vectors[GPoint];
Variables.ConstitutiveMatrix = constitutive_matrices[GPoint];

// calculating weighting coefficient for integration
Variables.IntegrationCoefficient =
this->CalculateIntegrationCoefficient(IntegrationPoints[GPoint], Variables.detJ);
const auto stiffness_matrix = GeoEquationOfMotionUtilities::CalculateStiffnessMatrix(
b_matrices, constitutive_matrices, integration_coefficients);

// Contributions of material stiffness to the left hand side
this->CalculateAndAddStiffnessMatrix(rStiffnessMatrix, Variables);
}
GeoElementUtilities::AssembleUUBlockMatrix(rStiffnessMatrix, stiffness_matrix);

KRATOS_CATCH("")
}
Expand Down Expand Up @@ -1724,16 +1713,14 @@ void SmallStrainUPwDiffOrderElement::CalculateAndAddLHS(MatrixType& rLeftHandSid
}

void SmallStrainUPwDiffOrderElement::CalculateAndAddStiffnessMatrix(MatrixType& rLeftHandSideMatrix,
ElementVariables& rVariables) const
const ElementVariables& rVariables) const
{
KRATOS_TRY

Matrix StiffnessMatrix =
prod(trans(rVariables.B), Matrix(prod(rVariables.ConstitutiveMatrix, rVariables.B))) *
rVariables.IntegrationCoefficient;
const auto stiffness_matrix = GeoEquationOfMotionUtilities::CalculateStiffnessMatrixGPoint(
rVariables.B, rVariables.ConstitutiveMatrix, rVariables.IntegrationCoefficient);

// Distribute stiffness block matrix into the elemental matrix
GeoElementUtilities::AssembleUUBlockMatrix(rLeftHandSideMatrix, StiffnessMatrix);
GeoElementUtilities::AssembleUUBlockMatrix(rLeftHandSideMatrix, stiffness_matrix);

KRATOS_CATCH("")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) SmallStrainUPwDiffOrderElement : pub

void CalculateAndAddLHS(MatrixType& rLeftHandSideMatrix, ElementVariables& rVariables);

void CalculateAndAddStiffnessMatrix(MatrixType& rLeftHandSideMatrix, ElementVariables& rVariables) const;
void CalculateAndAddStiffnessMatrix(MatrixType& rLeftHandSideMatrix, const ElementVariables& rVariables) const;

void CalculateAndAddCouplingMatrix(MatrixType& rLeftHandSideMatrix, const ElementVariables& rVariables);

Expand Down
12 changes: 11 additions & 1 deletion applications/GeoMechanicsApplication/custom_utilities/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,25 @@ $$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.

### Stiffness Matrix (K)

The mathematical definition is:
$$K = \int_\Omega B^T C_{constitutive} B d\Omega$$

Where $\Omega$ is the domain, $B$ is the B-matrix and $C_{constitutive}$ is the constitutive matrix.


### Damping Matrix (D)

The mathematical definition is:
$$D = \alpha_R M + \beta_R K$$

Where $M$ and $K$ are the mass and stiffness matrices respectively and $\alpha_R$ and $\beta_R$ are the coefficients from the Rayleigh Method.

File equation_of_motion_utilities.hpp includes
File equation_of_motion_utilities.h includes
- CalculateMassMatrix function
- CalculateStiffnessMatrixGPoint provides a stiffness matrix for a specific integration point
- CalculateStiffnessMatrix provides a stiffness matrix for an element
- CalculateDampingMatrix function
- CalculateIntegrationCoefficientsInitialConfiguration function that calculates integration coefficient for all integration points

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,23 @@ Matrix GeoEquationOfMotionUtilities::CalculateDampingMatrix(double Raylei
return RayleighAlpha * rMassMatrix + RayleighBeta * rStiffnessMatrix;
}

Matrix GeoEquationOfMotionUtilities::CalculateStiffnessMatrixGPoint(const Matrix& rB,
const Matrix& rConstitutiveMatrix,
double IntegrationCoefficient)
{
return prod(trans(rB), Matrix(prod(rConstitutiveMatrix, rB))) * IntegrationCoefficient;
}

Matrix GeoEquationOfMotionUtilities::CalculateStiffnessMatrix(const std::vector<Matrix>& rBs,
const std::vector<Matrix>& rConstitutiveMatrices,
const std::vector<double>& rIntegrationCoefficients)
{
Matrix result = ZeroMatrix(rBs[0].size2(), rBs[0].size2());
for (unsigned int GPoint = 0; GPoint < rBs.size(); ++GPoint) {
result += CalculateStiffnessMatrixGPoint(rBs[GPoint], rConstitutiveMatrices[GPoint],
rIntegrationCoefficients[GPoint]);
}
return result;
}

} /* namespace Kratos.*/
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,13 @@ class GeoEquationOfMotionUtilities
const Matrix& rMassMatrix,
const Matrix& rStiffnessMatrix);

static Matrix CalculateStiffnessMatrixGPoint(const Matrix& rB,
const Matrix& rConstitutiveMatrix,
double IntegrationCoefficient);

static Matrix CalculateStiffnessMatrix(const std::vector<Matrix>& rBs,
const std::vector<Matrix>& rConstitutiveMatrices,
const std::vector<double>& rIntegrationCoefficients);

}; /* Class GeoTransportEquationUtilities*/
} /* namespace Kratos.*/
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,29 @@ KRATOS_TEST_CASE_IN_SUITE(CalculateDampingMatrixGivesCorrectResults, KratosGeoMe
KRATOS_CHECK_MATRIX_NEAR(damping_matrix, expected_damping_matrix, 1e-4)
}

KRATOS_TEST_CASE_IN_SUITE(CalculateStiffnessMatrixGivesCorrectResults, KratosGeoMechanicsFastSuite)
{
constexpr std::size_t voigt_size = 4;
constexpr std::size_t n = 3;

const Matrix b = ScalarMatrix(voigt_size, n, 0.5);
std::vector<Matrix> b_matrices;
b_matrices.push_back(b);
b_matrices.push_back(b);

const Matrix constitutive = ScalarMatrix(voigt_size, voigt_size, 2.0);
std::vector<Matrix> constitutive_matrices;
constitutive_matrices.push_back(constitutive);
constitutive_matrices.push_back(constitutive);

std::vector<double> integration_coefficients{1.0, 2.0};

auto stiffness_matrix = GeoEquationOfMotionUtilities::CalculateStiffnessMatrix(
b_matrices, constitutive_matrices, integration_coefficients);

const auto expected_stiffness_matrix = ScalarMatrix(n, n, 24.0);

KRATOS_CHECK_MATRIX_NEAR(stiffness_matrix, expected_stiffness_matrix, 1e-4)
}

} // namespace Kratos::Testing
Loading