Reference documentation for deal.II version 9.4.1
\(\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\}}\)
Loading...
Searching...
No Matches
function_parser.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 2005 - 2022 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
25#include <deal.II/base/point.h>
26#include <deal.II/base/tensor.h>
27
28#include <map>
29#include <vector>
30
32
33// Forward declaration
34#ifndef DOXYGEN
35template <typename>
36class Vector;
37#endif
38
216template <int dim>
218 : public AutoDerivativeFunction<dim>,
220{
221public:
230 FunctionParser(const unsigned int n_components = 1,
231 const double initial_time = 0.0,
232 const double h = 1e-8);
233
240 FunctionParser(const std::string &expression,
241 const std::string &constants = "",
242 const std::string &variable_names = default_variable_names() +
243 ",t",
244 const double h = 1e-8);
245
251
257
263 operator=(const FunctionParser &) = delete;
264
271
275 using ConstMap = std::map<std::string, double>;
276
311 virtual void
312 initialize(const std::string & vars,
313 const std::vector<std::string> &expressions,
314 const ConstMap & constants,
315 const bool time_dependent = false) override;
316
324 void
325 initialize(const std::string &vars,
326 const std::string &expression,
327 const ConstMap & constants,
328 const bool time_dependent = false);
329
335 static std::string
337
344 virtual double
345 value(const Point<dim> &p, const unsigned int component = 0) const override;
346
351 const std::vector<std::string> &
352 get_expressions() const;
353
359 int,
360 std::string,
361 << "Parsing Error at Column " << arg1
362 << ". The parser said: " << arg2);
363
365 int,
366 int,
367 << "The number of components (" << arg1
368 << ") is not equal to the number of expressions (" << arg2
369 << ").");
370
372};
373
374
375template <int dim>
376std::string
378{
379 switch (dim)
380 {
381 case 1:
382 return "x";
383 case 2:
384 return "x,y";
385 case 3:
386 return "x,y,z";
387 default:
388 Assert(false, ExcNotImplemented());
389 }
390 return "";
391}
392
393
394
396
397#endif
virtual void initialize(const std::string &vars, const std::vector< std::string > &expressions, const ConstMap &constants, const bool time_dependent=false) override
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
FunctionParser & operator=(const FunctionParser &)=delete
static std::string default_variable_names()
const unsigned int n_components
Definition: function.h:164
Definition: point.h:111
Definition: vector.h:109
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:442
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:443
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
Definition: exceptions.h:1473
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:532
static ::ExceptionBase & ExcInvalidExpressionSize(int arg1, int arg2)
static ::ExceptionBase & ExcParseError(int arg1, std::string arg2)