timestep too small error with non-linear capacitor - how to handle possible discontinuous points

I am using LT spice to simulate a thermal problem involving a phase-change material (a paraffin). [

with the paraffin modeled as a non-linear capacitor and resistor (the capacitor represents the heat capacity, the resistor the thermal conductivity: Note: the thermal resistance is simulated as a voltage-controlled current source because a normal resistor can't handle if() statements in its value, even in parameters.

For thermal simulations, the voltages in the circuit equate to temperatures in Kelvin and current equates to heat-flow. (See, for instance, Learn LTSpice: A Tutorial The non-linear capacitor has the equation

Q = {PCM_mass_g} * if(
V(Heat_In) <= ({Tm} - ({epsilon}/2)),
(x*{Cps}),
if(
V(Heat_In)>=({Tm}+({epsilon}/2)
),
({Cps}*{Tm}+{Hfus}*{Cpl}*(x-{Tm})),
(
({C3}*((x-{deltaTc})**3)) + ({C2}*((x-{deltaTc})**2)) +({C1}*(x-{deltaTc}))+{C0}
)
)
)


epsilon is a small band around the melting point. Below temperature = (Tmelting - epsilon/2) the thermal capacity has the value for a solid; above (Tmelting + epsilon/2) it has another value for the liquid form, and within the epsilon band it is a complex polynomial that describes the heat of fusion for the material.

The equation should be reasonably continuous, at least it is in the spreadsheet:

But whenever the simulation voltage V(a) hits (Tmelting-epsilon/2) LTSpice throws a "timestep too small" error.

I will be most grateful for any suggestions as to how to get around this!

• Normally I throw in small, negligible resistors here and there so things do not have to happen instantly and there is something to provide some give and take up slack in the system. Without them, you often have unstoppable force versus immovable object contradictions where things have to happen both instantly and not at all. Jan 30 at 20:47
• What's the .SUBCKT? The complete model would be a big help.
– jonk
Jan 30 at 21:10
• There isn't a SUBCKT per se. Just the "Q=..." definition. The current source is "I=(V(Heat_In)-V(Heat_Out))*((if((V(Heat_In)>{Tm}),{tcl},{tcs})*{PCM_area_m2})/{PCM_depth_m})" Jan 30 at 22:15
• That looks scary. I haven't ran your formula, but did you make sure it's the integrated version of the desired result? The manual (LTspice > Circuit Elements > C) clearly says "LTspice will compile this expression and symbolically differentiate it with respect to all the variables, finding the partial derivative's that correspond to capacitances" (more on this). I would use that expression in a bi source with a unity value capacitor in parallel (and 1G resistor), then take that voltage to Q= (+ maybe a small cap across). Jan 30 at 22:15
• Also take care of this. Jan 30 at 22:18