# title: Piecewise linear efficiency
#
# description: |
#     Add a piecewise technology efficiency function that steadily increases technology efficiency as outflow increases.
#     This requires the user to switch on the integer operating_units decision variable for any relevant technology.
#     Without the operating_units decision variable, the technology will have non-zero inflow requirements even if the technology capacity is zero and it has no outflow.
#
#     New indexed parameters:
#
#     - `flow_eff_piecewise_slopes` (defining the new set `pieces`)
#     - `flow_eff_piecewise_intercept` (defining the new set `pieces`)
#
# ---

dimensions:
  pieces:
    dtype: integer
    iterator: piece

parameters:
  flow_eff_piecewise_slopes:
    description: The gradient of each of the piecewise limiting line defining the convex, non-linear efficiency curve
  flow_eff_piecewise_intercept:
    description: The y-axis intercept of each of the piecewise limiting line defining the convex, non-linear efficiency curve


constraints:
  piecewise_efficiency:
    description: >
      Limit the lower bound of inflow requirements to monotonically increasing
      values as the quantity of technology outflow increases.
      Since the model is cost minimising and higher inflows translate to higher
      costs (because more carrier flow is needed in the system), this is
      equivalent to forcing the inflow to a specific point along the curve that
      is traced by the superposition of all pieces.
    foreach: [nodes, techs, timesteps, pieces]
    where: >
        flow_eff_piecewise_slopes AND flow_eff_piecewise_intercept
        AND available_flow_cap
    equations:
      - expression: >
          sum(flow_in, over=carriers) >=
          flow_eff_piecewise_slopes * sum(flow_out, over=carriers)
          + flow_eff_piecewise_intercept * sum(available_flow_cap, over=carriers)
