Reference documentation for deal.II version 9.3.3
\(\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
32namespace mu
33{
34 class Parser;
35}
36
38
39// Forward declaration
40#ifndef DOXYGEN
41template <typename>
42class Vector;
43#endif
44
110template <int rank, int dim, typename Number = double>
111class TensorFunctionParser : public TensorFunction<rank, dim, Number>
112{
113public:
120 TensorFunctionParser(const double initial_time = 0.0);
121
131 const std::string &expression,
132 const std::string &constants = "",
133 const std::string &variable_names = default_variable_names() + ",t");
134
140
146
150 virtual ~TensorFunctionParser() override;
151
158
165
169 using ConstMap = std::map<std::string, double>;
170
171
207 void
208 initialize(const std::string & vars,
209 const std::vector<std::string> &expressions,
210 const ConstMap & constants,
211 const bool time_dependent = false);
212
220 void
221 initialize(const std::string &vars,
222 const std::string &expression,
223 const ConstMap & constants,
224 const bool time_dependent = false);
225
231 static std::string
233
238 value(const Point<dim> &p) const override;
239
243 virtual void
244 value_list(const std::vector<Point<dim>> & p,
245 std::vector<Tensor<rank, dim, Number>> &values) const override;
246
251 const std::vector<std::string> &
252 get_expressions() const;
253
259 int,
260 std::string,
261 << "Parsing Error at Column " << arg1
262 << ". The parser said: " << arg2);
263
265 int,
266 int,
267 << "The number of components (" << arg1
268 << ") is not equal to the number of expressions (" << arg2
269 << ").");
270
272
273private:
274#ifdef DEAL_II_WITH_MUPARSER
279
287
292 std::map<std::string, double> constants;
293
298 std::vector<std::string> var_names;
299
306 void
307 init_muparser() const;
308#endif
309
314 std::vector<std::string> expressions;
315
321
329 unsigned int n_vars;
330
334 unsigned int n_components;
335};
336
337
338template <int rank, int dim, typename Number>
339std::string
341{
342 switch (dim)
343 {
344 case 1:
345 return "x";
346 case 2:
347 return "x,y";
348 case 3:
349 return "x,y,z";
350 default:
351 Assert(false, ExcNotImplemented());
352 }
353 return "";
354}
355
356
357
359
360#endif
Definition: point.h:111
TensorFunctionParser & operator=(const TensorFunctionParser &)=delete
TensorFunctionParser(const double initial_time=0.0)
virtual Tensor< rank, dim, Number > value(const Point< dim > &p) const override
TensorFunctionParser(const TensorFunctionParser &)=delete
TensorFunctionParser(TensorFunctionParser &&)=delete
void initialize(const std::string &vars, const std::vector< std::string > &expressions, const ConstMap &constants, const bool time_dependent=false)
TensorFunctionParser & operator=(TensorFunctionParser &&)=delete
virtual void value_list(const std::vector< Point< dim > > &p, std::vector< Tensor< rank, dim, Number > > &values) const override
static std::string default_variable_names()
std::map< std::string, double > ConstMap
virtual ~TensorFunctionParser() override
const std::vector< std::string > & get_expressions() const
Definition: tensor.h:472
A class that provides a separate storage location on each thread that accesses the object.
Definition: vector.h:110
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:402
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:403
static ::ExceptionBase & ExcParseError(int arg1, std::string arg2)
Threads::ThreadLocalStorage< std::vector< double > > vars
Threads::ThreadLocalStorage< std::vector< std::unique_ptr< mu::Parser > > > tfp
static ::ExceptionBase & ExcNotImplemented()
std::map< std::string, double > constants
#define Assert(cond, exc)
Definition: exceptions.h:1465
static ::ExceptionBase & ExcInvalidExpressionSize(int arg1, int arg2)
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:538
std::vector< std::string > var_names
std::vector< std::string > expressions