@@ -10,17 +10,21 @@ Caps a hydraulic port to prevent mass flow in or out.
10
10
# Connectors:
11
11
- `port`: hydraulic port
12
12
"""
13
- @component function Cap (; name)
14
- vars = @variables p (t), [guess = 0 ]
13
+ @mtkmodel Cap begin
15
14
16
- systems = @named begin
15
+ @variables begin
16
+ p (t), [guess = 0 ]
17
+ end
18
+
19
+ @components begin
17
20
port = HydraulicPort ()
18
21
end
19
22
20
- eqs = [port. p ~ p
21
- port. dm ~ 0 ]
23
+ @equations begin
24
+ port. p ~ p
25
+ port. dm ~ 0
26
+ end
22
27
23
- ODESystem (eqs, t, vars, []; name, systems)
24
28
end
25
29
26
30
"""
@@ -34,22 +38,22 @@ Provides an "open" boundary condition for a hydraulic port such that mass flow `
34
38
# Connectors:
35
39
- `port`: hydraulic port
36
40
"""
37
- @component function Open (; name)
38
- pars = []
41
+ @mtkmodel Open begin
39
42
40
- vars = @variables begin
43
+ @variables begin
41
44
p (t), [guess = 0 ]
42
45
dm (t), [guess = 0 ]
43
46
end
44
47
45
- systems = @named begin
48
+ @components begin
46
49
port = HydraulicPort ()
47
50
end
48
51
49
- eqs = [port. p ~ p
50
- port. dm ~ dm]
52
+ @equations begin
53
+ port. p ~ p
54
+ port. dm ~ dm
55
+ end
51
56
52
- ODESystem (eqs, t, vars, pars; name, systems)
53
57
end
54
58
55
59
"""
@@ -238,33 +242,33 @@ Reduces the flow from `port_a` to `port_b` by `n`. Useful for modeling parallel
238
242
- `port_a`: full flow hydraulic port
239
243
- `port_b`: part flow hydraulic port
240
244
"""
241
- @component function FlowDivider (; n, name)
245
+ @mtkmodel FlowDivider begin
242
246
243
247
# TODO : assert n >= 1
244
248
245
- pars = @parameters begin
249
+ @parameters begin
246
250
n = n
247
251
end
248
252
249
- vars = @variables begin
253
+ @variables begin
250
254
dm_a (t), [guess = 0 ]
251
255
dm_b (t), [guess = 0 ]
252
256
end
253
257
254
- systems = @named begin
258
+ @components begin
255
259
port_a = HydraulicPort ()
256
260
port_b = HydraulicPort ()
257
261
open = Open ()
258
262
end
259
263
260
- eqs = [connect (port_a, port_b, open. port)
261
- dm_a ~ port_a. dm
262
- dm_b ~ dm_a / n
263
- open. dm ~ dm_a - dm_b # extra flow dumps into an open port
264
- # port_b.dm ~ dm_b # divided flow goes to port_b
265
- ]
264
+ @equations begin
265
+ connect (port_a, port_b, open. port)
266
+ dm_a ~ port_a. dm
267
+ dm_b ~ dm_a / n
268
+ open. dm ~ dm_a - dm_b # extra flow dumps into an open port
269
+ # port_b.dm ~ dm_b # divided flow goes to port_b
270
+ end
266
271
267
- ODESystem (eqs, t, vars, pars; name, systems)
268
272
end
269
273
270
274
@component function ValveBase (
@@ -357,36 +361,38 @@ Valve with `area` input and discharge coefficient `Cd` defined by https://en.wik
357
361
ODESystem (eqs, t, vars, pars; name, systems)
358
362
end
359
363
360
- @component function VolumeBase (; area, dead_volume = 0 , Χ1 = 1 , Χ2 = 1 ,
361
- name)
362
- pars = @parameters begin
363
- area = area
364
- dead_volume = dead_volume
364
+ @mtkmodel VolumeBase begin
365
+
366
+ @structural_parameters begin
367
+ Χ1 = 1
368
+ Χ2 = 1
365
369
end
366
370
367
- systems = @named begin
371
+ @parameters begin
372
+ area
373
+ dead_volume
374
+ end
375
+
376
+ @components begin
368
377
port = HydraulicPort ()
369
378
end
370
379
371
- vars = @variables begin
380
+ @variables begin
372
381
x (t)
373
382
dx (t), [guess = 0 ]
374
383
rho (t), [guess = liquid_density (port)]
375
384
drho (t), [guess = 0 ]
376
385
vol (t)
377
386
end
378
387
379
- # let
380
- dm = port. dm
381
- p = port. p
382
-
383
- eqs = [vol ~ dead_volume + area * x
384
- D (x) ~ dx
385
- D (rho) ~ drho
386
- rho ~ full_density (port, p)
387
- dm ~ drho * vol * Χ1 + rho * area * dx * Χ2]
388
+ @equations begin
389
+ vol ~ dead_volume + area * x
390
+ D (x) ~ dx
391
+ D (rho) ~ drho
392
+ rho ~ full_density (port, port. p)
393
+ port. dm ~ drho * vol * Χ1 + rho * area * dx * Χ2
394
+ end
388
395
389
- ODESystem (eqs, t, vars, pars; name, systems)
390
396
end
391
397
392
398
"""
@@ -400,33 +406,31 @@ Fixed fluid volume.
400
406
# Connectors:
401
407
- `port`: hydraulic port
402
408
"""
403
- @component function FixedVolume (; vol, name)
404
- pars = @parameters begin
405
- vol = vol
409
+ @mtkmodel FixedVolume begin
410
+
411
+ @parameters begin
412
+ vol
406
413
end
407
414
408
- systems = @named begin
415
+ @components begin
409
416
port = HydraulicPort (;)
410
417
end
411
418
412
- vars = @variables begin
419
+ @variables begin
413
420
rho (t), [guess = liquid_density (port)]
414
421
drho (t), [guess = 0 ]
415
422
end
416
423
417
- # let
418
- dm = port. dm
419
- p = port. p
420
-
421
- eqs = [D (rho) ~ drho
422
- rho ~ full_density (port, p)
423
- dm ~ drho * vol]
424
+ @equations begin
425
+ D (rho) ~ drho
426
+ rho ~ full_density (port, port. p)
427
+ port. dm ~ drho * vol
428
+ end
424
429
425
- ODESystem (eqs, t, vars, pars; name, systems)
426
430
end
427
431
428
432
"""
429
- Volume(; x, dx=0, p, drho=0, dm=0, area, direction = + 1, name)
433
+ Volume(; x, dx=0, p, drho=0, dm=0, area, direction = 1, name)
430
434
431
435
Volume with moving wall with `flange` connector for converting hydraulic energy to 1D mechanical. The `direction` argument aligns the mechanical port with the hydraulic port, useful when connecting two dynamic volumes together in oppsing directions to create an actuator.
432
436
@@ -463,16 +467,17 @@ dm ────► │ │ area
463
467
464
468
See also [`FixedVolume`](@ref), [`DynamicVolume`](@ref)
465
469
"""
466
- @component function Volume (;
470
+ @mtkmodel Volume begin
467
471
468
- # parameters
469
- area,
470
- direction = + 1 , name)
471
- pars = @parameters begin
472
- area = area
472
+ @structural_parameters begin
473
+ direction = 1
473
474
end
474
475
475
- vars = @variables begin
476
+ @parameters begin
477
+ area
478
+ end
479
+
480
+ @variables begin
476
481
x (t)
477
482
dx (t)
478
483
p (t)
@@ -482,32 +487,36 @@ See also [`FixedVolume`](@ref), [`DynamicVolume`](@ref)
482
487
dm (t)
483
488
end
484
489
485
- systems = @named begin
490
+ @components begin
486
491
port = HydraulicPort ()
487
492
flange = MechanicalPort ()
488
493
end
489
494
490
- eqs = [
491
- # connectors
492
- port. p ~ p
493
- port. dm ~ dm
494
- flange. v * direction ~ dx
495
- flange. f * direction ~ - f
495
+ @equations begin
496
+ # connectors
497
+ port. p ~ p
498
+ port. dm ~ dm
499
+ flange. v * direction ~ dx
500
+ flange. f * direction ~ - f
496
501
497
- # differentials
498
- D (x) ~ dx
499
- D (rho) ~ drho
502
+ # differentials
503
+ D (x) ~ dx
504
+ D (rho) ~ drho
500
505
501
- # physics
502
- rho ~ liquid_density (port, p)
503
- f ~ p * area
504
- dm ~ drho * x * area + rho * dx * area]
506
+ # physics
507
+ rho ~ liquid_density (port, p)
508
+ f ~ p * area
509
+ dm ~ drho * x * area + rho * dx * area
510
+ end
511
+
512
+ @defaults begin
513
+ rho => liquid_density (port)
514
+ end
505
515
506
- ODESystem (eqs, t, vars, pars; name, systems, defaults = [rho => liquid_density (port)])
507
516
end
508
517
509
518
"""
510
- DynamicVolume(N, add_inertia=true; p_int, area, x_int = 0, x_max, x_min = 0, x_damp = x_min, direction = +1, perimeter = 2 * sqrt(area * pi), shape_factor = 64, head_factor = 1, Cd = 1e2, Cd_reverse = Cd, name)
519
+ DynamicVolume(N, add_inertia=true, reversible=false; area, x_int = 0, x_max, x_min = 0, x_damp = x_min, direction = +1, perimeter = 2 * sqrt(area * pi), shape_factor = 64, head_factor = 1, Cd = 1e2, Cd_reverse = Cd, name)
511
520
512
521
Volume with moving wall with `flange` connector for converting hydraulic energy to 1D mechanical. The `direction` argument aligns the mechanical port with the hydraulic port, useful when connecting two dynamic volumes together in oppsing directions to create an actuator.
513
522
0 commit comments