diff --git a/interfaces/cython/cantera/__init__.py b/interfaces/cython/cantera/__init__.py index d5b796035..29a0a7426 100644 --- a/interfaces/cython/cantera/__init__.py +++ b/interfaces/cython/cantera/__init__.py @@ -3,4 +3,4 @@ from ._cantera import __version__, _have_sundials from .liquidvapor import * import os as _os -addDirectory(_os.path.join(_os.path.dirname(__file__), 'data')) +add_directory(_os.path.join(_os.path.dirname(__file__), 'data')) diff --git a/interfaces/cython/cantera/_cantera.pxd b/interfaces/cython/cantera/_cantera.pxd index 229b8db12..b38039d6e 100644 --- a/interfaces/cython/cantera/_cantera.pxd +++ b/interfaces/cython/cantera/_cantera.pxd @@ -520,8 +520,8 @@ cdef class _SolutionBase: cdef CxxThermoPhase* thermo cdef CxxKinetics* kinetics cdef CxxTransport* transport - cdef int thermoBasis - cdef np.ndarray _selectedSpecies + cdef int thermo_basis + cdef np.ndarray _selected_species cdef object parent cdef class Kinetics(_SolutionBase): @@ -551,13 +551,13 @@ cdef class WallSurface: cdef class Wall: cdef CxxWall* wall - cdef WallSurface leftSurface - cdef WallSurface rightSurface - cdef object _velocityFunc - cdef object _heatFluxFunc + cdef WallSurface left_surface + cdef WallSurface right_surface + cdef object _velocity_func + cdef object _heat_flux_func cdef str name cdef class FlowDevice: cdef CxxFlowDevice* dev - cdef Func1 _rateFunc + cdef Func1 _rate_func cdef str name diff --git a/interfaces/cython/cantera/base.pyx b/interfaces/cython/cantera/base.pyx index d1a3021c0..b351b5489 100644 --- a/interfaces/cython/cantera/base.pyx +++ b/interfaces/cython/cantera/base.pyx @@ -13,8 +13,8 @@ cdef class _SolutionBase: self.kinetics = other.kinetics self.transport = other.transport - self.thermoBasis = other.thermoBasis - self._selectedSpecies = other._selectedSpecies.copy() + self.thermo_basis = other.thermo_basis + self._selected_species = other._selected_species.copy() return # Instantiate a set of new Cantera C++ objects @@ -51,7 +51,7 @@ cdef class _SolutionBase: # Initialization of transport is deferred to Transport.__init__ self.transport = NULL - self._selectedSpecies = np.ndarray(0, dtype=np.integer) + self._selected_species = np.ndarray(0, dtype=np.integer) def __init__(self, *args, **kwargs): if isinstance(self, Transport): @@ -61,20 +61,20 @@ cdef class _SolutionBase: copy = self.__class__(source=self) if isinstance(selection, slice): selection = range(selection.start or 0, - selection.stop or self.nSpecies, + selection.stop or self.n_species, selection.step or 1) - copy.selectedSpecies = selection + copy.selected_species = selection return copy - property selectedSpecies: + property selected_species: def __get__(self): - return list(self._selectedSpecies) + return list(self._selected_species) def __set__(self, species): if isinstance(species, (str, unicode, int)): species = (species,) - self._selectedSpecies.resize(len(species)) + self._selected_species.resize(len(species)) for i,spec in enumerate(species): - self._selectedSpecies[i] = self.speciesIndex(spec) + self._selected_species[i] = self.species_index(spec) def __dealloc__(self): # only delete the C++ objects if this is the parent object diff --git a/interfaces/cython/cantera/constants.pyx b/interfaces/cython/cantera/constants.pyx index 6fcde141e..14ddd8a7f 100644 --- a/interfaces/cython/cantera/constants.pyx +++ b/interfaces/cython/cantera/constants.pyx @@ -13,34 +13,34 @@ cdef extern from "cantera/base/ct_defs.h" namespace "Cantera": cdef double CxxEpsilon_0 "Cantera::epsilon_0" #: Avogadro's Number, /kmol -Avogadro = CxxAvogadro +avogadro = CxxAvogadro #: The ideal gas constant in J/kmo-K -GasConstant = CxxGasConstant +gas_constant = CxxGasConstant #: One atmosphere in Pascals -OneAtm = CxxOneAtm +one_atm = CxxOneAtm #: Boltzmann constant -Boltzmann = CxxBoltzmann +boltzmann = CxxBoltzmann #: Planck constant (J/s) -Planck = CxxPlanck +planck = CxxPlanck #: The Stefan-Boltzmann constant, W/m^2K^4 -StefanBoltz = CxxStefanBoltz +stefan_boltzmann = CxxStefanBoltz #: The charge on an electron (C) -ElectronCharge = CxxElectronCharge +electron_charge = CxxElectronCharge #: The mass of an electron (kg) -ElectronMass = CxxElectronMass +electron_mass = CxxElectronMass #: Faraday constant, C/kmol -Faraday = CxxFaraday +faraday = CxxFaraday #: Speed of Light (m/s). -lightSpeed = CxxLightSpeed +light_speed = CxxLightSpeed #: Permeability of free space :math:`\mu_0` in N/A^2. permeability_0 = CxxPermeability_0 diff --git a/interfaces/cython/cantera/examples/onedim/adiabatic_flame.py b/interfaces/cython/cantera/examples/onedim/adiabatic_flame.py index 6f97c2a12..e0b499963 100644 --- a/interfaces/cython/cantera/examples/onedim/adiabatic_flame.py +++ b/interfaces/cython/cantera/examples/onedim/adiabatic_flame.py @@ -7,7 +7,7 @@ import csv import cantera as ct # Simulation parameters -p = ct.OneAtm # pressure [Pa] +p = ct.one_atm # pressure [Pa] Tin = 300.0 # unburned gas temperature [K] reactants = 'H2:1.1, O2:1, AR:5' # premixed gas composition @@ -23,36 +23,36 @@ gas.TPX = Tin, p, reactants # Flame object f = ct.FreeFlame(gas, initial_grid) -f.flame.setSteadyTolerances(default=tol_ss) -f.flame.setTransientTolerances(default=tol_ts) +f.flame.set_steady_tolerances(default=tol_ss) +f.flame.set_transient_tolerances(default=tol_ts) # Set properties of the upstream fuel-air mixture f.inlet.T = Tin f.inlet.X = reactants -f.showSolution() +f.show_solution() # Solve with the energy equation disabled -f.energyEnabled = False -f.setMaxJacAge(10, 10) -f.setTimeStep(1e-5, [2, 5, 10, 20]) +f.energy_enabled = False +f.set_max_jac_age(10, 10) +f.set_time_step(1e-5, [2, 5, 10, 20]) f.solve(loglevel=loglevel, refine_grid=False) f.save('h2_adiabatic.xml', 'no_energy', 'solution with the energy equation disabled') # Solve with the energy equation enabled -f.setRefineCriteria(ratio=3, slope=0.06, curve=0.12) -f.energyEnabled = True +f.set_refine_criteria(ratio=3, slope=0.06, curve=0.12) +f.energy_enabled = True f.solve(loglevel=loglevel, refine_grid=refine_grid) f.save('h2_adiabatic.xml', 'energy', 'solution with mixture-averaged transport') -f.showSolution() +f.show_solution() print('mixture-averaged flamespeed = {:7f} m/s'.format(f.u[0])) # Solve with multi-component transport properties -f.transportModel = 'Multi' +f.transport_model = 'Multi' f.solve(loglevel, refine_grid) -f.showSolution() +f.show_solution() print('multicomponent flamespeed = {:7f} m/s'.format(f.u[0])) f.save('h2_adiabatic.xml','energy_multi', 'solution with multicomponent transport') @@ -66,7 +66,7 @@ V = f.V with open('h2_adiabatic.csv', 'w') as csvfile: writer = csv.writer(csvfile) writer.writerow(['z (m)', 'u (m/s)', 'V (1/s)', 'T (K)', 'rho (kg/m3)'] + - list(gas.speciesNames)) - for n in range(f.flame.nPoints): - f.setGasState(n) + list(gas.species_names)) + for n in range(f.flame.n_points): + f.set_gas_state(n) writer.writerow([z[n], u[n], V[n], T[n], gas.density] + list(gas.X)) diff --git a/interfaces/cython/cantera/examples/onedim/burner_flame.py b/interfaces/cython/cantera/examples/onedim/burner_flame.py index aa1790cab..acde753c8 100644 --- a/interfaces/cython/cantera/examples/onedim/burner_flame.py +++ b/interfaces/cython/cantera/examples/onedim/burner_flame.py @@ -5,7 +5,7 @@ A burner-stabilized lean premixed hydrogen-oxygen flame at low pressure. import cantera as ct import csv -p = 0.05 * ct.OneAtm +p = 0.05 * ct.one_atm tburner = 373.0 mdot = 0.06 reactants = 'H2:1.5, O2:1, AR:7' # premixed gas composition @@ -26,28 +26,28 @@ f.burner.T = tburner f.burner.X = reactants f.burner.mdot = mdot -f.setInitialGuess() -f.flame.setSteadyTolerances(default=tol_ss) -f.flame.setTransientTolerances(default=tol_ts) -f.showSolution() +f.set_initial_guess() +f.flame.set_steady_tolerances(default=tol_ss) +f.flame.set_transient_tolerances(default=tol_ts) +f.show_solution() -f.energyEnabled = False -f.setMaxJacAge(10, 10) +f.energy_enabled = False +f.set_max_jac_age(10, 10) f.solve(loglevel, refine_grid=False) f.save('h2_burner_flame.xml', 'no_energy', 'solution with the energy equation disabled') -f.setRefineCriteria(ratio=3.0, slope=0.05, curve=0.1) -f.energyEnabled = True +f.set_refine_criteria(ratio=3.0, slope=0.05, curve=0.1) +f.energy_enabled = True f.solve(loglevel, refine_grid) f.save('h2_burner_flame.xml', 'energy', 'solution with the energy equation enabled') #print('mixture-averaged flamespeed = ', f.u[0]) -f.transportModel = 'Multi' +f.transport_model = 'Multi' f.solve(loglevel, refine_grid) -f.showSolution() +f.show_solution() print('multicomponent flamespeed = ', f.u[0]) f.save('h2_burner_flame.xml','energy_multi', 'solution with the energy equation enabled and multicomponent transport') @@ -60,9 +60,9 @@ V = f.V with open('h2_burner_flame.csv', 'w') as csvfile: writer = csv.writer(csvfile) writer.writerow(['z (m)', 'u (m/s)', 'V (1/s)', 'T (K)', 'rho (kg/m3)'] + - list(gas.speciesNames)) - for n in range(f.flame.nPoints): - f.setGasState(n) + list(gas.species_names)) + for n in range(f.flame.n_points): + f.set_gas_state(n) writer.writerow([z[n], u[n], V[n], T[n], gas.density] + list(gas.X)) print('solution saved to h2_burner_flame.csv') diff --git a/interfaces/cython/cantera/examples/onedim/diffusion_flame.py b/interfaces/cython/cantera/examples/onedim/diffusion_flame.py index 1349a3103..3af0b2306 100644 --- a/interfaces/cython/cantera/examples/onedim/diffusion_flame.py +++ b/interfaces/cython/cantera/examples/onedim/diffusion_flame.py @@ -6,7 +6,7 @@ import cantera as ct import numpy as np import csv -p = ct.OneAtm # pressure +p = ct.one_atm # pressure tin_f = 300.0 # fuel inlet temperature tin_o = 300.0 # oxidizer inlet temperature mdot_o = 0.72 # kg/m^2/s @@ -35,18 +35,18 @@ f.oxidizer_inlet.mdot = mdot_o f.oxidizer_inlet.X = comp_o f.oxidizer_inlet.T = tin_o -f.flame.setSteadyTolerances(default=tol_ss) -f.flame.setTransientTolerances(default=tol_ts) +f.flame.set_steady_tolerances(default=tol_ss) +f.flame.set_transient_tolerances(default=tol_ts) -f.setInitialGuess(fuel='C2H6') -f.energyEnabled = False +f.set_initial_guess(fuel='C2H6') +f.energy_enabled = False f.solve(loglevel, refine_grid=False) -f.energyEnabled = True -f.setRefineCriteria(ratio=4, slope=0.2, curve=0.3, prune=0.04) +f.energy_enabled = True +f.set_refine_criteria(ratio=4, slope=0.2, curve=0.3, prune=0.04) f.solve(loglevel, refine_grid=refine_grid) +f.show_solution() -f.showSolution() f.save('c2h6_diffusion.xml') @@ -58,9 +58,9 @@ V = f.V with open('c2h6_diffusion.csv', 'w') as csvfile: writer = csv.writer(csvfile) writer.writerow(['z (m)', 'u (m/s)', 'V (1/s)', 'T (K)', 'rho (kg/m3)'] + - list(gas.speciesNames)) - for n in range(f.flame.nPoints): - f.setGasState(n) + list(gas.species_names)) + for n in range(f.flame.n_points): + f.set_gas_state(n) writer.writerow([z[n], u[n], V[n], T[n], gas.density] + list(gas.X)) print('solution saved to c2h6_diffusion.csv') diff --git a/interfaces/cython/cantera/kinetics.pyx b/interfaces/cython/cantera/kinetics.pyx index 7170f4866..04dff16bf 100644 --- a/interfaces/cython/cantera/kinetics.pyx +++ b/interfaces/cython/cantera/kinetics.pyx @@ -4,16 +4,16 @@ ctypedef void (*kineticsMethod1d)(CxxKinetics*, double*) except + # cause "layout conflicts" when creating derived classes with multiple bases, # e.g. class Solution. [Cython 0.16] cdef np.ndarray get_species_array(Kinetics kin, kineticsMethod1d method): - cdef np.ndarray[np.double_t, ndim=1] data = np.empty(kin.nTotalSpecies) + cdef np.ndarray[np.double_t, ndim=1] data = np.empty(kin.n_total_species) method(kin.kinetics, &data[0]) - # @TODO: Fix _selectedSpecies to work with interface kinetics - if kin._selectedSpecies.size: - return data[kin._selectedSpecies] + # @TODO: Fix _selected_species to work with interface kinetics + if kin._selected_species.size: + return data[kin._selected_species] else: return data cdef np.ndarray get_reaction_array(Kinetics kin, kineticsMethod1d method): - cdef np.ndarray[np.double_t, ndim=1] data = np.empty(kin.nReactions) + cdef np.ndarray[np.double_t, ndim=1] data = np.empty(kin.n_reactions) method(kin.kinetics, &data[0]) return data @@ -25,7 +25,7 @@ cdef class Kinetics(_SolutionBase): a reaction mechanism. """ - property nTotalSpecies: + property n_total_species: """ Total number of species in all phases participating in the kinetics mechanism. @@ -33,144 +33,144 @@ cdef class Kinetics(_SolutionBase): def __get__(self): return self.kinetics.nTotalSpecies() - property nReactions: + property n_reactions: """Number of reactions in the reaction mechanism.""" def __get__(self): return self.kinetics.nReactions() - property nPhases: + property n_phases: """Number of phases in the reaction mechanism.""" def __get__(self): return self.kinetics.nPhases() - property reactionPhaseIndex: + property reaction_phase_index: """The index of the phase where the reactions occur.""" def __get__(self): return self.kinetics.reactionPhaseIndex() - def _checkPhaseIndex(self, n): - if not 0 <= n < self.nPhases: + def _check_phase_index(self, n): + if not 0 <= n < self.n_phases: raise ValueError("Phase index ({}) out of range".format(n)) - def _checkReactionIndex(self, n): - if not 0 <= n < self.nReactions: + def _check_reaction_index(self, n): + if not 0 <= n < self.n_reactions: raise ValueError("Reaction index ({}) out of range".format(n)) - def _checkKineticsSpeciesIndex(self, n): - if not 0 <= n < self.nTotalSpecies: + def _check_kinetics_species_index(self, n): + if not 0 <= n < self.n_total_species: raise ValueError("Kinetics Species index ({}) out of range".format(n)) - def kineticsSpeciesIndex(self, int species, int phase): + def kinetics_species_index(self, int species, int phase): """ The index of species *species* of phase *phase* within arrays returned by methods of class `Kinetics`. """ - self._checkKineticsSpeciesIndex(species) - self._checkPhaseIndex(phase) + self._check_kinetics_species_index(species) + self._check_phase_index(phase) return self.kinetics.kineticsSpeciesIndex(species, phase) - def isReversible(self, int iReaction): - """True if reaction `iReaction` is reversible.""" - self._checkReactionIndex(iReaction) - return self.kinetics.isReversible(iReaction) + def is_reversible(self, int i_reaction): + """True if reaction `i_reaction` is reversible.""" + self._check_reaction_index(i_reaction) + return self.kinetics.isReversible(i_reaction) - def multiplier(self, int iReaction): + def multiplier(self, int i_reaction): """ A scaling factor applied to the rate coefficient for reaction - *iReaction*. Can be used to carry out sensitivity analysis or to - selectively disable a particular reaction. See `setMultiplier`. + *i_reaction*. Can be used to carry out sensitivity analysis or to + selectively disable a particular reaction. See `set_multiplier`. """ - self._checkReactionIndex(iReaction) - return self.kinetics.multiplier(iReaction) + self._check_reaction_index(i_reaction) + return self.kinetics.multiplier(i_reaction) - def setMultiplier(self, double value, int iReaction=-1): + def set_multiplier(self, double value, int i_reaction=-1): """ - Set the multiplier for for reaction *iReaction* to *value*. - If *iReaction* is not specified, then the multiplier for all reactions + Set the multiplier for for reaction *i_reaction* to *value*. + If *i_reaction* is not specified, then the multiplier for all reactions is set to *value*. See `multiplier`. """ - if iReaction == -1: - for iReaction in range(self.nReactions): - self.kinetics.setMultiplier(iReaction, value) + if i_reaction == -1: + for i_reaction in range(self.n_reactions): + self.kinetics.setMultiplier(i_reaction, value) else: - self._checkReactionIndex(iReaction) - self.kinetics.setMultiplier(iReaction, value) + self._check_reaction_index(i_reaction) + self.kinetics.setMultiplier(i_reaction, value) - def reactionType(self, int iReaction): - """Type of reaction *iReaction*.""" - self._checkReactionIndex(iReaction) - return self.kinetics.reactionType(iReaction) + def reaction_type(self, int i_reaction): + """Type of reaction *i_reaction*.""" + self._check_reaction_index(i_reaction) + return self.kinetics.reactionType(i_reaction) - def reactionEquation(self, int iReaction): - """The equation for the specified reaction. See also `reactionEquations`.""" - self._checkReactionIndex(iReaction) - return pystr(self.kinetics.reactionString(iReaction)) + def reaction_equation(self, int i_reaction): + """The equation for the specified reaction. See also `reaction_equations`.""" + self._check_reaction_index(i_reaction) + return pystr(self.kinetics.reactionString(i_reaction)) - def reactionEquations(self, indices=None): + def reaction_equations(self, indices=None): """ Returns a list containing the reaction equation for all reactions in the mechanism (if *indices* is unspecified) or the equations for each reaction in the sequence *indices*. For example:: - >>> gas.reactionEquations() + >>> gas.reaction_equations() ['2 O + M <=> O2 + M', 'O + H + M <=> OH + M', 'O + H2 <=> H + OH', ...] - >>> gas.reactionEquations([2,3]) + >>> gas.reaction_equations([2,3]) ['O + H + M <=> OH + M', 'O + H2 <=> H + OH'] - See also `reactionEquation`. + See also `reaction_equation`. """ if indices is None: - return [self.reactionEquation(i) for i in range(self.nReactions)] + return [self.reaction_equation(i) for i in range(self.n_reactions)] else: - return [self.reactionEquation(i) for i in indices] + return [self.reaction_equation(i) for i in indices] - def reactantStoichCoeff(self, int kSpec, int iReaction): + def reactant_stoich_coeff(self, int k_spec, int i_reaction): """ - The stoichiometric coefficient of species *kSpec* as a reactant in - reaction *iReaction*. + The stoichiometric coefficient of species *k_spec* as a reactant in + reaction *i_reaction*. """ - self._checkKineticsSpeciesIndex(kSpec) - self._checkReactionIndex(iReaction) - return self.kinetics.reactantStoichCoeff(kSpec, iReaction) + self._check_kinetics_species_index(k_spec) + self._check_reaction_index(i_reaction) + return self.kinetics.reactantStoichCoeff(k_spec, i_reaction) - def productStoichCoeff(self, int kSpec, int iReaction): + def product_stoich_coeff(self, int k_spec, int i_reaction): """ - The stoichiometric coefficient of species *kSpec* as a product in - reaction *iReaction*. + The stoichiometric coefficient of species *k_spec* as a product in + reaction *i_reaction*. """ - self._checkKineticsSpeciesIndex(kSpec) - self._checkReactionIndex(iReaction) - return self.kinetics.productStoichCoeff(kSpec, iReaction) + self._check_kinetics_species_index(k_spec) + self._check_reaction_index(i_reaction) + return self.kinetics.productStoichCoeff(k_spec, i_reaction) - def reactantStoichCoeffs(self): + def reactant_stoich_coeffs(self): """ The array of reactant stoichiometric coefficients. Element *[k,i]* of this array is the reactant stoichiometric coefficient of species *k* in reaction *i*. """ - cdef np.ndarray[np.double_t, ndim=2] data = np.empty((self.nTotalSpecies, - self.nReactions)) + cdef np.ndarray[np.double_t, ndim=2] data = np.empty((self.n_total_species, + self.n_reactions)) cdef int i,k - for i in range(self.nReactions): - for k in range(self.nTotalSpecies): + for i in range(self.n_reactions): + for k in range(self.n_total_species): data[k,i] = self.kinetics.reactantStoichCoeff(k,i) return data - def productStoichCoeffs(self): + def product_stoich_coeffs(self): """ The array of product stoichiometric coefficients. Element *[k,i]* of this array is the product stoichiometric coefficient of species *k* in reaction *i*. """ - cdef np.ndarray[np.double_t, ndim=2] data = np.empty((self.nTotalSpecies, - self.nReactions)) + cdef np.ndarray[np.double_t, ndim=2] data = np.empty((self.n_total_species, + self.n_reactions)) cdef int i,k - for i in range(self.nReactions): - for k in range(self.nTotalSpecies): + for i in range(self.n_reactions): + for k in range(self.n_total_species): data[k,i] = self.kinetics.productStoichCoeff(k,i) return data - property fwdRatesOfProgress: + property forward_rates_of_progress: """ Forward rates of progress for the reactions. [kmol/m^3/s] for bulk phases or [kmol/m^2/s] for surface phases. @@ -178,7 +178,7 @@ cdef class Kinetics(_SolutionBase): def __get__(self): return get_reaction_array(self, kin_getFwdRatesOfProgress) - property revRatesOfProgress: + property reverse_rates_of_progress: """ Reverse rates of progress for the reactions. [kmol/m^3/s] for bulk phases or [kmol/m^2/s] for surface phases. @@ -186,7 +186,7 @@ cdef class Kinetics(_SolutionBase): def __get__(self): return get_reaction_array(self, kin_getRevRatesOfProgress) - property netRatesOfProgress: + property net_rates_of_progress: """ Net rates of progress for the reactions. [kmol/m^3/s] for bulk phases or [kmol/m^2/s] for surface phases. @@ -194,17 +194,17 @@ cdef class Kinetics(_SolutionBase): def __get__(self): return get_reaction_array(self, kin_getNetRatesOfProgress) - property equilibriumConstants: + property equilibrium_constants: """Equilibrium constants in concentration units for all reactions.""" def __get__(self): return get_reaction_array(self, kin_getEquilibriumConstants) - property activationEnergies: + property activation_energies: """Activation energies for all reactions [K].""" def __get__(self): return get_reaction_array(self, kin_getActivationEnergies) - property fwdRateConstants: + property forward_rate_constants: """ Forward rate constants for all reactions. Units are a combination of kmol, m^3 and s, that depend on the rate expression for the reaction. @@ -212,7 +212,7 @@ cdef class Kinetics(_SolutionBase): def __get__(self): return get_reaction_array(self, kin_getFwdRateConstants) - property revRateConstants: + property reverse_rate_constants: """ Reverse rate constants for all reactions. Units are a combination of kmol, m^3 and s, that depend on the rate expression for the reaction. @@ -220,7 +220,7 @@ cdef class Kinetics(_SolutionBase): def __get__(self): return get_reaction_array(self, kin_getRevRateConstants) - property creationRates: + property creation_rates: """ Creation rates for each species. [kmol/m^3/s] for bulk phases or [kmol/m^2/s] for surface phases. @@ -228,7 +228,7 @@ cdef class Kinetics(_SolutionBase): def __get__(self): return get_species_array(self, kin_getCreationRates) - property destructionRates: + property destruction_rates: """ Destruction rates for each species. [kmol/m^3/s] for bulk phases or [kmol/m^2/s] for surface phases. @@ -236,7 +236,7 @@ cdef class Kinetics(_SolutionBase): def __get__(self): return get_species_array(self, kin_getDestructionRates) - property netProductionRates: + property net_production_rates: """ Net production rates for each species. [kmol/m^3/s] for bulk phases or [kmol/m^2/s] for surface phases. @@ -244,22 +244,22 @@ cdef class Kinetics(_SolutionBase): def __get__(self): return get_species_array(self, kin_getNetProductionRates) - property deltaEnthalpy: + property delta_enthalpy: """Change in enthalpy for each reaction [J/kmol].""" def __get__(self): return get_reaction_array(self, kin_getDeltaEnthalpy) - property deltaGibbs: + property delta_gibbs: """Change in Gibbs free energy for each reaction [J/kmol].""" def __get__(self): return get_reaction_array(self, kin_getDeltaGibbs) - property deltaEntropy: + property delta_entropy: """Change in entropy for each reaction [J/kmol/K].""" def __get__(self): return get_reaction_array(self, kin_getDeltaEntropy) - property deltaStandardEnthalpy: + property delta_standard_enthalpy: """ Change in standard-state enthalpy (independent of composition) for each reaction [J/kmol]. @@ -267,7 +267,7 @@ cdef class Kinetics(_SolutionBase): def __get__(self): return get_reaction_array(self, kin_getDeltaSSEnthalpy) - property deltaStandardGibbs: + property delta_standard_gibbs: """ Change in standard-state Gibbs free energy (independent of composition) for each reaction [J/kmol]. @@ -275,7 +275,7 @@ cdef class Kinetics(_SolutionBase): def __get__(self): return get_reaction_array(self, kin_getDeltaSSGibbs) - property deltaStandardEntropy: + property delta_standard_entropy: """ Change in standard-state entropy (independent of composition) for each reaction [J/kmol/K]. @@ -295,7 +295,7 @@ cdef class InterfaceKinetics(Kinetics): kinetics_type_edge): raise TypeError("Underlying Kinetics class is not of the correct type.") - def advanceCoverages(self, double dt): + def advance_coverages(self, double dt): """ This method carries out a time-accurate advancement of the surface coverages for a specified amount of time. diff --git a/interfaces/cython/cantera/mixture.pyx b/interfaces/cython/cantera/mixture.pyx index 79d6d20aa..6f835d1cf 100644 --- a/interfaces/cython/cantera/mixture.pyx +++ b/interfaces/cython/cantera/mixture.pyx @@ -6,13 +6,13 @@ cdef class Mixture: paired with the number of moles for that phase:: >>> gas = cantera.Solution('gas.cti') - >>> gas.speciesNames + >>> gas.species_names ['H2', 'H', 'O2', 'O', 'OH'] >>> graphite = cantera.Solution('graphite.cti') - >>> graphite.speciesNames + >>> graphite.species_names ['C(g)'] - >>> mix = Mixture([(gas, 1.0), (graphite, 0.1)]) - >>> mix.speciesNames + >>> mix = cantera.Mixture([(gas, 1.0), (graphite, 0.1)]) + >>> mix.species_names ['H2', 'H', 'O2', 'O', 'OH', 'C(g)'] Note that the objects representing each phase compute only the intensive @@ -60,7 +60,7 @@ cdef class Mixture: s = [] for i,phase in enumerate(self._phases): s.append('************ Phase {0} ************'.format(phase.name)) - s.append('Moles: {0}'.format(self.phaseMoles(i))) + s.append('Moles: {0}'.format(self.phase_moles(i))) s.append(phase.report()) return '\n'.join(s) @@ -68,15 +68,15 @@ cdef class Mixture: def __call__(self): print(self.report()) - property nElements: + property n_elements: """Total number of elements present in the mixture.""" def __get__(self): return self.mix.nElements() - cpdef int elementIndex(self, element) except *: + cpdef int element_index(self, element) except *: """Index of element with name 'element':: - >>> mix.elementIndex('H') + >>> mix.element_index('H') 2 """ if isinstance(element, (str, unicode)): @@ -86,26 +86,26 @@ cdef class Mixture: else: raise TypeError("'element' must be a string or a number") - if not 0 <= index < self.nElements: + if not 0 <= index < self.n_elements: raise ValueError('No such element.') return index - property nSpecies: + property n_species: """Number of species.""" def __get__(self): return self.mix.nSpecies() - def speciesName(self, k): + def species_name(self, k): """Name of the species with index *k*. Note that index numbers are assigned in order as phases are added.""" return pystr(self.mix.speciesName(k)) - property speciesNames: + property species_names: def __get__(self): - return [self.speciesName(k) for k in range(self.nSpecies)] + return [self.species_name(k) for k in range(self.n_species)] - def speciesIndex(self, phase, species): + def species_index(self, phase, species): """ :param phase: Phase object, index or name @@ -114,32 +114,32 @@ cdef class Mixture: Returns the global index of species *species* in phase *phase*. """ - p = self.phaseIndex(phase) + p = self.phase_index(phase) if isinstance(species, (str, unicode)): - k = self.phase(p).speciesIndex(species) + k = self.phase(p).species_index(species) elif isinstance(species, (int, float)): k = species - if not 0 <= k < self.nSpecies: + if not 0 <= k < self.n_species: raise ValueError('Species index out of range') else: raise TypeError("'species' must be a string or number") return self.mix.speciesIndex(k, p) - def nAtoms(self, k, m): + def n_atoms(self, k, m): """ Number of atoms of element *m* in the species with global index *k*. The element may be referenced either by name or by index. - >>> n = mix.nAtoms(3, 'H') + >>> n = mix.n_atoms(3, 'H') 4.0 """ - if not 0 <= k < self.nSpecies: - raise IndexError('Species index ({}) out of range (0 < {})'.format(k, self.nSpecies)) - return self.mix.nAtoms(k, self.elementIndex(m)) + if not 0 <= k < self.n_species: + raise IndexError('Species index ({}) out of range (0 < {})'.format(k, self.n_species)) + return self.mix.nAtoms(k, self.element_index(m)) - property nPhases: + property n_phases: """Number of phases""" def __get__(self): return len(self._phases) @@ -147,13 +147,13 @@ cdef class Mixture: def phase(self, n): return self._phases[n] - def phaseIndex(self, p): + def phase_index(self, p): """Index of the phase named *p*.""" if isinstance(p, ThermoPhase): p = p.name if isinstance(p, (int, float)): - if p == int(p) and 0 <= p < self.nPhases: + if p == int(p) and 0 <= p < self.n_phases: return int(p) else: raise IndexError("Phase index '{0}' out of range.".format(p)) @@ -163,7 +163,7 @@ cdef class Mixture: return i raise KeyError("No such phase: '{0}'".format(p)) - property phaseNames: + property phase_names: """Names of all phases in the order added.""" def __get__(self): return [phase.name for phase in self._phases] @@ -178,20 +178,20 @@ cdef class Mixture: def __set__(self, T): self.mix.setTemperature(T) - property minTemp: + property min_temp: """ The minimum temperature for which all species in multi-species solutions have valid thermo data. Stoichiometric phases are not - considered in determining minTemp. + considered in determining min_temp. """ def __get__(self): return self.mix.minTemp() - property maxTemp: + property max_temp: """ The maximum temperature for which all species in multi-species solutions have valid thermo data. Stoichiometric phases are not - considered in determining maxTemp. + considered in determining max_temp. """ def __get__(self): return self.mix.maxTemp() @@ -209,27 +209,27 @@ cdef class Mixture: def __get__(self): return self.mix.charge() - def phaseCharge(self, p): + def phase_charge(self, p): """The charge of phase *p* in Coulumbs.""" - return self.mix.phaseCharge(self.phaseIndex(p)) + return self.mix.phaseCharge(self.phase_index(p)) - def phaseMoles(self, p=None): + def phase_moles(self, p=None): """ Moles in phase *p*, if *p* is specified, otherwise the number of moles in all phases. """ if p is None: - return [self.mix.phaseMoles(n) for n in range(self.nPhases)] + return [self.mix.phaseMoles(n) for n in range(self.n_phases)] else: - return self.mix.phaseMoles(self.phaseIndex(p)) + return self.mix.phaseMoles(self.phase_index(p)) - def setPhaseMoles(self, p, moles): + def set_phase_moles(self, p, moles): """ Set the number of moles of phase *p* to *moles* """ - self.mix.setPhaseMoles(self.phaseIndex(p), moles) + self.mix.setPhaseMoles(self.phase_index(p), moles) - def speciesMoles(self, species=None): + def species_moles(self, species=None): """ Returns the number of moles of species *k* if *k* is specified, or the number of of moles of each species otherwise. @@ -237,12 +237,12 @@ cdef class Mixture: if species is not None: return self.mix.speciesMoles(species) - cdef np.ndarray[np.double_t, ndim=1] data = np.empty(self.nSpecies) - for k in range(self.nSpecies): + cdef np.ndarray[np.double_t, ndim=1] data = np.empty(self.n_species) + for k in range(self.n_species): data[k] = self.mix.speciesMoles(k) return data - def setSpeciesMoles(self, moles): + def set_species_moles(self, moles): """ Set the moles of the species [kmol]. The moles may be specified either as a string, or as an array. If an array is used, it must be @@ -250,36 +250,36 @@ cdef class Mixture: mixture. Note that the species may belong to any phase, and unspecified species are set to zero. - >>> mix.setSpeciesMoles('C(s):1.0, CH4:2.0, O2:0.2') + >>> mix.set_species_moles('C(s):1.0, CH4:2.0, O2:0.2') """ if isinstance(moles, (str, unicode)): self.mix.setMolesByName(stringify(moles)) return - if len(moles) != self.nSpecies: - raise ValueError('mole array must be of length nSpecies') + if len(moles) != self.n_species: + raise ValueError('mole array must be of length n_species') cdef np.ndarray[np.double_t, ndim=1] data = \ np.ascontiguousarray(moles, dtype=np.double) self.mix.setMoles(&data[0]) - def elementMoles(self, e): + def element_moles(self, e): """ Total number of moles of element *e*, summed over all species. The element may be referenced either by index number or by name. """ - return self.mix.elementMoles(self.elementIndex(e)) + return self.mix.elementMoles(self.element_index(e)) - property chem_potentials: + property chemical_potentials: """The chemical potentials of all species [J/kmol].""" def __get__(self): - cdef np.ndarray[np.double_t, ndim=1] data = np.empty(self.nSpecies) + cdef np.ndarray[np.double_t, ndim=1] data = np.empty(self.n_species) self.mix.getChemPotentials(&data[0]) return data - def equilibrate(self, XY, solver='vcs', rtol=1e-9, maxsteps=1000, - maxiter=100, estimateEquil=0, printlevel=0, loglevel=0): + def equilibrate(self, XY, solver='vcs', rtol=1e-9, max_steps=1000, + max_iter=100, estimate_equil=0, print_level=0, log_level=0): """ Set to a state of chemical equilibrium holding property pair *XY* constant. This method uses a version of the VCS algorithm to find the @@ -301,29 +301,29 @@ cdef class Mixture: less than this value for each reaction. Note that this default is very conservative, and good equilibrium solutions may be obtained with larger error tolerances. - :param maxsteps: + :param max_steps: Maximum number of steps to take while solving the equilibrium problem for specified *T* and *P*. - :param maxiter: + :param max_iter: Maximum number of temperature and/or pressure iterations. This is only relevant if a property pair other than (T,P) is specified. - :param estimateEquil: + :param estimate_equil: Flag indicating whether the solver should estimate its own initial condition. If 0, the initial mole fraction vector in the phase objects are used as the initial condition. If 1, the initial mole fraction vector is used if the element abundances are satisfied. if -1, the initial mole fraction vector is thrown out, and an estimate is formulated. - :param printlevel: + :param print_level: Determines the amount of output displayed during the solution process. 0 indicates no output, while larger numbers produce successively more verbose information. - :param loglevel: + :param log_level: Controls the amount of diagnostic output written to an HTML log - file. If loglevel = 0, no diagnostic output is written. For + file. If log_level = 0, no diagnostic output is written. For values > 0, more detailed information is written to the log file as - loglevel increases. The default log file name is + log_level increases. The default log file name is "equilibrium_log.html", but if this file exists, the log information will be written to "equilibrium_log{n}.html", where {n} is an integer chosen to avoid overwriting existing @@ -337,5 +337,6 @@ cdef class Mixture: raise ValueError('Unrecognized equilibrium solver ' 'specified: "{}"'.format(solver)) - vcs_equilibrate(deref(self.mix), stringify(XY).c_str(), estimateEquil, - printlevel, iSolver, rtol, maxsteps, maxiter, loglevel) + vcs_equilibrate(deref(self.mix), stringify(XY).c_str(), estimate_equil, + print_level, iSolver, rtol, max_steps, max_iter, + log_level) diff --git a/interfaces/cython/cantera/onedim.pyx b/interfaces/cython/cantera/onedim.pyx index 8309aa0a0..1eadf9e3f 100644 --- a/interfaces/cython/cantera/onedim.pyx +++ b/interfaces/cython/cantera/onedim.pyx @@ -15,30 +15,30 @@ cdef class Domain1D: def __get__(self): return self.domain.domainIndex() - property nComponents: + property n_components: """Number of solution components at each grid point.""" def __get__(self): return self.domain.nComponents() - property nPoints: + property n_points: """Number of grid points belonging to this domain.""" def __get__(self): return self.domain.nPoints() - def componentName(self, int n): + def component_name(self, int n): """Name of the nth component.""" return pystr(self.domain.componentName(n)) - property componentNames: + property component_names: """List of the names of all components of this domain.""" def __get__(self): - return [self.componentName(n) for n in range(self.nComponents)] + return [self.component_name(n) for n in range(self.n_components)] - def componentIndex(self, str name): + def component_index(self, str name): """Index of the component with name 'name'""" return self.domain.componentIndex(stringify(name)) - def setBounds(self, *, default=None, Y=None, **kwargs): + def set_bounds(self, *, default=None, Y=None, **kwargs): """ Set the lower and upper bounds on the solution. @@ -48,20 +48,20 @@ cdef class Domain1D: bounds for all unspecified components. The keyword *Y* can be used to stand for all species mass fractions in flow domains. - >>> d.setBounds(default=(0, 1), Y=(-1.0e-5, 2.0)) + >>> d.set_bounds(default=(0, 1), Y=(-1.0e-5, 2.0)) """ if default is not None: - for n in range(self.nComponents): + for n in range(self.n_components): self.domain.setBounds(n, default[0], default[1]) if Y is not None: - for n in range(4, self.nComponents): + for n in range(4, self.n_components): self.domain.setBounds(n, Y[0], Y[1]) for name,(lower,upper) in kwargs.items(): - self.domain.setBounds(self.componentName(name), lower, upper) + self.domain.setBounds(self.component_name(name), lower, upper) - def setSteadyTolerances(self, *, default=None, Y=None, **kwargs): + def set_steady_tolerances(self, *, default=None, Y=None, **kwargs): """ Set the error tolerances for the steady-state problem. @@ -71,9 +71,9 @@ cdef class Domain1D: unspecified components. The keyword *Y* can be used to stand for all species mass fractions in flow domains. """ - self._setTolerances(0, default, Y, kwargs) + self._set_tolerances(0, default, Y, kwargs) - def setTransientTolerances(self, *, default=None, Y=None, **kwargs): + def set_transient_tolerances(self, *, default=None, Y=None, **kwargs): """ Set the error tolerances for the steady-state problem. @@ -83,21 +83,21 @@ cdef class Domain1D: unspecified components. The keyword *Y* can be used to stand for all species mass fractions in flow domains. """ - self._setTolerances(1, default, Y, kwargs) + self._set_tolerances(1, default, Y, kwargs) - def _setTolerances(self, isTransient, default, Y, components): + def _set_tolerances(self, is_transient, default, Y, components): if default is not None: - for n in range(self.nComponents): + for n in range(self.n_components): self.domain.setTolerances(n, default[0], default[1], - isTransient) + is_transient) if Y is not None: - for n in range(4, self.nComponents): - self.domain.setTolerances(n, Y[0], Y[1], isTransient) + for n in range(4, self.n_components): + self.domain.setTolerances(n, Y[0], Y[1], is_transient) for name,(lower,upper) in components.items(): - self.domain.setTolerances(self.componentName(name), - lower, upper, isTransient) + self.domain.setTolerances(self.component_name(name), + lower, upper, is_transient) def bounds(self, component): """ @@ -106,7 +106,7 @@ cdef class Domain1D: >>> d.bounds('T') (200.0, 5000.0) """ - n = self.componentIndex(component) + n = self.component_index(component) return self.domain.lowerBound(n), self.domain.upperBound(n) def tolerances(self, component): @@ -116,15 +116,15 @@ cdef class Domain1D: >>> rtol, atol = d.tolerances('u') """ - k = self.componentIndex(component) + k = self.component_index(component) return self.domain.rtol(k), self.domain.atol(k) property grid: """ The grid for this domain """ def __get__(self): - cdef np.ndarray[np.double_t, ndim=1] grid = np.empty(self.nPoints) + cdef np.ndarray[np.double_t, ndim=1] grid = np.empty(self.n_points) cdef int i - for i in range(self.nPoints): + for i in range(self.n_points): grid[i] = self.domain.grid(i) return grid @@ -209,7 +209,7 @@ cdef class Inlet1D(Boundary1D): def __dealloc__(self): del self.inlet - property spreadRate: + property spread_rate: def __get__(self): return self.inlet.spreadRate() def __set__(self, s): @@ -275,7 +275,7 @@ cdef class ReactingSurface1D(Boundary1D): def __dealloc__(self): del self.surf - def setKinetics(self, Kinetics kin): + def set_kinetics(self, Kinetics kin): """Set the kinetics manager (surface reaction mechanism object).""" if kin.kinetics.type() not in (kinetics_type_interface, kinetics_type_edge): @@ -283,7 +283,7 @@ cdef class ReactingSurface1D(Boundary1D): 'InterfaceKinetics.') self.surf.setKineticsMgr(kin.kinetics) - def enableCoverageEquations(self, on=True): + def enable_coverage_equations(self, on=True): """ Turn solving the surface coverage equations on or off. """ self.surf.enableCoverageEquations(on) @@ -311,11 +311,11 @@ cdef class _FlowBase(Domain1D): def __set__(self, P): self.flow.setPressure(P) - def setTransport(self, _SolutionBase phase): + def set_transport(self, _SolutionBase phase): self.gas = phase self.flow.setTransport(deref(self.gas.transport)) - property soretEnabled: + property soret_enabled: """ Determines whether or not to include diffusive mass fluxes due to the Soret effect. Enabling this option works only when using the @@ -326,7 +326,7 @@ cdef class _FlowBase(Domain1D): def __set__(self, enable): self.flow.enableSoret(enable) - property energyEnabled: + property energy_enabled: """ Determines whether or not to solve the energy equation.""" def __get__(self): return self.flow.doEnergy(0) @@ -336,7 +336,7 @@ cdef class _FlowBase(Domain1D): else: self.flow.fixTemperature() - def setFixedTempProfile(self, pos, T): + def set_fixed_temp_profile(self, pos, T): """Set the fixed temperature profile. This profile is used whenever the energy equation is disabled. @@ -345,8 +345,8 @@ cdef class _FlowBase(Domain1D): :param temp: array of temperature values - >>> d.setFixedTempProfile(array([0.0, 0.5, 1.0]), - ... array([500.0, 1500.0, 2000.0]) + >>> d.set_fixed_temp_profile(array([0.0, 0.5, 1.0]), + ... array([500.0, 1500.0, 2000.0]) """ cdef vector[double] x, y for p in pos: @@ -368,7 +368,7 @@ cdef CxxIdealGasPhase* getIdealGasPhase(ThermoPhase phase) except *: cdef class FreeFlow(_FlowBase): def __cinit__(self, _SolutionBase thermo, *args, **kwargs): gas = getIdealGasPhase(thermo) - self.flow = (new CxxFreeFlame(gas, thermo.nSpecies, 2)) + self.flow = (new CxxFreeFlame(gas, thermo.n_species, 2)) cdef class AxisymmetricStagnationFlow(_FlowBase): @@ -402,7 +402,7 @@ cdef class AxisymmetricStagnationFlow(_FlowBase): """ def __cinit__(self, _SolutionBase thermo, *args, **kwargs): gas = getIdealGasPhase(thermo) - self.flow = (new CxxAxiStagnFlow(gas, thermo.nSpecies, 2)) + self.flow = (new CxxAxiStagnFlow(gas, thermo.n_species, 2)) cdef class Sim1D: @@ -431,7 +431,7 @@ cdef class Sim1D: self._initialized = False - def domainIndex(self, dom): + def domain_index(self, dom): """ Get the index of a domain, specified either by name or as a Domain1D object. @@ -453,14 +453,14 @@ cdef class Sim1D: return idom def _get_indices(self, dom, comp): - idom = self.domainIndex(dom) + idom = self.domain_index(dom) dom = self.domains[idom] if isinstance(comp, (str, unicode)): - kcomp = dom.componentIndex(comp) + kcomp = dom.component_index(comp) else: kcomp = comp - assert 0 <= kcomp < dom.nComponents + assert 0 <= kcomp < dom.n_components return idom, kcomp @@ -480,7 +480,7 @@ cdef class Sim1D: dom, comp = self._get_indices(domain, component) return self.sim.value(dom, comp, point) - def setValue(self, domain, component, point, value): + def set_value(self, domain, component, point, value): """ Set the value of one component in one domain at one point to 'value'. @@ -500,7 +500,7 @@ cdef class Sim1D: dom, comp = self._get_indices(domain, component) self.sim.setValue(dom, comp, point, value) - def workValue(self, domain, component, point): + def work_value(self, domain, component, point): """ Internal work array value at one point. After calling eval, this array contains the values of the residual function. @@ -531,12 +531,12 @@ cdef class Sim1D: idom, kcomp = self._get_indices(domain, component) dom = self.domains[idom] cdef int j - cdef np.ndarray[np.double_t, ndim=1] data = np.empty(dom.nPoints) - for j in range(dom.nPoints): + cdef np.ndarray[np.double_t, ndim=1] data = np.empty(dom.n_points) + for j in range(dom.n_points): data[j] = self.sim.value(idom, kcomp, j) return data - def setProfile(self, domain, component, positions, values): + def set_profile(self, domain, component, positions, values): """ Set an initial estimate for a profile of one component in one domain. @@ -549,7 +549,7 @@ cdef class Sim1D: :param values: sequence of values at the relative positions specified in *positions* - >>> s.setProfile(d, 'T', [0.0, 0.2, 1.0], [400.0, 800.0, 1500.0]) + >>> s.set_profile(d, 'T', [0.0, 0.2, 1.0], [400.0, 800.0, 1500.0]) """ dom, comp = self._get_indices(domain, component) @@ -561,7 +561,7 @@ cdef class Sim1D: self.sim.setProfile(dom, comp, pos_vec, val_vec) - def setFlatProfile(self, domain, component, value): + def set_flat_profile(self, domain, component, value): """Set a flat profile for one component in one domain. :param domain: @@ -571,42 +571,42 @@ cdef class Sim1D: :param v: value - >>> s.setFlatProfile(d, 'u', -3.0) + >>> s.set_flat_profile(d, 'u', -3.0) """ dom, comp = self._get_indices(domain, component) self.sim.setFlatProfile(dom, comp, value) - def showSolution(self): + def show_solution(self): """ print the current solution. """ if not self._initialized: - self.setInitialGuess() + self.set_initial_guess() self.sim.showSolution() - def setTimeStep(self, stepsize, nSteps): + def set_time_step(self, stepsize, n_steps): """Set the sequence of time steps to try when Newton fails. :param stepsize: initial time step size [s] - :param nSteps: + :param n_steps: sequence of integer step numbers - >>> s.setTimeStep(1.0e-5, [1, 2, 5, 10]) + >>> s.set_time_step(1.0e-5, [1, 2, 5, 10]) """ cdef vector[int] data - for n in nSteps: + for n in n_steps: data.push_back(n) self.sim.setTimeStep(stepsize, data.size(), &data[0]) - def setInitialGuess(self): + def set_initial_guess(self): """ Set the initial guess for the solution. Derived classes extend this function to set approximations for the temperature and composition profiles. """ - self._getInitialSolution() + self._get_initial_solution() self._initialized = True - def _getInitialSolution(self): + def _get_initial_solution(self): """ Load the initial solution from each domain into the global solution vector. @@ -624,7 +624,7 @@ cdef class Sim1D: if True, enable grid refinement. """ if not self._initialized: - self.setInitialGuess() + self.set_initial_guess() self.sim.solve(loglevel, refine_grid) def refine(self, loglevel=1): @@ -634,7 +634,7 @@ cdef class Sim1D: """ self.sim.refine(loglevel) - def setRefineCriteria(self, domain, ratio=10.0, slope=0.8, curve=0.8, + def set_refine_criteria(self, domain, ratio=10.0, slope=0.8, curve=0.8, prune=0.05): """ Set the criteria used to refine one domain. @@ -658,12 +658,12 @@ cdef class Sim1D: 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) + >>> s.set_refine_criteria(d, ratio=5.0, slope=0.2, curve=0.3, prune=0.03) """ - idom = self.domainIndex(domain) + idom = self.domain_index(domain) self.sim.setRefineCriteria(idom, ratio, slope, curve, prune) - def setMaxJacAge(self, ss_age, ts_age): + def set_max_jac_age(self, ss_age, ts_age): """ Set the maximum number of times the Jacobian will be used before it must be re-evaluated. @@ -675,22 +675,22 @@ cdef class Sim1D: """ self.sim.setJacAge(ss_age, ts_age) - def setTimeStepFactor(self, tfactor): + def set_time_step_factor(self, tfactor): """ Set the factor by which the time step will be increased after a successful step, or decreased after an unsuccessful one. """ self.sim.setTimeStepFactor(tfactor) - def setMinTimeStep(self, tsmin): + def set_min_time_step(self, tsmin): """ Set the minimum time step. """ self.sim.setMinTimeStep(tsmin) - def setMaxTimeStep(self, tsmax): + def set_max_time_step(self, tsmax): """ Set the maximum time step. """ self.sim.setMaxTimeStep(tsmax) - def setFixedTemperature(self, T): + def set_fixed_temperature(self, T): """ Set the temperature used to fix the spatial location of a freely propagating flame. @@ -725,14 +725,14 @@ cdef class Sim1D: self.sim.restore(stringify(filename), stringify(name), loglevel) self._initialized = True - def showStats(self, printTime=True): + def show_stats(self, print_time=True): """ Show the statistics for the last solution. If invoked with no arguments or with a non-zero argument, the timing statistics will be printed. Otherwise, the timing will not be printed. """ - self.sim.writeStats(printTime) + self.sim.writeStats(print_time) def __dealloc__(self): del self.sim @@ -753,36 +753,36 @@ class FlameBase(Sim1D): self.gas = gas self.flame.P = gas.P - def setRefineCriteria(self, ratio=10.0, slope=0.8, curve=0.8, prune=0.0): - super().setRefineCriteria(self.flame, ratio, slope, curve, prune) + def set_refine_criteria(self, ratio=10.0, slope=0.8, curve=0.8, prune=0.0): + super().set_refine_criteria(self.flame, ratio, slope, curve, prune) - def setProfile(self, component, locations, values): - super().setProfile(self.flame, component, locations, values) + def set_profile(self, component, locations, values): + super().set_profile(self.flame, component, locations, values) @property - def transportModel(self): - return self.gas.transportModel + def transport_model(self): + return self.gas.transport_model - @transportModel.setter - def transportModel(self, model): - self.gas.transportModel = model - self.flame.setTransport(self.gas) + @transport_model.setter + def transport_model(self, model): + self.gas.transport_model = model + self.flame.set_transport(self.gas) @property - def energyEnabled(self): - return self.flame.energyEnabled + def energy_enabled(self): + return self.flame.energy_enabled - @energyEnabled.setter - def energyEnabled(self, enable): - self.flame.energyEnabled = enable + @energy_enabled.setter + def energy_enabled(self, enable): + self.flame.energy_enabled = enable @property - def soretEnabled(self): - return self.flame.soretEnabled + def soret_enabled(self): + return self.flame.soret_enabled - @soretEnabled.setter - def soretEnabled(self, enable): - self.flame.soretEnabled = enable + @soret_enabled.setter + def soret_enabled(self, enable): + self.flame.soret_enabled = enable @property def grid(self): @@ -822,10 +822,10 @@ class FlameBase(Sim1D): else: return self.value(self.flame, component, point) - def setGasState(self, point): - k0 = self.flame.componentIndex(self.gas.speciesName(0)) + def set_gas_state(self, point): + k0 = self.flame.component_index(self.gas.species_name(0)) Y = [self.solution(k, point) - for k in range(k0, k0 + self.gas.nSpecies)] + for k in range(k0, k0 + self.gas.n_species)] self.gas.TPY = self.value(self.flame, 'T', point), self.P, Y def _trim(docstring): @@ -858,55 +858,55 @@ def _array_property(attr, size=None): def getter(self): if size is None: # 1D array for scalar property - vals = np.empty(self.flame.nPoints) + vals = np.empty(self.flame.n_points) else: # 2D array - vals = np.empty((getattr(self.gas, size), self.flame.nPoints)) + vals = np.empty((getattr(self.gas, size), self.flame.n_points)) - for i in range(self.flame.nPoints): - self.setGasState(i) + for i in range(self.flame.n_points): + self.set_gas_state(i) vals[...,i] = getattr(self.gas, attr) return vals if size is None: - extradoc = "\nReturns an array of length `nPoints`." + extradoc = "\nReturns an array of length `n_points`." else: - extradoc = "\nReturns an array of size `%s` x `nPoints`." % size + extradoc = "\nReturns an array of size `%s` x `n_points`." % size doc = _trim(getattr(Solution, attr).__doc__) + extradoc return property(getter, doc=doc) # Add scalar properties to FlameBase for attr in ['density', 'density_mass', 'density_mole', 'volume_mass', - 'volume_mole', 'intEnergy_mole', 'intEnergy_mass', 'h', + 'volume_mole', 'int_energy_mole', 'int_energy_mass', 'h', 'enthalpy_mole', 'enthalpy_mass', 's', 'entropy_mole', 'entropy_mass', 'g', 'gibbs_mole', 'gibbs_mass', 'cv', 'cv_mole', 'cv_mass', 'cp', 'cp_mole', 'cp_mass', - 'isothermalCompressibility', 'thermalExpansionCoeff', - 'viscosity', 'thermalConductivity']: + 'isothermal_compressibility', 'thermal_expansion_coeff', + 'viscosity', 'thermal_conductivity']: setattr(FlameBase, attr, _array_property(attr)) FlameBase.volume = _array_property('v') # avoid confusion with velocity gradient 'V' -FlameBase.intEnergy = _array_property('u') # avoid collision with velocity 'u' +FlameBase.int_energy = _array_property('u') # avoid collision with velocity 'u' # Add properties with values for each species for attr in ['X', 'Y', 'concentrations', 'partial_molar_enthalpies', 'partial_molar_entropies', 'partial_molar_int_energies', - 'chem_potentials', 'electrochem_potentials', 'partial_molar_cp', + 'chemical_potentials', 'electrochemical_potentials', 'partial_molar_cp', 'partial_molar_volumes', 'standard_enthalpies_RT', - 'standard_entropies_R', 'standard_intEnergies_RT', - 'standard_gibbs_RT', 'standard_cp_R', 'creationRates', - 'destructionRates', 'netProductionRates', 'mixDiffCoeffs', - 'mixDiffCoeffsMass', 'mixDiffCoeffsMole', 'thermalDiffCoeffs']: - setattr(FlameBase, attr, _array_property(attr, 'nSpecies')) + 'standard_entropies_R', 'standard_int_energies_RT', + 'standard_gibbs_RT', 'standard_cp_R', 'creation_rates', + 'destruction_rates', 'net_production_rates', 'mix_diff_coeffs', + 'mix_diff_coeffs_mass', 'mix_diff_coeffs_mole', 'thermal_diff_coeffs']: + setattr(FlameBase, attr, _array_property(attr, 'n_species')) # Add properties with values for each reaction -for attr in ['fwdRatesOfProgress', 'revRatesOfProgress', 'netRatesOfProgress', - 'equilibriumConstants', 'fwdRateConstants', 'revRateConstants', - 'deltaEnthalpy', 'deltaGibbs', 'deltaEntropy', - 'deltaStandardEnthalpy', 'deltaStandardGibbs', - 'deltaStandardEntropy']: - setattr(FlameBase, attr, _array_property(attr, 'nReactions')) +for attr in ['forward_rates_of_progress', 'reverse_rates_of_progress', 'net_rates_of_progress', + 'equilibrium_constants', 'forward_rate_constants', 'reverse_rate_constants', + 'delta_enthalpy', 'delta_gibbs', 'delta_entropy', + 'delta_standard_enthalpy', 'delta_standard_gibbs', + 'delta_standard_entropy']: + setattr(FlameBase, attr, _array_property(attr, 'n_reactions')) class FreeFlame(FlameBase): @@ -927,7 +927,7 @@ class FreeFlame(FlameBase): super().__init__((self.inlet, self.flame, self.outlet), gas, grid) - def setInitialGuess(self): + def set_initial_guess(self): """ Set the initial guess for the solution. The adiabatic flame temperature and equilibrium composition are computed for the inlet gas @@ -935,7 +935,7 @@ class FreeFlame(FlameBase): domain width to Tad, then is flat. The mass fraction profiles are set similarly. """ - super().setInitialGuess() + super().set_initial_guess() self.gas.TPY = self.inlet.T, self.P, self.inlet.Y Y0 = self.inlet.Y u0 = self.inlet.mdot/self.gas.density @@ -948,12 +948,12 @@ class FreeFlame(FlameBase): u1 = self.inlet.mdot/self.gas.density locs = [0.0, 0.3, 0.5, 1.0] - self.setProfile('u', locs, [u0, u0, u1, u1]) - self.setProfile('T', locs, [T0, T0, Teq, Teq]) - self.setFixedTemperature(0.5 * (T0 + Teq)) - for n in range(self.gas.nSpecies): - self.setProfile(self.gas.speciesName(n), - locs, [Y0[n], Y0[n], Yeq[n], Yeq[n]]) + self.set_profile('u', locs, [u0, u0, u1, u1]) + self.set_profile('T', locs, [T0, T0, Teq, Teq]) + self.set_fixed_temperature(0.5 * (T0 + Teq)) + for n in range(self.gas.n_species): + self.set_profile(self.gas.species_name(n), + locs, [Y0[n], Y0[n], Yeq[n], Yeq[n]]) class BurnerFlame(FlameBase): @@ -982,7 +982,7 @@ class BurnerFlame(FlameBase): super().__init__((self.burner, self.flame, self.outlet), gas, grid) - def setInitialGuess(self): + def set_initial_guess(self): """ Set the initial guess for the solution. The adiabatic flame temperature and equilibrium composition are computed for the burner @@ -990,7 +990,7 @@ class BurnerFlame(FlameBase): 20% of the flame to Tad, then is flat. The mass fraction profiles are set similarly. """ - super().setInitialGuess() + super().set_initial_guess() self.gas.TPY = self.burner.T, self.P, self.burner.Y Y0 = self.burner.Y @@ -1004,11 +1004,11 @@ class BurnerFlame(FlameBase): u1 = self.burner.mdot/self.gas.density locs = [0.0, 0.2, 1.0] - self.setProfile('u', locs, [u0, u1, u1]) - self.setProfile('T', locs, [T0, Teq, Teq]) - for n in range(self.gas.nSpecies): - self.setProfile(self.gas.speciesName(n), - locs, [Y0[n], Yeq[n], Yeq[n]]) + self.set_profile('u', locs, [u0, u1, u1]) + self.set_profile('T', locs, [T0, Teq, Teq]) + for n in range(self.gas.n_species): + self.set_profile(self.gas.species_name(n), + locs, [Y0[n], Yeq[n], Yeq[n]]) class CounterflowDiffusionFlame(FlameBase): @@ -1041,35 +1041,35 @@ class CounterflowDiffusionFlame(FlameBase): super().__init__((self.fuel_inlet, self.flame, self.oxidizer_inlet), gas, grid) - def setInitialGuess(self, fuel, oxidizer='O2', stoich=None): + def set_initial_guess(self, fuel, oxidizer='O2', stoich=None): """ Set the initial guess for the solution. The fuel species must be specified: - >>> f.setInitialGuess(fuel='CH4') + >>> f.set_initial_guess(fuel='CH4') The oxidizer and corresponding stoichiometry must be specified if it is not 'O2'. The initial guess is generated by assuming infinitely- fast chemistry. """ - super().setInitialGuess() + super().set_initial_guess() if stoich is None: if oxidizer == 'O2': stoich = 0.0 - if 'H' in self.gas.elementNames: - stoich += 0.25 * self.gas.nAtoms(fuel, 'H') - if 'C' in self.gas.elementNames: - stoich += self.gas.nAtoms(fuel, 'C') + if 'H' in self.gas.element_names: + stoich += 0.25 * self.gas.n_atoms(fuel, 'H') + if 'C' in self.gas.element_names: + stoich += self.gas.n_atoms(fuel, 'C') else: raise Exception('oxidizer/fuel stoichiometric ratio must be ' 'specified since the oxidizer is not O2') - kFuel = self.gas.speciesIndex(fuel) - kOx = self.gas.speciesIndex(oxidizer) + kFuel = self.gas.species_index(fuel) + kOx = self.gas.species_index(oxidizer) - s = stoich * self.gas.molecularWeights[kOx] / self.gas.molecularWeights[kFuel] + s = stoich * self.gas.molecular_weights[kOx] / self.gas.molecular_weights[kFuel] phi = s * self.fuel_inlet.Y[kFuel] / self.oxidizer_inlet.Y[kOx] zst = 1.0 / (1.0 + phi) @@ -1098,12 +1098,12 @@ class CounterflowDiffusionFlame(FlameBase): zz = self.flame.grid dz = zz[-1] - zz[0] a = (u0o + u0f)/dz - f = np.sqrt(a / (2.0 * self.gas.mixDiffCoeffs[kOx])) + f = np.sqrt(a / (2.0 * self.gas.mix_diff_coeffs[kOx])) x0 = mdotf * dz / (mdotf + mdoto) nz = len(zz) - Y = np.zeros((nz, self.gas.nSpecies)) + Y = np.zeros((nz, self.gas.n_species)) T = np.zeros(nz) for j in range(nz): x = zz[j] @@ -1120,8 +1120,8 @@ class CounterflowDiffusionFlame(FlameBase): T[-1] = T0o zrel = zz/dz - self.setProfile('u', [0.0, 1.0], [u0f, -u0o]) - self.setProfile('V', [0.0, x0/dz, 1.0], [0.0, a, 0.0]) - self.setProfile('T', zrel, T) - for k,spec in enumerate(self.gas.speciesNames): - self.setProfile(spec, zrel, Y[:,k]) + self.set_profile('u', [0.0, 1.0], [u0f, -u0o]) + self.set_profile('V', [0.0, x0/dz, 1.0], [0.0, a, 0.0]) + self.set_profile('T', zrel, T) + for k,spec in enumerate(self.gas.species_names): + self.set_profile(spec, zrel, Y[:,k]) diff --git a/interfaces/cython/cantera/reactor.pyx b/interfaces/cython/cantera/reactor.pyx index 24c5f2497..c50455619 100644 --- a/interfaces/cython/cantera/reactor.pyx +++ b/interfaces/cython/cantera/reactor.pyx @@ -7,9 +7,9 @@ cdef class ReactorBase: """ Common base class for reactors and reservoirs. """ - reactorType = "None" + reactor_type = "None" def __cinit__(self, *args, **kwargs): - self.rbase = newReactor(stringify(self.reactorType)) + self.rbase = newReactor(stringify(self.reactor_type)) def __init__(self, ThermoPhase contents=None, name=None, **kwargs): self._inlets = [] @@ -21,9 +21,9 @@ cdef class ReactorBase: if name is not None: self.name = name else: - reactor_counts[self.reactorType] += 1 - n = reactor_counts[self.reactorType] - self.name = '{0}_{1}'.format(self.reactorType, n) + reactor_counts[self.reactor_type] += 1 + n = reactor_counts[self.reactor_type] + self.name = '{0}_{1}'.format(self.reactor_type, n) def __dealloc__(self): del self.rbase @@ -89,21 +89,21 @@ cdef class ReactorBase: def __get__(self): return self._walls - def _addInlet(self, inlet): + def _add_inlet(self, inlet): """ Store a reference to *inlet* to prevent it from being prematurely garbage collected. """ self._inlets.append(inlet) - def _addOutlet(self, outlet): + def _add_outlet(self, outlet): """ Store a reference to *outlet* to prevent it from being prematurely garbage collected. """ self._outlets.append(outlet) - def _addWall(self, wall): + def _add_wall(self, wall): """ Store a reference to *wall* to prevent it from being prematurely garbage collected. @@ -118,7 +118,7 @@ cdef class Reactor(ReactorBase): chemically-inert walls. These properties may all be changed by adding appropriate components, e.g. `Wall`, `MassFlowController` and `Valve`. """ - reactorType = "Reactor" + reactor_type = "Reactor" def __cinit__(self, *args, **kwargs): self.reactor = (self.rbase) @@ -158,7 +158,7 @@ cdef class Reactor(ReactorBase): super().__init__(contents, **kwargs) if energy == 'off': - self.energyEnabled = False + self.energy_enabled = False elif energy != 'on': raise ValueError("'energy' must be either 'on' or 'off'") @@ -177,7 +177,7 @@ cdef class Reactor(ReactorBase): self.rbase.restoreState() return self._kinetics - property energyEnabled: + property energy_enabled: """ *True* when the energy equation is being solved for this reactor. When this is *False*, the reactor temperature is held constant. @@ -188,7 +188,7 @@ cdef class Reactor(ReactorBase): def __set__(self, pybool value): self.reactor.setEnergy(int(value)) - def addSensitivityReaction(self, m): + def add_sensitivity_reaction(self, m): self.reactor.addSensitivityReaction(m) @@ -198,7 +198,7 @@ cdef class Reservoir(ReactorBase): pressure, and chemical composition in a reservoir never change from their initial values. """ - reactorType = "Reservoir" + reactor_type = "Reservoir" cdef class ConstPressureReactor(Reactor): @@ -206,7 +206,7 @@ cdef class ConstPressureReactor(Reactor): of the reactor changes as a function of time in order to keep the pressure constant. """ - reactorType = "ConstPressureReactor" + reactor_type = "ConstPressureReactor" cdef class FlowReactor(Reactor): @@ -215,9 +215,9 @@ cdef class FlowReactor(Reactor): Time integration follows a fluid element along the length of the reactor. The reactor is assumed to be frictionless and adiabatic. """ - reactorType = "FlowReactor" + reactor_type = "FlowReactor" - property massFlowRate: + property mass_flow_rate: """ Mass flow rate per unit area [kg/m^2*s] """ def __set__(self, double value): (self.reactor).setMassFlowRate(value) @@ -252,7 +252,7 @@ cdef class WallSurface: return self._kinetics def __set__(self, Kinetics k): self._kinetics = k - self.wall._setKinetics() + self.wall._set_kinetics() property coverages: """ @@ -266,13 +266,13 @@ cdef class WallSurface: def __set__(self, coverages): if self._kinetics is None: raise Exception("Can't set coverages before assigning kinetics manager.") - if len(coverages) != self._kinetics.nSpecies: + if len(coverages) != self._kinetics.n_species: raise ValueError('Incorrect number of site coverages specified') cdef np.ndarray[np.double_t, ndim=1] data = \ np.ascontiguousarray(coverages, dtype=np.double) self.cxxwall.setCoverages(self.side, &data[0]) - def addSensitivityReaction(self, int m): + def add_sensitivity_reaction(self, int m): self.cxxwall.addSensitivityReaction(self.side, m) @@ -313,8 +313,8 @@ cdef class Wall: def __cinit__(self, *args, **kwargs): self.wall = new CxxWall() - self.leftSurface = WallSurface(self, 0) - self.rightSurface = WallSurface(self, 1) + self.left_surface = WallSurface(self, 0) + self.right_surface = WallSurface(self, 1) def __init__(self, left, right, *, name=None, A=None, K=None, U=None, Q=None, velocity=None, kinetics=(None,None)): @@ -346,8 +346,8 @@ cdef class Wall: chemistry occurs on only one side, enter ``None`` for the non-reactive side. """ - self._velocityFunc = None - self._heatFluxFunc = None + self._velocity_func = None + self._heat_flux_func = None self._install(left, right) if name is not None: @@ -360,38 +360,38 @@ cdef class Wall: if A is not None: self.area = A if K is not None: - self.expansionRateCoeff = K + self.expansion_rate_coeff = K if U is not None: - self.heatTransferCoeff = U + self.heat_transfer_coeff = U if Q is not None: - self.setHeatFlux(Q) + self.set_heat_flux(Q) if velocity is not None: - self.setVelocity(velocity) + self.set_velocity(velocity) if kinetics[0] is not None: - self.leftSurface.kinetics = kinetics[0] + self.left_surface.kinetics = kinetics[0] if kinetics[1] is not None: - self.rightSurface.kinetics = kinetics[1] + self.right_surface.kinetics = kinetics[1] def _install(self, ReactorBase left, ReactorBase right): """ Install this Wall between two `Reactor` objects or between a `Reactor` and a `Reservoir`. """ - left._addWall(self) - right._addWall(self) + left._add_wall(self) + right._add_wall(self) self.wall.install(deref(left.rbase), deref(right.rbase)) property left: """ The left surface of this wall. """ def __get__(self): - return self.leftSurface + return self.left_surface property right: """ The right surface of this wall. """ def __get__(self): - return self.rightSurface + return self.right_surface - property expansionRateCoeff: + property expansion_rate_coeff: """ The coefficient *K* [m/s/Pa] that determines the velocity of the wall as a function of the pressure difference between the adjacent reactors. @@ -408,7 +408,7 @@ cdef class Wall: def __set__(self, double value): self.wall.setArea(value) - property heatTransferCoeff: + property heat_transfer_coeff: """the overall heat transfer coefficient [W/m^2/K]""" def __get__(self): return self.wall.getHeatTransferCoeff() @@ -422,7 +422,7 @@ cdef class Wall: def __set__(self, double value): self.wall.setEmissivity(value) - def setVelocity(self, v): + def set_velocity(self, v): """ The wall velocity [m/s]. May be either a constant or an arbirary function of time. See `Func1`. @@ -433,10 +433,10 @@ cdef class Wall: else: f = Func1(v) - self._velocityFunc = f + self._velocity_func = f self.wall.setVelocity(f.func) - def setHeatFlux(self, q): + def set_heat_flux(self, q): """ Heat flux [W/m^2] across the wall. May be either a constant or an arbitrary function of time. See `Func1`. @@ -447,7 +447,7 @@ cdef class Wall: else: f = Func1(q) - self._heatFluxFunc = f + self._heat_flux_func = f self.wall.setHeatFlux(f.func) def vdot(self, double t): @@ -466,11 +466,11 @@ cdef class Wall: """ return self.wall.Q(t) - def _setKinetics(self): - cdef CxxKinetics* L = (self.leftSurface._kinetics.kinetics - if self.leftSurface._kinetics else NULL) - cdef CxxKinetics* R = (self.rightSurface._kinetics.kinetics - if self.rightSurface._kinetics else NULL) + def _set_kinetics(self): + cdef CxxKinetics* L = (self.left_surface._kinetics.kinetics + if self.left_surface._kinetics else NULL) + cdef CxxKinetics* R = (self.right_surface._kinetics.kinetics + if self.right_surface._kinetics else NULL) self.wall.setKinetics(L, R) @@ -491,7 +491,7 @@ cdef class FlowDevice: def __init__(self, upstream, downstream, *, name=None): assert self.dev != NULL - self._rateFunc = None + self._rate_func = None if name is not None: self.name = name @@ -510,8 +510,8 @@ cdef class FlowDevice: Install the device between the *upstream* (source) and *downstream* (destination) reactors or reservoirs. """ - upstream._addOutlet(self) - downstream._addInlet(self) + upstream._add_outlet(self) + downstream._add_inlet(self) self.dev.install(deref(upstream.rbase), deref(downstream.rbase)) def mdot(self, double t): @@ -548,15 +548,15 @@ cdef class MassFlowController(FlowDevice): def __init__(self, upstream, downstream, *, name=None, mdot=None): super().__init__(upstream, downstream, name=name) if mdot is not None: - self.setMassFlowRate(mdot) + self.set_mass_flow_rate(mdot) - def setMassFlowRate(self, m): + def set_mass_flow_rate(self, m): """ Set the mass flow rate [kg/s] through this controller to be either a constant or an arbitrary function of time. See `Func1`. - >>> mfc.setMassFlowRate(0.3) - >>> mfc.setMassFlowRate(lambda t: 2.5 * exp(-10 * (t - 0.5)**2)) + >>> mfc.set_mass_flow_rate(0.3) + >>> mfc.set_mass_flow_rate(lambda t: 2.5 * exp(-10 * (t - 0.5)**2)) """ cdef Func1 f if isinstance(m, Func1): @@ -564,7 +564,7 @@ cdef class MassFlowController(FlowDevice): else: f = Func1(m) - self._rateFunc = f + self._rate_func = f self.dev.setFunction(f.func) @@ -596,9 +596,9 @@ cdef class Valve(FlowDevice): def __init__(self, upstream, downstream, *, name=None, K=None): super().__init__(upstream, downstream, name=name) if K is not None: - self.setValveCoeff(K) + self.set_valve_coeff(K) - def setValveCoeff(self, k): + def set_valve_coeff(self, k): """ Set the relationship betwen mass flow rate and the pressure drop across the valve. If a number is given, it is the proportionality constant @@ -606,8 +606,8 @@ cdef class Valve(FlowDevice): rate [kg/s] given the pressure drop [Pa]. >>> V = Valve(res1, reactor1) - >>> V.setValveCoeff(1e-4) - >>> V.setValveCoeff(lambda dP: (1e-5 * dP)**2) + >>> V.set_valve_coeff(1e-4) + >>> V.set_valve_coeff(lambda dP: (1e-5 * dP)**2) """ cdef double kv cdef Func1 f @@ -620,7 +620,7 @@ cdef class Valve(FlowDevice): f = k else: f = Func1(k) - self._rateFunc = f + self._rate_func = f self.dev.setFunction(f.func) @@ -642,18 +642,18 @@ cdef class PressureController(FlowDevice): def __init__(self, upstream, downstream, *, name=None, master=None, K=None): super().__init__(upstream, downstream, name=name) if master is not None: - self.setMaster(master) + self.set_master(master) if K is not None: - self.setPressureCoeff(K) + self.set_pressure_coeff(K) - def setPressureCoeff(self, double k): + def set_pressure_coeff(self, double k): """ Set the proportionality constant *k* [kg/s/Pa] between the pressure drop and the mass flow rate. """ self.dev.setParameters(1, &k) - def setMaster(self, FlowDevice d): + def set_master(self, FlowDevice d): """ Set the "master" `FlowDevice` used to compute this device's mass flow rate. @@ -684,9 +684,9 @@ cdef class ReactorNet: def __init__(self, reactors=()): self._reactors = [] # prevents premature garbage collection for R in reactors: - self.addReactor(R) + self.add_reactor(R) - def addReactor(self, ReactorBase r): + def add_reactor(self, ReactorBase r): """Add a reactor to the network.""" self._reactors.append(r) self.net.addReactor(r.rbase) @@ -710,14 +710,14 @@ cdef class ReactorNet: def __get__(self): return self.net.time() - def setInitialTime(self, double t): + def set_initial_time(self, double t): """ Set the initial time. Restarts integration from this time using the current state as the initial condition. Default: 0.0 s. """ self.net.setInitialTime(t) - def setMaxTimeStep(self, double t): + def set_max_time_step(self, double t): """ Set the maximum time step *t* [s] that the integrator is allowed to use. @@ -744,7 +744,7 @@ cdef class ReactorNet: def __set__(self, tol): self.net.setTolerances(-1, tol) - property rtolSensitivity: + property rtol_sensitivity: """ The relative error tolerance for sensitivity analysis. """ @@ -753,7 +753,7 @@ cdef class ReactorNet: def __set__(self, tol): self.net.setSensitivityTolerances(tol, -1) - property atolSensitivity: + property atol_sensitivity: """ The absolute error tolerance for sensitivity analysis. """ @@ -780,20 +780,20 @@ cdef class ReactorNet: def sensitivities(self): cdef np.ndarray[np.double_t, ndim=2] data = \ - np.empty((self.nVars, self.nSensitivityParams)) + np.empty((self.n_vars, self.n_sensitivity_params)) cdef int p,k - for p in range(self.nSensitivityParams): - for k in range(self.nVars): + for p in range(self.n_sensitivity_params): + for k in range(self.n_vars): data[k,p] = self.net.sensitivity(k,p) return data - def sensitivityParameterName(self, int p): + def sensitivity_parameter_name(self, int p): return pystr(self.net.sensitivityParameterName(p)) - property nSensitivityParams: + property n_sensitivity_params: def __get__(self): return self.net.nparams() - property nVars: + property n_vars: def __get__(self): return self.net.neq() diff --git a/interfaces/cython/cantera/test/__init__.py b/interfaces/cython/cantera/test/__init__.py index 75b2fcc80..8416431c8 100644 --- a/interfaces/cython/cantera/test/__init__.py +++ b/interfaces/cython/cantera/test/__init__.py @@ -1,7 +1,7 @@ import os import cantera -cantera.addDirectory(os.path.dirname(__file__)) +cantera.add_directory(os.path.dirname(__file__)) from .test_thermo import * from .test_purefluid import * diff --git a/interfaces/cython/cantera/test/test_kinetics.py b/interfaces/cython/cantera/test/test_kinetics.py index 2119ad03d..be854c2aa 100644 --- a/interfaces/cython/cantera/test/test_kinetics.py +++ b/interfaces/cython/cantera/test/test_kinetics.py @@ -8,67 +8,67 @@ class TestKinetics(utilities.CanteraTest): def setUp(self): self.phase = ct.Solution('h2o2.xml') self.phase.X = [0.1, 1e-4, 1e-5, 0.2, 2e-4, 0.3, 1e-6, 5e-5, 0.4] - self.phase.TP = 800, 2*ct.OneAtm + self.phase.TP = 800, 2*ct.one_atm def test_counts(self): - self.assertEqual(self.phase.nReactions, 27) - self.assertEqual(self.phase.nTotalSpecies, 9) - self.assertEqual(self.phase.nPhases, 1) - self.assertEqual(self.phase.reactionPhaseIndex, 0) + self.assertEqual(self.phase.n_reactions, 27) + self.assertEqual(self.phase.n_total_species, 9) + self.assertEqual(self.phase.n_phases, 1) + self.assertEqual(self.phase.reaction_phase_index, 0) - def test_isReversible(self): - for i in range(self.phase.nReactions): - self.assertTrue(self.phase.isReversible(i)) + def test_is_reversible(self): + for i in range(self.phase.n_reactions): + self.assertTrue(self.phase.is_reversible(i)) def test_multiplier(self): - fwd_rates0 = self.phase.fwdRatesOfProgress - rev_rates0 = self.phase.revRatesOfProgress + fwd_rates0 = self.phase.forward_rates_of_progress + rev_rates0 = self.phase.reverse_rates_of_progress - self.phase.setMultiplier(2.0, 0) - self.phase.setMultiplier(0.1, 6) + self.phase.set_multiplier(2.0, 0) + self.phase.set_multiplier(0.1, 6) - fwd_rates1 = self.phase.fwdRatesOfProgress - rev_rates1 = self.phase.revRatesOfProgress + fwd_rates1 = self.phase.forward_rates_of_progress + rev_rates1 = self.phase.reverse_rates_of_progress self.assertNear(2 * fwd_rates0[0], fwd_rates1[0]) self.assertNear(0.1 * fwd_rates0[6], fwd_rates1[6]) self.assertNear(2 * rev_rates0[0], rev_rates1[0]) self.assertNear(0.1 * rev_rates0[6], rev_rates1[6]) - for i in range(self.phase.nReactions): + for i in range(self.phase.n_reactions): if i not in (0,6): self.assertNear(fwd_rates0[i], fwd_rates1[i]) self.assertNear(rev_rates0[i], rev_rates1[i]) - self.phase.setMultiplier(0.5) - fwd_rates2 = self.phase.fwdRatesOfProgress - rev_rates2 = self.phase.revRatesOfProgress + self.phase.set_multiplier(0.5) + fwd_rates2 = self.phase.forward_rates_of_progress + rev_rates2 = self.phase.reverse_rates_of_progress self.assertArrayNear(0.5 * fwd_rates0, fwd_rates2) self.assertArrayNear(0.5 * rev_rates0, rev_rates2) - def test_reactionType(self): - self.assertNear(self.phase.reactionType(0), 2) # 3rd body - self.assertNear(self.phase.reactionType(2), 1) # elementary - self.assertNear(self.phase.reactionType(19), 4) # falloff + def test_reaction_type(self): + self.assertNear(self.phase.reaction_type(0), 2) # 3rd body + self.assertNear(self.phase.reaction_type(2), 1) # elementary + self.assertNear(self.phase.reaction_type(19), 4) # falloff - self.assertRaises(ValueError, self.phase.reactionType, 33) - self.assertRaises(ValueError, self.phase.reactionType, -2) + self.assertRaises(ValueError, self.phase.reaction_type, 33) + self.assertRaises(ValueError, self.phase.reaction_type, -2) - def test_reactionEquations(self): - self.assertEqual(self.phase.nReactions, - len(self.phase.reactionEquations())) - self.assertEqual(self.phase.reactionEquation(16), + def test_reaction_equations(self): + self.assertEqual(self.phase.n_reactions, + len(self.phase.reaction_equations())) + self.assertEqual(self.phase.reaction_equation(16), 'H + H2O2 <=> HO2 + H2') - def test_stoichCoeffs(self): - nu_r = self.phase.reactantStoichCoeffs() - nu_p = self.phase.productStoichCoeffs() + def test_stoich_coeffs(self): + nu_r = self.phase.reactant_stoich_coeffs() + nu_p = self.phase.product_stoich_coeffs() def check_reactant(k, i, value): - self.assertEqual(self.phase.reactantStoichCoeff(k,i), value) + self.assertEqual(self.phase.reactant_stoich_coeff(k,i), value) self.assertEqual(nu_r[k,i], value) def check_product(k, i, value): - self.assertEqual(self.phase.productStoichCoeff(k,i), value) + self.assertEqual(self.phase.product_stoich_coeff(k,i), value) self.assertEqual(nu_p[k,i], value) # H + H2O2 <=> HO2 + H2 @@ -88,34 +88,34 @@ class TestKinetics(utilities.CanteraTest): check_product(2, 0, 0) check_product(3, 0, 1) - def test_ratesOfProgress(self): - self.assertEqual(len(self.phase.netRatesOfProgress), - self.phase.nReactions) - self.assertArrayNear(self.phase.fwdRatesOfProgress - self.phase.revRatesOfProgress, - self.phase.netRatesOfProgress) + def test_rates_of_progress(self): + self.assertEqual(len(self.phase.net_rates_of_progress), + self.phase.n_reactions) + self.assertArrayNear(self.phase.forward_rates_of_progress - self.phase.reverse_rates_of_progress, + self.phase.net_rates_of_progress) - def test_rateConstants(self): - self.assertEqual(len(self.phase.fwdRateConstants), self.phase.nReactions) - self.assertArrayNear(self.phase.fwdRateConstants / self.phase.revRateConstants, - self.phase.equilibriumConstants) + def test_rate_constants(self): + self.assertEqual(len(self.phase.forward_rate_constants), self.phase.n_reactions) + self.assertArrayNear(self.phase.forward_rate_constants / self.phase.reverse_rate_constants, + self.phase.equilibrium_constants) def test_species_rates(self): - nu_p = self.phase.productStoichCoeffs() - nu_r = self.phase.reactantStoichCoeffs() - creation = (np.dot(nu_p, self.phase.fwdRatesOfProgress) + - np.dot(nu_r, self.phase.revRatesOfProgress)) - destruction = (np.dot(nu_r, self.phase.fwdRatesOfProgress) + - np.dot(nu_p, self.phase.revRatesOfProgress)) + nu_p = self.phase.product_stoich_coeffs() + nu_r = self.phase.reactant_stoich_coeffs() + creation = (np.dot(nu_p, self.phase.forward_rates_of_progress) + + np.dot(nu_r, self.phase.reverse_rates_of_progress)) + destruction = (np.dot(nu_r, self.phase.forward_rates_of_progress) + + np.dot(nu_p, self.phase.reverse_rates_of_progress)) - self.assertArrayNear(self.phase.creationRates, creation) - self.assertArrayNear(self.phase.destructionRates, destruction) - self.assertArrayNear(self.phase.netProductionRates, + self.assertArrayNear(self.phase.creation_rates, creation) + self.assertArrayNear(self.phase.destruction_rates, destruction) + self.assertArrayNear(self.phase.net_production_rates, creation - destruction) def test_reaction_deltas(self): - self.assertArrayNear(self.phase.deltaEnthalpy - - self.phase.deltaEntropy * self.phase.T, - self.phase.deltaGibbs) - self.assertArrayNear(self.phase.deltaStandardEnthalpy - - self.phase.deltaStandardEntropy * self.phase.T, - self.phase.deltaStandardGibbs) + self.assertArrayNear(self.phase.delta_enthalpy - + self.phase.delta_entropy * self.phase.T, + self.phase.delta_gibbs) + self.assertArrayNear(self.phase.delta_standard_enthalpy - + self.phase.delta_standard_entropy * self.phase.T, + self.phase.delta_standard_gibbs) diff --git a/interfaces/cython/cantera/test/test_mixture.py b/interfaces/cython/cantera/test/test_mixture.py index 13e3266e6..940215e06 100644 --- a/interfaces/cython/cantera/test/test_mixture.py +++ b/interfaces/cython/cantera/test/test_mixture.py @@ -13,88 +13,88 @@ class TestMixture(utilities.CanteraTest): self.mix = ct.Mixture([(self.phase1, 1.0), (self.phase2, 2.0)]) def test_sizes(self): - self.assertEqual(self.mix.nPhases, 2) + self.assertEqual(self.mix.n_phases, 2) - self.assertEqual(self.mix.nSpecies, - self.phase1.nSpecies + self.phase2.nSpecies) + self.assertEqual(self.mix.n_species, + self.phase1.n_species + self.phase2.n_species) - E = set(self.phase1.elementNames) | set(self.phase2.elementNames) - self.assertEqual(len(E), self.mix.nElements) + E = set(self.phase1.element_names) | set(self.phase2.element_names) + self.assertEqual(len(E), self.mix.n_elements) - def test_elementIndex(self): - m_H = self.mix.elementIndex('H') - self.assertEqual(m_H, self.mix.elementIndex(m_H)) + def test_element_index(self): + m_H = self.mix.element_index('H') + self.assertEqual(m_H, self.mix.element_index(m_H)) with self.assertRaises(ValueError): - self.mix.elementIndex('W') + self.mix.element_index('W') with self.assertRaises(ValueError): - self.mix.elementIndex(41) + self.mix.element_index(41) with self.assertRaises(TypeError): - self.mix.elementIndex(None) + self.mix.element_index(None) def test_speciesIndex(self): - names = self.mix.speciesNames + names = self.mix.species_names kOH = names.index('OH') kN2 = names.index('N2') - self.assertEqual(self.mix.speciesName(kOH), 'OH') - self.assertEqual(self.mix.speciesName(kN2), 'N2') + self.assertEqual(self.mix.species_name(kOH), 'OH') + self.assertEqual(self.mix.species_name(kN2), 'N2') - self.assertEqual(self.mix.speciesIndex(0, 'OH'), kOH) - self.assertEqual(self.mix.speciesIndex(self.phase1, 'OH'), kOH) - self.assertEqual(self.mix.speciesIndex(self.phase1.name, 'OH'), kOH) - self.assertEqual(self.mix.speciesIndex(0, self.phase1.speciesIndex('OH')), kOH) - self.assertEqual(self.mix.speciesIndex(1, self.phase2.speciesIndex('N2')), kN2) - self.assertEqual(self.mix.speciesIndex(1, 'N2'), kN2) + self.assertEqual(self.mix.species_index(0, 'OH'), kOH) + self.assertEqual(self.mix.species_index(self.phase1, 'OH'), kOH) + self.assertEqual(self.mix.species_index(self.phase1.name, 'OH'), kOH) + self.assertEqual(self.mix.species_index(0, self.phase1.species_index('OH')), kOH) + self.assertEqual(self.mix.species_index(1, self.phase2.species_index('N2')), kN2) + self.assertEqual(self.mix.species_index(1, 'N2'), kN2) with self.assertRaises(IndexError): - self.mix.speciesIndex(3, 'OH') + self.mix.species_index(3, 'OH') with self.assertRaises(ValueError): - self.mix.speciesIndex(1, 'OH') + self.mix.species_index(1, 'OH') with self.assertRaises(ValueError): - self.mix.speciesIndex(0, -2) + self.mix.species_index(0, -2) with self.assertRaises(ValueError): - self.mix.speciesIndex(1, 'CO2') + self.mix.species_index(1, 'CO2') - def test_nAtoms(self): - names = self.mix.speciesNames + def test_n_atoms(self): + names = self.mix.species_names kOH = names.index('OH') kN2 = names.index('N2') - mH = self.mix.elementIndex('H') - mN = self.mix.elementIndex('N') + mH = self.mix.element_index('H') + mN = self.mix.element_index('N') - self.assertEqual(self.mix.nAtoms(kOH, 'H'), 1) - self.assertEqual(self.mix.nAtoms(kOH, 'O'), 1) - self.assertEqual(self.mix.nAtoms(kOH, mH), 1) - self.assertEqual(self.mix.nAtoms(kOH, mN), 0) + self.assertEqual(self.mix.n_atoms(kOH, 'H'), 1) + self.assertEqual(self.mix.n_atoms(kOH, 'O'), 1) + self.assertEqual(self.mix.n_atoms(kOH, mH), 1) + self.assertEqual(self.mix.n_atoms(kOH, mN), 0) - self.assertEqual(self.mix.nAtoms(kN2, mN), 2) - self.assertEqual(self.mix.nAtoms(kN2, mH), 0) + self.assertEqual(self.mix.n_atoms(kN2, mN), 2) + self.assertEqual(self.mix.n_atoms(kN2, mH), 0) def test_phase(self): self.assertEqual(self.phase1, self.mix.phase(0)) self.assertEqual(self.phase2, self.mix.phase(1)) - phaseNames = self.mix.phaseNames - self.assertEqual(len(phaseNames), self.mix.nPhases) + phaseNames = self.mix.phase_names + self.assertEqual(len(phaseNames), self.mix.n_phases) self.assertEqual(phaseNames[0], self.phase1.name) self.assertEqual(phaseNames[1], self.phase2.name) - def test_phaseIndex(self): - self.assertEqual(self.mix.phaseIndex(self.phase1), 0) - self.assertEqual(self.mix.phaseIndex(self.phase2), 1) - self.assertEqual(self.mix.phaseIndex(self.phase2.name), 1) - self.assertEqual(self.mix.phaseIndex(1), 1) + def test_phase_index(self): + self.assertEqual(self.mix.phase_index(self.phase1), 0) + self.assertEqual(self.mix.phase_index(self.phase2), 1) + self.assertEqual(self.mix.phase_index(self.phase2.name), 1) + self.assertEqual(self.mix.phase_index(1), 1) with self.assertRaises(KeyError): - self.mix.phaseIndex('foobar') + self.mix.phase_index('foobar') with self.assertRaises(IndexError): - self.mix.phaseIndex(2) + self.mix.phase_index(2) def test_properties(self): self.mix.T = 350 @@ -104,79 +104,79 @@ class TestMixture(utilities.CanteraTest): self.assertEqual(self.mix.P, 2e5) self.assertEqual(self.mix.T, 350) - self.assertGreater(self.mix.maxTemp, self.mix.minTemp) + self.assertGreater(self.mix.max_temp, self.mix.min_temp) def test_charge(self): - C = sum(self.mix.phaseCharge(i) for i in range(self.mix.nPhases)) + C = sum(self.mix.phase_charge(i) for i in range(self.mix.n_phases)) self.assertEqual(self.mix.charge, C) - def test_phaseMoles(self): - M = self.mix.phaseMoles() - self.assertEqual(M[0], self.mix.phaseMoles(0)) - self.assertEqual(M[1], self.mix.phaseMoles('air')) + def test_phase_moles(self): + M = self.mix.phase_moles() + self.assertEqual(M[0], self.mix.phase_moles(0)) + self.assertEqual(M[1], self.mix.phase_moles('air')) - self.mix.setPhaseMoles('air', 4) - self.assertEqual(self.mix.phaseMoles(1), 4) + self.mix.set_phase_moles('air', 4) + self.assertEqual(self.mix.phase_moles(1), 4) - def test_speciesMoles(self): - self.mix.setSpeciesMoles('H2:1.0, N2:4.0') - P = self.mix.phaseMoles() - S = self.mix.speciesMoles() + def test_species_moles(self): + self.mix.set_species_moles('H2:1.0, N2:4.0') + P = self.mix.phase_moles() + S = self.mix.species_moles() self.assertEqual(P[0], 1) self.assertEqual(P[1], 4) - self.assertEqual(S[self.mix.speciesIndex(0, 'H2')], 1) - self.assertEqual(S[self.mix.speciesIndex(1, 'N2')], 4) + self.assertEqual(S[self.mix.species_index(0, 'H2')], 1) + self.assertEqual(S[self.mix.species_index(1, 'N2')], 4) S[2] = 7 - self.mix.setSpeciesMoles(S) - self.assertNear(self.mix.speciesMoles(2), S[2]) - self.assertNear(self.mix.phaseMoles(0), sum(S[:self.phase1.nSpecies])) + self.mix.set_species_moles(S) + self.assertNear(self.mix.species_moles(2), S[2]) + self.assertNear(self.mix.phase_moles(0), sum(S[:self.phase1.n_species])) with self.assertRaises(ValueError): - self.mix.setSpeciesMoles((1,2,3)) + self.mix.set_species_moles((1,2,3)) with self.assertRaises(TypeError): - self.mix.setSpeciesMoles(9) + self.mix.set_species_moles(9) - def test_elementMoles(self): - self.mix.setSpeciesMoles('H2:1.0, OH:4.0') + def test_element_moles(self): + self.mix.set_species_moles('H2:1.0, OH:4.0') - self.assertNear(self.mix.elementMoles('H'), 6) - self.assertNear(self.mix.elementMoles('O'), 4) - self.assertNear(self.mix.elementMoles('N'), 0) + self.assertNear(self.mix.element_moles('H'), 6) + self.assertNear(self.mix.element_moles('O'), 4) + self.assertNear(self.mix.element_moles('N'), 0) - def test_chem_potentials(self): - C = self.mix.chem_potentials - C1 = self.phase1.chem_potentials - C2 = self.phase2.chem_potentials + def test_chemical_potentials(self): + C = self.mix.chemical_potentials + C1 = self.phase1.chemical_potentials + C2 = self.phase2.chemical_potentials - self.assertArrayNear(C[:self.phase1.nSpecies], C1) - self.assertArrayNear(C[self.phase1.nSpecies:], C2) + self.assertArrayNear(C[:self.phase1.n_species], C1) + self.assertArrayNear(C[self.phase1.n_species:], C2) def test_equilibrate1(self): - self.mix.setSpeciesMoles('H2:1.0, O2:0.5, N2:1.0') + self.mix.set_species_moles('H2:1.0, O2:0.5, N2:1.0') self.mix.T = 400 - self.mix.P = 2 * ct.OneAtm + self.mix.P = 2 * ct.one_atm - E1 = [self.mix.elementMoles(m) for m in range(self.mix.nElements)] + E1 = [self.mix.element_moles(m) for m in range(self.mix.n_elements)] self.mix.equilibrate('TP') - E2 = [self.mix.elementMoles(m) for m in range(self.mix.nElements)] + E2 = [self.mix.element_moles(m) for m in range(self.mix.n_elements)] self.assertArrayNear(E1, E2) self.assertNear(self.mix.T, 400) - self.assertNear(self.mix.P, 2 * ct.OneAtm) + self.assertNear(self.mix.P, 2 * ct.one_atm) def test_equilibrate2(self): - self.mix.setSpeciesMoles('H2:1.0, O2:0.5, N2:1.0') + self.mix.set_species_moles('H2:1.0, O2:0.5, N2:1.0') self.mix.T = 400 - self.mix.P = 2 * ct.OneAtm + self.mix.P = 2 * ct.one_atm - E1 = [self.mix.elementMoles(m) for m in range(self.mix.nElements)] + E1 = [self.mix.element_moles(m) for m in range(self.mix.n_elements)] self.mix.equilibrate('TP', solver='gibbs') - E2 = [self.mix.elementMoles(m) for m in range(self.mix.nElements)] + E2 = [self.mix.element_moles(m) for m in range(self.mix.n_elements)] self.assertArrayNear(E1, E2) self.assertNear(self.mix.T, 400) - self.assertNear(self.mix.P, 2 * ct.OneAtm) + self.assertNear(self.mix.P, 2 * ct.one_atm) diff --git a/interfaces/cython/cantera/test/test_onedim.py b/interfaces/cython/cantera/test/test_onedim.py index 4a3ad305d..06c3d21b8 100644 --- a/interfaces/cython/cantera/test/test_onedim.py +++ b/interfaces/cython/cantera/test/test_onedim.py @@ -21,7 +21,7 @@ class TestOnedim(utilities.CanteraTest): interface = ct.Solution('diamond.xml', 'diamond_100', (gas, solid)) surface = ct.ReactingSurface1D() - surface.setKinetics(interface) + surface.set_kinetics(interface) class TestFreeFlame(utilities.CanteraTest): @@ -37,8 +37,8 @@ class TestFreeFlame(utilities.CanteraTest): # Flame object self.sim = ct.FreeFlame(self.gas, initial_grid) - self.sim.flame.setSteadyTolerances(default=tol_ss) - self.sim.flame.setTransientTolerances(default=tol_ts) + self.sim.flame.set_steady_tolerances(default=tol_ss) + self.sim.flame.set_transient_tolerances(default=tol_ts) # Set properties of the upstream fuel-air mixture self.sim.inlet.T = Tin @@ -46,35 +46,35 @@ class TestFreeFlame(utilities.CanteraTest): def solve_fixed_T(self): # Solve with the energy equation disabled - self.sim.energyEnabled = False - self.sim.setMaxJacAge(50, 50) - self.sim.setTimeStep(1e-5, [2, 5, 10, 20]) + self.sim.energy_enabled = False + self.sim.set_max_jac_age(50, 50) + self.sim.set_time_step(1e-5, [2, 5, 10, 20]) self.sim.solve(loglevel=0, refine_grid=False) - self.assertFalse(self.sim.energyEnabled) + self.assertFalse(self.sim.energy_enabled) def solve_mix(self, ratio=3.0, slope=0.3, curve=0.2, prune=0.0): # Solve with the energy equation enabled - self.sim.setRefineCriteria(ratio=ratio, slope=slope, curve=curve, prune=prune) - self.sim.energyEnabled = True + self.sim.set_refine_criteria(ratio=ratio, slope=slope, curve=curve, prune=prune) + self.sim.energy_enabled = True self.sim.solve(loglevel=0, refine_grid=True) - self.assertTrue(self.sim.energyEnabled) - self.assertEqual(self.sim.transportModel, 'Mix') + self.assertTrue(self.sim.energy_enabled) + self.assertEqual(self.sim.transport_model, 'Mix') def solve_multi(self): - self.sim.transportModel = 'Multi' + self.sim.transport_model = 'Multi' self.sim.solve(loglevel=0, refine_grid=True) - self.assertEqual(self.sim.transportModel, 'Multi') + self.assertEqual(self.sim.transport_model, 'Multi') def test_converge_adiabatic(self): # Test that the adiabatic flame temperature and species profiles # converge to the correct equilibrium values as the grid is refined reactants= 'H2:1.1, O2:1, AR:5' - p = ct.OneAtm + p = ct.one_atm Tin = 300 self.create_sim(p, Tin, reactants) @@ -100,13 +100,13 @@ class TestFreeFlame(utilities.CanteraTest): self.assertLess(abs(T2-Tad), abs(T1-Tad)) self.assertLess(abs(T3-Tad), abs(T2-Tad)) - for k in range(self.gas.nSpecies): + for k in range(self.gas.n_species): self.assertLess(abs(X2[k]-Xad[k]), abs(X1[k]-Xad[k])) self.assertLess(abs(X3[k]-Xad[k]), abs(X2[k]-Xad[k])) def test_mixture_averaged(self): reactants= 'H2:1.1, O2:1, AR:5' - p = ct.OneAtm + p = ct.one_atm Tin = 300 self.create_sim(p, Tin, reactants) @@ -125,7 +125,7 @@ class TestFreeFlame(utilities.CanteraTest): # @utilities.unittest.skip('sometimes slow') def test_multicomponent(self): reactants= 'H2:1.1, O2:1, AR:5.3' - p = ct.OneAtm + p = ct.one_atm Tin = 300 self.create_sim(p, Tin, reactants) @@ -137,16 +137,16 @@ class TestFreeFlame(utilities.CanteraTest): # the mixture-averaged flame speed. self.solve_multi() Su_multi = self.sim.u[0] - self.assertFalse(self.sim.soretEnabled) + self.assertFalse(self.sim.soret_enabled) self.assertNear(Su_mix, Su_multi, 5e-2) self.assertNotEqual(Su_mix, Su_multi) # Flame speed with Soret effect should be similar but not identical to # the multicomponent flame speed - self.sim.soretEnabled = True + self.sim.soret_enabled = True self.sim.solve(loglevel=0, refine_grid=True) - self.assertTrue(self.sim.soretEnabled) + self.assertTrue(self.sim.soret_enabled) Su_soret = self.sim.u[0] self.assertNear(Su_multi, Su_soret, 2e-1) @@ -154,7 +154,7 @@ class TestFreeFlame(utilities.CanteraTest): def test_prune(self): reactants= 'H2:1.1, O2:1, AR:5' - p = ct.OneAtm + p = ct.one_atm Tin = 300 self.create_sim(p, Tin, reactants) @@ -172,7 +172,7 @@ class TestFreeFlame(utilities.CanteraTest): def test_save_restore(self): reactants= 'H2:1.1, O2:1, AR:5' - p = 2 * ct.OneAtm + p = 2 * ct.one_atm Tin = 400 self.create_sim(p, Tin, reactants) @@ -188,8 +188,8 @@ class TestFreeFlame(utilities.CanteraTest): self.sim.save(filename, 'test', loglevel=0) - self.create_sim(ct.OneAtm, Tin, reactants) - self.sim.energyEnabled = False + self.create_sim(ct.one_atm, Tin, reactants) + self.sim.energy_enabled = False self.sim.restore(filename, 'test', loglevel=0) P2a = self.sim.P @@ -215,7 +215,7 @@ class TestFreeFlame(utilities.CanteraTest): self.assertArrayNear(V1, V3, 1e-3) def test_array_properties(self): - self.create_sim(ct.OneAtm, 300, 'H2:1.1, O2:1, AR:5') + self.create_sim(ct.one_atm, 300, 'H2:1.1, O2:1, AR:5') for attr in ct.FlameBase.__dict__: if isinstance(ct.FlameBase.__dict__[attr], property): @@ -244,8 +244,8 @@ class TestDiffusionFlame(utilities.CanteraTest): # Flame object self.sim = ct.CounterflowDiffusionFlame(self.gas, initial_grid) - self.sim.flame.setSteadyTolerances(default=tol_ss) - self.sim.flame.setTransientTolerances(default=tol_ts) + self.sim.flame.set_steady_tolerances(default=tol_ss) + self.sim.flame.set_transient_tolerances(default=tol_ts) # Set properties of the fuel and oxidizer mixtures self.sim.fuel_inlet.mdot = mdot_fuel @@ -256,27 +256,27 @@ class TestDiffusionFlame(utilities.CanteraTest): self.sim.oxidizer_inlet.X = oxidizer self.sim.oxidizer_inlet.T = T_ox - self.sim.setInitialGuess(fuel='H2') + self.sim.set_initial_guess(fuel='H2') def solve_fixed_T(self): # Solve with the energy equation disabled - self.sim.energyEnabled = False + self.sim.energy_enabled = False self.sim.solve(loglevel=0, refine_grid=False) - self.assertFalse(self.sim.energyEnabled) + self.assertFalse(self.sim.energy_enabled) def solve_mix(self, ratio=3.0, slope=0.1, curve=0.12, prune=0.0): # Solve with the energy equation enabled - self.sim.setRefineCriteria(ratio=ratio, slope=slope, curve=curve, prune=prune) - self.sim.energyEnabled = True + self.sim.set_refine_criteria(ratio=ratio, slope=slope, curve=curve, prune=prune) + self.sim.energy_enabled = True self.sim.solve(loglevel=0, refine_grid=True) - self.assertTrue(self.sim.energyEnabled) - self.assertEqual(self.sim.transportModel, 'Mix') + self.assertTrue(self.sim.energy_enabled) + self.assertEqual(self.sim.transport_model, 'Mix') def test_mixture_averaged(self, saveReference=False): - self.create_sim(p=ct.OneAtm) + self.create_sim(p=ct.one_atm) nPoints = len(self.sim.grid) Tfixed = self.sim.T @@ -285,7 +285,7 @@ class TestDiffusionFlame(utilities.CanteraTest): self.assertArrayNear(Tfixed, self.sim.T) self.solve_mix() - data = np.empty((self.sim.flame.nPoints, self.gas.nSpecies + 4)) + data = np.empty((self.sim.flame.n_points, self.gas.n_species + 4)) data[:,0] = self.sim.grid data[:,1] = self.sim.u data[:,2] = self.sim.V diff --git a/interfaces/cython/cantera/test/test_purefluid.py b/interfaces/cython/cantera/test/test_purefluid.py index 2f9dba0dd..c54210a34 100644 --- a/interfaces/cython/cantera/test/test_purefluid.py +++ b/interfaces/cython/cantera/test/test_purefluid.py @@ -5,12 +5,12 @@ class TestPureFluid(utilities.CanteraTest): def setUp(self): self.water = ct.Water() - def test_critProperties(self): - self.assertNear(self.water.critPressure, 22.089e6) - self.assertNear(self.water.critTemperature, 647.286) - self.assertNear(self.water.critDensity, 317.0) + def test_critical_properties(self): + self.assertNear(self.water.critical_pressure, 22.089e6) + self.assertNear(self.water.critical_temperature, 647.286) + self.assertNear(self.water.critical_density, 317.0) - def test_setState(self): + def test_set_state(self): self.water.PX = 101325, 0.5 self.assertNear(self.water.P, 101325) self.assertNear(self.water.X, 0.5) diff --git a/interfaces/cython/cantera/test/test_reactor.py b/interfaces/cython/cantera/test/test_reactor.py index 75cdacac8..1743211b8 100644 --- a/interfaces/cython/cantera/test/test_reactor.py +++ b/interfaces/cython/cantera/test/test_reactor.py @@ -7,7 +7,7 @@ from . import utilities class TestReactor(utilities.CanteraTest): - def makeReactors(self, independent=True, nReactors=2, + def make_reactors(self, independent=True, n_reactors=2, T1=300, P1=101325, X1='O2:1.0', T2=300, P2=101325, X2='O2:1.0'): @@ -16,26 +16,26 @@ class TestReactor(utilities.CanteraTest): self.gas1 = ct.Solution('h2o2.xml') self.gas1.TPX = T1, P1, X1 self.r1 = ct.Reactor(self.gas1) - self.net.addReactor(self.r1) + self.net.add_reactor(self.r1) if independent: self.gas2 = ct.Solution('h2o2.xml') else: self.gas2 = self.gas1 - if nReactors >= 2: + if n_reactors >= 2: self.gas2.TPX = T2, P2, X2 self.r2 = ct.Reactor(self.gas2) - self.net.addReactor(self.r2) + self.net.add_reactor(self.r2) - def addWall(self, **kwargs): + def add_wall(self, **kwargs): self.w = ct.Wall(self.r1, self.r2, **kwargs) return self.w def test_insert(self): R = ct.Reactor() f1 = lambda r: r.T - f2 = lambda r: r.kinetics.netProductionRates + f2 = lambda r: r.kinetics.net_production_rates self.assertRaises(Exception, f1, R) self.assertRaises(Exception, f2, R) @@ -44,10 +44,10 @@ class TestReactor(utilities.CanteraTest): R.insert(g) self.assertNear(R.T, 300) - self.assertEqual(len(R.kinetics.netProductionRates), g.nSpecies) + self.assertEqual(len(R.kinetics.net_production_rates), g.n_species) def test_names(self): - self.makeReactors() + self.make_reactors() pattern = re.compile(r'(\d+)') digits1 = pattern.search(self.r1.name).group(0) @@ -62,7 +62,7 @@ class TestReactor(utilities.CanteraTest): T1, P1 = 300, 101325 T2, P2 = 500, 300000 - self.makeReactors(T1=T1, T2=T2, P1=P1, P2=P2) + self.make_reactors(T1=T1, T2=T2, P1=P1, P2=P2) self.net.advance(1.0) # Nothing should change from the initial condition @@ -75,7 +75,7 @@ class TestReactor(utilities.CanteraTest): T1, P1 = 300, 101325 T2, P2 = 500, 300000 - self.makeReactors(T1=T1, T2=T2, P1=P1, P2=P2, independent=False) + self.make_reactors(T1=T1, T2=T2, P1=P1, P2=P2, independent=False) self.net.advance(1.0) # Nothing should change from the initial condition @@ -85,14 +85,14 @@ class TestReactor(utilities.CanteraTest): self.assertNear(P2, self.r2.thermo.P) def test_timestepping(self): - self.makeReactors() + self.make_reactors() tStart = 0.3 tEnd = 10.0 dt_max = 0.07 t = tStart - self.net.setMaxTimeStep(dt_max) - self.net.setInitialTime(tStart) + self.net.set_max_time_step(dt_max) + self.net.set_initial_time(tStart) self.assertNear(self.net.time, tStart) while t < tEnd: @@ -103,9 +103,9 @@ class TestReactor(utilities.CanteraTest): #self.assertNear(self.net.time, tEnd) - def test_equalizePressure(self): - self.makeReactors(P1=101325, P2=300000) - self.addWall(K=0.1, A=1.0) + def test_equalize_pressure(self): + self.make_reactors(P1=101325, P2=300000) + self.add_wall(K=0.1, A=1.0) self.assertEqual(len(self.r1.walls), 1) self.assertEqual(len(self.r2.walls), 1) @@ -120,10 +120,10 @@ class TestReactor(utilities.CanteraTest): def test_tolerances(self): def integrate(atol, rtol): - P0 = 10 * ct.OneAtm + P0 = 10 * ct.one_atm T0 = 1100 X0 = 'H2:1.0, O2:0.5, AR:8.0' - self.makeReactors(nReactors=1, T1=T0, P1=P0, X1=X0) + self.make_reactors(n_reactors=1, T1=T0, P1=P0, X1=X0) self.net.rtol = rtol self.net.atol = atol @@ -147,34 +147,34 @@ class TestReactor(utilities.CanteraTest): self.assertTrue(n_baseline > n_rtol) self.assertTrue(n_baseline > n_atol) - def test_heatTransfer1(self): + def test_heat_transfer1(self): # Connected reactors reach thermal equilibrium after some time - self.makeReactors(T1=300, T2=1000) - self.addWall(U=500, A=1.0) + self.make_reactors(T1=300, T2=1000) + self.add_wall(U=500, A=1.0) self.net.advance(10.0) self.assertNear(self.net.time, 10.0) self.assertNear(self.r1.T, self.r2.T, 1e-7) self.assertNotAlmostEqual(self.r1.thermo.P, self.r2.thermo.P) - def test_heatTransfer2(self): + def test_heat_transfer2(self): # Result should be the same if (m * cp) / (U * A) is held constant - self.makeReactors(T1=300, T2=1000) - self.addWall(U=200, A=1.0) + self.make_reactors(T1=300, T2=1000) + self.add_wall(U=200, A=1.0) self.net.advance(1.0) T1a = self.r1.T T2a = self.r2.T - self.makeReactors(T1=300, T2=1000) + self.make_reactors(T1=300, T2=1000) self.r1.volume = 0.25 self.r2.volume = 0.25 - w = self.addWall(U=100, A=0.5) + w = self.add_wall(U=100, A=0.5) - self.assertNear(w.heatTransferCoeff * w.area * (self.r1.T - self.r2.T), + self.assertNear(w.heat_transfer_coeff * w.area * (self.r1.T - self.r2.T), w.qdot(0)) self.net.advance(1.0) - self.assertNear(w.heatTransferCoeff * w.area * (self.r1.T - self.r2.T), + self.assertNear(w.heat_transfer_coeff * w.area * (self.r1.T - self.r2.T), w.qdot(1.0)) T1b = self.r1.T T2b = self.r2.T @@ -186,10 +186,10 @@ class TestReactor(utilities.CanteraTest): # Adiabatic, constant volume combustion should proceed to equilibrum # at constant internal energy and volume. - P0 = 10 * ct.OneAtm + P0 = 10 * ct.one_atm T0 = 1100 X0 = 'H2:1.0, O2:0.5, AR:8.0' - self.makeReactors(nReactors=1, T1=T0, P1=P0, X1=X0) + self.make_reactors(n_reactors=1, T1=T0, P1=P0, X1=X0) self.net.advance(1.0) @@ -206,7 +206,7 @@ class TestReactor(utilities.CanteraTest): # Adiabatic, constant pressure combustion should proceed to equilibrum # at constant enthalpy and pressure. - P0 = 10 * ct.OneAtm + P0 = 10 * ct.one_atm T0 = 1100 X0 = 'H2:1.0, O2:0.5, AR:8.0' @@ -215,7 +215,7 @@ class TestReactor(utilities.CanteraTest): r1 = ct.ConstPressureReactor(gas1) net = ct.ReactorNet() - net.addReactor(r1) + net.add_reactor(r1) net.advance(1.0) gas2 = ct.Solution('h2o2.xml') @@ -228,7 +228,7 @@ class TestReactor(utilities.CanteraTest): self.assertArrayNear(r1.thermo.X, gas2.X) def test_wall_velocity(self): - self.makeReactors() + self.make_reactors() A = 0.2 V1 = 2.0 @@ -236,7 +236,7 @@ class TestReactor(utilities.CanteraTest): self.r1.volume = V1 self.r2.volume = V2 - self.addWall(A=A) + self.add_wall(A=A) def v(t): if 0 < t <= 1: @@ -246,7 +246,7 @@ class TestReactor(utilities.CanteraTest): else: return 0.0 - self.w.setVelocity(v) + self.w.set_velocity(v) self.net.advance(1.0) self.assertNear(self.w.vdot(1.0), 1.0 * A, 1e-7) self.net.advance(2.0) @@ -256,9 +256,9 @@ class TestReactor(utilities.CanteraTest): self.assertNear(self.r2.volume, V2 - 1.0 * A) def test_disable_energy(self): - self.makeReactors(T1=500) - self.r1.energyEnabled = False - self.addWall(A=1.0, U=2500) + self.make_reactors(T1=500) + self.r1.energy_enabled = False + self.add_wall(A=1.0, U=2500) self.net.advance(11.0) @@ -266,7 +266,7 @@ class TestReactor(utilities.CanteraTest): self.assertNear(self.r2.T, 500) def test_heat_flux_func(self): - self.makeReactors(T1=500, T2=300) + self.make_reactors(T1=500, T2=300) self.r1.volume = 0.5 U1a = self.r1.volume * self.r1.density * self.r1.thermo.u @@ -275,8 +275,8 @@ class TestReactor(utilities.CanteraTest): V1a = self.r1.volume V2a = self.r2.volume - self.addWall(A=0.3) - self.w.setHeatFlux(lambda t: 90000 * (1 - t**2) if t <= 1.0 else 0.0) + self.add_wall(A=0.3) + self.w.set_heat_flux(lambda t: 90000 * (1 - t**2) if t <= 1.0 else 0.0) Q = 0.3 * 60000 self.net.advance(1.1) @@ -289,13 +289,13 @@ class TestReactor(utilities.CanteraTest): self.assertNear(U2a + Q, U2b, 1e-6) def test_mass_flow_controller(self): - self.makeReactors(nReactors=1) + self.make_reactors(n_reactors=1) gas2 = ct.Solution('h2o2.xml') gas2.TPX = 300, 10*101325, 'H2:1.0' reservoir = ct.Reservoir(gas2) mfc = ct.MassFlowController(reservoir, self.r1) - mfc.setMassFlowRate(lambda t: 0.1 if 0.2 <= t < 1.2 else 0.0) + mfc.set_mass_flow_rate(lambda t: 0.1 if 0.2 <= t < 1.2 else 0.0) self.assertEqual(len(reservoir.inlets), 0) self.assertEqual(len(reservoir.outlets), 1) @@ -316,14 +316,14 @@ class TestReactor(utilities.CanteraTest): self.assertArrayNear(ma * Ya + 0.1 * gas2.Y, mb * Yb) def test_valve1(self): - self.makeReactors(P1=10*ct.OneAtm, X1='AR:1.0', X2='O2:1.0') + self.make_reactors(P1=10*ct.one_atm, X1='AR:1.0', X2='O2:1.0') valve = ct.Valve(self.r1, self.r2) k = 2e-5 - valve.setValveCoeff(k) + valve.set_valve_coeff(k) self.assertEqual(self.r1.outlets, self.r2.inlets) - self.assertTrue(self.r1.energyEnabled) - self.assertTrue(self.r2.energyEnabled) + self.assertTrue(self.r1.energy_enabled) + self.assertTrue(self.r2.energy_enabled) self.assertTrue((self.r1.thermo.P - self.r2.thermo.P) * k, valve.mdot(0)) @@ -348,15 +348,15 @@ class TestReactor(utilities.CanteraTest): # Similar to test_valve1, but by disabling the energy equation # (constant T) we can compare with an analytical solution for # the mass of each reactor as a function of time - self.makeReactors(P1=10*ct.OneAtm) - self.r1.energyEnabled = False - self.r2.energyEnabled = False + self.make_reactors(P1=10*ct.one_atm) + self.r1.energy_enabled = False + self.r2.energy_enabled = False valve = ct.Valve(self.r1, self.r2) k = 2e-5 - valve.setValveCoeff(k) + valve.set_valve_coeff(k) - self.assertFalse(self.r1.energyEnabled) - self.assertFalse(self.r2.energyEnabled) + self.assertFalse(self.r1.energy_enabled) + self.assertFalse(self.r2.energy_enabled) m1a = self.r1.thermo.density * self.r1.volume m2a = self.r2.thermo.density * self.r2.volume @@ -376,10 +376,10 @@ class TestReactor(utilities.CanteraTest): def test_valve3(self): # This case specifies a non-linear relationship between pressure drop # and flow rate. - self.makeReactors(P1=10*ct.OneAtm, X1='AR:1.0', X2='O2:1.0') + self.make_reactors(P1=10*ct.one_atm, X1='AR:1.0', X2='O2:1.0') valve = ct.Valve(self.r1, self.r2) mdot = lambda dP: 5e-3 * np.sqrt(dP) if dP > 0 else 0.0 - valve.setValveCoeff(mdot) + valve.set_valve_coeff(mdot) t = 0 while t < 1.0: @@ -389,34 +389,34 @@ class TestReactor(utilities.CanteraTest): self.assertNear(mdot(p1-p2), valve.mdot(t)) def test_pressure_controller(self): - self.makeReactors(nReactors=1) + self.make_reactors(n_reactors=1) g = ct.Solution('h2o2.xml') g.TPX = 500, 2*101325, 'H2:1.0' - inletReservoir = ct.Reservoir(g) + inlet_reservoir = ct.Reservoir(g) g.TP = 300, 101325 - outletReservoir = ct.Reservoir(g) + outlet_reservoir = ct.Reservoir(g) - mfc = ct.MassFlowController(inletReservoir, self.r1) + mfc = ct.MassFlowController(inlet_reservoir, self.r1) mdot = lambda t: np.exp(-100*(t-0.5)**2) - mfc.setMassFlowRate(mdot) + mfc.set_mass_flow_rate(mdot) - pc = ct.PressureController(self.r1, outletReservoir) - pc.setMaster(mfc) - pc.setPressureCoeff(1e-5) + pc = ct.PressureController(self.r1, outlet_reservoir) + pc.set_master(mfc) + pc.set_pressure_coeff(1e-5) t = 0 while t < 1.0: t = self.net.step(1.0) self.assertNear(mdot(t), mfc.mdot(t)) - dP = self.r1.thermo.P - outletReservoir.thermo.P + dP = self.r1.thermo.P - outlet_reservoir.thermo.P self.assertNear(mdot(t) + 1e-5 * dP, pc.mdot(t)) - def test_setInitialTime(self): - self.makeReactors(P1=10*ct.OneAtm, X1='AR:1.0', X2='O2:1.0') + def test_set_initial_time(self): + self.make_reactors(P1=10*ct.one_atm, X1='AR:1.0', X2='O2:1.0') self.net.rtol = 1e-12 valve = ct.Valve(self.r1, self.r2) mdot = lambda dP: 5e-3 * np.sqrt(dP) if dP > 0 else 0.0 - valve.setValveCoeff(mdot) + valve.set_valve_coeff(mdot) t0 = 0.0 tf = t0 + 0.5 @@ -425,14 +425,14 @@ class TestReactor(utilities.CanteraTest): p1a = self.r1.thermo.P p2a = self.r2.thermo.P - self.makeReactors(P1=10*ct.OneAtm, X1='AR:1.0', X2='O2:1.0') + self.make_reactors(P1=10*ct.one_atm, X1='AR:1.0', X2='O2:1.0') self.net.rtol = 1e-12 valve = ct.Valve(self.r1, self.r2) mdot = lambda dP: 5e-3 * np.sqrt(dP) if dP > 0 else 0.0 - valve.setValveCoeff(mdot) + valve.set_valve_coeff(mdot) t0 = 0.2 - self.net.setInitialTime(t0) + self.net.set_initial_time(t0) tf = t0 + 0.5 self.net.advance(tf) self.assertNear(self.net.time, tf) @@ -448,10 +448,10 @@ class TestFlowReactor(utilities.CanteraTest): g = ct.Solution('h2o2.xml') g.TPX = 300, 101325, 'O2:1.0' r = ct.FlowReactor(g) - r.massFlowRate = 10 + r.mass_flow_rate = 10 net = ct.ReactorNet() - net.addReactor(r) + net.add_reactor(r) t = 0 v0 = r.speed @@ -467,10 +467,10 @@ class TestFlowReactor(utilities.CanteraTest): g.TPX = 1400, 20*101325, 'CO:1.0, H2O:1.0' r = ct.FlowReactor(g) - r.massFlowRate = 10 + r.mass_flow_rate = 10 net = ct.ReactorNet() - net.addReactor(r) + net.add_reactor(r) net.atol = 1e-18 net.rtol = 1e-9 @@ -487,7 +487,7 @@ class TestFlowReactor(utilities.CanteraTest): class TestWallKinetics(utilities.CanteraTest): - def makeReactors(self): + def make_reactors(self): self.net = ct.ReactorNet() self.gas = ct.Solution('diamond.xml', 'gas') @@ -495,18 +495,18 @@ class TestWallKinetics(utilities.CanteraTest): self.interface = ct.Interface('diamond.xml', 'diamond_100', (self.gas, self.solid)) self.r1 = ct.Reactor(self.gas) - self.net.addReactor(self.r1) + self.net.add_reactor(self.r1) self.r2 = ct.Reactor(self.gas) - self.net.addReactor(self.r2) + self.net.add_reactor(self.r2) self.w = ct.Wall(self.r1, self.r2) def test_coverages(self): - self.makeReactors() + self.make_reactors() self.w.left.kinetics = self.interface - C = np.zeros(self.interface.nSpecies) + C = np.zeros(self.interface.n_species) C[0] = 0.3 C[4] = 0.7 @@ -518,7 +518,7 @@ class TestWallKinetics(utilities.CanteraTest): self.assertEqual(self.w.right.kinetics, None) self.assertRaises(Exception, lambda: self.w.right.coverages) - self.makeReactors() + self.make_reactors() self.w.right.kinetics = self.interface self.w.right.coverages = C self.assertArrayNear(self.w.right.coverages, C) @@ -539,18 +539,18 @@ class TestReactorSensitivities(utilities.CanteraTest): gas = ct.Solution('gri30.xml') gas.TPX = 1300, 20*101325, 'CO:1.0, H2:0.1, CH4:0.1, H2O:0.5' r1 = ct.Reactor(gas) - net.addReactor(r1) + net.add_reactor(r1) - self.assertEqual(net.nSensitivityParams, 0) - r1.addSensitivityReaction(40) - r1.addSensitivityReaction(41) + self.assertEqual(net.n_sensitivity_params, 0) + r1.add_sensitivity_reaction(40) + r1.add_sensitivity_reaction(41) net.advance(0.1) - self.assertEqual(net.nSensitivityParams, 2) - self.assertEqual(net.nVars, gas.nSpecies + 2) + self.assertEqual(net.n_sensitivity_params, 2) + self.assertEqual(net.n_vars, gas.n_species + 2) S = net.sensitivities() - self.assertEqual(S.shape, (net.nVars, net.nSensitivityParams)) + self.assertEqual(S.shape, (net.n_vars, net.n_sensitivity_params)) def test_sensitivities2(self): net = ct.ReactorNet() @@ -560,30 +560,30 @@ class TestReactorSensitivities(utilities.CanteraTest): interface = ct.Interface('diamond.xml', 'diamond_100', (gas1, solid)) r1 = ct.Reactor(gas1) - net.addReactor(r1) + net.add_reactor(r1) gas2 = ct.Solution('h2o2.xml') gas2.TPX = 900, 101325, 'H2:0.1, OH:1e-7, O2:0.1, AR:1e-5' r2 = ct.Reactor(gas2) - net.addReactor(r2) + net.add_reactor(r2) w = ct.Wall(r1, r2) w.left.kinetics = interface - C = np.zeros(interface.nSpecies) + C = np.zeros(interface.n_species) C[0] = 0.3 C[4] = 0.7 w.left.coverages = C - w.left.addSensitivityReaction(2) - r2.addSensitivityReaction(18) + w.left.add_sensitivity_reaction(2) + r2.add_sensitivity_reaction(18) for T in (901, 905, 910, 950, 1500): while r2.T < T: net.step(1.0) S = net.sensitivities() - K1 = gas1.nSpecies + interface.nSpecies + K1 = gas1.n_species + interface.n_species # Constant internal energy and volume should generate zero # sensitivity coefficients @@ -607,7 +607,7 @@ class TestReactorSensitivities(utilities.CanteraTest): gas.TPX = 900, 101325, 'H2:0.1, OH:1e-7, O2:0.1, AR:1e-5' r = ct.Reactor(gas) - net.addReactor(r) + net.add_reactor(r) return r, net def integrate(r, net): @@ -618,21 +618,21 @@ class TestReactorSensitivities(utilities.CanteraTest): r1,net1 = setup() params1 = [2,10,18,19] for p in params1: - r1.addSensitivityReaction(p) + r1.add_sensitivity_reaction(p) S1 = integrate(r1, net1) - pname = lambda r,i: '%s: %s' % (r.name, gas.reactionEquation(i)) + pname = lambda r,i: '%s: %s' % (r.name, gas.reaction_equation(i)) for i,p in enumerate(params1): - self.assertEqual(pname(r1,p), net1.sensitivityParameterName(i)) + self.assertEqual(pname(r1,p), net1.sensitivity_parameter_name(i)) r2,net2 = setup() params2 = [19,10,2,18] for p in params2: - r2.addSensitivityReaction(p) + r2.add_sensitivity_reaction(p) S2 = integrate(r2, net2) for i,p in enumerate(params2): - self.assertEqual(pname(r2,p), net2.sensitivityParameterName(i)) + self.assertEqual(pname(r2,p), net2.sensitivity_parameter_name(i)) for i,j in enumerate((2,1,3,0)): self.assertArrayNear(S1[:,i], S2[:,j]) @@ -651,11 +651,11 @@ class TestReactorSensitivities(utilities.CanteraTest): gas2.TPX = 920, 101325, 'H2:0.1, OH:1e-7, O2:0.1, AR:0.5' rB = ct.Reactor(gas2) if reverse: - net.addReactor(rB) - net.addReactor(rA) + net.add_reactor(rB) + net.add_reactor(rA) else: - net.addReactor(rA) - net.addReactor(rB) + net.add_reactor(rA) + net.add_reactor(rB) return rA, rB, net @@ -669,21 +669,21 @@ class TestReactorSensitivities(utilities.CanteraTest): rA1,rB1,net1 = setup(reverse) params1 = [(rA1,2),(rA1,19),(rB1,10),(rB1,18)] for r,p in params1: - r.addSensitivityReaction(p) + r.add_sensitivity_reaction(p) S.append(integrate(rA1, net1)) - pname = lambda r,i: '%s: %s' % (r.name, gas.reactionEquation(i)) + pname = lambda r,i: '%s: %s' % (r.name, gas.reaction_equation(i)) for i,(r,p) in enumerate(params1): - self.assertEqual(pname(r,p), net1.sensitivityParameterName(i)) + self.assertEqual(pname(r,p), net1.sensitivity_parameter_name(i)) rA2,rB2,net2 = setup(reverse) params2 = [(rB2,10),(rA2,19),(rB2,18),(rA2,2)] for r,p in params2: - r.addSensitivityReaction(p) + r.add_sensitivity_reaction(p) S.append(integrate(rA2, net2)) for i,(r,p) in enumerate(params2): - self.assertEqual(pname(r,p), net2.sensitivityParameterName(i)) + self.assertEqual(pname(r,p), net2.sensitivity_parameter_name(i)) # Check that the results reflect the changed parameter ordering for a,b in ((0,1), (2,3)): @@ -692,7 +692,7 @@ class TestReactorSensitivities(utilities.CanteraTest): # Check that results are consistent after changing the order that # reactors are added to the network - N = gas.nSpecies + 2 + N = gas.n_species + 2 self.assertArrayNear(S[0][:N], S[2][N:], 1e-5, 1e-5) self.assertArrayNear(S[0][N:], S[2][:N], 1e-5, 1e-5) self.assertArrayNear(S[1][:N], S[3][N:], 1e-5, 1e-5) @@ -727,8 +727,8 @@ class TestReactorSensitivities(utilities.CanteraTest): wA.area = 0.1 wB.area = 10 - C1 = np.zeros(interface.nSpecies) - C2 = np.zeros(interface.nSpecies) + C1 = np.zeros(interface.n_species) + C2 = np.zeros(interface.n_species) C1[0] = 0.3 C1[4] = 0.7 @@ -738,11 +738,11 @@ class TestReactorSensitivities(utilities.CanteraTest): wB.right.coverages = C2 if order // 2 == 0: - net.addReactor(rA) - net.addReactor(rB) + net.add_reactor(rA) + net.add_reactor(rB) else: - net.addReactor(rB) - net.addReactor(rA) + net.add_reactor(rB) + net.add_reactor(rA) return rA,rB,wA,wB,net @@ -756,14 +756,14 @@ class TestReactorSensitivities(utilities.CanteraTest): rA,rB,wA,wB,net = setup(order) for (obj,k) in [(rB,2), (rB,18), (wA.left,2), (wA.left,0), (wB.right,2)]: - obj.addSensitivityReaction(k) + obj.add_sensitivity_reaction(k) integrate(rB, net) S.append(net.sensitivities()) rA,rB,wA,wB,net = setup(order) for (obj,k) in [(wB.right,2), (wA.left,2), (rB,18), (wA.left,0), (rB,2)]: - obj.addSensitivityReaction(k) + obj.add_sensitivity_reaction(k) integrate(rB, net) S.append(net.sensitivities()) diff --git a/interfaces/cython/cantera/test/test_thermo.py b/interfaces/cython/cantera/test/test_thermo.py index 119e5edab..2ab1bf724 100644 --- a/interfaces/cython/cantera/test/test_thermo.py +++ b/interfaces/cython/cantera/test/test_thermo.py @@ -9,30 +9,30 @@ class TestThermoPhase(utilities.CanteraTest): self.phase = ct.Solution('h2o2.xml') def test_species(self): - self.assertEqual(self.phase.nSpecies, 9) - for i,name in enumerate(self.phase.speciesNames): - self.assertEqual(name, self.phase.speciesName(i)) - self.assertEqual(i, self.phase.speciesIndex(name)) - self.assertEqual(i, self.phase.speciesIndex(i)) + self.assertEqual(self.phase.n_species, 9) + for i,name in enumerate(self.phase.species_names): + self.assertEqual(name, self.phase.species_name(i)) + self.assertEqual(i, self.phase.species_index(name)) + self.assertEqual(i, self.phase.species_index(i)) def test_elements(self): - self.assertEqual(self.phase.nElements, 3) - for i,symbol in enumerate(self.phase.elementNames): - self.assertEqual(symbol, self.phase.elementName(i)) - self.assertEqual(i, self.phase.elementIndex(symbol)) - self.assertEqual(i, self.phase.elementIndex(i)) + self.assertEqual(self.phase.n_elements, 3) + for i,symbol in enumerate(self.phase.element_names): + self.assertEqual(symbol, self.phase.element_name(i)) + self.assertEqual(i, self.phase.element_index(symbol)) + self.assertEqual(i, self.phase.element_index(i)) - def test_nAtoms(self): - self.assertEqual(self.phase.nAtoms('H2', 'H'), 2) - self.assertEqual(self.phase.nAtoms('H2O2', 'H'), 2) - self.assertEqual(self.phase.nAtoms('HO2', 'H'), 1) - self.assertEqual(self.phase.nAtoms('AR', 'H'), 0) + def test_n_atoms(self): + self.assertEqual(self.phase.n_atoms('H2', 'H'), 2) + self.assertEqual(self.phase.n_atoms('H2O2', 'H'), 2) + self.assertEqual(self.phase.n_atoms('HO2', 'H'), 1) + self.assertEqual(self.phase.n_atoms('AR', 'H'), 0) - self.assertRaises(ValueError, lambda: self.phase.nAtoms('C', 'H2')) - self.assertRaises(ValueError, lambda: self.phase.nAtoms('H', 'CH4')) + self.assertRaises(ValueError, lambda: self.phase.n_atoms('C', 'H2')) + self.assertRaises(ValueError, lambda: self.phase.n_atoms('H', 'CH4')) def test_setComposition(self): - X = np.zeros(self.phase.nSpecies) + X = np.zeros(self.phase.n_species) X[2] = 1.0 self.phase.X = X Y = self.phase.Y @@ -54,7 +54,7 @@ class TestThermoPhase(utilities.CanteraTest): report = self.phase.report() self.assertTrue(self.phase.name in report) self.assertTrue('temperature' in report) - for name in self.phase.speciesNames: + for name in self.phase.species_names: self.assertTrue(name in report) def test_name(self): @@ -79,7 +79,7 @@ class TestThermoPhase(utilities.CanteraTest): self.assertEqual(self.phase.density_mass, self.phase.density) self.assertEqual(self.phase.enthalpy_mass, self.phase.h) self.assertEqual(self.phase.entropy_mass, self.phase.s) - self.assertEqual(self.phase.intEnergy_mass, self.phase.u) + self.assertEqual(self.phase.int_energy_mass, self.phase.u) self.assertEqual(self.phase.volume_mass, self.phase.v) self.assertEqual(self.phase.cv_mass, self.phase.cv) self.assertEqual(self.phase.cp_mass, self.phase.cp) @@ -90,7 +90,7 @@ class TestThermoPhase(utilities.CanteraTest): self.assertEqual(self.phase.density_mole, self.phase.density) self.assertEqual(self.phase.enthalpy_mole, self.phase.h) self.assertEqual(self.phase.entropy_mole, self.phase.s) - self.assertEqual(self.phase.intEnergy_mole, self.phase.u) + self.assertEqual(self.phase.int_energy_mole, self.phase.u) self.assertEqual(self.phase.volume_mole, self.phase.v) self.assertEqual(self.phase.cv_mole, self.phase.cv) self.assertEqual(self.phase.cp_mole, self.phase.cp) @@ -178,7 +178,7 @@ class TestThermoPhase(utilities.CanteraTest): self.check_getters() def test_getState(self): - self.assertNear(self.phase.P, ct.OneAtm) + self.assertNear(self.phase.P, ct.one_atm) self.assertNear(self.phase.T, 300) def test_partial_molar(self): @@ -190,9 +190,9 @@ class TestThermoPhase(utilities.CanteraTest): self.phase.entropy_mole) self.assertNear(sum(self.phase.partial_molar_int_energies * self.phase.X), - self.phase.intEnergy_mole) + self.phase.int_energy_mole) - self.assertNear(sum(self.phase.chem_potentials * self.phase.X), + self.assertNear(sum(self.phase.chemical_potentials * self.phase.X), self.phase.gibbs_mole) self.assertNear(sum(self.phase.partial_molar_cp * self.phase.X), @@ -201,26 +201,26 @@ class TestThermoPhase(utilities.CanteraTest): def test_nondimensional(self): self.phase.TDY = 850.0, 0.2, 'H2:0.1, H2O:0.6, AR:0.3' H = (sum(self.phase.standard_enthalpies_RT * self.phase.X) * - ct.GasConstant * self.phase.T) + ct.gas_constant * self.phase.T) self.assertNear(H, self.phase.enthalpy_mole) - U = (sum(self.phase.standard_intEnergies_RT * self.phase.X) * - ct.GasConstant * self.phase.T) - self.assertNear(U, self.phase.intEnergy_mole) + U = (sum(self.phase.standard_int_energies_RT * self.phase.X) * + ct.gas_constant * self.phase.T) + self.assertNear(U, self.phase.int_energy_mole) - cp = sum(self.phase.standard_cp_R * self.phase.X) * ct.GasConstant + cp = sum(self.phase.standard_cp_R * self.phase.X) * ct.gas_constant self.assertNear(cp, self.phase.cp_mole) - def test_isothermalCompressibility(self): - self.assertNear(self.phase.isothermalCompressibility, 1.0/self.phase.P) + def test_isothermal_compressibility(self): + self.assertNear(self.phase.isothermal_compressibility, 1.0/self.phase.P) - def test_thermalExpansionCoeff(self): - self.assertNear(self.phase.thermalExpansionCoeff, 1.0/self.phase.T) + def test_thermal_expansion_coeff(self): + self.assertNear(self.phase.thermal_expansion_coeff, 1.0/self.phase.T) def test_ref_info(self): - self.assertEqual(self.phase.refPressure, ct.OneAtm) - self.assertEqual(self.phase.minTemp, 300.0) - self.assertEqual(self.phase.maxTemp, 3500.0) + self.assertEqual(self.phase.reference_pressure, ct.one_atm) + self.assertEqual(self.phase.min_temp, 300.0) + self.assertEqual(self.phase.max_temp, 3500.0) class TestInterfacePhase(utilities.CanteraTest): @@ -231,5 +231,5 @@ class TestInterfacePhase(utilities.CanteraTest): (self.gas, self.solid)) def test_properties(self): - self.interface.siteDensity = 100 - self.assertEqual(self.interface.siteDensity, 100) + self.interface.site_density = 100 + self.assertEqual(self.interface.site_density, 100) diff --git a/interfaces/cython/cantera/test/test_transport.py b/interfaces/cython/cantera/test/test_transport.py index 4fae0bf2f..7a849f19d 100644 --- a/interfaces/cython/cantera/test/test_transport.py +++ b/interfaces/cython/cantera/test/test_transport.py @@ -8,24 +8,24 @@ class TestTransport(utilities.CanteraTest): def setUp(self): self.phase = ct.Solution('h2o2.xml') self.phase.X = [0.1, 1e-4, 1e-5, 0.2, 2e-4, 0.3, 1e-6, 5e-5, 0.4] - self.phase.TP = 800, 2*ct.OneAtm + self.phase.TP = 800, 2*ct.one_atm def test_scalar_properties(self): self.assertTrue(self.phase.viscosity > 0.0) - self.assertTrue(self.phase.thermalConductivity > 0.0) + self.assertTrue(self.phase.thermal_conductivity > 0.0) def test_mixtureAveraged(self): - self.assertEqual(self.phase.transportModel, 'Mix') - Dkm1 = self.phase.mixDiffCoeffs - Dkm1b = self.phase.mixDiffCoeffsMole - Dkm1c = self.phase.mixDiffCoeffsMass - Dbin1 = self.phase.binaryDiffCoeffs + self.assertEqual(self.phase.transport_model, 'Mix') + Dkm1 = self.phase.mix_diff_coeffs + Dkm1b = self.phase.mix_diff_coeffs_mole + Dkm1c = self.phase.mix_diff_coeffs_mass + Dbin1 = self.phase.binary_diff_coeffs - self.phase.transportModel = 'Multi' - Dkm2 = self.phase.mixDiffCoeffs - Dkm2b = self.phase.mixDiffCoeffsMole - Dkm2c = self.phase.mixDiffCoeffsMass - Dbin2 = self.phase.binaryDiffCoeffs + self.phase.transport_model = 'Multi' + Dkm2 = self.phase.mix_diff_coeffs + Dkm2b = self.phase.mix_diff_coeffs_mole + Dkm2c = self.phase.mix_diff_coeffs_mass + Dbin2 = self.phase.binary_diff_coeffs self.assertArrayNear(Dkm1, Dkm2) self.assertArrayNear(Dkm1b, Dkm2b) self.assertArrayNear(Dkm1c, Dkm2c) @@ -34,14 +34,14 @@ class TestTransport(utilities.CanteraTest): def test_multiComponent(self): self.assertRaises(Exception, - lambda: self.phase.MultiDiffCoeffs) + lambda: self.phase.Multi_diff_coeffs) - self.assertArrayNear(self.phase.thermalDiffCoeffs, - np.zeros(self.phase.nSpecies)) + self.assertArrayNear(self.phase.thermal_diff_coeffs, + np.zeros(self.phase.n_species)) - self.phase.transportModel = 'Multi' - self.assertTrue(all(self.phase.multiDiffCoeffs.flat >= 0.0)) - self.assertTrue(all(self.phase.thermalDiffCoeffs.flat != 0.0)) + self.phase.transport_model = 'Multi' + self.assertTrue(all(self.phase.multi_diff_coeffs.flat >= 0.0)) + self.assertTrue(all(self.phase.thermal_diff_coeffs.flat != 0.0)) class TestDustyGas(utilities.CanteraTest): @@ -49,18 +49,18 @@ class TestDustyGas(utilities.CanteraTest): self.phase = ct.DustyGas('h2o2.xml') self.phase.porosity = 0.2 self.phase.tortuosity = 0.3 - self.phase.meanPoreRadius = 1e-4 - self.phase.meanParticleDiameter = 5e-4 - self.Dref = self.phase.multiDiffCoeffs + self.phase.mean_pore_radius = 1e-4 + self.phase.mean_particle_diameter = 5e-4 + self.Dref = self.phase.multi_diff_coeffs def test_porosity(self): self.phase.porosity = 0.4 - D = self.phase.multiDiffCoeffs + D = self.phase.multi_diff_coeffs self.assertArrayNear(self.Dref * 2, D) def test_tortuosity(self): self.phase.tortuosity = 0.6 - D = self.phase.multiDiffCoeffs + D = self.phase.multi_diff_coeffs self.assertArrayNear(self.Dref * 0.5, D) # The other parameters don't have such simple relationships to the diffusion diff --git a/interfaces/cython/cantera/thermo.pyx b/interfaces/cython/cantera/thermo.pyx index d6e055f3c..e9191f1f2 100644 --- a/interfaces/cython/cantera/thermo.pyx +++ b/interfaces/cython/cantera/thermo.pyx @@ -1,6 +1,6 @@ -cdef enum ThermoBasis: - massBasis = 0 - molarBasis = 1 +cdef enum Thermasis: + mass_basis = 0 + molar_basis = 1 ctypedef void (*thermoMethod1d)(CxxThermoPhase*, double*) except + @@ -17,7 +17,7 @@ cdef class ThermoPhase(_SolutionBase): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) if 'source' not in kwargs: - self.thermoBasis = massBasis + self.thermo_basis = mass_basis def report(self, show_thermo=True): """ @@ -52,29 +52,29 @@ cdef class ThermoPhase(_SolutionBase): such as `HPX` and `UV`. """ def __get__(self): - if self.thermoBasis == massBasis: + if self.thermo_basis == mass_basis: return 'mass' else: return 'molar' def __set__(self, value): if value == 'mass': - self.thermoBasis = massBasis + self.thermo_basis = mass_basis elif value == 'molar': - self.thermoBasis = molarBasis + self.thermo_basis = molar_basis else: raise ValueError("Valid choices are 'mass' or 'molar'.") - cdef double _massFactor(self): + cdef double _mass_factor(self): """ Conversion factor from current basis to kg """ - if self.thermoBasis == molarBasis: + if self.thermo_basis == molar_basis: return self.thermo.meanMolecularWeight() else: return 1.0 - cdef double _moleFactor(self): + cdef double _mole_factor(self): """ Conversion factor from current basis to moles """ - if self.thermoBasis == massBasis: + if self.thermo_basis == mass_basis: return 1.0/self.thermo.meanMolecularWeight() else: return 1.0 @@ -135,12 +135,12 @@ cdef class ThermoPhase(_SolutionBase): ####### Composition, species, and elements ######## - property nElements: + property n_elements: """Number of elements.""" def __get__(self): return self.thermo.nElements() - cpdef int elementIndex(self, element) except *: + cpdef int element_index(self, element) except *: """ The index of element *element*, which may be specified as a string or an integer. In the latter case, the index is checked for validity and @@ -153,39 +153,39 @@ cdef class ThermoPhase(_SolutionBase): else: raise TypeError("'element' must be a string or a number") - if not 0 <= index < self.nElements: + if not 0 <= index < self.n_elements: raise ValueError('No such element.') return index - def elementName(self, m): + def element_name(self, m): """Name of the element with index *m*.""" return pystr(self.thermo.elementName(m)) - property elementNames: + property element_names: """A list of all the element names.""" def __get__(self): - return [self.elementName(m) for m in range(self.nElements)] + return [self.element_name(m) for m in range(self.n_elements)] - property nSpecies: + property n_species: """Number of species.""" def __get__(self): return self.thermo.nSpecies() - def speciesName(self, k): + def species_name(self, k): """Name of the species with index *k*.""" return pystr(self.thermo.speciesName(k)) - property speciesNames: + property species_names: """A list of all the species names.""" def __get__(self): - if self._selectedSpecies.size: - indices = self._selectedSpecies + if self._selected_species.size: + indices = self._selected_species else: - indices = range(self.nSpecies) - return [self.speciesName(k) for k in indices] + indices = range(self.n_species) + return [self.species_name(k) for k in indices] - cpdef int speciesIndex(self, species) except *: + cpdef int species_index(self, species) except *: """ The index of species *species*, which may be specified as a string or an integer. In the latter case, the index is checked for validity and @@ -198,44 +198,44 @@ cdef class ThermoPhase(_SolutionBase): else: raise TypeError("'species' must be a string or a number") - if not 0 <= index < self.nSpecies: + if not 0 <= index < self.n_species: raise ValueError('No such species.') return index - def nAtoms(self, species, element): + def n_atoms(self, species, element): """ Number of atoms of element *element* in species *species*. The element and species may be specified by name or by index. - >>> phase.nAtoms('CH4','H') + >>> phase.n_atoms('CH4','H') 4 """ - return self.thermo.nAtoms(self.speciesIndex(species), - self.elementIndex(element)) + return self.thermo.nAtoms(self.species_index(species), + self.element_index(element)) cdef np.ndarray _getArray1(self, thermoMethod1d method): - cdef np.ndarray[np.double_t, ndim=1] data = np.empty(self.nSpecies) + cdef np.ndarray[np.double_t, ndim=1] data = np.empty(self.n_species) method(self.thermo, &data[0]) - if self._selectedSpecies.size: - return data[self._selectedSpecies] + if self._selected_species.size: + return data[self._selected_species] else: return data cdef void _setArray1(self, thermoMethod1d method, values) except *: - if len(values) != self.nSpecies: + if len(values) != self.n_species: raise ValueError("Array has incorrect length") cdef np.ndarray[np.double_t, ndim=1] data = \ np.ascontiguousarray(values, dtype=np.double) method(self.thermo, &data[0]) - property molecularWeights: + property molecular_weights: """Array of species molecular weights (molar masses) [kg/kmol].""" def __get__(self): return self._getArray1(thermo_getMolecularWeights) - property meanMolecularWeight: + property mean_molecular_weight: """The mean molecular weight (molar mass) [kg/kmol].""" def __get__(self): return self.thermo.meanMolecularWeight() @@ -299,7 +299,7 @@ cdef class ThermoPhase(_SolutionBase): property density: """Density [kg/m^3 or kmol/m^3] depending on `basis`.""" def __get__(self): - return self.thermo.density() / self._massFactor() + return self.thermo.density() / self._mass_factor() property density_mass: """(Mass) density [kg/m^3].""" @@ -314,7 +314,7 @@ cdef class ThermoPhase(_SolutionBase): property v: """Specific volume [m^3/kg or m^3/kmol] depending on `basis`.""" def __get__(self): - return self._massFactor() / self.thermo.density() + return self._mass_factor() / self.thermo.density() property volume_mass: """Specific volume [m^3/kg].""" @@ -329,14 +329,14 @@ cdef class ThermoPhase(_SolutionBase): property u: """Internal energy in [J/kg or J/kmol].""" def __get__(self): - return self.thermo.intEnergy_mole() * self._moleFactor() + return self.thermo.intEnergy_mole() * self._mole_factor() - property intEnergy_mole: + property int_energy_mole: """Molar internal energy [J/kmol].""" def __get__(self): return self.thermo.intEnergy_mole() - property intEnergy_mass: + property int_energy_mass: """Specific internal energy [J/kg].""" def __get__(self): return self.thermo.intEnergy_mass() @@ -344,7 +344,7 @@ cdef class ThermoPhase(_SolutionBase): property h: """Enthalpy [J/kg or J/kmol] depending on `basis`.""" def __get__(self): - return self.thermo.enthalpy_mole() * self._moleFactor() + return self.thermo.enthalpy_mole() * self._mole_factor() property enthalpy_mole: """Molar enthalpy [J/kmol].""" @@ -359,7 +359,7 @@ cdef class ThermoPhase(_SolutionBase): property s: """Entropy [J/kg/K or J/kmol/K] depending on `basis`.""" def __get__(self): - return self.thermo.entropy_mole() * self._moleFactor() + return self.thermo.entropy_mole() * self._mole_factor() property entropy_mole: """Molar entropy [J/kmol/K].""" @@ -374,7 +374,7 @@ cdef class ThermoPhase(_SolutionBase): property g: """Gibbs free energy [J/kg or J/kmol] depending on `basis`.""" def __get__(self): - return self.thermo.gibbs_mole() * self._moleFactor() + return self.thermo.gibbs_mole() * self._mole_factor() property gibbs_mole: """Molar Gibbs free energy [J/kmol].""" @@ -392,7 +392,7 @@ cdef class ThermoPhase(_SolutionBase): `basis`. """ def __get__(self): - return self.thermo.cv_mole() * self._moleFactor() + return self.thermo.cv_mole() * self._mole_factor() property cv_mole: """Molar heat capacity at constant volume [J/kmol/K].""" @@ -410,7 +410,7 @@ cdef class ThermoPhase(_SolutionBase): on `basis`. """ def __get__(self): - return self.thermo.cp_mole() * self._moleFactor() + return self.thermo.cp_mole() * self._mole_factor() property cp_mole: """Molar heat capacity at constant pressure [J/kmol/K].""" @@ -429,7 +429,7 @@ cdef class ThermoPhase(_SolutionBase): def __get__(self): return self.T, self.density def __set__(self, values): - self.thermo.setState_TR(values[0], values[1] * self._massFactor()) + self.thermo.setState_TR(values[0], values[1] * self._mass_factor()) property TDX: """ @@ -484,8 +484,8 @@ cdef class ThermoPhase(_SolutionBase): def __get__(self): return self.u, self.v def __set__(self, values): - self.thermo.setState_UV(values[0] / self._massFactor(), - values[1] / self._massFactor()) + self.thermo.setState_UV(values[0] / self._mass_factor(), + values[1] / self._mass_factor()) property UVX: """ @@ -514,7 +514,7 @@ cdef class ThermoPhase(_SolutionBase): def __get__(self): return self.h, self.P def __set__(self, values): - self.thermo.setState_HP(values[0] / self._massFactor(), values[1]) + self.thermo.setState_HP(values[0] / self._mass_factor(), values[1]) property HPX: """Get/Set enthalpy [J/kg or J/kmol], pressure [Pa] and mole fractions.""" @@ -537,7 +537,7 @@ cdef class ThermoPhase(_SolutionBase): def __get__(self): return self.s, self.P def __set__(self, values): - self.thermo.setState_SP(values[0] / self._massFactor(), values[1]) + self.thermo.setState_SP(values[0] / self._mass_factor(), values[1]) property SPX: """Get/Set entropy [J/kg/K or J/kmol/K], pressure [Pa], and mole fractions.""" @@ -571,12 +571,12 @@ cdef class ThermoPhase(_SolutionBase): def __get__(self): return self._getArray1(thermo_getPartialMolarIntEnergies) - property chem_potentials: + property chemical_potentials: """Array of species chemical potentials [J/kmol].""" def __get__(self): return self._getArray1(thermo_getChemPotentials) - property electrochem_potentials: + property electrochemical_potentials: """Array of species electrochemical potentials [J/kmol].""" def __get__(self): return self._getArray1(thermo_getElectrochemPotentials) @@ -610,7 +610,7 @@ cdef class ThermoPhase(_SolutionBase): def __get__(self): return self._getArray1(thermo_getEntropy_R) - property standard_intEnergies_RT: + property standard_int_energies_RT: """ Array of nondimensional species standard-state internal energies at the current temperature and pressure. @@ -635,17 +635,17 @@ cdef class ThermoPhase(_SolutionBase): return self._getArray1(thermo_getCp_R) ######## Miscellaneous properties ######## - property isothermalCompressibility: + property isothermal_compressibility: """Isothermal compressibility [1/Pa].""" def __get__(self): return self.thermo.isothermalCompressibility() - property thermalExpansionCoeff: + property thermal_expansion_coeff: """Thermal expansion coefficient [1/K].""" def __get__(self): return self.thermo.thermalExpansionCoeff() - property minTemp: + property min_temp: """ Minimum temperature for which the thermodynamic data for the phase are valid. @@ -653,7 +653,7 @@ cdef class ThermoPhase(_SolutionBase): def __get__(self): return self.thermo.minTemp() - property maxTemp: + property max_temp: """ Maximum temperature for which the thermodynamic data for the phase are valid. @@ -661,19 +661,19 @@ cdef class ThermoPhase(_SolutionBase): def __get__(self): return self.thermo.maxTemp() - property refPressure: + property reference_pressure: """Reference state pressure [Pa].""" def __get__(self): return self.thermo.refPressure() - property electricPotential: + property electric_potential: """Get/Set the electric potential [V] for this phase.""" def __get__(self): return self.thermo.electricPotential() def __set__(self, double value): self.thermo.setElectricPotential(value) - def elementPotentials(self): + def element_potentials(self): """ Get the array of element potentials. The element potentials are only defined for equilibrium states. This method first sets the composition @@ -681,7 +681,7 @@ cdef class ThermoPhase(_SolutionBase): element potentials for this equilibrium state. """ self.equilibrate('TP') - cdef np.ndarray[np.double_t, ndim=1] data = np.zeros(self.nElements) + cdef np.ndarray[np.double_t, ndim=1] data = np.zeros(self.n_elements) self.thermo.getElementPotentials(&data[0]) return data @@ -694,7 +694,7 @@ cdef class InterfacePhase(ThermoPhase): raise TypeError('Underlying ThermoPhase object is of the wrong type.') self.surf = (self.thermo) - property siteDensity: + property site_density: """ Get/Set the site density. [kmol/m^2] for surface phases; [kmol/m] for edge phases. @@ -707,15 +707,15 @@ cdef class InterfacePhase(ThermoPhase): property coverages: """Get/Set the fraction of sites covered by each species.""" def __get__(self): - cdef np.ndarray[np.double_t, ndim=1] data = np.empty(self.nSpecies) + cdef np.ndarray[np.double_t, ndim=1] data = np.empty(self.n_species) self.surf.getCoverages(&data[0]) - if self._selectedSpecies.size: - return data[self._selectedSpecies] + if self._selected_species.size: + return data[self._selected_species] else: return data def __set__(self, theta): - if len(theta) != self.nSpecies: + if len(theta) != self.n_species: raise ValueError("Array has incorrect length") cdef np.ndarray[np.double_t, ndim=1] data = \ np.ascontiguousarray(theta, dtype=np.double) @@ -727,27 +727,27 @@ cdef class PureFluid(ThermoPhase): A pure substance that can be a gas, a liquid, a mixed gas-liquid fluid, or a fluid beyond its critical point. """ - property critTemperature: + property critical_temperature: """Critical temperature [K].""" def __get__(self): return self.thermo.critTemperature() - property critPressure: + property critical_pressure: """Critical pressure [Pa].""" def __get__(self): return self.thermo.critPressure() - property critDensity: + property critical_density: """Critical density [kg/m^3 or kmol/m^3] depending on `basis`.""" def __get__(self): - return self.thermo.critDensity() / self._massFactor() + return self.thermo.critDensity() / self._mass_factor() - property Psat: + property P_sat: """Saturation pressure [Pa] at the current temperature.""" def __get__(self): return self.thermo.satPressure(self.T) - property Tsat: + property T_sat: """Saturation temperature [K] at the current pressure.""" def __get__(self): return self.thermo.satTemperature(self.P) diff --git a/interfaces/cython/cantera/transport.pyx b/interfaces/cython/cantera/transport.pyx index 442e16051..e6ce20952 100644 --- a/interfaces/cython/cantera/transport.pyx +++ b/interfaces/cython/cantera/transport.pyx @@ -7,8 +7,8 @@ ctypedef void (*transportMethod2d)(CxxTransport*, size_t, double*) except + cdef np.ndarray get_transport_1d(Transport tran, transportMethod1d method): cdef np.ndarray[np.double_t, ndim=1] data = np.empty(tran.thermo.nSpecies()) method(tran.transport, &data[0]) - if tran._selectedSpecies.size: - return data[tran._selectedSpecies] + if tran._selected_species.size: + return data[tran._selected_species] else: return data @@ -30,7 +30,7 @@ cdef class Transport(_SolutionBase): self.transport = newDefaultTransportMgr(self.thermo) super().__init__(*args, **kwargs) - property transportModel: + property transport_model: """ Get/Set the transport model associated with this transport model. @@ -50,12 +50,12 @@ cdef class Transport(_SolutionBase): def __get__(self): return self.transport.viscosity() - property thermalConductivity: + property thermal_conductivity: """Thermal conductivity. [W/m/K].""" def __get__(self): return self.transport.thermalConductivity() - property mixDiffCoeffs: + property mix_diff_coeffs: """ Mixture-averaged diffusion coefficients [m^2/s] relating the mass-averaged diffusive fluxes (with respect to the mass averaged @@ -64,7 +64,7 @@ cdef class Transport(_SolutionBase): def __get__(self): return get_transport_1d(self, tran_getMixDiffCoeffs) - property mixDiffCoeffsMass: + property mix_diff_coeffs_mass: """ Mixture-averaged diffusion coefficients [m^2/s] relating the diffusive mass fluxes to gradients in the species mass fractions. @@ -72,7 +72,7 @@ cdef class Transport(_SolutionBase): def __get__(self): return get_transport_1d(self, tran_getMixDiffCoeffsMass) - property mixDiffCoeffsMole: + property mix_diff_coeffs_mole: """ Mixture-averaged diffusion coefficients [m^2/s] relating the molar diffusive fluxes to gradients in the species mole fractions. @@ -80,7 +80,7 @@ cdef class Transport(_SolutionBase): def __get__(self): return get_transport_1d(self, tran_getMixDiffCoeffsMole) - property thermalDiffCoeffs: + property thermal_diff_coeffs: """ Return a one-dimensional array of the species thermal diffusion coefficients [kg/m/s]. @@ -88,12 +88,12 @@ cdef class Transport(_SolutionBase): def __get__(self): return get_transport_1d(self, tran_getThermalDiffCoeffs) - property multiDiffCoeffs: + property multi_diff_coeffs: """Multicomponent diffusion coefficients [m^2/s].""" def __get__(self): return get_transport_2d(self, tran_getMultiDiffCoeffs) - property binaryDiffCoeffs: + property binary_diff_coeffs: """Binary diffusion coefficients [m^2/s].""" def __get__(self): return get_transport_2d(self, tran_getBinaryDiffCoeffs) @@ -103,7 +103,7 @@ cdef class DustyGasTransport(Transport): """ Implements the "dusty gas" model for transport in porous media. - As implemented here, only species transport (`~Transport.multiDiffCoeffs`) + As implemented here, only species transport (`~Transport.multi_diff_coeffs`) is handled. The viscosity, thermal conductivity, and thermal diffusion coefficients are not implemented. """ @@ -121,12 +121,12 @@ cdef class DustyGasTransport(Transport): def __set__(self, value): (self.transport).setTortuosity(value) - property meanPoreRadius: + property mean_pore_radius: """Mean pore radius of the porous medium [m].""" def __set__(self, value): (self.transport).setMeanPoreRadius(value) - property meanParticleDiameter: + property mean_particle_diameter: """Mean particle diameter of the porous medium [m].""" def __set__(self, value): (self.transport).setMeanParticleDiameter(value) diff --git a/interfaces/cython/cantera/utils.pyx b/interfaces/cython/cantera/utils.pyx index 77f2ba162..2fb243090 100644 --- a/interfaces/cython/cantera/utils.pyx +++ b/interfaces/cython/cantera/utils.pyx @@ -16,7 +16,7 @@ cdef pystr(string x): # Python 3.x return s.decode() -def addDirectory(directory): +def add_directory(directory): """ Add a directory to search for Cantera data files. """ CxxAddDirectory(stringify(directory))