0
$\begingroup$

I am trying to export an animated GIF file which is the result of a NDSolveValue computation (see below). The notebook is working fine and fast when I want to make a 3D plot of the solution, for example. It is the same when I want to plot the following animation (a little bit long but it is OK) :

ListAnimate[
 Table[ContourPlot[
   Evaluate[numsol[x, y, t]] == 0, {x, -a, a}, {y, -b, b}, 
   PlotLabel -> Style[t, 30, Bold], PlotRange -> All], {t, 0, 
   0.4, .01}]]

But when I want to export this animation, it seems to be very very very long. I let Mathematica running 36h, and the result was not still here.

Export["nodalanim12.gif", 
 ListAnimate[
  Table[ContourPlot[
    Evaluate[numsol[x, y, t]] == 0, {x, -a, a}, {y, -b, b}, 
    PlotLabel -> Style[t, 30, Bold], PlotRange -> All], {t, 0, 
    0.4, .01}]], "DisplayDurations" -> 10, 
 "AnimationRepetitions" -> Infinity]

So, am I doing something wrong, or is it MMA which is bugging or maybe this computation is really very complex? Below is my full code :

Ey = SetPrecision[2.078*10^11, Infinity];(*N/m^2*)
\[Nu] = Rationalize[0.317756];(*unitless*)
\[CurlyRho]d = 8166;(*kg/m^3*)
h = 1/1000;
Df = (Ey h^3)/(12 (1 - \[Nu]^2)); a = 1; b = 1;

eqn = {D[u[x, y, t], {x, 4}] + 2 D[u[x, y, t], {x, 2}, {y, 2}] + 
     D[u[x, y, t], {y, 4}] + (\[CurlyRho]d h)/
      Df D[u[x, y, t], {t, 2}] == 
    0}; (* for plates, governing equation = bi-harmonic equation *)

m = 1; n = 2;
ic = {u[x, y, 0] == 
    Cos[m \[Pi] x/a] Cos[n \[Pi] y/b] + 
     Cos[n \[Pi] x/a] Cos[m \[Pi] y/b], 
   Derivative[0, 0, 1][u][x, y, 0] == 0}; (* initial impulse *)
bc1fe = {Derivative[2, 0, 0][u][-a, y, t] == 0, 
   Derivative[3, 0, 0][u][-a, y, t] == 0, 
   Derivative[2, 0, 0][u][a, y, t] == 0, 
   Derivative[3, 0, 0][u][a, y, t] == 0}; (* free edges/ simplified *)


bc2fe = {Derivative[0, 2, 0][u][x, -b, t] == 0, 
   Derivative[0, 3, 0][u][x, -b, t] == 0, 
   Derivative[0, 2, 0][u][x, b, t] == 0, 
   Derivative[0, 3, 0][u][x, b, t] == 0}; (* free edges/ simplified *)

showStatus[status_] := 
  LinkWrite[$ParentLink, 
   SetNotebookStatusLine[FrontEnd`EvaluationNotebook[], 
    ToString[status]]];

clearStatus[] := showStatus[""];
clearStatus[]

jianshi[t_] := 
 EvaluationMonitor :> showStatus["t = " <> ToString[CForm[t]]]

mol[n : _Integer | {_Integer ..}, 
  o_ : "Pseudospectral"] := {"MethodOfLines", 
  "SpatialDiscretization" -> {"TensorProductGrid", "MaxPoints" -> n, 
    "MinPoints" -> n, "DifferenceOrder" -> o}}

mol[tf : False | True, sf_ : Automatic] := {"MethodOfLines", 
  "DifferentiateBoundaryConditions" -> {tf, "ScaleFactor" -> sf}}

numsol = NDSolveValue[{eqn, ic, bc1fe, bc2fe}, 
    u, {x, -a, a}, {y, -b, b}, {t, 0, 1}, 
    Method -> Union[mol[25, 4], mol[True, 100], {Method -> Adams}], 
    jianshi[t], MaxSteps -> Infinity]; // AbsoluteTiming
(* {95.0254, Null} *)
(* some warnings happen, but without blocking the computations *)

(* below is the exportation which causes the issue *)
Export["nodalanim12.gif", 
 ListAnimate[
  Table[ContourPlot[
    Evaluate[numsol[x, y, t]] == 0, {x, -a, a}, {y, -b, b}, 
    PlotLabel -> Style[t, 30, Bold], PlotRange -> All], {t, 0, 
    0.4, .01}]], "DisplayDurations" -> 10, 
 "AnimationRepetitions" -> Infinity]

To precise the context, this animation shows the nodal lines generated by a vibrating plate during 0.4s. We can show the evolution of the "12" mode vs time. I made a lot of various calculations such as Plot3D, Table of Plot3D, GIF exports, etc. and all was working fine. I just got a problem with the export I mentionned above. So, if somebody would have the kindness to try it and tell me if the same issue is happening? Thanks in advance.

NB : all the NDSolveValue settings and jianshi usage have been given to me through this link : Free vibrations of square plate with bi-harmonic equation

$\endgroup$
12
  • 2
    $\begingroup$ Usually you would Export just the Table of plots, not the ListAnimate. $\endgroup$
    – wxffles
    May 26 at 21:02
  • 1
    $\begingroup$ @ Pascal77 as WX said using table its better. Also i think you have to post your original problem so i try to make a new code or understand your code clearly at least $\endgroup$
    – Alrubaie
    May 27 at 2:09
  • $\begingroup$ @wxffles : thanks. I will try your suggestion. $\endgroup$
    – Pascal77
    May 27 at 9:07
  • $\begingroup$ @Alrubaie : thanks. $\endgroup$
    – Pascal77
    May 27 at 9:07
  • $\begingroup$ I just tried successfully a GIF export from the following commands : ``` contouranim = ListAnimate[ Table[ContourPlot[Evaluate[numsol[x, y, t]], {x, -a, a}, {y, -b, b}, PlotLabel -> Style[t, 30, Bold], PlotRange -> All], {t, 0, 0.9, .1}]] Export["contouranim12.gif", contouranim] ``` As you can see, it is a simple contourplot, not a nodal lines plot. The computation is very fast. As soon as I want to try with ContourPlot==0 (nodal lines, it is too slow). How to share with you the animated GIF file? $\endgroup$
    – Pascal77
    May 27 at 14:27

Your Answer

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

Browse other questions tagged or ask your own question.