From 2538c8f0d7c73b60e3b8ed7be37d0cb048fcb00d Mon Sep 17 00:00:00 2001 From: bangerth Date: Tue, 22 Nov 2011 16:57:52 +0000 Subject: [PATCH] Add documentation. Revert order of arguments. git-svn-id: https://svn.dealii.org/trunk@24760 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/include/deal.II/base/function.h | 49 ++++++++++++++++--------- deal.II/source/base/function.cc | 11 ++++-- tests/base/functions_06.cc | 2 +- 3 files changed, 39 insertions(+), 23 deletions(-) diff --git a/deal.II/include/deal.II/base/function.h b/deal.II/include/deal.II/base/function.h index e356655847..8bc5f9110b 100644 --- a/deal.II/include/deal.II/base/function.h +++ b/deal.II/include/deal.II/base/function.h @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------- // $Id$ // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009, 2010 by the deal.II authors +// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009, 2010, 2011 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -712,7 +712,7 @@ class ComponentSelectFunction : public ConstantFunction * @code * double foo (const Point &); * @endcode - * into an object of type Function@. + * into an object of type Function@. * Since the argument returns a scalar, the result is clearly a * Function object for which function.n_components==1. * The class works by storing a pointer to the given function and @@ -720,22 +720,22 @@ class ComponentSelectFunction : public ConstantFunction * calls foo(p) and returns the corresponding value. It * also makes sure that component is in fact zero, as needs * be for scalar functions. - * + * * The class provides an easy way to turn a simple global function into * something that has the required Function@ interface for operations * like VectorTools::interpolate_boundary_values() etc., and thereby * allows for simpler experimenting without having to write all the * boiler plate code of declaring a class that is derived from Function * and implementing the Function::value() function. - * + * * The class gains additional expressvive power because the argument it * takes does not have to be a pointer to an actual function. Rather, it is - * a function object, i.e., it can also be the result of call to + * a function object, i.e., it can also be the result of call to * std::bind (or boost::bind) or some other object that can be called with * a single argument. For example, if you need a Function object that * returns the norm of a point, you could write it like so: * @code - * template + * template * class Norm : public Function { * public: * virtual double value (const Point &p, @@ -744,7 +744,7 @@ class ComponentSelectFunction : public ConstantFunction * return p.norm(); * } * }; - * + * * Norm<2> my_norm_object; * @endcode * and then pass the my_norm_object around, or you could write it @@ -752,11 +752,11 @@ class ComponentSelectFunction : public ConstantFunction * @code * ScalarFunctionFromFunctionObject my_norm_object (&Point::norm); * @endcode - * + * * Similarly, to generate an object that computes the distance to a point * q, we could do this: * @code - * template + * template * class DistanceTo : public Function { * public: * DistanceTo (const Point &q) : q(q) {} @@ -768,7 +768,7 @@ class ComponentSelectFunction : public ConstantFunction * private: * const Point q; * }; - * + * * Point<2> q (2,3); * DistanceTo<2> my_distance_object; * @endcode @@ -780,7 +780,7 @@ class ComponentSelectFunction : public ConstantFunction * std_cxx1x::_1)); * @endcode * The savings in work to write this are apparent. - * + * * @author Wolfgang Bangerth, 2011 */ template @@ -825,13 +825,26 @@ private: * object. The result is a vector Function object that returns zero in * each component except the single selected one where it returns the * value returned by the given as the first argument to the constructor. - * + * * @note In the above discussion, note the difference between the * (scalar) "function object" (i.e., a C++ object x that can * be called as in x(p)) and the capitalized (vector valued) * "Function object" (i.e., an object of a class that is derived from * the Function base class). - * + * + * To be more concrete, let us consider the following example: + * @code + * double one (const Point<2> &p) { return 1; } + * VectorFunctionFromScalarFunctionObject<2> + * component_mask (&one, 1, 3); + * @endcode + * Here, component_mask then represents a Function object + * that for every point returns the vector $(0, 1, 0)^T$, i.e. a mask + * function that could, for example, be passed to VectorTools::integrate_difference(). + * This effect can also be achieved using the ComponentSelectFunction + * class but is obviously easily extended to functions that are + * non-constant in their one component. + * * @author Wolfgang Bangerth, 2011 */ template @@ -842,7 +855,7 @@ public: * Given a function object that takes a Point and returns a double * value, convert this into an object that matches the Function@ * interface. - * + * * @param function_object The scalar function that will form one component * of the resulting Function object. * @param n_components The total number of vector components of the @@ -851,8 +864,8 @@ public: * filled by the first argument. **/ VectorFunctionFromScalarFunctionObject (const std_cxx1x::function &)> &function_object, - const unsigned int n_components, - const unsigned int selected_component); + const unsigned int selected_component, + const unsigned int n_components); /** * Return the value of the @@ -875,14 +888,14 @@ public: */ virtual void vector_value (const Point &p, Vector &values) const; - + private: /** * The function object which we call when this class's value() or * value_list() functions are called. **/ const std_cxx1x::function &)> function_object; - + /** * The vector component whose value is to be filled by the * given scalar function. diff --git a/deal.II/source/base/function.cc b/deal.II/source/base/function.cc index 47296a638f..02b7135367 100644 --- a/deal.II/source/base/function.cc +++ b/deal.II/source/base/function.cc @@ -540,13 +540,16 @@ ScalarFunctionFromFunctionObject::value (const Point &p, template VectorFunctionFromScalarFunctionObject:: VectorFunctionFromScalarFunctionObject (const std_cxx1x::function &)> &function_object, - const unsigned int n_components, - const unsigned int selected_component) + 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)); +} @@ -557,7 +560,7 @@ VectorFunctionFromScalarFunctionObject::value (const Point &p, { Assert (component < this->n_components, ExcIndexRange (component, 0, this->n_components)); - + if (component == selected_component) return function_object (p); else diff --git a/tests/base/functions_06.cc b/tests/base/functions_06.cc index 60fbf9bb88..853b5a5478 100644 --- a/tests/base/functions_06.cc +++ b/tests/base/functions_06.cc @@ -22,7 +22,7 @@ template void check1 () { VectorFunctionFromScalarFunctionObject - object (&Point::norm, 3, 1); + object (&Point::norm, 1, 3); Assert (object.n_components == 3, ExcInternalError()); -- 2.39.5