finite element method for 1d transient convective heat ...1223250/fulltext01.pdf · derivation of...

46
Finite Element Method for 1D Transient Convective Heat Transfer Problems Whokko Schir´ en June 24, 2018

Upload: others

Post on 26-Jun-2020

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

Finite Element Method for 1D Transient

Convective Heat Transfer Problems

Whokko Schiren

June 24, 2018

Page 2: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

ii

Acknowledgement

I would like to express my deep gratitude to Bjorn Johannesson andKarl-Olof Lindahl, my supervisors in this thesis work. Without theirvaluable support and advice, their unwavering encouragement and trustand their valuable critique, this work would not have been possible. I alsowant to thank Winston Mmari who has been of great help in bringing thiswork forth and Marko Sobak who’s comments improved the quality of thework.

Finally I would like to thank my family for their great patience andsupport.

Page 3: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

iii

Abstract

We study heat transfer in one dimension with and without convection,also called advection-diffusion. This is done using the Finite ElementMethod (FEM) to discretise the mathematical model, i.e. the heat equa-tion. The results are compared to analytic Fourier series solutions. Ourmain result is that the FEM could be used to better model the heat trans-fer which allow for more accurate models than today’s use of steady statemodels.

Keywords: Advection-Diffusion; Convection; Convection Problems; Fi-nite Element Method; FEM; Transient 1D Heat Equation; Discretisation

Page 4: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

CONTENTS iv

Contents

1 Introduction 1

2 Theory 32.1 From strong formulation to weak . . . . . . . . . . . . . . . . . . 4

2.1.1 1D heat equation without convection . . . . . . . . . . . . 42.1.2 1D heat equation with convection . . . . . . . . . . . . . 5

3 Result and Analysis 73.1 Finite element models . . . . . . . . . . . . . . . . . . . . . . . . 7

3.1.1 Discretisation in space of the 1D heat equation withoutconvection . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

3.1.2 Discretisation in time of the 1D heat equation withoutconvection . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

3.1.3 Discretisation in space of the 1D heat equation with con-vection . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

3.1.4 Discretisation in time of the 1D heat equation with con-vection . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

3.2 Finite element implementation . . . . . . . . . . . . . . . . . . . 173.3 Condition numbers . . . . . . . . . . . . . . . . . . . . . . . . . . 193.4 Analytical solutions . . . . . . . . . . . . . . . . . . . . . . . . . 22

3.4.1 Analytical solution of the 1D heat equation without con-vection . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

3.4.2 Analytical solution for 1D heat transfer with convection . 273.5 Comparison between FEM and analytical solutions . . . . . . . . 28

4 Discussion 31

Appendix A FE-model & analytical, without convection A-1

Appendix B FE-model & analytical, with convection B-1

Appendix C Condition numbers, without convection C-1

Appendix D Condition numbers, with convection D-1

Page 5: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

1 INTRODUCTION 1

1 Introduction

This work focuses on the study of one dimensional transient heat transfer. Thisis of interest to the construction industry as heat and moisture levels are inter-dependent and moisture is a risk factor in buildings. If the relative humiditygets too high we might get moisture problems. The relative humidity dependson the temperature as air with higher temperature can hold more moisture,moisture that risks being turned into condensation if the temperature drops,and if we get condensation, let us say inside a wall, then we have got moistureproblems. Furthermore, we often have different air pressure inside and outsidea building and this difference could affect the temperature distribution insidethe wall as the difference in pressure pushes warm air through the wall, thisphenomenon is called convection, or, in some literature, advection-diffusion. Itis therefore of great interest to simulate the temperature distribution througha wall, with and without convection. We are especially interested in how thetemperature changes over time after a temperature change has been made onone side of the wall and before the steady state situation has been reached.

Every model is an idealisation of the real world and, as George Box put it,”All models are wrong; some are useful” [3, p. 1–10]. We start out with a physicalsystem, heat transfer through a wall, this system we idealise as a mathematicalmodel which we then do a discretisation on using the finite element method,this gives us a discrete solution. As a mathematical model we use the heatequation with and without an added convection term. We discretise the modelusing the Finite Element Method (FEM), this gives us a discrete problem. Westart by deriving the steady state heat balance equation, then we find the strongand the weak formulation for the one dimensional heat equation, in space andtime. This will be done for two cases, with and without convection. In each ofthese steps there could arise errors as we do approximations and simplifications,see Figure 1. The discrete solution could give solution errors, there could be

Figure 1: Simulation process, Figure 6.1 in [3].

discretisation errors given how we have done the discretisation and there couldexist modelling errors depending on the choice of idealisation. Typically thesolution errors will be small compared to the modelling errors which arise when

Page 6: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

1 INTRODUCTION 2

we make a model of a physical system. The only way to check these errors isby comparison to a physical system. This has not been done in this work, weinstead start from a mathematical model to obtain analytical solutions whichwe can compare our discrete solutions against.

A significant part of the work is how to handle the case with convection asthe standard numerical assumptions are not optimal when working with trans-port equations such as the convection equation for heat transfer. In FEM itis common to use the Galerkin method when choosing the weight function, i.e.the weight function is described by the shape function. In another numericalmethod, the finite difference method, the central difference scheme is typicallyused to approximate the state function in the spatial domain. None of thesemethods, the Galerkin method nor the central difference scheme, can correctlysolve the convection equation when the convection velocity is strong comparedto the conduction. In this work we will use the Petrov-Galerkin method asan approach to improve the solutions to the problem with convection. In thePetrov-Galerkin method the weight function is adjusted so that the analyticalsolution for a linear steady state problem is obtained. That is, the weight func-tion is chosen so that the analytical and numerical steady state solutions matchexactly at the nodal points. For this purpose we define a so-called elementPeclet number as a function of the local elements spatial length, the conductionand the convection velocity. For high element Peclet numbers the convectionvelocity is large compared to the other properties included in its definition andthe effect of using a proper weighting becomes more and more important. Weinvestigate the convection equation together with its transient behaviour, thatis, the change of the temperature with time is considered together with theheat capacity. In this work we take a analytical solution of a one dimensionalconvection equation from the literature and compare it to a developed transientfinite element scheme. A part of the problem is that the time stepping scheme isderived for its unconditional stability using standard transport equations with-out convection. This means that for high element Peclet numbers the solutionsmay be polluted by oscillations for implicit stable schemes. In order to investi-gate the overall stability of the scheme different transient numerical simulationresults where produced and compared to the analytical solutions using implicittime integration.

Next we implement our finite element models using MATLAB and check thecondition numbers for the cases with and without convection. We will also useMATLAB to calculate the heat transfer analytically and compare the results tothe results from the FEM implementations.

We found that the FEM is stable and give insight into how temperaturechange over time in one dimension. We also learned that we have to be carefulabout how we choose the integration interval in time for the analytic solutionsas the solution otherwise could get too large solutions errors as it is based on aFourier series and there arise problems due to the truncation of the series.

Now, as promised, we start our journey by deriving the heat equation.

Page 7: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

2 THEORY 3

2 Theory

Derivation of the heat equation

The heat equation for steady state conditions, that is when there is no timedependency, could be derived by looking at an infinitely small part dx of a onedimensional heat conducting body which is heated by a stationary inner heatsource Q. By one dimensional we mean that the body is laterally insulated sothat heat can only flow along the element in the x-direction. We also assumethat the body is thin enough for the temperature to be constant within anygiven cross-section of the body.

According to the law of energy conservation the amount of heat energy Hentering the body must be equal to the amount leaving it, as illustrated inFigure 2, so

H +Q dx = H + dH,

ordH

dx= Q. (1)

A definition of heat isH(x) = A(x)q(x),

where A is the cross-sectional area of the element and q denotes the heat flux,therefore we rewrite (1) as

d

dx(Aq) = Q,

this is the conservation equation.

Figure 2: Heat balance.

Let u (x) be the temperature, k the heat conductivity and ∂u/∂x the changerate of the temperature with respect to the position, then the heat flux is givenby Fourier’s law of heat conduction as

q = −k ∂u∂x. (2)

Page 8: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

2 THEORY 4

To allow for the heat to change with the time t we add a term which takesinto account the time dependency. Let ρ be the density and c the heat capacityor the amount of energy needed to raise the temperature inside the element byone degree. Then

ρc∂u

∂t+

∂x(Aq) = Q. (3)

We now substitute (2) into (3) to obtain the heat equation as

ρc∂u

∂t− ∂

∂x

(Ak

∂u

∂x

)−Q = 0.

We will use this one dimensional heat equation to formulate the strong versionof the problem. We will then reformulate this differential equation with itsboundary conditions in its weak form. This is the form that we will use in thefinite element (FE) approach.

