Reference documentation for deal.II version 8.5.1
function_parser.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2005 - 2016 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 at
12 // the top level of the deal.II distribution.
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 #include <deal.II/base/exceptions.h>
22 #include <deal.II/base/auto_derivative_function.h>
23 #include <deal.II/base/tensor.h>
24 #include <deal.II/base/point.h>
25 #include <deal.II/base/thread_local_storage.h>
26 #include <vector>
27 #include <map>
28 
29 namespace mu
30 {
31  class Parser;
32 }
33 
34 DEAL_II_NAMESPACE_OPEN
35 
36 
37 template <typename> class Vector;
38 
39 
179 template <int dim>
181 {
182 public:
192  FunctionParser (const unsigned int n_components = 1,
193  const double initial_time = 0.0,
194  const double h = 1e-8);
195 
200  ~FunctionParser();
201 
205  typedef std::map<std::string, double> ConstMap;
206 
210  typedef ConstMap::iterator ConstMapIterator;
211 
246  void initialize (const std::string &vars,
247  const std::vector<std::string> &expressions,
248  const ConstMap &constants,
249  const bool time_dependent = false);
250 
258  void initialize (const std::string &vars,
259  const std::string &expression,
260  const ConstMap &constants,
261  const bool time_dependent = false);
262 
268  static
269  std::string
271 
278  virtual double value (const Point<dim> &p,
279  const unsigned int component = 0) const;
280 
287  virtual void vector_value (const Point<dim> &p,
288  Vector<double> &values) const;
289 
295  int, char *,
296  << "Parsing Error at Column " << arg1
297  << ". The parser said: " << arg2);
298 
300  int, int,
301  << "The number of components (" << arg1
302  << ") is not equal to the number of expressions ("
303  << arg2 << ").");
304 
306 
307 private:
308 #ifdef DEAL_II_WITH_MUPARSER
309 
313 
318 
323  std::map<std::string, double> constants;
324 
329  std::vector<std::string> var_names;
330 
335  std::vector<std::string> expressions;
336 
343  void init_muparser() const;
344 #endif
345 
351 
359  unsigned int n_vars;
360 };
361 
362 
363 template <int dim>
364 std::string
366 {
367  switch (dim)
368  {
369  case 1:
370  return "x";
371  case 2:
372  return "x,y";
373  case 3:
374  return "x,y,z";
375  default:
376  Assert (false, ExcNotImplemented());
377  }
378  return "";
379 }
380 
381 
382 
383 DEAL_II_NAMESPACE_CLOSE
384 
385 #endif
386 
387 
FunctionParser(const unsigned int n_components=1, const double initial_time=0.0, const double h=1e-8)
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:576
A class that provides a separate storage location on each thread that accesses the object...
ConstMap::iterator ConstMapIterator
virtual double value(const Point< dim > &p, const unsigned int component=0) const
unsigned int n_vars
Threads::ThreadLocalStorage< std::vector< mu::Parser > > fp
static std::string default_variable_names()
const unsigned int n_components
Definition: function.h:144
#define Assert(cond, exc)
Definition: exceptions.h:313
Threads::ThreadLocalStorage< std::vector< double > > vars
void init_muparser() const
static ::ExceptionBase & ExcInvalidExpressionSize(int arg1, int arg2)
static ::ExceptionBase & ExcParseError(int arg1, char *arg2)
virtual void vector_value(const Point< dim > &p, Vector< double > &values) const
std::vector< std::string > var_names
void initialize(const std::string &vars, const std::vector< std::string > &expressions, const ConstMap &constants, const bool time_dependent=false)
std::map< std::string, double > ConstMap
static ::ExceptionBase & ExcNotImplemented()
std::vector< std::string > expressions
std::map< std::string, double > constants