# ThermoFAST Python Wrapper

The Python wrapper in this folder is an auto-generated `ctypes` interface to `ThermoFAST64.dll`.

The package also includes high-level Python helper functions in `dll_functions.py` that wrap pointer-heavy DLL calls and return plain Python dictionaries.

## Requirements

- Windows x64 (the wrapper loads `ThermoFAST64.dll`)
- Python 3.9+
- ThermoFAST generated wrappers in this folder (`dll_wrappers.py`, `dll_functions.py`, `__init__.py`)
- `ThermoFAST64.dll` in the same directory as `dll_wrappers.py`

> The code generation pipeline now copies `ThermoFAST64.dll` into this package folder when you run `scripts/generate_all.py`.

## Quick start (high-level wrappers)

```python
import thermofast as tf

# ---- Initialize ThermoFAST ----
tf.tf_init()

# ---- Configure feed (methane + ethane) ----
comp_names = ["Methane", "Ethane"]
comp_ids = [tf.tf_get_builtin_comp_id(name)["id"] for name in comp_names]

tf.tf_set_feed_builtin_comps(
    len(comp_ids),
    comp_ids,
    [True] * len(comp_ids),
)
tf.tf_set_feed_weights(len(comp_ids), [0.8, 0.2])

# Use ThermoFAST default models
models = tf.tf_get_default_models()
tf.tf_set_feed_models(
    models["fluid_model"],
    models["solid_model"],
    models["transport_model"],
    models["hydrate_model"],
    models["hydrate_type"],
)

# ---- Run a PT flash ----
# flash_type: 1 = PT
result = tf.tf_flash(1, 5.0, 280.0)
n_phases = result["n_phases"]
alerts = [a for a in result["alerts"] if a > 0]
print(f"Flash complete: n_phases={n_phases}, alerts={alerts}")

# ---- Read phase outputs ----
phase_type_idx = tf.tf_lookup_phase_attribute("Phase Type")["idx"]
molar_amount_idx = tf.tf_lookup_phase_attribute("Molar Amount")["idx"]

for phase_id in range(1, n_phases + 1):
    phase_type = tf.tf_get_phase_string(phase_type_idx, phase_id)["value"]
    molar_amount = tf.tf_get_phase_property(molar_amount_idx, phase_id, 0)["value"]

    print(f"Phase {phase_id}: type={phase_type}, molar_amount={molar_amount:.6g}")
```

## Notebook example

A notebook version of this example is provided at:

- `Wrappers/python/thermofast/examples/basic_flash.ipynb`

Open it with Jupyter Lab / Notebook and run cells in order.
