From 0a0e615272e8f350f656056c322380baaf9fe15e Mon Sep 17 00:00:00 2001 From: Niklas Fehn Date: Fri, 6 Mar 2020 08:50:17 +0100 Subject: [PATCH] new function set_zero_mean_value() --- doc/news/changes/minor/20200306NiklasFehn | 7 +++++++ include/deal.II/lac/vector_space_vector.h | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 doc/news/changes/minor/20200306NiklasFehn diff --git a/doc/news/changes/minor/20200306NiklasFehn b/doc/news/changes/minor/20200306NiklasFehn new file mode 100644 index 0000000000..3a935604fd --- /dev/null +++ b/doc/news/changes/minor/20200306NiklasFehn @@ -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. +
+(Niklas Fehn, 2020/03/06) diff --git a/include/deal.II/lac/vector_space_vector.h b/include/deal.II/lac/vector_space_vector.h index 10975c1d1c..1c13cc8640 100644 --- a/include/deal.II/lac/vector_space_vector.h +++ b/include/deal.II/lac/vector_space_vector.h @@ -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 + void + set_zero_mean_value(VectorSpaceVector &vector) + { + vector.add(-vector.mean_value()); + } +} // namespace LinearAlgebra + DEAL_II_NAMESPACE_CLOSE #endif -- 2.39.5