Skip to content
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 @@ -14,9 +14,12 @@
#include "custom_retention/retention_law.h"
#include "geo_mechanics_application_variables.h"

#include <string>

using namespace std::string_literals;

namespace Kratos
{

double& RetentionLaw::CalculateValue(Parameters& rParameters, const Variable<double>& rThisVariable, double& rValue) const
{
if (rThisVariable == DEGREE_OF_SATURATION) {
Expand Down Expand Up @@ -63,4 +66,45 @@ void RetentionLaw::load(Serializer& rSerializer)
// there is no member variables to be loaded
}

int RetentionLaw::Check(const std::vector<RetentionLaw::Pointer>& rRetentionLawVector,
const Properties& rProperties,
const ProcessInfo& rCurrentProcessInfo)
{
KRATOS_ERROR_IF(rRetentionLawVector.empty()) << "A retention law has to be provided." << std::endl;

return rRetentionLawVector[0]->Check(rProperties, rCurrentProcessInfo);
}

std::string RetentionLaw::Info() const { return "RetentionLaw"s; }

void RetentionLaw::PrintInfo(std::ostream& rOStream) const { rOStream << Info(); }

void RetentionLaw::PrintData(std::ostream& rOStream) const
{
rOStream << "RetentionLaw has no data";
}

RetentionLaw::Parameters::Parameters(const Properties& rMaterialProperties)
: mrMaterialProperties(rMaterialProperties)
{
}

void RetentionLaw::Parameters::SetFluidPressure(double FluidPressure)
{
mFluidPressure = FluidPressure;
};

double RetentionLaw::Parameters::GetFluidPressure() const
{
KRATOS_ERROR_IF_NOT(mFluidPressure.has_value())
<< "Fluid pressure is not yet set in the retention "
"law when trying to retrieve it, aborting.\n";
return mFluidPressure.value();
}

const Properties& RetentionLaw::Parameters::GetMaterialProperties() const
{
return mrMaterialProperties;
}

} // namespace Kratos
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) RetentionLaw
// Counted pointer of RetentionLaw
KRATOS_CLASS_POINTER_DEFINITION(RetentionLaw);

class Parameters
class KRATOS_API(GEO_MECHANICS_APPLICATION) Parameters
Copy link
Contributor

Choose a reason for hiding this comment

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

I haven't seen this used on internal classes (defined within another class). Is it necessary to add the KRATOS_API macro here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is necessary because I moved the definitions to cpp file.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, but then it's also necessary for the internal class? I know it's necessary for classes in general, but this parameters class is defined within the retention_law class

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is not linkable without KRATOS_API(GEO_MECHANICS_APPLICATION) because the functions have been moved to cpp file.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh apologies, I had missed the functions of this internal object had indeed also moved, thanks for the explanation!

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it has to do with the fact that this inner class is being referenced from the unit tests. Since the unit tests are in a separate executable, when building the unit tests the class and all of its members must be accessible. Previously, since the entire class and its definitions were in the header file, this requirement was met (resulting in duplicated machine code: one as part of the GeoMechanicsCore library and the other one as part of the unit test executable). After all, we include that header in the unit tests. Now that the definitions have been moved to the implementation file, that mechanism no longer worked. And also linking to the GeoMechanicsCore library didn't work, since the entire class wasn't exposed. Now that this class is exposed (by using KRATOS_API(GEO_MECHANICS_APPLICATION)), linking will work (and we have a single binary representation of this inner class, which is nice).

{
KRATOS_CLASS_POINTER_DEFINITION(Parameters);

Expand All @@ -41,27 +41,14 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) RetentionLaw
*/

public:
explicit Parameters(const Properties& rMaterialProperties)
: mrMaterialProperties(rMaterialProperties)
{
}

explicit Parameters(const Properties& rMaterialProperties);
~Parameters() = default;

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

[[nodiscard]] double GetFluidPressure() const
{
KRATOS_ERROR_IF_NOT(mFluidPressure.has_value())
<< "Fluid pressure is not yet set in the retention "
"law when trying to retrieve it, aborting.\n";
return mFluidPressure.value();
}
[[nodiscard]] double GetFluidPressure() const;

[[nodiscard]] const Properties& GetMaterialProperties() const
{
return mrMaterialProperties;
}
[[nodiscard]] const Properties& GetMaterialProperties() const;

private:
std::optional<double> mFluidPressure;
Expand Down Expand Up @@ -115,38 +102,13 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) RetentionLaw

static int Check(const std::vector<RetentionLaw::Pointer>& rRetentionLawVector,
const Properties& rProperties,
const ProcessInfo& rCurrentProcessInfo)
{
KRATOS_ERROR_IF(rRetentionLawVector.empty()) << "A retention law has to be provided." << std::endl;

return rRetentionLawVector[0]->Check(rProperties, rCurrentProcessInfo);
}

/**
* @brief This method is used to check that two Retention Laws are the same type (references)
* @param rLHS The first argument
* @param rRHS The second argument
*/
inline static bool HasSameType(const RetentionLaw& rLHS, const RetentionLaw& rRHS)
{
return (typeid(rLHS) == typeid(rRHS));
}

/**
* @brief This method is used to check that tow Retention Laws are the same type (pointers)
* @param rLHS The first argument
* @param rRHS The second argument
*/
inline static bool HasSameType(const RetentionLaw* rLHS, const RetentionLaw* rRHS)
{
return HasSameType(*rLHS, *rRHS);
}
const ProcessInfo& rCurrentProcessInfo);

