OGS
CreateTimeLoop.cpp
Go to the documentation of this file.
1 
11 #include "CreateTimeLoop.h"
12 
13 #include "BaseLib/ConfigTree.h"
17 #include "TimeLoop.h"
18 
19 namespace ProcessLib
20 {
21 std::unique_ptr<TimeLoop> createTimeLoop(
22  BaseLib::ConfigTree const& config, std::string const& output_directory,
23  const std::vector<std::unique_ptr<Process>>& processes,
24  const std::map<std::string, std::unique_ptr<NumLib::NonlinearSolverBase>>&
25  nonlinear_solvers,
26  std::vector<std::unique_ptr<MeshLib::Mesh>> const& meshes)
27 {
28  auto const& coupling_config
30  = config.getConfigSubtreeOptional("global_process_coupling");
31 
32  std::vector<std::unique_ptr<NumLib::ConvergenceCriterion>>
33  global_coupling_conv_criteria;
34  int max_coupling_iterations = 1;
35  if (coupling_config)
36  {
37  max_coupling_iterations
39  = coupling_config->getConfigParameter<int>("max_iter");
40 
41  auto const& coupling_convergence_criteria_config =
43  coupling_config->getConfigSubtree("convergence_criteria");
44 
45  for (
46  auto coupling_convergence_criterion_config :
48  coupling_convergence_criteria_config.getConfigSubtreeList(
49  "convergence_criterion"))
50  {
51  global_coupling_conv_criteria.push_back(
53  coupling_convergence_criterion_config));
54  }
55  }
56 
57  auto output =
59  createOutput(config.getConfigSubtree("output"), output_directory,
60  meshes);
61 
62  auto per_process_data = createPerProcessData(
64  config.getConfigSubtree("processes"), processes, nonlinear_solvers);
65 
66  if (coupling_config)
67  {
68  if (global_coupling_conv_criteria.size() != per_process_data.size())
69  {
70  OGS_FATAL(
71  "The number of convergence criteria of the global staggered "
72  "coupling loop is not identical to the number of the "
73  "processes! Please check the element by tag "
74  "global_process_coupling in the project file.");
75  }
76  }
77 
78  const auto minmax_iter = std::minmax_element(
79  per_process_data.begin(),
80  per_process_data.end(),
81  [](std::unique_ptr<ProcessData> const& a,
82  std::unique_ptr<ProcessData> const& b)
83  { return (a->timestepper->end() < b->timestepper->end()); });
84  const double start_time =
85  per_process_data[minmax_iter.first - per_process_data.begin()]
86  ->timestepper->begin();
87  const double end_time =
88  per_process_data[minmax_iter.second - per_process_data.begin()]
89  ->timestepper->end();
90 
91  return std::make_unique<TimeLoop>(
92  std::move(output), std::move(per_process_data), max_coupling_iterations,
93  std::move(global_coupling_conv_criteria), start_time, end_time);
94 }
95 } // namespace ProcessLib
#define OGS_FATAL(...)
Definition: Error.h:26
std::optional< ConfigTree > getConfigSubtreeOptional(std::string const &root) const
Definition: ConfigTree.cpp:155
ConfigTree getConfigSubtree(std::string const &root) const
Definition: ConfigTree.cpp:146
std::unique_ptr< ConvergenceCriterion > createConvergenceCriterion(const BaseLib::ConfigTree &config)
Creates a convergence criterion from the given configuration.
std::unique_ptr< Output > createOutput(const BaseLib::ConfigTree &config, std::string const &output_directory, std::vector< std::unique_ptr< MeshLib::Mesh >> const &meshes)
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)
std::unique_ptr< TimeLoop > createTimeLoop(BaseLib::ConfigTree const &config, std::string const &output_directory, const std::vector< std::unique_ptr< Process >> &processes, const std::map< std::string, std::unique_ptr< NumLib::NonlinearSolverBase >> &nonlinear_solvers, std::vector< std::unique_ptr< MeshLib::Mesh >> const &meshes)
Builds a TimeLoop from the given configuration.