Utilities#

A collection of routines with multiple purposes organized as follows:

  • unclasified

  • databases

  • display

  • eos

  • export

  • extensions

  • root_finding

  • thermo

  • validations

Unclasified utility functions#

A collection of unclasified functions necessary to perform all the calculations in CT.


Routines
Compute_YFuel(mix, mix_Fuel)#

Compute fuel mass fraction [-]

Parameters:
  • mix (struct) – Properties of the mixture (fuel + oxidizer + inerts)

  • mix_Fuel (struct) – Properties of the mixture (fuel)

Returns:

Yi_Fuel (float) – Mass fractions of the fuel mixture

Example

Yi_Fuel = Compute_YFuel(mix, mix_Fuel)

Compute_density(mix)#

Get density of the set of mixtures

Parameters:

mix (struct) – Properties of the mixture/s

Returns:

rho (float) – Vector with the densities of all the mixtures

GPL()#

Return Combustion Toolbox license

Returns:

license_content (char) – The license text

Example

license_content = GPL()

abundances2moles(elements, filename, varargin)#

Read solar abundances in log 10 scale and compute the initial molar fractions in the mixture [-]

Parameters:
  • elements (cell) – List with the given elements

  • filename (file) – Filename with the data

Optional Args:

metallicity (float): Metallicity

Returns:

moles (float) – moles relative to H of the remaining elements in the mixture

Examples

  • moles = abundances2moles({‘H’, ‘He’, ‘C’, ‘N’, ‘O’, ‘Ne’, ‘Ar’, ‘S’, ‘Cl’, ‘Fe’}, ‘abundances.txt’)

  • moles = abundances2moles({‘H’, ‘He’, ‘C’, ‘N’, ‘O’, ‘Ne’, ‘Ar’, ‘S’, ‘Cl’, ‘Fe’}, ‘abundances.txt’, 10)

append_cells(cell1, cell2, varargin)#

Append two or more cells in one common cell

Parameters:
  • cell1 (struct) – Cell 1

  • cell2 (struct) – Cell 2

Optional Args:

celli (struct): Additional cells

Returns:

append_cell (struct) – Merged cell

append_structs(s1, s2, varargin)#

Append two or more structs in one common struct

Parameters:
  • s1 (struct) – Struct 1

  • s2 (struct) – Struct 2

Optional Args:

si (struct): Additional structs

Returns:

append_s (struct) – Merged struct

ask_problem(self)#

Create a list selection dialog box (deprecated)

Parameters:

self (struct) – Data of the mixture, conditions, and databases

Returns:

PT (string) – String with the problem selected

assign_vector2cell(cell, vector, varargin)#

Assign values of a vector into a cell

Parameters:
  • cell (cell) – Cell in which the values of the given vector are going to be included

  • vector (any) – Vector with the values that are going to be included in the cell

Optional Args:

ind (float): List of index positions to assign specific positions to the cell

Returns:

cell (cell) – Cell with the values of the given vector

cell2vector(value, varargin)#

Convert values of an individual cell into a vector. If the value correspond with a struct it can return as a vector the values of a given fieldname.

Parameters:

value (cell or struct) – Data of the mixture, conditions, and databases

Optional Args:

field (str): Fieldname of the given value (struct)

Returns:

vector (any) – Vector with the values of the individual cell/fieldname (struct)

check_FOI(self, FOI_species)#

Check that fuel species are contained in the list of products (only for initial computations)

Parameters:
  • self (struct) – Data of the mixture, conditions, and databases

  • FOI_species (bool) – Species in the initial mixture (Fuel, Oxidizer, Inert)

Returns:

self (struct) – Data of the mixture, conditions, and databases

check_inputs(self)#

Check that all the inputs are specified

Parameters:

self (struct) – Data of the mixture, conditions, and databases

Returns:

self (struct) – Data of the mixture, conditions, and databases

check_temperature_range(self, T, ind, NS, FLAG)#

Remove species indeces out of the temperature range if FLAG = true, e.g., linear extrapolation of the polynomial fits is not allowed.

Parameters:
  • self (struct) – Data of the mixture, conditions, and databases

  • T (float) – Temperature

  • ind (float) – Vector with the species indeces

  • NS (float) – Number of species

  • FLAG (bool) – Flag indicating linear extrapolation of the polynomials fits

Returns:

Tuple containing

  • ind (float): Updated vector with the species indeces

  • NS (float): Update number of species

check_update(varargin)#

Check if there is a new release of the Combustion Toolbox

Optional Args:

fig (object): UIFigure class

Returns:

Tuple containing

  • FLAG_UPDATE (bool): FLAG indicating true (false) if there is (not) an update of the Combustion Toolbox

  • message (char): Message displayed

Examples

  • [FLAG_UPDATE, message] = check_update();

  • [FLAG_UPDATE, message] = check_update(UIFigure);

compute_Gammas(u2, rho2, p2)#

Compute slope of the Hugoniot curve

Parameters:
  • u2 (float) – Post-shock velocity [m/s]

  • rho2 (float) – Post-shock density [kg/m3]

  • p2 (float) – Post-shock pressure [bar]

Returns:

Gammas (float) – Slope of the Hugoniot curve [-]

compute_Gammas_frozen(M1, R, P)#

Compute slope of the Hugoniot curve for thermochemically frozen air

Parameters:
  • M1 (float) – Pre-shock Mach number [-]

  • R (float) – Density ratio [-]

  • P (float) – Pressure ratio [-]

Returns:

Gammas (float) – Slope of the Hugoniot curve [-]

compute_first_derivative(x, y)#

Compute first central derivate using a non-uniform grid

Parameters:
  • x (float) – Grid values

  • y (float) – Values for the corresponding grid

Returns:

dxdy (float) – Value of the first derivate for the given grid and its corresponding values

compute_phi_c(Fuel)#

Compute guess of equivalence ratio in which soot appears considering complete combustion

Parameters:

Fuel (struct) – Struct mix with all the properties of the Fuel mixture

Returns:

phi_c (float) – Equivalence ratio in which soot appears [-]

compute_properties(self, properties_matrix, p, T)#

Compute properties from the given properties matrix at pressure p [bar] and temperature T [K]

Parameters:
  • self (struct) – Data of the mixture, conditions, and databases

  • properties_matrix (float) – Matrix with the properties of the mixture

  • p (float) – Pressure [bar]

  • T (float) – Temperature [K]

Returns:

mix (struct) – Properties of the mixture

Example

mix = compute_properties(self, properties_matrix, p, T)

compute_ratio_oxidizers_O2(self)#

Compute ratio oxidizers/O2

Parameters:

self (struct) – Data of the mixture, conditions, and databases

Returns:

self (struct) – Data of the mixture, conditions, and databases

compute_temperature_mixture(self, species, moles, temperatures)#

Compute equilibrium temperature [K] of a gaseous mixture compound of n species with species at different temperatures

Parameters:
  • self (struct) – Data of the mixture, conditions, and databases

  • species (cell) – Cell array with the species of the mixture

  • moles (float) – Moles of the species in the mixture [mol]

  • temperatures (float) – Vector or cell array with the temperatures of each species

Returns:

T (float) – Temperature of the mixture at equilibrium

Example

T = compute_temperature_mixture(self, {‘H2’, ‘O2’}, [1, 2], [300, 400])

convert_Pa_to_bar(value)#

Convert pressure in [Pa] units to [bar]

Parameters:

value (float) – Pressure value(s) in [bar]

Returns:

value (float) – Pressure value(s) in [bar]

Example

value = convert_Pa_to_bar(1e5)

convert_atm_to_bar(value)#

Convert pressure in [atm] units to [bar]

Parameters:

value (float) – Pressure value(s) in [atm]

Returns:

value (float) – Pressure value(s) in [bar]

Example

value = convert_atm_to_bar(1)

convert_bar_to_Pa(value)#

Convert pressure in [bar] units to [Pa]

Parameters:

value (float) – Pressure value(s) in [bar]

Returns:

value (float) – Pressure value(s) in [Pa]

Example

value = convert_bar_to_Pa(1)

convert_bar_to_atm(value)#

Convert pressure in [bar] units to [atm]

Parameters:

value (float) – Pressure value(s) in [bar]

Returns:

value (float) – Pressure value(s) in [atm]

Example

value = convert_bar_to_atm(1.01325)

convert_weight_percentage_to_moles(LS, weight_percentage, DB)#

Convert weight percentage (wt%) to moles

Parameters:
  • LS (cell) – List of species

  • weight_percentage (float) – Weight percentage of the species [%]

  • DB (struct) – Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits

Returns:

moles (float) – Number of moles [mol]

Example

moles = convert_weight_percentage_to_moles({‘H2O’, ‘CO2’}, [50, 50], DB)

create_cell_ntimes(varargin)#

Create cell array with the same item n-times

define_F(self)#

Set Fuel of the mixture

Parameters:

self (struct) – Data of the mixture, conditions, and databases

Returns:

self (struct) – Data of the mixture, conditions, and databases

define_FOI(self, i)#

Set up mixture: fuel, oxidizer and diluent/inert species

Parameters:
  • self (struct) – Data of the mixture, conditions, and databases

  • i (float) – Position of the evaluated problem

