Page MenuHomec4science

timestepper.cpp
No OneTemporary

File Metadata

Created
Mon, Jul 22, 19:22

timestepper.cpp

#include "timestepper.hpp"
#include "reactive_transport_solver_structs.hpp"
namespace specmicp {
namespace reactmicp {
namespace solver {
scalar_t Timestepper::next_timestep(
scalar_t dt_done,
ReactiveTransportReturnCode return_code,
index_t nb_iterations
)
{
if (return_code <= ReactiveTransportReturnCode::NotConvergedYet)
{
return get_options().decrease_failure*dt_done;
}
// previous timestep is correct
m_total += dt_done;
m_average.add_point(nb_iterations);
scalar_t proposed_dt = dt_done;
// If the error is minimized we increase the timestep
if (return_code == ReactiveTransportReturnCode::ErrorMinimized)
{
proposed_dt *= get_options().increase_error_minimization;
}
else
// Increase or decrease the timestep to reach the number of iteration target range
{
if (m_average.current_value() <= get_options().iteration_lower_target)
{
proposed_dt *= get_options().increase_factor;
}
else if (m_average.current_value() > get_options().iteration_upper_target)
{
proposed_dt *= get_options().decrease_factor;
}
}
// Check that the total target is not exceeded
if (m_total + proposed_dt > m_total_target)
{
proposed_dt = m_total_target - m_total;
}
// Check that the timestep is inside the bounds
if (proposed_dt < get_options().lower_bound)
{
proposed_dt = get_options().lower_bound;
}
else if (proposed_dt > get_options().upper_bound)
{
proposed_dt = get_options().upper_bound;
}
return proposed_dt;
}
} // end namespace solver
} // end namespace reactmicp
} // end namespace specmicp

Event Timeline