class VectorFunctionFromTensorFunction : public Function<dim>
{
public:
- /** Given a TensorFunction object that takes a <tt>Point</tt> and returns a <tt>Tensor<1,dim></tt>
- * value, convert this into an object that matches the Function@<dim@>
- * interface.
- *
- * By default, create a Vector object of the same size as <tt>tensor_function</tt>
- * returns, i.e., with <tt>dim</tt> components.
- *
- * @param tensor_function The TensorFunction that will form one component
- * of the resulting Vector Function object.
- * @param n_components The total number of vector components of the
- * resulting TensorFunction object.
- * @param selected_component The first component that should be
- * filled by the first argument. This should be such that the entire tensor_function
- * fits inside the <tt>n_component</tt> length return vector.
- */
- VectorFunctionFromTensorFunction (const TensorFunction<1,dim> &tensor_function,
- const unsigned int selected_component=0,
- const unsigned int n_components=dim);
-
- /**
- * This destructor is defined as
- * virtual so as to coincide with all
- * other aspects of class.
- */
- virtual ~VectorFunctionFromTensorFunction();
-
- /**
- * Return a single component of a
- * vector-valued function at a
- * given point.
- */
- virtual double value (const Point<dim> &p,
- const unsigned int component = 0) const;
-
- /**
- * Return all components of a
- * vector-valued function at a
- * given point.
- *
- * <tt>values</tt> shall have the right
- * size beforehand,
- * i.e. #n_components.
- */
- virtual void vector_value (const Point<dim> &p,
- Vector<double> &values) const;
-
- /**
- * Return all components of a
- * vector-valued function at a
- * list of points.
- *
- * <tt>value_list</tt> shall be the same
- * size as <tt>points</tt> and each element
- * of the vector will be passed to
- * vector_value() to evaluate
- * the function
- */
- virtual void vector_value_list (const std::vector<Point<dim> > &points,
- std::vector<Vector<double> > &value_list) const;
+ /**
+ * Given a TensorFunction object that takes a <tt>Point</tt> and returns a <tt>Tensor<1,dim></tt>
+ * value, convert this into an object that matches the Function@<dim@>
+ * interface.
+ *
+ * By default, create a Vector object of the same size as <tt>tensor_function</tt>
+ * returns, i.e., with <tt>dim</tt> components.
+ *
+ * @param tensor_function The TensorFunction that will form one component
+ * of the resulting Vector Function object.
+ * @param n_components The total number of vector components of the
+ * resulting TensorFunction object.
+ * @param selected_component The first component that should be
+ * filled by the first argument. This should be such that the entire tensor_function
+ * fits inside the <tt>n_component</tt> length return vector.
+ */
+ VectorFunctionFromTensorFunction (const TensorFunction<1,dim> &tensor_function,
+ const unsigned int selected_component=0,
+ const unsigned int n_components=dim);
+
+ /**
+ * This destructor is defined as
+ * virtual so as to coincide with all
+ * other aspects of class.
+ */
+ virtual ~VectorFunctionFromTensorFunction();
+
+ /**
+ * Return a single component of a
+ * vector-valued function at a
+ * given point.
+ */
+ virtual double value (const Point<dim> &p,
+ const unsigned int component = 0) const;
+
+ /**
+ * Return all components of a
+ * vector-valued function at a
+ * given point.
+ *
+ * <tt>values</tt> shall have the right
+ * size beforehand,
+ * i.e. #n_components.
+ */
+ virtual void vector_value (const Point<dim> &p,
+ Vector<double> &values) const;
+
+ /**
+ * Return all components of a
+ * vector-valued function at a
+ * list of points.
+ *
+ * <tt>value_list</tt> shall be the same
+ * size as <tt>points</tt> and each element
+ * of the vector will be passed to
+ * vector_value() to evaluate
+ * the function
+ */
+ virtual void vector_value_list (const std::vector<Point<dim> > &points,
+ std::vector<Vector<double> > &value_list) const;
private:
- /**
- * The TensorFunction object which we call when this class's vector_value()
- * or vector_value_list() functions are called.
- **/
- const TensorFunction<1,dim> & tensor_function;
-
- /**
- * The first vector component whose value is to be filled by the
- * given TensorFunction. The values will be placed in components
- * selected_component to selected_component+dim-1 for a <tt>TensorFunction<1,dim></tt> object.
- */
- const unsigned int selected_component;
+ /**
+ * The TensorFunction object which we call when this class's vector_value()
+ * or vector_value_list() functions are called.
+ **/
+ const TensorFunction<1,dim> & tensor_function;
+
+ /**
+ * The first vector component whose value is to be filled by the
+ * given TensorFunction. The values will be placed in components
+ * selected_component to selected_component+dim-1 for a <tt>TensorFunction<1,dim></tt> object.
+ */
+ const unsigned int selected_component;
};
*/
template <int dim>
VectorFunctionFromTensorFunction<dim>::VectorFunctionFromTensorFunction (const TensorFunction<1,dim>& tensor_function,
- const unsigned int selected_component,
- const unsigned int n_components)
-:
-Function<dim> (n_components),
-tensor_function (tensor_function),
-selected_component (selected_component)
+ const unsigned int selected_component,
+ const unsigned int n_components)
+ :
+ Function<dim> (n_components),
+ tensor_function (tensor_function),
+ selected_component (selected_component)
{
- // Verify that the Tensor<1,dim> will fit in the given length selected_components
- // and not hang over the end of the vector.
- Assert (0 <= selected_component,
- ExcIndexRange (selected_component,0,0));
- Assert (selected_component + dim - 1 < this->n_components,
- ExcIndexRange (selected_component, 0, this->n_components));
+ // Verify that the Tensor<1,dim> will fit in the given length selected_components
+ // and not hang over the end of the vector.
+ Assert (0 <= selected_component,
+ ExcIndexRange (selected_component,0,0));
+ Assert (selected_component + dim - 1 < this->n_components,
+ ExcIndexRange (selected_component, 0, this->n_components));
}
template <int dim>
inline
double VectorFunctionFromTensorFunction<dim>::value (const Point<dim> &p,
- const unsigned int component) const
+ const unsigned int component) const
{
Assert (component<this->n_components,
- ExcIndexRange(component, 0, this->n_components));
+ ExcIndexRange(component, 0, this->n_components));
// if the requested component is out of the range selected, then we
// can return early
return 0;
// otherwise retrieve the values from the <tt>tensor_function</tt> to be
- // placed at the <tt>selected_component</tt> to <tt>selected_component + dim - 1</tt>
- // elements of the <tt>Vector</tt> values and pick the correct one
- const Tensor<1,dim> tensor_value = tensor_function.value (p);
+ // placed at the <tt>selected_component</tt> to <tt>selected_component + dim - 1</tt>
+ // elements of the <tt>Vector</tt> values and pick the correct one
+ const Tensor<1,dim> tensor_value = tensor_function.value (p);
- return tensor_value[component-selected_component];
+ return tensor_value[component-selected_component];
}
void VectorFunctionFromTensorFunction<dim>::vector_value (const Point<dim> &p,
Vector<double> &values) const
{
- Assert(values.size() == this->n_components,
- ExcDimensionMismatch(values.size(),this->n_components));
+ Assert(values.size() == this->n_components,
+ ExcDimensionMismatch(values.size(),this->n_components));
- // Retrieve the values from the <tt>tensor_function</tt> to be
- // placed at the <tt>selected_component</tt> to <tt>selected_component + dim - 1</tt>
- // elements of the <tt>Vector</tt> values.
- const Tensor<1,dim> tensor_value = tensor_function.value (p);
+ // Retrieve the values from the <tt>tensor_function</tt> to be
+ // placed at the <tt>selected_component</tt> to <tt>selected_component + dim - 1</tt>
+ // elements of the <tt>Vector</tt> values.
+ const Tensor<1,dim> tensor_value = tensor_function.value (p);
- // First we make all elements of values = 0
- values = 0;
+ // First we make all elements of values = 0
+ values = 0;
- // Second we adjust the desired components to take on the values in <tt>tensor_value</tt>.
- for (unsigned int i=0; i<dim; ++i)
- values(i+selected_component) = tensor_value[i];
+ // Second we adjust the desired components to take on the values in <tt>tensor_value</tt>.
+ for (unsigned int i=0; i<dim; ++i)
+ values(i+selected_component) = tensor_value[i];
}
*/
template <int dim>
void VectorFunctionFromTensorFunction<dim>::vector_value_list (const std::vector<Point<dim> > &points,
- std::vector<Vector<double> > &value_list) const
+ std::vector<Vector<double> > &value_list) const
{
- Assert (value_list.size() == points.size(),
- ExcDimensionMismatch (value_list.size(), points.size()));
+ Assert (value_list.size() == points.size(),
+ ExcDimensionMismatch (value_list.size(), points.size()));
- const unsigned int n_points = points.size();
+ const unsigned int n_points = points.size();
- for (unsigned int p=0; p<n_points; ++p)
- VectorFunctionFromTensorFunction<dim>::vector_value (points[p], value_list[p]);
+ for (unsigned int p=0; p<n_points; ++p)
+ VectorFunctionFromTensorFunction<dim>::vector_value (points[p], value_list[p]);
}