Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/InfrastructureOptimizationModels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,9 @@ export ReservationVariable
export PiecewiseLinearCostVariable
export RateofChangeConstraintSlackUp, RateofChangeConstraintSlackDown
export DCVoltage
# Flow-direction trait for variable types
export FlowSign, Injection, Withdrawal, Unsigned
export flow_sign, multiplier_from_sign
# Abstract types needed by POM for type hierarchy
export SparseVariableType, InterpolationVariableType, BinaryInterpolationVariableType

Expand Down
1 change: 0 additions & 1 deletion src/common_models/rateofchange_constraints.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# NOTE: not included currently.
function _get_minutes_per_period(container::OptimizationContainer)
resolution = get_resolution(container)
if resolution > Dates.Minute(1)
Expand Down
32 changes: 32 additions & 0 deletions src/core/standard_variables_expressions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,38 @@ struct RateofChangeConstraintSlackDown <: VariableType end
# HVDC Variables (used in add_pwl_methods)
struct DCVoltage <: VariableType end

#################################################################################
# Flow direction trait
#
# Encodes the sign with which a variable contributes to a power-balance
# expression. Replaces scattered `get_variable_multiplier(...) = ±1.0` overrides
# whose only signal is the variable type itself. Device-driven sign overrides
# (e.g. anything on `PSY.ElectricLoad`) still live in POM as more-specific
# dispatches.
#################################################################################

# Holy-traits style: `flow_sign` returns a *type*, and `multiplier_from_sign`
# dispatches on `::Type{<:FlowSign}`. Both layers resolve at compile time so the
# numeric multiplier folds away at every call site.
abstract type FlowSign end
struct Injection <: FlowSign end
struct Withdrawal <: FlowSign end
struct Unsigned <: FlowSign end

# Default: no directional meaning attached to the variable type.
flow_sign(::Type{<:VariableType}) = Unsigned

multiplier_from_sign(::Type{Injection}) = 1.0
multiplier_from_sign(::Type{Withdrawal}) = -1.0
# Variables without flow semantics (OnVariable, StartVariable, ...) keep the
# legacy 1.0 default so callers that don't care about sign still work.
multiplier_from_sign(::Type{Unsigned}) = 1.0

# Standard variable types defined here:
flow_sign(::Type{ActivePowerVariable}) = Injection
flow_sign(::Type{ActivePowerInVariable}) = Withdrawal
flow_sign(::Type{ActivePowerOutVariable}) = Injection

#################################################################################
# Standard Expression Types
# These are the base expression types for aggregating terms
Expand Down
Loading