def setUpClass(cls):
        # Create a working directory for output files. If this is
        # an in-source test, create the directory in the root
        # test/work directory. Otherwise, create a system level
        # temporary directory
        root_dir = os.path.abspath(
            os.path.join(os.path.dirname(__file__), '..', '..', '..', '..'))
        if os.path.exists(os.path.join(root_dir, 'SConstruct')):
            cls.test_work_dir = os.path.join(root_dir, 'test', 'work',
                                             'python')
            try:
                os.makedirs(cls.test_work_dir)
            except OSError as e:
                if e.errno == errno.EEXIST:
                    pass
                elif e.errno == errno.EACCES:
                    cls.test_work_dir = tempfile.mkdtemp()
                else:
                    raise
        else:
            cls.test_work_dir = tempfile.mkdtemp()

        cantera.add_directory(cls.test_work_dir)
        cls.test_data_dir = os.path.abspath(
            os.path.join(os.path.dirname(__file__), 'data'))
        cls.cantera_data = os.path.abspath(
            os.path.join(os.path.dirname(__file__), '..', 'data'))
Esempio n. 2
0
def set_env():
    import os
    import cantera
    absdir = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
    absdir = os.path.join(absdir, 'data')
    os.environ['CANTERA_DATA'] = f'{absdir}:$CANTERA_DATA'
    cantera.add_directory(absdir)
    cantera.suppress_thermo_warnings()
Esempio n. 3
0
 def __init__(self,
              mechs,
              connects,
              residenceTime=lambda t: 0.1,
              entrainment=lambda t: 0.1,
              fpath=None,
              setCanteraPath=None,
              build=False):
     """
     PyPlume PlumeModel constructor.
     Parameters:
     mechs - an array like structure with at least 3 mechanisms, [fuelMech,atmMech,eMech1,eMech2,...,eMechN]
     residenceTime - a function that specifies the residence time as a function of time---for combustor and system mass flow rates.
     entrainment - a function that specifies entrainment mass as a function of time.
     connects - an 2d adjacency matrix with integer values corresponding to the appropriate mass flow function+1 in the list of mass flow functions.
                 So, the first mass flow function, 0 index, will be represented as 1 in the matrix. This is because these values will be used for conditionals
                 as well. A template matrix can be generated. The matrix should specifically
     fpath -  file path where the output will be written (hdf5 format).
     setCanteraPath - path variable to cantera mech files
     build -  boolean that builds network strictly from configuration in mechanism files (T,P) if true.
              default: build=false
     """
     super(PlumeModel, self).__init__()
     #Saving contents into self of inputs
     self.mechs = mechs  #mechanisms used in gas creation
     self.connects = connects  #Adjacency matrix of connections
     self.residenceTime = residenceTime  #RTF a function that controlls mass flow
     self.entrainment = entrainment  #a function that specifies mass entrainment
     self.build = build  #This is a bool that says to build on construction
     self.nex = connects.shape[
         0] - 1  #This is the number of exhaust reactors
     self.fpath = fpath
     self.ptype = True  #True for sparse printing
     # Add cantera or mechanisms path
     if setCanteraPath is not None:
         ct.add_directory(setCanteraPath)
     else:
         self.mechPath = os.path.dirname(os.path.abspath(__file__))
         self.mechPath = os.path.join(self.mechPath, "mechanisms")
         sys.path.append(self.mechPath)
     #Creation of gas objects for reactors
     self.createGases()
     #Optionally building network from initialization
     if self.build:
         self.buildNetwork()
Esempio n. 4
0
    def setUpClass(cls):
        # Create a working directory for output files. If this is
        # an in-source test, create the directory in the root
        # test/work directory. Otherwise, create a system level
        # temporary directory
        root_dir = Path(__file__).parents[4].resolve()
        if (root_dir / "SConstruct").is_file():
            cls.test_work_path = root_dir / "test" / "work" / "python"
            cls.using_tempfile = False
            try:
                cls.test_work_path.mkdir(exist_ok=True)
            except FileNotFoundError:
                cls.test_work_path = Path(tempfile.mkdtemp())
                cls.using_tempfile = True
        else:
            cls.test_work_path = Path(tempfile.mkdtemp())
            cls.using_tempfile = True

        cantera.make_deprecation_warnings_fatal()
        cantera.add_directory(cls.test_work_path)
        cls.test_data_path = TEST_DATA_PATH
        cls.cantera_data_path = CANTERA_DATA_PATH
