Example #1
0
 def setUp(self):
     lp.set_caching_enabled(False)
     if not self.is_setup:
         utils.setup_logging()
         # load equations
         self.dirpath = os.path.dirname(os.path.realpath(__file__))
         gasname = os.path.join(self.dirpath, 'test.cti')
         # first check test config
         gasname = get_mechanism_file()
         # load the gas
         gas = ct.Solution(gasname)
         # the mechanism
         elems, specs, reacs = read_mech_ct(gasname)
         # and finally check for a test platform
         platform = get_platform_file()
         try:
             if platform is None:
                 platform = ''
                 raise OSError
             platform = build_and_validate('test_platform_schema.yaml',
                                           platform)
         except (OSError, IOError):
             logger = logging.getLogger(__name__)
             logger.warn('Test platform file {} was not found, reverting '
                         'to default.'.format(platform))
             platform = None
         self.store = storage(platform, gas, specs, reacs)
         self.is_setup = True
Example #2
0
def plot(mech, jac_type, out=''):
    # plot the sparsity patterns of our tested mechanisms

    # get gas
    gas = ct.Solution(mech)
    _, specs, reacs = read_mech_ct(gas=gas)

    # get indicies
    info = determine_jac_inds(reacs, specs, RateSpecialization.fixed, jac_type)
    inds = info['jac_inds']

    # set grid for plotting
    grid = np.zeros((gas.n_species + 1, gas.n_species + 1))
    grid[inds['flat_C'][:, 0], inds['flat_C'][:, 1]] = 1

    print('{}, Density: {:.3}%'.format(
        str(jac_type), 100. * np.where(grid)[0].size / grid.size))

    plt.imshow(grid, cmap='Greys', interpolation='none')

    if out:
        if out.endswith('.pdf'):
            out = out[:out.index('.pdf')]
        out += '_' + str(jac_type)[str(jac_type).index('.') + 1:] + '.png'
        plt.tight_layout()
        plt.savefig(out, dpi=1000)
    else:
        plt.show()
Example #3
0
def test_equality_checking():
    """ test species and reaction equality checking"""
    _, specs_ck, reacs_ck = read_mech(ck_file, None)
    _, specs_cti, reacs_cti = read_mech_ct(cti_file)

    assert reacs_ck[0] == reacs_cti[0]
    for i in range(1, len(reacs_ck)):
        assert reacs_ck[0] != reacs_cti[i]
    assert specs_ck[0] == specs_cti[0]
    for i in range(1, len(specs_ck)):
        assert specs_ck[0] != specs_cti[i]
Example #4
0
def test_mech_interpret_runs():
    """ test mechanism intpreter for both cantera and chemkin, and that results
        match"""
    _, specs_ck, reacs_ck = read_mech(ck_file, None)
    _, specs_cti, reacs_cti = read_mech_ct(cti_file)

    assert len(reacs_ck) == len(reacs_cti)
    for i in range(len(reacs_ck)):
        assert reacs_ck[i] == reacs_cti[i]
    assert len(specs_ck) == len(specs_cti)
    for i in range(len(specs_ck)):
        specs_ck[i] == specs_cti[i]
Example #5
0
    def test_heikki_issue(self):
        # tests issue raised by heikki via email re: incorrect re-ordering of species
        # post call to reassign_species_lists
        mech = get_mechanism_file()
        gas = ct.Solution(mech)
        # read our species for MW's
        _, specs, _ = read_mech_ct(gas=gas)

        # find the last species
        gas_map = find_last_species(specs, return_map=True)
        del specs
        # update the gas
        specs = gas.species()[:]
        gas = ct.Solution(thermo='IdealGas',
                          kinetics='GasKinetics',
                          species=[specs[x] for x in gas_map],
                          reactions=gas.reactions())
        del specs

        _, base_specs, base_reacs = read_mech_ct(gas=gas)
        # and reassign
        reassign_species_lists(base_reacs, base_specs)

        for opts in OptionLoopWrapper.from_get_oploop(self):
            reacs, specs = create_jacobian(opts.lang,
                                           mech_name=mech,
                                           vector_size=opts.vector_width,
                                           width=opts.width,
                                           depth=opts.depth,
                                           last_spec=base_specs[-1].name,
                                           platform=opts.platform_name.lower(),
                                           data_order=opts.order,
                                           explicit_simd=opts.is_simd,
                                           test_mech_interpret_vs_backend=True)

            assert all(r1 == r2 for r1, r2 in zip(*(reacs, base_reacs)))
            assert all(s1 == s2 for s1, s2 in zip(*(specs, base_specs)))
Example #6
0
    def setUp(self):
        lp.set_caching_enabled(False)
        if not self.is_setup:
            utils.setup_logging()
            # first check test config
            gasname = get_mechanism_file()
            # load the gas
            gas = ct.Solution(gasname)
            # the mechanism
            elems, specs, reacs = read_mech_ct(gasname)
            # get sort type
            sorting = get_rxn_sorting()
            if sorting != reaction_sorting.none:
                # get ordering
                ordering = sort_reactions(reacs, sorting, return_order=True)
                # and apply
                reacs = sort_reactions(reacs, sorting)
                ct_reacs = gas.reactions()
                # and apply to gas
                gas = ct.Solution(thermo='IdealGas',
                                  kinetics='GasKinetics',
                                  species=gas.species(),
                                  reactions=[ct_reacs[i] for i in ordering])

            # and reassign
            utils.reassign_species_lists(reacs, specs)
            # and finally check for a test platform
            platform = get_platform_file()
            try:
                if platform is None:
                    platform = ''
                    raise OSError
                platform = build_and_validate('test_platform_schema.yaml',
                                              platform)
            except (OSError, IOError):
                logger = logging.getLogger(__name__)
                logger.warn('Test platform file {} was not found, reverting '
                            'to default.'.format(platform))
                platform = None
            self.store = storage(platform, gas, specs, reacs)
            self.is_setup = True