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