Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GeoMechanicsApplication] Add process factory to settlement workflow #11591

Merged
merged 23 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f82d240
Merge branch 'master' into maas
rfaasse Sep 14, 2023
a752a92
Initial addition of processfactory to settlement workflow
rfaasse Sep 14, 2023
d4aae3b
Added version of a UT that checks if initialization throws
rfaasse Sep 14, 2023
e47ebf8
Progress on dgeosettlement unit test
rfaasse Sep 15, 2023
4107576
added first version of ProcessNameParser
rfaasse Sep 19, 2023
e45aaa0
Added functionality + UTs for retrieving process info
rfaasse Sep 20, 2023
1a388a9
Fix build
rfaasse Sep 20, 2023
9fc6f8a
Merge branch 'master' into geo/add-process-factory-to-settlement
rfaasse Sep 20, 2023
816ed51
Added ProjectInfoParser to GeoSettlement workflow + rename/interface …
rfaasse Sep 20, 2023
3a0d520
Revert rename
rfaasse Sep 20, 2023
b721234
Retrieved processes from json string and prepared vector of refs for …
rfaasse Sep 21, 2023
347214c
added stub functionality to stub process info parser
rfaasse Sep 21, 2023
206307e
Minor renaming and formatting changes
rfaasse Sep 21, 2023
fd46be1
Clean up + fixing SonarQube issues
rfaasse Sep 22, 2023
6f33fb6
SonarQube Fix
rfaasse Sep 22, 2023
c1bef92
Fix ubuntu build, which fails on comparison between different signedness
rfaasse Sep 25, 2023
e083848
Processing review comments
rfaasse Sep 26, 2023
f5dda6c
Made function const
rfaasse Sep 26, 2023
9c6849b
Added exception when process is unknown and added nullptr check
rfaasse Sep 26, 2023
995bb56
Added custom callback as per review comments
rfaasse Sep 26, 2023
4d808db
Review comments
rfaasse Sep 26, 2023
048177b
Fix Ubuntu build
rfaasse Sep 26, 2023
0274861
Minor SQ fixes
rfaasse Sep 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// KRATOS___
// // ) )
// // ___ ___
// // ____ //___) ) // ) )
// // / / // // / /
// ((____/ / ((____ ((___/ / MECHANICS
//
// License: geo_mechanics_application/license.txt
//
// Main authors: Richard Faasse
//
#include "json_process_info_parser.h"

