Spaces:
Sleeping
Sleeping
| """Pack a flat Simulation-parameter dict into cycle_sim keyword arguments. | |
| Shared by `run_simulation` (Tab 1) and `_sim_point` (Tab 2 sweep) so both | |
| tabs always hand identical kwargs to `cycle_sim`. If either tab wants a | |
| swept/override value, it merges `{key: value}` into the input dict BEFORE | |
| calling this helper. | |
| The array ordering here MUST match what `murphy_unified/engine_bridge.py` | |
| and the underlying engines expect. See `tabs/simulation.py` (pre-refactor) | |
| lines ~237-258 for the original packing. | |
| """ | |
| from __future__ import annotations | |
| def build_engine_kwargs(params: dict) -> dict: | |
| """Convert a flat params dict into kwargs for ``cycle_sim``. | |
| Parameters | |
| ---------- | |
| params : dict | |
| Flat dict keyed by `run_simulation` parameter names (see | |
| `murphy_unified/sim_defaults.py::SIM_DEFAULTS`). | |
| Returns | |
| ------- | |
| dict with keys: | |
| ``Pexit_barg``, ``speed_f``, ``Ptank_barg``, ``Psat_barg``, | |
| ``ICVparam``, ``DCVparam``, ``pump_geom``, ``proc_param``, | |
| ``flash_eff``, and optionally ``exit_param`` and ``n_cycles``. | |
| """ | |
| ICVparam = [ | |
| params["icv_port"], params["icv_mass"], params["icv_travel"], | |
| params["icv_dp_area"], params["icv_Fs"], params["icv_SC"], | |
| params["icv_leakKv"], params["icv_comp_eff"], int(params["icv_npts"]), | |
| ] | |
| DCVparam = [ | |
| params["dcv_port"], params["dcv_mass"], params["dcv_travel"], | |
| params["dcv_dp_area"], params["dcv_Fs"], params["dcv_SC"], | |
| params["dcv_leakKv"], params["dcv_comp_eff"], int(params["dcv_npts"]), | |
| ] | |
| pump_geom = [ | |
| params["bore"], params["stroke"], params["hOD"], params["cLen"], | |
| params["emH"], params["emS"], params["kvoid"], params["kH"], | |
| params["Vfv"], params["vac"], params["cpm"], params["dvf"], | |
| ] | |
| proc_param = [ | |
| params["Tamb"], params["htc"], params["drive"], params["Fmult"], | |
| params["KvBB"], params["Pbb"], params["fric"], params["Exp"], | |
| ] | |
| kw: dict = { | |
| "Pexit_barg": params["Pexit"], | |
| "speed_f": params["speed"], | |
| "Ptank_barg": params["Ptank"], | |
| "Psat_barg": params["Psat"], | |
| "ICVparam": ICVparam, | |
| "DCVparam": DCVparam, | |
| "pump_geom": pump_geom, | |
| "proc_param": proc_param, | |
| "flash_eff": params["flash_eff"], | |
| } | |
| fill = params.get("fill_type", "Fixed Pexit") | |
| if fill == "CHSS Fill": | |
| kw["exit_param"] = [1, params["vsnubber"], params["vchss"], | |
| params["aov140f"], params["rodia"]] | |
| elif fill == "RO Vent": | |
| kw["exit_param"] = [0, params["vsnubber"], 0, | |
| params["aov140f"], params["rodia"]] | |
| n_cyc = int(params.get("num_cycles", 1) or 1) | |
| if n_cyc > 1: | |
| kw["n_cycles"] = n_cyc | |
| return kw | |