def build_mesh(self): self.mesh = fd.BoxMesh(self.nx, self.ny, self.nz, self.Lx, self.Ly, self.Lz)
def __init__(self, mesh, bbox, orders, levels, fixed_dims=[], boundary_regularities=None): """ bbox: a list of tuples describing [(xmin, xmax), (ymin, ymax), ...] of a Cartesian grid that extends around the shape to be optimised orders: describe the orders (one integer per geometric dimension) of the tensor-product B-spline basis. A univariate B-spline has order "o" if it is a piecewise polynomial of degree "o-1". For instance, a hat function is a B-spline of order 2 and thus degree 1. levels: describe the subdivision levels (one integers per geometric dimension) used to construct the knots of univariate B-splines fixed_dims: dimensions in which the deformation should be zero boundary_regularities: how fast the splines go to zero on the boundary for each dimension [0,..,0] : they don't go to zero [1,..,1] : they go to zero with C^0 regularity [2,..,2] : they go to zero with C^1 regularity """ self.boundary_regularities = [o - 1 for o in orders] \ if boundary_regularities is None else boundary_regularities # information on B-splines self.dim = len(bbox) # geometric dimension self.bbox = bbox self.orders = orders self.levels = levels if isinstance(fixed_dims, int): fixed_dims = [fixed_dims] self.fixed_dims = fixed_dims self.construct_knots() self.comm = mesh.mpi_comm() # create temporary self.mesh_r and self.V_r to assemble innerproduct if self.dim == 2: nx = len(self.knots[0]) - 1 ny = len(self.knots[1]) - 1 Lx = self.bbox[0][1] - self.bbox[0][0] Ly = self.bbox[1][1] - self.bbox[1][0] meshloc = fd.RectangleMesh(nx, ny, Lx, Ly, quadrilateral=True, comm=self.comm) # quads or triangle? # shift in x- and y-direction meshloc.coordinates.dat.data[:, 0] += self.bbox[0][0] meshloc.coordinates.dat.data[:, 1] += self.bbox[1][0] # inner_product.fixed_bids = [1,2,3,4] elif self.dim == 3: # maybe use extruded meshes, quadrilateral not available nx = len(self.knots[0]) - 1 ny = len(self.knots[1]) - 1 nz = len(self.knots[2]) - 1 Lx = self.bbox[0][1] - self.bbox[0][0] Ly = self.bbox[1][1] - self.bbox[1][0] Lz = self.bbox[2][1] - self.bbox[2][0] meshloc = fd.BoxMesh(nx, ny, nz, Lx, Ly, Lz, comm=self.comm) # shift in x-, y-, and z-direction meshloc.coordinates.dat.data[:, 0] += self.bbox[0][0] meshloc.coordinates.dat.data[:, 1] += self.bbox[1][0] meshloc.coordinates.dat.data[:, 2] += self.bbox[2][0] # inner_product.fixed_bids = [1,2,3,4,5,6] self.mesh_r = meshloc maxdegree = max(self.orders) - 1 # self.V_r = # self.inner_product = inner_product # self.inner_product.get_impl(self.V_r, self.FullIFW) # is this the proper space? self.V_control = fd.VectorFunctionSpace(self.mesh_r, "CG", maxdegree) self.I_control = self.build_interpolation_matrix(self.V_control) # standard construction of ControlSpace self.mesh_r = mesh element = fd.VectorElement("CG", mesh.ufl_cell(), maxdegree) self.V_r = fd.FunctionSpace(self.mesh_r, element) X = fd.SpatialCoordinate(self.mesh_r) self.id = fd.Function(self.V_r).interpolate(X) self.T = fd.Function(self.V_r, name="T") self.T.assign(self.id) self.mesh_m = fda.Mesh(self.T) self.V_m = fd.FunctionSpace(self.mesh_m, element) assert self.dim == self.mesh_r.geometric_dimension() # assemble correct interpolation matrix self.FullIFW = self.build_interpolation_matrix(self.V_r)