def matrix_eval(self): A_array = assemble(a).array() A_array[[0, 1, min_dof_0_2pi, max_dof_0_2pi], :] = A_array[[min_dof_0_2pi, max_dof_0_2pi, 0, 1], :] A_array[:, [0, 1, min_dof_0_2pi, max_dof_0_2pi]] = A_array[:, [min_dof_0_2pi, max_dof_0_2pi, 0, 1]] A = Matrix(*A_array.shape) A[:, :] = A_array return A
def jacobian_eval(self, solution): self._solution_from_dense_to_sparse(solution) jacobian_array = assemble(j).array() jacobian_array[[0, 1, min_dof_0_2pi, max_dof_0_2pi], :] = jacobian_array[[min_dof_0_2pi, max_dof_0_2pi, 0, 1], :] jacobian_array[:, [0, 1, min_dof_0_2pi, max_dof_0_2pi]] = jacobian_array[:, [min_dof_0_2pi, max_dof_0_2pi, 0, 1]] jacobian = Matrix(*jacobian_array.shape) jacobian[:, :] = jacobian_array return jacobian
def jacobian_eval(self, t, solution, solution_dot, solution_dot_coefficient): self._solution_from_dense_to_sparse(solution, u) self._solution_from_dense_to_sparse(solution_dot, u_dot) jacobian_array = assemble(Constant(solution_dot_coefficient)*j_u_dot + j_u).array() jacobian_array[[0, 1, min_dof_0_2pi, max_dof_0_2pi], :] = jacobian_array[[min_dof_0_2pi, max_dof_0_2pi, 0, 1], :] jacobian_array[:, [0, 1, min_dof_0_2pi, max_dof_0_2pi]] = jacobian_array[:, [min_dof_0_2pi, max_dof_0_2pi, 0, 1]] jacobian = Matrix(*jacobian_array.shape) jacobian[:, :] = jacobian_array return jacobian
def _test_eigen_solver_dense(sparse_LHS, sparse_RHS): from rbnics.backends.online.numpy import EigenSolver, Matrix # Extract constrained matrices from sparse eigensolver LHS = Matrix(*sparse_LHS.array().shape) RHS = Matrix(*sparse_RHS.array().shape) LHS[:, :] = sparse_LHS.array() RHS[:, :] = sparse_RHS.array() # Solve the eigenproblem solver = EigenSolver(None, LHS, RHS) solver.set_parameters({ "problem_type": "gen_non_hermitian", "spectrum": "smallest real", }) solver.solve(1) r, c = solver.get_eigenvalue(0) assert abs(c) < 1.e-10 assert r > 0., "r = " + str(r) + " is not positive" print("Dense inf-sup constant: ", sqrt(r)) return (sqrt(r), LHS, RHS)