Filter löschen
Filter löschen

ODE15s Unable to meet integration tolerances without reducing the step size below the smallest value allowed

5 Ansichten (letzte 30 Tage)
Nx = 50; % Number of grid points
L = 5000; % Length of the spatial domain
dx = L / (Nx - 1); % Spatial step size
x = linspace(0, L, Nx); % Spatial points
A=0.1963;
f = 0.008;
D = 500e-3;
rho=1.2;
c = 348.5;
tspan = [0, 3600]; % Time span (0 to 3600 seconds)
% Initial conditions
P0 = 5e6*ones(Nx,1); % Initial condition for pressure (P)
m0 = zeros(Nx, 1); % Initial condition for mass flow rate (m)
% Initial conditions vector
u0 = [P0; m0];
options = odeset('RelTol', 1e-6, 'AbsTol', 1e-6);
% Solve the system of ODEs using ode15s
[t, u] = ode15s(@(t, u) MyODEs(t, u, Nx, dx, f, c, D), tspan, u0,options);
Warning: Failure at t=7.137117e+01. Unable to meet integration tolerances without reducing the step size below the smallest value allowed (2.273737e-13) at time t.
% Extract the solutions for P and m
P_solution = u(:, 1:Nx);
m_solution = u(:, Nx + 1:end);
Q_n= (m_solution./rho); %m/sec
Q=(Q_n .*A);% m^3/sec
figure;
plot(t,Q , 'LineWidth', 2);
xlabel('Time (t)');
ylabel('Q');
title('Q over Time');
figure;
plot(t,P_solution , 'LineWidth', 2);
xlabel('Time (t)');
ylabel('P');
title('P over Time');
% Define the boundary conditions as separate ODEs
function dPdt = PBoundaryODE(t, P)
% This ODE defines how P(1, t) evolves with time
dPdt = 0;
end
function dmNdt = mBoundaryODE(t, m)
% This ODE defines how m(Nx, t) evolves with time
if t < 60
dmNdt = 0;
elseif t < 1800
dmNdt = 509.10;
else
dmNdt = 0;
end
end
% Set up the system of ODEs including the boundary condition ODEs
function dudt = MyODEs(t, u, Nx, dx, f, c, D)
P = u(1:Nx);
m = u(Nx+1:end);
dudt = zeros(Nx * 2, 1); % Initialize the derivative vector
% Continuity equation (dP/dt) for P= Nx
dudt(Nx) = -c^2 *(3*m(Nx) - 4*m(Nx - 1)+m(Nx-2)) / (2*dx) ; % Eq at P(Nx)- Backward discretization
% Momentum equation (dm/dt) for m = 1
dudt(Nx + 1) = -(4*P(2) - 3*P(1)-P(3)) / (2*dx) - (f * m(1)^2 * c^2) / (2 *D* (P(1))); % Eq at m(1) forward discretization ;
% Interior points for Pressure and Mass Flow Rate
for i = 2:Nx - 1
dudt(i) = -c^2 * (m(i+1) - m(i-1)) / (2 * dx);
dudt(i + Nx) = -(P(i+1) - P(i-1)) / (2 * dx) - f * m(i) * m(i) * c^2 / (2 * D * P(i));
end
% Pressure boundary condition ODE at i = 1
dudt(1) = PBoundaryODE(t, u(1));
% Mass flow rate boundary condition ODE at m(Nx, t)
dudt(2*Nx) =mBoundaryODE(t, u(2*Nx)); % Mass flow rate boundary condition ODE at m(Nx, t)
end
%% why boundary condition should be include in main function?
% So, even though you have separate functions for the boundary conditions,
% you still need to include their contributions within the main ODE function MyODEs.
% The reason for this is that the ODE solvers in MATLAB expect a single function that defines the entire system of ODEs.
%Warning:
%Warning: Failure at t=7.137117e+01. Unable to meet integration tolerances without reducing the step size below the
%smallest value allowed (2.273737e-13) at time t.

Antworten (1)

Torsten
Torsten am 13 Nov. 2023
Bearbeitet: Torsten am 13 Nov. 2023
If you store P for 1:Nx and m for Nx+1:2*Nx, you should also return dPdt for 1:Nx and dmdt for Nx+1:2*Nx. But you return dPdt for 1 and Nx+2:2*Nx-1 and dmdt for 2:Nx and 2*Nx, don't you ?
  14 Kommentare
Torsten
Torsten am 17 Nov. 2023
Bearbeitet: Torsten am 17 Nov. 2023
Is this correct way of implementing upwind scheme for spatial part?
No, it's not correct. Your hyperbolic system has two eigenvalues: c and -c. For these eigenvalues, you have to determine the corresponding eigenvectors. Then you have to diagonalize your PDE system with the help of the eigenvectors. Then the characteristic variable corresponding to the negative eigenvalue has to be approximated from the right while the one corresponding to the positive eigenvalue has to be approximated from the left when forming the spatial derivative. I don't remember the whole process in detail, but you must invest a lot of effort if you are not used to this process. You cannot shake a scheme out of your sleeve and hope it is correct. That's why I adviced you to use the CLAWPACK software in order to prevent you from coding when better solutions already exist.
MAYUR MARUTI DHIRDE
MAYUR MARUTI DHIRDE am 18 Nov. 2023
I appreciate your assistance. I will take into account your suggestion and work on it.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Mathematics and Optimization finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by