0% found this document useful (0 votes)
9 views10 pages

Code Implimentation

The document outlines a computational model for simulating fluid concentration over time and space using diffusion and advection equations. It includes parameters for fluid velocity, diffusion coefficients, and grid dimensions, along with stability conditions and initial concentration settings. The model generates concentration plots and contour figures to visualize the results at specified time steps and coordinates.

Uploaded by

genetumelese50
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views10 pages

Code Implimentation

The document outlines a computational model for simulating fluid concentration over time and space using diffusion and advection equations. It includes parameters for fluid velocity, diffusion coefficients, and grid dimensions, along with stability conditions and initial concentration settings. The model generates concentration plots and contour figures to visualize the results at specified time steps and coordinates.

Uploaded by

genetumelese50
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

U=1 velocity of the fluid in the x-direc on

V=0 velocity component in the y-direc on

DTx=10^(-3); is the diffusion coefficient x-direc on

DTy=DTx;

Length (m)

dx=0.5 Change in the x direc on

dy=0.5 Change in the x direc on

xmin=0 minimum value of x-axis

xmax=100 maximum value of x-axis

x=xmin:dx:xmax For example the first value is 0 then the


second is 0.6 the next will be 0.6+0.6=1.2 this con nues up to 60

nx=length(x) number of nodes along y

xC0=20 ini al loca on of C0 along x

ymin=0 minimum value of x-axis

ymax=10 maximum value of x-axis

Y=ymax;

y=ymin:dy:ymax For example the first value is 0 then the


second is 0.6 the next will be 0.6+0.6=1.2 this con nues up to 10

ny=length(y) number of nodes along y

yC0=ymax/2 ini al loca on of C0 along y

dt1=1/(U/dx+2*DTx/(dx^2));

dt2=(1/U)*(2*DTx+dx);

dt3=1/(V/dy+2*DTy/(dy^2)); Stability condi ons, upwind scheme

dt4=(1/V)*(2*DTy+dy);

dt=0.7*min([dt1,dt2,dt3,dt4]); % 70% of dt1, dt2, dt3 or dt4


tmin=0 the minimum value of t

tmax=70 maximum value of t

t=tmin:dt:tmax; For example, the first value is 0 then the


second is 0.13125

nt=length(t); This is nodes along the me dimension (70/0.13125) + 1

Courant number

Crx=U*(dt/dx)

Cry=V*(dt/dy)

Diffusive parameter

deltax=DTx*(dt/(dx)^2) discre zed version of the diffusion

deltay=DTy*(dt/(dy)^2)

Peclet number

Pex=Crx/deltax;

Pey=Cry/deltay;

Ini al concentra on

C0=1; % g/L

C=zeros(nx,ny,nt);

nx0=xC0/dx+1; The number of nodes for x up to the ini al concentra on

ny0=yC0/dy+1; The number of nodes for y up to the ini al concentra on


C(1:(nx0-1), 1:(ny0-1), 1) = C0;

1:(nx0-1) will iterate for the x form 1 up to the last node which means xCo/dx+1

1:(ny0-1) will iterate for the y form 1 up to the last node which means yCo/dx+1

For example, some of the outputs of the above are

C(1,1,1)=1

C(2,1,1)=1

C(3,1,1)=1

C(4,1,1)=1

Sets all the matrix where the loop points out to Co=1

figure (1) Creates a new figure window with number 1

plot(y,C(1,:,1)) % Concentra on only along y Plots the concentra on values along the
y-axis at the first x-axis loca on and at the first me step.

tle("Concentra on along y for ini al condi on at t=0s") Sets the tle of the plot

xlim([0 ymax]) Sets the x-axis from 0 up to ymax

xlabel("y (m)") Lables the x-axis to”y(m)”

ylim([0 C0]) Sets the x-axis from 0 up to Co

ylabel("C (g/L)") Lables the y-axis to"C (g/L)"


figure (2)

plot(x,C(:,1,1)) % Concentra on only along x

tle("Concentra on along x for ini al condi on at t=0s")

xlim([0 xmax])

xlabel("x (m)")

ylim([0 C0])

ylabel("C (g/L)")

A=deltax(δx);

B=deltay(δy);

D=deltax(δx)+Crx;

E=deltay(δy)+Cry;

