Piecewise Interpolation Direct Entries¶
- class ionworkspipeline.direct_entries.BaseInterpolation(base_parameter_name: str, smoothing: float, source: str, print_precision: int = 6)¶
Base class for piecewise interpolation direct entries.
Provides common functionality for 1D and 2D interpolation.
Extends:
ionworkspipeline.direct_entries.direct_entry.DirectEntry- run(parameter_values: ParameterValues) ParameterValues¶
Create the piecewise interpolation function.
Parameters¶
- parameter_valuesiwp.ParameterValues
ParameterValues containing the parameter values at each breakpoint.
Returns¶
- iwp.ParameterValues
ParameterValues with the base parameter name mapped to the interpolation function.
- class ionworkspipeline.direct_entries.PiecewiseInterpolation1D(base_parameter_name: str, breakpoint_values: list[float], breakpoint_parameter_name: str, smoothing: float = 0.0001, formulation: str = 'knots', **kwargs)¶
A direct entry that creates a piecewise linear interpolation function for a parameter that varies with respect to a breakpoint parameter (e.g., SOC, temperature, voltage).
This uses smooth heaviside functions to create a continuous, differentiable interpolation that can be used in PyBaMM models.
Parameters¶
- base_parameter_namestr
The name of the parameter to create (e.g., “Particle diffusion time [s]”)
- breakpoint_valueslist[float]
List of breakpoint values at which the parameter is defined (e.g., [0.0, 0.5, 1.0])
- breakpoint_parameter_namestr
Name of the breakpoint parameter (e.g., “SOC”, “Temperature [K]”, “Voltage [V]”)
- smoothingfloat, optional
Smoothing parameter for heaviside transitions (default: 1e-4). Larger values create smoother transitions.
- formulationstr, optional
Parameterization formulation: “knots” (default) or “slopes”. - “knots”: Fit the parameter values at each breakpoint - “slopes”: Fit the initial value and slopes between breakpoints
Example¶
>>> # Create a SOC-dependent diffusivity with knots mode >>> calc = PiecewiseInterpolation1D( ... base_parameter_name="Particle diffusion time [s]", ... breakpoint_values=[0.0, 0.5, 1.0], ... breakpoint_parameter_name="SOC", ... smoothing=1e-4, ... formulation="knots" ... ) >>> # Provide parameter values for each breakpoint >>> param_values = { ... "Particle diffusion time at SOC 0 [s]": 500.0, ... "Particle diffusion time at SOC 0.5 [s]": 1000.0, ... "Particle diffusion time at SOC 1 [s]": 2000.0, ... } >>> result = calc.run(param_values) >>> # result["Particle diffusion time [s]"] is now a function that interpolates
>>> # Create a SOC-dependent diffusivity with slopes mode >>> calc = PiecewiseInterpolation1D( ... base_parameter_name="Particle diffusion time [s]", ... breakpoint_values=[0.0, 0.5, 1.0], ... breakpoint_parameter_name="SOC", ... smoothing=1e-4, ... formulation="slopes" ... ) >>> # Provide initial value and slopes for each segment >>> param_values = { ... "Particle diffusion time at SOC 0 [s]": 500.0, ... "Particle diffusion time slope from SOC 0 to 0.5 [s]": 1000.0, ... "Particle diffusion time slope from SOC 0.5 to 1 [s]": 2000.0, ... } >>> result = calc.run(param_values)
Extends:
ionworkspipeline.direct_entries.piecewise_interpolation.BaseInterpolation- property input_param_names¶
Returns the list of input parameters needed for this calculation.
In ‘knots’ formulation: Returns parameter names for all breakpoint values. In ‘slopes’ formulation: Returns parameter name for initial value and all slopes.
- to_config() dict¶
Convert to a config dict that can round-trip through the parser.
- class ionworkspipeline.direct_entries.PiecewiseInterpolation2D(base_parameter_name: str, breakpoint1_values: list[float], breakpoint1_parameter_name: str, breakpoint2_values: list[float], breakpoint2_parameter_name: str, smoothing1: float = 0.0001, smoothing2: float = 0.0001, formulation: str = 'knots', **kwargs)¶
A direct entry that creates a 2D piecewise bilinear interpolation function for a parameter that varies with respect to two breakpoint parameters (e.g., SOC and Temperature).
This uses smooth heaviside functions to create a continuous, differentiable interpolation that can be used in PyBaMM models.
Parameters¶
- base_parameter_namestr
The name of the parameter to create (e.g., “Particle diffusion time [s]”)
- breakpoint1_valueslist[float]
List of first breakpoint values (e.g., [0.0, 0.5, 1.0] for SOC)
- breakpoint1_parameter_namestr
Name of the first breakpoint parameter (e.g., “SOC”)
- breakpoint2_valueslist[float]
List of second breakpoint values (e.g., [273.15, 298.15, 323.15] for Temperature)
- breakpoint2_parameter_namestr
Name of the second breakpoint parameter (e.g., “Temperature [K]”)
- smoothing1float, optional
Smoothing parameter for first dimension heaviside transitions (default: 1e-4). Larger values create smoother transitions.
- smoothing2float, optional
Smoothing parameter for second dimension heaviside transitions (default: 1e-4). Larger values create smoother transitions. Use different smoothing values when the two dimensions have very different scales.
- formulationstr, optional
Parameterization formulation: “knots” (default) or “slopes”. - “knots”: Fit the parameter values at each 2D grid point - “slopes”: Fit the initial value and slopes along each dimension
Example¶
>>> # Create a SOC and Temperature-dependent diffusivity with knots mode >>> entry = PiecewiseInterpolation2D( ... base_parameter_name="Diffusivity [m2.s-1]", ... breakpoint1_values=[0.0, 0.5, 1.0], ... breakpoint1_parameter_name="SOC", ... breakpoint2_values=[273.15, 298.15], ... breakpoint2_parameter_name="Temperature [K]", ... smoothing1=1e-4, ... smoothing2=0.1, # Temperature has larger scale, so use larger smoothing ... formulation="knots" ... ) >>> # Provide parameter values for each 2D breakpoint >>> params = { ... "Diffusivity at SOC 0, Temperature [K] 273.15 [m2.s-1]": 1e-14, ... "Diffusivity at SOC 0, Temperature [K] 298.15 [m2.s-1]": 2e-14, ... "Diffusivity at SOC 0.5, Temperature [K] 273.15 [m2.s-1]": 3e-14, ... "Diffusivity at SOC 0.5, Temperature [K] 298.15 [m2.s-1]": 4e-14, ... "Diffusivity at SOC 1, Temperature [K] 273.15 [m2.s-1]": 2e-14, ... "Diffusivity at SOC 1, Temperature [K] 298.15 [m2.s-1]": 3e-14, ... } >>> result = entry.run(params) >>> # result["Diffusivity [m2.s-1]"] is now a function that takes two arguments
Extends:
ionworkspipeline.direct_entries.piecewise_interpolation.BaseInterpolation- property input_param_names¶
Returns the list of input parameters needed for this calculation.
In ‘knots’ formulation: Returns parameter names for all 2D grid points. In ‘slopes’ formulation: Returns parameter name for initial value and all slopes.
- to_config() dict¶
Convert to a config dict that can round-trip through the parser.