]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add a new constructor for function parser.
authorLuca Heltai <luca.heltai@sissa.it>
Sat, 21 Jul 2018 14:42:26 +0000 (16:42 +0200)
committerLuca Heltai <luca.heltai@sissa.it>
Sat, 21 Jul 2018 14:42:26 +0000 (16:42 +0200)
include/deal.II/base/function_parser.h
source/base/function_parser.cc

index 7efdedf006c16588a50355a3836bb6d04b31de65..7cfb2615d3327419c416ec005679abdf5fd599cc 100644 (file)
@@ -211,6 +211,18 @@ public:
                  const double       initial_time = 0.0,
                  const double       h            = 1e-8);
 
+  /**
+   * Constructor for Parsed functions. Take directly a semi-colon separated
+   * list of expressions (one for each component of the function), an optional
+   * comma-separated list of constants, variable names and step for the
+   * computation of first order derviatives by finite difference.
+   */
+  FunctionParser(const std::string &expression,
+                 const std::string &constants      = "",
+                 const std::string &variable_names = default_variable_names() +
+                                                     ",t",
+                 const double h = 1e-8);
+
   /**
    * Destructor. Explicitly delete the FunctionParser objects (there is one
    * for each component of the function).
index 3b96b8a5cd2d1eacaef497c8e3c8acd0cbf89aaa..10e1dd95e95dbd139f31deed52f3edcf869932e7 100644 (file)
@@ -15,6 +15,7 @@
 
 
 #include <deal.II/base/function_parser.h>
+#include <deal.II/base/patterns.h>
 #include <deal.II/base/thread_management.h>
 #include <deal.II/base/utilities.h>
 
@@ -53,6 +54,33 @@ FunctionParser<dim>::FunctionParser(const unsigned int n_components,
 {}
 
 
+template <int dim>
+FunctionParser<dim>::FunctionParser(const std::string &expression,
+                                    const std::string &constants,
+                                    const std::string &variable_names,
+                                    const double       h)
+  : AutoDerivativeFunction<dim>(
+      h,
+      Utilities::split_string_list(expression, ';').size())
+  , initialized(false)
+  , n_vars(0)
+{
+  auto constants_map = Patterns::Tools::Convert<ConstMap>::to_value(
+    constants,
+    Patterns::Map(Patterns::Anything(),
+                  Patterns::Double(),
+                  0,
+                  Patterns::Map::max_int_value,
+                  ",",
+                  "=")
+      .clone());
+  initialize(variable_names,
+             expression,
+             constants_map,
+             Utilities::split_string_list(variable_names, ",").size() ==
+               dim + 1);
+}
+
 
 // We deliberately delay the definition of the default destructor
 // so that we don't need to include the definition of mu::Parser

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.