Component Libraries

Updated: 2026-05-30

What is a library?

A library is a set of predefined components with their configurations and mathematical behaviors ready to use. In the case of GPSS-Plus components, it is limited to storing the CONFIG for each element. For example:

initial PIPE_CONFIG, {
  TYPE: "PIPE",
  EXPRESSIONS: [ "FLOW + K * (PRESSURE_A - PRESSURE_B)" ],
  STATES: ["FLOW"],
  VARIABLES: ["K"],
  OWNED_VARS: { A: ["FLOW"], B: ["-FLOW"] },
  REQUIRED_VARS: { A: ["PRESSURE_A"], B: ["PRESSURE_B"] }
}

We only need to perform an INCLUDE of the file containing it:

include ./library_componets_liquid/liquid.lib

And we use those configs as if we had written them in the main code.

initial pipe1_data, { K: 0.1 }
dynamic { name: pipe1, config: V$PIPE_CONFIG, values: V$pipe1_data, x: 100, y: 300 }

initial tank1_data, { PRESSURE_PREV: 10 }
dynamic { name: tank1, config: V$TANK_CONFIG, values: V$tank1_data, x: 50, y: 400 }

initial tank2_data, { PRESSURE_PREV: 5 }
dynamic { name: tank2, config: V$TANK_CONFIG, values: V$tank2_data, x: 200, y: 400 }

Advantages of using libraries

  • Reuse and standardization.

  • Error reduction.

  • Faster modeling with higher quality.

 

Example

SYSTEM {TYPE:PRE_RUN,TRIGGER:PRE_RUN}
SYSTEM {type:OPTIONS, TIME_DECIMALS:3, SPEED:1,pause:0}     

PLOTTER {NAME:movement, Y_0:tank1,  Y_1:tank2,  X:TIME_AC1}   
Graphic {NAME:tText,Type:TEXT,X:327,Y:486,Text:"tText"} 


include ./library_componets_liquid/liquid.lib

INITIAL pipe1_DATA, { K: 0.1 }
DYNAMIC {name:pipe1,config:V$pipe_CONFIG,VALUES:V$pipe1_DATA,X:373,Y:418}

INITIAL tank1_DATA, { PRESSURE_PREV: 10 }
DYNAMIC {name:tank1,config:V$tank_CONFIG,VALUES:V$tank1_DATA,X:123,Y:357}

INITIAL tank2_DATA, { PRESSURE_PREV: 1 }
DYNAMIC {name:tank2,config:V$tank_CONFIG,VALUES:V$tank2_DATA,X:624,Y:347}

initial COMPOSITOR, {
   COMPONENTS: [ "pipe1","tank1","tank2"],
   CONNECTIONS: [ "TANK1.A=PIPE1.A", "TANK2.A=PIPE1.B"]
   }

DYNAMIC {name:sys,compositor:V$COMPOSITOR,X:347,Y:164}


START 1

include ./library_graphics/tank.lib

;==============================================================

PROCEDURE agent.init

timeout change_tank,100
timeout change_tank2,200
    
while (1==1)


SOLVE {  name:"sys",  DT: 0.1,  SAVEVALUE: "result"}



SAVEVALUE TANK1_PRESSURE, X$(result.TANK1_PRESION)
SAVEVALUE TANK2_PRESSURE, X$(result.TANK2_PRESION)
SAVEVALUE PIPE1_FLOW,  X$(result.PIPE1_FLUJO)

PLOT movement, X$TANK1_PRESSURE, X$TANK2_PRESSURE

	assign rFlow,round(X$PIPE_FLOW,5)
	assign rH1,round(X$TANK1_PRESSURE,5)
	assign rH2,round(X$TANK2_PRESSURE,5)
    
    move {name:tText, text:"flow:\n P$rFlow Tot: P$rH1 P$rH2 "}

	CALL tank1.tank.set, X$TANK1_PRESSURE
	CALL tank2.tank.set, X$TANK2_PRESSURE


    IF (ABS(X$PIPE1_FLOW) < 0.001)
        stop
    ENDIF

advance 1,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:100 
            ,width:50 ,height:180
            ,value:X$TANK1_PRESSURE
            ,max_value:10
            ,"color":"#ff0000"}
            
	call tank1.tank.init,V$config

	assign config,{title:"TANK 2"
		,x:500,y:100 
            ,width:50 ,height:180
            ,value:X$TANK2_PRESSURE
            ,max_value:10
            ,"color":"#ff0000"}
            
	call tank2.tank.init,V$config
	
ENDPROCEDURE

;=================================================

PROCEDURE change_tank
    assign newParams,{PIPE1_K:0.3}
    dynamic_set sys,V$newParams
    TERMINATE_VE
ENDPROCEDURE

PROCEDURE change_tank2
    assign newParams,{TANK2_PRESION_PREV:10}
    dynamic_set sys,V$newParams
    TERMINATE_VE
ENDPROCEDURE