예제 #1
0
 def selectElements(self, f, elements):
     """Given an array 'f' of floating-point element properties,
     return a nummodule array of those values corresponding to elements
     listed in 'elements'.
     >>> f = ph.elementPotentials()
     >>> lam_o, lam_h = ph.selectElements(f, ['O', 'H'])
     """
     if elements:
         fs = []
         k = 0
         for s in elements:
             k = self.elementIndex(s)
             fs.append(f[k])
         return asarray(fs)
     else:
         return asarray(f)
예제 #2
0
    def setupGrid(self, grid):
        """Specify the grid.

        >>> d.setupGrid([0.0, 0.1, 0.2])

        """
        return _cantera.domain_setupGrid(self._hndl, asarray(grid))
예제 #3
0
파일: onedim.py 프로젝트: anujg1991/cantera
    def setupGrid(self, grid):
        """Specify the grid.

        >>> d.setupGrid([0.0, 0.1, 0.2])

        """
        return _cantera.domain_setupGrid(self._hndl, asarray(grid))
예제 #4
0
 def setCoverages(self, theta):
     """Set the surface coverages to the values in array 'theta'."""
     nt = len(theta)
     if nt == self.nSpecies():
         _cantera.surf_setcoverages(self._phase_id, asarray(theta, 'd'))
     else:
         raise CanteraError('expected ' + ` self.nSpecies() ` +
                            ' coverage values, but got ' + ` nt `)
예제 #5
0
    def setProfile(self, dom, comp, pos, v):
        """Set an initial estimate for a profile of one component in
        one domain.

        dom -- domain object
        comp -- component name
        pos -- sequence of relative positions, from 0 on the
               left to 1 on the right
        v -- sequence of values at the relative positions specified in 'pos'

        >>> s.setProfile(d, 'T', [0.0, 0.2, 1.0], [400.0, 800.0, 1500.0])
        
        """

        idom = dom.index()
        icomp = dom.componentIndex(comp)
        _cantera.sim1D_setProfile(self._hndl, idom, icomp, asarray(pos),
                                  asarray(v))
예제 #6
0
 def selectSpecies(self, f, species):
     """Given an array 'f' of floating-point species properties,
     return an array of those values corresponding to species
     listed in 'species'. This method is used internally to implement
     species selection in methods like moleFractions, massFractions, etc.
     >>> f = ph.chemPotentials()
     >>> muo2, muh2 = ph.selectSpecies(f, ['O2', 'H2'])
     """
     
     if species:
         fs = []
         k = 0
         for s in species:
             k = self.speciesIndex(s)
             fs.append(f[k])
         return asarray(fs)
     else:
         return asarray(f)
예제 #7
0
 def __init__(self, typ, n, coeffs=[]):
     """
     The constructor is
     meant to be called from constructors of subclasses of Func1.
     See: Polynomial, Gaussian, Arrhenius, Fourier, Const,
     PeriodicFunction """
     self.n = n
     self.coeffs = asarray(coeffs, 'd')
     self._func_id = _cantera.func_new(typ, n, self.coeffs)
예제 #8
0
 def setCoverages(self, theta):
     """Set the surface coverages to the values in array *theta*."""
     nt = len(theta)
     if nt == self.nSpecies():
         _cantera.surf_setcoverages(self._phase_id,
                                  asarray(theta,'d'))
     else:
         raise CanteraError('expected '+`self.nSpecies()`+
                            ' coverage values, but got '+`nt`)
예제 #9
0
    def setTimeStep(self, stepsize, nsteps):
        """Set the sequence of time steps to try when Newton fails.

        stepsize -- initial time step size [s]
        nsteps - sequence of integer step numbers

        >>> s.setTimeStep(1.0e-5, [1, 2, 5, 10])

        """
        _cantera.sim1D_setTimeStep(self._hndl, stepsize, asarray(nsteps))
예제 #10
0
파일: Func.py 프로젝트: hkmoffat/cantera
 def __init__(self, coefficients):
     """
     :param coefficients:
         sequence of (*A*, *b*, *E*) triplets.
     """
     cc = asarray(coefficients, "d")
     n, m = cc.shape
     if m <> 3:
         raise CanteraError("Three Arrhenius parameters (A, b, E) required.")
     Func1.__init__(self, 3, n, ravel(cc))
예제 #11
0
 def __init__(self, coefficients):
     """
     coefficients - sequence of \f$(A, b, E)\f$ triplets.
     
     """
     cc = asarray(coefficients,'d')
     n, m = cc.shape
     if m <> 3:
         raise CanteraError('Three Arrhenius parameters (A, b, E) required.')
     Func1.__init__(self, 3, n, ravel(cc))        
