Пример #1
0
igniter = Reactor(gas_c)

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
Пример #2
0
# 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()
Пример #3
0
# note that this connects two reactors with different reaction
# mechanisms and different numbers of species. Downstream and upstream
# species are matched by name.
m2 = MassFlowController(upstream = air_in,
                        downstream = combustor, mdot = air_mdot)

# The igniter will use a Gaussian 'functor' object to specify the
# time-dependent igniter mass flow rate.
igniter_mdot = Gaussian(t0 = 1.0, FWHM = 0.2, A = 0.1)
m3 = MassFlowController(upstream = igniter,
                        downstream = combustor, mdot = igniter_mdot)

# put a valve on the exhaust line to regulate the pressure
v = Valve(upstream = combustor, downstream = exhaust, Kv = 1.0)

# the simulation only contains one reactor
sim = ReactorNet([combustor])

# take single steps to 6 s, writing the results to a CSV file
# for later plotting.
tfinal = 6.0
tnow = 0.0
f = open('combustor.csv','w')
while tnow < tfinal:
    tnow = sim.step(tfinal)
    tres = combustor.mass()/v.massFlowRate()
    writeCSV(f, [tnow, combustor.temperature(), tres]
             +list(combustor.moleFractions()))
f.close()
Пример #4
0
    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
Пример #5
0
    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
Пример #6
0
# note that this connects two reactors with different reaction
# mechanisms and different numbers of species. Downstream and upstream
# species are matched by name.
m2 = MassFlowController(upstream = air_in,
                        downstream = combustor, mdot = air_mdot)

# The igniter will use a Guassiam 'functor' object to specify the
# time-dependent igniter mass flow rate.
igniter_mdot = Gaussian(t0 = 1.0, FWHM = 0.2, A = 0.1)
m3 = MassFlowController(upstream = igniter,
                        downstream = combustor, mdot = igniter_mdot)

# put a valve on the exhaust line to regulate the pressure
v = Valve(upstream = combustor, downstream = exhaust, Kv = 1.0)

# the simulation only contains one reactor
sim = ReactorNet([combustor])

# take single steps to 6 s, writing the results to a CSV file
# for later plotting.
tfinal = 6.0
tnow = 0.0
f = open('combustor.csv','w')
while tnow < tfinal:
    tnow = sim.step(tfinal)
    tres = combustor.mass()/v.massFlowRate()
    writeCSV(f, [tnow, combustor.temperature(), tres]
             +list(combustor.moleFractions()))
f.close()