I am looking to create a system which allows me to share input parameters, which as a consequence allows me to keep my system parameter space small. I give an MTK example from the standard library but I am also happy to go in and change components explicitly if needed. Here we see a parallel RC circuit in which both the resistors and capacitors are symetrc so depend on a single R and C.
using ModelingToolkit, OrdinaryDiffEq, Plots
using ModelingToolkitStandardLibrary.Electrical
using ModelingToolkitStandardLibrary.Blocks: Constant
R = 1.0
C = 1.0
V = 1.0
@variables t
@named resistor1 = Resistor(R = R)
@named resistor2 = Resistor(R = R)
@named capacitor1 = Capacitor(C = C, v = 0.0)
@named capacitor2 = Capacitor(C = C, v = 0.0)
@named source = Voltage()
@named constant = Constant(k = V)
@named ground = Ground()
rc_eqs = [connect(constant.output, source.V)
connect(source.p, resistor1.p, resistor2.p)
connect(resistor1.n, capacitor1.p)
connect(resistor2.n, capacitor2.p)
connect(capacitor2.n, capacitor1.n, source.n, ground.g)]
@named rc_model = ODESystem(rc_eqs, t,
systems = [resistor1, capacitor1, resistor2, capacitor2, constant, source, ground])
sys = structural_simplify(rc_model)
prob = ODAEProblem(sys, Pair[], (0, 10.0))
sol = solve(prob, Tsit5())
plot(sol, idxs = [capacitor.v, resistor.i],
title = "RC Circuit Demonstration",
labels = ["Capacitor Voltage" "Resistor Current"])
If I then run parameters(sys)
julia> parameters(sys)
5-element Vector{SymbolicUtils.BasicSymbolic{Real}}:
resistor1₊R
capacitor1₊C
resistor2₊R
capacitor2₊C
constant₊k
Here I am looking to have just one parameter for the resistance and one for the capacitance.
Is there a way in which I can use the R of resistor1 and feed this to resistor 2 as a constant? Such that if I made any changes to R this would carry through to both resistances and likewise for the capacitance?
I could collapse this circuit using basic theory however there will be some applications where the model topology is relevant and each component does need an individual parameter so I am looking for something as general as possible if I can.
Thanks,
Harry