Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Tempus_UnitTest_BDF2.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 
9 #include "Teuchos_UnitTestHarness.hpp"
10 #include "Teuchos_XMLParameterListHelpers.hpp"
11 #include "Teuchos_TimeMonitor.hpp"
12 #include "Teuchos_DefaultComm.hpp"
13 
14 #include "Thyra_VectorStdOps.hpp"
15 
18 
19 #include "../TestModels/SinCosModel.hpp"
20 #include "../TestModels/VanDerPolModel.hpp"
21 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp"
22 
23 #include <fstream>
24 #include <vector>
25 
26 namespace Tempus_Unit_Test {
27 
28 using Teuchos::RCP;
29 using Teuchos::rcp;
30 using Teuchos::rcp_const_cast;
31 using Teuchos::rcp_dynamic_cast;
32 using Teuchos::ParameterList;
33 using Teuchos::sublist;
34 using Teuchos::getParametersFromXmlFile;
35 
37 
38 // Comment out any of the following tests to exclude from build/run.
39 
40 
41 // ************************************************************
42 // ************************************************************
43 TEUCHOS_UNIT_TEST(BDF2, Default_Construction)
44 {
45  auto model = rcp(new Tempus_Test::SinCosModel<double>());
46 
47  // Default construction.
48  auto stepper = rcp(new Tempus::StepperBDF2<double>());
49  stepper->setModel(model);
50  stepper->initialize();
51  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
52 
53 
54  // Default values for construction.
55  auto obs = rcp(new Tempus::StepperBDF2Observer<double>());
56  auto solver = rcp(new Thyra::NOXNonlinearSolver());
57  solver->setParameterList(Tempus::defaultSolverParameters());
58 
59  auto startUpStepper = rcp(new Tempus::StepperDIRK_1StageTheta<double>());
60  startUpStepper->setModel(model); // Can use the same model since both steppers are implicit ODEs.
61  startUpStepper->initialize();
62 
63  auto defaultStepper = rcp(new Tempus::StepperBDF2<double>());
64  bool useFSAL = defaultStepper->getUseFSALDefault();
65  std::string ICConsistency = defaultStepper->getICConsistencyDefault();
66  bool ICConsistencyCheck = defaultStepper->getICConsistencyCheckDefault();
67  bool zeroInitialGuess = defaultStepper->getZeroInitialGuess();
68 
69  // Test the set functions.
70  stepper->setObserver(obs); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
71  stepper->setSolver(solver); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
72  stepper->setStartUpStepper(startUpStepper); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
73  stepper->setUseFSAL(useFSAL); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
74  stepper->setICConsistency(ICConsistency); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
75  stepper->setICConsistencyCheck(ICConsistencyCheck); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
76  stepper->setZeroInitialGuess(zeroInitialGuess); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
77 
78 
79  // Full argument list construction.
80  stepper = rcp(new Tempus::StepperBDF2<double>(
81  model, obs, solver, startUpStepper, useFSAL,
82  ICConsistency, ICConsistencyCheck, zeroInitialGuess));
83  TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
84 
85  // Test stepper properties.
86  TEUCHOS_ASSERT(stepper->getOrder() == 2);
87 }
88 
89 
90 // ************************************************************
91 // ************************************************************
92 TEUCHOS_UNIT_TEST(BDF2, StepperFactory_Construction)
93 {
94  auto model = rcp(new Tempus_Test::SinCosModel<double>());
95  testFactoryConstruction("BDF2", model);
96 }
97 
98 
99 } // namespace Tempus_Test
BDF2 (Backward-Difference-Formula-2) time stepper.
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_UNIT_TEST(BackwardEuler, Default_Construction)
StepperBDF2Observer class for StepperBDF2.