deal.II version GIT relicensing-6960-g70e9c5b7be 2026-10-22 20:10: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: Apache-2.0 WITH LLVM-exception OR 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// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13
14
16
17#ifdef DEAL_II_WITH_AMG4PSBLAS
18
20
21namespace PSCToolkitWrappers
22{
23
24 PreconditionAMG::PreconditionAMG()
25 {
26 psblas_preconditioner = amg_c_dprec_new();
27 }
28
29
30 void
31 PreconditionAMG::initialize(const SparseMatrix &matrix,
32 const AdditionalData &additional_data)
33 {
34 Assert(matrix.psblas_sparse_matrix != nullptr,
35 ExcMessage("Matrix has not been initialized."));
36
37 // set descriptor from matrix and allocate workspace with proper size
38 psblas_descriptor = matrix.psblas_descriptor;
39
40 int err = amg_c_dprecinit(*InitFinalize::get_psblas_context(),
41 psblas_preconditioner,
42 "ML");
43 AssertThrow(err == 0,
44 ExcMessage("Error " + std::to_string(err) +
45 " while initializing AMG preconditioner."));
46
47 amg_c_dprecsetc(psblas_preconditioner,
48 "ML_CYCLE",
49 additional_data.cycle_type);
50 amg_c_dprecseti(psblas_preconditioner,
51 "CYCLE_SWEEPS",
52 additional_data.n_cycles);
53 amg_c_dprecsetr(psblas_preconditioner,
54 "AGGR_THRSH",
55 additional_data.aggregation_threshold);
56 amg_c_dprecsetc(psblas_preconditioner,
57 "PAR_AGGR_ALG",
58 additional_data.parallel_aggr_algorithm);
59 amg_c_dprecsetc(psblas_preconditioner,
60 "AGGR_TYPE",
61 additional_data.aggregation_type);
62 amg_c_dprecseti(psblas_preconditioner,
63 "AGGR_SIZE",
64 additional_data.aggregation_size);
65 amg_c_dprecsetc(psblas_preconditioner,
66 "AGGR_PROL",
67 additional_data.aggr_prol);
68 amg_c_dprecsetc(psblas_preconditioner,
69 "AGGR_FILTER",
70 additional_data.aggr_filter);
71 amg_c_dprecsetc(psblas_preconditioner,
72 "SMOOTHER_TYPE",
73 additional_data.smoother_type);
74
75 // From the AMG4PSBLAS manual: if "SMOOTHER_TYPE" is set to
76 // "POLY", then "SMOOTHER_SWEEPS" is ignored and the number of smoother
77 // sweeps equals the polynomial degree is used instead.
78 if (std::strcmp(additional_data.smoother_type, "POLY") == 0)
79 amg_c_dprecseti(psblas_preconditioner,
80 "POLY_DEGREE",
81 additional_data.smoother_sweeps);
82 else
83 amg_c_dprecseti(psblas_preconditioner,
84 "SMOOTHER_SWEEPS",
85 additional_data.smoother_sweeps);
86 amg_c_dprecsetc(psblas_preconditioner,
87 "COARSE_SOLVE",
88 additional_data.coarse_type);
89
90 // build AMG hierarchy
91 err = amg_c_dhierarchy_build(matrix.psblas_sparse_matrix,
92 psblas_descriptor.get(),
93 psblas_preconditioner);
94 AssertThrow(err == 0,
95 ExcMessage("Error " + std::to_string(err) +
96 " while building AMG hierarchy."));
97 //... and smoothers
98 err = amg_c_dsmoothers_build(matrix.psblas_sparse_matrix,
99 psblas_descriptor.get(),
100 psblas_preconditioner);
101 AssertThrow(err == 0,
102 ExcMessage("Error " + std::to_string(err) +
103 " while building AMG smoothers."));
104
105 if (additional_data.output_details == true)
106 {
107 err = amg_c_ddescr(psblas_preconditioner);
108 AssertThrow(err == 0,
109 ExcMessage("Error " + std::to_string(err) +
110 " while printing AMG description."));
111 }
112 }
113
114
115 PreconditionAMG::~PreconditionAMG()
116 {
117 if (psblas_preconditioner)
118 try
119 {
120 clear();
121 }
122 catch (...)
123 {}
124 }
125
126
127
128 void
129 PreconditionAMG::clear()
130 {
131 int err = amg_c_dprecfree(psblas_preconditioner);
132 Assert(err == 0, ExcCallingPSBLASFunction(err, "amg_c_dprecfree"));
133 psblas_preconditioner = nullptr;
134 }
135
136
137
138 amg_c_dprec *
139 PreconditionAMG::get_psblas_preconditioner()
140 {
141 return psblas_preconditioner;
142 }
143
144
145
146 void
147 PreconditionAMG::vmult(Vector &dst, const Vector &src) const
148 {
149 AssertDimension(dst.size(), src.size());
150 int err = amg_c_dprecapply(psblas_preconditioner,
151 src.psblas_vector,
152 dst.psblas_vector,
153 psblas_descriptor.get());
154 Assert(err == 0,
155 ExcMessage("Failure while applying preconditioner on a vector."));
156 }
157
158
159
160 void
161 PreconditionAMG::Tvmult(Vector &dst, const Vector &src) const
162 {
163 AssertDimension(dst.size(), src.size());
165 }
166
167
168
169} // namespace PSCToolkitWrappers
170
172
173#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.