Reduce computational time for ODE solver

1 次查看(过去 30 天)
Hi all
i have this code
for iDom_hot = 1:numel(Dall_hot)
xRange_hot = Dall_hot{iDom_hot};
for iInitial_hot = 1:numel(Y0_Lhot)
Mach_hot=Mach_cell_hot{iInitial_hot};
Tw_hot=Tnew_cell_hot{iDom_hot};
Ch_hot=ChL_cell_hot{iDom_hot,iInitial_hot};
Fc_hot=fL_cell_hot{iDom_hot,iInitial_hot};
Hrrj_hot=hrrj_cell_hot{iDom_hot};
Aeff_hot=Aeff_cell_hot{iDom_hot,iInitial_hot};
Perim_hot=Perim_cell_hot{iDom_hot,iInitial_hot};
L_Ength_hot=L_cell_hot{iDom_hot};
Pend_chamb_hot=Pressure_ED_chamber_cell_hot{iDom_hot};
if Ch_hot>0&&Fc_hot>0&&Hrrj_hot>0&&Tw_hot>0 &&Mach_hot>0&&Perim_hot>0&&Aeff_hot>0&&L_Ength_hot>0&&Pend_chamb_hot>0
[xSol_hot{iDom_hot,iInitial_hot},YSol_L_hot{iDom_hot,iInitial_hot}]=ode23(@(x,Y)...
chambesinglebobbTWVARIABILEHOT(x,Y,Ch_hot,Aeff_hot,Perim_hot,Fc_hot,Tw_hot),xRange_hot,Y0_Lhot{iInitial_hot});
if(any(YSol_L_hot{iDom_hot,iInitial_hot}(:,3)>0.8))
disp([ ' condizione verificata'])
disp (iDom_hot)
disp(iInitial_hot)
break
end
end
end
end
that solve iteratively an ODE system:
function dYdx=tubosinglebobb(x,Y,Ch_hot,Aeff_hot,Perim_hot,Fc_hot,Tw_hot)
gamma=1.667;
Dexttantalum=0.001500000000000;
Tt=Y(1);
Pt=Y(2);
M=Y(3);
dTtdx=Ch_hot*(Tw_hot-Tt)*(Perim_hot/Aeff_hot);
dPtdx=Pt*((-gamma*((M^2)/2)*Fc_hot*(Perim_hot/Aeff_hot))-...
(gamma*((M^2)/2)*dTtdx*(1/Tt)));
dMdx=M*(((1+((gamma-1)/2)*M^2)/(1-M^2))*((gamma*(M^2)*Fc_hot*...
Perim_hot)/(2*Aeff_hot))+...
((0.5*((gamma*M^2)+1))*(1+((gamma-1)/2)*M^2)/(1-M^2))*...
(Ch_hot*(Tw_hot-Tt)*Perim_hot)/(Aeff_hot*Tt));
dYdx=[dTtdx;dPtdx;dMdx];
end
the computational time for solving the ODE system is very very large (days) due to ( i think) one problem. In particular:
numel(Dall_ho) is more or less equal to 700, while numel(Y0_Lhot) is equal to 30, those domains dimensions should not be problematic, the real problem is on the oscillation of the solution YSol_L_hot when its third column reach value around 1. I have prepared a break for this eventuality but doesn't seem to reduce computational time!! I don't really know which is the problem, could it be a syntax error?
Thank you all for the help
Regards

采纳的回答

Bjorn Gustavsson
Bjorn Gustavsson 2020-9-19
Have you tried the other ODE-integrating functions? From your problem description it sounds like your ODEs are stiff - for that ode23 is not the optimal function, perhaps you get much better success with ode15s or oed23s that both are designed for stiff ODEs. One further note is that to me it seems like the temperature-derivative does not depend on the other 2 parameters, perhaps you can refactor the problem to first integrate that ODE and then use that solution when integrating the other 2.
  8 个评论
EldaEbrithil
EldaEbrithil 2020-9-20
Moreover ode 45 is very less accurate than ode 23, the results are inaccetable... i seriuously don't know how to do for speeding up the process keeping a moderate accuracy
Bjorn Gustavsson
Bjorn Gustavsson 2020-9-20
Since you're modelling some physical system, where you have some assumptions and some physical constraints on what makes a valid solution. You have to make some analysis of what happens with your solutions (M < 0) and also make some checks on what happens around those periods. For handling things like this you can use the options to force (some components of) the solution to be positive: ode-options, and to handle shocks and transitions you can use the even-handling: event-location.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by