How to use the pymars.soln2cti function in pymars

To help you get started, we’ve selected a few pymars examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Niemeyer-Research-Group / pyMARS / pymars / sensitivity_analysis.py View on Github external
# If using the greedy algorithm, now need to reevaluate all species errors
            if algorithm_type == 'greedy':
                species_errors = evaluate_species_errors(
                    current_model, ignition_conditions, initial_metrics, species_limbo, 
                    phase_name=phase_name, num_threads=num_threads
                    )
                if min(species_errors) > error_limit:
                    break
    
    # Final model; may need to rewrite
    reduced_model = ReducedModel(
        model=current_model.model, filename=f'reduced_{current_model.model.n_species}.cti', 
        error=current_model.error
        )
    soln2cti.write(reduced_model.model, reduced_model.filename, path=path)

    logging.info(53 * '-')
    logging.info('Sensitivity analysis stage complete.')
    logging.info(f'Skeletal model: {reduced_model.model.n_species} species and '
                 f'{reduced_model.model.n_reactions} reactions.'
                 )
    logging.info(f'Maximum error: {reduced_model.error:.2f}%')
    return reduced_model
github Niemeyer-Research-Group / pyMARS / pymars / pfa.py View on Github external
os.remove(reduced_model.filename)
        
        previous_model = ReducedModel(
            model=reduced_model.model, filename=reduced_model.filename, 
            error=reduced_model.error, limbo_species=reduced_model.limbo_species
            )
    
    if reduced_model.error > error_limit:
        threshold -= (2 * threshold_increment)
        reduced_model = reduce_pfa(
            model_file, species_targets, species_safe, threshold, matrices, 
            ignition_conditions, sampled_metrics, 
            threshold_upper=threshold_upper, num_threads=num_threads, path=path
            )
    else:
        soln2cti.write(reduced_model, f'reduced_{reduced_model.model.n_species}.cti', path=path)
    
    logging.info(45 * '-')
    logging.info('PFA reduction complete.')
    logging.info(f'Skeletal model: {reduced_model.model.n_species} species and '
                 f'{reduced_model.model.n_reactions} reactions.'
                 )
    logging.info(f'Maximum error: {reduced_model.error:.2f}%')
    logging.info('Final reduced model saved as ' + reduced_model.filename)
    return reduced_model
github Niemeyer-Research-Group / pyMARS / pymars / drg.py View on Github external
os.remove(reduced_model.filename)
        
        previous_model = ReducedModel(
            model=reduced_model.model, filename=reduced_model.filename, 
            error=reduced_model.error, limbo_species=reduced_model.limbo_species
            )
    
    if error_current > error_limit:
        threshold -= (2 * threshold_increment)
        reduced_model = reduce_drg(
            model_file, species_targets, species_safe, threshold, matrices, 
            ignition_conditions, sampled_metrics, 
            threshold_upper=threshold_upper, num_threads=num_threads, path=path
            )
    else:
        soln2cti.write(reduced_model, f'reduced_{reduced_model.model.n_species}.cti', path=path)
    
    logging.info(45 * '-')
    logging.info('DRG reduction complete.')
    logging.info(f'Skeletal model: {reduced_model.model.n_species} species and '
                 f'{reduced_model.model.n_reactions} reactions.'
                 )
    logging.info(f'Maximum error: {reduced_model.error:.2f}%')
    logging.info('Final reduced model saved as ' + reduced_model.filename)
    return reduced_model
