Skip to content

models.propulsion.propellants.formulations

machwave.models.propulsion.propellants.formulations

get_propellant_from_json(filepath)

Load propellant formulation from JSON file.

Parameters:

Name Type Description Default
filepath str | Path

Path to JSON file.

required

Returns:

Type Description
SolidPropellant | BiliquidPropellant

SolidPropellant or BiliquidPropellant instance.

Raises:

Type Description
ValueError

If JSON data invalid.

FileNotFoundError

If file doesn't exist.

Source code in machwave/models/propulsion/propellants/formulations/base.py
def get_propellant_from_json(
    filepath: str | Path,
) -> propellant_categories.SolidPropellant | propellant_categories.BiliquidPropellant:
    """Load propellant formulation from JSON file.

    Args:
        filepath: Path to JSON file.

    Returns:
        SolidPropellant or BiliquidPropellant instance.

    Raises:
        ValueError: If JSON data invalid.
        FileNotFoundError: If file doesn't exist.
    """
    filepath = Path(filepath)

    if not filepath.exists():
        raise FileNotFoundError(f"Propellant JSON file not found: {filepath}")

    with open(filepath, "r") as f:
        data = json.load(f)

    mixture_type = _parse_mixture_type(data)
    components, mass_fractions = _parse_components(data, mixture_type=mixture_type)
    properties = _parse_properties(data)
    return _create_propellant(
        mixture_type, data, components, mass_fractions, properties
    )