Returns:

self (struct) – Data of the mixture, conditions, and databases

define_I(self)#

Set Inert of the mixture

Parameters:

self (struct) – Data of the mixture, conditions, and databases

Returns:

self (struct) – Data of the mixture, conditions, and databases

define_O(self)#

Set Oxidizer of the mixture

Parameters:

self (struct) – Data of the mixture, conditions, and databases

Returns:

self (struct) – Data of the mixture, conditions, and databases

docs_CT()#

Open Combustion Toolbox’s documentation in default web browser

find_ind(LS, species)#

Find the index of the species based on the given list (LS)

Parameters:
  • LS (cell) – List of species

  • species (cell) – Species to find index values

Returns:

index (float) – List with the index of the species based on the given list (LS)

Example

index = find_ind({‘H2O’, ‘CO2’, ‘CH4’}, {‘H2O’, ‘CH4’})

get_FLAG_N(self)#

Flag if the number of moles of fuel, oxidant and inert species is specified. If not, consider 1 mole for the fuel and calculate the remaining moles from the equivalence relation.

Parameters:

self (struct) – Data of the mixture, conditions, and databases

Returns:

self (struct) – Data of the mixture, conditions, and databases

get_combustion_toolbox_version()#

Get Combustion Toolbox version

Returns:

Tuple containing

  • release (char): Release version

  • date (char): Release date

get_index_phase_species(self, LS)#

Get index of gaseous, condensed and cryogenic species

Parameters:
  • self (struct) – Data of the mixture, conditions, and databases

  • LS (cell) – Name list species / list of species

Returns:

self (struct) – Data of the mixture, conditions, and databases

get_latest_version_github(user, repo_name)#

Get latest version from a repository from Github

Parameters:
  • user (char) – Username of the owner of the repository

  • repo_name (char) – Name of the repository

Returns:

Tuple containing

  • release (char): Release tag (latest)

  • git_data (struct): Body data of the request

Example

[release, git_data] = get_latest_version_github(‘AlbertoCuadra’, ‘combustion_toolbox’)

get_monitor_positions(varargin)#

Routine that gets the position in pixels of the monitor(s) connected to the device using Java (default) or MATLAB’s routines. If no monitor is specified, the position of the main monitor is returned.

Optional Args:

monitor_id (float): Get position in pixels for the given monitor

Returns:

position (float) – Position of the monitor(s)

Examples

  • position = get_monitor_positions() returns the position of the main monitor

  • position = getMonitorPositions(2) returns the position of the second monitor

  • position = getMonitorPositions(1) returns the position of the first monitor

  • position = getMonitorPositions(monitor_id) returns the position in pixels of the given monitor

Notes

This function first tries using Java to get the screen size values that do not take into account ui scaling, so it will return the proper screen size values. Otherwise, it gets the screen position using MATLAB’s routines

get_monitor_positions_MATLAB(varargin)#

Routine that gets the position in pixels of the monitor(s) connected to the device using MATLAB’s routines. If no monitor is specified, the position of the main monitor is returned.

Optional Args:

monitor_id (float): Get position in pixels for the given monitor

Returns:

position (float) – Position of the monitor(s)

Examples

  • position = get_monitor_positions() returns the position of the main monitor

  • position = getMonitorPositions(2) returns the position of the second monitor

  • position = getMonitorPositions(1) returns the position of the first monitor

  • position = getMonitorPositions(monitor_id) returns the position in pixels of the given monitor

get_order(value)#

Get order of magnitude of a number in base 10

Parameters:

value (float) – number in base 10

Returns:

order (float) – order of magnitude of a number in base 10

Example

order = get_order(0.0001)

get_oxidizer_reference(self, varargin)#

Get oxidizer of reference for computations with the equivalence ratio

Parameters:

self (struct) – Data of the mixture, conditions, and databases

Returns:

self (struct) – Data of the mixture, conditions, and databases, included the oxidizer of reference which can be obtained as self.S.ind_ox_ref

get_partial_derivative(self, mix)#

Get value of the partial derivative for the set problem type [kJ/K] (HP, EV) or [kJ/K^2] (SP, SV)

Parameters:
  • self (struct) – Data of the mixture, conditions, and databases

  • mix (struct) – Properties of the mixture

Returns:

value (float) – Value of the partial derivative for the set problem type [kJ/K] (HP, EV) or [kJ/K^2] (SP, SV)

get_title(self)#

Get a title based on the problem type and species involved

Parameters:

self (struct) – Data of the mixture, conditions, and databases

Returns:

titlename (char) – Title based on the problem type and species involved

get_transformation(self, field)#

Get the corresponding value of the field in Problem Description (PD)

Parameters:
  • self (struct) – Data of the mixture, conditions, and databases

  • field (char) – Fieldname in Problem Description (PD)

Returns:

value (float) – Value/s assigned to the field

get_typeSpecies(self)#

Create cell array with the type of species in the mixture

Parameters:

self (struct) – Data of the mixture, conditions, and databases

Returns:

typeSpecies (cell) – Cell array with the type of species in the mixture

list_phase_species(self, LS)#

Establish cataloged list of species according to the state of the phase (gaseous or condensed). It also obtains the indices of cryogenic liquid species, i.e., liquified gases.

Parameters:
  • self (struct) – Data of the mixture, conditions, and databases

  • LS (cell) – List of species

Returns:

self (struct) – Data of the mixture, conditions, and databases

mixture(T, p, species, moles, varargin)#

Compute the properties of a mixture at a given temperature and pressure

Parameters:
  • T (float) – Temperature [K]

  • p (float) – Pressure [bar]

  • species (cell) – List of species

  • moles (cell) – List of moles of each species

Optional Name-Value Pairs Args:
  • phi (float): Equivalence ratio [-]

Returns:

mix (struct) – Mixture properties

Examples

  • mix = mixture(300, 1, {‘CH4’, ‘O2’, ‘N2’}, [1, 2, 7.52])

  • mix = mixture(300, 1, {‘CH4’, ‘O2’, ‘N2’}, [1, 2, 7.52], ‘self’, self)

  • mix = mixture(300, 1, {‘CH4’, ‘O2’, ‘N2’}, [1, 2, 7.52], ‘DB_master’, DB_master, ‘DB’, DB)

post_results(self)#

Postprocess all the results with predefined plots

Parameters:

self (struct) – Data of the mixture, conditions, and databases

print_error(ME, varargin)#

Print message error

Parameters:

ME (object) – MException object that allows to identify the error

Optional Name-Value Pairs Args:
  • type (char): Type of message (error, warning, or other)

  • message_solution (char): Message solution

Returns:

error_message (char) – Message error

Examples

  • error_message = print_error(ME, ‘Type’, ‘Warning’)

  • error_message = print_error(ME, ‘Type’, ‘Warning’, ‘Solution’, ‘Returning an empty index value.’)

read_abundances(filename)#

Read solar abundances file

Format: [number element, element, abundance, name, molar mass (g/mol)]

Parameters:

filename (file) – Filename with the data

Returns:

Tuple containing

  • abundances (float): Vector with the logarithmic base 10 solar abundances

  • elements (cell): List with the given elements

reorganize_index_phase_species(self, LS)#

Reorginize index of gaseous, condensed and cryogenic species

Parameters:
  • self (struct) – Data of the mixture, conditions, and databases

  • LS (cell) – Name list species / list of species

Returns:

self (struct) – Data of the mixture, conditions, and databases

set_air(self, FLAG_IDEAL_AIR)#

Incluide air in the initial mixture

Parameters:
  • self (struct) – Data of the mixture, conditions, and databases

  • FLAG_IDEAL_AIR (bool) – Flag indicating consider ideal or non-ideal air mixture

Returns:

self (struct) – Data of the mixture, conditions, and databases

set_prop(self, varargin)#

Assign property values to the respective variables

Parameters:

self (struct) – Data of the mixture, conditions, and databases

Optional Args:
  • field (str): Fieldname in Problem Description (PD)

  • value (float): Value/s to assing in the field in Problem Description (PD)

Returns:

self (struct) – Data of the mixture, conditions, and databases

set_react_index(self, species)#

Set index of react (non-frozen) and frozen species

Parameters:
  • self (struct) – Data of the mixture, conditions, and databases

  • species (char) – Frozen species

Returns:

self (struct) – Data of the mixture, conditions, and databases

set_species(self, species, moles, T, varargin)#

Fill the properties matrix with the data of the mixture

Parameters:
  • self (struct) – Data of the mixture, conditions, and databases

  • species (cell) – Species contained in the system

  • moles (float) – Moles of the species in the mixture [mol]

  • T (float) – Temperature [K]

Optional Args:

ind (float): Vector with the indexes of the species to fill the properties matrix

Returns:

properties_matrix (float) – Properties matrix

Examples

properties_matrix = set_species(self, {‘N2’, ‘O2’}, [3.76, 1], 300) properties_matrix = set_species(self, {‘N2’, ‘O2’}, [3.76, 1], 300, [1, 2])

set_species_initilize(self, species)#

Fill the properties matrix with the data of the mixture

Parameters:
  • self (struct) – Data of the mixture, conditions, and databases

  • species (cell) – Species contained in the system

Returns:

