if ratio > 1.0e-9 or time < 10 * dt: alldone = 0 if alldone: break # set the gas object state to that of this reactor, in # preparation for the simulation of the next reactor # downstream, where this object will set the inlet conditions gas = r.contents() dist = n * rlen * 1.0e3 # distance in mm # write the gas mole fractions and surface coverages # vs. distance writeCSV(f, [dist, r.temperature() - 273.15, r.pressure() / OneAtm] + list(gas.moleFractions()) + list(surf.coverages())) f.close() # make a reaction path diagram tracing carbon. This diagram will show # the pathways by the carbon entering the bed in methane is convered # into CO and CO2. The diagram will be specifically for the exit of # the bed; if the pathways are desired at some interior point, then # put this statement inside the above loop. # # To process this diagram, give the command on the command line # after running this script: # dot -Tps < carbon_pathways.dot > carbon_pathways.ps # This will generate the diagram in Postscript.
if ratio > 1.0e-9 or time < 10*dt: alldone = 0 if alldone: break # set the gas object state to that of this reactor, in # preparation for the simulation of the next reactor # downstream, where this object will set the inlet conditions gas = r.contents() dist = n*rlen * 1.0e3 # distance in mm # write the gas mole fractions and surface coverages # vs. distance writeCSV(f, [dist, r.temperature() - 273.15, r.pressure()/OneAtm] + list(gas.moleFractions()) + list(surf.coverages())) f.close() # make a reaction path diagram tracing carbon. This diagram will show # the pathways by the carbon entering the bed in methane is convered # into CO and CO2. The diagram will be specifically for the exit of # the bed; if the pathways are desired at some interior point, then # put this statement inside the above loop. # # To process this diagram, give the command on the command line # after running this script: # dot -Tps < carbon_pathways.dot > carbon_pathways.ps # This will generate the diagram in Postscript.
time_list2=[] temp_list2=[] time_list3=[] temp_list3=[] NotOpenVent = False for n in range(166000): time = (n+1)*0.00002 area_valve = 5.E-5 roh = r1.density() kappa = gas.cp_mole()/gas.cv_mole() nym_real = min(gas_sink.pressure()/r1.pressure(),((2./(kappa+1.))**(kappa/(kappa-1.)))) #print nym_real,gas_sink.pressure()/r1.pressure(),((2./(kappa+1.))**(kappa/(kappa-1.))) Ausfluss = ( (kappa/(kappa-1.)) * (nym_real**(2./kappa))* (1.-(nym_real**((kappa-1.)/kappa)))**(1./2.)) Kv = area_valve * 1. * Ausfluss * (2*gas_sink.pressure()*roh)**(1./2.) / roh print r1.density(),r1.temperature(),r1.pressure() if (r1.pressure()/1E5)>1.5 or NotOpenVent: v1.setValveCoeff(Kv) NotOpenVent = True sim.advance(time) time_list.append(time) temp_list.append(r1.pressure()/1E5)
sim = ReactorNet([r]) time = 0.0 tim = zeros(100, 'd') data = zeros([100, 5], 'd') for n in range(100): time += 1.e-5 sim.advance(time) tim[n] = time data[n, 0] = r.temperature() data[n, 1] = r.moleFraction('OH') data[n, 2] = r.moleFraction('H') data[n, 3] = r.moleFraction('H2') print '%10.3e %10.3f %10.3f %14.6e' % (sim.time(), r.temperature(), r.pressure(), r.intEnergy_mass()) # plot the results if matplotlib is installed. # see http://matplotlib.sourceforge.net to get it args = sys.argv if len(args) > 1 and args[1] == '-plot': try: from matplotlib.pylab import * clf subplot(2, 2, 1) plot(tim, data[:, 0]) xlabel('Time (s)') ylabel('Temperature (K)') subplot(2, 2, 2) plot(tim, data[:, 1]) xlabel('Time (s)')
time += 5.0e-6 sim.advance(time) tim[n] = time data[n,0] = r.temperature() data[n,1] = r.moleFraction('OH') data[n,2] = r.moleFraction('H') data[n,3] = r.moleFraction('CH4') # sensitivity of OH to reaction 2 data[n,4] = sim.sensitivity('OH',2) # sensitivity of OH to reaction 3 data[n,5] = sim.sensitivity('OH',3) print '%10.3e %10.3f %10.3f %14.6e' % (sim.time(), r.temperature(), r.pressure(), r.intEnergy_mass()) #sim.sensitivity("OH",0)) # plot the results if matplotlib is installed. # see http://matplotlib.sourceforge.net to get it args = sys.argv if 1==1: try: from matplotlib.pylab import * clf subplot(2,2,1) plot(tim,data[:,0]) xlabel('Time (s)'); ylabel('Temperature (K)'); subplot(2,2,2)
ofen = Reactor(contents = gas, volume = 0.125) # Zwei weitere Reaktor stellen das Rohr da. rohr1 = Reactor(contents = gas, volume = 0.025) rohr2 = Reactor(contents = gas, volume = 0.025) # CO Quelle gas.set(T=300.0, P = OneAtm, X ='CO:1.0') CO_Quelle = Reactor(contents = gas, volume = 0.025) ZuGabe_CO = Gaussian(t0=1.0, FWHM = 0.4, A = 0.1) m1 = MassFlowController(upstream = CO_Quelle, downstream = ofen, mdot = ZuGabe_CO) air_mdot = 1 m2 = MassFlowController(upstream = air_in, downstream = ofen, mdot = air_mdot) m3 = Valve(upstream = ofen, downstream = rohr1, Kv=10.0) m4 = Valve(upstream = rohr1, downstream = air_out, Kv=10.0) #m4 = MassFlowController(upstream = rohr1, downstream = rohr2, mdot = air_mdot) #m5 = MassFlowController(upstream = rohr2, downstream = air_out, mdot = air_mdot) time = 0.0 reactors = ReactorNet([ofen,rohr1]) f = open('CO.csv','w') for n in range(1000): time += 4.e-2 reactors.advance(time) print time,ofen.moleFraction('CO'),rohr1.moleFraction('CO'),ofen.pressure() #writeCSV(f, [reactors.time(), ofen.moleFraction('CO')]) f.close()
c = (4.0-3.0*R)/(4.0*(1.0-R)) e = c/phi d = 3.7*e comp = 'CH4:0.5, H2:%(b)f, O2:%(e)f, N2:%(d)f'% vars() print '#'+comp gas = GRI30() gas.set(T = T0, P = OneAtm, X = comp) r = Reactor(gas) env = Reservoir(Air()) w = Wall(r,env) w.set(K = 0) # set expansion parameter. dV/dt = KA(P_1 - P_2) w.set(A = 1.0) sim = ReactorNet([r]) time = 0.0 #Told = r.temperature() #print '%10.3e %10.3f %10.3f %14.6e' % (sim.time(), r.temperature(), r.pressure(), r.intEnergy_mass()) for n in range(36): time = (n+1)*0.0005 sim.advance(time) print '%10.3e %10.3f %10.3f %14.6e' % (sim.time(), r.temperature(), r.pressure(), r.intEnergy_mass()) #while time <= tFinal: # time = sim.step(tFinal) # print '%10.3e %10.3f %10.3f %14.6e' % (sim.time(), r.temperature(), # r.pressure(), r.intEnergy_mass())#print MC_Gemisch(3,1)
mdot = 0.05) # connect the mixer to the downstream reservoir with a valve. outlet = Valve(upstream = mixer, downstream = downstream, Kv = 1.0) sim = ReactorNet([mixer]) # Since the mixer is a reactor, we need to integrate in time to reach # steady state. A few residence times should be enough. t = 0.0 for n in range(30): tres = mixer.mass()/(mfc1.massFlowRate() + mfc2.massFlowRate()) t += 0.5*tres sim.advance(t) # if ignited, turn the igniter off. # We also need to restart the integration in this case. if mixer.temperature() > 1200.0: mfc3.set(mdot = 0.0) sim.setInitialTime(t) print '%14.5g %14.5g %14.5g %14.5g %14.5g' % (t, mixer.temperature(), mixer.enthalpy_mass(), mixer.pressure(), mixer.massFraction('CH4')) # view the state of the gas in the mixer print mixer.contents()
igniter = Reservoir(gas) igniter_mdot = Gaussian(t0=2.0, FWHM=0.05, A=0.05) m3 = MassFlowController(upstream=igniter, downstream=r1, mdot=igniter_mdot) wall = Wall(left=r1, right=r2, K=1.0e3) sim = ReactorNet([r1, r2]) time_list = [] temp_list = [] time_list2 = [] temp_list2 = [] for n in range(3600): time = (n + 1) * 0.002 sim.advance(time) time_list.append(time) temp_list.append(r1.pressure() / 1e5) time_list2.append(time) temp_list2.append(r2.pressure() / 1e5) print time, r1.pressure(), r2.pressure() p.plot(list_to_array(time_list), list_to_array(temp_list)) p.plot(list_to_array(time_list2), list_to_array(temp_list2)) p.show() # print MC_Gemisch(3,1)
def PSRCalc(self, volume, tfinal): initial_gas = self.InitialGas() gas = self._gas1 NoGas = 0 ## Ignition isn't provided if NoGas = 0 mass_flow = 0 upstreams = numpy.empty(self._code, dtype=object) ms = numpy.empty(self._code, dtype=object) reactor = Reactor(initial_gas, volume=volume, energy='on') ControllerCount = 0 for code in range(0, self._argslength, 2): upstreams[ControllerCount] = Reservoir(self._args[code]) ms[ControllerCount] = MassFlowController() ms[ControllerCount].install(upstreams[ControllerCount], reactor) ms[ControllerCount].set(self._args[code + 1]) mass_flow += self._args[code + 1] ControllerCount += 1 exhaust = Reservoir(gas) v = Valve() v.install(reactor, exhaust) v.setValveCoeff(Kv=0.5) #Change made from 1.0 to 0.5 sim = ReactorNet([reactor]) tnow = 0.0 tracker = datetime.now() LoopCounter = 0 while (tnow < tfinal): LoopCounter += 1 tnow = sim.step(tfinal) tres = reactor.mass() / mass_flow currenttime = datetime.now() d = reactor.massFractions() IndexCounter = 0 for item in d: if item > 1: badguy = 1 baditem = item break else: badguy = 0 IndexCounter += 1 if badguy: break b = (currenttime.time().minute - tracker.time().minute) if (b > 2): break if (IndexCounter >= gas.nSpecies()): badSpecie = 'No Bad Species present' baditem = 'None' else: badSpecie = gas.speciesName(IndexCounter) tres = reactor.mass() / v.massFlowRate() T = reactor.temperature() P = reactor.pressure() reactor = Reactor(initial_gas) x = reactor.contents().moleFractions() initial_gas.setState_TPX(T, P, x) return initial_gas, mass_flow, tres
def PFR(self, volume, NReactors): initial_gas = self.InitialGas() gas = self._gas1 T = gas.temperature() P = gas.pressure() x = gas.moleFractions() initial_gas.setState_TPX(T, P, x) upstreams = numpy.empty(self._code - 1, dtype=object) ms = numpy.empty(self._code - 1, dtype=object) mass_flow = self._args[1] TOL = 1.0E-10 Niter = 20 nsp = gas.nSpecies() wdot = [''] * nsp wold = [''] * nsp volume_n = volume / NReactors tres = 0.0 for i in range(0, NReactors): reactor = Reactor(initial_gas, volume=volume_n, energy='on') upstream = Reservoir(initial_gas) downstream = Reservoir(initial_gas) m = MassFlowController() m.install(upstream, reactor) m.set(mass_flow) if (i == 0): ControllerCount = 0 for code in range(2, self._argslength, 2): upstreams[ControllerCount] = Reservoir(self._args[code]) ms[ControllerCount] = MassFlowController() ms[ControllerCount].install(upstreams[ControllerCount], reactor) ms[ControllerCount].set(self._args[code + 1]) mass_flow += self._args[code + 1] ControllerCount += 1 v = Valve() v.install(reactor, downstream) v.setValveCoeff(Kv=0.1) sim = ReactorNet([reactor]) dt = reactor.mass() / mass_flow tnow = 0.0 wold = initial_gas.netProductionRates() while (tnow < Niter * dt): tnow += dt sim.advance(tnow) max_change = 0.0 wdot = initial_gas.netProductionRates() for k in range(0, nsp): max_change = max(math.fabs(wdot[k] - wold[k]), max_change) wold[k] = wdot[k] if (max_change < TOL): break tres += reactor.mass() / mass_flow T = reactor.temperature() P = reactor.pressure() reactor = Reactor(initial_gas) x = reactor.contents().moleFractions() initial_gas.setState_TPX(T, P, x) f = self.FuelMassAnalyzer(initial_gas, mass_flow) return initial_gas, mass_flow, tres, f
time = 0.0 f = open('piston.csv','w') writeCSV(f,['time (s)','T1 (K)','P1 (Bar)','V1 (m3)', 'T2 (K)','P2 (Bar)','V2 (m3)']) temp = zeros([300, 2], 'd') pres = zeros([300, 2], 'd') vol = zeros([300, 2], 'd') tm = zeros(300,'d') for n in range(300): time += 4.e-4 print time, r2.temperature(),n sim.advance(time) tm[n] = time temp[n,:] = [r1.temperature(), r2.temperature()] pres[n,:] = [1.0e-5*r1.pressure(), 1.0e-5*r2.pressure()] vol[n,:] = [r1.volume(), r2.volume()] writeCSV(f, [tm[n], temp[n,0], pres[n,0], vol[n,0], temp[n,1], pres[n,1], vol[n,1]]) f.close() import os print 'Output written to file piston.csv' print 'Directory: '+os.getcwd() args = sys.argv if len(args) > 1 and args[1] == '-plot': try: from matplotlib.pylab import * clf subplot(2,2,1) plot(tm, temp[:,0],'g-',tm, temp[:,1],'b-')
f = open('piston.csv', 'w') writeCSV(f, [ 'time (s)', 'T1 (K)', 'P1 (Bar)', 'V1 (m3)', 'T2 (K)', 'P2 (Bar)', 'V2 (m3)' ]) temp = zeros([300, 2], 'd') pres = zeros([300, 2], 'd') vol = zeros([300, 2], 'd') tm = zeros(300, 'd') for n in range(300): time += 4.e-4 print time, r2.temperature(), n sim.advance(time) tm[n] = time temp[n, :] = [r1.temperature(), r2.temperature()] pres[n, :] = [1.0e-5 * r1.pressure(), 1.0e-5 * r2.pressure()] vol[n, :] = [r1.volume(), r2.volume()] writeCSV(f, [ tm[n], temp[n, 0], pres[n, 0], vol[n, 0], temp[n, 1], pres[n, 1], vol[n, 1] ]) f.close() import os print 'Output written to file piston.csv' print 'Directory: ' + os.getcwd() args = sys.argv if len(args) > 1 and args[1] == '-plot': try: from matplotlib.pylab import * clf
time += 5.0e-6 sim.advance(time) tim[n] = time data[n, 0] = r.temperature() data[n, 1] = r.moleFraction('OH') data[n, 2] = r.moleFraction('H') data[n, 3] = r.moleFraction('CH4') # sensitivity of OH to reaction 2 data[n, 4] = sim.sensitivity('OH', 2) # sensitivity of OH to reaction 3 data[n, 5] = sim.sensitivity('OH', 3) print '%10.3e %10.3f %10.3f %14.6e %10.3f %10.3f' % ( sim.time(), r.temperature(), r.pressure(), r.intEnergy_mass(), data[n, 4], data[n, 5]) # plot the results if matplotlib is installed. # see http://matplotlib.sourceforge.net to get it args = sys.argv if len(args) > 1 and args[1] == '-plot': try: from matplotlib.pylab import * clf subplot(2, 2, 1) plot(tim, data[:, 0]) xlabel('Time (s)') ylabel('Temperature (K)') subplot(2, 2, 2) plot(tim, data[:, 1])
# flow rates change or if there is chemistry occurring. mixer = Reactor(gas_b) # create two mass flow controllers connecting the upstream reservoirs # to the mixer, and set their mass flow rates to values corresponding # to stoichiometric combustion. mfc1 = MassFlowController(upstream=res_a, downstream=mixer, mdot=rho_a * 2.5 / 0.21) mfc2 = MassFlowController(upstream=res_b, downstream=mixer, mdot=rho_b * 1.0) # connect the mixer to the downstream reservoir with a valve. outlet = Valve(upstream=mixer, downstream=downstream, Kv=1.0) sim = ReactorNet([mixer]) # Since the mixer is a reactor, we need to integrate in time to reach # steady state. A few residence times should be enough. t = 0.0 for n in range(30): tres = mixer.mass() / (mfc1.massFlowRate() + mfc2.massFlowRate()) t += 0.5 * tres sim.advance(t) print '%14.5g %14.5g %14.5g %14.5g %14.5g' % ( t, mixer.temperature(), mixer.enthalpy_mass(), mixer.pressure(), mixer.massFraction('CH4')) # view the state of the gas in the mixer print mixer.contents()
time += 5.0e-6 sim.advance(time) tim[n] = time data[n,0] = r.temperature() data[n,1] = r.moleFraction('OH') data[n,2] = r.moleFraction('H') data[n,3] = r.moleFraction('CH4') # sensitivity of OH to reaction 2 data[n,4] = sim.sensitivity('OH',2) # sensitivity of OH to reaction 3 data[n,5] = sim.sensitivity('OH',3) print '%10.3e %10.3f %10.3f %14.6e %10.3f %10.3f' % (sim.time(), r.temperature(), r.pressure(), r.intEnergy_mass(), data[n,4], data[n,5]) # plot the results if matplotlib is installed. # see http://matplotlib.sourceforge.net to get it args = sys.argv if len(args) > 1 and args[1] == '-plot': try: from matplotlib.pylab import * clf subplot(2,2,1) plot(tim,data[:,0]) xlabel('Time (s)'); ylabel('Temperature (K)'); subplot(2,2,2) plot(tim,data[:,1])
mfc3 = MassFlowController(upstream = igniter, downstream = mixer, mdot = 0.05) # connect the mixer to the downstream reservoir with a valve. outlet = Valve(upstream = mixer, downstream = downstream, Kv = 1.0) sim = ReactorNet([mixer]) # Since the mixer is a reactor, we need to integrate in time to reach # steady state. A few residence times should be enough. t = 0.0 for n in range(30): tres = mixer.mass()/(mfc1.massFlowRate() + mfc2.massFlowRate()) t += 0.5*tres sim.advance(t) # if ignited, turn the igniter off. # We also need to restart the integration in this case. if mixer.temperature() > 1200.0: mfc3.set(mdot = 0.0) sim.setInitialTime(t) print '%14.5g %14.5g %14.5g %14.5g %14.5g' % (t, mixer.temperature(), mixer.enthalpy_mass(), mixer.pressure(), mixer.massFraction('CH4')) # view the state of the gas in the mixer print mixer.contents()
time_list = [] temp_list = [] temp_list3 = [] # Abbruchkriterium haelfte des Sauerstoffs ist Verbraucht. O2_Start = r2.moleFraction("O2") csvfile = "adiabatic.csv" f = open(csvfile, "w") writeCSV(f, ["Temp", "Pressure"]) for n in range(15): time = (n) * 30.0 + 0.015 sim.advance(time) time_list.append(time) # time_list2.append(1000./r2.temperature()) temp_list.append(r2.pressure()) temp_list3.append((r2.temperature() - 273.15)) writeCSV(f, [(r2.temperature() - 273.15), r2.pressure() / 1e5]) # temp_list3.append(r2.enthalpy_mass()) # if r2.temperature()>2500: # break # if O2_Start/40.>r2.moleFraction('O2'): # print time_list[-20],temp_list[-20],temp_list3[-20] # print time_list[-12],temp_list[-12],temp_list3[-12] # print time_list[-1],temp_list[-1],temp_list3[-1] # break # print time,0.000010*(r1.pressure()-gas_sink.pressure())