Solve a complex differential equations system

12 vues (au cours des 30 derniers jours)
Diego Rampi
Diego Rampi le 10 Avr 2024
Modifié(e) : Diego Rampi le 1 Oct 2024
I need to write a script that can solve the system of differential equation written in this article.
Thank you to everyone who will try to help me:)
  1 commentaire
Torsten
Torsten le 10 Avr 2024
And what is your specific question ?

Connectez-vous pour commenter.

Réponses (1)

Torsten
Torsten le 10 Avr 2024
The main problem with your equations is that they involve a term that has to be evaluated at a boundary point. Otherwise, you could have tried to use "pdepe". You could also look into "pde1m" under
I'm not sure if you have access to the values in all grid points with this code.
If it cannot solve your equations, you will have to discretize the spatial derivatives, include the boundary conditions and use "ode15s" to solve the resulting system of ordinary differential equations. Look up "method of lines" for more details.
  7 commentaires
Diego Rampi
Diego Rampi le 30 Sep 2024
the "pde1dm" solver seems to be to rigid for my problem because allows the solution of a PDE structured in the way reported at page 2 of the manual.
I don't now if is possible to write the script in a way that can solve my system, reported below:
\left\{\begin{array}{l}
\frac{\partial \mathrm{T}}{\partial \mathrm{t}}-\frac{\mathrm{y} \bar{v}+\left(v^{*}-\bar{v}\right)}{\bar{v} \mathrm{t}-\mathrm{H}} \frac{\partial \mathrm{T}}{\partial \mathrm{y}}-\frac{\alpha}{\mathrm{T}_{\text {ILG }}} \frac{1}{(\bar{v} \mathrm{t}-\mathrm{H})^{2}}\left(\mathrm{~T} \frac{\partial^{2} \mathrm{~T}}{\partial \mathrm{y}^{2}}-\left(\frac{\partial \mathrm{T}}{\partial \mathrm{y}}\right)^{2}+\left.\frac{\partial \mathrm{T}}{\partial \mathrm{y}} \frac{\partial \mathrm{T}}{\partial \mathrm{y}}\right|_{\mathrm{y}=0}\right)=0 \tag{13}\\
\frac{\partial \mathrm{C}}{\partial \mathrm{t}}-\frac{\mathrm{y} \bar{v}+\left(v^{*}-\bar{v}\right)}{\bar{v} \mathrm{t}-\mathrm{H}} \frac{\partial \mathrm{C}}{\partial \mathrm{y}}-\frac{\mathrm{E}}{(\bar{v} \mathrm{t}-\mathrm{H})^{2}} \frac{\partial^{2} \mathrm{C}}{\partial \mathrm{y}^{2}}+\frac{\alpha}{\mathrm{T}_{\text {ILG }}} \frac{1}{(\bar{v} \mathrm{t}-\mathrm{H})^{2}}\left(\frac{\partial \mathrm{C}}{\partial \mathrm{y}}\left(\frac{\partial \mathrm{T}}{\partial \mathrm{y}}-\left.\frac{\partial \mathrm{T}}{\partial \mathrm{y}}\right|_{\mathrm{y}=0}\right)+\mathrm{C} \frac{\partial^{2} \mathrm{~T}}{\partial \mathrm{y}^{2}}\right)=0
\end{array}\right.
Anyone as an idea?
I really appreciate your help, thank you!
Diego Rampi
Diego Rampi le 30 Sep 2024
Modifié(e) : Diego Rampi le 1 Oct 2024
This is my code for now:
clear;
clc;
% Parametri del serbatoio
H = 14; % Altezza del serbatoio in metri
diametro = H; % Diametro del serbatoio in metri
V_serbatoio = pi * (diametro / 2)^2 * H; % Volume del serbatoio
V_90 = 0.9 * V_serbatoio; % 90% del volume del serbatoio
P = 1e5; % Pressione in Pa
% Parametri fisici e costanti del Decano
M = 0.14; % Massa molare del Decano in kg/mol
R_gas = 8.314; % Costante dei gas perfetti in J/(mol*K)
k = 0.026; % Conducibilità termica dell'aria in W/m·K
D = 1.1e-5; % Diffusività in m²/s
cp = 2250; % Calore specifico in J/kg·K
mu = 1.8e-5; % Viscosità dinamica dell'aria (Pa·s)
cpL = 2000; % Calore specifico del Decano liquido in J/kg·K
h_L = 10; % Coefficiente di scambio termico del liquido W/m²·K
rho_liq = 740; % Densità del Decano liquido a 298 K in kg/m³
DeltaH_evap = 40000; % Calore latente di evaporazione in J/mol
% Costanti di Antoine per il calcolo della tensione di vapore del Decano
A_ant = 0.21021;
B_ant = 440.616;
C_ant = -156.896;
H_c = 2e-6; % Costante di Henry per il Decano in aria (mol/(m^3*Pa))
TL = 298; % Temperatura del liquido costante a 298 K
% Parametri di discretizzazione
N = 150; % Numero di nodi spaziali
dz = H / (N - 1); % Passo spaziale
t_max = 30 * 24 * 3600; % 30 giorni in secondi
z = linspace(0, H, N); % Discretizzazione spaziale
t_vec = linspace(0, t_max, 200); % Punti temporali
% Condizioni iniziali
T_init = 300 * ones(N, 1); % Temperatura iniziale uniforme (K)
C_init = linspace(0.02, 0.01, N)'; % Gradiente iniziale della concentrazione
y0 = [T_init; C_init];
% Velocità media del liquido
transition_time = 3600; % 1 ora di transizione
t_riempimento = 24 * 3600; % 24 ore di riempimento
t_riposo = 5 * 24 * 3600; % 5 giorni di riposo
t_svuotamento = 24 * 3600; % 24 ore di svuotamento
cycle_duration = t_riempimento + t_riposo + t_svuotamento;
% Funzione per la velocità media nel tempo
v_avg_func = @(t) v_cicli(t, V_90, diametro, t_riempimento, t_riposo, t_svuotamento, cycle_duration, transition_time);
% Risolvi il sistema di PDE usando pde1dm (inseriamo m=0 per geometria 1D)
m = 0; % Geometria 1D cartesiana
sol = pde1dm(m, @(x,t,u,dudx) pde_fun(x,t,u,dudx, diametro, v_avg_func, D, mu, cp), @ic_fun, @(xl,ul,xr,ur,t) bc_fun(xl,ul,xr,ur,t,v_avg_func, V_90, diametro, H, t_riempimento, t_riposo, t_svuotamento, cycle_duration, transition_time, P, M, R_gas, mu, D, k, cp, DeltaH_evap, A_ant, B_ant, C_ant, H_c, TL, h_L, cpL, rho_liq), z, t_vec); % Chiamata pde1dm
Warning: Failure at t=8.640000e+04. Unable to meet integration tolerances without reducing the step size below the smallest value allowed (3.069545e-10) at time t.
% Visualizzazione della soluzione
T_sol = sol(:, :, 1); % Estrae la soluzione di T
C_sol = sol(:, :, 2); % Estrae la soluzione di C
% Calcolo di C_top / C_sat
C_top_over_Csat = C_sol(:, end) ./ C_sol(:, 1);
% Grafico di C(top,t)/C_sat nel tempo
figure;
plot(t_vec / 3600, C_top_over_Csat, '-o'); % Tempo in ore
Error using plot
Specify the coordinates as vectors or matrices of the same size, or as a vector and a matrix that share the same length in at least one dimension.
xlabel('Tempo (ore)');
ylabel('C(top,t) / C_{sat}');
title('Andamento di C(top,t) / C_{sat} nel tempo');
grid on;
%% Funzione PDE per il sistema accoppiato (T e C)
function [c, f, s] = pde_fun(x, t, u, dudx, diametro, v_avg_func, D, mu, cp)
T = u(1); % Temperatura
C = u(2); % Concentrazione
dTdz = dudx(1);
dCdz = dudx(2);
P = 1e5; % Pressione
M = 0.14; % Massa molare
R_gas = 8.314; % Costante dei gas
k = 0.026; % Cond. termica
% Calcolo della densità
rho = P * M / (R_gas * T); % Densità variabile
% Calcolo della velocità media e v_star
v_avg = v_avg_func(t);
v_star = v_avg - (D / rho) * dCdz; % Calcolo di v_star
% Calcolo dei numeri adimensionali
nu = mu / rho; % Viscosità cinematica
Sc = nu / D; % Numero di Schmidt
Pr = nu / (k / (cp * rho)); % Numero di Prandtl
Re = v_avg * diametro * rho / mu; % Numero di Reynolds
% Coefficiente di dispersione assiale E
E = v_avg * diametro * (1 / (Re * Sc) + (Re * Sc) / 192);
% Coefficiente di dispersione termica E_t
E_t = v_avg * diametro * (1 / (Re * Pr) + (Re * Pr) / 192);
% Diffusività termica
alpha = E_t / (rho * cp); % Diffusività termica
% Velocità del vapore v
v = v_star + alpha / T * (dTdz - dTdz(1)); % Velocità del vapore
% Derivate temporali
c = [1; 1];
% Derivate spaziali (prime e seconde)
f = [alpha * dTdz; D * dCdz]; % Usa E e D per calcolare i contributi spaziali
% Termini sorgente accoppiati
s = [0; -D / rho * dCdz * dTdz]; % Accoppiamento tra T e C
end
%% Funzione per le condizioni iniziali
function u0 = ic_fun(x)
T0 = 300;
C0 = 0.02;
u0 = [T0; C0];
end
%% Funzione per le condizioni al contorno
function [pl, ql, pr, qr] = bc_fun(xl, ul, xr, ur, t, v_avg_func, V_90, diametro, H, t_riempimento, t_riposo, t_svuotamento, cycle_duration, transition_time, P, M, R_gas, mu, D, k, cp, DeltaH_evap, A_ant, B_ant, C_ant, H_c, TL, h_L, cpL, rho_liq)
% Calcola la velocità media
v_avg = v_avg_func(t);
% Calcolo di dTdz e dCdz in y=0
dTdz_0 = (ul(1) - ur(1)) / (H / (length(ul) - 1)); % Approssimazione della derivata prima per T
dCdz_0 = (ul(2) - ur(2)) / (H / (length(ul) - 1)); % Approssimazione della derivata prima per C
% Calcolo dinamico di T_ILG e C_sat tramite Antoine e legge di Henry
T_ILG = calc_T_ILG(TL, dTdz_0, dCdz_0, h_L, k, cpL, rho_liq, DeltaH_evap, v_avg, diametro, D);
P_vap = (10^(A_ant - B_ant / (T_ILG + C_ant))) * 1e5; % Pa
C_sat = P_vap * H_c; % mol/m³ (dalla legge di Henry)
% Condizioni al contorno alla base (y=0): T = T_ILG, C = C_sat
pl = [ul(1) - T_ILG; ul(2) - C_sat]; % T(0)=T_ILG, C(0)=C_sat
ql = [0; 0]; % Condizione di Dirichlet
% Condizioni al contorno al tetto (y=1)
if v_avg > 0 % Exhale: derivata nulla della concentrazione
pr = [ur(1) - 295; 0]; % T(H)=295, dC/dy(H) = 0
qr = [0; 1]; % Condizione Neumann per la concentrazione
else % Inhale: derivata non nulla per C
rho = P * M / (R_gas * ur(1)); % Densità variabile
nu = mu / rho;
Sc = nu / D;
Re = v_avg * diametro * rho / nu;
E = v_avg * diametro * (1 / (Re * Sc) + (Re * Sc) / 192);
% Condizione per inhale: derivata non nulla della concentrazione
pr = [ur(1) - 295; (H - v_avg * t) / E];
qr = [0; 1];
end
end
%% Funzione per calcolare T_ILG basato sul bilancio termico
function T_ILG = calc_T_ILG(TL, dTdz, dCdz, h_L, k, cpL, rho_liq, DeltaH_evap, v_avg, diametro, D)
% Calcolo della massa del liquido in base alla velocità media
V_liq = v_avg * (pi * (diametro / 2)^2); % Volume del liquido
m_liq = rho_liq * V_liq; % Massa del liquido
% Calcolo di T_ILG tramite bilancio termico
T_ILG = (h_L * (TL - 300) + m_liq * cpL * (TL - 300) + k * dTdz + D * dCdz * DeltaH_evap) / (h_L + m_liq * cpL);
end
%% Funzione per calcolare la velocità durante i cicli
function v_avg = v_cicli(t, V_90, diametro, t_riempimento, t_riposo, t_svuotamento, cycle_duration, transition_time)
v_riempimento = V_90 / (pi * (diametro / 2)^2 * t_riempimento);
v_svuotamento = -V_90 / (pi * (diametro / 2)^2 * t_svuotamento);
cycle_time = mod(t, cycle_duration);
if cycle_time <= t_riempimento
v_avg = v_riempimento * (1 + tanh((t_riempimento - cycle_time) / transition_time)) / 2;
elseif cycle_time <= (t_riempimento + t_riposo)
v_avg = 0;
else
v_avg = v_svuotamento * (1 + tanh((cycle_time - (t_riempimento + t_riposo)) / transition_time)) / 2;
end
end

Connectez-vous pour commenter.

Catégories

En savoir plus sur Polar Plots dans Help Center et File Exchange

Produits


Version

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by