Skip to content

Commit

Permalink
Merge pull request #44 from aruzicka555/master
Browse files Browse the repository at this point in the history
Round carbon calculation double arithmetic
  • Loading branch information
rmscheller authored Aug 13, 2018
2 parents c98451b + 70f745d commit 8da1da3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
16 changes: 8 additions & 8 deletions src/HarvestEffects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ public static void ReduceLayers(string prescriptionName, Site site)

// Structural litter

double carbonLoss = SiteVars.SurfaceStructural[site].Carbon * litterLossMultiplier;
double nitrogenLoss = SiteVars.SurfaceStructural[site].Nitrogen * litterLossMultiplier;
double carbonLoss = Math.Round(SiteVars.SurfaceStructural[site].Carbon * litterLossMultiplier, 2);
double nitrogenLoss = Math.Round(SiteVars.SurfaceStructural[site].Nitrogen * litterLossMultiplier, 2);

SiteVars.SurfaceStructural[site].Carbon -= carbonLoss;
SiteVars.SourceSink[site].Carbon += carbonLoss;
Expand All @@ -205,8 +205,8 @@ public static void ReduceLayers(string prescriptionName, Site site)

// Metabolic litter

carbonLoss = SiteVars.SurfaceMetabolic[site].Carbon * litterLossMultiplier;
nitrogenLoss = SiteVars.SurfaceMetabolic[site].Nitrogen * litterLossMultiplier;
carbonLoss = Math.Round(SiteVars.SurfaceMetabolic[site].Carbon * litterLossMultiplier, 2);
nitrogenLoss = Math.Round(SiteVars.SurfaceMetabolic[site].Nitrogen * litterLossMultiplier, 2);

SiteVars.SurfaceMetabolic[site].Carbon -= carbonLoss;
SiteVars.SourceSink[site].Carbon += carbonLoss;
Expand All @@ -215,8 +215,8 @@ public static void ReduceLayers(string prescriptionName, Site site)
SiteVars.SourceSink[site].Nitrogen += nitrogenLoss;

// Surface dead wood
carbonLoss = SiteVars.SurfaceDeadWood[site].Carbon * woodLossMultiplier;
nitrogenLoss = SiteVars.SurfaceDeadWood[site].Nitrogen * woodLossMultiplier;
carbonLoss = Math.Round(SiteVars.SurfaceDeadWood[site].Carbon * woodLossMultiplier, 2);
nitrogenLoss = Math.Round(SiteVars.SurfaceDeadWood[site].Nitrogen * woodLossMultiplier, 2);

SiteVars.SurfaceDeadWood[site].Carbon -= carbonLoss;
SiteVars.SourceSink[site].Carbon += carbonLoss;
Expand All @@ -226,8 +226,8 @@ public static void ReduceLayers(string prescriptionName, Site site)

// Soil Organic Matter (Duff)

carbonLoss = SiteVars.SOM1surface[site].Carbon * som_Multiplier;
nitrogenLoss = SiteVars.SOM1surface[site].Nitrogen * som_Multiplier;
carbonLoss = Math.Round(SiteVars.SOM1surface[site].Carbon * som_Multiplier, 2);
nitrogenLoss = Math.Round(SiteVars.SOM1surface[site].Nitrogen * som_Multiplier, 2);

SiteVars.SOM1surface[site].Carbon -= carbonLoss;
SiteVars.SourceSink[site].Carbon += carbonLoss;
Expand Down
8 changes: 4 additions & 4 deletions src/Layer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,18 +352,18 @@ public void DecomposeMetabolic(ActiveSite site)
//---------------------------------------------------------------------
public void TransferCarbon(Layer destination, double netCFlow)
{

if (netCFlow < 0)
{
//PlugIn.ModelCore.UI.WriteLine("NEGATIVE C FLOW! Source: {0},{1}; Destination: {2},{3}.", this.Name, this.Type, destination.Name, destination.Type);
}

if (netCFlow > this.Carbon)
netCFlow = this.Carbon;
//PlugIn.ModelCore.UI.WriteLine("C FLOW EXCEEDS SOURCE! Source: {0},{1}; Destination: {2},{3}.", this.Name, this.Type, destination.Name, destination.Type);
//PlugIn.ModelCore.UI.WriteLine("C FLOW EXCEEDS SOURCE! Source: {0},{1}; Destination: {2},{3}.", this.Name, this.Type, destination.Name, destination.Type);

this.Carbon -= netCFlow;
destination.Carbon += netCFlow;
//round these to avoid unexpected behavior
this.Carbon = Math.Round(this.Carbon - netCFlow);
destination.Carbon = Math.Round(destination.Carbon + netCFlow);

}

Expand Down

0 comments on commit 8da1da3

Please sign in to comment.