コード例 #1
0
ファイル: SISe3.c プロジェクト: trosendal/SimInf
/**
 * Update environmental infectious pressure phi
 *
 * @param v_new The continuous state vector in the node after the post
 * time step
 * @param u The compartment state vector in the node.
 * @param v The current continuous state vector in the node.
 * @param ldata The local data vector for the node.
 * @param gdata The global data vector.
 * @param node The node.
 * @param t Current time.
 * @param sd The sub-domain of the node.
 * @return error code (<0), or 1 if node needs to update the
 * transition rates, or 0 when it doesn't need to update the
 * transition rates.
 */
int SISe3_post_time_step(
    double *v_new,
    const int *u,
    const double *v,
    const double *ldata,
    const double *gdata,
    int node,
    double t,
    int sd)
{
    const int day = (int)t % 365;
    const double I_n = u[I_1] + u[I_2] + u[I_3];
    const double n = I_n + u[S_1] + u[S_2] + u[S_3];
    const double phi = v[PHI];

    /* Time dependent beta in each of the four intervals of the
     * year. Forward Euler step. */
    v_new[PHI] = siminf_forward_euler_linear_decay(
        phi, day,
        ldata[END_T1], ldata[END_T2], ldata[END_T3], ldata[END_T4],
        gdata[BETA_T1], gdata[BETA_T2], gdata[BETA_T3], gdata[BETA_T4]);

    if (n > 0.0)
        v_new[PHI] += gdata[ALPHA] * I_n / n + gdata[EPSILON];
    else
        v_new[PHI] += gdata[EPSILON];

    if (isfinite(v_new[PHI]))
        return phi != v_new[PHI]; /* 1 if needs update */
    return SIMINF_ERR_V_IS_NOT_FINITE;
}
コード例 #2
0
ファイル: SISe_sp.c プロジェクト: cran/SimInf
/**
 * Update environmental infectious pressure phi
 *
 * Decay environmental infectious pressure phi, add contribution from
 * infected individuals and proximity coupling.
 * @param v_new The continuous state vector in the node after the post
 * time step
 * @param u The compartment state vector in the node.
 * @param v The current continuous state vector in the node.
 * @param ldata The local data vector for the node.
 * @param gdata The global data vector.
 * @param node The node.
 * @param t Current time.
 * @param sd The sub-domain of the node.
 * @return error code (<0), or 1 if node needs to update the
 * transition rates, or 0 when it doesn't need to update the
 * transition rates.
 */
int SISe_sp_post_time_step(
    double *v_new,
    const int *u,
    const double *v,
    const double *ldata,
    const double *gdata,
    int node,
    double t,
    int sd)
{
    int i, j;
    const int day = (int)t % 365;
    const double I_n = u[I];
    const double n = u[S] + I_n;
    const double phi = v[PHI];
    const double coupling = gdata[COUPLING];

    /* Deterimine the pointer to the continuous state vector in the
     * first node. Use this to find phi at neighbours to the current
     * node. */
    const double *phi_0 = &v[-node];

    /* Time dependent decay (beta) of the environmental infectious
     * pressure in each of the four intervals of the year. Forward
     * Euler step. */
    v_new[PHI] = siminf_forward_euler_linear_decay(
        phi, day,
        ldata[END_T1], ldata[END_T2], ldata[END_T3], ldata[END_T4],
        gdata[BETA_T1], gdata[BETA_T2], gdata[BETA_T3], gdata[BETA_T4]);

    /* Add contribution from infected individuals */
    if (n > 0.0)
        v_new[PHI] += gdata[ALPHA] * I_n / n + gdata[EPSILON];
    else
        v_new[PHI] += gdata[EPSILON];

    /* Coupling between neighboring nodes. */
    /* i is the offset in local data to the first neighbor. */
    /* j is the neighbor node or -1 to stop.  */
    i = NEIGHBOR;
    j = (int)ldata[i];
    while (j >= 0) {
        v_new[PHI] += (phi_0[j] - phi) * coupling * ldata[i + 1];

        /* Move to next neighbor pair (index, value) */
        i += 2;
        j = (int)ldata[i];
    }

    if (isfinite(v_new[PHI]))
        return phi != v_new[PHI]; /* 1 if needs update */
    return SIMINF_ERR_V_IS_NOT_FINITE;
}