def createAggregateDemand(self): #------------------------------------------------------------------------------ logTrack("Processes (createAggregateDemand): Creating time and temperature dependent heat demand") dlg = DialogGauge(Status.main,_("Time dependent aggregate heat demand"),_("generate demand profile")) (projectData,generalData) = Status.prj.getProjectData() Status.HPerDayInd = projectData.HPerDayInd if Status.processData.outOfDate == False: logTrack("Processes (createAggregateDemand): WARNING - someone wants to create demand profile which is already up to date") if Status.processData.outOfDateYearly == True: logTrack("Processes (createAggregateDemand): creating yearly demand UPHk(T)") self.createYearlyDemand() if Status.schedules.outOfDate == True: logTrack("Processes (createAggregateDemand): creating process schedules") Status.schedules.create() processes = Status.prj.getProcesses() UPH_Tt = [] UPHw_Tt =[] UPHTotal_Tt = Status.int.createQ_Tt() UPHwTotal_Tt = Status.int.createQ_Tt() NK = len (processes) i = 0 for process in processes: k = process.ProcNo - 1 UPH_Tt.append(Status.int.createQ_Tt()) UPHw_Tt.append(Status.int.createQ_Tt()) scheduleC = Status.schedules.procInFlowSchedules[k] scheduleM = Status.schedules.procOpSchedules[k] scheduleS = Status.schedules.procStartUpSchedules[k] scheduleW = Status.schedules.procOutFlowSchedules[k] NT = Status.NT Nt = Status.Nt for it in range(Nt): time = Status.TimeStep*it fC = scheduleC.fav[it] fM = scheduleM.fav[it] fS = scheduleS.fav[it] fW = scheduleW.fav[it] for iT in range(NT+2): #NT + 1 + 1 -> additional value for T > Tmax UPH_Tt[k][iT][it] = Status.int.UPHc_T[k][iT]*fC +\ Status.int.UPHm_T[k][iT]*fM +\ Status.int.UPHs_T[k][iT]*fS UPHw_Tt[k][iT][it] = Status.int.UPHw_T[k][iT]*fW UPHTotal_Tt[iT][it] += UPH_Tt[k][iT][it] UPHwTotal_Tt[iT][it] += UPHw_Tt[k][iT][it] i += 1 dlg.update(90.0*i/NK) Status.int.UPH_Tt = UPH_Tt Status.int.UPHw_Tt = UPHw_Tt Status.int.UPHTotal_Tt = UPHTotal_Tt Status.int.UPHwTotal_Tt = UPHwTotal_Tt #.............................................................................. # set status-flag (required BEFORE call to runHRModule !!!) Status.int.cascadeUpdateLevel = 0 #indicates that demand profile is created !!! Status.processData.outOfDate = False #.............................................................................. # estimate equipment waste heat from annual QWHj and equipment schedules equipments = Status.prj.getEquipments() Status.int.QWHEqTotal_Tt = Status.int.createQ_Tt() Status.int.QWHEqTotal_T = Status.int.createQ_T() Status.int.QWHEqTotal_t = Status.int.createQ_t() Status.int.QWHEqTotal = 0 for equipe in equipments: j = equipe.EqNo - 1 schedule = Status.schedules.equipmentSchedules[j] NT = Status.NT Nt = Status.Nt # temperature distribution of waste heat. assumed as fix TExhaustGas = equipe.TExhaustGas if TExhaustGas == None: logDebug("Processes: Equipment exhaust gas temperature not specified. 200 ºC assumed") TExhaustGas = 200 # print "Process (calcAggDemand): Tgas(%s) = %s"%(j,TExhaustGas) if equipe.DBFuel_id is None: TMinOffGas = 0 dTtot = 1.e-10 else: fuel = Fuel(equipe.DBFuel_id) TMinOffGas = max(fuel.TCondOffGas(),0) dTtot = max(TExhaustGas-TMinOffGas,1.e-10) QWHj = equipe.QWHEq if QWHj is None: QWHj = 0.0 Status.int.QWHEqTotal += QWHj QWHj_T = Status.int.createQ_T() for iT in range(Status.NT+2): temp = Status.int.T[iT] dT = max(temp - TMinOffGas,0.) QWHj_T[iT] = QWHj*max(0.0,1.0 - dT/dTtot) Status.int.QWHEqTotal_T[iT] += QWHj_T[iT] QWHj_Tt = Status.int.createQ_Tt() for it in range(Nt): time = Status.TimeStep*it f = schedule.fav[it] # print "t: %s f: %s"%(time,f) for iT in range(NT+2): #NT + 1 + 1 -> additional value for T > Tmax QWHj_Tt[iT][it] = QWHj_T[iT]*f Status.int.QWHEqTotal_Tt[iT][it] += QWHj_Tt[iT][it] Status.int.QWHEqTotal_t = copy.deepcopy(Status.int.QWHEqTotal_Tt[0]) # print "Process (calcAggDemand): QWHEq(t) = ",Status.int.QWHEqTotal_t #.............................................................................. # get waste heat from WHEEs whees = Status.prj.getWHEEs() Status.int.QWHEE_Tt = Status.int.createQ_Tt() Status.int.QWHEE_T = Status.int.createQ_T() Status.int.QWHEE_t = Status.int.createQ_t() Status.int.QWHEE = 0 for whee in whees: n = whee.WHEENo - 1 schedule = Status.schedules.WHEESchedules[n] NT = Status.NT Nt = Status.Nt # temperature distribution of waste heat. assumed as fix Tout = whee.WHEETOutlet if Tout == None: logWarning("Processes: WHEE outlet temperature not specified. 70 ºC assumed") Tout = 70 Tret = max(Tout - 20,0.0) # by default Delta_T = 20 assumed dTtot = max(Tout-Tret,1.e-10) if whee.HPerDayWHEE is None or whee.NDaysWHEE is None or whee.QWHEE is None: QWHEE = 0.0 else: QWHEE = whee.QWHEE*whee.HPerDayWHEE*whee.NDaysWHEE Status.int.QWHEE += QWHEE QWHEE_T = Status.int.createQ_T() for iT in range(Status.NT+2): temp = Status.int.T[iT] dT = max(temp - Tret,0.) QWHEE_T[iT] = QWHEE*max(0.0,1.0 - dT/dTtot) Status.int.QWHEE_T[iT] += QWHj_T[iT] QWHEE_Tt = Status.int.createQ_Tt() for it in range(Nt): time = Status.TimeStep*it f = schedule.fav[it] # print "t: %s f: %s"%(time,f) for iT in range(NT+2): #NT + 1 + 1 -> additional value for T > Tmax QWHEE_Tt[iT][it] = QWHEE_T[iT]*f Status.int.QWHEE_Tt[iT][it] += QWHEE_Tt[iT][it] Status.int.QWHEE_t = copy.deepcopy(Status.int.QWHEE_Tt[0]) # print "Process (calcAggDemand): QWHEq(t) = ",Status.int.QWHEqTotal_t #.............................................................................. # now run HR module for calculating heat recovery and effective demand at pipe entry Status.mod.moduleHR.runHRModule() logTrack("Aggregate demand = %s"%str(Status.int.QD_T)) dlg.Destroy()
def runSimulation(self,first=None,last=None,loop=True): #------------------------------------------------------------------------------ # updates the energy flows for the full equipment cascade #------------------------------------------------------------------------------ logTrack("ModuleEnergy (runSimulation): starting") NT = Status.NT self.getEquipmentList() #.............................................................................. # initialising storage space for energy flows in cascade # assigning total heat demand and availability to the first row in cascade if (first == None) or (first < 1): first = 1 first = max(first,Status.int.cascadeUpdateLevel+1) #avoid unnecessary calculations if last == None or last > self.NEquipe: last = self.NEquipe Status.int.extendCascadeArrays(self.NEquipe) logTrack("ModuleEnergy (runSimulation): simulating from %s to %s"%(first,last)) #.............................................................................. # now calculate the cascade # call the calculation modules for each equipment dlg = DialogGauge(Status.main,_("EINSTEIN system simulation"),_("calculating energy flows")) for cascadeIndex in range(first,last+1): equipeID = Status.int.cascade[cascadeIndex-1]["equipeID"] equipe = Status.DB.qgenerationhc.QGenerationHC_ID[equipeID][0] equipeClass = getEquipmentClass(equipe.EquipType) logTrack("=================================\nModuleEnergy (runSimulation): %s - %s [%s: %s]"%\ (cascadeIndex,equipe.Equipment,equipeClass,equipe.EquipType)) if equipeClass == "HP": Status.mod.moduleHP.calculateEnergyFlows(equipe,cascadeIndex) elif equipeClass == "BB": Status.mod.moduleBB.calculateEnergyFlows(equipe,cascadeIndex) elif equipeClass == "ST": Status.mod.moduleST.calculateEnergyFlows(equipe,cascadeIndex) elif equipeClass == "CHP": Status.mod.moduleCHP.calculateEnergyFlows(equipe,cascadeIndex) else: logTrack("WARNING: equipment type not yet forseen in system simulation module") logTrack("running calculateEnergyFlows-dummy") self.calculateEnergyFlows(equipe,cascadeIndex) logTrack("ModuleEnergy (runSimulation): end simulation=====================================") dlg.update(100.0*(cascadeIndex-first+1)/(last-first+1)) #.............................................................................. # update the pointer to the last calculated cascade dlg.Destroy() Status.int.cascadeUpdateLevel = last #.............................................................................. # if a full cascade has been calculated, calculate the balances logTrack("ModuleEnergy (runSimulation): arrived at the end. %s [%s]"%\ (last,self.NEquipe)) if last == self.NEquipe: uncoveredDemand = Status.int.QD_T_mod[last][Status.NT+1] totalDemand = Status.int.QD_T_mod[0][Status.NT+1] if uncoveredDemand > 0.005*totalDemand: showWarning("Revise your design.\nCurrent equipment capacity is not sufficient for covering the demand\n"+\ "Remaining heat demand: %s [MWh]"%(uncoveredDemand/1000.0)) logTrack("ModuleEnergy (runSimulation): updating Energy balances") (projectData,generalData) = Status.prj.getProjectData() if loop == True: for i in range(10): USH0 = Status.int.USHTotal QWHEq0 = Status.int.QWHEqTotal Status.mod.moduleEA.calculateEquipmentEnergyBalances() Status.prj.setStatus("Energy") #probably redundant, already done in cEEB self.getEquipmentTotals() USH = Status.int.USHTotal QWHEq = Status.int.QWHEqTotal logTrack("ModuleEnergy - iterative cycle i %s (USH): %s -> %s (QWH): %s -> %s"% \ (i,USH0,USH,QWHEq0,QWHEq)) if abs(QWHEq - QWHEq0) < 0.0001*(USH + USH0): break else: Status.mod.moduleHR.runHRModule() # update waste heat calculations self.runSimulation(1,self.NEquipe,loop=False)