Skip to content

Commit a52aa12

Browse files
authored
[GeoMechanicsApplication] Move all non-template code to .cpp files and make sure any .h file does not contain any implementations (retention) (#14082)
* moved code from h to cpp * moved include to geo_mechanics_application.cpp * used string_literals * removed HasSameType
1 parent 33b2013 commit a52aa12

File tree

9 files changed

+108
-82
lines changed

9 files changed

+108
-82
lines changed

applications/GeoMechanicsApplication/custom_retention/retention_law.cpp

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@
1414
#include "custom_retention/retention_law.h"
1515
#include "geo_mechanics_application_variables.h"
1616

17+
#include <string>
18+
19+
using namespace std::string_literals;
20+
1721
namespace Kratos
1822
{
19-
2023
double& RetentionLaw::CalculateValue(Parameters& rParameters, const Variable<double>& rThisVariable, double& rValue) const
2124
{
2225
if (rThisVariable == DEGREE_OF_SATURATION) {
@@ -63,4 +66,45 @@ void RetentionLaw::load(Serializer& rSerializer)
6366
// there is no member variables to be loaded
6467
}
6568

69+
int RetentionLaw::Check(const std::vector<RetentionLaw::Pointer>& rRetentionLawVector,
70+
const Properties& rProperties,
71+
const ProcessInfo& rCurrentProcessInfo)
72+
{
73+
KRATOS_ERROR_IF(rRetentionLawVector.empty()) << "A retention law has to be provided." << std::endl;
74+
75+
return rRetentionLawVector[0]->Check(rProperties, rCurrentProcessInfo);
76+
}
77+
78+
std::string RetentionLaw::Info() const { return "RetentionLaw"s; }
79+
80+
void RetentionLaw::PrintInfo(std::ostream& rOStream) const { rOStream << Info(); }
81+
82+
void RetentionLaw::PrintData(std::ostream& rOStream) const
83+
{
84+
rOStream << "RetentionLaw has no data";
85+
}
86+
87+
RetentionLaw::Parameters::Parameters(const Properties& rMaterialProperties)
88+
: mrMaterialProperties(rMaterialProperties)
89+
{
90+
}
91+
92+
void RetentionLaw::Parameters::SetFluidPressure(double FluidPressure)
93+
{
94+
mFluidPressure = FluidPressure;
95+
};
96+
97+
double RetentionLaw::Parameters::GetFluidPressure() const
98+
{
99+
KRATOS_ERROR_IF_NOT(mFluidPressure.has_value())
100+
<< "Fluid pressure is not yet set in the retention "
101+
"law when trying to retrieve it, aborting.\n";
102+
return mFluidPressure.value();
103+
}
104+
105+
const Properties& RetentionLaw::Parameters::GetMaterialProperties() const
106+
{
107+
return mrMaterialProperties;
108+
}
109+
66110
} // namespace Kratos

applications/GeoMechanicsApplication/custom_retention/retention_law.h

Lines changed: 9 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) RetentionLaw
3232
// Counted pointer of RetentionLaw
3333
KRATOS_CLASS_POINTER_DEFINITION(RetentionLaw);
3434

35-
class Parameters
35+
class KRATOS_API(GEO_MECHANICS_APPLICATION) Parameters
3636
{
3737
KRATOS_CLASS_POINTER_DEFINITION(Parameters);
3838

@@ -41,27 +41,14 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) RetentionLaw
4141
*/
4242

4343
public:
44-
explicit Parameters(const Properties& rMaterialProperties)
45-
: mrMaterialProperties(rMaterialProperties)
46-
{
47-
}
48-
44+
explicit Parameters(const Properties& rMaterialProperties);
4945
~Parameters() = default;
5046

51-
void SetFluidPressure(double FluidPressure) { mFluidPressure = FluidPressure; };
47+
void SetFluidPressure(double FluidPressure);
5248

53-
[[nodiscard]] double GetFluidPressure() const
54-
{
55-
KRATOS_ERROR_IF_NOT(mFluidPressure.has_value())
56-
<< "Fluid pressure is not yet set in the retention "
57-
"law when trying to retrieve it, aborting.\n";
58-
return mFluidPressure.value();
59-
}
49+
[[nodiscard]] double GetFluidPressure() const;
6050

61-
[[nodiscard]] const Properties& GetMaterialProperties() const
62-
{
63-
return mrMaterialProperties;
64-
}
51+
[[nodiscard]] const Properties& GetMaterialProperties() const;
6552

6653
private:
6754
std::optional<double> mFluidPressure;
@@ -115,38 +102,13 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) RetentionLaw
115102

