Reference documentation for deal.II version GIT relicensing-12-g89ba5bf9db 2024-02-24 00:00:03+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: LGPL-2.1-or-later
4// Copyright (C) 2012 - 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#ifndef dealii_trilinos_parallel_block_vector_h
16#define dealii_trilinos_parallel_block_vector_h
17
18
19#include <deal.II/base/config.h>
20
21#ifdef DEAL_II_WITH_TRILINOS
22
27
28# include <functional>
29
31
32// forward declaration
33# ifndef DOXYGEN
34template <typename Number>
35class BlockVectorBase;
36
37namespace TrilinosWrappers
38{
39 // forward declaration
40 namespace MPI
41 {
42 class BlockVector;
43 }
45} // namespace TrilinosWrappers
46# endif
47
53namespace TrilinosWrappers
54{
55 namespace MPI
56 {
74 class BlockVector : public ::BlockVectorBase<MPI::Vector>
75 {
76 public:
81
86
98
102 BlockVector() = default;
103
110 explicit BlockVector(const std::vector<IndexSet> &parallel_partitioning,
111 const MPI_Comm communicator = MPI_COMM_WORLD);
112
118 BlockVector(const std::vector<IndexSet> &parallel_partitioning,
119 const std::vector<IndexSet> &ghost_values,
120 const MPI_Comm communicator,
121 const bool vector_writable = false);
122
127 BlockVector(const BlockVector &v);
128
133 BlockVector(BlockVector &&v) noexcept;
134
140 explicit BlockVector(const size_type num_blocks);
141
145 ~BlockVector() override = default;
146
152 operator=(const value_type s);
153
158 operator=(const BlockVector &v);
159
165 operator=(BlockVector &&v) noexcept;
166
177 template <typename Number>
179 operator=(const ::BlockVector<Number> &v);
180
189 void
190 reinit(const std::vector<IndexSet> &parallel_partitioning,
191 const MPI_Comm communicator = MPI_COMM_WORLD,
192 const bool omit_zeroing_entries = false);
193
211 void
212 reinit(const std::vector<IndexSet> &partitioning,
213 const std::vector<IndexSet> &ghost_values,
214 const MPI_Comm communicator = MPI_COMM_WORLD,
215 const bool vector_writable = false);
216
227 void
228 reinit(
229 const std::vector<std::shared_ptr<const Utilities::MPI::Partitioner>>
230 &partitioners,
231 const bool make_ghosted = true,
232 const bool vector_writable = false);
233
248 void
249 reinit(const BlockVector &V, const bool omit_zeroing_entries = false);
250
257 void
258 reinit(const size_type num_blocks);
259
277 void
279 const BlockVector &v);
280
287 bool
288 has_ghost_elements() const;
289
307 void
308 swap(BlockVector &v);
309
313 void
314 print(std::ostream &out,
315 const unsigned int precision = 3,
316 const bool scientific = true,
317 const bool across = true) const;
318
323
328 };
329
330
331
332 /*-------------------------- Inline functions ---------------------------*/
334 const std::vector<IndexSet> &parallel_partitioning,
335 const MPI_Comm communicator)
336 {
337 reinit(parallel_partitioning, communicator, false);
338 }
339
340
341
343 const std::vector<IndexSet> &parallel_partitioning,
344 const std::vector<IndexSet> &ghost_values,
345 const MPI_Comm communicator,
346 const bool vector_writable)
347 {
348 reinit(parallel_partitioning,
349 ghost_values,
350 communicator,
351 vector_writable);
352 }
353
354
355
356 inline BlockVector::BlockVector(const size_type num_blocks)
357 {
358 reinit(num_blocks);
359 }
360
361
362
364 : ::BlockVectorBase<MPI::Vector>()
365 {
367
368 this->components.resize(this->n_blocks());
369 for (unsigned int i = 0; i < this->n_blocks(); ++i)
370 this->components[i] = v.components[i];
371
372 this->collect_sizes();
373 }
374
375
376
378 {
379 // initialize a minimal, valid object and swap
380 reinit(0);
381 swap(v);
382 }
383
384
385
386 template <typename Number>
388 BlockVector::operator=(const ::BlockVector<Number> &v)
389 {
390 // we only allow assignment to vectors with the same number of blocks
391 // or to an empty BlockVector
392 Assert(this->n_blocks() == 0 || this->n_blocks() == v.n_blocks(),
393 ExcDimensionMismatch(this->n_blocks(), v.n_blocks()));
394
395 if (this->n_blocks() != v.n_blocks())
396 this->block_indices = v.get_block_indices();
397
398 this->components.resize(this->n_blocks());
399 for (unsigned int i = 0; i < this->n_blocks(); ++i)
400 this->components[i] = v.block(i);
401
402 this->collect_sizes();
403
404 return *this;
405 }
406
407
408
409 inline bool
411 {
412 bool ghosted = block(0).has_ghost_elements();
413# ifdef DEBUG
414 for (unsigned int i = 0; i < this->n_blocks(); ++i)
415 Assert(block(i).has_ghost_elements() == ghosted, ExcInternalError());
416# endif
417 return ghosted;
418 }
419
420
421
422 inline void
424 {
425 std::swap(this->components, v.components);
426
428 }
429
430
431
439 inline void
441 {
442 u.swap(v);
443 }
444
445 } /* namespace MPI */
446
447} /* namespace TrilinosWrappers */
448
452namespace internal
453{
454 namespace LinearOperatorImplementation
455 {
456 template <typename>
457 class ReinitHelper;
458
463 template <>
464 class ReinitHelper<TrilinosWrappers::MPI::BlockVector>
465 {
466 public:
467 template <typename Matrix>
468 static void
469 reinit_range_vector(const Matrix &matrix,
471 bool omit_zeroing_entries)
472 {
473 v.reinit(matrix.locally_owned_range_indices(),
474 matrix.get_mpi_communicator(),
475 omit_zeroing_entries);
476 }
477
478 template <typename Matrix>
479 static void
480 reinit_domain_vector(const Matrix &matrix,
482 bool omit_zeroing_entries)
483 {
484 v.reinit(matrix.locally_owned_domain_indices(),
485 matrix.get_mpi_communicator(),
486 omit_zeroing_entries);
487 }
488 };
489
490 } // namespace LinearOperatorImplementation
491} /* namespace internal */
492
493
497template <>
498struct is_serial_vector<TrilinosWrappers::MPI::BlockVector> : std::false_type
499{};
500
502
503#endif // DEAL_II_WITH_TRILINOS
504
505#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)
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:502
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:503
#define DeclException0(Exception0)
Definition exceptions.h:471
#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)