inline BlockVector::BlockVector(const BlockVector &v)
: BlockVectorBase<Vector>()
{
- this->components.resize(v.n_blocks());
this->block_indices = v.block_indices;
+ this->components.resize(this->n_blocks());
for (unsigned int i = 0; i < this->n_blocks(); ++i)
this->components[i] = v.components[i];
+
+ this->collect_sizes();
}
inline BlockVector::BlockVector(
{
// we only allow assignment to vectors with the same number of blocks
// or to an empty BlockVector
- Assert(n_blocks() == 0 || n_blocks() == v.n_blocks(),
- ExcDimensionMismatch(n_blocks(), v.n_blocks()));
+ Assert(this->n_blocks() == 0 || this->n_blocks() == v.n_blocks(),
+ ExcDimensionMismatch(this->n_blocks(), v.n_blocks()));
if (this->n_blocks() != v.n_blocks())
- reinit(v.n_blocks());
+ this->block_indices = v.block_indices;
- for (size_type i = 0; i < this->n_blocks(); ++i)
- this->components[i] = v.block(i);
+ this->components.resize(this->n_blocks());
+ for (unsigned int i = 0; i < this->n_blocks(); ++i)
+ this->components[i] = v.components[i];
- collect_sizes();
+ this->collect_sizes();
return *this;
}
const bool omit_zeroing_entries)
{
this->block_indices.reinit(block_sizes);
- if (this->components.size() != this->n_blocks())
- this->components.resize(this->n_blocks());
+ this->components.resize(this->n_blocks());
for (unsigned int i = 0; i < this->n_blocks(); ++i)
this->components[i].reinit(communicator,
block_sizes[i],
locally_owned_sizes[i],
omit_zeroing_entries);
+
+ this->collect_sizes();
}
inline void
BlockVector::reinit(const BlockVector &v, const bool omit_zeroing_entries)
{
- this->block_indices = v.get_block_indices();
- if (this->components.size() != this->n_blocks())
- this->components.resize(this->n_blocks());
+ if (this->n_blocks() != v.n_blocks())
+ this->block_indices = v.get_block_indices();
+ this->components.resize(this->n_blocks());
for (unsigned int i = 0; i < this->n_blocks(); ++i)
- block(i).reinit(v.block(i), omit_zeroing_entries);
+ this->components[i].reinit(v.components[i], omit_zeroing_entries);
+
+ this->collect_sizes();
}
inline void
BlockVector::reinit(const std::vector<IndexSet> ¶llel_partitioning,
const MPI_Comm & communicator)
{
- std::vector<size_type> sizes(parallel_partitioning.size());
- for (unsigned int i = 0; i < parallel_partitioning.size(); ++i)
- sizes[i] = parallel_partitioning[i].size();
-
- this->block_indices.reinit(sizes);
- if (this->components.size() != this->n_blocks())
- this->components.resize(this->n_blocks());
+ // update the number of blocks
+ this->block_indices.reinit(parallel_partitioning.size(), 0);
+ // initialize each block
+ this->components.resize(this->n_blocks());
for (unsigned int i = 0; i < this->n_blocks(); ++i)
- block(i).reinit(parallel_partitioning[i], communicator);
+ this->components[i].reinit(parallel_partitioning[i], communicator);
+
+ // update block_indices content
+ this->collect_sizes();
}
inline void
const std::vector<IndexSet> &ghost_entries,
const MPI_Comm & communicator)
{
- std::vector<types::global_dof_index> sizes(parallel_partitioning.size());
- for (unsigned int i = 0; i < parallel_partitioning.size(); ++i)
- sizes[i] = parallel_partitioning[i].size();
+ AssertDimension(parallel_partitioning.size(), ghost_entries.size());
- this->block_indices.reinit(sizes);
- if (this->components.size() != this->n_blocks())
- this->components.resize(this->n_blocks());
+ // update the number of blocks
+ this->block_indices.reinit(parallel_partitioning.size(), 0);
+ // initialize each block
+ this->components.resize(this->n_blocks());
for (unsigned int i = 0; i < this->n_blocks(); ++i)
- block(i).reinit(parallel_partitioning[i],
- ghost_entries[i],
- communicator);
+ this->components[i].reinit(parallel_partitioning[i],
+ ghost_entries[i],
+ communicator);
+
+ // update block_indices content
+ this->collect_sizes();
}
inline BlockVector::BlockVector(const BlockVector &v)
: dealii::BlockVectorBase<MPI::Vector>()
{
- this->components.resize(v.n_blocks());
this->block_indices = v.block_indices;
- for (size_type i = 0; i < this->n_blocks(); ++i)
+ this->components.resize(this->n_blocks());
+ for (unsigned int i = 0; i < this->n_blocks(); ++i)
this->components[i] = v.components[i];
+
+ this->collect_sizes();
}
BlockVector &
BlockVector::operator=(const ::dealii::BlockVector<Number> &v)
{
- if (n_blocks() != v.n_blocks())
- {
- std::vector<size_type> block_sizes(v.n_blocks(), 0);
- block_indices.reinit(block_sizes);
- if (components.size() != n_blocks())
- components.resize(n_blocks());
- }
-
- for (size_type i = 0; i < this->n_blocks(); ++i)
+ // we only allow assignment to vectors with the same number of blocks
+ // or to an empty BlockVector
+ Assert(this->n_blocks() == 0 || this->n_blocks() == v.n_blocks(),
+ ExcDimensionMismatch(this->n_blocks(), v.n_blocks()));
+
+ if (this->n_blocks() != v.n_blocks())
+ this->block_indices = v.get_block_indices();
+
+ this->components.resize(this->n_blocks());
+ for (unsigned int i = 0; i < this->n_blocks(); ++i)
this->components[i] = v.block(i);
- collect_sizes();
+ this->collect_sizes();
return *this;
}
{
// we only allow assignment to vectors with the same number of blocks
// or to an empty BlockVector
- Assert(n_blocks() == 0 || n_blocks() == v.n_blocks(),
- ExcDimensionMismatch(n_blocks(), v.n_blocks()));
+ Assert(this->n_blocks() == 0 || this->n_blocks() == v.n_blocks(),
+ ExcDimensionMismatch(this->n_blocks(), v.n_blocks()));
if (this->n_blocks() != v.n_blocks())
- reinit(v.n_blocks());
+ this->block_indices = v.block_indices;
- for (size_type i = 0; i < this->n_blocks(); ++i)
- this->components[i] = v.block(i);
+ this->components.resize(this->n_blocks());
+ for (unsigned int i = 0; i < this->n_blocks(); ++i)
+ this->components[i] = v.components[i];
- collect_sizes();
+ this->collect_sizes();
return *this;
}
const MPI_Comm & communicator,
const bool omit_zeroing_entries)
{
- const size_type no_blocks = parallel_partitioning.size();
- std::vector<size_type> block_sizes(no_blocks);
-
- for (size_type i = 0; i < no_blocks; ++i)
- {
- block_sizes[i] = parallel_partitioning[i].size();
- }
-
- this->block_indices.reinit(block_sizes);
- if (components.size() != n_blocks())
- components.resize(n_blocks());
-
- for (size_type i = 0; i < n_blocks(); ++i)
- components[i].reinit(parallel_partitioning[i],
- communicator,
- omit_zeroing_entries);
-
- collect_sizes();
+ // update the number of blocks
+ this->block_indices.reinit(parallel_partitioning.size(), 0);
+
+ // initialize each block
+ this->components.resize(this->n_blocks());
+ for (unsigned int i = 0; i < this->n_blocks(); ++i)
+ this->components[i].reinit(parallel_partitioning[i],
+ communicator,
+ omit_zeroing_entries);
+
+ // update block_indices content
+ this->collect_sizes();
}
const MPI_Comm & communicator,
const bool vector_writable)
{
- const size_type no_blocks = parallel_partitioning.size();
- std::vector<size_type> block_sizes(no_blocks);
-
- for (size_type i = 0; i < no_blocks; ++i)
- {
- block_sizes[i] = parallel_partitioning[i].size();
- }
+ AssertDimension(parallel_partitioning.size(), ghost_values.size());
- this->block_indices.reinit(block_sizes);
- if (components.size() != n_blocks())
- components.resize(n_blocks());
+ // update the number of blocks
+ this->block_indices.reinit(parallel_partitioning.size(), 0);
- for (size_type i = 0; i < n_blocks(); ++i)
- components[i].reinit(parallel_partitioning[i],
- ghost_values[i],
- communicator,
- vector_writable);
+ // initialize each block
+ this->components.resize(this->n_blocks());
+ for (unsigned int i = 0; i < this->n_blocks(); ++i)
+ this->components[i].reinit(parallel_partitioning[i],
+ ghost_values[i],
+ communicator,
+ vector_writable);
- collect_sizes();
+ // update block_indices content
+ this->collect_sizes();
}
void
BlockVector::reinit(const BlockVector &v, const bool omit_zeroing_entries)
{
- block_indices = v.get_block_indices();
- if (components.size() != n_blocks())
- components.resize(n_blocks());
+ if (this->n_blocks() != v.n_blocks())
+ this->block_indices = v.get_block_indices();
- for (size_type i = 0; i < n_blocks(); ++i)
- components[i].reinit(v.block(i), omit_zeroing_entries, false);
+ this->components.resize(this->n_blocks());
+ for (unsigned int i = 0; i < this->n_blocks(); ++i)
+ this->components[i].reinit(v.components[i],
+ omit_zeroing_entries,
+ false);
- collect_sizes();
+ this->collect_sizes();
}
void
BlockVector::reinit(const size_type num_blocks)
{
- std::vector<size_type> block_sizes(num_blocks, 0);
- this->block_indices.reinit(block_sizes);
- if (this->components.size() != this->n_blocks())
- this->components.resize(this->n_blocks());
-
- for (size_type i = 0; i < this->n_blocks(); ++i)
- components[i].clear();
+ this->block_indices.reinit(num_blocks, 0);
- collect_sizes();
+ this->components.resize(this->n_blocks());
+ for (auto &c : this->components)
+ c.clear();
}
const TrilinosWrappers::BlockSparseMatrix &m,
const BlockVector & v)
{
- Assert(m.n_block_rows() == v.n_blocks(),
- ExcDimensionMismatch(m.n_block_rows(), v.n_blocks()));
- Assert(m.n_block_cols() == v.n_blocks(),
- ExcDimensionMismatch(m.n_block_cols(), v.n_blocks()));
+ AssertDimension(m.n_block_rows(), v.n_blocks());
+ AssertDimension(m.n_block_cols(), v.n_blocks());
- if (v.n_blocks() != n_blocks())
- {
- block_indices = v.get_block_indices();
- components.resize(v.n_blocks());
- }
+ if (this->n_blocks() != v.n_blocks())
+ this->block_indices = v.get_block_indices();
- for (size_type i = 0; i < this->n_blocks(); ++i)
- components[i].import_nonlocal_data_for_fe(m.block(i, i), v.block(i));
+ this->components.resize(this->n_blocks());
+ for (unsigned int i = 0; i < this->n_blocks(); ++i)
+ this->components[i].import_nonlocal_data_for_fe(m.block(i, i),
+ v.block(i));
- collect_sizes();
+ this->collect_sizes();
}
const bool scientific,
const bool across) const
{
- for (size_type i = 0; i < this->n_blocks(); ++i)
+ for (unsigned int i = 0; i < this->n_blocks(); ++i)
{
if (across)
out << 'C' << i << ':';