jaxprop.bicubic.bicubic_interpolation module#
- class jaxprop.bicubic.bicubic_interpolation.FluidBicubic(fluid_name: str, backend: str, h_min: float, h_max: float, p_min: float, p_max: float, N_h: int, N_p: int, coarse_step: int = 10, gradient_method: str = 'central', identifier: str = None, table_name: str = None, table_dir: str = 'fluid_tables')[source]#
Bases:
ModuleFluid model using bicubic property interpolation on an enthalpy-pressure grid.
- Workflow:
On construction, attempts to load a precomputed table from disk.
If not found, generates the table with finite-difference derivatives, saves it to disk, and stores it in memory.
On get_props, performs bicubic interpolation at the requested state.
- Parameters:
- fluid_namestr
Fluid identifier for CoolProp.
- backendstr
CoolProp backend string.
- h_min, h_maxfloat
Min/max enthalpy [J/kg].
- p_min, p_maxfloat
Min/max pressure [Pa].
- N_h, N_pint
Number of grid points in h and p.
- coarse_stepint
Number of points to skip when determining the initial guess during 2D inverse interpolations
- table_namestr, optional
Name of the table pickle file (default: “{fluid_name}_{N_h}x{N_p}”).
- table_dirstr, optional
Directory for saving/loading table pickle (default: “fluid_tables”).
- identifierstr, optional
Tag stored in the returned FluidState objects.
Methods
get_state(input_type, val1, val2)Compute thermodynamic states from any supported input pair using bicubic interpolation.
Notes
Table generation uses forward finite differences for first and mixed derivatives with adaptive step size.
Currently supports only HmassP_INPUTS as input pair.
- N_h: int#
- N_p: int#
- PROPERTY_CALCULATORS = {9: <function FluidBicubic.<lambda>>, 10: <function FluidBicubic.<lambda>>, 18: <function FluidBicubic.<lambda>>, 20: <function FluidBicubic.<lambda>>, 22: <function FluidBicubic.<lambda>>, 26: <function FluidBicubic.<lambda>>, 30: <function FluidBicubic.<lambda>>, 32: <function FluidBicubic.<lambda>>}#
- backend: str#
- coarse_step: int#
- delta_h: float#
- delta_logP: float#
- fluid_name: str#
- get_state(input_type, val1, val2)[source]#
Compute thermodynamic states from any supported input pair using bicubic interpolation.
This is the main user-facing entry point. It accepts either scalar or array inputs for val1 and val2, automatically broadcasting them to a common shape and evaluating the corresponding fluid state at each point in a vectorized manner. Internally, the method selects one of several solvers depending on the specified input_type:
For (h, p) inputs, properties are obtained directly through bicubic interpolation on the enthalpy-log(pressure) grid.
For 1D inversion problems (e.g. P,T or D,p), a Newton root finder is used to solve for either enthalpy or pressure, using the closest table node as the initial guess.
For 2D inversion problems (e.g. D, T), a Newton solver in normalized (h, p) space is used to recover the unique thermodynamic state that matches both input properties simultaneously.
All computations are compatible with JAX transformations such as jit, vmap, and automatic differentiation. Vectorization is handled internally using vmap over the scalar solver/interpolator. The output is a FluidState object containing all thermodynamic and transport properties defined in the table, either for a single point (scalar inputs) or for each element of the broadcasted input arrays.
- Parameters:
- input_typeint
Identifier of the input pair (e.g. jxp.HmassP_INPUTS, jxp.PT_INPUTS).
- val1float or array_like
First input variable (e.g. enthalpy, pressure, density).
- val2float or array_like
Second input variable (e.g. pressure, temperature, entropy).
- Returns:
- FluidState
Interpolated fluid state(s) corresponding to the specified input pair. If inputs are arrays, each property is returned as an array with the broadcasted shape of val1 and val2.
- grad_method: str#
- h_max: float#
- h_min: float#
- h_vals: Array#
- identifier: str#
- logP_vals: Array#
- p_max: float#
- p_min: float#
- table: dict#
- table_dir: str#
- table_name: str#
- jaxprop.bicubic.bicubic_interpolation.compute_coefficients(value, grad_h, grad_logP, grad_hlogP, delta_h, delta_logP)[source]#
Compute bicubic interpolation coefficients for one property on a uniform (h, logP) grid.
- Parameters:
- valuendarray of shape (Nh, Np)
Property values f(h, P) evaluated on the grid.
- grad_hndarray of shape (Nh, Np)
Partial derivative with respect to enthalpy evaluated on the grid.
- grad_logPndarray of shape (Nh, Np)
Partial derivative with respect to pressure evaluated on the grid (with respect to P, not logP).
- grad_hlogPndarray of shape (Nh, Np)
Mixed derivative with respect to enthalpy and pressure evaluated on the grid.
- delta_hfloat
Uniform grid spacing in h.
- delta_logPfloat
Uniform grid spacing in logP.
- Returns:
- coeffsndarray of shape (Nh-1, Np-1, 16)
Bicubic coefficients for each cell. The ordering is c[4*n + m], where m is the power of x (h-direction) and n is the power of y (logP-direction).