From 6cb4bd93ce8d21328a11b02946fc96b55b624304 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Mon, 27 Feb 2012 18:13:05 +0000 Subject: [PATCH] Cleaned up whitespace in all Python files using reindent.py 4 spaces per indentation level, no tabs, no trailing whitespace, and a single newline at end of each file. --- doc/python/mkmkdoc.py | 5 - .../python/Cantera/DustyGasTransport.py | 12 +- interfaces/python/Cantera/Edge.py | 14 +- interfaces/python/Cantera/Func.py | 115 ++- interfaces/python/Cantera/Interface.py | 13 +- interfaces/python/Cantera/Kinetics.py | 84 +- .../python/Cantera/OneD/BurnerDiffFlame.py | 27 +- interfaces/python/Cantera/OneD/BurnerFlame.py | 27 +- .../python/Cantera/OneD/CounterFlame.py | 57 +- interfaces/python/Cantera/OneD/FreeFlame.py | 33 +- .../python/Cantera/OneD/StagnationFlow.py | 53 +- interfaces/python/Cantera/OneD/__init__.py | 2 - interfaces/python/Cantera/OneD/onedim.py | 170 ++-- interfaces/python/Cantera/Phase.py | 67 +- interfaces/python/Cantera/Reactor.py | 174 ++--- interfaces/python/Cantera/SolidTransport.py | 4 +- interfaces/python/Cantera/SurfacePhase.py | 2 +- interfaces/python/Cantera/ThermoPhase.py | 103 ++- interfaces/python/Cantera/Transport.py | 24 +- interfaces/python/Cantera/XML.py | 37 +- interfaces/python/Cantera/__init__.py | 9 +- interfaces/python/Cantera/ck2cti.py | 3 +- interfaces/python/Cantera/elements.py | 2 +- interfaces/python/Cantera/excel.py | 5 +- interfaces/python/Cantera/exceptions.py | 1 - interfaces/python/Cantera/gases.py | 9 +- interfaces/python/Cantera/importFromFile.py | 7 +- interfaces/python/Cantera/interp.py | 6 +- interfaces/python/Cantera/liquidvapor.py | 19 +- interfaces/python/Cantera/mixture.py | 84 +- interfaces/python/Cantera/num.py | 6 +- interfaces/python/Cantera/rxnpath.py | 27 +- interfaces/python/Cantera/set.py | 22 +- interfaces/python/Cantera/solid.py | 7 +- interfaces/python/Cantera/solids.py | 3 +- interfaces/python/Cantera/solution.py | 11 +- interfaces/python/Cantera/solve.py | 32 +- interfaces/python/Cantera/stoich.py | 5 +- interfaces/python/Cantera/tecplot.py | 5 +- .../python/MixMaster/CompositionFrame.py | 428 +++++----- interfaces/python/MixMaster/ControlPanel.py | 360 ++++----- interfaces/python/MixMaster/DataFrame.py | 59 +- interfaces/python/MixMaster/DataGraph.py | 356 +++++---- interfaces/python/MixMaster/Edit.py | 343 ++++---- interfaces/python/MixMaster/ElementFrame.py | 18 +- interfaces/python/MixMaster/GraphFrame.py | 220 +++--- interfaces/python/MixMaster/ImportFrame.py | 204 ++--- interfaces/python/MixMaster/KineticsFrame.py | 737 +++++++++--------- interfaces/python/MixMaster/MechManager.py | 57 +- interfaces/python/MixMaster/Mix.py | 49 +- interfaces/python/MixMaster/NewFlowFrame.py | 188 +++-- interfaces/python/MixMaster/SpeciesFrame.py | 18 +- interfaces/python/MixMaster/SpeciesInfo.py | 453 ++++++----- interfaces/python/MixMaster/ThermoFrame.py | 235 +++--- interfaces/python/MixMaster/ThermoProp.py | 110 ++- interfaces/python/MixMaster/TransportFrame.py | 59 +- interfaces/python/MixMaster/UnitChooser.py | 146 ++-- interfaces/python/MixMaster/Units/SI.py | 64 +- interfaces/python/MixMaster/Units/unit.py | 14 +- interfaces/python/MixMaster/__init__.py | 3 +- interfaces/python/MixMaster/config.py | 2 - interfaces/python/MixMaster/flowpanel.py | 9 +- interfaces/python/MixMaster/gri30.py | 4 +- interfaces/python/MixMaster/main.py | 84 +- interfaces/python/MixMaster/menu.py | 2 +- interfaces/python/MixMaster/newflow.py | 41 +- interfaces/python/MixMaster/utilities.py | 5 - interfaces/python/ctml_writer.py | 368 +++++---- .../equilibrium/adiabatic_flame/adiabatic.py | 45 +- .../multiphase_plasma/multiphase_plasma.py | 6 +- samples/python/equilibrium/plotting.py | 7 +- .../python/equilibrium/stoich_flame/stoich.py | 2 +- .../flames/adiabatic_flame/adiabatic_flame.py | 6 +- samples/python/flames/flame1/flame1.py | 5 +- samples/python/flames/flame2/flame2.py | 9 +- .../flames/flame_fixed_T/flame_fixed_T.py | 15 +- .../python/flames/free_h2_air/free_h2_air.py | 5 +- samples/python/flames/npflame1/npflame1.py | 7 +- samples/python/flames/stflame1/stflame1.py | 3 +- samples/python/fuel_cells/sofc.py | 12 +- .../gasdynamics/isentropic/isentropic.py | 28 +- .../gasdynamics/soundSpeed/soundSpeed.py | 6 +- samples/python/kinetics/ratecoeffs.py | 6 +- .../critProperties/critProperties.py | 2 - .../python/liquid_vapor/rankine/rankine.py | 9 +- samples/python/misc/rxnpath1.py | 4 +- .../reactors/combustor_sim/combustor.py | 1 - samples/python/reactors/mix1_sim/mix1.py | 1 - samples/python/reactors/mix2_sim/mix2.py | 3 +- samples/python/reactors/piston_sim/piston.py | 7 +- .../python/reactors/reactor1_sim/reactor1.py | 6 +- .../python/reactors/reactor2_sim/reactor2.py | 9 +- .../reactors/sensitivity_sim/sensitivity1.py | 14 +- .../python/reactors/surf_pfr_sim/surf_pfr.py | 130 ++- samples/python/run_examples.py | 4 +- .../catcomb_stagflow/catcomb.py | 18 +- .../surface_chemistry/diamond_cvd/diamond.py | 4 - samples/python/tut1.py | 16 +- samples/python/tut2.py | 3 - samples/python/tut3.py | 4 +- samples/python/tut4.py | 6 +- src/fortran/genf.py | 15 +- src/fortran/makect.py | 5 +- test_problems/diamondSurf/run_diamond.py | 16 +- test_problems/diamondSurf/tdia_a.py | 3 - test_problems/python/flame1/flame1.py | 5 +- test_problems/python/frac.py | 5 +- test_problems/python/tut1/tut1.py | 16 +- test_problems/python/tut2/tut2.py | 5 - test_problems/python/tut3/tut3.py | 4 +- test_problems/python/tut4/tut4.py | 6 +- 111 files changed, 3083 insertions(+), 3322 deletions(-) diff --git a/doc/python/mkmkdoc.py b/doc/python/mkmkdoc.py index 768e8bb22..1f5dc0a76 100644 --- a/doc/python/mkmkdoc.py +++ b/doc/python/mkmkdoc.py @@ -22,8 +22,3 @@ import Cantera.OneD writepydoc(Cantera.OneD, out) out.close() - - - - - diff --git a/interfaces/python/Cantera/DustyGasTransport.py b/interfaces/python/Cantera/DustyGasTransport.py index a7572eaca..4c813a416 100644 --- a/interfaces/python/Cantera/DustyGasTransport.py +++ b/interfaces/python/Cantera/DustyGasTransport.py @@ -17,7 +17,7 @@ class DustyGasTransport(Transport): DustyGasTransport. """ - + def __init__(self, phase = None): """ phase - The object representing the gas phase within the @@ -39,14 +39,14 @@ class DustyGasTransport(Transport): def setMeanParticleDiameter(self, diameter): """Set the mean particle diameter [m]. Internal. See: set""" - self.setParameters(3, 0, [diameter, 0.0]) + self.setParameters(3, 0, [diameter, 0.0]) def setPermeability(self, permeability): """Set the permeability. If not called, the value for close-packed spheres is used. Internal.""" self.setParameters(4, 0, [permeability, 0.0]) - + def set(self, **p): """Set model parameters. This is a convenience method that simply calls other methods depending on the keyword. @@ -58,7 +58,7 @@ class DustyGasTransport(Transport): tortuous. pore_radius - The pore radius [m]. - + All keywords are optional. """ for o in p.keys(): @@ -74,7 +74,3 @@ class DustyGasTransport(Transport): self.setPermeability(p[o]) else: raise 'unknown parameter' - - - - diff --git a/interfaces/python/Cantera/Edge.py b/interfaces/python/Cantera/Edge.py index a61faa968..675fdcb57 100644 --- a/interfaces/python/Cantera/Edge.py +++ b/interfaces/python/Cantera/Edge.py @@ -6,11 +6,11 @@ from SurfacePhase import EdgePhase from Kinetics import Kinetics import XML -class Edge(EdgePhase, Kinetics): +class Edge(EdgePhase, Kinetics): """ One-dimensional edge between two surfaces. - - Instances of class Edge represent reacting 1D edges between + + Instances of class Edge represent reacting 1D edges between between 2D surfaces. Class Edge defines no methods of its own. All of its methods derive from either EdgePhase or Kinetics. @@ -43,9 +43,9 @@ class Edge(EdgePhase, Kinetics): fn = src.split('#') id = "" if len(fn) > 1: - id = fn[1] + id = fn[1] fn = fn[0] - + # read in the root element of the tree if not building from # an already-built XML tree. Enable preprocessing if the film # is a .cti file instead of XML. @@ -60,9 +60,9 @@ class Edge(EdgePhase, Kinetics): # otherwise, find the first element with tag name 'phase' # (1D, 2D and 3D phases use the CTML tag name 'phase' else: - s = root.child(name = "phase") + s = root.child(name = "phase") - # build the surface phase + # build the surface phase EdgePhase.__init__(self, xml_phase=s) # build the reaction mechanism. This object (representing the diff --git a/interfaces/python/Cantera/Func.py b/interfaces/python/Cantera/Func.py index b9ebc3416..cb447c872 100644 --- a/interfaces/python/Cantera/Func.py +++ b/interfaces/python/Cantera/Func.py @@ -14,12 +14,12 @@ import types class Func1: - """Functors of one variable. + """Functors of one variable. A Functor is an object that behaves like a function. Class 'Func1' is the base class from which several functor classes derive. These classes are designed to allow specifying functions of time from Python - that can be used by the C++ kernel. + that can be used by the C++ kernel. Functors can be added, multiplied, and divided to yield new functors. >>> f1 = Polynomial([1.0, 0.0, 3.0]) # 3*t*t + 1 @@ -32,7 +32,7 @@ class Func1: >>> f3(2.0) ___4.3333333 """ - + def __init__(self, typ, n, coeffs=[]): """ The constructor is @@ -55,7 +55,7 @@ class Func1: def __repr__(self): return self.write() - + def __call__(self, t): """Implements function syntax, so that F(t) is equivalent to F.value(t).""" @@ -65,7 +65,7 @@ class Func1: return CompositeFunction(self, t) else: return _cantera.func_value(self._func_id, t) - + def __add__(self, other): """Overloads operator '+' @@ -75,17 +75,17 @@ class Func1: # it. if type(other) == types.FloatType: return SumFunction(self, Const(other)) - + return SumFunction(self, other) - + def __radd__(self, other): """Overloads operator '+' Returns a new function other(t) + self(t)""" # if 'other' is a number, then create a 'Const' functor for - # it. + # it. if type(other) == types.FloatType: - return SumFunction(Const(other),self) + return SumFunction(Const(other),self) return SumFunction(other, self) def __sub__(self, other): @@ -97,9 +97,9 @@ class Func1: # it. if type(other) != types.InstanceType: return DiffFunction(self, Const(other)) - + return DiffFunction(self, other) - + def __rsub__(self, other): """Overloads operator '-' @@ -110,13 +110,13 @@ class Func1: if type(other) != types.InstanceType: return DiffFunction(Const(other), self) return DiffFunction(other, self) - + def __mul__(self, other): """Overloads operator '*' - + Return a new function self(t)*other(t)""" if type(other) != types.InstanceType: - return ProdFunction(self, Const(other)) + return ProdFunction(self, Const(other)) return ProdFunction(self, other) def __rmul__(self, other): @@ -124,15 +124,15 @@ class Func1: Returns a new function other(t)*self(t)""" if type(other) != types.InstanceType: - return ProdFunction(Const(other), self) + return ProdFunction(Const(other), self) return ProdFunction(other, self) - + def __div__(self, other): """Overloads operator '/' Returns a new function self(t)/other(t)""" if type(other) != types.InstanceType: - return RatioFunction(self, Const(other)) + return RatioFunction(self, Const(other)) return RatioFunction(self, other) def __rdiv__(self, other): @@ -140,8 +140,8 @@ class Func1: Returns a new function other(t)/self(t)""" if type(other) != types.InstanceType: - return RatioFunction(Const(other), self) - return RatioFunction(other, self) + return RatioFunction(Const(other), self) + return RatioFunction(other, self) def func_id(self): """Internal. Return the integer index used internally to access the @@ -150,8 +150,8 @@ class Func1: def write(self, arg = 'x', length = 1000): return _cantera.func_write(self._func_id, length, arg) - - + + class Sin(Func1): def __init__(self,omega=1.0): Func1.__init__(self,100,1,omega) @@ -164,7 +164,7 @@ class Exp(Func1): class Pow(Func1): def __init__(self, n): Func1.__init__(self,106,1,n) - + class Polynomial(Func1): """A polynomial. Instances of class 'Polynomial' evaluate @@ -173,7 +173,7 @@ class Polynomial(Func1): \f] The coefficients are supplied as a list, beginning with \f$a_N\f$ and ending with \f$a_0\f$. - + >>> p1 = Polynomial([1.0, -2.0, 3.0]) # 3t^2 - 2t + 1 >>> p2 = Polynomial([6.0, 8.0]) # 8t + 6 @@ -184,10 +184,10 @@ class Polynomial(Func1): """ Func1.__init__(self, 2, len(coeffs)-1, coeffs) - + class Gaussian(Func1): - """A Gaussian pulse. Instances of class 'Gaussian' evaluate + """A Gaussian pulse. Instances of class 'Gaussian' evaluate \f[ f(t) = A \exp[-(t - t_0) / \tau] \f] @@ -200,7 +200,7 @@ class Gaussian(Func1): As an example, here is how to create a Gaussian pulse with peak amplitude 10.0, centered at time 2.0, with full-width at half max = 0.2: - >>> f = Gaussian(A = 10.0, t0 = 2.0, FWHM = 0.2) + >>> f = Gaussian(A = 10.0, t0 = 2.0, FWHM = 0.2) >>> f(2.0) ___10 >>> f(1.9) @@ -212,7 +212,7 @@ class Gaussian(Func1): coeffs = array([A, t0, FWHM], 'd') Func1.__init__(self, 4, 0, coeffs) - + class Fourier(Func1): """Fourier series. Instances of class 'Fourier' evaluate the Fourier series \f[ @@ -240,11 +240,11 @@ class Fourier(Func1): 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') + cc = asarray(coefficients,'d') n, m = cc.shape if m <> 2: raise CanteraError('provide (a, b) for each term') @@ -256,32 +256,32 @@ class Fourier(Func1): # \f[ # f(T) = \sum_{n=1}^N A_n T^{b_n}\exp(-E_n/T) # \f] -# +# # Example: # # >>> f = Arrhenius([(a0, b0, e0), (a1, b1, e1)]) -# +# class Arrhenius(Func1): """Sum of modified Arrhenius terms. Instances of class 'Arrhenius' evaluate \f[ f(T) = \sum_{n=1}^N A_n T^{b_n}\exp(-E_n/T) \f] - + Example: >>> f = Arrhenius([(a0, b0, e0), (a1, b1, e1)]) - + """ 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)) + Func1.__init__(self, 3, n, ravel(cc)) @@ -299,7 +299,7 @@ class Const(Func1): degree zero, with the constant term set to the desired value. """ def __init__(self, value): - Func1.__init__(self,110,1,value) + Func1.__init__(self,110,1,value) #return Polynomial([value]) @@ -313,7 +313,7 @@ class PeriodicFunction(Func1): """ Func1.__init__(self, 50, func.func_id(), array([T],'d')) func._own = 0 - + # functions that combine two functions @@ -323,7 +323,7 @@ class ComboFunc1(Func1): This class is the base class for functors that combine two other functors in a binary operation. """ - + def __init__(self, typ, f1, f2): self._own = 1 self._func_id = 0 @@ -331,14 +331,14 @@ class ComboFunc1(Func1): if type(f1) == types.IntType: f1 = Const(f1) if type(f2) == types.IntType: - f2 = Const(f2) + f2 = Const(f2) self.f1 = f1 self.f2 = f2 self.f1._own = 0 self.f2._own = 0 self._func_id = _cantera.func_newcombo(typ, f1.func_id(), f2.func_id()) - + class SumFunction(ComboFunc1): """Sum of two functions. Instances of class SumFunction evaluate the sum of two supplied functors. @@ -351,11 +351,11 @@ class SumFunction(ComboFunc1): In this example, object 'f3' is a functor of class'SumFunction' that calls f1 and f2 and returns their sum. """ - + def __init__(self, f1, f2): """ f1 - first functor. - + f2 - second functor. """ ComboFunc1.__init__(self, 20, f1, f2) @@ -373,15 +373,15 @@ class DiffFunction(ComboFunc1): In this example, object 'f3' is a functor of class'DiffFunction' that calls f1 and f2 and returns their difference. """ - + def __init__(self, f1, f2): """ f1 - first functor. - + f2 - second functor. """ ComboFunc1.__init__(self, 25, f1, f2) - + class ProdFunction(ComboFunc1): """Product of two functions. Instances of class ProdFunction @@ -389,14 +389,14 @@ class ProdFunction(ComboFunc1): necessary to explicitly create an instance of 'ProdFunction', since the multiplication operator of the base class is overloaded to return a 'ProdFunction' instance. - + >>> f1 = Polynomial([2.0, 1.0]) >>> f2 = Polynomial([3.0, -5.0]) >>> f3 = f1 * f2 # functor to evaluate (2t + 1)*(3t - 5) In this example, object 'f3' is a functor of class'ProdFunction' that calls f1 and f2 and returns their product. """ - + def __init__(self, f1, f2): """ f1 - first functor. f2 - second functor. @@ -415,13 +415,13 @@ class RatioFunction(ComboFunc1): >>> f3 = f1 / f2 # functor to evaluate (2t + 1)/(3t - 5) In this example, object 'f3' is a functor of class'RatioFunction' that calls f1 and f2 and returns their ratio. - """ + """ def __init__(self, f1, f2): """ f1 - first functor. - + f2 - second functor. - """ + """ ComboFunc1.__init__(self, 40, f1, f2) ## Function of a function. @@ -442,12 +442,12 @@ class CompositeFunction(ComboFunc1): def __init__(self, f1, f2): """ f1 - first functor. - - f2 - second functor. - """ - ComboFunc1.__init__(self, 60, f1, f2) - + f2 - second functor. + """ + ComboFunc1.__init__(self, 60, f1, f2) + + class DerivativeFunction(Func1): def __init__(self, f): self.f = f @@ -460,6 +460,3 @@ class DerivativeFunction(Func1): # def derivative(f): return DerivativeFunction(f) - - - diff --git a/interfaces/python/Cantera/Interface.py b/interfaces/python/Cantera/Interface.py index 6f9fa1113..c513b173b 100644 --- a/interfaces/python/Cantera/Interface.py +++ b/interfaces/python/Cantera/Interface.py @@ -6,10 +6,10 @@ from SurfacePhase import SurfacePhase, EdgePhase from Kinetics import Kinetics import XML -class Interface(SurfacePhase, Kinetics): +class Interface(SurfacePhase, Kinetics): """ Two-dimensional interfaces. - + Instances of class Interface represent reacting 2D interfaces between bulk 3D phases. Class Interface defines no methods of its own. All of its methods derive from either SurfacePhase or Kinetics. @@ -43,9 +43,9 @@ class Interface(SurfacePhase, Kinetics): fn = src.split('#') id = "" if len(fn) > 1: - id = fn[1] + id = fn[1] fn = fn[0] - + # read in the root element of the tree if not building from # an already-built XML tree. Enable preprocessing if the film # is a .cti file instead of XML. @@ -60,9 +60,9 @@ class Interface(SurfacePhase, Kinetics): # otherwise, find the first element with tag name 'phase' # (both 2D and 3D phases use the CTML tag name 'phase' else: - s = root.child(name = "phase") + s = root.child(name = "phase") - # build the surface phase + # build the surface phase SurfacePhase.__init__(self, xml_phase=s) # build the reaction mechanism. This object (representing the @@ -74,4 +74,3 @@ class Interface(SurfacePhase, Kinetics): """Delete the Interface instance.""" Kinetics.__del__(self) SurfacePhase.__del__(self) - diff --git a/interfaces/python/Cantera/Kinetics.py b/interfaces/python/Cantera/Kinetics.py index eaee178e5..b17576764 100755 --- a/interfaces/python/Cantera/Kinetics.py +++ b/interfaces/python/Cantera/Kinetics.py @@ -16,14 +16,14 @@ class Kinetics: parameters - kintype - integer specifying the type of kinetics manager to create. - + """ - + def __init__(self, kintype=-1, thrm=0, xml_phase=None, id=None, phases=[]): """Build a kinetics manager from an XML specification. root -- root of a CTML tree - + id -- id of the 'kinetics' node within the tree that contains the specification of the parameters. """ @@ -55,15 +55,15 @@ class Kinetics: self._np = self.nPhases() for nn in range(self._np): - p = self.phase(nn) - self._phnum[p.thermophase()] = nn - self._end.append(self._end[-1]+p.nSpecies()) - for k in range(p.nSpecies()): - self._sp.append(p.speciesName(k)) - + p = self.phase(nn) + self._phnum[p.thermophase()] = nn + self._end.append(self._end[-1]+p.nSpecies()) + for k in range(p.nSpecies()): + self._sp.append(p.speciesName(k)) + def __del__(self): self.clear() - + def clear(self): """Delete the kinetics manager.""" if self.ckin > 0: @@ -75,7 +75,7 @@ class Kinetics: def kinetics_hndl(self): return self.ckin - + def kineticsType(self): """Kinetics manager type.""" return _cantera.kin_type(self.ckin) @@ -107,11 +107,11 @@ class Kinetics: def reactionPhaseIndex(self): """The phase in which the reactions take place.""" return _cantera.kin_reactionPhaseIndex(self) - + def phase(self, n): """Return an object representing the nth phase.""" return ThermoPhase(index = _cantera.kin_phase(self.ckin, n)) - + def nReactions(self): """Number of reactions.""" return _cantera.kin_nreactions(self.ckin) @@ -162,16 +162,16 @@ class Kinetics: if nup <> 1.0: if nup <> round(nup): s += str(nup)+' ' - else: + else: s += `int(nup)`+' ' s += self._sp[k]+' + ' s = s[:-2] return s - + def reactantStoichCoeff(self,k,i): """The stoichiometric coefficient of species k as a reactant in reaction i.""" return _cantera.kin_rstoichcoeff(self.ckin,k,i) - + def reactantStoichCoeffs(self): """The array of reactant stoichiometric coefficients. Element [k,i] of this array is the reactant stoichiometric @@ -186,12 +186,12 @@ class Kinetics: def productStoichCoeff(self,k,i): """The stoichiometric coefficient of species k as a product in reaction i.""" - return _cantera.kin_pstoichcoeff(self.ckin,k,i) + return _cantera.kin_pstoichcoeff(self.ckin,k,i) def productStoichCoeffs(self): """The array of product stoichiometric coefficients. Element [k,i] of this array is the product stoichiometric - coefficient of species k in reaction i.""" + coefficient of species k in reaction i.""" nsp = _cantera.kin_nspecies(self.ckin) nr = _cantera.kin_nreactions(self.ckin) nu = zeros((nsp,nr),'d') @@ -199,7 +199,7 @@ class Kinetics: for k in range(nsp): nu[k,i] = _cantera.kin_pstoichcoeff(self.ckin,k,i) return nu - + def fwdRatesOfProgress(self): """Forward rates of progress of the reactions.""" return _cantera.kin_getarray(self.ckin,10) @@ -230,7 +230,7 @@ class Kinetics: return _cantera.kin_getarray(self.ckin,35) else: return _cantera.kin_getarray(self.ckin,36) - + def creationRates(self, phase = None): c = _cantera.kin_getarray(self.ckin,50) if phase: @@ -241,13 +241,13 @@ class Kinetics: else: raise CanteraError('unknown phase') else: - return c - + return c + def destructionRates(self, phase = None): d = _cantera.kin_getarray(self.ckin,60) if phase: - kp = phase.thermophase() + kp = phase.thermophase() if self._phnum.has_key(kp): n = self._phnum[kp] return d[self._end[n]:self._end[n+1]] @@ -256,11 +256,11 @@ class Kinetics: else: return d - + def netProductionRates(self, phase = None): - w = _cantera.kin_getarray(self.ckin,70) + w = _cantera.kin_getarray(self.ckin,70) if phase: - kp = phase.thermophase() + kp = phase.thermophase() if self._phnum.has_key(kp): n = self._phnum[kp] return w[self._end[n]:self._end[n+1]] @@ -268,28 +268,28 @@ class Kinetics: raise CanteraError('unknown phase') else: return w - + def sourceTerms(self): - return _cantera.kin_getarray(self.ckin,80) + return _cantera.kin_getarray(self.ckin,80) def delta_H(self): return _cantera.kin_getarray(self.ckin,90) def delta_G(self): return _cantera.kin_getarray(self.ckin,91) - + def delta_S(self): - return _cantera.kin_getarray(self.ckin,92) - + return _cantera.kin_getarray(self.ckin,92) + def delta_H0(self): return _cantera.kin_getarray(self.ckin,93) def delta_G0(self): - return _cantera.kin_getarray(self.ckin,94) + return _cantera.kin_getarray(self.ckin,94) def delta_S0(self): return _cantera.kin_getarray(self.ckin,95) - + def multiplier(self,i): return _cantera.kin_multiplier(self.ckin,i) @@ -299,19 +299,7 @@ class Kinetics: for i in range(nr): _cantera.kin_setMultiplier(self.ckin,i,value) else: - _cantera.kin_setMultiplier(self.ckin,reaction,value) - + _cantera.kin_setMultiplier(self.ckin,reaction,value) + def advanceCoverages(self,dt): - return _cantera.kin_advanceCoverages(self.ckin,dt) - - - - - - - - - - - - + return _cantera.kin_advanceCoverages(self.ckin,dt) diff --git a/interfaces/python/Cantera/OneD/BurnerDiffFlame.py b/interfaces/python/Cantera/OneD/BurnerDiffFlame.py index 80f48a50c..dc8294a94 100644 --- a/interfaces/python/Cantera/OneD/BurnerDiffFlame.py +++ b/interfaces/python/Cantera/OneD/BurnerDiffFlame.py @@ -3,7 +3,7 @@ from Cantera.num import array, zeros class BurnerDiffFlame(Stack): """A burner-stabilized flat flame.""" - + def __init__(self, gas = None, burner = None, outlet = None, grid = None): """ gas -- object to use to evaluate all gas properties and reaction @@ -18,7 +18,7 @@ class BurnerDiffFlame(Stack): represent the flame. The three domains comprising the stack are stored as self.burner, self.flame, and self.outlet. """ - + if burner: self.burner = burner else: @@ -44,7 +44,7 @@ class BurnerDiffFlame(Stack): in the first 20% of the flame to Tad, then is flat. The mass fraction profiles are set similarly. """ - self.getInitialSoln() + self.getInitialSoln() gas = self.gas nsp = gas.nSpecies() yin = zeros(nsp, 'd') @@ -53,7 +53,7 @@ class BurnerDiffFlame(Stack): gas.setState_TPY(self.burner.temperature(), self.pressure, yin) u0 = self.burner.mdot()/gas.density() t0 = self.burner.temperature() - + # get adiabatic flame temperature and composition gas.equilibrate('HP') teq = gas.temperature() @@ -99,24 +99,24 @@ class BurnerDiffFlame(Stack): self.flame.setTolerances(default = tol_time, time = 1) if energy: self.flame.set(energy = energy) - + def T(self, point = -1): """Temperature profile or value at one point.""" return self.solution('T', point) def u(self, point = -1): - """Axial velocity profile or value at one point.""" - return self.solution('u', point) - + """Axial velocity profile or value at one point.""" + return self.solution('u', point) + def V(self, point = -1): - """Radial velocity profile or value at one point.""" - return self.solution('V', point) + """Radial velocity profile or value at one point.""" + return self.solution('V', point) def solution(self, component = '', point = -1): """Solution component at one point, or full profile if no point specified.""" if point >= 0: return self.value(self.flame, component, point) - else: return self.profile(self.flame, component) + else: return self.profile(self.flame, component) def setGasState(self, j): """Set the state of the object representing the gas to the @@ -127,8 +127,3 @@ class BurnerDiffFlame(Stack): nm = self.gas.speciesName(n) y[n] = self.solution(nm, j) self.gas.setState_TPY(self.T(j), self.pressure, y) - - - - - diff --git a/interfaces/python/Cantera/OneD/BurnerFlame.py b/interfaces/python/Cantera/OneD/BurnerFlame.py index 44e87cb09..e2cfaf38b 100644 --- a/interfaces/python/Cantera/OneD/BurnerFlame.py +++ b/interfaces/python/Cantera/OneD/BurnerFlame.py @@ -3,7 +3,7 @@ from Cantera.num import array, zeros class BurnerFlame(Stack): """A burner-stabilized flat flame.""" - + def __init__(self, gas = None, burner = None, outlet = None, grid = None): """ gas -- object to use to evaluate all gas properties and reaction @@ -18,7 +18,7 @@ class BurnerFlame(Stack): represent the flame. The three domains comprising the stack are stored as self.burner, self.flame, and self.outlet. """ - + if burner: self.burner = burner else: @@ -44,7 +44,7 @@ class BurnerFlame(Stack): in the first 20% of the flame to Tad, then is flat. The mass fraction profiles are set similarly. """ - self.getInitialSoln() + self.getInitialSoln() gas = self.gas nsp = gas.nSpecies() yin = zeros(nsp, 'd') @@ -53,7 +53,7 @@ class BurnerFlame(Stack): gas.setState_TPY(self.burner.temperature(), self.pressure, yin) u0 = self.burner.mdot()/gas.density() t0 = self.burner.temperature() - + # get adiabatic flame temperature and composition gas.equilibrate('HP',solver=1) teq = gas.temperature() @@ -99,24 +99,24 @@ class BurnerFlame(Stack): self.flame.setTolerances(default = tol_time, time = 1) if energy: self.flame.set(energy = energy) - + def T(self, point = -1): """Temperature profile or value at one point.""" return self.solution('T', point) def u(self, point = -1): - """Axial velocity profile or value at one point.""" - return self.solution('u', point) - + """Axial velocity profile or value at one point.""" + return self.solution('u', point) + def V(self, point = -1): - """Radial velocity profile or value at one point.""" - return self.solution('V', point) + """Radial velocity profile or value at one point.""" + return self.solution('V', point) def solution(self, component = '', point = -1): """Solution component at one point, or full profile if no point specified.""" if point >= 0: return self.value(self.flame, component, point) - else: return self.profile(self.flame, component) + else: return self.profile(self.flame, component) def setGasState(self, j): """Set the state of the object representing the gas to the @@ -127,8 +127,3 @@ class BurnerFlame(Stack): nm = self.gas.speciesName(n) y[n] = self.solution(nm, j) self.gas.setState_TPY(self.T(j), self.pressure, y) - - - - - diff --git a/interfaces/python/Cantera/OneD/CounterFlame.py b/interfaces/python/Cantera/OneD/CounterFlame.py index e22bc2292..5d0a3d53d 100644 --- a/interfaces/python/Cantera/OneD/CounterFlame.py +++ b/interfaces/python/Cantera/OneD/CounterFlame.py @@ -1,7 +1,7 @@ """A counterflow flame.""" from onedim import * -from Cantera.num import zeros +from Cantera.num import zeros import math def erfc(x): @@ -31,7 +31,7 @@ def erf(x): class CounterFlame(Stack): """A non-premixed counterflow flame.""" - + def __init__(self, gas = None, grid = None): """The domains are [ self.fuel_inlet -- class Inlet, @@ -41,7 +41,7 @@ class CounterFlame(Stack): """ self.fuel_inlet = Inlet('fuel inlet') - self.oxidizer_inlet = Inlet('oxidizer inlet') + self.oxidizer_inlet = Inlet('oxidizer inlet') self.gas = gas self.fuel_inlet.set(temperature = gas.temperature()) self.oxidizer_inlet.set(temperature = gas.temperature()) @@ -62,7 +62,7 @@ class CounterFlame(Stack): The initial guess is generated by assuming infinitely-fast chemistry.""" - self.getInitialSoln() + self.getInitialSoln() gas = self.gas nsp = gas.nSpecies() wt = gas.molecularWeights() @@ -86,26 +86,26 @@ class CounterFlame(Stack): y0ox = self.oxidizer_inlet.massFraction(iox) phi = s*y0f/y0ox zst = 1.0/(1.0 + phi) - + yin_f = zeros(nsp, 'd') yin_o = zeros(nsp, 'd') - yst = zeros(nsp, 'd') + yst = zeros(nsp, 'd') for k in range(nsp): yin_f[k] = self.fuel_inlet.massFraction(k) yin_o[k] = self.oxidizer_inlet.massFraction(k) yst[k] = zst*yin_f[k] + (1.0 - zst)*yin_o[k] - + gas.setState_TPY(self.fuel_inlet.temperature(), self.pressure, yin_f) mdotf = self.fuel_inlet.mdot() - u0f = mdotf/gas.density() + u0f = mdotf/gas.density() t0f = self.fuel_inlet.temperature() - + gas.setState_TPY(self.oxidizer_inlet.temperature(), self.pressure, yin_o) mdoto = self.oxidizer_inlet.mdot() - u0o = mdoto/gas.density() - t0o = self.oxidizer_inlet.temperature() - + u0o = mdoto/gas.density() + t0o = self.oxidizer_inlet.temperature() + # get adiabatic flame temperature and composition tbar = 0.5*(t0o + t0f) gas.setState_TPY(tbar, self.pressure, yst) @@ -124,7 +124,7 @@ class CounterFlame(Stack): nz = len(zz) y = zeros([nz,nsp],'d') - t = zeros(nz,'d') + t = zeros(nz,'d') for j in range(nz): x = zz[j] zeta = f*(x - x0) @@ -138,7 +138,7 @@ class CounterFlame(Stack): for k in range(nsp): y[j,k] = yin_o[k] + zmix*(yeq[k] - yin_o[k])/zst t[j] = t0o + (teq - t0o)*zmix/zst - + t[0] = t0f t[-1] = t0o zrel = zz/dz @@ -147,7 +147,7 @@ class CounterFlame(Stack): self.setProfile('T', zrel, t) for k in range(nsp): self.setProfile(gas.speciesName(k), zrel, y[:,k]) - + self._initialized = 1 @@ -157,7 +157,7 @@ class CounterFlame(Stack): diagnostic output. Zero suppresses all output, and 5 produces very verbose output. Default: 1 refine_grid -- if non-zero, enable grid refinement.""" - + if not self._initialized: self.init() Stack.solve(self, loglevel = loglevel, refine_grid = refine_grid) @@ -179,16 +179,16 @@ class CounterFlame(Stack): removed. Set prune significantly smaller than 'slope' and 'curve'. Set to zero to disable pruning the grid. - + >>> f.setRefineCriteria(ratio = 5.0, slope = 0.2, curve = 0.3, ... prune = 0.03) - """ + """ Stack.setRefineCriteria(self, domain = self.flame, ratio = ratio, slope = slope, curve = curve, prune = prune) def setProfile(self, component, locs, vals): - """Set a profile in the flame""" + """Set a profile in the flame""" self._initialized = 1 Stack.setProfile(self, self.flame, component, locs, vals) @@ -197,25 +197,25 @@ class CounterFlame(Stack): tol -- (rtol, atol) for steady-state tol_time -- (rtol, atol) for time stepping energy -- 'on' or 'off' to enable or disable the energy equation - """ + """ if tol: self.flame.setTolerances(default = tol) if tol_time: self.flame.setTolerances(default = tol_time, time = 1) if energy: self.flame.set(energy = energy) - + def T(self, point = -1): """The temperature [K]""" return self.solution('T', point) def u(self, point = -1): """The axial velocity [m/s]""" - return self.solution('u', point) - + return self.solution('u', point) + def V(self, point = -1): """The radial velocity divided by radius [s^-1]""" - return self.solution('V', point) + return self.solution('V', point) def solution(self, component = '', point = -1): """The solution for one specified component. If a point number @@ -223,19 +223,14 @@ class CounterFlame(Stack): point. Otherwise, return the entire profile for this component.""" if point >= 0: return self.value(self.flame, component, point) - else: return self.profile(self.flame, component) + else: return self.profile(self.flame, component) def setGasState(self, j): """Set the state of the object representing the gas to the - current solution at grid point j.""" + current solution at grid point j.""" nsp = self.gas.nSpecies() y = zeros(nsp, 'd') for n in range(nsp): nm = self.gas.speciesName(n) y[n] = self.solution(nm, j) self.gas.setState_TPY(self.T(j), self.pressure, y) - - - - - diff --git a/interfaces/python/Cantera/OneD/FreeFlame.py b/interfaces/python/Cantera/OneD/FreeFlame.py index f6d1c4661..7a0d2015d 100644 --- a/interfaces/python/Cantera/OneD/FreeFlame.py +++ b/interfaces/python/Cantera/OneD/FreeFlame.py @@ -5,7 +5,7 @@ from Cantera.num import array, zeros class FreeFlame(Stack): """A freely-propagating flat flame.""" - + def __init__(self, gas = None, grid = None, tfix = 500.0): """ gas -- object to use to evaluate all gas properties and reaction @@ -16,16 +16,16 @@ class FreeFlame(Stack): represent the flame. The three domains comprising the stack are stored as self.inlet, self.flame, and self.outlet. """ - + self.inlet = Inlet('burner') self.gas = gas self.inlet.set(temperature = gas.temperature()) self.outlet = Outlet('outlet') self.pressure = gas.pressure() - + # type 2 is Cantera C++ class FreeFlame self.flame = AxisymmetricFlow('flame',gas = gas,type=2) - + self.flame.setupGrid(grid) Stack.__init__(self, [self.inlet, self.flame, self.outlet]) self.setRefineCriteria() @@ -40,7 +40,7 @@ class FreeFlame(Stack): in the first 20% of the flame to Tad, then is flat. The mass fraction profiles are set similarly. """ - self.getInitialSoln() + self.getInitialSoln() gas = self.gas nsp = gas.nSpecies() yin = zeros(nsp, 'd') @@ -49,7 +49,7 @@ class FreeFlame(Stack): gas.setState_TPY(self.inlet.temperature(), self.pressure, yin) u0 = self.inlet.mdot()/gas.density() t0 = self.inlet.temperature() - + # get adiabatic flame temperature and composition gas.equilibrate('HP',solver=1) teq = gas.temperature() @@ -82,7 +82,7 @@ class FreeFlame(Stack): def setFixedTemperature(self, temp): _cantera.sim1D_setFixedTemperature(self._hndl, temp) - + def setProfile(self, component, locs, vals): """Set a profile in the flame""" self._initialized = 1 @@ -100,24 +100,24 @@ class FreeFlame(Stack): self.flame.setTolerances(default = tol_time, time = 1) if energy: self.flame.set(energy = energy) - + def T(self, point = -1): """Temperature profile or value at one point.""" return self.solution('T', point) def u(self, point = -1): - """Axial velocity profile or value at one point.""" - return self.solution('u', point) - + """Axial velocity profile or value at one point.""" + return self.solution('u', point) + def V(self, point = -1): - """Radial velocity profile or value at one point.""" - return self.solution('V', point) + """Radial velocity profile or value at one point.""" + return self.solution('V', point) def solution(self, component = '', point = -1): """Solution component at one point, or full profile if no point specified.""" if point >= 0: return self.value(self.flame, component, point) - else: return self.profile(self.flame, component) + else: return self.profile(self.flame, component) def setGasState(self, j): """Set the state of the object representing the gas to the @@ -128,8 +128,3 @@ class FreeFlame(Stack): nm = self.gas.speciesName(n) y[n] = self.solution(nm, j) self.gas.setState_TPY(self.T(j), self.pressure, y) - - - - - diff --git a/interfaces/python/Cantera/OneD/StagnationFlow.py b/interfaces/python/Cantera/OneD/StagnationFlow.py index d422bcda0..ab3279045 100644 --- a/interfaces/python/Cantera/OneD/StagnationFlow.py +++ b/interfaces/python/Cantera/OneD/StagnationFlow.py @@ -3,7 +3,7 @@ from Cantera.num import array, zeros class StagnationFlow(Stack): """An axisymmetric flow impinging on a surface at normal incidence.""" - + def __init__(self, gas = None, surfchem = None, grid = None): """ gas -- object to use to evaluate all gas properties and reaction @@ -17,7 +17,7 @@ class StagnationFlow(Stack): be created to represent the surface. The three domains comprising the stack are stored as self.inlet, self.flow, and self.surface. - """ + """ self.inlet = Inlet('inlet') self.gas = gas self.surfchem = surfchem @@ -35,7 +35,7 @@ class StagnationFlow(Stack): then the equilibrium composition at the adiabatic flame temperature will be used to form the initial guess. Otherwise the inlet composition will be used.""" - self.getInitialSoln() + self.getInitialSoln() gas = self.gas nsp = gas.nSpecies() yin = zeros(nsp, 'd') @@ -45,12 +45,12 @@ class StagnationFlow(Stack): u0 = self.inlet.mdot()/gas.density() t0 = self.inlet.temperature() V0 = 0.0 - + tsurf = self.surface.temperature() - + zz = self.flow.grid() dz = zz[-1] - zz[0] - + if products == 'equil': gas.equilibrate('HP') teq = gas.temperature() @@ -59,15 +59,15 @@ class StagnationFlow(Stack): self.setProfile('T', locs, [t0, teq, teq, tsurf]) for n in range(nsp): self.setProfile(gas.speciesName(n), locs, [yin[n], yeq[n], yeq[n], yeq[n]]) - else: + else: locs = array([0.0, 1.0],'d') self.setProfile('T', locs, [t0, tsurf]) for n in range(nsp): self.setProfile(gas.speciesName(n), locs, [yin[n], yin[n]]) - - locs = array([0.0, 1.0],'d') + + locs = array([0.0, 1.0],'d') self.setProfile('u', locs, [u0, 0.0]) - self.setProfile('V', locs, [V0, V0]) + self.setProfile('V', locs, [V0, V0]) self._initialized = 1 @@ -78,7 +78,7 @@ class StagnationFlow(Stack): diagnostic output. Zero suppresses all output, and 5 produces very verbose output. Default: 1 refine_grid -- if non-zero, enable grid refinement.""" - + if not self._initialized: self.init() Stack.solve(self, loglevel = loglevel, refine_grid = refine_grid) @@ -100,16 +100,16 @@ class StagnationFlow(Stack): removed. Set prune significantly smaller than 'slope' and 'curve'. Set to zero to disable pruning the grid. - + >>> f.setRefineCriteria(ratio = 5.0, slope = 0.2, curve = 0.3, ... prune = 0.03) - """ + """ Stack.setRefineCriteria(self, domain = self.flow, ratio = ratio, slope = slope, curve = curve, prune = prune) def setProfile(self, component, locs, vals): - """Set a profile in the flame""" + """Set a profile in the flame""" self._initialized = 1 Stack.setProfile(self, self.flow, component, locs, vals) @@ -118,31 +118,31 @@ class StagnationFlow(Stack): tol -- (rtol, atol) for steady-state tol_time -- (rtol, atol) for time stepping energy -- 'on' or 'off' to enable or disable the energy equation - """ + """ if tol: self.flow.setTolerances(default = tol) if tol_time: self.flow.setTolerances(default = tol_time, time = 1) if energy: self.flow.set(energy = energy) - + def T(self, point = -1): - """The temperature [K]""" + """The temperature [K]""" return self.solution('T', point) def u(self, point = -1): - """The axial velocity [m/s]""" - return self.solution('u', point) - + """The axial velocity [m/s]""" + return self.solution('u', point) + def V(self, point = -1): - """The radial velocity divided by radius [s^-1]""" - return self.solution('V', point) + """The radial velocity divided by radius [s^-1]""" + return self.solution('V', point) def solution(self, component = '', point = -1): """The solution for one specified component. If a point number is given, return the value of component 'component' at this point. Otherwise, return the entire profile for this - component.""" + component.""" if point >= 0: return self.value(self.flow, component, point) else: return self.profile(self.flow, component) @@ -157,15 +157,10 @@ class StagnationFlow(Stack): def setGasState(self, j): """Set the state of the object representing the gas to the - current solution at grid point j.""" + current solution at grid point j.""" nsp = self.gas.nSpecies() y = zeros(nsp, 'd') for n in range(nsp): nm = self.gas.speciesName(n) y[n] = self.solution(nm, j) self.gas.setState_TPY(self.T(j), self.pressure, y) - - - - - diff --git a/interfaces/python/Cantera/OneD/__init__.py b/interfaces/python/Cantera/OneD/__init__.py index ae9a5773f..30afb90e0 100644 --- a/interfaces/python/Cantera/OneD/__init__.py +++ b/interfaces/python/Cantera/OneD/__init__.py @@ -6,5 +6,3 @@ from BurnerFlame import BurnerFlame from BurnerDiffFlame import BurnerDiffFlame from CounterFlame import CounterFlame from StagnationFlow import StagnationFlow - - diff --git a/interfaces/python/Cantera/OneD/onedim.py b/interfaces/python/Cantera/OneD/onedim.py index 9e6782815..470456383 100644 --- a/interfaces/python/Cantera/OneD/onedim.py +++ b/interfaces/python/Cantera/OneD/onedim.py @@ -6,26 +6,26 @@ _onoff = {'on':1, 'yes':1, 'off':0, 'no':0, 1:1, 0:0} class Domain1D: """Base class for one-dimensional domains.""" - + def __init__(self): self._hndl = 0 - + def __del__(self): _cantera.domain_del(self._hndl) def domain_hndl(self): """Integer used to reference the kernel object.""" return self._hndl - + def type(self): """Domain type. Integer.""" return _cantera.domain_type(self._hndl) - + def index(self): """Index of this domain in a stack. Returns -1 if this domain is not part of a stack.""" return _cantera.domain_index(self._hndl) - + def nComponents(self): """Number of solution components at each grid point.""" return _cantera.domain_nComponents(self._hndl) @@ -44,12 +44,12 @@ class Domain1D: for n in range(self.nComponents()): names.append(self.componentName(n)) return names - + def componentIndex(self, name): """Index of the component with name 'name'""" return _cantera.domain_componentIndex(self._hndl, name) - - def setBounds(self, **bounds): + + def setBounds(self, **bounds): """Set the lower and upper bounds on the solution. The argument list should consist of keyword/value pairs, with @@ -62,13 +62,13 @@ class Domain1D: >>> d.setBounds(default = (0, 1), ... Y = (-1.0e-5, 2.0)) """ - + d = {} if bounds.has_key('default'): for n in range(self.nComponents()): d[self.componentName(n)] = bounds['default'] del bounds['default'] - + for b in bounds.keys(): if b == 'Y': if self.type >= 50: @@ -88,7 +88,7 @@ class Domain1D: >>> d.bounds('T') (200.0, 5000.0) """ - + ic = self.componentIndex(component) lower = _cantera.domain_lowerBound(self._hndl, ic) upper = _cantera.domain_upperBound(self._hndl, ic) @@ -97,20 +97,20 @@ class Domain1D: def tolerances(self, component): """Return the (relative, absolute) error tolerances for a solution component. - + (r, a) = d.tolerances('u') """ ic = self.componentIndex(component) r = _cantera.domain_rtol(self._hndl, ic) - a = _cantera.domain_atol(self._hndl, ic) + a = _cantera.domain_atol(self._hndl, ic) return (r, a) - + def setTolerances(self, **tol): """Set the error tolerances. If 'time' is present and non-zero, then the values entered will apply to the transient problem. Otherwise, they will apply to the steady-state - problem. + problem. The argument list should consist of keyword/value pairs, with component names as keywords and (rtol, atol) tuples as the @@ -122,13 +122,13 @@ class Domain1D: default = (1.0e-7, 1.0e-12), time = 1) """ - + d = {} if tol.has_key('default'): for n in range(self.nComponents()): d[self.componentName(n)] = tol['default'] del tol['default'] - + itime = 0 for b in tol.keys(): if b == 'time': itime = -1 @@ -147,22 +147,22 @@ class Domain1D: # print 'setting tol for ',b,' itime = ',itime _cantera.domain_setTolerances(self._hndl, n, d[b][0], d[b][1], itime) - + def setupGrid(self, grid): """Specify the grid. d.setupGrid([0.0, 0.1, 0.2]) - + """ return _cantera.domain_setupGrid(self._hndl, asarray(grid)) - + def setID(self, id): return _cantera.domain_setID(self._hndl, id) - + def setDesc(self, desc): """Set the description of this domain.""" return _cantera.domain_setDesc(self._hndl, desc) - + def grid(self, n = -1): """ If n >= 0, return the value of the nth grid point from the left in this domain. If n is not supplied, return @@ -191,7 +191,7 @@ class Domain1D: """ self._set(options) - + def _set(self, options): for opt in options.keys(): v = options[opt] @@ -212,14 +212,14 @@ class Domain1D: def _dict2arrays(self, d = None, array1 = None, array2 = None): nc = self.nComponents() if d.has_key('default'): - a1 = zeros(nc,'d') + d['default'][0] + a1 = zeros(nc,'d') + d['default'][0] a2 = zeros(nc,'d') + d['default'][1] del d['default'] else: if array1: a1 = array(array1) else: a1 = zeros(nc,'d') if array2: a2 = array(array2) - else: a2 = zeros(nc,'d') + else: a2 = zeros(nc,'d') for k in d.keys(): c = self.componentIndex(k) @@ -229,19 +229,19 @@ class Domain1D: else: raise CanteraError('unknown component '+k) return (a1, a2) - + class Bdry1D(Domain1D): """Base class for boundary domains.""" - + def __init__(self): Domain1D.__init__(self) - + def setMdot(self, mdot): """Set the mass flow rate per unit area [kg/m2].""" _cantera.bdry_setMdot(self._hndl, mdot) - + def setTemperature(self, t): """Set the temperature [K]""" _cantera.bdry_setTemperature(self._hndl, t) @@ -276,10 +276,10 @@ class Bdry1D(Domain1D): del options[opt] elif opt == 'temperature' or opt == 'T': self.setTemperature(v) - del options[opt] + del options[opt] elif opt == 'mole_fractions' or opt == 'X': self.setMoleFractions(v) - del options[opt] + del options[opt] self._set(options) @@ -292,41 +292,41 @@ class Inlet(Bdry1D): Bdry1D.__init__(self) self._hndl = _cantera.inlet_new() if id: self.setID(id) - + def setSpreadRate(self, V0 = 0.0): """Set the spead rate, defined as the value of V = v/r at the inlet.""" _cantera.inlet_setSpreadRate(self._hndl, V0) - - + + class Outlet(Bdry1D): """A one-dimensional outlet. An outlet imposes a zero-gradient boundary condition on the flow.""" - + def __init__(self, id = 'outlet'): - Bdry1D.__init__(self) + Bdry1D.__init__(self) self._hndl = _cantera.outlet_new() - if id: self.setID(id) + if id: self.setID(id) class OutletRes(Bdry1D): """A one-dimensional outlet into a reservoir.""" - - def __init__(self, id = 'outletres'): - Bdry1D.__init__(self) - self._hndl = _cantera.outletres_new() - if id: self.setID(id) - + def __init__(self, id = 'outletres'): + Bdry1D.__init__(self) + self._hndl = _cantera.outletres_new() + if id: self.setID(id) + + class SymmPlane(Bdry1D): """A symmetry plane.""" def __init__(self, id = 'symmetry_plane'): - Bdry1D.__init__(self) + Bdry1D.__init__(self) self._hndl = _cantera.symm_new() - if id: self.setID(id) + if id: self.setID(id) class Surface(Bdry1D): """A surface (possibly reacting).""" def __init__(self, id = 'surface', surface_mech = None): - Bdry1D.__init__(self) + Bdry1D.__init__(self) if surface_mech: self._hndl = _cantera.reactingsurf_new() self.setKineticsMgr(surface_mech) @@ -339,7 +339,7 @@ class Surface(Bdry1D): """Set the kinetics manager (surface reaction mechanism object).""" _cantera.reactingsurf_setkineticsmgr(self._hndl, kin.kinetics_hndl()) - + def setCoverageEqs(self, onoff='on'): """Turn solving the surface coverage equations on or off.""" if onoff == 'on': @@ -347,19 +347,19 @@ class Surface(Bdry1D): else: _cantera.reactingsurf_enableCoverageEqs(self._hndl, 0) - + class AxisymmetricFlow(Domain1D): """An axisymmetric flow domain. In an axisymmetric flow domain, the equations solved are the similarity equations for the flow in a finite-height gap of infinite radial extent. The solution variables are - u -- axial velocity + u -- axial velocity V -- radial velocity divided by radius T -- temperature lambda -- (1/r)(dP/dr) Y_k -- species mass fractions - + It may be shown that if the boundary conditions on these variables are independent of radius, then a similarity solution to the exact governing equations exists in which these variables are all @@ -382,7 +382,7 @@ class AxisymmetricFlow(Domain1D): self._p = -1.0 self.setPressure(gas.pressure()) self.solveEnergyEqn() - + def setPressure(self, p): """Set the pressure [Pa]. The pressure is a constant, since the governing equations are those for the low-Mach-number limit.""" @@ -404,20 +404,20 @@ class AxisymmetricFlow(Domain1D): def pressure(self): """Pressure [Pa].""" return self._p - + def setFixedTempProfile(self, pos, temp): """Set the fixed temperature profile. This profile is used - whenever the energy equation is disabled. - + whenever the energy equation is disabled. + pos - arrray of relative positions from 0 to 1 temp - array of temperature values >>> d.setFixedTempProfile(array([0.0, 0.5, 1.0]), ... array([500.0, 1500.0, 2000.0]) - + """ return _cantera.stflow_setFixedTempProfile(self._hndl, pos, temp) - + def solveSpeciesEqs(self, flag = 1): """Enable or disable solving the species equations. If invoked with no arguments or with a non-zero argument, the species @@ -426,14 +426,14 @@ class AxisymmetricFlow(Domain1D): held at their initial values. Default: species equations enabled.""" return _cantera.stflow_solveSpeciesEqs(self._hndl, _onoff[flag]) - + def solveEnergyEqn(self, flag = 1): """Enable or disable solving the energy equation. If invoked with no arguments or with a non-zero argument, the energy equations will be solved. If invoked with a zero argument, it will not be, and instead the temperature profiles will be held to the one specified by the call to setFixedTempProfile. - Default: energy equation enabled.""" + Default: energy equation enabled.""" return _cantera.stflow_solveEnergyEqn(self._hndl, _onoff[flag]) def set(self, **opt): @@ -453,13 +453,13 @@ class AxisymmetricFlow(Domain1D): self.solveEnergyEqn(flag = _onoff[v]) else: self._set(opt) - + class Stack: - + """ Class Stack is a container for one-dimensional domains. It also holds the multi-domain solution vector, and controls the - process of finding the solution. + process of finding the solution. Domains are ordered left-to-right, with domain number 0 at the left. @@ -473,7 +473,7 @@ class Stack: hndls[n] = domains[n].domain_hndl() self._hndl = _cantera.sim1D_new(hndls) self._domains = domains - + def __del__(self): _cantera.sim1D_del(self._hndl) @@ -492,9 +492,9 @@ class Stack: idom = dom.domain_hndl() _cantera.sim1D_setValue(self._hndl, idom, comp, localPoint, value) - + def setProfile(self, dom, comp, pos, v): - + """Set an initial estimate for a profile of one component in one domain. @@ -505,14 +505,14 @@ class Stack: 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)) - + def setFlatProfile(self, dom, comp, v): """Set a flat profile for one component in one domain. dom -- domain object @@ -523,9 +523,9 @@ class Stack: """ idom = dom.index() - icomp = dom.componentIndex(comp) + icomp = dom.componentIndex(comp) _cantera.sim1D_setFlatProfile(self._hndl, idom, icomp, v) - + def showSolution(self, fname='-'): """Show the current solution. If called with no argument, the solution is printed to the screen. If a filename is @@ -536,7 +536,7 @@ class Stack: """ _cantera.sim1D_showSolution(self._hndl, fname) - + def setTimeStep(self, stepsize, nsteps): """Set the sequence of time steps to try when Newton fails. @@ -551,26 +551,26 @@ class Stack: # 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)) - + def getInitialSoln(self): """Load the initial solution from each domain into the global solution vector.""" _cantera.sim1D_getInitialSoln(self._hndl) - + def solve(self, loglevel=1, refine_grid=1): """Solve the problem. loglevel -- integer flag controlling the amount of diagnostic output. Zero suppresses all output, and 5 produces very verbose output. Default: 1 refine_grid -- if non-zero, enable grid refinement.""" - + return _cantera.sim1D_solve(self._hndl, loglevel, refine_grid) - + def refine(self, loglevel=1): """Refine the grid, adding points where solution is not adequately resolved.""" return _cantera.sim1D_refine(self._hndl, loglevel) - + def setRefineCriteria(self, domain = None, ratio = 10.0, slope = 0.8, curve = 0.8, prune = 0.05): """Set the criteria used to refine one domain. @@ -589,7 +589,7 @@ class Stack: removed. Set prune significantly smaller than 'slope' and 'curve'. Set to zero to disable pruning the grid. - + >>> s.setRefineCriteria(d, ratio = 5.0, slope = 0.2, curve = 0.3, ... prune = 0.03) """ @@ -601,10 +601,10 @@ class Stack: >>> s.save(file = 'save.xml', id = 'energy_off', ... desc = 'solution with energy eqn. disabled') - + """ return _cantera.sim1D_save(self._hndl, file, id, desc) - + def restore(self, file = 'soln.xml', id = 'solution'): """Set the solution vector to a previously-saved solution. @@ -662,15 +662,15 @@ class Stack: >>> t = s.value(flow, 'T', 6) - """ - idom = dom.index() + """ + idom = dom.index() return _cantera.sim1D_workValue(self._hndl, idom, icomp, localPoint) - + def eval(self, rdt, count=1): """Evaluate the residual function. If count = 0, do is 'silently', without adding to the function evaluation counter""" return _cantera.sim1D_eval(self._hndl, rdt, count) - + def setMaxJacAge(self, ss_age, ts_age): """Set the maximum number of times the Jacobian will be used before it must be re-evaluated. @@ -678,7 +678,7 @@ class Stack: ts_age -- age criterion during time-stepping mode """ return _cantera.sim1D_setMaxJacAge(self._hndl, ss_age, ts_age) - + def timeStepFactor(self, tfactor): """Set the factor by which the time step will be increased after a successful step, or decreased after an unsuccessful one. @@ -686,7 +686,7 @@ class Stack: s.timeStepFactor(3.0) """ return _cantera.sim1D_timeStepFactor(self._hndl, tfactor) - + def setTimeStepLimits(self, tsmin, tsmax): """Set the maximum and minimum time steps.""" return _cantera.sim1D_setTimeStepLimits(self._hndl, tsmin, tsmax) @@ -694,7 +694,7 @@ class Stack: def setFixedTemperature(self, temp): """This is a temporary fix.""" _cantera.sim1D_setFixedTemperature(self._hndl, temp) - + def clearDomains(): """Clear all domains.""" _cantera.domain_clear() diff --git a/interfaces/python/Cantera/Phase.py b/interfaces/python/Cantera/Phase.py index 34b9e6d16..deb6ef534 100755 --- a/interfaces/python/Cantera/Phase.py +++ b/interfaces/python/Cantera/Phase.py @@ -17,7 +17,7 @@ def _isseq(n, x): return 1 except: return 0 - + class Phase: """Phases of matter. @@ -30,21 +30,21 @@ class Phase: It does not know about the pressure, or any other thermodynamic property requiring the equation of state -- class ThermoPhase derives from Phase - and adds those properties. + and adds those properties. Class Phase is not usually instantiated directly. It is used as a base class for class ThermoPhase. - + """ - + #def __init__(self, index = -1): # pass - + def phase_id(self): """The integer index used to access the kernel-level object. Internal.""" return self._phase_id - + def nElements(self): """Number of elements.""" return _cantera.phase_nelements(self._phase_id) @@ -66,7 +66,7 @@ class Phase: return asarray(ae) else: return atw - + def nSpecies(self): """Number of species.""" return _cantera.phase_nspecies(self._phase_id) @@ -76,7 +76,7 @@ class Phase: The element and species may be specified by name or by number. >>> ph.nAtoms('CH4','H') ___ 4 - + """ try: m = self.elementIndex(element) @@ -86,7 +86,7 @@ class Phase: return na except CanteraError: return 0 - + def temperature(self): """Temperature [K].""" return _cantera.phase_temperature(self._phase_id) @@ -97,7 +97,7 @@ class Phase: def volume_mass(self): """Specific volume [m^3/kg].""" - return 1.0/_cantera.phase_density(self._phase_id) + return 1.0/_cantera.phase_density(self._phase_id) def molarDensity(self): """Molar density [kmol/m^3].""" @@ -138,7 +138,7 @@ class Phase: >>> ph.moleFraction('CH4') """ k = self.speciesIndex(species) - return _cantera.phase_molefraction(self._phase_id,k) + return _cantera.phase_molefraction(self._phase_id,k) def massFractions(self, species = None): @@ -177,7 +177,7 @@ class Phase: a string or an integer index. In the latter case, the index is checked for validity and returned. If no such element is present, an exception is thrown.""" - + nel = self.nElements() if type(element) == types.IntType: m = element @@ -189,14 +189,14 @@ class Phase: return m - + def speciesName(self,k): """Name of the species with index k.""" return _cantera.phase_getstring(self._phase_id,2,k) - + def speciesNames(self): - """Return a tuple of all species names.""" + """Return a tuple of all species names.""" nsp = self.nSpecies() return map(self.speciesName,range(nsp)) @@ -212,7 +212,7 @@ class Phase: for sp in species: s.append(self.speciesIndex(sp)) return s - + if type(species) == types.IntType or type(species) == types.FloatType: k = species else: @@ -221,8 +221,8 @@ class Phase: raise CanteraError("""Species """+`species`+""" not in set """ +`self.speciesNames()`) return k - - + + def setTemperature(self, t): """Set the temperature [K].""" _cantera.phase_setfp(self._phase_id,1,t) @@ -233,8 +233,8 @@ class Phase: def setMolarDensity(self, n): """Set the density [kmol/m3].""" - _cantera.phase_setfp(self._phase_id,3,n) - + _cantera.phase_setfp(self._phase_id,3,n) + def setMoleFractions(self, x, norm = 1): """Set the mole fractions. @@ -251,12 +251,12 @@ class Phase: """ if type(x) == types.StringType: _cantera.phase_setstring(self._phase_id,1,x) - elif _isseq(self.nSpecies(), 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') - - + + def setMassFractions(self, x, norm = 1): """Set the mass fractions. See: setMoleFractions @@ -267,14 +267,14 @@ class Phase: _cantera.phase_setarray(self._phase_id,2,norm,asarray(x)) else: raise CanteraError('mass fractions must be a string or array') - - + + def setState_TRX(self, t, rho, x): """Set the temperature, density, and mole fractions. The mole fractions may be entered as a string or array, >>> ph.setState_TRX(600.0, 2.0e-3, 'CH4:0.4, O2:0.6') """ - + self.setTemperature(t) self.setMoleFractions(x) self.setDensity(rho) @@ -284,23 +284,23 @@ class Phase: fractions may be entered as a string or array, >>> ph.setState_TNX(600.0, 2.0e-3, 'CH4:0.4, O2:0.6') """ - + self.setTemperature(t) self.setMoleFractions(x) - self.setMolarDensity(n) + self.setMolarDensity(n) def setState_TRY(self, t, rho, y): - """Set the temperature, density, and mass fractions.""" + """Set the temperature, density, and mass fractions.""" self.setTemperature(t) self.setMassFractions(y) - self.setDensity(rho) + self.setDensity(rho) def setState_TR(self, t, rho): """Set the temperature and density, leaving the composition - unchanged.""" + unchanged.""" self.setTemperature(t) self.setDensity(rho) - + def selectSpecies(self, f, species): """Given an array 'f' of floating-point species properties, return an array of those values corresponding to species @@ -309,7 +309,7 @@ class Phase: >>> f = ph.chemPotentials() >>> muo2, muh2 = ph.selectSpecies(f, ['O2', 'H2']) """ - + if species: fs = [] k = 0 @@ -336,4 +336,3 @@ class Phase: return asarray(fs) else: return asarray(f) - diff --git a/interfaces/python/Cantera/Reactor.py b/interfaces/python/Cantera/Reactor.py index 50bc4b11c..02afe36ab 100644 --- a/interfaces/python/Cantera/Reactor.py +++ b/interfaces/python/Cantera/Reactor.py @@ -65,23 +65,23 @@ class ReactorBase: if self._contents: s += "\n"+`self._contents` return s - + def __repr__(self): s = self._name - s += ':\n Volume = '+`self.volume()` + s += ':\n Volume = '+`self.volume()` if self._contents: s += ": \n"+`self._contents` return s - + def name(self): """The name of the reactor.""" return self._name - + def reactor_id(self): """The integer index used to access the kernel reactor object. For internal use.""" return self.__reactor_id - + def insert(self, contents): """ Insert 'contents' into the reactor. Sets the objects used to compute @@ -94,7 +94,7 @@ class ReactorBase: _cantera.reactor_setThermoMgr(self.__reactor_id, contents._phase_id) _cantera.reactor_setKineticsMgr(self.__reactor_id, contents.ckin) - + def setInitialTime(self, T0): """Deprecated. Set the initial time. Restarts integration from this time @@ -118,7 +118,7 @@ class ReactorBase: if ie: print 'enabling energy equation for reactor',self._name else: - print 'disabling energy equation for reactor',self._name + print 'disabling energy equation for reactor',self._name _cantera.reactor_setEnergy(self.__reactor_id, ie) def temperature(self): @@ -132,7 +132,7 @@ class ReactorBase: def volume(self): """The total reactor volume [m^3]. The volume may change with time if non-rigid walls are installed on the reactor.""" - return _cantera.reactor_volume(self.__reactor_id) + return _cantera.reactor_volume(self.__reactor_id) def time(self): """Deprecated. The current time [s].""" @@ -153,7 +153,7 @@ class ReactorBase: def pressure(self): """The pressure in the reactor [Pa].""" - return _cantera.reactor_pressure(self.__reactor_id) + return _cantera.reactor_pressure(self.__reactor_id) def advance(self, time): """Deprecated. @@ -168,9 +168,9 @@ class ReactorBase: Take one internal time step from the current time toward time 'time'. Note: this method is deprecated. See class ReactorNet.""" - raise "use method step of class ReactorNet" - #return _cantera.reactor_step(self.__reactor_id, time) - + raise "use method step of class ReactorNet" + #return _cantera.reactor_step(self.__reactor_id, time) + def massFraction(self, s): """The mass fraction of species s, specified either by name or index number. @@ -206,14 +206,14 @@ class ReactorBase: ___0.00012 >>> x2 = r.moleFraction('CH3') ___0.00012 - """ + """ if type(s) == types.StringType: kk = self._contents.speciesIndex(s) else: kk = s x = self.moleFractions() return x[kk] - + def inlets(self): """Return the list of flow devices installed on inlets to this reactor. This method can be used to access information about the flows entering @@ -221,7 +221,7 @@ class ReactorBase: >>> for n in r.inlets(): ... print n.name(), n.massFlowRate() See: MassFlowController, Valve, PressureController. - """ + """ return self._inlets def outlets(self): @@ -229,7 +229,7 @@ class ReactorBase: on this reactor. >>> for o in r.outlets(): ... print o.name(), o.massFlowRate() - See: MassFlowController, Valve, PressureController. + See: MassFlowController, Valve, PressureController. """ return self._outlets @@ -240,20 +240,20 @@ class ReactorBase: See: Wall. """ return self._walls - + def _addInlet(self, inlet, other): """For internal use. Store a reference to 'inlet' - so that it will not be deleted before this object.""" + so that it will not be deleted before this object.""" self._inlets.append(inlet) if self._type == 2 and other._type == 1: - self._reservoirs.append(other) + self._reservoirs.append(other) def _addOutlet(self, outlet, other): """For internal use. Store a reference to 'outlet' - so that it will not be deleted before this object.""" + so that it will not be deleted before this object.""" self._outlets.append(outlet) if self._type == 2 and other._type == 1: - self._reservoirs.append(other) + self._reservoirs.append(other) def _addWall(self, wall, other): """For internal use. Store a reference to 'wall' @@ -275,7 +275,7 @@ class ReactorBase: self._contents.setState_TRY(self.temperature(), self.density(), self.massFractions()) - + def contents(self): """Return an object representing the reactor contents, after first synchronizing its state with the current reactor state. This method @@ -285,7 +285,7 @@ class ReactorBase: >>> (statements that change the state of object 'gas') >>> c = r.contents() >>> print c.gibbs_mole(), c.chemPotentials() - + Note that after calling method 'contents', object 'c' references the same underlying kernel object as object 'gas' does. Therefore, all properties of 'c' and 'gas' are @@ -297,7 +297,7 @@ class ReactorBase: """ self.syncContents() return self._contents - + def nSensParams(self): """Number of sensitivity parameters for this reactor.""" @@ -321,7 +321,7 @@ class ReactorBase: return self._paramid else: return self._paramid[n] - + _reactorcount = 0 _reservoircount = 0 @@ -383,7 +383,7 @@ class FlowReactor(ReactorBase): """ def __init__(self, contents = None, name = '', volume = 1.0, energy = 'on', - mdot = -1.0, + mdot = -1.0, verbose = 0): """ contents - Reactor contents. If not specified, the reactor is @@ -412,11 +412,11 @@ class FlowReactor(ReactorBase): verbose = verbose, type = 3) if mdot > 0.0: self.setMassFlowRate(mdot) - + def setMassFlowRate(self, mdot): _cantera.flowReactor_setMassFlowRate(self.__reactor_id, mdot) - - + + class ConstPressureReactor(ReactorBase): """ """ @@ -448,7 +448,7 @@ class ConstPressureReactor(ReactorBase): ReactorBase.__init__(self, contents = contents, name = name, volume = volume, energy = energy, verbose = verbose, type = 4) - + class Reservoir(ReactorBase): """ @@ -476,17 +476,17 @@ class Reservoir(ReactorBase): >>> res1 = Reactor() >>> res1.insert(gas) Arguments may be specified using keywords in any order: - >>> res2 = Reservoir(contents = Air(), + >>> res2 = Reservoir(contents = Air(), ... name = 'environment') >>> res3 = Reservoir(contents = gas, name = 'upstream_state') - """ + """ global _reservoircount if name == '': name = 'Reservoir_'+`_reservoircount` _reservoircount += 1 ReactorBase.__init__(self, contents = contents, name = name, verbose = verbose, type = 1) - + def advance(self, time): """Deprecated. Do nothing.""" pass @@ -515,11 +515,11 @@ class FlowDevice: if self._verbose: print 'deleting '+self._name _cantera.flowdev_del(self.__fdev_id) - + def name(self): """The name specified when initially constructed.""" return self._name - + def ready(self): """ Deprecated. Returns true if the device is ready to use. @@ -533,7 +533,7 @@ class FlowDevice: def install(self, upstream, downstream): """ Install the device between the upstream and downstream - reactors or reservoirs. + reactors or reservoirs. >>> f.install(upstream = reactor1, downstream = reservoir2) """ if self._verbose: @@ -546,18 +546,18 @@ class FlowDevice: def _setParameters(self, c): params = array(c,'d') n = len(params) - return _cantera.flowdev_setParameters(self.__fdev_id, n, params) + return _cantera.flowdev_setParameters(self.__fdev_id, n, params) def setFunction(self, f): _cantera.flowdev_setFunction(self.__fdev_id, f.func_id()) def flowdev_id(self): return self.__fdev_id - + _mfccount = 0 class MassFlowController(FlowDevice): - + """Mass flow controllers. A mass flow controller maintains a specified mass flow rate independent of upstream and downstream conditions. The equation used to compute the mass flow rate is @@ -567,7 +567,7 @@ class MassFlowController(FlowDevice): a constant value or a function of time. Note that if \f$\dot m_0 < 0\f$, the mass flow rate will be set to zero, since reversal of the flow direction is not allowed. - + Unlike a real mass flow controller, a MassFlowController object will maintain the flow even if the downstream pressure is greater than the upstream pressure. This allows simple implementation of @@ -585,13 +585,13 @@ class MassFlowController(FlowDevice): and downstream reactors. Examples: - + >>> mfc1 = MassFlowController(upstream = res1, downstream = reactr, ... name = 'fuel_mfc', mdot = 0.1) >>> air_mdot = Gaussian(A = 0.1, t0 = 2.0, FWHM = 0.1) >>> mfc2 = MassFlowController(upstream = res2, downstream = reactr, ... name = 'air_mfc', mdot = air_mdot) - + """ def __init__(self, upstream=None, downstream=None, @@ -614,7 +614,7 @@ class MassFlowController(FlowDevice): verbose - if set to a positive integer, additional diagnostic information will be printed. - + """ global _mfccount if name == '': @@ -662,10 +662,10 @@ class Valve(FlowDevice): \dot m = F(P_1 - P_2). \f] if \f$ P_1 > P_2, \f$ - or \f$ \dot m = 0 \f$ otherwise. + or \f$ \dot m = 0 \f$ otherwise. It is never possible for the flow to reverse and go from the downstream to the upstream reactor/reservoir through - a line containing a Valve object. + a line containing a Valve object. 'Valve' objects are often used between an upstream reactor and a downstream reactor or reservoir to maintain them both at nearly the @@ -681,15 +681,15 @@ class Valve(FlowDevice): are constant across a Valve, and the pressure difference equals the difference in pressure between the upstream and downstream reactors. - + """ def __init__(self, upstream=None, downstream=None, name='', Kv = 0.0, mdot0 = 0.0, verbose=0): """ upstream - upstream reactor or reservoir. - + downstream - downstream reactor or reservoir. - + name - name used to identify the valve in output. If no name is specified, it defaults to 'Valve_n', where n is an integer assigned in the order the Valve object @@ -699,8 +699,8 @@ class Valve(FlowDevice): verbose - if set to a positive integer, additional diagnostic information will be printed. - - """ + + """ global _valvecount if name == '': name = 'Valve_'+`_valvecount` @@ -739,7 +739,7 @@ class Valve(FlowDevice): self.setFunction(F) if Kv > 0.0: self.setValveCoeff(Kv) - + _pccount = 0 @@ -762,9 +762,9 @@ class PressureController(FlowDevice): name='', master = None, Kv = 0.0, verbose=0): """ upstream - upstream reactor or reservoir. - + downstream - downstream reactor or reservoir. - + name - name used to identify the pressure controller in output. If no name is specified, it defaults to 'PressureController_n', where n is an integer assigned in the @@ -774,8 +774,8 @@ class PressureController(FlowDevice): verbose - if set to a positive integer, additional diagnostic information will be printed. - - """ + + """ global _pccount if name == '': name = 'PressureController_'+`_pccount` @@ -800,15 +800,15 @@ class PressureController(FlowDevice): """Set the master flow controller.""" _cantera.flowdev_setMaster(self.flowdev_id(), master.flowdev_id()) - + def set(self, Kv = -1.0, master = None): if master: self.setMaster(master) if Kv > 0.0: self.setPressureCoeff(Kv) - - + + #------------- Wall --------------------------- _wallcount = 0 @@ -816,7 +816,7 @@ _wallcount = 0 class Wall: """ Reactor walls. - + A Wall separates two reactors, or a reactor and a reservoir. A wall has a finite area, may conduct or radiate heat between the two reactors on either side, and may move like a piston. @@ -852,7 +852,7 @@ class Wall: reactor the surface in question faces. The surface temperature on each side is taken to be equal to the temperature of the reactor it faces. - + """ def __init__(self, left, right, name = '', A = 1.0, K = 0.0, U = 0.0, @@ -860,7 +860,7 @@ class Wall: kinetics = [None, None]): """ Constructor arguments: - + left - Reactor or reservoir on the left. Required. right - Reactor or reservoir on the right. Required. @@ -898,30 +898,30 @@ class Wall: else: _nm = name _wallcount += 1 - + if left and right: self.install(left, right) else: raise CanteraError('both left and right reactors must be specified.') self.setArea(A) self.setExpansionRateCoeff(K) - self.setVelocity(velocity) + self.setVelocity(velocity) self.setHeatTransferCoeff(U) self.setHeatFlux(Q) self.setKinetics(kinetics[0],kinetics[1]) self._paramid = [] - + def __del__(self): """ Delete the Wall instance. This method is called automatically when no Python object stores a reference to this Wall. Since reactors and reserviors store references to all Walls installed on them, this method will only be called after the reactors/reservoirs have been deleted. """ - + _cantera.wall_del(self.__wall_id) - + def ready(self): """ Return 1 if the wall instance is ready for use, 0 otherwise. Deprecated. @@ -955,8 +955,8 @@ class Wall: Set the emissivity. """ _cantera.wall_setEmissivity(self.__wall_id, epsilon) - - + + def setHeatFlux(self, qfunc): """ Specify the time-dependent heat flux function [W/m2]. @@ -970,8 +970,8 @@ class Wall: def setExpansionRateCoeff(self, k): """Set the coefficient K that determines the expansion rate resulting from a unit pressure drop.""" - _cantera.wall_setExpansionRateCoeff(self.__wall_id, k) - + _cantera.wall_setExpansionRateCoeff(self.__wall_id, k) + def setVelocity(self, vfunc): """ Specify the velocity function [m/s]. 'vfunc' must @@ -999,7 +999,7 @@ class Wall: def heatFlux(self): return self.heatFlowRate()/self.area() - + def install(self, left, right): left._addWall(self, right) right._addWall(self, left) @@ -1025,7 +1025,7 @@ class Wall: return self._rightkin else: raise CanteraError("side must be 'left' or 'right'") - + def set(self, **p): """Set various wall parameters: 'A', 'U', 'K', 'Q'. 'velocity'. These have the same meanings as in the constructor. @@ -1036,7 +1036,7 @@ class Wall: elif item == 'R': self.setThermalResistance(p[item]) elif item == 'U': - self.setHeatTransferCoeff(p[item]) + self.setHeatTransferCoeff(p[item]) elif item == 'K': self.setExpansionRateCoeff(p[item]) elif item == 'Q': @@ -1045,7 +1045,7 @@ class Wall: self.setVelocity(p[item]) else: raise 'unknown parameter: ',item - + def addSensitivityReaction(self, side = 'unknown', reactions = []): k = self.kinetics(side) @@ -1060,10 +1060,10 @@ class Wall: self._paramid.append(k.reactionEqn(n)) _cantera.wall_addSensitivityReaction(self.__wall_id, _ilr[side], n) - - + + class ReactorNet: - + """Networks of reactors. ReactorNet objects are used to simultaneously advance the state of a set of coupled reactors. @@ -1075,7 +1075,7 @@ class ReactorNet: >>> reactor_network = ReactorNet([r1, r2]) >>> reactor_network.advance(time) - + """ @@ -1102,7 +1102,7 @@ class ReactorNet: kernel reactornet object. For internal use. """ return self.__reactornet_id - + def add(self, reactor): """ Add a reactor to the network. @@ -1111,7 +1111,7 @@ class ReactorNet: _cantera.reactornet_addreactor(self.__reactornet_id, reactor.reactor_id()) - + def setInitialTime(self, t0): """Set the initial time. Restarts integration from this time using the current state as the initial condition. Default: 0.0 s""" @@ -1126,8 +1126,8 @@ class ReactorNet: """Set the relative and absolute error tolerances used in integrating the reactor equations.""" _cantera.reactornet_setTolerances(self.__reactornet_id, rtol, atol) - _cantera.reactornet_setSensitivityTolerances(self.__reactornet_id, rtolsens, atolsens) - + _cantera.reactornet_setSensitivityTolerances(self.__reactornet_id, rtolsens, atolsens) + def advance(self, time): """Advance the state of the reactor network in time from the current time to time 'time'.""" @@ -1136,7 +1136,7 @@ class ReactorNet: def step(self, time): """Take a single internal time step toward time 'time'. The time after taking the step is returned.""" - return _cantera.reactornet_step(self.__reactornet_id, time) + return _cantera.reactornet_step(self.__reactornet_id, time) def reactors(self): """Return the list of reactors in the network.""" @@ -1148,7 +1148,7 @@ class ReactorNet: for r in self._reactors: sum += r.nSensParams() return sum - + def sensitivity(self, component = '', parameter = -1, reactor = ''): """Sensitivity of solution component 'component' with respect @@ -1166,9 +1166,9 @@ class ReactorNet: reactor -- reactor containing the desired component. - + """ - + n = 0 if reactor <> '': for reac in self._reactors: @@ -1188,5 +1188,3 @@ class ReactorNet: return s else: raise CanteraError("sensitivity requested for illegal parameter number:"+`parameter`) - - diff --git a/interfaces/python/Cantera/SolidTransport.py b/interfaces/python/Cantera/SolidTransport.py index 91f18ee37..6af63d4da 100644 --- a/interfaces/python/Cantera/SolidTransport.py +++ b/interfaces/python/Cantera/SolidTransport.py @@ -7,7 +7,7 @@ modified Arrhenius form, and the thermal conductivity is constant. All parameters are user-specified, not computed from a physical model. Examples: - + >>> tr = SolidTransport(solid_phase) >>> tr.setThermalConductivity(0.5) # W/m/K >>> tr.setDiffCoeff(species = "OxygenIon", A = 2.0, n = 0.0, E = 700.0) @@ -30,5 +30,3 @@ class SolidTransport(Transport): def setDiffCoeff(self, species = "", A = 0.0, n = 0.0, E = 0.0): k = self._phase.speciesIndex(species) self.setParameters(0, k, [A, n, E]) - - diff --git a/interfaces/python/Cantera/SurfacePhase.py b/interfaces/python/Cantera/SurfacePhase.py index 33310131b..5703bdaec 100644 --- a/interfaces/python/Cantera/SurfacePhase.py +++ b/interfaces/python/Cantera/SurfacePhase.py @@ -17,7 +17,7 @@ class SurfacePhase(ThermoPhase): def siteDensity(self): """Site density [kmol/m2]""" return _cantera.surf_sitedensity(self._phase_id) - + def setCoverages(self, theta): """Set the surface coverages to the values in array 'theta'.""" nt = len(theta) diff --git a/interfaces/python/Cantera/ThermoPhase.py b/interfaces/python/Cantera/ThermoPhase.py index 1fa4d0079..aebb8a808 100644 --- a/interfaces/python/Cantera/ThermoPhase.py +++ b/interfaces/python/Cantera/ThermoPhase.py @@ -37,25 +37,25 @@ class ThermoPhase(Phase): The value of 'index' is the integer index number to reference the existing kernel object. """ - + self._phase_id = 0 self._owner = 0 self.idtag = "" if index >= 0: # create a Python wrapper for an existing kernel - # ThermoPhase instance + # ThermoPhase instance self._phase_id = index - + elif xml_phase: # create a new kernel instance from an XML specification self._phase_id = _cantera.ThermoFromXML(xml_phase._xml_id) self.idtag = xml_phase["id"] self._owner = 1 - + else: raise CanteraError('either xml_phase or index must be specified') - + def __del__(self): """Delete the object. If it is the owner of the kernel object, @@ -73,7 +73,7 @@ class ThermoPhase(Phase): def setName(self, name): """ Set the name attribute. This can be any string""" self.idtag = name - + def refPressure(self): """Reference pressure [Pa]. All standard-state thermodynamic properties are for this pressure. @@ -90,7 +90,7 @@ class ThermoPhase(Phase): return _cantera.thermo_mintemp(self._phase_id, -1) else: return _cantera.thermo_mintemp(self._phase_id, - self.speciesIndex(sp)) + self.speciesIndex(sp)) def maxTemp(self, sp=None): """ Maximum temperature for which thermodynamic property fits @@ -102,7 +102,7 @@ class ThermoPhase(Phase): return _cantera.thermo_maxtemp(self._phase_id, -1) else: return _cantera.thermo_maxtemp(self._phase_id, - self.speciesIndex(sp)) + self.speciesIndex(sp)) def enthalpy_mole(self): """ The molar enthalpy [J/kmol].""" @@ -110,7 +110,7 @@ class ThermoPhase(Phase): def intEnergy_mole(self): """ The molar internal energy [J/kmol].""" - return _cantera.thermo_getfp(self._phase_id,2) + return _cantera.thermo_getfp(self._phase_id,2) def entropy_mole(self): """ The molar entropy [J/kmol/K].""" @@ -119,7 +119,7 @@ class ThermoPhase(Phase): def gibbs_mole(self): """ The molar Gibbs function [J/kmol].""" return _cantera.thermo_getfp(self._phase_id,4) - + def cp_mole(self): """ The molar heat capacity at constant pressure [J/kmol/K].""" return _cantera.thermo_getfp(self._phase_id,5) @@ -130,15 +130,15 @@ class ThermoPhase(Phase): def pressure(self): """ The pressure [Pa].""" - return _cantera.thermo_getfp(self._phase_id,7) + return _cantera.thermo_getfp(self._phase_id,7) def electricPotential(self): """Electric potential [V].""" return _cantera.thermo_getfp(self._phase_id,25) - + def chemPotentials(self, species = []): """Species chemical potentials. - + This method returns an array containing the species chemical potentials [J/kmol]. The expressions used to compute these depend on the model implemented by the @@ -148,19 +148,19 @@ class ThermoPhase(Phase): def elementPotentials(self, elements = []): """Element potentials of the elements. - + This method returns an array containing the element potentials [J/kmol]. The element potentials are only defined for equilibrium states. This method first sets the composition to a state of equilibrium holding T and P constant, then computes the element potentials for this equilibrium state. """ - + lamb = _cantera.thermo_getarray(self._phase_id,21) return self.selectElements(lamb, elements) - + def enthalpies_RT(self, species = []): """Pure species non-dimensional reference state enthalpies. - + This method returns an array containing the pure-species standard-state enthalpies divided by RT. For gaseous species, these values are ideal gas enthalpies.""" @@ -169,7 +169,7 @@ class ThermoPhase(Phase): def entropies_R(self, species = []): """Pure species non-dimensional entropies. - + This method returns an array containing the pure-species standard-state entropies divided by R. For gaseous species, these values are ideal gas entropies.""" @@ -178,24 +178,24 @@ class ThermoPhase(Phase): def gibbs_RT(self, species = []): """Pure species non-dimensional Gibbs free energies. - + This method returns an array containing the pure-species standard-state Gibbs free energies divided by R. - For gaseous species, these are ideal gas values.""" + For gaseous species, these are ideal gas values.""" grt = (_cantera.thermo_getarray(self._phase_id,23) - _cantera.thermo_getarray(self._phase_id,24)) return self.selectSpecies(grt, species) - + def cp_R(self, species = []): """Pure species non-dimensional heat capacities at constant pressure. - + This method returns an array containing the pure-species standard-state heat capacities divided by R. For gaseous species, these values are ideal gas heat capacities.""" cpr = _cantera.thermo_getarray(self._phase_id,25) return self.selectSpecies(cpr, species) - + def setPressure(self, p): """Set the pressure [Pa].""" @@ -203,27 +203,27 @@ class ThermoPhase(Phase): def enthalpy_mass(self): """Specific enthalpy [J/kg].""" - return _cantera.thermo_getfp(self._phase_id,8) + return _cantera.thermo_getfp(self._phase_id,8) def intEnergy_mass(self): """Specific internal energy [J/kg].""" - return _cantera.thermo_getfp(self._phase_id,9) + return _cantera.thermo_getfp(self._phase_id,9) def entropy_mass(self): """Specific entropy [J/kg/K].""" - return _cantera.thermo_getfp(self._phase_id,10) + return _cantera.thermo_getfp(self._phase_id,10) def gibbs_mass(self): """Specific Gibbs free energy [J/kg].""" - return _cantera.thermo_getfp(self._phase_id,11) + return _cantera.thermo_getfp(self._phase_id,11) def cp_mass(self): """Specific heat at constant pressure [J/kg/K].""" - return _cantera.thermo_getfp(self._phase_id,12) + return _cantera.thermo_getfp(self._phase_id,12) def cv_mass(self): - """Specific heat at constant volume [J/kg/K].""" - return _cantera.thermo_getfp(self._phase_id,13) + """Specific heat at constant volume [J/kg/K].""" + return _cantera.thermo_getfp(self._phase_id,13) def setState_TPX(self, t, p, x): """Set the temperature [K], pressure [Pa], and @@ -234,23 +234,23 @@ class ThermoPhase(Phase): def setState_TPY(self, t, p, y): """Set the temperature [K], pressure [Pa], and - mass fractions.""" + mass fractions.""" self.setTemperature(t) self.setMassFractions(y) self.setPressure(p) def setState_TP(self, t, p): - """Set the temperature [K] and pressure [Pa].""" + """Set the temperature [K] and pressure [Pa].""" self.setTemperature(t) self.setPressure(p) def setState_PX(self, p, x): - """Set the pressure [Pa], and mole fractions.""" + """Set the pressure [Pa], and mole fractions.""" self.setMoleFractions(x) self.setPressure(p) def setState_PY(self, p, y): - """Set the pressure [Pa], and mass fractions.""" + """Set the pressure [Pa], and mass fractions.""" self.setMassFractions(y) self.setPressure(p) @@ -262,54 +262,54 @@ class ThermoPhase(Phase): def setState_UV(self, u, v): """Set the state by specifying the specific internal energy and the specific volume.""" - _cantera.thermo_setfp(self._phase_id, 3, u, v) + _cantera.thermo_setfp(self._phase_id, 3, u, v) def setState_SV(self, s, v): """Set the state by specifying the specific entropy and the specific volume.""" _cantera.thermo_setfp(self._phase_id, 4, s, v) - + def setState_SP(self, s, p): """Set the state by specifying the specific entropy - energy and the pressure.""" - _cantera.thermo_setfp(self._phase_id, 5, s, p) + energy and the pressure.""" + _cantera.thermo_setfp(self._phase_id, 5, s, p) def setElectricPotential(self, v): """Set the electric potential.""" _cantera.thermo_setfp(self._phase_id, 6, v, 0); - + def equilibrate(self, XY, solver = -1, rtol = 1.0e-9, maxsteps = 1000, maxiter = 100, loglevel = 0): """ Set to a state of chemical equilibrium holding property pair 'XY' constant. - + XY --- A two-letter string, which must be one of the set ['TP','TV','HP','SP','SV','UV','PT','VT','PH','PS','VS','VU']. If H, U, S, or V is specified, the value must be the specific value (per unit mass) - + solver --- Specifies the equilibrium solver to use. If solver = 0, a fast solver using the element potential method will be used. If solver > 0, a slower but more robust Gibbs minimization solver will be used. If solver < 0 or unspecified, the fast solver will be tried first, then if it fails the other will be tried. - + rtol -- the relative error tolerance. - + maxsteps -- maximum number of steps in composition to take to find a converged solution. - + maxiter -- for the Gibbs minimization solver only, this specifies the number of 'outer' iterations on T or P when some property pair other than TP is specified. - + loglevel -- set to a value > 0 to write diagnostic output to a file in HTML format. Larger values generate more detailed information. The file will be named 'equilibrate_log.html.' Subsequent files will be named 'equillibrate_log1.html', etc., so that log files are not overwritten. - + """ _cantera.thermo_equil(self._phase_id, XY, solver, rtol, maxsteps, maxiter, loglevel) @@ -326,7 +326,7 @@ class ThermoPhase(Phase): def restoreState(self, s): """Restore the state to that stored in array s.""" self.setState_TRY(s[0], s[1], s[2:]) - + def thermophase(self): """Return the integer index that is used to reference the kernel object. For internal use.""" @@ -334,12 +334,5 @@ class ThermoPhase(Phase): def thermo_hndl(self): """Return the integer index that is used to - reference the kernel object. For internal use.""" + reference the kernel object. For internal use.""" return self._phase_id - - - - - - - diff --git a/interfaces/python/Cantera/Transport.py b/interfaces/python/Cantera/Transport.py index c2844bee1..1b9e7f50a 100755 --- a/interfaces/python/Cantera/Transport.py +++ b/interfaces/python/Cantera/Transport.py @@ -40,7 +40,7 @@ class Transport: managers may be installed in one Python transport manager, although only one is active at any one time. This feature allows switching between transport models.""" - + def __init__(self, xml_phase=None, phase=None, model = "", loglevel=0): """Create a transport property manager. @@ -63,13 +63,13 @@ class Transport: self.model = "" else: self.model = model - + self.__tr_id = 0 self.__tr_id = _cantera.Transport(self.model, phase._phase_id, loglevel) self.trnsp = phase.nSpecies() self._phase_id = phase._phase_id - + # dictionary holding all installed transport managers self._models = {} self._models[self.model] = self.__tr_id @@ -92,7 +92,7 @@ class Transport: new_id = _cantera.Transport(model, self._phase_id, loglevel) self._models[model] = new_id - + def switchTransportModel(self, model): """Switch to a different transport model.""" @@ -102,7 +102,7 @@ class Transport: else: raise CanteraError("Transport model "+model+" not defined. Use " +"method addTransportModel first.") - + def desc(self): """A short description of the active model.""" if self.model == 'Multi': @@ -111,15 +111,15 @@ class Transport: return 'Mixture-averaged' else: return self.model - + def transport_id(self): """For internal use.""" return self.__tr_id def transport_hndl(self): - """For internal use.""" + """For internal use.""" return self.__tr_id - + def viscosity(self): "Viscosity [Pa-s].""" return _cantera.tran_viscosity(self.__tr_id) @@ -143,11 +143,11 @@ class Transport: """Species diffusion coefficients. (m^2/s).""" return self.mixDiffCoeffs() - + def mixDiffCoeffs(self): """Mixture-averaged diffusion coefficients.""" return _cantera.tran_mixDiffCoeffs(self.__tr_id, - self.trnsp) + self.trnsp) def multiDiffCoeffs(self): """Two-dimensional array of species multicomponent diffusion @@ -159,10 +159,10 @@ class Transport: """Set model-specific parameters.""" return _cantera.tran_setParameters(self.__tr_id, type, k, asarray(params)) - + def molarFluxes(self, state1, state2, delta): - return _cantera.tran_getMolarFluxes(self.__tr_id, self.trnsp, + return _cantera.tran_getMolarFluxes(self.__tr_id, self.trnsp, asarray(state1), asarray(state2), delta) diff --git a/interfaces/python/Cantera/XML.py b/interfaces/python/Cantera/XML.py index ec7f58c03..0addb9ada 100644 --- a/interfaces/python/Cantera/XML.py +++ b/interfaces/python/Cantera/XML.py @@ -1,5 +1,5 @@ """ -This module provides the Python interface to C++ class XML_Node. +This module provides the Python interface to C++ class XML_Node. """ import _cantera @@ -7,17 +7,17 @@ import types import tempfile import string import exceptions - + class XML_Node: """A node in an XML tree.""" def __init__(self, name="--", src="", wrap=0, root=None, preprocess=0, debug=0): """ Return an instance representing a node in an XML tree. - + If 'src' is specified, then the XML tree found in file 'src' is constructed, and this node forms the root of the tree. The XML tree is saved, and a second call with the same value for 'src' will use - the XML tree already read in, instead of reading it in again. + the XML tree already read in, instead of reading it in again. If 'wrap' is greater than zero, then only a Python wrapper is created - no new kernel object results. @@ -34,11 +34,11 @@ class XML_Node: elif src: self._xml_id = _cantera.xml_get_XML_File(src, debug) self.wrap = 1 # disable deleting - + # create a new empty node else: self._xml_id = _cantera.xml_new(name) - + def __del__(self): """Delete the node. Does nothing if this node is only a wrapper.""" if not self.wrap: @@ -70,10 +70,10 @@ class XML_Node: if (tag == "" or ch.tag() == tag): children.append(ch) return children - + def removeChild(self, child): """Remove a child and all its descendants.""" - _cantera.xml_removeChild(self._xml_id, child._xml_id) + _cantera.xml_removeChild(self._xml_id, child._xml_id) def addChild(self, name, value=""): """Add a child with tag 'name', and set its value if the value @@ -89,7 +89,7 @@ class XML_Node: x = self.attrib(key) if x: return 1 else: return 0 - + def attrib(self, key): """Return attribute 'key', or the empty string if this attribute does not exist.""" @@ -105,7 +105,7 @@ class XML_Node: def addComment(self, comment): """Add a comment.""" _cantera.xml_addComment(self._xml_id, comment) - + def value(self, loc=""): """Return the value of this node, or, if the loc argument is supplied, of the node with relative @@ -123,7 +123,7 @@ class XML_Node: m = _cantera.xml_findID(self._xml_id, id) elif name: m = _cantera.xml_findByName(self._xml_id, name) - + ch = XML_Node(wrap=m) return ch @@ -133,12 +133,12 @@ class XML_Node: def __setitem__(self, key, value): """Set a new attribute using the syntax node[key] = value.""" - return self.addAttrib(key, value) + return self.addAttrib(key, value) def __int__(self): """Conversion to integer.""" return self._xml_id - + def __call__(self, loc=''): """Get the value using the syntax node(loc).""" return self.value(loc) @@ -160,16 +160,7 @@ class XML_Node: def clear_XML(): _cantera.xml_clear() - + def getFloatArray(node, convert_units=0): sz = int(node['size']) return _cantera.ctml_getFloatArray(node._xml_id, convert_units, sz) - - - - - - - - - diff --git a/interfaces/python/Cantera/__init__.py b/interfaces/python/Cantera/__init__.py index 8fc7ba34b..8d66cd688 100755 --- a/interfaces/python/Cantera/__init__.py +++ b/interfaces/python/Cantera/__init__.py @@ -32,7 +32,7 @@ def writeCSV(f, list): f.write(item+', ') else: f.write(`item`+', ') - + f.write('\n') @@ -47,7 +47,7 @@ def table(keys, values): def getCanteraError(): """Return the Cantera error message, if any.""" - return _cantera.get_Cantera_Error() + return _cantera.get_Cantera_Error() def refCount(a): """Return the reference count for an object.""" @@ -65,13 +65,12 @@ def reset(): """Release all cached Cantera data. Equivalent to starting a fresh session.""" _cantera.ct_appdelete() - + # workaround for case problems in CVS repository file Mixture.py. On some # systems it appears as mixture.py, and on others as Mixture.py try: from Mixture import Mixture except: from mixture import Mixture - -from num import * +from num import * diff --git a/interfaces/python/Cantera/ck2cti.py b/interfaces/python/Cantera/ck2cti.py index 6bf936477..35b220102 100644 --- a/interfaces/python/Cantera/ck2cti.py +++ b/interfaces/python/Cantera/ck2cti.py @@ -24,11 +24,10 @@ validate - If set to 1, the mechanism will be checked for errors. This is recommended, but for very large mechanisms may slow down the conversion process. Default: on (1). -The translated file is written to the standard output. +The translated file is written to the standard output. """ def ck2cti(infile = "chem.inp", thermodb = "", trandb = "", idtag = "", debug = 0, validate = 1): _cantera.ct_ck2cti(infile, thermodb, trandb, idtag, debug, validate) - diff --git a/interfaces/python/Cantera/elements.py b/interfaces/python/Cantera/elements.py index 28b6caef2..219e1f202 100755 --- a/interfaces/python/Cantera/elements.py +++ b/interfaces/python/Cantera/elements.py @@ -13,7 +13,7 @@ def elementMoles(s, element): # in s. If it does not, return zero moles. try: m = s.elementIndex(element) - if m < 0.0: return 0.0 + if m < 0.0: return 0.0 except: return 0.0 diff --git a/interfaces/python/Cantera/excel.py b/interfaces/python/Cantera/excel.py index 5eedd5bd7..1333191f6 100755 --- a/interfaces/python/Cantera/excel.py +++ b/interfaces/python/Cantera/excel.py @@ -13,7 +13,7 @@ def write_CSV_data(fname, names, npts, nvar, append, data): method 'value', defined so that data.value(j,n) returns the value of variable n at point j. """ - + if append > 0: f = open(fname,'a') else: @@ -26,6 +26,3 @@ def write_CSV_data(fname, names, npts, nvar, append, data): f.write('%10.4e, ' % data.value(j,n)) f.write('\n') f.close() - - - diff --git a/interfaces/python/Cantera/exceptions.py b/interfaces/python/Cantera/exceptions.py index 770192237..64eeab438 100755 --- a/interfaces/python/Cantera/exceptions.py +++ b/interfaces/python/Cantera/exceptions.py @@ -24,4 +24,3 @@ class CanteraError(Exception): class OptionError(CanteraError): def __init__(self, msg): self.msg = 'Unknown option: '+msg - diff --git a/interfaces/python/Cantera/gases.py b/interfaces/python/Cantera/gases.py index 8b6d11239..e9f9df0ea 100755 --- a/interfaces/python/Cantera/gases.py +++ b/interfaces/python/Cantera/gases.py @@ -30,17 +30,16 @@ def GRI30(transport = ""): elif transport == "Mix": return Solution(src="gri30.cti", id="gri30_mix") elif transport == "Multi": - return Solution(src="gri30.cti", id="gri30_multi") - + return Solution(src="gri30.cti", id="gri30_multi") + def Air(): """Return a Solution instance implementing the O/N/Ar portion of reaction mechanism GRI-Mech 3.0. The initial composition is set to - that of air""" + that of air""" return Solution(src="air.cti", id="air") def Argon(): - """Return a Solution instance representing pure argon.""" + """Return a Solution instance representing pure argon.""" return Solution(src="argon.cti", id="argon") - diff --git a/interfaces/python/Cantera/importFromFile.py b/interfaces/python/Cantera/importFromFile.py index 25eb5fba7..8f355864c 100755 --- a/interfaces/python/Cantera/importFromFile.py +++ b/interfaces/python/Cantera/importFromFile.py @@ -36,7 +36,7 @@ def importInterface(file, name = '', phases = []): representing a gas phase or a solid. >>> gas1, cryst1 = importPhases('diamond.cti', ['gas', 'solid']) >>> diamond_surf = importInterface('diamond.cti', [gas1, cryst1]) - + Note the difference between the lists in the argument lists of these two functions. In importPhases, a list of name strings is entered, which are used to identify the appropriate definitions in the input @@ -50,7 +50,7 @@ def importInterface(file, name = '', phases = []): src = file+'#'+name else: src = file - return Interface.Interface(src = src, phases = phases) + return Interface.Interface(src = src, phases = phases) def importEdge(file, name = '', surfaces = []): @@ -58,5 +58,4 @@ def importEdge(file, name = '', surfaces = []): src = file+'#'+name else: src = file - return Edge.Edge(src = src, surfaces = surfaces) - + return Edge.Edge(src = src, surfaces = surfaces) diff --git a/interfaces/python/Cantera/interp.py b/interfaces/python/Cantera/interp.py index 7d2ad4854..d9ac3137b 100755 --- a/interfaces/python/Cantera/interp.py +++ b/interfaces/python/Cantera/interp.py @@ -6,13 +6,13 @@ def interp(z0, z, f): Sequences z and f must be of the same length, and the entries in z must be monotonically increasing. - Example: + Example: >>> z = [0.0, 0.2, 0.5, 1.2, 2.1] >>> f = [3.0, 2.0, 1.0, 0.0, -1.0] >>>print interp(-2, z, f), interp(0.5, z, f), interp(6, z, f) 3.0 7.0 -9.0 """ - + n = len(z) # if z0 is outside the range of z, then return the endpoint value, @@ -61,4 +61,4 @@ def quadInterp(z0, z, f): ## f = [3.0, 5.0, 11.0, 0.0, -9.0] ## print interp(-2, z, f), interp(0.3, z, f), interp(6, z, f) -## print quadInterp(-2, z, f), quadInterp(0.3, z, f), quadInterp(6, z, f) +## print quadInterp(-2, z, f), quadInterp(0.3, z, f), quadInterp(6, z, f) diff --git a/interfaces/python/Cantera/liquidvapor.py b/interfaces/python/Cantera/liquidvapor.py index 983d99ddf..e91d7dc67 100644 --- a/interfaces/python/Cantera/liquidvapor.py +++ b/interfaces/python/Cantera/liquidvapor.py @@ -15,7 +15,7 @@ import XML import _cantera -class PureFluid(ThermoPhase): +class PureFluid(ThermoPhase): """ A class for chemically-reacting solutions. @@ -38,16 +38,16 @@ class PureFluid(ThermoPhase): if id: s = root.child(id = id) - + else: s = root.child(name = "phase") self._name = s['id'] - + # initialize the equation of state ThermoPhase.__init__(self, xml_phase=s) - + def __del__(self): ThermoPhase.__del__(self) @@ -56,7 +56,7 @@ class PureFluid(ThermoPhase): def name(self): return self._name - + def set(self, **options): """Set various properties. T --- temperature [K] @@ -72,7 +72,7 @@ class PureFluid(ThermoPhase): Liquid --- saturated liquid fraction """ setByName(self, options) - + def critTemperature(self): """Critical temperature [K].""" return _cantera.thermo_getfp(self._phase_id,50) @@ -96,11 +96,11 @@ class PureFluid(ThermoPhase): def setState_Tsat(self, t, vaporFraction): """Set the state of a saturated liquid/vapor mixture by - specifying the temperature and vapor fraction.""" - _cantera.thermo_setfp(self._phase_id,7, t, vaporFraction) + specifying the temperature and vapor fraction.""" + _cantera.thermo_setfp(self._phase_id,7, t, vaporFraction) + - def Water(): return PureFluid('liquidvapor.cti','water') @@ -124,4 +124,3 @@ def CarbonDioxide(): def Heptane(): return PureFluid('liquidvapor.cti','heptane') - diff --git a/interfaces/python/Cantera/mixture.py b/interfaces/python/Cantera/mixture.py index 45b078fe2..7bce9effa 100644 --- a/interfaces/python/Cantera/mixture.py +++ b/interfaces/python/Cantera/mixture.py @@ -14,7 +14,7 @@ class Mixture: mixtures of one or more phases of matter. To construct a mixture, supply a list of phases to the constructor, each paired with the number of moles for that phase: - + >>> gas = importPhase('gas.cti') >>> gas.speciesNames() ['H2', 'H', 'O2', 'O', 'OH'] @@ -24,7 +24,7 @@ class Mixture: >>> mix = Mixture([(gas, 1.0), (graphite, 0.1)]) >>> mix.speciesNames() ['H2', 'H', 'O2', 'O', 'OH', 'C(g)'] - + Note that the objects representing each phase compute only the intensive state of the phase -- they do not store any information on the amount of this phase. Mixture objects, on the other hand, represent @@ -36,10 +36,10 @@ class Mixture: ('heavyweight') phase objects. Multiple mixture objects may be constructed using the same set of phase objects. Each one stores its own state information locally, and synchronizes the phases - objects whenever it requires phase properties. + objects whenever it requires phase properties. """ - + def __init__(self, phases=[]): """ init """ self.__mixid = _cantera.mix_new() @@ -58,9 +58,9 @@ class Mixture: moles = 0 self._addPhase(ph, moles) self._phases.append(ph) - _cantera.mix_init(self.__mixid) + _cantera.mix_init(self.__mixid) self.setTemperature(self._phases[0].temperature()) - self.setPressure(self._phases[0].pressure()) + self.setPressure(self._phases[0].pressure()) def __del__(self): """Delete the Mixture instance. The phase objects are not deleted.""" @@ -77,7 +77,7 @@ class Mixture: def _addPhase(self, phase = None, moles = 0.0): """Add a phase to the mixture.""" for k in range(phase.nSpecies()): - self._spnames.append(phase.speciesName(k)) + self._spnames.append(phase.speciesName(k)) _cantera.mix_addPhase(self.__mixid, phase.thermo_hndl(), moles) def nPhases(self): @@ -87,7 +87,7 @@ class Mixture: def phase(self, n): """Return the object representing the nth phase in the mixture.""" return self._phases[n] - + def phaseName(self, n): """Name of phase n.""" return self._phases[n].name() @@ -109,7 +109,7 @@ class Mixture: if self.phaseName(n) == phase: return n return -1 - + def nElements(self): """Total number of elements present in the mixture.""" return _cantera.mix_nElements(self.__mixid) @@ -124,24 +124,24 @@ class Mixture: return _cantera.mix_elementIndex(self.__mixid, element) else: return element - + def nSpecies(self): """Total number of species present in the mixture. This is the sum of the numbers of species in each phase.""" return _cantera.mix_nSpecies(self.__mixid) - + def speciesName(self, k): """Name of the species with index k. Note that index numbers are assigned in order as phases are added.""" return self._spnames[k] - + def speciesNames(self): n = self.nSpecies() s = [] for k in range(n): s.append(self.speciesName(k)) return s - + def speciesIndex(self, species): """Index of species with name 'species'. If 'species' is not a string, then it is simply returned.""" @@ -149,7 +149,7 @@ class Mixture: return self._spnames.index(species) else: return species - + def nAtoms(self, k, m): """Number of atoms of element m in species k. Both the species and the element may be referenced either by name or by index number. @@ -161,45 +161,45 @@ class Mixture: kk = self.speciesIndex(k) mm = self.elementIndex(m) return _cantera.mix_nAtoms(self.__mixid, kk, mm) - + def setTemperature(self, t): """Set the temperature [K]. The temperatures of all phases are set to this value, holding the pressure fixed.""" return _cantera.mix_setTemperature(self.__mixid, t) - + def temperature(self): """The temperature [K].""" return _cantera.mix_temperature(self.__mixid) - + def minTemp(self): """The minimum temperature for which all species in multi-species solutions have valid thermo data. Stoichiometric phases are not considered in determining minTemp. """ return _cantera.mix_minTemp(self.__mixid) - + def maxTemp(self): """The maximum temperature for which all species in multi-species solutions have valid thermo data. Stoichiometric - phases are not considered in determining maxTemp. """ + phases are not considered in determining maxTemp. """ return _cantera.mix_maxTemp(self.__mixid) - + def charge(self): """The total charge in Coulombs, summed over all phases.""" return _cantera.mix_charge(self.__mixid) - + def phaseCharge(self, p): """The charge of phase p (Coulombs).""" return _cantera.mix_phaseCharge(self.__mixid, p) - + def setPressure(self, p): """Set the pressure [Pa]. The pressures of all phases are set to the specified value, holding the temperature fixed.""" return _cantera.mix_setPressure(self.__mixid, p) - + def pressure(self): """The pressure [Pa].""" return _cantera.mix_pressure(self.__mixid) - + def phaseMoles(self, n = -1): """Moles of phase n.""" if n == -1: @@ -208,13 +208,13 @@ class Mixture: for m in range(np): moles[m] = _cantera.mix_phaseMoles(self.__mixid, m) return moles - else: + else: return _cantera.mix_phaseMoles(self.__mixid, n) - + def setPhaseMoles(self, n, moles): """Set the number of moles of phase n.""" _cantera.mix_setPhaseMoles(self.__mixid, n, moles) - + 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 @@ -229,21 +229,21 @@ class Mixture: _cantera.mix_setMolesByName(self.__mixid, moles) else: _cantera.mix_setMoles(self.__mixid, asarray(moles)) - + def speciesMoles(self, species = ""): """Moles of species k.""" moles = zeros(self.nSpecies(),'d') for k in range(self.nSpecies()): moles[k] = _cantera.mix_speciesMoles(self.__mixid, k) return self.selectSpecies(moles, species) - + def elementMoles(self, m): """Total number of moles of element m, summed over all species. The element may be referenced either by index number or by name. """ mm = self.elementIndex(m) return _cantera.mix_elementMoles(self.__mixid, mm) - + def chemPotentials(self, species=[]): """The chemical potentials of all species [J/kmol].""" mu = zeros(self.nSpecies(),'d') @@ -261,7 +261,7 @@ class Mixture: self.setSpeciesMoles(v) else: raise CanteraError("unknown property: "+o) - + def equilibrate(self, XY = "TP", err = 1.0e-9, maxsteps = 1000, maxiter = 200, loglevel = 0): """Set the mixture to a state of chemical equilibrium. @@ -277,11 +277,11 @@ class Mixture: specified temperature and pressure. If any other property pair other than "TP" is specified, then an outer iteration loop is used to adjust T and/or P so that the specified property - values are obtained. - + values are obtained. + XY - Two-letter string specifying the two properties to hold fixed. Currently, 'TP', 'HP', and 'SP' are implemented. Default: 'TP'. - + err - Error tolerance. Iteration will continue until (Delta mu)/RT is less than this value for each reaction. Default: 1.0e-9. Note that this default is very conservative, and good @@ -310,11 +310,11 @@ class Mixture: "equilibrate_log.html", "equilibrate_log1.html", "equilibrate_log2.html", and so on. Existing log files will not be overwritten. - + >>> mix.equilibrate('TP') >>> mix.equilibrate('TP', err = 1.0e-6, maxiter = 500) - + """ i = _cantera.mix_equilibrate(self.__mixid, XY, err, maxsteps, maxiter, loglevel) @@ -335,8 +335,8 @@ class Mixture: specified temperature and pressure. If any other property pair other than "TP" is specified, then an outer iteration loop is used to adjust T and/or P so that the specified property - values are obtained. - + values are obtained. + XY - Two-letter string specifying the two properties to hold fixed. Currently, 'TP', 'HP', and 'SP' are implemented. Default: 'TP'. @@ -348,7 +348,7 @@ class Mixture: solver - Determines which solver is used. - 1 MultiPhaseEquil solver - 2 VCSnonideal Solver (default) - + err - Error tolerance. Iteration will continue until (Delta mu)/RT is less than this value for each reaction. Default: 1.0e-9. Note that this default is very conservative, and good @@ -377,13 +377,13 @@ class Mixture: "equilibrate_log.html", "equilibrate_log1.html", "equilibrate_log2.html", and so on. Existing log files will not be overwritten. - + """ i = _cantera.mix_vcs_equilibrate(self.__mixid, XY, estimateEquil, printLvl, solver, rtol, maxsteps, maxiter, loglevel) - + def selectSpecies(self, f, species): """Given an array 'f' of floating-point species properties, return an array of those values corresponding to species @@ -406,5 +406,3 @@ class Mixture: return asarray(fs) else: return f - - diff --git a/interfaces/python/Cantera/num.py b/interfaces/python/Cantera/num.py index 90c48cdcc..56fc9913b 100644 --- a/interfaces/python/Cantera/num.py +++ b/interfaces/python/Cantera/num.py @@ -13,16 +13,16 @@ try: nummodule = Numeric except: print """ - + ERROR: """+_cantera.nummod+""" not found! - + Cantera uses a set of numerical extensions to Python, but these do not appear to be present on your system. To install the required package, go to http://sourceforge.net/projects/numpy, and install either the """+_cantera.nummod+""" package for your system. If you are using a Windows system, use the binary installer to install the selected package for you automatically. - + """ raise "could not import "+_cantera.nummod diff --git a/interfaces/python/Cantera/rxnpath.py b/interfaces/python/Cantera/rxnpath.py index a3c300727..f38f0ffc5 100755 --- a/interfaces/python/Cantera/rxnpath.py +++ b/interfaces/python/Cantera/rxnpath.py @@ -27,7 +27,7 @@ PathDiagram keyword options: -- type 'both' or 'net' (forward and reverse arrows, or net arrow) -- dot_options options passed through to 'dot' - + colors: -- normal_color color for normal-weight lines -- bold_color color for bold-weight lines @@ -38,7 +38,7 @@ PathDiagram keyword options: -- normal_threshold min relative strength for normal-weight path Below this value, paths are dashed. -- bold_threshold min relative strength for bold-weight path - + """ import _cantera @@ -64,10 +64,10 @@ class PathDiagram: def __del__(self): _cantera.rdiag_del(self.__rdiag_id) - + def id(self): return self.__rdiag_id - + def write(self, fmt, file): _cantera.rdiag_write(self.__rdiag_id, fmt, file) @@ -79,7 +79,7 @@ class PathDiagram: def displayOnly(self, node=-1): _cantera.rdiag_displayOnly(self.__rdiag_id, node) - + def setOptions(self, options): for o in options.keys(): v = options[o] @@ -111,7 +111,7 @@ class PathDiagram: elif o == "label_threshold": _cantera.rdiag_setLabelThreshold(self.__rdiag_id, v) elif o == "font": - _cantera.rdiag_setFont(self.__rdiag_id, v) + _cantera.rdiag_setFont(self.__rdiag_id, v) elif o == "flow_type": if v == "one_way": _cantera.rdiag_setFlowType(self.__rdiag_id, 0) @@ -119,9 +119,9 @@ class PathDiagram: _cantera.rdiag_setFlowType(self.__rdiag_id, 1) else: raise("unknown attribute "+o) - + class PathBuilder: - + def __init__(self, kin, logfile=""): if logfile == "": logfile = "rxnpath.log" @@ -131,7 +131,7 @@ class PathBuilder: def __del__(self): _cantera.rbuild_del(self.__rbuild_id) - + def build(self, diagram = None, element = "C", dotfile = "rxnpaths.dot", format="dot"): if diagram == None: @@ -140,7 +140,7 @@ class PathBuilder: "buildlog", diagram.id(), 1) if format == "dot": diagram.write(0, dotfile) - diagram.write(1, "rp.txt") + diagram.write(1, "rp.txt") elif format == "plain": diagram.write(1, dotfile) @@ -156,14 +156,11 @@ def view(url, ext = 'png'): import webbrowser dot_server = 'http://webdot.graphviz.org/cgi-bin/webdot/' webbrowser.open(dot_server+url+'.dot.'+ext) - - + + if __name__ == "__main__": from Cantera.gases import GRI30 gas = GRI30() x = [1.0] * gas.nSpecies() gas.setState_TPX(1800.0, 1.01325e5, x) write(gas, 'C', 'c:/users/dgg/test.dot') - - - diff --git a/interfaces/python/Cantera/set.py b/interfaces/python/Cantera/set.py index fd052de73..45561446d 100755 --- a/interfaces/python/Cantera/set.py +++ b/interfaces/python/Cantera/set.py @@ -22,8 +22,8 @@ def setByName(a, options): Entropy S specific entropy Vapor Vap vapor fraction in a two-phase mixture Liquid Liq liquid fraction in a two-phase mixture - - + + """ tval = None @@ -33,7 +33,7 @@ def setByName(a, options): sval = None vval = None qval = None - + np = 0 nt = 0 nv = 0 @@ -43,7 +43,7 @@ def setByName(a, options): nh = 0 nu = 0 nq = 0 - + for o in options.keys(): val = options[o] if o == 'Temperature' or o == 'T': @@ -60,7 +60,7 @@ def setByName(a, options): a.setMoleFractions(val) elif o == 'MassFractions' or o == 'Y': ny += 1 - a.setMassFractions(val) + a.setMassFractions(val) elif o == 'Pressure' or o == 'P': pval = val np += 1 @@ -69,7 +69,7 @@ def setByName(a, options): nh += 1 elif o == 'IntEnergy' or o == 'U': uval = val - nu += 1 + nu += 1 elif o == 'Entropy' or o == 'S': sval = val ns += 1 @@ -78,8 +78,8 @@ def setByName(a, options): qval = val elif o == 'Liquid' or o == 'Liq': nq += 1 - qval = 1.0 - val - + qval = 1.0 - val + else: raise CanteraError('unknown property: '+o) @@ -90,7 +90,7 @@ def setByName(a, options): for n in nn: if n > 1: raise CanteraError('property specified multiple times') - + ntot = nt + np + nv + ns + nh + nu + nq # set individual properties @@ -127,8 +127,6 @@ def setByName(a, options): else: raise CanteraError('unimplemented property pair') - + def set(a, **options): setByName(a, options) - - diff --git a/interfaces/python/Cantera/solid.py b/interfaces/python/Cantera/solid.py index da360e03c..d8b6a9853 100644 --- a/interfaces/python/Cantera/solid.py +++ b/interfaces/python/Cantera/solid.py @@ -11,12 +11,12 @@ from SolidTransport import SolidTransport import XML import _cantera -class Solid(ThermoPhase, Kinetics, SolidTransport): +class Solid(ThermoPhase, Kinetics, SolidTransport): """ """ def __init__(self, src="", root=None): - + self.ckin = 0 self._owner = 0 self.verbose = 1 @@ -31,7 +31,7 @@ class Solid(ThermoPhase, Kinetics, SolidTransport): Kinetics.__init__(self, xml_phase=s, phases=[self]) SolidTransport.__init__(self, phase=self) - + #self.setState_TP(300.0, OneAtm) @@ -43,4 +43,3 @@ class Solid(ThermoPhase, Kinetics, SolidTransport): SolidTransport.__del__(self) Kinetics.__del__(self) ThermoPhase.__del__(self) - diff --git a/interfaces/python/Cantera/solids.py b/interfaces/python/Cantera/solids.py index 6be3da64d..4ed0c5357 100755 --- a/interfaces/python/Cantera/solids.py +++ b/interfaces/python/Cantera/solids.py @@ -2,7 +2,7 @@ from solution import Solution -def Solid(src="", +def Solid(src="", kmodel=1, transport=None): return Solution(import_file=import_file, thermo_db="", @@ -11,4 +11,3 @@ def Solid(src="", kmodel=kmodel, trmodel=transport, validate=0) - diff --git a/interfaces/python/Cantera/solution.py b/interfaces/python/Cantera/solution.py index 945989f8c..aaa41e434 100755 --- a/interfaces/python/Cantera/solution.py +++ b/interfaces/python/Cantera/solution.py @@ -9,7 +9,7 @@ from set import setByName import XML import _cantera -class Solution(ThermoPhase, Kinetics, Transport): +class Solution(ThermoPhase, Kinetics, Transport): """ A class for chemically-reacting solutions. @@ -40,12 +40,12 @@ class Solution(ThermoPhase, Kinetics, Transport): if id: s = root.child(id = id) - + else: s = root.child(name = "phase") self._name = s['id'] - + # initialize the equation of state ThermoPhase.__init__(self, xml_phase=s) @@ -56,7 +56,7 @@ class Solution(ThermoPhase, Kinetics, Transport): # initialize the transport model Transport.__init__(self, xml_phase=s, phase=self, model = '', loglevel=loglevel) - + def __del__(self): Transport.__del__(self) Kinetics.__del__(self) @@ -67,7 +67,7 @@ class Solution(ThermoPhase, Kinetics, Transport): def name(self): return self._name - + def set(self, **options): """Set various properties. T --- temperature [K] @@ -83,4 +83,3 @@ class Solution(ThermoPhase, Kinetics, Transport): Liquid --- saturated liquid fraction """ setByName(self, options) - diff --git a/interfaces/python/Cantera/solve.py b/interfaces/python/Cantera/solve.py index 06c49862f..044e07229 100755 --- a/interfaces/python/Cantera/solve.py +++ b/interfaces/python/Cantera/solve.py @@ -1,7 +1,7 @@ """ Solve a steady-state problem by combined damped Newton iteration and time integration. Function solve is no longer used, now that the functional equivalent has been added to the Cantera C++ kernel. """ - + from Cantera import CanteraError from Cantera.num import array import math, types @@ -17,7 +17,7 @@ def solve(sim, loglevel = 0, refine_grid = 1, plotfile = '', savefile = ''): Solve a steady-state problem by combined damped Newton iteration and time integration. """ - + new_points = 1 # get options @@ -29,14 +29,14 @@ def solve(sim, loglevel = 0, refine_grid = 1, plotfile = '', savefile = ''): if type(_steps) == types.IntType: _steps = [_steps] len_nsteps = len(_steps) - dt = sim.option('timestep') - + dt = sim.option('timestep') + ll = loglevel soln_number = -1 max_timestep = sim.option('max_timestep') sim.collect() - + # loop until refine adds no more points while new_points > 0: @@ -48,35 +48,35 @@ def solve(sim, loglevel = 0, refine_grid = 1, plotfile = '', savefile = ''): while ok == 0: # Try to solve the steady-state problem by damped - # Newton iteration. + # Newton iteration. try: if loglevel > 0: print 'Attempt Newton solution of ',\ 'steady-state problem...', sim.newton_solve(loglevel-1) - + if loglevel > 0: print 'success.\n\n' - print '%'*79+'\n' + print '%'*79+'\n' print 'Problem solved on ',sim.npts,' point grid(s).\n' - print '%'*79+'\n' + print '%'*79+'\n' ok = 1 soln_number += 1 sim.finish() - + except CanteraError: # Newton iteration failed. if loglevel > 0: print '\n' - + # Take nsteps time steps, starting with step size # dt. The final dt may be smaller than the initial # value if one or more steps fail. if loglevel == 1: print 'Take',nsteps,' timesteps', - + dt = sim.py_timeStep(nsteps,dt,loglevel=ll-1) if loglevel == 1: print dt, math.log10(sim.ssnorm()) istep += 1 @@ -87,7 +87,7 @@ def solve(sim, loglevel = 0, refine_grid = 1, plotfile = '', savefile = ''): nsteps = _steps[istep] if dt > max_timestep: dt = max_timestep - + # A converged solution was found. Save and/or plot it, then # check whether the grid should be refined. @@ -104,11 +104,9 @@ def solve(sim, loglevel = 0, refine_grid = 1, plotfile = '', savefile = ''): if loglevel > 2: sim.show() if refine_grid: - + # Call refine to add new points, if needed new_points = sim.refine(loglevel = loglevel - 1) - + else: new_points = 0 - - diff --git a/interfaces/python/Cantera/stoich.py b/interfaces/python/Cantera/stoich.py index 6f28ae6a2..a9fa73ca3 100755 --- a/interfaces/python/Cantera/stoich.py +++ b/interfaces/python/Cantera/stoich.py @@ -13,9 +13,9 @@ def stoich_fuel_to_oxidizer(mix, fuel, oxidizer): This function only works for fuels composed of carbon, hydrogen, and/or oxygen. The fuel to oxidizer ratio is returned that results in - + """ - + # fuel mix.setMoleFractions(fuel) f_carbon = elementMoles(mix, 'C') @@ -43,4 +43,3 @@ def stoich_fuel_to_oxidizer(mix, fuel, oxidizer): if __name__ == "__main__": g = GRI30() print stoich_fuel_to_oxidizer(g, 'CH4:1', 'O2:1') - diff --git a/interfaces/python/Cantera/tecplot.py b/interfaces/python/Cantera/tecplot.py index 668048aee..eb613d12e 100755 --- a/interfaces/python/Cantera/tecplot.py +++ b/interfaces/python/Cantera/tecplot.py @@ -15,7 +15,7 @@ def write_TECPLOT_zone(fname, title, zone, names, npts, nvar, append, data): method 'value', defined so that data.value(j,n) returns the value of variable n at point j. """ - + if append > 0: f = open(fname,'a') else: @@ -35,6 +35,3 @@ def write_TECPLOT_zone(fname, title, zone, names, npts, nvar, append, data): f.write('%10.4e ' % data[j,n]) f.write('\n') f.close() - - - diff --git a/interfaces/python/MixMaster/CompositionFrame.py b/interfaces/python/MixMaster/CompositionFrame.py index 2fc698634..8d28a5fa2 100644 --- a/interfaces/python/MixMaster/CompositionFrame.py +++ b/interfaces/python/MixMaster/CompositionFrame.py @@ -9,238 +9,236 @@ _ATOL = 1.e-15 _RTOL = 1.e-7 class CompFrame(Frame): - def __init__(self,master): - Frame.__init__(self,master) - self.config(relief=FLAT, bd=4) - self.top = self.master.top - self.controls=Frame(self) - self.hide = IntVar() - self.hide.set(0) - self.comp = IntVar() - self.comp.set(0) - self.controls.grid(column=1,row=0,sticky=W+E+N) - self.makeControls() - mf = self.master - - def makeControls(self): - Radiobutton(self.controls,text='Moles', - variable=self.comp,value=0, - command=self.show).grid(column=0,row=0,sticky=W) - Radiobutton(self.controls,text='Mass', - variable=self.comp,value=1, - command=self.show).grid(column=0,row=1,sticky=W) - Radiobutton(self.controls,text='Concentration', - variable=self.comp,value=2, - command=self.show).grid(column=0,row=2,sticky=W) - Button(self.controls,text='Clear', - command=self.zero).grid(column=0,row=4,sticky=W+E) - Button(self.controls,text='Normalize', - command=self.norm).grid(column=0,row=5,sticky=W+E) - Checkbutton(self.controls,text='Hide Missing\nSpecies', - variable=self.hide,onvalue=1, - offvalue=0,command=self.master.redo).grid(column=0, - row=3, - sticky=W) + def __init__(self,master): + Frame.__init__(self,master) + self.config(relief=FLAT, bd=4) + self.top = self.master.top + self.controls=Frame(self) + self.hide = IntVar() + self.hide.set(0) + self.comp = IntVar() + self.comp.set(0) + self.controls.grid(column=1,row=0,sticky=W+E+N) + self.makeControls() + mf = self.master - def norm(self): - mf = self.master - mf.update() - - data = mf.comp - sum = 0.0 - for sp in data: - sum += sp - for i in range(len(mf.comp)): - mf.comp[i] /= sum - self.show() + def makeControls(self): + Radiobutton(self.controls,text='Moles', + variable=self.comp,value=0, + command=self.show).grid(column=0,row=0,sticky=W) + Radiobutton(self.controls,text='Mass', + variable=self.comp,value=1, + command=self.show).grid(column=0,row=1,sticky=W) + Radiobutton(self.controls,text='Concentration', + variable=self.comp,value=2, + command=self.show).grid(column=0,row=2,sticky=W) + Button(self.controls,text='Clear', + command=self.zero).grid(column=0,row=4,sticky=W+E) + Button(self.controls,text='Normalize', + command=self.norm).grid(column=0,row=5,sticky=W+E) + Checkbutton(self.controls,text='Hide Missing\nSpecies', + variable=self.hide,onvalue=1, + offvalue=0,command=self.master.redo).grid(column=0, + row=3, + sticky=W) - def set(self): - c = self.comp.get() - mix = self.top.mix - mf = self.master - g = mix.g - if c == 0: - mix.setMoles(mf.comp) + def norm(self): + mf = self.master + mf.update() - elif c == 1: - mix.setMass(mf.comp) + data = mf.comp + sum = 0.0 + for sp in data: + sum += sp + for i in range(len(mf.comp)): + mf.comp[i] /= sum + self.show() - elif c == 2: - pass - self.top.thermo.setState() - self.top.kinetics.show() + def set(self): + c = self.comp.get() + mix = self.top.mix + mf = self.master + g = mix.g + if c == 0: + mix.setMoles(mf.comp) - def show(self): - mf = self.master - mf.active = self - c = self.comp.get() - mix = self.top.mix - g = mix.g - if c == 0: - mf.var.set("Moles") - #mf.data = spdict(mix.g, mix.moles()) - mf.comp = mix.moles() + elif c == 1: + mix.setMass(mf.comp) - elif c == 1: - mf.var.set("Mass") - #mf.data = spdict(mix.g,mix.mass()) - mf.comp = mix.mass() + elif c == 2: + pass + self.top.thermo.setState() + self.top.kinetics.show() + + def show(self): + mf = self.master + mf.active = self + c = self.comp.get() + mix = self.top.mix + g = mix.g + if c == 0: + mf.var.set("Moles") + #mf.data = spdict(mix.g, mix.moles()) + mf.comp = mix.moles() + + elif c == 1: + mf.var.set("Mass") + #mf.data = spdict(mix.g,mix.mass()) + mf.comp = mix.mass() + + elif c == 2: + mf.var.set("Concentration") + mf.comp = mix.concentrations() + #mf.data = spdict(mix,mix,mf.comp) + + for s in mf.variable.keys(): + try: + k = g.speciesIndex(s) + if mf.comp[k] > _CUTOFF: + mf.variable[s].set(mf.comp[k]) + else: + mf.variable[s].set(0.0) + except: + pass + + + + def zero(self): + mf = self.master + mf.comp *= 0.0 + self.show() - elif c == 2: - mf.var.set("Concentration") - mf.comp = mix.concentrations() - #mf.data = spdict(mix,mix,mf.comp) - - for s in mf.variable.keys(): - try: - k = g.speciesIndex(s) - if mf.comp[k] > _CUTOFF: - mf.variable[s].set(mf.comp[k]) - else: - mf.variable[s].set(0.0) - except: - pass - - - def zero(self): - mf = self.master - mf.comp *= 0.0 - self.show() - - class MixtureFrame(Frame): - def __init__(self,master,top): - Frame.__init__(self,master) - self.config(relief=GROOVE, bd=4) - self.top = top - self.top.mixframe = self - self.g = self.top.mix.g - #self.scroll = Scrollbar(self) - self.entries=Frame(self) - #self.scroll.config(command=self.entries.xview) - #self.scroll.grid(column=0,row=1) - self.var = StringVar() - self.var.set("Moles") - self.comp = array(self.top.mix.moles()) - self.names = self.top.mix.speciesNames() - self.nsp = len(self.names) - #self.data = self.top.mix.moleDict() - self.makeControls() - self.makeEntries() - self.entries.bind('',self.minimize) - self.ctype = 0 - self.newcomp = 0 - - def makeControls(self): - self.c = CompFrame(self) - #self.k = KineticsFrame(self) - self.active = self.c - self.c.grid(column=1,row=0,sticky=E+W+N+S) - #self.k.grid(column=2,row=0,sticky=E+W+N+S) + def __init__(self,master,top): + Frame.__init__(self,master) + self.config(relief=GROOVE, bd=4) + self.top = top + self.top.mixframe = self + self.g = self.top.mix.g + #self.scroll = Scrollbar(self) + self.entries=Frame(self) + #self.scroll.config(command=self.entries.xview) + #self.scroll.grid(column=0,row=1) + self.var = StringVar() + self.var.set("Moles") + self.comp = array(self.top.mix.moles()) + self.names = self.top.mix.speciesNames() + self.nsp = len(self.names) + #self.data = self.top.mix.moleDict() + self.makeControls() + self.makeEntries() + self.entries.bind('',self.minimize) + self.ctype = 0 + self.newcomp = 0 - def update(self): - self.newcomp = 0 - for s in self.variable.keys(): - k = self.g.speciesIndex(s) - current = self.comp[k] - val = self.variable[s].get() - dv = abs(val - current) - if dv > _RTOL*abs(current) + _ATOL: - self.comp[k] = val - self.newcomp = 1 + def makeControls(self): + self.c = CompFrame(self) + #self.k = KineticsFrame(self) + self.active = self.c + self.c.grid(column=1,row=0,sticky=E+W+N+S) + #self.k.grid(column=2,row=0,sticky=E+W+N+S) - def show(self): - self.active.show() -## for k in range(self.nsp): -## sp = self.names[k] -## if self.comp[k] > _CUTOFF: -## self.variable[sp].set(self.comp[k]) -## else: -## self.variable[sp].set(0.0) - - def redo(self): - self.update() - self.entries.destroy() - self.entries=Frame(self) - self.makeEntries() + def update(self): + self.newcomp = 0 + for s in self.variable.keys(): + k = self.g.speciesIndex(s) + current = self.comp[k] + val = self.variable[s].get() + dv = abs(val - current) + if dv > _RTOL*abs(current) + _ATOL: + self.comp[k] = val + self.newcomp = 1 - def minimize(self,Event=None): - self.c.hide.set(1) - self.redo() - self.c.grid_forget() - self.entries.bind("",self.maximize) - - def maximize(self,Event=None): - self.c.hide.set(0) - self.redo() - self.c.grid(column=1,row=0,sticky=E+W+N+S) - self.entries.bind("",self.minimize) + def show(self): + self.active.show() +## for k in range(self.nsp): +## sp = self.names[k] +## if self.comp[k] > _CUTOFF: +## self.variable[sp].set(self.comp[k]) +## else: +## self.variable[sp].set(0.0) - def up(self, x): - self.update() - if self.newcomp: - self.c.set() - self.c.show() - self.top.update() - #thermo.showState() - #self.top.kinetics.show() - - def makeEntries(self): - self.entries.grid(row=0,column=0,sticky=W+N+S+E) - self.entries.config(relief=FLAT,bd=4) - DATAKEYS = self.top.species - self.variable = {} + def redo(self): + self.update() + self.entries.destroy() + self.entries=Frame(self) + self.makeEntries() - n=0 - ncol = 3 - col = 0 - row = 60 + def minimize(self,Event=None): + self.c.hide.set(1) + self.redo() + self.c.grid_forget() + self.entries.bind("",self.maximize) - equil = 0 - if self.top.thermo: - equil = self.top.thermo.equil.get() - - for sp in DATAKEYS: - s = sp # self.top.species[sp] - k = s.index - if row > 25: - row = 0 - col = col + 2 - l = Label(self.entries,text='Species') - l.grid(column=col,row=row,sticky=E+W) - e1 = Entry(self.entries) - e1.grid(column=col+1,row=row,sticky=E+W) - e1['textvariable'] = self.var - e1.config(state=DISABLED) - e1.config(bg='lightyellow',relief=RIDGE) - row = row + 1 + def maximize(self,Event=None): + self.c.hide.set(0) + self.redo() + self.c.grid(column=1,row=0,sticky=E+W+N+S) + self.entries.bind("",self.minimize) - spname = s.name - val = self.comp[k] - if not self.c.hide.get() or val: showit = 1 - else: showit = 0 + def up(self, x): + self.update() + if self.newcomp: + self.c.set() + self.c.show() + self.top.update() + #thermo.showState() + #self.top.kinetics.show() - l=SpeciesInfo(self.entries,species=s, - text=spname,relief=FLAT,justify=RIGHT, - fg='darkblue') - entry1 = Entry(self.entries) - self.variable[spname] = DoubleVar() - self.variable[spname].set(self.comp[k]) - entry1['textvariable']=self.variable[spname] - entry1.bind('',self.up) - if showit: - l.grid(column= col ,row=row,sticky=E) - entry1.grid(column=col+1,row=row) - n=n+1 - row = row + 1 - if equil == 1: - entry1.config(state=DISABLED,bg='lightgray') + def makeEntries(self): + self.entries.grid(row=0,column=0,sticky=W+N+S+E) + self.entries.config(relief=FLAT,bd=4) + DATAKEYS = self.top.species + self.variable = {} + + n=0 + ncol = 3 + col = 0 + row = 60 + + equil = 0 + if self.top.thermo: + equil = self.top.thermo.equil.get() + + for sp in DATAKEYS: + s = sp # self.top.species[sp] + k = s.index + if row > 25: + row = 0 + col = col + 2 + l = Label(self.entries,text='Species') + l.grid(column=col,row=row,sticky=E+W) + e1 = Entry(self.entries) + e1.grid(column=col+1,row=row,sticky=E+W) + e1['textvariable'] = self.var + e1.config(state=DISABLED) + e1.config(bg='lightyellow',relief=RIDGE) + row = row + 1 + + spname = s.name + val = self.comp[k] + if not self.c.hide.get() or val: showit = 1 + else: showit = 0 + + l=SpeciesInfo(self.entries,species=s, + text=spname,relief=FLAT,justify=RIGHT, + fg='darkblue') + entry1 = Entry(self.entries) + self.variable[spname] = DoubleVar() + self.variable[spname].set(self.comp[k]) + entry1['textvariable']=self.variable[spname] + entry1.bind('',self.up) + if showit: + l.grid(column= col ,row=row,sticky=E) + entry1.grid(column=col+1,row=row) + n=n+1 + row = row + 1 + if equil == 1: + entry1.config(state=DISABLED,bg='lightgray') ## if self.c.hide.get(): -## b=Button(self.entries,height=1,command=self.maximize) -## else: -## b=Button(self.entries,command=self.minimize) +## b=Button(self.entries,height=1,command=self.maximize) +## else: +## b=Button(self.entries,command=self.minimize) ## b.grid(column=col,columnspan=2, row=row+1) - - diff --git a/interfaces/python/MixMaster/ControlPanel.py b/interfaces/python/MixMaster/ControlPanel.py index 5172f78ba..b2dc7769c 100644 --- a/interfaces/python/MixMaster/ControlPanel.py +++ b/interfaces/python/MixMaster/ControlPanel.py @@ -5,209 +5,209 @@ from ScrolledText import ScrolledText #import filewindow def ff(): - print ' hi ' - + print ' hi ' + class ControlWindow(Frame): - fncs = [ff]*10 - - def __init__(self, title, master=None): - self.app = master - Frame.__init__(self,master) - self.grid(row=0,column=0,sticky=E+W+N+S) - self.master.title(title) + fncs = [ff]*10 + + def __init__(self, title, master=None): + self.app = master + Frame.__init__(self,master) + self.grid(row=0,column=0,sticky=E+W+N+S) + self.master.title(title) - def addButtons(self, label, funcs): - self.buttonholder = Frame(self, relief=FLAT, bd=2) - self.buttonholder.pack(side=TOP,anchor=W) - b = Label(self.buttonholder,text=label) - b.pack(side=LEFT,fill=X) - for f in funcs: - b=Button(self.buttonholder, - text=f[0],command=f[1], padx=1,pady=1) - b.pack(side=LEFT,fill=X) - - def disableButtons(self, *buttons): - for button in self.buttonholder.slaves(): - if (button.cget('text') in buttons): - try: - button.config(state=DISABLED) - except: - pass - - def enableButtons(self, *buttons): - for button in self.buttonholder.slaves(): - if (button.cget('text') in buttons): - try: - button.config(state=NORMAL) - except: - pass + def addButtons(self, label, funcs): + self.buttonholder = Frame(self, relief=FLAT, bd=2) + self.buttonholder.pack(side=TOP,anchor=W) + b = Label(self.buttonholder,text=label) + b.pack(side=LEFT,fill=X) + for f in funcs: + b=Button(self.buttonholder, + text=f[0],command=f[1], padx=1,pady=1) + b.pack(side=LEFT,fill=X) - + def disableButtons(self, *buttons): + for button in self.buttonholder.slaves(): + if (button.cget('text') in buttons): + try: + button.config(state=DISABLED) + except: + pass - def newFrame(self, label, var): - fr = Frame(self, relief = RIDGE, bd = 2) - fr.pack(side=TOP,fill=X) - c = Checkbutton(fr, variable=var) - c.pack(side = LEFT, fill = X) - b = Label(fr,text=label,foreground="NavyBlue") - b.pack(side=LEFT,fill=X) - return fr - - ##creates a new Toplevel object - ##options: transient=, - ## placement=(, ) - def newWindow(self, master, title, **options): - new = Toplevel(master) - new.title(title) - #new.config(takefocus=0) - if 'transient' in options.keys(): - new.transient(master) - if options['transient']: - new.protocol('WM_DELETE_WINDOW', options['transient']) - if 'placement' in options.keys(): - new.geometry("+%d+%d" % tuple(options['placement'])) - return new + def enableButtons(self, *buttons): + for button in self.buttonholder.slaves(): + if (button.cget('text') in buttons): + try: + button.config(state=NORMAL) + except: + pass - ##routes mouse and keyboard events to the window and - ##waits for it to close before returning - def makemodal(self, window): - window.focus_set() - window.grab_set() - window.wait_window() - return - - def PlotMenu(self, fr, label, funcs): - filebutton = Menubutton(fr,text=label, padx=3,pady=1) - filebutton.pack(side=LEFT) - filemenu = Menu(filebutton,tearoff=TRUE) - i = 0 - for f in funcs: - filemenu.add_command(label=f[0], command=f[1]) - i = i + 1 - filebutton['menu']=filemenu - return filemenu + + def newFrame(self, label, var): + fr = Frame(self, relief = RIDGE, bd = 2) + fr.pack(side=TOP,fill=X) + c = Checkbutton(fr, variable=var) + c.pack(side = LEFT, fill = X) + b = Label(fr,text=label,foreground="NavyBlue") + b.pack(side=LEFT,fill=X) + return fr + + ##creates a new Toplevel object + ##options: transient=, + ## placement=(, ) + def newWindow(self, master, title, **options): + new = Toplevel(master) + new.title(title) + #new.config(takefocus=0) + if 'transient' in options.keys(): + new.transient(master) + if options['transient']: + new.protocol('WM_DELETE_WINDOW', options['transient']) + if 'placement' in options.keys(): + new.geometry("+%d+%d" % tuple(options['placement'])) + return new + + ##routes mouse and keyboard events to the window and + ##waits for it to close before returning + def makemodal(self, window): + window.focus_set() + window.grab_set() + window.wait_window() + return + + + def PlotMenu(self, fr, label, funcs): + filebutton = Menubutton(fr,text=label, padx=3,pady=1) + filebutton.pack(side=LEFT) + filemenu = Menu(filebutton,tearoff=TRUE) + i = 0 + for f in funcs: + filemenu.add_command(label=f[0], command=f[1]) + i = i + 1 + filebutton['menu']=filemenu + return filemenu def testevent(event): - print 'event ',event.value + print 'event ',event.value def make_menu(name, menubar, list): - nc = len(name) - button=Menubutton(menubar, text=name, width=nc+4, padx=3,pady=1) - button.pack(side=LEFT) - menu = Menu(button,tearoff=FALSE) - m = menu - i = 0 - for entry in list: - i += 1 - if entry == 'separator': - menu.add_separator({}) - elif type(entry)==ListType: - for num in entry: - menu.entryconfig(num,state=DISABLED) - elif type(entry[1]) != ListType: - if i == 20: - i = 0 - submenu = Menu(button,tearoff=FALSE) - m.add_cascade(label='More...', - menu=submenu) - m = submenu - if len(entry) == 2 or entry[2] == 'command': - m.add_command(label=entry[0], - command=entry[1]) - elif entry[2] == 'check': - entry[3].set(0) - if len(entry) >= 5: val = entry[4] - else: val = 1 - m.add_checkbutton(label=entry[0], - command=entry[1], - variable = entry[3], - onvalue=val) - else: - submenu=make_menu(entry[0], menu, entry[1]) - m.add_cascade(label=entry[0], - menu=submenu) - button['menu']=menu - return button + nc = len(name) + button=Menubutton(menubar, text=name, width=nc+4, padx=3,pady=1) + button.pack(side=LEFT) + menu = Menu(button,tearoff=FALSE) + m = menu + i = 0 + for entry in list: + i += 1 + if entry == 'separator': + menu.add_separator({}) + elif type(entry)==ListType: + for num in entry: + menu.entryconfig(num,state=DISABLED) + elif type(entry[1]) != ListType: + if i == 20: + i = 0 + submenu = Menu(button,tearoff=FALSE) + m.add_cascade(label='More...', + menu=submenu) + m = submenu + if len(entry) == 2 or entry[2] == 'command': + m.add_command(label=entry[0], + command=entry[1]) + elif entry[2] == 'check': + entry[3].set(0) + if len(entry) >= 5: val = entry[4] + else: val = 1 + m.add_checkbutton(label=entry[0], + command=entry[1], + variable = entry[3], + onvalue=val) + else: + submenu=make_menu(entry[0], menu, entry[1]) + m.add_cascade(label=entry[0], + menu=submenu) + button['menu']=menu + return button def menuitem_state(button, *statelist): - for menu in button.children.keys(): - if isinstance(button.children[menu], Menu): - for (commandnum, onoff) in statelist: - if onoff==0: - button.children[menu].entryconfig(commandnum,state=DISABLED) - if onoff==1: - button.children[menu].entryconfig(commandnum,state=NORMAL) - else: - pass + for menu in button.children.keys(): + if isinstance(button.children[menu], Menu): + for (commandnum, onoff) in statelist: + if onoff==0: + button.children[menu].entryconfig(commandnum,state=DISABLED) + if onoff==1: + button.children[menu].entryconfig(commandnum,state=NORMAL) + else: + pass class ArgumentWindow(Toplevel): - import tkMessageBox - def __init__(self, sim, **options): - Toplevel.__init__(self, sim.cwin) - self.resizable(FALSE,FALSE) - self.protocol("WM_DELETE_WINDOW", lambda:0) #self.cancelled) - self.transient(sim.cwin) - if 'placement' in options.keys(): - self.geometry("+%d+%d" % tuple(options['placement'])) - self.title('Thermal Model Initialization') - self.sim = sim - - self.make_options() - - buttonframe = Frame(self) - buttonframe.pack(side=BOTTOM) - b1=Button(buttonframe, text='OK', command=self.callback) - b1.pack(side=LEFT) - #b2=Button(buttonframe, text='Cancel', command=self.cancelled) - #b2.pack(side=LEFT) - self.bind("", self.callback) - #self.bind("", self.cancelled) + import tkMessageBox + def __init__(self, sim, **options): + Toplevel.__init__(self, sim.cwin) + self.resizable(FALSE,FALSE) + self.protocol("WM_DELETE_WINDOW", lambda:0) #self.cancelled) + self.transient(sim.cwin) + if 'placement' in options.keys(): + self.geometry("+%d+%d" % tuple(options['placement'])) + self.title('Thermal Model Initialization') + self.sim = sim - self.initial_focus = self - self.initial_focus.focus_set() - #self.wait_window(self) - - def make_options(self): - pass + self.make_options() - ### must override this function ### - ### with the entry forms ### - ### be sure to use pack or a ### - ### frame that is packed into self ### + buttonframe = Frame(self) + buttonframe.pack(side=BOTTOM) + b1=Button(buttonframe, text='OK', command=self.callback) + b1.pack(side=LEFT) + #b2=Button(buttonframe, text='Cancel', command=self.cancelled) + #b2.pack(side=LEFT) + self.bind("", self.callback) + #self.bind("", self.cancelled) - def getArguments(self): - pass + self.initial_focus = self + self.initial_focus.focus_set() + #self.wait_window(self) - ### must override this function ### - ### with the validation checking ### - ### must return None if error, ### - ### and non_null if ok ### - - - def callback(self, event=None): - g=self.getArguments() - if not g: - self.initial_focus.focus_set() - return - self.withdraw() - self.update_idletasks() + def make_options(self): + pass - self.assign(g) - self.cancelled() + ### must override this function ### + ### with the entry forms ### + ### be sure to use pack or a ### + ### frame that is packed into self ### - def assign(self, obj): - pass + def getArguments(self): + pass - ### must override this function ### - ### to do the assignment in sim ### + ### must override this function ### + ### with the validation checking ### + ### must return None if error, ### + ### and non_null if ok ### - def cancelled(self,event=None): - self.sim.cwin.focus_set() - self.destroy() + + def callback(self, event=None): + g=self.getArguments() + if not g: + self.initial_focus.focus_set() + return + self.withdraw() + self.update_idletasks() + + self.assign(g) + self.cancelled() + + def assign(self, obj): + pass + + ### must override this function ### + ### to do the assignment in sim ### + + def cancelled(self,event=None): + self.sim.cwin.focus_set() + self.destroy() if __name__=='__main__': - t = Tk() - ControlWindow(t).mainloop() + t = Tk() + ControlWindow(t).mainloop() diff --git a/interfaces/python/MixMaster/DataFrame.py b/interfaces/python/MixMaster/DataFrame.py index 65f66f2d4..a1aa5118d 100644 --- a/interfaces/python/MixMaster/DataFrame.py +++ b/interfaces/python/MixMaster/DataFrame.py @@ -21,11 +21,11 @@ def testit(e = None): class DataFrame(Frame): def __init__(self,master,top): -# if master==None: +# if master==None: self.master = Toplevel() self.master.protocol("WM_DELETE_WINDOW",self.hide) #else: - # self.master = master + # self.master = master #self.vis = vis Frame.__init__(self,self.master) @@ -57,7 +57,7 @@ class DataFrame(Frame): Label(self.scframe,text='Grid Point').grid(column=0,row=0) self.sc.grid(row=0,column=1) self.sc.bind('',self.updateState) - self.gr.grid(row=4,column=0,columnspan=10) + self.gr.grid(row=4,column=0,columnspan=10) self.grid(column=0,row=10) self.makeMenu() @@ -69,7 +69,7 @@ class DataFrame(Frame): self.menubar.grid(row=0,column=0,sticky=N+W+E,columnspan=10) f = [('Open...',self.browseForDatafile)] #make_menu('File',self.menubar,items) - make_menu('File',self.menubar,f) + make_menu('File',self.menubar,f) make_menu('Dataset',self.menubar,self.datasets) make_menu('Plot',self.menubar,self.vars) @@ -87,7 +87,7 @@ class DataFrame(Frame): fname = os.path.basename(self.datafile.get()) ff = os.path.splitext(fname) self.datasets = [] - if len(ff) == 2 and (ff[1] == '.xml' or ff[1] == '.ctml'): + if len(ff) == 2 and (ff[1] == '.xml' or ff[1] == '.ctml'): x = XML.XML_Node('root',src=self.datafile.get()) c = x.child('ctml') @@ -100,9 +100,9 @@ class DataFrame(Frame): i += 1 self.solnid.set(self.solns[-1]['id']) self.soln = self.solns[-1] - + self.importData() - + elif len(ff) == 2 and (ff[1] == '.csv' or ff[1] == '.CSV'): self.importCSV() @@ -143,7 +143,7 @@ class DataFrame(Frame): fdata[j,n] = float(v[j]) except: fdata[j,n] = 0.0 - + self.nsp = self.g.nSpecies() self.y = zeros(self.nsp,'d') self.data = zeros((self.nsp+6,self.np),'d') @@ -159,29 +159,29 @@ class DataFrame(Frame): v2 = vars[n] if v2 == 'T': self.data[T_LOC,:] = fdata[n,:] - self.label[T_LOC] = vars[n] + self.label[T_LOC] = vars[n] w.append(('T', self.newplot, 'check', self.loc, T_LOC)) elif v2 == 'P': self.data[P_LOC,:] = fdata[n,:] - self.label[P_LOC] = vars[n] + self.label[P_LOC] = vars[n] w.append((vars[n], self.newplot, 'check', self.loc, P_LOC)) elif v2 == 'u': self.data[U_LOC,:] = fdata[n,:] - self.label[U_LOC] = vars[n] + self.label[U_LOC] = vars[n] w.append((vars[n], self.newplot, 'check', self.loc, U_LOC)) elif v2 == 'V': self.data[V_LOC,:] = fdata[n,:] - self.label[V_LOC] = vars[n] + self.label[V_LOC] = vars[n] w.append((vars[n], self.newplot, 'check', self.loc, V_LOC)) elif k >= 0: self.data[k+Y_LOC,:] = fdata[n,:] - self.label[k+Y_LOC] = vars[n] + self.label[k+Y_LOC] = vars[n] w.append((vars[n], self.newplot, 'check', self.loc, k + Y_LOC)) if self.data[P_LOC,0] == 0.0: self.data[P_LOC,:] = ones(self.np,'d')*OneAtm - print 'Warning: no pressure data. P set to 1 atm.' - + print 'Warning: no pressure data. P set to 1 atm.' + self.sc.config(cnf={'from':0,'to':self.np-1}) if self.loc.get() <= 0: self.loc.set(self.lastloc) @@ -189,12 +189,12 @@ class DataFrame(Frame): self.vars = w #self.makeMenu() - self.scframe.grid(row=5,column=0,columnspan=10) - + self.scframe.grid(row=5,column=0,columnspan=10) + def pickSoln(self): self.solnid.set(self.solns[self.whichsoln.get()]['id']) - self.soln = self.solns[self.whichsoln.get()] + self.soln = self.solns[self.whichsoln.get()] # self.t.destroy() self.importData() @@ -208,10 +208,10 @@ class DataFrame(Frame): self.ydata = None if self.plt: self.plt.destroy() - + self.nsp = self.g.nSpecies() self.label = ['-']*(self.nsp + 6) - + self.y = zeros(self.nsp,'d') gdata = self.soln.child('flowfield/grid_data') xp = self.soln.child('flowfield').children('float') @@ -236,23 +236,23 @@ class DataFrame(Frame): self.label[0] = t elif k >= 0: self.data[k + Y_LOC] = v - self.label[k + Y_LOC] = t + self.label[k + Y_LOC] = t w.append((t, self.newplot, 'check', self.loc, k + Y_LOC)) elif t == 'T': self.data[T_LOC,:] = v - self.label[T_LOC] = t + self.label[T_LOC] = t w.append((t, self.newplot, 'check', self.loc, T_LOC)) elif t == 'u': self.data[U_LOC,:] = v - self.label[U_LOC] = t + self.label[U_LOC] = t w.append((t, self.newplot, 'check', self.loc, U_LOC)) elif t == 'V': self.data[V_LOC,:] = v - self.label[V_LOC] = t + self.label[V_LOC] = t w.append((t, self.newplot, 'check', self.loc, V_LOC)) - + self.data[P_LOC,:] = ones(self.np,'d')*p - self.label[P_LOC] = 'P (Pa)' + self.label[P_LOC] = 'P (Pa)' self.sc.config(cnf={'from':0,'to':self.np-1}) if self.loc.get() <= 0: self.loc.set(self.lastloc) @@ -356,9 +356,4 @@ class DataFrame(Frame): i = i + 1 ymin = fctr*math.floor(ymin/fctr) ymax = fctr*(math.floor(ymax/fctr + 1)) - return (ymin, ymax, fctr) - - - - - + return (ymin, ymax, fctr) diff --git a/interfaces/python/MixMaster/DataGraph.py b/interfaces/python/MixMaster/DataGraph.py index 89463ec72..2b4e76a40 100644 --- a/interfaces/python/MixMaster/DataGraph.py +++ b/interfaces/python/MixMaster/DataGraph.py @@ -4,228 +4,226 @@ import math from Cantera.num import * def plotLimits(ypts, f=0.0, ndiv=5, logscale=0): - """Return plot limits that""" - if logscale: - threshold = 1.0e-19 - else: - threshold = -1.0e20 - ymax = -1.e20 - ymin = 1.e20 - for y in ypts: - if y > ymax: ymax = y - if y < ymin and y > threshold: ymin = y + """Return plot limits that""" + if logscale: + threshold = 1.0e-19 + else: + threshold = -1.0e20 + ymax = -1.e20 + ymin = 1.e20 + for y in ypts: + if y > ymax: ymax = y + if y < ymin and y > threshold: ymin = y - dy = abs(ymax - ymin) + dy = abs(ymax - ymin) + + if logscale: + ymin = math.floor(math.log10(ymin)) + ymax = math.floor(math.log10(ymax))+1 + fctr = 1.0 - if logscale: - ymin = math.floor(math.log10(ymin)) - ymax = math.floor(math.log10(ymax))+1 - fctr = 1.0 - ## if dy < 0.2*ymin: ## ymin = ymin*.9 ## ymax = ymax*1.1 ## dy = abs(ymax - ymin) ## else: - else: - ymin = ymin - f*dy - ymax = ymax + f*dy - dy = abs(ymax - ymin) + else: + ymin = ymin - f*dy + ymax = ymax + f*dy + dy = abs(ymax - ymin) - try: - p10 = math.floor(math.log10(0.1*dy)) - fctr = math.pow(10.0, p10) - except: - return (ymin -1.0, ymax + 1.0, 1.0) - mm = [2.0, 2.5, 2.0] - i = 0 - while dy/fctr > ndiv: - fctr = mm[i % 3]*fctr - i = i + 1 - ymin = fctr*math.floor(ymin/fctr) - ymax = fctr*(math.floor(ymax/fctr+0.999)) + try: + p10 = math.floor(math.log10(0.1*dy)) + fctr = math.pow(10.0, p10) + except: + return (ymin -1.0, ymax + 1.0, 1.0) + mm = [2.0, 2.5, 2.0] + i = 0 + while dy/fctr > ndiv: + fctr = mm[i % 3]*fctr + i = i + 1 + ymin = fctr*math.floor(ymin/fctr) + ymax = fctr*(math.floor(ymax/fctr+0.999)) + + return (ymin, ymax, fctr) - return (ymin, ymax, fctr) - class DataGraph(Frame): def __init__(self,master, - data, ix=0, iy=0, - title='', - label = ('x-axis','y-axis'), - logscale = (0,0), - pixelX=500, - pixelY=500): + data, ix=0, iy=0, + title='', + label = ('x-axis','y-axis'), + logscale = (0,0), + pixelX=500, + pixelY=500): self.logscale = logscale - self.data = data - self.ix = ix - self.iy = iy + self.data = data + self.ix = ix + self.iy = iy self.minX, self.maxX, self.dx = plotLimits(data[ix,:], - logscale=self.logscale[0]) - self.minY, self.maxY, self.dy = plotLimits(data[iy,:], - logscale=self.logscale[1]) + logscale=self.logscale[0]) + self.minY, self.maxY, self.dy = plotLimits(data[iy,:], + logscale=self.logscale[1]) Frame.__init__(self,master, relief=RIDGE, bd=2) - self.title = Label(self,text=' ') - self.title.grid(row=0,column=1,sticky=W+E) - self.graph_w, self.graph_h = pixelX - 120, pixelY - 70 - self.origin = (100, 20) - self.canvas = Canvas(self, - width=pixelX, - height=pixelY, - relief=SUNKEN,bd=1) - id = self.canvas.create_rectangle(self.origin[0],self.origin[1], + self.title = Label(self,text=' ') + self.title.grid(row=0,column=1,sticky=W+E) + self.graph_w, self.graph_h = pixelX - 120, pixelY - 70 + self.origin = (100, 20) + self.canvas = Canvas(self, + width=pixelX, + height=pixelY, + relief=SUNKEN,bd=1) + id = self.canvas.create_rectangle(self.origin[0],self.origin[1], pixelX-20,pixelY-50) - self.canvas.grid(row=1,column=1,rowspan=2,sticky=N+S+E+W) - self.last_points=[] + self.canvas.grid(row=1,column=1,rowspan=2,sticky=N+S+E+W) + self.last_points=[] self.ticks(self.minX, self.maxX, self.dx, - self.minY, self.maxY, self.dy, 10) - self.screendata() - self.draw() - self.canvas.create_text(self.origin[0] + self.graph_w/2, - self.origin[1] + self.graph_h + 30, - text=label[0],anchor=N) - self.canvas.create_text(self.origin[0] - 50, - self.origin[1] + self.graph_h/2, - text=label[1],anchor=E) + self.minY, self.maxY, self.dy, 10) + self.screendata() + self.draw() + self.canvas.create_text(self.origin[0] + self.graph_w/2, + self.origin[1] + self.graph_h + 30, + text=label[0],anchor=N) + self.canvas.create_text(self.origin[0] - 50, + self.origin[1] + self.graph_h/2, + text=label[1],anchor=E) def writeValue(self, y): - yval = '%15.4f' % (y) - self.title.config(text = yval) + yval = '%15.4f' % (y) + self.title.config(text = yval) def delete(self, ids): for id in ids: - self.canvas.delete(id) + self.canvas.delete(id) def screendata(self): - self.xdata = array(self.data[self.ix,:]) - self.ydata = array(self.data[self.iy,:]) - npts = len(self.ydata) - if self.logscale[0] > 0: - self.xdata = log10(self.xdata) - if self.logscale[1] > 0: - self.ydata = log10(self.ydata) - f = float(self.graph_w)/(self.maxX-self.minX) - self.xdata = (self.xdata - self.minX)*f + self.origin[0] - f = float(self.graph_h)/(self.maxY-self.minY) - self.ydata = (self.maxY - self.ydata)*f + self.origin[1] - + self.xdata = array(self.data[self.ix,:]) + self.ydata = array(self.data[self.iy,:]) + npts = len(self.ydata) + if self.logscale[0] > 0: + self.xdata = log10(self.xdata) + if self.logscale[1] > 0: + self.ydata = log10(self.ydata) + f = float(self.graph_w)/(self.maxX-self.minX) + self.xdata = (self.xdata - self.minX)*f + self.origin[0] + f = float(self.graph_h)/(self.maxY-self.minY) + self.ydata = (self.maxY - self.ydata)*f + self.origin[1] + def toscreen(self,x,y): - if self.logscale[0] > 0: - x = log10(x) - if self.logscale[1] > 0: - y = log10(y) - f = float(self.graph_w)/(self.maxX-self.minX) - xx = (x - self.minX)*f + self.origin[0] - f = float(self.graph_h)/(self.maxY-self.minY) - yy = (self.maxY - y)*f + self.origin[1] - return (xx, yy) - + if self.logscale[0] > 0: + x = log10(x) + if self.logscale[1] > 0: + y = log10(y) + f = float(self.graph_w)/(self.maxX-self.minX) + xx = (x - self.minX)*f + self.origin[0] + f = float(self.graph_h)/(self.maxY-self.minY) + yy = (self.maxY - y)*f + self.origin[1] + return (xx, yy) + def move(self, id, newpos, oldpos): dxpt = (newpos[0] - oldpos[0])/(self.maxX-self.minX)*self.graph_w - dypt = -(newpos[1] - oldpos[1])/(self.maxY-self.minY)*self.graph_h - self.canvas.move(id, dxpt, dypt) - self.writeValue(newpos[1]) - + dypt = -(newpos[1] - oldpos[1])/(self.maxY-self.minY)*self.graph_h + self.canvas.move(id, dxpt, dypt) + self.writeValue(newpos[1]) + def plot(self,n,color='black'): - xpt, ypt = self.toscreen(self.data[self.ix,n], - self.data[self.iy,n]) - #xpt = (x-self.minX)/(self.maxX-self.minX)*float(self.graph_w) + self.origin[0] - #ypt = (self.maxY-y)/(self.maxY-self.minY)*float(self.graph_h) + self.origin[1] - id_ycross = self.canvas.create_line(xpt,self.graph_h+self.origin[1],xpt,self.origin[1],fill = 'gray') - id_xcross = self.canvas.create_line(self.origin[0],ypt,self.graph_w+self.origin[0],ypt,fill = 'gray') - id = self.canvas.create_oval(xpt-2,ypt-2,xpt+2,ypt+2,fill=color) - #self.writeValue(y) - s = '(%g, %g)' % (self.data[self.ix,n],self.data[self.iy,n]) - if n > 0 and self.data[self.iy,n] > self.data[self.iy,n-1]: - idt = self.canvas.create_text(xpt+5,ypt+5,text=s,anchor=NW) - else: - idt = self.canvas.create_text(xpt+5,ypt-5,text=s,anchor=SW) - - return [id,id_xcross,id_ycross, idt] + xpt, ypt = self.toscreen(self.data[self.ix,n], + self.data[self.iy,n]) + #xpt = (x-self.minX)/(self.maxX-self.minX)*float(self.graph_w) + self.origin[0] + #ypt = (self.maxY-y)/(self.maxY-self.minY)*float(self.graph_h) + self.origin[1] + id_ycross = self.canvas.create_line(xpt,self.graph_h+self.origin[1],xpt,self.origin[1],fill = 'gray') + id_xcross = self.canvas.create_line(self.origin[0],ypt,self.graph_w+self.origin[0],ypt,fill = 'gray') + id = self.canvas.create_oval(xpt-2,ypt-2,xpt+2,ypt+2,fill=color) + #self.writeValue(y) + s = '(%g, %g)' % (self.data[self.ix,n],self.data[self.iy,n]) + if n > 0 and self.data[self.iy,n] > self.data[self.iy,n-1]: + idt = self.canvas.create_text(xpt+5,ypt+5,text=s,anchor=NW) + else: + idt = self.canvas.create_text(xpt+5,ypt-5,text=s,anchor=SW) + + return [id,id_xcross,id_ycross, idt] def draw(self,color='red'): - npts = len(self.xdata) - for n in range(1,npts): - self.canvas.create_line(self.xdata[n-1],self.ydata[n-1], - self.xdata[n],self.ydata[n],fill=color) + npts = len(self.xdata) + for n in range(1,npts): + self.canvas.create_line(self.xdata[n-1],self.ydata[n-1], + self.xdata[n],self.ydata[n],fill=color) def addLabel(self, y, orient=0): if orient==0: - xpt, ypt = self.toscreen(y, 1.0) - ypt = self.origin[1] + self.graph_h + 5 - self.canvas.create_text(xpt,ypt,text=y,anchor=N) - else: - xpt, ypt = self.toscreen(self.minX, y) - xpt = self.origin[0] - 5 - self.canvas.create_text(xpt,ypt,text=y,anchor=E) + xpt, ypt = self.toscreen(y, 1.0) + ypt = self.origin[1] + self.graph_h + 5 + self.canvas.create_text(xpt,ypt,text=y,anchor=N) + else: + xpt, ypt = self.toscreen(self.minX, y) + xpt = self.origin[0] - 5 + self.canvas.create_text(xpt,ypt,text=y,anchor=E) def addLegend(self,text,color=None): - m=Message(self,text=text,width=self.graph_w-10) - m.pack(side=BOTTOM) - if color: - m.config(fg=color) + m=Message(self,text=text,width=self.graph_w-10) + m.pack(side=BOTTOM) + if color: + m.config(fg=color) def pauseWhenFinished(self): - self.wait_window() + self.wait_window() def minorTicks(self, x0, x1, y, n, size, orient=0): xtick = x0 - dx = (x1 - x0)/float(n) - if orient == 0: - while xtick <= x1: - xx, yy = self.toscreen(xtick, y) - self.canvas.create_line(xx,yy, - xx,yy-size) - xtick += dx - else: - while xtick <= x1: - xx, yy = self.toscreen(y, xtick) - self.canvas.create_line(xx,yy, - xx+size,yy) - xtick += dx - - - def ticks(self, xmin, xmax, dx, ymin, ymax, dy, size): - - if self.logscale[0]: - xmin = math.pow(10.0,xmin) - xmax = math.pow(10.0,xmax) - if self.logscale[1]: - ymin = math.pow(10.0,ymin) - ymax = math.pow(10.0,ymax) + dx = (x1 - x0)/float(n) + if orient == 0: + while xtick <= x1: + xx, yy = self.toscreen(xtick, y) + self.canvas.create_line(xx,yy, + xx,yy-size) + xtick += dx + else: + while xtick <= x1: + xx, yy = self.toscreen(y, xtick) + self.canvas.create_line(xx,yy, + xx+size,yy) + xtick += dx - n = 5 + + def ticks(self, xmin, xmax, dx, ymin, ymax, dy, size): + + if self.logscale[0]: + xmin = math.pow(10.0,xmin) + xmax = math.pow(10.0,xmax) + if self.logscale[1]: + ymin = math.pow(10.0,ymin) + ymax = math.pow(10.0,ymax) + + n = 5 ytick = ymin while ytick <= ymax: - xx, yy = self.toscreen(xmin, ytick) - self.canvas.create_line(xx, yy, xx + size,yy) - self.addLabel(ytick,1) - xx, yy = self.toscreen(xmax, ytick) - self.canvas.create_line(xx, yy, xx - size,yy) - ytick0 = ytick - if self.logscale[1]: - ytick *= 10.0 - n = 10 - else: ytick = ytick + dy - if ytick <= ymax: - self.minorTicks(ytick0, ytick, xmin, n, 5, 1) - self.minorTicks(ytick0, ytick, xmax, n, -5, 1) - - n = 5 + xx, yy = self.toscreen(xmin, ytick) + self.canvas.create_line(xx, yy, xx + size,yy) + self.addLabel(ytick,1) + xx, yy = self.toscreen(xmax, ytick) + self.canvas.create_line(xx, yy, xx - size,yy) + ytick0 = ytick + if self.logscale[1]: + ytick *= 10.0 + n = 10 + else: ytick = ytick + dy + if ytick <= ymax: + self.minorTicks(ytick0, ytick, xmin, n, 5, 1) + self.minorTicks(ytick0, ytick, xmax, n, -5, 1) + + n = 5 xtick = xmin while xtick <= xmax: - xx, yy = self.toscreen(xtick, ymin) - self.canvas.create_line(xx, yy, xx, yy - size) - self.addLabel(xtick,0) - xx, yy = self.toscreen(xtick, ymax) - self.canvas.create_line(xx, yy, xx, yy + size) - if self.logscale[0]: - xtick *= 10.0 - n = 10 - else: xtick = xtick + dx - if xtick <= xmax: - self.minorTicks(xtick - dx, xtick, ymin, n, 5, 0) - self.minorTicks(xtick - dx, xtick, ymax, n, -5, 0) - - + xx, yy = self.toscreen(xtick, ymin) + self.canvas.create_line(xx, yy, xx, yy - size) + self.addLabel(xtick,0) + xx, yy = self.toscreen(xtick, ymax) + self.canvas.create_line(xx, yy, xx, yy + size) + if self.logscale[0]: + xtick *= 10.0 + n = 10 + else: xtick = xtick + dx + if xtick <= xmax: + self.minorTicks(xtick - dx, xtick, ymin, n, 5, 0) + self.minorTicks(xtick - dx, xtick, ymax, n, -5, 0) diff --git a/interfaces/python/MixMaster/Edit.py b/interfaces/python/MixMaster/Edit.py index 2e09cb217..d95b50aae 100644 --- a/interfaces/python/MixMaster/Edit.py +++ b/interfaces/python/MixMaster/Edit.py @@ -7,188 +7,187 @@ from config import * from SpeciesFrame import getSpecies def testit(): - pass + pass class EditFrame(Frame): - def redraw(self): - try: - self.eframe.destroy() - self.sframe.destroy() - self.rframe.destroy() - except: - pass - self.addElementFrame() - self.addSpeciesFrame() - self.addReactionFrame() - - def __init__(self, master, app): - Frame.__init__(self, master) - self.mix = app.mix - print self.mix, dir(self.mix) - self.app = app - self.master = master - self.master.title("Cantera Mechanism Editor") - self.redraw() - - def addReactionFrame(self): - self.rframe = Frame(self) - self.rframe.config(relief=GROOVE,bd=4) - self.rframe.grid(row=2,column=0,columnspan=10,sticky=E+W) - b=Button(self.rframe,text='Reactions',command=testit) - b.grid(column=5, row=0) + def redraw(self): + try: + self.eframe.destroy() + self.sframe.destroy() + self.rframe.destroy() + except: + pass + self.addElementFrame() + self.addSpeciesFrame() + self.addReactionFrame() - def addElementFrame(self): - self.eframe = Frame(self) - self.eframe.config(relief=GROOVE,bd=4) - self.eframe.grid(row=0,column=0,columnspan=10,sticky=E+W) - self.element_labels = [] - n = 0 - for el in self.mix._mech.elementNames(): - x = Label(self.eframe,text=el,fg='darkblue') - x.grid(column = n, row=0) - self.element_labels.append(x) - n = n + 1 - b=Button(self.eframe,text='Element',command=self.chooseElements, default=ACTIVE) - b.grid(column=0, row=1, columnspan=10) + def __init__(self, master, app): + Frame.__init__(self, master) + self.mix = app.mix + print self.mix, dir(self.mix) + self.app = app + self.master = master + self.master.title("Cantera Mechanism Editor") + self.redraw() + + def addReactionFrame(self): + self.rframe = Frame(self) + self.rframe.config(relief=GROOVE,bd=4) + self.rframe.grid(row=2,column=0,columnspan=10,sticky=E+W) + b=Button(self.rframe,text='Reactions',command=testit) + b.grid(column=5, row=0) + + def addElementFrame(self): + self.eframe = Frame(self) + self.eframe.config(relief=GROOVE,bd=4) + self.eframe.grid(row=0,column=0,columnspan=10,sticky=E+W) + self.element_labels = [] + n = 0 + for el in self.mix._mech.elementNames(): + x = Label(self.eframe,text=el,fg='darkblue') + x.grid(column = n, row=0) + self.element_labels.append(x) + n = n + 1 + b=Button(self.eframe,text='Element',command=self.chooseElements, default=ACTIVE) + b.grid(column=0, row=1, columnspan=10) - def addSpeciesFrame(self): - self.sframe = Frame(self) - self.sframe.config(relief=GROOVE,bd=4) - self.sframe.grid(row=1,column=0,columnspan=10,sticky=E+W) - r = 0 - c = 0 - splist = self.app.species - self.spcheck = [] - self.spec = [] - for i in range(self.app.mech.nSpecies()): - self.spec.append(IntVar()) - self.spec[i].set(1) - self.spcheck.append( Checkbutton(self.sframe, - text=splist[i].name, - variable=self.spec[i], - onvalue = 1, offvalue = 0) ) - self.spcheck[i].grid(row = r, column = c, sticky = N+W) - self.spcheck[i].bind("", self.editSpecies) - c = c + 1 - if c > 4: - c, r = 0, r + 1 + def addSpeciesFrame(self): + self.sframe = Frame(self) + self.sframe.config(relief=GROOVE,bd=4) + self.sframe.grid(row=1,column=0,columnspan=10,sticky=E+W) + r = 0 + c = 0 + splist = self.app.species + self.spcheck = [] + self.spec = [] + for i in range(self.app.mech.nSpecies()): + self.spec.append(IntVar()) + self.spec[i].set(1) + self.spcheck.append( Checkbutton(self.sframe, + text=splist[i].name, + variable=self.spec[i], + onvalue = 1, offvalue = 0) ) + self.spcheck[i].grid(row = r, column = c, sticky = N+W) + self.spcheck[i].bind("", self.editSpecies) + c = c + 1 + if c > 4: + c, r = 0, r + 1 - def getspecies(self): - print getSpecies(self.mix.speciesNames(), - self.mix.speciesNames()) - - def editSpecies(self, event=None): - e = Toplevel(event.widget.master) - w = event.widget - txt = w.cget('text') - sp = self.app.mix.species[txt] + def getspecies(self): + print getSpecies(self.mix.speciesNames(), + self.mix.speciesNames()) - # name, etc. - e1 = Frame(e, relief=FLAT) - self.addEntry(e1,'Name',0,0,sp.name) - self.addEntry(e1,'ID Tag',1,0,sp.id) - self.addEntry(e1,'Phase',2,0,sp.phase) - e1.grid(row=0,column=0) + def editSpecies(self, event=None): + e = Toplevel(event.widget.master) + w = event.widget + txt = w.cget('text') + sp = self.app.mix.species[txt] - # elements - elframe = Frame(e) - elframe.grid(row=1,column=0) - Label(elframe,text='Elemental Composition').grid(row=0,column=0,columnspan=2,sticky=E+W) + # name, etc. + e1 = Frame(e, relief=FLAT) + self.addEntry(e1,'Name',0,0,sp.name) + self.addEntry(e1,'ID Tag',1,0,sp.id) + self.addEntry(e1,'Phase',2,0,sp.phase) + e1.grid(row=0,column=0) - i = 0 - for el in self.app.mech.elementNames(): - self.addEntry(elframe,el,i,0,self.mech.nAtoms(sp, el)) - i = i + 1 + # elements + elframe = Frame(e) + elframe.grid(row=1,column=0) + Label(elframe,text='Elemental Composition').grid(row=0,column=0,columnspan=2,sticky=E+W) - # thermo - thframe = Frame(e) - thframe.grid(row=0,rowspan=2,column=1) - thframe.config(relief=GROOVE,bd=4) - i = 0 - Label(thframe,text='Thermodynamic Properties').grid(row=0, - column=0, columnspan=4, sticky=E+W) - if isinstance(sp.thermoParam(),NasaPolynomial): - Label(thframe,text='Parametrization:').grid(row=1,column=1) - self.addEntry(thframe,'',2,0,'NasaPolynomial') - Label(thframe,text='Temperatures (min, mid, max):').grid(row=3,column=1) - self.addEntry(thframe,'',4,0,`sp.minTemp`) - self.addEntry(thframe,'',5,0,`sp.midTemp`) - self.addEntry(thframe,'',6,0,`sp.maxTemp`) - low = Frame(thframe) - low.config(relief=GROOVE,bd=4) - low.grid(row=1,rowspan=6,column=3,columnspan=2) - Label(low,text='Coefficients for the Low\n Temperature Range').grid(row=0,column=0,columnspan=2,sticky=E+W) - c = sp.thermoParam().coefficients(sp.minTemp) - for j in range(7): - self.addEntry(low,'a'+`j`,j+3,0,`c[j]`) - high = Frame(thframe) - high.config(relief=GROOVE,bd=4) - high.grid(row=1,rowspan=6,column=5,columnspan=2) - Label(high,text='Coefficients for the High\n Temperature Range').grid(row=0,column=0,columnspan=2,sticky=E+W) - c = sp.thermoParam().coefficients(sp.maxTemp) - for j in range(7): - self.addEntry(high,'a'+`j`,j+3,0,`c[j]`) - - com = Frame(e) - com.grid(row=10,column=0,columnspan=5) - ok = Button(com,text='OK',default=ACTIVE) - ok.grid(row=0,column=0) - ok.bind('<1>',self.modifySpecies) - Button(com,text='Cancel',command=e.destroy).grid(row=0,column=1) - self.especies = e - - def modifySpecies(self,event=None): - button = event.widget - e = self.especies - for fr in e.children.values(): - for item in fr.children.values(): - try: - print item.cget('selection') - except: - pass - e.destroy() - - def addEntry(self,master,name,row,column,text): - if name: - Label(master, text=name).grid(row=row, column=column) - nm = Entry(master) - nm.grid(row=row, column=column+1) - nm.insert(END,text) - - def chooseElements(self): - oldel = self.mix.g.elementNames() - newel = getElements(self.mix.g.elementNames()) - removeList = [] - for el in oldel: - if not el in newel: - removeList.append(el) - #self.app.mech.removeElements(removeList) - addList = [] - for el in newel: - if not el in oldel: - addList.append(el) - #self.app.mech.addElements(addList) - try: - self.redraw() - self.app.makeWindows() - except: - handleError('Edit err') - - self.app.mix = IdealGasMixture(self.app.mech) - self.mix = self.app.mix - nn = self.mix.speciesList[0].name - self.mix.set(temperature = 300.0, pressure = 101325.0, moles = {nn:1.0}) - for label in self.element_labels: - label.destroy() - self.element_labels = [] - n = 0 - for el in self.mix._mech.elementList(): - x = Label(self.eframe,text=el.symbol(),fg='darkblue') - x.grid(column = n, row=0) - self.element_labels.append(x) - n = n + 1 + i = 0 + for el in self.app.mech.elementNames(): + self.addEntry(elframe,el,i,0,self.mech.nAtoms(sp, el)) + i = i + 1 - self.app.makeWindows() + # thermo + thframe = Frame(e) + thframe.grid(row=0,rowspan=2,column=1) + thframe.config(relief=GROOVE,bd=4) + i = 0 + Label(thframe,text='Thermodynamic Properties').grid(row=0, + column=0, columnspan=4, sticky=E+W) + if isinstance(sp.thermoParam(),NasaPolynomial): + Label(thframe,text='Parametrization:').grid(row=1,column=1) + self.addEntry(thframe,'',2,0,'NasaPolynomial') + Label(thframe,text='Temperatures (min, mid, max):').grid(row=3,column=1) + self.addEntry(thframe,'',4,0,`sp.minTemp`) + self.addEntry(thframe,'',5,0,`sp.midTemp`) + self.addEntry(thframe,'',6,0,`sp.maxTemp`) + low = Frame(thframe) + low.config(relief=GROOVE,bd=4) + low.grid(row=1,rowspan=6,column=3,columnspan=2) + Label(low,text='Coefficients for the Low\n Temperature Range').grid(row=0,column=0,columnspan=2,sticky=E+W) + c = sp.thermoParam().coefficients(sp.minTemp) + for j in range(7): + self.addEntry(low,'a'+`j`,j+3,0,`c[j]`) + high = Frame(thframe) + high.config(relief=GROOVE,bd=4) + high.grid(row=1,rowspan=6,column=5,columnspan=2) + Label(high,text='Coefficients for the High\n Temperature Range').grid(row=0,column=0,columnspan=2,sticky=E+W) + c = sp.thermoParam().coefficients(sp.maxTemp) + for j in range(7): + self.addEntry(high,'a'+`j`,j+3,0,`c[j]`) + com = Frame(e) + com.grid(row=10,column=0,columnspan=5) + ok = Button(com,text='OK',default=ACTIVE) + ok.grid(row=0,column=0) + ok.bind('<1>',self.modifySpecies) + Button(com,text='Cancel',command=e.destroy).grid(row=0,column=1) + self.especies = e + + def modifySpecies(self,event=None): + button = event.widget + e = self.especies + for fr in e.children.values(): + for item in fr.children.values(): + try: + print item.cget('selection') + except: + pass + e.destroy() + + def addEntry(self,master,name,row,column,text): + if name: + Label(master, text=name).grid(row=row, column=column) + nm = Entry(master) + nm.grid(row=row, column=column+1) + nm.insert(END,text) + + def chooseElements(self): + oldel = self.mix.g.elementNames() + newel = getElements(self.mix.g.elementNames()) + removeList = [] + for el in oldel: + if not el in newel: + removeList.append(el) + #self.app.mech.removeElements(removeList) + addList = [] + for el in newel: + if not el in oldel: + addList.append(el) + #self.app.mech.addElements(addList) + try: + self.redraw() + self.app.makeWindows() + except: + handleError('Edit err') + + self.app.mix = IdealGasMixture(self.app.mech) + self.mix = self.app.mix + nn = self.mix.speciesList[0].name + self.mix.set(temperature = 300.0, pressure = 101325.0, moles = {nn:1.0}) + for label in self.element_labels: + label.destroy() + self.element_labels = [] + n = 0 + for el in self.mix._mech.elementList(): + x = Label(self.eframe,text=el.symbol(),fg='darkblue') + x.grid(column = n, row=0) + self.element_labels.append(x) + n = n + 1 + + self.app.makeWindows() diff --git a/interfaces/python/MixMaster/ElementFrame.py b/interfaces/python/MixMaster/ElementFrame.py index 8ee42e1fa..e0c0a5ed9 100644 --- a/interfaces/python/MixMaster/ElementFrame.py +++ b/interfaces/python/MixMaster/ElementFrame.py @@ -34,7 +34,7 @@ class PeriodicTable(Frame): self.control = Frame(self) self.control.config(relief=GROOVE,bd=4) Button(self.control, text = 'Display',command=self.show).pack(fill=X,pady=3, padx=10) - Button(self.control, text = 'Clear',command=self.clear).pack(fill=X,pady=3, padx=10) + Button(self.control, text = 'Clear',command=self.clear).pack(fill=X,pady=3, padx=10) Button(self.control, text = ' OK ',command=self.get).pack(side=BOTTOM, fill=X,pady=3, padx=10) Button(self.control, text = 'Cancel',command=self.master.quit).pack(side=BOTTOM, @@ -64,7 +64,7 @@ class PeriodicTable(Frame): self.c[e]['bg'] = self.color(e, sel=1) def deselect(self, el): - e = string.capitalize(el) + e = string.capitalize(el) self.c[e]['relief'] = FLAT self.c[e]['bg'] = self.color(e, sel=0) @@ -72,7 +72,7 @@ class PeriodicTable(Frame): for el in ellist: ename = el self.select(ename) - + def setColors(self,event): el = event.widget['text'] if event.widget['relief'] == RAISED: @@ -82,7 +82,7 @@ class PeriodicTable(Frame): event.widget['relief'] = RAISED back = self.color(el, sel=1) event.widget['bg'] = back - + def color(self, el, sel=0): _normal = ['#88dddd','#dddd88','#dd8888'] _selected = ['#aaffff','#ffffaa','#ffaaaa'] @@ -104,7 +104,7 @@ class PeriodicTable(Frame): if self.c[el]['relief'] == RAISED: selected.append(periodicTable[el]) showElementProperties(selected) - + def get(self): self.selected = [] names = _pos.keys() @@ -114,7 +114,7 @@ class PeriodicTable(Frame): self.selected.append(periodicTable[el]) #self.master.quit()' self.master.destroy() - + def clear(self): for el in _pos.keys(): self.c[el]['bg'] = self.color(el, sel=0) @@ -132,7 +132,7 @@ class ElementPropertyFrame(Frame): row=0, sticky=W+S, padx=10, - pady=10) + pady=10) for el in ellist: Label(self, text=el.name).grid(column=0, @@ -176,9 +176,7 @@ def showElementProperties(ellist): m.title('Element Properties') elem = [] ElementPropertyFrame(m, ellist).pack() - + if __name__ == "__main__": print getElements() - - diff --git a/interfaces/python/MixMaster/GraphFrame.py b/interfaces/python/MixMaster/GraphFrame.py index 7acdf4181..d473cb41d 100644 --- a/interfaces/python/MixMaster/GraphFrame.py +++ b/interfaces/python/MixMaster/GraphFrame.py @@ -3,128 +3,126 @@ from Tkinter import * import math class Graph(Frame): - def __init__(self,master,title,minX,maxX,minY,maxY,pixelX=250,pixelY=250): - Frame.__init__(self,master, relief=RIDGE, bd=2) - # self.pack() - self.title = Label(self,text=' ') - self.title.grid(row=0,column=1,sticky=W+E) - self.graph_w, self.graph_h = pixelX, pixelY - self.maxX, self.maxY = maxX, maxY #float(math.floor(maxX + 1)), \ - #float(math.floor(maxY + 1)) - self.minX, self.minY = minX, minY # float(math.floor(minX)), float(math.floor(minY)) - self.canvas = Canvas(self, - width=self.graph_w, - height=self.graph_h, - relief=SUNKEN,bd=1) - ymintext = "%8.1f" % (self.minY) - ymaxtext = "%8.1f" % (self.maxY) - self.ml=Label(self, text=ymintext) - self.mr=Label(self, text=ymaxtext) - self.ml.grid(row=2,column=0,sticky=S+E) - self.mr.grid(row=1,column=0,sticky=N+E) - self.canvas.grid(row=1,column=1,rowspan=2,sticky=N+S+E+W) - self.last_points=[] - + def __init__(self,master,title,minX,maxX,minY,maxY,pixelX=250,pixelY=250): + Frame.__init__(self,master, relief=RIDGE, bd=2) + # self.pack() + self.title = Label(self,text=' ') + self.title.grid(row=0,column=1,sticky=W+E) + self.graph_w, self.graph_h = pixelX, pixelY + self.maxX, self.maxY = maxX, maxY #float(math.floor(maxX + 1)), \ + #float(math.floor(maxY + 1)) + self.minX, self.minY = minX, minY # float(math.floor(minX)), float(math.floor(minY)) + self.canvas = Canvas(self, + width=self.graph_w, + height=self.graph_h, + relief=SUNKEN,bd=1) + ymintext = "%8.1f" % (self.minY) + ymaxtext = "%8.1f" % (self.maxY) + self.ml=Label(self, text=ymintext) + self.mr=Label(self, text=ymaxtext) + self.ml.grid(row=2,column=0,sticky=S+E) + self.mr.grid(row=1,column=0,sticky=N+E) + self.canvas.grid(row=1,column=1,rowspan=2,sticky=N+S+E+W) + self.last_points=[] - def writeValue(self, y): - yval = '%15.4f' % (y) - self.title.config(text = yval) - def delete(self, ids): - for id in ids: - self.canvas.delete(id) - - def move(self, id, newpos, oldpos): - dxpt = (newpos[0] - oldpos[0])/(self.maxX-self.minX)*self.graph_w - dypt = -(newpos[1] - oldpos[1])/(self.maxY-self.minY)*self.graph_h - self.canvas.move(id, dxpt, dypt) - self.writeValue(newpos[1]) - - def plot(self,x,y,color='black'): - xpt = (x-self.minX)/(self.maxX-self.minX)*float(self.graph_w) + 1.5 - ypt = (self.maxY-y)/(self.maxY-self.minY)*float(self.graph_h) - 1.5 - id_ycross = self.canvas.create_line(xpt,self.graph_h,xpt,0,fill = 'gray') - id_xcross = self.canvas.create_line(0,ypt,self.graph_w,ypt,fill = 'gray') - id = self.canvas.create_oval(xpt-2,ypt-2,xpt+2,ypt+2,fill=color) - self.writeValue(y) - return [id,id_xcross,id_ycross] + def writeValue(self, y): + yval = '%15.4f' % (y) + self.title.config(text = yval) - def reset(self,minX,maxX,minY,maxY): - self.maxX, self.maxY = maxX, maxY - self.minX, self.minY = minX, minY - self.canvas.destroy() - self.canvas = Canvas(self, - width=self.graph_w, - height=self.graph_h, - relief=SUNKEN,bd=1) - self.canvas.create_text(4,2,text=self.maxY,anchor=NW) - self.canvas.create_text(4,self.graph_h,text=self.minY,anchor=SW) - self.ml["text"] = `minX` - self.mr["text"] = `maxX` - self.canvas.pack() - self.last_points = [] + def delete(self, ids): + for id in ids: + self.canvas.delete(id) - def join(self,point_list): - i = 0 - for pt in point_list: - x, y, color = pt - if self.last_points == []: - last_x, last_y, last_color = pt - else: - last_x, last_y, last_color = self.last_points[i] - i = i + 1 - xpt = (x - self.minX)/(float(self.maxX - self.minX)/self.graph_w) + 1.5 - ypt = (self.maxY-y)/(float(self.maxY - self.minY)/self.graph_h) - 1.5 - last_xpt = (last_x - self.minX)/(float(self.maxX - self.minX)/self.graph_w) + 1.5 - last_ypt = (self.maxY-last_y)/(float(self.maxY - self.minY)/self.graph_h) - 1.5 - self.canvas.create_line(last_xpt,last_ypt, - xpt,ypt,fill=color) - self.last_points = point_list - self.canvas.update() - return - + def move(self, id, newpos, oldpos): + dxpt = (newpos[0] - oldpos[0])/(self.maxX-self.minX)*self.graph_w + dypt = -(newpos[1] - oldpos[1])/(self.maxY-self.minY)*self.graph_h + self.canvas.move(id, dxpt, dypt) + self.writeValue(newpos[1]) - def addLegend(self,text,color=None): - m=Message(self,text=text,width=self.graph_w-10) - m.pack(side=BOTTOM) - if color: - m.config(fg=color) + def plot(self,x,y,color='black'): + xpt = (x-self.minX)/(self.maxX-self.minX)*float(self.graph_w) + 1.5 + ypt = (self.maxY-y)/(self.maxY-self.minY)*float(self.graph_h) - 1.5 + id_ycross = self.canvas.create_line(xpt,self.graph_h,xpt,0,fill = 'gray') + id_xcross = self.canvas.create_line(0,ypt,self.graph_w,ypt,fill = 'gray') + id = self.canvas.create_oval(xpt-2,ypt-2,xpt+2,ypt+2,fill=color) + self.writeValue(y) + return [id,id_xcross,id_ycross] - def pauseWhenFinished(self): - self.wait_window() + def reset(self,minX,maxX,minY,maxY): + self.maxX, self.maxY = maxX, maxY + self.minX, self.minY = minX, minY + self.canvas.destroy() + self.canvas = Canvas(self, + width=self.graph_w, + height=self.graph_h, + relief=SUNKEN,bd=1) + self.canvas.create_text(4,2,text=self.maxY,anchor=NW) + self.canvas.create_text(4,self.graph_h,text=self.minY,anchor=SW) + self.ml["text"] = `minX` + self.mr["text"] = `maxX` + self.canvas.pack() + self.last_points = [] + + def join(self,point_list): + i = 0 + for pt in point_list: + x, y, color = pt + if self.last_points == []: + last_x, last_y, last_color = pt + else: + last_x, last_y, last_color = self.last_points[i] + i = i + 1 + xpt = (x - self.minX)/(float(self.maxX - self.minX)/self.graph_w) + 1.5 + ypt = (self.maxY-y)/(float(self.maxY - self.minY)/self.graph_h) - 1.5 + last_xpt = (last_x - self.minX)/(float(self.maxX - self.minX)/self.graph_w) + 1.5 + last_ypt = (self.maxY-last_y)/(float(self.maxY - self.minY)/self.graph_h) - 1.5 + self.canvas.create_line(last_xpt,last_ypt, + xpt,ypt,fill=color) + self.last_points = point_list + self.canvas.update() + return + + + def addLegend(self,text,color=None): + m=Message(self,text=text,width=self.graph_w-10) + m.pack(side=BOTTOM) + if color: + m.config(fg=color) + + def pauseWhenFinished(self): + self.wait_window() if __name__=='__main__': - root= Tk() - g = Graph(root,'graph1',0,10,0.01,120) - h = Graph(root,'graph2',0,15,0,20000) - g.pack(side=LEFT) - h.pack(side=RIGHT) + root= Tk() + g = Graph(root,'graph1',0,10,0.01,120) + h = Graph(root,'graph2',0,15,0,20000) + g.pack(side=LEFT) + h.pack(side=RIGHT) - #root.protocol("WM_DELETE_WINDOW", root.destroy()) - j = Graph(root,'Graph',0,1000,0,2000) - j.pack() + #root.protocol("WM_DELETE_WINDOW", root.destroy()) + j = Graph(root,'Graph',0,1000,0,2000) + j.pack() - j.plot(0, 0, color='red') - j.last_points = [ (0, 0, 'red') ] - for i in range(100): - j.join( [ ( (i*10),(i*10+500), 'red' ) ] ) + j.plot(0, 0, color='red') + j.last_points = [ (0, 0, 'red') ] + for i in range(100): + j.join( [ ( (i*10),(i*10+500), 'red' ) ] ) - g.addLegend('An example of the GraphFrame') - h.addLegend('This is where the legend goes') - for i in range(100): - if root: - x,y = float(i)/10, i - g.plot(x,y,color='red') - h.plot(i,i**2)#(0,0) - #h.join([(i,i**2,'black')]) - else: - break - - #print("finished") - g.pauseWhenFinished() - h.pauseWhenFinished() - print g - + g.addLegend('An example of the GraphFrame') + h.addLegend('This is where the legend goes') + for i in range(100): + if root: + x,y = float(i)/10, i + g.plot(x,y,color='red') + h.plot(i,i**2)#(0,0) + #h.join([(i,i**2,'black')]) + else: + break + #print("finished") + g.pauseWhenFinished() + h.pauseWhenFinished() + print g diff --git a/interfaces/python/MixMaster/ImportFrame.py b/interfaces/python/MixMaster/ImportFrame.py index 9176c81f8..6208aa197 100644 --- a/interfaces/python/MixMaster/ImportFrame.py +++ b/interfaces/python/MixMaster/ImportFrame.py @@ -5,119 +5,119 @@ from Cantera import * from tkFileDialog import askopenfilename class ImportFrame(Frame): - def __init__(self,top): - self.master = Toplevel() - self.master.title('Convert and Import CK File') - self.master.protocol("WM_DELETE_WINDOW",self.hide) - - Frame.__init__(self,self.master) - self.config(relief=GROOVE, bd=4) - self.top = top - self.infile = StringVar() + def __init__(self,top): + self.master = Toplevel() + self.master.title('Convert and Import CK File') + self.master.protocol("WM_DELETE_WINDOW",self.hide) - Label(self,text="Input File").grid(row=0,column=0) - Entry(self, width=40, - textvariable=self.infile).grid(column=1,row=0) - Button(self, text='Browse', - command=self.browseForInput).grid(row=0,column=2) + Frame.__init__(self,self.master) + self.config(relief=GROOVE, bd=4) + self.top = top + self.infile = StringVar() - self.thermo = StringVar() - Label(self,text="Thermodynamic Database").grid(row=1,column=0) - Entry(self, width=40, - textvariable=self.thermo).grid(column=1,row=1) - Button(self, text='Browse', - command=self.browseForThermo).grid(row=1,column=2) + Label(self,text="Input File").grid(row=0,column=0) + Entry(self, width=40, + textvariable=self.infile).grid(column=1,row=0) + Button(self, text='Browse', + command=self.browseForInput).grid(row=0,column=2) + + self.thermo = StringVar() + Label(self,text="Thermodynamic Database").grid(row=1,column=0) + Entry(self, width=40, + textvariable=self.thermo).grid(column=1,row=1) + Button(self, text='Browse', + command=self.browseForThermo).grid(row=1,column=2) - self.transport = StringVar() - Label(self,text="Transport Database").grid(row=2,column=0) - Entry(self, width=40, - textvariable=self.transport).grid(column=1,row=2) - Button(self, text='Browse', - command=self.browseForTransport).grid(row=2,column=2) + self.transport = StringVar() + Label(self,text="Transport Database").grid(row=2,column=0) + Entry(self, width=40, + textvariable=self.transport).grid(column=1,row=2) + Button(self, text='Browse', + command=self.browseForTransport).grid(row=2,column=2) - bframe = Frame(self) - bframe.config(relief=GROOVE, bd=1) - bframe.grid(row=100,column=0) - Button(bframe, text='OK', width=8, command=self.importfile).grid(row=0,column=0) - self.grid(column=0,row=0) - Button(bframe, text='Cancel', width=8, command=self.hide).grid(row=0,column=1) - self.grid(column=0,row=0) - self.hide() + bframe = Frame(self) + bframe.config(relief=GROOVE, bd=1) + bframe.grid(row=100,column=0) + Button(bframe, text='OK', width=8, command=self.importfile).grid(row=0,column=0) + self.grid(column=0,row=0) + Button(bframe, text='Cancel', width=8, command=self.hide).grid(row=0,column=1) + self.grid(column=0,row=0) + self.hide() - def browseForInput(self, e=None): - pathname = askopenfilename( - filetypes=[("Reaction Mechanism Files", - ("*.inp","*.mech","*.ck2")), - ("All Files", "*.*")]) - if pathname: - self.infile.set(pathname) - self.show() + def browseForInput(self, e=None): + pathname = askopenfilename( + filetypes=[("Reaction Mechanism Files", + ("*.inp","*.mech","*.ck2")), + ("All Files", "*.*")]) + if pathname: + self.infile.set(pathname) + self.show() - def browseForThermo(self, e=None): - pathname = askopenfilename( - filetypes=[("Thermodynamic Databases", - ("*.dat","*.inp","*.therm")), - ("All Files", "*.*")]) - if pathname: - self.thermo.set(pathname) - self.show() + def browseForThermo(self, e=None): + pathname = askopenfilename( + filetypes=[("Thermodynamic Databases", + ("*.dat","*.inp","*.therm")), + ("All Files", "*.*")]) + if pathname: + self.thermo.set(pathname) + self.show() - def browseForTransport(self, e=None): - pathname = askopenfilename( - filetypes=[("Transport Databases", "*.dat"), - ("All Files", "*.*")]) - if pathname: - self.transport.set(pathname) - self.show() + def browseForTransport(self, e=None): + pathname = askopenfilename( + filetypes=[("Transport Databases", "*.dat"), + ("All Files", "*.*")]) + if pathname: + self.transport.set(pathname) + self.show() - def importfile(self): - ckfile = self.infile.get() - thermdb = self.thermo.get() - trandb = self.transport.get() - p = os.path.normpath(os.path.dirname(ckfile)) - fname = os.path.basename(ckfile) - ff = os.path.splitext(fname) - nm = "" - if len(ff) > 1: nm = ff[0] - else: nm = ff - outfile = p+os.sep+nm+'.xml' - try: - print 'not supported.' - #ck2ctml(infile = ckfile, thermo = thermdb, - # transport = trandb, outfile = outfile, - # id = nm) - self.hide() - return - - except: - print 'Errors were encountered. See log file ck2ctml.log' - self.hide() - return - - self.top.loadmech(nm,outfile,1) - self.hide() - -## cmd = 'ck2ctml -i '+ckfile+' -o '+outfile -## if thermdb <> "": -## cmd += ' -t '+thermdb -## if trandb <> "": -## cmd += ' -tr '+trandb -## cmd += ' -id '+nm -## ok = os.system(cmd) -## if ok == 0: -## self.top.loadmech(nm,outfile,1) + def importfile(self): + ckfile = self.infile.get() + thermdb = self.thermo.get() + trandb = self.transport.get() + p = os.path.normpath(os.path.dirname(ckfile)) + fname = os.path.basename(ckfile) + ff = os.path.splitext(fname) + nm = "" + if len(ff) > 1: nm = ff[0] + else: nm = ff + outfile = p+os.sep+nm+'.xml' + try: + print 'not supported.' + #ck2ctml(infile = ckfile, thermo = thermdb, + # transport = trandb, outfile = outfile, + # id = nm) + self.hide() + return + + except: + print 'Errors were encountered. See log file ck2ctml.log' + self.hide() + return + + self.top.loadmech(nm,outfile,1) + self.hide() + +## cmd = 'ck2ctml -i '+ckfile+' -o '+outfile +## if thermdb <> "": +## cmd += ' -t '+thermdb +## if trandb <> "": +## cmd += ' -tr '+trandb +## cmd += ' -id '+nm +## ok = os.system(cmd) +## if ok == 0: +## self.top.loadmech(nm,outfile,1) - def hide(self): - #self.vis.set(0) - self.master.withdraw() + def hide(self): + #self.vis.set(0) + self.master.withdraw() - def show(self): - #v = self.vis.get() - #if v == 0: - # self.hide() - # return + def show(self): + #v = self.vis.get() + #if v == 0: + # self.hide() + # return - self.master.deiconify() + self.master.deiconify() diff --git a/interfaces/python/MixMaster/KineticsFrame.py b/interfaces/python/MixMaster/KineticsFrame.py index 4ab124cb1..80728b72d 100644 --- a/interfaces/python/MixMaster/KineticsFrame.py +++ b/interfaces/python/MixMaster/KineticsFrame.py @@ -11,408 +11,407 @@ _ATOL = 1.e-15 _RTOL = 1.e-7 def showsvg(): - f = open('_rp_svg.html','w') - f.write('\n') - f.close() - webbrowser.open('file:///'+os.getcwd()+'/_rp_svg.html') + f = open('_rp_svg.html','w') + f.write('\n') + f.close() + webbrowser.open('file:///'+os.getcwd()+'/_rp_svg.html') def showpng(): - f = open('_rp_png.html','w') - f.write('\n') - f.close() - webbrowser.open('file:///'+os.getcwd()+'/_rp_png.html') + f = open('_rp_png.html','w') + f.write('\n') + f.close() + webbrowser.open('file:///'+os.getcwd()+'/_rp_png.html') class KineticsFrame(Frame): - def __init__(self,master): - Frame.__init__(self,master) - self.config(relief=FLAT, bd=4) - self.top = self.master.top - self.controls=Frame(self) - self.hide = IntVar() - self.hide.set(0) - self.comp = IntVar() - self.comp.set(2) - self.controls.grid(column=1,row=0,sticky=W+E+N) - self.makeControls() - mf = self.master - - def makeControls(self): - Radiobutton(self.controls,text='Creation Rates', - variable=self.comp,value=0, - command=self.show).grid(column=0,row=0,sticky=W) - Radiobutton(self.controls,text='Destruction Rates', - variable=self.comp,value=1, - command=self.show).grid(column=0,row=1,sticky=W) - Radiobutton(self.controls,text='Net Production Rates', - variable=self.comp,value=2, - command=self.show).grid(column=0,row=2,sticky=W) + def __init__(self,master): + Frame.__init__(self,master) + self.config(relief=FLAT, bd=4) + self.top = self.master.top + self.controls=Frame(self) + self.hide = IntVar() + self.hide.set(0) + self.comp = IntVar() + self.comp.set(2) + self.controls.grid(column=1,row=0,sticky=W+E+N) + self.makeControls() + mf = self.master - def show(self): - mf = self.master - mf.active = self - c = self.comp.get() - mix = self.top.mix - g = mix.g - if c == 0: - mf.var.set("Creation Rates") - #mf.data = spdict(mix.g, mix.moles()) - mf.comp = g.creationRates() + def makeControls(self): + Radiobutton(self.controls,text='Creation Rates', + variable=self.comp,value=0, + command=self.show).grid(column=0,row=0,sticky=W) + Radiobutton(self.controls,text='Destruction Rates', + variable=self.comp,value=1, + command=self.show).grid(column=0,row=1,sticky=W) + Radiobutton(self.controls,text='Net Production Rates', + variable=self.comp,value=2, + command=self.show).grid(column=0,row=2,sticky=W) - elif c == 1: - mf.var.set("Destruction Rates") - #mf.data = spdict(mix.g,mix.mass()) - mf.comp = g.destructionRates() + def show(self): + mf = self.master + mf.active = self + c = self.comp.get() + mix = self.top.mix + g = mix.g + if c == 0: + mf.var.set("Creation Rates") + #mf.data = spdict(mix.g, mix.moles()) + mf.comp = g.creationRates() - elif c == 2: - mf.var.set("Net Production Rates") - mf.comp = g.netProductionRates() - #mf.data = spdict(mix,mix,mf.comp) - - for s in mf.variable.keys(): - try: - k = g.speciesIndex(s) - if mf.comp[k] > _CUTOFF or -mf.comp[k] > _CUTOFF: - mf.variable[s].set(mf.comp[k]) - else: - mf.variable[s].set(0.0) - except: - pass + elif c == 1: + mf.var.set("Destruction Rates") + #mf.data = spdict(mix.g,mix.mass()) + mf.comp = g.destructionRates() + + elif c == 2: + mf.var.set("Net Production Rates") + mf.comp = g.netProductionRates() + #mf.data = spdict(mix,mix,mf.comp) + + for s in mf.variable.keys(): + try: + k = g.speciesIndex(s) + if mf.comp[k] > _CUTOFF or -mf.comp[k] > _CUTOFF: + mf.variable[s].set(mf.comp[k]) + else: + mf.variable[s].set(0.0) + except: + pass class SpeciesKineticsFrame(Frame): - def __init__(self,master,top): - Frame.__init__(self,master) - self.config(relief=GROOVE, bd=4) - self.top = top - self.top.kinetics = self - self.g = self.top.mix.g - self.entries=Frame(self) - self.var = StringVar() - self.var.set("Net Production Rates") - self.names = self.top.mix.speciesNames() - self.nsp = len(self.names) - self.comp = [0.0]*self.nsp - self.makeControls() - self.makeEntries() - self.entries.bind('',self.minimize) - self.ctype = 0 - - def makeControls(self): - self.c = KineticsFrame(self) - #self.rr = ReactionKineticsFrame(self, self.top) - self.c.grid(column=1,row=0,sticky=E+W+N+S) - #self.rr.grid(column=0,row=1,sticky=E+W+N+S) + def __init__(self,master,top): + Frame.__init__(self,master) + self.config(relief=GROOVE, bd=4) + self.top = top + self.top.kinetics = self + self.g = self.top.mix.g + self.entries=Frame(self) + self.var = StringVar() + self.var.set("Net Production Rates") + self.names = self.top.mix.speciesNames() + self.nsp = len(self.names) + self.comp = [0.0]*self.nsp + self.makeControls() + self.makeEntries() + self.entries.bind('',self.minimize) + self.ctype = 0 - def show(self): - self.c.show() - - def redo(self): - self.update() - self.entries.destroy() - self.entries=Frame(self) - self.makeEntries() + def makeControls(self): + self.c = KineticsFrame(self) + #self.rr = ReactionKineticsFrame(self, self.top) + self.c.grid(column=1,row=0,sticky=E+W+N+S) + #self.rr.grid(column=0,row=1,sticky=E+W+N+S) - def minimize(self,Event=None): - self.c.hide.set(1) - self.redo() - self.c.grid_forget() - self.entries.bind("",self.maximize) - - def maximize(self,Event=None): - self.c.hide.set(0) - self.redo() - self.c.grid(column=1,row=0,sticky=E+W+N+S) - self.entries.bind("",self.minimize) + def show(self): + self.c.show() - def up(self, x): - self.update() - - def makeEntries(self): - self.entries.grid(row=0,column=0,sticky=W+N+S+E) - self.entries.config(relief=FLAT,bd=4) - DATAKEYS = self.top.species - self.variable = {} + def redo(self): + self.update() + self.entries.destroy() + self.entries=Frame(self) + self.makeEntries() - n=0 - ncol = 3 - col = 0 - row = 60 + def minimize(self,Event=None): + self.c.hide.set(1) + self.redo() + self.c.grid_forget() + self.entries.bind("",self.maximize) - for sp in DATAKEYS: - s = sp - k = s.index - if row > 15: - row = 0 - col = col + 2 - l = Label(self.entries,text='Species') - l.grid(column=col,row=row,sticky=E+W) - e1 = Entry(self.entries) - e1.grid(column=col+1,row=row,sticky=E+W) - e1['textvariable'] = self.var - e1.config(state=DISABLED) - e1.config(bg='lightyellow',relief=RIDGE) - row = row + 1 + def maximize(self,Event=None): + self.c.hide.set(0) + self.redo() + self.c.grid(column=1,row=0,sticky=E+W+N+S) + self.entries.bind("",self.minimize) - spname = s.name - val = self.comp[k] - if not self.c.hide.get() or val: showit = 1 - else: showit = 0 + def up(self, x): + self.update() - l=SpeciesInfo(self.entries,species=s, - text=spname,relief=FLAT,justify=RIGHT, - fg='darkblue') - entry1 = Entry(self.entries) - self.variable[spname] = DoubleVar() - self.variable[spname].set(self.comp[k]) - entry1['textvariable']=self.variable[spname] - entry1.bind('',self.up) - if showit: - l.grid(column= col ,row=row,sticky=E) - entry1.grid(column=col+1,row=row) - n=n+1 - row = row + 1 - entry1.config(state=DISABLED,bg='lightgray') + def makeEntries(self): + self.entries.grid(row=0,column=0,sticky=W+N+S+E) + self.entries.config(relief=FLAT,bd=4) + DATAKEYS = self.top.species + self.variable = {} + + n=0 + ncol = 3 + col = 0 + row = 60 + + for sp in DATAKEYS: + s = sp + k = s.index + if row > 15: + row = 0 + col = col + 2 + l = Label(self.entries,text='Species') + l.grid(column=col,row=row,sticky=E+W) + e1 = Entry(self.entries) + e1.grid(column=col+1,row=row,sticky=E+W) + e1['textvariable'] = self.var + e1.config(state=DISABLED) + e1.config(bg='lightyellow',relief=RIDGE) + row = row + 1 + + spname = s.name + val = self.comp[k] + if not self.c.hide.get() or val: showit = 1 + else: showit = 0 + + l=SpeciesInfo(self.entries,species=s, + text=spname,relief=FLAT,justify=RIGHT, + fg='darkblue') + entry1 = Entry(self.entries) + self.variable[spname] = DoubleVar() + self.variable[spname].set(self.comp[k]) + entry1['textvariable']=self.variable[spname] + entry1.bind('',self.up) + if showit: + l.grid(column= col ,row=row,sticky=E) + entry1.grid(column=col+1,row=row) + n=n+1 + row = row + 1 + entry1.config(state=DISABLED,bg='lightgray') class ReactionKineticsFrame(Frame): - def __init__(self,vis,top): - self.master = Toplevel() - self.master.protocol("WM_DELETE_WINDOW",self.hide) - self.vis = vis - Frame.__init__(self,self.master) - self.config(relief=GROOVE, bd=4) - self.top = top - self.g = self.top.mix.g - nr = self.g.nReactions() - self.eqs=Text(self,width=40,height=30) - self.data = [] - self.start = DoubleVar() - if nr > 30: - self.end = self.start.get()+30 - else: - self.end = self.start.get()+nr - - for i in range(4): - self.data.append(Text(self,width=15,height=30)) + def __init__(self,vis,top): + self.master = Toplevel() + self.master.protocol("WM_DELETE_WINDOW",self.hide) + self.vis = vis + Frame.__init__(self,self.master) + self.config(relief=GROOVE, bd=4) + self.top = top + self.g = self.top.mix.g + nr = self.g.nReactions() + self.eqs=Text(self,width=40,height=30) + self.data = [] + self.start = DoubleVar() + if nr > 30: + self.end = self.start.get()+30 + else: + self.end = self.start.get()+nr - for n in range(nr): - s = self.g.reactionEqn(n) - self.eqs.insert(END,s+'\n') - self.eqs.grid(column=0,row=1,sticky=W+E+N) - for i in range(4): - self.data[i].grid(column=i+1,row=1,sticky=W+E+N) - Label(self, text='Reaction').grid(column=0,row=0,sticky=W+E+N) - Label(self, text='Fwd ROP').grid(column=1,row=0,sticky=W+E+N) - Label(self, text='Rev ROP').grid(column=2,row=0,sticky=W+E+N) - Label(self, text='Net ROP').grid(column=3,row=0,sticky=W+E+N) - Label(self, text='Kp').grid(column=4,row=0,sticky=W+E+N) + for i in range(4): + self.data.append(Text(self,width=15,height=30)) - self.scfr = Frame(self) - self.scfr.config(relief=GROOVE,bd=4) + for n in range(nr): + s = self.g.reactionEqn(n) + self.eqs.insert(END,s+'\n') + self.eqs.grid(column=0,row=1,sticky=W+E+N) + for i in range(4): + self.data[i].grid(column=i+1,row=1,sticky=W+E+N) + Label(self, text='Reaction').grid(column=0,row=0,sticky=W+E+N) + Label(self, text='Fwd ROP').grid(column=1,row=0,sticky=W+E+N) + Label(self, text='Rev ROP').grid(column=2,row=0,sticky=W+E+N) + Label(self, text='Net ROP').grid(column=3,row=0,sticky=W+E+N) + Label(self, text='Kp').grid(column=4,row=0,sticky=W+E+N) -## self.sc = Scrollbar(self.scfr,command=self.show, -## variable = self.start, -## orient='horizontal',length=400) - self.sc = Scale(self.scfr,command=self.show, - variable=self.start, - orient='vertical',length=400) -# self.sc.config(cnf={'from':0,'to':nr},variable = self.start) - #self.sc.bind('',self.couple) - #self.scfr.bind('',self.decouple) - self.sc.pack(side=RIGHT,fill=Y) - self.scfr.grid(row=0,column=6,rowspan=10,sticky=N+E+W) - self.grid(column=0,row=0) + self.scfr = Frame(self) + self.scfr.config(relief=GROOVE,bd=4) - self.hide() +## self.sc = Scrollbar(self.scfr,command=self.show, +## variable = self.start, +## orient='horizontal',length=400) + self.sc = Scale(self.scfr,command=self.show, + variable=self.start, + orient='vertical',length=400) +# self.sc.config(cnf={'from':0,'to':nr},variable = self.start) + #self.sc.bind('',self.couple) + #self.scfr.bind('',self.decouple) + self.sc.pack(side=RIGHT,fill=Y) + self.scfr.grid(row=0,column=6,rowspan=10,sticky=N+E+W) + self.grid(column=0,row=0) -## def decouple(self,event=None): -## d = DoubleVar() -## xx = self.start.get() -## d.set(xx) -## self.sc.config(variable = d) - -## def couple(self,event=None): -## self.sc.config(variable = self.start) - - def hide(self): -# self.vis.set(0) - self.master.withdraw() - - def show(self,e=None,b=None,c=None): - v = self.vis.get() - print e,b,c - #if v == 0: - # self.hide() - # return - - self.master.deiconify() - nr = self.g.nReactions() - frop = self.g.fwdRatesOfProgress() - rrop = self.g.revRatesOfProgress() - kp = self.g.equilibriumConstants() - self.data[0].delete(1.0,END) - self.data[1].delete(1.0,END) - self.data[2].delete(1.0,END) - self.data[3].delete(1.0,END) - self.eqs.delete(1.0,END) + self.hide() - n0 = int(self.start.get()) - nn = nr - n0 - if nn > 30: nn = 30 - for n in range(n0, nn+n0): - s = '%12.5e \n' % (frop[n],) - self.data[0].insert(END,s) - s = '%12.5e \n' % (rrop[n],) - self.data[1].insert(END,s) - s = '%12.5e \n' % (frop[n] - rrop[n],) - self.data[2].insert(END,s) - s = '%12.5e \n' % (kp[n],) - self.data[3].insert(END,s) - self.eqs.insert(END, self.g.reactionEqn(n)+'\n') +## def decouple(self,event=None): +## d = DoubleVar() +## xx = self.start.get() +## d.set(xx) +## self.sc.config(variable = d) + +## def couple(self,event=None): +## self.sc.config(variable = self.start) + + def hide(self): +# self.vis.set(0) + self.master.withdraw() + + def show(self,e=None,b=None,c=None): + v = self.vis.get() + print e,b,c + #if v == 0: + # self.hide() + # return + + self.master.deiconify() + nr = self.g.nReactions() + frop = self.g.fwdRatesOfProgress() + rrop = self.g.revRatesOfProgress() + kp = self.g.equilibriumConstants() + self.data[0].delete(1.0,END) + self.data[1].delete(1.0,END) + self.data[2].delete(1.0,END) + self.data[3].delete(1.0,END) + self.eqs.delete(1.0,END) + + n0 = int(self.start.get()) + nn = nr - n0 + if nn > 30: nn = 30 + for n in range(n0, nn+n0): + s = '%12.5e \n' % (frop[n],) + self.data[0].insert(END,s) + s = '%12.5e \n' % (rrop[n],) + self.data[1].insert(END,s) + s = '%12.5e \n' % (frop[n] - rrop[n],) + self.data[2].insert(END,s) + s = '%12.5e \n' % (kp[n],) + self.data[3].insert(END,s) + self.eqs.insert(END, self.g.reactionEqn(n)+'\n') class ReactionPathFrame(Frame): - def __init__(self,top): - self.master = Toplevel() - self.master.protocol("WM_DELETE_WINDOW",self.hide) - #self.vis = vis - Frame.__init__(self,self.master) - self.config(relief=GROOVE, bd=4) - self.grid(column=0,row=0) - self.top = top - self.g = self.top.mix.g - self.el = IntVar() - self.el.set(0) - self.thresh = DoubleVar() - - scframe = Frame(self) - self.sc = Scale(scframe,variable = self.thresh, - orient='horizontal',digits=3,length=300,resolution=0.01) - self.sc.config(cnf={'from':-6,'to':0}) - Label(scframe,text='log10 Threshold').grid(column=0,row=0) - self.sc.grid(row=0,column=1,columnspan=10) - self.sc.bind('',self.show) - scframe.grid(row=3,column=0,columnspan=10) - - enames = self.g.elementNames() - self.nel = len(enames) - - i = 1 - eframe = Frame(self) - Label(eframe,text='Element').grid(column=0,row=0,sticky=W) - for e in enames: - Radiobutton(eframe,text=e, - variable=self.el,value=i-1, - command=self.show).grid(column=i,row=0,sticky=W) - i += 1 - eframe.grid(row=0,column=0) + def __init__(self,top): + self.master = Toplevel() + self.master.protocol("WM_DELETE_WINDOW",self.hide) + #self.vis = vis + Frame.__init__(self,self.master) + self.config(relief=GROOVE, bd=4) + self.grid(column=0,row=0) + self.top = top + self.g = self.top.mix.g + self.el = IntVar() + self.el.set(0) + self.thresh = DoubleVar() - self.detailed = IntVar() - Checkbutton(self, text = 'Show details', variable=self.detailed, - command=self.show).grid(column=1,row=0) - self.net = IntVar() - Checkbutton(self, text = 'Show net flux', - variable=self.net, - command=self.show).grid(column=2,row=0) - self.local = StringVar() - Label(self,text='Species').grid(column=1,row=1,sticky=E) - sp = Entry(self, textvariable=self.local, - width=15) - sp.grid(column=2,row=1) - sp.bind('',self.show) - - self.b = rxnpath.PathBuilder(self.g) + scframe = Frame(self) + self.sc = Scale(scframe,variable = self.thresh, + orient='horizontal',digits=3,length=300,resolution=0.01) + self.sc.config(cnf={'from':-6,'to':0}) + Label(scframe,text='log10 Threshold').grid(column=0,row=0) + self.sc.grid(row=0,column=1,columnspan=10) + self.sc.bind('',self.show) + scframe.grid(row=3,column=0,columnspan=10) - self.fmt = StringVar() - self.fmt.set('svg') - i = 1 - fmtframe = Frame(self) - fmtframe.config(relief=GROOVE, bd=4) - self.browser = IntVar() - self.browser.set(0) - Checkbutton(fmtframe, text = 'Display in Web Browser', - variable=self.browser, - command=self.show).grid(column=0,columnspan=6,row=0) - Label(fmtframe,text='Format').grid(column=0,row=1,sticky=W) - for e in ['svg', 'png', 'gif', 'jpg']: - Radiobutton(fmtframe,text=e, - variable=self.fmt,value=e, - command=self.show).grid(column=i,row=1,sticky=W) - i += 1 - fmtframe.grid(row=5,column=0,columnspan=10,sticky=E+W) - - self.cv = Canvas(self,relief=SUNKEN,bd=1) - self.cv.grid(column=0,row=4,sticky=W+E+N,columnspan=10) + enames = self.g.elementNames() + self.nel = len(enames) - pframe = Frame(self) - pframe.config(relief=GROOVE, bd=4) - self.dot = StringVar() - self.dot.set('dot -Tgif rxnpath.dot > rxnpath.gif') - Label(pframe,text='DOT command:').grid(column=0,row=0,sticky=W) - Entry(pframe,width=60,textvariable=self.dot).grid(column=0, - row=1,sticky=W) - pframe.grid(row=6,column=0,columnspan=10,sticky=E+W) - - self.thresh.set(-2.0) - self.hide() + i = 1 + eframe = Frame(self) + Label(eframe,text='Element').grid(column=0,row=0,sticky=W) + for e in enames: + Radiobutton(eframe,text=e, + variable=self.el,value=i-1, + command=self.show).grid(column=i,row=0,sticky=W) + i += 1 + eframe.grid(row=0,column=0) - def hide(self): - #self.vis.set(0) - self.master.withdraw() - - def show(self,e=None): + self.detailed = IntVar() + Checkbutton(self, text = 'Show details', variable=self.detailed, + command=self.show).grid(column=1,row=0) + self.net = IntVar() + Checkbutton(self, text = 'Show net flux', + variable=self.net, + command=self.show).grid(column=2,row=0) + self.local = StringVar() + Label(self,text='Species').grid(column=1,row=1,sticky=E) + sp = Entry(self, textvariable=self.local, + width=15) + sp.grid(column=2,row=1) + sp.bind('',self.show) - self.master.deiconify() - el = self.g.elementName(self.el.get()) - det = 'false' - if self.detailed.get() == 1: det = 'true' - flow = 'one_way' - if self.net.get() == 1: flow = 'net' - self.d = rxnpath.PathDiagram(arrow_width=-2, - flow_type=flow, - detailed = det, - threshold=math.pow(10.0, - self.thresh.get())) - node = self.local.get() - try: - k = self.g.speciesIndex(node) - self.d.displayOnly(k) - except: - self.d.displayOnly() + self.b = rxnpath.PathBuilder(self.g) - self.b.build(element = el, diagram = self.d, - dotfile = 'rxnpath.dot', format = 'dot') - #self.b.build(element = el, diagram = self.d, - # dotfile = 'rxnpath.txt', format = 'plain') + self.fmt = StringVar() + self.fmt.set('svg') + i = 1 + fmtframe = Frame(self) + fmtframe.config(relief=GROOVE, bd=4) + self.browser = IntVar() + self.browser.set(0) + Checkbutton(fmtframe, text = 'Display in Web Browser', + variable=self.browser, + command=self.show).grid(column=0,columnspan=6,row=0) + Label(fmtframe,text='Format').grid(column=0,row=1,sticky=W) + for e in ['svg', 'png', 'gif', 'jpg']: + Radiobutton(fmtframe,text=e, + variable=self.fmt,value=e, + command=self.show).grid(column=i,row=1,sticky=W) + i += 1 + fmtframe.grid(row=5,column=0,columnspan=10,sticky=E+W) - if self.browser.get() == 1: - fmt = self.fmt.get() - os.system('dot -T'+fmt+' rxnpath.dot > rxnpath.'+fmt) - if fmt == 'svg': showsvg() - elif fmt == 'png': showpng() - else: - path = 'file:///'+os.getcwd()+'/rxnpath.'+fmt - webbrowser.open(path) - try: - self.cv.delete(self.image) - except: - pass - self.cv.configure(width=0, height=0) - else: - os.system(self.dot.get()) - self.rp = None - try: - self.cv.delete(self.image) - except: - pass - try: - self.rp = PhotoImage(file='rxnpath.gif') - self.cv.configure(width=self.rp.width(), - height=self.rp.height()) - - self.image = self.cv.create_image(0,0,anchor=NW, - image=self.rp) - except: - pass - + self.cv = Canvas(self,relief=SUNKEN,bd=1) + self.cv.grid(column=0,row=4,sticky=W+E+N,columnspan=10) + + pframe = Frame(self) + pframe.config(relief=GROOVE, bd=4) + self.dot = StringVar() + self.dot.set('dot -Tgif rxnpath.dot > rxnpath.gif') + Label(pframe,text='DOT command:').grid(column=0,row=0,sticky=W) + Entry(pframe,width=60,textvariable=self.dot).grid(column=0, + row=1,sticky=W) + pframe.grid(row=6,column=0,columnspan=10,sticky=E+W) + + self.thresh.set(-2.0) + self.hide() + + def hide(self): + #self.vis.set(0) + self.master.withdraw() + + def show(self,e=None): + + self.master.deiconify() + el = self.g.elementName(self.el.get()) + det = 'false' + if self.detailed.get() == 1: det = 'true' + flow = 'one_way' + if self.net.get() == 1: flow = 'net' + self.d = rxnpath.PathDiagram(arrow_width=-2, + flow_type=flow, + detailed = det, + threshold=math.pow(10.0, + self.thresh.get())) + node = self.local.get() + try: + k = self.g.speciesIndex(node) + self.d.displayOnly(k) + except: + self.d.displayOnly() + + self.b.build(element = el, diagram = self.d, + dotfile = 'rxnpath.dot', format = 'dot') + #self.b.build(element = el, diagram = self.d, + # dotfile = 'rxnpath.txt', format = 'plain') + + if self.browser.get() == 1: + fmt = self.fmt.get() + os.system('dot -T'+fmt+' rxnpath.dot > rxnpath.'+fmt) + if fmt == 'svg': showsvg() + elif fmt == 'png': showpng() + else: + path = 'file:///'+os.getcwd()+'/rxnpath.'+fmt + webbrowser.open(path) + try: + self.cv.delete(self.image) + except: + pass + self.cv.configure(width=0, height=0) + else: + os.system(self.dot.get()) + self.rp = None + try: + self.cv.delete(self.image) + except: + pass + try: + self.rp = PhotoImage(file='rxnpath.gif') + self.cv.configure(width=self.rp.width(), + height=self.rp.height()) + + self.image = self.cv.create_image(0,0,anchor=NW, + image=self.rp) + except: + pass diff --git a/interfaces/python/MixMaster/MechManager.py b/interfaces/python/MixMaster/MechManager.py index 7599c2e64..7a1843f0c 100644 --- a/interfaces/python/MixMaster/MechManager.py +++ b/interfaces/python/MixMaster/MechManager.py @@ -10,7 +10,7 @@ _autoload = [ (' GRI-Mech 3.0', 'gri30.cti'), (' Air', 'air.cti'), (' H/O/Ar', 'h2o2.cti') - ] + ] def testit(): pass @@ -18,41 +18,41 @@ def testit(): class MechManager(Frame): def __init__(self,master,app): - Frame.__init__(self,master) - #self.config(relief=GROOVE, bd=4) - self.app = app - self.master = master - self.mechindx = IntVar() - self.mechindx.set(1) - - #m = Label(self, text = 'Loaded Mechanisms') - #m.grid(column=0,row=0) + Frame.__init__(self,master) + #self.config(relief=GROOVE, bd=4) + self.app = app + self.master = master + self.mechindx = IntVar() + self.mechindx.set(1) + + #m = Label(self, text = 'Loaded Mechanisms') + #m.grid(column=0,row=0) # m.bind('',self.show) # self.mechindx.set(0) - self.mechanisms = [] - self.mlist = [ [] ] - i = 1 - #for m in self.mechanisms: - # self.mlist.append((m[0], self.setMechanism, 'check', self.mechindx, i)) - # i = i + 1 - #self.mlist.append([]) + self.mechanisms = [] + self.mlist = [ [] ] + i = 1 + #for m in self.mechanisms: + # self.mlist.append((m[0], self.setMechanism, 'check', self.mechindx, i)) + # i = i + 1 + #self.mlist.append([]) - self.mechmenu = make_menu('Mixtures', self, self.mlist) - self.mechmenu.grid(row=0,column=0,sticky=W) + self.mechmenu = make_menu('Mixtures', self, self.mlist) + self.mechmenu.grid(row=0,column=0,sticky=W) - self.mfr = None + self.mfr = None def addMechanism(self, name, mech): self.mechanisms.append((name, mech)) il = len(self.mechanisms) - self.mlist[-1] = (name, self.setMechanism, 'check', self.mechindx, il) + self.mlist[-1] = (name, self.setMechanism, 'check', self.mechindx, il) self.mlist.append([]) - + self.mechmenu = make_menu('Mixtures', self, self.mlist) self.mechindx.set(il) self.mechmenu.grid(row=0,column=0,sticky=W) - - + + def delMechanism(self, mech): self.mechanisms.remove(mech) self.show() @@ -73,14 +73,9 @@ class MechManager(Frame): ## i = i + 1 ## print 'end' - + def setMechanism(self, event=None): i = self.mechindx.get() self.app.mech = self.mechanisms[i-1][1] self.app.makeMix() - self.app.makeWindows() - - - - - + self.app.makeWindows() diff --git a/interfaces/python/MixMaster/Mix.py b/interfaces/python/MixMaster/Mix.py index 8d7b6c41f..b0b95317f 100644 --- a/interfaces/python/MixMaster/Mix.py +++ b/interfaces/python/MixMaster/Mix.py @@ -3,18 +3,18 @@ from Cantera.num import zeros, ones from utilities import handleError def spdict(phase, x): - nm = phase.speciesNames() - data = {} - for k in range(len(nm)): - data[nm[k]] = x[k] - return data + nm = phase.speciesNames() + data = {} + for k in range(len(nm)): + data[nm[k]] = x[k] + return data class Species: def __init__(self,g,name): self.g = g - t = g.temperature() - p = g.pressure() - x = g.moleFractions() + t = g.temperature() + p = g.pressure() + x = g.moleFractions() self.name = name self.symbol = name self.index = g.speciesIndex(name) @@ -23,28 +23,28 @@ class Species: self.molecularWeight = g.molecularWeights()[self.index] self.c = [] self.e = g.elementNames() - self.hf0 = self.enthalpy_RT(298.15)*GasConstant*298.15 - g.setState_TPX(t,p,x) + self.hf0 = self.enthalpy_RT(298.15)*GasConstant*298.15 + g.setState_TPX(t,p,x) for n in range(len(self.e)): na = g.nAtoms(self.index, n) if na > 0: self.c.append((self.e[n],na)) - + def composition(self): return self.c - + def enthalpy_RT(self,t): self.g.setTemperature(t) return self.g.enthalpies_RT()[self.index] def cp_R(self,t): self.g.setTemperature(t) - return self.g.cp_R()[self.index] + return self.g.cp_R()[self.index] def entropy_R(self,t): self.g.setTemperature(t) - return self.g.entropies_R()[self.index] - + return self.g.entropies_R()[self.index] + class Mix: def __init__(self,g): self.g = g @@ -71,14 +71,14 @@ class Mix: for k in range(self.nsp): sum += self._moles[k]*self.wt[k] return sum - + def moleDict(self): d = {} nm = self.g.speciesNames() for e in range(self.nsp): d[nm[e]] = self._moles[e] return d - + def setMass(self, m): self.setMoles( m/self.wt) @@ -99,7 +99,7 @@ class Mix: density = None, enthalpy = None, entropy = None, intEnergy = None, equil = 0): total_mass = self.totalMass() - + if temperature and pressure: self.g.setState_TP(temperature, pressure) if equil: @@ -114,7 +114,7 @@ class Mix: self.g.setState_HP(enthalpy, pressure) if equil: self.g.equilibrate('HP',solver=0) - + elif pressure and entropy: self.g.setState_SP(entropy, pressure) if equil: @@ -130,12 +130,9 @@ class Mix: if equil: self.g.equilibrate('UV',solver=0) -# else: -# handleError('unsupported property pair', warning=1) - - +# else: +# handleError('unsupported property pair', warning=1) + + total_moles = total_mass/self.g.meanMolecularWeight() self._moles = self.g.moleFractions()*total_moles - - - diff --git a/interfaces/python/MixMaster/NewFlowFrame.py b/interfaces/python/MixMaster/NewFlowFrame.py index b0335ce0e..0ac5791a6 100644 --- a/interfaces/python/MixMaster/NewFlowFrame.py +++ b/interfaces/python/MixMaster/NewFlowFrame.py @@ -8,109 +8,107 @@ _ATOL = 1.e-15 _RTOL = 1.e-7 class NewFlowFrame(Frame): - def __init__(self,master): - Frame.__init__(self,master) - self.config(relief=GROOVE, bd=4) - self.app = self.master.app - self.controls=Frame(self) - self.hide = IntVar() - self.hide.set(0) - self.p = DoubleVar() - #self.comp.set(1.0) - self.controls.grid(column=1,row=0,sticky=W+E+N) - #self.makeControls() - mf = self.master + def __init__(self,master): + Frame.__init__(self,master) + self.config(relief=GROOVE, bd=4) + self.app = self.master.app + self.controls=Frame(self) + self.hide = IntVar() + self.hide.set(0) + self.p = DoubleVar() + #self.comp.set(1.0) + self.controls.grid(column=1,row=0,sticky=W+E+N) + #self.makeControls() + mf = self.master - e1 = Entry(self) - e1.grid(column=0,row=0,sticky=E+W) - e1['textvariable'] = self.p - #e1.config(state=ENABLED) - e1.config(relief=RIDGE) - -## def makeControls(self): -## Radiobutton(self.controls,text='Moles', -## variable=self.comp,value=0,command=self.show).grid(column=0,row=0,sticky=W) -## Radiobutton(self.controls,text='Mass',variable=self.comp,value=1,command=self.show).grid(column=0,row=1,sticky=W) -## Radiobutton(self.controls,text='Concentration',variable=self.comp,value=2,command=self.show).grid(column=0,row=2,sticky=W) -## Button(self.controls,text='Clear',command=self.zero).grid(column=0,row=4,sticky=W+E) -## Button(self.controls,text='Normalize',command=self.norm).grid(column=0,row=5,sticky=W+E) -## Checkbutton(self.controls,text='Hide Missing\nSpecies', -## variable=self.hide,onvalue=1,offvalue=0,command=self.master.redo).grid(column=0,row=3,sticky=W) + e1 = Entry(self) + e1.grid(column=0,row=0,sticky=E+W) + e1['textvariable'] = self.p + #e1.config(state=ENABLED) + e1.config(relief=RIDGE) - -## def makeControls(self): -## self.c = CompFrame(self) -## self.c.grid(column=1,row=0,sticky=E+W+N+S) - -## def redo(self): -## self.update() -## self.entries.destroy() -## self.entries=Frame(self) -## self.makeEntries() - -## def minimize(self,Event=None): -## self.c.hide.set(1) -## self.redo() -## self.c.grid_forget() -## self.entries.bind("",self.maximize) - -## def maximize(self,Event=None): -## self.c.hide.set(0) -## self.redo() -## self.c.grid(column=1,row=0,sticky=E+W+N+S) -## self.entries.bind("",self.minimize) +## def makeControls(self): +## Radiobutton(self.controls,text='Moles', +## variable=self.comp,value=0,command=self.show).grid(column=0,row=0,sticky=W) +## Radiobutton(self.controls,text='Mass',variable=self.comp,value=1,command=self.show).grid(column=0,row=1,sticky=W) +## Radiobutton(self.controls,text='Concentration',variable=self.comp,value=2,command=self.show).grid(column=0,row=2,sticky=W) +## Button(self.controls,text='Clear',command=self.zero).grid(column=0,row=4,sticky=W+E) +## Button(self.controls,text='Normalize',command=self.norm).grid(column=0,row=5,sticky=W+E) +## Checkbutton(self.controls,text='Hide Missing\nSpecies', +## variable=self.hide,onvalue=1,offvalue=0,command=self.master.redo).grid(column=0,row=3,sticky=W) -## def makeEntries(self): -## self.entries.grid(row=0,column=0,sticky=W+N+S+E) -## self.entries.config(relief=GROOVE,bd=4) -## DATAKEYS = self.top.species -## self.variable = {} +## def makeControls(self): +## self.c = CompFrame(self) +## self.c.grid(column=1,row=0,sticky=E+W+N+S) -## n=0 -## ncol = 3 -## col = 0 -## row = 60 +## def redo(self): +## self.update() +## self.entries.destroy() +## self.entries=Frame(self) +## self.makeEntries() -## presbox = - -## for sp in DATAKEYS: -## s = sp # self.top.species[sp] -## k = s.index -## if row > 15: -## row = 0 -## col = col + 2 -## l = Label(self.entries,text='Species') -## l.grid(column=col,row=row,sticky=E+W) -## e1 = Entry(self.entries) -## e1.grid(column=col+1,row=row,sticky=E+W) -## e1['textvariable'] = self.var -## e1.config(state=DISABLED) -## e1.config(bg='lightyellow',relief=RIDGE) -## row = row + 1 +## def minimize(self,Event=None): +## self.c.hide.set(1) +## self.redo() +## self.c.grid_forget() +## self.entries.bind("",self.maximize) -## spname = s.name -## val = self.comp[k] -## if not self.c.hide.get() or val: showit = 1 -## else: showit = 0 +## def maximize(self,Event=None): +## self.c.hide.set(0) +## self.redo() +## self.c.grid(column=1,row=0,sticky=E+W+N+S) +## self.entries.bind("",self.minimize) -## l=SpeciesInfo(self.entries,species=s, + +## def makeEntries(self): +## self.entries.grid(row=0,column=0,sticky=W+N+S+E) +## self.entries.config(relief=GROOVE,bd=4) +## DATAKEYS = self.top.species +## self.variable = {} + +## n=0 +## ncol = 3 +## col = 0 +## row = 60 + +## presbox = + +## for sp in DATAKEYS: +## s = sp # self.top.species[sp] +## k = s.index +## if row > 15: +## row = 0 +## col = col + 2 +## l = Label(self.entries,text='Species') +## l.grid(column=col,row=row,sticky=E+W) +## e1 = Entry(self.entries) +## e1.grid(column=col+1,row=row,sticky=E+W) +## e1['textvariable'] = self.var +## e1.config(state=DISABLED) +## e1.config(bg='lightyellow',relief=RIDGE) +## row = row + 1 + +## spname = s.name +## val = self.comp[k] +## if not self.c.hide.get() or val: showit = 1 +## else: showit = 0 + +## l=SpeciesInfo(self.entries,species=s, ## text=spname,relief=FLAT,justify=RIGHT, -## fg='darkblue') -## entry1 = Entry(self.entries) -## self.variable[spname] = DoubleVar() -## self.variable[spname].set(self.comp[k]) -## entry1['textvariable']=self.variable[spname] -## entry1.bind('',self.up) -## if showit: -## l.grid(column= col ,row=row,sticky=E) -## entry1.grid(column=col+1,row=row) -## n=n+1 -## row = row + 1 +## fg='darkblue') +## entry1 = Entry(self.entries) +## self.variable[spname] = DoubleVar() +## self.variable[spname].set(self.comp[k]) +## entry1['textvariable']=self.variable[spname] +## entry1.bind('',self.up) +## if showit: +## l.grid(column= col ,row=row,sticky=E) +## entry1.grid(column=col+1,row=row) +## n=n+1 +## row = row + 1 ## if self.c.hide.get(): -## b=Button(self.entries,height=1,command=self.maximize) -## else: -## b=Button(self.entries,command=self.minimize) +## b=Button(self.entries,height=1,command=self.maximize) +## else: +## b=Button(self.entries,command=self.minimize) ## b.grid(column=col,columnspan=2, row=row+1) - - diff --git a/interfaces/python/MixMaster/SpeciesFrame.py b/interfaces/python/MixMaster/SpeciesFrame.py index 5f92d96fd..8b0ee0765 100644 --- a/interfaces/python/MixMaster/SpeciesFrame.py +++ b/interfaces/python/MixMaster/SpeciesFrame.py @@ -18,10 +18,10 @@ class SpeciesFrame(Frame): self.species = {} for sp in speciesList: self.species[sp.name] = sp - + self.control.config(relief=GROOVE,bd=4) Button(self.control, text = 'Display',command=self.show).pack(fill=X,pady=3, padx=10) - Button(self.control, text = 'Clear',command=self.clear).pack(fill=X,pady=3, padx=10) + Button(self.control, text = 'Clear',command=self.clear).pack(fill=X,pady=3, padx=10) Button(self.control, text = ' OK ',command=self.get).pack(side=BOTTOM, fill=X,pady=3, padx=10) Button(self.control, text = 'Cancel',command=self.master.quit).pack(side=BOTTOM, @@ -64,7 +64,7 @@ class SpeciesFrame(Frame): for sp in splist: spname = sp.name self.select(spname) - + def setColors(self,event): el = event.widget['text'] if event.widget['relief'] == RAISED: @@ -77,7 +77,7 @@ class SpeciesFrame(Frame): back = self.color(el, sel=1) event.widget['bg'] = back event.widget['fg'] = fore - + def color(self, el, sel=0): _normal = ['#88dddd','#005500','#dd8888'] _selected = ['#aaffff','#88dd88','#ffaaaa'] @@ -98,7 +98,7 @@ class SpeciesFrame(Frame): if self.c[sp.name]['relief'] == RAISED: selected.append(sp) #showElementProperties(selected) - + def get(self): self.selected = [] for sp in self.species.values(): @@ -106,7 +106,7 @@ class SpeciesFrame(Frame): self.selected.append(sp) #self.master.quit()' self.master.destroy() - + def clear(self): for sp in self.species.values(): self.c[sp]['bg'] = self.color(sp, sel=0) @@ -124,7 +124,7 @@ class SpeciesFrame(Frame): ## row=0, ## sticky=W+S, ## padx=10, -## pady=10) +## pady=10) ## for el in ellist: ## Label(self, ## text=el.name).grid(column=0, @@ -168,9 +168,7 @@ def showElementProperties(ellist): m.title('Element Properties') elem = [] ElementPropertyFrame(m, ellist).pack() - + if __name__ == "__main__": print getSpecies() - - diff --git a/interfaces/python/MixMaster/SpeciesInfo.py b/interfaces/python/MixMaster/SpeciesInfo.py index 6ef899447..5eff48a4c 100644 --- a/interfaces/python/MixMaster/SpeciesInfo.py +++ b/interfaces/python/MixMaster/SpeciesInfo.py @@ -6,240 +6,237 @@ from UnitChooser import UnitVar from GraphFrame import Graph def testit(): - pass + pass class SpeciesInfo(Label): - def __init__(self,master,phase=None,species=None,**opt): - Label.__init__(self,master,opt) - self.sp = species - self.phase = phase - self.bind('', self.show) - self.bind('', self.show) - self.bind('', self.highlight) - self.bind('', self.nohighlight) - - - def highlight(self, event=None): - self.config(fg='yellow') - - def nohighlight(self, event=None): - self.config(fg='darkblue') - - def show(self, event): - self.new=Toplevel() - self.new.title(self.sp.symbol) - #self.new.transient(self.master) - self.new.bind("", self.update,"+") - self.cpr = 0.0 - self.t = 0.0 - self.cpl = 0.0 - self.tl = 0.0 - self.cpp = [[(0.0, 0.0, 'red')]] - - # elemental composition - self.eframe = Frame(self.new) - self.eframe.config(relief=GROOVE,bd=4) - self.eframe.grid(row=0,column=0,columnspan=10,sticky=E+W) - r = 1 - Label(self.eframe,text='Atoms:')\ - .grid(row=0,column=0,sticky=N+W) - for el, c in self.sp.composition(): - Label(self.eframe,text=`int(c)`+' '+el).grid(row=0,column=r) - r = r + 1 - - - # thermodynamic properties - self.thermo = Frame(self.new) - self.thermo.config(relief=GROOVE,bd=4) - self.thermo.grid(row=1,column=0,columnspan=10,sticky=N+E+W) - Label(self.thermo,text = 'Standard Heat of Formation at 298 K: ').grid(row=0, column=0, sticky=W) - Label(self.thermo,text = '%8.2f kJ/mol' % (self.sp.hf0*1.0e-6)).grid(row=0, column=1, sticky=W) - Label(self.thermo,text = 'Molar Mass: ').grid(row=1, column=0, sticky=W) - Label(self.thermo,text = self.sp.molecularWeight).grid(row=1, column=1, sticky=W) - labels = ['Temperature', 'c_p', 'Enthalpy', 'Entropy'] - units = [temperature, specificEntropy, specificEnergy, specificEntropy] - whichone = [0, 1, 1, 1] - - r = 2 - self.prop = [] - for prop in labels: - Label(self.thermo,text=prop).grid(row=r,column=0,sticky=W) - p = UnitVar(self.thermo,units[r-2],whichone[r-2]) - p.grid(row=r,column=1,sticky=W) - p.v.config(state=DISABLED,bg='lightgray') - self.prop.append(p) - r = r + 1 - - tmin = self.sp.minTemp - tmax = self.sp.maxTemp - cp = self.sp.cp_R(tmin) - hh = self.sp.enthalpy_RT(tmin) - ss = self.sp.entropy_R(tmin) - - self.prop[0].bind("", self.decouple) - self.prop[0].bind("", self.update) - self.prop[0].bind("", self.update) - self.prop[0].v.config(state=NORMAL,bg='white') - self.prop[0].set(300.0) - - self.graphs = Frame(self.new) - self.graphs.config(relief=GROOVE,bd=4) - self.graphs.grid(row=2,column=0,columnspan=10,sticky=E+W) - - self.cpdata = [] - self.hdata = [] - self.sdata = [] - t = tmin - n = int((tmax - tmin)/100.0) - while t <= tmax: - self.cpdata.append((t,self.sp.cp_R(t))) - self.hdata.append((t,self.sp.enthalpy_RT(t))) - self.sdata.append((t,self.sp.entropy_R(t))) - t = t + n - - # specific heat - - Label(self.graphs,text='c_p/R').grid(row=0,column=0,sticky=W+E) - ymin, ymax, dtick = self.plotLimits(self.cpdata) - self.cpg = Graph(self.graphs,'',tmin,tmax,ymin,ymax, - pixelX=150,pixelY=150) - self.cpg.canvas.config(bg='white') - self.cpg.grid(row=1,column=0,columnspan=2,sticky=W+E) - self.ticks(ymin, ymax, dtick, tmin, tmax, self.cpg) - - # enthalpy - Label(self.graphs,text='enthalpy/RT').grid(row=0,column=3,sticky=W+E) - ymin, ymax, dtick = self.plotLimits(self.hdata) - self.hg = Graph(self.graphs,'',tmin,tmax,ymin,ymax, - pixelX=150,pixelY=150) - self.hg.canvas.config(bg='white') - self.hg.grid(row=1,column=3,columnspan=2,sticky=W+E) - self.ticks(ymin, ymax, dtick, tmin, tmax, self.hg) - - # entropy - Label(self.graphs,text='entropy/R').grid(row=0,column=5,sticky=W+E) - ymin, ymax, dtick = self.plotLimits(self.sdata) - self.sg = Graph(self.graphs,'',tmin,tmax,ymin,ymax, - pixelX=150,pixelY=150) - self.sg.canvas.config(bg='white') - self.sg.grid(row=1,column=5,columnspan=2,sticky=W+E) - self.ticks(ymin, ymax, dtick, tmin, tmax, self.sg) - - n = int((tmax - tmin)/100.0) - t = tmin - self.cpp = [] - - for t, cp in self.cpdata: - self.cpg.join([(t,cp,'red')]) - for t, h in self.hdata: - self.hg.join([(t,h,'green')]) - for t, s in self.sdata: - self.sg.join([(t,s,'blue')]) - - self.cpdot = self.cpg.plot(tmin,cp,'red') - self.hdot = self.hg.plot(tmin,hh,'green') - self.sdot = self.sg.plot(tmin,ss,'blue') - - b=Button(self.new,text=' OK ',command=self.finished, default=ACTIVE) - #ed=Button(self.new,text='Edit',command=testit) - b.grid(column=0, row=4,sticky=W) - #ed.grid(column=1,row=4,sticky=W) - - self.scfr = Frame(self.new) - self.scfr.config(relief=GROOVE,bd=4) - self.scfr.grid(row=3,column=0,columnspan=10,sticky=N+E+W) - self.sc = Scale(self.scfr,command=self.update,variable = self.prop[0].x, - orient='horizontal',digits=7,length=400) - self.sc.config(cnf={'from':tmin,'to':tmax}) - self.sc.bind('',self.couple) - self.scfr.bind('',self.decouple) - self.sc.grid(row=0,column=0,columnspan=10) - - def decouple(self,event=None): - d = DoubleVar() - xx = self.prop[0].get() - d.set(xx) - self.sc.config(variable = d) - - def couple(self,event=None): - self.sc.config(variable = self.prop[0].x) - #self.update() - - def update(self,event=None): - try: - tmp = self.prop[0].get() - cnd = self.sp.cp_R(tmp) - cc = cnd*GasConstant - self.prop[1].set(cc) - hnd = self.sp.enthalpy_RT(tmp) - hh = hnd*tmp*GasConstant - self.prop[2].set(hh) - snd = self.sp.entropy_R(tmp) - ss = snd*tmp*GasConstant - self.prop[3].set(ss) + def __init__(self,master,phase=None,species=None,**opt): + Label.__init__(self,master,opt) + self.sp = species + self.phase = phase + self.bind('', self.show) + self.bind('', self.show) + self.bind('', self.highlight) + self.bind('', self.nohighlight) - self.cppoint = tmp, cnd - self.hpoint = tmp, hnd - self.spoint = tmp, snd - if hasattr(self, 'cpdot'): - self.cpg.delete(self.cpdot) - self.cpdot = self.cpg.plot(self.cppoint[0], self.cppoint[1],'red') - self.hg.delete(self.hdot) - self.hdot = self.hg.plot(self.hpoint[0], self.hpoint[1],'green') - self.sg.delete(self.sdot) - self.sdot = self.sg.plot(self.spoint[0], self.spoint[1],'blue') - except: - pass - - def plotLimits(self, xy): - ymax = -1.e10 - ymin = 1.e10 - for x, y in xy: - if y > ymax: ymax = y - if y < ymin: ymin = y - - dy = abs(ymax - ymin) - if dy < 0.2*ymin: - ymin = ymin*.9 - ymax = ymax*1.1 - dy = abs(ymax - ymin) - else: - ymin = ymin - 0.1*dy - ymax = ymax + 0.1*dy - dy = abs(ymax - ymin) - - p10 = math.floor(math.log10(0.1*dy)) - fctr = math.pow(10.0, p10) - mm = [2.0, 2.5, 2.0] - i = 0 - while dy/fctr > 5: - fctr = mm[i % 3]*fctr - i = i + 1 - ymin = fctr*math.floor(ymin/fctr) - ymax = fctr*(math.floor(ymax/fctr + 1)) - return (ymin, ymax, fctr) + def highlight(self, event=None): + self.config(fg='yellow') - def ticks(self, ymin, ymax, dtick, tmin, tmax, plot): - ytick = ymin - eps = 1.e-3 - while ytick <= ymax: - if abs(ytick) < eps: - plot.join([(tmin, ytick, 'gray')]) - plot.join([(tmax, ytick, 'gray')]) - plot.last_points = [] - else: - plot.join([(tmin, ytick, 'gray')]) - plot.join([(tmin + 0.05*(tmax - tmin), ytick, 'gray')]) - plot.last_points = [] - plot.join([(2.0*tmax, ytick, 'gray')]) - plot.join([(tmax - 0.05*(tmax - tmin), ytick, 'gray')]) - plot.last_points = [] - - ytick = ytick + dtick + def nohighlight(self, event=None): + self.config(fg='darkblue') - def finished(self,event=None): - self.new.destroy() + def show(self, event): + self.new=Toplevel() + self.new.title(self.sp.symbol) + #self.new.transient(self.master) + self.new.bind("", self.update,"+") + self.cpr = 0.0 + self.t = 0.0 + self.cpl = 0.0 + self.tl = 0.0 + self.cpp = [[(0.0, 0.0, 'red')]] + + # elemental composition + self.eframe = Frame(self.new) + self.eframe.config(relief=GROOVE,bd=4) + self.eframe.grid(row=0,column=0,columnspan=10,sticky=E+W) + r = 1 + Label(self.eframe,text='Atoms:')\ + .grid(row=0,column=0,sticky=N+W) + for el, c in self.sp.composition(): + Label(self.eframe,text=`int(c)`+' '+el).grid(row=0,column=r) + r = r + 1 + # thermodynamic properties + self.thermo = Frame(self.new) + self.thermo.config(relief=GROOVE,bd=4) + self.thermo.grid(row=1,column=0,columnspan=10,sticky=N+E+W) + Label(self.thermo,text = 'Standard Heat of Formation at 298 K: ').grid(row=0, column=0, sticky=W) + Label(self.thermo,text = '%8.2f kJ/mol' % (self.sp.hf0*1.0e-6)).grid(row=0, column=1, sticky=W) + Label(self.thermo,text = 'Molar Mass: ').grid(row=1, column=0, sticky=W) + Label(self.thermo,text = self.sp.molecularWeight).grid(row=1, column=1, sticky=W) + labels = ['Temperature', 'c_p', 'Enthalpy', 'Entropy'] + units = [temperature, specificEntropy, specificEnergy, specificEntropy] + whichone = [0, 1, 1, 1] + r = 2 + self.prop = [] + for prop in labels: + Label(self.thermo,text=prop).grid(row=r,column=0,sticky=W) + p = UnitVar(self.thermo,units[r-2],whichone[r-2]) + p.grid(row=r,column=1,sticky=W) + p.v.config(state=DISABLED,bg='lightgray') + self.prop.append(p) + r = r + 1 + + tmin = self.sp.minTemp + tmax = self.sp.maxTemp + cp = self.sp.cp_R(tmin) + hh = self.sp.enthalpy_RT(tmin) + ss = self.sp.entropy_R(tmin) + + self.prop[0].bind("", self.decouple) + self.prop[0].bind("", self.update) + self.prop[0].bind("", self.update) + self.prop[0].v.config(state=NORMAL,bg='white') + self.prop[0].set(300.0) + + self.graphs = Frame(self.new) + self.graphs.config(relief=GROOVE,bd=4) + self.graphs.grid(row=2,column=0,columnspan=10,sticky=E+W) + + self.cpdata = [] + self.hdata = [] + self.sdata = [] + t = tmin + n = int((tmax - tmin)/100.0) + while t <= tmax: + self.cpdata.append((t,self.sp.cp_R(t))) + self.hdata.append((t,self.sp.enthalpy_RT(t))) + self.sdata.append((t,self.sp.entropy_R(t))) + t = t + n + + # specific heat + + Label(self.graphs,text='c_p/R').grid(row=0,column=0,sticky=W+E) + ymin, ymax, dtick = self.plotLimits(self.cpdata) + self.cpg = Graph(self.graphs,'',tmin,tmax,ymin,ymax, + pixelX=150,pixelY=150) + self.cpg.canvas.config(bg='white') + self.cpg.grid(row=1,column=0,columnspan=2,sticky=W+E) + self.ticks(ymin, ymax, dtick, tmin, tmax, self.cpg) + + # enthalpy + Label(self.graphs,text='enthalpy/RT').grid(row=0,column=3,sticky=W+E) + ymin, ymax, dtick = self.plotLimits(self.hdata) + self.hg = Graph(self.graphs,'',tmin,tmax,ymin,ymax, + pixelX=150,pixelY=150) + self.hg.canvas.config(bg='white') + self.hg.grid(row=1,column=3,columnspan=2,sticky=W+E) + self.ticks(ymin, ymax, dtick, tmin, tmax, self.hg) + + # entropy + Label(self.graphs,text='entropy/R').grid(row=0,column=5,sticky=W+E) + ymin, ymax, dtick = self.plotLimits(self.sdata) + self.sg = Graph(self.graphs,'',tmin,tmax,ymin,ymax, + pixelX=150,pixelY=150) + self.sg.canvas.config(bg='white') + self.sg.grid(row=1,column=5,columnspan=2,sticky=W+E) + self.ticks(ymin, ymax, dtick, tmin, tmax, self.sg) + + n = int((tmax - tmin)/100.0) + t = tmin + self.cpp = [] + + for t, cp in self.cpdata: + self.cpg.join([(t,cp,'red')]) + for t, h in self.hdata: + self.hg.join([(t,h,'green')]) + for t, s in self.sdata: + self.sg.join([(t,s,'blue')]) + + self.cpdot = self.cpg.plot(tmin,cp,'red') + self.hdot = self.hg.plot(tmin,hh,'green') + self.sdot = self.sg.plot(tmin,ss,'blue') + + b=Button(self.new,text=' OK ',command=self.finished, default=ACTIVE) + #ed=Button(self.new,text='Edit',command=testit) + b.grid(column=0, row=4,sticky=W) + #ed.grid(column=1,row=4,sticky=W) + + self.scfr = Frame(self.new) + self.scfr.config(relief=GROOVE,bd=4) + self.scfr.grid(row=3,column=0,columnspan=10,sticky=N+E+W) + self.sc = Scale(self.scfr,command=self.update,variable = self.prop[0].x, + orient='horizontal',digits=7,length=400) + self.sc.config(cnf={'from':tmin,'to':tmax}) + self.sc.bind('',self.couple) + self.scfr.bind('',self.decouple) + self.sc.grid(row=0,column=0,columnspan=10) + + def decouple(self,event=None): + d = DoubleVar() + xx = self.prop[0].get() + d.set(xx) + self.sc.config(variable = d) + + def couple(self,event=None): + self.sc.config(variable = self.prop[0].x) + #self.update() + + def update(self,event=None): + try: + tmp = self.prop[0].get() + cnd = self.sp.cp_R(tmp) + cc = cnd*GasConstant + self.prop[1].set(cc) + hnd = self.sp.enthalpy_RT(tmp) + hh = hnd*tmp*GasConstant + self.prop[2].set(hh) + snd = self.sp.entropy_R(tmp) + ss = snd*tmp*GasConstant + self.prop[3].set(ss) + + + self.cppoint = tmp, cnd + self.hpoint = tmp, hnd + self.spoint = tmp, snd + if hasattr(self, 'cpdot'): + self.cpg.delete(self.cpdot) + self.cpdot = self.cpg.plot(self.cppoint[0], self.cppoint[1],'red') + self.hg.delete(self.hdot) + self.hdot = self.hg.plot(self.hpoint[0], self.hpoint[1],'green') + self.sg.delete(self.sdot) + self.sdot = self.sg.plot(self.spoint[0], self.spoint[1],'blue') + except: + pass + + def plotLimits(self, xy): + ymax = -1.e10 + ymin = 1.e10 + for x, y in xy: + if y > ymax: ymax = y + if y < ymin: ymin = y + + dy = abs(ymax - ymin) + if dy < 0.2*ymin: + ymin = ymin*.9 + ymax = ymax*1.1 + dy = abs(ymax - ymin) + else: + ymin = ymin - 0.1*dy + ymax = ymax + 0.1*dy + dy = abs(ymax - ymin) + + p10 = math.floor(math.log10(0.1*dy)) + fctr = math.pow(10.0, p10) + mm = [2.0, 2.5, 2.0] + i = 0 + while dy/fctr > 5: + fctr = mm[i % 3]*fctr + i = i + 1 + ymin = fctr*math.floor(ymin/fctr) + ymax = fctr*(math.floor(ymax/fctr + 1)) + return (ymin, ymax, fctr) + + def ticks(self, ymin, ymax, dtick, tmin, tmax, plot): + ytick = ymin + eps = 1.e-3 + while ytick <= ymax: + if abs(ytick) < eps: + plot.join([(tmin, ytick, 'gray')]) + plot.join([(tmax, ytick, 'gray')]) + plot.last_points = [] + else: + plot.join([(tmin, ytick, 'gray')]) + plot.join([(tmin + 0.05*(tmax - tmin), ytick, 'gray')]) + plot.last_points = [] + plot.join([(2.0*tmax, ytick, 'gray')]) + plot.join([(tmax - 0.05*(tmax - tmin), ytick, 'gray')]) + plot.last_points = [] + + ytick = ytick + dtick + + def finished(self,event=None): + self.new.destroy() diff --git a/interfaces/python/MixMaster/ThermoFrame.py b/interfaces/python/MixMaster/ThermoFrame.py index 661f5cb2f..fbc42606b 100644 --- a/interfaces/python/MixMaster/ThermoFrame.py +++ b/interfaces/python/MixMaster/ThermoFrame.py @@ -16,131 +16,128 @@ _ENTHALPY = 4 _ENTROPY = 5 class ThermoFrame(Frame): - def __init__(self,master,top): - Frame.__init__(self,master) - self.config(relief=GROOVE, bd=4) - self.top = top - self.mix = self.top.mix - self.warn = 0 - self.internal = Frame(self) - self.internal.pack(side=LEFT,anchor=N+W,padx=2,pady=2) - self.controls=Frame(self.internal) - self.controls.pack(side=LEFT,anchor=N+W,padx=4,pady=5) - - self.entries=Frame(self.internal) - self.entries.pack(side=LEFT,anchor=N,padx=4,pady=2) - self.makeEntries() - self.makeControls() - self.showState() - - def makeControls(self): - Button(self.controls,text='Set State', width=15, - command=self.setState).grid(column=0,row=0) - self.equil = IntVar() - self.equil.set(0) - Button(self.controls,text='Equilibrate', width=15, - command=self.eqset).grid(column=0,row=1) -## Radiobutton(self.controls,text='Frozen',variable = self.equil, + def __init__(self,master,top): + Frame.__init__(self,master) + self.config(relief=GROOVE, bd=4) + self.top = top + self.mix = self.top.mix + self.warn = 0 + self.internal = Frame(self) + self.internal.pack(side=LEFT,anchor=N+W,padx=2,pady=2) + self.controls=Frame(self.internal) + self.controls.pack(side=LEFT,anchor=N+W,padx=4,pady=5) + + self.entries=Frame(self.internal) + self.entries.pack(side=LEFT,anchor=N,padx=4,pady=2) + self.makeEntries() + self.makeControls() + self.showState() + + def makeControls(self): + Button(self.controls,text='Set State', width=15, + command=self.setState).grid(column=0,row=0) + self.equil = IntVar() + self.equil.set(0) + Button(self.controls,text='Equilibrate', width=15, + command=self.eqset).grid(column=0,row=1) +## Radiobutton(self.controls,text='Frozen',variable = self.equil, ## command=self.freeze,value=0).grid(column=0,row=2,sticky='W') -## Radiobutton(self.controls,text='Equilibrium', -## variable=self.equil, +## Radiobutton(self.controls,text='Equilibrium', +## variable=self.equil, ## command=self.eqset,value=1).grid(column=0,row=3,sticky='W') - def eqset(self): - self.equil.set(1) - self.setState() - self.equil.set(0) - #if self.top.mixframe: - # self.top.mixframe.redo() - - def freeze(self): - self.equil.set(0) - if self.top.mixframe: - self.top.mixframe.redo() - - def makeEntries(self): - self.entries.pack() - self.variable = {} - self.prop = [] - props = ['Temperature', 'Pressure', 'Density', - 'Internal Energy', 'Enthalpy', 'Entropy'] - units = [temperature, pressure, density, specificEnergy, - specificEnergy, specificEntropy] - defaultunit = [0, 2, 0, 1, 1, 1] - for i in range(len(props)): - self.prop.append(ThermoProp(self.entries, self, i, props[i], - 0.0, units[i], defaultunit[i])) - #self.prop[-1].entry.bind("",self.setState) - self.last2 = self.prop[3] - self.last1 = self.prop[2] - self.prop[0].checked.set(1) - self.prop[0].check() - self.prop[1].checked.set(1) - self.prop[1].check() - self.showState() + def eqset(self): + self.equil.set(1) + self.setState() + self.equil.set(0) + #if self.top.mixframe: + # self.top.mixframe.redo() - def checkTPBoxes(self): - if not self.prop[0].isChecked(): - self.prop[0].checked.set(1) - self.prop[0].check() - if not self.prop[1].isChecked(): - self.prop[1].checked.set(1) - self.prop[1].check() - - def showState(self): - self.prop[_TEMPERATURE].set(self.mix.g.temperature()) - self.prop[_PRESSURE].set(self.mix.g.pressure()) - self.prop[_DENSITY].set(self.mix.g.density()) - self.prop[_INTENERGY].set(self.mix.g.intEnergy_mass()) - self.prop[_ENTHALPY].set(self.mix.g.enthalpy_mass()) - self.prop[_ENTROPY].set(self.mix.g.entropy_mass()) + def freeze(self): + self.equil.set(0) + if self.top.mixframe: + self.top.mixframe.redo() - def setState(self,event=None): - if event: - self.warn = 0 - else: - self.warn = 1 - self.top.mixfr.update() - i = self.equil.get() - optlist = ['frozen','equilibrium'] - opt = [optlist[i]] - - if self.prop[_PRESSURE].isChecked() \ - and self.prop[_TEMPERATURE].isChecked(): - self.mix.set( - temperature = self.prop[_TEMPERATURE].get(), - pressure = self.prop[_PRESSURE].get(), - equil=i) + def makeEntries(self): + self.entries.pack() + self.variable = {} + self.prop = [] + props = ['Temperature', 'Pressure', 'Density', + 'Internal Energy', 'Enthalpy', 'Entropy'] + units = [temperature, pressure, density, specificEnergy, + specificEnergy, specificEntropy] + defaultunit = [0, 2, 0, 1, 1, 1] + for i in range(len(props)): + self.prop.append(ThermoProp(self.entries, self, i, props[i], + 0.0, units[i], defaultunit[i])) + #self.prop[-1].entry.bind("",self.setState) + self.last2 = self.prop[3] + self.last1 = self.prop[2] + self.prop[0].checked.set(1) + self.prop[0].check() + self.prop[1].checked.set(1) + self.prop[1].check() + self.showState() - elif self.prop[_DENSITY].isChecked() \ - and self.prop[_TEMPERATURE].isChecked(): - self.mix.set( - temperature = self.prop[_TEMPERATURE].get(), - density = self.prop[_DENSITY].get(), - equil=i) - - elif self.prop[_ENTROPY].isChecked() \ - and self.prop[_PRESSURE].isChecked(): - self.mix.set(pressure = self.prop[_PRESSURE].get(), - entropy = self.prop[_ENTROPY].get(), - equil=i) - - elif self.prop[_ENTHALPY].isChecked() \ - and self.prop[_PRESSURE].isChecked(): - self.mix.set(pressure = self.prop[_PRESSURE].get(), - enthalpy = self.prop[_ENTHALPY].get(), - equil=i) - - elif self.prop[_INTENERGY].isChecked() \ - and self.prop[_DENSITY].isChecked(): - self.mix.set(density = self.prop[_DENSITY].get(), - intEnergy = self.prop[_INTENERGY].get(), - equil=i) - else: - if self.warn > 0: - handleError("unsupported property pair") + def checkTPBoxes(self): + if not self.prop[0].isChecked(): + self.prop[0].checked.set(1) + self.prop[0].check() + if not self.prop[1].isChecked(): + self.prop[1].checked.set(1) + self.prop[1].check() - self.top.update() + def showState(self): + self.prop[_TEMPERATURE].set(self.mix.g.temperature()) + self.prop[_PRESSURE].set(self.mix.g.pressure()) + self.prop[_DENSITY].set(self.mix.g.density()) + self.prop[_INTENERGY].set(self.mix.g.intEnergy_mass()) + self.prop[_ENTHALPY].set(self.mix.g.enthalpy_mass()) + self.prop[_ENTROPY].set(self.mix.g.entropy_mass()) - + def setState(self,event=None): + if event: + self.warn = 0 + else: + self.warn = 1 + self.top.mixfr.update() + i = self.equil.get() + optlist = ['frozen','equilibrium'] + opt = [optlist[i]] + if self.prop[_PRESSURE].isChecked() \ + and self.prop[_TEMPERATURE].isChecked(): + self.mix.set( + temperature = self.prop[_TEMPERATURE].get(), + pressure = self.prop[_PRESSURE].get(), + equil=i) + + elif self.prop[_DENSITY].isChecked() \ + and self.prop[_TEMPERATURE].isChecked(): + self.mix.set( + temperature = self.prop[_TEMPERATURE].get(), + density = self.prop[_DENSITY].get(), + equil=i) + + elif self.prop[_ENTROPY].isChecked() \ + and self.prop[_PRESSURE].isChecked(): + self.mix.set(pressure = self.prop[_PRESSURE].get(), + entropy = self.prop[_ENTROPY].get(), + equil=i) + + elif self.prop[_ENTHALPY].isChecked() \ + and self.prop[_PRESSURE].isChecked(): + self.mix.set(pressure = self.prop[_PRESSURE].get(), + enthalpy = self.prop[_ENTHALPY].get(), + equil=i) + + elif self.prop[_INTENERGY].isChecked() \ + and self.prop[_DENSITY].isChecked(): + self.mix.set(density = self.prop[_DENSITY].get(), + intEnergy = self.prop[_INTENERGY].get(), + equil=i) + else: + if self.warn > 0: + handleError("unsupported property pair") + + self.top.update() diff --git a/interfaces/python/MixMaster/ThermoProp.py b/interfaces/python/MixMaster/ThermoProp.py index fd9f6b03f..bd37ffd5f 100644 --- a/interfaces/python/MixMaster/ThermoProp.py +++ b/interfaces/python/MixMaster/ThermoProp.py @@ -5,64 +5,62 @@ _tv = ['Temperature','Internal Energy','Enthalpy'] _pv = ['Pressure', 'Density'] def badpair(a,b): - if a.name in _tv: - if not b.name in _pv: - return 1 - else: - if not b.name in _tv: - return 1 - + if a.name in _tv: + if not b.name in _pv: + return 1 + else: + if not b.name in _tv: + return 1 + class ThermoProp: - def __init__(self, master, thermoframe, row, name, value, units, defaultunit=0): - self.value = DoubleVar() - self.thermoframe = thermoframe - self.entry = UnitVar(master,units,defaultunit) - self.entry.grid(column=1,row=row,sticky=W) - self.entry.v.config(state=DISABLED,bg='lightgray') - self.checked=IntVar() - self.checked.set(0) - self.name = name - self.c=Checkbutton(master, - text=name, - variable=self.checked, - onvalue=1, - offvalue=0, - command=self.check - ) - self.c.grid(column=0,row=row, sticky=W+N) + def __init__(self, master, thermoframe, row, name, value, units, defaultunit=0): + self.value = DoubleVar() + self.thermoframe = thermoframe + self.entry = UnitVar(master,units,defaultunit) + self.entry.grid(column=1,row=row,sticky=W) + self.entry.v.config(state=DISABLED,bg='lightgray') + self.checked=IntVar() + self.checked.set(0) + self.name = name + self.c=Checkbutton(master, + text=name, + variable=self.checked, + onvalue=1, + offvalue=0, + command=self.check + ) + self.c.grid(column=0,row=row, sticky=W+N) - def check(self): - if self == self.thermoframe.last1: - self.checked.set(1) - return - elif self == self.thermoframe.last2: - self.checked.set(1) - self.thermoframe.last2 = self.thermoframe.last1 - self.thermoframe.last1 = self - return -# elif badpair(self, self.thermoframe.last1): -# self.checked.set(0) -# return - - self._check() - self.thermoframe.last2.checked.set(0) - self.thermoframe.last2._check() - self.thermoframe.last2 = self.thermoframe.last1 - self.thermoframe.last1 = self - - def _check(self): - if self.isChecked(): - self.entry.v.config(state=NORMAL,bg='white') - else: - self.entry.v.config(state=DISABLED,bg='lightgray') + def check(self): + if self == self.thermoframe.last1: + self.checked.set(1) + return + elif self == self.thermoframe.last2: + self.checked.set(1) + self.thermoframe.last2 = self.thermoframe.last1 + self.thermoframe.last1 = self + return +# elif badpair(self, self.thermoframe.last1): +# self.checked.set(0) +# return - def isChecked(self): - return self.checked.get() + self._check() + self.thermoframe.last2.checked.set(0) + self.thermoframe.last2._check() + self.thermoframe.last2 = self.thermoframe.last1 + self.thermoframe.last1 = self - def set(self, value): - self.entry.set(value) - - def get(self): - return self.entry.get() - + def _check(self): + if self.isChecked(): + self.entry.v.config(state=NORMAL,bg='white') + else: + self.entry.v.config(state=DISABLED,bg='lightgray') + def isChecked(self): + return self.checked.get() + + def set(self, value): + self.entry.set(value) + + def get(self): + return self.entry.get() diff --git a/interfaces/python/MixMaster/TransportFrame.py b/interfaces/python/MixMaster/TransportFrame.py index e3ecdb0b8..29473754a 100644 --- a/interfaces/python/MixMaster/TransportFrame.py +++ b/interfaces/python/MixMaster/TransportFrame.py @@ -1,35 +1,34 @@ from Tkinter import * class TransportFrame(Frame): - def show(self, i, frame, row, col): - if self.checked[i].get(): - frame.grid(row=row,column=col,sticky=N+E+S+W) - else: - frame.grid_forget() - - def showcomp(self): - self.show(0, self.top.mixfr, 8, 0) + def show(self, i, frame, row, col): + if self.checked[i].get(): + frame.grid(row=row,column=col,sticky=N+E+S+W) + else: + frame.grid_forget() - def showthermo(self): - self.show(1, self.top.thermo, 7, 0) - - def __init__(self,master,top): - self.top = top - self.c = [] - self.checked = [] - Frame.__init__(self,master) - self.config(relief=GROOVE, bd=4) - lbl = ['multicomponent', 'mixture-averaged'] - cmds = [self.showcomp, self.showthermo] - for i in range(2): - self.checked.append(IntVar()) - self.checked[i].set(0) - self.c.append(Checkbutton(self, - text=lbl[i], - variable=self.checked[i], - onvalue=1, - offvalue=0, - command=cmds[i] - )) - self.c[i].grid(column=i,row=0, sticky=W+N) + def showcomp(self): + self.show(0, self.top.mixfr, 8, 0) + def showthermo(self): + self.show(1, self.top.thermo, 7, 0) + + def __init__(self,master,top): + self.top = top + self.c = [] + self.checked = [] + Frame.__init__(self,master) + self.config(relief=GROOVE, bd=4) + lbl = ['multicomponent', 'mixture-averaged'] + cmds = [self.showcomp, self.showthermo] + for i in range(2): + self.checked.append(IntVar()) + self.checked[i].set(0) + self.c.append(Checkbutton(self, + text=lbl[i], + variable=self.checked[i], + onvalue=1, + offvalue=0, + command=cmds[i] + )) + self.c[i].grid(column=i,row=0, sticky=W+N) diff --git a/interfaces/python/MixMaster/UnitChooser.py b/interfaces/python/MixMaster/UnitChooser.py index 290787393..17bcb97eb 100644 --- a/interfaces/python/MixMaster/UnitChooser.py +++ b/interfaces/python/MixMaster/UnitChooser.py @@ -2,83 +2,81 @@ from Tkinter import * import re class UnitVar(Frame): - def __init__(self,master,unitmod,defaultunit=0): - Frame.__init__(self,master) - self.x = DoubleVar() - self.xsi = 0.0 - self.x.set(0.0) - self.unitmod = unitmod - try: - self.unitlist = self.unitmod.units - except: - self.unitlist = [] - unitlist=dir(self.unitmod) - for it in unitlist: - if it[0] != '_': - self.unitlist.append(it) - self.v = Entry(self,textvariable=self.x) - self.s = StringVar() - tmp = re.sub('__',' / ',self.unitlist[defaultunit]) - self.s.set(tmp) - self.conv = eval('self.unitmod.'+re.sub(' / ','__',self.s.get())).value - self.u = Label(self) - self.u.config(textvariable=self.s,fg='darkblue') - self.u.bind('', self.select) - self.u.bind('',self.highlight) - self.u.bind('',self.nohighlight) - self.v.grid(row=0,column=0) - self.u.grid(row=0,column=1) + def __init__(self,master,unitmod,defaultunit=0): + Frame.__init__(self,master) + self.x = DoubleVar() + self.xsi = 0.0 + self.x.set(0.0) + self.unitmod = unitmod + try: + self.unitlist = self.unitmod.units + except: + self.unitlist = [] + unitlist=dir(self.unitmod) + for it in unitlist: + if it[0] != '_': + self.unitlist.append(it) + self.v = Entry(self,textvariable=self.x) + self.s = StringVar() + tmp = re.sub('__',' / ',self.unitlist[defaultunit]) + self.s.set(tmp) + self.conv = eval('self.unitmod.'+re.sub(' / ','__',self.s.get())).value + self.u = Label(self) + self.u.config(textvariable=self.s,fg='darkblue') + self.u.bind('', self.select) + self.u.bind('',self.highlight) + self.u.bind('',self.nohighlight) + self.v.grid(row=0,column=0) + self.u.grid(row=0,column=1) - def highlight(self, event=None): - self.u.config(fg='yellow') - - def nohighlight(self, event=None): - self.u.config(fg='darkblue') - - def select(self, event): - self.new=Toplevel() - self.new.title("Units") - self.new.transient(self.master) - self.new.bind("", self.finished,"+") - - r=0 - c=0 - for each in self.unitlist: - if each[0] != '_' and each[:1] != '__' and each != 'SI': - each = re.sub('__',' / ',each) - Radiobutton(self.new, - text=each, - variable=self.u['textvariable'], - value=each, - command=self.update, - ).grid(column=c, row=r, sticky=W) - r=r+1 - if (r>10): - r=0 - c=c+1 - r=r+1 - - b=Button(self.new,text='OK',command=self.finished, default=ACTIVE) - b.grid(column=c, row=r) - - self.new.grab_set() - self.new.focus_set() - self.new.wait_window() + def highlight(self, event=None): + self.u.config(fg='yellow') - def finished(self,event=None): - self.new.destroy() - - def update(self): - self.xsi = self.x.get() * self.conv - self.conv = eval('self.unitmod.'+re.sub(' / ','__',self.s.get())).value - self.x.set(self.xsi/self.conv) + def nohighlight(self, event=None): + self.u.config(fg='darkblue') - def get(self): - self.xsi = self.x.get() * self.conv - return self.xsi + def select(self, event): + self.new=Toplevel() + self.new.title("Units") + self.new.transient(self.master) + self.new.bind("", self.finished,"+") - def set(self,value): - self.xsi = value - self.x.set(value/self.conv) + r=0 + c=0 + for each in self.unitlist: + if each[0] != '_' and each[:1] != '__' and each != 'SI': + each = re.sub('__',' / ',each) + Radiobutton(self.new, + text=each, + variable=self.u['textvariable'], + value=each, + command=self.update, + ).grid(column=c, row=r, sticky=W) + r=r+1 + if (r>10): + r=0 + c=c+1 + r=r+1 + b=Button(self.new,text='OK',command=self.finished, default=ACTIVE) + b.grid(column=c, row=r) + self.new.grab_set() + self.new.focus_set() + self.new.wait_window() + + def finished(self,event=None): + self.new.destroy() + + def update(self): + self.xsi = self.x.get() * self.conv + self.conv = eval('self.unitmod.'+re.sub(' / ','__',self.s.get())).value + self.x.set(self.xsi/self.conv) + + def get(self): + self.xsi = self.x.get() * self.conv + return self.xsi + + def set(self,value): + self.xsi = value + self.x.set(value/self.conv) diff --git a/interfaces/python/MixMaster/Units/SI.py b/interfaces/python/MixMaster/Units/SI.py index 8f6dcd18d..6c6b9e287 100755 --- a/interfaces/python/MixMaster/Units/SI.py +++ b/interfaces/python/MixMaster/Units/SI.py @@ -39,33 +39,33 @@ candela = unit(1.0, (0, 0, 0, 0, 0, 0, 1)) # # The 21 derived SI units with special names # -radian = dimensionless # plane angle -steradian = dimensionless # solid angle - -hertz = 1/second # frequency - -newton = meter*kilogram/second**2 # force -pascal = newton/meter**2 # pressure -joule = newton*meter # work, heat -watt = joule/second # power, radiant flux - -coulomb = ampere*second # electric charge -volt = watt/ampere # electric potential difference -farad = coulomb/volt # capacitance -ohm = volt/ampere # electric resistance -siemens = ampere/volt # electric conductance -weber = volt*second # magnetic flux -tesla = weber/meter**2 # magnetic flux density -henry = weber/ampere # inductance - -celsius = kelvin # Celsius temperature - -lumen = candela*steradian # luminous flux -lux = lumen/meter**2 # illuminance - -becquerel = 1/second # radioactivity -gray = joule/kilogram # absorbed dose -sievert = joule/kilogram # dose equivalent +radian = dimensionless # plane angle +steradian = dimensionless # solid angle + +hertz = 1/second # frequency + +newton = meter*kilogram/second**2 # force +pascal = newton/meter**2 # pressure +joule = newton*meter # work, heat +watt = joule/second # power, radiant flux + +coulomb = ampere*second # electric charge +volt = watt/ampere # electric potential difference +farad = coulomb/volt # capacitance +ohm = volt/ampere # electric resistance +siemens = ampere/volt # electric conductance +weber = volt*second # magnetic flux +tesla = weber/meter**2 # magnetic flux density +henry = weber/ampere # inductance + +celsius = kelvin # Celsius temperature + +lumen = candela*steradian # luminous flux +lux = lumen/meter**2 # illuminance + +becquerel = 1/second # radioactivity +gray = joule/kilogram # absorbed dose +sievert = joule/kilogram # dose equivalent # # The prefixes @@ -112,12 +112,12 @@ if __name__ == "__main__": print " radian: %s" % radian print " steradian: %s" % steradian print " hertz: %s" % hertz - + print " newton: %s" % newton print " pascal: %s" % pascal print " joule: %s" % joule print " watt: %s" % watt - + print " coulomb: %s" % coulomb print " volt: %s" % volt print " farad: %s" % farad @@ -126,12 +126,12 @@ if __name__ == "__main__": print " weber: %s" % weber print " tesla: %s" % tesla print " henry: %s" % henry - + print " degree Celcius: %s" % celcius - + print " lumen: %s" % lumen print " lux: %s" % lux - + print " becquerel: %s" % becquerel print " gray: %s" % gray print " sievert: %s" % sievert diff --git a/interfaces/python/MixMaster/Units/unit.py b/interfaces/python/MixMaster/Units/unit.py index df8c5c53e..2652af0eb 100755 --- a/interfaces/python/MixMaster/Units/unit.py +++ b/interfaces/python/MixMaster/Units/unit.py @@ -29,7 +29,7 @@ class unit: _zero = (0,) * 7 _negativeOne = (-1, ) * 7 - + _labels = ('m', 'kg', 's', 'A', 'K', 'mol', 'cd') @@ -56,7 +56,7 @@ class unit: def __mul__(self, other): if type(other) == type(0) or type(other) == type(0.0): return unit(other*self.value, self.derivation) - + value = self.value * other.value derivation = tuple(map(operator.add, self.derivation, other.derivation)) @@ -66,7 +66,7 @@ class unit: def __div__(self, other): if type(other) == type(0) or type(other) == type(0.0): return unit(self.value/other, self.derivation) - + value = self.value / other.value derivation = tuple(map(operator.sub, self.derivation, other.derivation)) @@ -81,7 +81,7 @@ class unit: derivation = tuple(map(operator.mul, [other]*7, self.derivation)) return unit(value, derivation) - + def __pos__(self): return self @@ -107,7 +107,7 @@ class unit: value = other/self.value derivation = tuple(map(operator.mul, self._negativeOne, self.derivation)) - + return unit(value, derivation) @@ -115,7 +115,7 @@ class unit: return self.value #if self.derivation == self._zero: return self.value #raise BadConversion(self) - + def __str__(self): str = "%g" % self.value @@ -130,6 +130,6 @@ class unit: return str dimensionless = unit(1, unit._zero) - + # # End of file diff --git a/interfaces/python/MixMaster/__init__.py b/interfaces/python/MixMaster/__init__.py index 28171ea12..58c70d95b 100644 --- a/interfaces/python/MixMaster/__init__.py +++ b/interfaces/python/MixMaster/__init__.py @@ -1,5 +1,4 @@ - + # from Cantera import * from main import MixMaster - diff --git a/interfaces/python/MixMaster/config.py b/interfaces/python/MixMaster/config.py index 9389b9eb9..c004001d5 100644 --- a/interfaces/python/MixMaster/config.py +++ b/interfaces/python/MixMaster/config.py @@ -3,5 +3,3 @@ from Cantera import * # thermo parametrizations #from Cantera.Species.Thermo.NasaPolynomial import NasaPolynomial - - diff --git a/interfaces/python/MixMaster/flowpanel.py b/interfaces/python/MixMaster/flowpanel.py index 04b8dfa08..4efdfcf92 100644 --- a/interfaces/python/MixMaster/flowpanel.py +++ b/interfaces/python/MixMaster/flowpanel.py @@ -12,12 +12,12 @@ class App: self.root = master.root except: self.root = master - + self.frame = Frame(master) self.frame.grid(row = 0, column = 0) self.makemenu(self.frame) - + self.quitbutton = Button(self.frame, text = "Quit", command = self.frame.quit) self.quitbutton.grid(row = 1, column = 0) @@ -32,11 +32,11 @@ class App: def newflow(self): n = newflow.NewFlowDialog(self.root) - + def makemenu(self,frame): self.menubar = Frame(frame, relief=FLAT, bd=0) self.menubar.grid(row = 0, column = 0) - + self.filemenu = menu.make_menu('File', self.menubar, [('New...', self.newflow), ('Open...', self.notyet), @@ -53,4 +53,3 @@ root = Tk() app = App(root) root.mainloop() - diff --git a/interfaces/python/MixMaster/gri30.py b/interfaces/python/MixMaster/gri30.py index 3ea536024..713e6672e 100644 --- a/interfaces/python/MixMaster/gri30.py +++ b/interfaces/python/MixMaster/gri30.py @@ -6,7 +6,7 @@ elements = { 'N':build.element(7, 'N', 'Nitrogen', 14.0067), 'Ar':build.element(18, 'Ar', 'Argon', 39.948) } -species = { +species = { 'H2':Species( name = 'H2', id = 'TPIS78', elements = {'H': 2}, @@ -432,7 +432,7 @@ species = { lowCoefficients = [4.7294595, -0.0031932858, 4.7534921e-005, -5.7458611e-008, 2.1931112e-011, -21572.878, 4.1030159]) ) } -reactions = [ +reactions = [ build.reaction([(-2, 'O'), (1, 'O2')],[1002, 0, 1, 'M', 0], {'H2': 1.4, 'AR': -0.17, 'C2H6': 2.0, 'CO': 0.75, 'CH4': 1.0, 'CO2': 2.6, 'H2O': 14.4}, build.rateCoeff('3',build.arrhenius(120000000000.0, -1.0, 0.0) ),species), diff --git a/interfaces/python/MixMaster/main.py b/interfaces/python/MixMaster/main.py index 9cd99d413..434cd8ee2 100644 --- a/interfaces/python/MixMaster/main.py +++ b/interfaces/python/MixMaster/main.py @@ -39,7 +39,7 @@ def testit(): class MixMaster: - + def stop(self): sys.exit(0) @@ -53,7 +53,7 @@ class MixMaster: def loadmech(self, mechname, pathname, mw=1): - + p = os.path.normpath(os.path.dirname(pathname)) self.fname = os.path.basename(pathname) ff = os.path.splitext(self.fname) @@ -61,7 +61,7 @@ class MixMaster: try: self.mech = IdealGasMix(pathname) self.mechname = ff[0] - + except: utilities.handleError('could not create gas mixture object: ' +ff[0]+'\n') @@ -72,7 +72,7 @@ class MixMaster: if not mechname: mechname = self.mechname - + self.mechframe.addMechanism(mechname, self.mech) if mw==1: self.makeWindows() @@ -111,7 +111,7 @@ class MixMaster: self.mixfr.show() - + def makeMix(self): self.mix = Mix(self.mech) nsp = self.mech.nSpecies() @@ -142,14 +142,14 @@ class MixMaster: self._windows = {} self._vis = {} self.windows = [] - + self.cwin = ControlWindow(_app_title,self.master) self.cwin.master.resizable(FALSE,FALSE) - + self.menubar = Frame(self.cwin, relief=GROOVE,bd=2) self.menubar.grid(row=0,column=0,sticky=N+W+E) - - self.mixfr = None + + self.mixfr = None self.thermo = None self.transport = None self.kinetics = None @@ -157,7 +157,7 @@ class MixMaster: self.rxnpaths = None self.edit = None self.fname = None - + self.mechframe = MechManager(self.cwin, self) self.mechframe.grid(row=1,column=0,sticky=N+W) @@ -171,7 +171,7 @@ class MixMaster: ] self.filemenu = make_menu('File', self.menubar, fileitems) - + self.vtherm = IntVar() self.vcomp = IntVar() self.vtran = IntVar() @@ -190,9 +190,9 @@ class MixMaster: #toolitems = [(' Convert...', self.importfile), # []] - #self.toolmenu = make_menu('Tools', self.menubar, toolitems) + #self.toolmenu = make_menu('Tools', self.menubar, toolitems) + - w = [(' Thermodynamic State', self.showthermo, 'check', self.vtherm), (' Composition', self.showcomp, 'check', self.vcomp), 'separator', @@ -200,31 +200,31 @@ class MixMaster: (' Reactions...', self.showrxns), (' Reaction Paths...', self.showrpaths), []] - + self.viewmenu = make_menu('Windows', self.menubar, w) - + self.helpmenu = make_menu('Help', self.menubar, [('About '+_app_title+'...', self.aboutmix), ('About Cantera...', testit), [] - + ]) # load the preloaded mechanisms for m in _autoload: self.loadmech(m[0],m[1],0) - - self.makeWindows() + + self.makeWindows() self.addWindow('import',ImportFrame(self)) self.vtherm.set(1) self.showthermo() ## self.vcomp.set(1) ## self.showcomp() - - self.master.iconify() - self.master.update() - self.master.deiconify() + + self.master.iconify() + self.master.update() + self.master.deiconify() self.cwin.mainloop() @@ -237,13 +237,13 @@ class MixMaster: def makeWindows(self): # if self.mixfr: for w in self.windows: - try: - w.destroy() - except: - pass + try: + w.destroy() + except: + pass fr = [MixtureFrame, ThermoFrame, TransportFrame] - + self.mixfr = MixtureFrame(self.cwin, self) self.thermo = ThermoFrame(self.cwin, self) @@ -254,13 +254,13 @@ class MixMaster: self.addWindow('rxnpaths',ReactionPathFrame(self)) self.addWindow('dataset',DataFrame(None, self)) - + #self.edit = EditFrame(t, self) self.windows = [self.mixfr, self.thermo, self.transport, self.kinetics] - + self.showthermo() self.showcomp() #self.showtransport() @@ -268,19 +268,19 @@ class MixMaster: #self.showrxns() #self.showrpaths() #self.showdata() - + if self.mech: self.mechframe.grid(row=1,column=0) else: self.mechframe.grid_forget() #self.showedit() - + def show(self, frame, vis, row, col): if vis: frame.grid(row=row,column=col,sticky=N+E+S+W) else: frame.grid_forget() - + def showthermo(self): if self.thermo: self.show(self.thermo, self.vtherm.get(), 7, 0) @@ -291,25 +291,25 @@ class MixMaster: def showkinetics(self): if self.kinetics: - self.show(self.kinetics, self.vkin.get(), 10, 0) + self.show(self.kinetics, self.vkin.get(), 10, 0) def showrxns(self): - self._windows['rxndata'].show() + self._windows['rxndata'].show() def showrpaths(self): self._windows['rxnpaths'].show() def showdata(self): self._windows['dataset'].browseForDatafile() - + def aboutmix(self): - + m = tkMessageBox.showinfo(title = 'About MixMaster', message = """ MixMaster - + version """+_app_version+""" - + written by: Prof. David G. Goodwin @@ -322,10 +322,4 @@ California Institute of Technology if __name__ == "__main__": - MixMaster() - - - - - - + MixMaster() diff --git a/interfaces/python/MixMaster/menu.py b/interfaces/python/MixMaster/menu.py index 2ebeab463..569c9e881 100644 --- a/interfaces/python/MixMaster/menu.py +++ b/interfaces/python/MixMaster/menu.py @@ -2,7 +2,7 @@ from Tkinter import * def make_menu(name, menubar, list): from types import * - button=Menubutton(menubar, text=name, padx=3,pady=1) + button=Menubutton(menubar, text=name, padx=3,pady=1) button.pack(side=LEFT, anchor=W) menu = Menu(button,tearoff=FALSE) for entry in list: diff --git a/interfaces/python/MixMaster/newflow.py b/interfaces/python/MixMaster/newflow.py index c9583e98a..2da711a20 100644 --- a/interfaces/python/MixMaster/newflow.py +++ b/interfaces/python/MixMaster/newflow.py @@ -20,14 +20,14 @@ class NewFlowDialog: lb = Listbox(geom) for item in ["One-Dimensional", "Stagnation"]: lb.insert(END, item) - lb.grid(row = 0, column = 0) + lb.grid(row = 0, column = 0) glb = Listbox(geom) for item in ["Axisymmetric","2D"]: glb.insert(END, item) glb.grid(row = 1, column = 0) - + # ------------- pressure input ---------------- - + self.p = DoubleVar() self.pbox = Entry(top, textvariable = self.p) self.pbox.grid(row = 0, column = 1) @@ -42,46 +42,46 @@ class NewFlowDialog: gl = Label(gasf, text='Gas Mixture Specification') gl.grid(row = 0, column = 0) - + self.infile = StringVar() Label(gasf, text='Mixture Input File').grid(row = 1, column = 0) Entry(gasf, textvariable = self.infile).grid(row = 1, column = 1) Button(gasf, text='Browse..', command=self.getinfile).grid(row = 1, column = 2) - self.spfile = StringVar() + self.spfile = StringVar() Label(gasf, text='Species Database').grid(row = 2, column = 0) Entry(gasf, textvariable = self.spfile).grid(row = 2, column = 1) Button(gasf, text='Browse..', command=self.getspfile).grid(row = 2, column = 2) - - - self.trfile = StringVar() + + + self.trfile = StringVar() Label(gasf, text='Transport Database').grid(row = 3, column = 0) Entry(gasf, textvariable = self.trfile).grid(row = 3, column = 1) Button(gasf, text='Browse..', command=self.gettrfile).grid(row = 3, column = 2) - + # ------------- grid ------------------------- gf = Frame(top, bd=2, relief=GROOVE) gf.grid(row = 5, column = 0, columnspan=2) - + gr = Label(gf, text='Initial Grid') gr.grid(row = 0, column = 0) self.zleft = DoubleVar() - self.zright = DoubleVar() + self.zright = DoubleVar() ll = Label(gf, text='Left boundary at ') rl = Label(gf, text='Right boundary at ') lbb = Entry(gf, textvariable = self.zleft) - rbb = Entry(gf, textvariable = self.zright) + rbb = Entry(gf, textvariable = self.zright) ll.grid(row = 1, column = 0) rl.grid(row = 2, column = 0) lbb.grid(row = 1, column = 1) - rbb.grid(row = 2, column = 1) - + rbb.grid(row = 2, column = 1) + ok = Button(top, text = 'OK', command=self.ok) ok.grid(row = 20, column = 20) @@ -101,12 +101,12 @@ class NewFlowDialog: self.gas = IdealGasMix(import_file = infile, thermo_db = spfile) else: - self.gas = IdealGasMix(import_file = infile) - + self.gas = IdealGasMix(import_file = infile) + except: tkMessageBox.showerror('Create Gas', 'Error reading file %s. See log file for more information.' % infile) - + #self.flow = Flow1D(flow_type = ftype, flow_geom = fgeom, # pressure = p, grid = gr, gas = g) self.top.destroy() @@ -127,9 +127,4 @@ class NewFlowDialog: pathname = askopenfilename(filetypes=[ ("Transport Data Files", "*.xml *.dat"), ("All Files", "*.*")]) - self.trfile.set(pathname) - - - - - + self.trfile.set(pathname) diff --git a/interfaces/python/MixMaster/utilities.py b/interfaces/python/MixMaster/utilities.py index 37458f605..f498520c1 100644 --- a/interfaces/python/MixMaster/utilities.py +++ b/interfaces/python/MixMaster/utilities.py @@ -37,8 +37,3 @@ def handleError(message = '', window = None, else: m = tkMessageBox.showerror(title = 'Error', message = message, parent = window) - - - - - diff --git a/interfaces/python/ctml_writer.py b/interfaces/python/ctml_writer.py index 94fd7c448..a5222b2c5 100644 --- a/interfaces/python/ctml_writer.py +++ b/interfaces/python/ctml_writer.py @@ -9,9 +9,9 @@ # as a script. # # script usage: -# +# # python ctml_writer.py infile.cti -# +# # This will produce CTML file 'infile.xml' import string @@ -48,12 +48,12 @@ indent = ['', #----------------------------------------------------- class XMLnode: - + """This is a minimal class to allow easy creation of an XML tree from Python. It can write XML, but cannot read it.""" - + def __init__(self, name="--", value = ""): - + """Create a new node. Usually this only needs to be explicitly called to create the root element. Method addChild calls this constructor to create the new child node.""" @@ -61,17 +61,17 @@ class XMLnode: self._name = name # convert 'value' to a string if it is not already, and - # strip leading whitespace + # strip leading whitespace if type(value) <> types.StringType: self._value = string.lstrip(`value`) else: self._value = string.lstrip(value) - + self._attribs = {} # dictionary of attributes self._children = [] # list of child nodes self._childmap = {} # dictionary of child nodes - + def name(self): """The tag name of the node.""" return self._name @@ -83,10 +83,10 @@ class XMLnode: def addChild(self, name, value=""): """Add a child with tag 'name', and set its value if the value parameter is supplied.""" - + # create a new node for the child c = XMLnode(name = name, value = value) - + # add it to the list of children, and to the dictionary # of children self._children.append(c) @@ -96,7 +96,7 @@ class XMLnode: def addComment(self, comment): """Add a comment.""" self.addChild(name = '_comment_', value = comment) - + def value(self): """A string containing the element value.""" return self._value @@ -111,7 +111,7 @@ class XMLnode: def __setitem__(self, key, value): """Set a new attribute using the syntax node[key] = value.""" - self._attribs[key] = value + self._attribs[key] = value def __call__(self): """Allows getting the value using the syntax 'node()'""" @@ -123,13 +123,13 @@ class XMLnode: f.write('\n') self._write(f, 0) f.write('\n') - + def _write(self, f, level = 0): """Internal method used to write the XML representation of each node.""" if self._name == "": return - + indnt = indent[level] # handle comments @@ -179,14 +179,14 @@ class XMLnode: OneAtm = 1.01325e5 OneBar = 1.0e5 # Conversion from eV to J/kmol (electronCharge * Navrog) -eV = 96.4853E6 +eV = 96.4853E6 # Electron Mass in kg ElectronMass = 9.10938188e-31 import types, math, copy # default units -_ulen = 'm' +_ulen = 'm' _umol = 'kmol' _umass = 'kg' _utime = 's' @@ -223,13 +223,13 @@ def export_species(file, fmt = 'CSV'): global _valfmt _valexport = file _valfmt = fmt - + def validate(species = 'yes', reactions = 'yes'): global _valsp global _valrxn _valsp = species _valrxn = reactions - + def isnum(a): """True if a is an integer or floating-point number.""" if type(a) == types.IntType or type(a) == types.FloatType: @@ -271,8 +271,8 @@ def ufmt(base, n): if n == 1: return '-'+base if n == -1: return '/'+base if n > 0: return '-'+base+`n` - if n < 0: return '/'+base+`-n` - + if n < 0: return '/'+base+`-n` + def write(): """write the CTML file.""" x = XMLnode("ctml") @@ -284,17 +284,17 @@ def write(): ed = x.addChild("elementData") for e in _elements: e.build(ed) - + for ph in _phases: ph.build(x) s = species_set(name = _name, species = _species) s.build(x) - + r = x.addChild('reactionData') r['id'] = 'reaction_data' for rx in _reactions: rx.build(r) - + if _name <> 'noname': x.write(_name+'.xml') else: @@ -305,7 +305,7 @@ def write(): for s in _species: s.export(f, _valfmt) f.close() - + def addFloat(x, nm, val, fmt='', defunits=''): """ Add a child element to XML element x representing a @@ -332,7 +332,7 @@ def addFloat(x, nm, val, fmt='', defunits=''): xc = x.addChild(nm, s) xc['units'] = u - + def getAtomicComp(atoms): if type(atoms) == types.DictType: return atoms a = atoms.replace(',',' ') @@ -352,7 +352,7 @@ def getReactionSpecies(s): >>> getReactionSpecies(s) >>> {'CH3':1, 'H':3.7, 'O2':5.2} """ - + # get rid of the '+' signs separating species. Only plus signs # surrounded by spaces are replaced, so that plus signs may be # used in species names (e.g. 'Ar3+') @@ -360,14 +360,14 @@ def getReactionSpecies(s): d = {} n = 1.0 for t in toks: - - # try to convert the token to a number. + + # try to convert the token to a number. try: n = float(t) if n < 0.0: raise CTI_Error("negative stoichiometric coefficient:" +s) - + #if t > '0' and t < '9': # n = int(t) #else: @@ -380,7 +380,7 @@ def getReactionSpecies(s): else: d[t] = n # first time this token has been seen, # so set its value to n - + n = 1 # reset n to 1.0 for species that do not # specify a stoichiometric coefficient return d @@ -401,14 +401,14 @@ class element: e["name"] = self._sym e["atomicWt"] = `self._atw` e["atomicNumber"] = `self._num` - + class species_set: def __init__(self, name = '', species = []): self._s = species self._name = name #self.type = SPECIES_SET - + def build(self, p): p.addComment(' species definitions ') sd = p.addChild("speciesData") @@ -419,10 +419,10 @@ class species_set: #else: # raise 'wrong object type in species_set: '+s.__class__ - + class species: """A species.""" - + def __init__(self, name = 'missing name!', atoms = '', @@ -435,12 +435,12 @@ class species: self._atoms = getAtomicComp(atoms) self._comment = note - + if thermo: self._thermo = thermo else: self._thermo = const_cp() - + self._transport = transport chrg = 0 self._charge = charge @@ -452,7 +452,7 @@ class species: else: self._charge = chrg self._size = size - + global _species global _enames _species.append(self) @@ -480,11 +480,11 @@ class species: for n in range(nt): self._thermo[n].export(f, fmt) f.write('\n') - + def build(self, p): hdr = ' species '+self._name+' ' - p.addComment(hdr) + p.addComment(hdr) s = p.addChild("species") s["name"] = self._name a = '' @@ -496,7 +496,7 @@ class species: if self._charge <> -999: s.addChild("charge",self._charge) if self._size <> 1.0: - s.addChild("size",self._size) + s.addChild("size",self._size) if self._thermo: t = s.addChild("thermo") if type(self._thermo) == types.InstanceType: @@ -512,7 +512,7 @@ class species: else: nt = len(self._transport) for n in range(nt): - self._transport[n].build(t) + self._transport[n].build(t) class thermo: """Base class for species standard-state thermodynamic properties.""" @@ -542,11 +542,11 @@ class Mu0_table(thermo): n['P0'] = `_pref` else: n['P0'] = `self._pref` - energy_units = _uenergy+'/'+_umol + energy_units = _uenergy+'/'+_umol addFloat(n,"H298", self._h298, defunits = energy_units) n.addChild("numPoints", len(self._mu0)) - + mustr = '' tstr = '' col = 0 @@ -560,7 +560,7 @@ class Mu0_table(thermo): tstr = tstr[:-2]+'\n' mustr = mustr[:-2]+'\n' col = 0 - + u = n.addChild("floatArray", mustr) u["size"] = "numPoints" u["name"] = "Mu0Values" @@ -569,11 +569,11 @@ class Mu0_table(thermo): u["size"] = "numPoints" u["name"] = "Mu0Temperatures" - + class NASA(thermo): """NASA polynomial parameterization.""" - - def __init__(self, range = (0.0, 0.0), + + def __init__(self, range = (0.0, 0.0), coeffs = [], p0 = -1.0): self._t = range self._pref = p0 @@ -588,11 +588,11 @@ class NASA(thermo): for i in range(7): str += '%17.9E, ' % self._coeffs[i] f.write(str) - + def build(self, t): n = t.addChild("NASA") n['Tmin'] = `self._t[0]` - #n['Tmid'] = `self._t[1]` + #n['Tmid'] = `self._t[1]` n['Tmax'] = `self._t[1]` if self._pref <= 0.0: n['P0'] = `_pref` @@ -610,11 +610,11 @@ class NASA(thermo): u["size"] = "7" u["name"] = "coeffs" - + class NASA9(thermo): """NASA9 polynomial parameterization for a single temperature region.""" - - def __init__(self, range = (0.0, 0.0), + + def __init__(self, range = (0.0, 0.0), coeffs = [], p0 = -1.0): self._t = range # Range of the polynomial representation self._pref = p0 # Reference pressure @@ -629,10 +629,10 @@ class NASA9(thermo): for i in range(9): str += '%17.9E, ' % self._coeffs[i] f.write(str) - + def build(self, t): n = t.addChild("NASA9") - n['Tmin'] = `self._t[0]` + n['Tmin'] = `self._t[0]` n['Tmax'] = `self._t[1]` if self._pref <= 0.0: n['P0'] = `_pref` @@ -653,8 +653,8 @@ class NASA9(thermo): class Shomate(thermo): """Shomate polynomial parameterization.""" - - def __init__(self, range = (0.0, 0.0), + + def __init__(self, range = (0.0, 0.0), coeffs = [], p0 = -1.0): self._t = range self._pref = p0 @@ -662,7 +662,7 @@ class Shomate(thermo): raise CTI_Error('Shomate coefficient list must have length = 7') self._coeffs = coeffs - + def build(self, t): n = t.addChild("Shomate") n['Tmin'] = `self._t[0]` @@ -685,7 +685,7 @@ class Shomate(thermo): class Adsorbate(thermo): """Adsorbed species characterized by a binding energy and a set of vibrational frequencies.""" - + def __init__(self, range = (0.0, 0.0), binding_energy = 0.0, frequencies = [], p0 = -1.0): @@ -694,7 +694,7 @@ class Adsorbate(thermo): self._freqs = frequencies self._be = binding_energy - + def build(self, t): n = t.addChild("adsorbate") n['Tmin'] = `self._t[0]` @@ -703,7 +703,7 @@ class Adsorbate(thermo): n['P0'] = `_pref` else: n['P0'] = `self._pref` - + energy_units = _uenergy+'/'+_umol addFloat(n,'binding_energy',self._be, defunits = energy_units) str = "" @@ -714,18 +714,18 @@ class Adsorbate(thermo): u = n.addChild("floatArray", str) u["size"] = `nfreq` u["name"] = "freqs" - - - + + + class const_cp(thermo): """Constant specific heat.""" - - def __init__(self, + + def __init__(self, t0 = 298.15, cp0 = 0.0, h0 = 0.0, s0 = 0.0, tmax = 5000.0, tmin = 100.0): self._t = [tmin, tmax] self._c = [t0, h0, s0, cp0] - + def build(self, t): #t = self._build(p) c = t.addChild('const_cp') @@ -734,7 +734,7 @@ class const_cp(thermo): energy_units = _uenergy+'/'+_umol addFloat(c,'t0',self._c[0], defunits = 'K') addFloat(c,'h0',self._c[1], defunits = energy_units) - addFloat(c,'s0',self._c[2], defunits = energy_units+'/K') + addFloat(c,'s0',self._c[2], defunits = energy_units+'/K') addFloat(c,'cp0',self._c[3], defunits = energy_units+'/K') @@ -759,11 +759,11 @@ class gas_transport: tg['title'] = 'geometry' addFloat(t, "LJ_welldepth", (self._well_depth, 'K'), '%8.3f') addFloat(t, "LJ_diameter", (self._diam, 'A'),'%8.3f') - addFloat(t, "dipoleMoment", (self._dipole, 'Debye'),'%8.3f') + addFloat(t, "dipoleMoment", (self._dipole, 'Debye'),'%8.3f') addFloat(t, "polarizability", (self._polar, 'A3'),'%8.3f') - addFloat(t, "rotRelax", self._rot_relax,'%8.3f') + addFloat(t, "rotRelax", self._rot_relax,'%8.3f') + - class Arrhenius: def __init__(self, A = 0.0, @@ -773,7 +773,7 @@ class Arrhenius: rate_type = ''): self._c = [A, n, E] self._type = rate_type - + if coverage: if type(coverage[0]) == types.StringType: self._cov = [coverage] @@ -782,10 +782,10 @@ class Arrhenius: else: self._cov = None - + def build(self, p, units_factor = 1.0, gas_species = [], name = '', rxn_phase = None): - + a = p.addChild('Arrhenius') if name: a['name'] = name @@ -801,8 +801,8 @@ reactant, but this reaction has """+`ngas`+': '+`gas_species`) else: a['species'] = gas_species[0] units_factor = 1.0 - - + + # if a pure number is entered for A, multiply by the conversion # factor to SI and write it to CTML as a pure number. Otherwise, # pass it as-is through to CTML with the unit string. @@ -810,7 +810,7 @@ reactant, but this reaction has """+`ngas`+': '+`gas_species`) addFloat(a,'A',self._c[0]*units_factor, fmt = '%14.6E') elif len(self._c[0]) == 2 and self._c[0][1] == '/site': addFloat(a,'A',self._c[0][0]/rxn_phase._sitedens, - fmt = '%14.6E') + fmt = '%14.6E') else: addFloat(a,'A',self._c[0], fmt = '%14.6E') @@ -842,7 +842,7 @@ def getPairs(s): key, val = t.split(':') m[key] = float(val) return m - + class reaction: def __init__(self, equation = '', @@ -855,7 +855,7 @@ class reaction: self._id = id self._e = equation self._order = order - + if type(options) == types.StringType: self._options = [options] else: @@ -881,7 +881,7 @@ class reaction: self._rxnorder[o] = ord[o] else: raise CTI_Error("order specified for non-reactant: "+o) - + self._kf = kf self._igspecies = [] self._dims = [0]*4 @@ -889,7 +889,7 @@ class reaction: self._type = '' _reactions.append(self) - + def build(self, p): if self._id: id = self._id @@ -899,12 +899,12 @@ class reaction: elif self._num < 100: nstr = '00'+`self._num` elif self._num < 1000: - nstr = '0'+`self._num` + nstr = '0'+`self._num` else: nstr = `self._num` id = nstr - + mdim = 0 ldim = 0 str = '' @@ -935,14 +935,14 @@ class reaction: mdim += nm*ns ldim += nl*ns - p.addComment(" reaction "+id+" ") + p.addComment(" reaction "+id+" ") r = p.addChild('reaction') r['id'] = id if self.rev: r['reversible'] = 'yes' else: r['reversible'] = 'no' - + noptions = len(self._options) for nss in range(noptions): s = self._options[nss] @@ -959,7 +959,7 @@ class reaction: for osp in self._rxnorder.keys(): o = r.addChild('order',self._rxnorder[osp]) o['species'] = osp - + # adjust the moles and length powers based on the dimensions of # the rate of progress (moles/length^2 or moles/length^3) @@ -967,7 +967,7 @@ class reaction: mdim += -1 ldim += 2 p = self._dims[:3] - if p[0] <> 0 or p[1] <> 0 or p[2] > 1: + if p[0] <> 0 or p[1] <> 0 or p[2] > 1: raise CTI_Error(self._e +'\nA surface reaction may contain at most '+ 'one surface phase.') elif self._type == 'edge': @@ -976,7 +976,7 @@ class reaction: p = self._dims[:2] if p[0] <> 0 or p[1] > 1: raise CTI_Error(self._e+'\nAn edge reaction may contain at most '+ - 'one edge phase.') + 'one edge phase.') else: mdim += -1 ldim += 3 @@ -996,7 +996,7 @@ class reaction: elif self._type == 'surface': self._kf = [self._kf] elif self._type == 'edge': - self._kf = [self._kf] + self._kf = [self._kf] elif self._type == 'threeBody': self._kf = [self._kf] mdim += 1 @@ -1006,7 +1006,7 @@ class reaction: if self._beta > 0: electro = kfnode.addChild('electrochem') electro['beta'] = `self._beta` - + for kf in self._kf: unit_fctr = (math.pow(_length[_ulen], -ldim) * @@ -1056,18 +1056,18 @@ class three_body_reaction(reaction): del self._r[r] for p in self._p.keys(): if p == 'M' or p == 'm': - del self._p[p] + del self._p[p] + - def build(self, p): r = reaction.build(self, p) if r == 0: return kfnode = r.child('rateCoeff') - + if self._eff: eff = kfnode.addChild('efficiencies',self._eff) eff['default'] = `self._effm` - + #--------------- @@ -1076,23 +1076,23 @@ class falloff_reaction(reaction): def __init__(self, equation = '', kf0 = None, - kf = None, + kf = None, efficiencies = '', falloff = None, id = '', options = [] ): - kf2 = (kf, kf0) + kf2 = (kf, kf0) reaction.__init__(self, equation, kf2, id, '', options) self._type = 'falloff' # use a Lindemann falloff function by default self._falloff = falloff if self._falloff == None: self._falloff = Lindemann() - + self._effm = 1.0 - self._eff = efficiencies + self._eff = efficiencies # clean up reactant and product lists del self._r['(+'] @@ -1110,20 +1110,20 @@ class falloff_reaction(reaction): raise CTI_Error('(+ '+mspecies+') and '+self._eff+' cannot both be specified') self._eff = r[-1]+':1.0' self._effm = 0.0 - + del self._r[r] del self._p[r] - + def build(self, p): r = reaction.build(self, p) if r == 0: return kfnode = r.child('rateCoeff') - + if self._eff and self._effm >= 0.0: eff = kfnode.addChild('efficiencies',self._eff) eff['default'] = `self._effm` - + if self._falloff: self._falloff.build(kfnode) @@ -1134,7 +1134,7 @@ class surface_reaction(reaction): equation = '', kf = None, id = '', - order = '', + order = '', options = []): reaction.__init__(self, equation, kf, id, order, options) self._type = 'surface' @@ -1154,7 +1154,7 @@ class edge_reaction(reaction): self._beta = beta -#-------------- +#-------------- class state: @@ -1173,7 +1173,7 @@ class state: self._y = mass_fractions self._c = coverages self._m = solute_molalities - + def build(self, ph): st = ph.addChild('state') if self._t: addFloat(st, 'temperature', self._t, defunits = 'K') @@ -1182,12 +1182,12 @@ class state: if self._x: st.addChild('moleFractions', self._x) if self._y: st.addChild('massFractions', self._y) if self._c: st.addChild('coverages', self._c) - if self._m: st.addChild('soluteMolalities', self._m) - + if self._m: st.addChild('soluteMolalities', self._m) + class phase: """Base class for phases of matter.""" - + def __init__(self, name = '', dim = 3, @@ -1196,17 +1196,17 @@ class phase: reactions = 'none', initial_state = None, options = []): - + self._name = name self._dim = dim self._el = elements self._sp = [] self._rx = [] - + if type(options) == types.StringType: self._options = [options] else: - self._options = options + self._options = options self.debug = 0 if 'debug' in options: @@ -1215,7 +1215,7 @@ class phase: #-------------------------------- # process species #-------------------------------- - + # if a single string is entered, make it a list if type(species) == types.StringType: self._species = [species] @@ -1224,12 +1224,12 @@ class phase: self._skip = 0 - # dictionary of species names + # dictionary of species names self._spmap = {} # for each species string, check whether or not the species # are imported or defined locally. If imported, the string - # contains a colon (:) + # contains a colon (:) for sp in self._species: icolon = sp.find(':') if icolon > 0: @@ -1239,13 +1239,13 @@ class phase: self._sp.append((datasrc+'.xml', spnames)) else: spnames = sp - self._sp.append(('', spnames)) + self._sp.append(('', spnames)) # strip the commas, and make the list of species names # 10/31/03: commented out the next line, so that species names may contain commas #sptoks = spnames.replace(',',' ').split() sptoks = spnames.split() - + for s in sptoks: # check for stray commas if s <> ',': @@ -1255,13 +1255,13 @@ class phase: if s <> 'all' and self._spmap.has_key(s): raise CTI_Error('Multiply-declared species '+s+' in phase '+self._name) self._spmap[s] = self._dim - + self._rxns = reactions # check that species have been declared if len(self._spmap) == 0: raise CTI_Error('No species declared for phase '+self._name) - + # and that only one species is declared if it is a pure phase if self.is_pure() and len(self._spmap) > 1: raise CTI_Error('Stoichiometric phases must declare exactly one species, \n'+ @@ -1272,12 +1272,12 @@ class phase: # add this phase to the global phase list global _phases _phases.append(self) - + def is_ideal_gas(self): """True if the entry represents an ideal gas.""" return 0 - + def is_pure(self): return 0 @@ -1290,17 +1290,17 @@ class phase: def conc_dim(self): """Concentration dimensions. Used in computing the units for reaction rate coefficients.""" - return (1, -self._dim) + return (1, -self._dim) + - def buildrxns(self, p): - + if type(self._rxns) == types.StringType: self._rxns = [self._rxns] - + # for each reaction string, check whether or not the reactions # are imported or defined locally. If imported, the string - # contains a colon (:) + # contains a colon (:) for r in self._rxns: icolon = r.find(':') if icolon > 0: @@ -1310,7 +1310,7 @@ class phase: self._rx.append((datasrc+'.xml', rnum)) else: rnum = r - self._rx.append(('', rnum)) + self._rx.append(('', rnum)) for r in self._rx: datasrc = r[0] @@ -1319,7 +1319,7 @@ class phase: if 'skip_undeclared_species' in self._options: rk = ra.addChild('skip') rk['species'] = 'undeclared' - + rtoks = r[1].split() if rtoks[0] <> 'all': i = ra.addChild('include') @@ -1328,9 +1328,9 @@ class phase: if len(rtoks) > 2 and (rtoks[1] == 'to' or rtoks[1] == '-'): i['max'] = rtoks[2] else: - i['max'] = rtoks[0] - - + i['max'] = rtoks[0] + + def build(self, p): p.addComment(' phase '+self._name+' ') ph = p.addChild('phase') @@ -1341,7 +1341,7 @@ class phase: #err = ph.addChild('validation') #err.addChild('duplicateReactions','halt') #err.addChild('thermo','warn') - + e = ph.addChild('elementArray',self._el) e['datasrc'] = 'elements.xml' for s in self._sp: @@ -1352,10 +1352,10 @@ class phase: if 'skip_undeclared_elements' in self._options: sk = sa.addChild('skip') sk['element'] = 'undeclared' - + if self._rxns <> 'none': self.buildrxns(ph) - + #self._eos.build(ph) if self._initial: self._initial.build(ph) @@ -1385,9 +1385,9 @@ class ideal_gas(phase): print 'in file '+__name__ except: pass - - + + def build(self, p): ph = phase.build(self, p) e = ph.addChild("thermo") @@ -1416,7 +1416,7 @@ class stoichiometric_solid(phase): transport = 'None', initial_state = None, options = []): - + phase.__init__(self, name, 3, elements, species, 'none', initial_state, options) self._dens = density @@ -1429,7 +1429,7 @@ class stoichiometric_solid(phase): """A stoichiometric solid always has unit activity, so the generalized concentration is 1 (dimensionless).""" return (0,0) - + def build(self, p): ph = phase.build(self, p) e = ph.addChild("thermo") @@ -1439,7 +1439,7 @@ class stoichiometric_solid(phase): t = ph.addChild('transport') t['model'] = self._tr k = ph.addChild("kinetics") - k['model'] = 'none' + k['model'] = 'none' class stoichiometric_liquid(stoichiometric_solid): @@ -1453,11 +1453,11 @@ class stoichiometric_liquid(stoichiometric_solid): transport = 'None', initial_state = None, options = []): - + stoichiometric_solid.__init__(self, name, elements, species, density, transport, initial_state, options) - + class metal(phase): """A metal.""" @@ -1469,7 +1469,7 @@ class metal(phase): transport = 'None', initial_state = None, options = []): - + phase.__init__(self, name, 3, elements, species, 'none', initial_state, options) self._dens = density @@ -1478,7 +1478,7 @@ class metal(phase): def conc_dim(self): return (0,0) - + def build(self, p): ph = phase.build(self, p) e = ph.addChild("thermo") @@ -1503,7 +1503,7 @@ class semiconductor(phase): transport = 'None', initial_state = None, options = []): - + phase.__init__(self, name, 3, elements, species, 'none', initial_state, options) self._dens = density @@ -1515,7 +1515,7 @@ class semiconductor(phase): def conc_dim(self): return (1,-3) - + def build(self, p): ph = phase.build(self, p) e = ph.addChild("thermo") @@ -1528,7 +1528,7 @@ class semiconductor(phase): t = ph.addChild('transport') t['model'] = self._tr k = ph.addChild("kinetics") - k['model'] = 'none' + k['model'] = 'none' class incompressible_solid(phase): @@ -1541,7 +1541,7 @@ class incompressible_solid(phase): transport = 'None', initial_state = None, options = []): - + phase.__init__(self, name, 3, elements, species, 'none', initial_state, options) self._dens = density @@ -1552,7 +1552,7 @@ class incompressible_solid(phase): def conc_dim(self): return (1,-3) - + def build(self, p): ph = phase.build(self, p) e = ph.addChild("thermo") @@ -1562,7 +1562,7 @@ class incompressible_solid(phase): t = ph.addChild('transport') t['model'] = self._tr k = ph.addChild("kinetics") - k['model'] = 'none' + k['model'] = 'none' class lattice(phase): @@ -1584,7 +1584,7 @@ class lattice(phase): if name == '': raise CTI_Error('sublattice name must be specified') if species == '': - raise CTI_Error('sublattice species must be specified') + raise CTI_Error('sublattice species must be specified') if site_density < 0.0: raise CTI_Error('sublattice '+name +' site density must be specified') @@ -1602,7 +1602,7 @@ class lattice(phase): t = ph.addChild('transport') t['model'] = self._tr k = ph.addChild("kinetics") - k['model'] = 'none' + k['model'] = 'none' class lattice_solid(phase): """A solid crystal consisting of one or more sublattices.""" @@ -1623,7 +1623,7 @@ class lattice_solid(phase): if not el in elist: elist.append(el) elements = string.join(elist) - + # find species slist = [] for lat in lattices: @@ -1635,7 +1635,7 @@ class lattice_solid(phase): if not sp in slist: slist.append(sp) species = string.join(slist) - + phase.__init__(self, name, 3, elements, species, 'none', initial_state, options) self._lattices = lattices @@ -1646,22 +1646,22 @@ class lattice_solid(phase): def conc_dim(self): return (0,0) - + def build(self, p): ph = phase.build(self, p) e = ph.addChild("thermo") e['model'] = 'LatticeSolid' - + if self._lattices: lat = e.addChild('LatticeArray') for n in self._lattices: n.build(lat, visible = 1) - + if self._tr: t = ph.addChild('transport') t['model'] = self._tr k = ph.addChild("kinetics") - k['model'] = 'none' + k['model'] = 'none' @@ -1671,7 +1671,7 @@ class liquid_vapor(phase): built-in liquid/vapor equations of state. The substance_flag parameter selects the fluid. See purefluids.py for the usage of this entry type.""" - + def __init__(self, name = '', elements = '', @@ -1679,7 +1679,7 @@ class liquid_vapor(phase): substance_flag = 0, initial_state = None, options = []): - + phase.__init__(self, name, 3, elements, species, 'none', initial_state, options) self._subflag = substance_flag @@ -1688,7 +1688,7 @@ class liquid_vapor(phase): def conc_dim(self): return (0,0) - + def build(self, p): ph = phase.build(self, p) e = ph.addChild("thermo") @@ -1705,7 +1705,7 @@ class redlich_kwong(phase): built-in liquid/vapor equations of state. The substance_flag parameter selects the fluid. See purefluids.py for the usage of this entry type.""" - + def __init__(self, name = '', elements = '', @@ -1715,7 +1715,7 @@ class redlich_kwong(phase): Tcrit = 1.0, Pcrit = 1.0, options = []): - + phase.__init__(self, name, 3, elements, species, 'none', initial_state, options) self._subflag = 7 @@ -1725,7 +1725,7 @@ class redlich_kwong(phase): def conc_dim(self): return (0,0) - + def build(self, p): ph = phase.build(self, p) e = ph.addChild("thermo") @@ -1737,7 +1737,7 @@ class redlich_kwong(phase): ph.addChild("kinetics") k['model'] = 'none' - + class ideal_interface(phase): """An ideal interface.""" @@ -1761,7 +1761,7 @@ class ideal_interface(phase): self._tr = transport self._phases = phases self._sitedens = site_density - + def build(self, p): ph = phase.build(self, p) e = ph.addChild("thermo") @@ -1800,7 +1800,7 @@ class edge(phase): self._tr = transport self._phases = phases self._sitedens = site_density - + def build(self, p): ph = phase.build(self, p) e = ph.addChild("thermo") @@ -1814,7 +1814,7 @@ class edge(phase): def conc_dim(self): - return (1, -1) + return (1, -1) ## class binary_salt_parameters: @@ -1832,7 +1832,7 @@ class edge(phase): ## self._beta1 = beta1 ## self._Cphi = Cphi ## self._Alpha1 = Alpha1 - + ## def build(self, a): ## s = a.addChild("binarySaltParameters") ## s["cation"] = self._cation @@ -1849,7 +1849,7 @@ class edge(phase): ## theta = 0.0): ## self._anions = anions ## self._theta = theta - + ## def build(self, a): ## s = a.addChild("thetaAnion") ## s["anion1"] = self._anions[0] @@ -1866,14 +1866,14 @@ class edge(phase): ## self._cation = cation ## self._theta = theta ## self._psi = psi - + ## def build(self, a): ## s = a.addChild("psiCommonCation") ## s["anion1"] = self._anions[0] ## s["anion2"] = self._anions[1] ## s["cation"] = self._cation ## s.addChild("Theta", self._theta) -## s.addChild("Psi", self._psi) +## s.addChild("Psi", self._psi) ## class psi_common_anion: ## def __init__(self, @@ -1885,35 +1885,35 @@ class edge(phase): ## self._cations = cations ## self._theta = theta ## self._psi = psi - + ## def build(self, a): ## s = a.addChild("psiCommonAnion") ## s["anion1"] = self._cations[0] ## s["anion2"] = self._cations[1] ## s["cation"] = self._anion ## s.addChild("Theta", self._theta) -## s.addChild("Psi", self._psi) +## s.addChild("Psi", self._psi) + - ## class theta_cation: ## def __init__(self, ## cations = None, ## theta = 0.0): ## self._cations = cations ## self._theta = theta - + ## def build(self, a): ## s = a.addChild("thetaCation") ## s["cation1"] = self._anions[0] ## s["cation2"] = self._anions[1] ## s.addChild("Theta", self._theta) - + ## class pitzer: ## def __init__(self, ## temp_model = "", ## A_Debye = "", ## default_ionic_radius = -1.0, - + ## class electrolyte(phase): ## """An electrolye solution obeying the HMW model.""" ## def __init__(self, @@ -1926,7 +1926,7 @@ class edge(phase): ## standard_concentration = '', ## activity_coefficients = None, ## options = []): - + ## phase.__init__(self, name, 3, elements, species, 'none', ## initial_state, options) ## self._pure = 0 @@ -1935,7 +1935,7 @@ class edge(phase): ## def conc_dim(self): ## return (1,-3) - + ## def build(self, p): ## ph = phase.build(self, p) ## e = ph.addChild("thermo") @@ -1943,27 +1943,27 @@ class edge(phase): ## sc['model'] = self._stdconc ## e['model'] = 'HMW' ## e.addChild("activity_coefficients") - + ## addFloat(e, 'density', self._dens, defunits = _umass+'/'+_ulen+'3') ## if self._tr: ## t = ph.addChild('transport') ## t['model'] = self._tr ## k = ph.addChild("kinetics") -## k['model'] = 'none' +## k['model'] = 'none' + - #------------------------------------------------------------------- # falloff parameterizations class Troe: - + def __init__(self, A = 0.0, T3 = 0.0, T1 = 0.0, T2 = -999.9): if T2 <> -999.9: self._c = (A, T3, T1, T2) else: self._c = (A, T3, T1) - + def build(self, p): s = '' for num in self._c: @@ -1978,7 +1978,7 @@ class SRI: self._c = (A, B, C, D, E) else: self._c = (A, B, C) - + def build(self, p): s = '' for num in self._c: @@ -2006,5 +2006,3 @@ if __name__ == "__main__": dataset(root) execfile(file) write() - - diff --git a/samples/python/equilibrium/adiabatic_flame/adiabatic.py b/samples/python/equilibrium/adiabatic_flame/adiabatic.py index 58148d307..300335d6c 100644 --- a/samples/python/equilibrium/adiabatic_flame/adiabatic.py +++ b/samples/python/equilibrium/adiabatic_flame/adiabatic.py @@ -54,35 +54,35 @@ if ifuel < 0: if gas.nAtoms(fuel_species,'O') > 0 or gas.nAtoms(fuel_species,'N') > 0: raise "Error: only hydrocarbon fuels are supported." - + stoich_O2 = gas.nAtoms(fuel_species,'C') + 0.25*gas.nAtoms(fuel_species,'H') for i in range(npoints): - phi[i] = phi_min + (phi_max - phi_min)*i/(npoints - 1) - x = zeros(nsp,'d') - x[ifuel] = phi[i] - x[io2] = stoich_O2 - x[in2] = stoich_O2*air_N2_O2_ratio + phi[i] = phi_min + (phi_max - phi_min)*i/(npoints - 1) + x = zeros(nsp,'d') + x[ifuel] = phi[i] + x[io2] = stoich_O2 + x[in2] = stoich_O2*air_N2_O2_ratio - # set the gas state - gas.set(T = temp, P = pres, X = x) + # set the gas state + gas.set(T = temp, P = pres, X = x) - # create a mixture of 1 mole of gas, and 0 moles of solid carbon. - mix = Mixture(mix_phases) - mix.setTemperature(temp) - mix.setPressure(pres) + # create a mixture of 1 mole of gas, and 0 moles of solid carbon. + mix = Mixture(mix_phases) + mix.setTemperature(temp) + mix.setPressure(pres) - # equilibrate the mixture adiabatically at constant P - # - # mix.equilibrate('HP', maxsteps = 1000, - # err = 1.0e-6, maxiter = 200, loglevel=0) - mix.vcs_equilibrate('HP', maxsteps = 1000, - rtol = 1.0e-6, maxiter = 200, loglevel=0) - - tad[i] = mix.temperature(); - print 'At phi = %12.4g, Tad = %12.4g' % (phi[i],tad[i]) - xeq[:,i] = mix.speciesMoles() + # equilibrate the mixture adiabatically at constant P + # + # mix.equilibrate('HP', maxsteps = 1000, + # err = 1.0e-6, maxiter = 200, loglevel=0) + mix.vcs_equilibrate('HP', maxsteps = 1000, + rtol = 1.0e-6, maxiter = 200, loglevel=0) + + tad[i] = mix.temperature(); + print 'At phi = %12.4g, Tad = %12.4g' % (phi[i],tad[i]) + xeq[:,i] = mix.speciesMoles() # write output CSV file for importing into Excel @@ -100,4 +100,3 @@ print 'output written to '+csvfile if '--plot' in sys.argv: import plotting plotting.plotEquilData(mix, phi, tad, xeq) - diff --git a/samples/python/equilibrium/multiphase_plasma/multiphase_plasma.py b/samples/python/equilibrium/multiphase_plasma/multiphase_plasma.py index 1afbb0eb6..15b0c32a7 100644 --- a/samples/python/equilibrium/multiphase_plasma/multiphase_plasma.py +++ b/samples/python/equilibrium/multiphase_plasma/multiphase_plasma.py @@ -1,5 +1,5 @@ # An equilibrium example with charged species in the gas phase -# and multiple condensed phases. +# and multiple condensed phases. # Note: This example runs fine on Mac and linux platforms, but # encounters some convergence difficulties under Windows. The reasons @@ -35,11 +35,9 @@ for n in range(100): # temperature and pressure fixed # mix.equilibrate("TP",maxsteps=10000,loglevel=1) mix.vcs_equilibrate("TP",printLvl=0,maxsteps=10000,loglevel=0) - + # write out the moles of each species writeCSV(f,[t]+ list(mix.speciesMoles())) # close the output file f.close() - - diff --git a/samples/python/equilibrium/plotting.py b/samples/python/equilibrium/plotting.py index 3a8a7ccfe..0dc3952c9 100644 --- a/samples/python/equilibrium/plotting.py +++ b/samples/python/equilibrium/plotting.py @@ -20,7 +20,7 @@ def plotEquilData(mix, phi, tad, xeq): if warnMac() < 0: return npoints = len(phi) - + nsp = mix.nSpecies() #titles = ['Major Species', 'Minor Species', 'N Minor Species'] @@ -50,7 +50,7 @@ def plotEquilData(mix, phi, tad, xeq): subplot(2,2,2+m); hold(True); - + for i in range(nsp): if p[i] == m: for j in range(npoints): @@ -74,7 +74,7 @@ def plotEquilData(mix, phi, tad, xeq): if m == 0: axis([phi[1], phi[-1], 0.0, 1.0]); else: - axis([phi[1], phi[-1], 1.0e-14, 1]); + axis([phi[1], phi[-1], 1.0e-14, 1]); xlabel('Equivalence Ratio'); ylabel('Mole Fraction'); @@ -82,4 +82,3 @@ def plotEquilData(mix, phi, tad, xeq): hold(False) show() - diff --git a/samples/python/equilibrium/stoich_flame/stoich.py b/samples/python/equilibrium/stoich_flame/stoich.py index fa04ec099..0cd861a21 100644 --- a/samples/python/equilibrium/stoich_flame/stoich.py +++ b/samples/python/equilibrium/stoich_flame/stoich.py @@ -43,7 +43,7 @@ gas.set(T = temp, P = OneAtm, X = comp) #################################################################### try: - gas.equilibrate("TP", solver = 0) # use the ChemEquil (0) solver + gas.equilibrate("TP", solver = 0) # use the ChemEquil (0) solver except: print "ChemEquil solver failed! Try the MultiPhaseEquil solver..." diff --git a/samples/python/flames/adiabatic_flame/adiabatic_flame.py b/samples/python/flames/adiabatic_flame/adiabatic_flame.py index bb042b45a..9ed9aba90 100644 --- a/samples/python/flames/adiabatic_flame/adiabatic_flame.py +++ b/samples/python/flames/adiabatic_flame/adiabatic_flame.py @@ -24,9 +24,9 @@ tol_ts = [1.0e-5, 1.0e-9] # [rtol atol] for time stepping loglevel = 1 # amount of diagnostic output (0 # to 5) - + refine_grid = 1 # 1 to enable refinement, 0 to - # disable + # disable gas = GRI30('Mix') @@ -37,7 +37,7 @@ gas.setState_TPX(tin, p, comp) f = FreeFlame(gas = gas, grid = initial_grid, tfix = 600.0) -# set the upstream properties +# set the upstream properties f.inlet.set(mole_fractions = comp, temperature = tin) f.set(tol = tol_ss, tol_time = tol_ts) diff --git a/samples/python/flames/flame1/flame1.py b/samples/python/flames/flame1/flame1.py index 904c461be..6914f87d3 100755 --- a/samples/python/flames/flame1/flame1.py +++ b/samples/python/flames/flame1/flame1.py @@ -32,9 +32,9 @@ tol_ts = [1.0e-4, 1.0e-9] # [rtol atol] for time stepping loglevel = 1 # amount of diagnostic output (0 # to 5) - + refine_grid = 1 # 1 to enable refinement, 0 to - # disable + # disable ################ create the gas object ######################## @@ -85,4 +85,3 @@ fcsv.close() print 'solution saved to flame1.csv' f.showStats() - diff --git a/samples/python/flames/flame2/flame2.py b/samples/python/flames/flame2/flame2.py index ae1466483..ab99ee578 100644 --- a/samples/python/flames/flame2/flame2.py +++ b/samples/python/flames/flame2/flame2.py @@ -27,9 +27,9 @@ tol_ts = [1.0e-5, 1.0e-4] # [rtol atol] for time stepping loglevel = 1 # amount of diagnostic output (0 # to 5) - + refine_grid = 1 # 1 to enable refinement, 0 to - # disable + # disable ################ create the gas object ######################## @@ -94,8 +94,3 @@ fcsv.close() print 'solution saved to flame2.csv' f.showStats() - - - - - diff --git a/samples/python/flames/flame_fixed_T/flame_fixed_T.py b/samples/python/flames/flame_fixed_T/flame_fixed_T.py index fa3b5511d..5126b2e80 100644 --- a/samples/python/flames/flame_fixed_T/flame_fixed_T.py +++ b/samples/python/flames/flame_fixed_T/flame_fixed_T.py @@ -25,7 +25,7 @@ def getTempData(filename): print 'problem?' print 'The one line found is: ',lines[0] - + for line in lines: if line[0] == '#': # use '#' as the comment character pass @@ -38,13 +38,13 @@ def getTempData(filename): pass print 'read',len(z),'temperature values.' f.close() - + # convert z values into non-dimensional relative positions. n = len(z) zmax = z[n-1] for i in range(n): z[i] = z[i]/zmax - + return [z,t] @@ -70,9 +70,9 @@ tol_ts = [1.0e-5, 1.0e-4] # [rtol atol] for time stepping loglevel = 1 # amount of diagnostic output (0 # to 5) - + refine_grid = 1 # 1 to enable refinement, 0 to - # disable + # disable ################ create the gas object ######################## @@ -142,8 +142,3 @@ fcsv.close() print 'solution saved to flame_fixed_T.csv' f.showStats() - - - - - diff --git a/samples/python/flames/free_h2_air/free_h2_air.py b/samples/python/flames/free_h2_air/free_h2_air.py index 258b57e03..4f4c1660e 100644 --- a/samples/python/flames/free_h2_air/free_h2_air.py +++ b/samples/python/flames/free_h2_air/free_h2_air.py @@ -28,9 +28,9 @@ tol_ts = [1.0e-4, 1.0e-9] # [rtol atol] for time stepping loglevel = 1 # amount of diagnostic output (0 # to 5) - + refine_grid = 1 # 1 to enable refinement, 0 to - # disable + # disable ################ create the gas object ######################## @@ -81,4 +81,3 @@ fcsv.close() print 'solution saved to freeflame1.csv' print 'flamespeed = ',u[0],'m/s' f.showStats() - diff --git a/samples/python/flames/npflame1/npflame1.py b/samples/python/flames/npflame1/npflame1.py index 79b1d36f7..051a3fc7a 100644 --- a/samples/python/flames/npflame1/npflame1.py +++ b/samples/python/flames/npflame1/npflame1.py @@ -34,9 +34,9 @@ tol_ts = [1.0e-3, 1.0e-9] # [rtol, atol] for time stepping loglevel = 1 # amount of diagnostic output (0 # to 5) - + refine_grid = 1 # 1 to enable refinement, 0 to - # disable + # disable ################ create the gas object ######################## @@ -119,6 +119,3 @@ print 'solution saved to npflame1.csv' f.showSolution() f.showStats(0) - - - diff --git a/samples/python/flames/stflame1/stflame1.py b/samples/python/flames/stflame1/stflame1.py index 88bd4fee2..dd58e79e3 100644 --- a/samples/python/flames/stflame1/stflame1.py +++ b/samples/python/flames/stflame1/stflame1.py @@ -47,7 +47,7 @@ tol_ts = [1.0e-4, 1.0e-9] # [rtol atol] for time stepping loglevel = 1 # amount of diagnostic output (0 # to 5) - + refine_grid = 1 # 1 to enable refinement, 0 to # disable ratio = 5.0 @@ -114,4 +114,3 @@ for md in mdot: print 'solution saved to flame1.csv' f.showStats() - diff --git a/samples/python/fuel_cells/sofc.py b/samples/python/fuel_cells/sofc.py index d523b313b..3f13f204d 100644 --- a/samples/python/fuel_cells/sofc.py +++ b/samples/python/fuel_cells/sofc.py @@ -80,7 +80,7 @@ def NewtonSolver(f, xstart, C = 0.0): """ f0 = f(xstart) - C x0 = xstart - dx = 1.0e-6 + dx = 1.0e-6 xlast = 999.0 n = 0 while n < 200: @@ -91,9 +91,9 @@ def NewtonSolver(f, xstart, C = 0.0): # avoid taking steps too large if abs(step) > 0.1: step = 0.1*step/abs(step) - + x0 += step - emax = 0.00001 # 0.01 mV tolerance + emax = 0.00001 # 0.01 mV tolerance if abs(f0) < emax and n > 8: return x0 xlast = x0 @@ -187,7 +187,7 @@ def cathode_curr(E): # the cathode potential. ee = E + oxide_c.electricPotential() cathode_bulk.setElectricPotential(ee) - + # get the species net production rates due to the cathode-side TPB # reaction mechanism. The production rate array has the values for # the neighbor species in the order listed in the .cti file, @@ -277,13 +277,13 @@ for n in range(100): # note that both the bulk and the surface potentials must be set oxide_c.setElectricPotential(phi_oxide_c) - oxide_surf_c.setElectricPotential(phi_oxide_c) + oxide_surf_c.setElectricPotential(phi_oxide_c) # Find the value of the cathode potential relative to the # cathode-side electrolyte that yields the same current density # as the anode current density Ec = NewtonSolver(cathode_curr, xstart = Ec0 + 0.1, C = curr) - + cathode_bulk.setElectricPotential(phi_oxide_c + Ec); # write the current density, anode and cathode overpotentials, diff --git a/samples/python/gasdynamics/isentropic/isentropic.py b/samples/python/gasdynamics/isentropic/isentropic.py index 6ae9b6722..f753ecf8b 100755 --- a/samples/python/gasdynamics/isentropic/isentropic.py +++ b/samples/python/gasdynamics/isentropic/isentropic.py @@ -5,7 +5,7 @@ import math def soundspeed(gas): """The speed of sound. Assumes an ideal gas.""" - + # if gas.isIdealGas(): gamma = gas.cp_mass()/gas.cv_mass() return math.sqrt(gamma * GasConstant @@ -14,11 +14,11 @@ def soundspeed(gas): # raise "non-ideal not implemented." - + def isentropic(g = None): """ ISENTROPIC isentropic, adiabatic flow example - + In this example, the area ratio vs. Mach number curve is computed. If a gas object is supplied, it will be used for the calculations, with the stagnation state given by the input gas @@ -39,24 +39,24 @@ def isentropic(g = None): s0 = gas.entropy_mass() h0 = gas.enthalpy_mass() p0 = gas.pressure() - + mdot = 1 # arbitrary amin = 1.e14 - + data = zeros((200,4),'d') - + # compute values for a range of pressure ratios for r in range(200): p = p0*(r+1)/201.0 # set the state using (p,s0) gas.set(S = s0, P = p) - + h = gas.enthalpy_mass() rho = gas.density() - + v2 = 2.0*(h0 - h) # h + V^2/2 = h0 - v = math.sqrt(v2) + v = math.sqrt(v2) area = mdot/(rho*v); # rho*v*A = constant if area < amin: amin = area data[r,:] = [area, v/soundspeed(gas), gas.temperature(), p/p0] @@ -65,7 +65,7 @@ def isentropic(g = None): return data - + if __name__ == "__main__": print isentropic.__doc__ @@ -78,13 +78,7 @@ if __name__ == "__main__": xlabel('Mach Number') title('Isentropic Flow: Area Ratio vs. Mach Number') show() - + except: print 'area ratio, Mach number, temperature, pressure ratio' print data - - - - - - diff --git a/samples/python/gasdynamics/soundSpeed/soundSpeed.py b/samples/python/gasdynamics/soundSpeed/soundSpeed.py index 7e2dfaa6b..ad4e0ee34 100644 --- a/samples/python/gasdynamics/soundSpeed/soundSpeed.py +++ b/samples/python/gasdynamics/soundSpeed/soundSpeed.py @@ -28,7 +28,7 @@ def equilSoundSpeeds(gas, rtol = 1.0e-6, maxiter = 5000): # save the density for this case for the frozen sound speed rho_frozen = gas.density() - + # now equilibrate the gas holding S and P constant gas.equilibrate("SP", loglevel=0, rtol = rtol, maxiter = maxiter) # , rtol = 1.0e-3, maxsteps=10000) @@ -52,12 +52,10 @@ def equilSoundSpeeds(gas, rtol = 1.0e-6, maxiter = 5000): # test program if __name__ == "__main__": - + gas = GRI30() gas.set(X = 'CH4:1.00, O2:2.0, N2:7.52') for n in range(27): temp = 300.0 + n*100.0 gas.set(T = temp, P = OneAtm) print temp, equilSoundSpeeds(gas) - - diff --git a/samples/python/kinetics/ratecoeffs.py b/samples/python/kinetics/ratecoeffs.py index be0d0aea2..0a91140f5 100644 --- a/samples/python/kinetics/ratecoeffs.py +++ b/samples/python/kinetics/ratecoeffs.py @@ -29,7 +29,7 @@ def show_rate_coefficients(mech, doIrrev = 0): for i in range(nr): print '%40s %12.5g %12.5g ' % (eqs[i], kf[i], kr[i]) - + print 'units: kmol, m, s' @@ -42,7 +42,5 @@ if __name__ == "__main__": mech = importPhase(sys.argv[1], sys.argv[2]) else: mech = GRI30() - + show_rate_coefficients(mech) - - diff --git a/samples/python/liquid_vapor/critProperties/critProperties.py b/samples/python/liquid_vapor/critProperties/critProperties.py index c2b42c61d..798bdd427 100644 --- a/samples/python/liquid_vapor/critProperties/critProperties.py +++ b/samples/python/liquid_vapor/critProperties/critProperties.py @@ -25,5 +25,3 @@ for name in fluids.keys(): mw = f.meanMolecularWeight() zc = pc*mw/(rc*GasConstant*tc) print '%20s %10.4g %10.4G %10.4G' % (name, tc, pc, zc) - - diff --git a/samples/python/liquid_vapor/rankine/rankine.py b/samples/python/liquid_vapor/rankine/rankine.py index e4095eec8..343b71ffa 100644 --- a/samples/python/liquid_vapor/rankine/rankine.py +++ b/samples/python/liquid_vapor/rankine/rankine.py @@ -51,7 +51,7 @@ def expand(fluid, pfinal, eta): def printState(n, fluid): print '\n\n***************** State '+`n`+' ******************\n', fluid - + ############################################################### @@ -85,10 +85,3 @@ printState(4,w) eff = (turbine_work - pump_work)/heat_added print 'efficiency = ',eff - - - - - - - diff --git a/samples/python/misc/rxnpath1.py b/samples/python/misc/rxnpath1.py index b386c2243..054f36377 100755 --- a/samples/python/misc/rxnpath1.py +++ b/samples/python/misc/rxnpath1.py @@ -31,7 +31,7 @@ output_urldir = 'http://your.http.server/' #----------------------------------------------------------------------- # these lines can be replaced by any commands that generate # an object of a class derived from class Kinetics (such as IdealGasMix) -# in some state. +# in some state. gas = GRI30() gas.setState_TPX(2500.0, OneAtm, 'CH4:0.4, O2:1, N2:3.76') gas.equilibrate('TP') @@ -52,5 +52,3 @@ if len(opts) > 1 and opts[1] == "-view": # graphics format. Must be one of png, svg, gif, or jpg fmt = 'svg' rxnpath.view(url, fmt) - - diff --git a/samples/python/reactors/combustor_sim/combustor.py b/samples/python/reactors/combustor_sim/combustor.py index 752aaac1c..96415100c 100644 --- a/samples/python/reactors/combustor_sim/combustor.py +++ b/samples/python/reactors/combustor_sim/combustor.py @@ -80,4 +80,3 @@ while tnow < tfinal: writeCSV(f, [tnow, combustor.temperature(), tres] +list(combustor.moleFractions())) f.close() - diff --git a/samples/python/reactors/mix1_sim/mix1.py b/samples/python/reactors/mix1_sim/mix1.py index f43d2df34..ff871cb24 100644 --- a/samples/python/reactors/mix1_sim/mix1.py +++ b/samples/python/reactors/mix1_sim/mix1.py @@ -81,4 +81,3 @@ for n in range(30): # view the state of the gas in the mixer print mixer.contents() - diff --git a/samples/python/reactors/mix2_sim/mix2.py b/samples/python/reactors/mix2_sim/mix2.py index 653e731b6..ad3c269c7 100644 --- a/samples/python/reactors/mix2_sim/mix2.py +++ b/samples/python/reactors/mix2_sim/mix2.py @@ -92,7 +92,7 @@ for n in range(30): 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(), @@ -100,4 +100,3 @@ for n in range(30): # view the state of the gas in the mixer print mixer.contents() - diff --git a/samples/python/reactors/piston_sim/piston.py b/samples/python/reactors/piston_sim/piston.py index 1430e5e5f..a1c5983a5 100644 --- a/samples/python/reactors/piston_sim/piston.py +++ b/samples/python/reactors/piston_sim/piston.py @@ -60,10 +60,10 @@ for n in range(30): v1.append(r1.volume()) v2.append(r2.volume()) v.append(r1.volume() + r2.volume()) - xco.append(r2.moleFraction('CO')) + xco.append(r2.moleFraction('CO')) xh2.append(r1.moleFraction('H2')) - + # plot the results if matplotlib is installed. # see http://matplotlib.sourceforge.net to get it args = sys.argv @@ -93,7 +93,6 @@ if len(args) > 1 and (args[1] == '-plot' or except: print """matplotlib required. http://matplotlib.sourceforge.net""" - + else: print """To view a plot of these results, run this script with the option -plot""" - diff --git a/samples/python/reactors/reactor1_sim/reactor1.py b/samples/python/reactors/reactor1_sim/reactor1.py index b6b60fedf..dd0a4bf9c 100644 --- a/samples/python/reactors/reactor1_sim/reactor1.py +++ b/samples/python/reactors/reactor1_sim/reactor1.py @@ -34,10 +34,10 @@ for n in range(100): sim.advance(time) tim[n] = time data[n,0] = r.temperature() - data[n,1] = r.moleFraction('OH') + 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(), + data[n,3] = r.moleFraction('H2') + print '%10.3e %10.3f %10.3f %14.6e' % (sim.time(), r.temperature(), r.pressure(), r.intEnergy_mass()) diff --git a/samples/python/reactors/reactor2_sim/reactor2.py b/samples/python/reactors/reactor2_sim/reactor2.py index 8ea267ef1..90a15909e 100644 --- a/samples/python/reactors/reactor2_sim/reactor2.py +++ b/samples/python/reactors/reactor2_sim/reactor2.py @@ -98,7 +98,7 @@ print 'Directory: '+os.getcwd() args = sys.argv if len(args) > 1 and args[1] == '-plot': - try: + try: from matplotlib.pylab import * clf subplot(2,2,1) @@ -106,22 +106,21 @@ if len(args) > 1 and args[1] == '-plot': legend(['Reactor 1','Reactor 2'],2) xlabel('Time (s)'); ylabel('Temperature (K)'); - + subplot(2,2,2) plot(tm, pres[:,0],'g-',tm, pres[:,1],'b-') legend(['Reactor 1','Reactor 2'],2) xlabel('Time (s)'); ylabel('Pressure (Bar)'); - + subplot(2,2,3) plot(tm, vol[:,0],'g-',tm, vol[:,1],'b-') legend(['Reactor 1','Reactor 2'],2) xlabel('Time (s)'); - ylabel('Volume (m^3)'); + ylabel('Volume (m^3)'); show() except: pass else: print """To view a plot of these results, run this script with the option -plot""" - diff --git a/samples/python/reactors/sensitivity_sim/sensitivity1.py b/samples/python/reactors/sensitivity_sim/sensitivity1.py index 881f524e3..0bf7ff8d1 100644 --- a/samples/python/reactors/sensitivity_sim/sensitivity1.py +++ b/samples/python/reactors/sensitivity_sim/sensitivity1.py @@ -47,17 +47,17 @@ for n in range(np): sim.advance(time) tim[n] = time data[n,0] = r.temperature() - data[n,1] = r.moleFraction('OH') + 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 + + # 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(), + + 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]) @@ -88,7 +88,7 @@ if len(args) > 1 and args[1] == '-plot': plot(tim,data[:,4],'-',tim,data[:,5],'-g') legend([r.sensParamName(2),r.sensParamName(3)],'best') xlabel('Time (s)'); - ylabel('OH Sensitivity'); + ylabel('OH Sensitivity'); show() except: print 'could not make plots' diff --git a/samples/python/reactors/surf_pfr_sim/surf_pfr.py b/samples/python/reactors/surf_pfr_sim/surf_pfr.py index 639e227cf..eeb6bade9 100644 --- a/samples/python/reactors/surf_pfr_sim/surf_pfr.py +++ b/samples/python/reactors/surf_pfr_sim/surf_pfr.py @@ -33,7 +33,7 @@ cat_area_per_vol = 1000.0 / cm # Catalyst particle surface area # per unit volume velocity = 40.0 * cm / minute # gas velocity porosity = 0.3 # Catalyst bed porosity - + # input file containing the surface reaction mechanism cti_file = 'methane_pox_on_pt.cti' @@ -90,79 +90,79 @@ mass_flow_rate = velocity * rho0 * area # reactor, integrating each one to steady state. for n in range(NReactors): - - # create a new reactor - r = Reactor(contents = gas, energy = 'off', volume = rvol) - # create a reservoir to represent the reactor immediately - # upstream. Note that the gas object is set already to the - # state of the upstream reactor - upstream = Reservoir(gas, name = 'upstream') + # create a new reactor + r = Reactor(contents = gas, energy = 'off', volume = rvol) - # create a reservoir for the reactor to exhaust into. The - # composition of this reservoir is irrelevant. - downstream = Reservoir(gas, name = 'downstream') + # create a reservoir to represent the reactor immediately + # upstream. Note that the gas object is set already to the + # state of the upstream reactor + upstream = Reservoir(gas, name = 'upstream') - # use a 'Wall' object to implement the reacting surface in the - # reactor. Since walls have to be installed between two - # reactors/reserviors, we'll install it between the upstream - # reservoir and the reactor. The area is set to the desired - # catalyst area in the reactor, and surface reactions are - # included only on the side facing the reactor. - w = Wall(left = upstream, right = r, A = cat_area, kinetics = [None, surf]) - # We need a valve between the reactor and the downstream reservoir. - # This will determine the pressure in the reactor. Set Kv large - # enough that the pressure difference is very small. - v = Valve(upstream = r, downstream = downstream, Kv = 3.0e-6) + # create a reservoir for the reactor to exhaust into. The + # composition of this reservoir is irrelevant. + downstream = Reservoir(gas, name = 'downstream') - # The mass flow rate into the reactor will be fixed by using a - # MassFlowController object. - m = MassFlowController(upstream = upstream, - downstream = r, mdot = mass_flow_rate) + # use a 'Wall' object to implement the reacting surface in the + # reactor. Since walls have to be installed between two + # reactors/reserviors, we'll install it between the upstream + # reservoir and the reactor. The area is set to the desired + # catalyst area in the reactor, and surface reactions are + # included only on the side facing the reactor. + w = Wall(left = upstream, right = r, A = cat_area, kinetics = [None, surf]) + # We need a valve between the reactor and the downstream reservoir. + # This will determine the pressure in the reactor. Set Kv large + # enough that the pressure difference is very small. + v = Valve(upstream = r, downstream = downstream, Kv = 3.0e-6) - sim = ReactorNet([upstream, r, downstream]) + # The mass flow rate into the reactor will be fixed by using a + # MassFlowController object. + m = MassFlowController(upstream = upstream, + downstream = r, mdot = mass_flow_rate) - # set relative and absolute tolerances on the simulation - sim.setTolerances(rtol = 1.0e-4, atol = 1.0e-11) - - time = 0 - while 1 > 0: - time = time + dt - sim.advance(time) - - # check whether surface coverages are in steady - # state. This will be the case if the creation and - # destruction rates for a surface (but not gas) species - # are equal. - alldone = 1 + sim = ReactorNet([upstream, r, downstream]) - # Note: netProduction = creation - destruction. By - # supplying the surface object as an argument, only the - # values for the surface species are returned by these - # 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 relative and absolute tolerances on the simulation + sim.setTolerances(rtol = 1.0e-4, atol = 1.0e-11) - # 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() + time = 0 + while 1 > 0: + time = time + dt + sim.advance(time) - dist = n*rlen * 1.0e3 # distance in mm + # check whether surface coverages are in steady + # state. This will be the case if the creation and + # destruction rates for a surface (but not gas) species + # are equal. + alldone = 1 - # 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())) + # Note: netProduction = creation - destruction. By + # supplying the surface object as an argument, only the + # values for the surface species are returned by these + # 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() @@ -179,5 +179,3 @@ f.close() element = 'C' rxnpath.write(surf, element, 'carbon_pathways.dot') - - diff --git a/samples/python/run_examples.py b/samples/python/run_examples.py index 68e3112d6..687cbcf9b 100644 --- a/samples/python/run_examples.py +++ b/samples/python/run_examples.py @@ -3,7 +3,7 @@ from os.path import walk pycmd = os.getenv("PYTHON_CMD") if not pycmd: pycmd = "python" - + def run_example(dir, file): print "******************************************" print " Example "+file+" ("+dir+")" @@ -16,7 +16,7 @@ def run_examples(a, dir, files): for f in files: base, ext = os.path.splitext(f) print base, " <> ",ext - if dir <> "." and ext == ".py": + if dir <> "." and ext == ".py": run_example(dir, f) walk(".",run_examples,None) diff --git a/samples/python/surface_chemistry/catcomb_stagflow/catcomb.py b/samples/python/surface_chemistry/catcomb_stagflow/catcomb.py index 32588e0a0..948618e6e 100644 --- a/samples/python/surface_chemistry/catcomb_stagflow/catcomb.py +++ b/samples/python/surface_chemistry/catcomb_stagflow/catcomb.py @@ -1,5 +1,5 @@ # CATCOMB -- Catalytic combustion of methane on platinum. -# +# # This script solves a catalytic combustion problem. A stagnation flow # is set up, with a gas inlet 10 cm from a platinum surface at 900 # K. The lean, premixed methane/air mixture enters at ~ 6 cm/s (0.06 @@ -49,10 +49,10 @@ tol_ts = [1.0e-4, 1.0e-9] # [rtol, atol] for time stepping loglevel = 1 # amount of diagnostic output # (0 to 5) - + refine_grid = 1 # 1 to enable refinement, 0 to # disable - + ################ create the gas object ######################## # # This object will be used to evaluate all thermodynamic, kinetic, @@ -60,7 +60,7 @@ refine_grid = 1 # 1 to enable refinement, 0 to # # The gas phase will be taken from the definition of phase 'gas' in # input file 'ptcombust.cti,' which is a stripped-down version of -# GRI-Mech 3.0. +# GRI-Mech 3.0. gas = importPhase('ptcombust.cti','gas') gas.set(T = tinlet, P = p, X = comp1) @@ -71,7 +71,7 @@ gas.set(T = tinlet, P = p, X = comp1) # rates. It will be created from the interface definition 'Pt_surf' # in input file 'ptcombust.cti,' which implements the reaction # mechanism of Deutschmann et al., 1995 for catalytic combustion on -# platinum. +# platinum. # surf_phase = importInterface('ptcombust.cti','Pt_surf', [gas]) surf_phase.setTemperature(tsurf) @@ -79,7 +79,7 @@ surf_phase.setTemperature(tsurf) # integrate the coverage equations in time for 1 s, holding the gas # composition fixed to generate a good starting estimate for the -# coverages. +# coverages. surf_phase.advanceCoverages(1.0) # create the object that simulates the stagnation flow, and specify an @@ -94,7 +94,7 @@ sim.surface.set(T = tsurf) # Set error tolerances sim.set(tol = tol_ss, tol_time = tol_ts) -# Method 'init' must be called before beginning a simulation +# Method 'init' must be called before beginning a simulation sim.init() # Show the initial solution estimate @@ -172,10 +172,10 @@ cov = sim.coverages() names = surf_phase.speciesNames() for n in range(len(names)): writeCSV(f, [names[n], cov[n]]) - + f.close() print 'solution saved to catcomb.csv' -# show some statistics +# show some statistics sim.showStats() diff --git a/samples/python/surface_chemistry/diamond_cvd/diamond.py b/samples/python/surface_chemistry/diamond_cvd/diamond.py index c8c9f8a86..07cf293e9 100644 --- a/samples/python/surface_chemistry/diamond_cvd/diamond.py +++ b/samples/python/surface_chemistry/diamond_cvd/diamond.py @@ -42,7 +42,3 @@ for n in range(20): f.close() print 'H concentration, growth rate, and surface coverages written to file diamond.csv' - - - - diff --git a/samples/python/tut1.py b/samples/python/tut1.py index 27eed4980..887689aa9 100755 --- a/samples/python/tut1.py +++ b/samples/python/tut1.py @@ -35,7 +35,7 @@ print gas1 # heat capacity c_p 14311.8 2.885e+04 J/K # heat capacity c_v 10187.3 2.054e+04 J/K -# X Y +# X Y # ------------- ------------ # H2 1.000000e+00 1.000000e+00 # H 0.000000e+00 0.000000e+00 @@ -132,8 +132,8 @@ print gas1 # density 0.081896 kg/m^3 # mean mol. weight 2.01594 amu # -# X Y -# ------------- ------------ +# X Y +# ------------- ------------ # H2 1.000000e+000 1.000000e+000 # (other species not shown) # @@ -156,7 +156,7 @@ print gas1 # b) Setting the pressure is done holding temperature and # composition fixed. (The density changes.) -# +# # c) Setting the composition is done holding temperature # and density fixed. (The pressure changes). # @@ -196,7 +196,7 @@ print gas1 # heat capacity c_p 1304.4 3.604e+04 J/K # heat capacity c_v 1003.52 2.773e+04 J/K -# X Y +# X Y # ------------- ------------ # H2 0.000000e+00 0.000000e+00 # H 0.000000e+00 0.000000e+00 @@ -286,9 +286,3 @@ print gas1 # To set the mass fractions to equal values: gas1.set(Y = x) print gas1 - - - - - - diff --git a/samples/python/tut2.py b/samples/python/tut2.py index cfdfbc649..8448fdbcd 100755 --- a/samples/python/tut2.py +++ b/samples/python/tut2.py @@ -117,6 +117,3 @@ diamonnd_surf2 = importInterface('diamond.xml','diamond_100', # # ck2cti -i mech.inp -t therm.dat -tr tran.dat -id mymech > mech.cti # - - - diff --git a/samples/python/tut3.py b/samples/python/tut3.py index 5c3146513..473ee0037 100644 --- a/samples/python/tut3.py +++ b/samples/python/tut3.py @@ -7,7 +7,7 @@ print """ ###################################################### # Suppose you have created a Cantera object and want to know what -# methods are available for it, and get help on using the methods. +# methods are available for it, and get help on using the methods. from Cantera import * g = GRI30() @@ -42,7 +42,7 @@ help(g.__class__) # do this instead: Run 'pythonw' interactively (not 'python'), import # module 'pydoc', and call function 'gui': # -# pythonw +# pythonw # >>> import pydoc # >>> pydoc.gui() # diff --git a/samples/python/tut4.py b/samples/python/tut4.py index fc873eb15..e68a1121c 100755 --- a/samples/python/tut4.py +++ b/samples/python/tut4.py @@ -50,8 +50,8 @@ g.equilibrate('HP') rf = g.fwdRatesOfProgress() rr = g.revRatesOfProgress() for i in range(g.nReactions()): - if g.isReversible(i) and rf[i] <> 0.0: - print ' %4i %10.4g ' % (i, (rf[i] - rr[i])/rf[i]) + if g.isReversible(i) and rf[i] <> 0.0: + print ' %4i %10.4g ' % (i, (rf[i] - rr[i])/rf[i]) # If the magnitudes of the numbers in this list are all very small, # then each reversible reaction is very nearly equilibrated, which # only occurs if the gas is in chemical equilibrium. @@ -73,4 +73,4 @@ for i in range(g.nReactions()): # does a few other things to generate a good starting guess and to # produce a reasonably robust algorithm. If you want to know more # about the details, look at the on-line documented source code of -# Cantera C++ class 'ChemEquil.h' at http://www.cantera.org. +# Cantera C++ class 'ChemEquil.h' at http://www.cantera.org. diff --git a/src/fortran/genf.py b/src/fortran/genf.py index ba7cca383..9b48328e1 100644 --- a/src/fortran/genf.py +++ b/src/fortran/genf.py @@ -69,7 +69,7 @@ def writeinterface(fint, rtype, name, args): elif a[0] in _c2fout: fint.write(' '+_c2fout[a[0]]+', intent(out) :: '+a[1]+arr+'\n') fint.write(' end function '+name+'\n\n') - + def writef90(fmod, rtype, otype, hndl, name, args): subroutine = 0 @@ -82,7 +82,7 @@ def writef90(fmod, rtype, otype, hndl, name, args): if name[-1] == '_': name = name[:-1] wname = 'ct'+name[1:] - + s += wname + '(' argstr='self, ' for a in args[1:]: @@ -98,7 +98,7 @@ def writef90(fmod, rtype, otype, hndl, name, args): if a[0][0] == 'd': arr = '(*)' else: - arr = '' + arr = '' if a[0] in _c2fin: fmod.write(' '+_c2fin[a[0]]+', intent(in) :: '+a[1]+arr+'\n') elif a[0] in _c2fout: @@ -106,7 +106,7 @@ def writef90(fmod, rtype, otype, hndl, name, args): if subroutine: s = ' self%err = '+name+'(self%'+hndl+', ' else: - s = ' '+wname+' = '+name+'(self%'+hndl+', ' + s = ' '+wname+' = '+name+'(self%'+hndl+', ' argstr = '' for a in args[1:]: if a[0] <> 'ftnlen': @@ -117,9 +117,9 @@ def writef90(fmod, rtype, otype, hndl, name, args): fmod.write(s+'\n end subroutine '+wname+'\n\n') else: fmod.write(s+'\n end function '+wname+'\n\n') - - + + fname = sys.argv[1] # fctxml otype = sys.argv[2] # XML_Node hndl = sys.argv[3] # xml_id @@ -200,6 +200,3 @@ for line in lines: fmod.write('end module '+base+'\n') fmod.close() - - - diff --git a/src/fortran/makect.py b/src/fortran/makect.py index 7c93f393f..02731a404 100644 --- a/src/fortran/makect.py +++ b/src/fortran/makect.py @@ -11,7 +11,7 @@ for m in lines: if len(toks) == 2: if toks[0] == 'module': mods.append(toks[1]) - + le = line.find('end') lf = line.find('function') ls = line.find('subroutine') @@ -39,7 +39,6 @@ for fn in funcs: fout.write('\n INTERFACE '+fn+'\n') for cf in gen[fn]: fout.write(' MODULE PROCEDURE '+cf+'\n') - fout.write(' END INTERFACE '+fn+'\n') + fout.write(' END INTERFACE '+fn+'\n') fout.write('\nEND MODULE CANTERA\n\n') - diff --git a/test_problems/diamondSurf/run_diamond.py b/test_problems/diamondSurf/run_diamond.py index 802d5add5..02c155034 100644 --- a/test_problems/diamondSurf/run_diamond.py +++ b/test_problems/diamondSurf/run_diamond.py @@ -14,12 +14,12 @@ ih = g.speciesIndex('H') f = open('d.csv', 'w') for n in range (20): - x[ih] /= 1.4 - g.setState_TPX(t, p, x) - # integrate the coverage equations to steady state - d.advanceCoverages(100.0) - cdot = d.netProductionRates(phase = dbulk) [0] #net rate of C(d production /m^2 - mdot = mw * cdot - linear_rate = mdot/dbulk.density() - writeCSV(f, [x[ih], rate]+list(d.coverages())) + x[ih] /= 1.4 + g.setState_TPX(t, p, x) + # integrate the coverage equations to steady state + d.advanceCoverages(100.0) + cdot = d.netProductionRates(phase = dbulk) [0] #net rate of C(d production /m^2 + mdot = mw * cdot + linear_rate = mdot/dbulk.density() + writeCSV(f, [x[ih], rate]+list(d.coverages())) f.close() diff --git a/test_problems/diamondSurf/tdia_a.py b/test_problems/diamondSurf/tdia_a.py index 23df6bc1b..13a9cb42f 100755 --- a/test_problems/diamondSurf/tdia_a.py +++ b/test_problems/diamondSurf/tdia_a.py @@ -26,6 +26,3 @@ for n in range(20): print x[ih], rate*1.0e6*3600.0 writeCSV(f,[x[ih],rate]+list(d.coverages())) f.close() - - - diff --git a/test_problems/python/flame1/flame1.py b/test_problems/python/flame1/flame1.py index 6433fcc9a..e64eb37d0 100755 --- a/test_problems/python/flame1/flame1.py +++ b/test_problems/python/flame1/flame1.py @@ -32,9 +32,9 @@ tol_ts = [1.0e-5, 1.0e-11] # [rtol atol] for time stepping loglevel = 1 # amount of diagnostic output (0 # to 5) - + refine_grid = 1 # 1 to enable refinement, 0 to - # disable + # disable ################ create the gas object ######################## @@ -86,4 +86,3 @@ print 'solution saved to flame1.csv' # Disabled, because timings cause text differences # f.showStats() - diff --git a/test_problems/python/frac.py b/test_problems/python/frac.py index d7a76c00c..709ad8b66 100644 --- a/test_problems/python/frac.py +++ b/test_problems/python/frac.py @@ -39,7 +39,7 @@ print '%12s %10.4e %10.4e ' % (gas.speciesName(ih2o), print '\nDestruction Rates:' for k in range(nsp-1): print '%12s %10.4e %10.4e ' % (gas.speciesName(k), - ddot[k], ddot[k]/fwd_rop[1]) + ddot[k], ddot[k]/fwd_rop[1]) print '%12s %10.4e %10.4e ' % (gas.speciesName(ih2o), ddot[ih2o], ddot[ih2o]/fwd_rop[0]) print @@ -64,11 +64,10 @@ r1 = fwd_rop[1] r2 = cproduct*kf[1] diff12 = (r1 - r2)/(r1 + r2) if (abs(diff12) < 1.0E-10) : - diff12 = 0.0 + diff12 = 0.0 print r1, r2, diff12 print print 'Reactant stoichiometric coefficients:' print gas.reactantStoichCoeffs() print 'Product stoichiometric coefficients:' print gas.productStoichCoeffs() - diff --git a/test_problems/python/tut1/tut1.py b/test_problems/python/tut1/tut1.py index 27eed4980..887689aa9 100755 --- a/test_problems/python/tut1/tut1.py +++ b/test_problems/python/tut1/tut1.py @@ -35,7 +35,7 @@ print gas1 # heat capacity c_p 14311.8 2.885e+04 J/K # heat capacity c_v 10187.3 2.054e+04 J/K -# X Y +# X Y # ------------- ------------ # H2 1.000000e+00 1.000000e+00 # H 0.000000e+00 0.000000e+00 @@ -132,8 +132,8 @@ print gas1 # density 0.081896 kg/m^3 # mean mol. weight 2.01594 amu # -# X Y -# ------------- ------------ +# X Y +# ------------- ------------ # H2 1.000000e+000 1.000000e+000 # (other species not shown) # @@ -156,7 +156,7 @@ print gas1 # b) Setting the pressure is done holding temperature and # composition fixed. (The density changes.) -# +# # c) Setting the composition is done holding temperature # and density fixed. (The pressure changes). # @@ -196,7 +196,7 @@ print gas1 # heat capacity c_p 1304.4 3.604e+04 J/K # heat capacity c_v 1003.52 2.773e+04 J/K -# X Y +# X Y # ------------- ------------ # H2 0.000000e+00 0.000000e+00 # H 0.000000e+00 0.000000e+00 @@ -286,9 +286,3 @@ print gas1 # To set the mass fractions to equal values: gas1.set(Y = x) print gas1 - - - - - - diff --git a/test_problems/python/tut2/tut2.py b/test_problems/python/tut2/tut2.py index 9e3fef050..6c42cfa60 100755 --- a/test_problems/python/tut2/tut2.py +++ b/test_problems/python/tut2/tut2.py @@ -127,8 +127,3 @@ print cc # will get infs because coverages are zero. gg = diamonnd_surf2.chemPotentials() print gg[0], gg[1] - - - - - diff --git a/test_problems/python/tut3/tut3.py b/test_problems/python/tut3/tut3.py index 5c3146513..473ee0037 100644 --- a/test_problems/python/tut3/tut3.py +++ b/test_problems/python/tut3/tut3.py @@ -7,7 +7,7 @@ print """ ###################################################### # Suppose you have created a Cantera object and want to know what -# methods are available for it, and get help on using the methods. +# methods are available for it, and get help on using the methods. from Cantera import * g = GRI30() @@ -42,7 +42,7 @@ help(g.__class__) # do this instead: Run 'pythonw' interactively (not 'python'), import # module 'pydoc', and call function 'gui': # -# pythonw +# pythonw # >>> import pydoc # >>> pydoc.gui() # diff --git a/test_problems/python/tut4/tut4.py b/test_problems/python/tut4/tut4.py index fdaf662dc..9d2639144 100755 --- a/test_problems/python/tut4/tut4.py +++ b/test_problems/python/tut4/tut4.py @@ -50,8 +50,8 @@ g.equilibrate('HP') rf = g.fwdRatesOfProgress() rr = g.revRatesOfProgress() for i in range(g.nReactions()): - if g.isReversible(i) and rf[i] <> 0.0: - print ' %4i %10.3g %10.3g ' % (i, rf[i] , rr[i]) + if g.isReversible(i) and rf[i] <> 0.0: + print ' %4i %10.3g %10.3g ' % (i, rf[i] , rr[i]) # print ' %4i %10.4g ' % (i, (rf[i] - rr[i])/rf[i]) # (modification for test suite -> shouldn't print nearly zero numbers) # If the magnitudes of the numbers in this list are all very small, @@ -75,4 +75,4 @@ for i in range(g.nReactions()): # does a few other things to generate a good starting guess and to # produce a reasonably robust algorithm. If you want to know more # about the details, look at the on-line documented source code of -# Cantera C++ class 'ChemEquil.h' at http://www.cantera.org. +# Cantera C++ class 'ChemEquil.h' at http://www.cantera.org.