APSIMInitiative / ApsimX

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

Problem with thermalConductivity[airNode] in SoilTemperature #9404

Open hol353 opened 3 weeks ago

hol353 commented 3 weeks ago

What happened?

The attached scrum simulation throws an exception:

ERROR in file: C:\Work\Repos\APSIMInitiative\ApsimX\Prototypes\SCRUM\SCRUM.apsimx
Simulation name: SCRUMRotationComponent
Models.Core.SimulationException
 ---> System.Exception: newTemps(1) = 100.13956532272108 is outside range of -50 to 100
   at Models.Soils.SoilTemp.SoilTemperature.boundCheck(Double VariableValue, Double Lower, Double Upper, String VariableName) in C:\Work\Repos\APSIMInitiative\ApsimX\Models\Soils\SoilTemp\SoilTemperature.cs:line 1532
   at Models.Soils.SoilTemp.SoilTemperature.doThomas(Double[]& newTemps) in C:\Work\Repos\APSIMInitiative\ApsimX\Models\Soils\SoilTemp\SoilTemperature.cs:line 1199
   at Models.Soils.SoilTemp.SoilTemperature.doProcess() in C:\Work\Repos\APSIMInitiative\ApsimX\Models\Soils\SoilTemp\SoilTemperature.cs:line 1018
   at Models.Soils.SoilTemp.SoilTemperature.OnProcess(Object sender, EventArgs e) in C:\Work\Repos\APSIMInitiative\ApsimX\Models\Soils\SoilTemp\SoilTemperature.cs:line 737
   at Models.Clock.OnDoCommence(Object _, CommenceArgs e) in C:\Work\Repos\APSIMInitiative\ApsimX\Models\Clock.cs:line 373
   at Models.Core.Simulation.Run(CancellationTokenSource cancelToken) in C:\Work\Repos\APSIMInitiative\ApsimX\Models\Core\Simulation.cs:line 298
   --- End of inner exception stack trace ---
   at Models.Core.Simulation.Run(CancellationTokenSource cancelToken) in C:\Work\Repos\APSIMInitiative\ApsimX\Models\Core\Simulation.cs:line 307
   at Models.Core.Run.SimulationDescription.Run(CancellationTokenSource cancelToken) in C:\Work\Repos\APSIMInitiative\ApsimX\Models\Core\Run\SimulationDescription.cs:line 136
   at APSIM.Shared.JobRunning.JobRunner.Run(IRunnable job) in C:\Work\Repos\APSIMInitiative\ApsimX\APSIM.Shared\JobRunning\JobRunner.cs:line 226
   at APSIM.Shared.JobRunning.JobRunner.RunActualJob(IRunnable job, IJobManager jobManager) in C:\Work\Repos\APSIMInitiative\ApsimX\APSIM.Shared\JobRunning\JobRunner.cs:line 189

I think this is caused by a negative value of thermalConductivity[airNode] calculated on line 1015:

thermalConductivity[airNode] = getBoundaryLayerConductance(ref newTemperature);

To help with debugging, I inserted the following if statement to into line 1326:

            if (clock.Today == new DateTime(1966, 5, 8))
            {

            }

This let me put a breakpoint inside the if statement and I could then debug line by line in getBoundaryLayerConductance.

At the bottom of getBoundaryLayerConductance, if I comment out the unstable conditions else statement, it runs without error:

                else
                {
                    // Unstable conditions, when surface temperature is higher than air temperature, sensible heat flux in the
                    // boundary layer is positive and stability parameter is negative.
                    //stabilityCorrectionHeat = -2.0 * Math.Log((1.0 + Math.Sqrt(1.0 - 16.0 * stabilityParammeter)) / 2.0);    // Eqn 12.16
                    //stabilityCorrectionMomentum = 0.6 * stabilityCorrectionHeat;                // Eqn 12.17
                }

SCRUM.zip

What Operating System are you on?

Windows

hol353 commented 5 days ago

There are still problem with some simulations failing.