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\}}\)
tensor_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_tensor_function_parser_h
17 #define dealii_tensor_function_parser_h
18 
19 
20 #include <deal.II/base/config.h>
21 
23 #include <deal.II/base/point.h>
24 #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 
111 template <int rank, int dim, typename Number = double>
112 class TensorFunctionParser : public TensorFunction<rank, dim, Number>
113 {
114 public:
121  TensorFunctionParser(const double initial_time = 0.0);
122 
132  const std::string &expression,
133  const std::string &constants = "",
134  const std::string &variable_names = default_variable_names() + ",t");
135 
140  TensorFunctionParser(const TensorFunctionParser &) = delete;
141 
147 
151  virtual ~TensorFunctionParser() override;
152 
158  operator=(const TensorFunctionParser &) = delete;
159 
165  operator=(TensorFunctionParser &&) = delete;
166 
170  using ConstMap = std::map<std::string, double>;
171 
172 
208  void
209  initialize(const std::string & vars,
210  const std::vector<std::string> &expressions,
211  const ConstMap & constants,
212  const bool time_dependent = false);
213 
221  void
222  initialize(const std::string &vars,
223  const std::string &expression,
224  const ConstMap & constants,
225  const bool time_dependent = false);
226 
232  static std::string
233  default_variable_names();
234 
239  value(const Point<dim> &p) const override;
240 
244  virtual void
245  value_list(const std::vector<Point<dim>> & p,
246  std::vector<Tensor<rank, dim, Number>> &values) const override;
247 
252  const std::vector<std::string> &
253  get_expressions() const;
254 
259  DeclException2(ExcParseError,
260  int,
261  std::string,
262  << "Parsing Error at Column " << arg1
263  << ". The parser said: " << arg2);
264 
265  DeclException2(ExcInvalidExpressionSize,
266  int,
267  int,
268  << "The number of components (" << arg1
269  << ") is not equal to the number of expressions (" << arg2
270  << ").");
271 
273 
274 private:
275 #ifdef DEAL_II_WITH_MUPARSER
276 
280 
288 
293  std::map<std::string, double> constants;
294 
299  std::vector<std::string> var_names;
300 
307  void
308  init_muparser() const;
309 #endif
310 
315  std::vector<std::string> expressions;
316 
322 
330  unsigned int n_vars;
331 
335  unsigned int n_components;
336 };
337 
338 
339 template <int rank, int dim, typename Number>
340 std::string
342 {
343  switch (dim)
344  {
345  case 1:
346  return "x";
347  case 2:
348  return "x,y";
349  case 3:
350  return "x,y,z";
351  default:
352  Assert(false, ExcNotImplemented());
353  }
354  return "";
355 }
356 
357 
358 
360 
361 #endif
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:541
std::map< std::string, double > constants
A class that provides a separate storage location on each thread that accesses the object...
std::map< std::string, double > ConstMap
Threads::ThreadLocalStorage< std::vector< std::unique_ptr< mu::Parser > > > tfp
static std::string default_variable_names()
#define Assert(cond, exc)
Definition: exceptions.h:1419
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
std::vector< std::string > expressions
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
Threads::ThreadLocalStorage< std::vector< double > > vars
static ::ExceptionBase & ExcNotImplemented()
std::vector< std::string > var_names
static const bool value