properties_matrix (float) – Properties matrix

set_transformation(self, field, value)#

Set the corresponding value of the field in Problem Description (PD)

Parameters:
  • self (struct) – Data of the mixture, conditions, and databases

  • field (str) – Fieldname in Problem Description (PD)

  • value (float) – Value/s to assign to the field

Returns:

self (struct) – Data of the mixture, conditions, and databases

setup_segregated_solver(self, LS)#

Get additional inputs necessary to use the segregated model

smooth_data(x, y, varargin)#

Smooth data using Fourier NonlinearLeastSquares method

Parameters:
  • x (float) – data in the x direction

  • y (float) – data in the y direction

Optional Args:

start_point (float): initial point of the fit

Returns:

Tuple containing

  • x (float): smooth data in the x direction

  • y (float): smooth data in the y direction

solve_problem(self, ProblemType)#

Solve the given ProblemType with the conditions and mixture specified in self

Parameters:
  • self (struct) – Data of the mixture, conditions, and databases

  • ProblemType (char) – Tag of the problem to solve

Returns:

self (struct) – Data of the mixtures (initial and final), conditions, databases

soundspeed_eq(self, mix, P0, T0)#

Compute speed of sound at equilibrium

Parameters:
  • self (struct) – Data of the mixture, conditions, and databases

  • mix (struct) – Struct mix with all the properties of the mixture

  • P0 (float) – Pressure [bar]

  • T0 (float) – Temperature [K]

Returns:

sound (float) – sound speed [m/s]

stoich_prop_matrix(self)#

Initialize the stoichiometric matrix and properties matrix

Parameters:

self (struct) – Data of the mixture, conditions, and databases

Returns:

self (struct) – Data of the mixture, conditions, and databases

vector2cell(value)#

Create cell array from vector

Parameters:

value (any) – Vector with data of any type

Returns:

c (cell) – Cell with the values of the vector

website_CT()#

Open Combustion Toolbox’s website in default web browser

Database functions#

A collection of functions necessary to obtain generate the databases in CT.


Routines
FullName2name(species)#

Get full name of the given species

Parameters:

species (char) – Chemical species

Returns:

name (char) – Full name of the given species

check_DB(self, DB_master, DB, varargin)#

Include not defined species in database from master database (deprecated)

Parameters:
  • self (struct) – Data of the mixture, conditions, and databases

  • DB_master (struct) – Database with the thermodynamic data of the chemical species

  • DB (struct) – Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits

Optional Args:

LS_check (cell): Check only the given list of species

Returns:

Tuple containing

  • DB (struct): Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits

  • E (struct): Elements data

  • S (struct): Slements data

  • C (struct): Constant data

Examples

  • [DB, E, S, C] = check_DB(self, DB_master, DB)

  • [DB, E, S, C] = check_DB(self, DB_master, DB, {‘H2O’, ‘CO2’})

compute_change_moles_gas_reaction(element_matrix, phase)#

In order to compute the internal energy of formation from the enthalpy of formation of a given species, we must determine the change in moles of gases during the formation reaction of a mole of that species starting from the elements in their reference state.

Notes

The only elements that are stable as diatomic gases are elements 1 (H), 8 (N), 9 (O), 10 (F), and 18 (Cl). The remaining elements that are stable as (monoatomic) gases are the noble gases He (3), Ne (11), Ar (19), Kr (37), Xe (55), and Rn (87), which do not form any compound.

Parameters:
  • element_matrix (float) – Element matrix of the species

  • phase (float) – 0 or 1 indicating gas or condensed species

Returns:

Delta_n (float) – Change in moles of gases during the formation reaction of a mole of that species starting from the elements in their reference state

Example

Delta_n = compute_change_moles_gas_reaction(element_matrix, phase)

compute_interval_NASA(species, T, DB, tRange, ctTInt)#

Compute interval NASA polynomials

Parameters:
  • species (char) – Chemical species

  • T (float) – Temperature [K]

  • DB (struct) – Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits

  • tRange (cell) – Ranges of temperatures [K]

  • ctTInt (float) – Number of intervals of temperatures

Returns:

tInterval (float) – Index of the interval of temperatures

detect_location_of_phase_specifier(species)#

Detect the location of the opening pharenthesis of the phase identifier (if any)

Parameters:

species (char) – Chemical species

Returns:

n_open_parenthesis (float) – Index of the location of the open parenthesis

Example

index_open_parenthesis = detect_location_of_phase_specifier(‘C8H18(L),isooct’)

find_products(self, species, varargin)#

Find all the combinations of species from DB that can appear as products for the given list of reactants

Parameters:
  • self (struct) – Data of the mixture, conditions, and databases

  • species (cell) – List of reactants

Optional Name-Value Pairs Args:
  • ind_elements_DB (float): Matrix NS_DB x MAX_ELEMENTS with element indeces of the species contained in the database

  • FLAG_BURCAT (bool): Flag indicating to look for species also in Burcat’s database

  • FLAG_ION (bool): Flag indicating to include ionized species

  • FLAG_CONDENSED (bool): Flag indicating to include condensed species

Returns:

Tuple containing

  • LS (cell): List of products

  • ind_elements_DB (float): Matrix NS_DB x MAX_ELEMENTS with element indeces of the species contained in the database

Examples

  • [LS, ind_elements_DB] = find_products(self, {‘O2’, ‘N’, ‘eminus’})

  • [LS, ind_elements_DB] = find_products(self, {‘O2’, ‘CO’, ‘N’}, ‘flag_burcat’, true)

  • [LS, ind_elements_DB] = find_products(self, {‘O2’, ‘CO’, ‘N’}, ‘flag_burcat’, true, ‘flag_ion’, true)

  • [LS, ind_elements_DB] = find_products(self, {‘O2’, ‘CO’, ‘N’}, ‘flag_burcat’, true, ‘flag_ion’, true, ‘flag_condensed’, true, ‘ind’, ind_elements_DB)

  • [LS, ind_elements_DB] = find_products(self, {‘O2’, ‘CO’, ‘N’}, ‘flag_burcat’, true, ‘flag_ion’, true, ‘ind’, ind_elements_DB)

find_species_LS(LS, cond_with, type_with, cond_without, type_without)#

Find species in the given list that contain all/any elements of cond_with and that not include all/any elements of cond_without

Parameters:
  • LS (cell) – List of species

  • cond_with (cell) – List of elements to include

  • type_with (char) – Satisfy all or any of the elements in cond_with

  • cond_without (cell) – List of elements to avoid

  • type_without (char) – Satisfy all or any of the elements in cond_without

Returns:

LS (cell) – List of species

Examples

  • LS = find_species_LS(LS, {‘C’,’N’,’O’,’minus’,’plus’,’Ar’}, ‘any’,…
    {‘I’, ‘S’, ‘L’, ‘T’, ‘P’, ‘F’, ‘ab’, ‘W’,…

    ‘Z’,’X’,’R’,’Os’,’Cr’,’H’,’Br’,’G’,’K’,… ‘U’,’Co’,’Cu’,’B’,’V’,’Ni’,’Na’,’Mg’,… ‘Mo’,’Ag’,’Nb’,’Cb’,’Cl’,’D’,’T’,… ‘Ca’,’Cs’,’Ne’,’Cd’,’Mn’}, ‘all’)

  • LS = find_species_LS(self.S.LS_DB, {}, ‘any’, {‘_M’}, ‘all’)

generate_DB(DB_master, varargin)#

Generate Database (DB) with thermochemical interpolation curves for the species contained in DB_master

Parameters:

DB_master (struct) – Database with the thermodynamic data of the chemical species

Optional Args:

LS (cell): List of species to be included in DB

Returns:

DB (struct) – Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits

Examples

  • DB = generate_DB(DB_master)

  • DB = generate_DB(DB_master, {‘CO2’, ‘H2O’, ‘O2’, ‘N2’})

generate_DB_Theo()#

Generate database for theoretical computation of the jump conditions of a diatomic species only considering dissociation.

Returns:

DB_Theo (struct) – Database with quantum data of several diatomic species

generate_DB_master(varargin)#

Generate Mater Database (DB_master) with the thermodynamic data of the chemical species

Optional Args:

FLAG_REDUCED_DB (bool): Flag indicating reduced database (default: false) thermoFile (char): File name of NASA’s thermodynamic database (default: thermo_CT.inp)

Returns:

DB_master (struct) – Database with the thermodynamic data of the chemical species

Examples

  • DB_master = generate_DB_master(false)

  • DB_master = generate_DB_master(false, ‘thermo_CT.inp’)

generate_DB_master_reduced(DB_master)#

Generate Reduced Mater Database (DB_master_reduced) with the thermodynamic data of the chemical species (deprecated)

Parameters:

DB_master (struct) – Database with the thermodynamic data of the chemical species

Returns:

DB_master_reduced (struct) – Reduced database with the thermodynamic data of the chemical species

get_ind_elements(LS, DB, elements, MAX_ELEMENTS)#

Get element indeces of each species contained in LS

Parameters:
  • LS (cell) – List of species

  • DB (struct) – Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits

  • elements (cell) – Elements in the periodic table

  • MAX_ELEMENTS (float) – Maximum number of elements contained in one species

