deal.II version GIT relicensing-6809-ge913b9bb34 2026-09-25 17: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_parallel_block_vector.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) 2012 - 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_trilinos_parallel_block_vector_h
14#define dealii_trilinos_parallel_block_vector_h
15
16
17#include <deal.II/base/config.h>
18
19#ifndef DEAL_II_TRILINOS_WITH_EPETRA
22
23#endif
24
25#ifdef DEAL_II_TRILINOS_WITH_EPETRA
30
31# include <functional>
32
33#endif
34
36
37#ifdef DEAL_II_TRILINOS_WITH_EPETRA
38// forward declaration
39# ifndef DOXYGEN
40template <typename Number>
41class BlockVectorBase;
42# endif
43
49namespace TrilinosWrappers
50{
51 namespace MPI
52 {
70 class BlockVector : public ::BlockVectorBase<MPI::Vector>
71 {
72 public:
77
82
94
98 BlockVector() = default;
99
106 explicit BlockVector(const std::vector<IndexSet> &parallel_partitioning,
107 const MPI_Comm communicator = MPI_COMM_WORLD);
108
114 BlockVector(const std::vector<IndexSet> &parallel_partitioning,
115 const std::vector<IndexSet> &ghost_values,
116 const MPI_Comm communicator,
117 const bool vector_writable = false);
118
123 BlockVector(const BlockVector &v);
124
129 BlockVector(BlockVector &&v) noexcept;
130
136 explicit BlockVector(const size_type num_blocks);
137
141 ~BlockVector() override = default;
142
148 operator=(const value_type s);
149
161 operator=(const BlockVector &v);
162
168 operator=(BlockVector &&v) noexcept;
169
180 template <typename Number>
182 operator=(const ::BlockVector<Number> &v);
183
192 void
193 reinit(const std::vector<IndexSet> &parallel_partitioning,
194 const MPI_Comm communicator = MPI_COMM_WORLD,
195 const bool omit_zeroing_entries = false);
196
214 void
215 reinit(const std::vector<IndexSet> &partitioning,
216 const std::vector<IndexSet> &ghost_values,
217 const MPI_Comm communicator = MPI_COMM_WORLD,
218 const bool vector_writable = false);
219
230 void
231 reinit(
232 const std::vector<std::shared_ptr<const Utilities::MPI::Partitioner>>
233 &partitioners,
234 const bool make_ghosted = true,
235 const bool vector_writable = false);
236
251 void
252 reinit(const BlockVector &V, const bool omit_zeroing_entries = false);
253
260 void
261 reinit(const size_type num_blocks);
262
280 void
282 const BlockVector &v);
283
290 bool
291 has_ghost_elements() const;
292
310 void
311 swap(BlockVector &v) noexcept;
312
316 void
317 print(std::ostream &out,
318 const unsigned int precision = 3,
319 const bool scientific = true,
320 const bool across = true) const;
321
326
331 };
332
333
334
335 /*-------------------------- Inline functions ---------------------------*/
337 const std::vector<IndexSet> &parallel_partitioning,
338 const MPI_Comm communicator)
339 {
340 reinit(parallel_partitioning, communicator, false);
341 }
342
343
344
346 const std::vector<IndexSet> &parallel_partitioning,
347 const std::vector<IndexSet> &ghost_values,
348 const MPI_Comm communicator,
349 const bool vector_writable)
350 {
351 reinit(parallel_partitioning,
352 ghost_values,
353 communicator,
354 vector_writable);
355 }
356
357
358
359 inline BlockVector::BlockVector(const size_type num_blocks)
360 {
361 reinit(num_blocks);
362 }
363
364
365
368 {
370
371 this->components.resize(this->n_blocks());
372 for (unsigned int i = 0; i < this->n_blocks(); ++i)
373 this->components[i] = v.components[i];
374
375 this->collect_sizes();
376 }
377
378
379
381 {
382 // initialize a minimal, valid object and swap
383 reinit(0);
384 swap(v);
385 }
386
387
388
389 template <typename Number>
391 BlockVector::operator=(const ::BlockVector<Number> &v)
392 {
393 // we only allow assignment to vectors with the same number of blocks
394 // or to an empty BlockVector
395 Assert(this->n_blocks() == 0 || this->n_blocks() == v.n_blocks(),
396 ExcDimensionMismatch(this->n_blocks(), v.n_blocks()));
397
398 if (this->n_blocks() != v.n_blocks())
399 this->block_indices = v.get_block_indices();
400
401 this->components.resize(this->n_blocks());
402 for (unsigned int i = 0; i < this->n_blocks(); ++i)
403 this->components[i] = v.block(i);
404
405 this->collect_sizes();
406
407 return *this;
408 }
409
410
411
412 inline bool
414 {
415 bool ghosted = block(0).has_ghost_elements();
416 if constexpr (running_in_debug_mode())
417 {
418 for (unsigned int i = 0; i < this->n_blocks(); ++i)
419 Assert(block(i).has_ghost_elements() == ghosted,
421 }
422 return ghosted;
423 }
424
425
426
427 inline void
429 {
430 std::swap(this->components, v.components);
431
432 ::swap(this->block_indices, v.block_indices);
433 }
434
435
436
444 inline void
445 swap(BlockVector &u, BlockVector &v) noexcept
446 {
447 u.swap(v);
448 }
449
450 } /* namespace MPI */
451
452} /* namespace TrilinosWrappers */
453
457namespace internal
458{
459 namespace LinearOperatorImplementation
460 {
461 template <typename>
462 class ReinitHelper;
463
468 template <>
469 class ReinitHelper<TrilinosWrappers::MPI::BlockVector>
470 {
471 public:
472 template <typename Matrix>
473 static void
474 reinit_range_vector(const Matrix &matrix,
476 bool omit_zeroing_entries)
477 {
478 v.reinit(matrix.locally_owned_range_indices(),
479 matrix.get_mpi_communicator(),
480 omit_zeroing_entries);
481 }
482
483 template <typename Matrix>
484 static void
485 reinit_domain_vector(const Matrix &matrix,
487 bool omit_zeroing_entries)
488 {
489 v.reinit(matrix.locally_owned_domain_indices(),
490 matrix.get_mpi_communicator(),
491 omit_zeroing_entries);
492 }
493 };
494
495 } // namespace LinearOperatorImplementation
496} /* namespace internal */
497
498
502template <>
503struct is_serial_vector<TrilinosWrappers::MPI::BlockVector> : std::false_type
504{};
505
506#endif
507
509
510#endif
::internal::BlockVectorIterators::Iterator< BlockVectorBase, false > iterator
unsigned int n_blocks() const
typename BlockType::const_reference const_reference
types::global_dof_index size_type
typename BlockType::value_type value_type
std::vector< MPI::Vector > components
::internal::BlockVectorIterators::Iterator< BlockVectorBase, true > const_iterator
typename BlockType::reference reference
BlockType & block(const unsigned int i)
void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true, const bool across=true) const
void swap(BlockVector &u, BlockVector &v) noexcept
BlockVector & operator=(const value_type s)
void reinit(const std::vector< IndexSet > &parallel_partitioning, const MPI_Comm communicator=MPI_COMM_WORLD, const bool omit_zeroing_entries=false)
void import_nonlocal_data_for_fe(const TrilinosWrappers::BlockSparseMatrix &m, const BlockVector &v)
static void reinit_range_vector(const Matrix &matrix, TrilinosWrappers::MPI::BlockVector &v, bool omit_zeroing_entries)
static void reinit_domain_vector(const Matrix &matrix, TrilinosWrappers::MPI::BlockVector &v, bool omit_zeroing_entries)
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
constexpr bool running_in_debug_mode()
Definition config.h:76
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
#define DeclException0(Exception0)
#define Assert(cond, exc)
static ::ExceptionBase & ExcNonMatchingBlockVectors()
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
static ::ExceptionBase & ExcIteratorRangeDoesNotMatchVectorSize()
void swap(BlockVector &u, BlockVector &v) noexcept