From: Matthias Maier Date: Thu, 27 Aug 2015 02:34:55 +0000 (-0500) Subject: Refactor template definitions into function.templates.h X-Git-Tag: v8.4.0-rc2~541^2~6 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8ac3c8e1d7e3fee5cfdd11c4968ab481a3d36b8a;p=dealii.git Refactor template definitions into function.templates.h --- diff --git a/include/deal.II/base/function.templates.h b/include/deal.II/base/function.templates.h new file mode 100644 index 0000000000..d55257d629 --- /dev/null +++ b/include/deal.II/base/function.templates.h @@ -0,0 +1,711 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 1998 - 2015 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + +#ifndef dealii__function_templates_h +#define dealii__function_templates_h + + +#include + +#include +#include +#include +#include + +DEAL_II_NAMESPACE_OPEN + + +template +const unsigned int Function::dimension; + + +template +Function::Function (const unsigned int n_components, + const Number initial_time) + : + FunctionTime(initial_time), + n_components(n_components) +{ + // avoid the construction of function objects that don't return any + // values. This doesn't make much sense in the first place, but will lead + // to odd errors later on (happened to me in fact :-) + Assert (n_components > 0, ExcZero()); +} + + +template +Function::~Function () +{} + + + +template +Function &Function::operator= (const Function &f) +{ + (void)f; + AssertDimension (n_components, f.n_components); + return *this; +} + + +template +Number Function::value (const Point &, + const unsigned int) const +{ + Assert (false, ExcPureFunctionCalled()); + return 0; +} + + +template +void Function::vector_value (const Point &p, + Vector &v) const +{ + AssertDimension(v.size(), this->n_components); + for (unsigned int i=0; in_components; ++i) + v(i) = value(p, i); +} + + +template +void Function::value_list (const std::vector > &points, + std::vector &values, + const unsigned int component) const +{ + // check whether component is in the valid range is up to the derived + // class + Assert (values.size() == points.size(), + ExcDimensionMismatch(values.size(), points.size())); + + for (unsigned int i=0; ivalue (points[i], component); +} + + +template +void Function::vector_value_list (const std::vector > &points, + std::vector > &values) const +{ + // check whether component is in the valid range is up to the derived + // class + Assert (values.size() == points.size(), + ExcDimensionMismatch(values.size(), points.size())); + + for (unsigned int i=0; ivector_value (points[i], values[i]); +} + + +template +void Function::vector_values ( + const std::vector > &points, + std::vector > &values) const +{ + const unsigned int n = this->n_components; + AssertDimension (values.size(), n); + for (unsigned int i=0; i +Tensor<1,dim,Number> Function::gradient (const Point &, + const unsigned int) const +{ + Assert (false, ExcPureFunctionCalled()); + return Point(); +} + + +template +void Function::vector_gradient ( + const Point &p, + std::vector > &v) const +{ + AssertDimension(v.size(), this->n_components); + for (unsigned int i=0; in_components; ++i) + v[i] = gradient(p, i); +} + + +template +void Function::gradient_list ( + const std::vector > &points, + std::vector > &gradients, + const unsigned int component) const +{ + Assert (gradients.size() == points.size(), + ExcDimensionMismatch(gradients.size(), points.size())); + + for (unsigned int i=0; i +void Function::vector_gradient_list ( + const std::vector > &points, + std::vector > > &gradients) const +{ + Assert (gradients.size() == points.size(), + ExcDimensionMismatch(gradients.size(), points.size())); + + for (unsigned int i=0; i +void Function::vector_gradients ( + const std::vector > &points, + std::vector > > &values) const +{ + const unsigned int n = this->n_components; + AssertDimension (values.size(), n); + for (unsigned int i=0; i +Number 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 std::vector > &points, + std::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 std::vector > &points, + std::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 +std::size_t +Function::memory_consumption () const +{ + // only simple data elements, so use sizeof operator + return sizeof (*this); +} + + + +//--------------------------------------------------------------------------- + + + +template +ZeroFunction::ZeroFunction (const unsigned int n_components) + : + Function (n_components) +{} + + +template +ZeroFunction::~ZeroFunction () +{} + + +template +Number ZeroFunction::value (const Point &, + const unsigned int) const +{ + return 0.; +} + + +template +void ZeroFunction::vector_value (const Point &, + Vector &return_value) const +{ + Assert (return_value.size() == this->n_components, + ExcDimensionMismatch (return_value.size(), this->n_components)); + + std::fill (return_value.begin(), return_value.end(), 0.0); +} + + +template +void ZeroFunction::value_list ( + const std::vector > &points, + std::vector &values, + const unsigned int /*component*/) const +{ + (void)points; + Assert (values.size() == points.size(), + ExcDimensionMismatch(values.size(), points.size())); + + std::fill (values.begin(), values.end(), 0.); +} + + +template +void ZeroFunction::vector_value_list ( + const std::vector > &points, + std::vector > &values) const +{ + Assert (values.size() == points.size(), + ExcDimensionMismatch(values.size(), points.size())); + + for (unsigned int i=0; in_components, + ExcDimensionMismatch(values[i].size(), this->n_components)); + std::fill (values[i].begin(), values[i].end(), 0.); + }; +} + + +template +Tensor<1,dim,Number> ZeroFunction::gradient (const Point &, + const unsigned int) const +{ + return Tensor<1,dim,Number>(); +} + + +template +void ZeroFunction::vector_gradient ( + const Point &, + std::vector > &gradients) const +{ + Assert (gradients.size() == this->n_components, + ExcDimensionMismatch(gradients.size(), this->n_components)); + + for (unsigned int c=0; cn_components; ++c) + gradients[c].clear (); +} + + +template +void ZeroFunction::gradient_list ( + const std::vector > &points, + std::vector > &gradients, + const unsigned int /*component*/) const +{ + Assert (gradients.size() == points.size(), + ExcDimensionMismatch(gradients.size(), points.size())); + + for (unsigned int i=0; i +void ZeroFunction::vector_gradient_list ( + const std::vector > &points, + std::vector > > &gradients) const +{ + Assert (gradients.size() == points.size(), + ExcDimensionMismatch(gradients.size(), points.size())); + for (unsigned int i=0; in_components, + ExcDimensionMismatch(gradients[i].size(), this->n_components)); + for (unsigned int c=0; cn_components; ++c) + gradients[i][c].clear (); + }; +} + +//--------------------------------------------------------------------------- + + +template +ConstantFunction::ConstantFunction (const Number value, + const unsigned int n_components) + : + ZeroFunction (n_components), + function_value (value) +{} + + + +template +ConstantFunction::~ConstantFunction () {} + + + +template +Number ConstantFunction::value (const Point &, + const unsigned int component) const +{ + (void)component; + Assert (component < this->n_components, + ExcIndexRange (component, 0, this->n_components)); + return function_value; +} + + + +template +void ConstantFunction::vector_value (const Point &, + Vector &return_value) const +{ + Assert (return_value.size() == this->n_components, + ExcDimensionMismatch (return_value.size(), this->n_components)); + + std::fill (return_value.begin(), return_value.end(), function_value); +} + + + +template +void ConstantFunction::value_list ( + const std::vector > &points, + std::vector &values, + const unsigned int component) const +{ + (void)points; + (void)component; + Assert (component < this->n_components, + ExcIndexRange (component, 0, this->n_components)); + Assert (values.size() == points.size(), + ExcDimensionMismatch(values.size(), points.size())); + + std::fill (values.begin(), values.end(), function_value); +} + + + +template +void ConstantFunction::vector_value_list ( + const std::vector > &points, + std::vector > &values) const +{ + Assert (values.size() == points.size(), + ExcDimensionMismatch(values.size(), points.size())); + + for (unsigned int i=0; in_components, + ExcDimensionMismatch(values[i].size(), this->n_components)); + std::fill (values[i].begin(), values[i].end(), function_value); + }; +} + + + +template +std::size_t +ConstantFunction::memory_consumption () const +{ + // only simple data elements, so use sizeof operator + return sizeof (*this); +} + +//--------------------------------------------------------------------------- + +template +ComponentSelectFunction:: +ComponentSelectFunction (const unsigned int selected, + const Number value, + const unsigned int n_components) + : + ConstantFunction (value, n_components), + selected_components(std::make_pair(selected,selected+1)) +{} + + + +template +ComponentSelectFunction:: +ComponentSelectFunction (const unsigned int selected, + const unsigned int n_components) + : + ConstantFunction (1., n_components), + selected_components(std::make_pair(selected,selected+1)) +{ + Assert (selected < n_components, + ExcIndexRange (selected, 0, n_components)); +} + + + +template +ComponentSelectFunction:: +ComponentSelectFunction (const std::pair &selected, + const unsigned int n_components) + : + ConstantFunction (1., n_components), + selected_components(selected) +{ + Assert (selected_components.first < selected_components.second, + ExcMessage ("The upper bound of the interval must be larger than " + "the lower bound")); + Assert (selected_components.second <= n_components, + ExcMessage ("The upper bound of the interval must be less than " + "or equal to the total number of vector components")); +} + + + +template +void ComponentSelectFunction::vector_value ( + const Point &, + Vector &return_value) const +{ + Assert (return_value.size() == this->n_components, + ExcDimensionMismatch (return_value.size(), this->n_components)); + + return_value = 0; + std::fill (return_value.begin()+selected_components.first, + return_value.begin()+selected_components.second, + this->function_value); +} + + + +template +void ComponentSelectFunction::vector_value_list ( + const std::vector > &points, + std::vector > &values) const +{ + Assert (values.size() == points.size(), + ExcDimensionMismatch(values.size(), points.size())); + + for (unsigned int i=0; i::vector_value (points[i], + values[i]); +} + + + +template +std::size_t +ComponentSelectFunction::memory_consumption () const +{ + // only simple data elements, so use sizeof operator + return sizeof (*this); +} + + +template +ScalarFunctionFromFunctionObject:: +ScalarFunctionFromFunctionObject (const std_cxx11::function &)> &function_object) + : + Function(1), + function_object (function_object) +{} + + + +template +Number +ScalarFunctionFromFunctionObject::value (const Point &p, + const unsigned int component) const +{ + (void)component; + Assert (component == 0, + ExcMessage ("This object represents only scalar functions")); + return function_object (p); +} + + + +template +VectorFunctionFromScalarFunctionObject:: +VectorFunctionFromScalarFunctionObject ( + const std_cxx11::function &)> &function_object, + const unsigned int selected_component, + const unsigned int n_components) + : + Function(n_components), + function_object (function_object), + selected_component (selected_component) +{ + Assert (selected_component < this->n_components, + ExcIndexRange (selected_component, 0, this->n_components)); +} + + + +template +Number +VectorFunctionFromScalarFunctionObject::value ( + const Point &p, + const unsigned int component) const +{ + Assert (component < this->n_components, + ExcIndexRange (component, 0, this->n_components)); + + if (component == selected_component) + return function_object (p); + else + return 0; +} + + + +template +void +VectorFunctionFromScalarFunctionObject:: +vector_value (const Point &p, + Vector &values) const +{ + AssertDimension(values.size(), this->n_components); + + // set everything to zero, and then the right component to its correct + // value + values = 0; + values(selected_component) = function_object (p); +} + + + +/** + * The constructor for VectorFunctionFromTensorFunction which + * initiates the return vector to be size n_components. + */ +template +VectorFunctionFromTensorFunction::VectorFunctionFromTensorFunction ( + const TensorFunction<1,dim,Number> &tensor_function, + const unsigned int selected_component, + const unsigned int n_components) + : + Function (n_components), + tensor_function (tensor_function), + selected_component (selected_component) +{ + + // Verify that the Tensor<1,dim,Number> will fit in the given length + // selected_components and not hang over the end of the vector. + Assert (selected_component + dim - 1 < this->n_components, + ExcIndexRange (selected_component, 0, this->n_components)); +} + + +template +VectorFunctionFromTensorFunction::~VectorFunctionFromTensorFunction () +{} + + +template +inline +Number VectorFunctionFromTensorFunction::value (const Point &p, + const unsigned int component) const +{ + Assert (componentn_components, + ExcIndexRange(component, 0, this->n_components)); + + // if the requested component is out of the range selected, then we can + // return early + if ((component < selected_component) + || + (component >= selected_component+dim)) + return 0; + + // otherwise retrieve the values from the tensor_function to be + // placed at the selected_component to + // selected_component + dim - 1 elements of the Vector + // values and pick the correct one + const Tensor<1,dim,Number> tensor_value = tensor_function.value (p); + + return tensor_value[component-selected_component]; +} + + +template +inline +void VectorFunctionFromTensorFunction::vector_value ( + const Point &p, + Vector &values) const +{ + Assert(values.size() == this->n_components, + ExcDimensionMismatch(values.size(),this->n_components)); + + // Retrieve the values from the tensor_function to be placed at + // the selected_component to + // selected_component + dim - 1 elements of the Vector + // values. + const Tensor<1,dim,Number> tensor_value = tensor_function.value (p); + + // First we make all elements of values = 0 + values = 0; + + // Second we adjust the desired components to take on the values in + // tensor_value. + for (unsigned int i=0; ivector_value_list is the interface for giving + * a list of points (vector >) of which to evaluate + * using the vector_value member function. Again, this function + * is written so as to not replicate the function definition but passes + * each point on to vector_value to be evaluated. + */ +template +void VectorFunctionFromTensorFunction::vector_value_list ( + const std::vector > &points, + std::vector > &value_list) const +{ + Assert (value_list.size() == points.size(), + ExcDimensionMismatch (value_list.size(), points.size())); + + const unsigned int n_points = points.size(); + + for (unsigned int p=0; p::vector_value(points[p], + value_list[p]); +} + + +DEAL_II_NAMESPACE_CLOSE + +#endif /* dealii__function_templates_h */ diff --git a/source/base/function.cc b/source/base/function.cc index 91950f7dcc..e1e7a04229 100644 --- a/source/base/function.cc +++ b/source/base/function.cc @@ -13,679 +13,10 @@ // // --------------------------------------------------------------------- -#include -#include -#include -#include -#include +#include DEAL_II_NAMESPACE_OPEN - -template -const unsigned int Function::dimension; - - -template -Function::Function (const unsigned int n_components, - const Number initial_time) - : - FunctionTime(initial_time), - n_components(n_components) -{ - // avoid the construction of function - // objects that don't return any - // values. This doesn't make much sense in - // the first place, but will lead to odd - // errors later on (happened to me in fact - // :-) - Assert (n_components > 0, - ExcZero()); -} - - -template -Function::~Function () -{} - - - -template -Function &Function::operator= (const Function &f) -{ - (void)f; - AssertDimension (n_components, f.n_components); - return *this; -} - - -template -Number Function::value (const Point &, - const unsigned int) const -{ - Assert (false, ExcPureFunctionCalled()); - return 0; -} - - -template -void Function::vector_value (const Point &p, - Vector &v) const -{ - AssertDimension(v.size(), this->n_components); - for (unsigned int i=0; in_components; ++i) - v(i) = value(p, i); -} - - -template -void Function::value_list (const std::vector > &points, - std::vector &values, - const unsigned int component) const -{ - // check whether component is in - // the valid range is up to the - // derived class - Assert (values.size() == points.size(), - ExcDimensionMismatch(values.size(), points.size())); - - for (unsigned int i=0; ivalue (points[i], component); -} - - -template -void Function::vector_value_list (const std::vector > &points, - std::vector > &values) const -{ - // check whether component is in - // the valid range is up to the - // derived class - Assert (values.size() == points.size(), - ExcDimensionMismatch(values.size(), points.size())); - - for (unsigned int i=0; ivector_value (points[i], values[i]); -} - - -template -void Function::vector_values ( - const std::vector > &points, - std::vector > &values) const -{ - const unsigned int n = this->n_components; - AssertDimension (values.size(), n); - for (unsigned int i=0; i -Tensor<1,dim,Number> Function::gradient (const Point &, - const unsigned int) const -{ - Assert (false, ExcPureFunctionCalled()); - return Point(); -} - - -template -void Function::vector_gradient ( - const Point &p, - std::vector > &v) const -{ - AssertDimension(v.size(), this->n_components); - for (unsigned int i=0; in_components; ++i) - v[i] = gradient(p, i); -} - - -template -void Function::gradient_list (const std::vector > &points, - std::vector > &gradients, - const unsigned int component) const -{ - Assert (gradients.size() == points.size(), - ExcDimensionMismatch(gradients.size(), points.size())); - - for (unsigned int i=0; i -void Function::vector_gradient_list (const std::vector > &points, - std::vector > > &gradients) const -{ - Assert (gradients.size() == points.size(), - ExcDimensionMismatch(gradients.size(), points.size())); - - for (unsigned int i=0; i -void Function::vector_gradients ( - const std::vector > &points, - std::vector > > &values) const -{ - const unsigned int n = this->n_components; - AssertDimension (values.size(), n); - for (unsigned int i=0; i -Number 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 std::vector > &points, - std::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 std::vector > &points, - std::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 -std::size_t -Function::memory_consumption () const -{ - // only simple data elements, so - // use sizeof operator - return sizeof (*this); -} - - -//--------------------------------------------------------------------------- - -template -ZeroFunction::ZeroFunction (const unsigned int n_components) - : - Function (n_components) -{} - - -template -ZeroFunction::~ZeroFunction () -{} - - -template -Number ZeroFunction::value (const Point &, - const unsigned int) const -{ - return 0.; -} - - -template -void ZeroFunction::vector_value (const Point &, - Vector &return_value) const -{ - Assert (return_value.size() == this->n_components, - ExcDimensionMismatch (return_value.size(), this->n_components)); - - std::fill (return_value.begin(), return_value.end(), 0.0); -} - - -template -void ZeroFunction::value_list (const std::vector > &points, - std::vector &values, - const unsigned int /*component*/) const -{ - (void)points; - Assert (values.size() == points.size(), - ExcDimensionMismatch(values.size(), points.size())); - - std::fill (values.begin(), values.end(), 0.); -} - - -template -void ZeroFunction::vector_value_list (const std::vector > &points, - std::vector > &values) const -{ - Assert (values.size() == points.size(), - ExcDimensionMismatch(values.size(), points.size())); - - for (unsigned int i=0; in_components, - ExcDimensionMismatch(values[i].size(), this->n_components)); - std::fill (values[i].begin(), values[i].end(), 0.); - }; -} - - -template -Tensor<1,dim,Number> ZeroFunction::gradient (const Point &, - const unsigned int) const -{ - return Tensor<1,dim,Number>(); -} - - -template -void ZeroFunction::vector_gradient (const Point &, - std::vector > &gradients) const -{ - Assert (gradients.size() == this->n_components, - ExcDimensionMismatch(gradients.size(), this->n_components)); - - for (unsigned int c=0; cn_components; ++c) - gradients[c].clear (); -} - - -template -void ZeroFunction::gradient_list (const std::vector > &points, - std::vector > &gradients, - const unsigned int /*component*/) const -{ - Assert (gradients.size() == points.size(), - ExcDimensionMismatch(gradients.size(), points.size())); - - for (unsigned int i=0; i -void ZeroFunction::vector_gradient_list (const std::vector > &points, - std::vector > > &gradients) const -{ - Assert (gradients.size() == points.size(), - ExcDimensionMismatch(gradients.size(), points.size())); - for (unsigned int i=0; in_components, - ExcDimensionMismatch(gradients[i].size(), this->n_components)); - for (unsigned int c=0; cn_components; ++c) - gradients[i][c].clear (); - }; -} - -//--------------------------------------------------------------------------- - - -template -ConstantFunction::ConstantFunction (const Number value, - const unsigned int n_components) - : - ZeroFunction (n_components), - function_value (value) -{} - - - -template -ConstantFunction::~ConstantFunction () {} - - - -template -Number ConstantFunction::value (const Point &, - const unsigned int component) const -{ - (void)component; - Assert (component < this->n_components, - ExcIndexRange (component, 0, this->n_components)); - return function_value; -} - - - -template -void ConstantFunction::vector_value (const Point &, - Vector &return_value) const -{ - Assert (return_value.size() == this->n_components, - ExcDimensionMismatch (return_value.size(), this->n_components)); - - std::fill (return_value.begin(), return_value.end(), function_value); -} - - - -template -void ConstantFunction::value_list (const std::vector > &points, - std::vector &values, - const unsigned int component) const -{ - (void)points; - (void)component; - Assert (component < this->n_components, - ExcIndexRange (component, 0, this->n_components)); - Assert (values.size() == points.size(), - ExcDimensionMismatch(values.size(), points.size())); - - std::fill (values.begin(), values.end(), function_value); -} - - - -template -void ConstantFunction::vector_value_list (const std::vector > &points, - std::vector > &values) const -{ - Assert (values.size() == points.size(), - ExcDimensionMismatch(values.size(), points.size())); - - for (unsigned int i=0; in_components, - ExcDimensionMismatch(values[i].size(), this->n_components)); - std::fill (values[i].begin(), values[i].end(), function_value); - }; -} - - - -template -std::size_t -ConstantFunction::memory_consumption () const -{ - // only simple data elements, so - // use sizeof operator - return sizeof (*this); -} - -//--------------------------------------------------------------------------- - -template -ComponentSelectFunction:: -ComponentSelectFunction (const unsigned int selected, - const Number value, - const unsigned int n_components) - : - ConstantFunction (value, n_components), - selected_components(std::make_pair(selected,selected+1)) -{} - - - -template -ComponentSelectFunction:: -ComponentSelectFunction (const unsigned int selected, - const unsigned int n_components) - : - ConstantFunction (1., n_components), - selected_components(std::make_pair(selected,selected+1)) -{ - Assert (selected < n_components, - ExcIndexRange (selected, 0, n_components)); -} - - - -template -ComponentSelectFunction:: -ComponentSelectFunction (const std::pair &selected, - const unsigned int n_components) - : - ConstantFunction (1., n_components), - selected_components(selected) -{ - Assert (selected_components.first < selected_components.second, - ExcMessage ("The upper bound of the interval must be larger than " - "the lower bound")); - Assert (selected_components.second <= n_components, - ExcMessage ("The upper bound of the interval must be less than " - "or equal to the total number of vector components")); -} - - - -template -void ComponentSelectFunction::vector_value (const Point &, - Vector &return_value) const -{ - Assert (return_value.size() == this->n_components, - ExcDimensionMismatch (return_value.size(), this->n_components)); - - return_value = 0; - std::fill (return_value.begin()+selected_components.first, - return_value.begin()+selected_components.second, - this->function_value); -} - - - -template -void ComponentSelectFunction::vector_value_list (const std::vector > &points, - std::vector > &values) const -{ - Assert (values.size() == points.size(), - ExcDimensionMismatch(values.size(), points.size())); - - for (unsigned int i=0; i::vector_value (points[i], - values[i]); -} - - - -template -std::size_t -ComponentSelectFunction::memory_consumption () const -{ - // only simple data elements, so - // use sizeof operator - return sizeof (*this); -} - - -template -ScalarFunctionFromFunctionObject:: -ScalarFunctionFromFunctionObject (const std_cxx11::function &)> &function_object) - : - Function(1), - function_object (function_object) -{} - - - -template -Number -ScalarFunctionFromFunctionObject::value (const Point &p, - const unsigned int component) const -{ - (void)component; - Assert (component == 0, - ExcMessage ("This object represents only scalar functions")); - return function_object (p); -} - - - -template -VectorFunctionFromScalarFunctionObject:: -VectorFunctionFromScalarFunctionObject (const std_cxx11::function &)> &function_object, - const unsigned int selected_component, - const unsigned int n_components) - : - Function(n_components), - function_object (function_object), - selected_component (selected_component) -{ - Assert (selected_component < this->n_components, - ExcIndexRange (selected_component, 0, this->n_components)); -} - - - -template -Number -VectorFunctionFromScalarFunctionObject::value (const Point &p, - const unsigned int component) const -{ - Assert (component < this->n_components, - ExcIndexRange (component, 0, this->n_components)); - - if (component == selected_component) - return function_object (p); - else - return 0; -} - - - -template -void -VectorFunctionFromScalarFunctionObject:: -vector_value (const Point &p, - Vector &values) const -{ - AssertDimension(values.size(), this->n_components); - - // set everything to zero, and then the right component to its correct value - values = 0; - values(selected_component) = function_object (p); -} - - - -/** - * The constructor for VectorFunctionFromTensorFunction which initiates the return vector - * to be size n_components. - */ -template -VectorFunctionFromTensorFunction::VectorFunctionFromTensorFunction (const TensorFunction<1,dim,Number> &tensor_function, - const unsigned int selected_component, - const unsigned int n_components) - : - Function (n_components), - tensor_function (tensor_function), - selected_component (selected_component) -{ - - // Verify that the Tensor<1,dim,Number> will fit in the given length selected_components - // and not hang over the end of the vector. - Assert (selected_component + dim - 1 < this->n_components, - ExcIndexRange (selected_component, 0, this->n_components)); -} - - -template -VectorFunctionFromTensorFunction::~VectorFunctionFromTensorFunction () -{} - - -template -inline -Number VectorFunctionFromTensorFunction::value (const Point &p, - const unsigned int component) const -{ - Assert (componentn_components, - ExcIndexRange(component, 0, this->n_components)); - - // if the requested component is out of the range selected, then we - // can return early - if ((component < selected_component) - || - (component >= selected_component+dim)) - return 0; - - // otherwise retrieve the values from the tensor_function to be - // placed at the selected_component to selected_component + dim - 1 - // elements of the Vector values and pick the correct one - const Tensor<1,dim,Number> tensor_value = tensor_function.value (p); - - return tensor_value[component-selected_component]; -} - - -template -inline -void VectorFunctionFromTensorFunction::vector_value (const Point &p, - Vector &values) const -{ - Assert(values.size() == this->n_components, - ExcDimensionMismatch(values.size(),this->n_components)); - - // Retrieve the values from the tensor_function to be - // placed at the selected_component to selected_component + dim - 1 - // elements of the Vector values. - const Tensor<1,dim,Number> tensor_value = tensor_function.value (p); - - // First we make all elements of values = 0 - values = 0; - - // Second we adjust the desired components to take on the values in tensor_value. - for (unsigned int i=0; ivector_value_list is the interface for giving a list of - * points (vector >) of which to evaluate using the vector_value - * member function. Again, this function is written so as to not replicate the function definition - * but passes each point on to vector_value to be evaluated. - */ -template -void VectorFunctionFromTensorFunction::vector_value_list (const std::vector > &points, - std::vector > &value_list) const -{ - Assert (value_list.size() == points.size(), - ExcDimensionMismatch (value_list.size(), points.size())); - - const unsigned int n_points = points.size(); - - for (unsigned int p=0; p::vector_value (points[p], value_list[p]); -} - - - - // explicit instantiations template class Function<1>;