3
$\begingroup$

It is well known that we use // Evaluate or Evaluated -> True to get Plot to "see" that it has received a list of functions and style each curve individually. However, in Version 11.0 this results in extreme slowdown for interpolating functions on finite element meshes.

<< NDSolve`FEM`
reg = Disk[];
mesh = ToElementMesh[reg];
eqs = {Laplacian[z[x, y], {x, y}] == 1, DirichletCondition[z[x, y] == 0, True]};
fun = NDSolveValue[eqs, z, Element[{x, y}, mesh]];
Do[ Plot[Table[fun[x/n, 0], {n, 4}], {x, 0, 1}],                    100] // AbsoluteTiming
Do[ Plot[Table[fun[x/n, 0], {n, 4}] // Evaluate, {x, 0, 1}],        100] // AbsoluteTiming
Do[ Plot[Table[fun[x/n, 0], {n, 4}], {x, 0, 1}, Evaluated -> True], 100] // AbsoluteTiming

Surprisingly, the opposite occurs in Version 10.2 (i.e. the unevaluated version is slower):

                     Version 10.2      Version 11.0
(unevaluated)            73.6 (slow)        1.6
// Evaluate              11.8              53.9 (slow)
Evaluated -> True        11.6              53.5 (slow)

The time difference between unevaluated and evaluated does not appear in either version if we use polynomials or 1D interpolating functions, so this issue is specific to FEM interpolating functions.

What is causing slowness, why has it changed between versions, and how can I get fast plots in Version 11.0 with individually styled curves (apart from build a 1D interpolation or use ListPlot)?

$\endgroup$
  • 4
    $\begingroup$ Apparently, this has been fixed somewhere between version 11.0.1 and version 11.3. While it takes forever in version 11.0.1, version 11.3 produces the following timings (per single plot, measured with RepeatedTiming): 0.020, 0.015, and 0.014. $\endgroup$ – Henrik Schumacher May 15 '18 at 7:40
4
$\begingroup$

I can confirm this behavior on version 11.0.1. Running

<< NDSolve`FEM`
reg = Disk[];
mesh = ToElementMesh[reg];
eqs = {Laplacian[z[x, y], {x, y}] == 1, DirichletCondition[z[x, y] == 0, True]};
fun = NDSolveValue[eqs, z, Element[{x, y}, mesh]];
Plot[Table[fun[x/n, 0], {n, 4}], {x, 0, 1}]; // RepeatedTiming // First
Plot[Table[fun[x/n, 0], {n, 4}] // Evaluate, {x, 0, 1}]; // RepeatedTiming // First
Plot[Table[fun[x/n, 0], {n, 4}], {x, 0, 1}, Evaluated -> True]; // RepeatedTiming // First

on version 11.0.1 leads to

0.017

0.576

0.573

Apparently, the issue has been fixed somewhere between version 11.0.1 and 11.3. as version 11.3 returns

0.0190

0.015

0.015

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.