Skip to content

Commit

Permalink
Merge pull request #376 from DrylandEcology/feature_space
Browse files Browse the repository at this point in the history
Merge feature_space into master
  • Loading branch information
chaukap committed Aug 21, 2019
2 parents 21ac106 + dc27abf commit d075207
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 63 deletions.
3 changes: 2 additions & 1 deletion ST_indivs.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ void indiv_proportion_Kill(IndivType *ndv, int killType, RealF proportKilled)
// insertIndivKill(ndv->id, killType);

//kill indiv Proportionally or adjust their real size irrespective of being annual or perennial, both will have this effect
species_Update_Kills(ndv->myspecies, ndv->age);
// saving killing year real size here that is going to use for calculating next year proportional recovery
ndv->prv_yr_relsize = ndv->relsize;

Expand All @@ -238,6 +237,8 @@ void indiv_proportion_Kill(IndivType *ndv, int killType, RealF proportKilled)
if (ZERO(ndv->relsize) || LT(ndv->relsize, 0.0))
{
ndv->relsize =0.0;
// increase mortality count only if relsize has become zero due to fire
species_Update_Kills(ndv->myspecies, ndv->age);
}

#undef xF_DELTA
Expand Down
3 changes: 3 additions & 0 deletions ST_mortality.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ void mort_Main( Bool *killed) {
/* annuals are not subject to these sources of mortality and instead die in _kill_annuals */
if (g->max_age == 1) continue;

/* Calculate PR at the functional group level: resources required/resources available */
g->pr = ZRO(g->res_avail) ? 0. : g->res_required / g->res_avail;

/* kill plants if low resources for consecutive years */
/* increment yrs_neg_pr if pr > 1, else zero it. */
/* one good year cancels all previous bad years. */
Expand Down
9 changes: 6 additions & 3 deletions ST_params.c
Original file line number Diff line number Diff line change
Expand Up @@ -909,10 +909,12 @@ static void _rgroup_add1( char name[], RealF space, RealF density,
RGroup[rg]->grp_num = rg;
RGroup[rg]->max_stretch = (IntS) stretch;
RGroup[rg]->max_spp_estab = (IntS) estab;
RGroup[rg]->max_density = density;
RGroup[rg]->max_per_sqm = density / Globals.plotsize;
// input of `density` is in units of [# / m2]; convert to units of [# / plot]
RGroup[rg]->max_density = density * Globals.plotsize; // density per plot
RGroup[rg]->max_per_sqm = density; // density per square-meter
RGroup[rg]->use_mort = itob(mort);
RGroup[rg]->slowrate = slow;
RGroup[rg]->space = space;
RGroup[rg]->min_res_req = space;
RGroup[rg]->est_annually = itob(estann);
RGroup[rg]->startyr = styr;
Expand Down Expand Up @@ -1107,7 +1109,8 @@ static void _species_init( void) {
Species[sp]->received_prob = 0;
Species[sp]->cohort_surv = cohort;
Species[sp]->var = var;
Species[sp]->pseed = pseed / Globals.plotsize;
// input of `pseed` is in units of [# / m2]; convert to units of [# / plot]
Species[sp]->pseed = pseed * Globals.plotsize;
/* Species[sp]->ann_mort_prob = (age > 0)
? -log(cohort)/age
: 0.0;
Expand Down
48 changes: 34 additions & 14 deletions ST_resgroups.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ void rgroup_PartResources(void) {
LogError(logfp, LOGWARN, "RGroup %s : res_avail is Zero and res_required > 0", g->name);
}

/* Calculate PR at the functional group level: resources required/resources available */
g->pr = ZRO(g->res_avail) ? 0. : g->res_required / g->res_avail;
//printf("g->pr = %f\n,Group = %s \n",RGroup[rg]->name, g->pr);

/* If relsize>0 and individuals are established, reset noplants from TRUE to FALSE */
if (GT(getRGroupRelsize(rg), 0.))
noplants = FALSE;
Expand Down Expand Up @@ -257,7 +253,7 @@ static void _res_part_extra(RealF extra, RealF size[]) {
continue;

/* Check to avoid dividing by 0 */
if (sum_size == 0.)
if (ZRO(sum_size))
req_prop = 0.;

/* Calculate proportional biomass of each group out of the total biomass
Expand All @@ -267,9 +263,10 @@ static void _res_part_extra(RealF extra, RealF size[]) {

/* If the group can use extra resources, divide out extra based on
* proportional biomass */
if (g->use_extra_res)
if (g->use_extra_res) {
g->res_extra = req_prop * extra;

g->res_avail += g->res_extra;
}
/* If the group can't use extra resources, set res_extra to 0 */
else
g->res_extra = 0.;
Expand Down Expand Up @@ -384,9 +381,8 @@ void rgroup_ResPartIndiv(void) {

/* If individuals already have the resources they require do
* not assign extra */
if (ndv->res_avail == ndv->res_required) {
if (GE(ndv->res_avail, ndv->res_required)) {
ndv->res_extra = 0.0;
//printf("ndv->res_extra = %f\n", ndv->res_extra);
}

/* Assign extra resource as the difference of what is required
Expand Down Expand Up @@ -471,8 +467,7 @@ void rgroup_Grow(void) {
continue;

/* Modify growth rate by temperature calculated in Env_Generate() */
if (s->tempclass != NoSeason)
tgmod = Env.temp_reduction[s->tempclass];
tgmod = (s->tempclass == NoSeason) ? 1. : Env.temp_reduction[s->tempclass];

/* Now increase size of the individual plants of current species */
ForEachIndiv(ndv, s) {
Expand Down Expand Up @@ -616,6 +611,8 @@ void rgroup_Establish(void) {
/*------------------------------------------------------*/

IntS i, num_est; /* number of individuals of sp. that establish*/
RealF
used_space = 0; /* sums up all of the space that is currently used */
GrpIndex rg;
SppIndex sp;
GroupType *g;
Expand All @@ -634,6 +631,7 @@ void rgroup_Establish(void) {
continue;

g->regen_ok = TRUE; /* default */
g->min_res_req = g->space; /* reset min_res_req, if it was modified last year */

if (Globals.currYear < RGroup[rg]->startyr) {
g->regen_ok = FALSE;
Expand All @@ -652,7 +650,6 @@ void rgroup_Establish(void) {
if (Species[sp]->max_age == 1) {
//printf("Globals.currYear = %hu, call to _add_annuals sp=%d Species[sp]->lastyear_relsize : %.5f \n", Globals.currYear, sp, Species[sp]->lastyear_relsize);
num_est = _add_annuals(rg, sp, Species[sp]->lastyear_relsize);
// printf("g->seedbank annuals=%d \n",g->seedbank);
}

/* Establishment for species that belong to perennial functional groups*/
Expand All @@ -670,8 +667,30 @@ void rgroup_Establish(void) {

} /* end ForEachGroupSpp() */
}

// sum up min_res_req in case we need to redistribute min_res_req
if (g->est_count > 0) {
used_space += g->min_res_req;
} else {
// this group needs no resources because it is not established.
g->min_res_req = 0;
}
} /* end ForEachGroup() */

// If there is unused (or too much used) space we need to redistribute
if (!EQ(used_space, 1.0)) {

ForEachGroup(rg) {
g = RGroup[rg];
/* Redistribute the unused (or too much used) space to all groups that
are established */
if (g->est_count > 0) {
g->min_res_req = g->min_res_req / used_space;
}
}
}
}

/***********************************************************/
void rgroup_IncrAges(void)
{
Expand Down Expand Up @@ -717,17 +736,18 @@ void rgroup_IncrAges(void)
/* Sums relsize for all individuals in all species in RGroup rg.
param rg = RGroup index.
Return: RGroup relsize. */

RealF getRGroupRelsize(GrpIndex rg){
Int n;
SppIndex sp;
double sum = 0.0;

ForEachEstSpp( sp, rg, n){
sum += getSpeciesRelsize(sp);
sum += getSpeciesRelsize(sp);
}

if(RGroup[rg]->est_count > 0){
return (RealF) sum / (RealF) RGroup[rg]->est_count;
return (RealF) sum;
} else {
return 0;
}
Expand Down
7 changes: 4 additions & 3 deletions ST_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ struct species_st {
estabs, /* number of individuals established in iter */
*seedprod, /* annuals: array of previous years' seed production (size = viable_yrs)*/
seedbank,
pseed;
pseed; /* average number of seeds produced by annual species per 1g of biomass, per 1m^2 and per year (internally re-calculated as seeds per 1 g biomass per plot and per year) */
RealF lastyear_relsize, /* relsize from the previous year, used for annual establishment */
extragrowth, /* amt of superfluous growth from extra resources */
received_prob, //the chance that this species received seeds this year... only applicable if using seed dispersal and gridded option
Expand Down Expand Up @@ -180,9 +180,10 @@ struct resourcegroup_st {
grazingfrq, /* grazing effect on group at this frequency: <1=prob, >1=# years */
grazingfreq_startyr;/* start year for grazing frequency*/
SppIndex *species; /*list of spp belonging to this grp*/
RealF min_res_req, /* input from table */
RealF space, /* input from table */
min_res_req, /* input space from table, rescaled if one or more rgroups is not established */
max_density, /* number of mature plants per plot allowed */
max_per_sqm, /* convert density and plotsize to max plants/m^2 */
max_per_sqm, /* density of mature plants in units of plants / m^2 */
max_bmass, /* sum of mature biomass for all species in group */
killfreq, /* kill group at this frequency: <1=prob, >1=# years */
ignition, /* cheatgrass biomass (g/m2) that triggers potential ignition of a wildfire */
Expand Down
Loading

0 comments on commit d075207

Please sign in to comment.