From d284259b067703cdb44109fa098cbb78da52fdc7 Mon Sep 17 00:00:00 2001 From: Marjan Fathian <65416980+indigocoral@users.noreply.github.com> Date: Mon, 2 Oct 2023 12:06:20 +0200 Subject: [PATCH 1/2] Moved logic of `ApplyScalarConstraintsTableProcess` to C++ This class used to be defined in a Python module only. Now that we also need it for the custom settlement workflow, we had to port it from Python to C++. Note that the Python interface now uses the new C++ class. Also added a creator for the `ApplyScalarConstraintsTableProcess` to the process factory used by the custom workflow. The factory should now be able to create all kinds of processes that are relevant for settlement analysis. --- ...apply_scalar_constraints_table_process.cpp | 227 ++++++++++++++++++ .../apply_scalar_constraints_table_process.h | 63 +++++ .../add_custom_processes_to_python.cpp | 5 + .../custom_workflows/dgeosettlement.cpp | 11 +- .../apply_scalar_constraint_table_process.py | 111 +-------- 5 files changed, 308 insertions(+), 109 deletions(-) create mode 100644 applications/GeoMechanicsApplication/custom_processes/apply_scalar_constraints_table_process.cpp create mode 100644 applications/GeoMechanicsApplication/custom_processes/apply_scalar_constraints_table_process.h diff --git a/applications/GeoMechanicsApplication/custom_processes/apply_scalar_constraints_table_process.cpp b/applications/GeoMechanicsApplication/custom_processes/apply_scalar_constraints_table_process.cpp new file mode 100644 index 000000000000..14ee0ca4e5a6 --- /dev/null +++ b/applications/GeoMechanicsApplication/custom_processes/apply_scalar_constraints_table_process.cpp @@ -0,0 +1,227 @@ +// KRATOS___ +// // ) ) +// // ___ ___ +// // ____ //___) ) // ) ) +// // / / // // / / +// ((____/ / ((____ ((___/ / MECHANICS +// +// License: geo_mechanics_application/license.txt +// +// Main authors: Anne van de Graaf, +// Marjan Fathian +// +#include "apply_scalar_constraints_table_process.h" +#include "includes/model_part.h" +#include "includes/kratos_parameters.h" +#include "apply_component_table_process.hpp" +#include "processes/apply_constant_scalarvalue_process.h" +#include "apply_hydrostatic_pressure_table_process.hpp" +#include "apply_constant_phreatic_line_pressure_process.hpp" +#include "apply_phreatic_line_pressure_table_process.hpp" +#include "apply_constant_interpolate_line_pressure_process.hpp" +#include "apply_constant_phreatic_surface_pressure_process.hpp" +#include "apply_phreatic_surface_pressure_table_process.hpp" + +namespace +{ + +using namespace Kratos; + +Parameters ExtractParameters(const Parameters& rSourceParameters, + const std::vector& rNamesOfParametersToCopy) +{ + auto result = Parameters{}; + result.CopyValuesFromExistingParameters(rSourceParameters, rNamesOfParametersToCopy); + return result; +} + +void AppendParameterNameIfExists(const std::string& rParameterName, + const Parameters& rSourceParameters, + std::vector& rResult) +{ + if (rSourceParameters.Has(rParameterName)) { + rResult.emplace_back(rParameterName); + } +} + +} + +namespace Kratos +{ + +ApplyScalarConstraintsTableProcess::ApplyScalarConstraintsTableProcess(ModelPart& rModelPart, + const Parameters& rProcessSettings) + : Process(Flags()), + mrModelPart{rModelPart} +{ + MakeInternalProcess(rProcessSettings); +} + +ApplyScalarConstraintsTableProcess::~ApplyScalarConstraintsTableProcess() = default; + +void ApplyScalarConstraintsTableProcess::MakeInternalProcess(const Parameters& rProcessSettings) +{ + auto names_of_settings_to_copy = std::vector{"model_part_name", + "variable_name"}; + AppendParameterNameIfExists("is_fixed", rProcessSettings, names_of_settings_to_copy); + + if (rProcessSettings.Has("fluid_pressure_type")) { + MakeProcessForFluidPressureType(rProcessSettings, std::move(names_of_settings_to_copy)); + } + else { + MakeProcessForNonFluidPressureType(rProcessSettings, std::move(names_of_settings_to_copy)); + } +} + +void ApplyScalarConstraintsTableProcess::MakeProcessForFluidPressureType(const Parameters& rProcessSettings, + std::vector NamesOfSettingsToCopy) +{ + const auto fluid_pressure_type = rProcessSettings["fluid_pressure_type"].GetString(); + if (fluid_pressure_type == "Uniform") { + MakeProcessForUniformFluidPressure(rProcessSettings, std::move(NamesOfSettingsToCopy)); + } else if (fluid_pressure_type == "Hydrostatic") { + MakeProcessForHydrostaticFluidPressure(rProcessSettings, std::move(NamesOfSettingsToCopy)); + } else if (fluid_pressure_type == "Phreatic_Line") { + MakeProcessForPhreaticLine(rProcessSettings, std::move(NamesOfSettingsToCopy)); + } else if (fluid_pressure_type == "Interpolate_Line") { + MakeProcessForInterpolatedLine(rProcessSettings, std::move(NamesOfSettingsToCopy)); + } else if (fluid_pressure_type == "Phreatic_Surface") { + MakeProcessForPhreaticSurface(rProcessSettings, std::move(NamesOfSettingsToCopy)); + } else { + KRATOS_ERROR << "Unknown fluid_pressure_type: " << fluid_pressure_type << std::endl; + } +} + +void ApplyScalarConstraintsTableProcess::MakeProcessForNonFluidPressureType(const Parameters& rProcessSettings, + std::vector NamesOfSettingsToCopy) +{ + NamesOfSettingsToCopy.emplace_back("value"); + + if (rProcessSettings["table"].GetInt() == 0) { + mProcess = std::make_unique(mrModelPart, + ExtractParameters(rProcessSettings, + NamesOfSettingsToCopy)); + } else { + NamesOfSettingsToCopy.emplace_back("table"); + mProcess = std::make_unique(mrModelPart, + ExtractParameters(rProcessSettings, + NamesOfSettingsToCopy)); + } +} + +void ApplyScalarConstraintsTableProcess::MakeProcessForUniformFluidPressure(const Parameters& rProcessSettings, + std::vector NamesOfSettingsToCopy) +{ + NamesOfSettingsToCopy.emplace_back("value"); + + if (rProcessSettings["table"].GetInt() == 0) { + mProcess = std::make_unique(mrModelPart, + ExtractParameters(rProcessSettings, + NamesOfSettingsToCopy)); + } else { + NamesOfSettingsToCopy.emplace_back("table"); + mProcess = std::make_unique(mrModelPart, + ExtractParameters(rProcessSettings, + NamesOfSettingsToCopy)); + } +} + +void ApplyScalarConstraintsTableProcess::MakeProcessForHydrostaticFluidPressure(const Parameters& rProcessSettings, + std::vector NamesOfSettingsToCopy) +{ + NamesOfSettingsToCopy.insert(NamesOfSettingsToCopy.end(), {"gravity_direction", + "reference_coordinate", + "specific_weight"}); + AppendParameterNameIfExists("pressure_tension_cut_off", rProcessSettings, NamesOfSettingsToCopy); + AppendParameterNameIfExists("is_seepage", rProcessSettings, NamesOfSettingsToCopy); + + if (rProcessSettings["table"].GetInt() == 0) { + mProcess = std::make_unique(mrModelPart, + ExtractParameters(rProcessSettings, + NamesOfSettingsToCopy)); + } else { + NamesOfSettingsToCopy.emplace_back("table"); + mProcess = std::make_unique(mrModelPart, + ExtractParameters(rProcessSettings, + NamesOfSettingsToCopy)); + } +} + +void ApplyScalarConstraintsTableProcess::MakeProcessForPhreaticLine(const Parameters& rProcessSettings, + std::vector NamesOfSettingsToCopy) +{ + NamesOfSettingsToCopy.insert(NamesOfSettingsToCopy.end(), {"gravity_direction", + "out_of_plane_direction", + "first_reference_coordinate", + "second_reference_coordinate", + "specific_weight"}); + AppendParameterNameIfExists("pressure_tension_cut_off", rProcessSettings, NamesOfSettingsToCopy); + AppendParameterNameIfExists("is_seepage", rProcessSettings, NamesOfSettingsToCopy); + + if ((rProcessSettings["table"][0].GetInt() == 0) && + (rProcessSettings["table"][1].GetInt() == 0)) { + mProcess = std::make_unique(mrModelPart, + ExtractParameters(rProcessSettings, + NamesOfSettingsToCopy)); + } else { + NamesOfSettingsToCopy.emplace_back("table"); + mProcess = std::make_unique(mrModelPart, + ExtractParameters(rProcessSettings, + NamesOfSettingsToCopy)); + } +} + +void ApplyScalarConstraintsTableProcess::MakeProcessForInterpolatedLine(const Parameters& rProcessSettings, + std::vector NamesOfSettingsToCopy) +{ + NamesOfSettingsToCopy.insert(NamesOfSettingsToCopy.end(), {"gravity_direction", + "out_of_plane_direction"}); + AppendParameterNameIfExists("pressure_tension_cut_off", rProcessSettings, NamesOfSettingsToCopy); + AppendParameterNameIfExists("is_seepage", rProcessSettings, NamesOfSettingsToCopy); + + if (rProcessSettings["table"].GetInt() == 0) { + mProcess = std::make_unique(mrModelPart, + ExtractParameters(rProcessSettings, + NamesOfSettingsToCopy)); + } else { + KRATOS_ERROR << "No time dependent interpolate line pressure process available" << std::endl; + } +} + +void ApplyScalarConstraintsTableProcess::MakeProcessForPhreaticSurface(const Parameters& rProcessSettings, + std::vector NamesOfSettingsToCopy) +{ + NamesOfSettingsToCopy.insert(NamesOfSettingsToCopy.end(), {"gravity_direction", + "first_reference_coordinate", + "second_reference_coordinate", + "third_reference_coordinate", + "specific_weight"}); + AppendParameterNameIfExists("pressure_tension_cut_off", rProcessSettings, NamesOfSettingsToCopy); + AppendParameterNameIfExists("is_seepage", rProcessSettings, NamesOfSettingsToCopy); + + if ((rProcessSettings["table"][0].GetInt() == 0) && + (rProcessSettings["table"][1].GetInt() == 0) && + (rProcessSettings["table"][2].GetInt() == 0)) { + mProcess = std::make_unique(mrModelPart, + ExtractParameters(rProcessSettings, + NamesOfSettingsToCopy)); + } + else { + NamesOfSettingsToCopy.emplace_back("table"); + mProcess = std::make_unique(mrModelPart, + ExtractParameters(rProcessSettings, + NamesOfSettingsToCopy)); + } +} + +void ApplyScalarConstraintsTableProcess::ExecuteInitialize() +{ + mProcess->ExecuteInitialize(); +} + +void ApplyScalarConstraintsTableProcess::ExecuteInitializeSolutionStep() +{ + mProcess->ExecuteInitializeSolutionStep(); +} + +} diff --git a/applications/GeoMechanicsApplication/custom_processes/apply_scalar_constraints_table_process.h b/applications/GeoMechanicsApplication/custom_processes/apply_scalar_constraints_table_process.h new file mode 100644 index 000000000000..325091213c59 --- /dev/null +++ b/applications/GeoMechanicsApplication/custom_processes/apply_scalar_constraints_table_process.h @@ -0,0 +1,63 @@ +// KRATOS___ +// // ) ) +// // ___ ___ +// // ____ //___) ) // ) ) +// // / / // // / / +// ((____/ / ((____ ((___/ / MECHANICS +// +// License: geo_mechanics_application/license.txt +// +// Main authors: Anne van de Graaf, +// Marjan Fathian +// +#pragma once + +#include "processes/process.h" + +namespace Kratos +{ + +class ModelPart; +class Parameters; + + +class KRATOS_API(GEO_MECHANICS_APPLICATION) ApplyScalarConstraintsTableProcess : public Process +{ +public: + KRATOS_CLASS_POINTER_DEFINITION(ApplyScalarConstraintsTableProcess); + + ApplyScalarConstraintsTableProcess(ModelPart& rModelPart, + const Parameters& rProcessSettings); + + ~ApplyScalarConstraintsTableProcess() override; + + ApplyScalarConstraintsTableProcess(const ApplyScalarConstraintsTableProcess&) = delete; + ApplyScalarConstraintsTableProcess& operator=(const ApplyScalarConstraintsTableProcess&) = delete; + + using ProcessUniquePointer = std::unique_ptr; + + void ExecuteInitialize() override; + void ExecuteInitializeSolutionStep() override; + +private: + void MakeInternalProcess(const Parameters& rProcessSettings); + void MakeProcessForFluidPressureType(const Parameters& rProcessSettings, + std::vector NamesOfSettingsToCopy); + void MakeProcessForNonFluidPressureType(const Parameters& rProcessSettings, + std::vector NamesOfSettingsToCopy); + void MakeProcessForUniformFluidPressure(const Parameters& rProcessSettings, + std::vector NamesOfSettingsToCopy); + void MakeProcessForHydrostaticFluidPressure(const Parameters& rProcessSettings, + std::vector NamesOfSettingsToCopy); + void MakeProcessForPhreaticLine(const Parameters& rProcessSettings, + std::vector NamesOfSettingsToCopy); + void MakeProcessForInterpolatedLine(const Parameters& rProcessSettings, + std::vector NamesOfSettingsToCopy); + void MakeProcessForPhreaticSurface(const Parameters& rProcessSettings, + std::vector NamesOfSettingsToCopy); + + ModelPart& mrModelPart; + ProcessUniquePointer mProcess; +}; + +} diff --git a/applications/GeoMechanicsApplication/custom_python/add_custom_processes_to_python.cpp b/applications/GeoMechanicsApplication/custom_python/add_custom_processes_to_python.cpp index eb2127665ca1..0ba9ddac2267 100644 --- a/applications/GeoMechanicsApplication/custom_python/add_custom_processes_to_python.cpp +++ b/applications/GeoMechanicsApplication/custom_python/add_custom_processes_to_python.cpp @@ -42,6 +42,7 @@ #include "custom_processes/set_parameter_field_process.hpp" #include "custom_processes/set_multiple_moving_loads.h" #include "custom_processes/apply_vector_constraints_table_process.hpp" +#include "custom_processes/apply_scalar_constraints_table_process.h" namespace Kratos { namespace Python { @@ -141,6 +142,10 @@ void AddCustomProcessesToPython(pybind11::module& m) py::class_ (m, "ApplyVectorConstraintsTableProcess") .def(py::init()); + + py::class_ + (m, "ApplyScalarConstraintsTableProcess") + .def(py::init()); } } // Namespace Python. diff --git a/applications/GeoMechanicsApplication/custom_workflows/dgeosettlement.cpp b/applications/GeoMechanicsApplication/custom_workflows/dgeosettlement.cpp index 354be55027f1..9ee5c10b9d79 100644 --- a/applications/GeoMechanicsApplication/custom_workflows/dgeosettlement.cpp +++ b/applications/GeoMechanicsApplication/custom_workflows/dgeosettlement.cpp @@ -15,6 +15,7 @@ #include "utilities/variable_utils.h" +#include "custom_processes/apply_scalar_constraints_table_process.h" #include "custom_processes/apply_vector_constraints_table_process.hpp" #include "custom_processes/set_parameter_field_process.hpp" #include "custom_processes/apply_k0_procedure_process.hpp" @@ -47,7 +48,15 @@ KratosGeoSettlement::KratosGeoSettlement(std::unique_ptr pInputUti InitializeProcessFactory(); } -void KratosGeoSettlement::InitializeProcessFactory() { +void KratosGeoSettlement::InitializeProcessFactory() +{ + mProcessFactory->AddCreator("ApplyScalarConstraintsTableProcess", + [this](const Parameters& rParameters) + { + return std::make_unique(mModel.GetModelPart(mModelPartName), + rParameters); + }); + mProcessFactory->AddCreator("ApplyVectorConstraintsTableProcess", [this](const Parameters& rParameters) { diff --git a/applications/GeoMechanicsApplication/python_scripts/apply_scalar_constraint_table_process.py b/applications/GeoMechanicsApplication/python_scripts/apply_scalar_constraint_table_process.py index 09730c03fa89..7624a213a365 100644 --- a/applications/GeoMechanicsApplication/python_scripts/apply_scalar_constraint_table_process.py +++ b/applications/GeoMechanicsApplication/python_scripts/apply_scalar_constraint_table_process.py @@ -4,112 +4,7 @@ def Factory(settings, Model): if not isinstance(settings, KratosMultiphysics.Parameters): raise TypeError("expected input shall be a Parameters object, encapsulating a json string") - return ApplyScalarConstraintTableProcess(Model, settings["Parameters"]) -## All the python processes should be derived from "python_process" - -class ApplyScalarConstraintTableProcess(KratosMultiphysics.Process): - def __init__(self, Model, settings ): - KratosMultiphysics.Process.__init__(self) - - self.model_part = Model[settings["model_part_name"].GetString()] - - self.params = KratosMultiphysics.Parameters("{}") - self.params.AddValue("model_part_name",settings["model_part_name"]) - self.params.AddValue("variable_name",settings["variable_name"]) - if settings.Has("is_fixed"): - self.params.AddValue("is_fixed",settings["is_fixed"]) - - if settings.Has("fluid_pressure_type"): - # if settings["hydrostatic"].GetBool() == False: - if settings["fluid_pressure_type"].GetString() == "Uniform": - self.params.AddValue("value",settings["value"]) - if settings["table"].GetInt() == 0: - self.process = KratosMultiphysics.ApplyConstantScalarValueProcess(self.model_part, self.params) - else: - self.params.AddValue("table",settings["table"]) - self.process = KratosGeo.ApplyComponentTableProcess(self.model_part, self.params) - elif settings["fluid_pressure_type"].GetString() == "Hydrostatic": - self.params.AddValue("gravity_direction",settings["gravity_direction"]) - self.params.AddValue("reference_coordinate",settings["reference_coordinate"]) - self.params.AddValue("specific_weight",settings["specific_weight"]) - - if settings.Has("pressure_tension_cut_off"): - self.params.AddValue("pressure_tension_cut_off",settings["pressure_tension_cut_off"]) - - if settings.Has("is_seepage"): - self.params.AddValue("is_seepage",settings["is_seepage"]) - - if settings["table"].GetInt() == 0: - self.process = KratosGeo.ApplyConstantHydrostaticPressureProcess(self.model_part, self.params) - else: - self.params.AddValue("table",settings["table"]) - self.process = KratosGeo.ApplyHydrostaticPressureTableProcess(self.model_part, self.params) - elif settings["fluid_pressure_type"].GetString() == "Phreatic_Line": - self.params.AddValue("gravity_direction",settings["gravity_direction"]) - self.params.AddValue("out_of_plane_direction",settings["out_of_plane_direction"]) - self.params.AddValue("first_reference_coordinate",settings["first_reference_coordinate"]) - self.params.AddValue("second_reference_coordinate",settings["second_reference_coordinate"]) - self.params.AddValue("specific_weight",settings["specific_weight"]) - - if settings.Has("pressure_tension_cut_off"): - self.params.AddValue("pressure_tension_cut_off",settings["pressure_tension_cut_off"]) - - if settings.Has("is_seepage"): - self.params.AddValue("is_seepage",settings["is_seepage"]) - - if settings["table"][0].GetInt() == 0 and settings["table"][1].GetInt() == 0: - self.process = KratosGeo.ApplyConstantPhreaticLinePressureProcess(self.model_part, self.params) - else: - self.params.AddValue("table",settings["table"]) - self.process = KratosGeo.ApplyPhreaticLinePressureTableProcess(self.model_part, self.params) - elif settings["fluid_pressure_type"].GetString() == "Interpolate_Line": - self.params.AddValue("gravity_direction",settings["gravity_direction"]) - self.params.AddValue("out_of_plane_direction",settings["out_of_plane_direction"]) - - if settings.Has("pressure_tension_cut_off"): - self.params.AddValue("pressure_tension_cut_off",settings["pressure_tension_cut_off"]) - - if settings.Has("is_seepage"): - self.params.AddValue("is_seepage",settings["is_seepage"]) - - if settings["table"].GetInt() == 0: - self.process = KratosGeo.ApplyConstantInterpolateLinePressureProcess(self.model_part, self.params) - else: - raise RuntimeError("No time dependent interpolate line pressure process available") - elif settings["fluid_pressure_type"].GetString() == "Phreatic_Surface": - self.params.AddValue("gravity_direction",settings["gravity_direction"]) - self.params.AddValue("first_reference_coordinate",settings["first_reference_coordinate"]) - self.params.AddValue("second_reference_coordinate",settings["second_reference_coordinate"]) - self.params.AddValue("third_reference_coordinate",settings["third_reference_coordinate"]) - self.params.AddValue("specific_weight",settings["specific_weight"]) - - if settings.Has("pressure_tension_cut_off"): - self.params.AddValue("pressure_tension_cut_off",settings["pressure_tension_cut_off"]) - - if settings.Has("is_seepage"): - self.params.AddValue("is_seepage",settings["is_seepage"]) - - if settings["table"][0].GetInt() == 0 and settings["table"][1].GetInt() == 0 and settings["table"][2].GetInt() == 0: - self.process = KratosGeo.ApplyConstantPhreaticSurfacePressureProcess(self.model_part, self.params) - else: - self.params.AddValue("table",settings["table"]) - self.process = KratosGeo.ApplyPhreaticSurfacePressureTableProcess(self.model_part, self.params) - else: - raise Exception("unkown fluid_pressure_type!") - - else: - self.params.AddValue("value",settings["value"]) - if settings["table"].GetInt() == 0: - self.process = KratosMultiphysics.ApplyConstantScalarValueProcess(self.model_part, self.params) - else: - self.params.AddValue("table",settings["table"]) - self.process = KratosGeo.ApplyComponentTableProcess(self.model_part, self.params) - - def ExecuteInitialize(self): - - self.process.ExecuteInitialize() - - def ExecuteInitializeSolutionStep(self): - - self.process.ExecuteInitializeSolutionStep() + params = settings["Parameters"] + model_part = Model[params["model_part_name"].GetString()] + return KratosGeo.ApplyScalarConstraintsTableProcess(model_part, params) From 82bad65346d7cffa4bff38c6e29dc87dc6aa8812 Mon Sep 17 00:00:00 2001 From: Anne van de Graaf Date: Mon, 9 Oct 2023 14:54:26 +0200 Subject: [PATCH 2/2] Started to process Wijtze Pieter's review comments - Moved a member function to a more logical place. - Removed a duplicated member function and renamed the remaining one. - Added a helper function to detect whether a table has been attached to a process. - Since the logic was inverted, some statements had to be rearranged. --- ...apply_scalar_constraints_table_process.cpp | 108 ++++++++---------- .../apply_scalar_constraints_table_process.h | 10 +- 2 files changed, 54 insertions(+), 64 deletions(-) diff --git a/applications/GeoMechanicsApplication/custom_processes/apply_scalar_constraints_table_process.cpp b/applications/GeoMechanicsApplication/custom_processes/apply_scalar_constraints_table_process.cpp index 14ee0ca4e5a6..3981c7897448 100644 --- a/applications/GeoMechanicsApplication/custom_processes/apply_scalar_constraints_table_process.cpp +++ b/applications/GeoMechanicsApplication/custom_processes/apply_scalar_constraints_table_process.cpp @@ -44,6 +44,19 @@ void AppendParameterNameIfExists(const std::string& rParameterName, } } +bool HasTableAttached(const Parameters& rSettings) +{ + if (rSettings["table"].IsNumber()) { + return rSettings["table"].GetInt() != 0; + } + + KRATOS_ERROR_IF_NOT(rSettings["table"].IsArray()) << "'table' is neither a single number nor an array of numbers"; + + const auto& table = rSettings["table"]; + return std::any_of(table.begin(), table.end(), + [](const auto& value){return value.GetInt() != 0;}); +} + } namespace Kratos @@ -69,7 +82,7 @@ void ApplyScalarConstraintsTableProcess::MakeInternalProcess(const Parameters& r MakeProcessForFluidPressureType(rProcessSettings, std::move(names_of_settings_to_copy)); } else { - MakeProcessForNonFluidPressureType(rProcessSettings, std::move(names_of_settings_to_copy)); + MakeScalarConstraintsProcess(rProcessSettings, std::move(names_of_settings_to_copy)); } } @@ -78,7 +91,7 @@ void ApplyScalarConstraintsTableProcess::MakeProcessForFluidPressureType(const P { const auto fluid_pressure_type = rProcessSettings["fluid_pressure_type"].GetString(); if (fluid_pressure_type == "Uniform") { - MakeProcessForUniformFluidPressure(rProcessSettings, std::move(NamesOfSettingsToCopy)); + MakeScalarConstraintsProcess(rProcessSettings, std::move(NamesOfSettingsToCopy)); } else if (fluid_pressure_type == "Hydrostatic") { MakeProcessForHydrostaticFluidPressure(rProcessSettings, std::move(NamesOfSettingsToCopy)); } else if (fluid_pressure_type == "Phreatic_Line") { @@ -92,37 +105,20 @@ void ApplyScalarConstraintsTableProcess::MakeProcessForFluidPressureType(const P } } -void ApplyScalarConstraintsTableProcess::MakeProcessForNonFluidPressureType(const Parameters& rProcessSettings, - std::vector NamesOfSettingsToCopy) +void ApplyScalarConstraintsTableProcess::MakeScalarConstraintsProcess(const Parameters& rProcessSettings, + std::vector NamesOfSettingsToCopy) { NamesOfSettingsToCopy.emplace_back("value"); - if (rProcessSettings["table"].GetInt() == 0) { - mProcess = std::make_unique(mrModelPart, - ExtractParameters(rProcessSettings, - NamesOfSettingsToCopy)); - } else { + if (HasTableAttached(rProcessSettings)) { NamesOfSettingsToCopy.emplace_back("table"); mProcess = std::make_unique(mrModelPart, ExtractParameters(rProcessSettings, NamesOfSettingsToCopy)); - } -} - -void ApplyScalarConstraintsTableProcess::MakeProcessForUniformFluidPressure(const Parameters& rProcessSettings, - std::vector NamesOfSettingsToCopy) -{ - NamesOfSettingsToCopy.emplace_back("value"); - - if (rProcessSettings["table"].GetInt() == 0) { + } else { mProcess = std::make_unique(mrModelPart, ExtractParameters(rProcessSettings, NamesOfSettingsToCopy)); - } else { - NamesOfSettingsToCopy.emplace_back("table"); - mProcess = std::make_unique(mrModelPart, - ExtractParameters(rProcessSettings, - NamesOfSettingsToCopy)); } } @@ -135,15 +131,15 @@ void ApplyScalarConstraintsTableProcess::MakeProcessForHydrostaticFluidPressure( AppendParameterNameIfExists("pressure_tension_cut_off", rProcessSettings, NamesOfSettingsToCopy); AppendParameterNameIfExists("is_seepage", rProcessSettings, NamesOfSettingsToCopy); - if (rProcessSettings["table"].GetInt() == 0) { - mProcess = std::make_unique(mrModelPart, - ExtractParameters(rProcessSettings, - NamesOfSettingsToCopy)); - } else { + if (HasTableAttached(rProcessSettings)) { NamesOfSettingsToCopy.emplace_back("table"); mProcess = std::make_unique(mrModelPart, ExtractParameters(rProcessSettings, NamesOfSettingsToCopy)); + } else { + mProcess = std::make_unique(mrModelPart, + ExtractParameters(rProcessSettings, + NamesOfSettingsToCopy)); } } @@ -158,33 +154,15 @@ void ApplyScalarConstraintsTableProcess::MakeProcessForPhreaticLine(const Parame AppendParameterNameIfExists("pressure_tension_cut_off", rProcessSettings, NamesOfSettingsToCopy); AppendParameterNameIfExists("is_seepage", rProcessSettings, NamesOfSettingsToCopy); - if ((rProcessSettings["table"][0].GetInt() == 0) && - (rProcessSettings["table"][1].GetInt() == 0)) { - mProcess = std::make_unique(mrModelPart, - ExtractParameters(rProcessSettings, - NamesOfSettingsToCopy)); - } else { + if (HasTableAttached(rProcessSettings)) { NamesOfSettingsToCopy.emplace_back("table"); mProcess = std::make_unique(mrModelPart, ExtractParameters(rProcessSettings, NamesOfSettingsToCopy)); - } -} - -void ApplyScalarConstraintsTableProcess::MakeProcessForInterpolatedLine(const Parameters& rProcessSettings, - std::vector NamesOfSettingsToCopy) -{ - NamesOfSettingsToCopy.insert(NamesOfSettingsToCopy.end(), {"gravity_direction", - "out_of_plane_direction"}); - AppendParameterNameIfExists("pressure_tension_cut_off", rProcessSettings, NamesOfSettingsToCopy); - AppendParameterNameIfExists("is_seepage", rProcessSettings, NamesOfSettingsToCopy); - - if (rProcessSettings["table"].GetInt() == 0) { - mProcess = std::make_unique(mrModelPart, - ExtractParameters(rProcessSettings, - NamesOfSettingsToCopy)); } else { - KRATOS_ERROR << "No time dependent interpolate line pressure process available" << std::endl; + mProcess = std::make_unique(mrModelPart, + ExtractParameters(rProcessSettings, + NamesOfSettingsToCopy)); } } @@ -199,19 +177,33 @@ void ApplyScalarConstraintsTableProcess::MakeProcessForPhreaticSurface(const Par AppendParameterNameIfExists("pressure_tension_cut_off", rProcessSettings, NamesOfSettingsToCopy); AppendParameterNameIfExists("is_seepage", rProcessSettings, NamesOfSettingsToCopy); - if ((rProcessSettings["table"][0].GetInt() == 0) && - (rProcessSettings["table"][1].GetInt() == 0) && - (rProcessSettings["table"][2].GetInt() == 0)) { - mProcess = std::make_unique(mrModelPart, - ExtractParameters(rProcessSettings, - NamesOfSettingsToCopy)); - } - else { + if (HasTableAttached(rProcessSettings)) { NamesOfSettingsToCopy.emplace_back("table"); mProcess = std::make_unique(mrModelPart, ExtractParameters(rProcessSettings, NamesOfSettingsToCopy)); } + else { + mProcess = std::make_unique(mrModelPart, + ExtractParameters(rProcessSettings, + NamesOfSettingsToCopy)); + } +} + +void ApplyScalarConstraintsTableProcess::MakeProcessForInterpolatedLine(const Parameters& rProcessSettings, + std::vector NamesOfSettingsToCopy) +{ + KRATOS_ERROR_IF(HasTableAttached(rProcessSettings)) << "No time dependent interpolate line pressure process available" << std::endl; + + NamesOfSettingsToCopy.insert(NamesOfSettingsToCopy.end(), {"gravity_direction", + "out_of_plane_direction"}); + AppendParameterNameIfExists("pressure_tension_cut_off", rProcessSettings, NamesOfSettingsToCopy); + AppendParameterNameIfExists("is_seepage", rProcessSettings, NamesOfSettingsToCopy); + + mProcess = std::make_unique(mrModelPart, + ExtractParameters(rProcessSettings, + NamesOfSettingsToCopy)); + } void ApplyScalarConstraintsTableProcess::ExecuteInitialize() diff --git a/applications/GeoMechanicsApplication/custom_processes/apply_scalar_constraints_table_process.h b/applications/GeoMechanicsApplication/custom_processes/apply_scalar_constraints_table_process.h index 325091213c59..ae2cbbb2d77b 100644 --- a/applications/GeoMechanicsApplication/custom_processes/apply_scalar_constraints_table_process.h +++ b/applications/GeoMechanicsApplication/custom_processes/apply_scalar_constraints_table_process.h @@ -43,18 +43,16 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) ApplyScalarConstraintsTableProcess : void MakeInternalProcess(const Parameters& rProcessSettings); void MakeProcessForFluidPressureType(const Parameters& rProcessSettings, std::vector NamesOfSettingsToCopy); - void MakeProcessForNonFluidPressureType(const Parameters& rProcessSettings, - std::vector NamesOfSettingsToCopy); - void MakeProcessForUniformFluidPressure(const Parameters& rProcessSettings, - std::vector NamesOfSettingsToCopy); + void MakeScalarConstraintsProcess(const Parameters& rProcessSettings, + std::vector NamesOfSettingsToCopy); void MakeProcessForHydrostaticFluidPressure(const Parameters& rProcessSettings, std::vector NamesOfSettingsToCopy); void MakeProcessForPhreaticLine(const Parameters& rProcessSettings, std::vector NamesOfSettingsToCopy); - void MakeProcessForInterpolatedLine(const Parameters& rProcessSettings, - std::vector NamesOfSettingsToCopy); void MakeProcessForPhreaticSurface(const Parameters& rProcessSettings, std::vector NamesOfSettingsToCopy); + void MakeProcessForInterpolatedLine(const Parameters& rProcessSettings, + std::vector NamesOfSettingsToCopy); ModelPart& mrModelPart; ProcessUniquePointer mProcess;