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 CalculateFluidPressure function #12381

Merged
merged 5 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -1153,7 +1153,8 @@ std::vector<array_1d<double, TDim>> UPwSmallStrainElement<TDim, TNumNodes>::Calc

GeoElementUtilities::InterpolateVariableWithComponents<TDim, TNumNodes>(
Variables.BodyAcceleration, Variables.NContainer, Variables.VolumeAcceleration, GPoint);
Variables.FluidPressure = CalculateFluidPressure(Variables);
Variables.FluidPressure =
RetentionLaw::Parameters::CalculateFluidPressure(Variables.Np, Variables.PressureVector);
RetentionParameters.SetFluidPressure(Variables.FluidPressure);

Variables.RelativePermeability =
Expand Down Expand Up @@ -1747,24 +1748,15 @@ void UPwSmallStrainElement<TDim, TNumNodes>::SetRetentionParameters(const Elemen
KRATOS_CATCH("")
}

template <unsigned int TDim, unsigned int TNumNodes>
double UPwSmallStrainElement<TDim, TNumNodes>::CalculateFluidPressure(const ElementVariables& rVariables)
{
KRATOS_TRY

return inner_prod(rVariables.Np, rVariables.PressureVector);

KRATOS_CATCH("")
}

template <unsigned int TDim, unsigned int TNumNodes>
void UPwSmallStrainElement<TDim, TNumNodes>::CalculateRetentionResponse(ElementVariables& rVariables,
RetentionLaw::Parameters& rRetentionParameters,
unsigned int GPoint)
{
KRATOS_TRY

rVariables.FluidPressure = CalculateFluidPressure(rVariables);
rVariables.FluidPressure =
RetentionLaw::Parameters::CalculateFluidPressure(rVariables.Np, rVariables.PressureVector);
SetRetentionParameters(rVariables, rRetentionParameters);

rVariables.DegreeOfSaturation = mRetentionLawVector[GPoint]->CalculateSaturation(rRetentionParameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,7 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) UPwSmallStrainElement : public UPwBa
void InitializeNodalPorePressureVariables(ElementVariables& rVariables);
void InitializeNodalVolumeAccelerationVariables(ElementVariables& rVariables);

void InitializeProperties(ElementVariables& rVariables);
double CalculateFluidPressure(const ElementVariables& rVariables);
void InitializeProperties(ElementVariables& rVariables);
std::vector<array_1d<double, TDim>> CalculateFluidFluxes(const std::vector<double>& rPermeabilityUpdateFactors,
const ProcessInfo& rCurrentProcessInfo);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,8 @@ void UPwSmallStrainInterfaceElement<TDim, TNumNodes>::CalculateOnIntegrationPoin
RetentionLaw::Parameters RetentionParameters(this->GetProperties(), rCurrentProcessInfo);
// Loop over integration points
for (unsigned int GPoint = 0; GPoint < NumGPoints; ++GPoint) {
Variables.FluidPressure = CalculateFluidPressure(Variables);
Variables.FluidPressure =
RetentionLaw::Parameters::CalculateFluidPressure(Variables.Np, Variables.PressureVector);
SetRetentionParameters(Variables, RetentionParameters);

if (rVariable == DEGREE_OF_SATURATION)
Expand Down Expand Up @@ -2103,23 +2104,14 @@ void UPwSmallStrainInterfaceElement<TDim, TNumNodes>::SetRetentionParameters(
KRATOS_CATCH("")
}

template <unsigned int TDim, unsigned int TNumNodes>
double UPwSmallStrainInterfaceElement<TDim, TNumNodes>::CalculateFluidPressure(const InterfaceElementVariables& rVariables)
{
KRATOS_TRY

return inner_prod(rVariables.Np, rVariables.PressureVector);

KRATOS_CATCH("")
}

template <unsigned int TDim, unsigned int TNumNodes>
void UPwSmallStrainInterfaceElement<TDim, TNumNodes>::CalculateRetentionResponse(
InterfaceElementVariables& rVariables, RetentionLaw::Parameters& rRetentionParameters, unsigned int GPoint)
{
KRATOS_TRY

rVariables.FluidPressure = CalculateFluidPressure(rVariables);
rVariables.FluidPressure =
RetentionLaw::Parameters::CalculateFluidPressure(rVariables.Np, rVariables.PressureVector);
SetRetentionParameters(rVariables, rRetentionParameters);

rVariables.DegreeOfSaturation = mRetentionLawVector[GPoint]->CalculateSaturation(rRetentionParameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,6 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) UPwSmallStrainInterfaceElement
void SetRetentionParameters(const InterfaceElementVariables& rVariables,
RetentionLaw::Parameters& rRetentionParameters);

double CalculateFluidPressure(const InterfaceElementVariables& rVariables);

double CalculateBulkModulus(const Matrix& ConstitutiveMatrix);

void InitializeBiotCoefficients(InterfaceElementVariables& rVariables, const bool& hasBiotCoefficient = false);
Expand All @@ -295,7 +293,7 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) UPwSmallStrainInterfaceElement
unsigned int GPoint);

void CalculateSoilGamma(InterfaceElementVariables& rVariables);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,8 @@ void SmallStrainUPwDiffOrderElement::CalculateOnIntegrationPoints(const Variable
// Compute Np, GradNpT, B and StrainVector
this->CalculateKinematics(Variables, GPoint);

Variables.FluidPressure = CalculateFluidPressure(Variables);
Variables.FluidPressure =
RetentionLaw::Parameters::CalculateFluidPressure(Variables.Np, Variables.PressureVector);
SetRetentionParameters(Variables, RetentionParameters);

if (rVariable == DEGREE_OF_SATURATION)
Expand Down Expand Up @@ -1022,7 +1023,8 @@ void SmallStrainUPwDiffOrderElement::CalculateOnIntegrationPoints(const Variable
BodyAcceleration[idim] += Variables.Nu[i] * Variables.BodyAcceleration[Index++];
}

CalculateFluidPressure(Variables);
Variables.FluidPressure =
RetentionLaw::Parameters::CalculateFluidPressure(Variables.Np, Variables.PressureVector);
Copy link
Contributor

Choose a reason for hiding this comment

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

I have fixed the missing assignment a few minutes ago on master by merging one of my pending PRs. Please update this branch by merging master into it (you will probably need to a resolve a merge conflict, since we have touched the same lines).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right there were merge conflicts.

SetRetentionParameters(Variables, RetentionParameters);

const double RelativePermeability =
Expand Down Expand Up @@ -2113,15 +2115,6 @@ void SmallStrainUPwDiffOrderElement::CalculateJacobianOnCurrentConfiguration(dou
KRATOS_CATCH("")
}

double SmallStrainUPwDiffOrderElement::CalculateFluidPressure(const ElementVariables& rVariables) const
{
KRATOS_TRY

return inner_prod(rVariables.Np, rVariables.PressureVector);

KRATOS_CATCH("")
}

void SmallStrainUPwDiffOrderElement::SetRetentionParameters(const ElementVariables& rVariables,
RetentionLaw::Parameters& rRetentionParameters) const
{
Expand All @@ -2138,7 +2131,8 @@ void SmallStrainUPwDiffOrderElement::CalculateRetentionResponse(ElementVariables
{
KRATOS_TRY

rVariables.FluidPressure = CalculateFluidPressure(rVariables);
rVariables.FluidPressure =
RetentionLaw::Parameters::CalculateFluidPressure(rVariables.Np, rVariables.PressureVector);
SetRetentionParameters(rVariables, rRetentionParameters);

rVariables.DegreeOfSaturation = mRetentionLawVector[GPoint]->CalculateSaturation(rRetentionParameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,6 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) SmallStrainUPwDiffOrderElement : pub
Matrix CalculateDeformationGradient(unsigned int GPoint) const;
std::vector<Matrix> CalculateDeformationGradients() const;

double CalculateFluidPressure(const ElementVariables& rVariables) const;

void SetRetentionParameters(const ElementVariables& rVariables,
RetentionLaw::Parameters& rRetentionParameters) const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,30 @@
#include "includes/serializer.h"
#include <optional>

namespace Kratos {
namespace Kratos
{

/**
* Base class of retention laws.
*/
class KRATOS_API(GEO_MECHANICS_APPLICATION) RetentionLaw {
class KRATOS_API(GEO_MECHANICS_APPLICATION) RetentionLaw
{
public:
/**
* Type definitions
* NOTE: geometries are assumed to be of type Node for all problems
*/
using ProcessInfoType = ProcessInfo;
using SizeType = std::size_t;
using GeometryType = Geometry<Node>;
using SizeType = std::size_t;
using GeometryType = Geometry<Node>;

/**
* Counted pointer of RetentionLaw
*/
KRATOS_CLASS_POINTER_DEFINITION(RetentionLaw);

class Parameters {
class Parameters
{
KRATOS_CLASS_POINTER_DEFINITION(Parameters);

/**
Expand All @@ -64,17 +67,12 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) RetentionLaw {
*/

public:
Parameters(const Properties& rMaterialProperties,
const ProcessInfo& rCurrentProcessInfo)
: mrCurrentProcessInfo(rCurrentProcessInfo),
mrMaterialProperties(rMaterialProperties){};
Parameters(const Properties& rMaterialProperties, const ProcessInfo& rCurrentProcessInfo)
: mrCurrentProcessInfo(rCurrentProcessInfo), mrMaterialProperties(rMaterialProperties){};

~Parameters() = default;

void SetFluidPressure(double FluidPressure)
{
mFluidPressure = FluidPressure;
};
void SetFluidPressure(double FluidPressure) { mFluidPressure = FluidPressure; };

double GetFluidPressure() const
{
Expand All @@ -84,20 +82,19 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) RetentionLaw {
return mFluidPressure.value();
}

const ProcessInfo& GetProcessInfo() const
[[nodiscard]] static double CalculateFluidPressure(const Vector& rN, const Vector& rPressureVector)
Copy link
Contributor

Choose a reason for hiding this comment

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

I fully agree with the idea to move this functionality to a single location, rather than it being scattered across several elements (as it used to be). I doubt, however, whether this nested class is the best possible location. Perhaps we should consult @WPK4FEM. I can imagine that class GeoElementUtilities might be a good alternative. What do you think gentlemen?

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 think we discussed it briefly. Otherwise I would place the function in transport_..._utilities. GeoElementUtilities includes a lot of various functions right now. @WPK4FEM , what is 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.

Computing an interpolated value of a nodal variable uses the interpolation polynomials. These belong to the element and not to constitutive laws nor to retention laws. Therefore GeoElementUtilities sounds like a good place. utilities for retention laws or constitutive models is a bad place. Transport Equation utilities is also a good place, because it handles element matrices for the water pressure part.

As interpolation by definition is the inner product or shape functions and nodal variables, just writing inner_prod is fine. Naming this operation specifically for the water pressures is better, because the name of the function is explaining what the intention is.

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 for the detailed answer. The function has been moved to transport_equation_utilities.

{
return mrCurrentProcessInfo;
return inner_prod(rN, rPressureVector);
}

const Properties& GetMaterialProperties() const
{
return mrMaterialProperties;
}
const ProcessInfo& GetProcessInfo() const { return mrCurrentProcessInfo; }

const Properties& GetMaterialProperties() const { return mrMaterialProperties; }

private:
std::optional<double> mFluidPressure;
const ProcessInfo& mrCurrentProcessInfo;
const Properties& mrMaterialProperties;
const ProcessInfo& mrCurrentProcessInfo;
const Properties& mrMaterialProperties;

}; // class Parameters end

Expand All @@ -121,9 +118,7 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) RetentionLaw {
* @param rValue a reference to the returned value
* @param rValue output: the value of the specified variable
*/
virtual double& CalculateValue(Parameters& rParameters,
const Variable<double>& rThisVariable,
double& rValue) = 0;
virtual double& CalculateValue(Parameters& rParameters, const Variable<double>& rThisVariable, double& rValue) = 0;

virtual double CalculateSaturation(Parameters& rParameters) = 0;

Expand All @@ -143,9 +138,9 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) RetentionLaw {
* @param rElementGeometry the geometry of the current element
* @param rCurrentProcessInfo process info
*/
virtual void InitializeMaterial(const Properties& rMaterialProperties,
virtual void InitializeMaterial(const Properties& rMaterialProperties,
const GeometryType& rElementGeometry,
const Vector& rShapeFunctionsValues);
const Vector& rShapeFunctionsValues);

virtual void Initialize(Parameters& rParameters);

Expand Down Expand Up @@ -175,9 +170,9 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) RetentionLaw {
* @param rShapeFunctionsValues the shape functions values in the current integration point
* @param the current ProcessInfo instance
*/
virtual void ResetMaterial(const Properties& rMaterialProperties,
virtual void ResetMaterial(const Properties& rMaterialProperties,
const GeometryType& rElementGeometry,
const Vector& rShapeFunctionsValues);
const Vector& rShapeFunctionsValues);

/**
* This function is designed to be called once to perform all the checks
Expand All @@ -188,8 +183,7 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) RetentionLaw {
* @param rCurrentProcessInfo
* @return
*/
virtual int Check(const Properties& rMaterialProperties,
const ProcessInfo& rCurrentProcessInfo) = 0;
virtual int Check(const Properties& rMaterialProperties, const ProcessInfo& rCurrentProcessInfo) = 0;

/**
* @brief This method is used to check that two Retention Laws are the same type (references)
Expand All @@ -212,22 +206,13 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) RetentionLaw {
}

/// Turn back information as a string.
virtual std::string Info() const
{
return "RetentionLaw";
}
virtual std::string Info() const { return "RetentionLaw"; }

/// Print information about this object.
virtual void PrintInfo(std::ostream& rOStream) const
{
rOStream << Info();
}
virtual void PrintInfo(std::ostream& rOStream) const { rOStream << Info(); }

/// Print object's data.
virtual void PrintData(std::ostream& rOStream) const
{
rOStream << "RetentionLaw has no data";
}
virtual void PrintData(std::ostream& rOStream) const { rOStream << "RetentionLaw has no data"; }

private:
friend class Serializer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ class GeoTransportEquationUtilities
RetentionLaw::Parameters retention_parameters(rProp, rCurrentProcessInfo);
Vector result(rRetentionLawVector.size());
for (unsigned int g_point = 0; g_point < rRetentionLawVector.size(); ++g_point) {
const double fluid_pressure = inner_prod(row(rNContainer, g_point), rPressureSolution);
const double fluid_pressure = RetentionLaw::Parameters::CalculateFluidPressure(
row(rNContainer, g_point), rPressureSolution);
retention_parameters.SetFluidPressure(fluid_pressure);
result(g_point) = rRetentionLawVector[g_point]->CalculateSaturation(retention_parameters);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// KRATOS___
// // ) )
// // ___ ___
// // ____ //___) ) // ) )
// // / / // // / /
// ((____/ / ((____ ((___/ / MECHANICS
//
// License: geo_mechanics_application/license.txt
//
// Main authors: Gennady Markelov
//

#include "custom_retention/retention_law.h"
#include "includes/checks.h"
#include "testing/testing.h"

using namespace Kratos;

namespace Kratos::Testing
{

KRATOS_TEST_CASE_IN_SUITE(CalculateFluidPressureGivesCorrectResults, KratosGeoMechanicsFastSuite)
{
Vector N(5);
N(0) = 1.0;
N(1) = 2.0;
N(2) = 3.0;
N(3) = 4.0;
N(4) = 5.0;
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe these assignments can be simplified by using operator <<= (after including header boost/numeric/ublas/assignment.hpp):

Suggested change
N(0) = 1.0;
N(1) = 2.0;
N(2) = 3.0;
N(3) = 4.0;
N(4) = 5.0;
N <<= 1.0, 2.0, 3.0, 4.0, 5.0;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Many thanks! Copilot was not able to point to the header file.


Vector pressure_vector(5);
pressure_vector(0) = 0.5;
pressure_vector(1) = 0.7;
pressure_vector(2) = 0.8;
pressure_vector(3) = 0.9;
pressure_vector(4) = 0.4;
Copy link
Contributor

Choose a reason for hiding this comment

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

In the same way, you can simplify these assignments:

Suggested change
pressure_vector(0) = 0.5;
pressure_vector(1) = 0.7;
pressure_vector(2) = 0.8;
pressure_vector(3) = 0.9;
pressure_vector(4) = 0.4;
pressure_vector <<= 0.5, 0.7, 0.8, 0.9, 0.4;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


auto fluid_pressure = RetentionLaw::Parameters::CalculateFluidPressure(N, pressure_vector);
double expected_value = 9.9;
KRATOS_CHECK_NEAR(fluid_pressure, expected_value, 1e-12);
}

} // namespace Kratos::Testing
Loading