Implementing our backward order final equation

advertisement
Implementing our backward
order final equation
Jennifer Tanyer
March 27, 2002
Goals:
Balance the discretized equation from
Bob’s presentation
Develop a system of linear equations from
the given equation
Modify previous code to solve the implicit
function and get values for our unknown
concentration at time t+1
2
Our backward order
discretized equation:
 From Bob’s presentation:
c(k , t  1)  c(k , t )

( t )
D c( x  x, y, t  1)  c( x  x, y, t  1)  2c( x, y, t  1)
(

2

(x)
c( x, y  y, t  1)  c( x, y  y, t  1)  2c( x, y, t  1)
)
2
(y )
 c( x  x, y, t  1)  c( x  x, y, t  1)
ux (
)
2(x)
 c( x, y  y, t  1)  c( x, y  y, t  1)
uy (
)
2(y )
3
Problems with this equation:
 The system is not balanced.
i.e.(# of variables on the LHS  # of
variables on the RHS)
 LHS accounts for interior nodes only
 RHS accounts for interior and boundary
nodes
 # of Unknowns > #of Equations because of this.
The difference in the number is due to the lack of
representation for the boundary points
4
Solutions:
Add the boundary condition for each
boundary node onto the LHS of the
equation: c(x,y,t) = 0.
Since we can’t solve this system explicitly,
we must generate a system of linear
equations that establish an algorithm for
solving for our unknowns
Our unknown : concentration at time t + 1
5
Step 1: Developing the new
linear system
Place all of our unknowns: t + 1 onto the
LHS of our equation
The RHS will be equal to our
concentration at time t
6
Step 1:
 c(k , t )
 c ( k , t  1)


( t )
( t )
D c( x  x, y, t  1)  c( x  x, y, t  1)  2c( x, y, t  1)
(

2

(x)
c( x, y  y, t  1)  c( x, y  y, t  1)  2c( x, y, t  1)
)
2
(y )
 c( x  x, y, t  1)  c( x  x, y, t  1)
ux (
)
2(x)
 c( x, y  y, t  1)  c( x, y  y, t  1)
uy (
)
2(y )
7
Step 2: Replace equations
with their proper node labels
c(k , t )


( t )
2XK 
 XE
X
W


(
2
2
2 
 X K D  ( x ) (  x ) (  x ) 


t
  XN
2
X
X
S
K


)

2
2
2
 (y ) (y ) (y ) 
 u x(
 u y(
X
E
X
N

X
w

X
S
2 ( x ) 2 ( x )
2 ( y ) 2 (  y )
)
)
8
Step 3: Combine like terms
LHS
1 D 2
D 2
(



X K t  ( x ) 2   (  y ) 2 ) 
D 1
1



X E (  (  x ) 2 u x 2 ( x ) ) 
D 1
1
(



X W  ( x ) 2 u x 2( x ) ) 
D 1
1
X N (   ( y ) 2  u y  2 (  y ) ) 
D 1
1
X S (   ( y ) 2  u y  2 (  y ) )
 RHS K
 Refer to poisson.m
 These new combined
equations will
represent w(k,k),
w(k,E), w(k,W),
w(k,N), and w(k,S)
respectively.
9
Step 4: Implement the new
equation into ‘concentrate.m’
%Modified concentrate.m
deltat=0.5;
D=0.1;
rho=1;
time=10;
ntimes=round(time/deltat);
NRPOINTS=max(size(a10));
for k=1:NRPOINTS
Position=a10(k,1:2);
Concentration(k,1)=g(Position);
end
10
Modified concentration.m
continued…
for m=1:ntimes
m
w = zeros(1528, 1528);
rhs = zeros(1528,1);
deltaXsq = 1/deltaX^2;
deltaYsq = 1/deltaY^2;
for k = 1:1528
N = nb(k,find((nbor(k,:) == 1)));
W = nb(k,find((nbor(k,:) == 3)));
S = nb(k,find((nbor(k,:) == 5)));
E = nb(k,fgind((nbor(k,:) == 7)));
11
gAnd finally…
if(~g(N) & ~isempty(W) & ~isempty(S) & ~isempty(E))
ux = scaledvelocity(k,1);
uy = scaledvelocity(k,2);
w(k,N) = ((D/rho) * (1/deltaYsq) – uy * (1/(deltaY)*2));
w(k,S) = ((D/rho) * (1/deltaYsq) + uy * (1/(deltaY)*2));
w(k,E) = ((D/rho) * (1/deltaXsq) - ux * (1/(deltaX)*2));
w(k,W) = ((D/rho) * (1/deltaXsq) + ux * (1/(deltaX)*2));
w(k,k) = (-1/deltat – (D/rho)*(2/(deltaXsq)) – (D/rho) *(2/(deltaYsq));
rhs(k,1) = concentration(k,m)/deltat;
else
w(k,k) = 1;
rhs(k,1) = 0;
end
end
xjen=w\rhs;
12
In the End…
 You now have an algorithm of linear equations
that you can solve to get a 1532 x 1532 matrix of
concentrations at each node.
 You can use MATLAB to solve Ax = b
(w * x)
= rhs by using either
1.The inverse
of A >>x=inv(A)*b OR 2.Row Reduction
>>x1=A\b
 We no longer have approximate values for our
concentrations…we now have actual values
13
Download