namespace Kratos
{

std::vector<ProcessParameters> JsonProcessInfoParser::GetProcessList(const Parameters& rProcessParameters)
{
mProcessParameters = rProcessParameters;
avdg81 marked this conversation as resolved.
Show resolved Hide resolved
const std::vector<std::string> process_list_names = {"constraints_process_list",
"loads_process_list",
"auxiliar_process_list"};

for (const auto& process_list_name : process_list_names)
{
JsonProcessInfoParser::AddProcessesForList(process_list_name);
}

return mProcessNames;
}

void JsonProcessInfoParser::AddProcessesForList(const std::string& rProcessListName) {
if (!mProcessParameters.Has(rProcessListName))
{
return;
}

const auto processes_in_list = mProcessParameters[rProcessListName];

for (Parameters process : processes_in_list)
{
const std::string process_name_entry = "process_name";
if (process.Has(process_name_entry))
{
mProcessNames.emplace_back(process["Parameters"], process[process_name_entry].GetString());
}
}
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// KRATOS___
// // ) )
// // ___ ___
// // ____ //___) ) // ) )
// // / / // // / /
// ((____/ / ((____ ((___/ / MECHANICS
//
// License: geo_mechanics_application/license.txt
//
// Main authors: Richard Faasse
//

#pragma once

#include "process_info_parser.h"
#include "process_parameters.h"

#include <vector>

namespace Kratos {

class JsonProcessInfoParser : public ProcessInfoParser
{
public:
std::vector<ProcessParameters> GetProcessList(const Parameters& rProcessParameters) override;

private:
std::vector<ProcessParameters> mProcessNames;
Parameters mProcessParameters;

void AddProcessesForList(const std::string& rProcessListName);
};

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// KRATOS___
// // ) )
// // ___ ___
// // ____ //___) ) // ) )
// // / / // // / /
// ((____/ / ((____ ((___/ / MECHANICS
//
// License: geo_mechanics_application/license.txt
//
// Main authors: Richard Faasse
//

#pragma once

#include "process_parameters.h"

#include <vector>

namespace Kratos {

class ProcessInfoParser {
public:
virtual ~ProcessInfoParser() = default;
virtual std::vector<ProcessParameters> GetProcessList(const Parameters& rProcessParameters) = 0;
};

} // Kratos
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// KRATOS___
// // ) )
// // ___ ___
// // ____ //___) ) // ) )
// // / / // // / /
// ((____/ / ((____ ((___/ / MECHANICS
//
// License: geo_mechanics_application/license.txt
//
// Main authors: Richard Faasse
//
#pragma once

#include "includes/kratos_parameters.h"

#include <string>

namespace Kratos
{

struct ProcessParameters
avdg81 marked this conversation as resolved.
Show resolved Hide resolved
{
Parameters parameters;
std::string name;

ProcessParameters(const Parameters& rParameters, const std::string& rName) :
avdg81 marked this conversation as resolved.
Show resolved Hide resolved
parameters{rParameters},
name{rName}
{}

bool operator==(const ProcessParameters& rhs) const
{
return name == rhs.name && parameters.WriteJsonString() == rhs.parameters.WriteJsonString();
}
};

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@

#include "custom_workflow_factory.h"
#include "dgeosettlement.h"
#include "time_loop_executor.h"

#include "custom_utilities/file_input_utility.h"
#include "custom_utilities/json_process_info_parser.h"

#include <memory>

namespace Kratos
{

KratosGeoSettlement* CustomWorkflowFactory::CreateKratosGeoSettlement()
{
return new KratosGeoSettlement{std::make_unique<FileInputUtility>()};
return new KratosGeoSettlement{std::make_unique<FileInputUtility>(), std::make_unique<JsonProcessInfoParser>(), {}};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,28 @@
//
#include "dgeosettlement.h"
#include "input_output/logger.h"
#include "time_loop_executor.h"

#include "utilities/variable_utils.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"
#include "custom_processes/apply_excavation_process.hpp"

#include "custom_utilities/input_utility.h"
#include "custom_utilities/process_factory.hpp"
#include "custom_utilities/process_info_parser.h"

namespace Kratos
{

KratosGeoSettlement::KratosGeoSettlement(std::unique_ptr<InputUtility> pInputUtility) :
mpInputUtility{std::move(pInputUtility)}
KratosGeoSettlement::KratosGeoSettlement(std::unique_ptr<InputUtility> pInputUtility,
std::unique_ptr<ProcessInfoParser> pProcessInfoParser,
std::unique_ptr<TimeLoopExecutor> pTimeLoopExecutor) :
mpInputUtility{std::move(pInputUtility)},
mpProcessInfoParser{std::move(pProcessInfoParser)},
mpTimeLoopExecutor{std::move(pTimeLoopExecutor)}
{
KRATOS_INFO("KratosGeoSettlement") << "Setting up Kratos" << std::endl;
KRATOS_ERROR_IF_NOT(mpInputUtility) << "Invalid Input Utility";
Expand All @@ -29,6 +43,38 @@ KratosGeoSettlement::KratosGeoSettlement(std::unique_ptr<InputUtility> pInputUti
mpGeoApp = Kratos::make_shared<KratosGeoMechanicsApplication>();
mKernel.ImportApplication(mpGeoApp);
}

InitializeProcessFactory();
}

void KratosGeoSettlement::InitializeProcessFactory() {
mProcessFactory->AddCreator("ApplyVectorConstraintsTableProcess",
[this](const Parameters& rParameters)
{
return std::make_unique<ApplyVectorConstraintsTableProcess>(mModel.GetModelPart(mModelPartName),
rParameters);
});

mProcessFactory->AddCreator("SetParameterFieldProcess",
[this](const Parameters& rParameters)
{
return std::make_unique<SetParameterFieldProcess>(mModel.GetModelPart(mModelPartName),
rParameters);
});

mProcessFactory->AddCreator("ApplyExcavationProcess",
[this](const Parameters& rParameters)
{
return std::make_unique<ApplyExcavationProcess>(mModel.GetModelPart(mModelPartName),
rParameters);
});

mProcessFactory->AddCreator("ApplyK0ProcedureProcess",
[this](const Parameters& rParameters)
{
return std::make_unique<ApplyK0ProcedureProcess>(mModel.GetModelPart(mModelPartName),
rParameters);
});
}

int KratosGeoSettlement::RunStage(const std::filesystem::path& rWorkingDirectory,
Expand All @@ -45,6 +91,7 @@ int KratosGeoSettlement::RunStage(const std::filesystem::path& rWorki
project_parameters_file_path.generic_string());
KRATOS_INFO("KratosGeoSettlement") << "Parsed project parameters file " << project_parameters_file_path << std::endl;

mModelPartName = project_parameters["solver_settings"]["model_part_name"].GetString();
if (const auto model_part_name = project_parameters["solver_settings"]["model_part_name"].GetString();
!mModel.HasModelPart(model_part_name)) {
auto& model_part = AddNewModelPart(model_part_name);
Expand All @@ -59,6 +106,22 @@ int KratosGeoSettlement::RunStage(const std::filesystem::path& rWorki
KRATOS_INFO("KratosGeoSettlement") << "Read the materials from " << material_file_path << std::endl;
}

std::vector<std::reference_wrapper<Process>> process_references;
std::vector<std::unique_ptr<Process>> process_unique_ptrs;
avdg81 marked this conversation as resolved.
Show resolved Hide resolved
if (project_parameters.Has("processes"))
{
const auto processes = mpProcessInfoParser->GetProcessList(project_parameters["processes"]);
for (const auto& process : processes)
{
process_unique_ptrs.emplace_back(std::move(mProcessFactory->Create(process.name, process.parameters)));
}
for (const auto& process_unique_ptr : process_unique_ptrs)
{
process_references.emplace_back(*process_unique_ptr);
}
avdg81 marked this conversation as resolved.
Show resolved Hide resolved
}
mpTimeLoopExecutor->SetProcessReferences(process_references);

return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@
namespace Kratos
{

class ProcessFactory;
class InputUtility;
class ProcessInfoParser;
class TimeLoopExecutor;

class KRATOS_API(GEO_MECHANICS_APPLICATION) KratosGeoSettlement
{
public:
explicit KratosGeoSettlement(std::unique_ptr<InputUtility> pInputUtility);
explicit KratosGeoSettlement(std::unique_ptr<InputUtility> pInputUtility,
rfaasse marked this conversation as resolved.
Show resolved Hide resolved
std::unique_ptr<ProcessInfoParser> pProcessInfoParser,
std::unique_ptr<TimeLoopExecutor> pTimeLoopExecutor);
~KratosGeoSettlement();

int RunStage(const std::filesystem::path& rWorkingDirectory,
Expand All @@ -45,11 +50,16 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) KratosGeoSettlement
ModelPart& AddNewModelPart(const std::string& rModelPartName);
static void AddNodalSolutionStepVariablesTo(ModelPart& rModelPart);
static void AddDegreesOfFreedomTo(ModelPart& rModelPart);
void InitializeProcessFactory();

Kernel mKernel;
Model mModel;
std::string mModelPartName;
KratosGeoMechanicsApplication::Pointer mpGeoApp;
std::unique_ptr<ProcessFactory> mProcessFactory = std::make_unique<ProcessFactory>();
std::unique_ptr<InputUtility> mpInputUtility;
std::unique_ptr<ProcessInfoParser> mpProcessInfoParser;
std::unique_ptr<TimeLoopExecutor> mpTimeLoopExecutor;
};

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// KRATOS___
// // ) )
// // ___ ___
// // ____ //___) ) // ) )
// // / / // // / /
// ((____/ / ((____ ((___/ / MECHANICS
//
// License: geo_mechanics_application/license.txt
//
// Main authors: Richard Faasse
//

#pragma once

#include <vector>

namespace Kratos
{

class Process;

class TimeLoopExecutor {
public :
virtual ~TimeLoopExecutor() = default;
virtual void SetProcessReferences(const std::vector<std::reference_wrapper<Process>>& rProcessRefs) = 0;
};

}
Loading