majordome.common#

Constants#

majordome.common.DATA#

Path to project data folder.

Type aliases#

majordome.common.CompositionType#

Input type for Cantera composition dictionaries.

majordome.common.SolutionLikeType#

Input type for Cantera solution objects.

majordome.common.PathLike#

Input type for file system paths.

majordome.common.MaybePath#

Input type for optional file system paths.

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

Input type for Cantera TPX state dictionaries.

P: int | float | Number#

Alias for field number 2

T: int | float | Number#

Alias for field number 1

X: str | dict[str, float]#

Alias for field number 0

Utilities#

class majordome.common.AbstractReportable(*args, **kwargs)#

Abstract base class for reportable objects.

report(*args, **kwargs) str#

Provides a report of the object.

abstractmethod report_data(*args, **kwargs) list[tuple[Any, ...]]#

Provides data for assemblying the object report.

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.InteractiveSession(debug: bool = False, **opts)#

Produce interactive sessions with a copy of function locals.

class majordome.common.Capturing(iterable=(), /)#

Helper to capture excessive solver output.

In some cases, specially when running from a notebook, it might be desirable to capture solver (here Ipopt specifically) output to later check, thus avoiding a overly long notebook. For this end this context manager is to be used and redirect to a list.

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.

class majordome.common.StabilizeNvarsConvergenceCheck(*, n_vars: int, min_iter: int = 1, max_iter: int = inf, patience: int = 10, rtol: float = 1e-10, atol: float = 1e-20, equal_nan: bool = False, log_iter: bool = False)#

Check stabilization towards a constant value along iterations.

Parameters:
n_vars: int

Number of variables to be checked in problem.

min_iter: int

Minimum number of iterations before considering converged.

max_iter: int

Maximum number of iterations before considering failure.

patience: int

Number of consecutive convergences before declaring convergence.

rtol: float = 1.0e-06

See numpy.isclose for details.

atol: float = 1.0e-12

See numpy.isclose for details.

equal_nan: bool = False

See numpy.isclose for details.

log_iter: bool = False

If true, log convergence message when achieved.

property n_iterations: int#

Provides access to number of iterations performed.

class majordome.common.ComposedStabilizedConvergence(n_arrs, **kwargs)#

Wrapper for checking stabilization of several arrays.

See StabilizeNvarsConvergenceCheck for key-word arguments; these are shared by all tested arrays. It is always possible to compose your own convergence checker using individual instances for more control over setup.

static make_one(**opts)#

Create a single instance of convergence checker.

property n_iterations: int#

Provides access to number of iterations performed.

majordome.common.has_program(name: str) bool#

Test if a program is available in system path.

majordome.common.program_path(name: str, throw: bool = True) str | Path | None#

Returns a program path if it exists.

majordome.common.first_in_path(path_list: list[str | Path]) Path | None#

Find first existing path in path_list.

majordome.common.normalize_string(s: str) str#

Normalize strings to be used as valid Python code.

majordome.common.safe_remove(target_list: list[Any], to_remove: list[Any] | None, inplace: bool = False) list#

Safely remove elements from a list and return it.

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.