diff --git a/src/HarvestEffects.cs b/src/HarvestEffects.cs index 810c2d6..be4a037 100644 --- a/src/HarvestEffects.cs +++ b/src/HarvestEffects.cs @@ -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; @@ -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; @@ -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; @@ -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; diff --git a/src/Layer.cs b/src/Layer.cs index 575b54a..d8bdb6f 100644 --- a/src/Layer.cs +++ b/src/Layer.cs @@ -352,7 +352,6 @@ 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); @@ -360,10 +359,11 @@ public void TransferCarbon(Layer destination, double netCFlow) 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); }