deal.II version GIT relicensing-6842-g793a97d2aa 2026-10-02 14:00:01+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
psblas_precondition.cc
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2008 - 2023 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15
16
18
19#ifdef DEAL_II_WITH_AMG4PSBLAS
20
22
23namespace PSCToolkitWrappers
24{
25
26 PreconditionAMG::PreconditionAMG()
27 {
28 psblas_preconditioner = amg_c_dprec_new();
29 }
30
31
32 void
33 PreconditionAMG::initialize(const SparseMatrix &matrix,
34 const AdditionalData &additional_data)
35 {
36 Assert(matrix.psblas_sparse_matrix != nullptr,
37 ExcMessage("Matrix has not been initialized."));
38
39 // set descriptor from matrix and allocate workspace with proper size
40 psblas_descriptor = matrix.psblas_descriptor;
41
42 int err = amg_c_dprecinit(*InitFinalize::get_psblas_context(),
43 psblas_preconditioner,
44 "ML");
45 AssertThrow(err == 0,
46 ExcMessage("Error " + std::to_string(err) +
47 " while initializing AMG preconditioner."));
48
49 amg_c_dprecsetc(psblas_preconditioner,
50 "ML_CYCLE",
51 additional_data.cycle_type);
52 amg_c_dprecseti(psblas_preconditioner,
53 "CYCLE_SWEEPS",
54 additional_data.n_cycles);
55 amg_c_dprecsetr(psblas_preconditioner,
56 "AGGR_THRSH",
57 additional_data.aggregation_threshold);
58 amg_c_dprecsetc(psblas_preconditioner,
59 "PAR_AGGR_ALG",
60 additional_data.parallel_aggr_algorithm);
61 amg_c_dprecsetc(psblas_preconditioner,
62 "AGGR_TYPE",
63 additional_data.aggregation_type);
64 amg_c_dprecseti(psblas_preconditioner,
65 "AGGR_SIZE",
66 additional_data.aggregation_size);
67 amg_c_dprecsetc(psblas_preconditioner,
68 "AGGR_PROL",
69 additional_data.aggr_prol);
70 amg_c_dprecsetc(psblas_preconditioner,
71 "AGGR_FILTER",
72 additional_data.aggr_filter);
73 amg_c_dprecsetc(psblas_preconditioner,
74 "SMOOTHER_TYPE",
75 additional_data.smoother_type);
76
77 // From the AMG4PSBLAS manual: if "SMOOTHER_TYPE" is set to
78 // "POLY", then "SMOOTHER_SWEEPS" is ignored and the number of smoother
79 // sweeps equals the polynomial degree is used instead.
80 if (std::strcmp(additional_data.smoother_type, "POLY") == 0)
81 amg_c_dprecseti(psblas_preconditioner,
82 "POLY_DEGREE",
83 additional_data.smoother_sweeps);
84 else
85 amg_c_dprecseti(psblas_preconditioner,
86 "SMOOTHER_SWEEPS",
87 additional_data.smoother_sweeps);
88 amg_c_dprecsetc(psblas_preconditioner,
89 "COARSE_SOLVE",
90 additional_data.coarse_type);
91
92 // build AMG hierarchy
93 err = amg_c_dhierarchy_build(matrix.psblas_sparse_matrix,
94 psblas_descriptor.get(),
95 psblas_preconditioner);
96 AssertThrow(err == 0,
97 ExcMessage("Error " + std::to_string(err) +
98 " while building AMG hierarchy."));
99 //... and smoothers
100 err = amg_c_dsmoothers_build(matrix.psblas_sparse_matrix,
101 psblas_descriptor.get(),
102 psblas_preconditioner);
103 AssertThrow(err == 0,
104 ExcMessage("Error " + std::to_string(err) +
105 " while building AMG smoothers."));
106
107 if (additional_data.output_details == true)
108 {
109 err = amg_c_ddescr(psblas_preconditioner);
110 AssertThrow(err == 0,
111 ExcMessage("Error " + std::to_string(err) +
112 " while printing AMG description."));
113 }
114 }
115
116
117 PreconditionAMG::~PreconditionAMG()
118 {
119 if (psblas_preconditioner)
120 try
121 {
122 clear();
123 }
124 catch (...)
125 {}
126 }
127
128
129
130 void
131 PreconditionAMG::clear()
132 {
133 int err = amg_c_dprecfree(psblas_preconditioner);
134 Assert(err == 0, ExcCallingPSBLASFunction(err, "amg_c_dprecfree"));
135 psblas_preconditioner = nullptr;
136 }
137
138
139
140 amg_c_dprec *
141 PreconditionAMG::get_psblas_preconditioner()
142 {
143 return psblas_preconditioner;
144 }
145
146
147
148 void
149 PreconditionAMG::vmult(Vector &dst, const Vector &src) const
150 {
151 AssertDimension(dst.size(), src.size());
152 int err = amg_c_dprecapply(psblas_preconditioner,
153 src.psblas_vector,
154 dst.psblas_vector,
155 psblas_descriptor.get());
156 Assert(err == 0,
157 ExcMessage("Failure while applying preconditioner on a vector."));
158 }
159
160
161
162 void
163 PreconditionAMG::Tvmult(Vector &dst, const Vector &src) const
164 {
165 AssertDimension(dst.size(), src.size());
167 }
168
169
170
171} // namespace PSCToolkitWrappers
172
174
175#endif
virtual size_type size() const override
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
#define DEAL_II_NOT_IMPLEMENTED()
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
@ matrix
Contents is actually a matrix.