Effacer les filtres
Effacer les filtres

Algae growing. Concentration curve problem

3 vues (au cours des 30 derniers jours)
Alfonso
Alfonso le 23 Jan 2024
Commenté : Alfonso le 2 Fév 2024
Hi! i have made the following code:
function w = Bioreactor
clc
clear all
% Forward Euler method is used for solving the following boundary value problem:
% Problem parameters
alpha1 = 5*10^(-4); % Diffusion coefficient [m^2/s]
mu0 = 5;
mue = 3.5;
Hl = 5;
T = 5000; % [s]
nz = 100; nt = 1000;
KP = 2;
HP= 7;
PC = 1;
K = 2;
KN = 3;
HN = 14.5*10^(-6);
NC = 2;
KC = 5;
HC = 5 ;
PHs3 = 4 ;
PHs4 = 5;
lambda = 2 ;
rs= 10;
P(1)=3; % Initial chosen concentration of P [g/L]
N(1)=9; % Initial chosen concentration of N [g/L]
C(1)=30; % Initial chosen concentration of C [g/L]
Z = 10; % Lenght of the bioreactor [m]
%Check of the problem's parameters
if any([P(1)-PC N(1)-NC] <=0 )
error('Check problem parameters')
end
if any([alpha1 mu0 Hl Z T nz-2 nt-2 KP P(1) PC HC KN N(1) NC KC HC C(1) HN ] <= 0)
error('Check problem parameters')
end
% Stability
dz = Z/nz;
st = 1/2;
dt = st*dz^2/alpha1;
nt = T/dt;
% Initialization
z = linspace(0,Z,nz+1); t = linspace(0,T,nt+1);
nt = round(nt); % Round nt to an integer
nz = round(nz); % Round nz to an integer
N = zeros(1, nt+1); % Initialize N to zero
P = zeros(1, nt+1); % Initialize P to zero
C = zeros(1, nt+1); % Initialize C to zero
I0 = @(t) 100*max(sin ((t-0.4*3600)/(6.28)) , sin (0));
w = zeros(nz+1,nt+1);
% Finite-difference method
for j = 1:nt
f1= (KP*(P(j)-PC))/(HP+(P(j)-PC));
f2 = (KN*(N(j)-NC))/(HN+(N(j)-NC));
pH = (6.35 - log10(C(j))) /2 ;
f3 = 1/(1+exp(lambda*(pH-PHs3)));
f4 = 1/(1+exp(lambda*(pH-PHs4)));
I_in = I0(t(j)).*exp(-K*z.').*exp((-rs).*cumtrapz(z.',w(:,j)));
g = mu0*I_in./(Hl+I_in);
integral_term = f1 * f2 * f3 * trapz(z.',g.*w(:,j)); % Data organization
N(j+1) = N(j) + dt*( -1/Z*integral_term*N(j)); % Function of N over the time and space
P(j+1) = P(j) + dt*( -1/Z*integral_term*P(j)); % Function of P over the time and space
C(j+1) = C(j) + dt*( -1/Z*integral_term*C(j)); % Function of C over the time and space
w(nz+1,j+1) = 9; % Algae concentration at z=0 [Dirichlet]
w(2:nz,j+1) = w(2:nz,j) + dt*(f1*f2*f3*w(2:nz,j).*g(2:nz) + alpha1 * (w(3:nz+1,j)-2*w(2:nz,j)+w(1:nz-1,j))/dz^2);
w(1,j+1) = w(2,j+1); % Algae concentration at z=10 [Neumann]
plot(z,flipud(w(:,j+1)),'b');
%set(gca,'XDir','reverse');
xlabel('z'); ylabel('w');
title(['t=',num2str(t(j)),' s']);
axis([0 10 0 10]);
pause(0.0001);
end
end
And the code is working perfectly. But the W which is the algae concentration over space and time it has been fixed a value of 9 mg/L at the beginning of this bioreactor, so at z=0, im talking about the following row:
w(nz+1,j+1) = 9; % Algae concentration at z=0 [Dirichlet]
But now i would like to fix this concentration at a certain z which has to be equal to z=Z/2 so at the half of the bioreactor. I know that in order to make the code working for sure i have to modify this row:
w(2:nz,j+1) = w(2:nz,j) + dt*(f1*f2*f3*w(2:nz,j).*g(2:nz) + alpha1 * (w(3:nz+1,j)-2*w(2:nz,j)+w(1:nz-1,j))/dz^2);
Can you help me to do that? I've tried something but anything really worked.
Thanks, attached to this post there is the file from which i took the equations.
I should have a graph like this:

Réponses (1)

Torsten
Torsten le 23 Jan 2024
Modifié(e) : Torsten le 23 Jan 2024
Here is a code for a simple heat-conduction equation
dT/dt = d^2T/dz^2
T(z,0) = 0
T(0,t) = 200
T(1,t) = 340
T(0.5,t) = 90
You should be able to adapt it to your application.
L = 1;
zcut = L/2;
n1 = 50;
n2 = 50;
z1 = linspace(0,zcut,n1);
dz1 = z1(2)-z1(1);
z2 = linspace(zcut,L,n2);
dz2 = z2(2)-z2(1);
tstart = 0;
tend = 1;
dt = 1e-5;
nt = round((tend-tstart)/dt);
t = linspace(tstart,tend,nt);
T_at_zcut = 90;
T_at_0 = 200;
T_at_L = 340;
T = zeros(n1+n2-1,nt);
T(1,:) = T_at_0;
T(end,:) = T_at_L;
T(n1,:) = T_at_zcut;
for i = 1:nt-1
T(2:n1-1,i+1) = T(2:n1-1,i) + dt/dz1^2*(T(3:n1,i)-2*T(2:n1-1,i)+T(1:n1-2,i));
T(n1+1:n1+n2-2,i+1) = T(n1+1:n1+n2-2,i) + dt/dz2^2*(T(n1+2:n1+n2-1,i)-...
2*T(n1+1:n1+n2-2,i)+T(n1:n1+n2-3,i));
end
plot([z1,z2(2:end)],[T(:,1),T(:,100),T(:,250),T(:,500),T(:,750),T(:,1000),T(:,2500),T(:,5000),T(:,7500),T(:,end)])
  26 commentaires
Alfonso
Alfonso le 2 Fév 2024
Ok, man i will check. At least i didn't check the dimension before D:
Alfonso
Alfonso le 5 Fév 2024
@Torsten also with the right dimension the code doesn't work very well. Can i ask you a question? If i have this code:
function w = Bioreattore
clc
clear all
% Forward Euler method is used for solving the following boundary value problem:
% Problem parameters
Dm = 5*10^(-4); %m^2/s
mu0 = 8000%2.5; % L/day
mue = 3.5; % 1/day
Hl = 5; %half-saturation intensity W/(m^2*day)
T = 10000; % [s]
nz = 100; nt = 1000;
KP = 2 ;
HP= 7; %half-saturation concentrations of Phosphates
PC = 1; %critical concentration of the phosphates dopo la quale la crescita di w va a 0.
K = 2;
KN = 3 ;
HN = 0.02; %14.5*10^(-6); %half-saturation concentrations of nitrates [mgN/L]
NC = 2; %critical concentration of the nitrates dopo la quale la crescita di w va a 0.
KC = 5;
HC = 5 ;
PHs3 = 9 ; %describes the "switching" value of pH at which the growth increases if all other factors are kept unchanged.
lambda = 2 ; %sharpness of the profile of the f3 function
rs= 10; %L*m/d
P(1)=50; % Initial chosen concentration of P [mg/L]
N(1)=330; % Initial chosen concentration of N [mg/L]
C(1)=2100; % Initial chosen concentration of C/ Aumentando C, si abbassa il pH(+acido) e aumenta la morte algale [mg/L]
Z = 10; % Lenght of the bioreactor
%Check of the problem's parameters
if any([P(1)-PC N(1)-NC] <=0 )
error('Check problem parameters')
end
if any([Dm mu0 Hl Z T nz-2 nt-2 KP P(1) PC HC KN N(1) NC KC HC C(1) HN ] <= 0)
error('Check problem parameters')
end
% Stability
dz = Z/nz;
st = 1/2;
dt = st*dz^2/Dm;
nt = T/dt;
% Initialization
z = linspace(0,Z,nz+1); t = linspace(0,T,nt+1);
nt = round(nt); % Round nt to an integer
nz = round(nz); % Round nz to an integer
N = zeros(1, nt+1); % Initialize N to zero
P = zeros(1, nt+1); % Initialize P to zero
C = zeros(1, nt+1); % Initialize C to zero
I0 = @(t) 100*max(sin ((t-0.4*3600)/(6.28)) , sin (0));
w = zeros(nz+1,nt+1);
w(:,1) = 0; %Final concentration of the algae
% Finite-difference method
for j = 1:nt
f1= (KP*(P(j)-PC))/(HP+(P(j)-PC))
f2 = (KN*(N(j)-NC))/(HN+(N(j)-NC))
pH = (6.35 - log10(C(j))) /2 %relation between the pH and the concentration of carbon dioxide
f3 = 1/(1+exp(lambda*(pH-PHs3))) %The growth rate dependence function. Si riduce se il tutto diventa più acido (pH scende)..
Ha = mue*f3; %death rate of the algae. [gCOD/L]
I_in = I0(t(j)).*exp(-K*z.').*exp((-rs).*cumtrapz(z.',w(:,j))); % W/m^2*s
g = mu0*I_in./(Hl+I_in);
integral_term = f1 * f2 * f3 * trapz(z.',g.*w(:,j)); % Data organization
N(j+1) = N(j) + dt*( -1/Z*integral_term*N(j)); % Function of N over the time and space
P(j+1) = P(j) + dt*( -1/Z*integral_term*P(j)); % Function of P over the time and space
C(j+1) = C(j) + dt*( -1/Z*integral_term*C(j)); % Function of C over the time and space
w(nz+1,j+1) = 5; % Algae concentration at z=0 [gSST/L]
w(2:nz,j+1) = w(2:nz,j) + dt*(f1*f2*f3*w(2:nz,j).*g(2:nz) + Dm * (w(3:nz+1,j)-2*w(2:nz,j)+w(1:nz-1,j))/dz^2)- Ha*w(2:nz,j);
w(1,j+1) = w(2,j+1); % Algae concentration at z=10
plot(z,flipud(w(:,j+1)),'b');
%set(gca,'XDir','reverse');
xlabel('z'); ylabel('w');
title(['t=',num2str(t(j))]);
axis([0 10 0 10]);
pause(0.0001);
end
end
How can i modify the plot to obtain the following graphs:

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by