From 8e9a85ac5a2232f746e13e6b84a584278ed01a83 Mon Sep 17 00:00:00 2001 From: holos-aafc <95769272+holos-aafc@users.noreply.github.com> Date: Thu, 12 Sep 2024 07:51:40 -0600 Subject: [PATCH] Reduce N and C content with AD substrates, initialize silage yield --- H.Core/Calculators/Infrastructure/ADCalculator.cs | 4 ++-- H.Core/Calculators/Nitrogen/N2OEmissionFactorCalculator.cs | 2 -- H.Core/Models/Animals/AnimalGroup.cs | 1 - H.Core/Services/Animals/AnimalResultsServiceBase.cs | 6 ++---- .../Initialization/Crops/CropInitializationService.Yield.cs | 1 + 5 files changed, 5 insertions(+), 9 deletions(-) diff --git a/H.Core/Calculators/Infrastructure/ADCalculator.cs b/H.Core/Calculators/Infrastructure/ADCalculator.cs index 16583495..bfb957dd 100644 --- a/H.Core/Calculators/Infrastructure/ADCalculator.cs +++ b/H.Core/Calculators/Infrastructure/ADCalculator.cs @@ -727,7 +727,7 @@ public List GetDailyFlowRatesForSubstrateTypes( if (type == SubstrateType.ImportedManure) { // Equation 4.8.1-30 - substrateFlow.NitrogenFlowOfSubstrate = substrateViewItemBase.FlowRate * substrateViewItemBase.NitrogenContent; + substrateFlow.NitrogenFlowOfSubstrate = substrateViewItemBase.FlowRate * (substrateViewItemBase.NitrogenContent / 100.0); } // Equation 4.8.1-14 @@ -735,7 +735,7 @@ public List GetDailyFlowRatesForSubstrateTypes( if (type == SubstrateType.ImportedManure) { // Equation 4.8.1-31 - substrateFlow.CarbonFlowOfSubstrate = substrateViewItemBase.FlowRate * substrateViewItemBase.CarbonContent; + substrateFlow.CarbonFlowOfSubstrate = substrateViewItemBase.FlowRate * (substrateViewItemBase.CarbonContent / 100.0); } result.Add(substrateFlow); diff --git a/H.Core/Calculators/Nitrogen/N2OEmissionFactorCalculator.cs b/H.Core/Calculators/Nitrogen/N2OEmissionFactorCalculator.cs index ea43145d..3808e7ba 100644 --- a/H.Core/Calculators/Nitrogen/N2OEmissionFactorCalculator.cs +++ b/H.Core/Calculators/Nitrogen/N2OEmissionFactorCalculator.cs @@ -650,7 +650,5 @@ private double CalculateEmissionFactorUsingPotentialEvapotranspiration(double po } #endregion - - } } \ No newline at end of file diff --git a/H.Core/Models/Animals/AnimalGroup.cs b/H.Core/Models/Animals/AnimalGroup.cs index 57b005ef..7e5b63bc 100644 --- a/H.Core/Models/Animals/AnimalGroup.cs +++ b/H.Core/Models/Animals/AnimalGroup.cs @@ -245,7 +245,6 @@ public int GetNumberOfAnimalsByDate(DateTime dateTime) /// The that contains the given , or null if the doesn't exist public ManagementPeriod GetManagementPeriodByDate(DateTime dateTime) { - var result = this.ManagementPeriods.OrderBy(managementPeriod => managementPeriod.Start).FirstOrDefault(managementPeriod => managementPeriod.Start <= dateTime && managementPeriod.End >= dateTime); if (result != null) { diff --git a/H.Core/Services/Animals/AnimalResultsServiceBase.cs b/H.Core/Services/Animals/AnimalResultsServiceBase.cs index 5466f54e..a325bcc4 100644 --- a/H.Core/Services/Animals/AnimalResultsServiceBase.cs +++ b/H.Core/Services/Animals/AnimalResultsServiceBase.cs @@ -28,13 +28,11 @@ public abstract partial class AnimalResultsServiceBase : IAnimalResultsService private static readonly DietProvider _dietProvider; - protected readonly Table_49_Electricity_Conversion_Defaults_Provider _energyConversionDefaultsProvider = - new Table_49_Electricity_Conversion_Defaults_Provider(); + protected readonly Table_49_Electricity_Conversion_Defaults_Provider _energyConversionDefaultsProvider = new Table_49_Electricity_Conversion_Defaults_Provider(); protected readonly Table_43_Beef_Dairy_Default_Emission_Factors_Provider _defaultEmissionFactorsProvider = new Table_43_Beef_Dairy_Default_Emission_Factors_Provider(); - protected IAdditiveReductionFactorsProvider AdditiveReductionFactorsProvider = - new Table_19_Additive_Reduction_Factors_Provider(); + protected IAdditiveReductionFactorsProvider AdditiveReductionFactorsProvider = new Table_19_Additive_Reduction_Factors_Provider(); protected readonly Table_36_Livestock_Emission_Conversion_Factors_Provider _livestockEmissionConversionFactorsProvider = new Table_36_Livestock_Emission_Conversion_Factors_Provider(); diff --git a/H.Core/Services/Initialization/Crops/CropInitializationService.Yield.cs b/H.Core/Services/Initialization/Crops/CropInitializationService.Yield.cs index 3b94af67..640dc209 100644 --- a/H.Core/Services/Initialization/Crops/CropInitializationService.Yield.cs +++ b/H.Core/Services/Initialization/Crops/CropInitializationService.Yield.cs @@ -181,6 +181,7 @@ public void InitializeSilageCropYield(CropViewItem silageCropViewItem, Farm farm // We call AssignSystemDefaults with the CropViewItem representing the grain crop to get its default values. this.InitializePercentageReturns(farm, grainCropViewItem); + this.InitializeBiomassCoefficients(grainCropViewItem, farm); // We specifically find the PlantCarbonInAgriculturalProduct of the grain crop as that is needed in the yield calculation. grainCropViewItem.PlantCarbonInAgriculturalProduct = _icbmCarbonInputCalculator.CalculatePlantCarbonInAgriculturalProduct(previousYearViewItem: null, currentYearViewItem: grainCropViewItem, farm: farm);