Reference documentation for deal.II version 9.6.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\}}\)
Loading...
Searching...
No Matches
symbolic_function.h
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2020 - 2024 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15#ifndef dealii_symbolic_function_h
16#define dealii_symbolic_function_h
17
18#include <deal.II/base/config.h>
19
22#include <deal.II/base/point.h>
25#include <deal.II/base/tensor.h>
26
28
29#include <functional>
30#include <iostream>
31#include <vector>
32
34
35// Forward declarations
36#ifndef DOXYGEN
37template <typename number>
38class Vector;
39namespace Functions
40{
41 template <int dim, typename RangeNumberType>
42 class SymbolicFunction;
43}
44#endif
45
46namespace Functions
47{
48#ifdef DEAL_II_WITH_SYMENGINE
151 template <int dim, typename RangeNumberType = double>
152 class SymbolicFunction : public Function<dim, RangeNumberType>
153 {
154 public:
198 const std::vector<Differentiation::SD::Expression> &function,
205
218 SymbolicFunction(const std::string &expressions);
219
227 void
230
246 void
249
260
267
273
277 const std::vector<Differentiation::SD::Expression> &
279
285
293
294 // documentation inherited from the base class
295 virtual RangeNumberType
296 value(const Point<dim> &p, const unsigned int component = 0) const override;
297
298 // documentation inherited from the base class
301 const unsigned int component = 0) const override;
302
303 // documentation inherited from the base class
304 virtual RangeNumberType
306 const unsigned int component = 0) const override;
307
308 // documentation inherited from the base class
311 const unsigned int component = 0) const override;
312
317 template <typename StreamType>
318 StreamType &
319 print(StreamType &out) const;
320
321 private:
330
336 void
338
344 void
346
352 void
354
367 const std::vector<Differentiation::SD::Expression> user_function;
368
376
383
388 mutable std::vector<Differentiation::SD::Expression> function;
389
395 mutable std::vector<Tensor<1, dim, Differentiation::SD::Expression>>
397
403 mutable std::vector<Tensor<2, dim, Differentiation::SD::Expression>>
405
411 mutable std::vector<Differentiation::SD::Expression> function_laplacian;
412
417
422 };
423
427 template <int dim, typename RangeNumberType>
428 inline std::ostream &
429 operator<<(std::ostream &out, const SymbolicFunction<dim, RangeNumberType> &f)
430 {
431 return f.print(out);
432 }
433
434
435
436 // Inline and template functions
437 template <int dim, typename RangeNumberType>
438 template <typename StreamType>
439 StreamType &
441 {
442 for (unsigned int i = 0; i < dim; ++i)
443 out << coordinate_symbols[i] << ", ";
444 for (const auto &argument_pair : additional_function_arguments)
445 out << argument_pair.first << ", ";
446 out << time_symbol << " -> " << user_function[0];
447 for (unsigned int i = 1; i < user_function.size(); ++i)
448 out << "; " << user_function[i];
449 if (!user_substitution_map.empty())
450 {
451 out << " # ( ";
452 std::string sep = "";
453 for (const auto &substitution : user_substitution_map)
454 {
455 out << sep << substitution.first << " = " << substitution.second;
456 sep = ", ";
457 }
458 out << " )";
459 }
460 return out;
461 }
462#else
463 template <int dim, typename RangeNumberType = double>
464 class SymbolicFunction
465 {
466 public:
468 {
470 false,
472 "This class is not available if you did not enable SymEngine "
473 "when compiling deal.II."));
474 }
475 };
476#endif
477} // namespace Functions
478
480
481#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
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:503
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:504
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
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)