OGS 6.2.1-97-g73d1aeda3
CreateProcessData.cpp
Go to the documentation of this file.
1 
10 #include "BaseLib/Algorithm.h"
11 
14 
15 #include "CreateProcessData.h"
16 
17 namespace ProcessLib
18 {
19 static std::unique_ptr<ProcessData> makeProcessData(
20  std::unique_ptr<NumLib::TimeStepAlgorithm>&& timestepper,
21  NumLib::NonlinearSolverBase& nonlinear_solver,
22  Process& process,
23  std::unique_ptr<NumLib::TimeDiscretization>&& time_disc,
24  std::unique_ptr<NumLib::ConvergenceCriterion>&& conv_crit)
25 {
26  using Tag = NumLib::NonlinearSolverTag;
27 
28  if (auto* nonlinear_solver_picard =
30  &nonlinear_solver))
31  {
32  return std::make_unique<ProcessData>(
33  std::move(timestepper), *nonlinear_solver_picard,
34  std::move(conv_crit), std::move(time_disc), process);
35  }
36  if (auto* nonlinear_solver_newton =
38  &nonlinear_solver))
39  {
40  return std::make_unique<ProcessData>(
41  std::move(timestepper), *nonlinear_solver_newton,
42  std::move(conv_crit), std::move(time_disc), process);
43  }
44 
45  OGS_FATAL("Encountered unknown nonlinear solver type. Aborting");
46 }
47 
48 std::vector<std::unique_ptr<ProcessData>> createPerProcessData(
49  BaseLib::ConfigTree const& config,
50  std::vector<std::unique_ptr<Process>> const& processes,
51  std::map<std::string, std::unique_ptr<NumLib::NonlinearSolverBase>> const&
52  nonlinear_solvers)
53 {
54  std::vector<std::unique_ptr<ProcessData>> per_process_data;
55 
57  for (auto pcs_config : config.getConfigSubtreeList("process"))
58  {
60  auto const pcs_name = pcs_config.getConfigAttribute<std::string>("ref");
61  auto& pcs = *BaseLib::getIfOrError(
62  processes,
63  [&pcs_name](std::unique_ptr<Process> const& p) {
64  return p->name == pcs_name;
65  },
66  "A process with the given name has not been defined.");
67 
68  auto const nl_slv_name =
70  pcs_config.getConfigParameter<std::string>("nonlinear_solver");
71  auto& nl_slv = *BaseLib::getOrError(
72  nonlinear_solvers, nl_slv_name,
73  "A nonlinear solver with the given name has not been defined.");
74 
75  auto time_disc = NumLib::createTimeDiscretization(
77  pcs_config.getConfigSubtree("time_discretization"));
78 
79  auto timestepper = NumLib::createTimeStepper(
81  pcs_config.getConfigSubtree("time_stepping"));
82 
83  auto conv_crit = NumLib::createConvergenceCriterion(
85  pcs_config.getConfigSubtree("convergence_criterion"));
86 
88  auto output = pcs_config.getConfigSubtreeOptional("output");
89  if (output)
90  {
91  OGS_FATAL(
92  "In order to make the specification of output in the project "
93  "file consistent, the variables output tags were moved from "
94  "xpath "
95  "'//OpenGeoSysProject/time_loop/processes/process/output' "
96  "to the global output section, i.e., to the xpath "
97  "'//OpenGeoSysProject/time_loop/output'. This has to be done "
98  "in the current project file!");
99  }
100 
101  per_process_data.emplace_back(makeProcessData(
102  std::move(timestepper), nl_slv, pcs, std::move(time_disc),
103  std::move(conv_crit)));
104  }
105 
106  if (per_process_data.size() != processes.size())
107  {
108  if (processes.size() > 1)
109  {
110  OGS_FATAL(
111  "Some processes have not been configured to be solved by this "
112  " time loop.");
113  }
114  else
115  {
116  INFO(
117  "The equations of the coupled processes will be solved by the "
118  "staggered scheme.");
119  }
120  }
121 
122  return per_process_data;
123 }
124 } // namespace ProcessLib
std::unique_ptr< TimeStepAlgorithm > createTimeStepper(BaseLib::ConfigTree const &config)
Map::mapped_type & getOrError(Map &map, Key const &key, std::string const &error_message)
Definition: Algorithm.h:147
NonlinearSolverTag
Tag used to specify which nonlinear solver will be used.
Definition: Types.h:19
Container::value_type const & getIfOrError(Container const &container, Predicate &&predicate, std::string const &error_message)
Definition: Algorithm.h:178
Range< SubtreeIterator > getConfigSubtreeList(std::string const &root) const
Definition: ConfigTree.cpp:174
#define OGS_FATAL(fmt,...)
Definition: Error.h:63
std::vector< std::unique_ptr< ProcessData > > createPerProcessData(BaseLib::ConfigTree const &config, std::vector< std::unique_ptr< Process >> const &processes, std::map< std::string, std::unique_ptr< NumLib::NonlinearSolverBase >> const &nonlinear_solvers)
static std::unique_ptr< ProcessData > makeProcessData(std::unique_ptr< NumLib::TimeStepAlgorithm > &&timestepper, NumLib::NonlinearSolverBase &nonlinear_solver, Process &process, std::unique_ptr< NumLib::TimeDiscretization > &&time_disc, std::unique_ptr< NumLib::ConvergenceCriterion > &&conv_crit)
std::unique_ptr< ConvergenceCriterion > createConvergenceCriterion(const BaseLib::ConfigTree &config)
Creates a convergence criterion from the given configuration.
std::unique_ptr< TimeDiscretization > createTimeDiscretization(BaseLib::ConfigTree const &config)