Skip to content
Snippets Groups Projects
Commit 28fa627b authored by Brian Groenke's avatar Brian Groenke
Browse files

Fix function init error on reconstruction

parent cb61b18d
No related branches found
No related tags found
1 merge request!91Fix regression in interact! behavior
......@@ -10,7 +10,7 @@ struct FunctionInitializer{varname,F} <: VarInitializer{varname}
f::F
FunctionInitializer(varname::Symbol, f::F) where {F} = new{varname,F}(f)
end
(init::FunctionInitializer)(args...) = f(args...)
(init::FunctionInitializer)(args...) = init.f(args...)
Base.getindex(init::FunctionInitializer, itrv::Interval) = init
"""
InterpInitializer{varname,P,I,E} <: VarInitializer{varname}
......@@ -44,10 +44,6 @@ function (init::InterpInitializer{var})(state) where var
end
# automatic partitioning of profile based on interval
Base.getindex(init::InterpInitializer{var}, itrv::Interval) where var = InterpInitializer(var, init.profile[itrv], init.interp, init.extrap)
# constructor for constant initializer function
function _constantinit(::Val{varname}, x) where {varname}
return state -> state[varname] .= x
end
"""
initializer(varname::Symbol, x::Number) => FunctionInitializer w/ constant
initializer(varname::Symbol, f::Function) => FunctionInitializer
......@@ -55,6 +51,6 @@ end
Convenience constructor for `VarInitializer` that selects the appropriate initializer type based on the arguments.
"""
initializer(varname::Symbol, x::Number) = FunctionInitializer(varname, _constantinit(Val{varname}(), x))
initializer(varname::Symbol, x::Number) = FunctionInitializer(varname, state -> getproperty(state, varname) .= x)
initializer(varname::Symbol, f::Function) = FunctionInitializer(varname, f)
initializer(varname::Symbol, profile::Profile, interp=Linear(), extrap=Flat()) = InterpInitializer(varname, profile, interp, extrap)
......@@ -20,7 +20,7 @@ struct LayerState{iip,TGrid,TStates,TGrids,Tt,Tdt,Tz,varnames}
end
Base.getindex(state::LayerState, sym::Symbol) = getproperty(state, sym)
function Base.getproperty(state::LayerState, sym::Symbol)
return if sym (:grid, :grids, :states, :t, :z)
return if sym (:grid, :grids, :states, :bounds, :t, :dt, :z)
getfield(state, sym)
else
getproperty(getfield(state, :states), sym)
......@@ -56,7 +56,7 @@ end
Base.getindex(state::TileState, sym::Symbol) = Base.getproperty(state, sym)
Base.getindex(state::TileState, i::Int) = state.states[i]
function Base.getproperty(state::TileState, sym::Symbol)
return if sym (:grid,:states,:t)
return if sym (:grid,:states,:t,:dt)
getfield(state, sym)
else
getproperty(getfield(state, :states), sym)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment