1 #ifndef VERTEXCFD_TEMPUSTIMESTEPCONTROL_GLOBALCFL_IMPL_HPP
2 #define VERTEXCFD_TEMPUSTIMESTEPCONTROL_GLOBALCFL_IMPL_HPP
4 #include "VertexCFD_TempusTimeStepControl_GlobalCFL.hpp"
6 #include <Teuchos_ParameterList.hpp>
7 #include <Teuchos_RCP.hpp>
8 #include <Teuchos_StandardParameterEntryValidators.hpp>
15 namespace TempusTimeStepControl
18 template<
class Scalar>
19 GlobalCFL<Scalar>::GlobalCFL(
const Teuchos::ParameterList& user_params,
20 Teuchos::RCP<PhysicsManager> physics_manager)
21 : _cfl(user_params.get<double>(
"CFL"))
22 , _cfl_init(user_params.isType<double>(
"CFL_init")
23 ? user_params.get<double>(
"CFL_init")
25 , _cfl_transition_init(0.0)
26 , _cfl_transition(0.0)
27 , _cfl_type(CflTransitionType::steps)
28 , _response_manager(physics_manager)
31 if (user_params.isType<std::string>(
"CFL_transition_type"))
33 const auto type_validator = Teuchos::rcp(
34 new Teuchos::StringToIntegralParameterEntryValidator<CflTransitionType>(
35 Teuchos::tuple<std::string>(
"steps",
"time"),
"steps"));
36 _cfl_type = type_validator->getIntegralValue(
37 user_params.get<std::string>(
"CFL_transition_type"));
41 if (user_params.isType<
double>(
"CFL_transition"))
43 _cfl_transition = user_params.get<
double>(
"CFL_transition");
44 if (user_params.isType<
double>(
"CFL_transition_init"))
47 = user_params.get<
double>(
"CFL_transition_init");
50 else if (user_params.isType<
double>(
"CFL_transition_init"))
53 =
"\n\n'CFL_transition_init' must be"
54 "specified with 'CFL_transition'\n"
55 "in the input file. Please add 'CFL_transition'\n"
56 "to your input file.\n";
57 throw std::runtime_error(msg);
60 this->setCurrentCFL(_cfl_init);
62 _response_manager.addMinValueResponse(
"global_cfl_time_step",
"local_dt");
67 this->stepType_ =
"Variable";
68 this->strategyType_ =
"CFL Strategy";
69 this->name_ =
"CFL Strategy";
74 template<
class Scalar>
75 void GlobalCFL<Scalar>::setNextTimeStep(
76 const Tempus::TimeStepControl<Scalar>& tsc,
77 Teuchos::RCP<Tempus::SolutionHistory<Scalar>> solution_history,
81 auto working_state = solution_history->getWorkingState();
84 _response_manager.evaluateResponses(working_state->getX(),
85 working_state->getXDot());
86 const double dt_cfl1 = _response_manager.value();
90 if (_cfl_transition > 0)
93 double dt_index = 0.0;
94 if (_cfl_type == CflTransitionType::steps)
95 dt_index =
static_cast<double>(solution_history->getCurrentIndex());
97 dt_index = solution_history->getCurrentTime();
99 if (dt_index < _cfl_transition_init)
103 else if (dt_index >= _cfl_transition_init
104 && dt_index <= _cfl_transition + _cfl_transition_init)
106 wt = std::min((dt_index - _cfl_transition_init) / _cfl_transition,
120 const double cfl_desired = (1.0 - wt) * _cfl_init + wt * _cfl;
121 double dt = cfl_desired * dt_cfl1;
125 const int dt_index = working_state->getIndex() - 1;
126 if (dt_index == 0 && tsc.getInitTimeStep() != tsc.getMinTimeStep())
128 dt = tsc.getInitTimeStep();
130 else if (dt < tsc.getMinTimeStep())
132 dt = tsc.getMinTimeStep();
134 else if (dt > tsc.getMaxTimeStep())
136 dt = tsc.getMaxTimeStep();
138 working_state->setTimeStep(dt);
139 working_state->setTime(solution_history->getCurrentTime() + dt);
142 this->setCurrentCFL(dt / dt_cfl1);
150 #endif // end VERTEXCFD_TEMPUSTIMESTEPCONTROL_GLOBALCFL_IMPL_HPP