Skip to content

Commit

Permalink
Merge pull request #12733 from KratosMultiphysics/geo/some-minor-fixes
Browse files Browse the repository at this point in the history
[Hotfix][Geo] Fixing minor segfaults
  • Loading branch information
rubenzorrilla authored Oct 10, 2024
2 parents 279f0a6 + 3bee499 commit cb6a8f9
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) UPwBaseElement : public Element

std::string Info() const override
{
return "U-Pw Base class Element #" + std::to_string(Id()) +
"\nConstitutive law: " + mConstitutiveLawVector[0]->Info();
const std::string constitutive_info =
!mConstitutiveLawVector.empty() ? mConstitutiveLawVector[0]->Info() : "not defined";
return "U-Pw Base class Element #" + std::to_string(Id()) + "\nConstitutive law: " + constitutive_info;
}

void PrintInfo(std::ostream& rOStream) const override { rOStream << Info(); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,13 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) UPwSmallStrainFICElement
// Turn back information as a string.
std::string Info() const override
{
std::stringstream buffer;
buffer << "U-Pw smal strain FIC Element #" << this->Id()
<< "\nConstitutive law: " << mConstitutiveLawVector[0]->Info();
return buffer.str();
const std::string constitutive_info =
!mConstitutiveLawVector.empty() ? mConstitutiveLawVector[0]->Info() : "not defined";
return "U-Pw smal strain FIC Element #" + std::to_string(this->Id()) + "\nConstitutive law: " + constitutive_info;
}

// Print information about this object.
void PrintInfo(std::ostream& rOStream) const override
{
rOStream << "U-Pw smal strain FIC Element #" << this->Id()
<< "\nConstitutive law: " << mConstitutiveLawVector[0]->Info();
}
void PrintInfo(std::ostream& rOStream) const override { rOStream << Info(); }

protected:
struct FICElementVariables {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,9 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) UPwSmallStrainElement : public UPwBa

std::string Info() const override
{
return "U-Pw small strain Element #" + std::to_string(this->Id()) +
"\nConstitutive law: " + mConstitutiveLawVector[0]->Info();
const std::string constitutive_info =
!mConstitutiveLawVector.empty() ? mConstitutiveLawVector[0]->Info() : "not defined";
return "U-Pw small strain Element #" + std::to_string(this->Id()) + "\nConstitutive law: " + constitutive_info;
}

void PrintInfo(std::ostream& rOStream) const override { rOStream << Info(); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,14 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) UPwSmallStrainLinkInterfaceElement
// Turn back information as a string.
std::string Info() const override
{
std::stringstream buffer;
buffer << "U-Pw small strain link interface Element #" << this->Id()
<< "\nConstitutive law: " << mConstitutiveLawVector[0]->Info();
return buffer.str();
const std::string constitutive_info =
!mConstitutiveLawVector.empty() ? mConstitutiveLawVector[0]->Info() : "not defined";
return "U-Pw small strain link interface Element #" + std::to_string(this->Id()) +
"\nConstitutive law: " + constitutive_info;
}

// Print information about this object.
void PrintInfo(std::ostream& rOStream) const override
{
rOStream << "U-Pw small strain link interface Element #" << this->Id()
<< "\nConstitutive law: " << mConstitutiveLawVector[0]->Info();
}
void PrintInfo(std::ostream& rOStream) const override { rOStream << Info(); }

protected:
// Member Variables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,18 +171,14 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) UPwUpdatedLagrangianFICElement
/// Turn back information as a string.
std::string Info() const override
{
std::stringstream buffer;
buffer << "Updated Lagrangian U-Pw FIC Element #" << this->Id()
<< "\nConstitutive law: " << mConstitutiveLawVector[0]->Info();
return buffer.str();
const std::string constitutive_info =
!mConstitutiveLawVector.empty() ? mConstitutiveLawVector[0]->Info() : "not defined";
return "Updated Lagrangian U-Pw FIC Element #" + std::to_string(this->Id()) +
"\nConstitutive law: " + constitutive_info;
}

/// Print information about this object.
void PrintInfo(std::ostream& rOStream) const override
{
rOStream << "Updated Lagrangian U-Pw FIC Element #" << this->Id()
<< "\nConstitutive law: " << mConstitutiveLawVector[0]->Info();
}
void PrintInfo(std::ostream& rOStream) const override { rOStream << Info(); }

