Reference documentation for deal.II version Git 95a79d5 2018-06-20 15:34:22 +0200
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.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_function_h
17 #define dealii_function_h
18 
19 
20 #include <deal.II/base/config.h>
21 
22 #include <deal.II/base/exceptions.h>
23 #include <deal.II/base/function_time.h>
24 #include <deal.II/base/point.h>
25 #include <deal.II/base/subscriptor.h>
27 #include <deal.II/base/tensor.h>
28 
29 #include <functional>
30 #include <vector>
31 
32 DEAL_II_NAMESPACE_OPEN
33 
34 
35 template <typename number>
36 class Vector;
37 template <int rank, int dim, typename Number>
39 
144 template <int dim, typename RangeNumberType = double>
145 class Function : public FunctionTime<RangeNumberType>, public Subscriptor
146 {
147 public:
152  static const unsigned int dimension = dim;
153 
157  const unsigned int n_components;
158 
164  Function(const unsigned int n_components = 1,
165  const RangeNumberType initial_time = 0.0);
166 
188  virtual ~Function() override = 0;
189 
196  Function &
197  operator=(const Function &f);
198 
205  virtual RangeNumberType
206  value(const Point<dim> &p, const unsigned int component = 0) const;
207 
215  virtual void
216  vector_value(const Point<dim> &p, Vector<RangeNumberType> &values) const;
217 
227  virtual void
228  value_list(const std::vector<Point<dim>> &points,
229  std::vector<RangeNumberType> & values,
230  const unsigned int component = 0) const;
231 
242  virtual void
243  vector_value_list(const std::vector<Point<dim>> & points,
244  std::vector<Vector<RangeNumberType>> &values) const;
245 
254  virtual void
255  vector_values(const std::vector<Point<dim>> & points,
256  std::vector<std::vector<RangeNumberType>> &values) const;
257 
263  gradient(const Point<dim> &p, const unsigned int component = 0) const;
264 
268  virtual void
270  const Point<dim> & p,
271  std::vector<Tensor<1, dim, RangeNumberType>> &gradients) const;
272 
279  virtual void
280  gradient_list(const std::vector<Point<dim>> & points,
281  std::vector<Tensor<1, dim, RangeNumberType>> &gradients,
282  const unsigned int component = 0) const;
283 
292  virtual void
294  const std::vector<Point<dim>> & points,
295  std::vector<std::vector<Tensor<1, dim, RangeNumberType>>> &gradients) const;
296 
306  virtual void
308  const std::vector<Point<dim>> & points,
309  std::vector<std::vector<Tensor<1, dim, RangeNumberType>>> &gradients) const;
310 
314  virtual RangeNumberType
315  laplacian(const Point<dim> &p, const unsigned int component = 0) const;
316 
321  virtual void
322  vector_laplacian(const Point<dim> &p, Vector<RangeNumberType> &values) const;
323 
327  virtual void
328  laplacian_list(const std::vector<Point<dim>> &points,
329  std::vector<RangeNumberType> & values,
330  const unsigned int component = 0) const;
331 
335  virtual void
336  vector_laplacian_list(const std::vector<Point<dim>> & points,
337  std::vector<Vector<RangeNumberType>> &values) const;
338 
344  hessian(const Point<dim> &p, const unsigned int component = 0) const;
345 
350  virtual void
352  const Point<dim> & p,
353  std::vector<SymmetricTensor<2, dim, RangeNumberType>> &values) const;
354 
358  virtual void
359  hessian_list(const std::vector<Point<dim>> & points,
360  std::vector<SymmetricTensor<2, dim, RangeNumberType>> &values,
361  const unsigned int component = 0) const;
362 
366  virtual void
368  const std::vector<Point<dim>> & points,
369  std::vector<std::vector<SymmetricTensor<2, dim, RangeNumberType>>> &values)
370  const;
371 
372 
378  std::size_t
379  memory_consumption() const;
380 };
381 
382 
383 namespace Functions
384 {
392  template <int dim, typename RangeNumberType = double>
393  class ConstantFunction : public Function<dim, RangeNumberType>
394  {
395  public:
400  ConstantFunction(const RangeNumberType value,
401  const unsigned int n_components = 1);
402 
408  ConstantFunction(const std::vector<RangeNumberType> &values);
409 
415  ConstantFunction(const Vector<RangeNumberType> &values);
416 
421  ConstantFunction(const RangeNumberType *begin_ptr,
422  const unsigned int n_components);
423 
424  virtual RangeNumberType
425  value(const Point<dim> &p, const unsigned int component = 0) const override;
426 
427  virtual void
428  vector_value(const Point<dim> & p,
429  Vector<RangeNumberType> &return_value) const override;
430 
431  virtual void
432  value_list(const std::vector<Point<dim>> &points,
433  std::vector<RangeNumberType> & return_values,
434  const unsigned int component = 0) const override;
435 
436  virtual void
438  const std::vector<Point<dim>> & points,
439  std::vector<Vector<RangeNumberType>> &return_values) const override;
440 
442  gradient(const Point<dim> & p,
443  const unsigned int component = 0) const override;
444 
445  virtual void
447  const Point<dim> & p,
448  std::vector<Tensor<1, dim, RangeNumberType>> &gradients) const override;
449 
450  virtual void
451  gradient_list(const std::vector<Point<dim>> & points,
452  std::vector<Tensor<1, dim, RangeNumberType>> &gradients,
453  const unsigned int component = 0) const override;
454 
455  virtual void
457  const std::vector<Point<dim>> & points,
458  std::vector<std::vector<Tensor<1, dim, RangeNumberType>>> &gradients)
459  const override;
460 
461  std::size_t
462  memory_consumption() const;
463 
464  protected:
468  std::vector<RangeNumberType> function_value_vector;
469  };
470 
471 
472 
485  template <int dim, typename RangeNumberType = double>
486  class ZeroFunction : public ConstantFunction<dim, RangeNumberType>
487  {
488  public:
492  ZeroFunction(const unsigned int n_components = 1);
493  };
494 
495 } // namespace Functions
496 
503 template <int dim, typename RangeNumberType = double>
504 using ConstantFunction DEAL_II_DEPRECATED =
506 
512 template <int dim, typename RangeNumberType = double>
513 using ZeroFunction DEAL_II_DEPRECATED =
515 
516 
517 
532 template <int dim, typename RangeNumberType = double>
533 class ComponentSelectFunction : public ConstantFunction<dim, RangeNumberType>
534 {
535 public:
541  ComponentSelectFunction(const unsigned int selected,
542  const RangeNumberType value,
543  const unsigned int n_components);
544 
549  ComponentSelectFunction(const unsigned int selected,
550  const unsigned int n_components);
551 
559  ComponentSelectFunction(const std::pair<unsigned int, unsigned int> &selected,
560  const unsigned int n_components);
561 
562 
576  virtual void
579 
583  virtual void
584  vector_value(const Point<dim> & p,
585  Vector<RangeNumberType> &return_value) const override;
586 
593  virtual void
595  const std::vector<Point<dim>> & points,
596  std::vector<Vector<RangeNumberType>> &values) const override;
597 
603  std::size_t
604  memory_consumption() const;
605 
606 protected:
610  const std::pair<unsigned int, unsigned int> selected_components;
611 };
612 
613 
614 
695 template <int dim, typename RangeNumberType = double>
696 class ScalarFunctionFromFunctionObject : public Function<dim, RangeNumberType>
697 {
698 public:
705  const std::function<RangeNumberType(const Point<dim> &)> &function_object);
706 
711  virtual RangeNumberType
712  value(const Point<dim> &p, const unsigned int component = 0) const override;
713 
714 private:
719  const std::function<RangeNumberType(const Point<dim> &)> function_object;
720 };
721 
722 
723 
757 template <int dim, typename RangeNumberType = double>
759  : public Function<dim, RangeNumberType>
760 {
761 public:
775  const std::function<RangeNumberType(const Point<dim> &)> &function_object,
776  const unsigned int selected_component,
777  const unsigned int n_components);
778 
783  virtual RangeNumberType
784  value(const Point<dim> &p, const unsigned int component = 0) const override;
785 
791  virtual void
792  vector_value(const Point<dim> & p,
793  Vector<RangeNumberType> &values) const override;
794 
795 private:
800  const std::function<RangeNumberType(const Point<dim> &)> function_object;
801 
806  const unsigned int selected_component;
807 };
808 
809 
845 template <int dim, typename RangeNumberType = double>
846 class VectorFunctionFromTensorFunction : public Function<dim, RangeNumberType>
847 {
848 public:
867  const unsigned int selected_component = 0,
868  const unsigned int n_components = dim);
869 
874  virtual ~VectorFunctionFromTensorFunction() override = default;
875 
879  virtual RangeNumberType
880  value(const Point<dim> &p, const unsigned int component = 0) const override;
881 
887  virtual void
888  vector_value(const Point<dim> & p,
889  Vector<RangeNumberType> &values) const override;
890 
898  virtual void
900  const std::vector<Point<dim>> & points,
901  std::vector<Vector<RangeNumberType>> &value_list) const override;
902 
903 private:
909 
916  const unsigned int selected_component;
917 };
918 
919 
920 #ifndef DOXYGEN
921 // icc 2018 complains about an undefined reference
922 // if we put this in the templates.h file
923 //
924 // The destructor is pure virtual so we can't default it
925 // in the declaration.
926 template <int dim, typename RangeNumberType>
928 #endif
929 
930 
931 DEAL_II_NAMESPACE_CLOSE
932 
933 #endif
virtual void vector_gradient_list(const std::vector< Point< dim >> &points, std::vector< std::vector< Tensor< 1, dim, RangeNumberType >>> &gradients) const override
virtual void vector_value(const Point< dim > &p, Vector< RangeNumberType > &return_value) const override
const unsigned int n_components
Definition: function.h:157
virtual void gradient_list(const std::vector< Point< dim >> &points, std::vector< Tensor< 1, dim, RangeNumberType >> &gradients, const unsigned int component=0) const override
virtual ~VectorFunctionFromTensorFunction() override=default
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:152
virtual Tensor< 1, dim, RangeNumberType > gradient(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
virtual void vector_gradient_list(const std::vector< Point< dim >> &points, std::vector< std::vector< Tensor< 1, dim, RangeNumberType >>> &gradients) const
virtual void vector_laplacian_list(const std::vector< Point< dim >> &points, std::vector< Vector< RangeNumberType >> &values) const
virtual void vector_gradient(const Point< dim > &p, std::vector< Tensor< 1, dim, RangeNumberType >> &gradients) const
LinearAlgebra::distributed::Vector< Number > Vector
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const override
virtual void vector_laplacian(const Point< dim > &p, Vector< RangeNumberType > &values) const
const std::function< RangeNumberType(const Point< dim > &)> function_object
Definition: function.h:800
ComponentSelectFunction(const unsigned int selected, const RangeNumberType value, const unsigned int n_components)
Function & operator=(const Function &f)
virtual void vector_value_list(const std::vector< Point< dim >> &points, std::vector< Vector< RangeNumberType >> &value_list) const override
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const
virtual void vector_hessian(const Point< dim > &p, std::vector< SymmetricTensor< 2, dim, RangeNumberType >> &values) const
virtual void gradient_list(const std::vector< Point< dim >> &points, std::vector< Tensor< 1, dim, RangeNumberType >> &gradients, const unsigned int component=0) const
std::size_t memory_consumption() const
virtual void vector_value(const Point< dim > &p, Vector< RangeNumberType > &return_value) const override
virtual void vector_value(const Point< dim > &p, Vector< RangeNumberType > &values) const override
virtual RangeNumberType laplacian(const Point< dim > &p, const unsigned int component=0) const
virtual SymmetricTensor< 2, dim, RangeNumberType > hessian(const Point< dim > &p, const unsigned int component=0) const
const std::function< RangeNumberType(const Point< dim > &)> function_object
Definition: function.h:719
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const override
std::size_t memory_consumption() const
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const override
virtual void hessian_list(const std::vector< Point< dim >> &points, std::vector< SymmetricTensor< 2, dim, RangeNumberType >> &values, 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 override
virtual void vector_value(const Point< dim > &p, Vector< RangeNumberType > &values) const
virtual void vector_value_list(const std::vector< Point< dim >> &points, std::vector< Vector< RangeNumberType >> &return_values) const override
const TensorFunction< 1, dim, RangeNumberType > & tensor_function
Definition: function.h:908
ZeroFunction(const unsigned int n_components=1)
virtual void vector_value(const Point< dim > &p, Vector< RangeNumberType > &values) const override
virtual void vector_gradient(const Point< dim > &p, std::vector< Tensor< 1, dim, RangeNumberType >> &gradients) const override
const std::pair< unsigned int, unsigned int > selected_components
Definition: function.h:610
virtual void substitute_function_value_with(const Functions::ConstantFunction< dim, RangeNumberType > &f)
virtual void value_list(const std::vector< Point< dim >> &points, std::vector< RangeNumberType > &values, const unsigned int component=0) const
Definition: mpi.h:55
ConstantFunction(const RangeNumberType value, const unsigned int n_components=1)
virtual ~Function() override=0
const unsigned int selected_component
Definition: function.h:916
virtual void laplacian_list(const std::vector< Point< dim >> &points, std::vector< RangeNumberType > &values, const unsigned int component=0) const
virtual void vector_hessian_list(const std::vector< Point< dim >> &points, std::vector< std::vector< SymmetricTensor< 2, dim, RangeNumberType >>> &values) const
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const override
const unsigned int selected_component
Definition: function.h:806
virtual void vector_values(const std::vector< Point< dim >> &points, std::vector< std::vector< RangeNumberType >> &values) const
ScalarFunctionFromFunctionObject(const std::function< RangeNumberType(const Point< dim > &)> &function_object)
virtual void vector_value_list(const std::vector< Point< dim >> &points, std::vector< Vector< RangeNumberType >> &values) const override
virtual void vector_value_list(const std::vector< Point< dim >> &points, std::vector< Vector< RangeNumberType >> &values) const
std::vector< RangeNumberType > function_value_vector
Definition: function.h:468
VectorFunctionFromScalarFunctionObject(const std::function< RangeNumberType(const Point< dim > &)> &function_object, const unsigned int selected_component, const unsigned int n_components)
Function(const unsigned int n_components=1, const RangeNumberType initial_time=0.0)
virtual Tensor< 1, dim, RangeNumberType > gradient(const Point< dim > &p, const unsigned int component=0) const override