APSIMInitiative / ApsimX

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

InitialWater cannot be linked to in scrips #4141

Closed BrianCollinss closed 5 years ago

BrianCollinss commented 5 years ago

I used to be able to use [Link] InitialWater InitialWater; in my scripts which would give me the ability to change initial soil moisture (e.g. InitialWater.FractionFull = 0.5;) and then reset soil moisture on sowing to that level. After recent updates, I cannot add a link to the InitialWater object in the Soil model.

System.Exception: ERROR in file: C:\Users\uqbababa\UQ\00_Projects\2018.12.10 Analysis of Impact of Limited Transpiration on TE at 60 Sites\02_Simulations\Test\Badgingarra.apsimx Simulation name: Simulation System.Exception: Cannot find a match for link InitialWater in model .Simulation.Field.ResetWaterOnSowing.Script at Models.Core.Links.ResolveInternal(Object obj, ScopingRules scope) in C:\Users\uqbababa\UQ\07_Repository\ApsimNextGen\ApsimX\Models\Core\Links.cs:line 179 at Models.Core.Links.Resolve(IModel rootNode, Boolean allLinks, Boolean recurse) in C:\Users\uqbababa\UQ\07_Repository\ApsimNextGen\ApsimX\Models\Core\Links.cs:line 50 at Models.Core.Simulation.Run(CancellationTokenSource cancelToken) in C:\Users\uqbababa\UQ\07_Repository\ApsimNextGen\ApsimX\Models\Core\Simulation.cs:line 231 ---> System.Exception: Cannot find a match for link InitialWater in model .Simulation.Field.ResetWaterOnSowing.Script at Models.Core.Links.ResolveInternal(Object obj, ScopingRules scope) in C:\Users\uqbababa\UQ\07_Repository\ApsimNextGen\ApsimX\Models\Core\Links.cs:line 179 at Models.Core.Links.Resolve(IModel rootNode, Boolean allLinks, Boolean recurse) in C:\Users\uqbababa\UQ\07_Repository\ApsimNextGen\ApsimX\Models\Core\Links.cs:line 50 at Models.Core.Simulation.Run(CancellationTokenSource cancelToken) in C:\Users\uqbababa\UQ\07_Repository\ApsimNextGen\ApsimX\Models\Core\Simulation.cs:line 231 --- End of inner exception stack trace --- at Models.Core.Simulation.Run(CancellationTokenSource cancelToken) in C:\Users\uqbababa\UQ\07_Repository\ApsimNextGen\ApsimX\Models\Core\Simulation.cs:line 249 at Models.Core.Run.SimulationDescription.Run(CancellationTokenSource cancelToken) in C:\Users\uqbababa\UQ\07_Repository\ApsimNextGen\ApsimX\Models\Core\Run\SimulationDescription.cs:line 95 at APSIM.Shared.JobRunning.JobRunner.RunActualJob(IRunnable job, IJobManager jobManager) in C:\Users\uqbababa\UQ\07_Repository\ApsimNextGen\ApsimX\APSIM.Shared\JobRunning\JobRunner.cs:line 149

hol430 commented 5 years ago

@hol353 is currently working on a major refactor/restructure of the soil infrastructure. As part of this, the InitialWater node is removed from the simulations tree when the simulation is run. The initial SW content is calculated and stored in a model of type sample. So if you link to a sample, you should have access to this value.

[Link] private Sample sample;
...
sample.SW = x;
...
BrianCollinss commented 5 years ago

Thanks @hol430. A question regarding the email you had sent about APSIM.Shared. Should I now remove the APSIM.Shared folder? How about configuration? I see that APSIM.Shared is still built before debugging APSIMX.

image

BrianCollinss commented 5 years ago

And regarding Sample, SW is an array. Previously we could set FractionFull which in turn would automatically change initial SW of the whole profile. Is there any similar state variable in the new structure?

hol430 commented 5 years ago

You don't have to change anything in visual studio - I've made the necessary changes there. The only thing I changed was the location of APSIM.Shared. If you look inside your ApsimX directory, you will notice there is now a subdirectory called APSIM.Shared. This previously lived as a sibling directory to ApsimX.

E.g. you might have previously had this:

C:\ApsimX (required) C;\APSIM.Shared (required)

Now you might have this:

C:\ApsimX\APSIM.Shared (required) C:\APSIM.Shared (not required - can be deleted).

So if you want to delete the old APSIM.Shared, just open up windows explorer and delete it (it's a sibling directory to ApsimX). You shouldn't need to change anything in visual studio.

And regarding Sample, SW is an array. Previously we could set FractionFull which in turn would automatically change initial SW of the whole profile. Is there any similar state variable in the new structure?

As far as I know, there is no equivalent of FractionFull in the Sample model. If it helps, I think you might still be able to override FractionFull from a factor in an experiment.

@hol353 what is the use case here? Is there any way to change initial water on a fractional basis from a manager script?

hol430 commented 5 years ago

@hol353 - in case you missed this one - what is the use case here? Is there any way to change initial water on a fractional basis from a manager script?

hol353 commented 5 years ago

Currently you have to [Link] to a Sample and then set the SW values for each layer manually.