From deed157434b25d12b4dd43959eb7144b10a8e0c0 Mon Sep 17 00:00:00 2001 From: ashishtiwari2006 Date: Thu, 22 Oct 2015 18:16:10 -0600 Subject: [PATCH] adding changes for propostional killling with kill year and kill frequency in rgroup --- ST_indivs.c | 38 +++++++++++-------- ST_mortality.c | 2 +- ST_resgroups.c | 18 +++++++-- ST_species.c | 30 +++++++++++++-- .../Stepwat Inputs/Input/rgroup.in | 4 +- 5 files changed, 68 insertions(+), 24 deletions(-) diff --git a/ST_indivs.c b/ST_indivs.c index f0c72e5f..af5bf104 100755 --- a/ST_indivs.c +++ b/ST_indivs.c @@ -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 ********************/ @@ -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 @@ -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); + } } @@ -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. diff --git a/ST_mortality.c b/ST_mortality.c index 77375b4b..8de340ec 100755 --- a/ST_mortality.c +++ b/ST_mortality.c @@ -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; } } diff --git a/ST_resgroups.c b/ST_resgroups.c index 91772dfe..2ed3aa48 100755 --- a/ST_resgroups.c +++ b/ST_resgroups.c @@ -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 */ @@ -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); } /**********************************************************/ diff --git a/ST_species.c b/ST_species.c index c8b1ad30..a0a713e1 100755 --- a/ST_species.c +++ b/ST_species.c @@ -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 */ @@ -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)-xD_DELTA && (x)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 } diff --git a/testing.sagebrush.MT_drs/Stepwat Inputs/Input/rgroup.in b/testing.sagebrush.MT_drs/Stepwat Inputs/Input/rgroup.in index 4f2a265c..2afe2bc5 100644 --- a/testing.sagebrush.MT_drs/Stepwat Inputs/Input/rgroup.in +++ b/testing.sagebrush.MT_drs/Stepwat Inputs/Input/rgroup.in @@ -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