/* 
    Autogenerated using:
    - Template: 'src/ext/models/model.cu.mako'
    - Model definition: 'codegen/recipes/kuramoto.yaml'
    Do not modify this autogenerated code. Instead modify template
    or model definition.
*/
#include "cubnm/includes.cuh"
#include "cubnm/defines.h"
#include "cubnm/models/kuramoto.cuh"

__device__ __NOINLINE__ void KuramotoModel::init(
    double* _state_vars, double* _intermediate_vars,
    double* _global_params, double* _regional_params,
    int* _ext_int, bool* _ext_bool,
    int* _ext_int_shared, bool* _ext_bool_shared
) {
    // theta = init_theta
    _state_vars[0] = _regional_params[0];
}

__device__ __NOINLINE__ void KuramotoModel::restart(
    double* _state_vars, double* _intermediate_vars, 
    double* _global_params, double* _regional_params,
    int* _ext_int, bool* _ext_bool,
    int* _ext_int_shared, bool* _ext_bool_shared
) {
    // theta = init_theta
    _state_vars[0] = _regional_params[0];
}

__device__ void KuramotoModel::step(
        double* _state_vars, double* _intermediate_vars,
        double* _global_params, double* _regional_params,
        double& tmp_globalinput,
        double* noise, long& noise_idx
        ) {
    // theta_dot = omega + G * globalinput
    _intermediate_vars[0] = _regional_params[1] + _global_params[0] * tmp_globalinput;
    // theta = theta + dt * theta_dot + sqrt_dt * noise * sigma
    _state_vars[0] = _state_vars[0] + d_Kuramotoc.dt * _intermediate_vars[0] + d_Kuramotoc.sqrt_dt * noise[noise_idx] * _regional_params[2];
    // Phase reset
    // theta = fmod(theta, twopi)
    _state_vars[0] = fmod(_state_vars[0], d_Kuramotoc.twopi);
}