/// Print object's data.
void PrintData(std::ostream& rOStream) const override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,14 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) UPwUpdatedLagrangianElement
/// Turn back information as a string.
std::string Info() const override
{
std::stringstream buffer;
buffer << "Updated Lagrangian U-Pw Element #" << this->Id()
<< "\nConstitutive law: " << mConstitutiveLawVector[0]->Info();
return buffer.str();
const std::string constitutive_info =
!mConstitutiveLawVector.empty() ? mConstitutiveLawVector[0]->Info() : "not defined";
return "Updated Lagrangian U-Pw Element #" + std::to_string(this->Id()) +
"\nConstitutive law: " + constitutive_info;
}

/// Print information about this object.
void PrintInfo(std::ostream& rOStream) const override
{
rOStream << "Updated Lagrangian U-Pw Element #" << this->Id()
<< "\nConstitutive law: " << mConstitutiveLawVector[0]->Info();
}
void PrintInfo(std::ostream& rOStream) const override { rOStream << Info(); }

/// Print object's data.
void PrintData(std::ostream& rOStream) const override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ int SmallStrainUPwDiffOrderElement::Check(const ProcessInfo& rCurrentProcessInfo
if (rGeom.DomainSize() < 1.0e-15)
KRATOS_ERROR << "DomainSize < 1.0e-15 for the element " << this->Id() << std::endl;

// check pressure geometry pointer
KRATOS_DEBUG_ERROR_IF_NOT(mpPressureGeometry) << "Pressure Geometry is not defined\n";

// verify that the variables are correctly initialized
// Verify specific properties
const PropertiesType& rProp = this->GetProperties();
Expand Down Expand Up @@ -164,62 +167,6 @@ int SmallStrainUPwDiffOrderElement::Check(const ProcessInfo& rCurrentProcessInfo
KRATOS_CATCH("")
}

void SmallStrainUPwDiffOrderElement::Initialize(const ProcessInfo& rCurrentProcessInfo)
{
KRATOS_TRY

UPwBaseElement::Initialize(rCurrentProcessInfo);

const auto& r_geometry = GetGeometry();
const auto number_of_U_nodes = r_geometry.PointsNumber();
const auto dimension = r_geometry.WorkingSpaceDimension();

switch (number_of_U_nodes) {
case 6: // 2D T6P3
mpPressureGeometry = make_shared<Triangle2D3<Node>>(r_geometry(0), r_geometry(1), r_geometry(2));
break;
case 8: // 2D Q8P4
mpPressureGeometry = make_shared<Quadrilateral2D4<Node>>(r_geometry(0), r_geometry(1),
r_geometry(2), r_geometry(3));
break;
case 9: // 2D Q9P4
mpPressureGeometry = make_shared<Quadrilateral2D4<Node>>(r_geometry(0), r_geometry(1),
r_geometry(2), r_geometry(3));
break;
case 10: // 3D T10P4 //2D T10P6
if (dimension == 3)
mpPressureGeometry = make_shared<Tetrahedra3D4<Node>>(r_geometry(0), r_geometry(1),
r_geometry(2), r_geometry(3));
else if (dimension == 2)
mpPressureGeometry = make_shared<Triangle2D6<Node>>(
r_geometry(0), r_geometry(1), r_geometry(2), r_geometry(3), r_geometry(4), r_geometry(5));
break;
case 15: // 2D T15P10
mpPressureGeometry = make_shared<Triangle2D10<Node>>(
r_geometry(0), r_geometry(1), r_geometry(2), r_geometry(3), r_geometry(4),
r_geometry(5), r_geometry(6), r_geometry(7), r_geometry(8), r_geometry(9));
break;
case 20: // 3D H20P8
mpPressureGeometry =
make_shared<Hexahedra3D8<Node>>(r_geometry(0), r_geometry(1), r_geometry(2), r_geometry(3),
r_geometry(4), r_geometry(5), r_geometry(6), r_geometry(7));
break;
case 27: // 3D H27P8
mpPressureGeometry =
make_shared<Hexahedra3D8<Node>>(r_geometry(0), r_geometry(1), r_geometry(2), r_geometry(3),
r_geometry(4), r_geometry(5), r_geometry(6), r_geometry(7));
break;
default:
KRATOS_ERROR << "Unexpected geometry type for different order "
"interpolation element"
<< this->Id() << std::endl;
}

mIsInitialised = true;

KRATOS_CATCH("")
}

void SmallStrainUPwDiffOrderElement::InitializeSolutionStep(const ProcessInfo& rCurrentProcessInfo)
{
KRATOS_TRY
Expand Down Expand Up @@ -1587,6 +1534,52 @@ Element::DofsVectorType SmallStrainUPwDiffOrderElement::GetDofs() const
GetGeometry().WorkingSpaceDimension());
}

