Skip to content

Commit

Permalink
Merge pull request #58 from HamishBrownPFR/CropStageTests
Browse files Browse the repository at this point in the history
Fix error in fert schedulling when fertiliser event falls on a day with losses
  • Loading branch information
HamishBrownPFR authored Jun 13, 2024
2 parents d1275c1 + 1c36faf commit 7eac960
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
6 changes: 3 additions & 3 deletions SVSModel/Models/Fertiliser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static void RemainingFertiliserSchedule(DateTime startSchedulleDate,DateT
for (int passes = 0; passes < 50; passes++)
{
double lastPassLossEst = losses;
double remainingReqN = remainingRequirement(d, endScheduleDate, thisSim, trigger) + losses;
double remainingReqN = remainingRequirement(d, endScheduleDate, thisSim, initialN) + losses;
NAppn = remainingReqN / remainingSplits;
SoilNitrogen.UpdateBalance(d, NAppn, initialN, initialLossEst, ref thisSim, true, new Dictionary<DateTime, double>(),true);
losses = anticipatedLosses(d, endScheduleDate, thisSim.NLost);
Expand All @@ -90,12 +90,12 @@ public static void RemainingFertiliserSchedule(DateTime startSchedulleDate,DateT
}
}

private static double remainingRequirement(DateTime startDate, DateTime endDate, SimulationType thisSim, double trigger)
private static double remainingRequirement(DateTime startDate, DateTime endDate, SimulationType thisSim, double initialN)
{
double remainingCropN = thisSim.CropN[endDate] - thisSim.CropN[startDate];
DateTime[] remainingDates = Functions.DateSeries(startDate, endDate);
double remainingOrgN = remainingMineralisation(remainingDates, thisSim.NResidues, thisSim.NSoilOM);
double surplussMineralN = Math.Max(0, trigger - Constants.Trigger);
double surplussMineralN = Math.Max(0, initialN - Constants.Trigger);
return Math.Max(0, remainingCropN - remainingOrgN - surplussMineralN);
}

Expand Down
5 changes: 0 additions & 5 deletions SVSModel/Simulation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@ public class Simulation
//Do initial nitorgen balance with no fertiliser or resets
SoilNitrogen.UpdateBalance(config.StartDate, initialN, 0, 0, ref thisSim, false, nAapplied, ScheduleFert);

//Add fertiliser that has already been applied to the N balance
//DateTime StartApplicationDate = config.StartDate;
//DateTime StartSchedullingDate = Fertiliser.startSchedullingDate(nAapplied, testResults, config);
//Fertiliser.ApplyExistingFertiliser(StartApplicationDate, StartSchedullingDate, nAapplied, ref thisSim);

//Reset soil N with test valaues
SoilNitrogen.TestCorrection(testResults, ref thisSim);

Expand Down

0 comments on commit 7eac960

Please sign in to comment.