Skip to content

Examples in Python

Every bundled example ships a pure-Python builder beside its TOML: the same model assembled through the API, so you can read, copy or import it instead of parsing a file. They live in examples/python/, named after the case they mirror — examples/01_single_pipe_sod.toml has examples/python/01_single_pipe_sod.py.

Each file is standalone — read it, copy it, or load it. There is no examples/python/__init__.py, so these are scripts rather than an importable package; use runpy (below) if you want one from another module.

Each builder exposes one function:

def build_case() -> Case: ...

so you can take the case, change a field, and run it without a file on disk:

import runpy

ns = runpy.run_path("examples/python/03_two_pipes_junction.py")
case = ns["build_case"]()
case.case.t_end = 0.05          # override anything
case.pipes[0].n_cells = 200

from aeolus1d.io.case import run_case
pipes, junctions, t_final = run_case(case)

Running one directly builds and advances it, then prints a per-pipe summary:

python examples/python/01_single_pipe_sod.py

These files are generated, and guarded against drift

scripts/gen_example_python.py writes them from the TOML cases. tests/integration/test_examples_python_siblings.py asserts three things for every example: that a builder exists, that it is byte-identical to what the generator emits today, and that executing it produces a Case equal field by field to the one its TOML parses to. Edit the TOML (or the schema) and regenerate; do not hand-edit a builder.

