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\}}\)
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
32namespace mu
33{
34 class Parser;
35}
36
38
39// Forward declaration
40#ifndef DOXYGEN
41template <typename>
42class Vector;
43#endif
44
222template <int dim>
224{
225public:
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
255
261
265 virtual ~FunctionParser() override;
266
272 operator=(const FunctionParser &) = delete;
273
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
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
378 int,
379 std::string,
380 << "Parsing Error at Column " << arg1
381 << ". The parser said: " << arg2);
382
384 int,
385 int,
386 << "The number of components (" << arg1
387 << ") is not equal to the number of expressions (" << arg2
388 << ").");
389
391
392private:
393#ifdef DEAL_II_WITH_MUPARSER
398
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
452template <int dim>
453std::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
FunctionParser(const unsigned int n_components=1, const double initial_time=0.0, const double h=1e-8)
std::map< std::string, double > ConstMap
virtual double value(const Point< dim > &p, const unsigned int component=0) const override
FunctionParser(FunctionParser &&)=delete
FunctionParser & operator=(FunctionParser &&)=delete
const std::vector< std::string > & get_expressions() const
FunctionParser(const FunctionParser &)=delete
virtual ~FunctionParser() override
void initialize(const std::string &vars, const std::vector< std::string > &expressions, const ConstMap &constants, const bool time_dependent=false)
virtual void vector_value(const Point< dim > &p, Vector< double > &values) const override
FunctionParser & operator=(const FunctionParser &)=delete
static std::string default_variable_names()
const unsigned int n_components
Definition: function.h:164
Definition: point.h:111
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
void init_muparser() const
std::vector< std::string > expressions
std::map< std::string, double > constants
static ::ExceptionBase & ExcNotImplemented()
unsigned int n_vars
#define Assert(cond, exc)
Definition: exceptions.h:1465
Threads::ThreadLocalStorage< std::vector< std::unique_ptr< mu::Parser > > > fp
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:538
static ::ExceptionBase & ExcInvalidExpressionSize(int arg1, int arg2)
Threads::ThreadLocalStorage< std::vector< double > > vars
static ::ExceptionBase & ExcParseError(int arg1, std::string arg2)
std::vector< std::string > var_names
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)