def solve_schroedinger(mesh, l=0, Z=1, eqn_type="R", eig_num=4): """ Solves the Schroedinger equation on the given mesh. Returns the energies and eigenfunctions. """ # TODO: return the eigenfunctions as FESolutions N_dof = mesh.assign_dofs() A = CSCMatrix(N_dof) B = CSCMatrix(N_dof) assemble_schroedinger(mesh, A, B, l=l, Z=Z, eqn_type=eqn_type) eigs = solve_eig_scipy(A.to_scipy_csc(), B.to_scipy_csc()) eigs = eigs[:eig_num] energies = [E for E, eig in eigs] #print energies assert len(eigs) == eig_num eigs = [eig for E, eig in eigs] return N_dof, array(energies), eigs
def solve_dirac(mesh, kappa=1, Z=1, eig_num=4): """ Solves the Dirac equation on the given mesh. Returns the energies and eigenfunctions. """ mesh.set_bc_left_dirichlet(0, 0); mesh.set_bc_right_dirichlet(0, 0); N_dof = mesh.assign_dofs() A = CooMatrix(N_dof) B = CooMatrix(N_dof) assemble_dirac(mesh, A, B, kappa=kappa, Z=Z) eigs = solve_eig_scipy(A.to_scipy_coo(), B.to_scipy_coo()) c = 137.03599911 eigs = [(E, eig) for E, eig in eigs if E > -2*c**2 and E < 0] eigs = eigs[:eig_num] #assert len(eigs) == eig_num energies = [E for E, eig in eigs] eigs = [eig for E, eig in eigs] return N_dof, array(energies), eigs
def solve_dirac(mesh, kappa=1, Z=1, eig_num=4): """ Solves the Dirac equation on the given mesh. Returns the energies and eigenfunctions. """ mesh.set_bc_left_dirichlet(0, 0) mesh.set_bc_right_dirichlet(0, 0) N_dof = mesh.assign_dofs() A = CooMatrix(N_dof) B = CooMatrix(N_dof) assemble_dirac(mesh, A, B, kappa=kappa, Z=Z) eigs = solve_eig_scipy(A.to_scipy_coo(), B.to_scipy_coo()) c = 137.03599911 eigs = [(E, eig) for E, eig in eigs if E > -2 * c**2 and E < 0] eigs = eigs[:eig_num] #assert len(eigs) == eig_num energies = [E for E, eig in eigs] eigs = [eig for E, eig in eigs] return N_dof, array(energies), eigs