Introduction to Environment System Modeling -...
-
Upload
vuonghuong -
Category
Documents
-
view
226 -
download
0
Transcript of Introduction to Environment System Modeling -...
Introduction to Environment System Modeling
Department of Environment Systems,Graduate School of Frontier Sciences,
the University of TokyoMasaatsu AICHI
(Finite difference method~Diffusion equation & advection equation)
Example problem 1 of the diffusion equation
=
, 0 = 0.2
0, = 10.15, = 0.2
x [m]
C
= 1 − 0.8 ∗ 2
Initial concentration 0.2
x
Boundary concentration 1.0diffusivity D=2.5×10-9[m2/s]
time t=86400 [s]
Diffusion equation
Initial condition
Boundary condition
0.0
0.2
0.4
0.6
0.8
1.0
1.2
0 0.05 0.1 0.15
Implicit method• Governing equation
− = ∆∆∆ − ∆
∆ − ∆ − ∆∆ − ∆
= ∆ − ∆ + ∆= ∆∆ , = 1 + ∆∆ , = ∆∆
• Boundary condition∆ = 1, ∆ − ∆ = 0• Initial condition = 0.2• Unconditionally stable
Implicit method• Governing equation
− = 2∆∆∆ − ∆
∆ + ∆ − ∆ −∆ + ∆ − ∆
= ∆ − ∆ + ∆= ∆
∆ ∆ ∆ , = 1 + ∆∆ ∆ ∆ + ∆ ∆ , = ∆
∆ ∆ ∆• Boundary condition
= 25 + 286400 , = 25• Initial condition = 25• Unconditionally stable
Example problem 2 of the diffusion equation
=
, 0 = 25
0, = 25 + 2864000.1, = 25
Initial condition
Boundary condition
= 0.6 / ∙1 2
1. concrete
= 1900 /= 0.88 / ∙
2. Insulator
Case A: Inner insulation
3cm 3cm
Case B: Outer insulation
2 1
3cm 3cm
= 0.04 / ∙= 50 /= 2.1 / ∙
RoomOutsideair
Calculate the time-dependent heat flux into the room
RoomOutsideair
Solving as simultaneous equations
•
∆ + ∆ + ∆ = 0∆ = 1∆ − ∆ = 0
↔ 1 0
⋱ ⋱ ⋱
−1 1
∆∆
⋮ ∆∆∆
=1−⋮−− 0
Tridiagonal matrix
= 2∆∆ 1∆ + ∆= 2∆∆ 1∆ + ∆= −1 − 2∆∆ 1∆ + ∆ + 1∆ + ∆
Solver for tridiagonal matrix
⋱ ⋱ ⋱
→
0 0⋱ ⋱ ⋱ 0 0
10 1⋱ ⋱ ⋱0 10 10 1
Is divided to lower and upper triangular matrices
= = → = /,
= + = → = −, , = → = / i=2~n
Sequential calculation finds all , , recursively
Solver for tridiagonal matrix0 0⋱ ⋱ ⋱ 0 0
10 1⋱ ⋱ ⋱0 10 10 1
⋮ = ⋮
⋮ =10 1⋱ ⋱ ⋱0 10 10 1
⋮Let
0 0⋱ ⋱ ⋱ 0 0⋮ = ⋮
= /= − / i=2~n
Sequential calculation finds all recursively
Solver for tridiagonal matrix10 1⋱ ⋱ ⋱0 10 10 1
⋮ = ⋮== − ′ i=N-1~1
Sequential calculation finds the solution recursively for all
Summarizing the procedure,
= = /= = − = / (i=2~n)
= /= − / (i=2~n)
== − ′ (i=N-1~1) (If , , , and are not necessarily stored in
the memory after calculation, they can be overwritten by , , , and )
Solving the simultaneous equations with programming
• As a result the solution of simultaneous equations of tridiagonal matrix is necessary– This is applicable for various problems other than
the problem appeared in this lecture.– It is not effective if we write same code for each
occasion– Reusing the code is important.– Save the code as a module that solves the
tridiagonal matrix
Solver for tridiagonal matrixA core part of fortran code (overwriting the original matrix)
b(1)=b(1)/a(1)do i=2,n
a(i)=a(i)-c(i)*b(i-1)b(i)=b(i)/a(i)
enddor(1)=r(1)/a(1)do i=2,n
r(i)=(r(i)-c(i)*r(i-1))/a(i)enddodo i=n-1,1,-1
r(i)=r(i)-b(i)*r(i+1)enddo
LU decomposition
Forward substitution
Backward substitution
module m_Thomasimplicit nonecontains
subroutine Thomas(c,a,b,r)implicit nonereal(8), intent(inout) :: c(:),a(:),b(:),r(:)integer :: i,n
n=size(r)b(1)=b(1)/a(1)do i=2,n
a(i)=a(i)-c(i)*b(i-1)b(i)=b(i)/a(i)
enddor(1)=r(1)/a(1)do i=2,n
r(i)=(r(i)-c(i)*r(i-1))/a(i)enddodo i=n-1,1,-1
r(i)=r(i)-b(i)*r(i+1)enddo
returnend subroutine
end module m_Thomas
Module m_Thomas
Subroutine Thomas1D array c,a,b,r is input and r returns the solution
⋱ ⋱ ⋱ ⋮ = ⋮
Sub program
Main programprogram diffusionuse m_Thomasimplicit nonereal(8), parameter :: pi=4*atan(1d0)real(8), allocatable :: c(:),a(:),b(:),r(:),T(:,:),x(:),dx(:),k(:),rho(:),gm(:)real(8) :: dt,period,timeinteger :: i,n,nunit
open(newunit=nunit,file="input_diffusion.txt")read(nunit,*) n,dt,periodallocate(c(n),a(n),b(n),r(n),T(n,0:1),x(n),dx(n),k(n),rho(n),gm(n))do i=1,n
read(nunit,*) x(i),dx(i),k(i),rho(i),gm(i),T(i,0)enddoclose(nunit)
Main program diffusionm_Thomas is connected to this code
Calculation of π
(continued)
Main program(continued)open(newunit=nunit,file="output_diffusion.txt")time=0do while(time<period)
time=time+dtdo i=2,n-1
c(i)=2*dt/(rho(i)*gm(i)*dx(i))/(dx(i-1)/k(i-1)+dx(i)/k(i))a(i)=-1-2*dt/(rho(i)*gm(i)*dx(i))*(1d0/(dx(i+1)/k(i+1)+dx(i)/k(i))+1d0/(dx(i-1)/k(i-1)+dx(i)/k(i)))b(i)=2*dt/(rho(i)*gm(i)*dx(i))/(dx(i+1)/k(i+1)+dx(i)/k(i))r(i)=-T(i,0)
enddoa(1)=1; b(1)=0; r(1)=25+5*sin(2*pi*time/86400)c(n)=0; a(n)=1; r(n)=25call Thomas(c,a,b,r)T(1:n,1)=r(1:n)T(1:n,0)=T(1:n,1)write(nunit,*) time,-k(n)*(T(n,1)-T(n-1,1))/(x(n)-x(n-1))
enddoclose(nunit)
stopend program diffusion
Example problem 2 of the diffusion equation
=
, 0 = 25
0, = 25 + 2864000.1, = 25
Initial condition
Boundary condition
= 0.6 / ∙1 2
1. concrete
= 1900 /= 0.88 / ∙
2. Insulator
Case A: Inner insulation
3cm 3cm
Case B: Outer insulation
2 1
3cm 3cm
= 0.04 / ∙= 50 /= 2.1 / ∙
RoomOutsideair
Calculate the time-dependent heat flux into the room
RoomOutsideair
Training
• Calculate with MS-EXCEL– Space discretization:Refine the boundary
– Explicit method• What is the limitation of dt?• Calculate for the total period of 150,000 s
– Implicit method• Calculate for the total period of 150,000 s with dt=1500s
– Make a graph for heat flux vs time
Wall 1 Wall 2
22 3 3 4 4 4 3 3 2 22 3 3 4 4 4 3 223
Property boundary WallーAirAirーWall
ADVECTION EQUATION
Case of 1D advection equation
+ = 0Governing equation
− + −2Δ = 0Central difference equation
Analytical solution is a transport of initial distribution
One common ratio is negative and less than -1→The solution of this discretized equation is oscillating and diverges
Solving the characteristic equation for the recursive formula for three adjacent terms,
= −1 ± 1 + 4 = 2Δ
x+1-11 2 +1-1
0
∆
18
Stabilization for the discretized equation(upwind method)
Case of 1D advection equation
+ = 0Governing equation
− + −Δ = 0Upwind finite differential equation
Analytical solution is a transport of an initial distribution
Common ratios are positive and smaller than 1→The solution of this equation is smooth and finite.
= Δ
x+1-11 2 +1-1
0
∆
> 0= +
= 1 +19
Advantage and disadvantage of stabilization
Δx = 1 [m], = 1 [ / ], Δt = . [s]+ [ ]
0.0
0.2
0.4
0.6
0.8
1.0
1.2
0 50 100 150
オリジナル
10m100m1km2km
Too smooth
20
original
Training
• Calculation with MS-EXCEL– Implicit central difference− + −2Δ = 0– Implicit first order upwind method− + −Δ = 0 ≥ 0
− + −Δ = 0 < 0
Why the upwind method finds a smooth solution?− + −Δ = 0 ≥ 0− + −Δ = 0 < 0
can be reformulated to+ − = 0
Central finite difference Diffusion term with finite difference method
• Artificial diffusion term is appeared in the equation• The diffusion coefficient is Δ /2, and then, the artificial diffusion effect is
important in rapid flow and large mesh• The countermeasure is refining the meshes→Computational effort
CIP method (Takewaki et al., 1985)• and are main variables ( = )
• Advection equation is separated to + = 0 and + = 0• Let = + + + , and the coefficients are determined by the upwind mesh
values and in the mesh i-1
= , = , = 2 +Δ − 3 −Δ , = +
Δ − 2 −Δ• Interpolating and • Because the solution of advection equation is a Δt transport of the distribution, Δt before,
the solution for the next step is obtained by upwind values based on the above interpolation functions
Δt
− Δt
Δt
Approximation by piecewise 三次 function
Δt
23
Advantage and disadvantage of stabilization
Δx = 1 [m], = 1 [ / ], Δt = . [s]+ [ ]
CIP method is much better but unphysical oscillation appears
-0.2
0.0
0.2
0.4
0.6
0.8
1.0
1.2
0 50 100 150
オリジナル
10m100m1km2km
24
original
Problem of advection term• There is no killer solution for the exact simulation of advection term.• Currently, it is important to choose an appropriate method for the
objective– Smoothness and stability→Upwind method family– Accuracy of the location of advection front→Lagrangian method family
• Advanced method– Higher order upwind method(cancelling numerical diffusion)– Higher order backward tracking(tracking upstream accurately)– Adaptive mesh refinement(Mesh is adaptively refined to follow the
advection front. )– etc…
• For beginner, a first-order upwind method is used in this lecture because it is simple and stable. After this, you can study advanced methods.
Advection-diffusion-attenuationequation
, 0 = 0
0, = 1∞, = 0
Initial concentration 0
x
Boundary concentration 1.0 Diffusion coefficientD=2.5×10-5[m2/s]
time t=86400 [s]
Governing equation
Initial condition
Boundary condition
= − −
= 10 [m/s]
= ln 286400 [ ]
= 12 erfc − + 42
+ erfc + +2
Exact solution for comparison
= 4 +erfc = 1 − erf complementary error function
Practice
• Calculate with MS-Excel– Implicit first-order upwind finite difference
method− + −2Δ− Δ2 + − 2 +Δ + = 0