common¶
Value objects and helpers shared across the library, belonging to no single model package.
FluidState— A fluid at a thermodynamic state point: fluid name, pressure, temperature, and density. What a feed system hands the injector, so neither package has to import the other.DryMassProperties— Mass, center of gravity, and inertia tensor of a device's dry structure.- Array manipulation helpers and a
@timingdecorator for profiling. require()— Imports an optional dependency, raisingMissingOptionalDependencyErrornaming the packaging extra that ships it.
machwave.common.fluid_state
¶
FluidState
dataclass
¶
A fluid at a thermodynamic state point.
Attributes:
| Name | Type | Description |
|---|---|---|
fluid_name |
str
|
Name of the fluid in the CoolProp database. |
pressure |
float
|
Pressure [Pa]. |
temperature |
float
|
Temperature [K]. |
density |
float
|
Density [kg/m^3]. |
Source code in machwave/common/fluid_state.py
machwave.common.mass_properties
¶
DryMassProperties
dataclass
¶
Properties common to devices that contain dry mass.
Attributes:
| Name | Type | Description |
|---|---|---|
dry_mass |
float
|
Dry mass scalar [kg]. |
center_of_gravity_coordinate |
tuple[float, float, float]
|
Dry mass center of gravity position measured from
the nozzle exit |
moment_of_inertia |
tuple[float, float, float]
|
Dry mass principal moments of inertia |
Source code in machwave/common/mass_properties.py
__post_init__()
¶
Validate and normalize the dry mass properties.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the dry mass is non-positive or non-finite, either triple is malformed, or a moment of inertia is negative or non-finite. |
Source code in machwave/common/mass_properties.py
machwave.common.arrays
¶
replace_array_values(arr, to_replace, value)
¶
Replaces values in a NumPy array with another value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
NDArray[number]
|
The array in which to replace values. |
required |
to_replace
|
int | float
|
The value to be replaced. |
required |
value
|
int | float
|
The value to replace with. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[number]
|
A new array with the values replaced. |
Source code in machwave/common/arrays.py
machwave.common.decorators
¶
timing(f)
¶
Decorator to print the execution time of a function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
F
|
The function to be timed. |
required |
Returns:
| Type | Description |
|---|---|
F
|
The wrapped function with added timing functionality. |
Source code in machwave/common/decorators.py
machwave.common.objects
¶
get_object_dict(obj)
¶
Extract the attribute dictionary from an object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
Any Python object to inspect. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary mapping attribute names to their values, or an empty dictionary |
dict[str, Any]
|
if the object has no dict. |
Examples:
>>> class Example:
... def __init__(self):
... self.x = 1
... self.y = 2
>>> get_object_dict(Example())
{'x': 1, 'y': 2}
Source code in machwave/common/objects.py
machwave.common.extras
¶
Resolution of the optional dependencies behind Machwave's packaging extras.
Modules reached only once a feature is used guard their own import at module
level and re-raise MissingOptionalDependencyError; that keeps the third-party
names real and fully typed. require is for modules on the import path, which
must stay importable without their dependency. It returns the module untyped,
so prefer the module-level guard wherever both work.
MissingOptionalDependencyError
¶
Bases: ImportError
Raised when a feature needs an optional dependency that is not installed.
Source code in machwave/common/extras.py
__init__(module_name, extra, feature=None)
¶
Build the error from the missing dependency and the extra that ships it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module_name
|
str
|
Import name of the package, e.g. |
required |
extra
|
str
|
Packaging extra that installs it. |
required |
feature
|
str | None
|
Plural noun phrase naming the feature, overriding the default
wording for |
None
|
Source code in machwave/common/extras.py
require(module_name, extra, feature=None)
¶
Import an optional dependency, naming the extra that ships it on failure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module_name
|
str
|
Import name of the package, e.g. |
required |
extra
|
str
|
Packaging extra that installs it. |
required |
feature
|
str | None
|
Plural noun phrase naming the feature, overriding the default
wording for |
None
|
Returns:
| Type | Description |
|---|---|
ModuleType
|
The imported module. |
Raises:
| Type | Description |
|---|---|
MissingOptionalDependencyError
|
If the package is not installed. |