2.1 From strong formulation to weak

In this section we do as in [8] and go from a so called strong form, consistingof a differential equation with boundary conditions, to a weak form needed forthe FE approach.

2.1.1 1D heat equation without convection

Strong form

In our specific problem there is no internal heat source, therefore Q = 0 whichresults in the following strong form of the one-dimensional heat flow

ρc∂u

∂t=

∂x

(Ak

∂u

∂x

), (0 ≤ x ≤ L, t ≥ 0) , (4)

with boundary conditions

u (0, t) = a, u (L, t) = b.

As an initial condition we will use

u (x, 0) = 0.

The boundary conditions a and b are considered known constants. Next wesearch for the weak formulation of the strong form.

Weak form

We want to lower the degree of the right hand side of (4). This is achievedby multiplying the strong form with a weight function and integrating over theproblem domain, then by the use of Green-Gauss theorem we can separate theright hand side into two parts.

Page 9: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

2 THEORY 5

We start by multiplying the differential equation (4) by two weight functionsv(x) and w (t), one for the spatial domain and one for the time domain, and thenintegrate over each domain. This gives the following integrals,∫ L

0

v(x)ρc∂u

∂tdx =

∫ L

0

v(x)∂

∂x

(Ak

∂u

∂x

)dx (5)

and ∫ ∆t

0

w (t)

∫ L

0

v(x)ρc∂u

∂tdx dt =

∫ ∆t

0

w (t)

∫ L

0

v(x)∂

∂x

(Ak

∂u

∂x

)dx dt.

We will use the first integral here, the second one will be used later in thediscretisation in time. Integrate the right hand side of (5) using integration byparts to get∫ L

0

v(x)∂

∂x

(Ak

∂u

∂x

)dx =

[v(x)Ak

∂u

∂x

]L0

−∫ L

0

∂v

∂x

(Ak

∂u

∂x

)dx. (6)

In two or three dimension problems we would instead use the Green–Gausstheorem. Next substitute for (6) in (5) and rearrange the result to obtain∫ L

0

v(x)ρc∂u

∂tdx +

∫ L

0

∂v

∂x

(Ak

∂u

∂x

)dx =

[v(x)Ak

∂u

∂x

]L0

. (7)

Remembering that q denotes the flux allows for replacing(k ∂u∂x

)by −q to get∫ L

0

v(x)ρc∂u

∂tdx +

∫ L

0

∂v

∂x

(Ak

∂u

∂x

)dx = − [v(x)Aq]

L0 .

This equation together with the same boundary conditions as before,

u (0, t) = a, u (L, t) = b,

make up the weak formulation of the one-dimensional heat equation. This weakformulation will be the basis for our finite element formulation of the problem,found in Section 3.1.1.

2.1.2 1D heat equation with convection

Strong formulation

We know from the previous Section that

ρc∂u

∂t=

∂x

(Ak

∂u

∂x

),

where the left hand side is the transient part and the right hand is a diffusionterm. In this section we put A = 1 and add convection to the equation asdescribed in [10, pp. 13–15],

ν∂u

∂x+ ρc

∂u

∂t=

∂x

(k∂u

∂x

), (0 ≤ x ≤ L, t ≥ 0) , (8)

Page 10: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

2 THEORY 6

the first term describes the transport of the quantity u by convection in a fieldof velocity ν. Equation (8) together with boundary conditions

u (0, t) = a, u (L, t) = b,

make up the strong formulation of our problem.

Weak formulation

As before we leave everything connected to time until the discretisation in time,Section 3.1.4, instead now we multiply by the weighting function v(x) and inte-grate, ∫ L

0

v(x) ν∂u

∂xdx +

∫ L

0

v(x)ρc∂u

∂tdx =

∫ L

0

v(x)∂

∂x

(k∂u

∂x

)dx. (9)

We then use integration by parts on the right hand side to get∫ L

0

v(x)∂

∂x

(k∂u

∂x

)dx =

[v(x)k

∂u

∂x

]L0

−∫ L

0

∂v

∂x

(k∂u

∂x

)dx

which we put back into equation (9) and rearrange the terms to get our weakformulation as∫ L

0

v(x) ν∂u

∂xdx +

∫ L

0

v(x)ρc∂u

∂tdx+

∫ L

0

∂v

∂x

(k∂u

∂x

)dx =

[v(x)k

∂u

∂x

]L0

.

Remembering that −q =(k ∂u∂x

)let us rewrite this as∫ L

0

v(x) ν∂u

∂xdx +

∫ L

0

v(x)ρc∂u

∂tdx+

∫ L

0

∂v

∂x

(k∂u

∂x

)dx = − [v(x)Aq]

L0 . (10)

This weak formulation, together with the same initial condition and boundaryconditions as in Section 2.1.1, will be used in our finite element formulation ofthe one-dimensional heat equation with convection found in Section 3.1.3.

Page 11: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

3 RESULT AND ANALYSIS 7

3 Result and Analysis

3.1 Finite element models

We will now find the finite element formulations for one-dimensional heat flowwith and without convection, we use the method presented in [8].

In the Finite Element Method, complex systems described by general dif-ferential equations can be solved approximately by dividing the system into anumber of small elements where the state for each element can be fairly simplycalculated. By this we mean that even if a variable varies non-linearly over theglobal system it could be an acceptable approximation to say that it varies lin-early over each local element, if the size of the elements is small enough. Whenwe have decided the behaviour for all of these small elements they could be puttogether into a larger system approximately describing the whole system.

3.1.1 Discretisation in space of the 1D heat equation without con-vection

In our case we deal with one dimensional heat transfer and so we divide ourglobal system of length L into a number of local elements of equal length h asin Figure 3. The points i, j, k and l are called nodes. To decide the tempera-

Figure 3: Global system divided into local elements.

ture over each of these elements we interpolate between the nodes using shapefunctions, later in this section we will get back to how the shape functions aredefined. Let the approximation of the temperature in an element be equal to

u (x, t) = Na.

Both N and a are vectors,

N =[Ni Nj

], a =

[uiuj

],

N denotes the shape functions and a the nodal temperatures of an element.The derivative of the temperatures with respect to the position, that is thetemperature gradient, is

∂u

∂x=

∂x(Na) = Ba,

Page 12: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

3 RESULT AND ANALYSIS 8

where B = ∂xN and a is independent of x. If the derivative instead is takenwith respect to time, noting that N is independent of time, then the expressionbecome

∂u

∂t=

∂t(Na) = N

∂a

∂t= Na.

The weight function v(x) is a scalar, therefore v must be equal to vT and theweight function can be approximated as

v (x) = Nc = cTNT = vT,

where N still denotes the shape functions and c is an arbitrary non-zero vector.This choice of weight function is in accordance with the Galerkin method wherethe test functions are put equal to the shape functions. For more information onweight functions and why the Galerkin method is a good choice see [8, pp. 142–156]. The derivative of the weight function is

∂v

∂x= cT

∂NT

∂x= cTBT.

Each shape function has the property that it is equal to one at the node itcontrols and equal to zero in all other nodes, see Figure 4. In this case everythingis one dimensional and we choose linear shape functions, if an element has lengthh and goes from node 1 to 2 then

N e1 = 1− x

h, (0 ≤ x ≤ h),

N e2 =

x

h, (0 ≤ x ≤ h),

the superscript e denotes that these shape functions are for a local element. Theshape function vector for the studied case is

N =[1− x

h

x

h

],

which results in

B =

[−1

h

1

h

].

The temperature vector is

a =

[u1

u2

],

where u1 and u2 are temperatures at the nodes 1 and 2.Substituting for u, ∂u

∂x , ∂u∂t , v, and ∂v

∂x in (7) gives the following equation∫ h

0

cTNTρcNa dx +

∫ h

0

cTBTAkBa dx = −[cTNTAq

]h0.

Next, we eliminate cT, this is allowed as cT is an arbitrary non-zero vector. Weare left with ∫ h

0

NTρcNa dx +

∫ h

0

BTAkBa dx = −[NTAq

]h0

Page 13: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

3 RESULT AND ANALYSIS 9

Figure 4: Linear element shape functions.

which could be written in a compact form as

Ca + Ka = f (11)

with

C =

∫ h

0

NTρcN dx,

K =

∫ h

0

BTAkB dx,

f = −[NTAq

]h0,

where C is called the damping matrix, K the stiffness matrix, or more accuratelythe conductivity matrix, and f the force vector. Note that if the force vector issimplified we end up with

f = Aq

[1−1

].

