Computation time of PDE Toolbox increases drastically when defining the parameter 'f' as a function handle that uses state.u as input
Show older comments
I use the PDE Toolbox to simulate the diffusion of molecules in a 3D-space (Matlab 2015b). Initially I included separate steps outside the toolbox to account for secretion and degradation of those molecules. However, these processes happen simultaneously, so I tried to implement them into the toolbox using the parameter f.
I created a function ( f = @ffunction ), which calculates the secretion rates and additionally concentration changes due to a predefined half-life after every iteration by accessing state.u. While the first part hardly changed the calculation time, the degradation - using state.u as input - lead to a huge increase. I then found out, that apparently this step alone resulted in the function being called far more often than before (increase from 30 to about 300 times).These are the lines that cause the increase in calculation time:
function f = ffunction(region,state)
ht = evalin('base',ht1);
u = state.u;
tht = 2^(1/ht1);
u1 = u./tht;
f = u1-u;
end
I read a few topics about Matlab integrators requiring smooth functions, so might that be a potential cause?
Answers (1)
Alan Weiss
on 22 May 2017
0 votes
I am not sure whether you are using ht1 to represent time, in which case I think that you would do better not to use a global variable ht1, but instead use the state structure state.time. But I could easily be wrong.
When you include a nonlinear function for f, the solver solves a sequence of linear problems, and iterates to attempt to find a fixed point for the nonlinear problem. This is the reason that there are many more function evaluations. For a sketch of the nonlinear solver, see Nonlinear Equations.
Alan Weiss
MATLAB mathematical toolbox documentation
1 Comment
John Smith
on 23 May 2017
Categories
Find more on Structural Mechanics 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!