| 1 |
// ------------------------------------------------------------------------ |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
// Copyright (C) 2017 - 2024 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 |
#ifndef dealii_trilinos_linear_operator_h |
| 16 |
#define dealii_trilinos_linear_operator_h |
| 17 |
|
| 18 |
#include <deal.II/base/config.h> |
| 19 |
|
| 20 |
#ifdef DEAL_II_WITH_TRILINOS |
| 21 |
|
| 22 |
# include <deal.II/lac/block_linear_operator.h> |
| 23 |
# include <deal.II/lac/linear_operator.h> |
| 24 |
|
| 25 |
DEAL_II_NAMESPACE_OPEN |
| 26 |
|
| 27 |
namespace TrilinosWrappers |
| 28 |
{ |
| 29 |
// Forward declarations: |
| 30 |
# ifndef DOXYGEN |
| 31 |
class SparseMatrix; |
| 32 |
class PreconditionBase; |
| 33 |
class BlockSparseMatrix; |
| 34 |
|
| 35 |
namespace internal |
| 36 |
{ |
| 37 |
namespace LinearOperatorImplementation |
| 38 |
{ |
| 39 |
class TrilinosPayload; |
| 40 |
} |
| 41 |
|
| 42 |
namespace BlockLinearOperatorImplementation |
| 43 |
{ |
| 44 |
template <typename PayloadBlockType> |
| 45 |
class TrilinosBlockPayload; |
| 46 |
} |
| 47 |
} // namespace internal |
| 48 |
# endif |
| 49 |
|
| 50 |
/** |
| 51 |
* @name Creation of a LinearOperator |
| 52 |
*/ |
| 53 |
/** @{ */ |
| 54 |
|
| 55 |
|
| 56 |
/** |
| 57 |
* @relatesalso LinearOperator |
| 58 |
* |
| 59 |
* A function that encapsulates generic @p matrix objects, based on an |
| 60 |
* @p operator_exemplar, that act on a compatible Vector type into a |
| 61 |
* LinearOperator. |
| 62 |
* |
| 63 |
* This function is the equivalent of the dealii::linear_operator, but |
| 64 |
* ensures full compatibility with Trilinos operations by preselecting the |
| 65 |
* appropriate template parameters. |
| 66 |
* |
| 67 |
* |
| 68 |
* @ingroup TrilinosWrappers |
| 69 |
*/ |
| 70 |
template <typename Range, typename Domain = Range, typename Matrix> |
| 71 |
inline LinearOperator< |
| 72 |
Range, |
| 73 |
Domain, |
| 74 |
TrilinosWrappers::internal::LinearOperatorImplementation::TrilinosPayload> |
| 75 |
linear_operator(const TrilinosWrappers::SparseMatrix &operator_exemplar, |
| 76 |
const Matrix &matrix) |
| 77 |
{ |
| 78 |
using OperatorExemplar = TrilinosWrappers::SparseMatrix; |
| 79 |
using Payload = |
| 80 |
TrilinosWrappers::internal::LinearOperatorImplementation::TrilinosPayload; |
| 81 |
return dealii:: |
| 82 |
linear_operator<Range, Domain, Payload, OperatorExemplar, Matrix>( |
| 83 |
operator_exemplar, matrix); |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
/** |
| 88 |
* @relatesalso LinearOperator |
| 89 |
* |
| 90 |
* A function that encapsulates generic @p matrix objects that act on a |
| 91 |
* compatible Vector type into a LinearOperator. |
| 92 |
* |
| 93 |
* This function is the equivalent of the dealii::linear_operator, but |
| 94 |
* ensures full compatibility with Trilinos operations by preselecting the |
| 95 |
* appropriate template parameters. |
| 96 |
* |
| 97 |
* |
| 98 |
* @ingroup TrilinosWrappers |
| 99 |
*/ |
| 100 |
template <typename Range, typename Domain = Range> |
| 101 |
inline LinearOperator< |
| 102 |
Range, |
| 103 |
Domain, |
| 104 |
TrilinosWrappers::internal::LinearOperatorImplementation::TrilinosPayload> |
| 105 |
linear_operator(const TrilinosWrappers::SparseMatrix &matrix) |
| 106 |
{ |
| 107 |
using Matrix = TrilinosWrappers::SparseMatrix; |
| 108 |
using Payload = |
| 109 |
TrilinosWrappers::internal::LinearOperatorImplementation::TrilinosPayload; |
| 110 |
return dealii::linear_operator<Range, Domain, Payload, Matrix, Matrix>( |
| 111 |
matrix, matrix); |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
/** |
| 116 |
* @relatesalso LinearOperator |
| 117 |
* |
| 118 |
* A function that encapsulates generic @p matrix objects, based on an |
| 119 |
* @p operator_exemplar, that act on a compatible Vector type into a |
| 120 |
* LinearOperator. |
| 121 |
* |
| 122 |
* This function is the equivalent of the dealii::linear_operator, but |
| 123 |
* ensures full compatibility with Trilinos operations by preselecting the |
| 124 |
* appropriate template parameters. |
| 125 |
* |
| 126 |
* |
| 127 |
* @ingroup TrilinosWrappers |
| 128 |
*/ |
| 129 |
template <typename Range, typename Domain, typename Matrix> |
| 130 |
inline LinearOperator< |
| 131 |
Range, |
| 132 |
Domain, |
| 133 |
TrilinosWrappers::internal::LinearOperatorImplementation::TrilinosPayload> |
| 134 |
linear_operator( |
| 135 |
const LinearOperator< |
| 136 |
Range, |
| 137 |
Domain, |
| 138 |
TrilinosWrappers::internal::LinearOperatorImplementation::TrilinosPayload> |
| 139 |
&operator_exemplar, |
| 140 |
const Matrix &matrix) |
| 141 |
{ |
| 142 |
using Payload = |
| 143 |
TrilinosWrappers::internal::LinearOperatorImplementation::TrilinosPayload; |
| 144 |
using OperatorExemplar = LinearOperator<Range, Domain, Payload>; |
| 145 |
return dealii:: |
| 146 |
linear_operator<Range, Domain, Payload, OperatorExemplar, Matrix>( |
| 147 |
operator_exemplar, matrix); |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
/** @} */ |
| 152 |
/** |
| 153 |
* @name Creation of a BlockLinearOperator |
| 154 |
*/ |
| 155 |
/** @{ */ |
| 156 |
|
| 157 |
|
| 158 |
/** |
| 159 |
* @relatesalso BlockLinearOperator |
| 160 |
* |
| 161 |
* A function that encapsulates a @p block_matrix into a BlockLinearOperator. |
| 162 |
* |
| 163 |
* This function is the equivalent of the dealii::block_operator, but |
| 164 |
* ensures full compatibility with Trilinos operations by preselecting the |
| 165 |
* appropriate template parameters. |
| 166 |
* |
| 167 |
* |
| 168 |
* @ingroup TrilinosWrappers |
| 169 |
*/ |
| 170 |
template <typename Range, typename Domain = Range> |
| 171 |
inline BlockLinearOperator< |
| 172 |
Range, |
| 173 |
Domain, |
| 174 |
TrilinosWrappers::internal::BlockLinearOperatorImplementation:: |
| 175 |
TrilinosBlockPayload<TrilinosWrappers::internal:: |
| 176 |
LinearOperatorImplementation::TrilinosPayload>> |
| 177 |
block_operator(const TrilinosWrappers::BlockSparseMatrix &block_matrix) |
| 178 |
{ |
| 179 |
using BlockMatrix = TrilinosWrappers::BlockSparseMatrix; |
| 180 |
using PayloadBlockType = |
| 181 |
TrilinosWrappers::internal::LinearOperatorImplementation::TrilinosPayload; |
| 182 |
using BlockPayload = TrilinosWrappers::internal:: |
| 183 |
BlockLinearOperatorImplementation::TrilinosBlockPayload<PayloadBlockType>; |
| 184 |
return dealii::block_operator<Range, Domain, BlockPayload, BlockMatrix>( |
| 185 |
block_matrix); |
| 186 |
} |
| 187 |
|
| 188 |
|
| 189 |
/** |
| 190 |
* @relatesalso BlockLinearOperator |
| 191 |
* |
| 192 |
* A variant of above function that builds up a block diagonal linear operator |
| 193 |
* from an array @p ops of diagonal elements (off-diagonal blocks are assumed |
| 194 |
* to be 0). |
| 195 |
* |
| 196 |
* This function is the equivalent of the dealii::block_operator, but |
| 197 |
* ensures full compatibility with Trilinos operations by preselecting the |
| 198 |
* appropriate template parameters. |
| 199 |
* |
| 200 |
* |
| 201 |
* @ingroup TrilinosWrappers |
| 202 |
*/ |
| 203 |
template <std::size_t m, |
| 204 |
std::size_t n, |
| 205 |
typename Range, |
| 206 |
typename Domain = Range> |
| 207 |
inline BlockLinearOperator< |
| 208 |
Range, |
| 209 |
Domain, |
| 210 |
TrilinosWrappers::internal::BlockLinearOperatorImplementation:: |
| 211 |
TrilinosBlockPayload<TrilinosWrappers::internal:: |
| 212 |
LinearOperatorImplementation::TrilinosPayload>> |
| 213 |
block_operator( |
| 214 |
const std::array< |
| 215 |
std::array< |
| 216 |
LinearOperator<typename Range::BlockType, |
| 217 |
typename Domain::BlockType, |
| 218 |
TrilinosWrappers::internal:: |
| 219 |
LinearOperatorImplementation::TrilinosPayload>, |
| 220 |
n>, |
| 221 |
m> &ops) |
| 222 |
{ |
| 223 |
using PayloadBlockType = |
| 224 |
TrilinosWrappers::internal::LinearOperatorImplementation::TrilinosPayload; |
| 225 |
using BlockPayload = TrilinosWrappers::internal:: |
| 226 |
BlockLinearOperatorImplementation::TrilinosBlockPayload<PayloadBlockType>; |
| 227 |
return dealii::block_operator<m, n, Range, Domain, BlockPayload>(ops); |
| 228 |
} |
| 229 |
|
| 230 |
|
| 231 |
/** |
| 232 |
* @relatesalso BlockLinearOperator |
| 233 |
* |
| 234 |
* This function extracts the diagonal blocks of @p block_matrix (either a |
| 235 |
* block matrix type or a BlockLinearOperator) and creates a |
| 236 |
* BlockLinearOperator with the diagonal. Off-diagonal elements are |
| 237 |
* initialized as null_operator (with correct reinit_range_vector and |
| 238 |
* reinit_domain_vector methods). |
| 239 |
* |
| 240 |
* This function is the equivalent of the dealii::block_diagonal_operator, but |
| 241 |
* ensures full compatibility with Trilinos operations by preselecting the |
| 242 |
* appropriate template parameters. |
| 243 |
* |
| 244 |
* |
| 245 |
* @ingroup TrilinosWrappers |
| 246 |
*/ |
| 247 |
template <typename Range, typename Domain = Range> |
| 248 |
inline BlockLinearOperator< |
| 249 |
Range, |
| 250 |
Domain, |
| 251 |
TrilinosWrappers::internal::BlockLinearOperatorImplementation:: |
| 252 |
TrilinosBlockPayload<TrilinosWrappers::internal:: |
| 253 |
LinearOperatorImplementation::TrilinosPayload>> |
| 254 |
block_diagonal_operator( |
| 255 |
const TrilinosWrappers::BlockSparseMatrix &block_matrix) |
| 256 |
{ |
| 257 |
using BlockMatrix = TrilinosWrappers::BlockSparseMatrix; |
| 258 |
using PayloadBlockType = |
| 259 |
TrilinosWrappers::internal::LinearOperatorImplementation::TrilinosPayload; |
| 260 |
using BlockPayload = TrilinosWrappers::internal:: |
| 261 |
BlockLinearOperatorImplementation::TrilinosBlockPayload<PayloadBlockType>; |
| 262 |
return dealii:: |
| 263 |
block_diagonal_operator<Range, Domain, BlockPayload, BlockMatrix>( |
| 264 |
block_matrix); |
| 265 |
} |
| 266 |
|
| 267 |
|
| 268 |
/** |
| 269 |
* @relatesalso BlockLinearOperator |
| 270 |
* |
| 271 |
* A variant of above function that builds up a block diagonal linear operator |
| 272 |
* from an array @p ops of diagonal elements (off-diagonal blocks are assumed |
| 273 |
* to be 0). |
| 274 |
* |
| 275 |
* This function is the equivalent of the dealii::block_diagonal_operator, but |
| 276 |
* ensures full compatibility with Trilinos operations by preselecting the |
| 277 |
* appropriate template parameters. |
| 278 |
* |
| 279 |
* |
| 280 |
* @ingroup TrilinosWrappers |
| 281 |
*/ |
| 282 |
template <std::size_t m, typename Range, typename Domain = Range> |
| 283 |
inline BlockLinearOperator< |
| 284 |
Range, |
| 285 |
Domain, |
| 286 |
TrilinosWrappers::internal::BlockLinearOperatorImplementation:: |
| 287 |
TrilinosBlockPayload<TrilinosWrappers::internal:: |
| 288 |
LinearOperatorImplementation::TrilinosPayload>> |
| 289 |
block_diagonal_operator( |
| 290 |
const std::array< |
| 291 |
LinearOperator<typename Range::BlockType, |
| 292 |
typename Domain::BlockType, |
| 293 |
TrilinosWrappers::internal::LinearOperatorImplementation:: |
| 294 |
TrilinosPayload>, |
| 295 |
m> &ops) |
| 296 |
{ |
| 297 |
using PayloadBlockType = |
| 298 |
TrilinosWrappers::internal::LinearOperatorImplementation::TrilinosPayload; |
| 299 |
using BlockPayload = TrilinosWrappers::internal:: |
| 300 |
BlockLinearOperatorImplementation::TrilinosBlockPayload<PayloadBlockType>; |
| 301 |
return dealii::block_diagonal_operator<m, Range, Domain, BlockPayload>(ops); |
| 302 |
} |
| 303 |
|
| 304 |
/** @} */ |
| 305 |
|
| 306 |
} // namespace TrilinosWrappers |
| 307 |
|
| 308 |
DEAL_II_NAMESPACE_CLOSE |
| 309 |
|
| 310 |
#else |
| 311 |
|
| 312 |
// Make sure the scripts that create the C++20 module input files have |
| 313 |
// something to latch on if the preprocessor #ifdef above would |
| 314 |
// otherwise lead to an empty content of the file. |
| 315 |
DEAL_II_NAMESPACE_OPEN |
| 316 |
DEAL_II_NAMESPACE_CLOSE |
| 317 |
|
| 318 |
#endif // DEAL_II_WITH_TRILINOS |
| 319 |
#endif |