1D Heat equation and a finite-difference solver Guillaume Riflet MARETEC IST 1 The advection-diffusion equation The original concept applied to a property within a control volume from which is derived the integral advection-diffusion equation states as {Rate of change in time} = {Ingoing Outgoing fluxes} + {Created Destroyed}. 1) Annotated in a correct mathematical encapsulation, equation 1 yields d P d = P v n) ds K P n) ds + Sc Sk) d, 2) where P is the transported property concentration, v is the advecting field, K is the diffusivity coefficient, is the surface of the control volume, n is the outward normal to the control surface and Sc and Sk are the source and sink terms, respectively. The first term on the right hand side RHS) of equation 2 states ingoing and outgoing fluxes due to advection, the second term in the RHS states ingoing and outgoing fluxes due to diffusion, and the last term on the RHS accounts for source and sink terms. the Note that Fick s law, K P, is applied to mathematically describe diffusion [1]. By resorting to the divergence theorem, stating that the divergence of a vector field inside any finite gaussian volume is equal to its flux through the boundary of the volume, i.e..e d = E n ds, 3) 1
1 The advection-diffusion equation 2 being the gaussian volume, its boundary, E the vector field, and E n its flux through the boundary. n is defined as the external normal unit vector to the boundary. Hence, by applying equation3) to equation2), the finite volume formulation of equation 4) is obtained: d P d = v P ) d K P ) d + Sc Sk) d. 4) By resorting to the Leibniz integration rule, d d fx, t) fx, t)d = d, which is true as long as the integral volume and consequently x) is held fixed in time, in one hand. By joining all the integrals in into a single integral on the other, equation 4 yields { } P + v P ) + K P ) Sc + Sk d = 0. Since the above integral holds zero for all gaussian volume, then its integrand must be zero, thus yielding the differential equation of advectiondiffusion: P + v P ) + K P ) Sc + Sk = 0. 5) A few comments: first, the control volume is held fixed in time. Second, the time derivative applied to a function varying in time only in its explicit component such as P x, t)), may be annotated as a partial derivative,, without loss of generality. Third, the total derivative and the partial derivative are related by the Leibniz chain rule, d P xt), t) = P xt 0), t) + d xt) P xt 0 ), t 0 ) x + d yt) P xt 0 ), t 0 ) y + d zt) P xt 0 ), t 0 ). z
1 The advection-diffusion equation 3 If dx = 0, then the partial derivative equals the total derivative, which is the case of P within the fixed volume. By noting that equation 5 returns v P ) = v P + P v, P + v P + P v + K P ) Sc + Sk = 0. By noting that the material derivative is defined by equation 5 finally yields D Dt + v, DP + P v + K P ) Sc + Sk = 0. Dt In incompressible fluids we have v = 0, hence in such case DP + K P ) Sc + Sk = 0. 6) Dt Thus, to sum up, equation 2) is the integral equation of advection and diffusion with source and sink terms) in flux form, equation 4) is the integral equation of advection-diffusion in volume form, equation 5) is the differential equation of advection-diffusion where the advective field is the velocity of the fluid particles relative to a fixed reference frame) and equation 6) is the differential equation of advection-diffusion for an incompressible fluid. 1.1 The 1D Heat-equation The 1D heat equation consists of property P as being temperature T or heat applying for the unidimensional case of differential equation 5). The tridimensional case with a decay or sink term writes T + µ T ) + k T = 0, 7) where µ is the diffusivity coefficient and k is the decay coefficient. In the problem, only the 1D equation is relevant: T T µ 2 + k T = 0. 8) x2 This equation admits solutions under certain initial values and certain boundary conditions google wikipedia heat equation).
2 Finite-difference solvers 4 2 Finite-difference solvers In order to solve numerically equations like equation 8), it is necessary to discretize the derivative operators. After discretizing the derivative operators, it is also useful to have an estimate of the error of the solution. When one knows its analytical solution, then it suffices to compute the RMS root mean square error) in order to know exactly what is the error. However, often, numerical solvers are used because there are no known analytical solution to the PDE partial differential equation), thus there is no alternative but to estimate the error. A traditional approach consists in using constant discrete time steps and constant discrete spatial steps dx combined with the Taylor serie expansion definition of analytical functions [2]. The Taylor serie expansion of an analytical real function forward in its variable coordinate is f t + ) = f n) t) )n 9) n! n=0 and backward in its variable coordinate is f t ) = f n) t) )n. 10) n! 2.1 Explicit method n=0 The Taylor series in equation 9) expanded up to the second order with third order error), f t + ) = ft) + f t) + f t) )2 2 + o ) 3). 11) A first derivative approximation may be obtained from equation 11, f t) = f t + ) f t) + o ). 12) The first derivative approximation in equation 12) yields first order error. This numerical method is often referred to as the explicit method or the forward in time method. Note that o) 3 ) = o) 2 ), o) = o ) = o), are general properties of truncature error operator.
2 Finite-difference solvers 5 2.2 Implicit method Likewise, the Taylor series in equation 10) expanded up to the second order with third order error) yields, f t ) = ft) + f t) ) + f t) )2 2 + o ) 3). 13) A first derivative approximation may be obtained from equation 13, f t) = f t) f t ) + o ). 14) This numerical method is referred to as the implicit method or the backward in time method and is also first order error. 2.3 Mid-point method By subtracting equation 13) from equation 11), the mid-point method is obtained: ft + ) ft ) = f t) 2 + o ) 3), 15) f t) = ft + ) ft ) 2 + o ) 2). 16) Equation 16) is referred to as the mid-point method and has a second order error. 2.4 Second derivative discretization By summing equation 13) from equation 11), a discretization of the second derivative is obtained: ft + ) + ft ) = 2 ft) + f t) ) 2 + o ) 4). 17) Note that the third order terms in the forward and backward Taylor series expansion cancel out. In fact, every odd order term are cancelled when summing the forward and backward Taylor series expansion, whereas its the even terms that are cancelled when subtracting the backward Taylor series from the forward Taylor series. Thus, equation 17) yields f t) = ft + ) 2 ft) + ft ) ) 2 + o ) 2). 18)
3 Discretizing the heat equation 6 3 Discretizing the heat equation The idea is to discretize the heat equation 8) with a numerical scheme forward in time and centred in space FTCS). Thus by using the scheme in equation 12) to the time derivative and by using the numerical scheme in equation 18) to second-derivative in space, equation 8) becomes, in its algebraic form: T x, t + t) T x, t) = t T x + x, t) 2 T x, t) + T x x, t) µ x 2 k T x, t), 19) which in turn yields or even yet, T x, t + t) = T x, t) + µ t T x + x, t) 2 T x, t) + T x x, t)) x2 k t T x, t), 20) T x, t + t) = µ t T x + x, t) x2 + 1 k t 2 µ t ) x 2 T x, t) + µ t T x x, t). 21) x2 The numerical scheme is defined positive and physically realist) if and only if every coefficient affected to T x + x, t), T x, t) and T x x, t) is positive. Which is the case in equation 21) as long as 3.1 the grid 1 k t 2 µ t 1. 22) x2 Consider an even spaced bi-dimensional grid evolving over space by increments of x and over time by increments of t. Each grid point is indexed by integers i in space and n in time. The spatial axis of the grid represents the heated bar. The time axis of the grid represents the temporal evolution
3 Discretizing the heat equation 7 of the heat in the bar. Thus, given the values of temperature in the bar for all values of index i at a given instant n, Ti n, the temperature in the next time instant is Ti n+1 is deduced from equation 21), T n+1 i = Dif Ti+1 n + 1 k t 2 Dif) Ti n + Dif Ti 1, n 23) where, by definition, Dif µ t x 2. 3.2 Boundary conditions For boundary conditions, a null diffusive flux is considered as the heated bar is adiabatically insulated from the environment), thus a special scheme must be considered at the boundary grid points for i = 1 and i = Ni where Ni is the total number of grid points in the spatial axis. i = 1 T1 n+1 = Dif T2 n + 1 k t Dif) T1 n, i = Ni T n+1 Ni = 1 k t Dif) TNi n + Dif TNi 1. n Notice how the central diffusive flux coefficient was cut by half at the boundaries when compared with equation 23). Indeed the net diffusive flux is represented by an ingoing diffusive flux represented by the terms T i+1 and T i 1, and by an outgoing diffusive flux represented by the term T i. Thus, the outgoing diffusive represents the amount of heat from T i that flows to both the neighbour grid points i + 1 and i 1. At the boundaries, however, the outgoing diffusive flux flows to only one neighbouring grid point, thus cutting in half the diffusion that occurs. 3.3 Initial condition Equation 23) calculates T n+1 as a function of T n. Thus, at some point, T 1 needs to be defined. It s called the initial condition. The initial condition will describe an initial state of the modelled bar. 3.4 Continuous emission Suppose that there s an heat source at some point near the bar. This heat source will input heat continuously in the bar. A possible way to model a continuous emission is as follows: first, the regular diffusivity-decay algorithm is employed, T n+1 i = Dif Ti+1 n + 1 k t 2 Dif) Ti n + Dif Ti 1, n
3 Discretizing the heat equation 8 Then, the continous source term C is added at the given grid point, say i = p, Ti n+1 = Ti n+1 i p Ti n+1 = Ti n+1 + C t i = p. References [1] Chapra, S. C. Surface water-quality modeling. Mcgraw-hill Series In Water Resources And Environmental Engineering 1997). [2] Fletcher, C. A. J., and Srinivas, K. Computational Techniques for Fluid Dynamics 1. Springer, 1991.