Skip to content

Commit a4e119f

Browse files
committedApr 22, 2022
Add tests
1 parent f78caa9 commit a4e119f

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed
 

Diff for: ‎examples/electrical_components.jl

+38
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,41 @@ function Inductor(; name, L = 1.0)
6666
]
6767
extend(ODESystem(eqs, t, [], ps; name=name), oneport)
6868
end
69+
70+
@connector function HeatPort(;name)
71+
@variables T(t)=293.15 Q_flow(t)=0.0 [connect = Flow]
72+
ODESystem(Equation[], t, [T, Q_flow], [], name=name)
73+
end
74+
75+
function HeatingResistor(;name, R=1.0, TAmbient=293.15, alpha=1.0)
76+
@named p = Pin()
77+
@named n = Pin()
78+
@named h = HeatPort()
79+
@variables v(t) RTherm(t)
80+
@parameters R=R TAmbient=TAmbient alpha=alpha
81+
eqs = [
82+
RTherm ~ R*(1 + alpha*(h.T - TAmbient))
83+
v ~ p.i * RTherm
84+
h.Q_flow ~ -v * p.i # -LossPower
85+
v ~ p.v - n.v
86+
0 ~ p.i + n.i
87+
]
88+
compose(ODESystem(
89+
eqs, t, [v, RTherm], [R, TAmbient, alpha],
90+
name=name,
91+
), p, n, h)
92+
end
93+
94+
function HeatCapacitor(;name, rho=8050, V=1, cp=460, TAmbient=293.15)
95+
@parameters rho=rho V=V cp=cp
96+
C = rho*V*cp
97+
@named h = HeatPort()
98+
D = Differential(t)
99+
eqs = [
100+
D(h.T) ~ h.Q_flow / C
101+
]
102+
compose(ODESystem(
103+
eqs, t, [], [rho, V, cp],
104+
name=name,
105+
), h)
106+
end

Diff for: ‎src/structural_transformation/StructuralTransformations.jl

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export sorted_incidence_matrix, pantelides!, tearing_reassemble, find_solvables!
4545
export tearing_assignments, tearing_substitution
4646
export torn_system_jacobian_sparsity
4747
export full_equations
48+
export but_ordered_incidence, lowest_order_variable_mask, highest_order_variable_mask
4849

4950
include("utils.jl")
5051
include("pantelides.jl")

Diff for: ‎test/components.jl

+19
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,22 @@ end
211211

212212
@named foo = Circuit()
213213
@test structural_simplify(foo) isa ModelingToolkit.AbstractSystem
214+
215+
# BLT tests
216+
V = 2.0
217+
@named source = ConstantVoltage(V=V)
218+
@named ground = Ground()
219+
N = 50
220+
Rs = 10 .^range(0, stop=-4, length=N)
221+
Cs = 10 .^range(-3, stop=0, length=N)
222+
rc_systems = map(1:N) do i
223+
parallel_rc_model(i; name=:rc, source=source, ground=ground, R=Rs[i], C=Cs[i])
224+
end;
225+
@variables E(t)=0.0
226+
eqs = [
227+
D(E) ~ sum(((i, sys),)->getproperty(sys, Symbol(:resistor, i)).h.Q_flow, enumerate(rc_systems))
228+
]
229+
@named _big_rc = ODESystem(eqs, t, [E], [])
230+
@named big_rc = compose(_big_rc, rc_systems)
231+
ts = TearingState(expand_connections(big_rc))
232+
@test istriu(but_ordered_incidence(ts)[1])

0 commit comments

Comments
 (0)
Please sign in to comment.