Rythmos - Transient Integration for Differential Equations Version of the Day
Loading...
Searching...
No Matches
Rythmos_FixedStepControlStrategy_def.hpp
1//@HEADER
2// ***********************************************************************
3//
4// Rythmos Package
5// Copyright (2006) Sandia Corporation
6//
7// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8// license for use of this work by or on behalf of the U.S. Government.
9//
10// This library is free software; you can redistribute it and/or modify
11// it under the terms of the GNU Lesser General Public License as
12// published by the Free Software Foundation; either version 2.1 of the
13// License, or (at your option) any later version.
14//
15// This library is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18// Lesser General Public License for more details.
19//
20// You should have received a copy of the GNU Lesser General Public
21// License along with this library; if not, write to the Free Software
22// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23// USA
24// Questions? Contact Todd S. Coffey (tscoffe@sandia.gov)
25//
26// ***********************************************************************
27//@HEADER
28
29#ifndef Rythmos_FIXED_STEP_CONTROL_STRATEGY_DEF_H
30#define Rythmos_FIXED_STEP_CONTROL_STRATEGY_DEF_H
31
32#include "Rythmos_FixedStepControlStrategy_decl.hpp"
33#include "Teuchos_VerboseObjectParameterListHelpers.hpp"
34
35namespace Rythmos {
36
37
38// Constructors
39
40template<class Scalar>
41void FixedStepControlStrategy<Scalar>::setStepControlState_(
42 StepControlStrategyState newState)
43{
44 if (stepControlState_ == UNINITIALIZED) {
45 TEUCHOS_TEST_FOR_EXCEPTION(newState != BEFORE_FIRST_STEP, std::logic_error,
46 "newState = " << toString(newState) << "\n");
47 } else if (stepControlState_ == BEFORE_FIRST_STEP) {
48 TEUCHOS_TEST_FOR_EXCEPTION(newState != MID_STEP, std::logic_error,
49 "newState = " << toString(newState) << "\n");
50 } else if (stepControlState_ == MID_STEP) {
51 TEUCHOS_TEST_FOR_EXCEPTION(newState != AFTER_CORRECTION, std::logic_error,
52 "newState = " << toString(newState) << "\n");
53 } else if (stepControlState_ == AFTER_CORRECTION) {
54 TEUCHOS_TEST_FOR_EXCEPTION(newState != READY_FOR_NEXT_STEP,std::logic_error,
55 "newState = " << toString(newState) << "\n");
56 } else if (stepControlState_ == READY_FOR_NEXT_STEP) {
57 TEUCHOS_TEST_FOR_EXCEPTION(newState != MID_STEP, std::logic_error,
58 "newState = " << toString(newState) << "\n");
59 }
60 stepControlState_ = newState;
61}
62
63template<class Scalar>
64StepControlStrategyState FixedStepControlStrategy<Scalar>::getCurrentState()
65{
66 return(stepControlState_);
67}
68
69template<class Scalar>
70FixedStepControlStrategy<Scalar>::FixedStepControlStrategy()
71 : stepControlState_(UNINITIALIZED)
72{}
73
74template<class Scalar>
75void FixedStepControlStrategy<Scalar>::initialize(
76 const StepperBase<Scalar>& /* stepper */)
77{
78 stepControlState_ = UNINITIALIZED;
79 // Any other initialization goes here.
80 setStepControlState_(BEFORE_FIRST_STEP);
81}
82
83template<class Scalar>
84void FixedStepControlStrategy<Scalar>::setRequestedStepSize(
85 const StepperBase<Scalar>& stepper,
86 const Scalar& /* stepSize */,
87 const StepSizeType& stepSizeType)
88{
89 // typedef Teuchos::ScalarTraits<Scalar> ST; // unused
90 TEUCHOS_TEST_FOR_EXCEPTION(
91 !((stepControlState_ == UNINITIALIZED) ||
92 (stepControlState_ == BEFORE_FIRST_STEP) ||
93 (stepControlState_ == READY_FOR_NEXT_STEP) ||
94 (stepControlState_ == MID_STEP)), std::logic_error,
95 "Error: Invalid state (stepControlState_=" << toString(stepControlState_)
96 << ") for FixedStepControlStrategy<Scalar>::setRequestedStepSize()\n");
97
98 TEUCHOS_TEST_FOR_EXCEPTION(
99 (stepSizeType != STEP_TYPE_FIXED),
100 std::logic_error, "Error, step size type != STEP_TYPE_FIXED "
101 "for FixedStepControlStrategy!\n");
102
103 if (stepControlState_ == UNINITIALIZED) setStepControlData(stepper);
104}
105
106template<class Scalar>
107void FixedStepControlStrategy<Scalar>::nextStepSize(
108 const StepperBase<Scalar>& /* stepper */, Scalar* /* stepSize */,
109 StepSizeType* /* stepSizeType */, int* /* order */)
110{
111 TEUCHOS_TEST_FOR_EXCEPTION(!((stepControlState_ == BEFORE_FIRST_STEP) ||
112 (stepControlState_ == MID_STEP) ||
113 (stepControlState_ == READY_FOR_NEXT_STEP) ),
114 std::logic_error,
115 "Error: Invalid state (stepControlState_=" << toString(stepControlState_)
116 << ") for FixedStepControlStrategy<Scalar>::nextStepSize()\n");
117
118 setStepControlState_(MID_STEP);
119}
120
121template<class Scalar>
122void FixedStepControlStrategy<Scalar>::setCorrection(
123 const StepperBase<Scalar>& /* stepper */
124 ,const RCP<const Thyra::VectorBase<Scalar> >& /* soln */
125 ,const RCP<const Thyra::VectorBase<Scalar> >& /* dx */
126 ,int /* solveStatus */)
127{
128 TEUCHOS_TEST_FOR_EXCEPTION(stepControlState_ != MID_STEP, std::logic_error,
129 "Error: Invalid state (stepControlState_=" << toString(stepControlState_)
130 << ") for FixedStepControlStrategy<Scalar>::setCorrection()\n");
131 setStepControlState_(AFTER_CORRECTION);
132}
133
134template<class Scalar>
135bool FixedStepControlStrategy<Scalar>::acceptStep(
136 const StepperBase<Scalar>& /* stepper */, Scalar* /* value */)
137{
138 TEUCHOS_TEST_FOR_EXCEPTION(stepControlState_ != AFTER_CORRECTION,
139 std::logic_error,
140 "Error: Invalid state (stepControlState_=" << toString(stepControlState_)
141 << ") for FixedStepControlStrategy<Scalar>::completeStep()\n");
142
143 return true;
144}
145
146template<class Scalar>
147AttemptedStepStatusFlag FixedStepControlStrategy<Scalar>::rejectStep(
148 const StepperBase<Scalar>& /* stepper */)
149{
150 TEUCHOS_TEST_FOR_EXCEPTION(stepControlState_ != AFTER_CORRECTION,
151 std::logic_error,
152 "Error: Invalid state (stepControlState_=" << toString(stepControlState_)
153 << ") for FixedStepControlStrategy<Scalar>::completeStep()\n");
154
155 setStepControlState_(READY_FOR_NEXT_STEP);
156
157 return (REP_ERR_FAIL);
158}
159
160template<class Scalar>
161void FixedStepControlStrategy<Scalar>::completeStep(
162 const StepperBase<Scalar>& /* stepper */)
163{
164 TEUCHOS_TEST_FOR_EXCEPTION(stepControlState_ != AFTER_CORRECTION,
165 std::logic_error,
166 "Error: Invalid state (stepControlState_=" << toString(stepControlState_)
167 << ") for FixedStepControlStrategy<Scalar>::completeStep()\n");
168
169 setStepControlState_(READY_FOR_NEXT_STEP);
170}
171
172template<class Scalar>
173void FixedStepControlStrategy<Scalar>::describe(
174 Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
175{
176 using Teuchos::as;
177 if ( (as<int>(verbLevel) == as<int>(Teuchos::VERB_DEFAULT) ) ||
178 (as<int>(verbLevel) >= as<int>(Teuchos::VERB_LOW) ) ) {
179 out << this->description() << "::describe" << "\n";
180 }
181}
182
183template<class Scalar>
184void FixedStepControlStrategy<Scalar>::setParameterList(
185 RCP<Teuchos::ParameterList> const& paramList)
186{
187 // typedef Teuchos::ScalarTraits<Scalar> ST; // unused
188 TEUCHOS_TEST_FOR_EXCEPT(is_null(paramList));
189 paramList->validateParameters(*getValidParameters());
190}
191
192template<class Scalar>
193RCP<const Teuchos::ParameterList>
194FixedStepControlStrategy<Scalar>::getValidParameters() const
195{
196 static RCP<Teuchos::ParameterList> validPL;
197 if (is_null(validPL)) {
198 RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
199 Teuchos::setupVerboseObjectSublist(&*pl);
200 validPL = pl;
201 }
202
203 return (validPL);
204}
205
206template<class Scalar>
207RCP<Teuchos::ParameterList>
208FixedStepControlStrategy<Scalar>::unsetParameterList()
209{
210 RCP<Teuchos::ParameterList> temp_param_list = parameterList_;
211 parameterList_ = Teuchos::null;
212 return(temp_param_list);
213}
214
215template<class Scalar>
216RCP<Teuchos::ParameterList>
217FixedStepControlStrategy<Scalar>::getNonconstParameterList()
218{
219 return(parameterList_);
220}
221
222template<class Scalar>
223void FixedStepControlStrategy<Scalar>::setStepControlData(
224 const StepperBase<Scalar>& stepper)
225{
226 if (stepControlState_ == UNINITIALIZED) initialize(stepper);
227}
228
229template<class Scalar>
230bool FixedStepControlStrategy<Scalar>::supportsCloning() const
231{
232 return true;
233}
234
235
236template<class Scalar>
237RCP<StepControlStrategyBase<Scalar> >
238FixedStepControlStrategy<Scalar>::cloneStepControlStrategyAlgorithm() const
239{
240
241 RCP<FixedStepControlStrategy<Scalar> >
242 stepControl = rcp(new FixedStepControlStrategy<Scalar>());
243
244 if (!is_null(parameterList_))
245 stepControl->setParameterList(parameterList_);
246
247 return stepControl;
248}
249
250template<class Scalar>
251int FixedStepControlStrategy<Scalar>::getMaxOrder() const
252{
253 TEUCHOS_TEST_FOR_EXCEPTION(
254 stepControlState_ == UNINITIALIZED, std::logic_error,
255 "Error, attempting to call getMaxOrder before initialization!\n"
256 );
257 return(0);
258}
259
260//
261// Explicit Instantiation macro
262//
263// Must be expanded from within the Rythmos namespace!
264//
265
266#define RYTHMOS_FIXED_STEP_CONTROL_STRATEGY_INSTANT(SCALAR) \
267 template class FixedStepControlStrategy< SCALAR >;
268
269
270} // namespace Rythmos
271#endif // Rythmos_FIXED_STEP_CONTROL_STRATEGY_DEF_H