deal.II version GIT relicensing-6834-g5b78e6bcdf 2026-10-01 11:20: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
trilinos_tpetra_block_sparse_matrix.h
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) 2024 - 2026 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#ifndef dealii_tpetra_trilinos_block_sparse_matrix_h
14#define dealii_tpetra_trilinos_block_sparse_matrix_h
15
16
17#include <deal.II/base/config.h>
18
19#ifdef DEAL_II_TRILINOS_WITH_TPETRA
20
22
29
30# include <cmath>
31
32#endif // DEAL_II_TRILINOS_WITH_TPETRA
33
35
36#ifdef DEAL_II_TRILINOS_WITH_TPETRA
37// forward declarations
38# ifndef DOXYGEN
40template <typename number>
42# endif
43
44namespace LinearAlgebra
45{
50 namespace TpetraWrappers
51 {
75 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
77 : public BlockMatrixBase<SparseMatrix<Number, MemorySpace>>
78 {
79 public:
84
89
94 using pointer = typename BaseClass::pointer;
99 using iterator = typename BaseClass::iterator;
101
113 BlockSparseMatrix() = default;
114
119
126
137 operator=(const Number d);
138
152 void
153 reinit(const size_type n_block_rows, const size_type n_block_columns);
154
160 template <typename BlockSparsityPatternType>
161 void
162 reinit(const std::vector<IndexSet> &input_maps,
163 const BlockSparsityPatternType &block_sparsity_pattern,
164 const MPI_Comm communicator = MPI_COMM_WORLD,
165 const bool exchange_data = false);
166
172 template <typename BlockSparsityPatternType>
173 void
174 reinit(const BlockSparsityPatternType &block_sparsity_pattern);
175
182 void
184 const std::vector<IndexSet> &parallel_partitioning,
185 const ::BlockSparseMatrix<double> &dealii_block_sparse_matrix,
186 const MPI_Comm communicator = MPI_COMM_WORLD,
187 const double drop_tolerance = 1e-13);
188
196 void
197 reinit(const ::BlockSparseMatrix<double> &deal_ii_sparse_matrix,
198 const double drop_tolerance = 1e-13);
199
207 bool
209
221 void
223
228 std::uint64_t
230
236
242 std::vector<IndexSet>
244
250 std::vector<IndexSet>
252
259 template <typename VectorType1, typename VectorType2>
260 void
261 vmult(VectorType1 &dst, const VectorType2 &src) const;
262
268 template <typename VectorType1, typename VectorType2>
269 void
270 Tvmult(VectorType1 &dst, const VectorType2 &src) const;
271
284 template <typename VectorType1,
285 typename VectorType2,
286 typename VectorType3>
287 Number
288 residual(VectorType1 &dst,
289 const VectorType2 &x,
290 const VectorType3 &b) const;
291
297
298 private:
302 template <typename VectorType1, typename VectorType2>
303 void
304 vmult(VectorType1 &dst,
305 const VectorType2 &src,
306 const bool transpose,
307 const std::bool_constant<true>,
308 const std::bool_constant<true>) const;
309
314 template <typename VectorType1, typename VectorType2>
315 void
316 vmult(VectorType1 &dst,
317 const VectorType2 &src,
318 const bool transpose,
319 const std::bool_constant<false>,
320 const std::bool_constant<true>) const;
321
326 template <typename VectorType1, typename VectorType2>
327 void
328 vmult(VectorType1 &dst,
329 const VectorType2 &src,
330 const bool transpose,
331 const std::bool_constant<true>,
332 const std::bool_constant<false>) const;
333
339 template <typename VectorType1, typename VectorType2>
340 void
341 vmult(VectorType1 &dst,
342 const VectorType2 &src,
343 const bool transpose,
344 const std::bool_constant<false>,
345 const std::bool_constant<false>) const;
346 };
347
348 } // namespace TpetraWrappers
349
352 // ------------- inline and template functions -----------------
353 namespace TpetraWrappers
354 {
355 template <typename Number, typename MemorySpace>
356 template <typename VectorType1, typename VectorType2>
357 inline void
359 const VectorType2 &src) const
360 {
361 vmult(dst,
362 src,
363 false,
364 std::bool_constant<IsBlockVector<VectorType1>::value>(),
365 std::bool_constant<IsBlockVector<VectorType2>::value>());
366 }
367
368
369
370 template <typename Number, typename MemorySpace>
371 template <typename VectorType1, typename VectorType2>
372 inline void
374 const VectorType2 &src) const
375 {
376 vmult(dst,
377 src,
378 true,
379 std::bool_constant<IsBlockVector<VectorType1>::value>(),
380 std::bool_constant<IsBlockVector<VectorType2>::value>());
381 }
382
383
384
385 template <typename Number, typename MemorySpace>
386 template <typename VectorType1, typename VectorType2>
387 inline void
389 VectorType1 &dst,
390 const VectorType2 &src,
391 const bool transpose,
392 std::bool_constant<true>,
393 std::bool_constant<true>) const
394 {
395 if (transpose == true)
396 BaseClass::Tvmult_block_block(dst, src);
397 else
398 BaseClass::vmult_block_block(dst, src);
399 }
400
401
402
403 template <typename Number, typename MemorySpace>
404 template <typename VectorType1, typename VectorType2>
405 inline void
407 VectorType1 &dst,
408 const VectorType2 &src,
409 const bool transpose,
410 std::bool_constant<false>,
411 std::bool_constant<true>) const
412 {
413 if (transpose == true)
414 BaseClass::Tvmult_nonblock_block(dst, src);
415 else
416 BaseClass::vmult_nonblock_block(dst, src);
417 }
418
419
420
421 template <typename Number, typename MemorySpace>
422 template <typename VectorType1, typename VectorType2>
423 inline void
425 VectorType1 &dst,
426 const VectorType2 &src,
427 const bool transpose,
428 std::bool_constant<true>,
429 std::bool_constant<false>) const
430 {
431 if (transpose == true)
432 BaseClass::Tvmult_block_nonblock(dst, src);
433 else
434 BaseClass::vmult_block_nonblock(dst, src);
435 }
436
437
438
439 template <typename Number, typename MemorySpace>
440 template <typename VectorType1, typename VectorType2>
441 inline void
443 VectorType1 &dst,
444 const VectorType2 &src,
445 const bool transpose,
446 std::bool_constant<false>,
447 std::bool_constant<false>) const
448 {
449 if (transpose == true)
450 BaseClass::Tvmult_nonblock_nonblock(dst, src);
451 else
452 BaseClass::vmult_nonblock_nonblock(dst, src);
453 }
454 } // namespace TpetraWrappers
455
456} // namespace LinearAlgebra
457
458#endif // DEAL_II_TRILINOS_WITH_TPETRA
459
461
462#endif // dealii_tpetra_trilinos_block_sparse_matrix_h
value_type & reference
const value_type & const_reference
unsigned int n_block_rows() const
MatrixIterator< BlockMatrixIterators::Accessor< BlockMatrixBase, true > > const_iterator
types::global_dof_index size_type
typename BlockType::value_type value_type
const value_type * const_pointer
MatrixIterator< BlockMatrixIterators::Accessor< BlockMatrixBase, false > > iterator
void reinit(const std::vector< IndexSet > &parallel_partitioning, const ::BlockSparseMatrix< double > &dealii_block_sparse_matrix, const MPI_Comm communicator=MPI_COMM_WORLD, const double drop_tolerance=1e-13)
void Tvmult(VectorType1 &dst, const VectorType2 &src) const
BlockSparseMatrix< Number, MemorySpace > & operator=(const BlockSparseMatrix< Number, MemorySpace > &)=default
void vmult(VectorType1 &dst, const VectorType2 &src) const
std::vector< IndexSet > locally_owned_domain_indices() const
std::vector< IndexSet > locally_owned_range_indices() const
void reinit(const ::BlockSparseMatrix< double > &deal_ii_sparse_matrix, const double drop_tolerance=1e-13)
Number residual(VectorType1 &dst, const VectorType2 &x, const VectorType3 &b) const
void reinit(const BlockSparsityPatternType &block_sparsity_pattern)
BlockSparseMatrix< Number, MemorySpace > & operator=(const Number d)
void reinit(const size_type n_block_rows, const size_type n_block_columns)
void reinit(const std::vector< IndexSet > &input_maps, const BlockSparsityPatternType &block_sparsity_pattern, const MPI_Comm communicator=MPI_COMM_WORLD, const bool exchange_data=false)
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
DerivativeForm< 1, spacedim, dim, Number > transpose(const DerivativeForm< 1, dim, spacedim, Number > &DF)