OGS
CreateProcessData.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#include <range/v3/algorithm/contains.hpp>
5
6#include "BaseLib/Algorithm.h"
9#ifdef USE_PETSC
11#endif // USE_PETSC
12#include "CreateProcessData.h"
14
15namespace ProcessLib
16{
17static std::unique_ptr<ProcessData> makeProcessData(
18 std::unique_ptr<NumLib::TimeStepAlgorithm>&& timestepper,
19 NumLib::NonlinearSolverBase& nonlinear_solver, int const process_id,
20 std::string process_name, Process& process,
21 std::unique_ptr<NumLib::TimeDiscretization>&& time_disc,
22 std::unique_ptr<NumLib::ConvergenceCriterion>&& conv_crit,
23 bool const compensate_non_equilibrium_initial_residuum)
24{
26
27 if (auto* nonlinear_solver_picard =
29 &nonlinear_solver))
30 {
31 nonlinear_solver_picard->compensateNonEquilibriumInitialResiduum(
32 compensate_non_equilibrium_initial_residuum);
33 return std::make_unique<ProcessData>(
34 std::move(timestepper), Tag::Picard, *nonlinear_solver_picard,
35 std::move(conv_crit), std::move(time_disc), process_id,
36 std::move(process_name), process);
37 }
38 if (auto* nonlinear_solver_newton =
40 &nonlinear_solver))
41 {
42 nonlinear_solver_newton->compensateNonEquilibriumInitialResiduum(
43 compensate_non_equilibrium_initial_residuum);
44 return std::make_unique<ProcessData>(
45 std::move(timestepper), Tag::Newton, *nonlinear_solver_newton,
46 std::move(conv_crit), std::move(time_disc), process_id,
47 std::move(process_name), process);
48 }
49#ifdef USE_PETSC
50 if (auto* nonlinear_solver_petsc =
51 dynamic_cast<NumLib::PETScNonlinearSolver*>(&nonlinear_solver))
52 {
53 return std::make_unique<ProcessData>(
54 std::move(timestepper), Tag::Newton, *nonlinear_solver_petsc,
55 std::move(conv_crit), std::move(time_disc), process_id,
56 std::move(process_name), process);
57 }
58#endif // USE_PETSC
59
60 OGS_FATAL("Encountered unknown nonlinear solver type. Aborting");
61}
62
63std::vector<std::unique_ptr<ProcessData>> createPerProcessData(
64 BaseLib::ConfigTree const& config,
65 std::vector<std::unique_ptr<Process>> const& processes,
66 std::map<std::string, std::unique_ptr<NumLib::NonlinearSolverBase>> const&
67 nonlinear_solvers,
68 bool const compensate_non_equilibrium_initial_residuum,
69 std::vector<double> const& fixed_times_for_output)
70{
71 std::vector<std::unique_ptr<ProcessData>> per_process_data;
72 std::vector<std::string> process_names;
73 int process_id = 0;
74
76 for (auto pcs_config : config.getConfigSubtreeList("process"))
77 {
79 auto const pcs_name = pcs_config.getConfigAttribute<std::string>("ref");
80 auto& pcs = *BaseLib::getIfOrError(
81 processes,
82 [&pcs_name](std::unique_ptr<Process> const& p)
83 { return p->name == pcs_name; },
84 "A process with the given name has not been defined.");
85
86 auto const process_name =
88 pcs_config.getConfigParameter<std::string>("process_name", "");
89 if (process_name != "")
90 {
91 if (ranges::contains(process_names, process_name))
92 {
94 "The given process name is not unique! Please check the "
95 "element "
96 "'time_loop/process/name' in the project file. Found "
97 "duplicate "
98 "process name '{:s}'.",
99 process_name);
100 }
101 process_names.emplace_back(process_name);
102 }
103
104 auto const nl_slv_name =
106 pcs_config.getConfigParameter<std::string>("nonlinear_solver");
107 auto& nl_slv = *BaseLib::getOrError(
108 nonlinear_solvers, nl_slv_name,
109 "A nonlinear solver with the given name has not been defined.");
110
111 auto time_disc = NumLib::createTimeDiscretization(
113 pcs_config.getConfigSubtree("time_discretization"));
114
115 auto timestepper = NumLib::createTimeStepper(
117 pcs_config.getConfigSubtree("time_stepping"),
118 fixed_times_for_output);
119
120 auto conv_crit = NumLib::createConvergenceCriterion(
122 pcs_config.getConfigSubtree("convergence_criterion"));
123
125 auto output = pcs_config.getConfigSubtreeOptional("output");
126 if (output)
127 {
128 OGS_FATAL(
129 "In order to make the specification of output in the project "
130 "file consistent, the variables output tags were moved from "
131 "xpath "
132 "'//OpenGeoSysProject/time_loop/processes/process/output' to "
133 "the global output section, i.e., to the xpath "
134 "'//OpenGeoSysProject/time_loop/output'. This has to be done "
135 "in the current project file!");
136 }
137
138 per_process_data.emplace_back(makeProcessData(
139 std::move(timestepper), nl_slv, process_id, std::move(process_name),
140 pcs, std::move(time_disc), std::move(conv_crit),
141 compensate_non_equilibrium_initial_residuum));
142 ++process_id;
143 }
144
145 if (per_process_data.size() != processes.size())
146 {
147 if (processes.size() > 1)
148 {
149 OGS_FATAL(
150 "Some processes have not been configured to be solved by this "
151 "time loop.");
152 }
153 else
154 {
155 INFO(
156 "The equations of the coupled processes will be solved by the "
157 "staggered scheme.");
158 }
159 }
160
161 return per_process_data;
162}
163} // namespace ProcessLib
#define OGS_FATAL(...)
Definition Error.h:19
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:28
Range< SubtreeIterator > getConfigSubtreeList(std::string const &root) const
NonlinearSolverTag
Tag used to specify which nonlinear solver will be used.
Definition Types.h:13
OGS_NO_DANGLING Container::value_type const & getIfOrError(Container const &container, Predicate &&predicate, std::string const &error_message)
Definition Algorithm.h:156
OGS_NO_DANGLING Map::mapped_type & getOrError(Map &map, Key const &key, std::string const &error_message)
Definition Algorithm.h:111
std::unique_ptr< TimeDiscretization > createTimeDiscretization(BaseLib::ConfigTree const &config)
std::unique_ptr< TimeStepAlgorithm > createTimeStepper(BaseLib::ConfigTree const &config, std::vector< double > const &fixed_times_for_output)
std::unique_ptr< ConvergenceCriterion > createConvergenceCriterion(const BaseLib::ConfigTree &config)
Creates a convergence criterion from the given configuration.
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)
static std::unique_ptr< ProcessData > makeProcessData(std::unique_ptr< NumLib::TimeStepAlgorithm > &&timestepper, NumLib::NonlinearSolverBase &nonlinear_solver, int const process_id, std::string process_name, Process &process, std::unique_ptr< NumLib::TimeDiscretization > &&time_disc, std::unique_ptr< NumLib::ConvergenceCriterion > &&conv_crit, bool const compensate_non_equilibrium_initial_residuum)