## libmesh-users

 [Libmesh-users] Eigenvalue Solver From: David Xu - 2006-02-20 22:48:43 ```Hi Steffen and Ondrej, I read your previous message that you've extended the slepc interface to support generalized eigen problems. I'd like to get the details from you. I'm new to libmesh and I'm wondering if you can post some new tutorial examples on how to solve eigen problems using libmesh (eg. solve 1D or 2D simple harmonic oscillator)? That will a great help. Ondrej, I read about your message about your implementation of libmesh and pysparse's jacobi-davidson solver. That sounds really good. Could you please give me the details too? I really appreciate it. David ```
 [Libmesh-users] AW: Eigenvalue Solver From: Steffen Petersen - 2006-02-21 18:28:34 ```Hello David, I will commit an adjusted example within the next days. Note that some rather useful functionality is only available with the latest slepc version (e.g. computation of the smallest eigenvalues within the spectrum), so I recommend to use the 2.3.0 versions of petsc and slepc. Steffen > Hi Steffen and Ondrej, > > I read your previous message that you've extended the slepc interface > to support generalized eigen problems. I'd like to get the details > from you. I'm new to libmesh and I'm wondering if you can post some > new tutorial examples on how to solve eigen problems using libmesh > (eg. solve 1D or 2D simple harmonic oscillator)? That will a great > help. > > Ondrej, I read about your message about your implementation of libmesh > and pysparse's jacobi-davidson solver. That sounds really good. Could > you please give me the details too? I really appreciate it. > > David > ```
 [Libmesh-users] Re: Eigenvalue Solver From: Steffen Petersen - 2006-02-27 08:33:35 ```I have just committed an example 17 including a generalized eigenvalue problem. Currently, the largest eigenvalues in the spectrum are computed. The code can be easily changed in order to compute the smallest values (or use the slepc comman line options). However, the Lanczos solver slepc offers with this option appears to be somewhat unstable when used to compute the smallest values (perhaps this is due to the zero eigenmode in this example). An option to work around this problem is to configure and install slepc with arpack and parpack (the arpack solver works fine for example 17). Steffen David Xu schrieb: > Hi Steffen and Ondrej, > > I read your previous message that you've extended the slepc interface > to support generalized eigen problems. I'd like to get the details > from you. I'm new to libmesh and I'm wondering if you can post some > new tutorial examples on how to solve eigen problems using libmesh > (eg. solve 1D or 2D simple harmonic oscillator)? That will a great > help. > > Ondrej, I read about your message about your implementation of libmesh > and pysparse's jacobi-davidson solver. That sounds really good. Could > you please give me the details too? I really appreciate it. > > David ```
 [Libmesh-users] Re: Eigenvalue Solver From: David Xu - 2006-03-01 18:59:50 ```Hi Steffen, I'm looking forward to your example 17 and implementation of generalized eigen value solver with libmesh. Thanks, David On 2/27/06, Steffen Petersen wrote: > I have just committed an example 17 including a generalized > eigenvalue problem. Currently, the largest eigenvalues > in the spectrum are computed. The code can be easily changed > in order to compute the smallest values (or use the slepc comman > line options). However, the Lanczos solver slepc offers with this > option appears to be somewhat unstable when used to compute > the smallest values (perhaps this is due to the zero eigenmode in > this example). An option to work around this problem is to > configure and install slepc with arpack and parpack (the arpack > solver works fine for example 17). > > Steffen > > > > David Xu schrieb: > > Hi Steffen and Ondrej, > > > > I read your previous message that you've extended the slepc interface > > to support generalized eigen problems. I'd like to get the details > > from you. I'm new to libmesh and I'm wondering if you can post some > > new tutorial examples on how to solve eigen problems using libmesh > > (eg. solve 1D or 2D simple harmonic oscillator)? That will a great > > help. > > > > Ondrej, I read about your message about your implementation of libmesh > > and pysparse's jacobi-davidson solver. That sounds really good. Could > > you please give me the details too? I really appreciate it. > > > > David > > ```
 [Libmesh-users] Re: Eigenvalue Solver From: David Xu - 2006-03-04 18:14:50 ```Hi Steffen, I'm not familiar with Slepc. Could elaborate how to modify the code or use command line options to calculate the smallest eigenvalues? Thanks, David On 2/27/06, Steffen Petersen wrote: > I have just committed an example 17 including a generalized > eigenvalue problem. Currently, the largest eigenvalues > in the spectrum are computed. The code can be easily changed > in order to compute the smallest values (or use the slepc comman > line options). However, the Lanczos solver slepc offers with this > option appears to be somewhat unstable when used to compute > the smallest values (perhaps this is due to the zero eigenmode in > this example). An option to work around this problem is to > configure and install slepc with arpack and parpack (the arpack > solver works fine for example 17). > > Steffen > > > > David Xu schrieb: > > Hi Steffen and Ondrej, > > > > I read your previous message that you've extended the slepc interface > > to support generalized eigen problems. I'd like to get the details > > from you. I'm new to libmesh and I'm wondering if you can post some > > new tutorial examples on how to solve eigen problems using libmesh > > (eg. solve 1D or 2D simple harmonic oscillator)? That will a great > > help. > > > > Ondrej, I read about your message about your implementation of libmesh > > and pysparse's jacobi-davidson solver. That sounds really good. Could > > you please give me the details too? I really appreciate it. > > > > David > > ```
 [Libmesh-users] Re: Eigenvalue Solver From: David Xu - 2006-03-06 08:17:22 ```Hi Steffen, Besides ARPACK, can I call other package (BLZPACK, PLANSO, and TRLAN) from libmesh that SLEPC has an interface to? Of course I will install them with SLEPC first. Thanks, David On 2/27/06, Steffen Petersen wrote: > I have just committed an example 17 including a generalized > eigenvalue problem. Currently, the largest eigenvalues > in the spectrum are computed. The code can be easily changed > in order to compute the smallest values (or use the slepc comman > line options). However, the Lanczos solver slepc offers with this > option appears to be somewhat unstable when used to compute > the smallest values (perhaps this is due to the zero eigenmode in > this example). An option to work around this problem is to > configure and install slepc with arpack and parpack (the arpack > solver works fine for example 17). > > Steffen > > > > David Xu schrieb: > > Hi Steffen and Ondrej, > > > > I read your previous message that you've extended the slepc interface > > to support generalized eigen problems. I'd like to get the details > > from you. I'm new to libmesh and I'm wondering if you can post some > > new tutorial examples on how to solve eigen problems using libmesh > > (eg. solve 1D or 2D simple harmonic oscillator)? That will a great > > help. > > > > Ondrej, I read about your message about your implementation of libmesh > > and pysparse's jacobi-davidson solver. That sounds really good. Could > > you please give me the details too? I really appreciate it. > > > > David > > ```
 [Libmesh-users] Re: Eigenvalue Solver From: Steffen Petersen - 2006-03-02 10:26:06 ```Hello David, example 17 is already available. If you download the latest cvs version with cvs -d:pserver:anonymous@...:/cvsroot/libmesh co libmesh you will find ex17 in the example directory. If you want to update your current version, you will have to update libmesh with the "-d" option cvs -d:pserver:ano... update -d libmesh in order to receive the files that have been added recently. The online documentation does not include ex17 since it is not included in the actual libmesh release (although I think most people use the cvs version). As far as I know, the online documentation corresponds to the latest libmesh release (someone may correct me if I am wrong). Anyway, I will commit the corresponding files for the web page soon. Steffen David Xu schrieb: > Hi Steffen, > > I'm looking forward to your example 17 and implementation of > generalized eigen value solver with libmesh. > > Thanks, > > David > > On 2/27/06, Steffen Petersen wrote: > >>I have just committed an example 17 including a generalized >>eigenvalue problem. Currently, the largest eigenvalues >>in the spectrum are computed. The code can be easily changed >>in order to compute the smallest values (or use the slepc comman >>line options). However, the Lanczos solver slepc offers with this >>option appears to be somewhat unstable when used to compute >>the smallest values (perhaps this is due to the zero eigenmode in >>this example). An option to work around this problem is to >>configure and install slepc with arpack and parpack (the arpack >>solver works fine for example 17). >> >>Steffen >> >> >> >>David Xu schrieb: >> >>>Hi Steffen and Ondrej, >>> >>>I read your previous message that you've extended the slepc interface >>>to support generalized eigen problems. I'd like to get the details >>>from you. I'm new to libmesh and I'm wondering if you can post some >>>new tutorial examples on how to solve eigen problems using libmesh >>>(eg. solve 1D or 2D simple harmonic oscillator)? That will a great >>>help. >>> >>>Ondrej, I read about your message about your implementation of libmesh >>>and pysparse's jacobi-davidson solver. That sounds really good. Could >>>you please give me the details too? I really appreciate it. >>> >>>David >> >> ```
 [Libmesh-users] Re: Eigenvalue Solver From: David Xu - 2006-03-03 09:07:52 ```Steffen, Thanks for the heads up. I found the ex17 in the cvs. I question is how to export the desired eigenvalues to a file or standard output? You have the following lines in ex16 and ex17, which is to output the eigenvectors to a gmv file: =09eigen_system.get_eigenpair(nconv-1); =09 =09// Write the eigen vector to file. =09char buf[14]; =09sprintf (buf, "out.gmv"); =09GMVIO (mesh).write_equation_systems (buf, equation_systems); I didn't how to use eigen_system.get_eigenpair to get the eigenvalues. Please enlighten me. Also, please let me know how to export the system matrices A and B to a file, Ondrej Certik used pysparse/Jacobi-Davidson program on the system matrices after they are exported to files. I'd like to try that too. Thank you, David On 3/2/06, Steffen Petersen wrote: > > Hello David, > > example 17 is already available. If you download the latest > cvs version with > cvs -d:pserver:anonymous@...:/cvsroot/libmesh co libmesh > you will find ex17 in the example directory. > If you want to update your current version, you will > have to update libmesh with the "-d" option > cvs -d:pserver:ano... update -d libmesh > in order to receive the files that have been added recently. > > The online documentation does not include ex17 > since it is not included in the actual libmesh release > (although I think most people use the cvs version). > As far as I know, the online documentation corresponds to > the latest libmesh release (someone may correct me if I am wrong). > Anyway, I will commit the corresponding files for the > web page soon. > > Steffen > > > David Xu schrieb: > > Hi Steffen, > > > > I'm looking forward to your example 17 and implementation of > > generalized eigen value solver with libmesh. > > > > Thanks, > > > > David > > > > On 2/27/06, Steffen Petersen wrote: > > > >>I have just committed an example 17 including a generalized > >>eigenvalue problem. Currently, the largest eigenvalues > >>in the spectrum are computed. The code can be easily changed > >>in order to compute the smallest values (or use the slepc comman > >>line options). However, the Lanczos solver slepc offers with this > >>option appears to be somewhat unstable when used to compute > >>the smallest values (perhaps this is due to the zero eigenmode in > >>this example). An option to work around this problem is to > >>configure and install slepc with arpack and parpack (the arpack > >>solver works fine for example 17). > >> > >>Steffen > >> > >> > >> > >>David Xu schrieb: > >> > >>>Hi Steffen and Ondrej, > >>> > >>>I read your previous message that you've extended the slepc interface > >>>to support generalized eigen problems. I'd like to get the details > >>>from you. I'm new to libmesh and I'm wondering if you can post some > >>>new tutorial examples on how to solve eigen problems using libmesh > >>>(eg. solve 1D or 2D simple harmonic oscillator)? That will a great > >>>help. > >>> > >>>Ondrej, I read about your message about your implementation of libmesh > >>>and pysparse's jacobi-davidson solver. That sounds really good. Could > >>>you please give me the details too? I really appreciate it. > >>> > >>>David > >> > >> > > ```
 [Libmesh-users] Re: Eigenvalue Solver From: David Xu - 2006-03-04 09:59:38 ```Hi Everyone, I followed Steffen's new generalized eigen problem code in the new ex17 and wrote my first libmesh code to solve 1D time-independent schrodinger equation with simple harmonic oscillator potential, the equation is -0.5u''+0.5*x^2*u=3DE*u . The analytical solution of the eigenvalue E are: 0.5, 1.5, 2.5, 3.5. 4.5 ... I set up the 1D domain [-5 5] and apply the Dirichlet BC u(-5)=3Du(5)=3D0 following ex0. The code compiled okay, but the results were way large eigenvalues and I don't know what went wrong in my code. So, I'm attaching my code here, it should fairly straightforward since it's a simple 1D case. I'd really appreciate it if anyone can help me figure out the problem. Source code: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D // 1D Time independent Schrodinger Equation Eigenvalue Solver // using simple harmonic potential // libMesh include files. #include "libmesh.h" #include "mesh.h" #include "mesh_generation.h" #include "gmv_io.h" #include "eigen_system.h" #include "equation_systems.h" #include "fe.h" #include "quadrature_gauss.h" #include "dense_matrix.h" #include "sparse_matrix.h" #include "numeric_vector.h" #include "dof_map.h" #include "edge_edge3.h" // Function prototype. This is the function that will assemble // the eigen system. Here, we will simply assemble a mass matrix. void assemble_mass(EquationSystems& es, =09=09 const std::string& system_name); int main (int argc, char** argv) { // Initialize libMesh and the dependent libraries. libMesh::init (argc, argv); // This example is designed for the SLEPc eigen solver interface. #ifndef HAVE_SLEPC std::cerr << "ERROR: This example requires libMesh to be\n" =09 << "compiled with SLEPc eigen solvers support!" =09 << std::endl; return 0; #else // Braces are used to force object scope. { // Check for proper usage. if (argc < 3) { =09std::cerr << "\nUsage: " << argv[0] =09=09 << " -n " =09=09 << std::endl; =09error(); } // Tell the user what we are doing. else { =09std::cout << "Running " << argv[0]; =09 =09for (int i=3D1; i ("Eigensystem"); // Declare the system variables. { // Adds the variable "p" to "Eigensystem". "p" // will be approximated using second-order approximation. eigen_system.add_variable("u", SECOND); // Give the system a pointer to the matrix assembly // function defined below. eigen_system.attach_assemble_function (assemble_mass); // Set necessary parametrs used in EigenSystem::solve(), // i.e. the number of requested eigenpairs \p nev and the number // of basis vectors \p ncv used in the solution algorithm. Note that // ncv >=3D nev must hold and ncv >=3D 2*nev is recommended. equation_systems.parameters.set("eigenpairs") =3D ne= v; equation_systems.parameters.set("basis vectors") =3D ne= v*3; // Set the eigen solver type. SLEPc offers various solvers such as // the Arnoldi and subspace method. It // also offers interfaces to other solver packages (e.g. ARPACK). eigen_system.eigen_solver->set_eigensolver_type(ARNOLDI); // Set the solver tolerance and the maximum number of iterations. equation_systems.parameters.set("linear solver tolerance") =3D pow(TOLERANCE, 5./3.); equation_systems.parameters.set =09("linear solver maximum iterations") =3D 1000; // Set the type of the problem, here we deal with // a generalized Hermitian problem. eigen_system.set_eigenproblem_type(GHEP); // Set the eigenvalues to be computed. Note that not // all solvers support this. // eigen_system.eigen_solver->set_position_of_spectrum(SMALLEST_MAGNI= TUDE); // Initialize the data structures for the equation system. equation_systems.init(); // Prints information about the system to the screen. equation_systems.print_info(); } // Solve the system "Eigensystem". eigen_system.solve(); // Get the number of converged eigen pairs. unsigned int nconv =3D eigen_system.get_n_converged(); std::cout << "Number of converged eigenpairs: " << nconv =09 << "\n" << std::endl; std::pair myeig; // Get the last converged eigenpair if (nconv !=3D 0) { =09//print eigenvalues for(unsigned int n=3D0; n<=3Dnconv-1; n++) { =09myeig=3Deigen_system.get_eigenpair(n); std::cout << "eig(" << n << ")=3D " << myeig.first << "\n" << std::= endl; } } else { =09std::cout << "WARNING: Solver did not converge!\n" << nconv << std::endl= ; } } #endif // HAVE_SLEPC // All done. return libMesh::close (); } void assemble_mass(EquationSystems& es, =09=09 const std::string& system_name) { // It is a good idea to make sure we are assembling // the proper system. assert (system_name =3D=3D "Eigensystem"); #ifdef HAVE_SLEPC // Get a constant reference to the mesh object. const Mesh& mesh =3D es.get_mesh(); // The dimension that we are running. const unsigned int dim =3D mesh.mesh_dimension(); // Get a reference to our system. EigenSystem & eigen_system =3D es.get_system (system_name); // Get a constant reference to the Finite Element type // for the first (and only) variable in the system. FEType fe_type =3D eigen_system.get_dof_map().variable_type(0); // A reference to the two system matrices SparseMatrix& matrix_A =3D *eigen_system.matrix_A; SparseMatrix& matrix_B =3D *eigen_system.matrix_B; // Build a Finite Element object of the specified type. Since the // \p FEBase::build() member dynamically creates memory we will // store the object as an \p AutoPtr. This can be thought // of as a pointer that will clean up after itself. AutoPtr fe (FEBase::build(dim, fe_type)); // A Gauss quadrature rule for numerical integration. // Use the default quadrature order. //QGauss qrule (dim, fe_type.default_quadrature_order()); QGauss qrule(dim,FIFTH); // Tell the finite element object to use our quadrature rule. fe->attach_quadrature_rule (&qrule); // The element Jacobian * quadrature weight at each integration point. const std::vector& JxW =3D fe->get_JxW(); const std::vector& q_point =3D fe->get_xyz(); // The element shape functions evaluated at the quadrature points. const std::vector >& phi =3D fe->get_phi(); // The element shape function gradients evaluated at the quadrature // points. const std::vector >& dphi =3D fe->get_dphi(); // A reference to the \p DofMap object for this system. The \p DofMap // object handles the index translation from node and element numbers // to degree of freedom numbers. const DofMap& dof_map =3D eigen_system.get_dof_map(); // The element mass and stiffness matrices. DenseMatrix Me; DenseMatrix Ke; // This vector will hold the degree of freedom indices for // the element. These define where in the global system // the element degrees of freedom get mapped. std::vector dof_indices; // Now we will loop over all the elements in the mesh. // We will compute the element matrix contribution. MeshBase::const_element_iterator el =3D mesh.elements_begin(); const MeshBase::const_element_iterator end_el =3D mesh.elements_end(); for ( ; el !=3D end_el; ++el) { // Store a pointer to the element we are currently // working on. This allows for nicer syntax later. const Elem* elem =3D *el; // Get the degree of freedom indices for the // current element. These define where in the global // matrix and right-hand-side this element will // contribute to. dof_map.dof_indices (elem, dof_indices); // Compute the element-specific data for the current // element. This involves computing the location of the // quadrature points (q_point) and the shape functions // (phi, dphi) for the current element. fe->reinit (elem); // Zero the element matrices before // summing them. We use the resize member here because // the number of degrees of freedom might have changed from // the last element. Note that this will be the case if the // element type is different (i.e. the last element was a // triangle, now we are on a quadrilateral). Ke.resize (dof_indices.size(), dof_indices.size()); Me.resize (dof_indices.size(), dof_indices.size()); // Now loop over the quadrature points. This handles // the numeric integration. // // We will build the element matrix. This involves // a double loop to integrate the test funcions (i) against // the trial functions (j). for (unsigned int qp=3D0; qpn_sides(); s++) { if(elem->neighbor(s) =3D=3D NULL) { AutoPtr node(elem->side(s)); for(unsigned int n=3D0; nn_nodes(); n++) { if(elem->node(n) =3D=3D node->id()) { Ke(n,n) +=3D penalty; Me(n,n) +=3D 0*penalty; } } } } // Finally, simply add the element contribution to the // overall matrices A and B. matrix_A.add_matrix (Ke, dof_indices); matrix_B.add_matrix (Me, dof_indices); } // end of element loop #endif // HAVE_SLEPC /** * All done! */ return; } =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Thank you! David ```
 [Libmesh-users] Fwd: Eigenvalue Solver From: David Xu - 2006-03-04 17:59:32 ```Hi Everyone, I followed Steffen's new generalized eigen problem code in the new ex17 and wrote my first libmesh code to solve 1D time-independent schrodinger equation with simple harmonic oscillator potential, the equation is -0.5u''+0.5*x^2*u=3DE*u . The analytical solution of the eigenvalue E are: 0.5, 1.5, 2.5, 3.5. 4.5 ... I set up the 1D domain [-5 5] and apply the Dirichlet BC u(-5)=3Du(5)=3D0 following ex0. The code compiled okay, but the eigenvalue results were huge numbers and I don't know what went wrong in my code. So, I'm attaching my code here, it should fairly straightforward since it's a simple 1D case. I'd really appreciate it if anyone can help me figure out the problem. Source code: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D // 1D Time independent Schrodinger Equation Eigenvalue Solver // using simple harmonic potential // libMesh include files. #include "libmesh.h" #include "mesh.h" #include "mesh_generation.h" #include "gmv_io.h" #include "eigen_system.h" #include "equation_systems.h" #include "fe.h" #include "quadrature_gauss.h" #include "dense_matrix.h" #include "sparse_matrix.h" #include "numeric_vector.h" #include "dof_map.h" #include "edge_edge3.h" // Function prototype. This is the function that will assemble // the eigen system. Here, we will simply assemble a mass matrix. void assemble_mass(EquationSystems& es, const std::string& system_name); int main (int argc, char** argv) { // Initialize libMesh and the dependent libraries. libMesh::init (argc, argv); // This example is designed for the SLEPc eigen solver interface. #ifndef HAVE_SLEPC std::cerr << "ERROR: This example requires libMesh to be\n" << "compiled with SLEPc eigen solvers support!" << std::endl; return 0; #else // Braces are used to force object scope. { // Check for proper usage. if (argc < 3) { std::cerr << "\nUsage: " << argv[0] << " -n " << std::endl; error(); } // Tell the user what we are doing. else { std::cout << "Running " << argv[0]; for (int i=3D1; i ("Eigensystem"); // Declare the system variables. { // Adds the variable "p" to "Eigensystem". "p" // will be approximated using second-order approximation. eigen_system.add_variable("u", SECOND); // Give the system a pointer to the matrix assembly // function defined below. eigen_system.attach_assemble_function (assemble_mass); // Set necessary parametrs used in EigenSystem::solve(), // i.e. the number of requested eigenpairs \p nev and the number // of basis vectors \p ncv used in the solution algorithm. Note that // ncv >=3D nev must hold and ncv >=3D 2*nev is recommended. equation_systems.parameters.set("eigenpairs") =3D ne= v; equation_systems.parameters.set("basis vectors") =3D ne= v*3; // Set the eigen solver type. SLEPc offers various solvers such as // the Arnoldi and subspace method. It // also offers interfaces to other solver packages (e.g. ARPACK). eigen_system.eigen_solver->set_eigensolver_type(ARNOLDI); // Set the solver tolerance and the maximum number of iterations. equation_systems.parameters.set("linear solver tolerance") =3D pow(TOLERANCE, 5./3.); equation_systems.parameters.set ("linear solver maximum iterations") =3D 1000; // Set the type of the problem, here we deal with // a generalized Hermitian problem. eigen_system.set_eigenproblem_type(GHEP); // Set the eigenvalues to be computed. Note that not // all solvers support this. // eigen_system.eigen_solver->set_position_of_spectrum(SMALLEST_MAGNI= TUDE); // Initialize the data structures for the equation system. equation_systems.init(); // Prints information about the system to the screen. equation_systems.print_info(); } // Solve the system "Eigensystem". eigen_system.solve(); // Get the number of converged eigen pairs. unsigned int nconv =3D eigen_system.get_n_converged(); std::cout << "Number of converged eigenpairs: " << nconv << "\n" << std::endl; std::pair myeig; // Get the last converged eigenpair if (nconv !=3D 0) { //print eigenvalues for(unsigned int n=3D0; n<=3Dnconv-1; n++) { myeig=3Deigen_system.get_eigenpair(n); std::cout << "eig(" << n << ")=3D " << myeig.first << "\n" << std::= endl; } } else { std::cout << "WARNING: Solver did not converge!\n" << nconv << std::endl; } } #endif // HAVE_SLEPC // All done. return libMesh::close (); } void assemble_mass(EquationSystems& es, const std::string& system_name) { // It is a good idea to make sure we are assembling // the proper system. assert (system_name =3D=3D "Eigensystem"); #ifdef HAVE_SLEPC // Get a constant reference to the mesh object. const Mesh& mesh =3D es.get_mesh(); // The dimension that we are running. const unsigned int dim =3D mesh.mesh_dimension(); // Get a reference to our system. EigenSystem & eigen_system =3D es.get_system (system_name); // Get a constant reference to the Finite Element type // for the first (and only) variable in the system. FEType fe_type =3D eigen_system.get_dof_map().variable_type(0); // A reference to the two system matrices SparseMatrix& matrix_A =3D *eigen_system.matrix_A; SparseMatrix& matrix_B =3D *eigen_system.matrix_B; // Build a Finite Element object of the specified type. Since the // \p FEBase::build() member dynamically creates memory we will // store the object as an \p AutoPtr. This can be thought // of as a pointer that will clean up after itself. AutoPtr fe (FEBase::build(dim, fe_type)); // A Gauss quadrature rule for numerical integration. // Use the default quadrature order. //QGauss qrule (dim, fe_type.default_quadrature_order()); QGauss qrule(dim,FIFTH); // Tell the finite element object to use our quadrature rule. fe->attach_quadrature_rule (&qrule); // The element Jacobian * quadrature weight at each integration point. const std::vector& JxW =3D fe->get_JxW(); const std::vector& q_point =3D fe->get_xyz(); // The element shape functions evaluated at the quadrature points. const std::vector >& phi =3D fe->get_phi(); // The element shape function gradients evaluated at the quadrature // points. const std::vector >& dphi =3D fe->get_dphi(); // A reference to the \p DofMap object for this system. The \p DofMap // object handles the index translation from node and element numbers // to degree of freedom numbers. const DofMap& dof_map =3D eigen_system.get_dof_map(); // The element mass and stiffness matrices. DenseMatrix Me; DenseMatrix Ke; // This vector will hold the degree of freedom indices for // the element. These define where in the global system // the element degrees of freedom get mapped. std::vector dof_indices; // Now we will loop over all the elements in the mesh. // We will compute the element matrix contribution. MeshBase::const_element_iterator el =3D mesh.elements_begin(); const MeshBase::const_element_iterator end_el =3D mesh.elements_end(); for ( ; el !=3D end_el; ++el) { // Store a pointer to the element we are currently // working on. This allows for nicer syntax later. const Elem* elem =3D *el; // Get the degree of freedom indices for the // current element. These define where in the global // matrix and right-hand-side this element will // contribute to. dof_map.dof_indices (elem, dof_indices); // Compute the element-specific data for the current // element. This involves computing the location of the // quadrature points (q_point) and the shape functions // (phi, dphi) for the current element. fe->reinit (elem); // Zero the element matrices before // summing them. We use the resize member here because // the number of degrees of freedom might have changed from // the last element. Note that this will be the case if the // element type is different (i.e. the last element was a // triangle, now we are on a quadrilateral). Ke.resize (dof_indices.size(), dof_indices.size()); Me.resize (dof_indices.size(), dof_indices.size()); // Now loop over the quadrature points. This handles // the numeric integration. // // We will build the element matrix. This involves // a double loop to integrate the test funcions (i) against // the trial functions (j). for (unsigned int qp=3D0; qpn_sides(); s++) { if(elem->neighbor(s) =3D=3D NULL) { AutoPtr node(elem->side(s)); for(unsigned int n=3D0; nn_nodes(); n++) { if(elem->node(n) =3D=3D node->id()) { Ke(n,n) +=3D penalty; Me(n,n) +=3D 0*penalty; } } } } // Finally, simply add the element contribution to the // overall matrices A and B. matrix_A.add_matrix (Ke, dof_indices); matrix_B.add_matrix (Me, dof_indices); } // end of element loop #endif // HAVE_SLEPC /** * All done! */ return; } =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Thank you! David ```