Adaptive Mesh Refinement - unrefine

Hi all,

I’m fiddling around with Adaptive mesh refinement with time dependent problems. So far I’ve managed to refine the mesh so that the goal function is below a specified tolerance.
But I have 2 issues here:

  • At some point, solution should be 0 everywhere and it’s not the case.
  • I’d like some parts of the mesh to be unrefined when refinement is not needed in order to save computational time: is that even possible ?

Here’s a MWE:

from dolfin import *
import matplotlib.pyplot as plt
import sympy as sp
# Create mesh and define function space
mesh = UnitSquareMesh(4, 4)
V = FunctionSpace(mesh, "Lagrange", 1)

# Define boundary condition
# u0 = Function(V)
bc = DirichletBC(V, Constant(0), "x[0] < DOLFIN_EPS || x[0] > 1.0 - DOLFIN_EPS")

# Define variational problem
u = Function(V)
u_back = Function(V)
v = TestFunction(V)
x, y, t = sp.symbols("x[0] x[1] t")
f = (1+sp.sin(t))*100*sp.exp(-((x - 0.7)**2 + (y - 0.7)**2) / 0.002)*(t<2*pi)
f = Expression(sp.printing.ccode(f), degree=2, t=0)
F = dot(grad(u), grad(v))*dx - f*v*dx

# Define goal functional (quantity of interest)
M = u*dx

# Define error tolerance
tol = 1.e-4

du = TrialFunction(V)
J = derivative(F, u, du)

dt = 1
t = 0
file_T = XDMFFile("result.xdmf")
u_export = Function(V, name="T")
while t < 4*pi:
    t += dt
    f.t = t

    problem = NonlinearVariationalProblem(F, u, bc, J)
    solver = AdaptiveNonlinearVariationalSolver(problem, M)
    solver.solve(tol)

    u_export.assign(u.leaf_node())
    file_T.write(u_export, t)

As you can see here, the mesh is refined the same way.

Thanks all for your help!
Rem

1 Like

Hi Rem,

Did you find an answer for your second question? I am also fiddling around with adaptive meshing now.

Thanks,
Aditya

Hi, I’m afraid I haven’t… That’s a shame really. It’d be a very nice feature for many transient applications! :slight_smile:

Hey, just wanted to follow up on this. I was hoping to use adaptive meshes as well but not sure if it is worth trying if the solution isn’t correct. Anyone figured this out? :slight_smile:

I did something similar for the LLG equation. I have a time and space adaptive code, which is doing the refinement in space not with the AdaptiveNonlinearSolver but by refining the mesh based on some residual error estimator. The “coarsening” itself is no real coarsening but a remeshing in the sense that when ever we want to coarsen the mesh we refine a coarse mesh until it fits the current solution. Code is available on github and may be adapted to other equations than the LLG.
janbohn/AdaptiveLLG: space and time adaptive algorithm for the LLG equation

you may also consider
Hierarhical mesh - mesh - FEniCS Project
and the linked Github from Alexander Zimmerman

1 Like