Advanced Multi-Physics (AMP)
On-Line Documentation
Cycle.h
Go to the documentation of this file.
1#ifndef included_AMP_AMG_Cycle
2#define included_AMP_AMG_Cycle
3
4#include <memory>
5#include <string>
6#include <string_view>
7#include <vector>
8
9#include "AMP/operators/LinearOperator.h"
10#include "AMP/solvers/SolverStrategy.h"
11#include "AMP/solvers/amg/DeferConsistency.h"
12
13namespace AMP::Solver::AMG {
14struct LevelOperator : HasDeferConsistency<AMP::Operator::LinearOperator> {
16 using base::base;
18
19 virtual void apply( std::shared_ptr<const LinearAlgebra::Vector> u,
20 std::shared_ptr<LinearAlgebra::Vector> f ) override;
21};
22
23struct Level {
24 std::shared_ptr<LevelOperator> A;
25 std::shared_ptr<AMP::Operator::Operator> R, P;
26 std::unique_ptr<AMP::Solver::SolverStrategy> pre_relaxation, post_relaxation;
27 std::shared_ptr<LinearAlgebra::Vector> x, b, r, correction;
28 mutable std::size_t nrelax = 0;
29};
30
31template<std::size_t N>
33 // extra work vectors used in cycling
34 std::array<std::shared_ptr<LinearAlgebra::Vector>, N> work;
35};
36
37template<class T>
38constexpr bool is_level_v = std::is_base_of_v<Level, T>;
39
46template<std::size_t N>
48
49inline constexpr std::size_t num_work_kcycle = 5;
51
57void save_hierarchy( std::string_view base_name, const std::vector<KCycleLevel> &levels );
58
77 enum class krylov_type { fcg, gcr };
79 static krylov_type parseType( const std::string &kcycle_type );
81 static std::string_view krylovTypeName( const krylov_type t );
82
84 struct settings {
91 size_t kappa = 1;
93 float tol = 0;
95 bool comm_free_interp = false;
98 };
99
101
109 void operator()( std::shared_ptr<const LinearAlgebra::Vector> b,
110 std::shared_ptr<LinearAlgebra::Vector> x,
111 const std::vector<level> &levels,
112 SolverStrategy &coarse_solver ) const;
113
114private:
115 void cycle( size_t lvl,
116 size_t kappa,
117 std::shared_ptr<const LinearAlgebra::Vector> b,
118 std::shared_ptr<LinearAlgebra::Vector> x,
119 const std::vector<level> &levels,
120 SolverStrategy &coarse_solver ) const;
122 static inline std::map<std::string, krylov_type> type_map{ { "fcg", krylov_type::fcg },
123 { "gcr", krylov_type::gcr } };
124};
125} // namespace AMP::Solver::AMG
126
127#endif
Abstraction of a discrete Vector in a linear simulation.
Definition Vector.h:54
std::shared_ptr< AMP::Operator::Operator > shared_ptr
Definition Operator.h:29
constexpr std::size_t num_work_kcycle
Definition Cycle.h:49
constexpr bool is_level_v
Definition Cycle.h:38
LevelWithWorkspace< num_work_kcycle > KCycleLevel
Definition Cycle.h:50
void save_hierarchy(std::string_view base_name, const std::vector< KCycleLevel > &levels)
void clone_workspace(LevelWithWorkspace< N > &level, const LinearAlgebra::Vector &donor)
Settings for the Kappa K-cycle.
Definition Cycle.h:84
bool comm_free_interp
indicates interpolation will not use ghosts and communication may be avoided.
Definition Cycle.h:95
float tol
residual tolerance for FCG/GCR.
Definition Cycle.h:93
krylov_type type
Krylov method for cycle.
Definition Cycle.h:97
KappaKCycle(const settings &)
static std::string_view krylovTypeName(const krylov_type t)
Get krylov_type as string for printing.
static std::map< std::string, krylov_type > type_map
Definition Cycle.h:122
krylov_type
K-cycle variant.
Definition Cycle.h:77
void operator()(std::shared_ptr< const LinearAlgebra::Vector > b, std::shared_ptr< LinearAlgebra::Vector > x, const std::vector< level > &levels, SolverStrategy &coarse_solver) const
void cycle(size_t lvl, size_t kappa, std::shared_ptr< const LinearAlgebra::Vector > b, std::shared_ptr< LinearAlgebra::Vector > x, const std::vector< level > &levels, SolverStrategy &coarse_solver) const
static krylov_type parseType(const std::string &kcycle_type)
Recover krylov_type from input string (either "fcg" or "gcr").
LevelOperator(const AMP::Operator::LinearOperator &linop)
virtual void apply(std::shared_ptr< const LinearAlgebra::Vector > u, std::shared_ptr< LinearAlgebra::Vector > f) override
std::array< std::shared_ptr< LinearAlgebra::Vector >, N > work
Definition Cycle.h:34
std::size_t nrelax
Definition Cycle.h:28
std::unique_ptr< AMP::Solver::SolverStrategy > pre_relaxation
Definition Cycle.h:26
std::shared_ptr< LinearAlgebra::Vector > correction
Definition Cycle.h:27
std::shared_ptr< LevelOperator > A
Definition Cycle.h:24
std::shared_ptr< LinearAlgebra::Vector > b
Definition Cycle.h:27
std::shared_ptr< LinearAlgebra::Vector > r
Definition Cycle.h:27
std::shared_ptr< AMP::Operator::Operator > P
Definition Cycle.h:25
std::unique_ptr< AMP::Solver::SolverStrategy > post_relaxation
Definition Cycle.h:26
std::shared_ptr< AMP::Operator::Operator > R
Definition Cycle.h:25
std::shared_ptr< LinearAlgebra::Vector > x
Definition Cycle.h:27



Advanced Multi-Physics (AMP)
Oak Ridge National Laboratory
Idaho National Laboratory
Los Alamos National Laboratory
This page automatically produced from the
source code by doxygen
Last updated: Tue Mar 10 2026 13:06:41.
Comments on this page