Reap Sow and StepMonitor with FEM in Mathematica

Hello,

Can anyone help me figure out how to use Reap, Sow and StepMonitor with NDSolve applications using finite element module?

Thanks in advance.

Housam

KFUPM, KSA

Here’s how to do it with a one-dimensional problem.

In[1]:= res = 
  Reap[NDSolve[{y'[t] == y[t], y[0] == 1}, y, {t, 0, 1}, 
    EvaluationMonitor :> Sow[y[t]]]];

In[2]:= res

Out[2]= {{{y -> InterpolatingFunction[{{0., 1.}}, <>]}}, {{1., 
   1.00009, 1.00009, 1.00018, 1.00018, 1.00471, 1.00471, 1.00926, 
   1.00926, 1.01383, 1.01383, 1.03331, 1.03331, 1.02801, 1.02801, 
   1.0424, 1.0424, 1.05699, 1.05699, 1.07178, 1.07178, 1.10199, 
   1.10199, 1.13305, 1.13305, 1.16498, 1.16498, 1.19781, 1.19781, 
   1.23157, 1.23157, 1.31583, 1.31583, 1.40584, 1.40584, 1.50202, 
   1.50202, 1.60477, 1.60477, 1.71456, 1.71456, 1.83185, 1.83185, 
   2.02451, 2.02451, 2.23743, 2.23743, 2.46616, 2.46616, 2.71828, 
   2.71828}}}

Dear Frank,

I know this. Can you do something similar with NDSolve for PDEs using Mathematica’s finite element package?

Thanks much,

Housam

Doesn’t seem to work.

In[5]:= Needs["NDSolve`FEM`"]

In[8]:= \[CapitalOmega] = 
  ImplicitRegion[! ((x - 5)^2 + (y - 5)^2 <= 3^2), {{x, 0, 5}, {y, 0, 
     10}}];

In[11]:= op = -Laplacian[u[x, y], {x, y}] - 20;

In[9]:= Subscript[\[CapitalGamma], 
  D] = {DirichletCondition[u[x, y] == 0, x == 0 && 8 <= y <= 10],
   DirichletCondition[u[x, y] == 100, (x - 5)^2 + (y - 5)^2 == 3^2]};

In[13]:= res = 
 Reap @ NDSolveValue[{op == 
     0, {DirichletCondition[u[x, y] == 0, x == 0 && 8 <= y <= 10], 
     DirichletCondition[
      u[x, y] == 100, (-5 + x)^2 + (-5 + y)^2 == 9]}}, 
   u, {x, y} \[Element] 
    ImplicitRegion[(-5 + x)^2 + (-5 + y)^2 > 9 && 0 <= x <= 5 && 
      0 <= y <= 10, {x, y}], EvaluationMonitor :> Sow[{x, y, u[x, y]}]]

Out[13]= {InterpolatingFunction[{{0., 5.}, {0., 10.}}, <>], {}}