void setInitialNBodyState(NBodyState* st, const NBodyCtx* ctx, Body* bodies, int nbody)
{
    static const NBodyTree emptyTree = EMPTY_TREE;
    static const mwvector maxV = mw_vec(REAL_MAX, REAL_MAX, REAL_MAX);
    int i;

    st->tree = emptyTree;
    st->freeCell = NULL;
    st->usesQuad = ctx->useQuad;
    st->usesExact = (ctx->criterion == Exact);

    st->tree.rsize = ctx->treeRSize;
    st->step = 0;
    st->nbody = nbody;
    st->bodytab = bodies;


    st->orbitTrace = (mwvector*) mwMallocA(N_ORBIT_TRACE_POINTS * sizeof(mwvector));
    for (i = 0; i < N_ORBIT_TRACE_POINTS; ++i)
    {
        st->orbitTrace[i] = maxV;
    }

    /* The tests may step the system from an arbitrary place, so make sure this is 0'ed */
    st->acctab = (mwvector*) mwCallocA(nbody, sizeof(mwvector));
}
Exemple #2
0
/* Try to run a potential function and see if it fails. Return TRUE on failure. */
static int nbVerifyPotentialFunction(const NBodyFlags* nbf, const NBodyCtx* ctx, NBodyState* st)
{
    mwvector acc;
    mwvector pos = mw_vec(1.0, 1.0, 0.0);

    if (ctx->potentialType != EXTERNAL_POTENTIAL_CUSTOM_LUA)
    {
        return FALSE;
    }

    /* Try to use it once to make sure it is OK */
    if (nbOpenPotentialEvalStatePerThread(st, nbf))
    {
        return TRUE;
    }

    nbEvalPotentialClosure(st, pos, &acc);
    return st->potentialEvalError;
}