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