Reference documentation for deal.II version Git 53084d8c6a 2020-10-21 00:34:33 -0400
\(\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 
222 template <int dim>
224 {
225 public:
234  FunctionParser(const unsigned int n_components = 1,
235  const double initial_time = 0.0,
236  const double h = 1e-8);
237 
244  FunctionParser(const std::string &expression,
245  const std::string &constants = "",
246  const std::string &variable_names = default_variable_names() +
247  ",t",
248  const double h = 1e-8);
249 
254  FunctionParser(const FunctionParser &) = delete;
255 
260  FunctionParser(FunctionParser &&) = delete;
261 
265  virtual ~FunctionParser() override;
266 
272  operator=(const FunctionParser &) = delete;
273 
279  operator=(FunctionParser &&) = delete;
280 
284  using ConstMap = std::map<std::string, double>;
285 
320  void
321  initialize(const std::string & vars,
322  const std::vector<std::string> &expressions,
323  const ConstMap & constants,
324  const bool time_dependent = false);
325 
333  void
334  initialize(const std::string &vars,
335  const std::string &expression,
336  const ConstMap & constants,
337  const bool time_dependent = false);
338 
344  static std::string
345  default_variable_names();
346 
353  virtual double
354  value(const Point<dim> &p, const unsigned int component = 0) const override;
355 
363  virtual void
364  vector_value(const Point<dim> &p, Vector<double> &values) const override;
365 
370  const std::vector<std::string> &
371  get_expressions() const;
372 
377  DeclException2(ExcParseError,
378  int,
379  std::string,
380  << "Parsing Error at Column " << arg1
381  << ". The parser said: " << arg2);
382 
383  DeclException2(ExcInvalidExpressionSize,
384  int,
385  int,
386  << "The number of components (" << arg1
387  << ") is not equal to the number of expressions (" << arg2
388  << ").");
389 
391 
392 private:
393 #ifdef DEAL_II_WITH_MUPARSER
394 
398 
405  fp;
406 
411  std::map<std::string, double> constants;
412 
417  std::vector<std::string> var_names;
418 
425  void
426  init_muparser() const;
427 #endif
428 
433  std::vector<std::string> expressions;
434 
440 
448  unsigned int n_vars;
449 };
450 
451 
452 template <int dim>
453 std::string
455 {
456  switch (dim)
457  {
458  case 1:
459  return "x";
460  case 2:
461  return "x,y";
462  case 3:
463  return "x,y,z";
464  default:
465  Assert(false, ExcNotImplemented());
466  }
467  return "";
468 }
469 
470 
471 
473 
474 #endif
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:538
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:1423
Threads::ThreadLocalStorage< std::vector< double > > vars
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:369
std::vector< std::string > var_names
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:368
std::map< std::string, double > ConstMap
static ::ExceptionBase & ExcNotImplemented()
std::vector< std::string > expressions
std::map< std::string, double > constants