From: kanschat Date: Wed, 8 Dec 1999 17:28:53 +0000 (+0000) Subject: CosineFunction added X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2bb2ffa28942ac7916cf82ce214f53b54ea8e8ce;p=dealii-svn.git CosineFunction added git-svn-id: https://svn.dealii.org/trunk@2014 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/base/include/base/function_lib.h b/deal.II/base/include/base/function_lib.h index c2012f76d8..a4615e3095 100644 --- a/deal.II/base/include/base/function_lib.h +++ b/deal.II/base/include/base/function_lib.h @@ -63,6 +63,57 @@ class PillowFunction : public Function const unsigned int component = 0) const; }; +/** + * Cosine-shaped pillow function. + * This is another function with zero boundary values on $[-1,1]^d$. In the interior + * it is the product of $\cos(\pi/2 x_i)$. + * @author Guido Kanschat, 1999 + */ +template +class CosineFunction : public Function +{ + public: + /** + * The value at a single point. + */ + virtual double value (const Point &p, + const unsigned int component = 0) const; + + /** + * Values at multiple points. + */ + virtual void value_list (const vector > &points, + vector &values, + const unsigned int component = 0) const; + + /** + * Gradient at a single point. + */ + virtual Tensor<1,dim> gradient (const Point &p, + const unsigned int component = 0) const; + + /** + * Gradients at multiple points. + */ + virtual void gradient_list (const vector > &points, + vector > &gradients, + const unsigned int component = 0) const; + + /** + * Laplacian at a single point. + */ + double laplacian(const Point &p, + const unsigned int component = 0) const; + + /** + * Laplacian at multiple points. + */ + void laplacian_list(const vector > &points, + vector &values, + const unsigned int component = 0) const; +}; + + /** * Singularity on the L-shaped domain in 2D. * @author Guido Kanschat, 1999 diff --git a/deal.II/base/source/function_lib.cc b/deal.II/base/source/function_lib.cc index 575730f767..e5c57b153e 100644 --- a/deal.II/base/source/function_lib.cc +++ b/deal.II/base/source/function_lib.cc @@ -166,6 +166,162 @@ PillowFunction::gradient_list (const vector > &points, ////////////////////////////////////////////////////////////////////// +template +double +CosineFunction::value (const Point &p, + const unsigned int) const +{ + switch(dim) + { + case 1: + return cos(M_PI_2*p(0)); + case 2: + return cos(M_PI_2*p(0)) * cos(M_PI_2*p(1)); + case 3: + return cos(M_PI_2*p(0)) * cos(M_PI_2*p(1)) * cos(M_PI_2*p(2)); + default: + Assert(false, ExcNotImplemented()); + } + return 0.; +} + +template +void +CosineFunction::value_list (const vector > &points, + vector &values, + const unsigned int) const +{ + Assert (values.size() == points.size(), + ExcVectorHasWrongSize(values.size(), points.size())); + + for (unsigned int i=0;i& p = points[i]; + switch(dim) + { + case 1: + values[i] = cos(M_PI_2*p(0)); + break; + case 2: + values[i] = cos(M_PI_2*p(0)) * cos(M_PI_2*p(1)); + break; + case 3: + values[i] = cos(M_PI_2*p(0)) * cos(M_PI_2*p(1)) * cos(M_PI_2*p(2)); + break; + default: + Assert(false, ExcNotImplemented()); + } + } +} + +template +double +CosineFunction::laplacian (const Point &p, + const unsigned int) const +{ + switch(dim) + { + case 1: + return -M_PI_2*M_PI_2* cos(M_PI_2*p(0)); + case 2: + return -2*M_PI_2*M_PI_2* cos(M_PI_2*p(0)) * cos(M_PI_2*p(1)); + case 3: + return -3*M_PI_2*M_PI_2* cos(M_PI_2*p(0)) * cos(M_PI_2*p(1)) * cos(M_PI_2*p(2)); + default: + Assert(false, ExcNotImplemented()); + } + return 0.; +} + +template +void +CosineFunction::laplacian_list (const vector > &points, + vector &values, + const unsigned int) const +{ + Assert (values.size() == points.size(), + ExcVectorHasWrongSize(values.size(), points.size())); + + for (unsigned int i=0;i& p = points[i]; + switch(dim) + { + case 1: + values[i] = -M_PI_2*M_PI_2* cos(M_PI_2*p(0)); + break; + case 2: + values[i] = -2*M_PI_2*M_PI_2* cos(M_PI_2*p(0)) * cos(M_PI_2*p(1)); + break; + case 3: + values[i] = -3*M_PI_2*M_PI_2* cos(M_PI_2*p(0)) * cos(M_PI_2*p(1)) * cos(M_PI_2*p(2)); + break; + default: + Assert(false, ExcNotImplemented()); + } + } +} + +template +Tensor<1,dim> +CosineFunction::gradient (const Point &p, + const unsigned int) const +{ + Tensor<1,dim> result; + switch(dim) + { + case 1: + result[0] = -M_PI_2* sin(M_PI_2*p(0)); + break; + case 2: + result[0] = -M_PI_2* sin(M_PI_2*p(0)) * cos(M_PI_2*p(1)); + result[1] = -M_PI_2* cos(M_PI_2*p(0)) * sin(M_PI_2*p(1)); + break; + case 3: + result[0] = -M_PI_2* sin(M_PI_2*p(0)) * cos(M_PI_2*p(1)) * cos(M_PI_2*p(2)); + result[1] = -M_PI_2* cos(M_PI_2*p(0)) * sin(M_PI_2*p(1)) * cos(M_PI_2*p(2)); + result[2] = -M_PI_2* cos(M_PI_2*p(0)) * cos(M_PI_2*p(1)) * sin(M_PI_2*p(2)); + break; + default: + Assert(false, ExcNotImplemented()); + } + return result; +} + +template +void +CosineFunction::gradient_list (const vector > &points, + vector > &gradients, + const unsigned int) const +{ + Assert (gradients.size() == points.size(), + ExcVectorHasWrongSize(gradients.size(), points.size())); + + for (unsigned int i=0;i& p = points[i]; + switch(dim) + { + case 1: + gradients[i][0] = -M_PI_2* sin(M_PI_2*p(0)); + break; + case 2: + gradients[i][0] = -M_PI_2* sin(M_PI_2*p(0)) * cos(M_PI_2*p(1)); + gradients[i][1] = -M_PI_2* cos(M_PI_2*p(0)) * sin(M_PI_2*p(1)); + return; + case 3: + gradients[i][0] = -M_PI_2* sin(M_PI_2*p(0)) * cos(M_PI_2*p(1)) * cos(M_PI_2*p(2)); + gradients[i][1] = -M_PI_2* cos(M_PI_2*p(0)) * sin(M_PI_2*p(1)) * cos(M_PI_2*p(2)); + gradients[i][2] = -M_PI_2* cos(M_PI_2*p(0)) * cos(M_PI_2*p(1)) * sin(M_PI_2*p(2)); + break; + default: + Assert(false, ExcNotImplemented()); + } + } +} + +////////////////////////////////////////////////////////////////////// + double LSingularityFunction::value (const Point<2> &p, @@ -337,3 +493,6 @@ SlitSingularityFunction::gradient_list (const vector > &points, template PillowFunction<1>; template PillowFunction<2>; template PillowFunction<3>; +template CosineFunction<1>; +template CosineFunction<2>; +template CosineFunction<3>;