├── Clear_Sky_IT.m ├── D.mat ├── DG_module.m ├── Data_ElectricNetworkBarryIsalnd.m ├── Data_intro_ElectricThermal_NetworkBarryIsalnd.m ├── HPP.m ├── MC_HEATPOWER.m ├── MarkovFailure.m ├── NHPP.m ├── OPF.m ├── PowEl2PowTh.m ├── STP.m ├── TempMonteCarlo.m ├── Weather_Simulator.m ├── figs ├── CombinedGridTopology.jpg ├── ExampleSimulationResults.jpg └── readme.rm └── readme.md /Clear_Sky_IT.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Roberock/Heat_and_Electric_powerNetwork/a442f6040a0888d8e8adc7ce14c582283eff5419/Clear_Sky_IT.m -------------------------------------------------------------------------------- /D.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Roberock/Heat_and_Electric_powerNetwork/a442f6040a0888d8e8adc7ce14c582283eff5419/D.mat -------------------------------------------------------------------------------- /DG_module.m: -------------------------------------------------------------------------------- 1 | classdef DG_module 2 | % DG_module class: 3 | % to simulate the power produced by distributed generators 4 | %% START Proprieties 5 | properties 6 | % PV Panel 7 | PVn=1% PVn: number of solar technologies 8 | PVIPmax=1.32% PVIPmax: current at max power [A] 9 | PVItc=1.4% PVItc: current temperature coef. [mA/Celsius] 10 | PVIsc=1.8% PVIsc: short circuit current [A] 11 | PVTa=30% PVTa: ambient temperature [Celsius] 12 | PVTno=43% PVTno: nominal operating temperature [Celsius] 13 | PVVPmax=38% PVVPmax: voltage at max power [V] 14 | PVVtc=194% PVVtc: voltage temperature coef. [mV/Celsius] 15 | PVVoc=55.5% PVVoc: voltage open circuit [V] 16 | 17 | % WIND TURBINE 18 | WPrated =50 % WPrated: rated power [kW] 19 | WWSci =3.8000 % WWSci: cut-in wind speed [m/s] 20 | WWSrated =9.5 % WWSrated: rated wind speed [m/s] 21 | WWSco =23.8 % WWSco: cut-out wind speed [m/s] 22 | 23 | %Storage 24 | STPpeak=0.28; % storage peak power? 25 | STEs=0.0400; % storage electric power rating? 26 | STn=1; % STn: number of storage technologies 27 | 28 | % ON-OFF HeatPump (model Maneurop SH 140-4) 29 | a1=0.8387; a2= 0.08744; % Fitting Coefficient HP on-off (Dongelline et al) 30 | b1=0.01142; b2= 0.001204 ; 31 | c1=30.68/35; % [KW/deg C] 32 | c2= 3.615/35; 33 | end 34 | 35 | 36 | methods 37 | %% CONSTRUCTOR 38 | function PVobj = DG_module(varargin) % method to define an object of type Scenario_Based_Reliability 39 | if nargin==0; return % Create an empty object 40 | end 41 | for k=1:2:length(varargin) 42 | switch lower(varargin{k}) 43 | case {'data', 'del', 'd', 'datastructure'} 44 | % PV 45 | PVobj.PVn=varargin{k+1}.PVn; PVobj.PVIPmax=varargin{k+1}.PVIPmax; 46 | PVobj.PVItc=varargin{k+1}.PVItc; PVobj.PVIsc=varargin{k+1}.PVIsc; 47 | PVobj.PVTa=varargin{k+1}.PVTa; PVobj.PVTno=varargin{k+1}.PVTno; 48 | PVobj.PVVPmax=varargin{k+1}.PVVPmax; PVobj.PVVtc=varargin{k+1}.PVVtc; PVobj.PVVoc=varargin{k+1}.PVVoc; 49 | % WT 50 | PVobj.WPrated=varargin{k+1}.WPrated; 51 | PVobj.WWSci=varargin{k+1}.WWSci; 52 | PVobj.WWSrated=varargin{k+1}.WWSrated; 53 | PVobj.WWSco=varargin{k+1}.WWSco; 54 | % HeatPump On-Off 55 | PVobj.WWSco=varargin{k+1}.a1; 56 | PVobj.WWSco=varargin{k+1}.a2; 57 | PVobj.b1=varargin{k+1}.b1; 58 | PVobj.b2=varargin{k+1}.b2; 59 | PVobj.c1=varargin{k+1}.c1; 60 | PVobj.c2=varargin{k+1}.c2; 61 | end 62 | end 63 | end % of constructor 64 | 65 | %% power method for the PV pannels 66 | function Pow = Power_PV(obj,s,Text,NDn) 67 | % s sun irradiance 68 | % Text [Celsius] external air temperature 69 | % NDn number of nodes 70 | % Output 71 | % Pow: solar power produced by module(s) 72 | Idx=ones(NDn,1); 73 | tc = Text+s(:,ones(1,obj.PVn)).*(obj.PVTno(Idx,:)-20)/0.8; 74 | iy = s(:,ones(1,obj.PVn)).*(obj.PVIsc(Idx,:)+obj.PVItc(Idx,:).*(tc-25)/1000); 75 | vy = obj.PVVoc(Idx,:)-obj.PVVtc(Idx,:).*tc/1000; 76 | ff = (obj.PVVPmax(Idx,:).*obj.PVIPmax(Idx,:))./... 77 | (obj.PVVoc(Idx,:).*obj.PVIsc(Idx,:)); 78 | Pow = ff.*vy.*iy/1000; 79 | end 80 | 81 | %% power method for the Wind Turbines 82 | function Pow = Power_WT(obj,ws,NDn) 83 | % ws: wind speed [m/s] 84 | Pow = zeros(NDn,1); 85 | % Case 1: cut in wind speed < wind speed <= rated wind speed 86 | clas1 = all((obj.WWSci(ones(NDn,1),:) < ws(:,ones(1,1))).*(ws(:,ones(1,1)) <= obj.WWSrated(ones(NDn,1),:)) == 1); 87 | % Case 2: rated wind speed < wind speed <= cut out speed 88 | clas2 = all((obj.WWSrated(ones(NDn,1),:) < ws(:,ones(1,1))).*(ws(:,ones(1,1)) <= obj.WWSco(ones(NDn,1),:)) == 1); 89 | if clas1 90 | Pow = obj.WPrated(ones(NDn,1),:).*(ws(:,ones(1,1))-obj.WWSci(ones(NDn,1),:))./... 91 | (obj.WWSrated(ones(NDn,1),:)-obj.WWSci(ones(NDn,1),:)); 92 | elseif clas2 93 | Pow = obj.WPrated(ones(NDn,1),:); 94 | end 95 | end 96 | 97 | %% DGs Storage systems (ST) 98 | function Pow = Power_ST(obj,NDn) 99 | STlev = rand(NDn, obj.STn).*obj.STEs(ones(NDn,1),:); 100 | Pow = STlev; 101 | STPaux = obj.STPpeak(ones(NDn,1),:); 102 | Pow(Pow > STPaux) = STPaux(Pow > STPaux); 103 | end 104 | 105 | %% power method for the Heat Pumps Turbines 106 | function [Pow_hp,COPdc]=Power_HP_OnOff(obj,Text,Tw) 107 | %Onn-Off Air-to_Water Heat Pumps 108 | % Input 109 | % Text = External Air Temperature (e.g. Random Variable) 110 | % Tw = Hot Water Temperature (e.g. 35 deg Celsius) 111 | % Output 112 | % Powhp= Thermal Power Output delivered by the Heat Pump 113 | % COPdc = Coefficent of Performance at full load 114 | % Power and Coeff of performance at full load 115 | 116 | Pow_hp=obj.a1.*Text+obj.b1.*Text.^2+obj.c1.*Tw; 117 | %COPdc=3.42; 118 | COPdc=obj.a2.*Text+obj.b2.*Text.^2+obj.c2.*Tw; 119 | % if the temperature is outside the operative ranges 120 | Pow_hp(Text<-10 | Text>20)=0; COPdc(Text<-10 | Text>20)=0; 121 | end 122 | end 123 | end 124 | 125 | -------------------------------------------------------------------------------- /Data_ElectricNetworkBarryIsalnd.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear variables 3 | %% Barry island Electric Network Data 4 | Del.NDn=8; 5 | Del.FDn=7; 6 | Del.MSn=3; 7 | Del.MStyp=[1;2;1]; % 1 is Gas Turbine, 2 is steam Turbine 8 | Del.MSnod=[2,7,8]; 9 | Del.DGtn=4; 10 | Del.FDX=0.08; % Reactance Ohm/km 11 | Del.FDR=0.164; % Reactance Ohm/km 12 | Del.Lengths=[260;170;230;320;200;160;260]; %line Lenght 13 | Del.muLDth=[0.2;0;0.5;0.5;0.2;0.2;0;0]; % load Demanded 14 | Del.stdLDth=[0.02;0;0.05;0.05;0.02;0.02;0;0]; % load Demanded 15 | Del.Cm=[1.3;1/0.79]; 16 | Del.Z=8.1; % 17 | Del.MSmu=[20;10;20]; 18 | Del.MSsig=[2;1;2]; 19 | Del.MScap=[40;40;50]; 20 | Del.Vnom=11; % base voltage in [kV] 21 | Del.FDks=[1;2;3;4;8;5;6]; % start node 22 | Del.FDke=[2;3;4;8;5;6;7]; % end node 23 | Del.FDAmp=[400;400;400;400;400;400;400]; 24 | Del.MSCo=0.1450; % Main Generators cost 25 | Del.PVCo=3.7670e-05; % Potovolt cost 26 | Del.WCo=0.0390; % Wind Turbine cost 27 | Del.EVCo=0.0210; % El Vehicles cost 28 | Del.STCo=4.6284e-5; % Storage cost 29 | Del.VGCo=1e9; % Virtual generators cost 30 | Del.pckg=[50,1,1,50];% pakaging factors 31 | Del.VGcap=10000; % Virtual generators capacity 32 | Del.ts=1; % 1h simulation time 33 | % Storages 34 | Del.STn=1; 35 | Del.STEs=0.04; 36 | Del.STPpeak=0.2800; 37 | %% Barry island: Now Heat District Network Solution 38 | load('D.mat') 39 | 40 | 41 | %% Sample External Environmental Conditions 42 | Tamb=normrnd(6,3); % Heating Temperature Normally Distributed 43 | % Compute Thermal power Demand 44 | 45 | %% 1) Start With Electric Network Economic Dispatch 46 | % The Generators Allocation Matrix 47 | x=zeros(Del.NDn,Del.DGtn+1); 48 | x(Del.MSnod,1)=1; 49 | % the meccanical states 50 | FDmecst=ones(Del.FDn,1); %feeders meccanical state 51 | NETmecst=ones(Del.NDn,Del.DGtn+1); %feeders meccanical state 52 | % Loads 53 | LD=normrnd(Del.muLDth,Del.stdLDth); % MWel of the 5 lumped electrical loads 54 | % MS 55 | MSPp = normrnd(Del.MSmu, Del.MSsig); 56 | MSPav = MSPp(ones(Del.NDn,1),:); 57 | % DGs Storage systems (ST) 58 | ik=1; 59 | STlev = rand(Del.NDn, Del.STn).*Del.STEs(ones(Del.NDn,1),:); 60 | STPav = STP(STlev, x(:,1+ik), Del); 61 | STPav = STPav.*NETmecst(:,1+ik); 62 | % MCHP 63 | % DGPav=[..Pav MCHPav STPav] 64 | DGPav=x(:,2:end); 65 | NETPavM=[MSPav DGPav]; %Matrix of electric power Available 66 | [Pgen,ENS, NETminCo, PNETu, PDGu, ef] = OPF(x, NETPavM, LD, FDmecst, Del); 67 | PowTh=PowEl2PowTh(Pgen,Del); 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /Data_intro_ElectricThermal_NetworkBarryIsalnd.m: -------------------------------------------------------------------------------- 1 | clc; clear variables 2 | % see [1] for the original description of the heat-electric power network 3 | % case study and [2] for an application within a stochastic optimization framwork 4 | % [1] Xuezhi Liu et al "Combined analysis of electricity and heat networks ", Applied Energy, 5 | % Volume 162, 15 January 2016, Pages 1238-1250 6 | % DOI https://doi.org/10.1016/j.apenergy.2015.01.102 7 | 8 | % [2] R.Rocchetta and E.Patelli, "Stochastic analysis and reliability-cost optimization 9 | % of distributed generators and air source heat pumps", 2017 2nd International Conference on System Reliability and Safety (ICSRS) 10 | % https://strathprints.strath.ac.uk/72133/1/https://ieeexplore.ieee.org/document/8272792.pdf 11 | 12 | %% Example of how to define a data structure for the electric network 13 | % System topology clc; clear variables 14 | % see [1] for the original description of the heat-electric power network 15 | % case study and [2] for an application within a stochastic optimization framwork 16 | % [1] Xuezhi Liu et al "Combined analysis of electricity and heat networks ", Applied Energy, 17 | % Volume 162, 15 January 2016, Pages 1238-1250 18 | % DOI https://doi.org/10.1016/j.apenergy.2015.01.102 19 | 20 | % [2] R.Rocchetta and E.Patelli, "Stochastic analysis and reliability-cost optimization 21 | % of distributed generators and air source heat pumps", 2017 2nd International Conference on System Reliability and Safety (ICSRS) 22 | % https://strathprints.strath.ac.uk/72133/1/https://ieeexplore.ieee.org/document/8272792.pdf 23 | 24 | % Temp=load('D.mat'); 25 | % Del= Temp.D.Del; % electrical grid data 26 | % Dth= Temp.D.Dth; % thermal grid data 27 | %% Example of how to define a data structure for the electric network 28 | % System topology 29 | Del.NDn=8; % number of nodes 30 | Del.FDn=7; % number of feeders (links between the nodes) 31 | Del.FDks=[1;2;3;4;8;5;6]; % start node 32 | Del.FDke=[2;3;4;8;5;6;7]; % end node 33 | Del.FDAmp=[400;400;400;400;400;400;400]; % Ampacity [A], maxiumum current a cable can carry without exceeding its thermal limit 34 | 35 | % Nodes parameters (generators positions and propreties 36 | Del.MSn=3; % number of main generator sources 37 | Del.MStyp=[1;2;1]; % Generators Type: one is Gas Turbine(2) and two is-steam Turbines (1) 38 | Del.MSnod=[2,7,8]; % nodes where the main generating sources are located 39 | Del.DGtn=4; % 40 | 41 | % links (power cables) parameters 42 | Del.FDX=0.08; % Reactance [Ohm/km] 43 | Del.FDR=0.164; % Resistance [Ohm/km] 44 | Del.Lengths=[260;170;230;320;200;160;260]; % Lenght of the links 45 | 46 | % Nodes parameters (random power demanded, produced and base voltage) 47 | Del.muLDth=[0.2;0;0.5;0.5;0.2;0.2;0;0]; % mean Load Demand 48 | Del.stdLDth=[0.02;0;0.05;0.05;0.02;0.02;0;0]; % standard deviation of the Demand 49 | Del.MSmu=[20;10;20]; % mean power produced by the main generators 50 | Del.MSsig=[2;1;2]; % standard deviation of the power produced by the main generators 51 | Del.Vnom=11; % base voltage in [kV] 52 | 53 | % Cost data 54 | Del.Cm=[1.3;1/0.79]; % Cost for Gas Turbine(2) and two is-steam Turbines (???) 55 | Del.MSCo=0.1450; % Main Generators operational cost 56 | Del.PVCo=3.7670e-05; % Potovolt operational cost 57 | Del.WCo=0.0390; % Wind Turbine operational cost 58 | Del.EVCo=0.0210; % El Vehicles operational cost 59 | Del.STCo=4.6284e-5; % Storage operational cost 60 | Del.VGCo=1e9; % Virtual generators operational cost 61 | Del.Z=8.1; % t.b.d. 62 | Del.MScap=[40;40;50]; % t.b.d. 63 | 64 | % Distributed generators data and production cost 65 | Del.pckg=[50,1,1,50];% pakaging factors 66 | Del.VGcap=10000; % Virtual generators capacity (virtually inf) 67 | Del.ts=1; % 1-h simulation time step 68 | 69 | Del.STn=1; % storages number of technologies 70 | Del.STEs=0.04; % storage parameter 71 | Del.STPpeak=0.2800; % storage peak output 72 | 73 | Del.PVn=1; % PV number of technologies 74 | Del.PVTa=30; % PV parameters 75 | Del.PVTno=43; % 76 | Del.PVIsc=1.8; % 77 | Del.PVItc=1.4;% 78 | Del.PVVoc=55.5; % 79 | Del.PVVtc=194;% 80 | Del.PVVPmax=38;% 81 | Del.PVIPmax=1.32;% 82 | Del.EVPp=6.73;% EV power 83 | Del.SCn=300;% 84 | Del.Inc=0.0240; % 85 | Del.MScm=1.3;% 86 | Del.SCn=7e2;% 87 | 88 | Del.WWSrated=9.5; % rated Wind 89 | Del.Eprice=@(L)-5.13717E-09*L^2+5.31538E-05*L; % price of the electricity from the total load demanded L 90 | 91 | %% Barry island: Load the Heat District Network data 92 | Temp=load('D.mat'); 93 | Dth=Temp.D.Dth; % load the structure of the 'thermal' network 94 | 95 | %% show topology of the two networks (not linked) 96 | G_th=graph(Dth.From_Node,Dth.To_Node); 97 | G_th.plot; 98 | hold on; grid on 99 | G_el=graph(Del.FDks,Del.FDke); 100 | G_el.plot 101 | legend('Thermal nodes', 'Electrical nodes') 102 | 103 | %% Sample External Environmental Conditions 104 | 105 | long=-3.27; % Barry Island UK Longitude 106 | lat=51.3; % Barry Island UK Latitude 107 | SCn= 200; % Number of samples 108 | Ndays=5; % number of days 109 | [ITot,ws,~,~]=Weather_Simulator(SCn,long,lat,24*Ndays); % Generate weather history 110 | % ITot clear sky irradiance 111 | % ws wind speed 112 | % s total 'real' irradiance 113 | a= 0.2579; b= 0.7264; % distribution parameters 114 | s=betarnd(a , b,size(ITot)).*ITot; 115 | Tamb=normrnd(6,3); % Example of normal distributed Temperature 116 | subplot(2,1,1) 117 | % display weather samples 118 | plot(ITot); hold on; 119 | xlabel('IX of the simulated hour'); ylabel('irradiance') 120 | plot(s,'.-r'); legend('clear sky irr', 'with cloud cover') 121 | subplot(2,1,2) 122 | plot(ws); hold on; 123 | xlabel('IX of the simulated hour'); ylabel('wind speed [m/s]') 124 | %% 1) Start With Electric Network Economic Dispatch 125 | % The Generators Allocation Matrix 126 | %x=zeros(Del.NDn,Del.DGtn+1); % zero generators over the NDn nodes and for the Del.DGtn+1 technologies 127 | % user-defined el-grid allocation matrix 128 | % MS PV WT EV ST 129 | x=[ 0,11, 0, 0, 13 % node 1 130 | 0, 0, 1, 0, 15 % node 2 131 | 0, 4, 4, 0, 5 % node 3 132 | 0, 0, 0, 0, 5 % node 4 133 | 0, 4, 0, 0, 20 % node 5 134 | 0, 0, 0, 0, 2 % node 6 135 | 0, 1, 1, 0, 0 % node 7 136 | 0, 9, 1, 0, 40]; % node 8 137 | 138 | x(Del.MSnod,1)=1; % add main generators in the first colum 139 | 140 | % the meccanical states 141 | FDmecst=ones(Del.FDn,1); %feeders meccanical state 142 | NETmecst=ones(Del.NDn,Del.DGtn+1); %feeders meccanical state 143 | % Loads 144 | LD=normrnd(Del.muLDth,Del.stdLDth); % MWel of the 5 lumped electrical loads 145 | % MS (Main power sources) 146 | MSPp = normrnd(Del.MSmu, Del.MSsig); 147 | MSPav = MSPp(ones(Del.NDn,1),:); 148 | 149 | % Distirbuted generators (DG) 150 | DGmdl=DG_module();% define generic DG module 151 | 152 | % Photovoltaic PV 153 | Sun= 1; % irradiance 154 | Text=29; % ambient temperature 155 | PVPav=DGmdl.Power_PV(Sun,Text,Del.NDn); % available power from PV pannles 156 | PVPav = PVPav.*NETmecst(:,2).*x(:,2); 157 | 158 | % Wind turbines WT 159 | WSpeed=15; % wind speed 160 | WPav=DGmdl.Power_WT(WSpeed,Del.NDn); % available power from wind turbines 161 | WPav = WPav.*NETmecst(:,3).*x(:,3); 162 | 163 | % Electric Vehicles EV (to do) 164 | %.. 165 | EVav=zeros(Del.NDn,1); 166 | 167 | % Storages (ST) 168 | STPav=DGmdl.Power_ST(Del.NDn); % available power from storages 169 | STPav = STPav.*NETmecst(:,5).*x(:,5); % remove failed comp and use allocation matrix 170 | 171 | %Matrix of electric power Available 172 | NETPavM = [MSPav PVPav WPav EVav STPav].*[ones(Del.NDn,1) Del.pckg(ones(Del.NDn,1), 1:4 )]; 173 | 174 | Del.NDn=8; % number of nodes 175 | Del.FDn=7; % number of feeders (links between the nodes) 176 | Del.FDks=[1;2;3;4;8;5;6]; % start node 177 | Del.FDke=[2;3;4;8;5;6;7]; % end node 178 | Del.FDAmp=[400;400;400;400;400;400;400]; % Ampacity [A], maxiumum current a cable can carry without exceeding its thermal limit 179 | 180 | % Nodes parameters (generators positions and propreties 181 | Del.MSn=3; % number of main generator sources 182 | Del.MStyp=[1;2;1]; % Generators Type: one is Gas Turbine(2) and two is-steam Turbines (1) 183 | Del.MSnod=[2,7,8]; % nodes where the main generating sources are located 184 | Del.DGtn=4; % 185 | 186 | % links (power cables) parameters 187 | Del.FDX=0.08; % Reactance [Ohm/km] 188 | Del.FDR=0.164; % Resistance [Ohm/km] 189 | Del.Lengths=[260;170;230;320;200;160;260]; % Lenght of the links 190 | 191 | % Nodes parameters (random power demanded, produced and base voltage) 192 | Del.muLDth=[0.2;0;0.5;0.5;0.2;0.2;0;0]; % mean Load Demand 193 | Del.stdLDth=[0.02;0;0.05;0.05;0.02;0.02;0;0]; % standard deviation of the Demand 194 | Del.MSmu=[20;10;20]; % mean power produced by the main generators 195 | Del.MSsig=[2;1;2]; % standard deviation of the power produced by the main generators 196 | Del.Vnom=11; % base voltage in [kV] 197 | 198 | % Cost data 199 | Del.Cm=[1.3;1/0.79]; % Cost for Gas Turbine(2) and two is-steam Turbines (???) 200 | Del.MSCo=0.1450; % Main Generators operational cost 201 | Del.PVCo=3.7670e-05; % Potovolt operational cost 202 | Del.WCo=0.0390; % Wind Turbine operational cost 203 | Del.EVCo=0.0210; % El Vehicles operational cost 204 | Del.STCo=4.6284e-5; % Storage operational cost 205 | Del.VGCo=1e9; % Virtual generators operational cost 206 | Del.Z=8.1; % t.b.d. 207 | Del.MScap=[40;40;50]; % t.b.d. 208 | 209 | % Distributed generators data and production cost 210 | Del.pckg=[50,1,1,50];% pakaging factors 211 | Del.VGcap=10000; % Virtual generators capacity (virtually inf) 212 | Del.ts=1; % 1-h simulation time step 213 | 214 | Del.STn=1; % 215 | Del.STEs=0.04; % 216 | Del.STPpeak=0.2800; % 217 | 218 | Del.PVn=1; % 219 | Del.PVTa=30; % 220 | Del.PVTno=43; % 221 | Del.PVIsc=1.8; % 222 | Del.PVItc=1.4;% 223 | Del.PVVoc=55.5; % 224 | Del.PVVtc=194;% 225 | Del.PVVPmax=38;% 226 | Del.PVIPmax=1.32;% 227 | Del.EVPp=6.73;% 228 | Del.SCn=300;% 229 | Del.Inc=0.0240; % 230 | Del.MScm=1.3;% 231 | Del.SCn=7e2;% 232 | 233 | Del.WWSrated=9.5; % rated Wind 234 | Del.Eprice=@(L)-5.13717E-09*L^2+5.31538E-05*L; % price of the electricity from the total load demanded L 235 | 236 | %% Barry island: Load the Heat District Network data 237 | Temp=load('D.mat'); 238 | Dth=Temp.D.Dth; % load the structure of the 'thermal' network 239 | 240 | %% show topology of the two networks (not linked) 241 | figure 242 | G_th=graph(Dth.From_Node,Dth.To_Node); 243 | G_th.plot; 244 | hold on; grid on 245 | G_el=graph(Del.FDks,Del.FDke); 246 | G_el.plot 247 | legend('Thermal nodes', 'Electrical nodes') 248 | 249 | 250 | %% 1) Start With Electric Network Economic Dispatch 251 | % The Generators Allocation Matrix 252 | x=zeros(Del.NDn,Del.DGtn+1); 253 | x(Del.MSnod,1)=1; 254 | % the meccanical states 255 | FDmecst=ones(Del.FDn,1); %feeders meccanical state 256 | NETmecst=ones(Del.NDn,Del.DGtn+1); %feeders meccanical state 257 | % Loads 258 | LD=normrnd(Del.muLDth,Del.stdLDth); % MWel of the 5 lumped electrical loads 259 | % MS 260 | MSPp = normrnd(Del.MSmu, Del.MSsig); 261 | MSPav = MSPp(ones(Del.NDn,1),:); 262 | % DGs Storage systems (ST) 263 | ik=1; 264 | STlev = rand(Del.NDn, Del.STn).*Del.STEs(ones(Del.NDn,1),:); 265 | STPav = STP(STlev, x(:,1+ik), Del); 266 | STPav = STPav.*NETmecst(:,1+ik); 267 | % MCHP 268 | % DGPav=[..Pav MCHPav STPav] 269 | DGPav=x(:,2:end); 270 | NETPavM=[MSPav DGPav]; %Matrix of electric power Available 271 | [Pgen,ENS, NETminCo, PNETu, PDGu, ef] = OPF(x, NETPavM, LD, FDmecst, Del); 272 | PowTh=PowEl2PowTh(Pgen,Del); 273 | 274 | 275 | 276 | 277 | -------------------------------------------------------------------------------- /HPP.m: -------------------------------------------------------------------------------- 1 | %% HPP 2 | function T=HPP(lambda,Tmax) 3 | % lambda=input('Enter The lambda:'); % arrival rate 4 | % Tmax=input('Enter maximum time:'); % maximum time 5 | % clear T; 6 | T(1)= 0; 7 | i=1; 8 | 9 | while T(i) < Tmax, 10 | U(i)=rand(1,1); 11 | T(i+1)=T(i)-(1/lambda)*(log(U(i))); 12 | i=i+1; 13 | end 14 | 15 | T(i)=Tmax; 16 | end 17 | % 18 | % stairs(T(1:(i)), 0:(i-1)); 19 | % title(['A Sample path of the Poisson process with arrival rate ', num2str(lambda)]) 20 | % xlabel(['Time']) 21 | % ylabel(['Number of Arrivals in [0,', num2str(Tmax), ']',]) -------------------------------------------------------------------------------- /MC_HEATPOWER.m: -------------------------------------------------------------------------------- 1 | function [RES] = MC_HEATPOWER(X, D) 2 | % The Generators Allocation Matrix 3 | % the Data structure (contains 2 structures 1 for the heat and one for the 4 | % electrci network) 5 | Wea=D.Weather; % the electric network data 6 | Del=D.Del; % the electric network data 7 | Dth=D.Dth; % the heat network data 8 | % The decision variables 9 | x_el=X.x_el; % the DGs atrucutre (PV,WT,EV,ST) in the electric network 10 | x_th=X.x_th; % the DGs in the heat network 11 | %% Define a Distributed Generator Object 12 | % DGmdl=DG_module('D',Del); # --> not yet available, need flexible constructor 13 | DGmdl=DG_module(); 14 | %% Scenarios cycle 15 | [pdfENS, pdfCg,NETPav,NETuP, DGPu, ef] = deal(zeros(Del.SCn,1)); 16 | [nENS] = deal(zeros(Del.SCn,Del.NDn)); 17 | tic 18 | % random initial time state 19 | mnth = randi(12); % the random month of the year 20 | day = 1; 21 | td = randi(24); % random hour of the day td 22 | %% Generate weather History 23 | % ITot clear sky irradiance 24 | % ws is the wind speed profile [m/s] 25 | % Beta distributed solar irradiance [kW/m^2] the total 'real' irradiance 26 | long=-3.27; % Barry Island UK Longitude 27 | lat=51.3; % Barry Island UK Latitude 28 | [ITot,ws,~,~]=Weather_Simulator(Del.SCn,long,lat,mnth*day); 29 | s=betarnd(Wea.PVa(1) , Wea.PVb(1),size(ITot)).*ITot; 30 | Weather.s=s; % save weather samples 31 | Weather.ws=ws;% save weather samples 32 | 33 | 34 | for i = 1:Del.SCn 35 | 36 | % try a time-sequential simulation of the system state 37 | td=td+1; % add 1 h 38 | if td>24; td=1;day=day+1; end 39 | if day>30; day=1; mnth=mnth+1; end 40 | if mnth>12; mnth=1; end 41 | 42 | % mnth = randi(12); % the random month of the year 43 | % td = randi(24); % random hour of the day td 44 | %% The Meccanical State of the component 45 | % to include failures change a state from 1 to 0 46 | FDmecst=ones(Del.FDn,1); % meccanical state of the cables (1= healthy) 47 | NETmecst=ones(Del.NDn,Del.DGtn+1); % meccanical state of the generators (1= healthy) 48 | 49 | %% A simple failure model 50 | D.GenFailRates=[0.01 0.05 0.05 0.05 0.05]; % failure probability generators (probability of 1 --> 0 in 1-h) 51 | D.FDFailRates= 0.01; % failure probability links 52 | D.GenRecoveryRates= [0.6 0.3 0.3 0.3 0.3]; % recovery probability generators (probability of 0 --> 0 in 1-h) 53 | D.FDRecoveryRates= 0.8; % recovery probability links 54 | [FDmecst,NETmecst]=MarkovFailure(FDmecst,NETmecst,D); 55 | MecStates.FDmecst(i,:)=FDmecst; 56 | MecStates.NETmecst(i,:)=NETmecst(:); 57 | %% Random electric and thermal loads 58 | % electric loads 59 | LDel = normrnd(Del.muLDel(:,td).*1.5, Del.stdLDel(:,td)); % in [KWel] 60 | LDel(LDel<0)=0; 61 | % thermal loads 62 | LDth = normrnd(Dth.LDth(:,td).*1.5,(Dth.LDth(:,td).*1.5)/20); % expressed in [KWth] 63 | LDth(LDth<0)=0; 64 | LDtots.el(i)=sum(LDel); 65 | LDtots.th(i)=sum(LDth); 66 | %% Main supply generators 67 | MSpow=Del.MSmu; % this can be the control variable 68 | % MSpow = normrnd(Del.MSmu, Del.MSmu/10); % random power generated by the main sources 69 | MSPav = MSpow.*NETmecst(:,1).*x_el(:,1); 70 | % random external temperature conditioanl to month 71 | Text=normrnd(Wea.muText(mnth),Wea.stdText(mnth)); % external environmental conditions 72 | Weather.Text(i)=Text; 73 | %% Power DGs 74 | % PV 75 | PVPav=DGmdl.Power_PV(s(i),Text,Del.NDn); % available power from PV pannles 76 | PVPav = PVPav.*NETmecst(:,2).*x_el(:,2); 77 | % WT 78 | WPav=DGmdl.Power_WT(ws(i),Del.NDn); % available power from wind turbines 79 | WPav = WPav.*NETmecst(:,3).*x_el(:,3); 80 | 81 | % ST 82 | STPav=DGmdl.Power_ST(Del.NDn); % available power from storages 83 | STPav = STPav.*NETmecst(:,5).*x_el(:,4); 84 | 85 | %% Heat generated by Heat Pumps (function of the extenral tamperature) 86 | Twater=35; % target water temperature 87 | % [P_onoffhp,COPdc_onoffhp]=OnOff_HP(Text,Twater); 88 | [P_onoffhp,COPdc_onoffhp]=DGmdl.Power_HP_OnOff(Text,Twater); 89 | % [P_idhp,COPdc_idhp]=ID_HP(Text,Twater,psi); 90 | % Ncomp=randi(2); [P_mchp,COPdc_mchp]=MC_HP(Text,Twater,Ncomp); 91 | HPav=P_onoffhp.*x_th; 92 | Lel_onoffhp=HPav./COPdc_onoffhp; 93 | Lel_onoffhp(isnan(Lel_onoffhp))=0; 94 | LDel=LDel+Dth.LumpedThLoadsMatrix*Lel_onoffhp; 95 | 96 | %% Simple Power-Heat-Balance 97 | % solve flow-pression equations for the heat network 98 | NeededPowTh=(LDth-HPav); % the thermal power needed is the load - HP available from the Heat Pumps 99 | NeededPowTh(NeededPowTh<0)=0; % if there is a thermal production excedence, then it goes wasted!! 100 | % assume 100% efficent (if is an electric backup system is quite colose to 100%) 101 | LDelbackup= (Dth.LumpedThLoadsMatrix*(NeededPowTh)); 102 | LDel=LDel+ LDelbackup./Del.MScm; % MScm conversion efficiency 103 | LDtots.th_to_elbackup(i)=sum(LDelbackup./Del.MScm); 104 | LDtots.LumpedThLoads(i)=sum(Dth.LumpedThLoadsMatrix*Lel_onoffhp); 105 | %% Run an OPTIMAL Power Flow, Here we have the Network Solver 106 | NETPavM = [MSPav PVPav WPav STPav].*[ones(Del.NDn,1) Del.pckg(ones(Del.NDn,1),[1:2,4])]; %Matrix of electric power Available 107 | NETPav(i) = sum(sum(NETPavM)); % Total available power produced 108 | DGPp(i,:) = sum(NETPavM(:, 2:end));% Total production for each generator type 109 | [Pgenerators(i,:) ,pdfENS(i), NETminCo, NETuP(i), DGPu(i), nENS(i,:), ef(i)] = OPF(x_el, NETPavM, LDel, FDmecst, Del); 110 | 111 | %% Cost Model 112 | %ep= electricity price is a function of the electric load 113 | %NETCi= investment costs (fixed for x) prorated in thn years 114 | %NETminCo= operational cost of the electrical network 115 | %inc_th= incentives for producing clean thermal power (ASHP 2.61p/kWh incentive in pounds 2017 UK) 116 | %Del.Inc= incentives for producing clean electric power in p/kWh 117 | inc_th=0.0261; 118 | ep = Del.Eprice(sum(LDel)); 119 | DGCi = Del.DGCi.*Del.pckg; 120 | NETCi = (sum(sum(x_el).*[Del.MSCi DGCi([1:2,4])])+sum(x_th)*Dth.Cost_onoff)/(365*24*Del.thn); 121 | HPPowused=sum(LDth-NeededPowTh); 122 | NetGainDG_el=(Del.Inc + ep)*(DGPu(i))*Del.ts; % gain from producing renwable electric Energy 123 | NetGainDG_th= inc_th*HPPowused*Del.ts; % gain from producing renwable electric Energy 124 | pdfCg(i) = NETCi + NETminCo + - NetGainDG_el - NetGainDG_th; 125 | % try to add a cost of the energy not supplied (which must be bought from the grid at a cost ep) 126 | pdfCg(i) = pdfCg(i) + pdfENS(i)*ep; 127 | 128 | %% Incentives 2017 UK 129 | % ASHP 2.61 p/kWh 130 | % NETPpM = [MSPp PVPp WPp EVPp STPp].*[ones(D.NDn,D.MSn) D.pckg(ones(D.NDn,1),:)]; 131 | % NETPp(i) = sum(sum(NETPpM)); 132 | % DGPavM = NETPavM(:, 2:end); 133 | % DGPav(i) = sum(sum(DGPavM)); 134 | % TLD(i) = sum(LDel); 135 | end 136 | 137 | pdfCg(isnan(pdfCg))=[];% get rid of the NaN simulations 138 | pdfENS(isnan(pdfENS))=[];% get rid of the NaN simulations 139 | 140 | Pgenerators(isnan(pdfENS),:)=[]; 141 | RES.pdfPgenerators=Pgenerators; % power 142 | RES.NETPav=NETPav; 143 | RES.pdfnENS=nENS; % Enrgy not supplied per node 144 | RES.pdfDGP_RES=DGPu; % Total renewable power electric used 145 | RES.pdfNETuP=NETuP; % real used power in the net 146 | RES.pdfDGPp=DGPp; % real used power of the dgs 147 | RES.pdfLDel=LDtots; % total electric thermal and combined loads 148 | RES.pdfENS=pdfENS; 149 | RES.pdfCg=pdfCg; 150 | RES.Weather=Weather; % samples of the weather 151 | RES.MecStates=MecStates;% save mechanical states 152 | % Some statistics 153 | RES.EENS=mean(pdfENS); 154 | RES.ECg=mean(pdfCg); 155 | RES.CovENS=std(pdfENS)/RES.EENS; 156 | RES.CovCg=std(pdfCg)/RES.ECg; 157 | Alpha=0.95*100; 158 | RES.p95ENS=prctile(pdfENS,Alpha); 159 | RES.p95Cg=prctile(pdfCg,Alpha); 160 | RES.Supequantile95_ENS=mean(pdfENS(pdfENS>=prctile(pdfENS,Alpha))); 161 | RES.Supequantile95_ENSCg=mean(pdfCg(pdfCg>=prctile(pdfCg,Alpha))); 162 | end -------------------------------------------------------------------------------- /MarkovFailure.m: -------------------------------------------------------------------------------- 1 | function [FDmecst,NETmecst] = MarkovFailure(FDmecst, NETmecst, D) 2 | apply_random_failure_model = 0; 3 | if apply_random_failure_model==1 % recovery model to be implemented 4 | % Mechanical states of nodes --> 0 failure --> 1 operative 5 | NETmecst=zeros(D.Del.NDn,D.Del.DGtn+1); % generators meccanical states are all healthy 6 | NETf = D.GenFailRates; 7 | %NETr = D.GenRecoveryRates; 8 | %ppt = NETf./(NETf+NETr); 9 | NETrnd = rand(D.Del.NDn, D.Del.DGtn+1); 10 | NETmecst(NETrnd> NETf) = 1; 11 | %NETmecst(find((x~=0).*NETrnd > (x~=0).*ppt(ones(D.Del.NDn,1),:))) = 1; 12 | 13 | % Feeders mecanical state --> 0 failure --> 1 operative 14 | FDmecst = zeros(D.Del.FDn,1); 15 | FDmecst(rand(D.FDn, 1) > D.FDFailRates) = 1; 16 | 17 | else % example - all feeders and busses are operative 18 | FDmecst=ones(D.Del.FDn,1); % feeders meccanical states are all healthy 19 | NETmecst=ones(D.Del.NDn,D.Del.DGtn+1); % generators meccanical states are all healthy 20 | end 21 | 22 | end -------------------------------------------------------------------------------- /NHPP.m: -------------------------------------------------------------------------------- 1 | %% NHPP 2 | function NHPP(lambda,Tmax) 3 | lambda=input('Enter The arrival Rate:'); % arrival rate 4 | Tmax=input('Enter maximum time:'); % maximum time 5 | clear T; 6 | T(1)= 0; 7 | a=input('Enter constant a>0:'); 8 | b=input('Enter constant b<1:'); 9 | S(1)=0; 10 | i=1; 11 | 12 | while T(i) < Tmax, 13 | U(i)=rand(1,1); 14 | T(i+1)=T(i)-(1/lambda)*(log(U(i))); % Homogeneous Poisson Distr. 15 | lambdat=a*(T(i+1))^(-b); 16 | u(i)=rand(1,1); 17 | if u(i)<=lambdat/lambda % <-- Here is my doubt/question 18 | i=i+1; 19 | S(i)=T(i); % <-- Here is my doubt/question 20 | end 21 | end 22 | stairs(S(1:(i)), 0:(i-1)); 23 | title(['A Sample path of the non homogeneous Poisson process']); 24 | xlabel(['Time interval']); 25 | ylabel([' Number of event ']); -------------------------------------------------------------------------------- /OPF.m: -------------------------------------------------------------------------------- 1 | function [Pgen,ENS, NETminCo, PNETu, PDGu, nENS, ef] = OPF(x, NETPavM, LD, FDmecst, D) 2 | %% OPF.m: Optimal power flow function considering virtual generators 3 | % 4 | % Inputs 5 | % x: allocation matrix for the distributed generators 6 | % NETPavM: power available in the net 7 | % LD: loads 8 | % FDmecst: mechanical states of the feeders 9 | % D: struct with the needed data for the evaluation of fns 10 | % Output 11 | % ENS: Energy Non Supplied 12 | % NETminCo: minimum operating cost of the net 13 | % PNETu: real used power in the net 14 | % PDGu: real used power of the dgs 15 | % ef: exitflag of the solver of the OPF 16 | % 17 | % OPF problem definition 18 | % 19 | % min NETco x xNET 20 | % s.t. 21 | % Ainq x xnet <= binq 22 | % Aeq x xnet = beq 23 | % lb <= x <= up 24 | % 25 | % xNET: decision vector of the minimization problem. Contains the 26 | % DGs, the virtual generators and the feeders present in 27 | % the network. The optimal gives the real power used from the 28 | % DGs, the load shedding (power virtualy generated to satify 29 | % the demand) and the power flow in the feeders. 30 | % binq: containts the max power available for each generator 31 | % (NETPavM) and the limit of power that is allowed to flow by each feeder 32 | % beq: is equal to the load in each node 33 | % _________________________________________________________________________ 34 | % 35 | % DEVELOPED BY 2112 inc. 36 | %__________________________________________________________________________ 37 | %% 38 | 39 | V0 = D.Vnom; % per unit Voltage 40 | S0 = D.Vnom.^2; % per unit Apparent power 41 | Z0 = (V0.^2)/S0; % per unit Impedance 42 | Xpu = D.FDX/Z0; % per unit Reactance 43 | Bpu = (-1./Xpu); % per unit Susceptance 44 | LD0 = LD/S0; % per unit Susceptance 45 | FDPlim = D.FDAmp*D.Vnom; % feeders power limit 46 | 47 | spx = sparse(x); % sparse x 48 | nzn = nnz(spx); % number of non-zeros elements in x 49 | xvg = [x ones(D.NDn,1)]; % adding the virtual generators to x 50 | spxvg = sparse(xvg); % sparse xvg 51 | nznvg = nnz(spxvg); % number of non-zeros elements in xvg 52 | 53 | % UNTIL THE MOMENT THE COSTS OF THE FEEDERS ARE NOT CONSIDERED 54 | 55 | MSco = D.MSCo(ones(D.NDn,1),:); 56 | DGco = [D.PVCo(ones(D.NDn,1),:) D.WCo(ones(D.NDn,1),:) D.STCo(ones(D.NDn,1),:)].*D.pckg(ones(D.NDn,1),1:3); 57 | % DGco = [D.PVCo(ones(D.NDn,1),:) D.WCo(ones(D.NDn,1),:) D.EVCo(ones(D.NDn,1),:) D.STCo(ones(D.NDn,1),:)].*D.pckg(ones(D.NDn,1),:); 58 | MS_DG_VGco = [MSco DGco D.VGCo(ones(D.NDn,1),:)]; % add virtual gen 59 | NETco = [MS_DG_VGco(find(spxvg)); zeros(D.FDn,1)]; % [MS_DG_VGco FDco] 60 | 61 | MS_DGAeq = zeros(D.NDn,nznvg); 62 | [i,~,~] = find(spxvg); 63 | MS_DGAeq(i+(((1:nznvg)')-1)*D.NDn) = 1; 64 | 65 | FDAeq = zeros(D.NDn,D.FDn); 66 | FDAeq(D.FDks+(((1:D.FDn)')-1)*D.NDn) = Bpu.*FDmecst; 67 | FDAeq(D.FDke+(((1:D.FDn)')-1)*D.NDn) = -Bpu.*FDmecst; 68 | 69 | Aeq = [MS_DGAeq, FDAeq]; 70 | beq = LD0; 71 | lb = [zeros(nznvg,1); FDPlim./Bpu]/S0; 72 | ub = [NETPavM(find(spx)); ones(D.NDn,1)*D.VGcap; - FDPlim./Bpu]/S0; 73 | 74 | % Solver 75 | Options.Display='off'; 76 | [xNET, fval, ef] = linprog(NETco', [], [], Aeq, beq, lb, ub, Options); 77 | if ef~=1 78 | xNET=NETco.*NaN; 79 | fval=NaN; 80 | end 81 | 82 | % outputs 83 | %fdP = xNET(nzn+D.NDn+1:end).*Bpu*S0; 84 | %Angle=fdP./(Bpu*S0); 85 | ENS = sum(xNET(1+nzn:nzn+D.NDn))*S0/D.ts; 86 | NETminCo = fval*S0-ENS*D.VGCo(1); 87 | PNETu = sum(xNET(1:nzn))*S0; 88 | Pgen=xNET(1:nzn).*S0; 89 | PDGu = sum(xNET(D.MSn+1:nzn+D.MSn-1,1))*S0; 90 | nENS = xNET(1+nzn:nzn+D.NDn)*S0; 91 | % nPnetr = xNET.*[ones(nzn,1);zeros(D.NDn,1);zeros(D.FDn,1)]*S0; 92 | % fdP = xNET.*[zeros(nzn,1);zeros(D.NDn,1);ones(D.FDn,1)]*S0; 93 | 94 | 95 | end 96 | -------------------------------------------------------------------------------- /PowEl2PowTh.m: -------------------------------------------------------------------------------- 1 | function PowTh=PowEl2PowTh(MGPgen,D) 2 | %% simple example model for converting residual thermal to electrical power demand 3 | Powelcon=0.6; % MWel power output of extration unit in full condensing mode 4 | Powthcon=0; % MWth power output of extration unit in full condensing mode 5 | PowTh=zeros(size(MGPgen)); 6 | PowTh(D.MStyp==1)=MGPgen(D.MStyp==1).*D.Cm; % gas turbines 7 | PowTh(D.MStyp==2)=(Powelcon-MGPgen(D.MStyp==2)).*D.Z+Powthcon; % steam turbines 8 | end -------------------------------------------------------------------------------- /STP.m: -------------------------------------------------------------------------------- 1 | function Pow = STP(STlev, kg, D) 2 | 3 | %Storage power output in kW 4 | 5 | STlev = STlev.*kg; 6 | Pow = STlev/D.ts; 7 | STPaux = D.STPpeak(ones(D.NDn,1),:).*kg; 8 | Pow(Pow > STPaux) = STPaux(Pow > STPaux); 9 | 10 | end 11 | -------------------------------------------------------------------------------- /TempMonteCarlo.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Roberock/Heat_and_Electric_powerNetwork/a442f6040a0888d8e8adc7ce14c582283eff5419/TempMonteCarlo.m -------------------------------------------------------------------------------- /Weather_Simulator.m: -------------------------------------------------------------------------------- 1 | function [ITot,V,Wind_Events,Lightning_Events]=Weather_Simulator(Tseries,long,lat,g) 2 | ITot=[]; V=[]; 3 | %% LIGHTNING OCCURRANCE 4 | %% sequence of HPP for Lightning (with multiple, constant occurance ratio) 5 | %SeasonsInt=[0 1400 2200 2900 3500 4300 5030 5800 6500 7200 8760]; % time of the year 6 | SeasonsInt=linspace(1,8760,13); % 12 months 7 | Light_occurance=[0 0 0.0005 0.0001 0.0085 0.019 0.022 0.015 0.002 0.001 0 0]; % frequency of occurance 8 | Lightning_Events=[]; 9 | for i=1:length(Light_occurance) 10 | Tlight=HPP(Light_occurance(i),SeasonsInt(i+1)-SeasonsInt(i)); 11 | Lightning_Events=[Lightning_Events Tlight(2:end-1)+SeasonsInt(i)]; 12 | end 13 | %% WIND 14 | Wind_occurane=[0.011 0.012 0.0075 0.0065 0.005 0.006 0.003 0.0029 0.0045 0.0065 0.006 0.009]; % frequency of occurance 15 | Wind_Events=[]; 16 | for i=1:length(Wind_occurane) 17 | Twind=HPP(Wind_occurane(i),SeasonsInt(i+1)-SeasonsInt(i)); 18 | Wind_Events=[Wind_Events Twind(2:end-1)+SeasonsInt(i)]; 19 | end 20 | %Transition data from Malaysian state 21 | %[] Shamshad et al. "First Order Markov Chain Models for Synthetic 22 | %Generation of Wind Speed Time Series" Energy, 2005, 10.1016/j.energy.2004.05.026 23 | 24 | % % wind speed upper and lower bound for the considered states 25 | Vl=[0 2 4 6 8 10 12 14 16 18 20 22]; 26 | Vu=[2 4 6 8 10 12 14 16 18 20 22 25]; 27 | 28 | %First order cumulative transition matrix 29 | Pwindcum=[... 30 | 0.371 0.778 0.952 0.988 0.997 0.998 0.999 1.000 1.000 1.000 1.000 1.000 31 | 0.166 0.612 0.924 0.983 0.995 0.999 0.999 1.000 1.000 1.000 1.000 1.000 32 | 0.051 0.294 0.798 0.961 0.989 0.997 0.999 1.000 1.000 1.000 1.000 1.000 33 | 0.017 0.100 0.403 0.794 0.954 0.989 0.997 0.999 1.000 1.000 1.000 1.000 34 | 0.010 0.045 0.144 0.421 0.803 0.960 0.991 0.998 0.999 1.000 1.000 1.000 35 | 0.006 0.027 0.070 0.178 0.473 0.816 0.962 0.993 0.997 1.000 1.000 1.000 36 | 0.005 0.021 0.048 0.095 0.205 0.507 0.831 0.973 0.994 0.998 1.000 1.000 37 | 0.006 0.022 0.052 0.085 0.140 0.267 0.632 0.871 0.976 0.998 1.000 1.000 38 | 0.009 0.028 0.042 0.060 0.102 0.167 0.307 0.633 0.902 0.981 0.995 1.000 39 | 0.014 0.068 0.123 0.137 0.164 0.192 0.233 0.438 0.726 0.890 0.973 1.000 40 | 0.000 0.000 0.000 0.040 0.040 0.040 0.120 0.240 0.400 0.640 0.920 1.000 41 | 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.200 0.200 0.400 1.000 1.000]; 42 | St=randi(12);%initial wind state 43 | [V]=zeros(1,Tseries); 44 | IT=zeros(round(Tseries/24),24); 45 | 46 | for t=1:Tseries 47 | %Random wind speed depending on the previous state 48 | V(t)=Vl(St)+rand()*(Vu(St)-Vl(St)); 49 | % new state random consistent with the transition probability 50 | St= find(Pwindcum(St,:) > rand(), 1, 'first') ; 51 | 52 | %% IRRADIANCE CLEAR SKY 53 | gnew=ceil(t/24);%day of the year 54 | if g~=gnew %if we are analyzing a new day 55 | g=gnew; 56 | [It]=Clear_Sky_IT(g,long,lat); % return clear sky total irradiance for h=1 to h=24 for given day, and given latitude and longitude 57 | IT(g,:)=It; 58 | end 59 | 60 | %% External Temperature 61 | 62 | end 63 | IT=IT'; 64 | ITot=IT(:)'; 65 | end 66 | -------------------------------------------------------------------------------- /figs/CombinedGridTopology.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Roberock/Heat_and_Electric_powerNetwork/a442f6040a0888d8e8adc7ce14c582283eff5419/figs/CombinedGridTopology.jpg -------------------------------------------------------------------------------- /figs/ExampleSimulationResults.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Roberock/Heat_and_Electric_powerNetwork/a442f6040a0888d8e8adc7ce14c582283eff5419/figs/ExampleSimulationResults.jpg -------------------------------------------------------------------------------- /figs/readme.rm: -------------------------------------------------------------------------------- 1 | ### Visualization examples for the simulation results 2 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # **Simulation Code for Combined Heat and Electric Networks** 2 | 3 | This repository contains MATLAB code for simulating various operational states of a combined heat and electricity network, integrating distributed generators and heat pumps. 4 | 5 | ## **📄 Citation** 6 | If you use this code, please cite the following: 7 | 8 | ```bibtex 9 | @INPROCEEDINGS{8272792, 10 | author={Rocchetta, Roberto and Patelli, Edoardo}, 11 | booktitle={2017 2nd International Conference on System Reliability and Safety (ICSRS)}, 12 | title={Stochastic analysis and reliability-cost optimization of distributed generators and air source heat pumps}, 13 | year={2017}, 14 | pages={31-35}, 15 | doi={10.1109/ICSRS.2017.8272792} 16 | } 17 | ``` 18 | 19 | 20 | ## ⚙️ Functionality 21 | 22 | ### Core Functions 23 | - **`MC_HP.m`** → Power production model for multi-compressor air-to-water heat pumps 24 | - **`OnOff_HP.m`** → Power model for an on-off air-to-water heat pump (Maneurop SH 140-4) 25 | - **`HPP.m`** → Samples from a homogeneous Poisson Process (HPP) 26 | - **`MarkovFailure.m`** → Simulates random failures of network components 27 | - **`MC_HEATPOWER(X, D)`** → Monte Carlo simulation of the combined network 28 | - `X`: Allocation matrix 29 | - `D`: Data structure containing grid information 30 | - **`DG_module.m`** → Simulates power production from distributed generators (PV, EV, ST, WT, HP) 31 | - **`Weather_Simulator.m`** → Simulates weather conditions based on geo-location and day of the year 32 | - **`PowEl2PowTh.m`** → Converts electrical power to thermal power 33 | - **`OPF.m`** → Optimal power flow function considering virtual generators 34 | - **`Clear_Sky_IT.m`** → Computes clear sky irradiance 35 | 36 | ### Data Structures 37 | - **`D.mat`** → Contains key grid data: 38 | - **`Del`** → Electrical grid data 39 | - **`Dth`** → Thermal grid data 40 | - **`Weather`** → Weather data for simulations 41 | 42 | --- 43 | 44 | ## 📌 Examples 45 | 46 | ### Example 1: Monte Carlo Simulation for Resilience Assessment 47 | This example evaluates reliability and resilience (energy not supplied distribution) using Monte Carlo simulations for a given allocation matrix. 48 | 49 | ```matlab 50 | Temp=load('D.mat'); % load data 51 | D = Temp.D; # all data in the structure D 52 | Del= Temp.D.Del; % electrical grid data 53 | Dth= Temp.D.Dth; % thermal grid data 54 | Wtr= Temp.D.Weather; % weather data 55 | ``` 56 | 57 | 58 | ```matlab 59 | %% show topology of the two networks (not linked and separatelly) 60 | figure(10) 61 | G_th=graph(D.Dth.From_Node,D.Dth.To_Node); 62 | G_th.plot; 63 | hold on; grid on 64 | G_el=graph(D.Del.FDks,D.Del.FDke); 65 | G_el.plot 66 | legend('Thermal nodes', 'Electrical nodes') 67 | ``` 68 | 69 |

