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
346  default_variable_names();
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 
378  DeclException2(ExcParseError,
379  int,
380  std::string,
381  << "Parsing Error at Column " << arg1
382  << ". The parser said: " << arg2);
383 
384  DeclException2(ExcInvalidExpressionSize,
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
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:541
A class that provides a separate storage location on each thread that accesses the object...
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)
unsigned int n_vars
static std::string default_variable_names()
Threads::ThreadLocalStorage< std::vector< std::unique_ptr< mu::Parser > > > fp
#define Assert(cond, exc)
Definition: exceptions.h:1419
Threads::ThreadLocalStorage< std::vector< double > > vars
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
std::vector< std::string > var_names
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
std::map< std::string, double > ConstMap
static ::ExceptionBase & ExcNotImplemented()
unsigned int n_components(const DoFHandler< dim, spacedim > &dh)
static const bool value
std::vector< std::string > expressions
std::map< std::string, double > constants