Welcome to Micro-Grids’s documentation!

Organization 1:University Of Liege, Energy Systems Research unit
Organization 2:University Mayor of San Simon, Energy Center
Version:1.0
Date:Nov 27, 2017

The world is currently undergoing a drastic change of the energy matrix from conventional sources of energy to renewable and alternative ones. This trend is particularly relevant in the challenge of rural electrification in developing countries because in some cases the levelized cost of electricity (LCOE) of hybrid or renewable systems can be competitive with the extension of the main grid in order to supply the energy demand of isolated communities [1]. However, exploiting solar energy for off-grid rural electrification faces some major challenges, especially due to the stochastic nature of the solar resource and eventual electricity demand (viz.load profile). These can have a serious impact on the sizing of the micro-grid, and the stability and reliability of the energy supply. In addition, as analysed in [2-3], an insightful analysis on how the electrification process impacts the electricity-user’s behaviour is generally lacking when planning a micro-grid, as well as a generalized underestimation of the social aspect during the design phase.To this aim, optimization techniques fulfill a key role in differents aspects of micro-grid planning and operating procedure in order to reduce the LCOE for a determined micro-grid [4].

The Micro-Grid library main objective is to provide an open source alternative to the problem of sizing and dispatch of energy in micro-grids in isolated places. It’s written in python(pyomo) and use excel and text files as input and output data handling and visualization.

Main features:

  • Robust optimization
  • Optimal sizing of Lion-Ion batteries, diesel generators and PV panels in order to supply a demand with the lowest cost possible.
  • Optimal dispatch from different energy sources.
  • Calculation of the net present cost of the system for the project lifetime.
  • Determination of the LCOE for the optimal system1.

Contents

Overview

The main objective of the Micro-grid library is to determine the combination of install capacities of PV, Lion-Ion Batteries and diesel generators that makes the lowest Net Present Cost for the life time of the project and accomplish the constraints of the system. For this objective the problem is express as a linear programming problem.

_images/System.png

Fig. 1. The considered micro-grid typology: adapted from[1].

The main optimization variables are the size of the PV array, battery bank and diesel generator that minimize the objective function and satisfy the physical, technical and economical constraints of the different elements in the micro-grid. The optimal dispatch of energy is also a result of the optimization process. The time step of the demand load and the irradiation is 1 hour and the optimization horizon is 1 year.

After the optimization process finish and the results are found, a post-processing tool is used in order to present the results and the most important parameters in an excel sheet, finally a Figure with the energy flow from the choose days is created.

_images/Dispatch.png

Fig. 2. Example of a figure created by the micro-grids library.

Reference

[1] Agarwal N., Kumar A., Varun., Optimization of grid independent hybrid PV-diesel-battery system for power generation in remote villages of uttar Pradesh, india. Energy for Sustainable Development 2013; 17:210-219

Model Description

Sets

Name Symbol Description
Years n Year of the project
Periods t Period that are divided the years
Scenarios s Scenarios analalized

Parameters

Data analysis parameters

Name Unit Description
Startdate Day Start date of the analysis
PlotTime Days Number of days for the plot of energy dispatch
PlotDay Day Start date for the dispatch plot
PlotScenario   Scenario to be plot

PV parameters

Name Unit Description
PVNominalCapacity W/unit Nominal capacity of one PV unit
InverterEfficiency % efficiency of the inverter to transform DC energy to AC
PVinvesmentCost USD/W Investment Cost to install PV panels
PVEnergyProduction Wh The yield of energy of one PV unit in the period (i,t)

Battery bank parameters

Name Unit Description
ChargeBatteryEfficiency % The efficiency of the battery to charge energy
DischargeBatteryEfficiency % The efficiency of the battery to discharge energy
DeepOfDischarge % Minimum percentage of energy of the nominal capacity of the battery
MaximunBatteryChargeTime hour Maximum time to charge from 0 % to a 100 % of energy in the battery
MaximunBatteryDischargeTime hour Maximum time to discharge from 100 % to a 0 % of energy in the battery
BatteryInvesmentCost USD/Wh Investment cost to install a Wh of batteries
BatteryRepostionTime Years Time for the remplacement of the battery