In this section we set up the system of linear equations for an element but(11) is easily expanded to apply to a global system of linear equations. Asan example let us take the stiffness matrix K and expand it to fit the systemshown in Figure 3. We ignore all constants for the sake of the argument, thenthe stiffness of a local element is

Ke =

[1 −1−1 1

],

where the superscript e clarifies that this is indeed the stiffness of a local element.Then for the global system we assemble the local stiffness matrices based onour knowledge about the elements location in the global system. We know thatelement one go from node i to j, element two go from node j to k, and so on.

Page 14: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

3 RESULT AND ANALYSIS 10

For the system in Figure 3 we get the global stiffness matrix

K =

1 −1 0 0−1 2 −1 00 −1 2 −10 0 −1 1

,and

Ka =

1 −1 0 0−1 2 −1 00 −1 2 −10 0 −1 1

uiujukul

.The global damping matrix and force vector are assembled similarly. This wayof assembling the global systems of linear equations will be applied to all FEMin this work.

It is now time to integrate with respect to time. The force vector f could bea function of time but that case will not be considered here and now, only a(t)and a(t) are considered.

3.1.2 Discretisation in time of the 1D heat equation without con-vection

We want to find a discretisation in time. We consider the temperature an attime tn as known, and let ∆t be a finite time increment, then we are searchingfor the temperature an+1 at time tn+1 = tn + ∆t, [9, pp. 494–495]. We also letτ be normalised time such that it is set to zero at time tn and is equal to ∆t attime tn+1. If t is the actual time then the time variable τ = t − tn, [5, p. 195].The shape functions with respect to time should be such that Nn = 1 at time n

Figure 5: Visualisation of the time discretisation, Figure 18.1 in [9].

and equal to zero at all other time steps, and Nn+1 = 1 at time n+ 1 and equal

Page 15: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

3 RESULT AND ANALYSIS 11

to zero at all other time steps, as in [5, pp. 195–196]. Then the shape function

vector N take the form

N =[1− τ

∆t

τ

∆t

], (0 ≤ τ ≤ ∆t).

The approximation of the temperature at the nodes, depending on time, thenis

a(τ) = Nnan + Nn+1an+1.

Substituting for the shape functions gives the temperature with respect to timeas

a(τ) =(

1− τ

∆t

)an +

( τ

∆t

)an+1. (12)

The derivative of a(t) with respect to time is

a(τ) =d

[(1− τ

∆t

)an

]+

d

[( τ

∆t

)an+1

]= −

(1

∆t

)an +

(1

∆t

)an+1

=an+1 − an

∆t.

(13)

Substituting (12) and (13) into (11) yields

C

(an+1 − an

∆t

)+ Kan −

τ

∆tKan +

τ

∆tKan+1 = f.

Next we multiply by the weighting function w (τ) and integrate over the timestep ∆t to get∫ ∆t

0

w (τ)C

(an+1 − an

∆t

)dτ +

∫ ∆t

0

w (τ)Kan dτ −∫ ∆t

0

w (τ)τ

∆tKan dτ

+

∫ ∆t

0

w (τ)τ

∆tKan+1 dτ =

∫ ∆t

0

w (τ) f dτ.

We then divide the above expression by∫∆t

0w (τ) dτ to obtain

C

(an+1 − an

∆t

)+Kan−

(∫∆t

0w (τ) τ

∆t dτ∫∆t

0w (τ) dτ

)Kan+

(∫∆t

0w (τ) τ

∆t dτ∫∆t

0w (τ) dτ

)Kan+1 = f,

which if

Θ =

∫∆t

0w (τ) τ

∆t dτ∫∆t

0w (τ) dτ

, (14)

could be rewritten as

C

(an+1 − an

∆t

)+ Kan −ΘKan + ΘKan+1 = f.

Page 16: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

3 RESULT AND ANALYSIS 12

Assuming that an is a known temperature at time n we search for the temper-ature an+1 after a certain time has passed. Expanding the terms and collectinglike terms we get(

C

∆t+ ΘK

)an+1 =

(C

∆t−K (1−Θ)

)an + f.

As an is a known temperature and the only unknown is an+1, this could begeneralised as

K∗an+1 = f∗, (15)

where

K∗ =C

∆t+ ΘK,

f∗ =

(C

∆t−K (1−Θ)

)an + f

and

C =

∫ h

0

NTρcN dx,

K =

∫ h

0

BTAkB dx,

f = −[NTAq

]h0

as before. Note that the matrices C and K are symmetric. Also remember thatthe force does not depend on time, therefore if we simplify the force vector westill get

f = Aq

[1−1

]as in Section 3.1.1. In Section 3.2 we will make a finite element implementationof (15) to study the heat transfer without convection.

3.1.3 Discretisation in space of the 1D heat equation with convection

In this section we add convection to our one dimensional problem. This will leadto non-symmetrical stiffness matrices that can not be made symmetric with thestandard Galerkin weighting used in Section 3.1.1, [10, p. 14]. To find a solutionfor this we will first study an example to understand where the Peclet numbercomes from, we will then introduce another weighting function to take care ofthe problem with non-homogeneous stiffness matrices, [10, pp. 15–20].

Symmetric matrices should not be an absolute necessity to find a solution forthe system of algebraic equations, but it simplifies the numerical computationsso that the system of algebraic equations is more efficiently solved by computers.It is therefore common to change weighting function so that symmetric matricesare obtained.

Page 17: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

3 RESULT AND ANALYSIS 13

Standard steady state FE formulation

We use the same approximations as in Section 3.1.1, that is

u (x, t) = Na∂u

∂x= Ba

∂u

∂t= Na

v (x) = Nc = cTNT = vT∂v

∂x= cTBT ,

and substitute into (10) to obtain

cT

(∫ h

0

NT νBa dx +

∫ h

0

NT ρcNa dx +

∫ h

0

BT kBa dx = −[NT q

]h0

).

Remember that we let A = 1 for the case with convection. As cT is a arbitraryvector we can eliminate it and are left with∫ h

0

NT ρcNa dx +

(∫ h

0

BT kB dx +

∫ h

0

NT νB dx

)a = −

[NT q

]h0.

Observe that the expression in parentheses in front of a is non-symmetric as

NTB is non-symmetric. Put the convection matrix K =∫ h

0NT νB dx. Then,

using K together with C, K and f as defined at the end of Section 3.1.2, weobtain

Ca +(K + K

)a = f. (16)

This is the system that we want to solve and many solutions have been suggestedand considered to find a solution for the non-symmetric part. For simplicity wewill refer to the matrices K and K as stiffness matrices even though they haveslightly different functions in our model.

We want to find a solution to the problem with the non-symmetry and startby studying a simple example of the steady state version of (16). As done in [5,p. 183] we put the right hand side equal to zero,(

K + K)a = 0. (17)

Assume that we have only two elements with length h, and u1, u2 and u3 aregiven temperatures at the nodes 1, 2 and 3. From the definition of the stiffnessmatrices K and K we get

Ke + Ke

=k

h

[1 −1−1 1

]+ν

2

[−1 1−1 1

],

the superscript e denotes that this is the stiffness for a local element. Weassemble the global stiffness matrix and (17) take the form

(K + K

)a =

k

h

1 −1 0−1 2 −10 −1 1

2

−1 1 0−1 0 10 −1 1

u1

u2

u3

= 0.

Page 18: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

3 RESULT AND ANALYSIS 14

We then consider the middle row to assemble the equation for node 2 as

k

h(−u1 + 2u2 − u3) +

ν

2(−u1 + u3) = 0,

a formulation typical for the finite difference method. We multiply by h/k

(−u1 + 2u2 − u3) +νh

2k(−u1 + u3) = 0.

The parameter Pe = νh2k stem from the finite difference method and is called

the element Peclet number, [10, p. 16], [5, p. 183]. Different values of the Pecletnumber have been studied, tested and compared to analytical solutions of theproblem. If Pe = 0, i.e. if ν = 0, then we have a purely diffusive problem, andif Pe = ∞ we have a purely convective problem [10, p. 18]. It has also beenobserved that if |Pe| ≥ 1 then the solution becomes unstable and no exact nodalvalues can be obtained [10, p. 19]. In the next Section we will study a solutionto this problem.

Optimal steady state FE formulation

Until now we have used the approximation u (x, t) = Na and the standardGalerkin weighting v (x) = Nc. To solve the problem with non-symmetric stiff-ness matrix we will do as suggested in [10, p. 18] and change to a Petrov-Galerkintype of weighting function to find a solution for (16). This is possible as we havelinear shape functions. We start by studying the weight for a single node i, put

υi(x) = Ni + αw i (x) ,

where Ni is a shape function and w i(x) is such that∫ h

0

w i(x) dx = ±h

2,