예제 #12
0
파일: Func.py 프로젝트: hkmoffat/cantera
 def __init__(self, coefficients):
     """
     coefficients - sequence of \f$(A, b, E)\f$ triplets.
     
     """
     cc = asarray(coefficients,'d')
     n, m = cc.shape
     if m <> 3:
         raise CanteraError('Three Arrhenius parameters (A, b, E) required.')
     Func1.__init__(self, 3, n, ravel(cc))        
예제 #13
0
 def setMassFractions(self, x, norm = 1):
     """Set the mass fractions.
     See: setMoleFractions
     """
     if type(x) == types.StringType:
         _cantera.phase_setstring(self._phase_id,2,x)
     elif _isseq(self.nSpecies(), x):
         _cantera.phase_setarray(self._phase_id,2,norm,asarray(x))
     else:
         raise CanteraError('mass fractions must be a string or array')
예제 #14
0
    def setProfile(self, dom, comp, pos, v):
        
        """Set an initial estimate for a profile of one component in
        one domain.

        dom -- domain object
        comp -- component name
        pos -- sequence of relative positions, from 0 on the
               left to 1 on the right
        v -- sequence of values at the relative positions specified in 'pos'

        >>> s.setProfile(d, 'T', [0.0, 0.2, 1.0], [400.0, 800.0, 1500.0])
        
        """
        
        idom = dom.index()
        icomp = dom.componentIndex(comp)
        _cantera.sim1D_setProfile(self._hndl, idom, icomp,
                                  asarray(pos), asarray(v))
예제 #15
0
파일: Func.py 프로젝트: anujg1991/cantera
 def __init__(self, typ, n, coeffs=[]):
     """
     The constructor is
     meant to be called from constructors of subclasses of Func1.
     See: Polynomial, Gaussian, Arrhenius, Fourier, Const,
     PeriodicFunction """
     self.n = n
     self._own = 1
     self._func_id = 0
     self._typ = typ
     self.coeffs = asarray(coeffs,'d')
     self._func_id = _cantera.func_new(typ, n, self.coeffs)
예제 #16
0
 def __init__(self, omega, coefficients):
     """
     omega - fundamental frequency [radians/sec].
     
     coefficients - List of (a,b) pairs, beginning with \f$n = 0\f$.
     
     """
     cc = asarray(coefficients, 'd')
     n, m = cc.shape
     if m <> 2:
         raise CanteraError('provide (a, b) for each term')
     cc[0, 1] = omega
     Func1.__init__(self, 1, n - 1, ravel(transpose(cc)))
예제 #17
0
파일: Func.py 프로젝트: hkmoffat/cantera
 def __init__(self, omega, coefficients):
     """
     :param omega:
         fundamental frequency [radians/sec].
     :param coefficients:
         List of (a,b) pairs, beginning with n = 0.
     """
     cc = asarray(coefficients, "d")
     n, m = cc.shape
     if m <> 2:
         raise CanteraError("provide (a, b) for each term")
     cc[0, 1] = omega
     Func1.__init__(self, 1, n - 1, ravel(transpose(cc)))
예제 #18
0
파일: Func.py 프로젝트: hkmoffat/cantera
 def __init__(self, omega, coefficients):
     """
     omega - fundamental frequency [radians/sec].
     
     coefficients - List of (a,b) pairs, beginning with \f$n = 0\f$.
     
     """
     cc = asarray(coefficients,'d')       
     n, m = cc.shape
     if m <> 2:
         raise CanteraError('provide (a, b) for each term')
     cc[0,1] = omega
     Func1.__init__(self, 1, n-1, ravel(transpose(cc)))
예제 #19
0
파일: Phase.py 프로젝트: anujg1991/cantera
    def selectElements(self, f, elements):
        """Given an array *f* of floating-point element properties, return a
        those values corresponding to elements listed in *elements*. Returns an
        array if *elements* is a sequence, or a scalar if *elements* is a
        scalar.

        >>> f = ph.elementPotentials()
        >>> lam_o, lam_h = ph.selectElements(f, ['O', 'H'])
        >>> lam_h = ph.selectElements(f, 'H')
        """
        if isinstance(elements, types.StringTypes):
            m = self.elementIndex(elements)
            return f[m]
        if elements:
            fs = []
            k = 0
            for s in elements:
                k = self.elementIndex(s)
                fs.append(f[k])
            return asarray(fs)
        else:
            return asarray(f)
