Docsity

1 Finite difference example: 1D explicit heat equation, Study notes of Thermodynamics

Toggle sidebar
bg1
Excerpt from GEOL557 Numerical Modeling of Earth Systems by Becker and Kaus (2016)
1 Finite difference example: 1D explicit heat equation
Finite difference methods are perhaps best understood with an example. Consider the
one-dimensional, transient (i.e. time-dependent) heat conduction equation without heat
generating sources
ρcp
∂T
∂t=∂
∂xk∂T
∂x(1)
where ρis density, cpheat capacity, kthermal conductivity, Ttemperature, xdistance, and
ttime. If the thermal conductivity, density and heat capacity are constant over the model
domain, the equation can be simplified to
∂T
∂t=κ∂2T
∂x2(2)
where
κ=k
ρcp
(3)
is the thermal diffusivity (a common value for rocks is κ=10−6m2s−1; also see discussion
in sec. ??).
We are interested in the temperature evolution versus time, T(x,t), which satisfies
eq. (2), given an initial temperature distribution (Fig. 1A). An example would be the in-
trusion of a basaltic dike in cooler country rocks. How long does it take to cool the dike
to a certain temperature? What is the maximum temperature that the country rock expe-
riences?
The first step in the finite differences method is to construct a grid with points on
which we are interested in solving the equation (this is called discretization, see Fig. 1B).
The next step is to replace the continuous derivatives of eq. (2) with their finite difference
approximations. The derivative of temperature versus time ∂T
∂tcan be approximated with
a forward finite difference approximation as
∂T
∂t≈Tn+1
i−Tn
i
tn+1−tn=Tn+1
i−Tn
i
∆t=Tnew
i−Tcurrent
i
∆t. (4)
Here, nrepresents the temperature at the current time step whereas n+1 represents the
new (future) temperature. The subscript irefers to the location (Fig. 1B). Both nand iare
integers; nvaries from 1 to nt(total number of time steps) and ivaries from 1 to nx(total
number of grid points in x-direction). The spatial derivative of eq. (2) is replaced by a
central finite difference approximation (cf. sec. ??), i.e.
∂2T
∂x2=∂
∂x∂T
∂x≈
Tn
i+1−Tn
i
∆x−Tn
i−Tn
i−1
∆x
∆x=Tn
i+1−2Tn
i+Tn
i−1
(∆x)2. (5)
See geodynamics.usc.edu/~becker/Geodynamics557.pdf for complete document. 1
pf3
pf4
pf5

Partial preview of the text

Download 1 Finite difference example: 1D explicit heat equation and more Study notes Thermodynamics in PDF only on Docsity!

1 Finite difference example: 1D explicit heat equation

Finite difference methods are perhaps best understood with an example. Consider the one-dimensional, transient (i.e. time-dependent) heat conduction equation without heat generating sources

ρ cp

∂ T

∂ t

∂ x

k

∂ T

∂ x

where ρ is density, cp heat capacity, k thermal conductivity, T temperature, x distance, and t time. If the thermal conductivity, density and heat capacity are constant over the model domain, the equation can be simplified to

∂ T ∂ t

= κ

∂^2 T

∂ x^2

where

κ =

k ρ cp

is the thermal diffusivity (a common value for rocks is κ = 10 −^6 m^2 s−^1 ; also see discussion in sec. ?? ). We are interested in the temperature evolution versus time, T(x, t), which satisfies eq. (2), given an initial temperature distribution (Fig. 1A). An example would be the in- trusion of a basaltic dike in cooler country rocks. How long does it take to cool the dike to a certain temperature? What is the maximum temperature that the country rock expe- riences? The first step in the finite differences method is to construct a grid with points on which we are interested in solving the equation (this is called discretization, see Fig. 1B). The next step is to replace the continuous derivatives of eq. (2) with their finite difference

approximations. The derivative of temperature versus time ∂ ∂ Tt can be approximated with a forward finite difference approximation as

∂ T

∂ t

T in +^1 − Tin tn+^1 − tn^

T in +^1 − Tin ∆ t

Tinew − Ticurrent ∆ t

Here, n represents the temperature at the current time step whereas n + 1 represents the new (future) temperature. The subscript i refers to the location (Fig. 1B). Both n and i are integers; n varies from 1 to nt (total number of time steps) and i varies from 1 to nx (total number of grid points in x-direction). The spatial derivative of eq. (2) is replaced by a central finite difference approximation (cf. sec. ?? ), i.e.

