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
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 
260  int,
261  std::string,
262  << "Parsing Error at Column " << arg1
263  << ". The parser said: " << arg2);
264 
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
TensorFunctionParser::ExcParseError
static ::ExceptionBase & ExcParseError(int arg1, std::string arg2)
TensorFunctionParser::~TensorFunctionParser
virtual ~TensorFunctionParser() override
LinearAlgebraDealII::Vector
Vector< double > Vector
Definition: generic_linear_algebra.h:43
TensorFunctionParser::init_muparser
void init_muparser() const
Definition: tensor_function_parser.cc:146
TensorFunctionParser::ConstMap
std::map< std::string, double > ConstMap
Definition: tensor_function_parser.h:170
StandardExceptions::ExcNotImplemented
static ::ExceptionBase & ExcNotImplemented()
mu
Definition: function_parser.h:32
TensorFunctionParser::initialized
bool initialized
Definition: tensor_function_parser.h:321
TensorFunctionParser::tfp
Threads::ThreadLocalStorage< std::vector< std::unique_ptr< mu::Parser > > > tfp
Definition: tensor_function_parser.h:287
TensorFunctionParser::n_components
unsigned int n_components
Definition: tensor_function_parser.h:335
thread_local_storage.h
TensorFunctionParser::default_variable_names
static std::string default_variable_names()
Definition: tensor_function_parser.h:341
tensor.h
TensorFunctionParser::value
virtual Tensor< rank, dim, Number > value(const Point< dim > &p) const override
Definition: tensor_function_parser.cc:288
TensorFunctionParser::vars
Threads::ThreadLocalStorage< std::vector< double > > vars
Definition: tensor_function_parser.h:279
Tensor
Definition: tensor.h:450
TensorFunctionParser::expressions
std::vector< std::string > expressions
Definition: tensor_function_parser.h:315
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
TensorFunctionParser::get_expressions
const std::vector< std::string > & get_expressions() const
Definition: tensor_function_parser.cc:37
TensorFunctionParser::TensorFunctionParser
TensorFunctionParser(const double initial_time=0.0)
Definition: tensor_function_parser.cc:45
TensorFunctionParser::operator=
TensorFunctionParser & operator=(const TensorFunctionParser &)=delete
TensorFunctionParser
Definition: tensor_function_parser.h:112
TensorFunctionParser::value_list
virtual void value_list(const std::vector< Point< dim >> &p, std::vector< Tensor< rank, dim, Number >> &values) const override
Definition: tensor_function_parser.cc:333
Threads::ThreadLocalStorage
A class that provides a separate storage location on each thread that accesses the object.
Definition: thread_local_storage.h:72
TensorFunctionParser::n_vars
unsigned int n_vars
Definition: tensor_function_parser.h:330
TensorFunctionParser::var_names
std::vector< std::string > var_names
Definition: tensor_function_parser.h:299
exceptions.h
TensorFunction
Definition: tensor_function.h:57
TensorFunctionParser::initialize
void initialize(const std::string &vars, const std::vector< std::string > &expressions, const ConstMap &constants, const bool time_dependent=false)
Definition: tensor_function_parser.cc:91
Assert
#define Assert(cond, exc)
Definition: exceptions.h:1419
TensorFunctionParser::ExcInvalidExpressionSize
static ::ExceptionBase & ExcInvalidExpressionSize(int arg1, int arg2)
Point< dim >
config.h
TensorFunctionParser::constants
std::map< std::string, double > constants
Definition: tensor_function_parser.h:293
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
DeclException2
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:541
point.h
tensor_function.h