From beffe4e6f530dbb853f3ef474b15aefde3ad101c Mon Sep 17 00:00:00 2001 From: Guido Kanschat Date: Thu, 25 May 2000 21:24:21 +0000 Subject: [PATCH] ComponentSelectFunction added, CosineFunction fixed git-svn-id: https://svn.dealii.org/trunk@2946 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/include/base/function.h | 48 +++++++++++ deal.II/base/source/function.cc | 120 +++++++++++++++++++-------- deal.II/base/source/function_lib.cc | 2 +- 3 files changed, 134 insertions(+), 36 deletions(-) diff --git a/deal.II/base/include/base/function.h b/deal.II/base/include/base/function.h index 5b44c49f2d..2be2230aee 100644 --- a/deal.II/base/include/base/function.h +++ b/deal.II/base/include/base/function.h @@ -462,5 +462,53 @@ class ConstantFunction : public ZeroFunction const double function_value; }; +/** + * This is a constant vector-valued function, that is different from + * zero only in one component. + * + * It is especially useful as a weight function for + * @p{VectorTools::integrate_difference}, where it allows to integrate + * only one component. + * @author Guido Kanschat, 2000 + */ +template +class ComponentSelectFunction : public ConstantFunction +{ + public: + /** + * Constructor. Provide the + * component selected, the value + * for that component and the + * number of components. + */ + ComponentSelectFunction (const unsigned int selected, + const double value, + const unsigned int n_components); + + /** + * Return the value of the function + * at the given point for all + * components. + */ + virtual void vector_value (const Point &p, + Vector &return_value) const; + + /** + * Set #values# to the point values + * of the function at the #points#, + * for all components. + * It is assumed that #values# + * already has the right size, i.e. + * the same size as the #points# + * array. + */ + virtual void vector_value_list (const vector > &points, + vector > &values) const; + + protected: + const unsigned int selected; +}; + + #endif diff --git a/deal.II/base/source/function.cc b/deal.II/base/source/function.cc index 7ce1f9fa73..aa19b5436e 100644 --- a/deal.II/base/source/function.cc +++ b/deal.II/base/source/function.cc @@ -123,17 +123,69 @@ void Function::vector_gradient_list (const vector > &point for (unsigned int component=0; component +double Function::laplacian (const Point &, + const unsigned int) const +{ + Assert (false, ExcPureFunctionCalled()); + return 0; +} + + +template +void Function::vector_laplacian (const Point &, + Vector &) const +{ + Assert (false, ExcPureFunctionCalled()); +} + + + +template +void Function::laplacian_list (const vector > &points, + vector &laplacians, + const unsigned int component) const +{ + // check whether component is in + // the valid range is up to the + // derived class + Assert (laplacians.size() == points.size(), + ExcDimensionMismatch(laplacians.size(), points.size())); + + for (unsigned int i=0; ilaplacian (points[i], component); +} + + +template +void Function::vector_laplacian_list (const vector > &points, + vector > &laplacians) const +{ + // check whether component is in + // the valid range is up to the + // derived class + Assert (laplacians.size() == points.size(), + ExcDimensionMismatch(laplacians.size(), points.size())); + for (unsigned int i=0; ivector_laplacian (points[i], laplacians[i]); +} + +//------------------------------------------------------------// template ZeroFunction::ZeroFunction (const unsigned int n_components) : Function (n_components) -{}; +{} template -ZeroFunction::~ZeroFunction () {}; +ZeroFunction::~ZeroFunction () +{} template @@ -230,6 +282,8 @@ void ZeroFunction::vector_gradient_list (const vector > &p }; }; +//------------------------------------------------------------// + template ConstantFunction::ConstantFunction (const double value, @@ -287,52 +341,45 @@ void ConstantFunction::vector_value_list (const vector > &points }; }; +//------------------------------------------------------------// template -double Function::laplacian (const Point &, - const unsigned int) const -{ - Assert (false, ExcPureFunctionCalled()); - return 0; -} - - -template -void Function::vector_laplacian (const Point &, - Vector &) const -{ - Assert (false, ExcPureFunctionCalled()); -} +ComponentSelectFunction::ComponentSelectFunction (const unsigned int selected, + const double value, + const unsigned int n_components) + : + ConstantFunction (value, n_components), + selected(selected) +{} template -void Function::laplacian_list (const vector > &points, - vector &laplacians, - const unsigned int component) const +void ComponentSelectFunction::vector_value (const Point &, + Vector &return_value) const { - // check whether component is in - // the valid range is up to the - // derived class - Assert (laplacians.size() == points.size(), - ExcDimensionMismatch(laplacians.size(), points.size())); + Assert (return_value.size() == n_components, + ExcDimensionMismatch (return_value.size(), n_components)); - for (unsigned int i=0; ilaplacian (points[i], component); + fill_n (return_value.begin(), n_components, 0.); + return_value(selected) = function_value; } + template -void Function::vector_laplacian_list (const vector > &points, - vector > &laplacians) const +void ComponentSelectFunction::vector_value_list (const vector > &points, + vector > &values) const { - // check whether component is in - // the valid range is up to the - // derived class - Assert (laplacians.size() == points.size(), - ExcDimensionMismatch(laplacians.size(), points.size())); + Assert (values.size() == points.size(), + ExcDimensionMismatch(values.size(), points.size())); for (unsigned int i=0; ivector_laplacian (points[i], laplacians[i]); + { + Assert (values[i].size() == n_components, + ExcDimensionMismatch(values[i].size(), n_components)); + fill_n (values[i].begin(), n_components, 0.); + values[i](selected) = function_value; + } } @@ -341,9 +388,12 @@ void Function::vector_laplacian_list (const vector > &points, template class Function<1>; template class ZeroFunction<1>; template class ConstantFunction<1>; +template class ComponentSelectFunction<1>; template class Function<2>; template class ZeroFunction<2>; template class ConstantFunction<2>; +template class ComponentSelectFunction<2>; template class Function<3>; template class ZeroFunction<3>; template class ConstantFunction<3>; +template class ComponentSelectFunction<3>; diff --git a/deal.II/base/source/function_lib.cc b/deal.II/base/source/function_lib.cc index 13d8225c68..001bc23227 100644 --- a/deal.II/base/source/function_lib.cc +++ b/deal.II/base/source/function_lib.cc @@ -319,7 +319,7 @@ CosineFunction::gradient_list (const vector > &points, 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; + break; 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)); -- 2.39.5