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] 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;