Only the top-level examples/*.toml are bundled into the wheel, and the same is true of these — a pip install carries them, subdirectory cases still need a clone.

Which surface is this? The declarative one: these builders construct schema dataclasses and call run_case. For the component surface — Pipe, Volume/Port/Junction, BC factories, advance_network — see the pure-Python assembly tutorial, which is hand-written because assembly order is a thing to learn rather than to transcribe.

Every example

entities counts what the case contains: pipes / junctions / cylinders / turbos / controllers. lines is the size of the generated builder, which is a fair proxy for how much of the schema the example exercises.

Example Case name Entities Builder lines
01_single_pipe_sod.toml sod_shock_tube 1 / 0 / 0 / 0 / 0 examples/python/01_single_pipe_sod.py 90
02_cd_nozzle.toml cd_nozzle 1 / 0 / 0 / 0 / 0 examples/python/02_cd_nozzle.py 89
03_two_pipes_junction.toml two_pipes_junction 2 / 1 / 0 / 0 / 0 examples/python/03_two_pipes_junction.py 116
04_pulsed_intake.toml pulsed_intake 1 / 0 / 0 / 0 / 0 examples/python/04_pulsed_intake.py 85
05_catalyst_plug.toml catalyst_plug 1 / 0 / 0 / 0 / 0 examples/python/05_catalyst_plug.py 89
06_helmholtz_quasi2d.toml helmholtz_quasi2d 1 / 0 / 0 / 0 / 0 examples/python/06_helmholtz_quasi2d.py 100
07_catalyst_thermal_front.toml catalyst_thermal_front 1 / 0 / 0 / 0 / 0 examples/python/07_catalyst_thermal_front.py 97
08_reactive_pipe.toml reactive_pipe 1 / 0 / 0 / 0 / 0 examples/python/08_reactive_pipe.py 88
09_real_gas_shock_tube.toml real_gas_shock_tube 1 / 0 / 0 / 0 / 0 examples/python/09_real_gas_shock_tube.py 99
10_cp_junction_kloss.toml cp_junction_kloss 3 / 1 / 0 / 0 / 0 examples/python/10_cp_junction_kloss.py 135
11_neck_pipe_junction.toml neck_pipe_junction 3 / 1 / 0 / 0 / 0 examples/python/11_neck_pipe_junction.py 141
12_cp_junction.toml cp_junction 3 / 1 / 0 / 0 / 0 examples/python/12_cp_junction.py 134
13_ehr_helmholtz.toml ehr_helmholtz 1 / 1 / 0 / 0 / 0 examples/python/13_ehr_helmholtz.py 94
14_py_junction_bc.toml py_junction_bc 1 / 1 / 0 / 0 / 0 examples/python/14_py_junction_bc.py 95
15_strang_chemistry.toml strang_chemistry 1 / 0 / 0 / 0 / 0 examples/python/15_strang_chemistry.py 90
16_bs_chemistry.toml bs_chemistry 1 / 0 / 0 / 0 / 0 examples/python/16_bs_chemistry.py 90
17_real_gas_nozzle.toml real_gas_nozzle 1 / 0 / 0 / 0 / 0 examples/python/17_real_gas_nozzle.py 101
18_real_gas_catalyst.toml real_gas_catalyst 1 / 0 / 0 / 0 / 0 examples/python/18_real_gas_catalyst.py 110
19_real_gas_plenum.toml real_gas_plenum 2 / 1 / 0 / 0 / 0 examples/python/19_real_gas_plenum.py 133
20_multi_species.toml multi_species 1 / 0 / 0 / 0 / 0 examples/python/20_multi_species.py 95
21_multi_species_kinetics.toml multi_species_kinetics 1 / 0 / 0 / 0 / 0 examples/python/21_multi_species_kinetics.py 95
22_lodi_port.toml lodi_port 1 / 1 / 0 / 0 / 0 examples/python/22_lodi_port.py 95
23_mp5_sod.toml mp5_sod 1 / 0 / 0 / 0 / 0 examples/python/23_mp5_sod.py 89
24_hllc_lm_pulse.toml hllc_lm_pulse 1 / 0 / 0 / 0 / 0 examples/python/24_hllc_lm_pulse.py 99
25_valve_inlet.toml valve_inlet 1 / 0 / 0 / 0 / 0 examples/python/25_valve_inlet.py 86
26_valve_orifice.toml valve_orifice 1 / 0 / 0 / 0 / 0 examples/python/26_valve_orifice.py 88
27_compressor.toml compressor_demo 2 / 0 / 0 / 1 / 0 examples/python/27_compressor.py 108
28_turbo_shaft.toml turbo_shaft_demo 4 / 0 / 0 / 2 / 0 examples/python/28_turbo_shaft.py 166
29_learned_junction_bc.toml learned_junction_bc_demo 2 / 1 / 0 / 0 / 0 examples/python/29_learned_junction_bc.py 119
30_learned_turbo_map.toml learned_turbo_map_demo 2 / 0 / 0 / 1 / 0 examples/python/30_learned_turbo_map.py 112
31_cylinder.toml cylinder_4stroke 2 / 0 / 1 / 0 / 0 examples/python/31_cylinder.py 133
35_mechanism_pipe.toml mechanism_pipe_demo 1 / 0 / 0 / 0 / 0 examples/python/35_mechanism_pipe.py 91
38_engine_turbo_scr.toml engine_turbo_scr 4 / 0 / 1 / 2 / 0 examples/python/38_engine_turbo_scr.py 210
39_4cyl_engine_turbo_scr.toml 4cyl_engine_turbo_scr 13 / 3 / 4 / 2 / 0 examples/python/39_4cyl_engine_turbo_scr.py 544
40_implicit_adaptive_pipe.toml implicit_adaptive_pipe 1 / 0 / 0 / 0 / 0 examples/python/40_implicit_adaptive_pipe.py 91
41_dpf_regen.toml dpf_regen 1 / 0 / 0 / 0 / 0 examples/python/41_dpf_regen.py 121
42_scr_urea_injector.toml scr_urea_injector 2 / 1 / 0 / 0 / 0 examples/python/42_scr_urea_injector.py 208
43_scrf.toml scrf 2 / 1 / 0 / 0 / 0 examples/python/43_scrf.py 234
44_egr_cooler.toml egr_cooler 1 / 0 / 0 / 0 / 0 examples/python/44_egr_cooler.py 94
45_two_stage_scr.toml two_stage_scr 3 / 2 / 0 / 0 / 0 examples/python/45_two_stage_scr.py 237
46_doc.toml doc 2 / 1 / 0 / 0 / 0 examples/python/46_doc.py 158
48_hnco_hydrolysis.toml hnco_hydrolysis 2 / 1 / 0 / 0 / 0 examples/python/48_hnco_hydrolysis.py 153
49_dpf_no_inhibition.toml dpf_no_inhibition 1 / 0 / 0 / 0 / 0 examples/python/49_dpf_no_inhibition.py 118
50_dpf_active_regen.toml dpf_active_regen 1 / 0 / 0 / 0 / 0 examples/python/50_dpf_active_regen.py 123
50_two_cyl_engine.toml two_cyl_engine 6 / 2 / 2 / 0 / 0 examples/python/50_two_cyl_engine.py 266
51_vgt_boost_ctrl.toml vgt_boost_ctrl_demo 4 / 0 / 0 / 2 / 1 examples/python/51_vgt_boost_ctrl.py 179
52_knock_event.toml knock_event 2 / 0 / 1 / 0 / 0 examples/python/52_knock_event.py 135
53_dpf_heater_ctrl.toml dpf_heater_ctrl 1 / 0 / 0 / 0 / 1 examples/python/53_dpf_heater_ctrl.py 136
54_adaptive_picard_turbo.toml adaptive_picard_turbo 4 / 0 / 0 / 2 / 1 examples/python/54_adaptive_picard_turbo.py 184
55_dpf_regen_hrr.toml dpf_regen_hrr 1 / 0 / 0 / 0 / 0 examples/python/55_dpf_regen_hrr.py 123
55_vgt_3d_turbo.toml vgt_3d_turbo 4 / 0 / 0 / 2 / 1 examples/python/55_vgt_3d_turbo.py 179
56_dpf_regen_lowmach.toml dpf_regen_lowmach 1 / 0 / 0 / 0 / 0 examples/python/56_dpf_regen_lowmach.py 125
57_picard_stiffness_step.toml picard_stiffness_step 4 / 0 / 0 / 2 / 1 examples/python/57_picard_stiffness_step.py 185
58_tabulated_eos_implicit.toml tabulated_eos_implicit 1 / 0 / 0 / 0 / 0 examples/python/58_tabulated_eos_implicit.py 103
59_wastegate_boost_ctrl.toml wastegate_boost_ctrl_demo 4 / 0 / 0 / 2 / 1 examples/python/59_wastegate_boost_ctrl.py 179
60_twin_sequential_turbo.toml twin_sequential_turbo_demo 6 / 0 / 0 / 4 / 0 examples/python/60_twin_sequential_turbo.py 236
61_doc_sulfur_poisoning.toml doc_sulfur_poisoning 2 / 1 / 0 / 0 / 1 examples/python/61_doc_sulfur_poisoning.py 181
62_egr_valve_ctrl.toml egr_valve_ctrl 1 / 0 / 0 / 0 / 1 examples/python/62_egr_valve_ctrl.py 136
63_spark_timing_ctrl.toml spark_timing_ctrl_demo 2 / 0 / 1 / 0 / 1 examples/python/63_spark_timing_ctrl.py 150
71_ktm_510_si.toml ktm_510_si_7000rpm 2 / 0 / 1 / 0 / 0 examples/python/71_ktm_510_si.py 145
72_throttle_demo.toml throttle_demo 1 / 0 / 0 / 0 / 0 examples/python/72_throttle_demo.py 88
74_twc.toml twc_osc_discharge 1 / 0 / 0 / 0 / 0 examples/python/74_twc.py 250
75_coolant_pipe.toml coolant_jacket_demo 1 / 0 / 0 / 0 / 0 examples/python/75_coolant_pipe.py 107
76_wltp_lite_dpf.toml wltp_lite_dpf 1 / 0 / 0 / 0 / 0 examples/python/76_wltp_lite_dpf.py 260
77_pipe_flow_heat.toml pipe_flow_heat 1 / 0 / 0 / 0 / 0 examples/python/77_pipe_flow_heat.py 93
78_pipe_bend_loss.toml pipe_bend_loss 1 / 0 / 0 / 0 / 0 examples/python/78_pipe_bend_loss.py 90
79_orifice_plate.toml orifice_plate 1 / 0 / 0 / 0 / 0 examples/python/79_orifice_plate.py 92
80_pipe_wall_warmup.toml pipe_wall_warmup 1 / 0 / 0 / 0 / 0 examples/python/80_pipe_wall_warmup.py 98
81_bend_geometric.toml bend_geometric 1 / 0 / 0 / 0 / 0 examples/python/81_bend_geometric.py 92
82_multilayer_wall.toml multilayer_wall 1 / 0 / 0 / 0 / 0 examples/python/82_multilayer_wall.py 110
83_turbo_robustness.toml turbo_robustness_demo 4 / 0 / 0 / 2 / 0 examples/python/83_turbo_robustness.py 171
84_dpf_substrate_inertia.toml dpf_substrate_inertia 1 / 0 / 0 / 0 / 0 examples/python/84_dpf_substrate_inertia.py 101
85_vehicle_drive_cycle.toml case 0 / 0 / 0 / 0 / 0 examples/python/85_vehicle_drive_cycle.py 52
86_electrified_drive_cycle.toml case 0 / 0 / 0 / 0 / 0 examples/python/86_electrified_drive_cycle.py 52
87_multicomponent_variable_gamma_shock_tube.toml multicomponent_variable_gamma_shock_tube 1 / 0 / 0 / 0 / 0 examples/python/87_multicomponent_variable_gamma_shock_tube.py 108
88_dd13_diesel.toml dd13_diesel 2 / 0 / 1 / 0 / 0 examples/python/88_dd13_diesel.py 159
89_dd13_multizone.toml dd13_multizone 2 / 0 / 1 / 0 / 0 examples/python/89_dd13_multizone.py 159
89_epw_diesel.toml avl_epw_diesel_base 17 / 2 / 6 / 2 / 0 examples/python/89_epw_diesel.py 727
90_variable_cv_real_gas.toml variable_cv_real_gas 1 / 0 / 0 / 0 / 0 examples/python/90_variable_cv_real_gas.py 98
91_cylinder_species_transport.toml cylinder_species_transport 2 / 0 / 1 / 0 / 0 examples/python/91_cylinder_species_transport.py 182
92_component_library.toml component_library_demo 1 / 0 / 0 / 0 / 0 examples/python/92_component_library.py 83
93_tapered_species_muscl.toml tapered_species_muscl 2 / 0 / 0 / 0 / 0 examples/python/93_tapered_species_muscl.py 148
94_tapered_species_first_order.toml tapered_species_first_order 1 / 0 / 0 / 0 / 0 examples/python/94_tapered_species_first_order.py 98

Regenerating

python scripts/gen_example_python.py           # rewrite builders + this page
python scripts/gen_example_python.py --check    # CI: fail if anything is stale