How do I solve IDA ERROR using ode15s solver?

I want to solve the 1-d stiff ODE equation
dc/dt = -d(uG.cg)/dz + d/dz(Γdc/dz) - Sg
using ode15s solver but I keep getting the error:
[IDA ERROR] IDASolve At t = 0 and h = 3.8147e-009, the error test failed repeatedly or with |h| = hmin.
Based on the dt value I enter, like 0.1, 1 or 10s (which is my time step for the time loop) the value of h in the error message changes. Here is the part of my code which solves the equation:
dt = 1; % time step, [s]
Time = 3600; % modeling duration, [s]
tt = 0 : dt : Time;
Nt = length(tt);
for p = 1 : Nt-1
tspan = [(p-1)*dt p*dt];
options = odeset('reltol', 1e-15, 'abstol', 1e-18, 'normcontrol', 'on', 'refine', 5, 'NonNegative',1);
for ig = 1 : Nz
[t,y4] = ode15s(@(t,y4) ((-uG(ig,p)*y4+uG(ig-1,p)*cg_D(ig-1,p))/dh)+((gamma_dw(ig,p)*cg_D(ig-1,p)-(gamma_dw(ig,p)+gamma_up(ig,p))*y4+gamma_up(ig,p)*cg_D(ig+1,p))/dh^2)- Sg_D(ig,p), tspan, cg_D(ig,p), options);
cg_D(ig,p+1) = y4(end);
end
end
Other variables rather than y4 are defined in the code and have known values. These values change in each time step (p=1, P=2, ... p=Nt-1), which is why I can't solve the equation once for a tspan = [0 Nt-1] so I solve it for every p and use the result as initial values for the next time step. ig is the node index. At the end I want to draw a figure of cg_D-t that shows me the change of cg over time.

回答 (0 件)

カテゴリ

タグ

質問済み:

2022 年 4 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by