]> https://gitweb.dealii.org/ - dealii.git/commitdiff
add support for pow(a,b) in FunctionParser 1695/head
authorTimo Heister <timo.heister@gmail.com>
Wed, 30 Sep 2015 17:39:35 +0000 (13:39 -0400)
committerTimo Heister <timo.heister@gmail.com>
Wed, 30 Sep 2015 17:39:35 +0000 (13:39 -0400)
it turns out muparser only supports "a^b" out of the box, so we add
"pow(a,b)" as a custom function.

doc/news/changes.h
source/base/function_parser.cc
tests/base/function_parser_06.cc
tests/base/function_parser_06.with_muparser=true.output

index 4763589e90a58a8e953b1955f6f772faaf0f166b..3ad05671c42d54bc6a91944e285963bee6d4b844 100644 (file)
@@ -159,6 +159,11 @@ inconvenience this causes.
 <a name="general"></a>
 <h3>General</h3>
 <ol>
+  <li> New: FunctionParser now supports pow(a,b).
+  <br>
+  (Timo Heister, 2015/09/30)
+  </li>
+
   <li> New: MGTransferPrebuilt can now be used with parallel::distributed::Vector
   and TrilinosWrappers::SparseMatrix as a transfer matrix.
   <br>
index 61aef60acf20be2ce144ebaa719a0e65b72aa329..25ffd17e81dcd263f06aae9c0b177a02bdd6bdcc 100644 (file)
@@ -165,6 +165,11 @@ namespace internal
   {
     return log(value);
   }
+
+  double mu_pow(double a, double b)
+  {
+    return std::pow(a, b);
+  }
 }
 
 
@@ -202,6 +207,7 @@ void FunctionParser<dim>:: init_muparser() const
       fp.get()[component].DefineFun("floor", internal::mu_floor, true);
       fp.get()[component].DefineFun("sec", internal::mu_sec, true);
       fp.get()[component].DefineFun("log", internal::mu_log, true);
+      fp.get()[component].DefineFun("pow", internal::mu_pow, true);
 
       try
         {
@@ -250,7 +256,8 @@ void FunctionParser<dim>:: init_muparser() const
             "cot",
             "csc",
             "floor",
-            "sec"
+            "sec",
+            "pow"
           };
           for (unsigned int f=0; f<sizeof(function_names)/sizeof(function_names[0]); ++f)
             {
index 31c2a1e044e78d361e9a56710f99ee3f07cc6a76..816641f90dbe94a4433bfc2a4ed1b6cdb4494728 100644 (file)
@@ -96,6 +96,7 @@ void test()
   eval("sqrt(0.5)",Point<2>(0,0), sqrt(0.5));
   eval("tan(0.5)",Point<2>(0,0), tan(0.5));
   eval("tanh(0.5)",Point<2>(0,0), tanh(0.5));
+  eval("pow (9.0, 0.5)",Point<2>(0,0), 3.0);
 
 
 }
index 2ec9e6652b9cabb570280c6538816005514a0e8e..41caadd752c55c28bb3863ddcf7f7a36c2d46f06 100644 (file)
@@ -35,3 +35,4 @@ DEAL::'sinh(0.5)' @ 0.00000 0.00000 is 0.521095 ( expected 0.521095 )
 DEAL::'sqrt(0.5)' @ 0.00000 0.00000 is 0.707107 ( expected 0.707107 )
 DEAL::'tan(0.5)' @ 0.00000 0.00000 is 0.546302 ( expected 0.546302 )
 DEAL::'tanh(0.5)' @ 0.00000 0.00000 is 0.462117 ( expected 0.462117 )
+DEAL::'pow (9.0, 0.5)' @ 0.00000 0.00000 is 3.00000 ( expected 3.00000 )

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.