deal.II version GIT relicensing-6816-g8d70a4508a 2026-09-28 16:30:01+00:00
\(\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: Apache-2.0 WITH LLVM-exception OR 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// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13#ifndef dealii_symbolic_function_h
14#define dealii_symbolic_function_h
15
16#include <deal.II/base/config.h>
17
21#include <deal.II/base/point.h>
23#include <deal.II/base/tensor.h>
24
26
27#include <functional>
28#include <iostream>
29#include <vector>
30
32
33// Forward declarations
34#ifndef DOXYGEN
35template <typename number>
36class Vector;
37namespace Functions
38{
39 template <int dim, typename RangeNumberType>
40 class SymbolicFunction;
41}
42#endif
43
44namespace Functions
45{
46#ifdef DEAL_II_WITH_SYMENGINE
149 template <int dim, typename RangeNumberType = double>
150 class SymbolicFunction : public Function<dim, RangeNumberType>
151 {
152 public:
196 const std::vector<Differentiation::SD::Expression> &function,
203
216 SymbolicFunction(const std::string &expressions);
217
225 void
228
244 void
247
258
265
271
275 const std::vector<Differentiation::SD::Expression> &
277
283
291
292 // documentation inherited from the base class
293 virtual RangeNumberType
294 value(const Point<dim> &p, const unsigned int component = 0) const override;
295
296 // documentation inherited from the base class
299 const unsigned int component = 0) const override;
300
301 // documentation inherited from the base class
302 virtual RangeNumberType
304 const unsigned int component = 0) const override;
305
306 // documentation inherited from the base class
309 const unsigned int component = 0) const override;
310
315 template <typename StreamType>
316 StreamType &
317 print(StreamType &out) const;
318
319 private:
328
334 void
336
342 void
344
350 void
352
365 const std::vector<Differentiation::SD::Expression> user_function;
366
374
381
386 mutable std::vector<Differentiation::SD::Expression> function;
387
393 mutable std::vector<Tensor<1, dim, Differentiation::SD::Expression>>
395
401 mutable std::vector<Tensor<2, dim, Differentiation::SD::Expression>>
403
409 mutable std::vector<Differentiation::SD::Expression> function_laplacian;
410
415
420 };
421
425 template <int dim, typename RangeNumberType>
426 inline std::ostream &
427 operator<<(std::ostream &out, const SymbolicFunction<dim, RangeNumberType> &f)
428 {
429 return f.print(out);
430 }
431
432
433
434 // Inline and template functions
435 template <int dim, typename RangeNumberType>
436 template <typename StreamType>
437 StreamType &
439 {
440 for (unsigned int i = 0; i < dim; ++i)
441 out << coordinate_symbols[i] << ", ";
442 for (const auto &argument_pair : additional_function_arguments)
443 out << argument_pair.first << ", ";
444 out << time_symbol << " -> " << user_function[0];
445 for (unsigned int i = 1; i < user_function.size(); ++i)
446 out << "; " << user_function[i];
447 if (!user_substitution_map.empty())
448 {
449 out << " # ( ";
450 std::string sep = "";
451 for (const auto &substitution : user_substitution_map)
452 {
453 out << sep << substitution.first << " = " << substitution.second;
454 sep = ", ";
455 }
456 out << " )";
457 }
458 return out;
459 }
460#else
461 template <int dim, typename RangeNumberType = double>
462 class SymbolicFunction
463 {
464 public:
466 {
468 false,
470 "This class is not available if you did not enable SymEngine "
471 "when compiling deal.II."));
472 }
473 };
474#endif
475} // namespace Functions
476
478
479#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:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
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)