from __future__ import division
#To Determine the Demand and Supply Parameters for 15 bulbs
W=60 #Wattage of the bulb
N=15 #No. of bulbs
CL=W*N #Connected Load
Wih=2*(10**3) #Wattage of immersion heater
Wh=2*(10**3) #Wattage of heater
#Usage of Bulbs at different time periods
N1=5
N2=10
N3=6
#Time periods for bulbs
T1=2 #6pm - 8pm
T2=2 #8pm - 10pm
T3=2 #10pm - 12pm
#Time Periods for heaters
T4=4 #1pm - 5pm
T5=3 #8pm - 11pm
#CASE 1
MD1=W*N2 #Maximum Demand
DF=MD1*100/CL #Demand Factor
EC1=(N1*W*T1)+(N2*W*T2)+(N3*W*T3) #Energy Consumed
DLF1=EC1*100/(24*MD1) #Daily Load Factor
#CASE 2
MD2=(W*N2)+Wh #From 8pm - 10pm
EC2=(T4*Wih)+(T5*Wh)+EC1 #Energy Consumed
DLF2=EC2*100/(24*MD2) #Daily Load Factor
print '''i)a) Connected Load is %g W
b) The Maximum Demand is %g W
c) The Demand Factor is %0.2f percent
d) The Daily Load Factor is %g percent'''%(CL,MD1,DF,DLF1)
print 'ii) The Improved Daily Load Factor is %0.2f %%'%DLF2
#To determine the Demand and supply parameter of four consumers
#Maximum Demands of various users
MD1=2*(10**3) #9pm
MD2=2*(10**3) #12 noon
MD3=8*(10**3) #5pm
MD4=4*(10**3) #8pm
MDT=MD1+MD2+MD3+MD4 #Sum of all Maximum Demands
#Demands of various users
D1=1.6*(10**3) #8pm
D2=1*(10**3) #8pm
D3=5*(10**3) #8pm
#The Number after the Alphabets represents the Consumer
#Maximum Demand of the System arises at 8.00 PM
MDS = D1+D2+D3+MD4
TDF=MDT/MDS #Diversity Factor
#Given Values
#Average Loads
AL2=500
AL4=1000
#Load Factors
LF1=15/100
LF3=25/100
#Calculated Values
#Average Loads
AL1=LF1*MD1
AL3=LF3*MD3
#Load Factors
LF2=AL2*100/MD2
LF4=AL4*100/MD4
ALS=AL1+AL2+AL3+AL4 #Combined Average Loads
LFS=ALS*100/MDS #Combined Load Factor
print 'i) The Diversity Factor is %0.3f '%TDF
print 'ii) The Average load and Load factor of:'
print ' Consumer 1 : %g kW and %g %%'%(AL1/1000,LF1*100)
print ' Consumer 2 : %g kW and %g %%'%(AL2/1000,LF2)
print ' Consumer 3 : %g kW and %g %%'%(AL3/1000,LF3*100)
print ' Consumer 4 : %g kW and %g %%'%(AL4/1000,LF4)
print 'iii) The Combined Load Factor and The Combined Average Load is %0.2f percent and %0.2f kW respectively'%(LFS,ALS/1000 )
#To Determine the Yearly Cost of the substation
Teff=95/100 #Transmission Efficiency
Deff=85/100 #Distribution Efficiency
DFT=1.2 #Diversity Factor For Transmission
DFD=1.3 #Diversity Factor For Distribution
MDGS=100*(10**6) #Maximum Demand of Generating Station
ALF=40/100 #Annual Load Factor
ACCT=2.5*(10**6) #Annual Capital Charge for Transmission
ACCD=2*(10**6) #Annual Capital Charge for Distribution
GCC=100 #Generating Cost per KW demand
GCCU=5/100 # Per Unit Cost
#Fixed Charges from Supply to Substation Annually
GFC=GCC*MDGS/1000 #Generating
TFC=ACCT #Transmission
TotFCS=GFC+TFC #Total
#Fixed Charges for supply upto Consumer Annually
DFC=ACCD #Distribution
TotFCC=TotFCS+DFC #Total
AMDS= DFT*MDGS/1000 #Aggregate of Maximum Demand at Supply
AMDC= DFD*AMDS #Aggregate of Maximum Demand for Consumers
FCS=TotFCS/AMDS #Fixed Charges Per KW at substation
CES=GCCU/Teff #Cost of energy at the substation
FCC=TotFCC/AMDC #Fixed Charges per KW at the consumer premises
CEC=CES/Deff #Cost of Energy at the consumer premises
print 'The Yealy Cost per KW demand and the cost per KWhr at:'
print 'a) The substation is %0.2f rupees per KW and %0.2f paise per KWhr'%(FCS,CES*100)
print 'b) The consumer premises is %g rupees per KW and %0.1f paise per KWhr'%(FCC,CEC*100)
#To determine the Load factor and suitable units for 24 hr operation of the plant
#Demands at Various Time Periods starting from 12PM to 12PM
D1=500*(10**3)
D2=800*(10**3)
D3=2000*(10**3)
D4=1000*(10**3)
D5=2500*(10**3)
D6=2000*(10**3)
D7=1500*(10**3)
D8=1000*(10**3)
MD=D5 #Maximum Demand
#Time Periods of demands ststing from 12PM
T1=5
T2=5
T3=2
T4=2
T5=3
T6=3
T7=2
T8=2
#Total Energy Demand in 24hrs
TED=(T1*D1)+(T2*D2)+(T3*D3)+(D4*T4)+(T5*D5)+(D6*T6)+(D7*T7)+(T8*D8)
LF=TED*100/(24*MD)
print '''Since Maximum Demand is 2500 kW,
2 units 0f 1000W and one unit of 500W is required.
Also for continuity of supply, A reserve of 1000W unit is required.'''
C1000=3*1000*(10**3) #1000 unit
C500=1*500*(10**3) #500 Unit
TCP=C1000+C500 #Total capacity of the plant
PCF=TED*100/(24*TCP) #Plant Capacity Factor
#Operating Schedule, Units operated can be seen in the textbook
G1=500*(10**3)
G2=1000*(10**3)
G3=2000*(10**3)
G4=1000*(10**3)
G5=2500*(10**3)
G6=2000*(10**3)
G7=1500*(10**3)
G8=1000*(10**3)
TEG=(T1*G1)+(T2*G2)+(T3*G3)+(G4*T4)+(T5*G5)+(G6*T6)+(G7*T7)+(T8*G8) #Total Energy Generated
PUF=TED*100/(TEG) #Plant Use Factor
print 'a) The Reserve Capacity is a 1000kW Unit and Load Factor is %0.2f percent'%LF
print 'b) The Plant Capacity Factor is %0.2f percent'%PCF
print 'c) The Plant Use Factor is %0.2f percent'%PUF
#To determine the Plant use factore of each unit
MDS=25*(10**6) #Maximum Demand on the System
U1=15*(10**6) #Load Supplied By Unit 1
U2=12.5*(10**6) #Load Supplied By Unit 2
#Running Time Factor of the Unit
T1=1
T2=40/100
#Energy generated by each unit
E1=1*(10**8)
E2=1*(10**7)
Et=E1+E2 #Total Energy
#Maximum Demands on Each Units
MD1=U1
MD2=MDS-U1
#Annual Load Factor for the Units
ALF1=E1*1000*100/(MD1*8760)
ALF2=E2*1000*100/(MD2*8760)
LF2=E2*1000*100/(MD2*0.4*8760) #Load Factor for the it is loaded
#Since Unit runs all through the year without any reserve, Load Factor ,Plant Use Factor and Plant Capacity Factor are the same
PUF1=ALF1 #Plant Use Factor
PCF1=ALF1 # Plant Capacity Factor
PCF2=E2*1000*100/(U2*8760) #Plant Capacity Factor for Unit 2
PUF2=E2*1000*100/(U2*0.4*8760) #Plant Use Factor for Unit 2
LFP=Et*100*1000/(MDS*8760) #Annual Load Factor of the Complete Plant
print 'The Load Factor, Plant Capacity Factor, Plant Use Factor of: '
print 'Unit 1 : %g percent, %g percent, %0.2f %%'%(ALF1,PCF1,PUF1)
print 'Unit 2 : %g percent, %g percent, %0.2f %%'%(ALF2,PCF2,PUF2)
print 'The Annual Load Factor of the Entire Plant is %0.2f %%'%(LFP)
#To determine the Overall cost per kWhr
# C1 =(100,000 rupees + 100 rupees/kW + 6 paise /kWhr) #Base Load Station
# C2 =(80,000 rupees + 60 rupees/kW + 8 paise /kWhr) #Peak Load Station
MaxD=15*(10**6)
MinD=5*(10**6)
BLS=lambda b,c:100000+(b*100)+((6/100)*c) #Function to Find Annual Cost of Base Load Station.
PLS = lambda b,c:80000+(b*60)+((8/100)*c) #Function to Find Annual Cost of Peak Load Station.
a1=100
a2=60
b1=6/100
b2=8/100
Tpeak=(a1-a2)/(b2-b1) #Number of hours the peak plant should operate
#From the straight line annual load duration curve, Maximum Demand at Peak Load Station can be calculated
MDP=Tpeak*(MaxD-MinD)/8760
TotEG=(MaxD+MinD)*8760/(2*1000) #Total Energy Generated
EGP=MDP*Tpeak/(2*1000) #Energy Generated by Peak Load
EGB=TotEG-EGP #Energy Generated by Base Load
MDB=MaxD-MDP #Maximum Demand at the Base Load
#Total Annual Cost of Base Load and Peak Load Stations Respectively
C1=BLS((MDB/1000),EGB)
C2=PLS((MDP/1000),EGP)
TotC=C1+C2 #Total Cost of both the plants
CE=TotC*100/TotEG #Cost of energy in paise per kWhr
print 'The Operating Scedule of Peak Load Station for Minimum Annual Cost is %g hours'%Tpeak
print 'The Overall Cost per kWhr is %0.1f paise'%CE
#To determine the amount saved to replace the equipment
Pc=80000 #Plant Cost
UL= 15 #Useful Life of the Plant
SVE=5000 #Salvage Value of the Equipment
r=5/100 #Compound Interest Rate
A1=(Pc-SVE)/UL #Annual Amount to be saved using straight line method
A2=(Pc-SVE)*r*100/(100*(((1+r)**UL)-1))# Annual Amount to be saaved using Sink Fund Method
print 'i) The Amount to be Saved Annually according to straight line method is %g Rupees'%(A1)
print 'ii) The Amount to be Saved Annually according to sink fund method is %g Rupees'%(A2)
#To Obatin a two part tariff for the consumers
EG=390*(10**6) #Energy Generated in kWhr
MD=130*(10**6) #Maximum Demand of the Supply
SCeff=90/100 #The Amount of energy transferred from Substation to Consumer
#Total Cost for Each Division
Fuel=5*(10**6)
Gen=2.4*(10**6)
Trans=5*(10**6)
Dist=3.4*(10**6)
Tot=Fuel+Gen+Trans+Dist #Total Cost
Runcost = lambda y,z:(y*z/100) #Function to Find out the Running Costs
#Running Costs
Fuelr=Runcost(90,Fuel)
Genr=Runcost(10,Gen)
Transr=Runcost(5,Trans)
Distr=Runcost(7,Dist)
Totr=Fuelr+Genr+Transr+Distr #Total Cost
FixCost=Tot-Totr # Fixed Cost
FixChar=FixCost*1000/MD #Fixed Charges per KW
EnChar=Totr*100/(EG*SCeff) #Energy Charges in Paise for Consumer
OverCost=Tot*100/(EG*SCeff) #Overall Energy Charges
LF=40/100 #Load Factor Raised to 40%
EG1=LF*MD*8760/1000 #Energy Generated for Different Load Factor
Totr1=Totr*(EG1/EG) #Cost of Energy Generated
Tot1=FixCost+Totr1 #Total Cost for the New Load Factor
OverCost1=Tot1*100/(EG1*SCeff) #Overall Energy Charges
Saving=(OverCost-OverCost1)*100/OverCost #Percentage Saving in the Overall Cost per kWhr
print 'The Fixed Charges is %0.2f rupees per kW'%FixChar
print 'The Energy Charges for the Consumer is %0.3f paise per kWhr '%(EnChar)
print '''IF the Load Factor is raised to 40percent of the Same Maximum Demand,
then the percentage saving in the overall costs is %0.2f percent'''%Saving
import numpy as np
#To determine the most economic power factor
P=200*(10**3) #Maximum Demand
pf=0.707 #Power Factor Lagging
a=100 #Tariff per kVA per year
b=200 #Power factor improvement cost Per kVA.
r=20 #Interest Depriciation, maintenance and cost of losses amount to 20% of capital cost per year
# Economic PF = sqrt(1-((b1/a)**2))
b1=r*b/100 # b' term accrding to the equation above
pfeco=np.sqrt(1-((b1/a)**2)) #Economic Power Factor
print 'The Economic Power Factor is %0.4f'%pfeco