Specifying Discontinuous Functions
To specify a discontinuous function, such as a step in space or time, you can use logical functions that evaluate to 1 if true and 0 otherwise. For instance, the following function defines a sine wave that exists for 10 seconds and afterward takes the value 0:
sin(2*pi*t)*(t<10)
If a coefficient or a material property contains a step function or some other discontinuity, convergence problems can arise. For time-dependent problems, the time-stepping algorithm can run into problems. For stationary problems, mesh-resolution issues can arise such as overshooting or undershooting of the solution due to infinite flux problems. To avoid problems with a discontinuity, replace it with a smoothed step function that emulates steps. Doing so serves two purposes:
Smoothing of Discontinuous Functions
The easiest way to create a smooth step is to use the predefined Step function. It includes smoothing by default. The Piecewise, Ramp, Rectangle, and Triangle functions also include smoothing (active by default for Rectangle and Triangle functions). Smoothed Step and Rectangle functions are defined by piecewise 5th-degree polynomials, smoothed Ramp functions by piecewise 4th-degree polynomials, and smoothed Triangle functions by piecewise 3rd-degree polynomials. None of these functions have any overshoot or undershoot.
Additional Smoothed Functions
In addition, the following smoothed functions are available:
flsmhs, a smoothed step function, or Heaviside function, with a continuous first derivative and overshoot on both sides of the step. The overshoot ensures that the integral from 0 to infinity is correct. y=flsmhs(x,scale) approximates the logical expression y = (x>0) by smoothing the transition within the interval
scale < x < scale; that is, the scale value is half of the smoothing zone s. fldsmhs is the derivative of the smoothed Heaviside function.
flsmsign, a smoothed sign function with a continuous first derivative. y = flsmsign(x,scale) approximates the function y = sign(x) by smoothing the transition within the interval scale < x < scale. fldsmsign is the derivative of the smoothed sign function.
flc1hs, a smoothed Heaviside function with a continuous first derivative without overshoot. Its syntax is similar to the functions just described. The definition of flc1hs is the following:
-
flc1hs(x,d) = 0, if ≤ −d
-
flc1hs(x,d) = 1, if x ≥ d
-
flc1hs(x,d) = 0.5 + 0.75·(x / d) − 0.25·(x / d)3
flc2hs, a smoothed Heaviside function with a continuous second derivative without overshoot. Its syntax is similar to the functions just described. The definition of flc2hs is the following:
-
flc2hs(x,d) = 0, if ≤ −d
-
flc2hs(x,d) = 1, if x ≥ d
-
flc2hs(x,d) = 0.5 + 0.9375·(x / d) − 0.625·(x / d)3 + 0.1875·(x / d)5
To create a smoothed rectangle over an interval [a, b] with one continuous derivative and a smoothing zone s, use flc1hs(x-a,0.5*s))-flc1hs(x-b,0.5*s). Similarly, you define a smoothed rectangle over an interval [a, b] with two continuous derivatives and a smoothing zone s using flc2hs(x-a,0.5*s))-flc2hs(x-b,0.5*s).
These functions can be useful as a complement and extension to the predefined Step function. In the interval -scale<x<scale, the functions flsmhs and flsmsign are defined by a 7th-degree polynomial chosen so that the 2nd derivative is continuous. Moreover, the moments of order 0, 1, and 2 agree with those for the Heaviside function and the sign function, respectively. This implies that the functions have small overshoots.
Now consider an example. Use flc1hs to model the heat capacity Cp of a phase-changing material. Assume that a crystalline material has a heat capacity of 1 kJ/kg. Its melting point at the present pressure is 273.15 K. The liquid phase has a heat capacity of 2 kJ/kg. Create a parameter scale with a value of 0.1 and then an Analytic node where an analytic function HeatCapacity is defined using the following expression with an argument T: 1+flc1hs(T-273,scale); then define a plot range of 272.5–273.5 K under Plot Parameters and click the Plot button in the Settings window for Analytic to plot Cp around the melting point.