Skip to content

Commit

Permalink
adding changes for propostional killling with kill year and kill freq…
Browse files Browse the repository at this point in the history
…uency in rgroup
  • Loading branch information
ashishtiwari2006 committed Oct 23, 2015
1 parent 195e0cd commit deed157
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 24 deletions.
38 changes: 22 additions & 16 deletions ST_indivs.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ void indiv_proportion_Kill( IndivType *ndv, int killType,RealF proportionKilled)
/*********** Locally Used Function Declarations ************/
/***********************************************************/
static IndivType *_create ( void);
static void _delete (IndivType *ndv);

//_delete function also called from ST_species.c
void _delete (IndivType *ndv);

/***********************************************************/
/****************** Begin Function Code ********************/
Expand Down Expand Up @@ -193,7 +195,7 @@ Bool indiv_Kill_Partial( MortalityType code,
return( result);
}

void indiv_proportion_Kill( IndivType *ndv, int killType,RealF proportionKilled){
void indiv_proportion_Kill( IndivType *ndv, int killType,RealF proportKilled){
/*======================================================*/
/* PURPOSE */
/* Remove individual proportionally and adjust relative sizes of the
Expand All @@ -212,19 +214,23 @@ void indiv_proportion_Kill( IndivType *ndv, int killType,RealF proportionKilled)
ndv->age, Species[ndv->myspecies]->max_age,
Globals.currIter, Globals.currYear);
}
if(!UseGrid)
insertIndivKill(ndv->id,killType);

species_Update_Kills(ndv->myspecies, ndv->age);

if(proportionKilled >0.999){
Species_Update_Newsize(ndv->myspecies, -ndv->relsize);
_delete(ndv);
}else{
RealF newSize = -(ndv->relsize * proportionKilled);
printf("\n proportionKilled = %f, oldSize = %f, newSize for reduction = %f \n", ndv->relsize, newSize);
Species_Update_Newsize(ndv->myspecies, newSize);
}

if (!UseGrid)
insertIndivKill(ndv->id, killType);

species_Update_Kills(ndv->myspecies, ndv->age);

if (proportKilled > 0.999)
{
Species_Update_Newsize(ndv->myspecies, -ndv->relsize);
_delete(ndv);
}
else
{
RealF newSize = -(ndv->relsize * proportKilled);
ndv->relsize = ndv->relsize + newSize;
Species_Update_Newsize(ndv->myspecies, newSize);
}

}

Expand Down Expand Up @@ -256,7 +262,7 @@ void indiv_Kill_Complete( IndivType *ndv, int killType) {
}

/**************************************************************/
static void _delete (IndivType *ndv) {
void _delete (IndivType *ndv) {
/*======================================================*/
/* PURPOSE */
/* Local routine to remove the data object of an individual.
Expand Down
2 changes: 1 addition & 1 deletion ST_mortality.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ void mort_EndOfYear( void) {
if ( LT(g->killfreq, 1.0) ) {
if (RandUni() <= g->killfreq)
g->killyr = Globals.currYear;
} else if ( (Globals.currYear - g->startyr) % (IntU)g->killfreq == 0) {
} else if ( (Globals.currYear - (g->startyr-1)) % (IntU)g->killfreq == 0) {
g->killyr = Globals.currYear;
}
}
Expand Down
18 changes: 15 additions & 3 deletions ST_resgroups.c
Original file line number Diff line number Diff line change
Expand Up @@ -797,8 +797,21 @@ void RGroup_Update_Newsize( GrpIndex rg) {
/* first get group's relative size adjusted for num indivs */
/* ie, groupsize=1 when 1 indiv of each species is present */
/* ie each indiv is an equivalent contributor, not based on biomass */
ForEachEstSpp( sp, rg, n) sumsize += Species[sp]->relsize;
RGroup[rg]->relsize = sumsize / (RealF) RGroup[rg]->max_spp;
ForEachEstSpp( sp, rg, n)
sumsize += Species[sp]->relsize;

if (RGroup[rg]->est_count < 0)
RGroup[rg]->est_count = 0;

if (RGroup[rg]->est_count == 0 || LT(sumsize, 0.0))
{
RGroup[rg]->relsize = 0.0;
}
else
{
//For calculating rgroup relSize, sumsize should be divide by no of current established species in rgroup rather than total no of species in rgroup.
RGroup[rg]->relsize = sumsize / (RealF) RGroup[rg]->est_count;
}

if (RGroup[rg]->max_age != 1) {
/* compute the contribution of each indiv to the group's size */
Expand Down Expand Up @@ -1044,7 +1057,6 @@ void RGroup_Kill( GrpIndex rg) {

ForEachEstSpp2( rg, i)
Species_Proportion_Kill(RGroup[rg]->est_spp[i], 6,RGroup[rg]->proportion_killed);
//Species_Kill(RGroup[rg]->est_spp[i], 6);
}

/**********************************************************/
Expand Down
30 changes: 27 additions & 3 deletions ST_species.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Bool indiv_New( SppIndex sp);
void indiv_Kill_Complete( IndivType *ndv, int killType);
void indiv_proportion_Kill( IndivType *ndv, int killType,RealF proportionKilled);

void _delete (IndivType *ndv);

/*------------------------------------------------------*/
/* Modular functions only used on one or two specific */
/* places; that is, they are not generally useful */
Expand Down Expand Up @@ -372,22 +374,44 @@ void Species_Proportion_Kill (const SppIndex sp, int killType, RealF proportionK
*/

/*------------------------------------------------------*/
#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) )

IndivType *p = Species[sp]->IndvHead,
*t;


if (Species[sp]->max_age == 1) {
Species_Update_Newsize(sp, -Species[sp]->relsize);
} else {
while(p) {
t = p->Next;
//indiv_Kill_Complete( p, killType);
indiv_proportion_Kill( p, killType,proportionKilled);
p = t;
}
}

rgroup_DropSpecies(sp);
if ( LT(Species[sp]->relsize, 0.0) || ZERO(Species[sp]->relsize) )
{
//"Warning:ST_species.c Species_Proportion_Kill() Species[sp]->relsize is either zero or negative so deleting all the individual in species and making species rel_size to zero
Species[sp]->relsize = 0.0 ;
IndivType *p1 = Species[sp]->IndvHead, *t1;

while (p1)
{
t1 = p1->Next;
_delete(p);
p1 = t1;
}
rgroup_DropSpecies(sp);
}

#undef xF_DELTA
#undef xD_DELTA
#undef ZERO

}

Expand Down
4 changes: 3 additions & 1 deletion testing.sagebrush.MT_drs/Stepwat Inputs/Input/rgroup.in
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
# into ephemeral (this year's) biomass by
# grams_extra_biomass = mm_extra_ppt * xgrow_factor
# veg_prod_type = 1 for tree, 2 for shrub, & 3 for grass. Refer to soilwat's VegProd types in VegProd.h.
#
# proportion_killed = proportionally killed all members of the group at end of the given kill year.
# proportion_recovered =

#TM - density values from Biondini et al 1998 - used density% in Table 2 for p.cool.forb (Achillea millefolium) and
# p.warm.forb (Grindelia squarrosa)
#TM - density values for annual cool grasses from (http://www.fs.fed.us/database/feis/plants/graminoid/brojap/all.html) converted 56 stems/sqft to stems/sqmeter
Expand Down

0 comments on commit deed157

Please sign in to comment.