Open BrianCollinss opened 4 months ago
Hey @par456. This feels like a Science bug.
I am still seeing that issue, did you happen to change anything in the file?
One clue is that it almost always happens during "Maturing" phase.
I added the same check that exists in the Leaf class to the end of the SetNitrogenAllocation of the SimpleLeaf class:
public virtual void SetNitrogenAllocation(BiomassAllocationType nitrogen)
{
double StartN = Live.StructuralN + Live.MetabolicN + Live.StorageN;
Live.StructuralN += nitrogen.Structural;
Live.StorageN += nitrogen.Storage;
Live.MetabolicN += nitrogen.Metabolic;
Allocated.StructuralN += nitrogen.Structural;
Allocated.StorageN += nitrogen.Storage;
Allocated.MetabolicN += nitrogen.Metabolic;
// Retranslocation
if (MathUtilities.IsGreaterThan(nitrogen.Retranslocation, startLive.StorageN + startLive.MetabolicN - nitrogen.Reallocation))
throw new Exception("N retranslocation exceeds storage + metabolic nitrogen in organ: " + Name);
double storageNRetranslocation = Math.Min(nitrogen.Retranslocation, startLive.StorageN * (1 - senescenceRate.Value()) * nRetranslocationFactor.Value());
Live.StorageN -= storageNRetranslocation;
Live.MetabolicN -= (nitrogen.Retranslocation - storageNRetranslocation);
Allocated.StorageN -= nitrogen.Retranslocation;
// Reallocation
if (MathUtilities.IsGreaterThan(nitrogen.Reallocation, startLive.StorageN + startLive.MetabolicN))
throw new Exception("N reallocation exceeds storage + metabolic nitrogen in organ: " + Name);
double storageNReallocation = Math.Min(nitrogen.Reallocation, startLive.StorageN * senescenceRate.Value() * nReallocationFactor.Value());
Live.StorageN -= storageNReallocation;
Live.MetabolicN -= (nitrogen.Reallocation - storageNReallocation);
Allocated.StorageN -= nitrogen.Reallocation;
double endN = Live.StructuralN + Live.MetabolicN + Live.StorageN;
double checkValue = StartN + nitrogen.Structural + nitrogen.Metabolic + nitrogen.Storage -
nitrogen.Reallocation - nitrogen.Retranslocation - nitrogen.Respired;
double extentOfError = Math.Abs(endN - checkValue);
if (extentOfError > 0.00000001)
throw new Exception(Name + "Some Leaf N was not allocated.");
}
When I remove the other two checks (the lines after // Retranslocation and // Reallocation), I expect the new check to catch the same error, but it does not. So, either this check (that exists in Leaf class as well) doesn't do what is supposed to do, or something else is wrong in the way Reallocation is calculated.
Hey, @hol353. Do you think this is an issue that might exist in the Leaf class as well? I tried to trace the issue but failed. Do you think the model must calculate the C/N flow components correctly in all growth conditions?
BTW, I think these two currently existing checks in SimpleLeaf are placed in the code too late. They must be placed when the calculation of nitrogen.Reallocation is done.
I've been running in to this issue as well. CroptimizR seems very adept at finding parameter combinations that will run afoul of these two checks. Very small changes can cause the exception to be thrown, too (e.g. a day length of 13 will not be fine, but 13.00001 or 12.99999 will be fine with ControlledEnvironment).
I also deleted the two checks in a local copy which allowed CroptimizR to finish. Interestingly, the optimized values do not cause the exception to be thrown with the checks back in place. Nothing major seemed to break upon removing the checks, but I am not familiar enough with the arbitrator to know for sure.
What crop are you working with?
This is with Soybean, which uses the SimpleLeaf Model.
I've also been getting this message with Soybean when trying to calibrate. "N retranslocation exceeds storage + metabolic nitrogen in organ: Leaf" Could it be some values are going out of bounds during optimization and are not captured and dealt with in the code? Has anyone solved this?
I'm seeing similar in sorghumleaf and am trying to sort out some very convoluted code that gets it there. The conditions are "Exhausted N and plant about to die".
I'm unsure why it doesn't happen when I replaced the mass balance tests with those from Leaf. See my PR.
What happened?
Example.zip
What Operating System are you on?
Windows