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鈥檒l 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 Damping Matrix (D) #12368

Merged
merged 7 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -14,6 +14,7 @@
// Application includes
#include "custom_elements/U_Pw_base_element.hpp"
#include "custom_utilities/dof_utilities.h"
#include "custom_utilities/equation_of_motion_utilities.h"

namespace Kratos
{
Expand Down Expand Up @@ -327,26 +328,19 @@ void UPwBaseElement<TDim, TNumNodes>::CalculateDampingMatrix(MatrixType&
const unsigned int N_DOF = this->GetNumberOfDOF();

// Compute Mass Matrix
Copy link
Contributor

Choose a reason for hiding this comment

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

Feel free to remove this comment, since it doesn't add anything that the code already tells.

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. Indeed the comments just repeat the function names. Removed

MatrixType MassMatrix(N_DOF, N_DOF);

this->CalculateMassMatrix(MassMatrix, rCurrentProcessInfo);
MatrixType mass_matrix(N_DOF, N_DOF);
this->CalculateMassMatrix(mass_matrix, rCurrentProcessInfo);

// Compute Stiffness matrix
Copy link
Contributor

Choose a reason for hiding this comment

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

Feel free to also remove this comment.

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

MatrixType StiffnessMatrix(N_DOF, N_DOF);

this->CalculateMaterialStiffnessMatrix(StiffnessMatrix, rCurrentProcessInfo);
MatrixType stiffness_matrix(N_DOF, N_DOF);
this->CalculateMaterialStiffnessMatrix(stiffness_matrix, rCurrentProcessInfo);

// Compute Damping Matrix
Copy link
Contributor

Choose a reason for hiding this comment

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

And the same thing applies to this comment.

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

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

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

if (rProp.Has(RAYLEIGH_ALPHA)) noalias(rDampingMatrix) += rProp[RAYLEIGH_ALPHA] * MassMatrix;
else noalias(rDampingMatrix) += rCurrentProcessInfo[RAYLEIGH_ALPHA] * MassMatrix;

if (rProp.Has(RAYLEIGH_BETA)) noalias(rDampingMatrix) += rProp[RAYLEIGH_BETA] * StiffnessMatrix;
else noalias(rDampingMatrix) += rCurrentProcessInfo[RAYLEIGH_BETA] * StiffnessMatrix;
const PropertiesType& r_prop = this->GetProperties();
rDampingMatrix = GeoEquationOfMotionUtilities::CalculateDampingMatrix(
r_prop.Has(RAYLEIGH_ALPHA) ? r_prop[RAYLEIGH_ALPHA] : rCurrentProcessInfo[RAYLEIGH_ALPHA],
r_prop.Has(RAYLEIGH_BETA) ? r_prop[RAYLEIGH_BETA] : rCurrentProcessInfo[RAYLEIGH_BETA],
mass_matrix, stiffness_matrix);

KRATOS_CATCH("")
}
Expand Down Expand Up @@ -527,8 +521,8 @@ void UPwBaseElement<TDim, TNumNodes>::CalculateAll(MatrixType& rLeftHandS

//----------------------------------------------------------------------------------------
template <unsigned int TDim, unsigned int TNumNodes>
double UPwBaseElement<TDim, TNumNodes>::CalculateIntegrationCoefficient(
const GeometryType::IntegrationPointType& rIntegrationPoint, double detJ) const
double UPwBaseElement<TDim, TNumNodes>::CalculateIntegrationCoefficient(const GeometryType::IntegrationPointType& rIntegrationPoint,
double detJ) const

{
return mpStressStatePolicy->CalculateIntegrationCoefficient(rIntegrationPoint, detJ, GetGeometry());
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.

Thanks for eliminating the duplication; this looks much better. I have the same suggestions about code comments as for the previous file.

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 the comments

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// Application includes
#include "custom_elements/geo_structural_base_element.hpp"
#include "custom_utilities/dof_utilities.h"
#include "custom_utilities/equation_of_motion_utilities.h"
#include "geo_mechanics_application_variables.h"

namespace Kratos
Expand Down Expand Up @@ -268,22 +269,18 @@ void GeoStructuralBaseElement<TDim, TNumNodes>::CalculateDampingMatrix(MatrixTyp
// Rayleigh Method: Damping Matrix = alpha*M + beta*K

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

this->CalculateMassMatrix(MassMatrix, rCurrentProcessInfo);
MatrixType mass_matrix(N_DOF_ELEMENT, N_DOF_ELEMENT);
this->CalculateMassMatrix(mass_matrix, rCurrentProcessInfo);

// Compute Stiffness matrix
MatrixType StiffnessMatrix(N_DOF_ELEMENT, N_DOF_ELEMENT);

this->CalculateStiffnessMatrix(StiffnessMatrix, rCurrentProcessInfo);
MatrixType stiffness_matrix(N_DOF_ELEMENT, N_DOF_ELEMENT);
this->CalculateStiffnessMatrix(stiffness_matrix, rCurrentProcessInfo);

// Compute Damping Matrix
if (rDampingMatrix.size1() != N_DOF_ELEMENT)
rDampingMatrix.resize(N_DOF_ELEMENT, N_DOF_ELEMENT, false);
noalias(rDampingMatrix) = ZeroMatrix(N_DOF_ELEMENT, N_DOF_ELEMENT);

noalias(rDampingMatrix) += rCurrentProcessInfo[RAYLEIGH_ALPHA] * MassMatrix;
noalias(rDampingMatrix) += rCurrentProcessInfo[RAYLEIGH_BETA] * StiffnessMatrix;
noalias(rDampingMatrix) = GeoEquationOfMotionUtilities::CalculateDampingMatrix(
rCurrentProcessInfo[RAYLEIGH_ALPHA], rCurrentProcessInfo[RAYLEIGH_BETA], mass_matrix, stiffness_matrix);
Copy link
Contributor

Choose a reason for hiding this comment

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

Apparently, the damping for the "structural" elements within geo have an implementation that differs from the continuum elements. I wonder whether we should make the possibility for a material based alpha and beta possible or to avoid that effort as we hope to let the "structural" elements within geo slowly disappear.


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.

Same suggestions about the code comments.

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 the comments

Original file line number Diff line number Diff line change
Expand Up @@ -490,21 +490,14 @@ void SmallStrainUPwDiffOrderElement::CalculateDampingMatrix(MatrixType& r
this->CalculateMassMatrix(mass_matrix, rCurrentProcessInfo);

// Compute Stiffness matrix
MatrixType StiffnessMatrix(element_size, element_size);

this->CalculateMaterialStiffnessMatrix(StiffnessMatrix, rCurrentProcessInfo);
MatrixType stiffness_matrix(element_size, element_size);
this->CalculateMaterialStiffnessMatrix(stiffness_matrix, rCurrentProcessInfo);

// Compute Damping Matrix
if (rDampingMatrix.size1() != element_size)
rDampingMatrix.resize(element_size, element_size, false);
noalias(rDampingMatrix) = ZeroMatrix(element_size, element_size);

if (r_prop.Has(RAYLEIGH_ALPHA)) noalias(rDampingMatrix) += r_prop[RAYLEIGH_ALPHA] * mass_matrix;
else noalias(rDampingMatrix) += rCurrentProcessInfo[RAYLEIGH_ALPHA] * mass_matrix;

if (r_prop.Has(RAYLEIGH_BETA))
noalias(rDampingMatrix) += r_prop[RAYLEIGH_BETA] * StiffnessMatrix;
else noalias(rDampingMatrix) += rCurrentProcessInfo[RAYLEIGH_BETA] * StiffnessMatrix;
rDampingMatrix = GeoEquationOfMotionUtilities::CalculateDampingMatrix(
r_prop.Has(RAYLEIGH_ALPHA) ? r_prop[RAYLEIGH_ALPHA] : rCurrentProcessInfo[RAYLEIGH_ALPHA],
r_prop.Has(RAYLEIGH_BETA) ? r_prop[RAYLEIGH_BETA] : rCurrentProcessInfo[RAYLEIGH_BETA],
mass_matrix, stiffness_matrix);

KRATOS_CATCH("")
}
Expand Down Expand Up @@ -2036,7 +2029,7 @@ Vector SmallStrainUPwDiffOrderElement::CalculateStrain(const Matrix& rDeformatio
const SizeType VoigtSize = (Dim == N_DIM_3D ? VOIGT_SIZE_3D : VOIGT_SIZE_2D_PLANE_STRAIN);
return StressStrainUtilities::CalculateHenckyStrain(rDeformationGradient, VoigtSize);
}

return this->CalculateCauchyStrain(rB, rDisplacements);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,16 @@ $$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.

### 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
- CalculateMassMatrix function
- CalculateDampingMatrix function
- CalculateIntegrationCoefficientsInitialConfiguration function that calculates integration coefficient for all integration points

## Stress strain utilities
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,12 @@ Vector GeoEquationOfMotionUtilities::CalculateDetJsInitialConfiguration(const Ge
return det_Js_initial_configuration;
}

Matrix GeoEquationOfMotionUtilities::CalculateDampingMatrix(double RayleighAlpha,
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we ever want to check the inputs for the damping matrix (e.g. in this case I'd expect alpha and beta to be >0). We can also just assume the numbers to be correct, but since they are direct user inputs in this case, it might be a good idea to check them?

This might also be a broader discussion, since we don't do input validation for the jsons now, we might want to do that in a central place and avoid expensive checks for each time we call this function (which is done for each time step and each element of course)

Copy link
Contributor

Choose a reason for hiding this comment

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

Checks should be as early as possible and once, so not here but at element initialization and once per material property/constitutive law.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fully agreed with Wijtze-Pieter.

double RayleighBeta,
const Matrix& rMassMatrix,
const Matrix& rStiffnessMatrix)
{
return RayleighAlpha * rMassMatrix + RayleighBeta * rStiffnessMatrix;
}

} /* namespace Kratos.*/
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,10 @@ class GeoEquationOfMotionUtilities
static Vector CalculateDetJsInitialConfiguration(const Geometry<Node>& rGeom,
const GeometryData::IntegrationMethod IntegrationMethod);

static Matrix CalculateDampingMatrix(double RayleighAlpha,
double RayleighBeta,
const Matrix& rMassMatrix,
const Matrix& rStiffnessMatrix);

}; /* Class GeoTransportEquationUtilities*/
} /* namespace Kratos.*/
rfaasse marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// KRATOS___
// // ) )
// // ___ ___
// // ____ //___) ) // ) )
// // / / // // / /
// ((____/ / ((____ ((___/ / MECHANICS
//
// License: geo_mechanics_application/license.txt
//
// Main authors: Gennady Markelov
//

#include "custom_utilities/equation_of_motion_utilities.h"
#include "includes/checks.h"
#include "testing/testing.h"

using namespace Kratos;

namespace Kratos::Testing
{

KRATOS_TEST_CASE_IN_SUITE(CalculateDampingMatrixGivesCorrectResults, KratosGeoMechanicsFastSuite)
Copy link
Contributor

Choose a reason for hiding this comment

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

Very clear test!

{
constexpr std::size_t n = 10;

constexpr double mass_matrix_value = 10;
const auto mass_matrix = scalar_matrix(n, n, mass_matrix_value);

constexpr double stiffness_matrix_value = 20;
const auto stiffness_matrix = scalar_matrix(n, n, stiffness_matrix_value);

double rayleigh_alpha = 0.0;
double rayleigh_beta = 1.0;
auto damping_matrix = GeoEquationOfMotionUtilities::CalculateDampingMatrix(
rayleigh_alpha, rayleigh_beta, mass_matrix, stiffness_matrix);

KRATOS_CHECK_MATRIX_NEAR(damping_matrix, stiffness_matrix, 1e-4);

rayleigh_alpha = 1.0;
rayleigh_beta = 0.0;
damping_matrix = GeoEquationOfMotionUtilities::CalculateDampingMatrix(
rayleigh_alpha, rayleigh_beta, mass_matrix, stiffness_matrix);

KRATOS_CHECK_MATRIX_NEAR(damping_matrix, mass_matrix, 1e-4);

rayleigh_alpha = 0.5;
rayleigh_beta = 0.5;
damping_matrix = GeoEquationOfMotionUtilities::CalculateDampingMatrix(
rayleigh_alpha, rayleigh_beta, mass_matrix, stiffness_matrix);

const double expected_matrix_value = rayleigh_alpha * mass_matrix_value + rayleigh_beta * stiffness_matrix_value;
const auto expected_damping_matrix = scalar_matrix(n, n, expected_matrix_value);

KRATOS_CHECK_MATRIX_NEAR(damping_matrix, expected_damping_matrix, 1e-4)
}

} // namespace Kratos::Testing
Loading