Returns:

ind_elements (float) – Matrix numel(LS) x MAX_ELEMENTS with element indeces of the species contained in LS

Example

ind_elements = get_ind_elements(LS, DB, elements, MAX_ELEMENTS)

get_interval(species, T, DB)#

Get interval of the NASA’s polynomials from the Database (DB) for the given species and temperature [K].

Parameters:
  • species (char) – Chemical species

  • T (float) – Temperature [K]

  • DB (struct) – Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits

Returns:

tInterval (float) – Index of the interval of temperatures

get_reference_elements_with_T_intervals()#

Get list with reference form of elements and its temperature intervals

Returns:

list (cell) – List with reference form of elements and its temperature intervals

get_speciesProperties(DB, species, T, MassOrMolar, echo)#

Calculates the thermodynamic properties of any species included in the NASA database

Parameters:
  • DB (struct) – Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits

  • species (char) – Chemical species

  • T (float) – Temperature [K]

  • MassOrMolar (char) – Label indicating mass [kg] or molar [mol] units

  • echo (float) – 0 or 1 indicating species not found

Returns:

Tuple containing

  • txFormula (str): Chemical formula

  • mm (float): Molar weight [g/mol]

  • cP0 (float): Specific heat at constant pressure [J/(mol-k)]

  • hf0 (float): Enthalpy of formation [J/mol]

  • h0 (float): Enthalpy [J/mol]

  • ef0 (float): Internal energy of formation [J/mol]

  • s0 (float): Entropy [J/(mol-k)]

  • Dg0 (float): Gibbs energy [J/mol]

isRefElm(reference_elements, species, T)#

Check if the given species is a reference element

Parameters:
  • reference_elements (cell) – List of reference elements with temperature intervals [K]

  • species (char) – Chemical species

  • T (float) – Temperature

Returns:

name (char) – Full name of the given species

Example

[FLAG_RE, REname] = isRefElm(reference_elements, ‘O’, 1000)

name_with_parenthesis(species)#

Update the name of the given char with parenthesis. The character b if comes in pair represents parenthesis in the NASA’s database

Parameters:

species (char) – Chemical species in NASA’s Database format

Returns:

species_with (char) – Chemical species with parenthesis

Example

species_with = name_with_parenthesis(‘Cbgrb’)

set_DhT(LS, T, DB)#

Function that computes the vector of thermal enthalpy for the given set of species [J/mol]

Parameters:
  • LS (cell) – List of species

  • T (float) – Temperature [K]

  • DB (struct) – Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits

Returns:

DhT (float) – Thermal enthalpy in molar basis [J/mol]

Example

DhT = set_DhT({‘H2O’, ‘CO2’}, 298.15, DB)

set_cP(LS, T, DB)#

Function that computes the vector of specific heats at constant pressure for the given set of species [J/(mol-K)]

Parameters:
  • LS (cell) – List of species

  • T (float) – Temperature [K]

  • DB (struct) – Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits

Returns:

cP (float) – Specific heat at constant pressure in molar basis [J/(mol-K)]

Example

cP = set_cP({‘H2O’, ‘CO2’}, 298.15, DB)

set_e0(LS, T, DB)#

Function that computes the vector of internal energy for the given set of species [J/mol]

Parameters:
  • LS (cell) – List of species

  • T (float) – Temperature [K]

  • DB (struct) – Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits

Returns:

e0 (float) – Internal energy in molar basis [J/mol]

Example

e0 = set_e0({‘H2O’, ‘CO2’}, 298.15, DB)

set_element_matrix(txFormula, elements)#

Compute element matrix of the given species

Parameters:

txFormula (str) – Chemical formula

Returns:

element_matrix(float) – Element matrix

Example

For CO2

element_matrix = [7, 9; 1, 2]

That is, the species contains 1 atom of element 7 (C) and 2 atoms of element 9 (O)

set_g0(LS, T, DB)#

Function that computes the vector of gibbs free energy for the given set of species [J/mol]

Parameters:
  • LS (cell) – List of species

  • T (float) – Temperature [K]

  • DB (struct) – Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits

Returns:

g0 (float) – Gibbs energy in molar basis [J/mol]

Example

g0 = set_g0({‘H2O’, ‘CO2’}, 298.15, DB)

set_h0(LS, T, DB)#

Function that computes the vector of enthalpies for the given set of species [J/mol]

Parameters:
  • LS (cell) – List of species

  • T (float) – Temperature [K]

  • DB (struct) – Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits

Returns:

h0 (float) – Enthalpy in molar basis [J/mol]

Example

h0 = set_h0({‘H2O’, ‘CO2’}, 298.15, DB)

set_prop_DB(LS, property, DB)#

Function that gets the vector of the defined property for the given set of species

Parameters:
  • LS (cell) – List of species

  • property (str) – Property to obtain from the database

  • DB (struct) – Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits

Returns:

value (float) – Property vector

Example

value = set_prop_DB({‘H2O’, ‘CO2’}, ‘hf’, DB)

set_reference_form_of_elements#

Get list with reference form of elements

Returns:

Reference_form_of_elements (cell) – List with reference form of elements

set_reference_form_of_elements_with_T_intervals#

Get list with reference form of elements and its temperature intervals

Returns:

Reference_form_of_elements_with_T_intervals (cell) – List with reference form of elements and its temperature intervals

set_s0(LS, T, DB)#

Function that computes the vector of entropy for the given set of species [J/(mol-K)]

Parameters:
  • LS (cell) – List of species

  • T (float) – Temperature [K]

  • DB (struct) – Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits

Returns:

s0 (float) – Entropy in molar basis [J/(mol-K)]

Example

s0 = set_s0({‘H2O’, ‘CO2’}, 298.15, DB)

species_DeT(species, T, DB)#

Compute thermal internal energy [kJ/mol] of the species at the given temperature [K] using piecewise cubic Hermite interpolating polynomials and linear extrapolation

Parameters:
  • species (char) – Chemical species

  • T (float) – Temperature [K]

  • DB (struct) – Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits

Returns:

DeT (float) – Thermal internal energy in molar basis [kJ/mol]

Example

DeT = species_DeT(‘H2O’, 300, DB)

species_DeT_NASA(species, temperature, DB)#

Compute thermal internal energy [kJ/mol] of the species at the given temperature [K] using NASA’s 9 polynomials

Parameters:
  • species (char) – Chemical species

  • temperature (float) – Range of temperatures to evaluate [K]

  • DB (struct) – Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits

Returns:

DeT (float) – Thermal internal energy in molar basis [kJ/mol]

Example

DeT = species_DeT_NASA(‘H2O’, 300:100:6000, DB)

species_DhT(species, T, DB)#

Compute thermal enthalpy [kJ/mol] of the species at the given temperature [K] using piecewise cubic Hermite interpolating polynomials and linear extrapolation

Parameters:
  • species (char) – Chemical species

  • T (float) – Temperature [K]

  • DB (struct) – Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits

Returns:

DhT (float) – Thermal enthalpy in molar basis [kJ/mol]

Example

DhT = species_DhT(‘H2O’, 300, DB)

species_DhT_NASA(species, temperature, DB)#

Compute thermal enthalpy [kJ/mol] of the species at the given temperature [K] using NASA’s 9 polynomials

Parameters:
  • species (char) – Chemical species

  • temperature (float) – Range of temperatures to evaluate [K]

  • DB (struct) – Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits

Returns:

DhT (float) – Thermal enthalpy in molar basis [kJ/mol]

Example

DhT = species_DhT_NASA(‘H2O’, 300:100:6000, DB)

species_cP(species, T, DB)#

Compute specific heat at constant pressure [J/(mol-K)] of the species at the given temperature [K] using piecewise cubic Hermite interpolating polynomials and linear extrapolation

Parameters:
  • species (char) – Chemical species

  • T (float) – Temperature [K]

  • DB (struct) – Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits

Returns:

cP (float) – Specific heat at constant pressure in molar basis [J/(mol-K)]

Example

cP = species_cP(‘H2O’, 300, DB)

species_cP_NASA(species, temperature, DB)#

Compute specific heats at constant pressure and at constant volume [J/(mol-K)] of the species at the given temperature [K] using NASA’s 9 polynomials

Parameters:
  • species (char) – Chemical species

  • temperature (float) – Range of temperatures to evaluate [K]

  • DB (struct) – Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits

Returns:

Tuple containing

  • cP (float): Specific heat at constant pressure in molar basis [J/(mol-K)]

  • cV (float): Specific heat at constant volume in molar basis [J/(mol-K)]

Example

[cP, cV] = species_cP_NASA(‘H2O’, 300:100:6000, DB)

species_cV(species, T, DB)#

Compute specific heat at constant volume [J/(mol-K)] of the species at the given temperature [K] using piecewise cubic Hermite interpolating polynomials and linear extrapolation

Parameters:
  • species (char) – Chemical species

  • T (float) – Temperature [K]

  • DB (struct) – Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits

Returns:

cV (float) – Specific heat at constant volume in molar basis [J/(mol-K)]

Example

cV = species_cV(‘H2O’, 300, DB)

species_cV_NASA(species, temperature, DB)#

Compute specific heat at constant volume [J/(mol-K)] of the species at the given temperature [K] using NASA’s 9 polynomials

