Event function with DAE system

16 visualizzazioni (ultimi 30 giorni)
Yash Vardhan
Yash Vardhan il 2 Ott 2023
Commentato: Torsten il 27 Ott 2023
I have a DAE system for solving a set of diffrential and algebraic equations(4 differential equations and 13 algebraic). I am using the ode15s solver. In my system, I am calculating the Pressure of a vapour in a storage tank which is increasing with time at the moment.
Once the pressure reaches an upper threshold value, I want 2 of the 4 differential equations to change slightly. These updated equations will make the pressure drop and once the pressure reaches the lower threshold value, the system should revert back to the orginal differential equations.
Any idea how I can do this using event functions??
This is how I am defining my DAE_system function with a mass matrix
options = odeset('Mass', M, 'MassSingular', 'yes', 'RelTol', 1e-4, 'AbsTol', 1e-6);
[t, y] = ode15s(@(t,y) DAE_System(t,y,Params,userInput_geo), tspan, y0, options);
These are the original equations:
dy_dt(2,1) = Q_av - Q_v + M_e*hv + Pv*dy_dt(1, 1);
dy_dt(3,1) = M_e;
These are the equations I want once the upper threshold limit of Pv is reached:
dy_dt(2,1) = Q_av - Q_v + M_e*hv + Pv*dy_dt(1,1) - M_va*hv;
dy_dt(3,1) = M_e - M_va;

Risposta accettata

Torsten
Torsten il 2 Ott 2023
Modificato: Torsten il 2 Ott 2023
options = odeset('Mass', M, 'MassSingular', 'yes', 'RelTol', 1e-4, 'AbsTol', 1e-6,'Events',@event);
function [position,isterminal,direction] = event(t,y)
Pvmax = ...;
position = y(?) - Pvmax; % The value that we want to be zero, set the ? to the index of y that contains Pv
isterminal = 1; % Halt integration
direction = 0; % The zero can be approached from either direction
end
  17 Commenti
Yash Vardhan
Yash Vardhan il 27 Ott 2023
Yes It was throwing an error which is why I changed the system a little bit
while true
% Changing the options to use the correct event_function based on event_flag
[y0,yp0] = decic(@(t,y,yp)DAE_System(t,y,yp,Params,userInput_geo,event_flag),0,y0,[1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0],yp0,[]);
options = odeset('Events', @(t, y, yp) event_function2(t, y, yp, T_crit, P_crit, V_T, Pv_ul, Pv_ll));
[t_event, y_event, ~, ~, ie] = ode15i(@(t, y,yp) DAE_System(t, y, yp, Params, userInput_geo, event_flag), tspan, y0,yp0,options);
% Making 1 final array for t and 1 array for y and concatenating the
% results after every event
t = [t; t_event];
y = [y; y_event];
if isempty(ie) % No event occurred, break the loop
break;
elseif ie == 1||ie == 2 || ie == 3||ie == 4 || ie == 5 % End simulation
break;
elseif ie == 6
if event_flag == 1
ie
event_flag = 2;
end
% Updating tspan and y0 for continuing the simulation
if t_event(end) < tspan_finish
tspan = [t_event(end), tspan_finish];
y0 = y_event(end, :);
else
break;
end
% Printing which event occured when
fprintf('Event occurred at t = %f. event_flag set to %d\n', t_event(end), event_flag);
elseif ie == 7
ie
event_flag = 1;
if t_event(end) < tspan_finish
tspan = [t_event(end), tspan_finish];
y0 = y_event(end, :);
else
break;
end
% Printing which event occured when
fprintf('Event occurred at t = %f. event_flag set to %d\n', t_event(end), event_flag);
end
end
Now the the issue I am getting is with regards the tolerances
Warning: Failure at t=2.649540e+04. Unable to meet integration tolerances without reducing the step size below the
smallest value allowed (9.413057e-11) at time t.
> In ode15i (line 398)
Any clue?
Torsten
Torsten il 27 Ott 2023
You don't supply the actual derivatives to "decic" when you make a restart.
The yp0 in the call
decic(@(t,y,yp)DAE_System(t,y,yp,Params,userInput_geo,event_flag),0,y0,[1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0],yp0,[]);
is still the yp0 from the last t_event(end), not from the actual one.
After an event happened, use "deval" to recompute yp0 from t_event(end) and y_event(end,:).
[~,yp] = deval( )
Further, I'm not sure whether
elseif ie == 7
ie
event_flag = 1;
suffices or something as in the case ie = 6:
if event_flag == ...
ie
event_flag = ...;
end
The error message indicates that ode15i couldn't continue integration because it could no longer retain the error tolerances. Reasons can be a singularity in the solution, a programming error, too strict or weak tolerances,... . The only way to cope with it is to look at the solution at t=2.649540e+04 or slightly before this time and try to find the reason for the failure of the integrator.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Programming in Help Center e File Exchange

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by