OGS
StaggeredCoupling.cpp
Go to the documentation of this file.
1
11#include "StaggeredCoupling.h"
12
13#include <range/v3/view/filter.hpp>
14
15#include "BaseLib/Error.h"
16#include "BaseLib/RunTime.h"
20
21namespace NumLib
22{
30
32 std::vector<GlobalVector*> const& process_solutions)
33{
34 for (auto const* const x : process_solutions)
35 {
36 // Create a vector to store the solution of the last coupling iteration
39
40 // append a solution vector of suitable size
41 solutions_of_last_cpl_iteration_.emplace_back(&x0);
42 }
43}
44
46 std::vector<CouplingNodeVariant> const& coupling_nodes)
47{
48 auto is_regular_node = [](const CouplingNodeVariant& node)
49 { return std::holds_alternative<CouplingNode>(node); };
50
51 for (auto const& coupling_node :
52 coupling_nodes | ranges::views::filter(is_regular_node))
53 {
54 std::get<CouplingNode>(coupling_node)
55 .convergence_criterion->preFirstIteration();
56 }
57}
58
60 std::vector<CouplingNodeVariant> const& coupling_nodes)
61{
62 auto is_regular_node = [](const CouplingNodeVariant& node)
63 { return std::holds_alternative<CouplingNode>(node); };
64
65 for (auto& coupling_node :
66 coupling_nodes | ranges::views::filter(is_regular_node))
67 {
68 std::get<CouplingNode>(coupling_node).convergence_criterion->reset();
69 }
70}
71
73 const bool convergence_of_last_process,
74 CouplingNode const& coupling_node,
75 GlobalVector const& x) const
76{
77 bool is_coupling_iteration_converged = convergence_of_last_process;
78
79 auto& x_old = *solutions_of_last_cpl_iteration_[coupling_node.process_id];
80 // Since x_old can be immediately refreshed after computing dx,
81 // it is assigned with dx to save memory usage
82 MathLib::LinAlg::axpy(x_old, -1.0, x); // save dx = x - x_old to x_old.
83 INFO(
84 "------- Checking convergence criterion for coupled "
85 "solution of process {:s} with ID {:d} -------",
86 coupling_node.process_name, coupling_node.process_id);
87 // Note: x_old stores dx
88 coupling_node.convergence_criterion->checkDeltaX(x_old, x);
89
90 is_coupling_iteration_converged =
91 is_coupling_iteration_converged &&
92 coupling_node.convergence_criterion->isSatisfied();
93
94 return is_coupling_iteration_converged;
95}
96
98 GlobalVector const& x)
99{
100 auto& x_old = *solutions_of_last_cpl_iteration_[process_id];
101 MathLib::LinAlg::copy(x, x_old);
102}
103
104} // namespace NumLib
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
Definition of the RunTime class.
Global vector based on Eigen vector.
Definition EigenVector.h:25
void initializeCoupledSolutions(std::vector< GlobalVector * > const &process_solutions)
void resetCouplingConvergenceCriteria(std::vector< CouplingNodeVariant > const &coupling_nodes)
std::vector< GlobalVector * > solutions_of_last_cpl_iteration_
void setFirstIterationIndicator(std::vector< CouplingNodeVariant > const &coupling_nodes)
Set the indicator of the first staggered coupling iteration be true.
bool checkCouplingConvergence(const bool convergence_of_last_process, CouplingNode const &coupling_node, GlobalVector const &x) const
void updatePreviousSolution(int const process_id, GlobalVector const &x)
std::variant< CouplingNode, RootCouplingNode > CouplingNodeVariant
virtual GlobalVector & getVector(std::size_t &id)=0
Get an uninitialized vector with the given id.
virtual void releaseVector(GlobalVector const &x)=0
void copy(PETScVector const &x, PETScVector &y)
Definition LinAlg.cpp:37
void axpy(PETScVector &y, PetscScalar const a, PETScVector const &x)
Definition LinAlg.cpp:57
Information of a coupling node.
std::unique_ptr< NumLib::ConvergenceCriterion > convergence_criterion
static NUMLIB_EXPORT VectorProvider & provider