Reference documentation for deal.II version Git 6177fad8a5 2019-03-23 23:27:20 +0100
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
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 
147 template <int dim, typename RangeNumberType = double>
148 class Function : public FunctionTime<
149  typename numbers::NumberTraits<RangeNumberType>::real_type>,
150  public Subscriptor
151 {
152 public:
157  static const unsigned int dimension = dim;
158 
162  const unsigned int n_components;
163 
167  using time_type = typename FunctionTime<
169 
175  Function(const unsigned int n_components = 1,
176  const time_type initial_time = 0.0);
177 
199  virtual ~Function() override = 0;
200 
207  Function &
208  operator=(const Function &f);
209 
216  virtual RangeNumberType
217  value(const Point<dim> &p, const unsigned int component = 0) const;
218 
226  virtual void
227  vector_value(const Point<dim> &p, Vector<RangeNumberType> &values) const;
228 
238  virtual void
239  value_list(const std::vector<Point<dim>> &points,
240  std::vector<RangeNumberType> & values,
241  const unsigned int component = 0) const;
242 
253  virtual void
254  vector_value_list(const std::vector<Point<dim>> & points,
255  std::vector<Vector<RangeNumberType>> &values) const;
256 
265  virtual void
266  vector_values(const std::vector<Point<dim>> & points,
267  std::vector<std::vector<RangeNumberType>> &values) const;
268 
274  gradient(const Point<dim> &p, const unsigned int component = 0) const;
275 
279  virtual void
281  const Point<dim> & p,
282  std::vector<Tensor<1, dim, RangeNumberType>> &gradients) const;
283 
290  virtual void
291  gradient_list(const std::vector<Point<dim>> & points,
292  std::vector<Tensor<1, dim, RangeNumberType>> &gradients,
293  const unsigned int component = 0) const;
294 
303  virtual void
305  const std::vector<Point<dim>> & points,
306  std::vector<std::vector<Tensor<1, dim, RangeNumberType>>> &gradients) const;
307 
317  virtual void
319  const std::vector<Point<dim>> & points,
320  std::vector<std::vector<Tensor<1, dim, RangeNumberType>>> &gradients) const;
321 
325  virtual RangeNumberType
326  laplacian(const Point<dim> &p, const unsigned int component = 0) const;
327 
332  virtual void
333  vector_laplacian(const Point<dim> &p, Vector<RangeNumberType> &values) const;
334 
338  virtual void
339  laplacian_list(const std::vector<Point<dim>> &points,
340  std::vector<RangeNumberType> & values,
341  const unsigned int component = 0) const;
342 
346  virtual void
347  vector_laplacian_list(const std::vector<Point<dim>> & points,
348  std::vector<Vector<RangeNumberType>> &values) const;
349 
355  hessian(const Point<dim> &p, const unsigned int component = 0) const;
356 
361  virtual void
363  const Point<dim> & p,
364  std::vector<SymmetricTensor<2, dim, RangeNumberType>> &values) const;
365 
369  virtual void
370  hessian_list(const std::vector<Point<dim>> & points,
371  std::vector<SymmetricTensor<2, dim, RangeNumberType>> &values,
372  const unsigned int component = 0) const;
373 
377  virtual void
379  const std::vector<Point<dim>> & points,
380  std::vector<std::vector<SymmetricTensor<2, dim, RangeNumberType>>> &values)
381  const;
382 
383 
389  std::size_t
390  memory_consumption() const;
391 };
392 
393 
394 namespace Functions
395 {
403  template <int dim, typename RangeNumberType = double>
404  class ConstantFunction : public Function<dim, RangeNumberType>
405  {
406  public:
411  ConstantFunction(const RangeNumberType value,
412  const unsigned int n_components = 1);
413 
419  ConstantFunction(const std::vector<RangeNumberType> &values);
420 
427 
432  ConstantFunction(const RangeNumberType *begin_ptr,
433  const unsigned int n_components);
434 
435  virtual RangeNumberType
436  value(const Point<dim> &p, const unsigned int component = 0) const override;
437 
438  virtual void
439  vector_value(const Point<dim> & p,
440  Vector<RangeNumberType> &return_value) const override;
441 
442  virtual void
443  value_list(const std::vector<Point<dim>> &points,
444  std::vector<RangeNumberType> & return_values,
445  const unsigned int component = 0) const override;
446 
447  virtual void
449  const std::vector<Point<dim>> & points,
450  std::vector<Vector<RangeNumberType>> &return_values) const override;
451 
453  gradient(const Point<dim> & p,
454  const unsigned int component = 0) const override;
455 
456  virtual void
458  const Point<dim> & p,
459  std::vector<Tensor<1, dim, RangeNumberType>> &gradients) const override;
460 
461  virtual void
462  gradient_list(const std::vector<Point<dim>> & points,
463  std::vector<Tensor<1, dim, RangeNumberType>> &gradients,
464  const unsigned int component = 0) const override;
465 
466  virtual void
468  const std::vector<Point<dim>> & points,
469  std::vector<std::vector<Tensor<1, dim, RangeNumberType>>> &gradients)
470  const override;
471 
472  std::size_t
473  memory_consumption() const;
474 
475  protected:
479  std::vector<RangeNumberType> function_value_vector;
480  };
481 
482 
483 
496  template <int dim, typename RangeNumberType = double>
497  class ZeroFunction : public ConstantFunction<dim, RangeNumberType>
498  {
499  public:
503  ZeroFunction(const unsigned int n_components = 1);
504  };
505 
506 } // namespace Functions
507 
514 template <int dim, typename RangeNumberType = double>
515 using ConstantFunction DEAL_II_DEPRECATED =
517 
523 template <int dim, typename RangeNumberType = double>
524 using ZeroFunction DEAL_II_DEPRECATED =
526 
527 
528 
543 template <int dim, typename RangeNumberType = double>
544 class ComponentSelectFunction : public ConstantFunction<dim, RangeNumberType>
545 {
546 public:
552  ComponentSelectFunction(const unsigned int selected,
553  const RangeNumberType value,
554  const unsigned int n_components);
555 
560  ComponentSelectFunction(const unsigned int selected,
561  const unsigned int n_components);
562 
570  ComponentSelectFunction(const std::pair<unsigned int, unsigned int> &selected,
571  const unsigned int n_components);
572 
573 
587  virtual void
588  substitute_function_value_with(
590 
594  virtual void
595  vector_value(const Point<dim> & p,
596  Vector<RangeNumberType> &return_value) const override;
597 
604  virtual void
606  const std::vector<Point<dim>> & points,
607  std::vector<Vector<RangeNumberType>> &values) const override;
608 
614  std::size_t
615  memory_consumption() const;
616 
617 protected:
621  const std::pair<unsigned int, unsigned int> selected_components;
622 };
623 
624 
625 
709 template <int dim, typename RangeNumberType = double>
710 class ScalarFunctionFromFunctionObject : public Function<dim, RangeNumberType>
711 {
712 public:
719  const std::function<RangeNumberType(const Point<dim> &)> &function_object);
720 
725  virtual RangeNumberType
726  value(const Point<dim> &p, const unsigned int component = 0) const override;
727 
728 private:
733  const std::function<RangeNumberType(const Point<dim> &)> function_object;
734 };
735 
736 
737 
775 template <int dim, typename RangeNumberType = double>
777  : public Function<dim, RangeNumberType>
778 {
779 public:
793  const std::function<RangeNumberType(const Point<dim> &)> &function_object,
794  const unsigned int selected_component,
795  const unsigned int n_components);
796 
801  virtual RangeNumberType
802  value(const Point<dim> &p, const unsigned int component = 0) const override;
803 
809  virtual void
810  vector_value(const Point<dim> & p,
811  Vector<RangeNumberType> &values) const override;
812 
813 private:
818  const std::function<RangeNumberType(const Point<dim> &)> function_object;
819 
824  const unsigned int selected_component;
825 };
826 
827 
863 template <int dim, typename RangeNumberType = double>
864 class VectorFunctionFromTensorFunction : public Function<dim, RangeNumberType>
865 {
866 public:
884  const TensorFunction<1, dim, RangeNumberType> &tensor_function,
885  const unsigned int selected_component = 0,
886  const unsigned int n_components = dim);
887 
892  virtual ~VectorFunctionFromTensorFunction() override = default;
893 
897  virtual RangeNumberType
898  value(const Point<dim> &p, const unsigned int component = 0) const override;
899 
905  virtual void
906  vector_value(const Point<dim> & p,
907  Vector<RangeNumberType> &values) const override;
908 
916  virtual void
918  const std::vector<Point<dim>> & points,
919  std::vector<Vector<RangeNumberType>> &value_list) const override;
920 
921 private:
927 
934  const unsigned int selected_component;
935 };
936 
937 
938 #ifndef DOXYGEN
939 // icc 2018 complains about an undefined reference
940 // if we put this in the templates.h file
941 //
942 // The destructor is pure virtual so we can't default it
943 // in the declaration.
944 template <int dim, typename RangeNumberType>
946 #endif
947 
948 
949 DEAL_II_NAMESPACE_CLOSE
950 
951 #endif
Function(const unsigned int n_components=1, const time_type initial_time=0.0)
const unsigned int n_components
Definition: function.h:162
virtual void vector_hessian_list(const std::vector< Point< dim >> &points, std::vector< std::vector< SymmetricTensor< 2, dim, RangeNumberType >>> &values) const
virtual void vector_gradient_list(const std::vector< Point< dim >> &points, std::vector< std::vector< Tensor< 1, dim, RangeNumberType >>> &gradients) const
static const unsigned int dimension
Definition: function.h:157
virtual void vector_laplacian(const Point< dim > &p, Vector< RangeNumberType > &values) const
virtual void vector_hessian(const Point< dim > &p, std::vector< SymmetricTensor< 2, dim, RangeNumberType >> &values) const
virtual void vector_gradients(const std::vector< Point< dim >> &points, std::vector< std::vector< Tensor< 1, dim, RangeNumberType >>> &gradients) const
LinearAlgebra::distributed::Vector< Number > Vector
Function & operator=(const Function &f)
typename FunctionTime< typename numbers::NumberTraits< RangeNumberType >::real_type >::time_type time_type
Definition: function.h:168
virtual void vector_value_list(const std::vector< Point< dim >> &points, std::vector< Vector< RangeNumberType >> &values) const
virtual void vector_values(const std::vector< Point< dim >> &points, std::vector< std::vector< RangeNumberType >> &values) const
virtual SymmetricTensor< 2, dim, RangeNumberType > hessian(const Point< dim > &p, const unsigned int component=0) const
virtual void vector_value(const Point< dim > &p, Vector< RangeNumberType > &values) 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 TensorFunction< 1, dim, RangeNumberType > & tensor_function
Definition: function.h:926
virtual void vector_laplacian_list(const std::vector< Point< dim >> &points, std::vector< Vector< RangeNumberType >> &values) const
virtual Tensor< 1, dim, RangeNumberType > gradient(const Point< dim > &p, const unsigned int component=0) const
Number time_type
const std::pair< unsigned int, unsigned int > selected_components
Definition: function.h:621
virtual RangeNumberType laplacian(const Point< dim > &p, const unsigned int component=0) const
Definition: mpi.h:88
virtual void value_list(const std::vector< Point< dim >> &points, std::vector< RangeNumberType > &values, const unsigned int component=0) const
virtual ~Function() override=0
const unsigned int selected_component
Definition: function.h:934
const unsigned int selected_component
Definition: function.h:824
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const
std::size_t memory_consumption() const
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_gradient(const Point< dim > &p, std::vector< Tensor< 1, dim, RangeNumberType >> &gradients) const
std::vector< RangeNumberType > function_value_vector
Definition: function.h:479
virtual void laplacian_list(const std::vector< Point< dim >> &points, std::vector< RangeNumberType > &values, const unsigned int component=0) const