4545# 1516
4646let
4747 @connector function Fluid_port (; name, p = 101325.0 , m = 0.0 , T = 293.15 )
48- sts = @variables p (t)= p m (t)= m [ connect = Flow] T (t)= T [ connect = Stream]
48+ sts = @variables p (t) [guess = p] m (t) [guess = m, connect = Flow] T (t) [guess = T, connect = Stream]
4949 ODESystem (Equation[], t, sts, []; name = name)
5050 end
51-
51+
5252 # this one is for latter
5353 @connector function Heat_port (; name, Q = 0.0 , T = 293.15 )
54- sts = @variables T (t)= T Q (t)= Q [ connect = Flow]
54+ sts = @variables T (t) [guess = T] Q (t) [guess = Q, connect = Flow]
5555 ODESystem (Equation[], t, sts, []; name = name)
5656 end
57-
57+
5858 # like ground but for fluid systems (fluid_port.m is expected to be zero in closed loop)
5959 function Compensator (; name, p = 101325.0 , T_back = 273.15 )
6060 @named fluid_port = Fluid_port ()
6363 fluid_port. T ~ T_back]
6464 compose (ODESystem (eqs, t, [], ps; name = name), fluid_port)
6565 end
66-
66+
6767 function Source (; name, delta_p = 100 , T_feed = 293.15 )
6868 @named supply_port = Fluid_port () # expected to feed connected pipe -> m<0
6969 @named return_port = Fluid_port () # expected to receive from connected pipe -> m>0
7474 return_port. T ~ T_feed]
7575 compose (ODESystem (eqs, t, [], ps; name = name), [supply_port, return_port])
7676 end
77-
77+
7878 function Substation (; name, T_return = 343.15 )
7979 @named supply_port = Fluid_port () # expected to receive from connected pipe -> m>0
8080 @named return_port = Fluid_port () # expected to feed connected pipe -> m<0
8585 return_port. T ~ T_return]
8686 compose (ODESystem (eqs, t, [], ps; name = name), [supply_port, return_port])
8787 end
88-
88+
8989 function Pipe (; name, L = 1000 , d = 0.1 , N = 100 , rho = 1000 , f = 1 )
9090 @named fluid_port_a = Fluid_port ()
9191 @named fluid_port_b = Fluid_port ()
9292 ps = @parameters L= L d= d rho= rho f= f N= N
93- sts = @variables v (t)= 0.0 dp_z (t)= 0.0
93+ sts = @variables v (t) [guess = 0.0 ] dp_z (t) [guess = 0.0 ]
9494 eqs = [fluid_port_a. m ~ - fluid_port_b. m
9595 fluid_port_a. T ~ instream (fluid_port_a. T)
9696 fluid_port_b. T ~ fluid_port_a. T
@@ -114,18 +114,18 @@ let
114114 connect (return_pipe. fluid_port_a, source. return_port)]
115115 compose (ODESystem (eqs, t, [], ps; name = name), subs)
116116 end
117-
117+
118118 @named system = System (L = 10 )
119119 @unpack supply_pipe, return_pipe = system
120120 sys = structural_simplify (system)
121121 u0 = [
122122 system. supply_pipe. v => 0.1 , system. return_pipe. v => 0.1 , D (supply_pipe. v) => 0.0 ,
123123 D (return_pipe. fluid_port_a. m) => 0.0 ,
124124 D (supply_pipe. fluid_port_a. m) => 0.0 ]
125- prob1 = ODEProblem (sys, u0 , (0.0 , 10.0 ), [])
126- prob2 = ODEProblem (sys, u0 , (0.0 , 10.0 ), [])
125+ prob1 = ODEProblem (sys, [] , (0.0 , 10.0 ), [], guesses = u0 )
126+ prob2 = ODEProblem (sys, [] , (0.0 , 10.0 ), [], guesses = u0 )
127127 prob3 = DAEProblem (sys, D .(unknowns (sys)) .=> 0.0 , u0, (0.0 , 10.0 ), [])
128- @test solve (prob1, FBDF ()). retcode == ReturnCode. Success
128+ @test solve (prob1, FBDF ()). retcode == ReturnCode. Success
129129 # @test solve(prob2, FBDF()).retcode == ReturnCode.Success
130130 @test solve (prob3, DFBDF ()). retcode == ReturnCode. Success
131131end
0 commit comments