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