• No se han encontrado resultados

Constructing Simulations of PDEs

N/A
N/A
Protected

Academic year: 2023

Share "Constructing Simulations of PDEs"

Copied!
35
0
0

Texto completo

(1)

10.34: Numerical Methods Applied to

Chemical Engineering

Finite Volume Methods

Constructing Simulations of PDEs

1

(2)

Recap

von Neumann stability analysis

Finite volume methods

2

(3)

3

Generally used for conservation equations of the form:

is the density of a conserved quantity

is the flux density of a conserved quantity

The integral version of such an equation is:

Finite Volume Method

@ b

@ t = r · j + r (x, t)

b(x, t) j(x, t)

d dt

Z

V

b(x, t) dV = Z

S

n · j(x, t) dS + Z

r (x, t) dV

V

d B

(t) = F

(t) + R

(t)

dt

ACC IN/OUT GEN/C

or

*

ON

(4)

4

What are each of these terms?

B

(t) = V

¯ b

(t)

R

(t) = V

r ¯

(t)

F

(t) = X F

k

(t) =

k2faces k2

X A

k

(n

k

faces

· j)(t)

the sum of fluxes through each face of the volume *

d ¯ b

V

= F

k

(t) + V

r ¯

(t) dt

We want to solve for by approximating the reaction and flux terms. Let’s construct low order approximations physically.

d B

(t) = F

(t) + R

(t)

dt

ACC IN/OUT GEN/CON

*

¯ b(t)

X

k2faces

Finite Volume Method

Conservation within a finite volume:

(5)

5

*

@ b

@ t = r · j + r(x, t)

d ¯ b

V

=

dt

k2

X F

k

(t) + V

r ¯

(t)

faces

Finite Volume Method

(6)

6

*

@ t = r · j + r(x, t)

d ¯ b

V

=

dt

k2

X F

k

(t) + V

r ¯

(t)

faces

Finite Volume Method

@ b

(7)

7

@ b

@ t = r · j + r(x, t)

d ¯ b

V

= X

F

k

(t) + V

r ¯

(t)

, France

dt

k2faces

*

Geometrica: INRIA

Finite Volume Method

© INRIA. All rights reserved. This content is excluded from our Creative Commons license. For more information, see https://ocw.mit.edu/help/faq-fair-use/.

(8)

8

d ¯ b

V

=

dt

k2

X F

k

(t) + V

r ¯

(t)

faces

Cardiff et al. J Biomech Eng 136(1), 2013

*

Finite Volume Method

@ b

@ t = r · j + r(x, t)

© Cardiff, Philip et al. License: cc by-nc-nd. Some rights reserved. This content is excluded from our CreativeCommons license. For more information, see https://ocw.mit.edu/help/faq-fair-use/.

(9)

9

Numerical Solution of PDEs

L

Step 1: domain decomposition finite difference: nodes

i, j

W

(10)

10

Numerical Solution of PDEs

L W

Step 1: domain decomposition finite volume: cells

i, j

(11)

L

11

W

Numerical Solution of PDEs

Step 1: domain decomposition

finite element: elements (local basis functions)

i, j

(12)

12

Numerical Solution of PDEs

Step 1: domain decomposition

Always choose the spacing between nodes/dimensions of cells to match the physics.

Never pick a certain number of nodes or cells a priori. That number is irrelevant.

(13)

13

19

x-coordinate (cm)