116103
static int Check(const std::vector<RetentionLaw::Pointer>& rRetentionLawVector,
117104
const Properties& rProperties,
118-
const ProcessInfo& rCurrentProcessInfo)
119-
{
120-
KRATOS_ERROR_IF(rRetentionLawVector.empty()) << "A retention law has to be provided." << std::endl;
121-
122-
return rRetentionLawVector[0]->Check(rProperties, rCurrentProcessInfo);
123-
}
124-
125-
/**
126-
* @brief This method is used to check that two Retention Laws are the same type (references)
127-
* @param rLHS The first argument
128-
* @param rRHS The second argument
129-
*/
130-
inline static bool HasSameType(const RetentionLaw& rLHS, const RetentionLaw& rRHS)
131-
{
132-
return (typeid(rLHS) == typeid(rRHS));
133-
}
134-
135-
/**
136-
* @brief This method is used to check that tow Retention Laws are the same type (pointers)
137-
* @param rLHS The first argument
138-
* @param rRHS The second argument
139-
*/
140-
inline static bool HasSameType(const RetentionLaw* rLHS, const RetentionLaw* rRHS)
141-
{
142-
return HasSameType(*rLHS, *rRHS);
143-
}
105+
const ProcessInfo& rCurrentProcessInfo);
144106

145-
[[nodiscard]] virtual std::string Info() const { return "RetentionLaw"; }
107+
[[nodiscard]] virtual std::string Info() const;
146108

147-
virtual void PrintInfo(std::ostream& rOStream) const { rOStream << Info(); }
109+
virtual void PrintInfo(std::ostream& rOStream) const;
148110

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

151113
private:
152114
friend class Serializer;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// KRATOS___
2+
// // ) )
3+
// // ___ ___
4+
// // ____ //___) ) // ) )
5+
// // / / // // / /
6+
// ((____/ / ((____ ((___/ / MECHANICS
7+
//
8+
// License: geo_mechanics_application/license.txt
9+
//
10+
// Main authors: Vahid Galavi
11+
//
12+
13+
// Project includes
14+
#include "custom_retention/retention_law_factory.h"
15+
#include "custom_retention/saturated_below_phreatic_level_law.h"
16+
#include "custom_retention/saturated_law.h"
17+
#include "custom_retention/van_genuchten_law.h"
18+
19+
// Application includes
20+
#include "geo_mechanics_application_variables.h"
21+
22+
namespace Kratos
23+
{
24+
std::unique_ptr<RetentionLaw> RetentionLawFactory::Clone(const Properties& rMaterialProperties)
25+
{
26+
if (rMaterialProperties.Has(RETENTION_LAW)) {
27+
const std::string& RetentionLawName = rMaterialProperties[RETENTION_LAW];
28+
if (RetentionLawName == "VanGenuchtenLaw") return std::make_unique<VanGenuchtenLaw>();
29+
30+
if (RetentionLawName == "SaturatedLaw") return std::make_unique<SaturatedLaw>();
31+
32+
if (RetentionLawName == "SaturatedBelowPhreaticLevelLaw")
33+
return std::make_unique<SaturatedBelowPhreaticLevelLaw>();
34+
35+
if (RetentionLawName == "PressureFilterLaw") return std::make_unique<SaturatedLaw>();
36+
37+
KRATOS_ERROR << "Undefined RETENTION_LAW! " << RetentionLawName << std::endl;
38+
39+
return nullptr;
40+
}
41+
42+
// default is saturated law
43+
return std::make_unique<SaturatedLaw>();
44+
}
45+
46+
} // namespace Kratos.

applications/GeoMechanicsApplication/custom_retention/retention_law_factory.h

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,12 @@
1313
#pragma once
1414

