]> https://gitweb.dealii.org/ - dealii.git/commitdiff
add LA::d::BlockVector::norm_sqr() and LA::d::Vector::norm_sqr() 5659/head
authorDenis Davydov <davydden@gmail.com>
Thu, 21 Dec 2017 13:29:22 +0000 (14:29 +0100)
committerDenis Davydov <davydden@gmail.com>
Thu, 21 Dec 2017 13:29:22 +0000 (14:29 +0100)
doc/news/changes/minor/20171221DenisDavydov [new file with mode: 0644]
include/deal.II/lac/la_parallel_block_vector.h
include/deal.II/lac/la_parallel_block_vector.templates.h
include/deal.II/lac/la_parallel_vector.h
include/deal.II/lac/la_parallel_vector.templates.h

diff --git a/doc/news/changes/minor/20171221DenisDavydov b/doc/news/changes/minor/20171221DenisDavydov
new file mode 100644 (file)
index 0000000..4408762
--- /dev/null
@@ -0,0 +1,4 @@
+New: add LinearAlgebra::distributed::BlockVector::norm_sqr() and
+LinearAlgebra::distributed::Vector::norm_sqr() that return square of the l2 norm.
+<br>
+(Denis Davydov, 2017/12/21)
index f2e2f7ae3f714711df0b0f561530f2678b47e9c9..1e61a3f0ff13bf75022137ffc9cd97d06be27043 100644 (file)
@@ -523,6 +523,11 @@ namespace LinearAlgebra
        */
       virtual real_type l2_norm() const override;
 
+      /**
+       * Return square of the l<sub>2</sub> 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).
index 8d266fa6df49d93653e11301d2c060ce788ceb40..ed35e14ce9c8e46e46381913a398a7ca2dcb3ebb 100644 (file)
@@ -617,7 +617,7 @@ namespace LinearAlgebra
     template <typename Number>
     inline
     typename BlockVector<Number>::real_type
-    BlockVector<Number>::l2_norm () const
+    BlockVector<Number>::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 <typename Number>
+    inline
+    typename BlockVector<Number>::real_type
+    BlockVector<Number>::l2_norm () const
+    {
+      return std::sqrt(norm_sqr());
     }
 
 
index a50b33c8a6164bb28aca10e4bba80d62e1584dde..77d50c5d3702f536bcb07cef93feafc358bf2c8e 100644 (file)
@@ -639,6 +639,11 @@ namespace LinearAlgebra
        */
       virtual real_type l2_norm() const override;
 
+      /**
+       * Return square of the l<sub>2</sub> 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).
index c5734e16a61aaf4d4b12031d7b156b4787e9821d..0ab50f602cfc25c28f90ffc4814816c6face6fbf 100644 (file)
@@ -1218,14 +1218,23 @@ namespace LinearAlgebra
 
     template <typename Number>
     typename Vector<Number>::real_type
-    Vector<Number>::l2_norm () const
+    Vector<Number>::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 Number>
+    typename Vector<Number>::real_type
+    Vector<Number>::l2_norm () const
+    {
+      return std::sqrt(norm_sqr());
     }
 
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.