the sign depend on the direction of the velocity ν. We will get back to theconstant α later in this Section.

The weighting function could be chosen in many ways, but according to [10,p. 19] the most convenient way is to define υi as

υi(x) = Ni + αh

2

dNidx

(sign ν),

where w i(x) becomes h2

dNidx and sign ν reminds us that w i could be positive

or negative depending on the direction of the velocity. Remember that it hasbeen observed that the solution becomes unstable if |Pe| ≥ 1, see the previousSection. According to [10, p. 19] and [2, p. 1393] it is possible to choose anoptimal value of α so that we get exact nodal values for all values of Pe, thisoptimal value is obtained if

|α| = αopt = coth |Pe| − 1

|Pe|.

Page 19: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

3 RESULT AND ANALYSIS 15

To get the sign of ν we multiply the second term of υ with γ = ν/|ν|. The fullexpression for the weighting function is

υ(x) =

(N + αopt

h

2

dN

dxγ

)c

or

υT (x) = cT

(NT + αopt

h

2

dNT

dxγ

)= cT

(NT + αopt

h

2BT γ

).

Observe that∂υ

∂x= cTBT

as the second term of υ is a constant and therefore will be zero when we takethe derivative.

We substitute for this new weighting function in (10), letting

u(x, t) = Na∂u

∂x= Ba

∂u

∂t= Na

as always, this yields the following weak formulation, note that we have elimi-nated cT as before,∫ h

0

(NT + αopt

h

2BT γ

)νBa dx +

∫ h

0

(NT + αopt

h

2BT γ

)ρcNa dx

+

∫ h

0

BT kBa dx = −[(

NT + αopth

2BT γ

)q

]h0

.

This could, as in Section 3.1.1, be reformulated as the finite element formulation

Ca +(K + K

)a = f, (18)

with a different damping matrix

C =

∫ h

0

NT ρcN dx +

∫ h

0

αopth

2BT γρcN dx

=ρch

6

[2 11 2

]+ αopt

h

4BT γρc

[−1 −11 1

],

and conductivity matrix

K =

∫ h

0

BT kB dx =k

h

[1 −1−1 1

],

and the convection matrix

K =

∫ h

0

NT νB dx +

∫ h

0

αopth

2γBT νB dx

2

[−1 1−1 1

]+ αoptγ

ν

2

[1 −1−1 1

].

The discretisation, (18), is our discretisation in the spatial domain, next wesearch for a discretisation of (18) in the time domain.

Page 20: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

3 RESULT AND ANALYSIS 16

3.1.4 Discretisation in time of the 1D heat equation with convection

We start by multiplying (18) with a time weighting function,∫ ∆t

0

w (τ)Ca dτ +

∫ ∆t

0

w (τ)(K + K

)a dτ −

∫ ∆t

0

w (τ) f dτ = 0. (19)

We use the same approximations as we did for the time discretisation in Section3.1.2,

a(τ) = Na =[

1− τ∆t

τ∆t

] [ anan+1

]=(

1− τ

∆t

)an +

τ

∆tan+1

and

a(τ) =∂

∂τ

(Na)

=[ −1

∆t1

∆t

] [ anan+1

]=

an+1 − an∆t

,

and substitute the approximations into (19) to yield∫ ∆t

0

w (τ)Can+1 − an

∆tdτ +

∫ ∆t

0

w (τ)(K + K

)[(1− τ

∆t

)an +

τ

∆tan+1

]dτ

−∫ ∆t

0

w (τ) f dτ = 0.

If we again divide throughout with∫∆t

0w (τ) dτ and let

Θ =

∫∆t

0w (τ) τ

∆t dτ∫∆t

0w (τ) dτ

,

then

Can+1 − an

∆t+(K + K

)(an + Θ (an+1 − an)) = f.

We collect like terms and end up with[C

∆t+ Θ

(K + K

)]an+1 =

[C

∆t− (1−Θ)

(K + K

)]an + f,

which is generalised asK∗an+1 = f∗, (20)

where

K∗ =C

∆t+ Θ

(K + K

)f∗ =

[C

∆t− (1−Θ)

(K + K

)]an + f.

The system of linear equations (20) is the system that we will make a MATLABimplementation for in the next Section.

Page 21: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

3 RESULT AND ANALYSIS 17

3.2 Finite element implementation

In this section we are going to study the MATLAB implementations for heattransfer with and without convection and present the results.

In the weak formulations (15) and (20), which we are going to make finiteelement models of, there is a parameter Θ that we have to choose. We usethe Galerkin type 2 scheme which is one of the possibilities given in [5, p. 197]and put w = τ/∆t and calculate the integral (14). We find that Θ = 2/3when w = τ/∆t. We could have chosen w differently, the solutions will beunconditionally stable for 0.5 ≤ Θ ≤ 1 and for Θ = 0 we get a conditionallystable solution which requires certain criteria to be fulfilled for the length of thetime step, [5, p. 197].

The sets of parameter values used in the FE-models have been chosen toreflect how the analytic solutions, found in Section 3.4.1 and 3.4.2, are derived.This has been done to make it possible to make comparisons between the finiteelement implementations and the analytical solutions. For the FE-model for 1Dheat transfer without convection the following set of parameters has been used:length L = π, heat conductivity k = 5 × 10−13, density ρ = 1, heat capacityc = 1 and total time T = 1.7× 1012. For the model with convection we insteaduse: length L = 1, heat conductivity k = 1, density ρ = 1, heat capacity c = 1,convective velocity ν = 10 and total time T = 0.2.

MATLAB is a program built to handle matrix manipulations effectively.There are a lot of toolboxes available to be used together with MATLAB and inour implementation we use two functions from the CALFEM toolbox, namelyassem.m and SOLVE.m. The purpose of assem.m is to assemble element ma-trices, such as the stiffness matrices, into a global matrix. The order of theassembly is decided by a topology matrix called edof in which the degrees offreedom are specified. The function SOLVE.m solve systems of linear equationstaking stiffness matrices, load vectors and boundary conditions as input data.

From executing the implementation found in Appendix A we get the plotsin Figure 6 and 7. In Figure 6a we have divided the total time into ten steps,in Figure 6b we used one hundred time steps. We can see that we have notyet reached the steady state, but in Figure 7 we have increased the time fromT = 1.7× 1012 to T = 1.7× 1013 and reached the steady state distribution.

In Appendix B we find the code for the implementation of (20), that is theconvection dominated heat equation. The execution result in the plot presentedin Figure 8. We can observe how the heat, over time, is pushed through thewall by the difference in pressure on either side of the wall.

Page 22: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

3 RESULT AND ANALYSIS 18

(a) Ten time steps in [0, 1.7 × 1012].(b) One hundred time steps in [0, 1.7×1012].

Figure 6: FEM solutions with different number of time steps, without convec-tion. The leftmost curve correspond to the shortest time step in each plot. Totaltime t = 1.7× 1012 for both plots.

Figure 7: FEM solution without convection, steady state. One hundred timesteps in [0, 1.7×1013]. The leftmost curve correspond to the shortest time step.

Figure 8: FEM solution with convection, one hundred time steps in [0, 0.2].The shortest time step give the leftmost curve.

Page 23: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

3 RESULT AND ANALYSIS 19

3.3 Condition numbers

To check the stability of our finite element models we calculate the conditionnumbers of the stiffness matrices. We do this in two ways, using the theoret-ical condition number, cond(A), found in MATLAB, and by constructing anexperimental condition number, econd(A), [7].

Experimental condition number

Let A be an invertible matrix. The experimental condition number is con-structed by solving a system of linear equations Ax = b, then letting b be avector of small random perturbations of b we solve the system again, Ax = b,where x is the solution to the perturbated system. The perturbation b = b+ dwhere d is a vector of random disturbances and each element in d belong to[−0.0005 b, 0.0005 b]. We then calculate econd(A) as

econd(A) =||x− x||/||x||||b− b||/||b||

where ||x|| stand for the norm of x.

Comparison between condition numbers

The results from the calculation of analytical condition numbers, cond(A), andexperimental condition numbers, econd(A), could be compared through plot-ting. All figures in this section come from executing the programs found inappendices C and D. For different executions of the program econd(A) we willget slightly different plots as seen in Figures 9, 10 and 11. Each plot consist ofthe results from three to four executions of the program, in the plots a, b, c andd stand for different executions of the program. We note that the results aresimilar regardless of the random perturbation.

(a) Witout convection. (b) With convection.

Figure 9: Experimental condition numbers, the number of elements and timesteps are equal. Curves a, b, and c are generated by different executions of theFE implementations.

Page 24: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

3 RESULT AND ANALYSIS 20