예제 #20
0
    def setSpeciesMoles(self, moles):
        """Set the moles of the species [kmol]. The moles may be
        specified either as a string, or as an array. If an array is
        used, it must be dimensioned at least as large as the total
        number of species in the mixture. Note that the species may
        belong to any phase, and unspecified species are set to zero.

        >>> mix.setSpeciesMoles('C(s):1.0, CH4:2.0, O2:0.2')

        """
        if type(moles) == types.StringType:
            _cantera.mix_setMolesByName(self.__mixid, moles)
        else:
            _cantera.mix_setMoles(self.__mixid, asarray(moles))
예제 #21
0
    def setTimeStep(self, stepsize, nsteps):
        """Set the sequence of time steps to try when Newton fails.

        stepsize -- initial time step size [s]
        nsteps - sequence of integer step numbers

        >>> s.setTimeStep(1.0e-5, [1, 2, 5, 10])

        """
        # 3/20/09
        # The use of asarray seems to set the nsteps array to be of
        # type double. This needs to be checked out further.
        # Probably a function of python version and Numerics version
        _cantera.sim1D_setTimeStep(self._hndl, stepsize, asarray(nsteps))
예제 #22
0
    def setSpeciesMoles(self, moles):
        """Set the moles of the species [kmol]. The moles may be
        specified either as a string, or as an array. If an array is
        used, it must be dimensioned at least as large as the total
        number of species in the mixture. Note that the species may
        belong to any phase, and unspecified species are set to zero.

        >>> mix.setSpeciesMoles('C(s):1.0, CH4:2.0, O2:0.2')

        """
        if type(moles) == types.StringType:
            _cantera.mix_setMolesByName(self.__mixid, moles)
        else:
            _cantera.mix_setMoles(self.__mixid, asarray(moles))
예제 #23
0
    def setTimeStep(self, stepsize, nsteps):
        """Set the sequence of time steps to try when Newton fails.

        stepsize -- initial time step size [s]
        nsteps - sequence of integer step numbers

        >>> s.setTimeStep(1.0e-5, [1, 2, 5, 10])

        """
        # 3/20/09
        # The use of asarray seems to set the nsteps array to be of
        # type double. This needs to be checked out further.
        # Probably a function of python version and Numerics version
        _cantera.sim1D_setTimeStep(self._hndl, stepsize, asarray(nsteps))
예제 #24
0
파일: Func.py 프로젝트: minhbau/Cantera
 def __init__(self, typ, n, coeffs=[]):
     """
     The constructor is meant to be called from constructors of subclasses
     of Func1: :class:`Polynomial`, :class:`Gaussian`, :class:`Arrhenius`,
     :class:`Fourier`, :class:`Const`, :class:`PeriodicFunction`.
     """
     self.n = n
     self._own = 1
     self._func_id = 0
     self._typ = typ
     if _cantera.nummod == 'numpy':
         self.coeffs = array(coeffs, dtype=float, ndmin=1)
     else:
         self.coeffs = asarray(coeffs, 'd')
     self._func_id = _cantera.func_new(typ, n, self.coeffs)
예제 #25
0
파일: Func.py 프로젝트: hkmoffat/cantera
 def __init__(self, typ, n, coeffs=[]):
     """
     The constructor is meant to be called from constructors of subclasses
     of Func1: :class:`Polynomial`, :class:`Gaussian`, :class:`Arrhenius`,
     :class:`Fourier`, :class:`Const`, :class:`PeriodicFunction`.
     """
     self.n = n
     self._own = 1
     self._func_id = 0
     self._typ = typ
     if _cantera.nummod == "numpy":
         self.coeffs = array(coeffs, dtype=float, ndmin=1)
     else:
         self.coeffs = asarray(coeffs, "d")
     self._func_id = _cantera.func_new(typ, n, self.coeffs)
예제 #26
0
파일: Phase.py 프로젝트: anujg1991/cantera
    def selectSpecies(self, f, species):
        """Given an array *f* of floating-point species properties, return
        those values corresponding to species listed in *species*. Returns an
        array if *species* is a sequence, or a scalar if *species* is a
        scalar. This method is used internally to implement species selection
        in methods like moleFractions, massFractions, etc.

        >>> f = ph.chemPotentials()
        >>> muo2, muh2 = ph.selectSpecies(f, ['O2', 'H2'])
        >>> muh2 = ph.selectSpecies(f, 'H2')
        """

        if isinstance(species, types.StringTypes):
            k = self.speciesIndex(species)
            return f[k]
        elif species:
            fs = []
            k = 0
            for s in species:
                k = self.speciesIndex(s)
                fs.append(f[k])
            return asarray(fs)
        else:
            return asarray(f)
