I have a time dependant phase separation problem, where I would like to track the radius of a half circle a the upper boundary of a square mesh over time. This MWE works in serial
import dolfin as dlf
import numpy as np
class InitialConditions(dlf.UserExpression):
def __init__(self, **kwargs):
super().__init__(**kwargs)
def eval_cell(self, values, x, ufc_cell):
values[0] = 1.0/dlf.pi * ( dlf.pi/2.0 + dlf.atan((dlf.sqrt( ( x[0]- .5 )**2 \
+ ( x[1] - 1.0 )**2 )-0.1)/1.0e-3))
values[1] = 0.0
def value_shape(self):
return (2,)
def get_data(u):
m = dlf.assemble(u.split()[0]*dlf.dx)
DG_elem = dlf.FiniteElement("DG", u.function_space().mesh().ufl_cell(), 0)
V_DG = dlf.FunctionSpace(u.function_space().mesh(), DG_elem*DG_elem)
u_dg = dlf.project(u, V_DG)
c_dg = u_dg.vector().get_local()[0::2]
cell_midpt = V_DG.tabulate_dof_coordinates()[0::2]
indexes = np.where(c_dg <= 0.50)[0]
if len(indexes) != 0:
mid_y = cell_midpt[indexes][:,1]
r = ( 1.0 - np.amin(mid_y) )
else:
r = 0.0
return m, r
n = 100
nx, ny = n, n
mesh = dlf.UnitSquareMesh(nx, ny, "left/right")
da = dlf.Measure("dx", domain=mesh)
x = dlf.SpatialCoordinate(mesh)
CG_elem = dlf.FiniteElement("CG", mesh.ufl_cell(), 1)
V_CG = dlf.FunctionSpace(mesh, CG_elem*CG_elem)
u_cg = dlf.Function(V_CG)
c, mu = dlf.split(u_cg)
u_cg = dlf.interpolate(InitialConditions(degree=1), V_CG)
m, r = get_data(u_cg)
print("m = %.3e, r = %3e" % (m, r))
But since the dofs get scatter when running in parallel, tabulate_dof_coordinates() does not do the trick anymore. Does anybody know a workaround to this?
Greetings