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