Parameters:
  • species (char) – Chemical species

  • temperature (float) – Range of temperatures to evaluate [K]

  • DB (struct) – Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits

Returns:

cV (float) – Specific heat at constant volume in molar basis [J/(mol-K)]

Example

cV = species_cV_NASA(‘H2O’, 300:100:6000, DB)

species_e0(species, T, DB)#

Compute internal energy [kJ/mol] of the species at the given temperature [K] using piecewise cubic Hermite interpolating polynomials and linear extrapolation

Parameters:
  • species (char) – Chemical species

  • T (float) – Temperature [K]

  • DB (struct) – Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits

Returns:

e0 (float) – Internal energy in molar basis [kJ/mol]

Example

e0 = species_e0(‘H2O’, 300, DB)

species_e0_NASA(species, temperature, DB)#

Compute internal energy and the thermal internal energy [kJ/mol] of the species at the given temperature [K] using NASA’s 9 polynomials

Parameters:
  • species (char) – Chemical species

  • temperature (float) – Range of temperatures to evaluate [K]

  • DB (struct) – Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits

Returns:

Tuple containing

  • e0 (float): Internal energy in molar basis [kJ/mol]

  • DeT (float): Thermal internal energy in molar basis [kJ/mol]

Example

[e0, DeT] = species_e0_NASA(‘H2O’, 300:100:6000, DB)

species_g0(species, T, DB)#

Compute Gibbs energy [kJ/mol] of the species at the given temperature [K] using piecewise cubic Hermite interpolating polynomials and linear extrapolation

Parameters:
  • species (char) – Chemical species

  • T (float) – Temperature [K]

  • DB (struct) – Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits

Returns:

g0 (float) – Gibbs energy in molar basis [kJ/mol]

Example

g0 = species_g0(‘H2O’, 298.15, DB)

species_g0_NASA(species, temperature, DB)#

Compute Compute Gibbs energy [kJ/mol] of the species at the given temperature [K] using NASA’s 9 polynomials

Parameters:
  • species (char) – Chemical species

  • temperature (float) – Range of temperatures to evaluate [K]

  • DB (struct) – Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits

Returns:

g0 (float) – Gibbs energy in molar basis [kJ/mol]

Example

g0 = species_g0_NASA(‘H2O’, 300:100:6000, DB)

species_gamma(species, T, DB)#

Compute adiabatic index of the species [-] at the given temperature [K] using piecewise cubic Hermite interpolating polynomials and linear extrapolation

Parameters:
  • species (char) – Chemical species

  • T (float) – Temperature [K]

  • DB (struct) – Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits

Returns:

gamma (float) – Adiabatic index [-]

Example

gamma = species_gamma(‘H2O’, 300, DB)

species_gamma_NASA(species, T, DB)#

Compute adiabatic index of the species [-] at the given temperature [K] using piecewise cubic Hermite interpolating polynomials and linear extrapolation

Parameters:
  • species (char) – Chemical species

  • T (float) – Range of temperatures to evaluate [K]

  • DB (struct) – Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits

Returns:

gamma (float) – Adiabatic index [-]

Example

gamma = species_gamma_NASA(‘H2O’, 300:100:6000, DB)

species_h0(species, T, DB)#

Compute enthalpy [kJ/mol] of the species at the given temperature [K] using piecewise cubic Hermite interpolating polynomials and linear extrapolation

Parameters:
  • species (char) – Chemical species

  • T (float) – Temperature [K]

  • DB (struct) – Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits

Returns:

h0 (float) – Enthalpy in molar basis [kJ/mol]

Example

h0 = species_h0(‘H2O’, 300, DB)

species_h0_NASA(species, temperature, DB)#

Compute enthalpy and thermal enthalpy [kJ/mol] of the species at the given temperature [K] using NASA’s 9 polynomials

Parameters:
  • species (char) – Chemical species

  • temperature (float) – Range of temperatures to evaluate [K]

  • DB (struct) – Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits

Returns:

Tuple containing

  • h0 (float): Enthalpy in molar basis [kJ/mol]

  • DhT (float): Thermal enthalpy in molar basis [kJ/mol]

Example

[h0, DhT] = species_h0_NASA(‘H2O’, 300:100:6000, DB)

species_s0(species, T, DB)#

Compute entropy [kJ/(mol-K)] of the species at the given temperature [K] using piecewise cubic Hermite interpolating polynomials and linear extrapolation

Parameters:
  • species (char) – Chemical species

  • T (float) – Temperature [K]

  • DB (struct) – Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits

Returns:

s0 (float) – Entropy in molar basis [kJ/(mol-K)]

Example

s0 = species_s0(‘H2O’, 300, DB)

species_s0_NASA(species, temperature, DB)#

Compute entropy [kJ/(mol-K)] of the species at the given temperature [K] using NASA’s 9 polynomials

Parameters:
  • species (char) – Chemical species

  • temperature (float) – Range of temperatures to evaluate [K]

  • DB (struct) – Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits

Returns:

s0 (float) – Entropy in molar basis [kJ/(mol-K)]

Example

s0 = species_s0_NASA(‘H2O’, 300:100:6000, DB)

species_thermo_NASA(species, temperature, DB)#

Compute thermodynamic function using NASA’s 9 polynomials

Parameters:
  • species (char) – Chemical species

  • temperature (float) – Range of temperatures to evaluate [K]

  • DB (struct) – Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits

Returns:

Tuple containing

  • cP (float): Specific heat at constant pressure in molar basis [J/(mol-K)]

  • cV (float): Specific heat at constant volume in molar basis [J/(mol-K)]

  • h0 (float): Enthalpy in molar basis [kJ/mol]

  • DhT (float): Thermal enthalpy in molar basis [kJ/mol]

  • e0 (float): Internal energy in molar basis [kJ/mol]

  • DeT (float): Thermal internal energy in molar basis [kJ/mol]

  • s0 (float): Entropy in molar basis [J/(mol-K)]

  • g0 (float): Gibbs energy in molar basis [kJ/mol]

Example

[cP, cV, h0, DhT, e0, DeT, s0, g0] = species_thermo_NASA(‘H2O’, 300:100:6000, DB)

thermo_millennium_2_thermoNASA9(filename)#

Read Extended Third Millennium Thermodynamic Database of New NASA Polynomials with Active Thermochemical Tables update and write a new file compatible with thermo NASA 9 format

Parameters:

filename (char) – Filename of the thermo_millennium data

unpack_NASA_coefficients(species, DB)#

Unpack NASA’s polynomials coefficients from database

Parameters:
  • species (char) – Chemical species

  • DB (struct) – Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits

Returns:

Tuple containing

  • a (cell): Temperature coefficients

  • b (cell): Integration constants

  • tRange (cell): Ranges of temperatures [K]

  • tExponents (cell): Exponent coefficients

  • ctTInt (float): Number of intervals of temperatures

  • txFormula (char): Chemical formula

  • phase (float): 0 or 1 indicating gas or condensed phase, respectively

Example

[a, b, tRange, tExponents, ctTInt, txFormula, phase] = unpack_NASA_coefficients(‘H2O’, DB)

Display functions#

A collection of functions necessary to display the results (command window and plots).


Routines
displaysweepresults(self, mix, xvar, varargin)#

Plot a given variable against the molar fractions of the mixture

Parameters:
  • self (struct) – Data of the mixture, conditions, and databases

  • mix (struct) – Properties of the mixture

  • xvar (float) – Vector with the x data

Optional Args:
  • config (struct): Struct with the configuration for plots

  • xscale (string): Scale fot the x-axis (linear or log)

  • yscale (string): Scale fot the y-axis (linear or log)

  • xdir (string): Direction of the x-axis (normal or reverse)

  • ydir (string): Direction of the x-axis (normal or reverse)

Returns:

ax (axes) – Axes object

get_mixtures(PS, pattern)#

Get all non-empty mixture

Parameters:
  • PS (struct) – Struct with all the data of Problem Solution (PS)

  • pattern (str) – Pattern/s name of the mixture

Returns:

mixtures (cell) – Cell with all the non-empty mixtures

Examples

  • mixtures = get_mixtures(self.PS, ‘mix’);

  • mixtures = get_mixtures(self.PS, ‘strP’);

interpreter_label(property, varargin)#

Interpreter label for properties - returns property name

Note

The ‘interpreter_label.m’ routine considers that the properties are in mass basis. This will be fixed in a future patch.

Parameters:

property (char) – Property name

Optional Args:

type (char): Type of label to return. Can be ‘short’, ‘medium’ or ‘long’ (default: medium)

Returns:

value (char) – Corresponding name of the property

plot_figure(x_field, x_var, y_field, y_var, varargin)#

Plot figure with customizable settings

Note

The ‘interpreter_label.m’ routine considers that the properties are in mass basis. This will be fixed in a future patch.

Parameters:
  • x_field (char) – Field name for the x-axis data

  • x_var (cell) – Cell array containing the x-axis data

  • y_field (char) – Field name for the y-axis data

  • y_var (cell) – Cell array containing the y-axis data

