OGS
CreateTimeLoop.cpp
Go to the documentation of this file.
1
11#include "CreateTimeLoop.h"
12
13#include <algorithm>
14#include <range/v3/algorithm/any_of.hpp>
15#include <range/v3/view/join.hpp>
16#include <string>
17
18#include "BaseLib/ConfigTree.h"
25#include "TimeLoop.h"
26
27namespace ProcessLib
28{
29std::unique_ptr<TimeLoop> createTimeLoop(
30 BaseLib::ConfigTree const& config, std::string const& output_directory,
31 const std::vector<std::unique_ptr<Process>>& processes,
32 const std::map<std::string, std::unique_ptr<NumLib::NonlinearSolverBase>>&
33 nonlinear_solvers,
34 std::vector<std::unique_ptr<MeshLib::Mesh>>& meshes,
35 bool const compensate_non_equilibrium_initial_residuum)
36{
38 auto output_config_tree = config.getConfigSubtreeOptional("output");
39 if (!output_config_tree)
40 {
41 INFO("No output section found.");
42 }
43 auto outputs =
44 output_config_tree
45 ? createOutput(*output_config_tree, output_directory, meshes)
47 : createOutputs(config.getConfigSubtree("outputs"),
48 output_directory, meshes);
49 auto const fixed_times_for_output =
51
52 if (auto const submesh_residuum_output_config_tree =
54 config.getConfigSubtreeOptional("submesh_residuum_output");
55 submesh_residuum_output_config_tree)
56 {
58 *submesh_residuum_output_config_tree, output_directory, meshes);
59
60 for (auto& process : processes)
61 {
62 auto const& residuum_vector_names =
63 process->initializeAssemblyOnSubmeshes(smroc.meshes);
64
65 for (auto const& name : residuum_vector_names | ranges::views::join)
66 {
67 smroc.output.doNotProjectFromBulkMeshToSubmeshes(
69 }
70 }
71
72 outputs.push_back(std::move(smroc.output));
73 }
74 else
75 {
76 // Submesh assembly must always be initialized.
77 for (auto& process : processes)
78 {
79 process->initializeAssemblyOnSubmeshes({});
80 }
81 }
82
83 auto per_process_data = createPerProcessData(
85 config.getConfigSubtree("processes"), processes, nonlinear_solvers,
86 compensate_non_equilibrium_initial_residuum, fixed_times_for_output);
87
88 const bool use_staggered_scheme =
89 ranges::any_of(processes.begin(), processes.end(),
90 [](auto const& process)
91 { return !(process->isMonolithicSchemeUsed()); });
92
93 std::unique_ptr<NumLib::StaggeredCoupling> staggered_coupling = nullptr;
94 if (use_staggered_scheme)
95 {
97 config, per_process_data);
98 }
99 else
100 {
101 if (per_process_data.size() > 1)
102 {
103 OGS_FATAL(
104 "The monolithic scheme is used. However more than one "
105 "process data tags (by name \"process\") inside tag "
106 "\"time_loop\" are defined for the staggered scheme. If you "
107 "want to use staggered scheme, please set the element of tag "
108 "\"<coupling_scheme>\" to \"staggered\".");
109 }
110 }
111
112 const auto minmax_iter =
113 std::minmax_element(per_process_data.begin(),
114 per_process_data.end(),
115 [](std::unique_ptr<ProcessData> const& a,
116 std::unique_ptr<ProcessData> const& b) {
117 return (a->timestep_algorithm->end() <
118 b->timestep_algorithm->end());
119 });
120 auto const start_time =
121 per_process_data[minmax_iter.first - per_process_data.begin()]
122 ->timestep_algorithm->begin();
123 auto const end_time =
124 per_process_data[minmax_iter.second - per_process_data.begin()]
125 ->timestep_algorithm->end();
126
127 return std::make_unique<TimeLoop>(
128 std::move(outputs), std::move(per_process_data),
129 std::move(staggered_coupling), start_time, end_time);
130}
131} // namespace ProcessLib
#define OGS_FATAL(...)
Definition Error.h:26
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
std::optional< ConfigTree > getConfigSubtreeOptional(std::string const &root) const
ConfigTree getConfigSubtree(std::string const &root) const
std::unique_ptr< StaggeredCoupling > createStaggeredCoupling(BaseLib::ConfigTree const &config, std::vector< std::unique_ptr< ProcessData > > const &per_process_data)
Create a StaggeredCoupling instance from the given configuration.
SubmeshResiduumOutputConfig createSubmeshResiduumOutputConfig(BaseLib::ConfigTree const &config, std::string const &output_directory, std::vector< std::unique_ptr< MeshLib::Mesh > > &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, bool const compensate_non_equilibrium_initial_residuum, std::vector< double > const &fixed_times_for_output)
Output createOutput(OutputConfig &&oc, std::string const &output_directory, std::vector< std::unique_ptr< MeshLib::Mesh > > const &meshes)
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 > > &meshes, bool const compensate_non_equilibrium_initial_residuum)
Builds a TimeLoop from the given configuration.
std::vector< double > calculateUniqueFixedTimesForAllOutputs(std::vector< Output > const &outputs)
Definition Output.cpp:433
std::vector< Output > createOutputs(const BaseLib::ConfigTree &output_configs, std::string const &output_directory, std::vector< std::unique_ptr< MeshLib::Mesh > > &meshes)