∂^2 T

∂ x^2

∂ x

∂ T

∂ x

Tin+ 1 −Tin ∆ x −^

Tin −Tni− 1 ∆ x ∆ x

Tin+ 1 − 2 Tin + Tin− 1 ( ∆ x)^2

country rockcountry rock dike

x

T(x,0)

A B

space

time

L

boundary nodes

Dx

Dt

i,n

i,n-

i,n+

i-1,n i+1,n

L

Figure 1: A) Setup of the thermal cooling model considered here. A hot basaltic dike intrudes cooler country rocks. Only variations in x-direction are considered; properties in the other di- rections are assumed to be constant. The initial temperature distribution T(x, 0) has a step-like perturbation, centered around the origin with [−W/2; W/2] B) Finite difference discretization of the 1D heat equation. The finite difference method approximates the temperature at given grid points, with spacing ∆ x. The time-evolution is also computed at given times with time step ∆ t.

Substituting eqs. (5) and (4) into eq. (2) gives

T in +^1 − Tin ∆ t

= κ

Tin+ 1 − 2 Tin + Tin− 1 ( ∆ x)^2

The third and last step is a rearrangement of the discretized equation, so that all known quantities (i.e. temperature at time n) are on the right hand side and the unknown quan- tities on the left-hand side (properties at n + 1). This results in:

T in +^1 = Tin + κ∆ t

Tin+ 1 − 2 Tin + Tin− 1 ( ∆ x)^2

Because the temperature at the current time step (n) is known, we can use eq. (7) to com- pute the new temperature without solving any additional equations. Such a scheme is and explicit finite difference method and was made possible by the choice to evaluate the temporal derivative with forward differences. We know that this numerical scheme will converge to the exact solution for small ∆ x and ∆ t because it has been shown to be con- sistent – that its discretization process can be reversed, through a Taylor series expansion, to recover the governing partial differential equation – and because it is stable for certain values of ∆ t and ∆ x: any spontaneous perturbations in the solution (such as round-off error) will either be bounded or will decay.

%heat1Dexplicit.m % % Solves the 1D heat equation with an explicit finite difference scheme clear %Physical parameters L = 100; % Length of modeled domain [m] Tmagma = 1200; % Temperature of magma [C] Trock = 300; % Temperature of country rock [C] kappa = 1e-6; % Thermal diffusivity of rock [m2/s] W = 5; % Width of dike [m] day = 360024; % # seconds per day dt = 1day; % Timestep [s] % Numerical parametersnx = 201; % Number of gridpoints in x-direction nt = 500; % Number of timesteps to compute dx = L/(nx-1); % Spacing of grid x = -L/2:dx:L/2;% Grid % Setup initial temperature profile T = ones(size(x))*Trock; T(find(abs(x)<=W/2)) = Tmagma; time = 0; for n=1:nt % Timestep loop % Compute new temperature Tnew = zeros(1,nx); for i=2:nx- Tnew(i) = T(i) + ?????; end % Set boundary conditions Tnew(1) = T(1); Tnew(nx) = T(nx); % Update temperature and time T = Tnew; time = time+dt; % Plot solution figure(1), clf plot(x,Tnew); xlabel(’x [m]’) ylabel(’Temperature [^oC]’) title([’Temperature evolution after ’,num2str(time/day),’ days’]) drawnow end

Figure 2: MATLAB script heat1Dexplicit.m to solve eq. (2) (once the blanks indicated by the questions marks are filled in... ).

  1. Record and plot the temperature evolution versus time at a distance of 5 m from the dikecountry rock contact. What is the maximum temperature the country rock experiences at this location and when is it reached? Assume that the country rock was composed of shales, and that those shales were transformed to hornfels above a temperature of 600◦C. What is the width of the metamorphic aureole?
  2. Think about how one would write a non-dimensionalized version of the tempera- ture solver.
  3. Add a test with an analytical solution for diffusion and plot error vrs. resolution. A good reference for analytical solutions for heat conduction problems is Carslaw and Jaeger (1959), or see sec. ??. The spatial discretization should be second order for a second order scheme.
  4. Derive a finite-difference approximation for variable k (and variable ∆ x allowing for

uneven spacing between grid points should you so desire). Test the solution for the case of k = 10 inside the dike, and k = 3 in the country rock.