KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
solving_strategy_factory.hpp
Go to the documentation of this file.
1 // KRATOS___
2 // // ) )
3 // // ___ ___
4 // // ____ //___) ) // ) )
5 // // / / // // / /
6 // ((____/ / ((____ ((___/ / MECHANICS
7 //
8 // License: geo_mechanics_application/license.txt
9 //
10 // Main authors: Richard Faasse
11 //
12 
13 #pragma once
14 
15 #include <memory>
16 #include <string>
17 
22 #include "scheme_factory.hpp"
25 #include "parameters_utilities.h"
26 
27 namespace Kratos {
28 
29 template<class TSparseSpace, class TDenseSpace, class TLinearSolver>
31 public:
32  [[nodiscard]] static std::unique_ptr<SolvingStrategy<TSparseSpace, TDenseSpace>>
33  Create(const Parameters& rSolverSettings, ModelPart& rModelPart) {
34  const std::string strategy_type = "strategy_type";
35 
36  KRATOS_ERROR_IF_NOT(rSolverSettings.Has(strategy_type))
37  << "The parameter strategy_type is undefined, aborting.";
38 
39  const auto echo_level = rSolverSettings["echo_level"].GetInt();
40 
42  rSolverSettings["linear_solver_settings"]);
43  KRATOS_ERROR_IF_NOT(solver) << "Failed to create a linear solver" << std::endl;
44 
45  auto scheme = SchemeFactory<TSparseSpace, TDenseSpace>::Create(rSolverSettings);
46  KRATOS_ERROR_IF_NOT(scheme) << "Failed to create a scheme" << std::endl;
47 
49  rSolverSettings, solver);
50  KRATOS_ERROR_IF_NOT(builder_and_solver) << "Failed to create a builder-and-solver" << std::endl;
51  builder_and_solver->SetEchoLevel(echo_level);
52 
54  KRATOS_ERROR_IF_NOT(criteria) << "Failed to create convergence criteria" << std::endl;
55  criteria->SetEchoLevel(echo_level);
56 
57  if (rSolverSettings[strategy_type].GetString() == "newton_raphson") {
58  const auto max_iterations = rSolverSettings["max_iterations"].GetInt();
59  const auto calculate_reactions = rSolverSettings["calculate_reactions"].GetBool();
60  const auto reform_dof_set_at_each_step = rSolverSettings["reform_dofs_at_each_step"].GetBool();
61  const auto move_mesh_flag = rSolverSettings["move_mesh_flag"].GetBool();
62 
63  const std::vector<std::string> strategy_entries = {"loads_sub_model_part_list",
64  "loads_variable_list"};
65  auto strategy_parameters = ParametersUtilities::CopyOptionalParameters(
66  rSolverSettings, strategy_entries);
67  auto result = std::make_unique<GeoMechanicsNewtonRaphsonStrategy<TSparseSpace,
68  TDenseSpace,
69  TLinearSolver>>(rModelPart,
70  scheme,
71  solver,
72  criteria,
73  builder_and_solver,
74  strategy_parameters,
76  calculate_reactions,
77  reform_dof_set_at_each_step,
78  move_mesh_flag);
79  result->SetEchoLevel(echo_level);
80  return result;
81  } else if (rSolverSettings[strategy_type].GetString() == "line_search") {
82  const std::vector<std::string> strategy_entries = {"max_iteration",
83  "compute_reactions",
84  "max_line_search_iterations",
85  "first_alpha_value",
86  "second_alpha_value",
87  "min_alpha",
88  "max_alpha",
89  "line_search_tolerance",
90  "move_mesh_flag",
91  "reform_dofs_at_each_step",
92  "echo_level"};
93 
94  auto strategy_parameters = ParametersUtilities::CopyOptionalParameters(
95  rSolverSettings, strategy_entries);
96  auto result = std::make_unique<LineSearchStrategy<TSparseSpace,
97  TDenseSpace,
98  TLinearSolver>>(rModelPart,
99  scheme,
100  solver,
101  criteria,
102  strategy_parameters);
103  return result;
104  }
105 
106  return nullptr;
107  }
108 };
109 
110 }
static std::shared_ptr< BuilderAndSolverType > Create(const Parameters &rSolverSettings, typename TLinearSolver::Pointer pNewLinearSystemSolver)
Definition: builder_and_solver_factory.hpp:28
static std::shared_ptr< ConvergenceCriteriaType > Create(const Parameters &rSolverSettings)
Definition: convergence_criteria_factory.hpp:28
Definition: geo_mechanics_newton_raphson_strategy.hpp:31
Short class definition.
Definition: line_search_strategy.h:84
Here we add the functions needed for the registration of linear solvers.
Definition: linear_solver_factory.h:62
virtual LinearSolver< TSparseSpace, TLocalSpace >::Pointer Create(Kratos::Parameters Settings) const
This method creates a new solver.
Definition: linear_solver_factory.h:100
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
int GetInt() const
This method returns the integer contained in the current Parameter.
Definition: kratos_parameters.cpp:666
bool Has(const std::string &rEntry) const
This method checks if the Parameter contains a certain entry.
Definition: kratos_parameters.cpp:520
bool GetBool() const
This method returns the boolean contained in the current Parameter.
Definition: kratos_parameters.cpp:675
static Parameters CopyOptionalParameters(const Parameters &rSourceParameters, const std::vector< std::string > &rNamesOfParametersToCopy)
Definition: parameters_utilities.cpp:27
void SetEchoLevel(int Level) override
It sets the level of echo for the solving strategy.
Definition: residualbased_newton_raphson_strategy.h:599
static std::shared_ptr< SchemeType > Create(const Parameters &rSolverSettings)
Definition: scheme_factory.hpp:28
Definition: solving_strategy_factory.hpp:30
static std::unique_ptr< SolvingStrategy< TSparseSpace, TDenseSpace > > Create(const Parameters &rSolverSettings, ModelPart &rModelPart)
Definition: solving_strategy_factory.hpp:33
#define KRATOS_ERROR_IF_NOT(conditional)
Definition: exception.h:163
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
unique_ptr< C > make_unique(Args &&...args)
Definition: smart_pointers.h:45
int max_iterations
Definition: ProjectParameters.py:53
echo_level
Definition: script.py:68
solver
Definition: script.py:98