Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Tempus_UnitTest_ERK_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 
14 using Teuchos::RCP;
15 using Teuchos::rcp;
16 using Teuchos::rcp_const_cast;
17 using Teuchos::rcp_dynamic_cast;
18 
19 // ************************************************************
20 // ************************************************************
21 TEUCHOS_UNIT_TEST(ERK_General, Default_Construction)
22 {
23  auto model = rcp(new Tempus_Test::SinCosModel<double>());
24 
25  // Default construction.
26  auto stepper = rcp(new Tempus::StepperERK_General<double>());
27  stepper->setModel(model);
28  stepper->initialize();
29  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
30 
31  // Default values for construction.
32  auto modifier = rcp(new Tempus::StepperRKModifierDefault<double>());
33  auto modifierX = rcp(new Tempus::StepperRKModifierXDefault<double>());
34  auto observer = rcp(new Tempus::StepperRKObserverDefault<double>());
35  bool useFSAL = stepper->getUseFSAL();
36  std::string ICConsistency = stepper->getICConsistency();
37  bool ICConsistencyCheck = stepper->getICConsistencyCheck();
38  bool useEmbedded = stepper->getUseEmbedded();
39 
40  int NumStages = 4;
41  Teuchos::SerialDenseMatrix<int, double> A(NumStages, NumStages);
45 
46  // Fill A:
47  A(0, 0) = 0.0;
48  A(0, 1) = 0.0;
49  A(0, 2) = 0.0;
50  A(0, 3) = 0.0;
51  A(1, 0) = 0.5;
52  A(1, 1) = 0.0;
53  A(1, 2) = 0.0;
54  A(1, 3) = 0.0;
55  A(2, 0) = 0.0;
56  A(2, 1) = 0.5;
57  A(2, 2) = 0.0;
58  A(2, 3) = 0.0;
59  A(3, 0) = 0.0;
60  A(3, 1) = 0.0;
61  A(3, 2) = 1.0;
62  A(3, 3) = 0.0;
63 
64  // Fill b:
65  b(0) = 1.0 / 6.0;
66  b(1) = 1.0 / 3.0;
67  b(2) = 1.0 / 3.0;
68  b(3) = 1.0 / 6.0;
69 
70  // fill c:
71  c(0) = 0.0;
72  c(1) = 0.5;
73  c(2) = 0.5;
74  c(3) = 1.0;
75 
76  int order = 4;
77 
78  // Test the set functions.
79  stepper->setAppAction(modifier);
80  stepper->initialize();
81  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
82  stepper->setAppAction(modifierX);
83  stepper->initialize();
84  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
85  stepper->setAppAction(observer);
86  stepper->initialize();
87  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
88  stepper->setUseFSAL(useFSAL);
89  stepper->initialize();
90  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
91  stepper->setICConsistency(ICConsistency);
92  stepper->initialize();
93  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
94  stepper->setICConsistencyCheck(ICConsistencyCheck);
95  stepper->initialize();
96  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
97  stepper->setUseEmbedded(useEmbedded);
98  stepper->initialize();
99  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
100 
101  stepper->setTableau(A, b, c, order, order, order);
102  stepper->initialize();
103  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
104 
105  // Full argument list construction.
107  model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, A, b, c,
108  order, order, order, bstar, modifier));
109  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
110 
111  // Test stepper properties.
112  TEUCHOS_ASSERT(stepper->getOrder() == 4);
113 }
114 
115 // ************************************************************
116 // ************************************************************
117 TEUCHOS_UNIT_TEST(ERK_General, StepperFactory_Construction)
118 {
119  auto model = rcp(new Tempus_Test::SinCosModel<double>());
120  testFactoryConstruction("General ERK", model);
121 }
122 
123 // ************************************************************
124 // ************************************************************
125 TEUCHOS_UNIT_TEST(ERK_General, AppAction)
126 {
127  auto stepper = rcp(new Tempus::StepperERK_General<double>());
128  auto model = rcp(new Tempus_Test::SinCosModel<double>());
129  testRKAppAction(stepper, model, out, success);
130 }
131 
132 } // namespace Tempus_Unit_Test
void testFactoryConstruction(std::string stepperType, const Teuchos::RCP< const Thyra::ModelEvaluator< double > > &model)
Unit test utility for Stepper construction through StepperFactory.
General Explicit Runge-Kutta Butcher Tableau.
Sine-Cosine model problem from Rythmos. This is a canonical Sine-Cosine differential equation with a...
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)
#define TEUCHOS_ASSERT(assertion_test)
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)