From 8573930165ce8763c6d3194c66106f5f39d5c36f Mon Sep 17 00:00:00 2001 From: guido Date: Wed, 12 Jul 2000 20:08:47 +0000 Subject: [PATCH] new function compute_mean_value in VectorTools git-svn-id: https://svn.dealii.org/trunk@3153 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/deal.II/include/numerics/vectors.h | 52 ++++++++++++++++++---- deal.II/deal.II/source/numerics/vectors.cc | 47 +++++++++++++++++++ 2 files changed, 90 insertions(+), 9 deletions(-) diff --git a/deal.II/deal.II/include/numerics/vectors.h b/deal.II/deal.II/include/numerics/vectors.h index 3e010209b4..3f51c7e1fb 100644 --- a/deal.II/deal.II/include/numerics/vectors.h +++ b/deal.II/deal.II/include/numerics/vectors.h @@ -504,13 +504,16 @@ class VectorTools /** * Mean-value filter for Stokes. * The pressure in Stokes' - * equations is determined up to a - * constant only. This function - * allows to subtract the mean - * value of the pressure. It is - * usually called in a - * preconditioner and generates - * updates with mean value zero. + * equations with only Dirichlet + * boundaries for the velocities + * is determined up to a constant + * only. This function allows to + * subtract the mean value of the + * pressure. It is usually called + * in a preconditioner and + * generates updates with mean + * value zero. The mean value is + * understood in the l1-sense. * * Apart from the vector @p{v} to * operate on, this function @@ -522,8 +525,39 @@ class VectorTools */ static void subtract_mean_value(Vector &v, const vector &p_select); - - + + /** + * Compute the mean value of one + * component of the solution. + * + * This function integrates the + * chosen component over the + * whole domain and returns the + * result. + * + * Subtracting this mean value + * from the node vector does not + * generally yield the desired + * result of a finite element + * function with mean value + * zero. In fact, it only works + * for Lagrangian + * elements. Therefore, it is + * necessary to compute the mean + * value and subtract it in the + * evaluation routine. + * + * So far, this is needed only in + * the error evaluation for + * Stokes with complete Dirichlet + * boundaries for the velocities. + */ + template + static double compute_mean_value (const DoFHandler &dof, + const Quadrature &quadrature, + Vector &v, + const unsigned int component); + /** * Exception */ diff --git a/deal.II/deal.II/source/numerics/vectors.cc b/deal.II/deal.II/source/numerics/vectors.cc index 38f8712d7d..5c439e143b 100644 --- a/deal.II/deal.II/source/numerics/vectors.cc +++ b/deal.II/deal.II/source/numerics/vectors.cc @@ -1110,6 +1110,45 @@ VectorTools::integrate_difference (const DoFHandler &dof, }; + +template +double +VectorTools::compute_mean_value (const DoFHandler &dof, + const Quadrature &quadrature, + Vector &v, + const unsigned int component) +{ + Assert (component < dof.get_fe().n_components(), + ExcIndexRange(component, 0, dof.get_fe().n_components())); + + FEValues fe(dof.get_fe(), quadrature, + UpdateFlags(update_JxW_values + | update_values)); + + DoFHandler::active_cell_iterator c; + vector > values(quadrature.n_quadrature_points, + Vector (dof.get_fe().n_components())); + + double mean = 0.; + double area = 0.; + // Compute mean value + for (c = dof.begin_active(); + c != dof.end(); + ++c) + { + fe.reinit (c); + fe.get_function_values(v, values); + for (unsigned int k=0; k< quadrature.n_quadrature_points; ++k) + { + mean += fe.JxW(k) * values[k](component); + area += fe.JxW(k); + } + } + return (mean/area); +} + + + // explicit instantiations template void VectorTools::integrate_difference (const DoFHandler &, @@ -1141,6 +1180,14 @@ void VectorTools::interpolate (const DoFHandler &, const Function &, Vector &); +template +double VectorTools::compute_mean_value (const DoFHandler &dof, + const Quadrature &quadrature, + Vector &v, + const unsigned int component); + + + // the following two functions are not derived from a template in 1d // and thus need no explicit instantiation #if deal_II_dimension > 1 -- 2.39.5