From: Denis Davydov Date: Thu, 21 Dec 2017 13:29:22 +0000 (+0100) Subject: add LA::d::BlockVector::norm_sqr() and LA::d::Vector::norm_sqr() X-Git-Tag: v9.0.0-rc1~632^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9999c0538b48978ab298dce8937fcb02b0f16870;p=dealii.git add LA::d::BlockVector::norm_sqr() and LA::d::Vector::norm_sqr() --- diff --git a/doc/news/changes/minor/20171221DenisDavydov b/doc/news/changes/minor/20171221DenisDavydov new file mode 100644 index 0000000000..440876241a --- /dev/null +++ b/doc/news/changes/minor/20171221DenisDavydov @@ -0,0 +1,4 @@ +New: add LinearAlgebra::distributed::BlockVector::norm_sqr() and +LinearAlgebra::distributed::Vector::norm_sqr() that return square of the l2 norm. +
+(Denis Davydov, 2017/12/21) diff --git a/include/deal.II/lac/la_parallel_block_vector.h b/include/deal.II/lac/la_parallel_block_vector.h index f2e2f7ae3f..1e61a3f0ff 100644 --- a/include/deal.II/lac/la_parallel_block_vector.h +++ b/include/deal.II/lac/la_parallel_block_vector.h @@ -523,6 +523,11 @@ namespace LinearAlgebra */ virtual real_type l2_norm() const override; + /** + * Return square of the l2 norm of the vector. + */ + real_type norm_sqr() const; + /** * Return the maximum norm of the vector (i.e., the maximum absolute value * among all entries and among all processors). diff --git a/include/deal.II/lac/la_parallel_block_vector.templates.h b/include/deal.II/lac/la_parallel_block_vector.templates.h index 8d266fa6df..ed35e14ce9 100644 --- a/include/deal.II/lac/la_parallel_block_vector.templates.h +++ b/include/deal.II/lac/la_parallel_block_vector.templates.h @@ -617,7 +617,7 @@ namespace LinearAlgebra template inline typename BlockVector::real_type - BlockVector::l2_norm () const + BlockVector::norm_sqr () const { Assert (this->n_blocks() > 0, ExcEmptyObject()); @@ -626,10 +626,20 @@ namespace LinearAlgebra local_result += this->block(i).norm_sqr_local(); if (this->block(0).partitioner->n_mpi_processes() > 1) - return std::sqrt(Utilities::MPI::sum (local_result, - this->block(0).partitioner->get_communicator())); + return Utilities::MPI::sum (local_result, + this->block(0).partitioner->get_communicator()); else - return std::sqrt(local_result); + return local_result; + } + + + + template + inline + typename BlockVector::real_type + BlockVector::l2_norm () const + { + return std::sqrt(norm_sqr()); } diff --git a/include/deal.II/lac/la_parallel_vector.h b/include/deal.II/lac/la_parallel_vector.h index a50b33c8a6..77d50c5d37 100644 --- a/include/deal.II/lac/la_parallel_vector.h +++ b/include/deal.II/lac/la_parallel_vector.h @@ -639,6 +639,11 @@ namespace LinearAlgebra */ virtual real_type l2_norm() const override; + /** + * Return square of the l2 norm of the vector. + */ + real_type norm_sqr() const; + /** * Return the maximum norm of the vector (i.e., the maximum absolute value * among all entries and among all processors). diff --git a/include/deal.II/lac/la_parallel_vector.templates.h b/include/deal.II/lac/la_parallel_vector.templates.h index c5734e16a6..0ab50f602c 100644 --- a/include/deal.II/lac/la_parallel_vector.templates.h +++ b/include/deal.II/lac/la_parallel_vector.templates.h @@ -1218,14 +1218,23 @@ namespace LinearAlgebra template typename Vector::real_type - Vector::l2_norm () const + Vector::norm_sqr () const { real_type local_result = norm_sqr_local(); if (partitioner->n_mpi_processes() > 1) - return std::sqrt(Utilities::MPI::sum(local_result, - partitioner->get_mpi_communicator())); + return Utilities::MPI::sum(local_result, + partitioner->get_mpi_communicator()); else - return std::sqrt(local_result); + return local_result; + } + + + + template + typename Vector::real_type + Vector::l2_norm () const + { + return std::sqrt(norm_sqr()); }