First we let the number of elements and the time steps increase equally,Figure 9. Next we let the time step be constant and equal to 10 and let thenumber of elements increase, Figure 10. Last we keep the number of elementsfixed to 10 while we let the number of time steps increase. All of the plots gotowards zero except in Figure 11. A problem would be considered ill-conditionedif econd >> 1. Even when the experimental condition number does not gotowards zero, as in Figure 11, it does not get much larger than 1 and so thesystem is considered well-conditioned. There is a rule of thumb saying thatif econd(A) = 10k then the size of the error, coming from how well- or ill-conditioned the problem is, could be up to k digits.

(a) Witout convection. (b) With convection.

Figure 10: Experimental condition numbers, the number of time steps are fixed.The curves a, b and c are generated by different executions of the FE imple-mentations.

(a) Witout convection. (b) With convection.

Figure 11: Experimental condition numbers, the number of elements are fixed.Curves a to d are generated by different executions of the FE implementations.

We also check the analytical condition numbers given by the built in MAT-LAB function cond(A), Figures 12, 13 and 14. We use the same procedure, firstwe let the number of elements and time steps increase equally, Figure 12. This

Page 25: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

3 RESULT AND ANALYSIS 21

give less satisfactory results where the condition number for the case with con-vection gets larger than 200. We are also using fewer number of elements andtime steps when calculating the analytical condition numbers as the matricesotherwise get too big for the MATLAB function, cond(A), to handle. Next wekeep the number of elements fixed to ten and let the time steps increase, Figure13, this give condition numbers of size 4–5 for one hundred time steps. Last wekeep the number of time steps fixed to ten and increase the number of elements,then we get large condition numbers, Figure 14, above 10 000 for the FE modelwithout convection and above 25 000 for the model with convection.

The experimental condition number could be considered a more accurateindication of whether the problem is well-conditioned or not [6]. Therefore wedo not put so much importance on the results given by cond(A) but considerthe FEM implementations well-conditioned.

(a) Witout convection. (b) With convection.

Figure 12: Analytical condition numbers, the number of elements and time stepsare equal

(a) Without convection. (b) With convection.

Figure 13: Analytical condition numbers, the number of elements are fixed.

Page 26: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

3 RESULT AND ANALYSIS 22

(a) Without convection. (b) With convection.

Figure 14: Theoretical condition numbers, the number of time steps are fixed.

3.4 Analytical solutions

3.4.1 Analytical solution of the 1D heat equation without convection

In this section we will assume that A is a constant. Our one dimensional tran-sient heat problem with boundary conditions then become:

∂u

∂t= Ak

∂ 2u

∂x 2(0 ≤ x ≤ L, t ≥ 0) (21)

u(0, t) = u0, u(L, t) = 0, u(x, 0) = 0, (0 ≤ x ≤ L) . (22)

Initially we change the boundary conditions to

u(0, t) = 0, u(L, t) = u0, u(x, 0) = 0, (0 ≤ x ≤ L) (23)

as these boundary conditions are easier to work with. Then in the end we willmake the variable change x1 = L−x and substitute x for x1 in our final equationto get the same boundary conditions as in (22).

We try to use separation of variables to solve the problem. Put

u(x, t) = X(x)T (t).

Then (21) takes the form

X(x)T ′(t) = AkX ′′(x)T (t). (24)

From this we getT ′

AkT=X ′′

X= −λ,

where −λ is a constant also known as the eigenvalue of (24). We could restatethe above as

T ′ + AkλT = 0,

X ′′ + λX = 0.

Page 27: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

3 RESULT AND ANALYSIS 23

Solving this system, for the cases λ = 0, λ = −α2 and λ = α2, yields trivialsolutions for the first two cases but for λ = α2 we get the solution

X(x) = bn sinnπx

L,

T (t) = e−n2π2

L2 Akt,

(25)

where we have substituted for α = nπL , bn are constants and (n = 1, 2, ...). We

recognise λ = n2π2

L2 as the eigenvalue of the problem, and the correspondingsolutions X(x) are called the eigenfunctions. Next we check if the separation ofvariables fulfils the conditions given in (23). The first boundary condition

u(0, t) = X(0)T (t) = 0

will be satisfied if X(0) = 0 as T (0) 66= 0. The second boundary condition

u(L, t) = X(L)T (t) = u0

is non-homogeneous, therefore ordinary separation of variables will not give asolution. Instead, as in [1, p. 132], we change the problem into a problemwith homogeneous boundary conditions with an extra term taking care of thenon-homogeneity

u(x, t) = U(x, t) + Φ(x)

which allows us to rewrite (21) as

∂U

∂t= Ak

[∂ 2U

∂x 2+ Φ′′(x)

]with boundary conditions

u(0, t) = U(0, t) + Φ(0) = 0,

u(L, t) = U(L, t) + Φ(L) = u0,

U(x, 0) + Φ(x) = 0, (0 ≤ x ≤ L) .

Suppose that the following is true,

Φ′′ = 0, Φ(0) = 0 and Φ(L) = u0, (26)

then U fulfils the boundary conditions and we have

∂U

∂t= Ak

∂ 2U

∂x 2, U(0, t) = U(L, t) = 0 and U(x, 0) = −Φ(x).

The conditions (26) lead to the following equation,

Φ(x) = u0x

L.

Page 28: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

3 RESULT AND ANALYSIS 24

Recall that, as explained in [1, pp. 130–131], the corresponding problem withhomogeneous boundary conditions u(0, t) = u(L, t) = 0 has the solution

u(x, t) =

∞∑n=1

bne−n2π2

L2 Akt sinnπx

L, (27)

possibly including a non-homogeneous initial condition u(x, 0) = f(x). Notethat this solution also corresponds with (25). We put f(x) = U(x, 0) = −Φ(x) =−u0

L x, note that this is an odd function of x and therefore let

f(x) =

∞∑n=1

bn sinnπx

L(0 < x < L),

where

bn =2

L

∫ L

0

f(x) sinnπx

Ldx (n = 1, 2, 3...), (28)

see [1, p. 84]. Also let us assume that f(x) is piecewise smooth on the interval0 < x < L.

Note that (27) together with (28) give a formal solution to (21) with bound-ary conditions U(0, t) = U(L, t) = 0. To fulfil the actual boundary conditionswe remember that

f(x) = U(x, 0) = −Φ(x) = −u0x

L(29)

and insert this into (28) to get the coefficients, bn. This gives

bn =2

L

∫ L

0

f(x) sinnπx

Ldx = −2u0

L2

∫ L

0

x sinnπx

Ldx. (30)

Integration by parts of the integral results in∫ L

0

x sinnπx

Ldx =

[− L

nπx cos

nπx

L+

L2

n2π2sin

nπx

L

]L0

.

We insert the solution into (30) to calculate our bn as

bn = −2u0

L2

[− L

nπx cos

nπx

L+

L2

n2π2sin

nπx

L

]L0

= −2u0

L2

(− L

nπL cos

nπL

L+

L2

n2π2sin

nπL

L− (−0 + 0)

)=

2u0

(cosnπ − sinnπ

).

Considering that n = 1, 2, 3, ... we get

bn =2u0

π

(−1)n

n(31)

Page 29: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

3 RESULT AND ANALYSIS 25

and equation (31) inserted into (27) gives

U(x, t) = X(x)T(t)

=

∞∑n=1

bne−n2π2

L2 Akt sinnπx

L

=

∞∑n=1

2u0

π

(−1)n

ne−

n2π2

L2 Akt sinnπx

L.

(32)

Finally combining (29) and (32) results in the sought after expression

u(x, t) = Φ(x) + U(x, t)

=u0

πx +

2u0

π

∞∑n=1

(−1)n

ne−

n2π2

L2 Akt sinnπx

L.

Last of all we do our change of variables to get the equation to fulfil the wantedboundary conditions u(0, t) = u0 and u(L, t) = 0,

u(x1, t) =u0

π(L− x) +

2u0

π

∞∑n=1

(−1)n

ne−

n2π2

L2 Akt sinnπ (L− x)

L. (33)

We let u0 = 1 and plot (33) in MATLAB, the result can be seen in Figure 15.In Figure 15a only one time step has been used, in Figure 15b the total time,t = 1.7× 10 12, has been divided into ten time steps and in Figure 15c there areone hundered time steps. If we let the time increase then we will eventually cometo the steady state distribution as in Figure 16, here we used T = 1.7× 1013.

In Section 3.5 the analytical results will be compared to the FEM resultsfrom Section 3.2.

Page 30: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

3 RESULT AND ANALYSIS 26

(a) One time step. (b) Ten time steps.

(c) One hundred time steps.

