예제 #1
0
def system_balance_constraint_rule(backend_model, loc_carrier, timestep):
    """
    System balance ensures that, within each location, the production and
    consumption of each carrier is balanced.

    .. container:: scrolling-wrapper

        .. math::

            \\sum_{loc::tech::carrier_{prod} \\in loc::carrier} \\boldsymbol{carrier_{prod}}(loc::tech::carrier, timestep)
            + \\sum_{loc::tech::carrier_{con} \\in loc::carrier} \\boldsymbol{carrier_{con}}(loc::tech::carrier, timestep)
            + \\sum_{loc::tech::carrier_{export} \\in loc::carrier} \\boldsymbol{carrier_{export}}(loc::tech::carrier, timestep)
            \\quad \\forall loc::carrier \\in loc::carriers, \\forall timestep \\in timesteps

    """
    prod, con, export = get_loc_tech_carriers(backend_model, loc_carrier)
    if backend_model.__calliope_run_config.get("ensure_feasibility", False):
        unmet_demand = backend_model.unmet_demand[loc_carrier, timestep]
        unused_supply = backend_model.unused_supply[loc_carrier, timestep]
    else:
        unmet_demand = unused_supply = 0

    backend_model.system_balance[loc_carrier, timestep].expr = (
        sum(backend_model.carrier_prod[loc_tech_carrier, timestep]
            for loc_tech_carrier in prod) +
        sum(backend_model.carrier_con[loc_tech_carrier, timestep]
            for loc_tech_carrier in con) + unmet_demand + unused_supply)

    return backend_model.system_balance[loc_carrier, timestep] == 0
예제 #2
0
def system_balance_constraint_rule(backend_model, loc_carrier, timestep):
    """
    System balance ensures that, within each location, the production and
    consumption of each carrier is balanced.

    .. container:: scrolling-wrapper

        .. math::

            \\sum_{loc::tech::carrier_{prod} \\in loc::carrier} \\boldsymbol{carrier_{prod}}(loc::tech::carrier, timestep)
            + \\sum_{loc::tech::carrier_{con} \\in loc::carrier} \\boldsymbol{carrier_{con}}(loc::tech::carrier, timestep)
            + \\sum_{loc::tech::carrier_{export} \\in loc::carrier} \\boldsymbol{carrier_{export}}(loc::tech::carrier, timestep)
            \\quad \\forall loc::carrier \\in loc::carriers, \\forall timestep \\in timesteps

    """
    prod, con, export = get_loc_tech_carriers(backend_model, loc_carrier)
    if backend_model.__calliope_model_data__['attrs'].get('run.ensure_feasibility', False):
        unmet_demand = backend_model.unmet_demand[loc_carrier, timestep]
        unused_supply = backend_model.unused_supply[loc_carrier, timestep]
    else:
        unmet_demand = unused_supply = 0

    backend_model.system_balance[loc_carrier, timestep].expr = (
        sum(backend_model.carrier_prod[loc_tech_carrier, timestep] for loc_tech_carrier in prod) +
        sum(backend_model.carrier_con[loc_tech_carrier, timestep] for loc_tech_carrier in con) +
        unmet_demand + unused_supply
    )

    return backend_model.system_balance[loc_carrier, timestep] == 0
예제 #3
0
def update_system_balance_constraint(backend_model, loc_carrier, timestep):
    """
    Update system balance constraint (from energy_balance.py) to include export

    Math given in :func:`~calliope.backend.pyomo.constraints.energy_balance.system_balance_constraint_rule`
    """
    prod, con, export = get_loc_tech_carriers(backend_model, loc_carrier)

    backend_model.system_balance[loc_carrier, timestep].expr += -1 * (sum(
        backend_model.carrier_export[loc_tech_carrier, timestep]
        for loc_tech_carrier in export))

    return None