Reference documentation for deal.II version 9.3.3
\(\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
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
38template <typename number>
39class Vector;
40namespace Functions
41{
42 template <int dim, typename RangeNumberType>
43 class SymbolicFunction;
44}
45#endif
46
47namespace Functions
48{
49#ifdef DEAL_II_WITH_SYMENGINE
152 template <int dim, typename RangeNumberType = double>
153 class SymbolicFunction : public Function<dim, RangeNumberType>
154 {
155 public:
199 const std::vector<Differentiation::SD::Expression> &function,
206
219 SymbolicFunction(const std::string &expressions);
220
228 void
231
247 void
250
261
268
274
278 const std::vector<Differentiation::SD::Expression> &
280
286
294
295 // documentation inherited from the base class
296 virtual RangeNumberType
297 value(const Point<dim> &p, const unsigned int component = 0) const override;
298
299 // documentation inherited from the base class
302 const unsigned int component = 0) const override;
303
304 // documentation inherited from the base class
305 virtual RangeNumberType
307 const unsigned int component = 0) const override;
308
309 // documentation inherited from the base class
312 const unsigned int component = 0) const override;
313
318 template <typename StreamType>
319 StreamType &
320 print(StreamType &out) const;
321
322 private:
331
337 void
339
345 void
347
353 void
355
368 const std::vector<Differentiation::SD::Expression> user_function;
369
377
384
389 mutable std::vector<Differentiation::SD::Expression> function;
390
396 mutable std::vector<Tensor<1, dim, Differentiation::SD::Expression>>
398
404 mutable std::vector<Tensor<2, dim, Differentiation::SD::Expression>>
406
412 mutable std::vector<Differentiation::SD::Expression> function_laplacian;
413
418
423 };
424
428 template <int dim, typename RangeNumberType>
429 inline std::ostream &
430 operator<<(std::ostream &out, const SymbolicFunction<dim, RangeNumberType> &f)
431 {
432 return f.print(out);
433 }
434
435
436
437 // Inline and template functions
438 template <int dim, typename RangeNumberType>
439 template <typename StreamType>
440 StreamType &
442 {
443 for (unsigned int i = 0; i < dim; ++i)
444 out << coordinate_symbols[i] << ", ";
445 for (const auto &argument_pair : additional_function_arguments)
446 out << argument_pair.first << ", ";
447 out << time_symbol << " -> " << user_function[0];
448 for (unsigned int i = 1; i < user_function.size(); ++i)
449 out << "; " << user_function[i];
450 if (!user_substitution_map.empty())
451 {
452 out << " # ( ";
453 std::string sep = "";
454 for (const auto &substitution : user_substitution_map)
455 {
456 out << sep << substitution.first << " = " << substitution.second;
457 sep = ", ";
458 }
459 out << " )";
460 }
461 return out;
462 }
463#else
464 template <int dim, typename RangeNumberType = double>
465 class SymbolicFunction
466 {
467 public:
469 {
471 false,
473 "This class is not available if you did not enable SymEngine "
474 "when compiling deal.II."));
475 }
476 };
477#endif
478} // namespace Functions
479
481
482#endif
StreamType & print(StreamType &out) const
const Differentiation::SD::types::substitution_map & get_user_substitution_map() const
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={})
std::vector< Differentiation::SD::Expression > function_laplacian
std::vector< Tensor< 2, dim, Differentiation::SD::Expression > > function_hessian
const std::vector< Differentiation::SD::Expression > user_function
virtual RangeNumberType laplacian(const Point< dim > &p, const unsigned int component=0) const override
const Differentiation::SD::Expression & get_time_symbol() const
void update_first_derivatives() const
SymbolicFunction(const std::string &expressions)
static Tensor< 1, dim, Differentiation::SD::Expression > get_default_coordinate_symbols()
Differentiation::SD::types::substitution_map user_substitution_map
virtual SymmetricTensor< 2, dim, RangeNumberType > hessian(const Point< dim > &p, const unsigned int component=0) const override
void set_additional_function_arguments(const Differentiation::SD::types::substitution_map &arguments)
std::vector< Tensor< 1, dim, Differentiation::SD::Expression > > function_gradient
Differentiation::SD::types::substitution_map additional_function_arguments
void update_user_substitution_map(const Differentiation::SD::types::substitution_map &substitutions)
virtual Tensor< 1, dim, RangeNumberType > gradient(const Point< dim > &p, const unsigned int component=0) const override
Differentiation::SD::Expression time_symbol
const Tensor< 1, dim, Differentiation::SD::Expression > & get_coordinate_symbols() const
const std::vector< Differentiation::SD::Expression > & get_symbolic_function_expressions() const
SymbolicFunction< dim, RangeNumberType > time_derivative() const
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const override
std::vector< Differentiation::SD::Expression > function
Differentiation::SD::types::substitution_map create_evaluation_substitution_map(const Point< dim > &point) const
Tensor< 1, dim, Differentiation::SD::Expression > coordinate_symbols
void update_second_derivatives() const
Definition: point.h:111
Definition: vector.h:110
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:402
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:403
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
Definition: exceptions.h:1575
std::map< SD::Expression, SD::Expression, internal::ExpressionKeyLess > substitution_map
Expression make_symbol(const std::string &symbol)
std::ostream & operator<<(std::ostream &out, const SymbolicFunction< dim, RangeNumberType > &f)
Point< spacedim > point(const gp_Pnt &p, const double tolerance=1e-10)
Definition: utilities.cc:188