Optional Name-Value Pair Args:
  • config (struct): Struct with the configuration for plots

  • leg or legend (cell): Cell array of strings containing the legend names

  • legend_location (char): Location of the legend

  • ax or axes (object): Handle of the axes to plot on

  • linestyle (char): Line style

  • linewidth (float): Line width

  • fontsize (float): Font size

  • title (char): Title of the figure

  • labelx, xlabel, label_x, or x_label (char): x-axis label

  • labely, ylabel, label_y, or ‘y_label (char): y-axis label

  • label_type (char): Label type

  • xscale (char): Set x-axis scale (linear or log)

  • yscale (char): Set y-axis scale (linear or log)

  • xdir (char): Set x-axis direction (normal or reverse)

  • ydir (char): Set y-axis direction (normal or reverse)

  • color (float): Line color [R, G, B]

Returns:

Tuple containing

  • ax (object): Handle of the axes

  • dline (object): Handle of the plotted line

plot_figure_set(range_name, range, properties, mix, varargin)#

Plot a set of properties in a tiled layout figure

Parameters:
  • range_name (char) – Variable name of the x-axis parameter

  • range (float) – Vector x-axis values

  • properties (cell) – Cell array of properties to plot

  • mix (struct) – Mixture

Optional Args:
  • ax (handle): Handle to the main axis

  • config (struct): Configuration settings for the figure

  • basis (cell): Cell array with the basis for each property

Returns:

** main_ax (obj)* – Handle to the main axis

Examples

  • plot_figure_set(‘T’, 300:100:1000, {‘cp’, ‘cv’, ‘h’, ‘s’}, mix)

  • plot_figure_set(‘T’, 300:100:1000, {‘cp’, ‘cv’, ‘h’, ‘s’}, mix, ‘config’, config)

  • plot_figure_set(‘T’, 300:100:1000, {‘cp’, ‘cv’, ‘h’, ‘s’}, mix, ‘config’, config, ‘basis’, {‘’, ‘’, ‘mi’, ‘mi’});

  • plot_figure_set(‘T’, 300:100:1000, {‘cp’, ‘cv’, ‘h’, ‘s’}, mix, ‘config’, config, ‘basis’, {‘’, ‘’, ‘mi’, ‘mi’}, ‘ax’, ax);

plot_hugoniot(self, mix1, mix2, varargin)#

Plot the Hugoniot curve for a a given pre-shock state (mix1) and post-shock state (mix2)

Parameters:
  • self (struct) – Data of the mixture, conditions, and databases

  • mix1 (struct) – Pre-shock mixture

  • mix2 (struct) – Post-shock mixture

Optional Args:

ax (object): Axis handle to plot on

Returns:

ax (object) – Axis handle to plot on

Examples

  • ax = plot_hugoniot(self, mix1, mix2)

  • ax = plot_hugoniot(self, mix1, mix2, ax)

plot_molar_fractions(self, x_var, x_field, y_field, varargin)#

Plot molar fractions againts any variable

Parameters:
  • self (struct) – Data of the mixture, conditions, and databases

  • x_var (cell) – Properties of the mixture for all the cases

  • x_field (char) – Field name for the x-axis data

  • y_field (char) – Field name for the y-axis data

Optional Name-Value Pair Args:
  • validation (struct): Struct that contains validations with (x_field, y_field)

  • nfrec (float): Frequency points to plot validations

  • mintol (float): Minimum limit i-axis with the composition of the mixture

  • display_species (cell): List of species to plot

  • y_var (cell): Get y-axis data from a different mixture

  • config (struct): Struct with the configuration for plots

  • axis_x (char): Set x-axis limits

  • axis_y (char): Set y-axis limits

  • xscale (char): Set x-axis scale (linear or log)

  • yscale (char): Set y-axis scale (linear or log)

  • xdir (char): Set x-axis direction (normal or reverse)

  • ydir (char): Set y-axis direction (normal or reverse)

  • ax (object): Handle of the axes to plot on

Returns:

Tuple containing

  • ax (object): Handle of the axes

  • fig (object): Handle of the figure

Examples

  • [ax, fig] = plot_molar_fractions(self, mix1, ‘phi’, ‘Xi’)

  • [ax, fig] = plot_molar_fractions(self, mix1, ‘phi’, ‘Xi’, ‘y_var’, mix2)

  • [ax, fig] = plot_molar_fractions(self, mix1, ‘phi’, ‘Xi’, ‘y_var’, mix2, ‘validation’, results_CEA)

  • [ax, fig] = plot_molar_fractions(self, mix1, ‘phi’, ‘Xi’, ‘y_var’, mix2, ‘validation’, results_CEA, ‘display_species’, display_species)

plot_shock_polar(varargin)#

Routine to obtain shock polar plots

  • Plot (pressure, deflection)

  • Plot (wave angle, deflection)

  • Plot velocity components

polynomial_regression(x, y, n)#

Obtain polynomial regression for the given dataset (x, y) and polynomial order

Parameters:
  • x (float) – x values

  • y (float) – y values

  • n (float) – polynomial order

Returns:

y_poly (float) – y values of the polynomial regression

print_mixture(self, varargin)#

Print properties and composition of the given mixtures in the command window

Parameters:

self (struct) – Data of the mixture, conditions, and databases

Optional Args:
  • mix1 (struct): Struct with the properties of the mixture

  • mix2 (struct): Struct with the properties of the mixture

  • mixi (struct): Struct with the properties of the mixture

  • mixN (struct): Struct with the properties of the mixture

Examples

  • print_mixture(self, mix1)

  • print_mixture(self, mix1, mix2)

  • print_mixture(self, mix1, mix2, mix3)

  • print_mixture(self, mix1, mix2, mix3, mix4)

print_stoichiometric_matrix(self, varargin)#

Print stoichiometric matrix

Parameters:

self (struct) – Data of the mixture, conditions, and databases

Optional args:

type (char): ‘transpose’

Optional returns:
A0 (table): Stoichiometric matrix. In case type == ‘transpose’

it returns the transpose of stoichiometric matrix

results(self, i)#

Display results in the command window

Parameters:
  • self (struct) – Data of the mixture, conditions, and databases

  • i (float) – index of the current iteration

set_figure(varargin)#

Initialize figure with a standard composition

Optional Args:
  • ax (axis): Figure axis

  • config (struct): Struct with default plot parameters

Returns:

Tuple containing

  • ax (axis): Axis of the standard figure

  • config (struct): Struct with default plot parameters

  • fig (figure): Standard figure

set_legends(ax, legend_name, varargin)#

Set legend to the given axes

Parameters:
  • ax (object) – Handle to the axes

  • legend_name (cell) – Cell array of char containing the legend names

Optional Name-Value Pairs Args:
  • config (struct): Struct containing the configuration parameters for the plots

  • obj (object): Handle to the plotted objects (e.g. lines, patches, etc.)

set_title(ax, varargin)#

Set legend to the given axes

species2latex(species, varargin)#

Convert species name into LateX format

Parameters:

species (char) – Species name

Optional Args:

FLAG_BURCAT (bool): If true, do not remove Burcat database prefix (default: true)

Returns:

speciesLatex (char) – Species name in LateX format

Examples

  • species2latex(‘H2ObLb’)

  • species2latex(‘Si2H6_M’)

  • species2latex(‘Si2H6_M’, false)

Equation of State functions#

A collection of Equation of States (EoS) implemented in CT.


Routines
eos_PengRobinson(self, T, p, species, Xi)#

Compute molar volume of the mixture considering Peng-Robinson Equation of State (EoS)

Parameters:
  • self (struct) – Data of the mixture, conditions, and databases

  • species (cell) – List of the species in the mixture

  • Xi (float) – Molar fractions of the mixture

  • T (float) – Temperature [K]

  • p (float) – Pressure [bar]

Returns:

Tuple containing

  • V (float): Molar volume of the mixture [m3/mol]

  • Vi (float): Molar volume of the components [m3/mol]

eos_VanderWaals(self, species, Xi, T, p)#

Compute molar volume of the mixture considering Van der Waals Equation of State (EoS)

Parameters:
  • self (struct) – Data of the mixture, conditions, and databases

  • species (cell) – List of the species in the mixture

  • Xi (float) – Molar fractions of the mixture

  • T (float) – Temperature [K]

  • p (float) – Pressure [bar]

Returns:

Tuple containing

  • V (float): Molar volume of the mixture [m3/mol]

  • Vi (float): Molar volume of the components [m3/mol]

eos_ideal(self, T, p, varargin)#

Compute pressure considering ideal Equation of State (EoS)

Parameters:
  • self (struct) – Data of the mixture, conditions, and databases

  • T (float) – Temperature of the mixture [K]

  • p (float) – Pressure of the mixture [Pa]

Returns:

V (float) – Molar volume of the mixture [m3/mol]

eos_ideal_p(self, n, T, v, varargin)#

Compute pressure considering ideal Equation of State (EoS)

Parameters:
  • self (struct) – Data of the mixture, conditions, and databases

  • n (float) – Number of moles of the mixture in gaseous phase [mol]

  • T (float) – Temperature of the mixture [K]

  • v (float) – Volume of the mixture [m3]

Returns:

p (float) – Pressure of the mixture [Pa]

mu_ex_eos(self, Xi, T, p, V, a_mix, b_mix, a, b)#

