]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
New test.
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 2 Mar 2009 02:41:57 +0000 (02:41 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 2 Mar 2009 02:41:57 +0000 (02:41 +0000)
git-svn-id: https://svn.dealii.org/trunk@18442 0785d39b-7218-0410-832d-ea1e28bc413d

tests/base/function_parser_02.cc [new file with mode: 0644]
tests/base/function_parser_02/cmp/generic [new file with mode: 0644]

diff --git a/tests/base/function_parser_02.cc b/tests/base/function_parser_02.cc
new file mode 100644 (file)
index 0000000..ddb92df
--- /dev/null
@@ -0,0 +1,93 @@
+//----------------------------  function_parser.cc  ---------------------------
+//    $Id$
+//    Version: $Name$ 
+//
+//    Copyright (C) 2005, 2009 by the deal.II authors and Victor Prosolin
+//
+//    This file is subject to QPL and may not be  distributed
+//    without copyright and license information. Please refer
+//    to the file deal.II/doc/license.html for the  text  and
+//    further information on this license.
+//
+//----------------------------  function_parser.cc  ---------------------------
+
+
+// This program tests the functionality of the function parser
+// wrapper with respect to the ability to deal with units.
+
+#include "../tests.h"
+#include <fstream>
+#include <iomanip>
+#include <map>
+#include <base/logstream.h>
+#include <base/point.h>
+#include <lac/vector.h>
+#include <base/function_parser.h>
+
+
+int main () 
+{
+  std::ofstream logfile("function_parser_02/output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  
+  std::vector<std::string> function(1);
+  std::map<std::string, double> constants;
+  std::map<std::string, double> units;
+
+  constants["PI"] = 3.141592654;
+  units["cm"] = 10;
+  units["m"] = 1000;
+
+  Point<2> point(2.0, 3.0);
+
+                                  //initialized with units
+  FunctionParser<2> fp;
+  function[0] = "x cm + y m + PI";
+  fp.initialize(FunctionParser<2>::default_variable_names(),
+               function, constants, units);
+
+  deallog << "Function " << "[" << function[0] << "]" <<
+    " @point " << "[" << point << "]" << " is " <<
+    "[" <<  fp.value(point) << "]" << std::endl;
+
+                                  //now initialize with a function
+                                  //that's a string, not vector of
+                                  //strings
+  FunctionParser<2> fp4;
+  fp4.initialize(FunctionParser<2>::default_variable_names(),
+                function[0], constants, units);
+
+  deallog << "Function " << "[" << function[0] << "]" <<
+    " @point " << "[" << point << "]" << " is " <<
+    "[" <<  fp4.value(point) << "]" << std::endl;
+
+                                  //now initialize a function without
+                                  //units to check backwards
+                                  //compatibility
+  FunctionParser<2> fp2;
+  function[0] = "x + y + PI";
+  fp2.initialize(FunctionParser<2>::default_variable_names(),
+                function, constants);
+  deallog << "Function " << "[" << function[0] << "]" <<
+    " @point " << "[" << point << "]" << " is " <<
+    "[" <<  fp2.value(point) << "]" << std::endl;
+
+
+
+                                  //same as above but the function is
+                                  //a string, not a vector
+  FunctionParser<2> fp3;
+  fp3.initialize(FunctionParser<2>::default_variable_names(),
+                function[0], constants);
+
+  deallog << "Function " << "[" << function[0] << "]" <<
+    " @point " << "[" << point << "]" << " is " <<
+    "[" <<  fp3.value(point) << "]" << std::endl;
+}
+
+      
+
+  
diff --git a/tests/base/function_parser_02/cmp/generic b/tests/base/function_parser_02/cmp/generic
new file mode 100644 (file)
index 0000000..9e199c8
--- /dev/null
@@ -0,0 +1,5 @@
+
+DEAL::Function [x cm + y m + PI] @point [2.00000 3.00000] is [3023.14]
+DEAL::Function [x cm + y m + PI] @point [2.00000 3.00000] is [3023.14]
+DEAL::Function [x + y + PI] @point [2.00000 3.00000] is [8.14159]
+DEAL::Function [x + y + PI] @point [2.00000 3.00000] is [8.14159]

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.