]> https://gitweb.dealii.org/ - dealii.git/commitdiff
LinearOperator: Implement a mean value filter operator
authorMatthias Maier <tamiko@43-1.org>
Thu, 3 May 2018 02:46:57 +0000 (21:46 -0500)
committerMatthias Maier <tamiko@43-1.org>
Thu, 3 May 2018 18:57:36 +0000 (13:57 -0500)
include/deal.II/lac/linear_operator.h

index ed3d14812c672628feeeba2ec9f3b84511172014..a08b89cb762e5d5462f2d75bc09c6b26431712a4 100644 (file)
@@ -851,6 +851,72 @@ null_operator(const LinearOperator<Range, Domain, Payload> &op)
 }
 
 
+/**
+ * @relatesalso LinearOperator
+ *
+ * Return a LinearOperator that acts as a mean value filter. The vmult()
+ * functions of this matrix subtract the mean values of the vector.
+ *
+ * The function takes an <code>std::function</code> object @p reinit_vector as
+ * an argument to initialize the <code>reinit_range_vector</code> and
+ * <code>reinit_domain_vector</code> objects of the LinearOperator object.
+ *
+ * @ingroup LAOperators
+ */
+template <typename Range,
+          typename Payload = internal::LinearOperatorImplementation::EmptyPayload>
+LinearOperator<Range, Range, Payload>
+mean_value_filter(const std::function<void(Range &, bool)> &reinit_vector)
+{
+  LinearOperator<Range, Range, Payload> return_op ((Payload()));
+
+  return_op.reinit_range_vector = reinit_vector;
+  return_op.reinit_domain_vector = reinit_vector;
+
+  return_op.vmult = [](Range &v, const Range &u)
+  {
+    const auto mean = u.mean_value();
+    for (types::global_dof_index i = 0; i<v.size(); ++i)
+      v(i) = u(i) - mean;
+  };
+
+  return_op.vmult_add = [](Range &v, const Range &u)
+  {
+    const auto mean = u.mean_value();
+    for (types::global_dof_index i = 0; i<v.size(); ++i)
+      v(i) += u(i) - mean;
+  };
+
+  return_op.Tvmult = return_op.vmult_add;
+  return_op.Tvmult_add = return_op.vmult_add;
+
+  return return_op;
+}
+
+
+/**
+ * @relatesalso LinearOperator
+ *
+ * Return a LinearOperator that acts as a mean value filter. The vmult()
+ * functions of this matrix subtract the mean values of the vector.
+ *
+ * The function takes a LinearOperator @p op and uses its range initializer
+ * to create an mean value filter operator. The function also ensures that
+ * the underlying Payload matches that of the input @p op.
+ *
+ * @ingroup LAOperators
+ */
+template <typename Range, typename Domain, typename Payload>
+LinearOperator<Range, Domain, Payload>
+mean_value_filter(const LinearOperator<Range, Domain, Payload> &op)
+{
+  auto return_op = mean_value_operator<Range, Payload>(op.reinit_range_vector);
+  static_cast<Payload &>(return_op) = op.identity_payload();
+
+  return return_op;
+}
+
+
 namespace internal
 {
   namespace LinearOperatorImplementation

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.