コード例 #1
0
ファイル: water_balance.c プロジェクト: Jinyan-Yang/GDAY
void initialise_soil_moisture_parameters(control *c, params *p) {
    /*
      initialise parameters, if these are not known for the site use
      values derived from Cosby et al to calculate the amount of plant
      available water.
     */

    double *fsoil_top = NULL, *fsoil_root = NULL;

    if (c->calc_sw_params) {
        fsoil_top = get_soil_fracs(p->topsoil_type);
        fsoil_root = get_soil_fracs(p->rootsoil_type);

        /* top soil */
        calc_soil_params(fsoil_top, &p->theta_fc_topsoil, &p->theta_wp_topsoil,
                         &p->theta_sp_topsoil, &p->b_topsoil,
                         &p->psi_sat_topsoil);

        /* Plant available water in top soil (mm) */
        p->wcapac_topsoil = p->topsoil_depth  *\
                            (p->theta_fc_topsoil - p->theta_wp_topsoil);
        /* Root zone */
        calc_soil_params(fsoil_root, &p->theta_fc_root, &p->theta_wp_root,
                         &p->theta_sp_root, &p->b_root, &p->psi_sat_root);

        /* Plant available water in rooting zone (mm) */
        p->wcapac_root = p->rooting_depth * \
                            (p->theta_fc_root - p->theta_wp_root);
    }


    /* calculate Landsberg and Waring SW modifier parameters if not
       specified by the user based on a site calibration */
    if (p->ctheta_topsoil < -900.0 && p->ntheta_topsoil  < -900.0 &&
        p->ctheta_root < -900.0 && p->ntheta_root < -900.0) {
        get_soil_params(p->topsoil_type, &p->ctheta_topsoil, &p->ntheta_topsoil);
        get_soil_params(p->rootsoil_type, &p->ctheta_root, &p->ntheta_root);
    }
    /*
    printf("%f\n", p->wcapac_topsoil);
    printf("%f\n\n", p->wcapac_root);

    printf("%f\n", p->ctheta_topsoil);
    printf("%f\n", p->ntheta_topsoil);
    printf("%f\n", p->ctheta_root);
    printf("%f\n", p->ntheta_root);
    printf("%f\n", p->rooting_depth);

    exit(1); */



    free(fsoil_top);
    free(fsoil_root);

    return;
}
コード例 #2
0
void initialise_soils_sub_daily(control *c, fluxes *f, params *p, state *s) {
    /*
        Initialise soil water state & parameters
            - We have two options: (i) simple two-layer bucket, or
            - multi-layer soil model.

        Currently, I'm just using the same soil type for all layers in the
        multi-layer model, once it all works we can add something to allow
        texture to be changes by layer/depth.

        NB. get_soil_fracs, calc_soil_params, get_soil_params live in
            water_balance.c
    */

    double *fsoil_top = NULL, *fsoil_root = NULL;
    int     i;

    /* site params not known, so derive them based on Cosby et al */
    if (c->calc_sw_params) {
        fsoil_top = get_soil_fracs(p->topsoil_type);
        fsoil_root = get_soil_fracs(p->rootsoil_type);

        /* top soil */
        calc_soil_params(fsoil_top, &p->theta_fc_topsoil, &p->theta_wp_topsoil,
                         &p->theta_sp_topsoil, &p->b_topsoil,
                         &p->psi_sat_topsoil);

        /* Plant available water in top soil (mm) */
        p->wcapac_topsoil = p->topsoil_depth  *\
                            (p->theta_fc_topsoil - p->theta_wp_topsoil);
        /* Root zone */
        calc_soil_params(fsoil_root, &p->theta_fc_root, &p->theta_wp_root,
                         &p->theta_sp_root, &p->b_root, &p->psi_sat_root);

        /* Plant available water in rooting zone (mm) */
        p->wcapac_root = p->rooting_depth * \
                            (p->theta_fc_root - p->theta_wp_root);
    }


    /* calculate Landsberg and Waring SW modifier parameters if not
       specified by the user based on a site calibration */
    if (p->ctheta_topsoil < -900.0 && p->ntheta_topsoil  < -900.0 &&
        p->ctheta_root < -900.0 && p->ntheta_root < -900.0) {
        get_soil_params(p->topsoil_type, &p->ctheta_topsoil, &p->ntheta_topsoil);
        get_soil_params(p->rootsoil_type, &p->ctheta_root, &p->ntheta_root);
    }

    /* Set up all the hydraulics stuff */
    if (c->water_balance == HYDRAULICS) {
        calc_saxton_stuff(p, fsoil_root);

        for (i = 0; i < p->wetting; i++) {
            s->wetting_bot[i] = 0.0;
            s->wetting_top[i] = 0.0;
        }

        /* saturate the top layer */
        s->wetting_bot[0] = s->thickness[0];

        /* Initalise SW fraction - we should read this from param file */
        s->initial_water = 0.0;
        for (i = 0; i < p->n_layers; i++) {
            s->water_frac[i] = 0.4;
            s->initial_water += 1E3 * (s->water_frac[i] * s->thickness[i]);
        }

        /*
        ** The loop needs to be outside the func as we need to be able to
        ** calculate the soil conductance per layer and call this via
        ** the integration func when we update the soil water balance
        */
        for (i = 0; i < p->n_layers; i++) {
            f->soil_conduct[i] = calc_soil_conductivity(s->water_frac[i],
                                                        p->cond1[i], p->cond2[i],
                                                        p->cond3[i]);
        }

        calc_soil_root_resistance(f, p, s);
        calc_soil_water_potential(f, p, s);

        /* Calculate the weighted soil-water-potential */
        calc_water_uptake_per_layer(f, p, s);
    }

    if (c->calc_sw_params) {
        free(fsoil_top);
        free(fsoil_root);
    }

    return;
}