def build_nullspace(V): """Function to build null space for 3D elasticity""" # Create list of vectors for null space index_map = V.dofmap.index_map nullspace_basis = [cpp.la.create_vector(index_map) for i in range(6)] 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) V.sub(2).dofmap.set(basis[2], 1.0) # Build rotational null space basis 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) # Create vector space basis and orthogonalize basis = VectorSpaceBasis(nullspace_basis) basis.orthonormalize() _x = [basis[i] for i in range(6)] nsp = PETSc.NullSpace() nsp.create(_x) return nsp
def build_nullspace(V, x): """Function to build null space for 3D elasticity""" # Create list of vectors for null space nullspace_basis = [PETScVector(x) for i in range(6)] # 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) V.sub(2).dofmap().set(nullspace_basis[2], 1.0) # Build rotational null space basis 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) for x in nullspace_basis: x.apply() # Create vector space basis and orthogonalize basis = VectorSpaceBasis(nullspace_basis) basis.orthonormalize() return basis
def build_nullspace(V): """Function to build null space for 3D elasticity""" # Create list of vectors for null space index_map = V.dofmap().index_map() nullspace_basis = [cpp.la.create_vector(index_map) for i in range(6)] # 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) V.sub(2).dofmap().set(nullspace_basis[2], 1.0) # Build rotational null space basis 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) # Create vector space basis and orthogonalize basis = VectorSpaceBasis(nullspace_basis) basis.orthonormalize() _x = [basis[i] for i in range(6)] nsp = PETSc.NullSpace() nsp.create(_x) return nsp
def build_nullspace(V, x): """Function to build null space for 2D elasticity""" # Create list of vectors for null space nullspace_basis = [x.copy() for i in range(3)] # 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) for x in nullspace_basis: x.apply("insert") null_space = VectorSpaceBasis(nullspace_basis) null_space.orthonormalize() return null_space
def build_nullspace(V, x): """Function to build null space for 2D elasticity""" # Create list of vectors for null space nullspace_basis = [x.copy() for i in range(3)] 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) null_space = VectorSpaceBasis(nullspace_basis) null_space.orthonormalize() return null_space