Peclet Number for controlling adaptive mesh refinement

I want to play with AMR in FEniCS and I was wondering is there a way to use the AdaptiveLinearVariationalSolver() with something like the Peclet number defined on each cell rather than using a functional like u*dx in this example?

Thanks!

As I understand it, the automated AdaptiveSolver classes require a global goal functional (u*dx or similar).

But you can obtain fine control of mesh refinement (manually controlled as it were), by manually marking cells.

Something like

markers = MeshFunction("bool", mesh, mesh.topology().dim())
meshNeedsRefine=False
for c in cells(mesh):
  if cellNeedsRefinement(c):
    markers[c] = True
    meshNeedsRefine=True
if meshNeedsRefine:
  mesh = refine(mesh, markers)

where cellNeedsRefinement() would contain your Peclet number logic.

1 Like

Thanks for your help! So, based on what you are suggesting, I wanted to implement something like the following:

def peclet(u0, D, mu):
Pe = h*mu*mag(grad(u0))/D
return Pe

def check_cell(cell, Pe):
p = cell.midpoint()
if Pe.eval_cell(Pe, p, cell) >= 1.0:
    return True
else:
    return False

def refine_by_cell_eval(mesh_, u0, D, mu):
markers = MeshFunction("bool", mesh_, mesh_.topology().dim())
meshNeedsRefine=False
Pe = project(peclet(u0, D, mu), V0)
for c in cells(mesh_):
  if check_cell(c, Pe):
    markers[c] = True
    meshNeedsRefine=True
if meshNeedsRefine:
  mesh_ = refine(mesh_, markers)
return mesh_

However, I’m struggling to evaluate the Peclet number on each cell–how would I go about doing that if I have a piecewise constant projection of the Peclet number on the whole domain?

I haven’t used eval_cell() so I can’t advise on that.

Does Pe evaluate at Points in the normal way? Can you use Pe(p) instead of Pe.eval_cell()?