优化端口传递物性参数方式,减少上下游元件重复计算量
This commit is contained in:
1 parent
91bd9fb252
commit
5d5a2e1843
12 files changed
+773
-65
No files matched your search
@@ -1,5 +1,6 @@
|
||||
#ifndef NATIVE_KERNELS_H
|
||||
#define NATIVE_KERNELS_H
|
||||
#include <stddef.h>
|
||||
typedef struct { double p, T, rho, u, h; } NativeGas;
|
||||
typedef struct {
|
||||
int velocity_index;
|
||||
@@ -8,6 +9,30 @@ typedef struct {
|
||||
} NativeStop;
|
||||
/* Constants are emitted per medium instance by the model compiler. */
|
||||
typedef struct { int real_helium; double R, cp, Tref, slope, mu, muT, S; } NativeMedium;
|
||||
/* Caller-owned scratch for ONE model_eval. Keys use exact values and a copy of
|
||||
* every medium constant. No process/thread global cache or approximate reuse. */
|
||||
enum {
|
||||
NATIVE_PROPERTY_PT=1, NATIVE_PROPERTY_H=2, NATIVE_PROPERTY_RHO=4,
|
||||
NATIVE_PROPERTY_MU=8, NATIVE_PROPERTY_ISENTROPIC=16
|
||||
};
|
||||
typedef struct {
|
||||
NativeMedium medium;
|
||||
double p, T, h, rho, mu, isentropic_factor, isentropic_exponent;
|
||||
unsigned valid;
|
||||
} NativePropertyState;
|
||||
typedef struct {
|
||||
NativePropertyState *states;
|
||||
size_t count, capacity;
|
||||
} NativePropertyCache;
|
||||
void native_properties_init(NativePropertyCache *, NativePropertyState *, size_t capacity);
|
||||
int native_gas_context(NativePropertyCache *, double m, double U, double V, NativeGas *);
|
||||
int native_medium_gas_context(NativePropertyCache *, const NativeMedium *, double m, double U, double V, NativeGas *);
|
||||
double native_temperature_ph_context(NativePropertyCache *, const NativeMedium *, double p, double h);
|
||||
double native_density_context(NativePropertyCache *, const NativeMedium *, double p, double T);
|
||||
int native_orifice_context(NativePropertyCache *, double p1, double p2, double h1, double h2,
|
||||
double area, double opening, double *q, double *cm, double *v);
|
||||
int native_medium_orifice_context(NativePropertyCache *, const NativeMedium *, double p1, double p2, double h1, double h2,
|
||||
double area, double opening, double *q, double *cm, double *v);
|
||||
/* One entry per pipe branch, zero-initialized for each model_eval. Never shared
|
||||
* across solver trials. Exact inputs, including medium constants, form the key. */
|
||||
typedef struct {
|
||||
@@ -15,6 +40,16 @@ typedef struct {
|
||||
double p1, p2, T, diameter, length, roughness, flow;
|
||||
int kind, valid;
|
||||
} NativePipeCache;
|
||||
typedef struct { int converged, iterations, bisections; double relative_residual; } NativePipeSolve;
|
||||
/* Solve Re^2*f(Re)=K for the shared pipe resistance law. On failure returns
|
||||
* NAN, with converged=0; flow_per_re converts the local stopping test to kg/s. */
|
||||
double native_pipe_resistance(double K, double roughness, double flow_per_re, NativePipeSolve *status);
|
||||
double native_pipe_flow_context(NativePropertyCache *, const NativeMedium *, double p1, double p2, double T,
|
||||
double diameter, double length, double roughness, int kind);
|
||||
double native_pipe_flow_cached_context(NativePropertyCache *, NativePipeCache *, const NativeMedium *,
|
||||
double p1, double p2, double T, double diameter, double length, double roughness, int kind);
|
||||
void native_pipe_diagnostics_context(NativePropertyCache *, const NativeMedium *, double q, double p, double T,
|
||||
double diameter, double length, double roughness, int diagnostic, double *result);
|
||||
int native_medium_init(const NativeMedium *, double p, double T, double V, int legacy_ideal_initial, double *mU);
|
||||
double native_density(const NativeMedium *, double p, double T);
|
||||
double native_temperature_ph(const NativeMedium *, double p, double h);
|
||||
|
||||
Reference in new issue
Block a user