Using Replace! to Replace a Component in FUND

I built a new ‘climatedynamics’ component in Jupyter notebook for FUND with a 2-box ocean model adjusted to match climate modes. The component runs without error. The first few lines are;
@defcomp climatedynamics begin
# 2-box climate model
radforc = Parameter(index=[time])
temp = Variable(index=[time])
tempocean = Variable(index=[time])
deeplayer = Parameter()
climatesensitivity = Parameter()
function run_timestep(p, v, d, t)
heatcapdeep = 0.7 * deeplayer * 4180000.0

The next cell is:
replace!(m, :climatedynamics => climatedynamics)

That ran without errors and gave an output of 5760 words!
The next cell is:
set_param!(m, :climatesensitivity, 1.5)
set_param!(m, :deeplayer, 1200)
run(m)
The response was:
UndefVarError: deeplayer not defined

Stacktrace:
[1] run_timestep_Main_climatedynamics(::Mimi.ComponentInstanceParameters{NamedTuple{(:radforc, :deeplayer, :climatesensitivity),Tuple{Mimi.TimestepArray{Mimi.FixedTimestep{1950,1,LAST} where LAST,Union{Missing, Float64},1,1},Mimi.ScalarModelParameter{Float64},Mimi.ScalarModelParameter{Float64}}}}, ::Mimi.ComponentInstanceVariables{NamedTuple{(:temp, :tempocean),Tuple{Mimi.TimestepArray{Mimi.FixedTimestep{1950,1,LAST} where LAST,Union{Missing, Float64},1,1},Mimi.TimestepArray{Mimi.FixedTimestep{1950,1,LAST} where LAST,Union{Missing, Float64},1,1}}}}, ::Mimi.DimValueDict, ::Mimi.FixedTimestep{1950,1,3000}) at C:\Users\Ken.julia\packages\Mimi\mHt54\src\core\defcomp.jl:21
[2] run_timestep(::Mimi.LeafComponentInstance{Mimi.ComponentInstanceVariables{NamedTuple{(:temp, :tempocean),Tuple{Mimi.TimestepArray{Mimi.FixedTimestep{1950,1,LAST} where LAST,Union{Missing, Float64},1,1},Mimi.TimestepArray{Mimi.FixedTimestep{1950,1,LAST} where LAST,Union{Missing, Float64},1,1}}}},Mimi.ComponentInstanceParameters{NamedTuple{(:radforc, :deeplayer, :climatesensitivity),Tuple{Mimi.TimestepArray{Mimi.FixedTimestep{1950,1,LAST} where LAST,Union{Missing, Float64},1,1},Mimi.ScalarModelParameter{Float64},Mimi.ScalarModelParameter{Float64}}}}}, ::Mimi.Clock{Mimi.FixedTimestep}, ::Mimi.DimValueDict) at C:\Users\Ken.julia\packages\Mimi\mHt54\src\core\instances.jl:277
[3] run_timestep(::Mimi.ModelInstance, ::Mimi.Clock{Mimi.FixedTimestep}, ::Mimi.DimValueDict) at C:\Users\Ken.julia\packages\Mimi\mHt54\src\core\instances.jl:286

Can you see why this doesn’t work?

At first glance I think you need to refer to the deeplayer parameter within your component as p.deeplayer to indicate that you are referring to a parameter defined in the component defcomp macro?

Also if the output of the replace! call is frustrating for you, you can put a semicolon after the call to suppress the output. The text block that is output is because replace! returns an object and that text describes the object, but we can also look at shortening the text if that seems to be longer than desired.

replace!(m, :climatedynamics => climatedynamics);

Thanks. The component now runs correctly.