Reference documentation for deal.II version 8.4.2
function_parser.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2005 - 2015 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/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>
180 class FunctionParser : public Function<dim>
181 {
182 public:
190  FunctionParser (const unsigned int n_components = 1,
191  const double initial_time = 0.0);
192 
197  ~FunctionParser();
198 
202  typedef std::map<std::string, double> ConstMap;
203 
207  typedef ConstMap::iterator ConstMapIterator;
208 
243  void initialize (const std::string &vars,
244  const std::vector<std::string> &expressions,
245  const ConstMap &constants,
246  const bool time_dependent = false);
247 
255  void initialize (const std::string &vars,
256  const std::string &expression,
257  const ConstMap &constants,
258  const bool time_dependent = false);
259 
265  static
266  std::string
267  default_variable_names ();
268 
275  virtual double value (const Point<dim> &p,
276  const unsigned int component = 0) const;
277 
284  virtual void vector_value (const Point<dim> &p,
285  Vector<double> &values) const;
286 
291  DeclException2 (ExcParseError,
292  int, char *,
293  << "Parsing Error at Column " << arg1
294  << ". The parser said: " << arg2);
295 
296  DeclException2 (ExcInvalidExpressionSize,
297  int, int,
298  << "The number of components (" << arg1
299  << ") is not equal to the number of expressions ("
300  << arg2 << ").");
301 
303 
304 private:
305 #ifdef DEAL_II_WITH_MUPARSER
306 
310 
315 
320  std::map<std::string, double> constants;
321 
326  std::vector<std::string> var_names;
327 
332  std::vector<std::string> expressions;
333 
340  void init_muparser() const;
341 #endif
342 
348 
356  unsigned int n_vars;
357 };
358 
359 
360 template <int dim>
361 std::string
363 {
364  switch (dim)
365  {
366  case 1:
367  return "x";
368  case 2:
369  return "x,y";
370  case 3:
371  return "x,y,z";
372  default:
373  Assert (false, ExcNotImplemented());
374  }
375  return "";
376 }
377 
378 
379 
380 DEAL_II_NAMESPACE_CLOSE
381 
382 #endif
383 
384 
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:552
A class that provides a separate storage location on each thread that accesses the object...
ConstMap::iterator ConstMapIterator
unsigned int n_vars
Threads::ThreadLocalStorage< std::vector< mu::Parser > > fp
static std::string default_variable_names()
#define Assert(cond, exc)
Definition: exceptions.h:294
Threads::ThreadLocalStorage< std::vector< double > > vars
std::vector< std::string > var_names
std::map< std::string, double > ConstMap
std::vector< std::string > expressions
std::map< std::string, double > constants