Skip to content

Commit

Permalink
Resolving issues #73 and #78.
Browse files Browse the repository at this point in the history
  • Loading branch information
BrendenBe1 committed Feb 6, 2018
1 parent 2c8c28d commit 5d6ad4c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 28 deletions.
4 changes: 1 addition & 3 deletions ST_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,6 @@ int main(int argc, char **argv) {
RandSeed(Globals.randseed);
Globals.currIter = iter;

memset(SXW.transp_SWA, 0, sizeof(SXW.transp_SWA)); // set transp_SWA to 0; needs to be reset each iteration
//memset(SXW.sum_dSWA_repartitioned, 0, sizeof(SXW.sum_dSWA_repartitioned));

/* ------ Begin running the model ------ */
for (year = 1; year <= Globals.runModelYears; year++){
Globals.currYear = year;
Expand Down Expand Up @@ -333,6 +330,7 @@ void Plot_Initialize(void) {
RGroup[rg]->yrs_neg_pr = 0;
RGroup[rg]->extirpated = FALSE;
}
memset(SXW.transp_SWA, 0, sizeof(SXW.transp_SWA)); // set transp_SWA to 0; needs to be reset each iteration

if (UseSoilwat)
SXW_InitPlot();
Expand Down
57 changes: 35 additions & 22 deletions ST_resgroups.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void rgroup_PartResources(void)
else
{
g->res_required = RGroup_GetBiomass(rg);
g->res_avail = SXW_GetResource(rg); //1.0;
g->res_avail = SXW_GetTranspiration(rg); //1.0;
//PR limit can be really high see mort no_resource I limit to the groups estab indiv because that is what we can kill.
//This was at 10 but ten might be to low or high in some cases.
if(!ZRO(g->res_avail) && g->res_required / g->res_avail > g->estabs)
Expand All @@ -146,7 +146,7 @@ void rgroup_PartResources(void)
}
//KAP:Previously, a seperate set of code was used to determine resource availability for annual species
//Now, resource paritioning for annuals occurs in the same way as for perennials, by getting the RGroup Biomass
//and the resource_cur from SXW_GetResource
//and the resource_cur from SXW_GetTranspiration
//Annuals seem to have a artificial limit of 20. We do Annuals here differently
if(g->max_age == 1)
{
Expand Down Expand Up @@ -175,8 +175,8 @@ void rgroup_PartResources(void)

/*these functions are not used if using SOILWAT,
extra resource partitioning does not occur when running SOILWAT*/
// _res_part_extra(do_base, xtra_base, size_base);
//_res_part_extra(do_extra, xtra_obase, size_obase);
_res_part_extra(do_base, xtra_base, size_base);
_res_part_extra(do_extra, xtra_obase, size_obase);

/* reset annuals' "TRUE" relative size here */
//KAP: formely, this call established annual species. We have moved annual establishment to the Rgroup_Establish function,
Expand Down Expand Up @@ -397,8 +397,7 @@ static void _res_part_extra(Bool isextra, RealF extra, RealF size[])
void rgroup_ResPartIndiv(void)
{
/*======================================================*/
/* PURPOSE */
/* The PR value used in the growth loop is now at the
/* The PR value used in the growth loop is now at the
individual level rather than the group level, so the
resource availability for the group is divided between
individuals of the group, largest to smallest. Species
Expand All @@ -412,6 +411,8 @@ void rgroup_ResPartIndiv(void)

GrpIndex rg;
GroupType *g; /* shorthand for RGroup[rg] */
SppIndex sp;
Int j;
IndivType **indivs, /* dynamic array of indivs in RGroup[rg] */
*ndv; /* shorthand for the current indiv */
IntS numindvs, n;
Expand All @@ -425,32 +426,46 @@ void rgroup_ResPartIndiv(void)
if (!g->est_count)
continue;

numindvs = 0; // setting to 0 so no problems passing into RGroup_GetIndivs function
/* --- allocate the temporary group-oriented arrays */
indivs = RGroup_GetIndivs(rg, SORT_D, &numindvs); // SORT_D = sort in descending order
indivs = RGroup_GetIndivs(rg, SORT_D, &numindvs);

/* ---- assign indivs' availability, not including extra ---- */
/* resource <= 1.0 is for basic growth, >= extra */
/* amount of extra, if any, is kept in g->res_extra */
/* base_rem = fmin(1, g->res_avail); */
base_rem = g->res_avail;
for (n = 0; n < numindvs; n++)

ForEachEstSpp(sp, rg, j)
{
ndv = indivs[n];

ndv->res_required = (ndv->relsize / g->max_spp) / g->estabs;
if (GT(g->pr, 1.))
for (n = 0; n < numindvs; n++)
{
ndv = indivs[n];

ndv->res_required = (ndv->relsize * Species [sp]->mature_biomass);
//printf("ndv->res_required = %f\n, Species = %s \n", Species[sp]->name, ndv->res_required);

if (GT(g->pr, 1.))
{
ndv->res_avail = fmin(ndv->res_required, base_rem);
//printf("ndv->res_avail_pr>1 = %f\n", ndv->res_avail);

base_rem = fmax(base_rem - ndv->res_avail, 0.);
}
else
{
//printf("base_rem pr>1 = %f\n", base_rem);

}

else
{
ndv->res_avail = ndv->grp_res_prop * g->res_avail;
//printf("ndv->res_avail pr <1 = %f\n", ndv->res_avail);

}
}
}

base_rem += fmin(0, g->res_avail - 1.0);
//printf("base_rem end = %f\n", base_rem);

/* --- compute PR, but on the way, assign extra resource */
for (n = 0; n < numindvs; n++)
Expand All @@ -460,23 +475,21 @@ void rgroup_ResPartIndiv(void)
if (g->use_extra_res)
{
/* polish off any remaining resource not allocated to extra */
ndv->res_avail +=
ZRO(base_rem) ? 0. : ndv->grp_res_prop * base_rem;
ndv->res_avail += ZRO(base_rem) ? 0. : ndv->grp_res_prop * base_rem;
/* extra resource gets assigned here if applicable */
if (GT(g->res_extra, 0.))
{
x = 1. - ndv->relsize;
ndv->res_extra = (1. - x) * ndv->grp_res_prop
* g->res_extra;
ndv->res_extra = (1. - x) * ndv->grp_res_prop* g->res_extra;
ndv->res_avail += x * ndv->grp_res_prop * g->res_extra;
}

}

/* ---- at last! compute the PR value, or dflt to 100 */
ndv->pr =
GT(ndv->res_avail, 0.) ?
ndv->res_required / ndv->res_avail : 100.;
ndv->pr = GT(ndv->res_avail, 0.) ? ndv->res_required / ndv->res_avail : 100.;
//printf("ndv->pr = %f\n", ndv->pr);

}

Mem_Free(indivs);
Expand Down
4 changes: 2 additions & 2 deletions sxw.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,11 @@ KAP 7/20/2016
//return pr > 10 ? 10 : pr;
}

RealF SXW_GetResource( GrpIndex rg) {
RealF SXW_GetTranspiration( GrpIndex rg) {
/*======================================================*/
/* see _sxw_update_resource() for _resource_cur[]
*/
//printf("SXW_GetResource _resource_cur[%d] = %.5f \n", rg, _resource_cur[rg]);
//printf("SXW_GetTranspiration _resource_cur[%d] = %.5f \n", rg, _resource_cur[rg]);
return _resource_cur[rg];
}

Expand Down
2 changes: 1 addition & 1 deletion sxw_funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "sxw.h"

RealF SXW_GetPR( GrpIndex rg) ;
RealF SXW_GetResource( GrpIndex rg);
RealF SXW_GetTranspiration( GrpIndex rg);


RealF SXW_ResourceAvailable (void);
Expand Down

0 comments on commit 5d6ad4c

Please sign in to comment.