def build_broken_elastic_nullspace(V): """Function to build incorrect null space for 2D elasticity""" # Create list of vectors for null space nullspace_basis = [ cpp.la.create_vector(V.dofmap.index_map) for i in range(4) ] with ExitStack() as stack: vec_local = [ stack.enter_context(x.localForm()) for x in nullspace_basis ] basis = [np.asarray(x) for x in vec_local] # Build translational null space basis V.sub(0).dofmap.set(basis[0], 1.0) V.sub(1).dofmap.set(basis[1], 1.0) # Build rotational null space basis V.sub(0).set_x(basis[2], -1.0, 1) V.sub(1).set_x(basis[2], 1.0, 0) # Add vector that is not in nullspace V.sub(1).set_x(basis[3], 1.0, 1) return la.VectorSpaceBasis(nullspace_basis)
def build_elastic_nullspace(V): """Function to build nullspace for 2D/3D elasticity""" # Get geometric dim gdim = V.mesh().geometry.dim assert gdim == 2 or gdim == 3 # Set dimension of nullspace dim = 3 if gdim == 2 else 6 # Create list of vectors for null space nullspace_basis = [ cpp.la.create_vector(V.dofmap().index_map()) for i in range(dim) ] # Build translational null space basis for i in range(gdim): V.sub(i).dofmap().set(nullspace_basis[i], 1.0) # Build rotational null space basis if gdim == 2: V.sub(0).set_x(nullspace_basis[2], -1.0, 1) V.sub(1).set_x(nullspace_basis[2], 1.0, 0) elif gdim == 3: V.sub(0).set_x(nullspace_basis[3], -1.0, 1) V.sub(1).set_x(nullspace_basis[3], 1.0, 0) V.sub(0).set_x(nullspace_basis[4], 1.0, 2) V.sub(2).set_x(nullspace_basis[4], -1.0, 0) V.sub(2).set_x(nullspace_basis[5], 1.0, 1) V.sub(1).set_x(nullspace_basis[5], -1.0, 2) return la.VectorSpaceBasis(nullspace_basis)
def build_broken_elastic_nullspace(V): """Function to build incorrect null space for 2D elasticity""" # Create list of vectors for null space nullspace_basis = [ cpp.la.create_vector(V.dofmap().index_map()) for i in range(4) ] # Build translational null space basis V.sub(0).dofmap().set(nullspace_basis[0], 1.0) V.sub(1).dofmap().set(nullspace_basis[1], 1.0) # Build rotational null space basis V.sub(0).set_x(nullspace_basis[2], -1.0, 1) V.sub(1).set_x(nullspace_basis[2], 1.0, 0) # Add vector that is not in nullspace V.sub(1).set_x(nullspace_basis[3], 1.0, 1) return la.VectorSpaceBasis(nullspace_basis)
def build_elastic_nullspace(V): """Function to build nullspace for 2D/3D elasticity""" # Get geometric dim gdim = V.mesh.geometry.dim assert gdim == 2 or gdim == 3 # Set dimension of nullspace dim = 3 if gdim == 2 else 6 # Create list of vectors for null space nullspace_basis = [ cpp.la.create_vector(V.dofmap.index_map) for i in range(dim) ] with ExitStack() as stack: vec_local = [ stack.enter_context(x.localForm()) for x in nullspace_basis ] basis = [np.asarray(x) for x in vec_local] # Build translational null space basis for i in range(gdim): V.sub(i).dofmap.set(basis[i], 1.0) # Build rotational null space basis if gdim == 2: V.sub(0).set_x(basis[2], -1.0, 1) V.sub(1).set_x(basis[2], 1.0, 0) elif gdim == 3: V.sub(0).set_x(basis[3], -1.0, 1) V.sub(1).set_x(basis[3], 1.0, 0) V.sub(0).set_x(basis[4], 1.0, 2) V.sub(2).set_x(basis[4], -1.0, 0) V.sub(2).set_x(basis[5], 1.0, 1) V.sub(1).set_x(basis[5], -1.0, 2) return la.VectorSpaceBasis(nullspace_basis)