Clarification on annual_excess_gen sign convention in hybrids battery simulation

Hi everyone,

I am currently working with the hybrid optimisation in OnSSET (I am in the process of creating a PV-biomass extension) and have been comparing the Differential Evolution implementation against my own MILP formulation of the same dispatch problem.

While doing so, I noticed something in hour_simulation_pv_biomass() that I wanted to check with the developers (@AndreasSahlberg) before assuming that it is an error.

For the battery case, excess generation is currently calculated as:

annual_excess_gen += (soc_prev + soc_usage - 1) / n_chg / battery_inv_eff * battery_size

However, during charging soc_usage is negative (since SOC is updated using soc -= soc_usage). This means that the expression appears to calculate the excess generation with the opposite sign to what would be expected.

I believe the corresponding expression should instead be:

annual_excess_gen += (soc_prev - soc_usage - 1) / n_chg / battery_inv_eff * battery_size

I initially thought I might be misunderstanding the SOC/sign convention, so I reproduced the dispatch in a MILP formulation and checked the annual energy balance. With the corrected sign, the energy balance closes consistently:

PV generation + diesel generation + battery discharge − battery charge − excess generation = annual demand.

I therefore wanted to ask whether there is some aspect of the original implementation that I am overlooking, or whether this could indeed be a sign error in the current OnSSET implementation.

If it is a bug, I would be happy to submit a pull request with the correction.

Thanks very much for your help!

Best,
Stuart