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()
# 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()
# methods sdot = surf.netProductionRates(surf) cdot = surf.creationRates(surf) ddot = surf.destructionRates(surf) for ks in range(nsurf): ratio = sdot[ks] / (cdot[ks] + ddot[ks]) if ratio < 0.0: ratio = -ratio 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
# methods sdot = surf.netProductionRates(surf) cdot = surf.creationRates(surf) ddot = surf.destructionRates(surf) for ks in range(nsurf): ratio = sdot[ks]/(cdot[ks] + ddot[ks]) if ratio < 0.0: ratio = -ratio 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
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
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