]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Function parser Test suite.
authorluca <luca@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 31 Mar 2005 17:31:27 +0000 (17:31 +0000)
committerluca <luca@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 31 Mar 2005 17:31:27 +0000 (17:31 +0000)
git-svn-id: https://svn.dealii.org/trunk@10332 0785d39b-7218-0410-832d-ea1e28bc413d

tests/base/Makefile
tests/base/function_parser.cc [new file with mode: 0644]
tests/results/i686-pc-linux-gnu+gcc3.4/base/function_parser.output [new file with mode: 0644]

index 7d677602d2bc5a8d291346bf9ffaf5e8db8ffb9a..6dfa667f9d09ef86f92e3c95caae2bc1cc89a2ee 100644 (file)
@@ -36,7 +36,8 @@ tests_x =  logtest \
           auto_derivative_function \
           anisotropic_* \
            hierarchical \
-          data_out_base
+          data_out_base \
+          function_parser
 
 # from above list of regular expressions, generate the real set of
 # tests
diff --git a/tests/base/function_parser.cc b/tests/base/function_parser.cc
new file mode 100644 (file)
index 0000000..2cbdc9c
--- /dev/null
@@ -0,0 +1,95 @@
+//----------------------------  function_parser.cc  ---------------------------
+//    $Id$
+//    Version: $Name$ 
+//
+//    Copyright (C) 2005 by the deal.II authors 
+//
+//    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. 
+
+#include "../tests.h"
+#include <fstream>
+#include <iostream>
+#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.output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  
+  // Define some constants that will be used by the function parser
+  std::map<std::string, double> constants;
+  constants["pi"] = M_PI;
+  // Define the variables that will be used inside the expressions
+  std::string variables = "x,y";
+  // Define the expressions of the vector_valued function.
+  std::vector<std::string> expressions;
+  expressions.push_back("sin(2*pi*x)");
+  expressions.push_back("cos(2*pi*y*x)");
+  expressions.push_back("if(x<.5,y,exp(x))");
+  expressions.push_back("if(x<.5,y,exp(x)*exp(x*y))");
+  
+  // Concatenate the declared expressions, to test the second way of
+  // initializing
+  std::string concatenated="cos(pi*y)";
+  // Now test each possibility
+  for(unsigned int i=1; i<=expressions.size(); ++i) {
+    try {
+      {
+       FunctionParser<2> function(i);
+       function.initialize(variables,
+                           expressions,
+                           constants);
+       deallog << "Initialize Succeded with dim = 2, "
+               << i << " components, "
+               << expressions.size() << " expressions, " 
+               << variables << " as variables." << std::endl;
+      }
+    } catch(...) {
+       deallog << "Initialize Failed with dim = 2, "
+               << i << " components, "
+               << expressions.size() << " expressions, " 
+               << variables << " as variables." << std::endl;
+    }
+    
+    try {
+      {
+       FunctionParser<2> function_bis(i);
+       function_bis.initialize(variables,
+                               concatenated,
+                               constants);
+       deallog << "Initialize Succeded with dim = 2, "
+               << i << " components, "
+               << concatenated << " as function and "
+               << variables << " as variables." << std::endl; 
+      }
+    } catch(...) {
+      deallog << "Initialize Failed with dim = 2, "
+             << i << " components, "
+             << concatenated  << " as function and "
+             << variables << " as variables." << std::endl;
+    }
+    
+    concatenated += "; " + expressions[i-1];
+  }
+}
+
+      
+
+  
diff --git a/tests/results/i686-pc-linux-gnu+gcc3.4/base/function_parser.output b/tests/results/i686-pc-linux-gnu+gcc3.4/base/function_parser.output
new file mode 100644 (file)
index 0000000..4ecbff8
--- /dev/null
@@ -0,0 +1,9 @@
+
+DEAL::Initialize Failed with dim = 2, 1 components, 4 expressions, x,y as variables.
+DEAL::Initialize Succeded with dim = 2, 1 components, cos(pi*y) as function and x,y as variables.
+DEAL::Initialize Failed with dim = 2, 2 components, 4 expressions, x,y as variables.
+DEAL::Initialize Succeded with dim = 2, 2 components, cos(pi*y); sin(2*pi*x) as function and x,y as variables.
+DEAL::Initialize Failed with dim = 2, 3 components, 4 expressions, x,y as variables.
+DEAL::Initialize Succeded with dim = 2, 3 components, cos(pi*y); sin(2*pi*x); cos(2*pi*y*x) as function and x,y as variables.
+DEAL::Initialize Succeded with dim = 2, 4 components, 4 expressions, x,y as variables.
+DEAL::Initialize Succeded with dim = 2, 4 components, cos(pi*y); sin(2*pi*x); cos(2*pi*y*x); if(x<.5,y,exp(x)) as function and x,y as variables.

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.