]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Test Using add parameter.
authorLuca Heltai <luca.heltai@sissa.it>
Wed, 20 Sep 2017 09:43:43 +0000 (11:43 +0200)
committerLuca Heltai <luca.heltai@sissa.it>
Tue, 26 Sep 2017 17:19:23 +0000 (19:19 +0200)
tests/parameter_handler/parameter_acceptor_02.cc [new file with mode: 0644]
tests/parameter_handler/parameter_acceptor_02.output [new file with mode: 0644]

diff --git a/tests/parameter_handler/parameter_acceptor_02.cc b/tests/parameter_handler/parameter_acceptor_02.cc
new file mode 100644 (file)
index 0000000..7f3ecbe
--- /dev/null
@@ -0,0 +1,80 @@
+//-----------------------------------------------------------
+//
+//    Copyright (C) 2015 by the deal.II authors
+//
+//    This file is part of the deal.II library.
+//
+//    The deal.II library is free software; you can use it, redistribute
+//    it, and/or modify it under the terms of the GNU Lesser General
+//    Public License as published by the Free Software Foundation; either
+//    version 2.1 of the License, or (at your option) any later version.
+//    The full text of the license can be found in the file LICENSE at
+//    the top level of the deal.II distribution.
+//
+//-----------------------------------------------------------
+
+#include "../tests.h"
+#include <deal.II/base/utilities.h>
+#include <deal.II/base/parameter_acceptor.h>
+#include <boost/core/demangle.hpp>
+
+template<int dim>
+class Test : public ParameterAcceptor
+{
+public:
+  Test()
+  {
+    add_parameter("A double", a);
+    add_parameter("An int"  , b);
+    add_parameter("A string", c);
+    add_parameter("A bool"  , d);
+  };
+
+  void log_info()
+  {
+    deallog << "My type: " << boost::core::demangle(typeid(*this).name()) << std::endl
+            << "a: " << a << std::endl
+            << "b: " << b << std::endl
+            << "c: " << c << std::endl
+            << "d: " << (d ? "true" : "false") << std::endl;
+  }
+
+private:
+  double a = 1.0;
+  int b = 2;
+  std::string c = "Ciao";
+  bool d = true;
+
+};
+
+
+int main ()
+{
+  initlog();
+  Test<1> a;
+  Test<2> b;
+
+  auto &prm = ParameterAcceptor::prm;
+
+  ParameterAcceptor::declare_all_parameters();
+  ParameterAcceptor::parse_all_parameters();
+  prm.log_parameters(deallog);
+
+  a.log_info();
+  b.log_info();
+
+  prm.parse_input_from_string(""
+                              "subsection Test<1>\n"
+                              "  set A double = 3.0\n"
+                              "end\n"
+                              "subsection Test<2>\n"
+                              "  set A double = 5.0\n"
+                              "end\n");
+
+  prm.log_parameters(deallog);
+  ParameterAcceptor::parse_all_parameters(prm);
+
+  a.log_info();
+  b.log_info();
+
+}
diff --git a/tests/parameter_handler/parameter_acceptor_02.output b/tests/parameter_handler/parameter_acceptor_02.output
new file mode 100644 (file)
index 0000000..e2e44a3
--- /dev/null
@@ -0,0 +1,37 @@
+
+DEAL:parameters:Test<1>::A bool: true
+DEAL:parameters:Test<1>::A double: 1.0
+DEAL:parameters:Test<1>::A string: Ciao
+DEAL:parameters:Test<1>::An int: 2
+DEAL:parameters:Test<2>::A bool: true
+DEAL:parameters:Test<2>::A double: 1.0
+DEAL:parameters:Test<2>::A string: Ciao
+DEAL:parameters:Test<2>::An int: 2
+DEAL::My type: Test<1>
+DEAL::a: 1.00000
+DEAL::b: 2
+DEAL::c: Ciao
+DEAL::d: true
+DEAL::My type: Test<2>
+DEAL::a: 1.00000
+DEAL::b: 2
+DEAL::c: Ciao
+DEAL::d: true
+DEAL:parameters:Test<1>::A bool: true
+DEAL:parameters:Test<1>::A double: 3.0
+DEAL:parameters:Test<1>::A string: Ciao
+DEAL:parameters:Test<1>::An int: 2
+DEAL:parameters:Test<2>::A bool: true
+DEAL:parameters:Test<2>::A double: 5.0
+DEAL:parameters:Test<2>::A string: Ciao
+DEAL:parameters:Test<2>::An int: 2
+DEAL::My type: Test<1>
+DEAL::a: 3.00000
+DEAL::b: 2
+DEAL::c: Ciao
+DEAL::d: true
+DEAL::My type: Test<2>
+DEAL::a: 5.00000
+DEAL::b: 2
+DEAL::c: Ciao
+DEAL::d: true

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.