Figure 15: Analytical solution without convection with different number of timesteps. The total time is equal 1.7× 10 12 for all three plots.

Figure 16: Analytic solution without convection, steady state, one hundred timesteps. Total time 1.7× 10 13.

Page 31: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

3 RESULT AND ANALYSIS 27

3.4.2 Analytical solution for 1D heat transfer with convection

We use the method presented in [4, p. 3300].We add a convective term to the problem solved in Section 3.4.1 which give

us the following equation to consider

ν∂u

∂x+ ρc

∂u

∂t= k

∂2u

∂x2. (34)

The initial boundary conditions are the same as before,

u(0, t) = u0, u(L, t) = 0, u(x, 0) = 0,

for this version of the problem we let L = 1. As the first boundary conditionis non-homogeneous we have to define a filter function to obtain homogeneousboundary conditions. We find this filter function through the steady state ver-sion of equation (34),

kd 2U

dx 2− ν dU

dx= 0, (35)

and we choose the boundary conditions to be

U(0) = 1, U(1) = 0.

Suppose that U(x) = erx, insert this into equation (35) to find the characteristicequation,

kr2 − νr = 0

which has the solutions r1 = 0 and r2 = ν/k. These solutions lead to the generalsolution for (35),

U(x) = c1e0 + c2e

νxk .

