Hi guys,
I am new to Julia and am using ModelingToolkit to try to build a simple heat conduction model (3R2C wall model).
So it will look like this…
I am trying to create a constant ambient temperature then switch that to a hourly weather data. However, I cannot even finish my first step, that is connect the left-resistor to the ambient.
In my code, I am using a heat port, and this is how I try to connect it, which didn’t report any fault but just do nothing to the whole system
@named Resistor_conv_o = ThermalResistor(R = R_conv_o)
@named T_weather = HeatPort(T = 273.15 + 20)
connect(Resistor_conv_o.port_a, T_weather)
I would really appreciate someone’s help!
After figuring this out, I also would like to ask for some insight of how can I switch the constant ambient temeprature data linked with a series of weather data (file/array…). I used to have something like this in my own model:
hour_index = Int(floor(t) % 24 + 1) # in hourly resolution
T_out = T_out_hourly[hour_index]
Many thanks!
See the full code of the 3R2C model as below:
using ModelingToolkit
using ModelingToolkitStandardLibrary.Thermal, ModelingToolkit, OrdinaryDiffEq, Plots
@parameters t
A = 20.0 #wall area
h = 1.0 #Convective coefficient
C_wall_out = 20000
C_wall_in = 20000
C_zone = 70000
R_conv_o = 1/(R*A)
R_conv_i = 1/(R*A)
R_wall = 0.13
#TempConstant = 20
# Capacitors
@named Capacitor_wall_out = HeatCapacitor(C = C_wall_out, T = 273.15 + 20)
@named Capacitor_wall_in = HeatCapacitor(C = C_wall_in, T = 273.15 + 50)
@named Capacitor_zone = HeatCapacitor(C = C_zone, T = 273.15 + 50)
# Resistors
@named Resistor_conv_o = ThermalResistor(R = R_conv_o)
@named Resistor_conv_i = ThermalResistor(R = R_conv_i)
@named Resistor_wall = ThermalResistor(R = R_wall)
# Heat port aka temperature source
@named T_weather = HeatPort(T = 273.15 + -200)
# Temeprature sensors
@named T_wall_out = TemperatureSensor()
@named T_wall_in = TemperatureSensor()
@named T_zone = TemperatureSensor()
connections = [
connect(Resistor_conv_o.port_a, T_weather),
connect(Resistor_conv_o.port_b, Capacitor_wall_out.port, Resistor_wall.port_a, T_wall_out.port),
connect(Resistor_wall.port_b, Capacitor_wall_in.port, Resistor_conv_i.port_a, T_wall_in.port),
connect(Resistor_conv_i.port_b, Capacitor_zone.port, T_zone.port),
]
@named model = ODESystem(connections, t,
systems = [Capacitor_wall_out, Capacitor_wall_in, Capacitor_zone, Resistor_conv_o,Resistor_conv_i, Resistor_wall, T_weather, T_wall_out, T_wall_in, T_zone])
sys = structural_simplify(model)
prob = ODEProblem(sys, Pair[], (0, 3600))
sol = solve(prob, Tsit5())
Plot1 = plot(title = "Thermal Conduction Case")
Plot1 = plot!(sol, idxs = [Capacitor_wall_out.T, Capacitor_wall_in.T, Capacitor_zone.T].-273.15, labels = ["Wall out" "Wall in" "Zone"])
display(Plot1)