Quickstart
Smallest end-to-end script. Replace mixing_elbow.cas.h5 with your own
case file and the input/output names with what your case actually exposes.
Run it:
docs/examples/quickstart.pyis the runnable version of this page.
import cfdtwin
project = cfdtwin.Project.create("./my_study", name="study1")
project.set_case_file("mixing_elbow.cas.h5")
project.set_inputs({
"cold-inlet|momentum > velocity_magnitude": (0.2, 0.6),
"hot-inlet|momentum > velocity_magnitude": (0.4, 1.2),
})
project.set_outputs([
{"name": "outlet", "category": "Surface",
"field_variables": ["temperature"]},
])
project.generate_doe(n=20, method="lhs")
# mixing_elbow.cas.h5 is single-precision; drop the kwarg for double-precision cases.
project.connect_fluent(precision="single")
project.run_simulations(verbose=True)
result = project.train(model_name="run1")
print(result.summary())
pred = project.predict("run1", {
"cold-inlet|momentum > velocity_magnitude": 0.4,
"hot-inlet|momentum > velocity_magnitude": 0.8,
})
print(pred.values.shape) # (1, n_points)
What just happened
Project.create— laid out the project folder structure on disk (my_study/dataset/,my_study/models/, etc.).set_inputs/set_outputs— wrotemodel_setup.jsonandoutput_parameters.json. No Fluent required at this stage.generate_doe(n=20, method="lhs")— sampled 20 points from the input space using Latin hypercube and saved them todoe_samples.json.run_simulations()— launched Fluent, applied each DOE point's BCs, ran 100 iterations per sim, extracted the configured outputs, savedsim_0001.npz...sim_0020.npz.train(model_name="run1")— trained a POD+NN surrogate (one model per output field) and saved everything undermy_study/models/run1/.predict(...)— evaluated the surrogate at a new input point. No Fluent involved; it loads the trained model from disk.
Running it again
generate_doe replaces existing samples by default (use append=True to
add to them). run_simulations skips already-completed sim IDs, so you
can interrupt it and restart safely.
If you re-run train(model_name="run1") while a run1/ folder already
exists, cfdtwin auto-suffixes the new run as run1_2, run1_3, etc., and
emits a warning. The final folder name is in result.model_name.