Reference documentation for deal.II version GIT 741a3088b8 2023-04-01 07:05:02+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\}}\)
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 
19 #include <deal.II/base/patterns.h>
20 #include <deal.II/base/utilities.h>
21 
22 #include <deal.II/lac/vector.h>
23 
24 #include <map>
25 
27 
28 
29 template <int dim>
30 const std::vector<std::string> &
32 {
33  return this->expressions;
34 }
35 
36 
37 
38 template <int dim>
39 FunctionParser<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 
46 template <int dim>
47 FunctionParser<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 {
56  constants,
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 
72 template <int dim>
73 void
74 FunctionParser<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 
87 template <int dim>
88 void
89 FunctionParser<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 
102 template <int dim>
103 double
105  const unsigned int component) const
106 {
107  return this->do_value(p, this->get_time(), component);
108 }
109 
110 // Explicit Instantiations.
111 
112 template class FunctionParser<1>;
113 template class FunctionParser<2>;
114 template 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:110
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:474
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:475
#define AssertThrow(cond, exc)
Definition: exceptions.h:1675
std::string get_time()
Definition: utilities.cc:1014
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