Diesel generator parameters

Name Unit Description
GeneratorEfficiency % Generator efficiency to transform heat into electricity
LowHeatingValue W/L Low heating value of the diesel
DieselCost USD/L Diesel cost
GeneratorInvesmentCost USD/W Investment cost to install a diesel generator

Energy balance parameters

Name Unit Description
EnergyDemand (s,t) W The total energy demand of the system for each scenario.
LostLoadProbability % The percentage of the demand that the micro-grid has to provide
ValueOfLostLoad USD/W The price of the load that is not supply to the system

Project parameters

Name Unit Description
Periods Hours Number of periods of the year
Years Years Number of years in the project
DeltaTime Hours Time step of the analysis of the energy flow
PorcentageFunded % Percentage of the total investment that is Funded by a bank or another entity
MaintenanceOperationCostPV % Percentage of the total investment spend in operation and management of PV
MaintenanceOperationCostBattery % Percentage of the total investment spend in operation and management of the battery
MaintenanceOperationCostGenerator % Percentage of the total investment spend in operation and management of the genset
DiscountRate % Discount rate of the project
InterestRate % Interest rate of the loan
ProbalityOccurrence (s) % Probability of occurrence of each scenario
N Years Years of duration of the project

Variables

PV variables

Name Unit Description
PVUnits unit Number of installed PV
TotalEnergyPV (s,t) Wh Energy generated for all the PVs in the system in each scenario
OyMCostPV USD Cost of the OyM of the PV during the life time of the proyect

Battery variables

Name Unit Description
BatteryNominalCapacity Wh Nominal capacity of the battery bank
EnergyBatteryDischarge (s,t) Wh Energy that flows out of the battery in each scenario
EnergyBatteryCharge (s,t) Wh Energy that flows in to the battery in each scenario
StateOfChargeBattery (s,t) Wh Energy inside the battery in each scenario
MaximunChargePower W Maximum charge power
MaximunDischargePower W Maximum discharge power

Diesel generator variables

Name Unit Description
GeneratorNominalCapacity W Nominal capacity of the diesel generator
DieselConsumed (s,t) L Diesel consumed to produce energy
GeneratorEnergy (s,t) Wh Energy produced by the diesel generator
DieselCostTotal (s) USD Cost of the diesel during the life time of the project

Energy balance variables

Name Unit Description
LostLoad (s,t) Wh Energy not supply by the system in each scenario
EnergyCurtailment (s,t) Wh Curtailment of solar energy in each scenario
LostLoadCostTotal (s) USD Cost of the Lost load during the life time of the project

Project variables

Name Unit Description
FinancialCost USD Annual constant payment for the loan adquire to finance the project
ScenarioNetPresentCost USD Net present cost of each scenario
InitialInversion USD Value of the inital inversion of the project
OyMCost USD Total cost of the Operation and maintenence during the life time of the project
FinancialCostTotal USD Total cost of the payment for the loan during the life time of the project
BatteryRepositionCost USD Cost for the reposition of the battery

Modeling of the system

Objective function

The objective function will minimize the sum of the multiplication of the net present cost of each scenario and their probability of occurrence.

Objective Funtion = \sum _s\mathit{ScenarioNetPresentCost}_s  \cdot \mathit{ProbalityOccurrence}_s

The net present cost of each scenario is computed with the following equation:

\mathit{ScenarioNetPresentCost}_s = InitialInversion + OyMCost + FinancialCostTotal

        + BatteryRepositionCost + \mathit{DieselCostTotal}_s + \mathit{LostLoadCostTotal}_s

The total investment equation is:

InitialInversion = (PVinvestmentCost \cdot PVNominalCapacity \cdot PVUnits +BatteryNominalCapacity \cdot BatteryInvestmentCost

+ GeneratorInvestmentCost \cdot GeneratorNominalCapacity  ) \cdot (1 - PorcentageFunded)