[[nodiscard]] virtual std::string Info() const { return "RetentionLaw"; }
[[nodiscard]] virtual std::string Info() const;

virtual void PrintInfo(std::ostream& rOStream) const { rOStream << Info(); }
virtual void PrintInfo(std::ostream& rOStream) const;

virtual void PrintData(std::ostream& rOStream) const { rOStream << "RetentionLaw has no data"; }
virtual void PrintData(std::ostream& rOStream) const;

private:
friend class Serializer;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// KRATOS___
// // ) )
// // ___ ___
// // ____ //___) ) // ) )
// // / / // // / /
// ((____/ / ((____ ((___/ / MECHANICS
//
// License: geo_mechanics_application/license.txt
//
// Main authors: Vahid Galavi
//

// Project includes
#include "custom_retention/retention_law_factory.h"
#include "custom_retention/saturated_below_phreatic_level_law.h"
#include "custom_retention/saturated_law.h"
#include "custom_retention/van_genuchten_law.h"

// Application includes
#include "geo_mechanics_application_variables.h"

namespace Kratos
{
std::unique_ptr<RetentionLaw> RetentionLawFactory::Clone(const Properties& rMaterialProperties)
{
if (rMaterialProperties.Has(RETENTION_LAW)) {
const std::string& RetentionLawName = rMaterialProperties[RETENTION_LAW];
if (RetentionLawName == "VanGenuchtenLaw") return std::make_unique<VanGenuchtenLaw>();

if (RetentionLawName == "SaturatedLaw") return std::make_unique<SaturatedLaw>();

if (RetentionLawName == "SaturatedBelowPhreaticLevelLaw")
return std::make_unique<SaturatedBelowPhreaticLevelLaw>();

if (RetentionLawName == "PressureFilterLaw") return std::make_unique<SaturatedLaw>();

KRATOS_ERROR << "Undefined RETENTION_LAW! " << RetentionLawName << std::endl;

return nullptr;
}

// default is saturated law
return std::make_unique<SaturatedLaw>();
}

} // namespace Kratos.
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,12 @@
#pragma once

// System includes
#include "includes/define.h"
#include <iostream>
#include <string>

// External includes

// Project includes
#include "custom_retention/retention_law.h"
#include "custom_retention/saturated_below_phreatic_level_law.h"
#include "custom_retention/saturated_law.h"
#include "custom_retention/van_genuchten_law.h"

// Application includes
#include "geo_mechanics_application_variables.h"
#include "includes/define.h"

namespace Kratos
{
class Properties;

/**
* @class RetentionLawFactory
Expand All @@ -42,27 +31,7 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) RetentionLawFactory
/// Counted pointer of RetentionLawFactory
KRATOS_CLASS_POINTER_DEFINITION(RetentionLawFactory);

static unique_ptr<RetentionLaw> Clone(const Properties& rMaterialProperties)
{
if (rMaterialProperties.Has(RETENTION_LAW)) {
const std::string& RetentionLawName = rMaterialProperties[RETENTION_LAW];
if (RetentionLawName == "VanGenuchtenLaw") return std::make_unique<VanGenuchtenLaw>();

if (RetentionLawName == "SaturatedLaw") return std::make_unique<SaturatedLaw>();

if (RetentionLawName == "SaturatedBelowPhreaticLevelLaw")
return std::make_unique<SaturatedBelowPhreaticLevelLaw>();

if (RetentionLawName == "PressureFilterLaw") return std::make_unique<SaturatedLaw>();

KRATOS_ERROR << "Undefined RETENTION_LAW! " << RetentionLawName << std::endl;

return nullptr;
}

// default is saturated law
return std::make_unique<SaturatedLaw>();
}
static std::unique_ptr<RetentionLaw> Clone(const Properties& rMaterialProperties);

}; // Class RetentionLawFactory
} // namespace Kratos.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

// Application includes
#include "geo_mechanics_application.h"
#include "custom_retention/saturated_below_phreatic_level_law.h"

namespace Kratos
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "custom_elements/Pw_element.h"
#include "custom_elements/calculation_contribution.h"
#include "custom_elements/integration_coefficient_modifier_for_line_element.h"
#include "custom_retention/saturated_law.h"
#include "geometries/line_2d_4.h"
#include "geometries/line_2d_5.h"
#include "tests/cpp_tests/geo_mechanics_fast_suite.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "custom_constitutive/plane_strain.h"
#include "custom_elements/plane_strain_stress_state.h"
#include "custom_elements/small_strain_U_Pw_diff_order_element.hpp"
#include "custom_retention/saturated_law.h"
#include "custom_utilities/registration_utilities.h"
#include "custom_utilities/ublas_utilities.h"
#include "geo_mechanics_application_variables.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "custom_elements/plane_strain_stress_state.h"
#include "custom_elements/three_dimensional_stress_state.h"
#include "custom_elements/transient_Pw_element.hpp"
#include "custom_retention/saturated_law.h"
#include "tests/cpp_tests/geo_mechanics_fast_suite.h"
#include "tests/cpp_tests/test_utilities.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "custom_constitutive/small_strain_udsm_law.h"
#include "custom_elements/U_Pw_small_strain_element.hpp"
#include "custom_elements/plane_strain_stress_state.h"
#include "custom_retention/saturated_law.h"
#include "custom_utilities/registration_utilities.h"
#include "includes/variables.h"
#include "test_setup_utilities/element_setup_utilities.h"
Expand Down
Loading