29 #ifndef Rythmos_FIXED_STEP_CONTROL_STRATEGY_DEF_H
30 #define Rythmos_FIXED_STEP_CONTROL_STRATEGY_DEF_H
32 #include "Rythmos_FixedStepControlStrategy_decl.hpp"
33 #include "Teuchos_VerboseObjectParameterListHelpers.hpp"
40 template<
class Scalar>
41 void FixedStepControlStrategy<Scalar>::setStepControlState_(
42 StepControlStrategyState newState)
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");
60 stepControlState_ = newState;
63 template<
class Scalar>
64 StepControlStrategyState FixedStepControlStrategy<Scalar>::getCurrentState()
66 return(stepControlState_);
69 template<
class Scalar>
70 FixedStepControlStrategy<Scalar>::FixedStepControlStrategy()
71 : stepControlState_(UNINITIALIZED)
74 template<
class Scalar>
75 void FixedStepControlStrategy<Scalar>::initialize(
76 const StepperBase<Scalar>& )
78 stepControlState_ = UNINITIALIZED;
80 setStepControlState_(BEFORE_FIRST_STEP);
83 template<
class Scalar>
84 void FixedStepControlStrategy<Scalar>::setRequestedStepSize(
85 const StepperBase<Scalar>& stepper,
87 const StepSizeType& stepSizeType)
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");
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");
103 if (stepControlState_ == UNINITIALIZED) setStepControlData(stepper);
106 template<
class Scalar>
107 void FixedStepControlStrategy<Scalar>::nextStepSize(
108 const StepperBase<Scalar>& , Scalar* ,
109 StepSizeType* ,
int* )
111 TEUCHOS_TEST_FOR_EXCEPTION(!((stepControlState_ == BEFORE_FIRST_STEP) ||
112 (stepControlState_ == MID_STEP) ||
113 (stepControlState_ == READY_FOR_NEXT_STEP) ),
115 "Error: Invalid state (stepControlState_=" << toString(stepControlState_)
116 <<
") for FixedStepControlStrategy<Scalar>::nextStepSize()\n");
118 setStepControlState_(MID_STEP);
121 template<
class Scalar>
122 void FixedStepControlStrategy<Scalar>::setCorrection(
123 const StepperBase<Scalar>&
124 ,
const RCP<
const Thyra::VectorBase<Scalar> >&
125 ,
const RCP<
const Thyra::VectorBase<Scalar> >&
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);
134 template<
class Scalar>
135 bool FixedStepControlStrategy<Scalar>::acceptStep(
136 const StepperBase<Scalar>& , Scalar* )
138 TEUCHOS_TEST_FOR_EXCEPTION(stepControlState_ != AFTER_CORRECTION,
140 "Error: Invalid state (stepControlState_=" << toString(stepControlState_)
141 <<
") for FixedStepControlStrategy<Scalar>::completeStep()\n");
146 template<
class Scalar>
147 AttemptedStepStatusFlag FixedStepControlStrategy<Scalar>::rejectStep(
148 const StepperBase<Scalar>& )
150 TEUCHOS_TEST_FOR_EXCEPTION(stepControlState_ != AFTER_CORRECTION,
152 "Error: Invalid state (stepControlState_=" << toString(stepControlState_)
153 <<
") for FixedStepControlStrategy<Scalar>::completeStep()\n");
155 setStepControlState_(READY_FOR_NEXT_STEP);
157 return (REP_ERR_FAIL);
160 template<
class Scalar>
161 void FixedStepControlStrategy<Scalar>::completeStep(
162 const StepperBase<Scalar>& )
164 TEUCHOS_TEST_FOR_EXCEPTION(stepControlState_ != AFTER_CORRECTION,
166 "Error: Invalid state (stepControlState_=" << toString(stepControlState_)
167 <<
") for FixedStepControlStrategy<Scalar>::completeStep()\n");
169 setStepControlState_(READY_FOR_NEXT_STEP);
172 template<
class Scalar>
173 void FixedStepControlStrategy<Scalar>::describe(
174 Teuchos::FancyOStream &out,
const Teuchos::EVerbosityLevel verbLevel)
const
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";
183 template<
class Scalar>
184 void FixedStepControlStrategy<Scalar>::setParameterList(
185 RCP<Teuchos::ParameterList>
const& paramList)
188 TEUCHOS_TEST_FOR_EXCEPT(is_null(paramList));
189 paramList->validateParameters(*getValidParameters());
192 template<
class Scalar>
193 RCP<const Teuchos::ParameterList>
194 FixedStepControlStrategy<Scalar>::getValidParameters()
const
196 static RCP<Teuchos::ParameterList> validPL;
197 if (is_null(validPL)) {
198 RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
199 Teuchos::setupVerboseObjectSublist(&*pl);
206 template<
class Scalar>
207 RCP<Teuchos::ParameterList>
208 FixedStepControlStrategy<Scalar>::unsetParameterList()
210 RCP<Teuchos::ParameterList> temp_param_list = parameterList_;
211 parameterList_ = Teuchos::null;
212 return(temp_param_list);
215 template<
class Scalar>
216 RCP<Teuchos::ParameterList>
217 FixedStepControlStrategy<Scalar>::getNonconstParameterList()
219 return(parameterList_);
222 template<
class Scalar>
223 void FixedStepControlStrategy<Scalar>::setStepControlData(
224 const StepperBase<Scalar>& stepper)
226 if (stepControlState_ == UNINITIALIZED) initialize(stepper);
229 template<
class Scalar>
230 bool FixedStepControlStrategy<Scalar>::supportsCloning()
const
236 template<
class Scalar>
237 RCP<StepControlStrategyBase<Scalar> >
238 FixedStepControlStrategy<Scalar>::cloneStepControlStrategyAlgorithm()
const
241 RCP<FixedStepControlStrategy<Scalar> >
242 stepControl = rcp(
new FixedStepControlStrategy<Scalar>());
244 if (!is_null(parameterList_))
245 stepControl->setParameterList(parameterList_);
250 template<
class Scalar>
251 int FixedStepControlStrategy<Scalar>::getMaxOrder()
const
253 TEUCHOS_TEST_FOR_EXCEPTION(
254 stepControlState_ == UNINITIALIZED, std::logic_error,
255 "Error, attempting to call getMaxOrder before initialization!\n"
266 #define RYTHMOS_FIXED_STEP_CONTROL_STRATEGY_INSTANT(SCALAR) \
267 template class FixedStepControlStrategy< SCALAR >;
271 #endif // Rythmos_FIXED_STEP_CONTROL_STRATEGY_DEF_H