Reference documentation for deal.II version 8.5.1
function.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1998 - 2016 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii__function_h
17 #define dealii__function_h
18 
19 
20 #include <deal.II/base/config.h>
21 #include <deal.II/base/exceptions.h>
22 #include <deal.II/base/function_time.h>
23 #include <deal.II/base/subscriptor.h>
24 #include <deal.II/base/tensor.h>
25 #include <deal.II/base/symmetric_tensor.h>
26 #include <deal.II/base/point.h>
27 #include <deal.II/base/std_cxx11/function.h>
28 
29 #include <vector>
30 
31 DEAL_II_NAMESPACE_OPEN
32 
33 
34 template <typename number> class Vector;
35 template <int rank, int dim, typename Number> class TensorFunction;
36 
130 template <int dim, typename Number=double>
131 class Function : public FunctionTime<Number>,
132  public Subscriptor
133 {
134 public:
139  static const unsigned int dimension = dim;
140 
144  const unsigned int n_components;
145 
151  Function (const unsigned int n_components = 1,
152  const Number initial_time = 0.0);
153 
175  virtual ~Function () = 0;
176 
183  Function &operator= (const Function &f);
184 
191  virtual Number value (const Point<dim> &p,
192  const unsigned int component = 0) const;
193 
201  virtual void vector_value (const Point<dim> &p,
202  Vector<Number> &values) const;
203 
213  virtual void value_list (const std::vector<Point<dim> > &points,
214  std::vector<Number> &values,
215  const unsigned int component = 0) const;
216 
227  virtual void vector_value_list (const std::vector<Point<dim> > &points,
228  std::vector<Vector<Number> > &values) const;
229 
238  virtual void vector_values (const std::vector<Point<dim> > &points,
239  std::vector<std::vector<Number> > &values) const;
240 
245  virtual Tensor<1,dim, Number> gradient (const Point<dim> &p,
246  const unsigned int component = 0) const;
247 
251  virtual void vector_gradient (const Point<dim> &p,
252  std::vector<Tensor<1,dim, Number> > &gradients) const;
253 
260  virtual void gradient_list (const std::vector<Point<dim> > &points,
261  std::vector<Tensor<1,dim, Number> > &gradients,
262  const unsigned int component = 0) const;
263 
272  virtual void vector_gradients (const std::vector<Point<dim> > &points,
273  std::vector<std::vector<Tensor<1,dim, Number> > > &gradients) const;
274 
284  virtual void vector_gradient_list (const std::vector<Point<dim> > &points,
285  std::vector<std::vector<Tensor<1,dim, Number> > > &gradients) const;
286 
290  virtual Number laplacian (const Point<dim> &p,
291  const unsigned int component = 0) const;
292 
297  virtual void vector_laplacian (const Point<dim> &p,
298  Vector<Number> &values) const;
299 
303  virtual void laplacian_list (const std::vector<Point<dim> > &points,
304  std::vector<Number> &values,
305  const unsigned int component = 0) const;
306 
310  virtual void vector_laplacian_list (const std::vector<Point<dim> > &points,
311  std::vector<Vector<Number> > &values) const;
312 
318  const unsigned int component = 0) const;
319 
324  virtual void vector_hessian (const Point<dim> &p,
325  std::vector<SymmetricTensor<2,dim,Number> > &values) const;
326 
330  virtual void hessian_list (const std::vector<Point<dim> > &points,
331  std::vector<SymmetricTensor<2,dim,Number> > &values,
332  const unsigned int component = 0) const;
333 
337  virtual void vector_hessian_list (const std::vector<Point<dim> > &points,
338  std::vector<std::vector<SymmetricTensor<2,dim,Number> > > &values) const;
339 
340 
346  std::size_t memory_consumption () const;
347 };
348 
349 
350 
363 template <int dim, typename Number=double>
364 class ZeroFunction : public Function<dim, Number>
365 {
366 public:
370  ZeroFunction (const unsigned int n_components = 1);
371 
376  virtual ~ZeroFunction ();
377 
378  virtual Number value (const Point<dim> &p,
379  const unsigned int component) const;
380 
381  virtual void vector_value (const Point<dim> &p,
382  Vector<Number> &return_value) const;
383 
384  virtual void value_list (const std::vector<Point<dim> > &points,
385  std::vector<Number> &values,
386  const unsigned int component = 0) const;
387 
388  virtual void vector_value_list (const std::vector<Point<dim> > &points,
389  std::vector<Vector<Number> > &values) const;
390 
391  virtual Tensor<1,dim, Number> gradient (const Point<dim> &p,
392  const unsigned int component = 0) const;
393 
394  virtual void vector_gradient (const Point<dim> &p,
395  std::vector<Tensor<1,dim, Number> > &gradients) const;
396 
397  virtual void gradient_list (const std::vector<Point<dim> > &points,
398  std::vector<Tensor<1,dim, Number> > &gradients,
399  const unsigned int component = 0) const;
400 
401  virtual void vector_gradient_list (const std::vector<Point<dim> > &points,
402  std::vector<std::vector<Tensor<1,dim, Number> > > &gradients) const;
403 };
404 
405 
406 
424 template <int dim, typename Number=double>
425 class ConstantFunction : public ZeroFunction<dim, Number>
426 {
427 public:
432  ConstantFunction (const Number value,
433  const unsigned int n_components = 1);
434 
439  ConstantFunction (const std::vector<Number> &values);
440 
445  ConstantFunction (const Vector<Number> &values);
446 
451  ConstantFunction (const Number *begin_ptr, const unsigned int n_components);
452 
456  virtual ~ConstantFunction ();
457 
458  virtual Number value (const Point<dim> &p,
459  const unsigned int component) const;
460 
461  virtual void vector_value (const Point<dim> &p,
462  Vector<Number> &return_value) const;
463 
464  virtual void value_list (const std::vector<Point<dim> > &points,
465  std::vector<Number> &return_values,
466  const unsigned int component = 0) const;
467 
468  virtual void vector_value_list (const std::vector<Point<dim> > &points,
469  std::vector<Vector<Number> > &return_values) const;
470 
471  std::size_t memory_consumption () const;
472 
473 protected:
477  std::vector<Number> function_value_vector;
478 };
479 
480 
495 template <int dim, typename Number=double>
496 class ComponentSelectFunction : public ConstantFunction<dim, Number>
497 {
498 public:
504  ComponentSelectFunction (const unsigned int selected,
505  const Number value,
506  const unsigned int n_components);
507 
512  ComponentSelectFunction (const unsigned int selected,
513  const unsigned int n_components);
514 
522  ComponentSelectFunction (const std::pair<unsigned int, unsigned int> &selected,
523  const unsigned int n_components);
524 
525 
540 
544  virtual void vector_value (const Point<dim> &p,
545  Vector<Number> &return_value) const;
546 
553  virtual void vector_value_list (const std::vector<Point<dim> > &points,
554  std::vector<Vector<Number> > &values) const;
555 
561  std::size_t memory_consumption () const;
562 
563 protected:
567  const std::pair<unsigned int,unsigned int> selected_components;
568 };
569 
570 
571 
649 template <int dim, typename Number=double>
650 class ScalarFunctionFromFunctionObject : public Function<dim, Number>
651 {
652 public:
658  ScalarFunctionFromFunctionObject (const std_cxx11::function<Number (const Point<dim> &)> &function_object);
659 
664  virtual Number value (const Point<dim> &p,
665  const unsigned int component = 0) const;
666 
667 private:
672  const std_cxx11::function<Number (const Point<dim> &)> function_object;
673 };
674 
675 
676 
710 template <int dim, typename Number=double>
712 {
713 public:
725  VectorFunctionFromScalarFunctionObject (const std_cxx11::function<Number (const Point<dim> &)> &function_object,
726  const unsigned int selected_component,
727  const unsigned int n_components);
728 
733  virtual Number value (const Point<dim> &p,
734  const unsigned int component = 0) const;
735 
741  virtual void vector_value (const Point<dim> &p,
742  Vector<Number> &values) const;
743 
744 private:
749  const std_cxx11::function<Number (const Point<dim> &)> function_object;
750 
755  const unsigned int selected_component;
756 };
757 
758 
793 template <int dim, typename Number=double>
794 class VectorFunctionFromTensorFunction : public Function<dim, Number>
795 {
796 public:
814  const unsigned int selected_component=0,
815  const unsigned int n_components=dim);
816 
822 
826  virtual Number value (const Point<dim> &p,
827  const unsigned int component = 0) const;
828 
834  virtual void vector_value (const Point<dim> &p,
835  Vector<Number> &values) const;
836 
844  virtual void vector_value_list (const std::vector<Point<dim> > &points,
845  std::vector<Vector<Number> > &value_list) const;
846 
847 private:
853 
860  const unsigned int selected_component;
861 };
862 
863 
864 DEAL_II_NAMESPACE_CLOSE
865 
866 #endif
ComponentSelectFunction(const unsigned int selected, const Number value, const unsigned int n_components)
virtual void substitute_function_value_with(const ConstantFunction< dim, Number > &f)
virtual void laplacian_list(const std::vector< Point< dim > > &points, std::vector< Number > &values, const unsigned int component=0) const
const std_cxx11::function< Number(const Point< dim > &)> function_object
Definition: function.h:672
VectorFunctionFromScalarFunctionObject(const std_cxx11::function< Number(const Point< dim > &)> &function_object, const unsigned int selected_component, const unsigned int n_components)
virtual void vector_value(const Point< dim > &p, Vector< Number > &values) const
virtual void vector_hessian_list(const std::vector< Point< dim > > &points, std::vector< std::vector< SymmetricTensor< 2, dim, Number > > > &values) const
virtual void vector_gradient_list(const std::vector< Point< dim > > &points, std::vector< std::vector< Tensor< 1, dim, Number > > > &gradients) const
virtual void hessian_list(const std::vector< Point< dim > > &points, std::vector< SymmetricTensor< 2, dim, Number > > &values, const unsigned int component=0) const
Function(const unsigned int n_components=1, const Number initial_time=0.0)
virtual void vector_laplacian(const Point< dim > &p, Vector< Number > &values) const
ZeroFunction(const unsigned int n_components=1)
virtual void vector_value_list(const std::vector< Point< dim > > &points, std::vector< Vector< Number > > &values) const
virtual ~Function()=0
virtual Tensor< 1, dim, Number > gradient(const Point< dim > &p, const unsigned int component=0) const
virtual void vector_value_list(const std::vector< Point< dim > > &points, std::vector< Vector< Number > > &values) const
virtual Number value(const Point< dim > &p, const unsigned int component=0) const
virtual ~ConstantFunction()
virtual void vector_value(const Point< dim > &p, Vector< Number > &return_value) const
virtual void vector_values(const std::vector< Point< dim > > &points, std::vector< std::vector< Number > > &values) const
virtual void vector_hessian(const Point< dim > &p, std::vector< SymmetricTensor< 2, dim, Number > > &values) const
Function & operator=(const Function &f)
static const unsigned int dimension
Definition: function.h:139
const unsigned int n_components
Definition: function.h:144
virtual void vector_value(const Point< dim > &p, Vector< Number > &return_value) const
virtual void vector_value_list(const std::vector< Point< dim > > &points, std::vector< Vector< Number > > &return_values) const
virtual Tensor< 1, dim, Number > gradient(const Point< dim > &p, const unsigned int component=0) const
std::size_t memory_consumption() const
virtual void vector_value_list(const std::vector< Point< dim > > &points, std::vector< Vector< Number > > &value_list) const
const TensorFunction< 1, dim, Number > & tensor_function
Definition: function.h:852
const std_cxx11::function< Number(const Point< dim > &)> function_object
Definition: function.h:749
virtual void vector_gradient(const Point< dim > &p, std::vector< Tensor< 1, dim, Number > > &gradients) const
virtual SymmetricTensor< 2, dim, Number > hessian(const Point< dim > &p, const unsigned int component=0) const
const std::pair< unsigned int, unsigned int > selected_components
Definition: function.h:567
virtual void value_list(const std::vector< Point< dim > > &points, std::vector< Number > &values, const unsigned int component=0) const
virtual void vector_gradients(const std::vector< Point< dim > > &points, std::vector< std::vector< Tensor< 1, dim, Number > > > &gradients) const
virtual void gradient_list(const std::vector< Point< dim > > &points, std::vector< Tensor< 1, dim, Number > > &gradients, const unsigned int component=0) const
const unsigned int selected_component
Definition: function.h:755
virtual Number laplacian(const Point< dim > &p, const unsigned int component=0) const
std::vector< Number > function_value_vector
Definition: function.h:477
VectorFunctionFromTensorFunction(const TensorFunction< 1, dim, Number > &tensor_function, const unsigned int selected_component=0, const unsigned int n_components=dim)
ConstantFunction(const Number value, const unsigned int n_components=1)
virtual Number value(const Point< dim > &p, const unsigned int component=0) const
virtual ~ZeroFunction()
virtual Number value(const Point< dim > &p, const unsigned int component=0) const
virtual void gradient_list(const std::vector< Point< dim > > &points, std::vector< Tensor< 1, dim, Number > > &gradients, const unsigned int component=0) const
virtual Number value(const Point< dim > &p, const unsigned int component) const
virtual void value_list(const std::vector< Point< dim > > &points, std::vector< Number > &values, const unsigned int component=0) const
virtual void vector_gradient(const Point< dim > &p, std::vector< Tensor< 1, dim, Number > > &gradients) const
ScalarFunctionFromFunctionObject(const std_cxx11::function< Number(const Point< dim > &)> &function_object)
virtual void vector_value_list(const std::vector< Point< dim > > &points, std::vector< Vector< Number > > &values) const
virtual void vector_value(const Point< dim > &p, Vector< Number > &return_value) const
std::size_t memory_consumption() const
virtual Number value(const Point< dim > &p, const unsigned int component) const
virtual void vector_value(const Point< dim > &p, Vector< Number > &values) const
virtual void vector_gradient_list(const std::vector< Point< dim > > &points, std::vector< std::vector< Tensor< 1, dim, Number > > > &gradients) const
virtual void value_list(const std::vector< Point< dim > > &points, std::vector< Number > &return_values, const unsigned int component=0) const
const unsigned int selected_component
Definition: function.h:860
virtual void vector_value(const Point< dim > &p, Vector< Number > &values) const
virtual Number value(const Point< dim > &p, const unsigned int component=0) const
virtual void vector_laplacian_list(const std::vector< Point< dim > > &points, std::vector< Vector< Number > > &values) const