Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 
11 #include "Teuchos_TimeMonitor.hpp"
12 #include "Teuchos_DefaultComm.hpp"
13 
14 #include "Thyra_VectorStdOps.hpp"
15 
17 
18 #include "../TestModels/SinCosModel.hpp"
19 #include "../TestModels/VanDerPolModel.hpp"
20 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp"
21 
22 #include <fstream>
23 #include <vector>
24 
25 namespace Tempus_Unit_Test {
26 
27 using Teuchos::RCP;
28 using Teuchos::rcp;
29 using Teuchos::rcp_const_cast;
30 using Teuchos::rcp_dynamic_cast;
32 using Teuchos::sublist;
33 using Teuchos::getParametersFromXmlFile;
34 
35 
36 // ************************************************************
37 // ************************************************************
38 TEUCHOS_UNIT_TEST(DIRK_General, Default_Construction)
39 {
40  auto model = rcp(new Tempus_Test::SinCosModel<double>());
41 
42  // Default construction.
43  auto stepper = rcp(new Tempus::StepperDIRK_General<double>());
44  stepper->setModel(model);
45  stepper->initialize();
46  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
47 
48 
49  // Default values for construction.
50  auto modifier = rcp(new Tempus::StepperRKModifierDefault<double>());
51  auto modifierX = rcp(new Tempus::StepperRKModifierXDefault<double>());
52  auto observer = rcp(new Tempus::StepperRKObserverDefault<double>());
53  auto solver = rcp(new Thyra::NOXNonlinearSolver());
54  solver->setParameterList(Tempus::defaultSolverParameters());
55 
56  bool useFSAL = stepper->getUseFSAL();
57  std::string ICConsistency = stepper->getICConsistency();
58  bool ICConsistencyCheck = stepper->getICConsistencyCheck();
59  bool useEmbedded = stepper->getUseEmbedded();
60  bool zeroInitialGuess = stepper->getZeroInitialGuess();
61 
62  using Teuchos::as;
63  int NumStages = 2;
64  Teuchos::SerialDenseMatrix<int,double> A(NumStages,NumStages);
68 
69  // Fill A:
70  A(0,0) = 0.2928932188134524; A(0,1) = 0.0;
71  A(1,0) = 0.7071067811865476; A(1,1) = 0.2928932188134524;
72 
73  // Fill b:
74  b(0) = 0.7071067811865476;
75  b(1) = 0.2928932188134524;
76 
77  // Fill c:
78  c(0) = 0.2928932188134524;
79  c(1) = 1.0;
80 
81  int order = 2;
82 
83  // Test the set functions.
84  stepper->setAppAction(modifier); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
85  stepper->setAppAction(modifierX); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
86  stepper->setAppAction(observer); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
87  stepper->setSolver(solver); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
88  stepper->setUseFSAL(useFSAL); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
89  stepper->setICConsistency(ICConsistency); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
90  stepper->setICConsistencyCheck(ICConsistencyCheck); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
91  stepper->setUseEmbedded(useEmbedded); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
92  stepper->setZeroInitialGuess(zeroInitialGuess); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
93 
94  stepper->setTableau(A, b, c, order, order, order); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
95 
96 
97  // Full argument list construction.
99  model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
100  useEmbedded, zeroInitialGuess, modifier,
101  A, b, c, order, order, order,bstar));
102  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
103 
104  // Test stepper properties.
105  TEUCHOS_ASSERT(stepper->getOrder() == 2);
106 }
107 
108 
109 // ************************************************************
110 // ************************************************************
111 TEUCHOS_UNIT_TEST(DIRK_General, StepperFactory_Construction)
112 {
113  auto model = rcp(new Tempus_Test::SinCosModel<double>());
114  testFactoryConstruction("General DIRK", model);
115 }
116 
117 
118 // ************************************************************
119 // ************************************************************
120 TEUCHOS_UNIT_TEST(DIRK_General, AppAction)
121 {
122  auto stepper = rcp(new Tempus::StepperDIRK_General<double>());
123  auto model = rcp(new Tempus_Test::SinCosModel<double>());
124  testRKAppAction(stepper, model, out, success);
125 }
126 
127 
128 } // 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_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)
TypeTo as(const TypeFrom &t)
#define TEUCHOS_ASSERT(assertion_test)
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)