Reference documentation for deal.II version 9.2.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\}}\)
function_parser.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2005 - 2020 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 #ifndef dealii_function_parser_h
17 #define dealii_function_parser_h
18 
19 
20 #include <deal.II/base/config.h>
21 
24 #include <deal.II/base/point.h>
25 #include <deal.II/base/tensor.h>
27 
28 #include <map>
29 #include <memory>
30 #include <vector>
31 
32 namespace mu
33 {
34  class Parser;
35 }
36 
38 
39 // Forward declaration
40 #ifndef DOXYGEN
41 template <typename>
42 class Vector;
43 #endif
44 
223 template <int dim>
225 {
226 public:
235  FunctionParser(const unsigned int n_components = 1,
236  const double initial_time = 0.0,
237  const double h = 1e-8);
238 
245  FunctionParser(const std::string &expression,
246  const std::string &constants = "",
247  const std::string &variable_names = default_variable_names() +
248  ",t",
249  const double h = 1e-8);
250 
255  FunctionParser(const FunctionParser &) = delete;
256 
261  FunctionParser(FunctionParser &&) = delete;
262 
266  virtual ~FunctionParser() override;
267 
273  operator=(const FunctionParser &) = delete;
274 
280  operator=(FunctionParser &&) = delete;
281 
285  using ConstMap = std::map<std::string, double>;
286 
321  void
322  initialize(const std::string & vars,
323  const std::vector<std::string> &expressions,
324  const ConstMap & constants,
325  const bool time_dependent = false);
326 
334  void
335  initialize(const std::string &vars,
336  const std::string &expression,
337  const ConstMap & constants,
338  const bool time_dependent = false);
339 
345  static std::string
347 
354  virtual double
355  value(const Point<dim> &p, const unsigned int component = 0) const override;
356 
364  virtual void
365  vector_value(const Point<dim> &p, Vector<double> &values) const override;
366 
371  const std::vector<std::string> &
372  get_expressions() const;
373 
379  int,
380  std::string,
381  << "Parsing Error at Column " << arg1
382  << ". The parser said: " << arg2);
383 
385  int,
386  int,
387  << "The number of components (" << arg1
388  << ") is not equal to the number of expressions (" << arg2
389  << ").");
390 
392 
393 private:
394 #ifdef DEAL_II_WITH_MUPARSER
395 
399 
406  fp;
407 
412  std::map<std::string, double> constants;
413 
418  std::vector<std::string> var_names;
419 
426  void
427  init_muparser() const;
428 #endif
429 
434  std::vector<std::string> expressions;
435 
441 
449  unsigned int n_vars;
450 };
451 
452 
453 template <int dim>
454 std::string
456 {
457  switch (dim)
458  {
459  case 1:
460  return "x";
461  case 2:
462  return "x,y";
463  case 3:
464  return "x,y,z";
465  default:
466  Assert(false, ExcNotImplemented());
467  }
468  return "";
469 }
470 
471 
472 
474 
475 #endif
auto_derivative_function.h
LinearAlgebraDealII::Vector
Vector< double > Vector
Definition: generic_linear_algebra.h:43
FunctionParser::fp
Threads::ThreadLocalStorage< std::vector< std::unique_ptr< mu::Parser > > > fp
Definition: function_parser.h:406
StandardExceptions::ExcNotImplemented
static ::ExceptionBase & ExcNotImplemented()
mu
Definition: function_parser.h:32
FunctionParser::FunctionParser
FunctionParser(const unsigned int n_components=1, const double initial_time=0.0, const double h=1e-8)
Definition: function_parser.cc:45
FunctionParser::init_muparser
void init_muparser() const
Definition: function_parser.cc:137
AutoDerivativeFunction
Definition: auto_derivative_function.h:83
Function< dim >::n_components
const unsigned int n_components
Definition: function.h:165
Physics::Elasticity::Kinematics::e
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)
FunctionParser::ExcParseError
static ::ExceptionBase & ExcParseError(int arg1, std::string arg2)
AutoDerivativeFunction::h
double h
Definition: auto_derivative_function.h:224
FunctionParser::default_variable_names
static std::string default_variable_names()
Definition: function_parser.h:455
thread_local_storage.h
tensor.h
FunctionParser::value
virtual double value(const Point< dim > &p, const unsigned int component=0) const override
Definition: function_parser.cc:276
FunctionParser::ConstMap
std::map< std::string, double > ConstMap
Definition: function_parser.h:285
FunctionParser::~FunctionParser
virtual ~FunctionParser() override
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
FunctionParser::vector_value
virtual void vector_value(const Point< dim > &p, Vector< double > &values) const override
Definition: function_parser.cc:311
FunctionParser::constants
std::map< std::string, double > constants
Definition: function_parser.h:412
FunctionParser::n_vars
unsigned int n_vars
Definition: function_parser.h:449
FunctionParser::expressions
std::vector< std::string > expressions
Definition: function_parser.h:434
Threads::ThreadLocalStorage
A class that provides a separate storage location on each thread that accesses the object.
Definition: thread_local_storage.h:72
FunctionParser::ExcInvalidExpressionSize
static ::ExceptionBase & ExcInvalidExpressionSize(int arg1, int arg2)
exceptions.h
FunctionParser::vars
Threads::ThreadLocalStorage< std::vector< double > > vars
Definition: function_parser.h:398
FunctionParser::initialize
void initialize(const std::string &vars, const std::vector< std::string > &expressions, const ConstMap &constants, const bool time_dependent=false)
Definition: function_parser.cc:94
FunctionParser::var_names
std::vector< std::string > var_names
Definition: function_parser.h:418
Assert
#define Assert(cond, exc)
Definition: exceptions.h:1419
FunctionParser::get_expressions
const std::vector< std::string > & get_expressions() const
Definition: function_parser.cc:37
FunctionParser::operator=
FunctionParser & operator=(const FunctionParser &)=delete
Point< dim >
config.h
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
Vector< double >
DeclException2
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:541
FunctionParser::initialized
bool initialized
Definition: function_parser.h:440
FunctionParser
Definition: function_parser.h:224
point.h