Skip to content

Commit

Permalink
Started to process Wijtze Pieter's review comments
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
avdg81 committed Oct 9, 2023
1 parent d284259 commit 82bad65
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));
}
}

Expand All @@ -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") {
Expand All @@ -92,37 +105,20 @@ void ApplyScalarConstraintsTableProcess::MakeProcessForFluidPressureType(const P
}
}

void ApplyScalarConstraintsTableProcess::MakeProcessForNonFluidPressureType(const Parameters& rProcessSettings,
std::vector<std::string> NamesOfSettingsToCopy)
void ApplyScalarConstraintsTableProcess::MakeScalarConstraintsProcess(const Parameters& rProcessSettings,
std::vector<std::string> NamesOfSettingsToCopy)
{
NamesOfSettingsToCopy.emplace_back("value");

if (rProcessSettings["table"].GetInt() == 0) {
mProcess = std::make_unique<ApplyConstantScalarValueProcess>(mrModelPart,
ExtractParameters(rProcessSettings,
NamesOfSettingsToCopy));
} else {
if (HasTableAttached(rProcessSettings)) {
NamesOfSettingsToCopy.emplace_back("table");
mProcess = std::make_unique<ApplyComponentTableProcess>(mrModelPart,
ExtractParameters(rProcessSettings,
NamesOfSettingsToCopy));
}
}

void ApplyScalarConstraintsTableProcess::MakeProcessForUniformFluidPressure(const Parameters& rProcessSettings,
std::vector<std::string> NamesOfSettingsToCopy)
{
NamesOfSettingsToCopy.emplace_back("value");

if (rProcessSettings["table"].GetInt() == 0) {
} else {
mProcess = std::make_unique<ApplyConstantScalarValueProcess>(mrModelPart,
ExtractParameters(rProcessSettings,
NamesOfSettingsToCopy));
} else {
NamesOfSettingsToCopy.emplace_back("table");
mProcess = std::make_unique<ApplyComponentTableProcess>(mrModelPart,
ExtractParameters(rProcessSettings,
NamesOfSettingsToCopy));
}
}

Expand All @@ -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<ApplyConstantHydrostaticPressureProcess>(mrModelPart,
ExtractParameters(rProcessSettings,
NamesOfSettingsToCopy));
} else {
if (HasTableAttached(rProcessSettings)) {
NamesOfSettingsToCopy.emplace_back("table");
mProcess = std::make_unique<ApplyHydrostaticPressureTableProcess>(mrModelPart,
ExtractParameters(rProcessSettings,
NamesOfSettingsToCopy));
} else {
mProcess = std::make_unique<ApplyConstantHydrostaticPressureProcess>(mrModelPart,
ExtractParameters(rProcessSettings,
NamesOfSettingsToCopy));
}
}

Expand All @@ -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<ApplyConstantPhreaticLinePressureProcess>(mrModelPart,
ExtractParameters(rProcessSettings,
NamesOfSettingsToCopy));
} else {
if (HasTableAttached(rProcessSettings)) {
NamesOfSettingsToCopy.emplace_back("table");
mProcess = std::make_unique<ApplyPhreaticLinePressureTableProcess>(mrModelPart,
ExtractParameters(rProcessSettings,
NamesOfSettingsToCopy));
}
}

void ApplyScalarConstraintsTableProcess::MakeProcessForInterpolatedLine(const Parameters& rProcessSettings,
std::vector<std::string> 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<ApplyConstantInterpolateLinePressureProcess>(mrModelPart,
ExtractParameters(rProcessSettings,
NamesOfSettingsToCopy));
} else {
KRATOS_ERROR << "No time dependent interpolate line pressure process available" << std::endl;
mProcess = std::make_unique<ApplyConstantPhreaticLinePressureProcess>(mrModelPart,
ExtractParameters(rProcessSettings,
NamesOfSettingsToCopy));
}
}

Expand All @@ -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<ApplyConstantPhreaticSurfacePressureProcess>(mrModelPart,
ExtractParameters(rProcessSettings,
NamesOfSettingsToCopy));
}
else {
if (HasTableAttached(rProcessSettings)) {
NamesOfSettingsToCopy.emplace_back("table");
mProcess = std::make_unique<ApplyPhreaticSurfacePressureTableProcess>(mrModelPart,
ExtractParameters(rProcessSettings,
NamesOfSettingsToCopy));
}
else {
mProcess = std::make_unique<ApplyConstantPhreaticSurfacePressureProcess>(mrModelPart,
ExtractParameters(rProcessSettings,
NamesOfSettingsToCopy));
}
}

void ApplyScalarConstraintsTableProcess::MakeProcessForInterpolatedLine(const Parameters& rProcessSettings,
std::vector<std::string> 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<ApplyConstantInterpolateLinePressureProcess>(mrModelPart,
ExtractParameters(rProcessSettings,
NamesOfSettingsToCopy));

}

void ApplyScalarConstraintsTableProcess::ExecuteInitialize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,16 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) ApplyScalarConstraintsTableProcess :
void MakeInternalProcess(const Parameters& rProcessSettings);
void MakeProcessForFluidPressureType(const Parameters& rProcessSettings,
std::vector<std::string> NamesOfSettingsToCopy);
void MakeProcessForNonFluidPressureType(const Parameters& rProcessSettings,
std::vector<std::string> NamesOfSettingsToCopy);
void MakeProcessForUniformFluidPressure(const Parameters& rProcessSettings,
std::vector<std::string> NamesOfSettingsToCopy);
void MakeScalarConstraintsProcess(const Parameters& rProcessSettings,
std::vector<std::string> NamesOfSettingsToCopy);
void MakeProcessForHydrostaticFluidPressure(const Parameters& rProcessSettings,
std::vector<std::string> NamesOfSettingsToCopy);
void MakeProcessForPhreaticLine(const Parameters& rProcessSettings,
std::vector<std::string> NamesOfSettingsToCopy);
void MakeProcessForInterpolatedLine(const Parameters& rProcessSettings,
std::vector<std::string> NamesOfSettingsToCopy);
void MakeProcessForPhreaticSurface(const Parameters& rProcessSettings,
std::vector<std::string> NamesOfSettingsToCopy);
void MakeProcessForInterpolatedLine(const Parameters& rProcessSettings,
std::vector<std::string> NamesOfSettingsToCopy);

ModelPart& mrModelPart;
ProcessUniquePointer mProcess;
Expand Down

0 comments on commit 82bad65

Please sign in to comment.