Reference documentation for deal.II version GIT relicensing-1054-gedd46abbd6 2024-07-12 01:20: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
function_parser.cc
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2005 - 2023 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
20
21#include <deal.II/lac/vector.h>
22
23#include <map>
24
26
27
28template <int dim>
29const std::vector<std::string> &
31{
32 return this->expressions;
33}
34
35
36
37template <int dim>
38FunctionParser<dim>::FunctionParser(const unsigned int n_components,
39 const double initial_time,
40 const double h)
41 : AutoDerivativeFunction<dim>(h, n_components, initial_time)
42{}
43
44
45template <int dim>
46FunctionParser<dim>::FunctionParser(const std::string &expression,
47 const std::string &constants,
48 const std::string &variable_names,
49 const double h)
51 h,
52 Utilities::split_string_list(expression, ';').size())
53{
58 0,
60 ",",
61 "="));
62 initialize(variable_names,
63 expression,
64 constants_map,
65 Utilities::split_string_list(variable_names, ",").size() ==
66 dim + 1);
67}
68
69
70
71template <int dim>
72void
73FunctionParser<dim>::initialize(const std::string &variables,
74 const std::vector<std::string> &expressions,
75 const std::map<std::string, double> &constants,
76 const bool time_dependent)
77{
78 AssertThrow(this->n_components == expressions.size(),
79 ExcInvalidExpressionSize(this->n_components, expressions.size()));
81 variables, expressions, constants, time_dependent);
82}
83
84
85
86template <int dim>
87void
88FunctionParser<dim>::initialize(const std::string &vars,
89 const std::string &expression,
90 const std::map<std::string, double> &constants,
91 const bool time_dependent)
92{
93 initialize(vars,
94 Utilities::split_string_list(expression, ';'),
95 constants,
96 time_dependent);
97}
98
99
100
101template <int dim>
102double
104 const unsigned int component) const
105{
106 return this->do_value(p, this->get_time(), component);
107}
108
109// Explicit Instantiations.
110
111template class FunctionParser<1>;
112template class FunctionParser<2>;
113template class FunctionParser<3>;
114
FunctionParser(const unsigned int n_components=1, const double initial_time=0.0, const double h=1e-8)
virtual void initialize(const std::string &vars, const std::vector< std::string > &expressions, const ConstMap &constants, const bool time_dependent=false) override
virtual double value(const Point< dim > &p, const unsigned int component=0) const override
const std::vector< std::string > & get_expressions() const
static const unsigned int max_int_value
Definition patterns.h:590
Definition point.h:111
virtual void initialize(const std::string &vars, const std::vector< std::string > &expressions, const std::map< std::string, double > &constants, const bool time_dependent=false)
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:502
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:503
#define AssertThrow(cond, exc)
std::vector< std::string > split_string_list(const std::string &s, const std::string &delimiter=",")
Definition utilities.cc:701
static T to_value(const std::string &s, const Patterns::PatternBase &p= *Convert< T >::to_pattern())=delete