Hello, I'm solving a diffusion equations, with the flux resulting from a gradient of a form, mu. mu is defined as a function of the unknown variable, c, and another variable p.
The system reaches steady state (implying that the gradient of mu is constant and zero for these boundary conditions), but when I project and examine mu I see that it is not flat.
I haven't been able to eliminate this by adjusting solver parameters.
Does anyone have an explanation for this please?
Thanks, MWE below.
from dolfin import *
from cbcpost import *
t, dt, t_final = [0, Constant(.01), 1.]
mesh = IntervalMesh(100,0,1)
V1 = FunctionSpace(mesh, "CG", 1)
C = Function(V1)
dU = TrialFunction(V1)
test_C = TestFunction(V1)
C_old = Function(V1)
x = SpatialCoordinate(mesh)
p = .5*(1.+tanh((-x[0]+.5)/.05))
mu = -( -C+p )
J = -grad( mu )
F_C = inner(J, grad(test_C))*dx
Ft_C = (C-C_old)*test_C*dx
F_C = Ft_C - dt*F_C
C.interpolate(project(((1-p)*.1+p),V1))
t = t+dt(0)
iter, iter_max = 0, 100
C_old.vector()[:] = C.vector()
problem = NonlinearVariationalProblem(F_C, C, [], derivative(F_C, C, dU))
solver = NonlinearVariationalSolver(problem)
pp = PostProcessor(dict(casedir="Results", clean_casedir=True))
pp.add_field(SolutionField("C", dict(save=True, save_as=["xdmf"])))
pp.add_field(SolutionField("mu", dict(save=True, save_as=["xdmf"])))
solution = {"C": lambda: project(C,V1), "mu": lambda: project(mu,V1) }
pp.update_all(solution, 0, 0)
while (iter< iter_max):
iter +=1
solver.solve()
pp.update_all(solution, t, iter)
t += dt(0)
C_old.vector()[:] = C.vector()
pp.finalize_all()