diff --git a/applications/GeoMechanicsApplication/custom_constitutive/thermal_dispersion_law.cpp b/applications/GeoMechanicsApplication/custom_constitutive/thermal_dispersion_law.cpp index cf3d9566a78a..6f5c359fd0f0 100644 --- a/applications/GeoMechanicsApplication/custom_constitutive/thermal_dispersion_law.cpp +++ b/applications/GeoMechanicsApplication/custom_constitutive/thermal_dispersion_law.cpp @@ -19,20 +19,15 @@ namespace Kratos { -GeoThermalDispersionLaw::GeoThermalDispersionLaw() { mNumberOfDimensions = 2; } +GeoThermalDispersionLaw::GeoThermalDispersionLaw() : mNumberOfDimensions{2} {} GeoThermalDispersionLaw::GeoThermalDispersionLaw(std::size_t NumberOfDimensions) + : mNumberOfDimensions{NumberOfDimensions} { - mNumberOfDimensions = NumberOfDimensions; KRATOS_ERROR_IF(mNumberOfDimensions < 1 || mNumberOfDimensions > 3) << "Got invalid number of dimensions: " << mNumberOfDimensions << std::endl; } -GeoThermalLaw::Pointer GeoThermalDispersionLaw::Clone() const -{ - return Kratos::make_shared(*this); -} - Matrix GeoThermalDispersionLaw::CalculateThermalDispersionMatrix(const Properties& rProp, const ProcessInfo& rProcessInfo) const { diff --git a/applications/GeoMechanicsApplication/custom_constitutive/thermal_dispersion_law.h b/applications/GeoMechanicsApplication/custom_constitutive/thermal_dispersion_law.h index 3066bb898623..f3e860f30a95 100644 --- a/applications/GeoMechanicsApplication/custom_constitutive/thermal_dispersion_law.h +++ b/applications/GeoMechanicsApplication/custom_constitutive/thermal_dispersion_law.h @@ -38,11 +38,11 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) GeoThermalDispersionLaw : public Geo ~GeoThermalDispersionLaw() override = default; - GeoThermalLaw::Pointer Clone() const override; - Matrix CalculateThermalDispersionMatrix(const Properties& rProp, const ProcessInfo& rProcessInfo) const override; private: + std::size_t mNumberOfDimensions = 0; + friend class Serializer; void save(Serializer& rSerializer) const override diff --git a/applications/GeoMechanicsApplication/custom_constitutive/thermal_filter_law.cpp b/applications/GeoMechanicsApplication/custom_constitutive/thermal_filter_law.cpp index 81e6b51fafcf..215c4fa14f0a 100644 --- a/applications/GeoMechanicsApplication/custom_constitutive/thermal_filter_law.cpp +++ b/applications/GeoMechanicsApplication/custom_constitutive/thermal_filter_law.cpp @@ -17,21 +17,16 @@ namespace Kratos { -GeoThermalFilterLaw::GeoThermalFilterLaw() { mNumberOfDimensions = 1; } +GeoThermalFilterLaw::GeoThermalFilterLaw() : mNumberOfDimensions{1} {} GeoThermalFilterLaw::GeoThermalFilterLaw(SizeType NumberOfDimensions) + : mNumberOfDimensions{NumberOfDimensions} { - mNumberOfDimensions = NumberOfDimensions; KRATOS_ERROR_IF(mNumberOfDimensions != 1) << "Got invalid number of dimensions. The dimension has to be 1, but got: " << mNumberOfDimensions << std::endl; } -GeoThermalLaw::Pointer GeoThermalFilterLaw::Clone() const -{ - return Kratos::make_shared(*this); -} - Matrix GeoThermalFilterLaw::CalculateThermalDispersionMatrix(const Properties& rProp, const ProcessInfo&) const { return ScalarMatrix(1, 1, rProp[THERMAL_CONDUCTIVITY_WATER]); diff --git a/applications/GeoMechanicsApplication/custom_constitutive/thermal_filter_law.h b/applications/GeoMechanicsApplication/custom_constitutive/thermal_filter_law.h index b406d261781e..9843ce92358c 100644 --- a/applications/GeoMechanicsApplication/custom_constitutive/thermal_filter_law.h +++ b/applications/GeoMechanicsApplication/custom_constitutive/thermal_filter_law.h @@ -35,11 +35,11 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) GeoThermalFilterLaw : public GeoTher ~GeoThermalFilterLaw() override = default; - GeoThermalLaw::Pointer Clone() const override; - Matrix CalculateThermalDispersionMatrix(const Properties& rProp, const ProcessInfo&) const override; private: + std::size_t mNumberOfDimensions = 0; + friend class Serializer; void save(Serializer& rSerializer) const override diff --git a/applications/GeoMechanicsApplication/custom_constitutive/thermal_law.h b/applications/GeoMechanicsApplication/custom_constitutive/thermal_law.h index 9da3c205fae6..a927b34a3497 100644 --- a/applications/GeoMechanicsApplication/custom_constitutive/thermal_law.h +++ b/applications/GeoMechanicsApplication/custom_constitutive/thermal_law.h @@ -35,27 +35,14 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) GeoThermalLaw virtual ~GeoThermalLaw() = default; - virtual GeoThermalLaw::Pointer Clone() const = 0; - - std::size_t WorkingSpaceDimension() const { return mNumberOfDimensions; } - virtual Matrix CalculateThermalDispersionMatrix(const Properties& rProp, const ProcessInfo& rProcessInfo) const = 0; -protected: - std::size_t mNumberOfDimensions = 0; - private: friend class Serializer; - virtual void save(Serializer& rSerializer) const - { - rSerializer.save("NumberOfDimensions", mNumberOfDimensions); - } + virtual void save(Serializer& rSerializer) const {} - virtual void load(Serializer& rSerializer) - { - rSerializer.load("NumberOfDimensions", mNumberOfDimensions); - } + virtual void load(Serializer& rSerializer) {} }; } // namespace Kratos. diff --git a/applications/GeoMechanicsApplication/custom_elements/transient_thermal_element.h b/applications/GeoMechanicsApplication/custom_elements/transient_thermal_element.h index 653d18891b18..04b24e8a9249 100644 --- a/applications/GeoMechanicsApplication/custom_elements/transient_thermal_element.h +++ b/applications/GeoMechanicsApplication/custom_elements/transient_thermal_element.h @@ -270,22 +270,22 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) TransientThermalElement : public Ele const ProcessInfo& rCurrentProcessInfo) const { const std::size_t number_of_dimensions = GetGeometry().LocalSpaceDimension(); - unique_ptr law; + std::unique_ptr law; if (GetProperties().Has(THERMAL_LAW)) { const std::string& rThermalLawName = GetProperties()[THERMAL_LAW]; if (rThermalLawName == "GeoThermalDispersionLaw") { - law = make_unique(number_of_dimensions); + law = std::make_unique(number_of_dimensions); } else if (rThermalLawName == "GeoThermalFilterLaw") { - law = make_unique(number_of_dimensions); + law = std::make_unique(number_of_dimensions); } else { KRATOS_ERROR << "Undefined THERMAL_LAW! " << rThermalLawName << std::endl; } } else { - law = make_unique(number_of_dimensions); + law = std::make_unique(number_of_dimensions); } const auto constitutive_matrix = law->CalculateThermalDispersionMatrix(GetProperties(), rCurrentProcessInfo); diff --git a/applications/GeoMechanicsApplication/tests/cpp_tests/test_thermal_dispersion_law.cpp b/applications/GeoMechanicsApplication/tests/cpp_tests/test_thermal_dispersion_law.cpp index 357700305952..ff60973ff982 100644 --- a/applications/GeoMechanicsApplication/tests/cpp_tests/test_thermal_dispersion_law.cpp +++ b/applications/GeoMechanicsApplication/tests/cpp_tests/test_thermal_dispersion_law.cpp @@ -101,12 +101,9 @@ KRATOS_TEST_CASE_IN_SUITE(CalculateThermalDispersionMatrix3D, KratosGeoMechanics } } -KRATOS_TEST_CASE_IN_SUITE(GetWorkingSpaceDimension_ReturnsCorrectValue, KratosGeoMechanicsFastSuite) +KRATOS_TEST_CASE_IN_SUITE(TestDispersionLawThrowsWhenDimensionInvalid, KratosGeoMechanicsFastSuite) { - constexpr SizeType dimension = 3; - GeoThermalDispersionLaw geo_thermal_dispersion_3D_law(dimension); - - KRATOS_EXPECT_EQ(geo_thermal_dispersion_3D_law.WorkingSpaceDimension(), dimension); + KRATOS_EXPECT_EXCEPTION_IS_THROWN(GeoThermalFilterLaw law{0}, "Got invalid number of dimensions: 0") } } // namespace Kratos::Testing diff --git a/applications/GeoMechanicsApplication/tests/cpp_tests/test_thermal_filter_law.cpp b/applications/GeoMechanicsApplication/tests/cpp_tests/test_thermal_filter_law.cpp index 38f002235e6f..9cd0bb029753 100644 --- a/applications/GeoMechanicsApplication/tests/cpp_tests/test_thermal_filter_law.cpp +++ b/applications/GeoMechanicsApplication/tests/cpp_tests/test_thermal_filter_law.cpp @@ -39,18 +39,9 @@ KRATOS_TEST_CASE_IN_SUITE(CalculateThermalFilterLawMatrix, KratosGeoMechanicsFas KRATOS_EXPECT_NEAR(thermal_filter_matrix(0, 0), expected_solution(0, 0), tolerance); } -KRATOS_TEST_CASE_IN_SUITE(GetWorkingSpaceDimension_ReturnsFilterDimensionValue, KratosGeoMechanicsFastSuite) +KRATOS_TEST_CASE_IN_SUITE(TestFilterLawThrowsWhenDimensionInvalid, KratosGeoMechanicsFastSuite) { - constexpr SizeType dimension = 1; - GeoThermalFilterLaw geo_thermal_filter_law(dimension); - - KRATOS_EXPECT_EQ(geo_thermal_filter_law.WorkingSpaceDimension(), dimension); -} - -KRATOS_TEST_CASE_IN_SUITE(TestFilterThrowsWhenDimensionInvalid, KratosGeoMechanicsFastSuite) -{ - KRATOS_EXPECT_EXCEPTION_IS_THROWN( - GeoThermalFilterLaw law{2}, + KRATOS_EXPECT_EXCEPTION_IS_THROWN(GeoThermalFilterLaw law{2}, "Got invalid number of dimensions. The dimension has to be 1, but got: 2") }