LWFBrook90 simulation question

Hi I am using LWFBrook 90 v1.9 to simulate the hydro-dynamics. These are the scripts I am using:

using LWFBrook90

model1 = loadSPAC(input_path, input_prefix; simulate_isotopes = false);
simulation = setup(model1)

Here are the data I am using. Julia - Google Drive

However, I have this error.

ERROR: AssertionError: Problem with simulation: Return code of simulation was ‘MaxIters’
Stacktrace: [1] simulate!(s::DiscretizedSPAC; assert_retcode::Bool, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})

I am thinking to increase the Maxiters, but I don’t know how to use:

solve(simulation, maxiters = 1e7, progress = true)

Could anyone help me? Thanks in advance!

Hi there! It looks like the simulate! docstring (type ?simulate!) mentions that keywords to simulate! get forwarded to solve, so simulate!(simulation; maxiters = 1e7) should work.

simulate!(s::DiscretizedSPAC; kwargs...)

Simulates a SPAC model and stores the solution in s.ODESolution.

  kwargs... are passed through to solve(SciML::ODEProblem; ...) and are documented under

I tried to run your example, I haven’t used LWFBrook90 before, so perhaps @fabern should chime in, but here are some observations:


Hi there.

Thank you for your question and thanks @visr for solving the programming aspect of the problem.

Indeed you can pass options into simulate!() and they will be passed through to the call to solve() from DifferentialEquations.jl. The package LWFBrook90.jl basically works as a wrapper around DifferentialEquations.jl. The possibility to change the default options can be needed for some more “difficult” simulations. Some ranges of the soil parameters can make the problem much harder to solve.

However, as @visr pointed out correctly: That many iterations are not always expected. The issue you see is probably rather linked with your model specifications. I noticed some very small \alpha values in your input parameters. Have you double-checked the units of all the Mualem-van Genuchten parameters (in your soil_horizons.csv)?

Note that the parameter \alpha (alpha) is expected in units of m-1. The example simulation DAV-2020 uses \alpha values on the order of 20 m-1. Puhlmann and von Wilpert (2012)* report mean values for different forest soil types for alpha ranging from 0.030 to 0.181 hPa-1, i.e. from 0.30 to 1.8 kPa-1 or from 2.9 to 17.6 m-1 (with 9.81 kPa/m).

If I modify the \alpha in your simulations the solution works. It will be best to correct your input data in soil_horizons.csv. Alternatively, the code below overwrites the loaded values with remakeSPAC().

Let me know if that helps.

using LWFBrook90

# Read in input data
input_path = "."; input_prefix = "real-full";
model = loadSPAC(input_path, input_prefix; simulate_isotopes = false);

# Setup and run simulation
simulation          = setup(model)
# simulate!(simulation) 
# would run for ~40 hours and gives maxiters warning

simulation2 = remakeSPAC(model, 
    soil_horizons = (; alpha_per_m = [12.00007,12.000085,12.0001]))
simulate!(simulation2) # works

using Plots, Measures; gr();

* Puhlmann, H. and Wilpert, K. von: Pedotransfer functions for water retention and unsaturated hydraulic conductivity of forest soils, J. Plant Nutr. Soil Sci., 175, 221–235, https://doi.org/10.1002/jpln.201100139, 2012.

1 Like

Wow Thanks for the reply from you and @visr ! It works now!

I would also like to ask one question of the example in LWFBrook90 (Tell me if I should post another one). I had this errorr in the line with discretize(). ERROR: MethodError: no method matching discretize(::SPAC; tspan::Tuple{Int64, Int64}). I tried to use two other functions: DiscretizedSPAC or SPAC(), but still had the similar problem. Is it becuase of the problem of the version?

using LWFBrook90
input_prefix = “isoBEA2010-18-reset-FALSE”
input_path = “examples/“input_prefix”-input/”
model = loadSPAC(input_path, input_prefix; simulate_isotopes = true)
simulation = setup(model) # this works
simulation = LWFBrook90.discretize(model; tspan = (0,100)) # the followings not work
simulation = LWFBrook90.(model)
simulation = LWFBrook90.SPAC(model; tspan = (0,100));

Thank you!

Glad to hear that!

And sorry about the issue with the example. That page in the documentation was not updated and the example code still referred to an older version that used different commands. I have just modified the documentation and removed this page (it will only be updated soon).

The commands have changed in the past and are now: loadSPAC(), setup(), and simulate!().
Please refer to the example shown on below page, that should be current: Example-01 (autogenerated) · LWFBrook90.jl
Or use the help-function by typing ?loadSPAC to show the function documentation.

Note that, I try to change these user-facing functions as little as possible from a version to another. If they do change, this should be reflected in the version number by a MAJOR increase (e.g. 0.9 → 0.10 following https://semver.org).

1 Like

Hi Fabern
Thanks for the answere. Now I am clear about the examples.

Also, I want to mention that I could only use


to run the script in the website (The following one would have error)

using LWFBrook90;run_example()

Hi Fabern,
I am also using the same code as Joy,

I tried to run the code
model1 = loadSPAC(input_path, inputh_prefix; simulate_isotopes = false)
model1 = loadSPAC(input_path, inputh_prefix; simulate_isotopes = true)

but I keep getting this error

ERROR: thread = 1 error parsing DateTime around row = 1, col = 1: “1/1/2019,”, error=INVALID: OK | DELIMITED | INVALID_DELIMITER

can you please help?

Hi Phebe,
I haven’t seen your question here previously. But you posted it also on my github. For anybody seeing this later, Phebe’s question is answered here: Error parsing Dates.DateTime · Issue #77 · fabern/LWFBrook90.jl · GitHub

Thank you Fabern.