70 | Size Limit CLI 71 |

72 | 73 | 74 | 75 | ```matlab 76 | % Electrical allocation matrix (MS, PV, WT, EV, ST) 77 | # MainSources PhotoV WindT ElVehicle StorageUnits 78 | x_el = [0,11, 0,0,13; % Node 1 79 | 1, 0,11,0, 1; % Node 2 80 | 0,11,23,0,10; % Node 3 81 | 0, 0,11,0,21; % Node 4 82 | 0,11, 0,0,11; % Node 5 83 | 0, 0, 0,0, 2; % Node 6 84 | 1,11,11,0, 0; % Node 7 85 | 1,11,11,0,11]; % Node 8 86 | 87 | # Aggregated Number of HeatPumps at the electrical nodes 88 | x_th = [5; % Node 1 89 | 0; % Node 2 90 | 0; % Node 3 91 | 0; % Node 4 92 | 0; % Node 5 93 | 14; % Node 6 94 | 0; % Node 7 95 | 0]; % Node 8 96 | 97 | X_candidate = [x_el, x_th]; 98 | ``` 99 | 100 | 101 | ```matlab 102 | % Run Monte Carlo simulation for data structure D and thermal-electrical allocation 103 | 104 | [RES] = MC_HEATPOWER(X_candidate, D); 105 | ``` 106 | 107 | 108 |

109 | 110 |

111 | 112 | 113 | --------------------------------------------------------------------------------