The OyMCost is calculated by the following equation:

OyMCostPV = PVinvesmentCost \cdot PVNominalCapacity \cdot PVUnits \cdot MaintenanceOperationCostPV

OyMCostBattery = BatteryNominalCapacity \cdot BatteryInvesmentCost  \cdot MaintenanceOperationCostBattery

OyMCostGenerator = GeneratorInvesmentCost \cdot GeneratorNominalCapacity  \cdot MaintenanceOperationCostGenerator

OyMCost = \sum _n\frac{ OyMCostPV + OyMCostBattery + OyMCostGenerator} {(1 + DiscountRate)^{n}}

The financial cost is a fix amount, that is payed each period to pay the loan acquire to finance a percentage of the initial investment and is calculated with the following equation:

FinancialCost = \frac{INV \cdot PorcentageFunded \cdot InterestRate} {1 - (1 +InterestRate)^{-N}}

The total cost incurred in the lifetime of the project for the financial cost is calculated with equation:

FinancialCostTotal = \sum _n\frac{FinancialCost} {(1+ DiscountRate)^{n}}

The replacement cost is given by the fallowing equation:

\mathit{ReplacementCost}_{10} = \frac{BatteryNominalCapacity \cdot BatteryInvesmentCost} {(1+ DiscountRate)^{N}}

The Diesel cost is calculated by:

\mathit{DieselCostTotal}_s = \sum _n\frac{\sum _t\mathit{DieselConsumed}_{s,t} \cdot DieselCost} {(1+ DiscountRate)^{n}}

Finally the cost for the unmment load is calculated with the following equation:

\mathit{LostLoadCostTotal}_s = \sum _n\frac{\sum _t\mathit{LostLoad}_{s,t} \cdot ValueOfLostLoad} {(1+ DiscountRate)^{n}}

PV model

The equation that model the PV array energy yield is given by:

\mathit{TotalEnergyPV}_{s,t} = \mathit{PVEnergyProduction}_{s,t} \cdot \mathit{InverterEfficiency} \cdot \mathit{PVUnits}

Diesel generator

The fuel consumption is modeled by:

\mathit{DieselConsumed}_{s,t} = \mathit{GeneratorEnergy}_{s,t} / (\mathit{GeneratorEfficiency} \cdot \mathit{LowHeatingValue})

In order to ensure that the generator will not exceed his capacity the fallowing constraint is added to the model:

\mathit{GeneratorNominalCapacity} \cdot \mathit{DeltaTime} \geq \mathit{GeneratorEnergy}_{s,t}

Battery bank

The state of charge of the battery is modeled by:

t=1:

\mathit{StateOfChargeBattery}_{s,1} = BatteryNominalCapacity - \mathit{EnergyBatteryCharge}_{s,1} \cdot  \mathit{ChargeBatteryEfficiency} - \mathit{EnergyBatteryDischarge}_{s,1} \cdot  \mathit{DischargeBatteryEfficiency}

t>1:

\mathit{StateOfChargeBattery}_{s,t} = BatteryNominalCapacity - \mathit{EnergyBatteryCharge}_{s,t} \cdot  \mathit{ChargeBatteryEfficiency} - \mathit{EnergyBatteryDischarge}_{s,t} \cdot  \mathit{DischargeBatteryEfficiency}

In this equations is important to highlight that in the period 1 the stated of charge of the batterie is equal to the total capacity of the battery.

In order to ensure the durability of the battery a minimum depth of discharge (%) and maximum charge are establish as a constraint:

BatteryNominalCapacity \cdot DeepOfDischarge \leq \mathit{StateOfChargeBattery}_{s,t} \leq BatteryNominalCapacity

The maximum power of charge and discharge are modeled as follow:

MaximunChargePower = BatteryNominalCapacity/MaximunBatteryChargeTime

MaximunDischargePower = BatteryNominalCapacity/MaximunBatteryDischargeTime

The flow of energy is into and out of the battery is restricted by:

\mathit{EnergyBatteryCharge}_{s,t} \geq - MaximunChargePower \cdot DeltaTime

\mathit{EnergyBatteryDischarge}_{s,t} \leq MaximunDischargePower \cdot DeltaTime

Energy constraints

In order to ensure a perfect match between generation and demand, an energy balance is created as a constraint.

\mathit{EnergyDemand}_{s,t} = \mathit{TotalEnergyPV}_{s,t} + \mathit{DieselConsumed}_{s,t} + \mathit{EnergyBatteryCharge}_{s,t}

+ \mathit{EnergyBatteryDischarge}_{s,t} + \mathit{EnergyCurtailment}_{s,t} + \mathit{LostLoad}_{s,t}

This constraint is used to ensure that a percentage of the demand will always be supply and is express as follow:

LostLoadProbability =  \frac{\sum _t\mathit{LostLoad}_{s,t}} {\sum _t\mathit{EnergyDemand}_{s,t}}

API Documentation

Model Creation

Initialize parameters

Model Resolution

Constraints

Economical analisis

Results

Tutorial

This section is a walkthrough of how to use the Micro-Grids library in order to obtain the optimal nominal capacity for an isolated micro-grid with a given demand and PV production.

Requirements

The MicroGrid library can be use in Linux or windows and needs different programs and phyton libraries in order to work.

Python

First of all Micro-Grids needs Python 3 install in the computer. The easiest way to obtain it, is download anaconda in order to have all the tools needed to run python scripts.

Python libraries

The python libraries needed to run Micro-Grids are the following:

  • pyomo Optimization object library, interface to LP solver (e.g. CPLEX)
  • pandas for input and result data handling
  • matplotlib for plotting

Solver

Any of the fallowing solvers can be used during the optimization process in the Micro-Grids library:

Download of MicroGrid library

For the moment the Micro-Grids library is in form of python scripts, in order to download them please follow this link:

https://github.com/squoilin/MicroGrids

Once they have been download, create a folder and put the scripts in there. Also create two folders with the names of ‘Results’ and Inputs as show in the following Figure:

_images/Setup.png

Inputs

The Micro-grids library needs the input files are stored in the folder ‘Inputs’, these are the needed files:

Name of the file type of file Description
Data.dat Txt file In this file the value of the parameters are set
Demand.xls Excel file The demand of energy of the system for each period is set in this file
PV_Energy.xls Excel file The energy yield in each period from one PV is set in this file

Data.dat file

This file has to contain all the parameters for the Micro-Grids library to be able to perform an optimization of the nominal capacity of the PV, battery bank and diesel generator. This file has to be write in AMPL data format. A table of all the parameters with an example of value and how they have to be written in the txt can be seen in the next table.

Name of the parameter Ampl format Observation
Stardate param: StartDate := ‘01/01/2014 01:00:00’; month/day/year hour:minute:second
PlotTime param: PlotTime := 1; The number of days to be plot
PlotDay param: PlotDay := ‘02/01/2014 01:00:00’; month/day/year hour:minute:second
PlotScenario param: PlotScenario := 2; The scenario to be ploted
Delta_Time param: Delta_Time := 1.0; Duration of the periods
PVNominalCapacity param: PV_Nominal_Capacity := 300;  
PVinvesmentCost param: PV_invesment_Cost := 1.6667;  
InverterEfficiency param: Inverter_Efficiency := 0.986;  
ChargeBatteryEfficiency param: Charge_Battery_Efficiency := 0.95;  
DischargeBatteryEfficiency param: Discharge_Battery_Efficiency := 0.95;  
DeepOfDischarge param: Deep_of_Discharge := 0.2; Between 0 a 1
MaximunBatteryChargeTime param: Maximun_Battery_Charge_Time := 5;  
MaximunBatteryDischargeTime param: Maximun_Battery_Discharge_Time := 5;  
BatteryInvesmentCost param: Battery_Invesment_Cost := 0.6;  
N param: Battery_Reposition_Time := 10;  
GeneratorEfficiency param: Generator_Efficiency := 0.337040782;  
LowHeatingValue param: Low_Heating_Value := 9890; It depends on the fuel used
DieselCost param: Diesel_Unitary_Cost := 1.18;  
GeneratorInvesmentCost param: Generator_Invesment_Cost := 1.48;  
LostLoadProbability param: Lost_Load_Probability := 0.00; Between 0 and 1
ValueOfLostLoad param: Value_Of_Lost_Load := 0.18;  
Periods param: Periods := 8760; A year has 8760 hours
Years param: Years := 20;  
PorcentageFunded param: Porcentage_Funded := 0.55;  
MaintenanceOperationCostPV param: Maintenance_Operation_Cost_PV := 0.015;  
MaintenanceOperationCostBattery param: Maintenance_Operation_Cost_Battery:= 0.015;  
MaintenanceOperationCostGenerator param: Maintenance_Operation_Cost_Generator := 0.015;  
DiscountRate param: Discount_Rate := 0.12;  
InterestRate param: Interest_Rate_Loan := 0.06;  
s param: Scenarios :=3;  

