From a12983948e4690e3ed77106e4d37dfdfdcd3ae75 Mon Sep 17 00:00:00 2001 From: Nicolas Kruse Date: Tue, 17 Jun 2025 23:18:24 +0200 Subject: [PATCH] moving type aliases to typing --- src/gaspype/_main.py | 17 ++++++----------- src/gaspype/typing.py | 6 ++++++ 2 files changed, 12 insertions(+), 11 deletions(-) create mode 100644 src/gaspype/typing.py diff --git a/src/gaspype/_main.py b/src/gaspype/_main.py index 0d05ace..9c83251 100644 --- a/src/gaspype/_main.py +++ b/src/gaspype/_main.py @@ -7,10 +7,7 @@ from gaspype._phys_data import atomic_weights, db_reader import re import pkgutil from .constants import R, epsy, p0 - -_Shape = tuple[int, ...] -NDFloat = np.float64 -FloatArray = NDArray[NDFloat] +from .typing import FloatArray, NDFloat, Shape T = TypeVar('T', 'fluid', 'elements') @@ -209,6 +206,8 @@ class fluid: array_fractions (FloatArray): Array of the molar fractions of the species in the fluid total (FloatArray | float): Array of the sums of the molar amount of all species fs (fluid_system): Reference to the fluid_system used for this fluid + shape (_Shape): Shape of the fluid array + elements (list[str]): List of elements in the fluid_system """ __array_priority__ = 100 @@ -219,7 +218,7 @@ class fluid: """Instantiates a fluid. Args: - composition: A dict of species names with their composition, e.g.: + composition: A dict of species names with their composition, e.g. {'O2':0.5,'H2O':0.5} or a list/numpy-array of compositions. The array can be multidimensional, the size of the last dimension must match the number of species defined for the fluid_system. @@ -258,7 +257,7 @@ class fluid: self.array_composition: FloatArray = comp_array self.total: FloatArray | float = np.sum(self.array_composition, axis=-1, dtype=NDFloat) self.array_fractions: FloatArray = self.array_composition / (np.expand_dims(self.total, -1) + epsy) - self.shape: _Shape = self.array_composition.shape[:-1] + self.shape: Shape = self.array_composition.shape[:-1] self.fs = fs self.array_elemental_composition: FloatArray = np.dot(self.array_composition, fs.array_species_elements) self.species = fs.species @@ -596,7 +595,7 @@ class elements: assert composition.shape[-1] == len(fs.elements), f'composition.shape[-1] ({composition.shape[-1]}) must be {len(fs.elements)}' self.array_elemental_composition = composition - self.shape: _Shape = self.array_elemental_composition.shape[:-1] + self.shape: Shape = self.array_elemental_composition.shape[:-1] self.fs = fs self.elements = fs.elements @@ -667,10 +666,6 @@ class elements: '\nMols:\n' + self.array_elemental_composition.__repr__()) -# def _combine_index(index1: list[str], index2: list[str]) -> list[str]: -# return list(set(index1) | set(index2)) - - def lookup(prop_array: FloatArray, temperature: FloatArray | float, t_offset: float) -> FloatArray: diff --git a/src/gaspype/typing.py b/src/gaspype/typing.py new file mode 100644 index 0000000..ad935c4 --- /dev/null +++ b/src/gaspype/typing.py @@ -0,0 +1,6 @@ +from numpy import float64 +from numpy.typing import NDArray + +Shape = tuple[int, ...] +NDFloat = float64 +FloatArray = NDArray[NDFloat]