@@ -44,7 +44,7 @@ nothing #hide
44
44
#=
45
45
Now we'll define three specific node types:
46
46
47
- 1. A constant pressure node that forces pressure to maintain a specific value
47
+ **A) A constant pressure node that forces pressure to maintain a specific value**
48
48
=#
49
49
@mtkmodel ConstantPressureNode begin
50
50
@extend GasNode ()
58
58
nothing # hide
59
59
60
60
#=
61
- 2. A static prosumer node which forces a certain flow (pressure is fully implicit)
61
+ **B) A static prosumer node which forces a certain flow (pressure is fully implicit)**
62
62
=#
63
63
@mtkmodel StaticProsumerNode begin
64
64
@extend GasNode ()
72
72
nothing # hide
73
73
74
74
#=
75
- 3. A dynamic prosumer node with compliance, which adds dynamics to the pressure state
75
+ **C) A dynamic prosumer node with compliance, which adds dynamics to the pressure state**
76
76
=#
77
77
@mtkmodel DynamicProsumerNode begin
78
78
@extend GasNode ()
87
87
nothing # hide
88
88
89
89
#=
90
- 4. A pressure control node that tries to maintain a set pressure by adjusting its injection
90
+ **D) A pressure control node that tries to maintain a set pressure by adjusting its injection**
91
91
=#
92
92
@mtkmodel PressureControlNode begin
93
93
@extend GasNode ()
@@ -206,7 +206,7 @@ u_static = find_fixpoint(nw_static, u_static_guess)
206
206
207
207
Now we'll define our dynamic model using more complex components:
208
208
=#
209
- @named v1_mod_dyn = PressureControlNode (;p_set = 1 )
209
+ @named v1_mod_dyn = PressureControlNode ()
210
210
v1_dyn = VertexModel (v1_mod_dyn, [:q̃_nw ], [:p ], vidx= 1 )
211
211
212
212
@named v2_mod_dyn = DynamicProsumerNode (q̃_prosumer= - 0.6 )
@@ -236,37 +236,62 @@ nw_dyn = Network([v1_dyn, v2_dyn, v3_dyn], [p12_dyn, p13_dyn, p23_dyn])
236
236
Now comes the important part: we need to initialize the interface values (pressures and flows)
237
237
of the dynamic model with the results from the static model.
238
238
239
- First, let's handle node 1 (the pressure control node) :
239
+ We can do this manually :
240
240
=#
241
-
241
+ # # Vertex 1: output
242
242
set_default! (nw_dyn[VIndex (1 )], :p , u_static. v[1 , :p ])
243
+ # # Vertex 1: input
243
244
set_default! (nw_dyn[VIndex (1 )], :q̃_nw , u_static. v[1 , :q̃_nw ])
244
- v1_dyn # hide
245
+ nothing # hide
246
+
247
+ #=
248
+ But there is also a built in method [`set_interface_defaults!`](@ref) which we can use
249
+ automaticially:
250
+ =#
251
+ set_interface_defaults! (nw_dyn, u_static; verbose= true )
252
+ nothing # hide
253
+
245
254
#=
246
- In the output, you can see that state ξ is "approx" 1 (guess value) while the rest is fixed.
247
- Now we can initialize the dynamic model's internal states:
255
+ With the interfaces all set, we can "initialize" the internal states of the dynamic models.
256
+
257
+ For example, let's inspect the state of our first vertex:
258
+ =#
259
+ nw_dyn[VIndex (1 )]
260
+
261
+ #=
262
+ We observe, that both the initial state `ξ` as well as the pressure setpoint `p_set`
263
+ is left "free". Using [`initialize_component!`](@ref), we can try to find values for the
264
+ "free" states and parameters such that the interface constraints are fulfilled.
248
265
=#
249
- initialize_component! (v1_dyn)
250
- v1_dyn # hide
266
+ initialize_component! (nw_dyn[VIndex (1 )])
267
+ #=
268
+ We may also use [`dump_initial_state`](@ref) to get a more detailed view of the state:
269
+ =#
270
+ dump_initial_state (nw_dyn[VIndex (1 )])
271
+ nothing # hide
251
272
252
273
#=
253
- For the other two vertices (which are simpler), we just need to set the default values:
274
+ We can also initialize the other two vertices, however it is a bit useless
275
+ since their state is allready completely determined by the fixed input/output:
254
276
=#
255
- set_default ! (nw_dyn[VIndex (2 )], :p , u_static . v[ 2 , :p ])
256
- set_default ! (nw_dyn[VIndex (3 )], :p , u_static . v[ 3 , :p ])
277
+ initialize_component ! (nw_dyn[VIndex (2 )])
278
+ initialize_component ! (nw_dyn[VIndex (3 )])
257
279
nothing # hide
258
280
259
281
#=
260
- For the pipe models, we manually initialize the flow state of the dynamic line model:
282
+ Similarily, we can initialize the dynamic pipe models. However since their dynamic state
283
+ equals the output, once again there is nothing to initialize.
261
284
=#
262
- set_default ! (nw_dyn[EIndex (1 )], :q̃ , u_static . e[ 1 , :q̃ ])
263
- set_default ! (nw_dyn[EIndex (2 )], :q̃ , u_static . e[ 2 , :q̃ ])
264
- set_default ! (nw_dyn[EIndex (3 )], :q̃ , u_static . e[ 3 , :q̃ ])
285
+ initialize_component ! (nw_dyn[EIndex (1 )])
286
+ initialize_component ! (nw_dyn[EIndex (2 )])
287
+ initialize_component ! (nw_dyn[EIndex (3 )])
265
288
nothing # hide
266
289
267
290
#=
268
- Now that we've set all the "default" values for all the states, we can call `NWState` on the
269
- network to get a fully initialized state vector:
291
+ Now, everything is initialized, which means every input, output, state and parameter
292
+ either has a `default` metadata or a `init` metadate. When constructing the `NWState`
293
+ for this network, it will be filled with all those values which should now correspond
294
+ to a steady state of the system:
270
295
=#
271
296
u0_dyn = NWState (nw_dyn)
272
297
0 commit comments