Reference documentation for deal.II version 9.0.0
function_parser.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2005 - 2017 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 #include <memory>
29 
30 namespace mu
31 {
32  class Parser;
33 }
34 
35 DEAL_II_NAMESPACE_OPEN
36 
37 
38 template <typename> class Vector;
39 
40 
194 template <int dim>
196 {
197 public:
207  FunctionParser (const unsigned int n_components = 1,
208  const double initial_time = 0.0,
209  const double h = 1e-8);
210 
215  ~FunctionParser();
216 
220  typedef std::map<std::string, double> ConstMap;
221 
225  typedef ConstMap::iterator ConstMapIterator;
226 
261  void initialize (const std::string &vars,
262  const std::vector<std::string> &expressions,
263  const ConstMap &constants,
264  const bool time_dependent = false);
265 
273  void initialize (const std::string &vars,
274  const std::string &expression,
275  const ConstMap &constants,
276  const bool time_dependent = false);
277 
283  static
284  std::string
286 
293  virtual double value (const Point<dim> &p,
294  const unsigned int component = 0) const;
295 
302  virtual void vector_value (const Point<dim> &p,
303  Vector<double> &values) const;
304 
310  int, char *,
311  << "Parsing Error at Column " << arg1
312  << ". The parser said: " << arg2);
313 
315  int, int,
316  << "The number of components (" << arg1
317  << ") is not equal to the number of expressions ("
318  << arg2 << ").");
319 
321 
322 private:
323 #ifdef DEAL_II_WITH_MUPARSER
324 
328 
334 #if TBB_VERSION_MAJOR >= 4
336 #else
337  // older TBBs have a bug in which they want to return thread-local
338  // objects by value. this doesn't work for std::unique_ptr, so use a
339  // std::shared_ptr
341 #endif
342 
347  std::map<std::string, double> constants;
348 
353  std::vector<std::string> var_names;
354 
359  std::vector<std::string> expressions;
360 
367  void init_muparser() const;
368 #endif
369 
375 
383  unsigned int n_vars;
384 };
385 
386 
387 template <int dim>
388 std::string
390 {
391  switch (dim)
392  {
393  case 1:
394  return "x";
395  case 2:
396  return "x,y";
397  case 3:
398  return "x,y,z";
399  default:
400  Assert (false, ExcNotImplemented());
401  }
402  return "";
403 }
404 
405 
406 
407 DEAL_II_NAMESPACE_CLOSE
408 
409 #endif
410 
411 
FunctionParser(const unsigned int n_components=1, const double initial_time=0.0, const double h=1e-8)
Threads::ThreadLocalStorage< std::vector< std::shared_ptr< mu::Parser > > > fp
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:358
const unsigned int n_components
Definition: function.h:154
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
static std::string default_variable_names()
#define Assert(cond, exc)
Definition: exceptions.h:1142
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