void sync_network::calculate_phases(const solve_type solver, const double t, const double step, const double int_step) { std::vector<double> next_phases(size(), 0); std::vector<void *> argv(2, NULL); argv[0] = (void *) this; unsigned int number_int_steps = (unsigned int) (step / int_step); for (unsigned int index = 0; index < size(); index++) { argv[1] = (void *) &index; switch(solver) { case solve_type::FAST: { double result = m_oscillators[index].phase + phase_kuramoto(t, m_oscillators[index].phase, argv); next_phases[index] = phase_normalization(result); break; } case solve_type::RK4: { differ_state<double> inputs(1, m_oscillators[index].phase); differ_result<double> outputs; runge_kutta_4(m_callback_solver, inputs, t, t + step, number_int_steps, false, argv, outputs); next_phases[index] = phase_normalization( outputs[0].state[0] ); break; } case solve_type::RKF45: { differ_state<double> inputs(1, m_oscillators[index].phase); differ_result<double> outputs; runge_kutta_fehlberg_45(m_callback_solver, inputs, t, t + step, 0.00001, false, argv, outputs); next_phases[index] = phase_normalization( outputs[0].state[0] ); break; } default: { throw std::runtime_error("Unknown type of solver"); } } } /* store result */ for (unsigned int index = 0; index < size(); index++) { m_oscillators[index].phase = next_phases[index]; } }
void syncnet::phase_kuramoto_equation(const double t, const differ_state<double> & inputs, const differ_extra<void *> & argv, differ_state<double> & outputs) const { outputs.resize(1); outputs[0] = phase_kuramoto(t, inputs[0], argv); }