From 7f305c0cbca98ceddf8f046ee2f0ee1f860c36bd Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Thu, 2 Apr 1998 12:19:43 +0000 Subject: [PATCH] Add zero-function. git-svn-id: https://svn.dealii.org/trunk@117 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/include/base/function.h | 44 +++++++++++++++++++ deal.II/base/source/function.cc | 44 +++++++++++++++++++ .../deal.II/Attic/examples/poisson/poisson.cc | 9 ++-- tests/big-tests/poisson/poisson.cc | 9 ++-- 4 files changed, 98 insertions(+), 8 deletions(-) diff --git a/deal.II/base/include/base/function.h b/deal.II/base/include/base/function.h index 5ecd440b72..ef4f87b458 100644 --- a/deal.II/base/include/base/function.h +++ b/deal.II/base/include/base/function.h @@ -79,6 +79,50 @@ class Function { +/** + Provide a function which always returns zero. Obviously, also the derivates + of this function are zero. + + This function is of use when you want to implement homogeneous boundary + conditions. +*/ +template +class ZeroFunction : public Function { + public: + /** + * Return the value of the function + * at the given point. + */ + virtual double operator () (const Point &p) const; + + /** + * Set #values# to the point values + * of the function at the #points#. + * It is assumed that #values# be + * empty. + */ + virtual void value_list (const vector > &points, + vector &values) const; + + /** + * Return the gradient of the function + * at the given point. + */ + virtual Point gradient (const Point &p) const; + + /** + * Set #gradients# to the gradients of + * the function at the #points#. + * It is assumed that #values# be + * empty. + */ + virtual void gradient_list (const vector > &points, + vector > &gradients) const; +}; + + + + /*---------------------------- function.h ---------------------------*/ /* end of #ifndef __function_H */ #endif diff --git a/deal.II/base/source/function.cc b/deal.II/base/source/function.cc index 7de474db45..20f52784f0 100644 --- a/deal.II/base/source/function.cc +++ b/deal.II/base/source/function.cc @@ -50,6 +50,50 @@ void Function::gradient_list (const vector > &points, + + +template +double ZeroFunction::operator () (const Point &) const { + return 0.; +}; + + + +template +void ZeroFunction::value_list (const vector > &points, + vector &values) const { + Assert (values.size() == 0, + ExcVectorNotEmpty()); + + values.reserve (points.size()); + values.insert (values.begin(), points.size(), 0.); +}; + + + +template +Point ZeroFunction::gradient (const Point &) const { + return Point(); +}; + + + +template +void ZeroFunction::gradient_list (const vector > &points, + vector > &values) const { + Assert (values.size() == 0, + ExcVectorNotEmpty()); + + values.reserve (points.size()); + values.insert (values.begin(), points.size(), Point()); +}; + + + + // explicit instantiations template class Function<1>; template class Function<2>; + +template class ZeroFunction<1>; +template class ZeroFunction<2>; diff --git a/deal.II/deal.II/Attic/examples/poisson/poisson.cc b/deal.II/deal.II/Attic/examples/poisson/poisson.cc index 7f65197b91..ce07669646 100644 --- a/deal.II/deal.II/Attic/examples/poisson/poisson.cc +++ b/deal.II/deal.II/Attic/examples/poisson/poisson.cc @@ -170,11 +170,12 @@ int main () { cout << "Assembling matrices..." << endl; FEValues<2>::UpdateStruct update_flags; - update_flags.q_points = true; - update_flags.gradients = true; - update_flags.jacobians = true; - update_flags.JxW_values = true; + update_flags.q_points = update_flags.gradients = true; + update_flags.jacobians = update_flags.JxW_values = true; + ProblemBase<2>::DirichletBC dirichlet_bc; + ZeroFunction<2> zero; + dirichlet_bc[0] = &zero; problem.assemble (equation, quadrature, fe, update_flags, dirichlet_bc); cout << "Solving..." << endl; diff --git a/tests/big-tests/poisson/poisson.cc b/tests/big-tests/poisson/poisson.cc index 7f65197b91..ce07669646 100644 --- a/tests/big-tests/poisson/poisson.cc +++ b/tests/big-tests/poisson/poisson.cc @@ -170,11 +170,12 @@ int main () { cout << "Assembling matrices..." << endl; FEValues<2>::UpdateStruct update_flags; - update_flags.q_points = true; - update_flags.gradients = true; - update_flags.jacobians = true; - update_flags.JxW_values = true; + update_flags.q_points = update_flags.gradients = true; + update_flags.jacobians = update_flags.JxW_values = true; + ProblemBase<2>::DirichletBC dirichlet_bc; + ZeroFunction<2> zero; + dirichlet_bc[0] = &zero; problem.assemble (equation, quadrature, fe, update_flags, dirichlet_bc); cout << "Solving..." << endl; -- 2.39.5