Reference documentation for deal.II version 9.0.0
function.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1998 - 2017 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>
26 #include <deal.II/base/point.h>
27 
28 #include <functional>
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 
140 template <int dim, typename RangeNumberType=double>
141 class Function : public FunctionTime<RangeNumberType>,
142  public Subscriptor
143 {
144 public:
149  static const unsigned int dimension = dim;
150 
154  const unsigned int n_components;
155 
161  Function (const unsigned int n_components = 1,
162  const RangeNumberType initial_time = 0.0);
163 
185  virtual ~Function () = 0;
186 
193  Function &operator= (const Function &f);
194 
201  virtual RangeNumberType value (const Point<dim> &p,
202  const unsigned int component = 0) const;
203 
211  virtual void vector_value (const Point<dim> &p,
212  Vector<RangeNumberType> &values) const;
213 
223  virtual void value_list (const std::vector<Point<dim> > &points,
224  std::vector<RangeNumberType> &values,
225  const unsigned int component = 0) const;
226 
237  virtual void vector_value_list (const std::vector<Point<dim> > &points,
238  std::vector<Vector<RangeNumberType> > &values) const;
239 
248  virtual void vector_values (const std::vector<Point<dim> > &points,
249  std::vector<std::vector<RangeNumberType> > &values) const;
250 
256  const unsigned int component = 0) const;
257 
261  virtual void vector_gradient (const Point<dim> &p,
262  std::vector<Tensor<1,dim, RangeNumberType> > &gradients) const;
263 
270  virtual void gradient_list (const std::vector<Point<dim> > &points,
271  std::vector<Tensor<1,dim, RangeNumberType> > &gradients,
272  const unsigned int component = 0) const;
273 
282  virtual void vector_gradients (const std::vector<Point<dim> > &points,
283  std::vector<std::vector<Tensor<1,dim, RangeNumberType> > > &gradients) const;
284 
294  virtual void vector_gradient_list (const std::vector<Point<dim> > &points,
295  std::vector<std::vector<Tensor<1,dim, RangeNumberType> > > &gradients) const;
296 
300  virtual RangeNumberType laplacian (const Point<dim> &p,
301  const unsigned int component = 0) const;
302 
307  virtual void vector_laplacian (const Point<dim> &p,
308  Vector<RangeNumberType> &values) const;
309 
313  virtual void laplacian_list (const std::vector<Point<dim> > &points,
314  std::vector<RangeNumberType> &values,
315  const unsigned int component = 0) const;
316 
320  virtual void vector_laplacian_list (const std::vector<Point<dim> > &points,
321  std::vector<Vector<RangeNumberType> > &values) const;
322 
328  const unsigned int component = 0) const;
329 
334  virtual void vector_hessian (const Point<dim> &p,
335  std::vector<SymmetricTensor<2,dim,RangeNumberType> > &values) const;
336 
340  virtual void hessian_list (const std::vector<Point<dim> > &points,
341  std::vector<SymmetricTensor<2,dim,RangeNumberType> > &values,
342  const unsigned int component = 0) const;
343 
347  virtual void vector_hessian_list (const std::vector<Point<dim> > &points,
348  std::vector<std::vector<SymmetricTensor<2,dim,RangeNumberType> > > &values) const;
349 
350 
356  std::size_t memory_consumption () const;
357 };
358 
359 
360 namespace Functions
361 {
362 
370  template <int dim, typename RangeNumberType=double>
371  class ConstantFunction : public Function<dim, RangeNumberType>
372  {
373  public:
378  ConstantFunction (const RangeNumberType value,
379  const unsigned int n_components = 1);
380 
385  ConstantFunction (const std::vector<RangeNumberType> &values);
386 
391  ConstantFunction (const Vector<RangeNumberType> &values);
392 
397  ConstantFunction (const RangeNumberType *begin_ptr, const unsigned int n_components);
398 
399  virtual RangeNumberType value (const Point<dim> &p,
400  const unsigned int component = 0) const;
401 
402  virtual void vector_value (const Point<dim> &p,
403  Vector<RangeNumberType> &return_value) const;
404 
405  virtual void value_list (const std::vector<Point<dim> > &points,
406  std::vector<RangeNumberType> &return_values,
407  const unsigned int component = 0) const;
408 
409  virtual void vector_value_list (const std::vector<Point<dim> > &points,
410  std::vector<Vector<RangeNumberType> > &return_values) const;
411 
413  const unsigned int component = 0) const;
414 
415  virtual void vector_gradient (const Point<dim> &p,
416  std::vector<Tensor<1,dim, RangeNumberType> > &gradients) const;
417 
418  virtual void gradient_list (const std::vector<Point<dim> > &points,
419  std::vector<Tensor<1,dim, RangeNumberType> > &gradients,
420  const unsigned int component = 0) const;
421 
422  virtual void vector_gradient_list (const std::vector<Point<dim> > &points,
423  std::vector<std::vector<Tensor<1,dim, RangeNumberType> > > &gradients) const;
424 
425  std::size_t memory_consumption () const;
426 
427  protected:
431  std::vector<RangeNumberType> function_value_vector;
432  };
433 
434 
435 
448  template <int dim, typename RangeNumberType=double>
449  class ZeroFunction : public ConstantFunction<dim, RangeNumberType>
450  {
451  public:
455  ZeroFunction (const unsigned int n_components = 1);
456  };
457 
458 }
459 
466 template <int dim, typename RangeNumberType=double>
468 
474 template <int dim, typename RangeNumberType=double>
476 
477 
478 
493 template <int dim, typename RangeNumberType=double>
494 class ComponentSelectFunction : public ConstantFunction<dim, RangeNumberType>
495 {
496 public:
502  ComponentSelectFunction (const unsigned int selected,
503  const RangeNumberType value,
504  const unsigned int n_components);
505 
510  ComponentSelectFunction (const unsigned int selected,
511  const unsigned int n_components);
512 
520  ComponentSelectFunction (const std::pair<unsigned int, unsigned int> &selected,
521  const unsigned int n_components);
522 
523 
538 
542  virtual void vector_value (const Point<dim> &p,
543  Vector<RangeNumberType> &return_value) const;
544 
551  virtual void vector_value_list (const std::vector<Point<dim> > &points,
552  std::vector<Vector<RangeNumberType> > &values) const;
553 
559  std::size_t memory_consumption () const;
560 
561 protected:
565  const std::pair<unsigned int,unsigned int> selected_components;
566 };
567 
568 
569 
649 template <int dim, typename RangeNumberType=double>
650 class ScalarFunctionFromFunctionObject : public Function<dim, RangeNumberType>
651 {
652 public:
658  ScalarFunctionFromFunctionObject (const std::function<RangeNumberType (const Point<dim> &)> &function_object);
659 
664  virtual RangeNumberType value (const Point<dim> &p,
665  const unsigned int component = 0) const;
666 
667 private:
672  const std::function<RangeNumberType (const Point<dim> &)> function_object;
673 };
674 
675 
676 
710 template <int dim, typename RangeNumberType=double>
711 class VectorFunctionFromScalarFunctionObject : public Function<dim, RangeNumberType>
712 {
713 public:
725  VectorFunctionFromScalarFunctionObject (const std::function<RangeNumberType (const Point<dim> &)> &function_object,
726  const unsigned int selected_component,
727  const unsigned int n_components);
728 
733  virtual RangeNumberType value (const Point<dim> &p,
734  const unsigned int component = 0) const;
735 
741  virtual void vector_value (const Point<dim> &p,
742  Vector<RangeNumberType> &values) const;
743 
744 private:
749  const std::function<RangeNumberType (const Point<dim> &)> function_object;
750 
755  const unsigned int selected_component;
756 };
757 
758 
793 template <int dim, typename RangeNumberType=double>
794 class VectorFunctionFromTensorFunction : public Function<dim, RangeNumberType>
795 {
796 public:
814  const unsigned int selected_component=0,
815  const unsigned int n_components=dim);
816 
821  virtual ~VectorFunctionFromTensorFunction() = default;
822 
826  virtual RangeNumberType value (const Point<dim> &p,
827  const unsigned int component = 0) const;
828 
834  virtual void vector_value (const Point<dim> &p,
835  Vector<RangeNumberType> &values) const;
836 
844  virtual void vector_value_list (const std::vector<Point<dim> > &points,
845  std::vector<Vector<RangeNumberType> > &value_list) const;
846 
847 private:
853 
860  const unsigned int selected_component;
861 };
862 
863 
864 #ifndef DOXYGEN
865 // icc 2018 complains about an undefined reference
866 // if we put this in the templates.h file
867 //
868 // The destructor is pure virtual so we can't default it
869 // in the declaration.
870 template <int dim, typename RangeNumberType>
871 inline
873 #endif
874 
875 
876 DEAL_II_NAMESPACE_CLOSE
877 
878 #endif
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const
virtual ~VectorFunctionFromTensorFunction()=default
virtual void vector_values(const std::vector< Point< dim > > &points, std::vector< std::vector< RangeNumberType > > &values) const
virtual void vector_value(const Point< dim > &p, Vector< RangeNumberType > &values) const
const unsigned int n_components
Definition: function.h:154
virtual void gradient_list(const std::vector< Point< dim > > &points, std::vector< Tensor< 1, dim, RangeNumberType > > &gradients, const unsigned int component=0) const
virtual void value_list(const std::vector< Point< dim > > &points, std::vector< RangeNumberType > &return_values, const unsigned int component=0) const
const std::function< RangeNumberType(const Point< dim > &)> function_object
Definition: function.h:672
virtual Tensor< 1, dim, RangeNumberType > gradient(const Point< dim > &p, const unsigned int component=0) const
VectorFunctionFromTensorFunction(const TensorFunction< 1, dim, RangeNumberType > &tensor_function, const unsigned int selected_component=0, const unsigned int n_components=dim)
static const unsigned int dimension
Definition: function.h:149
virtual void vector_laplacian(const Point< dim > &p, Vector< RangeNumberType > &values) const
const std::pair< unsigned int, unsigned int > selected_components
Definition: function.h:565
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const
virtual void hessian_list(const std::vector< Point< dim > > &points, std::vector< SymmetricTensor< 2, dim, RangeNumberType > > &values, const unsigned int component=0) const
const std::function< RangeNumberType(const Point< dim > &)> function_object
Definition: function.h:749
virtual void vector_hessian(const Point< dim > &p, std::vector< SymmetricTensor< 2, dim, RangeNumberType > > &values) const
virtual void vector_value_list(const std::vector< Point< dim > > &points, std::vector< Vector< RangeNumberType > > &return_values) const
virtual void vector_value_list(const std::vector< Point< dim > > &points, std::vector< Vector< RangeNumberType > > &values) const
virtual void value_list(const std::vector< Point< dim > > &points, std::vector< RangeNumberType > &values, const unsigned int component=0) const
virtual void vector_gradient(const Point< dim > &p, std::vector< Tensor< 1, dim, RangeNumberType > > &gradients) const
virtual Tensor< 1, dim, RangeNumberType > gradient(const Point< dim > &p, const unsigned int component=0) const
virtual void vector_value(const Point< dim > &p, Vector< RangeNumberType > &return_value) const
ComponentSelectFunction(const unsigned int selected, const RangeNumberType value, const unsigned int n_components)
virtual void vector_hessian_list(const std::vector< Point< dim > > &points, std::vector< std::vector< SymmetricTensor< 2, dim, RangeNumberType > > > &values) const
Function & operator=(const Function &f)
virtual void vector_value(const Point< dim > &p, Vector< RangeNumberType > &return_value) const
virtual SymmetricTensor< 2, dim, RangeNumberType > hessian(const Point< dim > &p, const unsigned int component=0) const
virtual void vector_laplacian_list(const std::vector< Point< dim > > &points, std::vector< Vector< RangeNumberType > > &values) const
virtual void vector_value_list(const std::vector< Point< dim > > &points, std::vector< Vector< RangeNumberType > > &value_list) const
virtual void vector_gradient_list(const std::vector< Point< dim > > &points, std::vector< std::vector< Tensor< 1, dim, RangeNumberType > > > &gradients) const
std::size_t memory_consumption() const
virtual void vector_value(const Point< dim > &p, Vector< RangeNumberType > &values) const
virtual void vector_gradient(const Point< dim > &p, std::vector< Tensor< 1, dim, RangeNumberType > > &gradients) const
ZeroFunction(const unsigned int n_components=1)
virtual ~Function()=0
virtual void gradient_list(const std::vector< Point< dim > > &points, std::vector< Tensor< 1, dim, RangeNumberType > > &gradients, const unsigned int component=0) const
virtual void vector_value(const Point< dim > &p, Vector< RangeNumberType > &values) const
virtual void substitute_function_value_with(const Functions::ConstantFunction< dim, RangeNumberType > &f)
virtual RangeNumberType laplacian(const Point< dim > &p, const unsigned int component=0) const
Definition: mpi.h:53
virtual void laplacian_list(const std::vector< Point< dim > > &points, std::vector< RangeNumberType > &values, const unsigned int component=0) const
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const
ConstantFunction(const RangeNumberType value, const unsigned int n_components=1)
const unsigned int selected_component
Definition: function.h:860
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const
virtual void vector_gradients(const std::vector< Point< dim > > &points, std::vector< std::vector< Tensor< 1, dim, RangeNumberType > > > &gradients) const
const unsigned int selected_component
Definition: function.h:755
ScalarFunctionFromFunctionObject(const std::function< RangeNumberType(const Point< dim > &)> &function_object)
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const
std::size_t memory_consumption() const
const TensorFunction< 1, dim, RangeNumberType > & tensor_function
Definition: function.h:852
std::vector< RangeNumberType > function_value_vector
Definition: function.h:431
VectorFunctionFromScalarFunctionObject(const std::function< RangeNumberType(const Point< dim > &)> &function_object, const unsigned int selected_component, const unsigned int n_components)
virtual void vector_gradient_list(const std::vector< Point< dim > > &points, std::vector< std::vector< Tensor< 1, dim, RangeNumberType > > > &gradients) const
virtual void vector_value_list(const std::vector< Point< dim > > &points, std::vector< Vector< RangeNumberType > > &values) const
Function(const unsigned int n_components=1, const RangeNumberType initial_time=0.0)