def project_onto(self, mesh, proj_type="Fekete"): """ Projects 'self' onto the 'mesh' using the 'proj_type' projection. proj_type == "Fekete"/"L2"/"H1" """ if mesh == self._mesh: return self if proj_type == "Fekete": return Function(self, mesh) elif proj_type in ["L2", "H1"]: from hermes1d.h1d_wrapper.h1d_wrapper import \ (assemble_projection_matrix_rhs, Mesh, FESolution) from hermes1d.hermes_common.matrix import CSCMatrix, AVector pts, orders = mesh.get_mesh_data() m = Mesh(pts, orders) n_dof = m.assign_dofs() A = CSCMatrix(n_dof) rhs = AVector(n_dof) assemble_projection_matrix_rhs(m, A, rhs, self, projection_type=proj_type) coeffs = solve(A.to_scipy_csc().todense(), rhs.to_numpy()) return FESolution(m, coeffs).to_discrete_function() else: raise ValueError("Unknown projection type")
def calculate_FE_coeffs(self): if self._fe_sol is None: from hermes1d.h1d_wrapper.h1d_wrapper import \ (assemble_projection_matrix_rhs, Mesh, FESolution) from hermes1d.hermes_common.matrix import CSCMatrix, AVector pts, orders = self._mesh.get_mesh_data() m = Mesh(pts, orders) n_dof = m.assign_dofs() A = CSCMatrix(n_dof) rhs = AVector(n_dof) assemble_projection_matrix_rhs(m, A, rhs, self, projection_type="L2") coeffs = solve(A.to_scipy_csc().todense(), rhs.to_numpy()) self._fe_sol = FESolution(m, coeffs)