Introduction to Scientific Computing

advertisement
Dr. Jennifer Parham-Mocello
What is an IDE?
 IDE – Integrated Development Environment
 Software application providing conveniences to
computer programmers for software development.
 Consists of editor, compiler/interpreter, building tools,
and a graphical debugger.
Heat Diffusion / Finite Difference Methods
2
Eclipse
 Java, C/C++, and PHP IDE
 Uses Java Runtime Environment (JRE)
 Install JRE/JDK http://www.oracle.com/technetwork/java/index.html
 Need C/C++ compiler
 Install Wascana (Windows version)
http://www.eclipselabs.org/p/wascana
Heat Diffusion / Finite Difference Methods
3
Using Eclipse
 Example – Open HelloWorld C++ project
 File -> New -> C++ Project
 Enter Project Name
 Building/Compiling Projects
 Project -> Build All
 Run -> Run
 Console
Heat Diffusion / Finite Difference Methods
4
Heat Diffusion
Heat Diffusion / Finite Difference Methods
5
Heat Diffusion Equation
 Describes the distribution of heat (or variation in
temperature) in a given region over time.
 For a function u(x, t) of one spatial variables(x) and
the time variable t, the heat diffusion equation is:
 2u
u
k 2  c
0
x
t
1D
or
 2u
u
k 2  c
x
t
1D
Material Parameters – thermal conductivity (k), specific heat (c), density ()
Heat Diffusion / Finite Difference Methods
6
Conceptual and theoretical basis
 Conservation of mass, energy, momentum, etc.
 Rate of flow in - Rate of flow out = Rate of heat storage
u
u
k 2  c
1D
x
t
2
  2u  2u 
u
k  2  2   c
2D
y 
t
 x
  2u  2u  2u 
u


k  2  2  2   c
y
z 
t
 x
Heat Diffusion / Finite Difference Methods
3D
7
Example 1D Heat Diffusion Problem
Wire with perfect
insulation, except
at ends
x=0.0
Physical Parameters
k  0.13 cal / sec cm C
x=4.0
Boundary
Conditions
Initial
Conditions
u (0.0, t ) 0 C

c  0.11cal/g C
u (4.0, t )  100 C

  7.8 g/cm 3
u( x,0.0) 0 C
 2u
u
Given theoreticalequation, k 2  c ,
x
t
physicalparameters, and initialand boundary
conditions, solvefor u ( x, t ) for all valuesof
x and t.
Heat Diffusion / Finite Difference Methods
8
Outline of Solution
 Discretization (spatial and temporal)
 Transformation of theoretical equations to
approximate algebraic form
 Solution of algebraic equations
Heat Diffusion / Finite Difference Methods
9
Discretization
 Spatial - Partition into equally-spaced nodes
u
0
u
u
x=0.33
x=0.67
1
x=0.0
2
u
3
x=1.0
Temporal - Decide on time stepping parameters
Let to = 0.0, tn = 10.0, and Dt = 0.1
Heat Diffusion / Finite Difference Methods
10
Approximate Theoretical with
Algebra
Finite difference approximations for
first and second derivatives
u u t  Dt  u t

t
Dt
 2u ui 1  2ui  ui 1

2
x
(Dx) 2
u0
u1
ui-1
ui
ui+1
Heat Diffusion / Finite Difference Methods
un-1 un
11
Approximation
 2u
u
k 2  c
x
t

t  Dt
t
 u t i 1  2u t i  u t i 1 
ui  ui
  c
k 
2
(Dx)
Dt



kDt
t  Dt
t
t
t
t


u

2
u

u

u

u
i 1
i
i 1
i
i
2
c (Dx)
kDt
Let r 
, then wehave
2
c (Dx)


r u t i 1  2u t i  u t i 1  ui
Heat Diffusion / Finite Difference Methods
t  Dt
 ui
t
12
Algorithm


r ut i 1  2ut i  ut i 1  ui
t Dt
 ui
t
for t=0,tn
for each node, i
predict ut+Dt
endfor
endfor
• Predicting ut+Dt at each node
• Explicit solution
• Implicit solution (system of
equations)
Heat Diffusion / Finite Difference Methods
13
Explicit Solution
Rearrange

ru
t
i 1
 2u i  u
t
 ui
 2u i  u
 u
by solvingfor ui
ui
t  Dt

ru
t
i 1
 u
t  Dt
i
t
i 1
t  Dt
t
,
t
Heat Diffusion / Finite Difference Methods
t
i 1
t
i
14
Simulation
(Explicit
Solution)
Physical Parameters
k  1.0
c  2.0
u
u
0
1
u
2
u
3
  5.0
D t  0 .1
Dx  0.33
kDt
(1.0)(0.1)

 0.092
2
2
c (Dx)
(2.0)(5.0)(0.33)
Not e: for st abilit ypurposes,we want
1
r 
2
r
Boundary
Conditions
Initial
Conditions
u (0.0, t )  0
u ( x,0.0)  0
u (1.0, t )  100
t
0.0
0.1
0.2
0.3
u0
0.0000
0.0000
0.0000
0.0000
u1
u2
u3
0.0000 0.0000
0.0000
0.0000 9.1874 100.0000
0.8432 16.6790 100.0000
2.2200 22.8760 100.0000
10.0 0.0000 33.3300 66.6640 100.0000
0.0000 33.3333 66.6667 100.0000
Heat Diffusion / Finite Difference Methods
15
Extension
 Two Dimensions
  2u  2u 
u


k  2  2   c
y 
t
 x

t  Dt
ui , j  ui , j
 u t i 1, j  2u t i , j  u t i 1, j u t i , j 1  2u t i , j  u t i , j 1 
  c
k 

2
2
(Dx)
(Dy )
Dt


t
u i,j+1
u i,j
u i-1,j
u i+1,j
u i,j-1
Heat Diffusion / Finite Difference Methods
16
Implement 1-D Heat Diffusion
 Open New C++ Project
 Name the Project
 Open New C++ source code file
 File -> New -> Source File
 Name C++ File (remember extension, .C, .c++, .cpp)
Heat Diffusion / Finite Difference Methods
17
EXTRAS
Heat Diffusion / Finite Difference Methods
18
Shorthand
Notations
 Gradient (“Del”) Operator
1D :
2D :
3D :

,
x

 x 
    ,
 
 y 
u
x
 u 
 x 
u   u 
 
 y 

u 

 x 

 
   ,
 y 

 z 
 u 
 x 
 u 
 
u   
 y 
 u 
 z 
Heat Diffusion / Finite Difference Methods
19
 Divergence (Gradient of a vector field)
1D :
2D :
3D :
2


u

u


 T u     2
x  x  x

 u  
 x
T

 T u  
 x
 u 
   x   2u  2u
 u   2  2

y    x
y
 y 

y
 u 
 x 
   u   2u  2u  2u
  2  2  2

z   y  x
y
z
 u 
 z 
Heat Diffusion / Finite Difference Methods
20
 Laplacian Operator
 2  T 
1D :
2D :
3D :
2

u
2
 u 2
x
2
2

u

u
2
 u 2  2
x
y
2
2
2

u

u

u
2
 u 2  2  2
x
y
z
Note: Sometimes Du   2u
Heat Diffusion / Finite Difference Methods
21
 Heat Diffusion Equation - rewritten
 2u
u
k 2  c
x
t
  2u  2u 
u
k  2  2   c
y 
t
 x
  2u  2u  2u 
u
k  2  2  2   c
y
z 
t
 x
u
k u  c
t
2
Heat Diffusion / Finite Difference Methods
•LHS represents spatial
variations
•RHS represents temporal
variation
22
Download