Skip to content

Commit

Permalink
Addressing issue #131 and #130
Browse files Browse the repository at this point in the history
- formatted
- added check to skip annual species in proportion_recovery as they are already dead at this point
-corrected warning in indiv_proportion_Recovery, it is fine is relsize is 0.0 here.
-added print statements
- edited check_sizes so more decimal places are printed out.
  • Loading branch information
kpalmqui committed Jun 12, 2018
1 parent 51e3628 commit 7766fa7
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 162 deletions.
124 changes: 65 additions & 59 deletions ST_indivs.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,83 +254,89 @@ void indiv_proportion_Kill(IndivType *ndv, int killType, RealF proportKilled)
}
void indiv_proportion_Grazing( IndivType *ndv, RealF proportionGrazing)
{
/*======================================================*/
/* PURPOSE */
/* Do individual grazing proportionally and adjust relative sizes of the
* RGroup and Species downward proportionally by the size of the indiv.
* Also keep up with survivorship data.
*/
/* HISTORY */
/* 1st Nov 2015- AT
/*------------------------------------------------------*/

#define xF_DELTA (20*F_DELTA)
#define xD_DELTA (20*D_DELTA)
#define ZERO(x) \
/*======================================================*/
/* PURPOSE */
/* Do individual grazing proportionally and adjust relative sizes of the
* RGroup and Species downward proportionally by the size of the indiv.
* Also keep up with survivorship data.
*/
/* HISTORY */
/* 1st Nov 2015- AT */
/*------------------------------------------------------*/

#define xF_DELTA (20*F_DELTA)
#define xD_DELTA (20*D_DELTA)
#define ZERO(x) \
( (sizeof(x) == sizeof(float)) \
? ((x)>-xF_DELTA && (x)<xF_DELTA) \
: ((x)>-xD_DELTA && (x)<xD_DELTA) )


RealF grazing_reduce = -(ndv->relsize * proportionGrazing);
// printf("inside indiv_proportion_Grazing() old indiv rel_size=%f, grazing_reduce=%f \n",ndv->relsize,grazing_reduce);
ndv->relsize = ndv->relsize + grazing_reduce;
// printf("inside indiv_proportion_Grazing() new indiv rel_size=%f \n",ndv->relsize);
Species_Update_Newsize(ndv->myspecies, grazing_reduce);
RealF grazing_reduce = -(ndv->relsize * proportionGrazing);
// printf("inside indiv_proportion_Grazing() old indiv rel_size=%f, grazing_reduce=%f \n",ndv->relsize,grazing_reduce);
ndv->relsize = ndv->relsize + grazing_reduce;
// printf("inside indiv_proportion_Grazing() new indiv rel_size=%f \n",ndv->relsize);
Species_Update_Newsize(ndv->myspecies, grazing_reduce);

if (ZERO(ndv->relsize) || LT(ndv->relsize, 0.0))
{
ndv->relsize = 0.0;
}
#undef xF_DELTA
#undef xD_DELTA
#undef ZERO
ndv->relsize = 0.0;
}
#undef xF_DELTA
#undef xD_DELTA
#undef ZERO
}

