Hello,
I’m currently modeling a nitrogen hydraulic system, and I have an issue when trying to create an array of components using a for loop.
A simple model (Test_No_List) runs without any problems. However, the model written in an array using a for loop (Test_List) fails to compile. I’m certain the problem lies within the loop syntax, as the rest of the code translates to a Julia file correctly when I remove the Test_List part.
I need to scale this up to 20-30 control volumes (N_CV), so a clean implementation using a for loop is essential. Can anyone see what’s wrong with my code?
(For context, all component definitions are located within the same ‘dyad’ directory.)
Thanks in advance for your help!
# Example in Dyad docs
# https://help.juliahub.com/dyad/dev/manual/syntax.html#syntax-arrays
# Another Example in Dyad docs _ https://help.juliahub.com/dyad/dev/analyses/surrogate.html#Example-Definition
resistors = [Resistor(R=i*10) for i in 1:5] # Array of 5 resistors
[Edit] I changed the code for a direct comparison.
# Works well
component Test_No_List
valve_1 = ConstValve(A = 1.0, C = 0.1)
valve_2 = ConstValve(A = 1.0, C = 0.1)
valve_3 = ConstValve(A = 1.0, C = 0.1)
wall_1 = T_wall_source(T_wall=400.0)
wall_2 = T_wall_source(T_wall=400.0)
R_th_1 = Thermal_R_const(R=100.0)
R_th_2 = Thermal_R_const(R=100.0)
mv_1 = MixingVolume_HeatPort(volume = 1.0e4, p0=1.0e6, T0=500.0)
mv_2 = MixingVolume_HeatPort(volume = 1.0e4, p0=1.0e6, T0=500.0)
boundary = Source_PT(p_fixed=1.0e6, T_fixed=500.0)
cv = ClosedVolume(volume = 1.0e4, p0=1.0e5, T0=400.0)
path medium_data::AbstractMedium = N2
relations
continuity(medium_data, boundary.port.medium)
# Hydraulic connections (src - valve - mv - ... - valve - cv)
connect(boundary.port, valve_1.port_a)
connect(valve_1.port_b, mv_1.port_a)
connect(mv_1.port_b, valve_2.port_a)
connect(valve_2.port_b, mv_2.port_a)
connect(mv_2.port_b, valve_3.port_a)
connect(valve_3.port_b, cv.port)
# Thermal connections (mv - R_th - wall)
connect(mv_1.port_heat, R_th_1.port_a)
connect(R_th_1.port_b, wall_1.port_a)
connect(mv_2.port_heat, R_th_2.port_a)
connect(R_th_2.port_b, wall_2.port_a)
end
# Failed..
component Test_List
structural parameter N::Integer = 2
valves = [ConstValve(A = 1.0, C = 0.1) for i in 1:N+1]
mvs = [MixingVolume_HeatPort(volume = 1.0e4, p0=1.0e6, T0=500.0) for i in 1:N]
walls = [T_wall_source(T_wall=400.0) for i in 1:N]
R_ths = [Thermal_R_const(R=100.0) for i in 1:N]
boundary = Source_PT(p_fixed=1.0e6, T_fixed=500.0)
cv = ClosedVolume(volume = 1.0e4, p0=1.0e5, T0=400.0)
path medium_data::AbstractMedium = N2
relations
continuity(medium_data, boundary.port.medium)
# Hydraulic connections (src - valve - mv - ... - valve - cv)
connect(boundary.port, valves[1].port_a)
for i in 1:N
connect(valves[i].port_b, mvs[i].port_a)
connect(mvs[i].port_b, valves[i+1].port_a)
end
connect(valves[N+1].port_b, cv.port)
# Thermal connections (mv - R_th - wall)
for i in 1:N
connect(mvs[i].port_heat, R_ths[i].port_a)
connect(R_ths[i].port_b, walls[i].port_a)
end
end