cm)( etanidrocoy-

Concentration profile in (x,y)-space. Thin medical implant at x [1,2] cm.

0 5 10 15 20 25 30

0 0.5 1 1.5 2

-2 0 2 4 6 x 108 -4

x-coordinate (cm)

y-coordinate (cm)

Close-up of concentration profile in (x,y)-space.

R = 30, B = 2, N = 300. Semi-infinite boundary condition at x=R and y=B: Dirichlet zero concentration.

0 2 4 6 8 10

0 0.02 0.04 0.06 0.08 0.1

-2 0 2 4 6 x 108 -4

Figure 6.2 Concentration profile using Dirichlet boundary condition for x = R and y = B. R = 30 cm, B = 2 cm, and N = 300.

(14)

14

Numerical Solution of PDEs

Step 2: formulate an equation to be satisfied at each node/cell

(15)

15

Numerical Solution of PDEs

Step 2: formulate an equation to be satisfied at each node/cell Example: at interior node/cell i,j

r

2

c = 0

equation i,j:

c

i+1,j

+ c

i 1,j

+ c

i,j 1

+ c

i,j+1

4c

i,j

= 0

(16)

16

Numerical Solution of PDEs

Step 2: formulate an equation to be satisfied at each node/cell Example: at boundary node/cell i,j

equation i,j:

c = 1

c

i,j

1 = 0

(17)

17

Numerical Solution of PDEs

Step 3: solve the system of equations formulated at each node/cell for the value of unknown function at each node/cell

f (c) = 0

If equations are linear, use linear iterative methods

If equations are nonlinear, use nonlinear iterative methods

(18)

18

Numerical Solution of PDEs

Step 3: solve the system of equations formulated at each node/cell for the value of unknown function at each node/cell

f (c) = 0

must be a vector of the unknowns must be a vector of the equations

c

f

(19)

19

Numerical Solution of PDEs

1 N

x

N

y

1 2

i j

Indexing

k = i + (j 1)N

x

c

i,j+1

= c

k+Nx

c

k

= c

i,j or

k = j + (i 1)N

y

c

i,j+1

= c

k+1

3,

(20)

20

Numerical Solution of PDEs

y

1 , 2

i j

Indexing

1 N

x

N

k = i + (j 1)N

x

f

k

(c) = f

i,j

(c)

or

k = j + (i 1)N

y

3

(21)

21

Numerical Solution of PDEs

N

y

1 2

j

Indexing

1 N

x

k = i + (j 1)N

x

f

k

(c) = f

i,j

(c)

or

k = j + (i 1)N

y

3,

i

(22)

22

Numerical Solution of PDEs

N

x

y

N

z

N

c

l

= c

i,j,k

, l =?

Exercise: write a single index for finite difference nodes in a cubic domain with (Nx, Ny, Nz) nodes in each cartesian direction

(23)

Numerical Solution of PDEs

Exercise: write a single index for finite difference nodes in a cubic domain with (Nx, Ny, Nz) nodes in each cartesian direction

N

x

N

y

N

z

c

l

= c

i,j,k

, l = i + (j 1)N

x

+ (k 1)N

x

N

y

23

(24)

Numerical Solution of PDEs

Example: solve the diffusion equation in 2-D on a square with side = 1.

r

2

c = 0 c = 0

c = 0

c = 0

c = 1

f (c) = 0

24

(25)

25

Numerical Solution of PDEs

Example: solve the diffusion equation in 2-D on a square with side = 1.

h = 1 / 10; % Spacing between finite difference nodes Nx = 1 + 1 / h; % Number of nodes in x-direction

Ny = Nx; % Number of nodes in y-direction

c0 = zeros( Nx * Ny, 1 ); % Initial guess for solution

c = fsolve( @( c ) my_func( c, Nx, Ny ), c0 ); % Find root of FD equations

(26)

26

Numerical Solution of PDEs

Example: solve the diffusion equation in 2-D on a square with side = 1.

function f = my_func( c, Nx, Ny )

% Loop over all nodes for i = 1:Nx

for j = 1:Ny

k = i + ( j - 1 ) * Nx; % Compound index

% Boundary nodes if ( i == 1 )

f( k ) = c( k );

elseif ( i == Nx ) f( k ) = c( k );

elseif( j == 1 )

f( k ) = c( k ) - 1;

elseif( j == Ny ) f( k ) = c( k );

% Interior nodes else

f( k ) = c( k + 1 ) + c( k - 1 ) + c( k - Nx ) + c( k + Nx ) - 4*c( k );

end;

end;

end;

(27)

27

Numerical Solution of PDEs

Example: solve the diffusion equation in 2-D on a square with side = 1.

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

0.08 seconds to solve

h = 1/10

(28)

28

Numerical Solution of PDEs

Example: solve the diffusion equation in 2-D on a square with side = 1.

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

h = 1/100

700 seconds to solve!

Why is it almost 10,000x slower?

(29)

29

Numerical Solution of PDEs

Example: solve the diffusion equation in 2-D on a square with side = 1.

f (c) = 0 = Ac b

function [ Ac, b ] = my_func( c, Nx, Ny ) Ac = sparse( Nx * Ny, 1 );

b = sparse( Nx * Ny, 1 );

% Loop over all nodes for i = 1:Nx

for j = 1:Ny

k = i + ( j - 1 ) * Nx; % Compound index

% Boundary nodes if ( i == 1 )

Ac( k ) = c( k );

elseif ( i == Nx ) Ac( k ) = c( k );

elseif( j == 1 )

Ac( k ) = c( k );

b( k ) = 1;

elseif( j == Ny ) Ac( k ) = c( k );

% Interior nodes else

Ac( k ) = c( k + 1 ) + c( k - 1 ) + c( k - Nx ) + c( k + Nx ) - 4*c( k );

end;

end;

end;

(30)

30

Numerical Solution of PDEs

Example: solve the diffusion equation in 2-D on a square with side = 1.

h = 1 / 10; % Spacing between finite difference nodes Nx = 1 + 1 / h; % Number of nodes in x-direction

Ny = Nx; % Number of nodes in y-direction

% Calculate RHS of Ac = b

[ Ac, b ] = my_func( zeros( Nx * Ny, 1 ), Nx, Ny );

% Find solution of linear FD equations using the an iterative method

% This is gmres (generalized minimum residual). Other choices include

% bicgstab (conjugate gradient), minres (minimum residual), etc.

% The requires a function that returns A*c given c.

c = gmres( @( c ) my_func( c, Nx, Ny ), b, 100, 1e-6, 100 );

(31)

31

Numerical Solution of PDEs

Example: solve the diffusion equation in 2-D on a square with side = 1.

0.015 seconds to solve!

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9

1

h = 1/10

(32)

32

Numerical Solution of PDEs

Example: solve the diffusion equation in 2-D on a square with side = 1.

5 seconds to solve!

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9

1

h = 1/100

(33)

33

Numerical Solution of PDEs

Example: solve the diffusion equation in 2-D on a square with side = 1.

function [ Ac, b ] = my_func( c, Nx, Ny ) Ac = sparse( Nx * Ny, 1 );

b = sparse( Nx * Ny, 1 );

k = i + (j 1)N

x

% Define indices of boundary points and interior points bottom = [ 1:Nx ];

top = Nx*Ny - [ 1:Nx ];

left = [ 1:Nx:Nx*Ny ];

right = [ Nx:Nx:Nx*Ny ];

interior = setdiff( [ 1:Nx*Ny ], [ left, right, bottom, top ] );

Ac( left ) = c( left );

Ac( right ) = c( right );

Ac( top ) = c( top );

Ac( bottom ) = c( bottom );

b( bottom ) = 1;

A( interior ) = c( interior - 1 ) + c( interior + 1 ) + c( interior - Nx ) + c( interior + Nx ) … - 4 * c( interior );

f (c) = 0 = Ac b

(34)

34

Numerical Solution of PDEs

Example: solve the diffusion equation in 2-D on a square with side = 1.

1.2 seconds to solve!

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9

1

h = 1/100

(35)

MIT OpenCourseWare https://ocw.mit.edu

10.34 Numerical Methods Applied to Chemical Engineering

Fall 2015

For information about citing these materials or our Terms of Use, visit: https://ocw.mit.edu/terms.

Figure

Figure 6.2 Concentration profile using Dirichlet boundary condition for  x = R and y = B

Referencias

Documento similar

PARA UN MAPEO PREVIO ANTE LA INICIATIVA DEL SECTOR COLABORACIÓN DE ELABORAR UN CURSO VIRTUAL SOBRE IGNACIANIDAD. Provincia o