]> https://gitweb.dealii.org/ - dealii.git/commitdiff
new function set_zero_mean_value() 9631/head
authorNiklas Fehn <fehn@lnm.mw.tum.de>
Fri, 6 Mar 2020 07:50:17 +0000 (08:50 +0100)
committerNiklas Fehn <fehn@lnm.mw.tum.de>
Tue, 10 Mar 2020 13:13:07 +0000 (14:13 +0100)
doc/news/changes/minor/20200306NiklasFehn [new file with mode: 0644]
include/deal.II/lac/vector_space_vector.h

diff --git a/doc/news/changes/minor/20200306NiklasFehn b/doc/news/changes/minor/20200306NiklasFehn
new file mode 100644 (file)
index 0000000..3a93560
--- /dev/null
@@ -0,0 +1,7 @@
+New: LinearAlgebra::set_zero_mean_value()
+Add free function that allows to shift a vector by a constant value in a
+way that its mean value becomes zero. This function only makes use of the
+pure virtual functions add() and mean_value() of the abstract class
+VectorSpaceVector.
+<br>
+(Niklas Fehn, 2020/03/06)
index 10975c1d1c64e01a46a5d62219884d8b97c90a99..1c13cc8640c91d75c3ba93dfb217265ac071689e 100644 (file)
@@ -273,6 +273,22 @@ namespace LinearAlgebra
   /*@}*/
 } // namespace LinearAlgebra
 
+// ---------------------------- Free functions --------------------------
+
+namespace LinearAlgebra
+{
+  /**
+   * Shift all entries of the vector by a constant factor so that the mean
+   * value of the vector becomes zero.
+   */
+  template <typename Number>
+  void
+  set_zero_mean_value(VectorSpaceVector<Number> &vector)
+  {
+    vector.add(-vector.mean_value());
+  }
+} // namespace LinearAlgebra
+
 DEAL_II_NAMESPACE_CLOSE
 
 #endif

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.