Skip to content

Commit e9dc864

Browse files
committed
Undefined Reference Error
See test/Hydraulic/debugging.jl Ben Chung guided me to adding a continuous_events function that seems to have bug.
1 parent 15bf96b commit e9dc864

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

test/Hydraulic/debugging.jl

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using ModelingToolkit, OrdinaryDiffEq, Test
2+
using ModelingToolkit: t_nounits as t, D_nounits as D
3+
import ModelingToolkitStandardLibrary.Hydraulic.IsothermalCompressible as IC
4+
import ModelingToolkitStandardLibrary.Blocks as B
5+
import ModelingToolkitStandardLibrary.Mechanical.Translational as T
6+
7+
using ModelingToolkitStandardLibrary.Blocks: Parameter
8+
9+
@component function Step(;
10+
name, height = 1.0, offset = 0.0, start_time = 0.0, duration = Inf,
11+
smooth = 1e-5)
12+
@named output = B.RealOutput()
13+
duration_numeric = duration
14+
pars = @parameters offset=offset start_time=start_time height=height duration=duration step_val(t) :: Bool = true
15+
equation = if smooth == false # use comparison in case smooth is a float
16+
offset +
17+
ifelse((step_val) & (t < start_time + duration), height, zero(height))
18+
# ifelse((start_time <= t) & (t < start_time + duration), height, zero(height))
19+
else
20+
smooth === true && (smooth = 1e-5)
21+
if duration_numeric == Inf
22+
smooth_step(t, smooth, height, offset, start_time)
23+
else
24+
smooth_step(t, smooth, height, offset, start_time) -
25+
smooth_step(t, smooth, height, zero(start_time), start_time + duration)
26+
end
27+
end
28+
29+
eqs = [
30+
output.u ~ equation
31+
]
32+
33+
compose(ODESystem(eqs, t, [], pars; name = name, continuous_events = [[t ~ start_time, t ~ start_time + duration] => ((i,u,p,c) -> i.ps[p.step_val]=false, [], [step_val], [step_val], nothing)]), [output])
34+
35+
end
36+
37+
#@testset "Fluid Domain and Tube" begin
38+
function System(N; bulk_modulus, name)
39+
pars = @parameters begin
40+
bulk_modulus = bulk_modulus
41+
end
42+
43+
systems = @named begin
44+
fluid = IC.HydraulicFluid(; bulk_modulus)
45+
stp = Step(; height = 2*101325, offset = 101325, start_time = 0.05, duration = Inf,
46+
smooth = false)
47+
src = IC.Pressure(;)
48+
vol = IC.FixedVolume(; vol = 10.0)
49+
res = IC.Tube(N; area = 0.01, length = 50.0)
50+
end
51+
52+
eqs = [connect(stp.output, src.p)
53+
connect(fluid, src.port)
54+
connect(src.port, res.port_a)
55+
connect(res.port_b, vol.port)]
56+
57+
ODESystem(eqs, t, [], pars; name, systems)
58+
end
59+
60+
@named sys5_1 = System(2; bulk_modulus = 1e9)
61+
62+
sys5_1 = structural_simplify(sys5_1)
63+
64+
initialization_eqs = [sys5_1.vol.port.p ~ 101325,sys5_1.res.p1.port_a.dm ~ 0]
65+
initsys5_1 = ModelingToolkit.generate_initializesystem(sys5_1;initialization_eqs)
66+
67+
initsys5_1 = structural_simplify(initsys5_1)
68+
initprob5_1 = NonlinearProblem(initsys5_1, [t=>0])
69+
initsol5_1 = solve(initprob5_1)
70+
71+
prob5_1 = ODEProblem(sys5_1, [], (0, 50); initialization_eqs)
72+
sol5_1 = solve(prob5_1) # ERROR: UndefRefError: access to undefined reference

test/Hydraulic/isothermal_compressible.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ NEWTON = NLNewton(check_div = false, always_new = true, max_iter = 100, relax =
2828
connect(src.port, res.port_a)
2929
connect(res.port_b, vol.port)]
3030

31-
ODESystem(eqs, t, [], pars; name, systems)
31+
ODESystem(eqs, t, [], pars; name, systems)
3232
end
3333

3434
@named sys1_2 = System(1; bulk_modulus = 2e9)

0 commit comments

Comments
 (0)