Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
executable file 134 lines (133 sloc) 4.94 KB
 % Coupled nonlinear PDE's % Buckley Leverett equation % dependent variables: pressure and water saturation % Prepared for educational purposes by ** AAE ** clc; clear; %% define the geometry Nx = 100; % number of cells in x direction Ny = 30; % number of cells in y direction W = 300; % [m] length of the domain in x direction H = 30; % [m] length of the domain in y direction m = createMesh2D(Nx, Ny, W, H); % creates a 2D mesh %% define the physical parametrs krw0 = 1.0; kro0 = 0.76; nw = 2.4; no = 2.0; sor=0.12; swc=0.09; sws=@(sw)((sw>swc).*(sw<1-sor).*(sw-swc)/(1-sor-swc)+(sw>=1-sor).*ones(size(sw))); kro=@(sw)((sw>=swc).*kro0.*(1-sws(sw)).^no+(sw1-sor).*(-(1-krw0)/sor.*(1.0-sw)+1.0)); dkrwdsw=@(sw)((sw<=1-sor).*nw.*krw0.*(1/(1-sor-swc)).*sws(sw).^(nw-1)+(sw>1-sor)*((1-krw0)/sor)); dkrodsw=@(sw)((sw>=swc).*(-kro0*no*(1-sws(sw)).^(no-1))/(-swc-sor+1)+(sweps_p) || (error_sw>eps_sw)) loop_count=loop_count+1; if loop_count>10 break end % calculate parameters pgrad = gradientTerm(p); sw_face = upwindMean(sw, -pgrad); % average value of water saturation labdao = lo.*funceval(kro, sw_face); labdaw = lw.*funceval(krw, sw_face); dlabdaodsw = lo.*funceval(dkrodsw, sw_face); dlabdawdsw = lw.*funceval(dkrwdsw, sw_face); labda = labdao+labdaw; dlabdadsw = dlabdaodsw+dlabdawdsw; % compute [Jacobian] matrices Mdiffp1 = diffusionTerm(-labda); Mdiffp2 = diffusionTerm(-labdaw); Mconvsw1 = convectionUpwindTerm(-dlabdadsw.*pgrad); Mconvsw2 = convectionUpwindTerm(-dlabdawdsw.*pgrad); [Mtranssw2, RHStrans2] = transientTerm(sw_old, dt, phi); % Compute RHS values RHS1 = divergenceTerm(-dlabdadsw.*sw_face.*pgrad); RHS2 = divergenceTerm(-dlabdawdsw.*sw_face.*pgrad); % include boundary conditions [Mbcp, RHSbcp] = boundaryCondition(BCp); [Mbcsw, RHSbcsw] = boundaryCondition(BCs); % Couple the equations; BC goes into the block on the main diagonal M = [Mdiffp1+Mbcp Mconvsw1; Mdiffp2 Mconvsw2+Mtranssw2+Mbcsw]; RHS = [RHS1+RHSbcp; RHS2+RHStrans2+RHSbcsw]; % solve the linear system of equations x = M\RHS; % x = agmg(M, RHS, [], 1e-10, 500, [], [p.value(:); sw.value(:)]); % separate the variables from the solution p_new = reshapeCell(m,full(x(1:(Nx+2)*(Ny+2)))); sw_new = reshapeCell(m,full(x((Nx+2)*(Ny+2)+1:end))); % calculate error values error_p = max(abs((p_new(:)-p.value(:))./p_new(:))); error_sw = max(abs(sw_new(:)-sw.value(:))); % assign new values of p and sw p.value = p_new; sw.value = sw_new; end if loop_count>10 p=p_old; sw=sw_old; dt=dt/5; continue end dsw=max(abs(sw_new(:)-sw_old.value(:))./sw_new(:)); t=t+dt dt=min([dt*(dsw_alwd/dsw), 2*dt, t_end-t]); p_old = p; sw_old = sw; figure(1);visualizeCells(sw); drawnow; end
You can’t perform that action at this time.