예제 #27
0
    def atomicWeights(self, elements = []):
        """Array of element molar masses [kg/kmol].

        If a sequence of element symbols is supplied, only the values
        for those elements are returned, ordered as in the
        list. Otherwise, the values are for all elements in the phase,
        ordered as in the input file.  """
        atw = _cantera.phase_getarray(self._phase_id,1)
        if elements:
            ae = []
            m = 0
            for e in elements:
                m = self.elementIndex(e)
                ae.append(atw[m])
            return asarray(ae)
        else:
            return atw
예제 #28
0
파일: Phase.py 프로젝트: anujg1991/cantera
    def setMoleFractions(self, x, norm = 1):
        """Set the mole fractions.

        :param x:
            string or array of mole fraction values
        :param norm:
            If non-zero (default), array values will be scaled to sum to 1.0.

        >>> ph.setMoleFractions('CO:1, H2:7, H2O:7.8')
        >>> x = [1.0]*ph.nSpecies()
        >>> ph.setMoleFractions(x)
        >>> ph.setMoleFractions(x, norm = 0)  # don't normalize values
        """
        if type(x) == types.StringType:
            _cantera.phase_setstring(self._phase_id,1,x)
        elif _isseq(self.nSpecies(), x):
            _cantera.phase_setarray(self._phase_id,1,norm,asarray(x))
        else:
            raise CanteraError('mole fractions must be a string or array')
예제 #29
0
    def setMoleFractions(self, x, norm = 1):
        """Set the mole fractions.

        x - string or array of mole fraction values

        norm - If non-zero (default), array values will be
        scaled to sum to 1.0.

        >>> ph.setMoleFractions('CO:1, H2:7, H2O:7.8')
        >>> x = [1.0]*ph.nSpecies()
        >>> ph.setMoleFractions(x)
        >>> ph.setMoleFractions(x, norm = 0)  # don't normalize values

        """
        if type(x) == types.StringType:
            _cantera.phase_setstring(self._phase_id,1,x)
        elif _isseq(self.nSpecies(), x): 
            _cantera.phase_setarray(self._phase_id,1,norm,asarray(x))
        else:
            raise CanteraError('mole fractions must be a string or array')
예제 #30
0
    def selectSpecies(self, f, species):
        """Given an array *f* of floating-point species properties,
        return an array of those values corresponding to species
        listed in *species*. This method is used internally to implement
        species selection in methods like :meth:`~.Phase.moleFractions`,
        :meth:`~.Phase.massFractions`, etc.

        >>> f = mix.chemPotentials()
        >>> muo2, muh2 = mix.selectSpecies(f, ['O2', 'H2'])
        """
        sp = []
        if species:
            if type(species) == types.StringType:
                sp = [species]
            else:
                sp = species
            fs = []
            k = 0
            for s in sp:
                k = self.speciesIndex(s)
                fs.append(f[k])
            return asarray(fs)
        else:
            return f
예제 #31
0
파일: mixture.py 프로젝트: minhbau/Cantera
    def selectSpecies(self, f, species):
        """Given an array *f* of floating-point species properties,
        return an array of those values corresponding to species
        listed in *species*. This method is used internally to implement
        species selection in methods like :meth:`~.Phase.moleFractions`,
        :meth:`~.Phase.massFractions`, etc.

        >>> f = mix.chemPotentials()
        >>> muo2, muh2 = mix.selectSpecies(f, ['O2', 'H2'])
        """
        sp = []
        if species:
            if type(species) == types.StringType:
                sp = [species]
            else:
                sp = species
            fs = []
            k = 0
            for s in sp:
                k = self.speciesIndex(s)
                fs.append(f[k])
            return asarray(fs)
        else:
            return f
예제 #32
0
 def molarFluxes(self, state1, state2, delta):
     return _cantera.tran_getMolarFluxes(self.__tr_id, self.trnsp, 
                                         asarray(state1), asarray(state2),
                                         delta)
예제 #33
0
 def massFluxes(self, state1, state2, delta):
     return _cantera.tran_getMassFluxes(self.__tr_id, self.trnsp,
                                        asarray(state1), asarray(state2),
                                        delta)
예제 #34
0
 def setParameters(self, type, k, params):
     """Set model-specific parameters."""
     return _cantera.tran_setParameters(self.__tr_id,
                                        type, k, asarray(params))
예제 #35
0
 def setParameters(self, type, k, params):
     """Set model-specific parameters."""
     return _cantera.tran_setParameters(self.__tr_id, type, k,
                                        asarray(params))