Esempio n. 5
0
    def setUpClass(cls):
        # Create a working directory for output files. If this is
        # an in-source test, create the directory in the root
        # test/work directory. Otherwise, create a system level
        # temporary directory
        root_dir = os.path.abspath(os.path.join(os.path.dirname(__file__),
                                                '..', '..', '..', '..'))
        if os.path.exists(os.path.join(root_dir, 'SConstruct')):
            cls.test_work_dir = os.path.join(root_dir, 'test', 'work', 'python')
            try:
                os.makedirs(cls.test_work_dir)
            except OSError as e:
                if e.errno == errno.EEXIST:
                    pass
                elif e.errno == errno.EACCES:
                    cls.test_work_dir = tempfile.mkdtemp()
                else:
                    raise
        else:
            cls.test_work_dir = tempfile.mkdtemp()

        cantera.add_directory(cls.test_work_dir)
        cls.test_data_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), 'data'))
Esempio n. 6
0
from pathlib import Path
import cantera

from .test_composite import *
from .test_convert import *
from .test_equilibrium import *
from .test_func1 import *
from .test_kinetics import *
from .test_mixture import *
from .test_onedim import *
from .test_purefluid import *
from .test_reaction import *
from .test_reactor import *
from .test_thermo import *
from .test_transport import *
from .test_utils import *

cantera.add_directory(Path(__file__) / "data")
cantera.add_directory(
    Path(__file__).parents[1] / "examples" / "surface_chemistry")
Esempio n. 7
0
import os
import cantera

from .test_thermo import *
from .test_purefluid import *
from .test_equilibrium import *
from .test_kinetics import *
from .test_transport import *
from .test_mixture import *
from .test_func1 import *
from .test_reactor import *
from .test_onedim import *
from .test_convert import *

cantera.add_directory(os.path.join(os.path.dirname(__file__), 'data'))
cantera.add_directory(os.path.join(os.path.dirname(__file__), '..', 'examples', 'surface_chemistry'))
Esempio n. 8
0
import cantera as ct
import os
DATA_DIR = os.path.abspath('../data')
MECH_DIR = os.path.join(DATA_DIR, 'mechanisms')
ct.add_directory(MECH_DIR)  # for custom mechanisms
Esempio n. 9
0
#name = 'my_mechanism.cti'
name = 'As_thermo_data.cti'
# composition
# Jupiter AsH3 0.55 times enrichment
# composition = 'H2:1.0,He:0.157,CH4:2.37e-3,H2O:7.518e-3,NH3:6.64e-4,AsH3:2.2e-10'
# Saturn AsH3 7.5 times enrichment
composition = 'H2:1.0,He:0.135,CH4:5.33e-3,H2O:9.8e-3,NH3:4.54e-4,AsH3:3.0e-9'
# list of species that you want to plot
species_names = ['As', 'As2', 'As3', 'As4', 'AsH', 'AsH2', 'AsH3']
# output
output_file_name = 'As_eq_Sat.dat'

################################################################################
# no need to change the scripts below
# initialization the phase
ct.add_directory(mechanism_directory)
gas1 = ct.Solution(name)
gas1.X = composition
nspecies = gas1.n_species
N = len(P)
x = np.zeros((nspecies, N))
# equilibrium states
for i in range(N):
    gas1.TP = T[i], P[i]
    gas1.equilibrate('TP')
    x[:, i] = gas1.X

# if plot argument exists, make a plot
if '--plot' in sys.argv[1:]:
    import matplotlib.pyplot as plt
    #species_names = ['CO','H2O','CH4','NH3','N2']
Esempio n. 10
0
File: engines.py Progetto: NREL/MPRL
 def setup_cantera(self):
     """Wrapper function to setup all cantera objects"""
     ct.add_directory(self.datadir)
     self.setup_gas()
Esempio n. 11
0
import os.path as _path

import cantera
from ._ember import *
from . import _ember
from .input import *
from .output import *
from . import utils

__version__ = '1.4.0'

# Add Ember's data file directory to Cantera's search path. Because the Python
# module is statically linked to Cantera, this needs to be done separately for
# each of the two copies of the Cantera library that have been loaded.
_datapath = _path.join(_path.dirname(_path.abspath(__file__)), 'data')
_ember.addCanteraDirectory(_datapath)
cantera.add_directory(_datapath)
Esempio n. 12
0
import cantera as ct
from .gases import *
from .reactors import *
from .configurations import *

# this makes cantera available directly through pt namespace
# (dubious...)
from cantera import *



