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_block_vector.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 - 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
14
15#ifdef DEAL_II_WITH_TRILINOS
16
19
20
21
22#endif
23
25
26#ifdef DEAL_II_WITH_TRILINOS
27
28namespace TrilinosWrappers
29{
30 namespace MPI
31 {
34 {
36 return *this;
37 }
38
39
40
43 {
44 // we only allow assignment to vectors with the same number of blocks
45 // or to an empty BlockVector
46 Assert(this->n_blocks() == 0 || this->n_blocks() == v.n_blocks(),
48
49 if (this->n_blocks() != v.n_blocks())
51
52 this->components.resize(this->n_blocks());
53 for (unsigned int i = 0; i < this->n_blocks(); ++i)
54 this->components[i] = v.components[i];
55
56 this->collect_sizes();
57
58 return *this;
59 }
60
61
62
65 {
66 swap(v);
67 return *this;
68 }
69
70
71
72 void
73 BlockVector::reinit(const std::vector<IndexSet> &parallel_partitioning,
74 const MPI_Comm communicator,
75 const bool omit_zeroing_entries)
76 {
77 // update the number of blocks
78 this->block_indices.reinit(parallel_partitioning.size(), 0);
79
80 // initialize each block
81 this->components.resize(this->n_blocks());
82 for (unsigned int i = 0; i < this->n_blocks(); ++i)
83 this->components[i].reinit(parallel_partitioning[i],
84 communicator,
85 omit_zeroing_entries);
86
87 // update block_indices content
88 this->collect_sizes();
89 }
90
91
92
93 void
94 BlockVector::reinit(const std::vector<IndexSet> &parallel_partitioning,
95 const std::vector<IndexSet> &ghost_values,
96 const MPI_Comm communicator,
97 const bool vector_writable)
98 {
99 AssertDimension(parallel_partitioning.size(), ghost_values.size());
100
101 // update the number of blocks
102 this->block_indices.reinit(parallel_partitioning.size(), 0);
103
104 // initialize each block
105 this->components.resize(this->n_blocks());
106 for (unsigned int i = 0; i < this->n_blocks(); ++i)
107 this->components[i].reinit(parallel_partitioning[i],
108 ghost_values[i],
109 communicator,
110 vector_writable);
111
112 // update block_indices content
113 this->collect_sizes();
114 }
115
116
117
118 void
120 const std::vector<std::shared_ptr<const Utilities::MPI::Partitioner>>
121 &partitioners,
122 const bool make_ghosted,
123 const bool vector_writable)
124 {
125 // update the number of blocks
126 this->block_indices.reinit(partitioners.size(), 0);
127
128 // initialize each block
129 this->components.resize(this->n_blocks());
130 for (unsigned int i = 0; i < this->n_blocks(); ++i)
131 this->components[i].reinit(partitioners[i],
132 make_ghosted,
133 vector_writable);
134
135 // update block_indices content
136 this->collect_sizes();
137 }
138
139
140
141 void
142 BlockVector::reinit(const BlockVector &v, const bool omit_zeroing_entries)
143 {
144 if (this->n_blocks() != v.n_blocks())
146
147 this->components.resize(this->n_blocks());
148 for (unsigned int i = 0; i < this->n_blocks(); ++i)
149 this->components[i].reinit(v.components[i], omit_zeroing_entries);
150
151 this->collect_sizes();
152 }
153
154
155
156 void
158 {
159 this->block_indices.reinit(num_blocks, 0);
160
161 this->components.resize(this->n_blocks());
162 for (auto &c : this->components)
163 c.clear();
164 }
165
166
167
168 void
171 const BlockVector &v)
172 {
175
176 if (this->n_blocks() != v.n_blocks())
178
179 this->components.resize(this->n_blocks());
180 for (unsigned int i = 0; i < this->n_blocks(); ++i)
182 v.block(i));
183
184 this->collect_sizes();
185 }
186
187
188
189 void
190 BlockVector::print(std::ostream &out,
191 const unsigned int precision,
192 const bool scientific,
193 const bool across) const
194 {
195 for (unsigned int i = 0; i < this->n_blocks(); ++i)
196 {
197 if (across)
198 out << 'C' << i << ':';
199 else
200 out << "Component " << i << std::endl;
201 this->components[i].print(out, precision, scientific, across);
202 }
203 }
204
205 } /* end of namespace MPI */
206} /* end of namespace TrilinosWrappers */
207
208
209
210#endif
void reinit(const unsigned int n_blocks, const size_type n_elements_per_block)
unsigned int n_block_rows() const
unsigned int n_block_cols() const
BlockType & block(const unsigned int row, const unsigned int column)
unsigned int n_blocks() const
BlockVectorBase & operator=(const value_type s)
std::vector< MPI::Vector > components
BlockType & block(const unsigned int i)
const BlockIndices & get_block_indices() const
void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true, const bool across=true) const
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)
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
void swap(BlockVector &u, BlockVector &v) noexcept