pdepe/pde1dm's vectorized option
Show older comments
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 Comments
feynman feynman
on 6 Feb 2024
Edited: feynman feynman
on 17 Feb 2024
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
on 17 Feb 2024
Edited: feynman feynman
on 17 Feb 2024
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
on 18 Feb 2024
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
on 18 Feb 2024
feynman feynman
on 19 Feb 2024
Torsten
on 19 Feb 2024
I just remembered one of your thousand questions when you asked whether it's possible to replace the integrator within "pdepe" ... :-)
feynman feynman
on 19 Feb 2024
Torsten
on 19 Feb 2024
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
on 20 Feb 2024
type pdentrp
feynman feynman
on 20 Feb 2024
feynman feynman
on 10 Mar 2024
Edited: feynman feynman
on 10 Mar 2024
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
on 10 Mar 2024
Answers (0)
Categories
Find more on Numerical Integration and Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!