finite differences matlab - web.calpoly.edukshollen/me350/handouts/finite_differences.pdf · steps...
Post on 23-Mar-2020
22 Views
Preview:
TRANSCRIPT
Steps for Finite-Difference Method
1. Define geometry, domain (including mesh and elements), and properties
2. Simplify (or model) by making assumptions3. Define boundary (and initial) conditions4. Use energy balance to develop system of finite-
difference equations to solve for temperatures5. Use Fourier’s Law and known temperatures to
solve for heat fluxes
1) Define Geometry and Properties
qx = 0
T1
Lx = Ly = 2.0 cm
T1 = 100 ˚C
h = 100 W/m2•K
T∞ = 20 ˚C
k = 0.72 W/m•K
Note: qx = 0 on line of thermal symmetry at x = 0
y
x
h, T∞
h, T∞
Lx
Ly
Define Domain, Mesh, and Elements
qx = 0
T1
0 ≤ x ≤ Lx
0 ≤ y ≤ Ly
x = (i -1) ∆x
y = (j -1) ∆y
i = 1, 2, 3,…, Nx + 1
j = 1, 2, 3,…, Ny + 1
∆x = Lx / Nx
∆y = Ly / Ny
y, j
x, ii = 1 2 3 Nx Nx+1
3
2
j = 1
h, T∞
h, T∞
Ny +1
Ny
Lx
Ly
Mesh Definitions
Differential Elements - discrete areas over which temperature and properties are assumed constant
Node - center of each elementMesh - combination of all
nodes (or elements)
i,j i+1,j i-1,j
i,j+1
i,j-1
node
element
Mesh Definitions, cont.
Structured Mesh - mesh with regularly spaced nodes that align with axes
Mesh Refinement - decreasing size of mesh elements resulting in more nodes and higher accuracy
Boundary Elements - elements on boundary of domain that can be full, half, or quarter size. Nodes located on the boundary are more accurate and required for symmetry boundary conditions.
2) Simplify (or model) by �Making Assumptions
• Steady state• 2-D conduction in brick• Constant properties• Negligible radiation
3) Define Boundary Conditions
• Symmetry plane at x = 0: �qx (x = 0) = 0
• Fixed temperature at y = 0:�T(y = 0) = T1
• Convection x = Lx and y = Ly�
4) Develop Finite-Difference Equations
Interior Nodes:
i, j i+1, ji-1, j
i, j+1
i, j-1
∆x
∆y€
Ti, j =Ti+1, j +Ti−1, j +Ti, j+1 +Ti, j−1
4
Develop Equations Continued…
Boundary at j = 1 (y = 0) and i = 1 to Nx +1:Temperatures are all fixed at T1
Ti, 1 = T1
Develop Equations Continued…
Boundary at i = 1 (x = 0) and j = 2 to Ny :
1, j 2, j
1, j - 1
1, j + 1
∆x/2
∆y
€
T1, j =2 T2, j +T1, j+1 +T1, j−1
4
Develop Equations Continued…
Boundary at i = 1 (x = 0) and j = Ny + 1:
1, Ny + 1 2, Ny +1
1, Ny
h, T∞
∆y/2
∆x/2€
T1,Ny+1 =T2,Ny+1 +T1,Ny
+Bi T∞2+Bi
Develop Equations Continued…
Boundary at i = Nx + 1 (x = Lx) and j = 2 to Ny:
Nx, j Nx + 1, j
Nx + 1, j - 1
Nx + 1, j + 1
∆x/2
∆yh, T∞
€
TNx+1, j =2 TNx , j +TNx+1, j+1 +TNx+1, j−1 +2 Bi T∞
4 +2 Bi
Develop Equations Continued…
Boundary at i = Nx + 1 (x = Lx) and j = Ny + 1:
Nx, Ny + 1
Nx + 1, Ny + 1
Nx + 1, Ny
∆x/2
∆y/2 h, T∞
h, T∞
€
TNx+1,Ny+1 =TNx ,Ny+1 +TNx+1,Ny
+2 Bi T∞2+2 Bi
Develop Equations Continued…
Boundary at j = Ny + 1 (y = Ly) and i = 2 to Nx:
i, Ny + 1 i + 1, Ny + 1i - 1, Ny + 1
i, Ny
∆x
∆y/2
h, T∞
€
Ti,Ny+1 =2 Ti,Ny
+Ti+1,Ny+1 +Ti−1,Ny+1 +2 Bi T∞4 +2 Bi
Solve System of Linear Equations
Procedure for Direct Matrix Inversion:a. Renumber each node: k = (j - 1)(Nx + 1) + i�
for a total of N = (Nx + 1)(Ny + 1) nodes.b. Use equations derived above to write an equation
for each node. Example for interior nodes:
k k+1k-1
k + (Nx+1)
k - (Nx +1)
€
Tk −14Tk+1 +Tk−1 +Tk+(Nx+1) +Tk−(Nx+1)[ ] = 0
Solve System Continued …
c. Express equations as follows:
d. Calculate the A matrix and C vector.e. Calculate temperature: [T] = [A]-1 [C]
€
a1,1 a1,2 ! a1,k ! a1,Na2,1 a2,2 ! a2,k ! a2,N" " # "ak,1 ak,2 ak,k ak,N" " " # "
aN ,1 aN ,2 ! aN ,k ! aN ,N
⎡
⎣
⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢
⎤
⎦
⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥
T1T2"Tk"TN
⎡
⎣
⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢
⎤
⎦
⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥
=
C1C2"Ck"CN
⎡
⎣
⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢
⎤
⎦
⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥
Solve System Continued …
Procedure for Gauss-Seidel Iteration:a. Assume initial temperature distributionPick something reasonable: • For this case either T1 or T∞ works well• Alternatively, T = 0 ˚C would work• Picking good initial guess for temperature
will speed up convergence
Solve System Continued …
b. Solve for Ti, j at Each Node:• Use equations derived above for each node• Always use most recently calculated
temperatures for each new calculation• Perform calculations in systematic order to
improve efficiency (i.e. T1, 1, T2, 1, T3, 1, …)
Solve System Continued …
c. Check for Convergence• Calculate |Tnew- Told| after updating all of the
temperature data• When difference falls below desired
tolerance at every node solution has converged
• Repeat steps b. and c. until convergence
5) Solve for Heat Fluxes
Use known temperatures and Fourier’s Law:
where gradient for 2-D Cartesian is:
thus, components and magnitude are:
€
ʹ ́ ! q = −k ∇T
€
∇T =∂T∂x
ˆ i +∂T∂y
ˆ j
€
ʹ ́ q x = −k ∂T∂x,
€
ʹ ́ q y = −k ∂T∂y,
€
ʹ ́ ! q = ʹ ́ q x( )2 + ʹ ́ q y( )2
Use Finite Differences for Gradient
For 2nd order accurate approximation:
Central differences:
Forward differences:
Backwards differences:
€
∂T∂x
≈Ti+1 −Ti−1
2 Δx
€
∂T∂x
≈−3Ti + 4 Ti+1 −Ti+2
2 Δx
€
∂T∂x
≈3Ti − 4 Ti−1 +Ti−2
2 Δx
Calculating Heat Transfer at y = 0�(j = 1) per Unit Length (z-direction)
Must integrate over x-direction:
Approximate integral using:
€
ʹ q y = 0( ) = ʹ ́ q y y = 0( )dxx=0Lx∫
€
ʹ q y = 0( ) ≈ ʹ ́ q y,1Δx2
⎛ ⎝ ⎜
⎞ ⎠ ⎟ + ʹ ́ q y, i Δx
i=2
Nx
∑ + ʹ ́ q y, Nx+1Δx2
⎛ ⎝ ⎜
⎞ ⎠ ⎟
MATLAB Programs
Two programs in MATLAB to solve Example #8:1. conduction_matrix_inv.m2. conduction_Gauss_Seidel.m
Both are available online on my webpage at www.calpoly.edu/~kshollen.
All system parameters, such as Nx, h, and k, can be changed to test their effect on the solution.
top related