Reference documentation for deal.II version Git d228448 2017-10-17 21:17:08 +0200
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>
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 
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 namespace Functions
351 {
352 
360  template <int dim, typename Number=double>
361  class ConstantFunction : public Function<dim, Number>
362  {
363  public:
368  ConstantFunction (const Number value,
369  const unsigned int n_components = 1);
370 
375  ConstantFunction (const std::vector<Number> &values);
376 
381  ConstantFunction (const Vector<Number> &values);
382 
387  ConstantFunction (const Number *begin_ptr, const unsigned int n_components);
388 
389  virtual Number value (const Point<dim> &p,
390  const unsigned int component = 0) const;
391 
392  virtual void vector_value (const Point<dim> &p,
393  Vector<Number> &return_value) const;
394 
395  virtual void value_list (const std::vector<Point<dim> > &points,
396  std::vector<Number> &return_values,
397  const unsigned int component = 0) const;
398 
399  virtual void vector_value_list (const std::vector<Point<dim> > &points,
400  std::vector<Vector<Number> > &return_values) const;
401 
402  virtual Tensor<1,dim, Number> gradient (const Point<dim> &p,
403  const unsigned int component = 0) const;
404 
405  virtual void vector_gradient (const Point<dim> &p,
406  std::vector<Tensor<1,dim, Number> > &gradients) const;
407 
408  virtual void gradient_list (const std::vector<Point<dim> > &points,
409  std::vector<Tensor<1,dim, Number> > &gradients,
410  const unsigned int component = 0) const;
411 
412  virtual void vector_gradient_list (const std::vector<Point<dim> > &points,
413  std::vector<std::vector<Tensor<1,dim, Number> > > &gradients) const;
414 
415  std::size_t memory_consumption () const;
416 
417  protected:
421  std::vector<Number> function_value_vector;
422  };
423 
424 
425 
438  template <int dim, typename Number=double>
439  class ZeroFunction : public ConstantFunction<dim, Number>
440  {
441  public:
445  ZeroFunction (const unsigned int n_components = 1);
446 
447  };
448 
449 }
450 
457 template <int dim, typename Number=double>
459 
465 template <int dim, typename Number=double>
466 using ZeroFunction DEAL_II_DEPRECATED = Functions::ZeroFunction<dim,Number>;
467 
468 
469 
484 template <int dim, typename Number=double>
485 class ComponentSelectFunction : public ConstantFunction<dim, Number>
486 {
487 public:
493  ComponentSelectFunction (const unsigned int selected,
494  const Number value,
495  const unsigned int n_components);
496 
501  ComponentSelectFunction (const unsigned int selected,
502  const unsigned int n_components);
503 
511  ComponentSelectFunction (const std::pair<unsigned int, unsigned int> &selected,
512  const unsigned int n_components);
513 
514 
529 
533  virtual void vector_value (const Point<dim> &p,
534  Vector<Number> &return_value) const;
535 
542  virtual void vector_value_list (const std::vector<Point<dim> > &points,
543  std::vector<Vector<Number> > &values) const;
544 
550  std::size_t memory_consumption () const;
551 
552 protected:
556  const std::pair<unsigned int,unsigned int> selected_components;
557 };
558 
559 
560 
638 template <int dim, typename Number=double>
639 class ScalarFunctionFromFunctionObject : public Function<dim, Number>
640 {
641 public:
647  ScalarFunctionFromFunctionObject (const std::function<Number (const Point<dim> &)> &function_object);
648 
653  virtual Number value (const Point<dim> &p,
654  const unsigned int component = 0) const;
655 
656 private:
661  const std::function<Number (const Point<dim> &)> function_object;
662 };
663 
664 
665 
699 template <int dim, typename Number=double>
701 {
702 public:
714  VectorFunctionFromScalarFunctionObject (const std::function<Number (const Point<dim> &)> &function_object,
715  const unsigned int selected_component,
716  const unsigned int n_components);
717 
722  virtual Number value (const Point<dim> &p,
723  const unsigned int component = 0) const;
724 
730  virtual void vector_value (const Point<dim> &p,
731  Vector<Number> &values) const;
732 
733 private:
738  const std::function<Number (const Point<dim> &)> function_object;
739 
744  const unsigned int selected_component;
745 };
746 
747 
782 template <int dim, typename Number=double>
783 class VectorFunctionFromTensorFunction : public Function<dim, Number>
784 {
785 public:
803  const unsigned int selected_component=0,
804  const unsigned int n_components=dim);
805 
810  virtual ~VectorFunctionFromTensorFunction() = default;
811 
815  virtual Number value (const Point<dim> &p,
816  const unsigned int component = 0) const;
817 
823  virtual void vector_value (const Point<dim> &p,
824  Vector<Number> &values) const;
825 
833  virtual void vector_value_list (const std::vector<Point<dim> > &points,
834  std::vector<Vector<Number> > &value_list) const;
835 
836 private:
842 
849  const unsigned int selected_component;
850 };
851 
852 
853 #ifndef DOXYGEN
854 // icc 2018 complains about an undefined reference
855 // if we put this in the templates.h file
856 //
857 // The destructor is pure virtual so we can't default it
858 // in the declaration.
859 template <int dim, typename Number>
860 inline
862 #endif
863 
864 
865 DEAL_II_NAMESPACE_CLOSE
866 
867 #endif
virtual void vector_value(const Point< dim > &p, Vector< Number > &values) const
virtual void vector_values(const std::vector< Point< dim > > &points, std::vector< std::vector< Number > > &values) const
ComponentSelectFunction(const unsigned int selected, const Number value, const unsigned int n_components)
virtual Number value(const Point< dim > &p, const unsigned int component=0) const
virtual void vector_gradient(const Point< dim > &p, std::vector< Tensor< 1, dim, Number > > &gradients) const
virtual void vector_hessian(const Point< dim > &p, std::vector< SymmetricTensor< 2, dim, Number > > &values) 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
virtual void vector_value(const Point< dim > &p, Vector< Number > &values) const
std::size_t memory_consumption() const
virtual void vector_gradient(const Point< dim > &p, std::vector< Tensor< 1, dim, Number > > &gradients) const
virtual void vector_gradient_list(const std::vector< Point< dim > > &points, std::vector< std::vector< Tensor< 1, dim, Number > > > &gradients) const
virtual void vector_value(const Point< dim > &p, Vector< Number > &values) const
Function(const unsigned int n_components=1, const Number initial_time=0.0)
const std::function< Number(const Point< dim > &)> function_object
Definition: function.h:738
virtual Number value(const Point< dim > &p, const unsigned int component=0) const
virtual Number laplacian(const Point< dim > &p, const unsigned int component=0) const
virtual ~Function()=0
virtual void vector_value_list(const std::vector< Point< dim > > &points, std::vector< Vector< Number > > &values) const
virtual void value_list(const std::vector< Point< dim > > &points, std::vector< Number > &return_values, const unsigned int component=0) 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 substitute_function_value_with(const Functions::ConstantFunction< dim, Number > &f)
virtual void vector_value_list(const std::vector< Point< dim > > &points, std::vector< Vector< Number > > &value_list) const
virtual void vector_value_list(const std::vector< Point< dim > > &points, std::vector< Vector< Number > > &values) const
const TensorFunction< 1, dim, Number > & tensor_function
Definition: function.h:841
VectorFunctionFromScalarFunctionObject(const std::function< Number(const Point< dim > &)> &function_object, const unsigned int selected_component, const unsigned int n_components)
ScalarFunctionFromFunctionObject(const std::function< Number(const Point< dim > &)> &function_object)
std::size_t memory_consumption() const
virtual Tensor< 1, dim, Number > gradient(const Point< dim > &p, const unsigned int component=0) const
const std::pair< unsigned int, unsigned int > selected_components
Definition: function.h:556
virtual void vector_value(const Point< dim > &p, Vector< Number > &return_value) 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_value_list(const std::vector< Point< dim > > &points, std::vector< Vector< Number > > &return_values) const
virtual Number value(const Point< dim > &p, const unsigned int component=0) const
virtual void laplacian_list(const std::vector< Point< dim > > &points, std::vector< Number > &values, const unsigned int component=0) const
virtual Number value(const Point< dim > &p, const unsigned int component=0) const
virtual SymmetricTensor< 2, dim, Number > hessian(const Point< dim > &p, const unsigned int component=0) const
virtual ~VectorFunctionFromTensorFunction()=default
const unsigned int selected_component
Definition: function.h:744
virtual void hessian_list(const std::vector< Point< dim > > &points, std::vector< SymmetricTensor< 2, dim, Number > > &values, const unsigned int component=0) const
VectorFunctionFromTensorFunction(const TensorFunction< 1, dim, Number > &tensor_function, const unsigned int selected_component=0, const unsigned int n_components=dim)
ZeroFunction(const unsigned int n_components=1)
virtual void vector_value(const Point< dim > &p, Vector< Number > &return_value) const
virtual void vector_gradient_list(const std::vector< Point< dim > > &points, std::vector< std::vector< Tensor< 1, dim, Number > > > &gradients) const
virtual Tensor< 1, dim, Number > gradient(const Point< dim > &p, const unsigned int component=0) const
ConstantFunction(const Number value, const unsigned int n_components=1)
std::vector< Number > function_value_vector
Definition: function.h:421
virtual void vector_laplacian_list(const std::vector< Point< dim > > &points, std::vector< Vector< Number > > &values) const
virtual void value_list(const std::vector< Point< dim > > &points, std::vector< Number > &values, const unsigned int component=0) const
const std::function< Number(const Point< dim > &)> function_object
Definition: function.h:661
virtual Number value(const Point< dim > &p, const unsigned int component=0) const
const unsigned int selected_component
Definition: function.h:849
virtual void vector_laplacian(const Point< dim > &p, Vector< Number > &values) const
virtual void gradient_list(const std::vector< Point< dim > > &points, std::vector< Tensor< 1, dim, Number > > &gradients, const unsigned int component=0) const