To find the particular solution we take the boundary conditions into considera-tion and obtain to the following system of linear equations{

1 = c1 + c2

0 = c1 + c2eνk ,

which has solutions

c1 = − eνk

1− e νk, c2 =

1

1− e νk

and lead to the particular solution

U(x) =eνk x − e νk1− e νk

,

or, if we multiply both nominator and denominator by −e−ν/k,

U(x) =1− e− νk (1−x)

1− e− νk,

Page 32: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

3 RESULT AND ANALYSIS 28

which is how the solution is presented in [4].It is straight forward to verify that (36) solve (34), [4, pp. 3300–3301],

u(x, t) = eν2k x−

ν2

4kR t∞∑n=1

Ψn(x)e−µ2nR t fn + U(x). (36)

With U(x) spelled out (36) become

u(x, t) = eν2k x−

ν2

4kR t∞∑n=1

Ψn(x)e−µ2nR t fn +

1− e− νk (1−x)

1− e− νk, (37)

where R = ρc is the coefficient in front of ∂u/∂t and

Ψn =√

2 sin (nπx) ,

µn = nπ√k,

fn = − (−1)n4√

2k2µne− ν

2k

ν2 + 4k2µ2n

where n = 1, 2, 3, ... throughout. The FEM implementation of (37) give us theplot in Figure 17. In [4, p. 3301] they use t = 0.1, here we have used t = 0.2.

Figure 17: Analytical solution, t = 0.2.

In the next Section we are going to compare the results from the FEM tothe analytical solutions.

3.5 Comparison between FEM and analytical solutions

To see whether the finite element models are valid representations of heat trans-fer or not we make comparisons to the analytical results. We do this by display-ing the results from both FEM and analytical solutions in the same plots. InFigure 18 we see that the curves from the FE model and the analytical solutionfollow each other well but not exactly. To get an exact measure of the differ-ence we would have to do a regression analysis or similar. We are satisfied with

Page 33: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

3 RESULT AND ANALYSIS 29

the fact that they come closer to each other when time increase. The differ-ence between the FEM and analytic solutions stem from the truncation errorsintroduced when we truncate the Fourier series to plot them in MATLAB.

Figure 18: FE (dashed) and analytical (solid) solution, without convection. Tentime steps in

[0, 1.7× 1012

], the two leftmost curves are both connected to time

step one, the two next to time step two, and so on.

In Figure 19 we see a comparison between the solution methods with con-vection. As the FE model coincide with the analytical solution when the totaltime has passed we feel satisfied that the FE model is a valid model for heattransfer under convection.

Page 34: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

3 RESULT AND ANALYSIS 30

Figure 19: FE with 100 time steps in [0, 0.2] and analytical solution for t = 0.2,with convection.

Page 35: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

4 DISCUSSION 31

4 Discussion

Nowadays most of the calculations for the heat distribution in a building aredone with the assumption that the system is in steady state. This is easierto calculate for but it does not give the full picture as a building seldom is insteady state. With more exact models it is easier to point out weaknesses in aconstruction at an early stage and hopefully they can be fixed before any realdamage has been made.

The one dimensional transient simulations produced indicate that the Petrov-Galerkin weighting in the spatial domain works well together with the implicittime integration used for the transient version of the convection equation. Thisconclusion is based on the fact that the difference obtained between the analyti-cal and numerical solutions was small. The proposed numerical method has thebenefit of being easily implemented into a standard finite element frameworksince it just modifies the weight function in a straight forward manner. Further,the standard unconditionally stable finite element time integration schemes canbe used without any direct modifications. However, the use of small local ele-ment lengths and short time steps becomes more crucial for convection problemsat high element Peclet numbers, compared to standard transport equations.One drawback of the Petrov-Galerkin weighting function proposed in this workis that it is based on an analytical case restricted to linear and one-dimensionalconditions, so a generalisation to two- or three-dimensions could be hard. Letus say that we have a convective velocity vector and a triangular element, thenwhat is the length of this element along the velocity vector? As this questioncould be tricky to answer, a generalisation into two- or three-dimensions is notstraight forward.

A more precise model could give a better view of the temperature distri-bution in a joint between two wall elements. In joints we could possibly havelarger problems from pressure differences than we would have in the middle ofan element, that is, the pressure difference could push warm moist air out intothe joint where it would get cooled down giving rise to condensation and mois-ture problems. This is something that could be of interest to look into in futurework. Another idea for future work is to make two- or three-dimensional modelsfor heat transfer. Last but not least, to validate the models we would have tocheck them against a real physical system, this also makes for interesting futurework.

Page 36: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

REFERENCES 32

References

[1] J. W. Brown and R. Churchill. Fourier Series and Boundary Value Prob-lems. 5th ed. McGraw-Hill, Inc – Singapor, 1993.

[2] I. Christie et al. “Finite element methods for second order differentialequations with significant first derivatives”. In: International Journal fornumerical methods in engineering 10 (1976), pp. 1389–1396.

[3] C. A. Felippa. Introduction to Finite Element Methods. University of Col-orado, Boulder, USA, 2004.

[4] J. S. Perez Guerrero et al. “Analytical solution of the advection–diffusiontransport equation using a change-of-variable and integral transform tech-nique”. In: International Journal of Heat and Mass Transfer – Elsevier52.13–14 (June 2009), pp. 3297–3304.

[5] B. Johannesson. “Modelling of Transport Processes Involved in ServiceLife Prediction of Concrete Important Principles”. PhD thesis. Lund Uni-versity, Lund Institute of Technology, 1998.

[6] K-O Lindahl. Private conversation. Apr. 2018.

[7] K-O Lindahl. “Basic numerical methods – lecture 6, Systems of equations– linear algebra”. Lecture notes.

[8] N. S. Ottosen and H. Petersson. Introduction to the Finite Element Method.Prentice Hall, 1992.

[9] O. C. Zienkiewicz and R. L. Taylor. Finite Element Method, Volume one:The Basis. 5th ed. Vol. 1. Butterworth-Heinemann, 2000.

[10] O. C. Zienkiewicz and R. L. Taylor. Finite Element Method, Volume three:Fluid Dynamics. 5th ed. Vol. 3. Butterworth-Heinemann, 2000.

Page 37: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

A-1

Appendices

A FE-model & analytical, without convection

1 % 1D Finite Element Model and Analytical Solution of Transient ...Heat Transfer

2

3 clear; close;4 % -----------Input data---------------5 lambda = 5e-13; % Heat conductivity6 rho = 1; % Density7 c =1; % Heat capacity8 A = 1; % Area9 noe = 99; % Nr of elements

10 non = noe+1; % Nr of nodes11 not = 100; % Nr of timesteps12 T = 1.7e+12; % Total time13 ∆T = T/not; % Timestep14 L = pi; % Total length15 elLength = L/noe; % Element length16 Theta = 2/3; % Capital theta, 0 ≤ Theta ≤ 1;17 inTemp = 1; % Initial temperature at left hand side, bc18 outTemp = 0; % Initial temperature at right hand ...

side, bc19

20 % -----------------------------------------------------------------21 % -----------Finite element part-----------------------------------22

23 % -----------Build Edof--------------24 % Element number i goes from node i to node i+1.25 Edof = zeros(noe,3);26 for i=1:noe27 Edof(i,1)=i;28 Edof(i,2)=i;29 Edof(i,3)=i+1;30 end31

32 % -----------Boundary conditions and empty matrices----------------33 bc = [1 inTemp;non outTemp];% Boundary conditions, at node 1 ...

temp 1 C , last node = 0 C34 an = zeros(non,1); % Initial temperatures at each node35 K = zeros(non, non); % Empty element stiffness matrix36 C = zeros(non, non); % Empty element damping matrix37 A matrix = zeros(non, non); % Matrix to store results in38

39 % -----------Spatial domain---------------40 Ke = lambda*A/elLength*[1 -1; -1 1]; % Element stiffness41 Ce = rho*c*elLength/6*[2 1; 1 2]; % Element damping42

43 % -----------Global matrices--------------44 K global = assem(Edof, K, Ke);45 C global = assem(Edof, C, Ce);46

47

Page 38: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

A FE-MODEL & ANALYTICAL, WITHOUT CONVECTION A-2

48 % -----------Time domain-------------------------------------------49 % -----------Time step zero---------------50 A matrix(:,1) = an; % Add the initial temperatures to the ...

first column of A matrix51 A matrix(1,1) = 1; % Add the boundary condition52

53 % -----------The development over time--------------54 for i=1:not55 K star = C global/∆T + Theta*K global; % Global stiffness ...

with respect to time56 f star = (C global/∆T-K global*(1-Theta))*an; % Global ...

damping with respect to time57 an1 = SOLVE(K star, f star, bc); % Temperature in each node ...

at time n+158 A matrix(:,i+1) = an1; % Store the temperatures in ...

column i+159 an = an1; % Update temperatures for ...

time n60 end61

62 % -----------Plot temperature distribution through wall over time--63 %figure (1)64 hold on;65

66 %title('1D transient heat')67 x = 0:noe; % x goes from 0 to nr of elements68 x=x*pi/noe; % change scale so that the element thickness ...

become pi69 axis([0 3.5 0 1]);70

71 % -----------Plot temperature distribution through wall over time--72 % -----------FEM---------------------------------------------------73 plot(x', A matrix(:,1:end-1))%,':') % plot columns of ...

A matrix against the nodes74

75 % -----------------------------------------------------------------76 % -----------Analytic solution 1D transient heat-------------------77 u0 = inTemp; % Initial temperature at x=078 k = A*lambda; % Area*(heat conductivity)79 nsize = 1000; % Number of terms in the sum. Sum from 1 to n80 U = zeros(1,nsize); % Vector of elements to sum up81

82 x values = 0:0.01:L;83 y values = zeros(size(x values));84

85 hold on;86 for i=1:100 % Decide the time steps87 t = ((T)/100)*i;88 for m=1:length(x values)89 x = x values(1,m);90 for n=1:nsize91 U(1,n) = ...

1/n*(-1)ˆ(n)*exp(-nˆ2*piˆ2*k*t/Lˆ2)*sin(n*pi*(L-x)/L);92 end93 y values(1,m) = u0*(L-x)/pi + 2*u0/pi*sum(U);94 end95

Page 39: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

A FE-MODEL & ANALYTICAL, WITHOUT CONVECTION A-3

96 axis([0 3.5 0 1]); % Limits for the plot97 % -------Plot temperature distribution through wall over time---98 % -------Analytic solution--------------------------------------99 plot(x values,y values)

100 end101

102 % -----------Plot temperature distribution through wall over time---103 % -----------Analytic solution--------------------------------------104 pa = plot(x values,y values,'Color','black','LineWidth',1.5);105 legend([pa],{'Analytic solution'})%,'Location','southwest')106 set(gca,'FontSize',[14])107 box on;108 xlabel('Distance [m]')109 ylabel('Temperature [ C ]')

Page 40: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

B FE-MODEL & ANALYTICAL, WITH CONVECTION B-1

B FE-model & analytical, with convection

1 % 1D Finite Element Model and Analytical Solution of 1D ...Transient Heat Transfer With Convection

2

3 clear; close;4 % -----------Input data---------------5 lambda = 1; % Heat conductivity6 rho = 1; % Density7 c =1; % Heat capacity8 R = rho*c;9 v = 10; % convective velocity

10 noe = 1000; % Nr of elements11 non = noe+1; % Nr of nodes12 not = 100; % Nr of timesteps13 T = 0.2; % Total time14 ∆T = T/not; % Timestep15 L = 1; % Total length16 elLength = L/noe; % Element length17 Theta = 2/3; % Capital theta, 0 ≤ Theta ≤ 1;18 Pe = abs(v*elLength/2/lambda); % Peclet number19 alphaOpt = coth(Pe) - 1/Pe; %20 gamma = v/abs(v); %21

22 %-------------------------------------------------------------------23 %------------FEM----------------------------------------------------24

25 % -----------Build Edof-------------------------26 % Element number i goes from node i to node i+1.27 Edof = zeros(noe,3);28 for i=1:noe29 Edof(i,1)=i;30 Edof(i,2)=i;31 Edof(i,3)=i+1;32 end33

34 % -----------Boundary conditions and empty matrices---------------35 bc = [1 1;non 0]; % Boundary conditions, at first node temp = 1◦C,

at last node temp = 0◦C36 initialTemp = 0;37 an = zeros(non,1)+initialTemp; % Initial temperatures at each node38 K = zeros(non, non); % Empty element stiffness matrix39 C = zeros(non, non); % Empty element damping matrix40 A matrix = zeros(non, non); % Matrix to store results in41

42 % -----------Spatial domain---------------43 Ke = lambda/elLength*[1 -1; -1 1]; % Element stiffness44 Ktilde = v/2*[-1 1;-1 1] + alphaOpt*gamma*v/2*[1 -1;-1 1]; % ...

Element stiffness45

46 Ce = rho*c*elLength/6*[2 1; 1 2] + ...alphaOpt*gamma*rho*c*elLength/4*[-1 -1;1 1]; % Element ...damping

47

48

49

Page 41: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

B FE-MODEL & ANALYTICAL, WITH CONVECTION B-2

50 % -----------Global matrices--------------51 K global = assem(Edof, K, Ke);52 Ktilde global = assem(Edof, K, Ktilde);53 C global = assem(Edof, C, Ce);54

55 % -----------Time domain--------------------------------------------56 % -----------Time step zero---------------57 A matrix(:,1) = an; % Add the initial temperatures to the ...

first column of A matrix58 A matrix(1,1) = 1; % Add the boundary condition59

60 A matrix tilde(:,1) = an;61 A matrix tilde(1,1) = 1;62

63 % -----------The development over time--------------64 for i=1:not65 K star = C global/∆T + Theta*(K global+Ktilde global); % ...

Global stiffness with respect to time66 f star = (C global/∆T-(K global + Ktilde global) ...

*(1-Theta))*an; % Global damping with respect to time67 an1 = SOLVE(K star, f star, bc); % Temperature in each node ...

at time n+168 A matrix(:,i+1) = an1; % Store the temperatures in ...

column i+169 an = an1; % Update temperatures for ...

time n70 end71

72 %-------------------------------------------------------------------73 %------------Analytic solution--------------------------------------74 t = T; % Total time75 nsize = 100; % Number of elements in the sum. Sum from 1 ...

to nsize76 S = zeros(1,nsize); % Vector of elements to sum up77

78 x values1 = 0:0.01:L; % Vector of x-values79 y values1 = zeros(size(x values1)); % Vector of y-values80

81 for m=1:length(x values1) % For each x-value82 x = x values1(1,m); % Update x83 for n=1:nsize % Number of terms in the sum84 S(1,n) = sqrt(2)*sin(n*pi*x)*exp(-nˆ2*piˆ2*lambda*t/R)*...85 (-(-1)ˆn*4*sqrt(2)*lambdaˆ2.5*n*pi*exp(-v/2/lambda)/...86 (vˆ2+4*lambdaˆ3*nˆ2*piˆ2)); % Store the terms in a vector87 end88 y values1(1,m) = exp(v*x/2/lambda - vˆ2*t/4/lambda/R)*sum(S) ...

+ (1-exp(-v*(1-x)/lambda))/(1-exp(-v/lambda));89 end90

91 % --------Plot temperature distribution through wall over time----92 % --------FEM-----------------------------------------------------93 x = 1:size(A matrix); % x goes from 1 to nr of nodes94 hold on;95 plot(x'/noe, A matrix(:,1:end-1))%,'--') % plot columns of ...

A matrix against the nodes96 % --------Analytic solution---------------------------------------97 pa = plot(x values1,y values1,'Color','black','LineWidth',1.5);

Page 42: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

B FE-MODEL & ANALYTICAL, WITH CONVECTION B-3

98 set(gca,'FontSize',[14])99 box on;

100 xlabel('Distance (m)');101 ylabel('Temperature (◦C)');

Page 43: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

C CONDITION NUMBERS, WITHOUT CONVECTION C-1

C Condition numbers, without convection

1 % Finite Element Model of 1D Transient Heat Transfer2

3 clear;4

5 % Choose relevant combinations of number of elements and time steps6 % Vector with number of elements7 %Noe = [10, 30, 70, 100, 200, 500, 1000, 5000, 10000, 30000 ];8 Noe = zeros(1,10)+10;9

10 % Vector with number of time steps11 Not = [10, 30, 70, 100, 200, 500, 1000, 5000, 10000, 30000 ];12 %Not = zeros(1,10)+10;13

14 % ---------------Calculate the condition number----------------15 Econd = zeros(1,length(Noe));16 Cond = zeros(1,length(Noe));17 for j=1:length(Noe) % Allows us to calculate econd and ...

cond(A) for different values of Noe and Not18 noe = Noe(1,j); % Nr of elements19 non = Noe(1,j)+1; % Nr of nodes20 not = Not(1,j); % Nr of timesteps21 % -----------Input---------------22 lambda = 1e-12; % Heat conductivity23 rho = 1; % Density24 c =1; % Heat capacity25 A = 1; % Area26 T = 60*60*24*60; % 60sek*60minutes*24hours*60days27 ∆T = T/not; % Timestep28 Length = 0.01; % Length of mesh29 elLength = Length/noe; % Element length30 Theta = 0.5; % Capital theta, 0 ≤ Theta ≤ 1;31 inTemp = 20; % Initial temperature32

33 % -----------Build Edof--------------34 % Element number i goes from node i to node i+1.35 Edof = zeros(noe,3);36 for i=1:noe37 Edof(i,1)=i;38 Edof(i,2)=i;39 Edof(i,3)=i+1;40 end41

42 % -----------Boundary conditions and empty matrices---------43 bc = [1 inTemp]; % Boundary condition, at node 1 ...

temperature equal to 20◦C44 initialTemp = 0; % Temperature at t<045 an = zeros(non,1)+10; % Initial temperatures at each node46 K = spalloc(non, non, non*3); % Empty element ...

stiffness matrix47 C = spalloc(non, non, non*3); % Empty element damping ...

matrix48 K star = spalloc(non, non, non*3);49 f star = zeros(non,1);

Page 44: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

C CONDITION NUMBERS, WITHOUT CONVECTION C-2

50 A matrix = zeros(non, non); % Matrix to store results in51

52 % -----------Spatial domain---------------53 Ke = lambda*A/elLength*[1 -1; -1 1]; % Element stiffness54 Ce = rho*c*elLength/6*[2 1; 1 2]; % Element damping55

56 % -----------Global matrices--------------57 K global = assem(Edof, K, Ke);58 C global = assem(Edof, C, Ce);59

60 % -----------Time step zero---------------61 A matrix(:,1) = an; % Add the initial temperatures to ...

the first column of A matrix62 A matrix(1,1) = 20; % Add the boundary condition63

64 % -----------The development over time--------------65 for i=1:not66 K star = C global/∆T + Theta*K global; % Global ...

stiffness with respect to time67 f star = (C global/∆T-K global*(1-Theta))*an; % Global ...

damping with respect to time68 an1 = SOLVE(K star, f star, bc); % Temperature in ...

each node at time n+169 A matrix(:,i+1) = an1; % Store the temperatures in ...

column i+170 an = an1; % Update temperatures for ...

time n71

72 % ----------Disturb the result--------------------------73 mid = (max(f star)+min(f star))/2;74 nerme f star = f star + ...

mid*(rand(length(f star),1)-0.5)/1000;75

76 an1 tilde = SOLVE(K star, nerme f star, bc); % ...Temperature in each node at time n+1

77 end78 econd = (norm(an1 tilde-an1)/norm(an1))/...79 (norm(nerme f star-f star)/norm(f star));80 Econd(1,j) = econd;81 % ----------Theoretical condition number--------------------82 if j<883 fullK = full(K star);84 Cond(1,j) = cond(fullK);85 end86 end87 Econd88 Cond

Page 45: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

D CONDITION NUMBERS, WITH CONVECTION D-1

D Condition numbers, with convection

1 % Finite Element Model of Transient Heat Transfer With Convection2

3 clear;4

5 % Choose relevant combinations of number of elements and time steps6 % Vector with number of elements7 %Noe = [10, 30, 70, 100, 200, 500, 1000]; %, 5000, 10000, 30000 ...

]; % ]; %8 Noe = zeros(1,7)+10;9

