Constraints
Constraint Templates
Constraint templates help simplify data wrangling across multiple Gas Flow formulations by providing an abstraction layer between the network data and network constraint definitions. The constraint template's job is to extract the required parameters from a given network data structure and pass the data as named arguments to the Gas Flow formulations.
These templates should be defined over AbstractGasModel
and should not refer to model variables. For more details, see the files: core/constraint_template.jl
and core/constraint.jl
.
Junction Constraints
Flow balance constraints
The primary constraints related to junctions ensure that mass flow is balanced at these nodes. The specifics of the constraint implementation will change if there are network design options (denoted by \_ne
in the name of the function).
GasModels.constraint_mass_flow_balance
— FunctionConstraint: standard flow balance equation where demand and production are variables
Template: Constraints for mass flow balance equation where demand and production is are a mix of constants and variables
Constraint: standard flow balance equation where demand and production are variables
GasModels.constraint_mass_flow_balance_ne
— FunctionConstraint: standard flow balance equation where demand and production are variables and there are expansion connections
Template: Constraints for mass flow balance equation where demand and production is are a mix of constants and variables and there are expansion connections
Constraint: standard flow balance equation where demand and production are variables and there are expansion connections
Direction On/off Constraints
The disjunctive forms of problems (where directions are controlled by on/off variables) include special (redundant) constraints which tie the direction variables together. Examples include ensuring that ensure at least one edge of junction that has only sources of natural gas has outgoing flow.
GasModels.constraint_source_flow
— FunctionConstraint: Make sure there is at least one direction set to take flow away from a junction (typically used on source nodes)
Template: Constraints for ensuring that at least one direction is set to take flow away from a junction (typically used on source nodes)
GasModels.constraint_sink_flow
— FunctionConstraint: Make sure there is at least one direction set to take flow to a junction (typically used on sink nodes)
Template: Constraints for ensuring that at least one direction is set to take flow away from a junction (typically used on sink nodes)
GasModels.constraint_conserve_flow
— FunctionConstraint: This constraint is intended to ensure that flow is one direction through a node with degree 2 and no production or consumption
Template: Constraints to ensure that flow is the same direction through a node with degree 2 and no production or consumption
GasModels.constraint_source_flow_ne
— FunctionConstraint: Make sure there is at least one direction set to take flow away from a junction (typically used on source nodes)
Template: Constraints for ensuring that at least one direction is set to take flow away from a junction (typically used on source nodes)
GasModels.constraint_sink_flow_ne
— FunctionConstraint: Make sure there is at least one direction set to take flow to a junction (typically used on sink nodes)
Template: Constraints for ensuring that at least one direction is set to take flow away from a junction (typically used on sink nodes)
GasModels.constraint_conserve_flow_ne
— FunctionConstraint: This constraint is intended to ensure that flow is on direction through a node with degree 2 and no production or consumption for a node with expansion edges
Template: Constraints to ensure that flow is the same direction through a node with degree 2 and no production or consumption
Pipe Constraints
Weymouth's law constraints
The primary constraints related to pipes ensure that that pressure drop and flow across a pipe is related through the Weymouth relationships. Here, the naming convention ne
is used to denote the form of the constraint used for expansion pipes.
GasModels.constraint_pipe_weymouth
— FunctionTemplate: Weymouth equation for defining the relationship between pressure drop and flow across a pipe
Constraint: Weymouth equation–not applicable for LRDWP models
Constraint: Weymouth equation–not applicable for LRWP models
Weymouth equation with absolute value
Weymouth equation with discrete direction variables
Constraint 1:
This constraint should be active when flow goes from i to j. Pressure needs to decrease from i to j. y = 1 models this condition When y = 1, this constraint becomes w(pi - pj) >= f^2, which is only true when pi >= pj When y = 0, we have w(pi - pj) >= f^2 - fmin^2 + w*pdmin. By definition, w(pi - pj) <= 0. The lower bound on w(pi - pj) is w*pdmin. Since flow is reversed in this situation, f^2 is bounded by fmin^2. Thus f^2 - f_min^2 only further decreases the rhs. Thus, this constraint is always true (inactive when y = 0)
Constraint 2:
When y = 1, w(pi - pj) >= 0 this constraint needs to be active, so should be upper bounded by f^2 to get equality when combined with weymouth1
When y = 0, w(pi - pj) <= 0, making this constraint always true (inactive when y = 0)
Constraint 3:
This constraint should be active when flow goes from j to i. Pressure needs to decrease from j to i. y = 0 models this condition
When y = 0, this constraint becomes w*(pj - pi) >= f^2, which is only true when pj >= pi
When y = 1, we have w(pj - pi) >= f^2 - f_max^2 - wpd_max. By definition, w(pj - pi) <= 0. The lower bound on w(pi - pj) is
-w*pdmax (sign flip on pi amnd pj). Since flow is forward in this situation, f^2 is bounded by fmax^2. Thus f^2 - f_max^2 only further decreases the rhs.
Thus, this constraint is always true (inactive when y = 1)
Constraint 4:
When y = 0, w(pj - pi) >= 0 this constraint needs to be active, so should be upper bounded by f^2 to get equality when combined with weymouth3
When y = 1, w(pj - pi) <= 0, making this constraint always true (inactive when y = 1)
note the sign flip between pi and pj
Weymouth equation for a pipe
GasModels.constraint_pipe_weymouth_ne
— FunctionTemplate: Weymouth equation for expansion pipes
Constraint: Weymouth equation
Constraint: Weymouth equation
Weymouth equation for an expansion pipe
Weymouth equation for an expansion pipe
Constraint 1:
When zp = 1, this constraint reduces to constraint weymouth1 in constraintpipeweymouth, which is what we want (i.e. an active constraint) When zp = 0, we want this constraint to be in active AND any y value should be valid. In this case, since f^2 = 0 (there is no flow) the constraint becomes w(pi - pj) >= -(1-y) * (f_min^2 - wpdmin) - abs(w*pdmin). When y = 1, we have w(pi - pj) >= -abs(wpdmin). Since pdmin is the lower bound on pi - pj, this is always true. When y = 0, we have w(pi - pj) >= -f_min^2 + wpdmin - abs(w*pdmin). Which is always true. wpd_min is the lower bound on wpi - pj and the other two terms just drive the lower bound further down.
Constraint 2:
When zp = 1, this constraint reduces to constraint weymouth2 in constraintpipeweymouth, which is what we want (i.e. an active constraint) When zp = 0, we have w(pi - pj) <= f^2 + wpdmax. Since w*pdmax is the upper bound on w*(pi-pj), this is always true.
Constraint 3:
When zp = 1, this constraint reduces to constraint weymouth3 in constraintpipeweymouth, which is what we want (i.e. an active constraint) When zp = 0, we want this constraint to be in active AND any y value should be valid. In this case, since f^2 = 0 (there is no flow) the constraint becomes w(pj - pi) >= - y * (f_max^2 + wpdmax) - abs(w*pdmax). When y = 0, we have w(pj - pi) >= -abs(wpdmax). Since -pdmax is the lower bound on pj - pi note reversal of pressure sign, this is always true. When y = 1, we have w(pj - pi) >= -f_max^2 - wpdmax - abs(w*pdmax). Which is always true. -wpd_max is the lower bound on w(pj - pi) (note the sign flip). The other two terms just drive the lower bound further down.
Constraint 4:
When zp = 1, this constraint reduces to constraint weymouth4 in constraintpipeweymouth, which is what we want (i.e. an active constraint)
When zp = 0, we have (pj - pi) <= f^2 - wpd_min). Since -wpd_min is the upper bound on w*(pj-pi)–the pi and pj are flipped, this is always true.
Weymouth equation for an expansion pipe
Missing docstring for constraint_pipe_weymouth_ne
. Check Documenter's build log for details.
Mass flow and pressure drop constraints
Secondarily, there are constraints associated with limits on pressure drop or mass flow across pipes. These constraints also use the ne
and naming conventions.
GasModels.constraint_pipe_mass_flow
— FunctionConstraint: Constraint on mass flow across the pipe
Template: Constraint on mass flow across a pipe
Constraint: Constraint on flow across a pipe when there are on/off direction variables
GasModels.constraint_pipe_pressure
— FunctionConstraint: Constraints which define pressure drop across a pipe
Template: Pressure drop across pipes
Constraint: Constraints which define pressure drop across a pipe when there are on/off direction variables
Network expansion constraints
These constraints turn on or off the association between pressure and flow for pipes designated as expansion options.
GasModels.constraint_pipe_ne
— FunctionConstraint: on/off constraints on flow across pipes for expansion pipes
Template: Constraint associatd with turning off flow depending on the status of expansion pipes
Direction on/off constraints
The disjunctive forms of problems (where directions are controlled by on/off variables) include special (redundant) constraints which tie the direction variables together. Examples include ensuring that ensuring that parallel pipes have flow in the same direction.
GasModels.constraint_pipe_parallel_flow
— FunctionConstraint: ensures that parallel lines have flow in the same direction
Template: Constraints which ensure that parallel lines have flow in the same direction - customized for pipe
GasModels.constraint_ne_pipe_parallel_flow
— FunctionConstraint: ensures that parallel lines have flow in the same direction
Template: Constraints which ensure that parallel lines have flow in the same direction - customized for ne_pipe
Resistor Constraints
Weymouth's law constraints
The primary constraints related to resistor ensure that that pressure drop and flow across a resistor is related through the Weymouth relationships.
Missing docstring for constraint_resistor_weymouth
. Check Documenter's build log for details.
Mass flow and pressure drop constraints
Secondarily, there are constraints associated with limits on pressure drop or mass flow across pipes.
GasModels.constraint_resistor_mass_flow
— FunctionConstraint: Constraint on mass flow across the resistor
Template: Constraint on mass flow across a pipe
Constraint: Constraint on flow across a resistor when there are on/off direction variables
GasModels.constraint_resistor_pressure
— FunctionTemplate: Pressure drop across resistor with on/off direction variables
Constraint: Define pressures across a resistor
Constraint: Define pressures across a resistor
Constraint: Constraints which define pressure drop across a resistor
Constraint: Define pressures across a resistor
Constraint: Define pressures across a resistor
Direction on/off constraints
The disjunctive forms of problems (where directions are controlled by on/off variables) include special (redundant) constraints which tie the direction variables together. Examples include ensuring that ensuring that parallel pipes have flow in the same direction.
GasModels.constraint_resistor_parallel_flow
— FunctionConstraint: ensures that parallel lines have flow in the same direction
Template: Constraints which ensure that parallel lines have flow in the same direction - customized for resistor
Loss Resistor Constraints
The primary constraints related to loss resistors ensure that the pressure drop is constant along each edge. They also ensure that squared pressure variables are somehow related to (nonsquared) pressure variables.
Mass flow and pressure drop constraints
GasModels.constraint_loss_resistor_mass_flow
— FunctionConstraint: Constraint on mass flow across the loss_resistor
Template: Constraint on mass flow across a loss_resistor
Constraint: Constraint on flow across a loss_resistor when there are on/off direction variables
GasModels.constraint_loss_resistor_pressure
— FunctionTemplate: Pressure drop across loss_resistor with on/off direction variables
Constraint: Constraints which define pressure drop across a loss resistor
Constraint: Constraints which define pressure drop across a loss resistor
Constraint: Constraints which define pressure drop across a loss resistor
Constraint: Constraints which define pressure drop across a loss resistor
Constraint: Constraints which define pressure drop across a loss resistor
Compressor Constraints
Operations Constraints
The primary constraints related to compressors ensure that that the compressors operate within the limits of their capability (boost ratio, energy consumption, etc.). These constraints use the ne
naming conventions to denote constraints where the compressor is an expansion option.
GasModels.constraint_compressor_ratios
— FunctionTemplate: Compression ratios for a compressor
Constraint: enforces pressure changes bounds that obey compression ratios for a compressor with on/off direction variables
Constraint: Compressor ratio constraints on pressure differentials–not applicable for LRWP models
enforces pressure changes bounds that obey compression ratios
GasModels.constraint_compressor_ratios_ne
— FunctionTemplate: constraints on pressure drop across a compressor
Constraint: constraints on pressure drop across expansion compressors with on/off decision variables
Constraint: compressor ratios on a new compressor
constraints on pressure drop across a compressor
GasModels.constraint_compressor_mass_flow
— FunctionConstraint: constraints on flow across a compressor - handled by variable bounds
Template: constraints on flow across a compressor
Constraint: constraints on flow across a compressor with on/off direction variables
GasModels.constraint_compressor_energy
— FunctionTemplate: Constraints on the compressor energy
Constraint: constrains the energy of the compressor
Constraint: constrains the energy of the compressor
Constraint: constrains the energy of the compressor
Constraint: constrains the energy of the compressor
Constraint: constrains the energy of the compressor
Direction On/off Constraints
The disjunctive forms of problems (where directions are controlled by on/off variables) include special constraints to connect direction of flow with the choice of the binary variable.
GasModels.constraint_compressor_parallel_flow
— FunctionConstraint: ensures that parallel lines have flow in the same direction
Template: Constraints which ensure that parallel lines have flow in the same direction - customized for compressor
GasModels.constraint_ne_compressor_parallel_flow
— FunctionConstraint: ensures that parallel lines have flow in the same direction
Template: Constraints which ensure that parallel lines have flow in the same direction - customized for ne_compressor
Network Expansion Constraints
Constraints are also used to turn on/off flow through a compressor in expansion planning formulations
GasModels.constraint_compressor_ne
— FunctionConstraint: on/off constraints on flow across compressors for expansion variables
Template: Constraint for turning on or off flow through expansion compressor
Regulator Constraints
Operations Constraints
The primary constraints related to regulator ensure that that the valves operate within the limits of their capability (pressure reduction). The control valve also has an open/close variable to determine whether or not flow is allowed through the valve
GasModels.constraint_on_off_regulator_mass_flow
— Functionconstraints on flow across control valves
Template: constraints on flow across control valves with on/off direction variables
Constraint: Constraints on flow across control valves with on/off direction variables
GasModels.constraint_on_off_regulator_pressure
— FunctionConstraint Enforces pressure changes bounds that obey decompression ratios for
Constraint: Constraints on pressure drop across control valves that have on/off direction variables
constraints on pressure drop across control valves–not applicable for LRWP models
constraints on pressure drop across control valves
Direction On/off Constraints
The disjunctive forms of problems (where directions are controlled by on/off variables) include special constraints to connect direction of flow with the choice of the binary variable.
GasModels.constraint_regulator_parallel_flow
— FunctionConstraint: ensures that parallel lines have flow in the same direction
Template: Constraints which ensure that parallel lines have flow in the same direction - customized for control valve
Valve Constraints
Operations Constraints
The primary function of a valve is to open or close a pipe.
GasModels.constraint_on_off_valve_mass_flow
— Functionconstraints on flow across valves
Template: constraints on flow across valves modeled with on/off direction variables
Constraint: Constraints on flow across valves with on/off direction variables
GasModels.constraint_on_off_valve_pressure
— FunctionConstraint: Constraints on pressure drop across valves where the valve can open or close
Template: Constraint on pressure drop across valves, where the valve may be closed or opened
Direction On/off Constraints
The disjunctive forms of problems (where directions are controlled by on/off variables) include special constraints to connect direction of flow with the choice of the binary variable.
GasModels.constraint_valve_parallel_flow
— FunctionConstraint: ensures that parallel lines have flow in the same direction
Template: Constraints which ensure that parallel lines have flow in the same direction - customized for valve
Short Pipes
Pressure Constraints
Short pipes are used to model frictionless connections between junctions. The primary constraint ensures the pressure on both sides of the short pipe are the same.
GasModels.constraint_short_pipe_pressure
— FunctionConstraint: Constraint on pressure drop across a short pipe
Template: Constraint on pressure drop across a short pipe
GasModels.constraint_short_pipe_mass_flow
— FunctionConstraint: Constraints on flow across a short pipe with on/off direction variables
Constraint: constraints on flow across a short pipe
Constraint: Constraints on flow across a short pipe with on/off direction variables
Direction On/off Constraints
The disjunctive forms of problems (where directions are controlled by on/off variables) include special constraints to connect direction of flow with the choice of the binary variable.
GasModels.constraint_short_pipe_parallel_flow
— FunctionConstraint: ensures that parallel lines have flow in the same direction
Template: Constraints which ensure that parallel lines have flow in the same direction - customized for short pipe