OGS
CreateStaggeredCoupling.cpp
Go to the documentation of this file.
1
13
14#include "BaseLib/ConfigTree.h"
15#include "BaseLib/Error.h"
17#include "StaggeredCoupling.h"
18
19namespace NumLib
20{
21
24std::vector<LocalCouplingParameters> parseLocalCoupling(
25 BaseLib::ConfigTree const& config, const std::size_t max_process_number)
26{
27 auto const local_coupling_configs =
29 config.getConfigSubtreeList("local_coupling_processes");
30
31 if (local_coupling_configs.empty())
32 {
33 return {};
34 }
35
36 std::vector<LocalCouplingParameters> all_local_coupling_parameters;
37 std::vector<std::string> all_local_process_names;
38 for (auto const& local_coupling_config : local_coupling_configs)
39 {
40 std::vector<std::string> process_names;
41
42 for (
43 auto name :
44 local_coupling_config
46 .getConfigParameterList<std::string>("process_name"))
47 {
48 if (std::find(process_names.begin(), process_names.end(), name) !=
49 process_names.end())
50 {
52 "The name of locally coupled process, {}, is not unique.",
53 name);
54 }
55 process_names.push_back(name);
56
57 all_local_process_names.push_back(name);
58 }
59
60 if (process_names.size() > max_process_number)
61 {
63 "The number of the locally coupled processes is greater "
64 "than the number of total coupled processes. "
65 "Please check the number of elements in the tag "
66 "'time_loop/global_process_coupling/"
67 "local_coupling_processes' in the project file.");
68 }
69
70 INFO("There are {:d} locally coupled processes.", process_names.size());
71
72 int max_iterations =
73 local_coupling_config
75 .getConfigParameter<int>("max_iter");
76
77 all_local_coupling_parameters.push_back(
78 {process_names, max_iterations});
79 }
80
81 // std::adjacent_find only finds equal elements directly next to each other.
82 // Therefore, a copy of the vector is sorted first and then it is checked
83 // for duplicated element.
84 std::vector<std::string> copy_all_local_process_names =
85 all_local_process_names;
86 std::sort(copy_all_local_process_names.begin(),
87 copy_all_local_process_names.end());
88 if (auto it = std::adjacent_find(copy_all_local_process_names.begin(),
89 copy_all_local_process_names.end());
90 it != copy_all_local_process_names.end())
91 {
93 "There are process names appearing in multiple tags of "
94 "'time_loop/global_process_coupling/local_coupling_processes'. For "
95 "example, name {}",
96 *it);
97 }
98
99 return all_local_coupling_parameters;
100}
101
102std::tuple<std::vector<std::unique_ptr<NumLib::ConvergenceCriterion>>,
103 std::vector<LocalCouplingParameters>,
104 int>
106{
107 auto const& coupling_config
109 = config.getConfigSubtreeOptional("global_process_coupling");
110
111 std::vector<std::unique_ptr<NumLib::ConvergenceCriterion>>
112 global_coupling_conv_criteria;
113
114 std::vector<LocalCouplingParameters> all_local_coupling_parameters;
115
116 int max_coupling_iterations = 1;
117 if (coupling_config)
118 {
119 max_coupling_iterations
121 = coupling_config->getConfigParameter<int>("max_iter");
122
123 auto const& coupling_convergence_criteria_config =
125 coupling_config->getConfigSubtree("convergence_criteria");
126
127 auto coupling_convergence_criterion_config =
129 coupling_convergence_criteria_config.getConfigSubtreeList(
130 "convergence_criterion");
131 std::transform(coupling_convergence_criterion_config.begin(),
132 coupling_convergence_criterion_config.end(),
133 std::back_inserter(global_coupling_conv_criteria),
134 [](BaseLib::ConfigTree const& c)
135 { return NumLib::createConvergenceCriterion(c); });
136
137 all_local_coupling_parameters = parseLocalCoupling(
138 *coupling_config, global_coupling_conv_criteria.size());
139 }
140
141 return {std::move(global_coupling_conv_criteria),
142 std::move(all_local_coupling_parameters), max_coupling_iterations};
143}
144
145} // namespace NumLib
#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
Range< SubtreeIterator > getConfigSubtreeList(std::string const &root) const
std::vector< LocalCouplingParameters > parseLocalCoupling(BaseLib::ConfigTree const &config, const std::size_t max_process_number)
std::tuple< std::vector< std::unique_ptr< NumLib::ConvergenceCriterion > >, std::vector< LocalCouplingParameters >, int > parseCoupling(BaseLib::ConfigTree const &config)