def test_spacepool_base_functionality(mesh): p = SpacePool(mesh) d = mesh.geometry().dim() spaces = [] shapes = [(), (3,), (2,4)] degrees = [0,1,2] for shape in shapes: for degree in degrees: V = p.get_custom_space("DG", degree, shape) assert V.ufl_element().degree() == degree assert V.ufl_element().value_shape() == shape rank = len(shape) shape2 = (d,)*rank U = p.get_space(degree, rank) assert U.ufl_element().degree() == degree assert U.ufl_element().value_shape() == shape2 spaces.append((V,U)) k = 0 for shape in shapes: for degree in degrees: V0, U0 = spaces[k]; k += 1 V = p.get_custom_space("DG", degree, shape) U = p.get_space(degree, len(shape)) assert id(V0) == id(V) assert id(U0) == id(U)
def before_first_compute(self, get): u = get(self.valuename) if u is None: return None V = u.function_space() element = V.ufl_element() #family = element.family() #degree = element.degree() spaces = SpacePool(self.mesh) FS = spaces.get_custom_space(element.family(), element.degree(), element.value_shape()) if LooseVersion(dolfin_version()) > LooseVersion("1.6.0"): rank = len(u.ufl_shape) else: rank = u.rank() if rank > 0: FS_scalar = spaces.get_custom_space(element.family(), element.degree(), ()) self.assigner = FunctionAssigner(FS, [FS_scalar]*FS.num_sub_spaces()) self.us = [] for i in range(FS.num_sub_spaces()): self.us.append(Function(FS_scalar)) self.u = Function(FS, name=self.name)
def before_first_compute(self, get): u = get(self.valuename) assert isinstance( u, Function), "Can only extract boundary values of Function-objects" FS = u.function_space() spaces = SpacePool(FS.mesh()) element = FS.ufl_element() #FS_boundary = spaces.get_space(FS.ufl_element().degree(), FS.num_sub_spaces(), boundary=True) FS_boundary = spaces.get_custom_space(element.family(), element.degree(), element.value_shape(), boundary=True) local_dofmapping = mesh_to_boundarymesh_dofmap(spaces.BoundaryMesh, FS, FS_boundary) #self._keys = local_dofmapping.keys() self._keys = np.array(local_dofmapping.keys(), dtype=np.intc) #self._values = local_dofmapping.values() self._values = np.array(local_dofmapping.values(), dtype=np.intc) self._temp_array = np.zeros(len(self._keys), dtype=np.float_) self.u_bdry = Function(FS_boundary)
def create_function_from_metadata(pp, fieldname, metadata, saveformat): "Create a function from metadata" assert metadata['type'] == 'Function' # Load mesh if saveformat == 'hdf5': mesh = Mesh() hdf5file = HDF5File(mpi_comm_world(), os.path.join(pp.get_savedir(fieldname), fieldname+'.hdf5'), 'r') hdf5file.read(mesh, "Mesh", False) del hdf5file elif saveformat == 'xml' or saveformat == 'xml.gz': mesh = Mesh() hdf5file = HDF5File(mpi_comm_world(), os.path.join(pp.get_savedir(fieldname), "mesh.hdf5"), 'r') hdf5file.read(mesh, "Mesh", False) del hdf5file # Replace loaded mesh if same mesh is loaded previously mesh = MeshPool(mesh, tolerance=0.0) shape = eval(metadata["element_value_shape"]) degree = eval(metadata["element_degree"]) family = eval(metadata["element_family"]) # Get space from existing function spaces if mesh is the same spaces = SpacePool(mesh) space = spaces.get_custom_space(family, degree, shape) return Function(space, name=fieldname)