reinit(const BlockVector<Number2> &V,
const bool omit_zeroing_entries = false);
+ /**
+ * Initialize the block vector. For each block, the local range is
+ * specified by the corresponding entry in @p local_ranges (note that this
+ * must be a contiguous interval, multiple intervals are not possible).
+ * The parameter @p ghost_indices specifies ghost indices for each block,
+ * i.e., indices which one might need to read data from or accumulate data
+ * from. It is allowed that the set of ghost indices also contains the
+ * local range, but it does not need to.
+ *
+ * This function involves global communication, so it should only be
+ * called once for a given layout. Use the @p reinit function with
+ * BlockVector<Number> argument to create additional vectors with the same
+ * parallel layout.
+ *
+ * @see
+ * @ref GlossGhostedVector "vectors with ghost elements"
+ */
+ void
+ reinit(const std::vector<IndexSet> &local_ranges,
+ const std::vector<IndexSet> &ghost_indices,
+ const MPI_Comm & communicator);
+
+ /**
+ * Same as above, but without ghost entries.
+ */
+ void
+ reinit(const std::vector<IndexSet> &local_ranges,
+ const MPI_Comm & communicator);
+
/**
* This function copies the data that has accumulated in the data buffer
* for ghost indices to the owning processor. For the meaning of the
const std::vector<IndexSet> &ghost_indices,
const MPI_Comm & communicator)
{
- std::vector<size_type> sizes(local_ranges.size());
- for (unsigned int i = 0; i < local_ranges.size(); ++i)
- sizes[i] = local_ranges[i].size();
-
- this->block_indices.reinit(sizes);
- this->components.resize(this->n_blocks());
-
- for (unsigned int i = 0; i < this->n_blocks(); ++i)
- this->block(i).reinit(local_ranges[i], ghost_indices[i], communicator);
+ reinit(local_ranges, ghost_indices, communicator);
}
BlockVector<Number>::BlockVector(const std::vector<IndexSet> &local_ranges,
const MPI_Comm & communicator)
{
- std::vector<size_type> sizes(local_ranges.size());
- for (unsigned int i = 0; i < local_ranges.size(); ++i)
- sizes[i] = local_ranges[i].size();
-
- this->block_indices.reinit(sizes);
- this->components.resize(this->n_blocks());
-
- for (unsigned int i = 0; i < this->n_blocks(); ++i)
- this->block(i).reinit(local_ranges[i], communicator);
+ reinit(local_ranges, communicator);
}
BlockVector<Number>::BlockVector(const BlockVector<Number> &v)
: BlockVectorBase<Vector<Number>>()
{
- 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();
}
const bool omit_zeroing_entries)
{
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)
+ this->components.resize(this->n_blocks());
+ for (unsigned int i = 0; i < this->n_blocks(); ++i)
this->components[i].reinit(block_sizes[i], omit_zeroing_entries);
+
+ this->collect_sizes();
}
BlockVector<Number>::reinit(const BlockVector<Number2> &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)
+ this->components[i].reinit(v.block(i), omit_zeroing_entries);
+
+ this->collect_sizes();
+ }
+
+
+
+ template <typename Number>
+ void
+ BlockVector<Number>::reinit(const std::vector<IndexSet> &local_ranges,
+ const std::vector<IndexSet> &ghost_indices,
+ const MPI_Comm & communicator)
+ {
+ AssertDimension(local_ranges.size(), ghost_indices.size());
+
+ // update the number of blocks
+ this->block_indices.reinit(local_ranges.size(), 0);
+ // initialize each block
+ this->components.resize(this->n_blocks());
for (unsigned int i = 0; i < this->n_blocks(); ++i)
- this->block(i).reinit(v.block(i), omit_zeroing_entries);
+ this->components[i].reinit(local_ranges[i],
+ ghost_indices[i],
+ communicator);
+
+ // update block_indices content
+ this->collect_sizes();
+ }
+
+
+
+ template <typename Number>
+ void
+ BlockVector<Number>::reinit(const std::vector<IndexSet> &local_ranges,
+ const MPI_Comm & communicator)
+ {
+ // update the number of blocks
+ this->block_indices.reinit(local_ranges.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(local_ranges[i], communicator);
+
+ // update block_indices content
+ this->collect_sizes();
}
ExcDimensionMismatch(this->n_blocks(), v.n_blocks()));
if (this->n_blocks() != v.n_blocks())
- reinit(v.n_blocks(), true);
+ this->block_indices = v.block_indices;
+ this->components.resize(this->n_blocks());
for (size_type i = 0; i < this->n_blocks(); ++i)
- this->components[i] = v.block(i);
+ this->components[i] = v.components[i];
this->collect_sizes();
+
return *this;
}
const bool omit_zeroing_entries = false);
/**
- * Initialize the vector. The local range is specified by @p
- * locally_owned_set (note that this must be a contiguous interval,
- * multiple intervals are not possible). The IndexSet @p ghost_indices
- * specifies ghost indices, i.e., indices which one might need to read
- * data from or accumulate data from. It is allowed that the set of
- * ghost indices also contains the local range, but it does not need to.
+ * Initialize the vector. The local range is specified by @p local_range
+ * (note that this must be a contiguous interval, multiple intervals are
+ * not possible). The IndexSet @p ghost_indices specifies ghost indices,
+ * i.e., indices which one might need to read data from or accumulate data
+ * from. It is allowed that the set of ghost indices also contains the
+ * local range, but it does not need to.
*
* This function involves global communication, so it should only be
* called once for a given layout. Use the @p reinit function with