From 27e62dac216b6882e16e88a252b7d2534836a44d Mon Sep 17 00:00:00 2001 From: schrage Date: Wed, 23 Jun 1999 16:25:02 +0000 Subject: [PATCH] Premature check-in for data transfer. git-svn-id: https://svn.dealii.org/trunk@1451 0785d39b-7218-0410-832d-ea1e28bc413d --- .../chapter-1.elements/parameters.html | 161 ++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 deal.II/doc/tutorial/chapter-1.elements/parameters.html diff --git a/deal.II/doc/tutorial/chapter-1.elements/parameters.html b/deal.II/doc/tutorial/chapter-1.elements/parameters.html new file mode 100644 index 0000000000..2c75b2a25e --- /dev/null +++ b/deal.II/doc/tutorial/chapter-1.elements/parameters.html @@ -0,0 +1,161 @@ + + + + + + +Parameter Input + + + + + + + + +

Parameter Input

+ +

+When writing a numerical program you will usually wish to keep it flexible +with regard to parameter settings and the like. Rewriting a program +everytime a parameter changes is ever so annoying. +For this reason deal.II provides a class +called ParameterHandler. This class enables you to easily +parse a parameter file and extract the values of the parameters. +The names and allowed values of the parameters can be defined by you. +

+ +

+Example: +We enable a program, that is, the class TestCases that really handles +everything to read parameters from a file given on the command line. +Everything that is not strictly relevant to parameter input has been cut out. +

+ +
 
+
+#include <base/parameter_handler.h>
+
+
+#include <fstream>
+#include <cmath>
+#include <cstdlib>
+
+
+
+template <int dim>
+class TestCases : public MultipleParameterLoop::UserClass{
+  public:
+    TestCases ();
+    
+    virtual void declare_parameters (ParameterHandler &prm);
+    virtual void run (ParameterHandler &prm);
+
+};
+
+
+
+template <int dim>
+TestCases<dim>::TestCases () :
+		{};
+
+
+
+template <int dim>
+void TestCases<dim>::declare_parameters (ParameterHandler &prm) {
+  if (dim>=2)
+    prm.declare_entry ("Test run", "zoom in",
+		       Patterns::Sequence("zoom in|ball|curved line|random"));
+  else
+    prm.declare_entry ("Test run", "zoom in",
+		       Patterns::Sequence("zoom in|random"));
+  prm.declare_entry ("Grid file", "grid.1");
+  prm.declare_entry ("Sparsity file", "sparsity.1");
+  prm.declare_entry ("Condensed sparsity file", "sparsity.c.1");
+};
+
+
+
+template <int dim>
+void TestCases<dim>::run (ParameterHandler &prm) {
+  cout << "Test case = " << prm.get ("Test run") << endl
+       << endl;
+  
+  cout << "    Making grid..." << endl;
+
+  string test = prm.get ("Test run");
+  unsigned int test_case;
+  if (test=="zoom in") test_case = 1;
+  else
+    if (test=="ball") test_case = 2;
+    else
+      if (test=="curved line") test_case = 3;
+      else
+	if (test=="random") test_case = 4;
+	else
+	  cerr << "This test seems not to be implemented!" << endl;
+  
+  
+  switch (test_case) 
+    {
+      case 1:  // code for case 1: zoom in
+      case 2:  // code for case 2: ball
+      case 3:  // code for case 3: curved line
+      case 4:  // code for case 4: random
+    };
+
+  cout << "    Writing grid..." << endl;
+  ofstream out(prm.get("Grid file").c_str());
+  // code for output
+
+};
+
+
+
+int main (int argc, char **argv) {
+  if (argc!=2) 
+    {
+      cout << "Usage: grid_test parameterfile" << endl << endl;
+      return 1;
+    };
+
+  TestCases<2> tests;
+  class MultipleParameterLoop input_data;   //needs at least gcc2.8
+
+  tests.declare_parameters(input_data);
+  input_data.read_input (argv[1]);
+  input_data.loop (tests);
+  
+  return 0;
+};
+
+
+ + +
+ + + + + + + +
+
+Jan Schrage
+

+Last modified: $Date$ +

+ + -- 2.39.5