优化端口传递物性参数方式,减少上下游元件重复计算量
This commit is contained in:
1 parent
91bd9fb252
commit
5d5a2e1843
12 files changed
+773
-65
No files matched your search
@@ -260,7 +260,7 @@ def _compile_storage_anchored_program(network: SimulationNetwork) -> NativeProgr
|
||||
initial_volume = max(base, c.cvol0 / 100) if c.model_type == "amesim_pnch012" else base
|
||||
init.append(f"if (!native_gas_init({_number(c.p0)}, {_number(c.T0)}, {_number(initial_volume)}, &y[{si(c, 'm')}])) return 0;")
|
||||
lines.append(f"NativeGas gas_{gi};")
|
||||
lines.append(f"if (!native_gas(y[{si(c, 'm')}], y[{si(c, 'U')}], {volume}, &gas_{gi})) return 0;")
|
||||
lines.append(f"if (!native_gas_context(properties, y[{si(c, 'm')}], y[{si(c, 'U')}], {volume}, &gas_{gi})) return 0;")
|
||||
for field in ("m", "U"):
|
||||
put(c, field, f"y[{si(c, field)}]")
|
||||
for field in ("p", "T", "rho", "u", "h"):
|
||||
@@ -277,7 +277,7 @@ def _compile_storage_anchored_program(network: SimulationNetwork) -> NativeProgr
|
||||
continue
|
||||
a, b = chamber_at(c, "port_2"), chamber_at(c, "port_3")
|
||||
put(c, "xv", f"fmax(0.0, fmin(1.0, {get(c, 'res.signal')}))")
|
||||
lines.append(f"if (!native_orifice({get(a, 'p')}, {get(b, 'p')}, {get(a, 'h')}, {get(b, 'h')}, {_number(c.effective_cq * c.maximum_area)}, {get(c, 'xv')}, &{get(c, 'port_2.m_flow')}, &{get(c, 'cm')}, &{get(c, 'gasvel')})) return 0;")
|
||||
lines.append(f"if (!native_orifice_context(properties, {get(a, 'p')}, {get(b, 'p')}, {get(a, 'h')}, {get(b, 'h')}, {_number(c.effective_cq * c.maximum_area)}, {get(c, 'xv')}, &{get(c, 'port_2.m_flow')}, &{get(c, 'cm')}, &{get(c, 'gasvel')})) return 0;")
|
||||
assigned.update((key(c, "cm"), key(c, "gasvel")))
|
||||
put(c, "port_3.m_flow", f"-{get(c, 'port_2.m_flow')}")
|
||||
put(c, "port_2.h_outflow", get(b, "h"))
|
||||
@@ -368,7 +368,10 @@ def _compile_storage_anchored_program(network: SimulationNetwork) -> NativeProgr
|
||||
f"const double model_atol[NSTATES] = {{{','.join(map(state_absolute_tolerance, state_keys))}}};",
|
||||
"const char *const model_output_keys[NOUTPUTS] = {" + ",".join(json.dumps(v.key, ensure_ascii=True) for v in variables) + "};",
|
||||
"int model_init(double *y) {", *init, "return 1; }",
|
||||
"int model_eval(double t, const double *y, double *dy, double *w) {", "(void)t;", *lines,
|
||||
"int model_eval(double t, const double *y, double *dy, double *w) {", "(void)t;",
|
||||
f"NativePropertyState property_states[{min(256,max(16,4*len(components)))}];",
|
||||
"NativePropertyCache property_cache, *properties=&property_cache;",
|
||||
"native_properties_init(properties,property_states,sizeof(property_states)/sizeof(property_states[0]));", *lines,
|
||||
"for (int i=0;i<NSTATES;i++) if (!isfinite(dy[i])) return 0;",
|
||||
"for (int i=0;i<NOUTPUTS;i++) if (!isfinite(w[i])) return 0;",
|
||||
"return 1; }",
|
||||
|
||||
Reference in new issue
Block a user