Example #1
0
void KL_fprintf(const ok_list* kl, FILE* out, const char* fmt, const char* lfmt) {
    lfmt = (lfmt != NULL ? lfmt : "%10s%d");
    
    int np = MROWS(kl->kernels[0]->elements)-1;
    int vo = PARAMS_SIZE;
    
    fprintf(out, "# Planets = %d\n", np);
    fprintf(out, "# Trials = %d\n", kl->size);
    fprintf(out, "# Mstar = %e\n", K_getMstar(kl->prototype));
    fprintf(out, "# Epoch = %e\n", K_getEpoch(kl->prototype));
    
    
    
    for (int i = 0; i < ALL_ELEMENTS_SIZE; i++)
        for (int j = 1; j <= np; j++)
            fprintf(out, lfmt, ok_all_orb_labels[i], j);
    for (int i = 0; i < vo; i++)
        fprintf(out, lfmt, "PARAM", i);
    fprintf(out, "\n");
    
    for (int m = 0; m < kl->size; m++) {

        gsl_matrix* ae = kl->kernels[m]->elements;
        for (int i = 0; i < ALL_ELEMENTS_SIZE; i++)
            for (int j = 1; j <= np; j++)
                fprintf(out, fmt, MGET(ae, j, i));
        
        for (int i = 0; i < vo; i++)
            fprintf(out, fmt, VGET(kl->kernels[m]->params, i));
        
        fprintf(out, fmt, kl->kernels[m]->merit);
        fprintf(out, fmt, kl->kernels[m]->merit_pr);
        fprintf(out, fmt, kl->kernels[m]->merit_li);
        fprintf(out, fmt, kl->kernels[m]->tag);
        fprintf(out, " \n");
        
    }
    
}
Example #2
0
double K_integrateForward(ok_kernel* k, const int mode, const double nyears,
                          const int row, const int col) {

    static ok_system* sys = NULL;
    static double time;
    static double yearspast;
    static double dt;
    static gsl_vector* times = NULL;
    static gsl_matrix* els = NULL;

    if (K_getNplanets(k) == 0)
        return 0;

    if (mode == JS_I_START) {
        if (times == NULL)
            times = gsl_vector_alloc(2);
        dt = MIN(nyears, 10);
        time = K_getEpoch(k);
        yearspast = 0;
        sys = ok_copy_system(k->system);
        ok_setup(sys);
    } else if (mode == JS_I_STEP) {
        if (yearspast >= nyears)
            return JS_I_ENDREACHED;

        if (els != NULL) {
            gsl_matrix_free(els);
            els = NULL;
        }
        VSET(times, 0, time);
        VSET(times, 1, time + dt * 365.25);

        yearspast += dt;

        int error;
        ok_system** bag = ok_integrate(sys, times, k->intOptions, RK89, NULL, &error);
        els = ok_get_els(bag, 2, false);

        ok_free_system(sys);
        sys = ok_copy_system(bag[1]);
        ok_free_systems(bag, 2);
        time += dt * 365.25;

        if (error != INTEGRATION_SUCCESS)
            return -error;

        return yearspast;
    } else if (mode == JS_I_END) {
        if (els != NULL) {
            gsl_matrix_free(els);
            els = NULL;
        }
        if (sys != NULL) {
            ok_free_system(sys);
            sys = NULL;
        }
    } else if (mode == JS_I_GET) {
        if (col == SMA) {
            int idx = row * ELEMENTS_SIZE + PER + 1;
            double mstar = K_getMstar(k) * K2;
            double mp = K_getElement(k, row, MASS) * MJUP / MSUN * K2;
            double P = MGET(els, 1, idx);

            return ok_acalc(P, mstar, mp);
        } else {
            int idx = row * ELEMENTS_SIZE + col + 1;
            return MGET(els, 1, idx);
        }
    };


    return 0;
}