pdepe/pde1dm's vectorized option
이전 댓글 표시
In pdepe, when vectorized is turned on, the elapsed time is the same as that when vectorized is off. Why no improvement?
The doc of pde1dm says that for vectorized mode, we return coefficients at multiple x locations, so in the pdefunc function
nx=length(x); c = ones(1,nx);
need to replace the original
c=1
While pde1dm requires the above change in the pdefunc function code, when c and s in the pdefunc function aren't changed to their vector form, pdepe still allows vectorized to be turned on. Why such a difference?
댓글 수: 18
feynman feynman
2024년 2월 6일
편집: feynman feynman
2024년 2월 17일
Where did you see that you can use the Vectorized option for "pdepe" ? I only see the following options available according to the documentation:
Option structure, specified as a structure array. Use the odeset function to create or modify the option structure. pdepe supports these options:
In most cases, default values for these options provide satisfactory solutions.
feynman feynman
2024년 2월 17일
편집: feynman feynman
2024년 2월 17일
I think actually pdefun, icfun etc accept tensors as arguments so maybe vectorization is already adopted?
The inputs to "pdefun" and "icfun" are pointwise in x, not vectorwise. The functions are called in a loop from "pdepe" for every single x-value, and the same is expected for the returned output.
type pdepe
feynman feynman
2024년 2월 18일
Because this option is simply ignored and it is assumed that you read the documentation. That's why no error message is reported. Only the documented options are tested for in the options structure supplied by the user.
But just look through the code - that's why I included it:
% Extract relevant options and augment with new ones
reltol = odeget(options,'RelTol',[]);
abstol = odeget(options,'AbsTol',[]);
normcontrol = odeget(options,'NormControl',[]);
initialstep = odeget(options,'InitialStep',[]);
maxstep = odeget(options,'MaxStep',[]);
events = odeget(options,'Events',[]); %events(m,t,xmesh,umesh)
hasEvents = ~isempty(events);
if hasEvents
eventfcn = @(t,y) events(m,t,xmesh,y,varargin{:});
else
eventfcn = [];
end
opts = odeset('RelTol',reltol,'AbsTol',abstol,'NormControl',normcontrol,...
'InitialStep',initialstep,'MaxStep',maxstep,'Events',eventfcn,...
'Mass',M,'JPattern',S);
% Call DAE solver
tfinal = t(end);
try
if hasEvents
[t,y,te,ye,ie] = ode15s(@pdeodes,t,y0(:),opts);
else
[t,y] = ode15s(@pdeodes,t,y0(:),opts);
end
catch ME
if strcmp(ME.identifier,'MATLAB:daeic12:IndexGTOne')
error(message('MATLAB:pdepe:SpatialDiscretizationFailed'))
else
rethrow(ME);
end
end
feynman feynman
2024년 2월 18일
feynman feynman
2024년 2월 19일
Torsten
2024년 2월 19일
I just remembered one of your thousand questions when you asked whether it's possible to replace the integrator within "pdepe" ... :-)
feynman feynman
2024년 2월 19일
Torsten
2024년 2월 19일
If you rename the "pdepe" into something else and also copy the function "pdentrp" called from the "pdepe" code, it doesn't work ?
feynman feynman
2024년 2월 20일
type pdentrp
feynman feynman
2024년 2월 20일
feynman feynman
2024년 3월 10일
편집: feynman feynman
2024년 3월 10일
Sure, if you can vectorize this loop in the "pdepe" code and rewrite "pdentrp" such that it accepts array inputs, you are done:
% Interior points
for ii = 2:nx-1
[U,Ux] = pdentrp(singular,m,xmesh(ii),u(:,ii),xmesh(ii+1),u(:,ii+1),xi(ii));
[cR,fR,sR] = feval(pde,xi(ii),tnow,U,Ux,varargin{:});
denom = zxmp1(ii) * cR + xzmp1(ii-1) * cL;
denom(denom == 0) = 1;
up(:,ii) = ((xim(ii) * fR - xim(ii-1) * fL) + ...
(zxmp1(ii) * sR + xzmp1(ii-1) * sL)) ./ denom;
cL = cR;
fL = fR;
sL = sR;
end
feynman feynman
2024년 3월 10일
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!