deal.II version GIT relicensing-6834-g5b78e6bcdf 2026-10-01 11:20:01+00:00
\(\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// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2005 - 2026 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13#ifndef dealii_function_parser_h
14#define dealii_function_parser_h
15
16
17#include <deal.II/base/config.h>
18
21#include <deal.II/base/point.h>
22
23#include <map>
24#include <vector>
25
27
28// Forward declaration
29#ifndef DOXYGEN
30template <typename>
31class Vector;
32#endif
33
219template <int dim>
221 : public AutoDerivativeFunction<dim>,
223{
224public:
233 FunctionParser(const unsigned int n_components = 1,
234 const double initial_time = 0.0,
235 const double h = 1e-8);
236
243 FunctionParser(const std::string &expression,
244 const std::string &constants = "",
245 const std::string &variable_names = default_variable_names() +
246 ",t",
247 const double h = 1e-8);
248
254
260
266 operator=(const FunctionParser &) = delete;
267
274
278 using ConstMap = std::map<std::string, double>;
279
314 virtual void
315 initialize(const std::string &vars,
316 const std::vector<std::string> &expressions,
317 const ConstMap &constants,
318 const bool time_dependent = false) override;
319
327 void
328 initialize(const std::string &vars,
329 const std::string &expression,
330 const ConstMap &constants,
331 const bool time_dependent = false);
332
338 static std::string
340
347 virtual double
348 value(const Point<dim> &p, const unsigned int component = 0) const override;
349
354 const std::vector<std::string> &
355 get_expressions() const;
356
362 int,
363 std::string,
364 << "Parsing Error at Column " << arg1
365 << ". The parser said: " << arg2);
366
368 int,
369 int,
370 << "The number of components (" << arg1
371 << ") is not equal to the number of expressions (" << arg2
372 << ").");
373
375};
376
377
378template <int dim>
379std::string
381{
382 switch (dim)
383 {
384 case 1:
385 return "x";
386 case 2:
387 return "x,y";
388 case 3:
389 return "x,y,z";
390 default:
392 }
393 return "";
394}
395
396
397
399
400#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:162
Definition point.h:111
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
#define DEAL_II_NOT_IMPLEMENTED()
#define DeclException2(Exception2, type1, type2, outsequence)
static ::ExceptionBase & ExcInvalidExpressionSize(int arg1, int arg2)
static ::ExceptionBase & ExcParseError(int arg1, std::string arg2)