]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Function parser Test suite.
authorLuca Heltai <luca.heltai@sissa.it>
Thu, 31 Mar 2005 17:31:27 +0000 (17:31 +0000)
committerLuca Heltai <luca.heltai@sissa.it>
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]

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];
+  }
+}
+
+      
+
+  

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.