majordome.common#

Constants#

majordome.common.DATA#

Path to project data folder.

majordome.common.GRAVITY#

Conventional gravitational acceleration on Earth [m/s²].

majordome.common.T_REFERENCE#

Thermodynamic reference temperature [K].

majordome.common.T_NORMAL#

Normal state reference temperature [K].

majordome.common.P_NORMAL#

Normal state reference temperature [K].

Type aliases#

majordome.common.CompositionType#

Input type for Cantera composition dictionaries.

class majordome.common.StateType(X: str | dict[str, float], T: Number = 273.15, P: Number = 101325.0)#

Input type for Cantera TPX state dictionaries.

P: Number#

Alias for field number 2

T: Number#

Alias for field number 1

X: str | dict[str, float]#

Alias for field number 0

Utilities#

class majordome.common.NormalFlowRate(mech: str | Path, *, X: str | dict[str, float] = None, Y: str | dict[str, float] = None, T_ref: float = 273.15, P_ref: float = 101325.0, name: str = None)#

Compute normal flow rate for a given composition.

This class makes use of the user defined state to create a function object that converts industrial scale flow rates in normal cubic meters per hour to kilograms per second. Nothing more, nothing less, it aims at helping the process engineer in daily life for this quite repetitive need when performing mass balances.

Parameters:
mech: str | Path

Path to Cantera mechanism used to compute mixture properties.

X: CompositionType = None

Composition specification in mole fractions. Notice that both X and Y are mutally exclusive keyword arguments.

Y: CompositionType = None

Composition specification in mass fractions. Notice that both X and Y are mutally exclusive keyword arguments.

T_ref: float = T_NORMAL

Reference temperature of the system. If your industry does not use the same standard as the default values, and only in that case, please consider updating this keyword.

P_ref: float = P_NORMAL

Reference pressure of the system. If your industry does not use the same standard as the default values, and only in that case, please consider updating this keyword.

name: str = None

Name of phase in mechanism, if more than one are specified within the same Cantera YAML database file.

property TPX: tuple[float, float, dict[str, float]]#

Provides access to the state of internal solution.

property density: float#

Provides access to the density of internal solution [kg/m³].

report(**kwargs) str#

Provides a report of the mixture state.

class majordome.common.ReadTextData#

Utilities for reading common text data formats.

static read_data(fname, nlines=None)#

Read raw text data file with optional number of lines at end.

static read_nlines(fp, nlines)#

Read at most n lines from text file.

static read_sep(fname, nlines=None, sep='\\s+', **kwargs)#

Read raw text data file as a pandas.DataFrame object.

class majordome.common.StandardPlot(fig, ax)#

Wraps a matplotlib figure and axis.

property axes#

Provides access to undelining figure.

property figure#

Provides access to undelining figure.

resize(w, h)#

Resize a plot with width and height in inches.

savefig(filename: str, **kwargs)#

Save figure to file.

class majordome.common.InteractiveSession(debug: bool = False, **opts)#

Produce interactive sessions with a copy of function locals.

class majordome.common.StabilizeNvarsConvergenceCheck(max_iter: int, patience: int, n_vars: int)#

Check stabilization towards a constant value along iterations.

Parameters:
max_iter: int

Maximum number of iterations before considering failure.

patience: int

Number of consecutive convergences before declaring convergence.

n_vars: int

Number of variables to be checked in problem.

class majordome.common.RelaxUpdate(v_ini: ndarray, alpha: float = 0.5)#

Relax solution for updating new iteration.

Parameters:
v_ini: np.ndarray

Initial guess of solution.

alpha: float = 0.5

Fraction of old solution to use at updates.

update(alpha: float) None#

Update relaxation coefficients.

majordome.common.safe_remove(target_list: list, to_remove: list, inplace: bool = False) list#

Safely remove elements from a list and return it.

majordome.common.standard_plot(shape: tuple[int, int] = (1, 1), sharex: bool = True, grid: bool = True, style: str = 'classic', resized: tuple[float, float] = None) StandardPlot#

Wraps a function for ensuring a standardized plot.

majordome.common.solution_report(sol: Solution, specific_props: bool = True, composition_spec: str = 'mass', selected_species: list[str] = []) list[tuple[str, str, Any]]#

Generate a solution report for tabulation.

Parameters:
sol: ct.Solution

Cantera solution object for report generation.

specific_props: bool = True

If true, add specific heat capacity and enthalpy.

composition_spec: str = “mass”

Composition units specification, mass or mole.

selected_species: list[str] = []

Selected species to display; return all if a composition specification was provided.

Returns:
list[tuple[str, str, Any]]

A list of data entries intended to be displayed externally, e.g. with tabulate.tabulate or appended.

Raises:
ValueError

If in invalid composition specification is provided. If species filtering lead to an empty set of compositions.

majordome.common.bounds(arr)#

Returns minimum and maximum values of array arr.

majordome.common.within(x, arr)#

Check if value x is between extrema of array arr.

majordome.common.apply(f, iterable)#

Apply unit operation over iterable items.