github Niemeyer-Research-Group / pyMARS / pymars / drg.py View on Github external
for matrix in matrices:
        species_retained += trim_drg(matrix, solution.species_names, species_targets, threshold)
    
    # want to ensure retained species are the set of those reachable for each state
    species_retained = list(set(species_retained))

    if previous_model and len(species_retained) == previous_model.model.n_species:
        return previous_model

    species_removed = [sp for sp in solution.species_names
                       if sp not in (species_retained + species_safe)
                       ]

    # Cut the exclusion list from the model.
    reduced_model = trim(model_file, species_removed, f'reduced_{model_file}')
    reduced_model_filename = soln2cti.write(
        reduced_model, f'reduced_{reduced_model.n_species}.cti', path=path
        )

    reduced_model_metrics = sample_metrics(
        reduced_model_filename, ignition_conditions, num_threads=num_threads, path=path
        )
    error = calculate_error(sampled_metrics, reduced_model_metrics)
    
    # If desired, now identify limbo species for future sensitivity analysis
    limbo_species = []
    if threshold_upper:
        species_retained += trim_drg(
            matrix, solution.species_names, species_targets, threshold_upper
            )
        limbo_species = [
            sp for sp in solution.species_names
github Niemeyer-Research-Group / pyMARS / pymars / sensitivity_analysis.py View on Github external
use the specified number of threads.
    
    Returns
    -------
    species_errors : numpy.ndarray
        Maximum errors induced by removal of each limbo species

    """
    species_errors = np.zeros(len(species_limbo))
    with TemporaryDirectory() as temp_dir:
        for idx, species in enumerate(species_limbo):
            test_model = trim(
                starting_model.filename, [species], f'reduced_model_{species}.cti', 
                phase_name=phase_name
                )
            test_model_file = soln2cti.write(
                test_model, f'reduced_model_{species}.cti', path=temp_dir
                )
            reduced_model_metrics = sample_metrics(
                test_model_file, ignition_conditions, phase_name=phase_name, 
                num_threads=num_threads
                )
            species_errors[idx] = calculate_error(metrics, reduced_model_metrics)
    
    return species_errors
github Niemeyer-Research-Group / pyMARS / pymars / pfa.py View on Github external
for matrix in matrices:
        species_retained += trim_pfa(matrix, solution.species_names, species_targets, threshold)
    
    # want to ensure retained species are the set of those reachable for each state
    species_retained = list(set(species_retained))

    if previous_model and len(species_retained) == previous_model.model.n_species:
        return previous_model

    species_removed = [sp for sp in solution.species_names
                       if sp not in (species_retained + species_safe)
                       ]

    # Cut the exclusion list from the model.
    reduced_model = trim(model_file, species_removed, f'reduced_{model_file}')
    reduced_model_filename = soln2cti.write(
        reduced_model, f'reduced_{reduced_model.n_species}.cti', path=path
        )

    reduced_model_metrics = sample_metrics(
        reduced_model_filename, ignition_conditions, num_threads=num_threads, path=path
        )
    error = calculate_error(sampled_metrics, reduced_model_metrics)
    
    # If desired, now identify limbo species for future sensitivity analysis
    limbo_species = []
    if threshold_upper:
        species_retained += trim_pfa(
            matrix, solution.species_names, species_targets, threshold_upper
            )
        limbo_species = [
            sp for sp in solution.species_names
github Niemeyer-Research-Group / pyMARS / pymars / drgep.py View on Github external
solution = ct.Solution(model_file, phase_name)
    species_removed = [sp for sp in solution.species_names
                       if importance_coeffs[sp] < threshold 
                       and sp not in species_safe
                       ]
    
    if (previous_model and 
        len(species_removed) == solution.n_species - previous_model.model.n_species
        ):
        return previous_model

    # Cut the exclusion list from the model.
    reduced_model = trim(
        model_file, species_removed, f'reduced_{model_file}', phase_name=phase_name
        )
    reduced_model_filename = soln2cti.write(
        reduced_model, f'reduced_{reduced_model.n_species}.cti', path=path
        )

    reduced_model_metrics = sample_metrics(
        reduced_model_filename, ignition_conditions, phase_name=phase_name, 
        num_threads=num_threads, path=path
        )
    error = calculate_error(sampled_metrics, reduced_model_metrics)

    return ReducedModel(
        model=reduced_model, filename=reduced_model_filename, error=error
        )
github Niemeyer-Research-Group / pyMARS / pymars / drgep.py View on Github external
if previous_model.model.n_species != reduced_model.model.n_species:
            os.remove(reduced_model.filename)
        
        previous_model = ReducedModel(
            model=reduced_model.model, filename=reduced_model.filename, 
            error=reduced_model.error, limbo_species=reduced_model.limbo_species
            )
    
    if reduced_model.error > error_limit:
        threshold -= (2 * threshold_increment)
        reduced_model = reduce_drgep(
            model_file, species_safe, threshold, importance_coeffs, ignition_conditions, 
            sampled_metrics, phase_name=phase_name, num_threads=num_threads, path=path
            )
    else:
        soln2cti.write(reduced_model, f'reduced_{reduced_model.model.n_species}.cti', path=path)

    if threshold_upper:
        for sp in reduced_model.model.species_names:
            if importance_coeffs[sp] < threshold_upper and (sp not in species_safe):
                reduced_model.limbo_species.append(sp)
    
    logging.info(45 * '-')
    logging.info('DRGEP reduction complete.')
    logging.info(f'Skeletal model: {reduced_model.model.n_species} species and '
                 f'{reduced_model.model.n_reactions} reactions.'
                 )
    logging.info(f'Maximum error: {reduced_model.error:.2f}%')
    logging.info('Final reduced model saved as ' + reduced_model.filename)
    return reduced_model