Compute non ideal contribution (excess) of the chemical potential assuming cubic Equation of State (EoS) [J/mol]

Parameters:
  • self (struct) – Data of the mixture, conditions, and databases

  • T (float) – Temperature of the mixture [K]

  • p (float) – Pressure of the mixture [bar]

  • V (float) – Molar volume of the mixture [m3/mol]

  • a_mix (float) – Atraction factor mixture of the cubic EoS

  • b_mix (float) – Repulsion factor mixture of the cubic EoS

  • a (float) – Atraction factor components of the cubic EoS

  • b (float) – Repulsion factor components of the cubic EoS

Returns:

chemical_potential_ex (float) – Chemical potential excess [J/mol]

mu_ex_ideal(self, moles, temperature, volume)#

Compute non ideal contribution (excess) of the chemical potential assuming ideal Equation of State [J/mol]

Parameters:
  • self (struct) – Data of the mixture, conditions, and databases

  • moles (float) – Number of moles of the mixture in gaseous phase [mol]

  • temperature (float) – Temperature of the mixture [K]

  • volume (float) – Volume of the mixture [m3]

Returns:

pressure (float) – Pressure of the mixture [Pa]

mu_ex_vanderwaals(self, moles, temperature, volume)#

Compute non ideal contribution (excess) of the chemical potential assuming Van der Waal’s Equation of State [J/mol]

Parameters:
  • self (struct) – Data of the mixture, conditions, and databases

  • moles (float) – Number of moles of the mixture in gaseous phase [mol]

  • temperature (float) – Temperature of the mixture [K]

  • volume (float) – Volume of the mixture [m3]

Returns:

pressure (float) – Pressure of the mixture [Pa]

mu_ex_virial(self, moles, temperature, volume)#

Compute non ideal contribution (excess) of the chemical potential assuming Virial Equation of State [J/mol]

Parameters:
  • self (struct) – Data of the mixture, conditions, and databases

  • moles (float) – Number of moles of the mixture in gaseous phase [mol]

  • temperature (float) – Temperature of the mixture [K]

  • volume (float) – Volume of the mixture [m3]

Returns:

pressure (float) – Pressure of the mixture [Pa]

Export functions#

A collection of functions to export results.


Routines
export_results(self)#

Export results of reactants (mix1) and products (mix2) into a .xls file

Parameters:

self (struct) – Data of the mixture, conditions, and databases

get_excel_cell(mix, species, phi)#

Construct a cell with the thermodynamic data of the given mixture

Parameters:
  • mix (struct) – Properties of the mixture

  • species (cell) – List of species

  • phi (float) – Vector of equivalence ratio

Returns:

excell_cell (cell) – Cell with the thermodynamic data of the given mixture

Example

excell_cell(self.PS.strR, self.S.LS, self.PD.phi.value)

protected_function#

Extensions functions#

