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: Time Integration and Sensitivity Analysis Package
4 //
5 // Copyright 2017 NTESS and the Tempus contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 //@HEADER
9 
11 
12 namespace Tempus_Unit_Test {
13 
15 using Teuchos::RCP;
16 using Teuchos::rcp;
17 using Teuchos::rcp_const_cast;
18 using Teuchos::rcp_dynamic_cast;
19 using Teuchos::sublist;
20 
21 // ************************************************************
22 // ************************************************************
23 TEUCHOS_UNIT_TEST(DIRK_General, Default_Construction)
24 {
25  auto model = rcp(new Tempus_Test::SinCosModel<double>());
26 
27  // Default construction.
28  auto stepper = rcp(new Tempus::StepperDIRK_General<double>());
29  stepper->setModel(model);
30  stepper->initialize();
31  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
32 
33  // Default values for construction.
34  auto modifier = rcp(new Tempus::StepperRKModifierDefault<double>());
35  auto modifierX = rcp(new Tempus::StepperRKModifierXDefault<double>());
36  auto observer = rcp(new Tempus::StepperRKObserverDefault<double>());
37  auto solver = rcp(new Thyra::NOXNonlinearSolver());
38  solver->setParameterList(Tempus::defaultSolverParameters());
39 
40  bool useFSAL = stepper->getUseFSAL();
41  std::string ICConsistency = stepper->getICConsistency();
42  bool ICConsistencyCheck = stepper->getICConsistencyCheck();
43  bool useEmbedded = stepper->getUseEmbedded();
44  bool zeroInitialGuess = stepper->getZeroInitialGuess();
45 
46  using Teuchos::as;
47  int NumStages = 2;
48  Teuchos::SerialDenseMatrix<int, double> A(NumStages, NumStages);
52 
53  // Fill A:
54  A(0, 0) = 0.2928932188134524;
55  A(0, 1) = 0.0;
56  A(1, 0) = 0.7071067811865476;
57  A(1, 1) = 0.2928932188134524;
58 
59  // Fill b:
60  b(0) = 0.7071067811865476;
61  b(1) = 0.2928932188134524;
62 
63  // Fill c:
64  c(0) = 0.2928932188134524;
65  c(1) = 1.0;
66 
67  int order = 2;
68 
69  // Test the set functions.
70  stepper->setAppAction(modifier);
71  stepper->initialize();
72  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
73  stepper->setAppAction(modifierX);
74  stepper->initialize();
75  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
76  stepper->setAppAction(observer);
77  stepper->initialize();
78  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
79  stepper->setSolver(solver);
80  stepper->initialize();
81  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
82  stepper->setUseFSAL(useFSAL);
83  stepper->initialize();
84  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
85  stepper->setICConsistency(ICConsistency);
86  stepper->initialize();
87  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
88  stepper->setICConsistencyCheck(ICConsistencyCheck);
89  stepper->initialize();
90  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
91  stepper->setUseEmbedded(useEmbedded);
92  stepper->initialize();
93  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
94  stepper->setZeroInitialGuess(zeroInitialGuess);
95  stepper->initialize();
96  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
97 
98  stepper->setTableau(A, b, c, order, order, order);
99  stepper->initialize();
100  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
101 
102  // Full argument list construction.
104  model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
105  zeroInitialGuess, modifier, A, b, c, order, order, order, bstar));
106  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
107 
108  // Test stepper properties.
109  TEUCHOS_ASSERT(stepper->getOrder() == 2);
110 }
111 
112 // ************************************************************
113 // ************************************************************
114 TEUCHOS_UNIT_TEST(DIRK_General, StepperFactory_Construction)
115 {
116  auto model = rcp(new Tempus_Test::SinCosModel<double>());
117  testFactoryConstruction("General DIRK", model);
118 }
119 
120 // ************************************************************
121 // ************************************************************
122 TEUCHOS_UNIT_TEST(DIRK_General, AppAction)
123 {
124  auto stepper = rcp(new Tempus::StepperDIRK_General<double>());
125  auto model = rcp(new Tempus_Test::SinCosModel<double>());
126  testRKAppAction(stepper, model, out, success);
127 }
128 
129 } // namespace Tempus_Unit_Test
General Implicit Runge-Kutta Butcher Tableau.
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.
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.
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)