Event function with DAE system
조회 수: 8 (최근 30일)
이전 댓글 표시
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;
댓글 수: 0
채택된 답변
Torsten
2023년 10월 2일
편집: Torsten
2023년 10월 2일
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
Torsten
2023년 10월 27일
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.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!