10 % Vector with number of time steps11 Not = [10, 30, 70, 100, 200, 500, 1000]; %, 5000, 10000, 30000 ];12 %Not = zeros(1,7)+10;13

14 % ---------------Calculate the condition number----------------15 Econd = zeros(1,length(Noe));16 for j=1:length(Noe)17 noe = Noe(1,j); % Nr of elements18 non = Noe(1,j)+1; % Nr of nodes19 not = Not(1,j); % Nr of timesteps20 % -----------Input---------------21 lambda = 1e-12; % Heat conductivity22 rho = 1; % Density23 c =1; % Heat capacity24 T = 60*60*24*60; % 60*60*24*60 seconds, ...

60sek*60minutes*24hours*60days25 ∆T = T/not; % Timestep26 Length = 0.01; % Length27 elLength = Length/noe; % Element length28 Theta = 1; % Capital theta, 0 ≤ Theta ≤ 1;29 A = 2e-9; % convective velocity30 Pe = abs(A*elLength/2/lambda); % Peclet number31 alphaOpt = coth(Pe) - 1/Pe; %32 gamma = A/abs(A); %33

34 % -----------Build Edof--------------35 % Element number i goes from node i to node i+1.36 Edof = zeros(noe,3);37 for i=1:noe38 Edof(i,1)=i;39 Edof(i,2)=i;40 Edof(i,3)=i+1;41 end42

43 % -----------Boundary conditions and empty matrices---------44 bc = [1 1]; % Boundary condition45 bc1 = 1;46 initialTemp = 0; % Temperature at t<047 an = zeros(non,1)+initialTemp; % Initial temperatures at ...

each node48 K = spalloc(non,non,non*3); % Empty element stiffness matrix49 C = spalloc(non,non,non*3); % Empty element damping matrix50 A matrix = zeros(non); % Matrix to store results in

Page 46: Finite Element Method for 1D Transient Convective Heat ...1223250/FULLTEXT01.pdf · Derivation of the heat equation The heat equation for steady state conditions, that is when there

D CONDITION NUMBERS, WITH CONVECTION D-2

51

52 % -----------Spatial domain---------------53 Ke = lambda/elLength*[1 -1; -1 1]; % Element stiffness54 Ktilde = A/2*[-1 1;-1 1] + alphaOpt*gamma*A/2*[1 -1;-1 1];55 Ce = rho*c*elLength/6*[2 1; 1 2] + ...

alphaOpt*gamma*rho*c*elLength/4*[-1 -1;1 1]; % ...Element damping

56

57 % -----------Global matrices--------------58 K global = assem(Edof, K, Ke); % Global stiffness59 Ktilde global = assem(Edof, K, Ktilde);60 C global = assem(Edof, C, Ce); % Global damping61

62 % -----------Time domain-------------------------------------63 % -----------Time step zero---------------64 A matrix(:,1) = an; % Add the initial temperatures to ...

the first column of A matrix65 A matrix(1,1) = bc1; % Add the boundary condition66

67 % -----------The development over time--------------68 f star = zeros(non,1); % Load vector69 for i=1:not70 K star = C global/∆T + Theta*(K global+Ktilde global); ...

% Global stiffness with respect to time71 f star = ...

(C global/∆T-(K global+Ktilde global)*(1-Theta))*an; ...% Global damping with respect to time

72 an1 = SOLVE(K star, f star, bc); % Temperature in ...each node at time n+1

73 A matrix(:,i+1) = an1; % Store the ...temperatures in column i+1

74 an = an1; % Update ...temperatures for time n

75

76 % ----------Disturb the result--------------------------77 mid = (max(f star)+min(f star))/2;78 nerme f star = f star + ...

mid*(rand(length(f star),1)-0.5)/1000;79

80 an1 tilde = SOLVE(K star, nerme f star, bc); % ...Temperature in each node at time n+1

81 end82 econd = (norm(an1 tilde-an1)/norm(an1))/...83 (norm(nerme f star-f star)/norm(f star));84 Econd(1,j) = econd;85 % Theoretical condition number86 if j<887 fullK = full(K star);88 Cond(1,j) = cond(fullK);89 end90 end91 Econd92 Cond