Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Tempus_UnitTest_DIRK_General.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 #include "Teuchos_DefaultComm.hpp"
13 
14 #include "Thyra_VectorStdOps.hpp"
15 
18 
19 #include "../TestModels/SinCosModel.hpp"
20 #include "../TestModels/VanDerPolModel.hpp"
21 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp"
22 
23 #include <fstream>
24 #include <vector>
25 
26 namespace Tempus_Unit_Test {
27 
28 using Teuchos::RCP;
29 using Teuchos::rcp;
30 using Teuchos::rcp_const_cast;
31 using Teuchos::rcp_dynamic_cast;
32 using Teuchos::ParameterList;
33 using Teuchos::sublist;
34 using Teuchos::getParametersFromXmlFile;
35 
37 
38 
39 // ************************************************************
40 // ************************************************************
41 TEUCHOS_UNIT_TEST(DIRK_General, Default_Construction)
42 {
43  auto model = rcp(new Tempus_Test::SinCosModel<double>());
44 
45  // Default construction.
46  auto stepper = rcp(new Tempus::StepperDIRK_General<double>());
47  stepper->setModel(model);
48  stepper->initialize();
49  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
50 
51 
52  // Default values for construction.
53  auto modifier = rcp(new Tempus::StepperRKModifierDefault<double>());
54  auto modifierX = rcp(new Tempus::StepperRKModifierXDefault<double>());
55  auto observer = rcp(new Tempus::StepperRKObserverDefault<double>());
56  auto solver = rcp(new Thyra::NOXNonlinearSolver());
57  solver->setParameterList(Tempus::defaultSolverParameters());
58 
59  bool useFSAL = stepper->getUseFSALDefault();
60  std::string ICConsistency = stepper->getICConsistencyDefault();
61  bool ICConsistencyCheck = stepper->getICConsistencyCheckDefault();
62  bool useEmbedded = stepper->getUseEmbeddedDefault();
63  bool zeroInitialGuess = stepper->getZeroInitialGuess();
64 
65  using Teuchos::as;
66  int NumStages = 2;
67  Teuchos::SerialDenseMatrix<int,double> A(NumStages,NumStages);
68  Teuchos::SerialDenseVector<int,double> b(NumStages);
69  Teuchos::SerialDenseVector<int,double> c(NumStages);
70  Teuchos::SerialDenseVector<int,double> bstar(0);
71 
72  // Fill A:
73  A(0,0) = 0.2928932188134524; A(0,1) = 0.0;
74  A(1,0) = 0.7071067811865476; A(1,1) = 0.2928932188134524;
75 
76  // Fill b:
77  b(0) = 0.7071067811865476;
78  b(1) = 0.2928932188134524;
79 
80  // Fill c:
81  c(0) = 0.2928932188134524;
82  c(1) = 1.0;
83 
84  int order = 2;
85 
86  // Test the set functions.
87 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
88  auto obs = rcp(new Tempus::StepperRKObserverComposite<double>());
89  stepper->setObserver(obs); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
90 #endif
91  stepper->setAppAction(modifier); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
92  stepper->setAppAction(modifierX); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
93  stepper->setAppAction(observer); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
94  stepper->setSolver(solver); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
95  stepper->setUseFSAL(useFSAL); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
96  stepper->setICConsistency(ICConsistency); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
97  stepper->setICConsistencyCheck(ICConsistencyCheck); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
98  stepper->setUseEmbedded(useEmbedded); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
99  stepper->setZeroInitialGuess(zeroInitialGuess); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
100 
101  stepper->setTableau(A, b, c, order, order, order); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
102 
103 
104  // Full argument list construction.
105 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
106  stepper = rcp(new Tempus::StepperDIRK_General<double>(
107  model, obs, solver, useFSAL,
108  ICConsistency, ICConsistencyCheck, useEmbedded, zeroInitialGuess,
109  A, b, c, order, order, order, bstar));
110  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
111 #endif
112  stepper = rcp(new Tempus::StepperDIRK_General<double>(
113  model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
114  useEmbedded, zeroInitialGuess, modifier,
115  A, b, c, order, order, order, bstar));
116  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
117 
118  // Test stepper properties.
119  TEUCHOS_ASSERT(stepper->getOrder() == 2);
120 }
121 
122 
123 // ************************************************************
124 // ************************************************************
125 TEUCHOS_UNIT_TEST(DIRK_General, StepperFactory_Construction)
126 {
127  auto model = rcp(new Tempus_Test::SinCosModel<double>());
128  testFactoryConstruction("General DIRK", model);
129 }
130 
131 
132 // ************************************************************
133 // ************************************************************
134 TEUCHOS_UNIT_TEST(DIRK_General, AppAction)
135 {
136  auto stepper = rcp(new Tempus::StepperDIRK_General<double>());
137  auto model = rcp(new Tempus_Test::SinCosModel<double>());
138  testRKAppAction(stepper, model, out, success);
139 }
140 
141 
142 } // namespace Tempus_Test
General Implicit Runge-Kutta Butcher Tableau.
void testRKAppAction(const Teuchos::RCP< Tempus::StepperRKBase< double > > &stepper, const Teuchos::RCP< const Thyra::ModelEvaluator< double > > &model, Teuchos::FancyOStream &out, bool &success)
Unit test utility for Stepper RK AppAction.
void testFactoryConstruction(std::string stepperType, const Teuchos::RCP< const Thyra::ModelEvaluator< double > > &model)
Unit test utility for Stepper construction through StepperFactory.
Sine-Cosine model problem from Rythmos. This is a canonical Sine-Cosine differential equation with a...
Teuchos::RCP< Teuchos::ParameterList > defaultSolverParameters()
Returns the default solver ParameterList for implicit Steppers.
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)