A collection of external functions from other repositories.

  • Combustion Toolbox’s color palette is obtained from the following repository: Stephen (2021). ColorBrewer: Attractive and Distinctive Colormaps (https://github.com/DrosteEffect/BrewerMap), GitHub. Retrieved December 3, 2021.

  • For validations, Combustion Toolbox uses CPU Info from the following repository: Ben Tordoff (2022). CPU Info (https://github.com/BJTor/CPUInfo/releases/tag/v1.3), GitHub. Retrieved March 22, 2022.

  • Combustion Toolbox’s splash screen is based on a routine from the following repository: Ben Tordoff (2022). SplashScreen (https://www.mathworks.com/matlabcentral/fileexchange/30508-splashscreen), MATLAB Central File Exchange. Retrieved October 15, 2022.

Root finding algorithms#

Roots algorithm used to obtain the temperature at equilibrium for a given thermochemical transformation. The methods implemented are:

  • Newton-Raphson method.

  • Steffensen-Aitken method.


Routines
newton_2(f, fprime, x0)#

Find the temperature [K] (root) for the set chemical transformation at equilibrium using the Newton-Raphson method

Parameters:
  • self (struct) – Data of the mixture, conditions, and databases

  • mix1 (struct) – Properties of the initial mixture

  • pP (float) – Pressure [bar]

  • field (str) – Fieldname in Problem Description (PD)

  • x0 (float) – Guess temperature [K]

  • guess_moles (float) – Guess moles final mixture

Returns:

Tuple containing

  • x (float): Temperature at equilibrium [K]

  • STOP (float): Relative error [-]

  • guess_moles (struct): Guess moles final mixture

print_error_root(it, itMax, T, STOP)#

Print error of the method if the number of iterations is greater than maximum iterations allowed

Parameters:
  • it (float) – Number of iterations executed in the method

  • itMax (float) – Maximum nNumber of iterations allowed in the method

  • T (float) – Temperature [K]

  • STOP (float) – Relative error [-]

regula_guess(self, mix1, pP, field)#

Find a estimate of the temperature for the set chemical equilibrium transformation using the regula falsi method

Parameters:
  • self (struct) – Data of the mixture, conditions, and databases

  • mix1 (struct) – Properties of the initial mixture

  • pP (float) – Pressure [bar]

  • field (str) – Fieldname in Problem Description (PD)

Returns:

x0 (float) – Guess temperature [K]

newton(self, mix1, pP, field, x0, guess_moles)#

Find the temperature [K] (root) for the set chemical transformation at equilibrium using the second-order Newton-Raphson method

Parameters:
  • self (struct) – Data of the mixture, conditions, and databases

  • mix1 (struct) – Properties of the initial mixture

  • pP (float) – Pressure [bar]

  • field (str) – Fieldname in Problem Description (PD)

  • x0 (float) – Guess temperature [K]

  • guess_moles (float) – Guess moles final mixture

Returns:

Tuple containing

  • x (float): Temperature at equilibrium [K]

  • STOP (float): Relative error [-]

  • guess_moles (struct): Guess moles final mixture

get_gpoint(self, mix1, pP, field, x0, guess_moles)#

Get fixed point of a function based on the chemical transformation

Parameters:
  • self (struct) – Data of the mixture, conditions, and databases

  • mix1 (struct) – Properties of the initial mixture

  • pP (float) – Pressure [bar]

  • field (str) – Fieldname in Problem Description (PD)

  • x0 (float) – Guess temperature [K]

Returns:

Tuple containing

  • gpoint (float): Fixed point of the function [kJ] (HP, EV) or [kJ/K] (SP, SV)

  • gpoint_relative (float): Fixed relative point of the function [kJ] (HP, EV) or [kJ/K] (SP, SV)

get_point(x_vector, f_vector)#

Get point using the regula falsi method

Parameters:
  • x_vector (float) – Guess temperature [K]

  • f_vector (struct) – evaluated functions [kJ] (HP, EV) or [kJ/K] (SP, SV)

Returns:

point (float) – Point of the function [K]

get_point_aitken(x0, g_vector)#

Get fixed point of a function based on the chemical transformation using the Aitken acceleration method

Parameters:
  • x0 (float) – Guess temperature [K]

  • g_vector (struct) – Fixed points of the function [kJ] (HP, EV) or [kJ/K] (SP, SV)

Returns:

point (float) – Point of the function [K]

steff(self, mix1, pP, field, x0, guess_moles)#

Find the temperature [K] (root) for the set chemical transformation at equilibrium using the Steffenson-Aitken method

Parameters:
  • self (struct) – Data of the mixture, conditions, and databases

  • mix1 (struct) – Properties of the initial mixture

  • pP (float) – Pressure [bar]

  • field (str) – Fieldname in Problem Description (PD)

  • x0 (float) – Guess temperature [K]

  • guess_moles (float) – Guess moles final mixture

Returns:

Tuple containing

  • x (float): Temperature at equilibrium [K]

  • STOP (float): Relative error [-]

  • guess_moles (float): Guess moles final mixture

Thermodynamic properties#

Functions to obtain thermodynamic properties from a given mixture.


Routines
MolecularWeight(mix)#

Get the molecular weight [g/mol] of the mixture

Parameters:

mix (struct) – Properties of the mixture

Returns:

value (float) – Molecular weight [g/mol] of the mixture

adiabaticIndex(mix)#

Get the adiabatic index [-] of the mixture from the ratio of the specific heat capacities

Parameters:

mix (struct) – Properties of the mixture

Returns:

value (float) – Adiabatic index of the mixture [-]

adiabaticIndex_sound(mix)#

Get the adiabatic index [-] of the mixture from definition of sound velocity

Parameters:

mix (struct) – Properties of the mixture

Returns:

value (float) – Adiabatic index [-] of the mixture

compressibility_factor(mix)#

Compute compressibility factor of the mixture [-]

Parameters:

mix (struct) – Properties of the mixture

Returns:

Z (float) – Compressibility factor [-]

compute_heatrelease(mix1, mix2)#

Compute heat release [J/kg] of the chemical transformation of the mixture 1 to mixture 2

Parameters:
  • mix1 (struct) – Properties of the initial mixture

  • mix2 (struct) – Properties of the final mixture

Returns:

q (float) – heat release [J/kg] == [m^2/s^2] Q (float): dimensionless heat release

compute_sound(T, p, species, composition, varargin)#

Routine to compute sound velocity [m/s] for a given temperature-pressure profile

Parameters:
  • T (float) – Temperature [K]

  • p (float) – Pressure [bar]

  • species (cell) – List of species

  • composition (float) – composition of species (mol)

Optional Name-Value Pairs Args:

self (struct): Data of the mixtures, conditions, databases

Returns:

sound (float) – Sound velocity [m/s]

Examples

sound = compute_sound(300, 1, {‘H2’, ‘O2’}, [1, 1]) sound = compute_sound(300, 1, {‘H2’, ‘O2’}, [1, 1], ‘self’, self)

cp_mass(mix)#

Get the mass-basis specific heat at constant pressure [kJ/kg-K] of the mixture

Parameters:

mix (struct) – Properties of the mixture

Returns:

value (float) – Mass-basis specific heat at constant pressure [kJ/kg-K] of the mixture

cp_mole(mix)#

Get the mole-basis specific heat at constant pressure [kJ/mol-K] of the mixture

Parameters:

mix (struct) – Properties of the mixture

Returns:

value (float) – Mole-basis specific heat at constant pressure [kJ/mol-K] of the mixture

cv_mass(mix)#

Get the mass-basis specific heat at constant volume [kJ/kg-K] of the mixture

Parameters:

mix (struct) – Properties of the mixture

Returns:

value (float) – Mass-basis specific heat at constant volume [kJ/kg-K] of the mixture

cv_mole(mix)#

Get the mole-basis specific heat at constant volume [kJ/mol-K] of the mixture

Parameters:

mix (struct) – Properties of the mixture

Returns:

value (float) – Mole-basis specific heat at constant volume [kJ/mol-K] of the mixture

density(mix)#

Get the density [kg/m3] of the mixture

Parameters:

mix (struct) – Properties of the mixture

Returns:

value (float) – density [kg/m3] of the mixture

enthalpy_formation_mass(mix)#

Get the mass specific enthalpy formation [kJ/kg] of the mixture

Parameters:

mix (struct) – Properties of the mixture

Returns:

value (float) – Mass-basis specific enthalpy formation [kJ/kg] of the mixture

enthalpy_formation_mole(mix)#

Get the mole specific enthalpy formation [kJ/mol] of the mixture

Parameters:

mix (struct) – Properties of the mixture

Returns:

value (float) – Mole-basis specific enthalpy formation [kJ/mol] of the mixture

enthalpy_mass(mix)#

Get the mass specific enthalpy [kJ/kg] of the mixture

Parameters:

mix (struct) – Properties of the mixture

Returns:

value (float) – Mass-basis specific enthalpy [kJ/kg] of the mixture

enthalpy_mole(mix)#

Get the mole specific enthalpy [kJ/mol] of the mixture

Parameters:

mix (struct) – Properties of the mixture

Returns:

value (float) – Mole-basis specific enthalpy [kJ/mol] of the mixture

entropy_mass(mix)#

Get the mass specific entropy [kJ/kg-K] of the mixture

Parameters:

mix (struct) – Properties of the mixture

Returns:

value (float) – Mass-basis specific entropy [kJ/kg-K] of the mixture

entropy_mole(mix)#

Get the mole specific entropy [kJ/mol-K] of the mixture

Parameters:

mix (struct) – Properties of the mixture

Returns:

value (float) – Mole-basis specific entropy [kJ/mol-K] of the mixture

equivalenceRatio(mix)#

Get the equivalence ratio of the initial mixture [-]

Parameters:

mix (struct) – Properties of the mixture

Returns:

value (float) – Equivalence ratio of the initial mixture [-]

gibbs_mass(mix)#

Get the mass specific gibbs free energy [kJ/kg] of the mixture

Parameters:

mix (struct) – Properties of the mixture

Returns:

value (float) – Mass-basis specific gibbs free energy [kJ/kg] of the mixture

gibbs_mole(mix)#

Get the mole specific gibbs free energy [kJ/mol] of the mixture

Parameters:

mix (struct) – Properties of the mixture

Returns:

value (float) – Mole-basis specific gibbs free energy [kJ/mol] of the mixture

humidity_specific(T, p, humidity_relative)#

Get the specific humidity of air [kg_w/kg_da] at a given temperature, pressure, and relative humidity

Parameters:
  • T (float) – Temperature [K]

  • p (float) – Pressure [bar]

  • humidity_relative (float) – Relative humidity [%]

Returns:

value (float) – Specific humidity of air [kg_w/kg_da]

intEnergy_mass(mix)#

Get the mass specific internal energy [kJ/kg] of the mixture

Parameters:

mix (struct) – Properties of the mixture

Returns:

value (float) – Mass-basis specific internal energy [kJ/kg] of the mixture

intEnergy_mole(mix)#

Get the mole specific internal energy [kJ/mol] of the mixture

Parameters:

mix (struct) – Properties of the mixture

Returns:

value (float) – Mole-basis specific internal energy [kJ/mol] of the mixture

mass(mix)#

Get the mass [kg] of the mixture

Parameters:

mix (struct) – Properties of the mixture

Returns:

value (float) – mass [kg] of the mixture

massFractions(mix)#

Get the mass fractions of all the species in the mixture [-]

Parameters:

mix (struct) – Properties of the mixture

Returns:

value (float) – Mass fractions of all the species in the mixture [-]

meanMolecularWeight(mix)#

Get the mean molecular weight [g/mol] of the mixture

Parameters:

mix (struct) – Properties of the mixture

Returns:

value (float) – Mean molecular weight [g/mol] of the mixture

moleFractions(mix)#

Get the mole fractions of all the species in the mixture [-]

Parameters:

mix (struct) – Properties of the mixture

Returns:

value (float) – Mole fractions of all the species in the mixture [-]

moles(mix)#

Get the moles [mol] of all the species in the mixture

Parameters:

mix (struct) – Properties of the mixture

Returns:

value (float) – Moles [mol] of all the species in the mixture

molesGas(mix)#

Get the moles of the gases in the mixture [mol]

pressure(mix)#

Get the pressure [bar] in the mixture

Parameters:

mix (struct) – Properties of the mixture

Returns:

value (float) – Pressure [bar] in the mixture

soundspeed(mix)#

Get the speed of sound [m/s] in the mixture

Parameters:

mix (struct) – Properties of the mixture

Returns:

value (float) – Speed of sound [m/s] in the mixture

temperature(mix)#

Get the temperature [K] in the mixture

Parameters:

mix (struct) – Properties of the mixture

Returns:

value (float) – Temperature [K] in the mixture

velocity_relative(mix)#

Get the velocity of the gases relative to the shock front [m/s] in the mixture

Parameters:

mix (struct) – Properties of the mixture

Returns:

value (float) – Velocity of the gases relative to the shock front [m/s] in the mixture

volume(mix)#

Get the volume [m3] of the mixture

Parameters:

mix (struct) – Properties of the mixture

Returns:

value (float) – volume [m3] of the mixture

Validations functions#

A collection of functions to generate the validations automatically.


Routines
compute_error_moles_CEA(results1, results2, varname_x, value, varname_y, species)#

Compute max error of CT against CEA

compute_error_prop_CEA(results1, results2, varsname_x, value, varsname_y, type)#

Compute max error of CT against CEA

debug_plot_error(it, STOP, varargin)#

Debug function that plots the error per iteration along with the value of the correction factor

get_problems_solved(varargin)#

Get problems solved based on the length of the given variable

load_struct(filename, variable_name)#

Load variable from a struct saved in a file

plot_molar_fractions_validation(results1, results2, varname_x, varname_y, species, varargin)#

Default values

plot_properties_validation(results1, results2, varsname_x, varsname_y, type, varargin)#

Plot properties varname_y vs varname_x from CT (results1) against results obtained from other code (results2). The properties to plot are specified by varsname_x and varsname_y, which are cell arrays of strings.

plot_thermo_validation(species, property, DB, varargin)#

Validation custom thermodynamic polynomials with NASA’s 9 polynomials

Parameters:
  • species (cell) – List of species

  • property (str) – Name of the thermodynamic property to check

  • DB (struct) – Database with custom thermodynamic polynomials functions generated from NASAs 9 polynomials fits

Optional Args:
  • nfrec (float): Points frequency for NASA values

  • range (float): Temperature range [K]

Returns:

ax (object) – Axes of the plotted figure

plot_validation_shock_polar_SDToolbox(results_CT, results_SDToolbox, config)#

Plot numerical results obtained with SDToolbox, which use CANTERA as a thermochemical kernel.

  • Pressure ratio with the deflection angle [deg]

  • Wave angle [deg] with the deflection angle [deg]

read_CEA(filename)#

READ DATA FROM CEA AS TXT EXTENSION fid=fopen(‘test_soot_acetylene.txt’,’r’);

run_CT(varargin)#

A generalized function to run Combustion Toolbox for a given set of inputs. Otherwise, it will run the predefined case.

set_inputs_thermo_validations(property)#

Set corresponding thermodynamic functions for NASA and Combustion Toolbox

Parameters:

property (str) – Thermodynamic property name

Returns:

Tuple containing

  • funname_NASA (function): Function to use NASA’s polynomials

  • funname_CT (function): Function to use Combustion Toolbox polynomials

  • y_labelname (str): Label y axis