#################################
# Add the mechanisms directory to Cantera's search path
# so we don't have to copy XML files everywhere
import pkg_resources 
ct.add_directory( pkg_resources.resource_filename('pantera','mechanisms') )


#################################
# Monkey patch Cantera 

from cantera_monkey_patches import *

Esempio n. 13
0
import os.path as _path

import cantera
from _ember import *
import _ember
from input import *
from output import *
import utils

__version__ = '1.4.0a1'

# Add Ember's data file directory to Cantera's search path. Because the Python
# module is statically linked to Cantera, this needs to be done separately for
# each of the two copies of the Cantera library that have been loaded.
_datapath = _path.join(_path.dirname(_path.abspath(__file__)), 'data')
_ember.addCanteraDirectory(_datapath)
cantera.add_directory(_datapath)
Esempio n. 14
0
import os
import cantera

cantera.add_directory(os.path.join(os.path.dirname(__file__), 'data'))

from .test_thermo import *
from .test_purefluid import *
from .test_equilibrium import *
from .test_kinetics import *
from .test_transport import *
from .test_mixture import *
from .test_func1 import *
from .test_reactor import *
from .test_onedim import *
from .test_convert import *
"""
Constant-pressure, adiabatic kinetics simulation.

Requires: cantera >= 2.5.0, matplotlib >= 2.0
"""

import sys

import cantera as ct
from Particle import *
ct.add_directory('./data')
gas = ct.Solution('caltech.yaml')
gas.TPX = 1700.0, 12 * ct.one_atm, 'CH4:1,N2:1'
r = ct.IdealGasConstPressureReactor(gas, energy='off')

sim = ct.ReactorNet([r])
sim.verbose = True

# Particle arrays initilization
PND = []  # Particle Number Density
PND.append(0.0)
FV = []  # Particle Volume Fraction
FV.append(0.0)
X_A4R5C = [
]  # Mole fraction of A4R5 after consumption with the particle module
X_A4R5C.append(0.0)

# limit advance when temperature difference is exceeded
delta_T_max = 20.
r.set_advance_limit('temperature', delta_T_max)
Esempio n. 16
0
import sys
import numpy as np

import cantera as ct

from mesh_saturn import *

from matplotlib.pyplot import *

# create mesh for Saturn
N = 70
[z, dz, T, log_PG, mu_average, rho] = mesh(N)
PG = 10**log_PG

# initialization the phase
ct.add_directory('/Users/wangdong/Documents/2014_summer/cantera_input_files')
gas1 = ct.Solution('P_Reaction_set.cti')
nspecies = gas1.n_species

# O/H2 protosolar: 1.074e-3, 10 times protosolar
#gas1.X = 'H2:1.0,He:0.135,H2O:1.074e-2,PH3:7.28e-6'
# O/H2 protosolar:  1.074e-3 20 times protosolar
gas1.X = 'H2:1.0,He:0.135,H2O:2.148e-2,PH3:7.28e-6'

y_eq = np.zeros((nspecies, N))
# set up the initial state using equilibrium states
for i in range(N):
    gas1.TP = T[i], PG[i] * 1.e5
    gas1.equilibrate('TP')
    y_eq[:, i] = gas1.Y
Esempio n. 17
0
dataoutputfolder = os.path.join(finalanalysisfolder, 'Data')
metadatafolder = os.path.join(dataoutputfolder, 'data_generation_metadata')

dsst = load.loadprocesseddata(os.path.join(dataoutputfolder, 'dsst'))

with open(os.path.join(dataoutputfolder, 'da_ct.pickle'), 'rb') as file:
    da_ct = pickle.load(file)

#mhdcantera repository cantera utilities (originally from table gen)
import sys
mhdcantera_repo_path = r'C:\Users\aspit\Git\MHDLab\mhdcantera'
sys.path.append(mhdcantera_repo_path)
from cantera_utils import util as ct_utils

ct_path = os.path.join(mhdcantera_repo_path, 'cantera_utils', 'data')
ct.add_directory(ct_path)

g, electron_trans = ct_utils.gen_gas(GasThermo_tr='data/drm19_SeededKero.cti',
                                     GasThermoName_tr='gas',
                                     CrossSectionFile='data/NETL_CF2017.csv',
                                     basis='mass')

W = g.molecular_weights
MW = {name: W[i] for i, name in enumerate(g.species_names)}
MW["K2CO3"] = 2 * MW["K"] + MW["CO2"] + 0.5 * MW["O2"]


def gen_Y_str(Y_K, debug=False):

    #f are mass fractions in the emulsion
    recepie_em = {