#include "api.hpp" #include "state.hpp" #include PLUGIN_EXPORT std::uint32_t plugin_api_version(){ return PLUGIN_API_VERSION; } PLUGIN_EXPORT PluginType plugin_type(){ return PluginType::Solver; } PLUGIN_EXPORT const char* plugin_name(){ return "Adams-Bashforth 2"; } PLUGIN_EXPORT const char* plugin_description(){ return "Explicit second-order Adams-Bashforth method with an RK4 start"; } PLUGIN_EXPORT void solver(const SolverParameters* parameters, SolutionPoint* output, size_t output_size){ State initial_state{1.0, 0.0, 0.0}; output[0] = make_step(parameters->t_begin, initial_state); State first_state = runge_kutta_step(initial_state, *parameters); output[1] = make_step(parameters->t_begin + parameters->step, first_state); for (size_t index = 1; index + 1 < output_size; index++){ State current = state_from_point(output[index]); State previous = state_from_point(output[index - 1]); State current_derivative = derivative(current, *parameters); State previous_derivative = derivative(previous, *parameters); double h = parameters->step; State next{current.x1 + h * (1.5 * current_derivative.x1 - 0.5 * previous_derivative.x1), current.x2 + h * (1.5 * current_derivative.x2 - 0.5 * previous_derivative.x2), current.x3 + h * (1.5 * current_derivative.x3 - 0.5 * previous_derivative.x3), }; double next_time = parameters->t_begin + static_cast(index + 1) * h; output[index + 1] = make_step(next_time, next); } }