APSIMInitiative / ApsimX

ApsimX is the next generation of APSIM
http://www.apsim.info
Other
136 stars 164 forks source link

Maintenance respiration in excess of daily assimilation is not accounted for in DM balance #3243

Closed BrianCollinss closed 5 years ago

BrianCollinss commented 5 years ago

Wheat.zip

In this specific experiment from Wheat validation dataset, in which CanopyPhotosynthesis is used as the Photosynthesis model instead of the default RUE model, I get this error towards the end of the season:

NaN (not a number) found when getting variable: [Leaf].Live.Wt

System.Exception: ERROR in file: C:\Users\uqbababa\UQ\04_Analyses\(2018.10.31) ApsimNG Validation\Wheat\Test.apsimx
Simulation name: APS2TOS2
NaN (not a number) found when getting variable: [Leaf].Live.Wt ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Exception: NaN (not a number) found when getting variable: [Leaf].Live.Wt
   at Models.Functions.VariableReference.Value(Int32 arrayIndex) in C:\Users\uqbababa\UQ\07_Repository\ApsimNextGen\ApsimX\Models\Functions\Variable.cs:line 46
   at Models.Functions.DivideFunction.Value(Int32 arrayIndex) in C:\Users\uqbababa\UQ\07_Repository\ApsimNextGen\ApsimX\Models\Functions\DivideFunction.cs:line 30
   at Models.Functions.MultiplyFunction.Value(Int32 arrayIndex) in C:\Users\uqbababa\UQ\07_Repository\ApsimNextGen\ApsimX\Models\Functions\MultiplyFunction.cs:line 29
   at Models.PMF.Organs.ReproductiveOrgan.OnDoActualPlantGrowth(Object sender, EventArgs e) in C:\Users\uqbababa\UQ\07_Repository\ApsimNextGen\ApsimX\Models\Plant\Organs\ReproductiveOrgan.cs:line 354
   at System.EventHandler.Invoke(Object sender, EventArgs e)
   at Models.Clock.OnDoCommence(Object sender, CommenceArgs e) in C:\Users\uqbababa\UQ\07_Repository\ApsimNextGen\ApsimX\Models\Clock.cs:line 280
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at Models.Core.Events.Subscriber.Invoke(Object[] args) in C:\Users\uqbababa\UQ\07_Repository\ApsimNextGen\ApsimX\Models\Core\Events.cs:line 176
   at Models.Core.Events.Publish(String eventName, Object[] args) in C:\Users\uqbababa\UQ\07_Repository\ApsimNextGen\ApsimX\Models\Core\Events.cs:line 121
   at Models.Core.Runners.RunSimulation.Run(CancellationTokenSource cancelToken) in C:\Users\uqbababa\UQ\07_Repository\ApsimNextGen\ApsimX\Models\Core\Runners\RunSimulation.cs:line 121
   --- End of inner exception stack trace ---
   at Models.Core.Runners.RunSimulation.Run(CancellationTokenSource cancelToken) in C:\Users\uqbababa\UQ\07_Repository\ApsimNextGen\ApsimX\Models\Core\Runners\RunSimulation.cs:line 136
   at APSIM.Shared.Utilities.JobRunnerAsync.<>c__DisplayClass10_0.<JobRunnerThread>b__0() in C:\Users\uqbababa\UQ\07_Repository\ApsimNextGen\APSIM.Shared\Utilities\JobRunnerAsync.cs:line 98

I tried to fix this by making sure maintenance respiration was not assigned to organs with zero metabolic and storage dry matter. But that would lead to another error telling me that mass balance was not met (in Leaf, line 1664). I don't get the same error when I use the default RUE model for photosynthesis since there is no maintenance respiration explicitly accounted for in the RUE model.

In OrganArbitrator, the method SubtractMaintenanceRespiration determines maintenance respiration of all organs. If respiration is more than daily assimilation, for example when VPD is too high, part of maintenance respiration is assigned to organs and deducted from live storage and metabolic DMs. However, in Leaf (the only organ that seems to check the DM balance!), this amount is not accounted for when the DM balance of the day is checked at the end of the method SetDryMatterAllocation.

In my branch, I added a line to check how much DM is lost at the end of the day and that exactly amounted to the maintenance respiration of the leaves. The maintenance respiration IS deducted from the leaf DM, but it is not accounted for when the daily balance of DM is calculated, which results in an Exception. Maybe we should just get rid of that DM-balance part. It doesn't exist in other organs.

2 image

BrianCollinss commented 5 years ago

@hol353 Hi Dean. By any chance, is there anyone I can mention and share this with to double check? These growth conditions rarely occur and as the RUE model is mostly used, this problem may have been neglected. I worked on it over the weekend and might have fixed it in my new commit. Just need a second pair of eyes. Thanks for reading this anyway.

hol353 commented 5 years ago

@HamishBrownPFR can you comment on this?