17 #ifndef __deal2__parallel_block_vector_h 18 #define __deal2__parallel_block_vector_h 21 #include <deal.II/base/config.h> 23 #include <deal.II/lac/block_indices.h> 24 #include <deal.II/lac/block_vector_base.h> 25 #include <deal.II/lac/parallel_vector.h> 57 template <
typename Number>
76 typedef typename BaseClass::pointer pointer;
77 typedef typename BaseClass::const_pointer const_pointer;
78 typedef typename BaseClass::reference reference;
79 typedef typename BaseClass::const_reference const_reference;
80 typedef typename BaseClass::size_type size_type;
94 explicit BlockVector (
const size_type num_blocks = 0,
95 const size_type block_size = 0);
104 #ifndef DEAL_II_EXPLICIT_CONSTRUCTOR_BUG 117 template <
typename OtherNumber>
126 BlockVector (
const std::vector<size_type> &block_sizes);
132 BlockVector (
const std::vector<IndexSet> &local_ranges,
133 const std::vector<IndexSet> &ghost_indices,
134 const MPI_Comm communicator);
139 BlockVector (
const std::vector<IndexSet> &local_ranges,
140 const MPI_Comm communicator);
164 template <
class Number2>
186 void reinit (
const size_type num_blocks,
187 const size_type block_size = 0,
188 const bool fast =
false);
208 void reinit (
const std::vector<size_type> &N,
209 const bool fast=
false);
225 template <
typename Number2>
227 const bool fast=
false);
252 void compress (::VectorOperation::values operation);
302 template <
typename Number2>
308 template <
typename Number2>
314 template <
typename Number2>
345 real_type
lp_norm (
const real_type p)
const;
367 template <
class BlockVector2>
368 void scale (
const BlockVector2 &v);
405 template <
typename Number>
408 const size_type block_size)
410 reinit (n_blocks, block_size);
415 template <
typename Number>
423 template <
typename Number>
426 const std::vector<IndexSet> &ghost_indices,
427 const MPI_Comm communicator)
429 std::vector<size_type> sizes(local_ranges.size());
430 for (
unsigned int i=0; i<local_ranges.size(); ++i)
431 sizes[i] = local_ranges[i].
size();
436 for (
unsigned int i=0; i<this->
n_blocks(); ++i)
437 this->
block(i).reinit(local_ranges[i], ghost_indices[i], communicator);
441 template <
typename Number>
444 const MPI_Comm communicator)
446 std::vector<size_type> sizes(local_ranges.size());
447 for (
unsigned int i=0; i<local_ranges.size(); ++i)
448 sizes[i] = local_ranges[i].
size();
453 for (
unsigned int i=0; i<this->
n_blocks(); ++i)
454 this->
block(i).reinit(local_ranges[i], communicator);
459 template <
typename Number>
468 for (size_type i=0; i<this->
n_blocks(); ++i)
473 #ifndef DEAL_II_EXPLICIT_CONSTRUCTOR_BUG 475 template <
typename Number>
476 template <
typename OtherNumber>
488 template <
typename Number>
494 std::vector<size_type> n(n_bl, bl_sz);
499 template <
typename Number>
504 this->block_indices.reinit (n);
505 if (this->components.size() != this->n_blocks())
506 this->components.resize(this->n_blocks());
508 for (
size_type i=0; i<this->n_blocks(); ++i)
509 this->components[i].reinit(n[i], fast);
514 template <
typename Number>
515 template <
typename Number2>
521 if (this->components.size() != this->n_blocks())
522 this->components.resize(this->n_blocks());
524 for (
unsigned int i=0; i<this->n_blocks(); ++i)
530 template <
typename Number>
537 template <
typename Number>
545 BaseClass::operator = (s);
551 template <
typename Number>
558 Assert (this->n_blocks() == 0 || this->n_blocks() == v.
n_blocks(),
561 if (this->n_blocks() != v.
n_blocks())
564 for (
size_type i=0; i<this->n_blocks(); ++i)
565 this->components[i] = v.
block(i);
567 this->collect_sizes();
573 template <
typename Number>
578 BaseClass::operator = (v);
584 template <
typename Number>
585 template <
typename Number2>
591 BaseClass::operator = (v);
597 template <
typename Number>
604 for (
unsigned int block=0; block<this->n_blocks(); ++block)
605 this->block(block).compress_start(block*10 + 8273, operation);
606 for (
unsigned int block=0; block<this->n_blocks(); ++block)
607 this->block(block).compress_finish(operation);
612 template <
typename Number>
617 for (
unsigned int block=0; block<this->n_blocks(); ++block)
618 this->block(block).update_ghost_values_start(block*10 + 9923);
619 for (
unsigned int block=0; block<this->n_blocks(); ++block)
620 this->block(block).update_ghost_values_finish();
625 template <
typename Number>
630 for (
unsigned int block=0; block<this->n_blocks(); ++block)
631 this->block(block).zero_out_ghosts();
636 template <
typename Number>
641 bool has_ghost_elements =
false;
642 for (
unsigned int block=0; block<this->n_blocks(); ++block)
643 if (this->block(block).has_ghost_elements() ==
true)
644 has_ghost_elements =
true;
645 return has_ghost_elements;
650 template <
typename Number>
662 int local_result = -1;
663 for (
unsigned int i=0; i<this->n_blocks(); ++i)
664 local_result = std::max(local_result,
665 -static_cast<int>(this->block(i).all_zero_local()));
667 if (this->block(0).partitioner->n_mpi_processes() > 1)
669 this->block(0).partitioner->get_communicator());
676 template <
typename Number>
682 int local_result = -1;
683 for (
unsigned int i=0; i<this->n_blocks(); ++i)
684 local_result = std::max(local_result,
685 -static_cast<int>(this->block(i).is_non_negative_local()));
686 if (this->block(0).partitioner->n_mpi_processes() > 1)
688 this->block(0).partitioner->get_communicator());
695 template <
typename Number>
696 template <
typename Number2>
706 unsigned int local_result = 0;
707 for (
unsigned int i=0; i<this->n_blocks(); ++i)
708 local_result = std::max(local_result,
709 static_cast<unsigned int>(!this->block(i).vectors_equal_local(v.
block(i))));
710 unsigned int result =
711 this->block(0).partitioner->n_mpi_processes() > 1
721 template <
typename Number>
722 template <
typename Number2>
727 return !(operator == (v));
732 template <
typename Number>
733 template <
typename Number2>
741 Number local_result = Number();
742 for (
unsigned int i=0; i<this->n_blocks(); ++i)
743 local_result += this->block(i).inner_product_local(v.
block(i));
745 if (this->block(0).partitioner->n_mpi_processes() > 1)
747 this->block(0).partitioner->get_communicator());
754 template <
typename Number>
756 typename BlockVector<Number>::real_type
761 real_type local_result = real_type();
762 for (
unsigned int i=0; i<this->n_blocks(); ++i)
763 local_result += this->block(i).norm_sqr_local();
765 if (this->block(0).partitioner->n_mpi_processes() > 1)
767 this->block(0).partitioner->get_communicator());
774 template <
typename Number>
781 Number local_result = Number();
782 for (
unsigned int i=0; i<this->n_blocks(); ++i)
783 local_result += this->block(i).mean_value_local()*(real_type)this->block(i).partitioner->local_size();
785 if (this->block(0).partitioner->n_mpi_processes() > 1)
787 this->block(0).partitioner->get_communicator())/
788 (real_type)this->size();
790 return local_result/(real_type)this->size();
795 template <
typename Number>
797 typename BlockVector<Number>::real_type
802 real_type local_result = real_type();
803 for (
unsigned int i=0; i<this->n_blocks(); ++i)
804 local_result += this->block(i).l1_norm_local();
806 if (this->block(0).partitioner->n_mpi_processes() > 1)
808 this->block(0).partitioner->get_communicator());
815 template <
typename Number>
817 typename BlockVector<Number>::real_type
820 return std::sqrt(norm_sqr());
825 template <
typename Number>
827 typename BlockVector<Number>::real_type
832 real_type local_result = real_type();
833 for (
unsigned int i=0; i<this->n_blocks(); ++i)
834 local_result += std::pow(this->block(i).lp_norm_local(p), p);
836 if (this->block(0).partitioner->n_mpi_processes() > 1)
838 this->block(0).partitioner->get_communicator()),
839 static_cast<real_type>(1.0/p));
841 return std::pow (local_result, static_cast<real_type>(1.0/p));
846 template <
typename Number>
848 typename BlockVector<Number>::real_type
853 real_type local_result = real_type();
854 for (
unsigned int i=0; i<this->n_blocks(); ++i)
855 local_result = std::max(local_result, this->block(i).linfty_norm_local());
857 if (this->block(0).partitioner->n_mpi_processes() > 1)
859 this->block(0).partitioner->get_communicator());
866 template <
typename Number>
873 for (
size_type i=0; i<this->n_blocks(); ++i)
874 ::swap (this->components[i], v.
components[i]);
880 template <
typename Number>
886 for (
size_type i=0; i<this->n_blocks(); ++i)
887 this->components[i].scale(factor);
892 template <
typename Number>
893 template <
class BlockVector2>
896 BaseClass::scale (v);
913 template <
typename Number>
921 DEAL_II_NAMESPACE_CLOSE
#define AssertDimension(dim1, dim2)
void reinit(const size_type num_blocks, const size_type block_size=0, const bool fast=false)
bool is_non_negative() const
bool operator==(const BlockVector< Number2 > &v) const
void scale(const value_type factor) DEAL_II_DEPRECATED
void swap(parallel::distributed::BlockVector< Number > &u, parallel::distributed::BlockVector< Number > &v)
BlockVector & operator=(const value_type s)
Number mean_value() const
unsigned int n_blocks() const
BaseClass::BlockType BlockType
DeclException0(ExcIteratorRangeDoesNotMatchVectorSize)
BlockVectorBase< Vector< Number > > BaseClass
bool is_finite(const double x)
BlockIndices block_indices
real_type linfty_norm() const
T sum(const T &t, const MPI_Comm &mpi_communicator)
#define Assert(cond, exc)
::ExceptionBase & ExcEmptyObject()
real_type norm_sqr() const
BlockType::real_type real_type
const BlockIndices & get_block_indices() const
void reinit(const unsigned int n_blocks, const size_type n_elements_per_block)
real_type l1_norm() const
Number operator*(const BlockVector< Number2 > &V) const
BlockCompressedSparsityPattern CompressedBlockSparsityPattern DEAL_II_DEPRECATED
void swap(BlockVector< Number > &v)
std::vector< Vector< Number > > components
real_type lp_norm(const real_type p) const
real_type l2_norm() const
void update_ghost_values() const
::ExceptionBase & ExcNumberNotFinite()
BaseClass::value_type value_type
void compress() DEAL_II_DEPRECATED
bool operator!=(const BlockVector< Number2 > &v) const
::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
BlockType & block(const unsigned int i)
T max(const T &t, const MPI_Comm &mpi_communicator)
BlockVector(const size_type num_blocks=0, const size_type block_size=0)
bool has_ghost_elements() const