void SmallStrainUPwDiffOrderElement::SetUpPressureGeometryPointer()
{
const auto& r_geometry = GetGeometry();
const auto number_of_U_nodes = r_geometry.PointsNumber();
const auto dimension = r_geometry.WorkingSpaceDimension();
switch (number_of_U_nodes) {
case 6: // 2D T6P3
mpPressureGeometry = make_shared<Triangle2D3<Node>>(r_geometry(0), r_geometry(1), r_geometry(2));
break;
case 8: // 2D Q8P4
mpPressureGeometry = make_shared<Quadrilateral2D4<Node>>(r_geometry(0), r_geometry(1),
r_geometry(2), r_geometry(3));
break;
case 9: // 2D Q9P4
mpPressureGeometry = make_shared<Quadrilateral2D4<Node>>(r_geometry(0), r_geometry(1),
r_geometry(2), r_geometry(3));
break;
case 10:
if (dimension == 3) // 3D T10P4
mpPressureGeometry = make_shared<Tetrahedra3D4<Node>>(r_geometry(0), r_geometry(1),
r_geometry(2), r_geometry(3));
else if (dimension == 2) // 2D T10P6
mpPressureGeometry = make_shared<Triangle2D6<Node>>(
r_geometry(0), r_geometry(1), r_geometry(2), r_geometry(3), r_geometry(4), r_geometry(5));
break;
case 15: // 2D T15P10
mpPressureGeometry = make_shared<Triangle2D10<Node>>(
r_geometry(0), r_geometry(1), r_geometry(2), r_geometry(3), r_geometry(4),
r_geometry(5), r_geometry(6), r_geometry(7), r_geometry(8), r_geometry(9));
break;
case 20: // 3D H20P8
mpPressureGeometry =
make_shared<Hexahedra3D8<Node>>(r_geometry(0), r_geometry(1), r_geometry(2), r_geometry(3),
r_geometry(4), r_geometry(5), r_geometry(6), r_geometry(7));
break;
case 27: // 3D H27P8
mpPressureGeometry =
make_shared<Hexahedra3D8<Node>>(r_geometry(0), r_geometry(1), r_geometry(2), r_geometry(3),
r_geometry(4), r_geometry(5), r_geometry(6), r_geometry(7));
break;
default:
KRATOS_ERROR << "Unexpected geometry type for different order interpolation element "
<< this->Id() << std::endl;
}
}

Vector SmallStrainUPwDiffOrderElement::GetPressureSolutionVector()
{
Vector result(mpPressureGeometry->PointsNumber());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) SmallStrainUPwDiffOrderElement : pub
std::unique_ptr<StressStatePolicy> pStressStatePolicy)
: UPwBaseElement(NewId, pGeometry, std::move(pStressStatePolicy))
{
SetUpPressureGeometryPointer();
}

SmallStrainUPwDiffOrderElement(IndexType NewId,
Expand All @@ -57,6 +58,7 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) SmallStrainUPwDiffOrderElement : pub
std::unique_ptr<StressStatePolicy> pStressStatePolicy)
: UPwBaseElement(NewId, pGeometry, pProperties, std::move(pStressStatePolicy))
{
SetUpPressureGeometryPointer();
}

~SmallStrainUPwDiffOrderElement() override = default;
Expand All @@ -69,8 +71,6 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) SmallStrainUPwDiffOrderElement : pub

int Check(const ProcessInfo& rCurrentProcessInfo) const override;

void Initialize(const ProcessInfo& rCurrentProcessInfo) override;

void InitializeSolutionStep(const ProcessInfo& rCurrentProcessInfo) override;

