|
| 1 | +% see http://fvt.simulkade.com/posts/2015-05-11-tracer-flow-porous-media.html |
| 2 | +Nx=50; |
| 3 | +Ny=50; |
| 4 | +Lx=1.0; % (m) |
| 5 | +Ly=1.0; % (m) |
| 6 | +% physical values |
| 7 | +D_val=1.0e-9; % (m^2/s) |
| 8 | +mu_val=1e-3; % (Pa.s) |
| 9 | +poros=0.2; |
| 10 | +perm_val=1.0e-12; % (m^2) |
| 11 | +clx=0.05; |
| 12 | +cly=0.05; |
| 13 | +V_dp=0.6; |
| 14 | +perm= field2d(Nx,Ny,perm_val,V_dp,clx,cly); |
| 15 | +% physical system |
| 16 | +u_inj=1.0/(3600*24); % (m/s) |
| 17 | +c_init=0.0; |
| 18 | +c_inj=1.0; |
| 19 | +p_out=100e5; % (Pa) |
| 20 | +% create mesh and assign values to the domain |
| 21 | +m= createMesh2D(Nx, Ny, Lx, Ly); |
| 22 | +k=createCellVariable(m, perm); |
| 23 | +phi=createCellVariable(m,poros); |
| 24 | +D=createCellVariable(m, D_val); |
| 25 | +% Define the boundaries |
| 26 | +BCp = createBC(m); % Neumann BC for pressure |
| 27 | +BCc = createBC(m); % Neumann BC for concentration |
| 28 | +% change the right boandary to constant pressure (Dirichlet) |
| 29 | +BCp.right.a(:)=0.0; |
| 30 | +BCp.right.b(:)=1.0; |
| 31 | +BCp.right.c(:)=p_out; |
| 32 | +% left boundary |
| 33 | +BCp.left.a(:)=-perm_val/mu_val; |
| 34 | +BCp.left.c(:)=u_inj; |
| 35 | +% change the left boundary to constant concentration (Dirichlet) |
| 36 | +BCc.left.a(:)=0.0; |
| 37 | +BCc.left.b(:)=1.0; |
| 38 | +BCc.left.c(:)=1.0; |
| 39 | +labda_face=harmonicMean(m, k/mu_val); |
| 40 | +Mdiffp=diffusionTerm(m,labda_face); |
| 41 | +[Mbcp, RHSp] = boundaryCondition(m,BCp); |
| 42 | +Mp= Mdiffp+Mbcp; |
| 43 | +p_val=solvePDE(m, Mp, RHSp); |
| 44 | +figure(1) |
| 45 | +visualizeCells(m,p_val); |
| 46 | +title('Pressure profile (Pa)'); |
| 47 | +colorbar(); |
| 48 | + |
| 49 | +% estimate a practical time step |
| 50 | +n_loop=50; |
| 51 | +dt=Lx/u_inj/(5*100); % (s) |
| 52 | +% find the velocity vector |
| 53 | +u=-labda_face.*gradientTerm(m, p_val); % (m/s) |
| 54 | +% find the matrices of coefficients |
| 55 | +D_face=harmonicMean(m, phi.*D); |
| 56 | +Mdiffc=diffusionTerm(m, D_face); |
| 57 | +Mconvc=convectionUpwindTerm(m, u); |
| 58 | +[Mbcc, RHSbcc] = boundaryCondition(m, BCc); |
| 59 | +% initialize |
| 60 | +c_old = createCellVariable(m, c_init, BCc); |
| 61 | +c.value = c_old; |
| 62 | +c.Old = c_old; |
| 63 | +% start the loop |
| 64 | +for i=1:n_loop |
| 65 | + [Mtransc, RHStransc] = transientTerm(m, phi, dt, c); |
| 66 | + Mc=-Mdiffc+Mconvc+Mbcc+Mtransc; |
| 67 | + RHSc=RHSbcc+RHStransc; |
| 68 | + c_val=solvePDE(m, Mc, RHSc); |
| 69 | + c.Old=c_val; |
| 70 | +end |
| 71 | +figure(2); |
| 72 | +subplot(1,2,1); |
| 73 | +visualizeCells(m, c_val); |
| 74 | +title('concentration profile'); |
| 75 | +colorbar(); |
| 76 | +subplot(1,2,2); |
| 77 | +pcolor(k); |
| 78 | +colorbar() |
| 79 | +title('perm field'); |
0 commit comments