void indiv_proportion_Recovery( IndivType *ndv, int killType,RealF proportionRecovery,RealF proportionKilled)
{
/*======================================================*/
/* PURPOSE */
/* Recover individual proportionally and adjust relative sizes of the
* RGroup and Species upward proportionally by the size of the indiv.
* Also keep up with survivorship data. */
/* HISTORY */
/* 1st Nov 2015- AT */
/*------------------------------------------------------*/

#define xF_DELTA (20*F_DELTA)
#define xD_DELTA (20*D_DELTA)
#define ZERO(x) \
void indiv_proportion_Recovery(IndivType *ndv, int killType, RealF proportionRecovery, RealF proportionKilled) {
/*======================================================*/
/* PURPOSE */
/* Recover individuals proportionally after fire and adjust relative sizes
* of the RGroup and Species upward proportionally by the size of the indiv.
* Also keep up with survivorship data. */
/* HISTORY */
/* 1st Nov 2015- AT */
/*------------------------------------------------------*/

#define xF_DELTA (20*F_DELTA)
#define xD_DELTA (20*D_DELTA)
#define ZERO(x) \
( (sizeof(x) == sizeof(float)) \
? ((x)>-xF_DELTA && (x)<xF_DELTA) \
: ((x)>-xD_DELTA && (x)<xD_DELTA) )

// using individual killing year old real size and reduction for making base for calculating proportional recovery
RealF prev_reduction = ndv->prv_yr_relsize * proportionKilled;
RealF increase = prev_reduction * proportionRecovery;

//printf("previous year ndv->relsize before = %f\n, Species = %s \n", ndv->prv_yr_relsize, Species[ndv->myspecies]->name);
//printf("ndv->relsize before = %f\n, Species = %s \n", ndv->relsize, Species[ndv->myspecies]->name);
//printf("increase = %f\n, Species = %s \n", increase, Species[ndv->myspecies]->name);
/* Utilize individual relsize saved before killing and proportionKilled
* to determine proportional recovery */
RealF prev_reduction = ndv->prv_yr_relsize * proportionKilled;
RealF increase = prev_reduction * proportionRecovery;

ndv->relsize = ndv->relsize + increase;
Species_Update_Newsize(ndv->myspecies, increase);
//printf("ndv->relsize after = %f\n,Species = %s \n", ndv->relsize, Species[ndv->myspecies]->name);
//printf("previous year ndv->relsize before = %f\n, Species = %s \n", ndv->prv_yr_relsize, Species[ndv->myspecies]->name);
//printf("ndv->relsize before = %f\n, Species = %s \n", ndv->relsize, Species[ndv->myspecies]->name);
//printf("increase = %f\n, Species = %s \n", increase, Species[ndv->myspecies]->name);

if (ZERO(ndv->relsize) || LT(ndv->relsize, 0.0))
{
// this should never happend because `increase` should always be positive
LogError(logfp, LOGWARN, "'indiv_proportion_Recovery': an individual of "\
"%s reached relsize of 0 and is removed (increase = %.3f): for " \
ndv->relsize = ndv->relsize + increase;

Species_Update_Newsize(ndv->myspecies, increase);
//printf("ndv->relsize after = %f\n,Species = %s \n", ndv->relsize, Species[ndv->myspecies]->name);

/* This should never happen because proportion recovered should always be
* positive or zero */
if (LT(ndv->relsize, 0.0)) {
// this should never happend because `increase` should always be positive
LogError(logfp, LOGWARN, "'indiv_proportion_Recovery': an individual of "\
"%s reached relsize < 0 and is removed (increase = %.3f): for " \
"killType = %d, proportionKilled = %.2f, proportionRecovery = %.2f",
Species[ndv->myspecies]->name, increase,
killType, proportionKilled, proportionRecovery);
Species[ndv->myspecies]->name, increase,
killType, proportionKilled, proportionRecovery);
}

_delete(ndv);
}
#undef xF_DELTA
#undef xD_DELTA
#undef ZERO
/* If the relsize is still zero or is less than zero, remove the individual */
if (ZERO(ndv->relsize) || LT(ndv->relsize, 0.0)) {
_delete(ndv);
}

#undef xF_DELTA
#undef xD_DELTA
#undef ZERO
}

/**************************************************************/
Expand Down
4 changes: 2 additions & 2 deletions ST_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -569,15 +569,15 @@ void check_sizes(const char *chkpt) {

if (LT(diff, fabs(spsize - Species[sp]->relsize)) ) {
LogError(stdout, LOGWARN, "%s (%d:%d): SP: \"%s\" size error: "
"SP=%.3f, ndv=%.3f",
"SP=%.7f, ndv=%.7f",
chkpt, Globals.currIter, Globals.currYear,
Species[sp]->name, Species[sp]->relsize, spsize);
}
}

if ( LT(diff, fabs(rgsize -RGroup[rg]->relsize)) ) {
LogError(stdout, LOGWARN, "%s (%d:%d): RG \"%s\" size error: "
"RG=%.3f, ndv=%.3f",
"RG=%.7f, ndv=%.7f",
chkpt, Globals.currIter, Globals.currYear,
RGroup[rg]->name, RGroup[rg]->relsize, rgsize);
}
Expand Down
95 changes: 52 additions & 43 deletions ST_mortality.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,61 +316,70 @@ void grazing_EndOfYear( void){

}

void proportion_Recovery(void)
{
/*======================================================*/
void proportion_Recovery(void) {
/*======================================================*/
/* PURPOSE */
/* Perform the sorts of proportion_Recovery one might expect at next year after the killing year
/* Perform recovery of biomass that represents re-sprouting after a fire. This
* is controlled by proportion_recovered, specified in inputs and can be turned
* on or off for each functional group, depending on their ability to resprout. */
/* HISTORY */
/* 1st Nov 2015 -AT -Added Species Proportion Recovery */
/*======================================================*/
/* 1st Nov 2015 -AT -Added Species Proportion Recovery */
/*======================================================*/

GrpIndex rg;
GroupType *g;
GrpIndex rg;
GroupType *g;
SppIndex sp;

ForEachGroup(rg)
{
ForEachGroup(rg) {

if (Globals.currYear < RGroup[rg]->startyr)
{
/* don't start trying to grow until RGroup[rg]->startyr year */
continue;
}
if (Globals.currYear < RGroup[rg]->startyr) {
/* don't start trying to grow until RGroup[rg]->startyr year */
continue;
}

g = RGroup[rg];
g = RGroup[rg];

if ((Globals.currYear >= g->killfreq_startyr) && GT(g->killfreq, 0.))
{
if (LT(g->killfreq, 1.0))
{
if (RandUni() <= g->killfreq)
{
g->killyr = Globals.currYear;
}
if ((Globals.currYear >= g->killfreq_startyr) && GT(g->killfreq, 0.)) {
if (LT(g->killfreq, 1.0)) {
if (RandUni() <= g->killfreq) {
g->killyr = Globals.currYear;
}

}
else if (((Globals.currYear - g->killfreq_startyr) % (IntU) g->killfreq) == 0)
{
g->killyr = Globals.currYear;
}
} else if (((Globals.currYear - g->killfreq_startyr) % (IntU) g->killfreq) == 0) {
g->killyr = Globals.currYear;
}

}
}

//rgroup proportion recovery
if (Globals.currYear == RGroup[rg]->killyr)
{
Int i;
ForEachEstSpp2( rg, i)
{
Species_Proportion_Recovery(RGroup[rg]->est_spp[i], 6,
RGroup[rg]->proportion_recovered,
RGroup[rg]->proportion_killed);
}
}
//rgroup proportion recovery
if (Globals.currYear == RGroup[rg]->killyr) {
Int i;

}
}
//printf("'before proportion_recovery': Group = %s, relsize = %f, est_count = %d\n",
//RGroup[rg]->name, RGroup[rg]->relsize, RGroup[rg]->est_count);

ForEachEstSpp(sp, rg, i) {

/* Annuals have already been killed in _kill_annuals and are not
* subject to proportion recovery after fire */
if (Species[sp]->max_age == 1)
continue;

//printf("'before proportion_recovery': Species = %s, relsize = %f, est_count = %d\n",
// Species[sp]->name, Species[sp]->relsize, Species[sp]->est_count);

Species_Proportion_Recovery(RGroup[rg]->est_spp[i], 6,
RGroup[rg]->proportion_recovered,
RGroup[rg]->proportion_killed);

//printf("'after proportion_recovery': Species = %s, relsize = %f, est_count = %d\n",
//Species[sp]->name, Species[sp]->relsize, Species[sp]->est_count);
}
//printf("'after proportion_recovery': Group = %s, relsize = %f, est_count = %d\n",
// RGroup[rg]->name, RGroup[rg]->relsize, RGroup[rg]->est_count);
}
}
}

/***********************************************************/
static void _pat( const SppIndex sp) {
Expand Down
Loading

0 comments on commit 7766fa7

Please sign in to comment.