Reference documentation for deal.II version 9.2.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
symbolic_function.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2019 - 2020 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_symbolic_function_h
17 #define dealii_symbolic_function_h
18 
19 #include <deal.II/base/config.h>
20 
22 #include <deal.II/base/function.h>
23 #include <deal.II/base/point.h>
26 #include <deal.II/base/tensor.h>
27 
29 
30 #include <functional>
31 #include <iostream>
32 #include <vector>
33 
35 
36 // Forward declarations
37 #ifndef DOXYGEN
38 template <typename number>
39 class Vector;
40 namespace Functions
41 {
42  template <int dim, typename RangeNumberType>
43  class SymbolicFunction;
44 }
45 #endif
46 
47 namespace Functions
48 {
49 #ifdef DEAL_II_WITH_SYMENGINE
50 
153  template <int dim, typename RangeNumberType = double>
154  class SymbolicFunction : public Function<dim, RangeNumberType>
155  {
156  public:
200  const std::vector<Differentiation::SD::Expression> &function,
206  &user_substitution_map = {});
207 
220  SymbolicFunction(const std::string &expressions);
221 
229  void
231  const Differentiation::SD::types::substitution_map &substitutions);
232 
248  void
251 
262 
268  get_coordinate_symbols() const;
269 
274  get_time_symbol() const;
275 
279  const std::vector<Differentiation::SD::Expression> &
281 
287 
294  time_derivative() const;
295 
296  // documentation inherited from the base class
297  virtual RangeNumberType
298  value(const Point<dim> &p, const unsigned int component = 0) const override;
299 
300  // documentation inherited from the base class
302  gradient(const Point<dim> & p,
303  const unsigned int component = 0) const override;
304 
305  // documentation inherited from the base class
306  virtual RangeNumberType
307  laplacian(const Point<dim> & p,
308  const unsigned int component = 0) const override;
309 
310  // documentation inherited from the base class
312  hessian(const Point<dim> & p,
313  const unsigned int component = 0) const override;
314 
319  template <typename StreamType>
320  StreamType &
321  print(StreamType &out) const;
322 
323  private:
332 
338  void
339  update_values() const;
340 
346  void
347  update_first_derivatives() const;
348 
354  void
356 
369  const std::vector<Differentiation::SD::Expression> user_function;
370 
378 
385 
390  mutable std::vector<Differentiation::SD::Expression> function;
391 
397  mutable std::vector<Tensor<1, dim, Differentiation::SD::Expression>>
399 
405  mutable std::vector<Tensor<2, dim, Differentiation::SD::Expression>>
407 
413  mutable std::vector<Differentiation::SD::Expression> function_laplacian;
414 
419 
424  };
425 
429  template <int dim, typename RangeNumberType>
430  inline std::ostream &
432  {
433  return f.print(out);
434  }
435 
436 
437 
438  // Inline and template functions
439  template <int dim, typename RangeNumberType>
440  template <typename StreamType>
441  StreamType &
443  {
444  for (unsigned int i = 0; i < dim; ++i)
445  out << coordinate_symbols[i] << ", ";
446  for (const auto &argument_pair : additional_function_arguments)
447  out << argument_pair.first << ", ";
448  out << time_symbol << " -> " << user_function[0];
449  for (unsigned int i = 1; i < user_function.size(); ++i)
450  out << "; " << user_function[i];
451  if (!user_substitution_map.empty())
452  {
453  out << " # ( ";
454  std::string sep = "";
455  for (const auto &substitution : user_substitution_map)
456  {
457  out << sep << substitution.first << " = " << substitution.second;
458  sep = ", ";
459  }
460  out << " )";
461  }
462  return out;
463  }
464 #else
465  template <int dim, typename RangeNumberType = double>
466  class SymbolicFunction
467  {
468  public:
470  {
471  AssertThrow(
472  false,
473  ExcMessage(
474  "This class is not available if you did not enable SymEngine "
475  "when compiling deal.II."));
476  }
477  };
478 #endif
479 } // namespace Functions
480 
482 
483 #endif
Functions::SymbolicFunction::function_laplacian
std::vector< Differentiation::SD::Expression > function_laplacian
Definition: symbolic_function.h:413
Functions::SymbolicFunction::gradient
virtual Tensor< 1, dim, RangeNumberType > gradient(const Point< dim > &p, const unsigned int component=0) const override
Functions
Definition: flow_function.h:28
Functions::SymbolicFunction::update_values
void update_values() const
LinearAlgebraDealII::Vector
Vector< double > Vector
Definition: generic_linear_algebra.h:43
Functions::SymbolicFunction::get_coordinate_symbols
const Tensor< 1, dim, Differentiation::SD::Expression > & get_coordinate_symbols() const
Functions::SymbolicFunction
Definition: symbolic_function.h:154
SymmetricTensor
Definition: symmetric_tensor.h:611
Functions::SymbolicFunction::print
StreamType & print(StreamType &out) const
Definition: symbolic_function.h:442
Functions::SymbolicFunction::get_symbolic_function_expressions
const std::vector< Differentiation::SD::Expression > & get_symbolic_function_expressions() const
Functions::SymbolicFunction::SymbolicFunction
SymbolicFunction(const std::vector< Differentiation::SD::Expression > &function, const Tensor< 1, dim, Differentiation::SD::Expression > &coordinate_symbols=get_default_coordinate_symbols(), const Differentiation::SD::Expression &time_symbol=Differentiation::SD::make_symbol("t"), const Differentiation::SD::types::substitution_map &user_substitution_map={})
Differentiation::SD::types::substitution_map
std::map< SD::Expression, SD::Expression, internal::ExpressionKeyLess > substitution_map
Definition: symengine_types.h:62
OpenCASCADE::point
Point< spacedim > point(const gp_Pnt &p, const double tolerance=1e-10)
Definition: utilities.cc:188
Functions::SymbolicFunction::function_gradient
std::vector< Tensor< 1, dim, Differentiation::SD::Expression > > function_gradient
Definition: symbolic_function.h:398
Functions::SymbolicFunction::time_derivative
SymbolicFunction< dim, RangeNumberType > time_derivative() const
tensor.h
Functions::SymbolicFunction::hessian
virtual SymmetricTensor< 2, dim, RangeNumberType > hessian(const Point< dim > &p, const unsigned int component=0) const override
StandardExceptions::ExcMessage
static ::ExceptionBase & ExcMessage(std::string arg1)
Functions::SymbolicFunction::laplacian
virtual RangeNumberType laplacian(const Point< dim > &p, const unsigned int component=0) const override
subscriptor.h
Tensor< 1, dim, Differentiation::SD::Expression >
Functions::SymbolicFunction::get_user_substitution_map
const Differentiation::SD::types::substitution_map & get_user_substitution_map() const
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
Functions::SymbolicFunction::set_additional_function_arguments
void set_additional_function_arguments(const Differentiation::SD::types::substitution_map &arguments)
Functions::SymbolicFunction::update_second_derivatives
void update_second_derivatives() const
Functions::SymbolicFunction::get_time_symbol
const Differentiation::SD::Expression & get_time_symbol() const
Functions::SymbolicFunction::additional_function_arguments
Differentiation::SD::types::substitution_map additional_function_arguments
Definition: symbolic_function.h:384
exceptions.h
Differentiation::SD::Expression
Definition: symengine_number_types.h:179
Functions::SymbolicFunction::create_evaluation_substitution_map
Differentiation::SD::types::substitution_map create_evaluation_substitution_map(const Point< dim > &point) const
Differentiation::SD::make_symbol
Expression make_symbol(const std::string &symbol)
Definition: symengine_scalar_operations.cc:41
function.h
sd.h
symmetric_tensor.h
Functions::SymbolicFunction::user_function
const std::vector< Differentiation::SD::Expression > user_function
Definition: symbolic_function.h:369
Functions::SymbolicFunction::get_default_coordinate_symbols
static Tensor< 1, dim, Differentiation::SD::Expression > get_default_coordinate_symbols()
Functions::SymbolicFunction::update_first_derivatives
void update_first_derivatives() const
Point< dim >
config.h
Functions::operator<<
std::ostream & operator<<(std::ostream &out, const SymbolicFunction< dim, RangeNumberType > &f)
Definition: symbolic_function.h:431
Function
Definition: function.h:151
Functions::SymbolicFunction::function_hessian
std::vector< Tensor< 2, dim, Differentiation::SD::Expression > > function_hessian
Definition: symbolic_function.h:406
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
Functions::SymbolicFunction::value
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const override
Functions::SymbolicFunction::update_user_substitution_map
void update_user_substitution_map(const Differentiation::SD::types::substitution_map &substitutions)
Functions::SymbolicFunction::coordinate_symbols
Tensor< 1, dim, Differentiation::SD::Expression > coordinate_symbols
Definition: symbolic_function.h:418
AssertThrow
#define AssertThrow(cond, exc)
Definition: exceptions.h:1531
Functions::SymbolicFunction::time_symbol
Differentiation::SD::Expression time_symbol
Definition: symbolic_function.h:423
Functions::SymbolicFunction::user_substitution_map
Differentiation::SD::types::substitution_map user_substitution_map
Definition: symbolic_function.h:377
point.h