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/fe.h" 45 #include "libmesh/quadrature_gauss.h" 46 #include "libmesh/dense_matrix.h" 47 #include "libmesh/sparse_matrix.h" 48 #include "libmesh/numeric_vector.h" 49 #include "libmesh/dof_map.h" 50 #include "libmesh/getpot.h" 58 const std::string & system_name);
60 int main (
int argc,
char ** argv)
65 #ifdef LIBMESH_DEFAULT_SINGLE_PRECISION 67 libmesh_example_requires(
false,
"--disable-singleprecision");
70 #ifndef LIBMESH_HAVE_SLEPC 71 libmesh_example_requires(
false,
"--enable-slepc");
74 libmesh_error_msg_if(argc < 3,
"\nUsage: " << argv[0] <<
" -n <number of eigen values>");
79 for (
int i=1; i<argc; i++)
92 libmesh_example_requires(2 <= LIBMESH_DIM,
"2D support");
130 equation_systems.
parameters.
set<
unsigned int>(
"eigenpairs") = nev;
131 equation_systems.
parameters.
set<
unsigned int>(
"basis vectors") = nev*3;
145 (
"linear solver maximum iterations") = 1000;
148 equation_systems.
init();
154 eigen_system.
solve();
159 libMesh::out <<
"Number of converged eigenpairs: " << nconv
160 <<
"\n" << std::endl;
167 #ifdef LIBMESH_HAVE_EXODUS_API 170 #endif // #ifdef LIBMESH_HAVE_EXODUS_API 174 libMesh::out <<
"WARNING: Solver did not converge!\n" << nconv << std::endl;
179 #endif // LIBMESH_HAVE_SLEPC 185 const std::string & libmesh_dbg_var(system_name))
189 libmesh_assert_equal_to (system_name,
"Eigensystem");
191 #ifdef LIBMESH_HAVE_SLEPC 217 QGauss qrule (
dim, fe_type.default_quadrature_order());
220 fe->attach_quadrature_rule (&qrule);
223 const std::vector<Real> & JxW = fe->get_JxW();
226 const std::vector<std::vector<Real>> & phi = fe->get_phi();
239 std::vector<dof_id_type> dof_indices;
247 for (
const auto & elem :
mesh.active_local_element_ptr_range())
267 const unsigned int n_dofs =
268 cast_int<unsigned int>(dof_indices.size());
269 Me.
resize (n_dofs, n_dofs);
277 for (
unsigned int qp=0; qp<qrule.n_points(); qp++)
278 for (
unsigned int i=0; i != n_dofs; i++)
279 for (
unsigned int j=0; j != n_dofs; j++)
280 Me(i,j) += JxW[qp]*phi[i][qp]*phi[j][qp];
301 #endif // LIBMESH_HAVE_SLEPC class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
virtual std::pair< Real, Real > get_eigenpair(dof_id_type i)
T command_line_next(std::string name, T default_value)
Use GetPot's search()/next() functions to get following arguments from the command line...
This is the EquationSystems class.
const SparseMatrix< Number > & get_matrix_A() const
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
static constexpr Real TOLERANCE
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
const FEType & variable_type(const unsigned int c) const
void print_info(std::ostream &os=libMesh::out) const
Prints information about the equation systems, by default to libMesh::out.
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
The libMesh namespace provides an interface to certain functionality in the library.
const T_sys & get_system(std::string_view name) const
This is the MeshBase class.
int main(int argc, char **argv)
This class handles the numbering of degrees of freedom on a mesh.
void libmesh_ignore(const Args &...)
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.
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.
void print_info(std::ostream &os=libMesh::out, const unsigned int verbosity=0, const bool global=true) const
Prints relevant information about the mesh.
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
static std::unique_ptr< FEGenericBase > build(const unsigned int dim, const FEType &type)
Builds a specific finite element type.
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.
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.
virtual void solve() override
Assembles & solves the eigen system.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
T & set(const std::string &)
const MeshBase & get_mesh() const
void resize(const unsigned int new_m, const unsigned int new_n)
Resizes the matrix to the specified size and calls zero().
This class implements specific orders of Gauss quadrature.
unsigned int mesh_dimension() const
Parameters parameters
Data structure holding arbitrary parameters.
unsigned int get_n_converged() const
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.
Manages consistently variables, degrees of freedom, and coefficient vectors for eigenvalue problems...
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
const DofMap & get_dof_map() const
void assemble_mass(EquationSystems &es, const std::string &system_name)
void constrain_element_matrix(DenseMatrix< Number > &matrix, std::vector< dof_id_type > &elem_dofs, bool asymmetric_constraint_rows=true) const
Constrains the element matrix.