38#include "libmesh/libmesh.h"
39#include "libmesh/mesh.h"
40#include "libmesh/mesh_generation.h"
41#include "libmesh/exodusII_io.h"
42#include "libmesh/eigen_system.h"
43#include "libmesh/equation_systems.h"
44#include "libmesh/slepc_eigen_solver.h"
45#include "libmesh/fe.h"
46#include "libmesh/quadrature_gauss.h"
47#include "libmesh/dense_matrix.h"
48#include "libmesh/sparse_matrix.h"
49#include "libmesh/numeric_vector.h"
50#include "libmesh/dof_map.h"
51#include "libmesh/enum_eigen_solver_type.h"
52#include "libmesh/getpot.h"
61 const std::string & system_name);
65int main (
int argc,
char ** argv)
71#ifndef LIBMESH_HAVE_SLEPC
72 if (init.comm().rank() == 0)
73 libMesh::err <<
"ERROR: This example requires libMesh to be\n"
74 <<
"compiled with SLEPc eigen solvers support!"
80#ifdef LIBMESH_DEFAULT_SINGLE_PRECISION
82 libmesh_example_requires(
false,
"--disable-singleprecision");
86 libmesh_error_msg_if(argc < 3,
"\nUsage: " << argv[0] <<
" -n <number of eigen values>");
91 for (
int i=1; i<argc; i++)
105 libmesh_example_requires(2 <= LIBMESH_DIM,
"2D support");
143 equation_systems.
parameters.
set<
unsigned int>(
"eigenpairs") = nev;
144 equation_systems.
parameters.
set<
unsigned int>(
"basis vectors") = nev*3;
156 equation_systems.
parameters.
set<
unsigned int>(
"linear solver maximum iterations") = 1000;
167 equation_systems.
init();
172#if SLEPC_VERSION_LESS_THAN(3,1,0)
173 libmesh_error_msg(
"SLEPc 3.1 is required to call EigenSolver::set_initial_space()");
179 initial_space.
add(1.0);
184 eigen_system.
solve();
199#ifdef LIBMESH_HAVE_EXODUS_API
206 libMesh::out <<
"WARNING: Solver did not converge!\n" << nconv << std::endl;
218 const std::string & libmesh_dbg_var(system_name))
223 libmesh_assert_equal_to (system_name,
"Eigensystem");
225#ifdef LIBMESH_HAVE_SLEPC
252 QGauss qrule (
dim, fe_type.default_quadrature_order());
255 fe->attach_quadrature_rule (&qrule);
258 const std::vector<Real> & JxW = fe->get_JxW();
261 const std::vector<std::vector<Real>> & phi = fe->get_phi();
265 const std::vector<std::vector<RealGradient>> & dphi = fe->get_dphi();
279 std::vector<dof_id_type> dof_indices;
287 for (
const auto & elem :
mesh.active_local_element_ptr_range())
307 const unsigned int n_dofs =
308 cast_int<unsigned int>(dof_indices.size());
309 Ke.
resize (n_dofs, n_dofs);
310 Me.
resize (n_dofs, n_dofs);
318 for (
unsigned int qp=0; qp<qrule.
n_points(); qp++)
319 for (
unsigned int i=0; i<n_dofs; i++)
320 for (
unsigned int j=0; j<n_dofs; j++)
322 Me(i,j) += JxW[qp]*phi[i][qp]*phi[j][qp];
323 Ke(i,j) += JxW[qp]*(dphi[i][qp]*dphi[j][qp]);
Defines a dense matrix for use in Finite Element-type computations.
void resize(const unsigned int new_m, const unsigned int new_n)
Resizes the matrix to the specified size and calls zero().
This class handles the numbering of degrees of freedom on a mesh.
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
const FEType & variable_type(const unsigned int i) const
This class provides an interface to solvers for eigenvalue problems.
virtual void set_initial_space(NumericVector< T > &initial_space_in)=0
Provide one basis vector for the initial guess.
Manages consistently variables, degrees of freedom, and coefficient vectors for eigenvalue problems.
void set_eigenproblem_type(EigenProblemType ept)
Sets the type of the current eigen problem.
const SparseMatrix< Number > & get_matrix_B() const
virtual void solve() override
Assembles & solves the eigen system.
virtual std::pair< Real, Real > get_eigenpair(dof_id_type i)
unsigned int get_n_converged() const
const SparseMatrix< Number > & get_matrix_A() const
const EigenSolver< Number > & get_eigen_solver() const
This is the EquationSystems class.
void print_info(std::ostream &os=libMesh::out) const
Prints information about the equation systems, by default to libMesh::out.
const MeshBase & get_mesh() const
Parameters parameters
Data structure holding arbitrary parameters.
virtual void init()
Initialize all the systems.
virtual System & add_system(std::string_view system_type, std::string_view name)
Add the system of type system_type named name to the systems array.
const T_sys & get_system(std::string_view name) const
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
virtual void write_equation_systems(const std::string &fname, const EquationSystems &es, const std::set< std::string > *system_names=nullptr) override
Writes out the solution for no specific time or timestep.
static std::unique_ptr< FEGenericBase > build(const unsigned int dim, const FEType &type)
Builds a specific finite element type.
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
This is the MeshBase class.
unsigned int mesh_dimension() const
void print_info(std::ostream &os=libMesh::out, const unsigned int verbosity=0, const bool global=true) const
Prints relevant information about the mesh.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
virtual void add(const numeric_index_type i, const T value)=0
Adds value to the vector entry specified by i.
T & set(const std::string &)
unsigned int n_points() const
This class implements specific orders of Gauss quadrature.
virtual void add_matrix(const DenseMatrix< T > &dm, const std::vector< numeric_index_type > &rows, const std::vector< numeric_index_type > &cols)=0
Add the full matrix dm to the SparseMatrix.
void attach_assemble_function(void fptr(EquationSystems &es, const std::string &name))
Register a user function to use in assembling the system matrix and RHS.
unsigned int add_variable(std::string_view var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Adds the variable var to the list of variables for this system.
NumericVector< Number > & add_vector(std::string_view vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Adds the additional vector vec_name to this system.
const DofMap & get_dof_map() const
void assemble_mass(EquationSystems &es, const std::string &system_name)
The libMesh namespace provides an interface to certain functionality in the library.
void libmesh_ignore(const Args &...)
T command_line_next(std::string name, T default_value)
Use GetPot's search()/next() functions to get following arguments from the command line.
static constexpr Real TOLERANCE
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real