Reference documentation for deal.II version 9.5.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
function_parser.cc
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 2005 - 2022 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
21
22#include <deal.II/lac/vector.h>
23
24#include <map>
25
27
28
29template <int dim>
30const std::vector<std::string> &
32{
33 return this->expressions;
34}
35
36
37
38template <int dim>
39FunctionParser<dim>::FunctionParser(const unsigned int n_components,
40 const double initial_time,
41 const double h)
42 : AutoDerivativeFunction<dim>(h, n_components, initial_time)
43{}
44
45
46template <int dim>
47FunctionParser<dim>::FunctionParser(const std::string &expression,
48 const std::string &constants,
49 const std::string &variable_names,
50 const double h)
52 h,
53 Utilities::split_string_list(expression, ';').size())
54{
59 0,
61 ",",
62 "="));
63 initialize(variable_names,
64 expression,
65 constants_map,
66 Utilities::split_string_list(variable_names, ",").size() ==
67 dim + 1);
68}
69
70
71
72template <int dim>
73void
74FunctionParser<dim>::initialize(const std::string & variables,
75 const std::vector<std::string> &expressions,
76 const std::map<std::string, double> &constants,
77 const bool time_dependent)
78{
79 AssertThrow(this->n_components == expressions.size(),
80 ExcInvalidExpressionSize(this->n_components, expressions.size()));
82 variables, expressions, constants, time_dependent);
83}
84
85
86
87template <int dim>
88void
89FunctionParser<dim>::initialize(const std::string & vars,
90 const std::string & expression,
91 const std::map<std::string, double> &constants,
92 const bool time_dependent)
93{
94 initialize(vars,
95 Utilities::split_string_list(expression, ';'),
96 constants,
97 time_dependent);
98}
99
100
101
102template <int dim>
103double
105 const unsigned int component) const
106{
107 return this->do_value(p, this->get_time(), component);
108}
109
110// Explicit Instantiations.
111
112template class FunctionParser<1>;
113template class FunctionParser<2>;
114template class FunctionParser<3>;
115
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:591
Definition point.h:112
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:472
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:473
#define AssertThrow(cond, exc)
std::vector< std::string > split_string_list(const std::string &s, const std::string &delimiter=",")
Definition utilities.cc:702
static T to_value(const std::string &s, const Patterns::PatternBase &p= *Convert< T >::to_pattern())=delete