In complex simulations, we often need to model systems formed by multiple interacting components, such as tanks connected by pipes, electrical circuits, or coupled mechanical systems. To this end, GPSS-Plus uses the concept of system composition via the COMPOSITOR.
What does the composition do?
The composition allows for merging multiple individual DYNAMICs into a single dynamic system. This merger is performed by connecting their variables according to a common node scheme and solving all internal equations simultaneously.
Structure of a composite system
Let's look at a practical example: three tanks connected by two pipes, where the central tank has two inlets. The layout would be:
TANK1 --- PIPE12 --- TANK2 --- PIPE23 --- TANK3
This system is defined as follows:
INITIAL LIQUID_SYSTEM, {
COMPONENTS: ["pipe12", "pipe23", "tank1", "tank2", "tank3"],
CONNECTIONS: [
{ NODE: "n1", CONNECTIONS: ["tank1.A","pipe12.A"] },
{ NODE: "n2", CONNECTIONS: ["pipe12.B", "tank2.A"] },
{ NODE: "n3", CONNECTIONS: ["pipe23.A", "tank2.B"] },
{ NODE: "n4", CONNECTIONS: ["pipe23.B", "tank3.A"] }
]
}
Each NODE indicates a physical connection point between one or more components. Each NODE is assigned a shared effort variable (such as pressure or voltage), and each component contributes its own internal and flow equations.
Defining the components
Pipe (PIPE):
INITIAL PIPE_CONFIG, {
EFFORTS: {
A: { NAME: "PressureA", UNIT: "Pa" },
B: { NAME: "PressureB", UNIT: "Pa" }
},
ROLES: {
QA: { ROLE: "FLOW", EXPOSED: ["A"] },
QB: { ROLE: "FLOW", EXPOSED: ["B"] },
K: { ROLE: "CONST" }
},
EXPRESSIONS: [
"QA + K * (PressureA - PressureB)", ; Flow from A to B
"QA + QB" ; Internal flow conservation
]
}
Each and every variable appearing in EXPRESSIONS must be clearly defined in one of the two groups.
- EFFORT: A: { NAME: "PressureA", UNIT: "Pa" } : Defines which effort variables will be equalized with other components connected at the same node. For example, a tank will have a pressure at that node, which will be equalized with all pressures at that same node. The unit must be specified to ensure compatibility. In this case, Pascals (Pa).
- ROLES: QA: { ROLE: "FLOW", EXPOSED: ["A"] }: Defines the
ROLEassigned to the rest of the system variables.- FLOW: Flow variables moving inside each component and the port where they are exposed.
FLOWcan be exposed at one port (a single mesh) or two (creating two distinct meshes and a conservation equation). - CONST: System constant with a numerical value.
- STATE: Variable required to be calculated by the system.
- FLOW: Flow variables moving inside each component and the port where they are exposed.
Two-port tank:
INITIAL TANK_2_PORTS_CONFIG, {"EFFORTS": {
"A": { "NAME": "PressureA", "UNIT": "Pa" },
"B": { "NAME": "PressureB", "UNIT": "Pa" }
},
"ROLES": {
"PressureA_PREV": { "ROLE": "const", "UNIT": "Pa" },
"IN1": { "ROLE": "flow", "EXPOSED": ["A"] },
"IN2": { "ROLE": "flow", "EXPOSED": ["B"] }
},
"EXPRESSIONS": [
"PressureA - PressureA_PREV - (IN1 + IN2) * DT", ; Mass/volume conservation
"PressureA - PressureB" ; Same pressure at both ports
]
}
Final system composition
After declaring components and connections, it is simply used in the COMMAND:
DYNAMIC {name:sys, compositor:V$LIQUID_SYSTEM, X:712, Y:54}
This DYNAMIC automatically generates all necessary equations by combining:
-
Effort variables shared per node.
-
Flow variables connected per port.
-
Conservation rules (mass, energy, etc.).
The result visible in the debug area would be:
EXPRESSIONS: 1: FLOW_1 + PIPE12_K * (PA_N1 - PA_N2) 2: FLOW_1 + FLOW_2 3: FLOW_3 + PIPE23_K * (PA_N3 - PA_N4) 4: FLOW_3 + FLOW_4 5: PA_N1 - TANK1_PRESSURE_PREV - FLOW_1 * DT 6: PA_N2 - TANK2_PRESSUREA_PREV - (FLOW_2 + FLOW_3) * DT 7: PA_N2 - PA_N3 8: PA_N4 - TANK3_PRESSURE_PREV - FLOW_4 * DT
Where we see that effort variables have been equalized with one for each node and flow variables have been numbered by mesh.
Final observations
-
Each component can be easily reused with different values.
-
It is possible to build complete component libraries (
.lib) and combine them to build complex models without rewriting expressions. -
The system automatically handles previous values (_PREV), unified names, and internal meshes.
Example
/*
By components: COMPOSITOR
*/
SYSTEM {TYPE:PRE_RUN,TRIGGER:PRE_RUN}
SYSTEM {type:OPTIONS, TIME_DECIMALS:2, SPEED:5}
PLOTTER {NAME:pressures, Y_0:tank1, Y_1:tank2, Y_2:tank3, X:TIME_AC1}
PLOTTER {NAME:flow, Y_0:flow, X:TIME_AC1}
Graphic {NAME:tText,Type:TEXT,X:376,Y:579,Text:"tText"} ; Text: battery level
include ./library_componets_liquid/liquid.lib
INITIAL PIPE12_VALUES, { K: 0.1 }
INITIAL PIPE23_VALUES, { K: 0.1 }
INITIAL TANK1_VALUES, { Presion_PREV: 10 }
INITIAL TANK2_VALUES, { PresionA_PREV: 0 }
INITIAL TANK3_VALUES, { Presion_PREV: 3 }
DYNAMIC {name:tank1, config:V$TANK_CONFIG, VALUES:V$TANK1_VALUES, X:113, Y:491}
DYNAMIC {name:tank2, config:V$TANK_2_PORTS_CONFIG, VALUES:V$TANK2_VALUES, X:396, Y:389}
DYNAMIC {name:tank3, config:V$TANK_CONFIG, VALUES:V$TANK3_VALUES, X:696, Y:342}
DYNAMIC {name:pipe12, config:V$PIPE_CONFIG, VALUES:V$PIPE12_VALUES, X:189, Y:333}
DYNAMIC {name:pipe23, config:V$PIPE_CONFIG, VALUES:V$PIPE23_VALUES, X:603, Y:512}
INITIAL LIQUID_SYSTEM, {
COMPONENTS: ["pipe12", "pipe23", "tank1", "tank2", "tank3"],
CONNECTIONS: [
{ NODE: "n1", CONNECTIONS: ["tank1.A","pipe12.A"] },
{ NODE: "n2", CONNECTIONS: ["pipe12.B", "tank2.A"] },
{ NODE: "n3", CONNECTIONS: ["pipe23.A", "tank2.B"] },
{ NODE: "n4", CONNECTIONS: ["pipe23.B", "tank3.A"] }
]
}
DYNAMIC {name:sys, compositor:V$LIQUID_SYSTEM, X:712, Y:54}
START 1000
include ./library_graphics/tank.lib
;==============================================================
PROCEDURE agent.init
timeout change_tank,2
advance 0.1
while (1==1)
SOLVE { name:"sys", DT: 0.01, SAVEVALUE: "result"}
SAVEVALUE TANK1_PRESSURE, X$(result.tank1_Presion)
SAVEVALUE TANK2_PRESSURE, X$(result.tank2_PresionA)
SAVEVALUE TANK3_PRESSURE, X$(result.tank3_Presion)
SAVEVALUE PIPE12, X$(result.pipe12_QA)
SAVEVALUE PIPE23, X$(result.pipe23_QA)
PLOT pressures, X$TANK1_PRESSURE, X$TANK2_PRESSURE, X$TANK3_PRESSURE
PLOT flow, X$PIPE_FLOW
assign rFlow12,round(X$PIPE12,3)
assign rFlow23,round(X$PIPE23,3)
assign rH1,round(X$TANK1_PRESSURE,3)
assign rH2,round(X$TANK2_PRESSURE,3)
assign rH3,round(X$TANK3_PRESSURE,3)
move {name:tText, text:"AC1$ flows: P$rFlow12 ----- P$rFlow23 "}
CALL tank1.tank.set, P$rH1
CALL tank2.tank.set, P$rH2
CALL tank3.tank.set, P$rH3
IF (ABS(X$PIPE_FLOW) < 0.001)
;stop
ENDIF
advance 0.01,0
endwhile
stop
ENDPROCEDURE
;====================================================================
PROCEDURE PRE_RUN
CALL create_tanks
TIMEOUT agent.init,0
TERMINATE_VE
ENDPROCEDURE
;=================================================
PROCEDURE create_tanks
assign config,{title:"TANK 1"
,x:100,y:50
,width:50 ,height:180
,value:0
,max_value:10
,"color":"#ff0000"}
timeout tank1.tank.init,0,V$config
assign config,{title:"TANK 2"
,x:300,y:50
,width:50 ,height:180
,value:0
,max_value:10
,"color":"#ff0000"}
timeout tank2.tank.init,0,V$config
assign config,{title:"TANK 3"
,x:500,y:50
,width:50 ,height:180
,value:0
,max_value:10
,"color":"#ff0000"}
timeout tank3.tank.init,0,V$config
ENDPROCEDURE
;=================================================
PROCEDURE change_tank
assign newParams,{tank3_Presion_PREV:10}
dynamic_set sys,V$newParams
TERMINATE_VE
ENDPROCEDURE