import matplotlib.pyplot as plt import numpy as np from scipy.interpolate import griddata from fenics import * from python_phase_retrieval import circle2d # (0) Could not get correct dof behavior in initialization in (3) parameters["reorder_dofs_serial"] = False # (1) Create diffraction data x = np.linspace(0.,1.,11) y = np.linspace(0.,2.,21) [xm,ym] = np.meshgrid(x,y) flat_order = 'C' gdata = circle2d(xm,ym).flatten(order=flat_order) xdata = np.zeros([len(gdata), 2]) xdata[:,0] = xm.flatten(order=flat_order) xdata[:,1] = ym.flatten(order=flat_order) # (2) Create mesh and function spaces nx = len(x) - 1 # Number of cells in :math:'x'-direction ny = len(y) - 1 # Number of cells in :math:'y'-direction mesh = RectangleMesh(Point(x[0],y[0]), Point(x[-1],y[-1]), nx, ny, 'right') q = 1 # FEM dimension V1 = FunctionSpace(mesh, 'Lagrange', q) V2 = VectorFunctionSpace(mesh, 'Lagrange', q, dim=2) g = Function(V1) v = Function(V2) # (3) Instanitate Fenics density function
def eval(self, value, x): value[0] = circle2d(x[0],x[1])
# (1) Create diffraction data and some initial velocity lenx = 11 leny = 21 ndof = lenx*leny x = np.linspace(0.,1.,lenx) y = np.linspace(0.,2.,leny) xmin = x[0] xmax = x[-1] xdelta = x[1] - x[0] ymin = y[0] ymax = y[-1] ydelta = y[1] - y[0] [xm,ym] = np.meshgrid(x,y) flat_order = 'C' gdat = circle2d(xm,ym) #gdat = np.zeros_like(gdat) #gdat[0,-1] = 1 gdata = gdat.flatten(order=flat_order) xdata = np.zeros([len(gdata), 2]) xdata[:,0] = xm.flatten(order=flat_order) xdata[:,1] = ym.flatten(order=flat_order) v_init = np.asarray([0.02*np.ones_like(gdata), 0.01*np.ones_like(gdata)], dtype=float) v_init = v_init.flatten() # (2) Create mesh and function spaces nx = len(x) # Number of cells in :math:'x'-direction ny = len(y) - 1 # Number of cells in :math:'y'-direction mesh = RectangleMesh(Point(xmin,ymin), Point(xmax+xdelta,ymax), \ nx, ny, 'right') q = 1 # FEM dimension