From charlesreid1

from Cantera import *
from Cantera.Reactor import *

class ResidenceTimeReactorNet(ReactorNet):
    def __init__(self, g, tau):
        """
        Parameters:
        g = gas flowing into reactor
        tau = residence time of reactor [s]
        """
        self.tau = tau

        # Build our reactors
        self.upstream = Reservoir(g)
        self.downstream = Reservoir(g)
        self.reactor = Reactor(g)

        # Compute mass flow going into reactor
        # by assuming a volume basis (1 L), 
        # then specifying mass flow as X kg/s 
        # per unit of reactor volume 
        mdot = g.density() / tau

        # Put a flow controller at the inlet
        self.inlet = MassFlowController(self, upstream=self.upstream, downstream=self.reactor, mdot=mdot)

        # Put a pressure valve at the outlet 
        self.outlet = Valve(self.reactor, self, Kv=100)

        # Call the ReactorNet constructor to build your ReactorNet
        ReactorNet.__init__(self,[self.reactor])
    
    def run(self,dt=1.0e-4):
        """
        """
        t = 0
        while t < self.tau:
            t = t + dt
            self.advance(t)

        print "Run complete."


if __name__=="__main__":

    g = importPhase('h2o2.cti')
    g.set(T=1000,P=OneAtm,X="H2:2.0, O2:1.0, H:0.000001")

    n = ResidenceTimeReactorNet(g,0.01)

    n.run()

    print n.reactor