F=1-2*deltax-2*deltay-Crx-Cry;
Temporal loop

for k = 1:(nt-1)

Update concentra on for the next me step

C(:,:,k+1) = updateConcentra on(C(:,:,k), A, B, D, E, F, nx, ny)

end

In the above code when we get to the func on calling the func on carries the arguments or parameters
and will be jumping or going to the func on created.

figure(3), Creates windows figure(3)

color

subplot(4,1,1) Creates a 4 row plots in one window(figure) at me writen


on the (Z)third dimension)

contourf(C(:,:,1)') Ceates a graphical representa on by filling it with the


concentra on color from the concentra on bar

tle('t=0s') Lables the me as t then “value given here”

colorbar it provides a key for interpre ng the colors in terms of the data
values they represent.

clim([0 C0]) Starts 0 and stops at the set concentra on

subplot(4,1,2)

contourf(C(:,:,44)')

tle('t=15s')

colorbar

clim([0 C0])

subplot(4,1,3)

contourf(C(:,:,87)')

tle('t=30s')

colorbar

clim([0 C0])
subplot(4,1,4)

contourf(C(:,:,145)')

tle('t=50s')

xlabel("along x")

ylabel("along y")

colorbar

clim([0 C0])

figure(4)

contourf(C(:,:,nt)')

tle('t=70s')

xlabel("along x")

ylabel("along y")

colorbar

clim([0 C0])

figure (5)

plot(x,C(:,:,nt)) % Concentra on only along x

tle("Concentra on along x for final me")

xlim([0 xmax])

xlabel("x (m)")

ylim([0 C0])

ylabel("C (g/L)")

Fr=U/sqrt(9.81*Y);
Define the specific y-coordinate

y_desired = 4 y-coordinate where you want to slice the data

x_desired = 10 x-coordinate where you want to slice the data

[~, yIndex] = min(abs(y - y_desired)); For y = 10

[~, xIndex] = min(abs(x - x_desired)); For x = 10

Extract concentra on data for all x and t at y = 10, and all y and t at x = 10

concentra onSliceY = squeeze(C(:, yIndex, :))

concentra onSliceX = squeeze(C(xIndex, :, :))

% Correct the orienta on if necessary

if size(concentra onSliceY, 1) ~= length(x) || size(concentra onSliceY, 2) ~= length(t)

concentra onSliceY = concentra onSliceY'; % Transpose

end

checks if the number of rows in concentra onSliceY is equal to the number of elements in x. Similarly,
size(concentra onSliceY, 2) ~= length(t) checks if the number of columns in concentra onSliceY equals
the number of elements in t.

Transposing concentra onSliceY swaps its rows and columns, ensuring the first dimension aligns with x
and the second with t.

if size(concentra onSliceX, 1) ~= length(y) || size(concentra onSliceX, 2) ~= length(t)

concentra onSliceX = concentra onSliceX'; % Transpose

end
% Contour plot for y = 10 (all x over me)

figure(9);

contourf(x, t, concentra onSliceY);

colorbar;

xlabel('x-coordinate');

ylabel('Time');

tle(['Concentra on over x and Time at y = ', num2str(y_desired)]);

clim([0 C0])

% Contour plot for x = 10 (all y over me)

figure(10);

contourf(t, y, concentra onSliceX);

colorbar;

xlabel('Time');

ylabel('y-coordinate');

tle(['Concentra on over y and Time at x = ', num2str(x_desired)]);

clim([0 C0])
% Func on to update the concentra on matrix

func on C_updated = updateConcentra on(C, A, B, D, E, F, nx, ny)

C_updated = C; % Ini alize with current concentra on values

% Loop over spa al dimensions (excluding the boundaries)

for i = 2:(nx-1)

for j = 2:(ny-1)

% Compute the new concentra on value

C_updated(i,j) = A * C(i+1,j) + B * C(i,j+1) + D * C(i-1,j) + ...

E * C(i,j-1) + F * C(i,j);

End

C_updated(:,1) = C_updated(:,2); % Bo om boundary

C_updated(:,ny) = C_updated(:,ny-1); % Top boundary

end

% Boundary condi ons

C_updated(1,:) = C_updated(2,:); % Le boundary

C_updated(nx,:) = C_updated(nx-1,:); % Right boundary

End

You might also like