Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Tempus_IntegratorTest.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ****************************************************************************
3 // Tempus: Copyright (2017) Sandia Corporation
4 //
5 // Distributed under BSD 3-clause license (See accompanying file Copyright.txt)
6 // ****************************************************************************
7 // @HEADER
8 
9 #include "Teuchos_UnitTestHarness.hpp"
10 #include "Teuchos_XMLParameterListHelpers.hpp"
11 #include "Teuchos_TimeMonitor.hpp"
12 
13 #include "Tempus_IntegratorBasic.hpp"
14 
15 #include "../TestModels/SinCosModel.hpp"
16 
17 #include <vector>
18 
19 namespace Tempus_Test {
20 
21 using Teuchos::RCP;
22 using Teuchos::ParameterList;
23 using Teuchos::sublist;
24 using Teuchos::getParametersFromXmlFile;
25 
29 
30 // Test Integrator construction from ParameterList and ModelEvaluator.
31 TEUCHOS_UNIT_TEST(IntegratorBasic, PL_ME_Construction)
32 {
33  // 1) Setup the ParameterList (here we start with params from .xml file)
34  RCP<ParameterList> pl = getParametersFromXmlFile("Tempus_default.xml");
35 
36  // 2) Setup the ModelEvaluator
37  RCP<SinCosModel<double> > model = Teuchos::rcp(new SinCosModel<double> ());
38 
39  // 3) Setup the Integrator
40  RCP<ParameterList> tempusPL = sublist(pl, "Tempus", true);
41  RCP<Tempus::IntegratorBasic<double> > integrator =
42  Tempus::integratorBasic<double>(tempusPL, model);
43 
44  // Test the ParameterList
45  RCP<ParameterList> testPL = integrator->getTempusParameterList();
46  // Write out ParameterList to rebaseline test.
47  //writeParameterListToXmlFile(*testPL, "Tempus_IntegratorBasic_ref-test.xml");
48 
49  // Read params from reference .xml file
50  RCP<ParameterList> referencePL =
51  getParametersFromXmlFile("Tempus_IntegratorBasic_ref.xml");
52 
53  bool pass = haveSameValues(*testPL, *referencePL, true);
54  if (!pass) {
55  std::cout << std::endl;
56  std::cout << "testPL -------------- \n" << *testPL << std::endl;
57  std::cout << "referencePL -------------- \n" << *referencePL << std::endl;
58  }
59  TEST_ASSERT(pass)
60 }
61 
62 
63 // Test integator construction, and then setParameterList, setStepper, and
64 // initialization.
66 {
67  // 1) Setup the Integrator
68  RCP<Tempus::IntegratorBasic<double> > integrator =
69  Tempus::integratorBasic<double>();
70 
71  // 2) Setup the ParameterList
72  // - Start with the default Tempus PL
73  // - Add Stepper PL
74  RCP<ParameterList> tempusPL = integrator->getTempusParameterList();
75 
76  tempusPL->sublist("Default Integrator").set("Stepper Name", "Demo Stepper");
77  RCP<ParameterList> stepperPL = Teuchos::parameterList();
78  stepperPL->set("Stepper Type", "Forward Euler");
79  tempusPL->set("Demo Stepper", *stepperPL);
80 
81  integrator->setTempusParameterList(tempusPL);
82 
83  // 3) Setup the Stepper
84  RCP<SinCosModel<double> > model = Teuchos::rcp(new SinCosModel<double> ());
85  integrator->setStepper(model);
86 
87  // 4) Initialize integrator
88  integrator->initialize();
89 
90  // Test the ParameterList
91  RCP<ParameterList> testPL = integrator->getTempusParameterList();
92  // Write out ParameterList to rebaseline test.
93  //writeParameterListToXmlFile(*testPL,"Tempus_IntegratorBasic_ref2-test.xml");
94 
95  // Read params from reference .xml file
96  RCP<ParameterList> referencePL =
97  getParametersFromXmlFile("Tempus_IntegratorBasic_ref2.xml");
98 
99  bool pass = haveSameValues(*testPL, *referencePL, true);
100  if (!pass) {
101  std::cout << std::endl;
102  std::cout << "testPL -------------- \n" << *testPL << std::endl;
103  std::cout << "referencePL -------------- \n" << *referencePL << std::endl;
104  }
105  TEST_ASSERT(pass)
106 }
107 
108 } // namespace Tempus_Test
Sine-Cosine model problem from Rythmos. This is a canonical Sine-Cosine differential equation with a...
TEUCHOS_UNIT_TEST(BackwardEuler, SinCos_ASA)
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
Solution state for integrators and steppers. SolutionState contains the metadata for solutions and th...