This file must be save inside the folder “Inputs”. An example can be downloaded in the fallowing link:

https://github.com/squoilin/MicroGrids/tree/master/MicroGrids/Example

Demand.xls file

The Demand.xls file has to have the energy demand of the system in each period of analysis. The excel file must have a column with the periods and another with the demand in W as shown in the following figure.

_images/Demand.png

This file must be save inside the folder “Inputs”. An example can be downloaded in the fallowing link:

https://github.com/squoilin/MicroGrids/tree/master/MicroGrids/Example

PV_Energy.xls

The PV_Energy.xls file has to have the energy yield for one PV in each period of analysis. The excel file must have a column with the periods and the number of columns equal to the number of scenarios energy yield in W as shown in the following figure.

_images/PV_Energy.png

This file must be save inside the folder “Inputs”. An example can be downloaded in the fallowing link:

https://github.com/squoilin/MicroGrids/tree/master/MicroGrids/Example

Run Micro-Grids library

Once all the above steps are performed, the easiest way to run the Micro-grids library is opening the Micro-Grids.py file in an development environment like spider and run the script inside it. Another way is to open a terminal in the folder where all the scripts are and use the following command:

python Micro-Grids.py

Outputs

After the optimization is finish a message will appear with the Levelized cost of energy and the net present value of the system. Also 3 files will be created in the ‘Results’ folder, this files are specified in the following table.

Name of the file type of file Description
Size.xls Txt file Contains the nominal capacities of the PV, Battery, Diesel generator and other information
Time_series.xls Excel file Contains the the energy flow in each period for all the energy variables and the diesel consume
Scenario_Information.xls Excel file Contains some information of the scenarios
Energy_flow.png Excel file Contains the Figure of the energy flow from the ‘PlotDay’ during for ‘PlotTime’ days

Indices and tables

License

Copyright 2016 Sergio Balderrama, Sylvain Quoilin

Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the European Commission - subsequent versions of the EUPL (the “Licence”); You may not use this work except in compliance with the Licence. You may obtain a copy of the Licence at:

http://ec.europa.eu/idabc/eupl

Unless required by applicable law or agreed to in writing, software distributed under the Licence is distributed on an “AS IS” basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Licence for the specific language governing permissions and limitations under the Licence.

References

[1]Nguyen K., Alternatives to grid extension for rural electrification: Decentralized renewable energy technologies in Vietnam. Energy Policy 2007; 35:2579-2589.
[2]Murphy T., Making the energy transition in rural East Africa: Is leapfrogging an alternative? Technological Forecasting & Social Change 2001; 68: 173-193.
[3]Madubansi M, Shackleton C.M., Changing energy profiles and consumption patterns following electrification in five rural villages, South Africa. Energy Policy 2006; 34: 4081-4092.
[4]Gamarra C., Guerrero J., Computational optimization techniques applied to microgrids planning: A review. Renewable and Sustainable Energy Reviews 2015; 48:413-424.