1515
// System includes
16-
#include "includes/define.h"
17-
#include <iostream>
18-
#include <string>
19-
20-
// External includes
21-
22-
// Project includes
2316
#include "custom_retention/retention_law.h"
24-
#include "custom_retention/saturated_below_phreatic_level_law.h"
25-
#include "custom_retention/saturated_law.h"
26-
#include "custom_retention/van_genuchten_law.h"
27-
28-
// Application includes
29-
#include "geo_mechanics_application_variables.h"
17+
#include "includes/define.h"
3018

3119
namespace Kratos
3220
{
21+
class Properties;
3322

3423
/**
3524
* @class RetentionLawFactory
@@ -42,27 +31,7 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) RetentionLawFactory
4231
/// Counted pointer of RetentionLawFactory
4332
KRATOS_CLASS_POINTER_DEFINITION(RetentionLawFactory);
4433

45-
static unique_ptr<RetentionLaw> Clone(const Properties& rMaterialProperties)
46-
{
47-
if (rMaterialProperties.Has(RETENTION_LAW)) {
48-
const std::string& RetentionLawName = rMaterialProperties[RETENTION_LAW];
49-
if (RetentionLawName == "VanGenuchtenLaw") return std::make_unique<VanGenuchtenLaw>();
50-
51-
if (RetentionLawName == "SaturatedLaw") return std::make_unique<SaturatedLaw>();
52-
53-
if (RetentionLawName == "SaturatedBelowPhreaticLevelLaw")
54-
return std::make_unique<SaturatedBelowPhreaticLevelLaw>();
55-
56-
if (RetentionLawName == "PressureFilterLaw") return std::make_unique<SaturatedLaw>();
57-
58-
KRATOS_ERROR << "Undefined RETENTION_LAW! " << RetentionLawName << std::endl;
59-
60-
return nullptr;
61-
}
62-
63-
// default is saturated law
64-
return std::make_unique<SaturatedLaw>();
65-
}
34+
static std::unique_ptr<RetentionLaw> Clone(const Properties& rMaterialProperties);
6635

6736
}; // Class RetentionLawFactory
6837
} // namespace Kratos.

applications/GeoMechanicsApplication/geo_mechanics_application.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
// Application includes
1616
#include "geo_mechanics_application.h"
17+
#include "custom_retention/saturated_below_phreatic_level_law.h"
1718

1819
namespace Kratos
1920
{

applications/GeoMechanicsApplication/tests/cpp_tests/custom_elements/test_pw_element.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "custom_elements/Pw_element.h"
1515
#include "custom_elements/calculation_contribution.h"
1616
#include "custom_elements/integration_coefficient_modifier_for_line_element.h"
17+
#include "custom_retention/saturated_law.h"
1718
#include "geometries/line_2d_4.h"
1819
#include "geometries/line_2d_5.h"
1920
#include "tests/cpp_tests/geo_mechanics_fast_suite.h"

applications/GeoMechanicsApplication/tests/cpp_tests/custom_elements/test_small_strain_u_pw_diff_order_element.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "custom_constitutive/plane_strain.h"
1515
#include "custom_elements/plane_strain_stress_state.h"
1616
#include "custom_elements/small_strain_U_Pw_diff_order_element.hpp"
17+
#include "custom_retention/saturated_law.h"
1718
#include "custom_utilities/registration_utilities.h"
1819
#include "custom_utilities/ublas_utilities.h"
1920
#include "geo_mechanics_application_variables.h"

applications/GeoMechanicsApplication/tests/cpp_tests/custom_elements/test_transient_Pw_element.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "custom_elements/plane_strain_stress_state.h"
1515
#include "custom_elements/three_dimensional_stress_state.h"
1616
#include "custom_elements/transient_Pw_element.hpp"
17+
#include "custom_retention/saturated_law.h"
1718
#include "tests/cpp_tests/geo_mechanics_fast_suite.h"
1819
#include "tests/cpp_tests/test_utilities.h"
1920

applications/GeoMechanicsApplication/tests/cpp_tests/custom_elements/test_u_pw_small_strain_element.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "custom_constitutive/small_strain_udsm_law.h"
1717
#include "custom_elements/U_Pw_small_strain_element.hpp"
1818
#include "custom_elements/plane_strain_stress_state.h"
19+
#include "custom_retention/saturated_law.h"
1920
#include "custom_utilities/registration_utilities.h"
2021
#include "includes/variables.h"
2122
#include "test_setup_utilities/element_setup_utilities.h"

0 commit comments

Comments
 (0)