void FinalizeSolutionStep(const ProcessInfo& rCurrentProcessInfo) override;
Expand Down Expand Up @@ -108,18 +108,14 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) SmallStrainUPwDiffOrderElement : pub
// Turn back information as a string.
std::string Info() const override
{
std::stringstream buffer;
buffer << "U-Pw small strain different order Element #" << Id()
<< "\nConstitutive law: " << mConstitutiveLawVector[0]->Info();
return buffer.str();
const std::string constitutive_info =
!mConstitutiveLawVector.empty() ? mConstitutiveLawVector[0]->Info() : "not defined";
return "U-Pw small strain different order Element #" + std::to_string(Id()) +
"\nConstitutive law: " + constitutive_info;
}

// Print information about this object.
void PrintInfo(std::ostream& rOStream) const override
{
rOStream << "U-Pw small strain different order Element #" << Id()
<< "\nConstitutive law: " << mConstitutiveLawVector[0]->Info();
}
void PrintInfo(std::ostream& rOStream) const override { rOStream << Info(); }

protected:
struct ElementVariables {
Expand Down Expand Up @@ -262,6 +258,13 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) SmallStrainUPwDiffOrderElement : pub

[[nodiscard]] DofsVectorType GetDofs() const override;

/**
* @brief Sets the up the pressure geometry pointer object
* This function sets the pointer for the auxiliary geometry for the pressure problem
* The pressure geometry pointer is set according to the element geometry number of nodes and dimension
*/
void SetUpPressureGeometryPointer();

// Serialization

friend class Serializer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,13 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) SteadyStatePwElement : public Transi
// Turn back information as a string.
std::string Info() const override
{
std::stringstream buffer;
buffer << "steady-state Pw flow Element #" << this->Id()
<< "\nRetention law: " << mRetentionLawVector[0]->Info();
return buffer.str();
const std::string retention_info =
!mRetentionLawVector.empty() ? mRetentionLawVector[0]->Info() : "not defined";
return "steady-state Pw flow Element #" + std::to_string(this->Id()) + "\nRetention law: " + retention_info;
}

// Print information about this object.
void PrintInfo(std::ostream& rOStream) const override
{
rOStream << "steady-state Pw flow Element #" << this->Id()
<< "\nRetention law: " << mRetentionLawVector[0]->Info();
}
void PrintInfo(std::ostream& rOStream) const override { rOStream << Info(); }

protected:
/// Member Variables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,13 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) TransientPwElement : public UPwSmall
// Turn back information as a string.
std::string Info() const override
{
std::stringstream buffer;
buffer << "transient Pw flow Element #" << this->Id()
<< "\nRetention law: " << mRetentionLawVector[0]->Info();
return buffer.str();
const std::string retention_info =
!mRetentionLawVector.empty() ? mRetentionLawVector[0]->Info() : "not defined";
return "transient Pw flow Element #" + std::to_string(this->Id()) + "\nRetention law: " + retention_info;
}

// Print information about this object.
void PrintInfo(std::ostream& rOStream) const override
{
rOStream << "transient Pw flow Element #" << this->Id()
<< "\nRetention law: " << mRetentionLawVector[0]->Info();
}
void PrintInfo(std::ostream& rOStream) const override { rOStream << Info(); }

protected:
void CalculateAll(MatrixType& rLeftHandSideMatrix,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,14 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) UndrainedUPwSmallStrainElement
// Turn back information as a string.
std::string Info() const override
{
std::stringstream buffer;
buffer << "undrained small strain Element #" << this->Id()
<< "\nConstitutive law: " << mConstitutiveLawVector[0]->Info();
return buffer.str();
const std::string constitutive_info =
!mConstitutiveLawVector.empty() ? mConstitutiveLawVector[0]->Info() : "not defined";
return "undrained small strain Element #" + std::to_string(this->Id()) +
"\nConstitutive law: " + constitutive_info;
}

// Print information about this object.
void PrintInfo(std::ostream& rOStream) const override
{
rOStream << "undrained small strain Element #" << this->Id()
<< "\nConstitutive law: " << mConstitutiveLawVector[0]->Info();
}
void PrintInfo(std::ostream& rOStream) const override { rOStream << Info(); }

protected:
/// Member Variables
Expand Down
Loading

0 comments on commit cb6a8f9

Please sign in to comment.