Go to the documentation of this file.
   53 #include "libmesh/libmesh.h" 
   54 #include "libmesh/mesh.h" 
   55 #include "libmesh/mesh_generation.h" 
   56 #include "libmesh/exodusII_io.h" 
   57 #include "libmesh/condensed_eigen_system.h" 
   58 #include "libmesh/equation_systems.h" 
   59 #include "libmesh/fe.h" 
   60 #include "libmesh/quadrature_gauss.h" 
   61 #include "libmesh/dense_matrix.h" 
   62 #include "libmesh/sparse_matrix.h" 
   63 #include "libmesh/numeric_vector.h" 
   64 #include "libmesh/dof_map.h" 
   65 #include "libmesh/fe_interface.h" 
   66 #include "libmesh/getpot.h" 
   67 #include "libmesh/elem.h" 
   68 #include "libmesh/zero_function.h" 
   69 #include "libmesh/dirichlet_boundaries.h" 
   70 #include "libmesh/slepc_macro.h" 
   71 #include "libmesh/enum_eigen_solver_type.h" 
   73 #define BOUNDARY_ID 100 
   82                        const std::string & system_name);
 
   86                         const std::string & system_name,
 
   87                         std::set<unsigned int> & global_dirichlet_dofs_set);
 
   90 int main (
int argc, 
char ** argv)
 
   96 #ifndef LIBMESH_HAVE_EXODUS_API 
   97   libmesh_example_requires(
false, 
"--enable-exodus");
 
  101 #ifndef LIBMESH_HAVE_SLEPC 
  102   if (
init.comm().rank() == 0)
 
  103     libMesh::err << 
"ERROR: This example requires libMesh to be\n" 
  104                  << 
"compiled with SLEPc eigen solvers support!" 
  110 #ifdef LIBMESH_DEFAULT_SINGLE_PRECISION 
  112   libmesh_example_requires(
false, 
"--disable-singleprecision");
 
  115 #if defined(LIBMESH_USE_COMPLEX_NUMBERS) && SLEPC_VERSION_LESS_THAN(3,6,2) 
  118   libmesh_example_requires(
false, 
"--disable-complex or use SLEPc>=3.6.2");
 
  122 #ifndef LIBMESH_ENABLE_DIRICHLET 
  123   libmesh_example_requires(
false, 
"--enable-dirichlet");
 
  130     for (
int i=1; i<argc; i++)
 
  137   libmesh_example_requires(2 <= LIBMESH_DIM, 
"2D support");
 
  140   GetPot command_line (argc, argv);
 
  143   std::string mesh_name = 
"";
 
  144   if (command_line.search(1, 
"-mesh_name"))
 
  145     mesh_name = command_line.next(mesh_name);
 
  149   unsigned int plotting_index = 0;
 
  150   if (command_line.search(1, 
"-plotting_index"))
 
  151     plotting_index = command_line.next(plotting_index);
 
  154   unsigned int n_evals = 0;
 
  155   if (command_line.search(1, 
"-n_evals"))
 
  156     n_evals = command_line.next(n_evals);
 
  159   std::ostringstream mesh_name_exodus;
 
  160   mesh_name_exodus << mesh_name << 
"_mesh.e";
 
  172     for (
auto side : elem->side_index_range())
 
  173       if (elem->neighbor_ptr (side) == 
nullptr)
 
  198   equation_systems.
parameters.
set<
unsigned int>(
"eigenpairs")    = n_evals;
 
  199   equation_systems.
parameters.
set<
unsigned int>(
"basis vectors") = n_evals*3;
 
  204     (
"linear solver maximum iterations") = 1000;
 
  214     std::set<boundary_id_type> boundary_ids;
 
  215     boundary_ids.insert(BOUNDARY_ID);
 
  217     std::vector<unsigned int> variables;
 
  218     variables.push_back(0);
 
  222 #ifdef LIBMESH_ENABLE_DIRICHLET 
  233   equation_systems.
init();
 
  241   eigen_system.
solve();
 
  251   if (plotting_index > n_evals)
 
  253       libMesh::out << 
"WARNING: Solver did not converge for the requested eigenvector!" << std::endl;
 
  257   std::ostringstream eigenvalue_output_name;
 
  258   eigenvalue_output_name << mesh_name << 
"_evals.txt";
 
  259   std::ofstream evals_file(eigenvalue_output_name.str().c_str());
 
  261   for (
unsigned int i=0; i<nconv; i++)
 
  266       libmesh_assert_less (eval.second, 
TOLERANCE);
 
  267       evals_file << eval.first << std::endl;
 
  270       if (i == plotting_index)
 
  272 #ifdef LIBMESH_HAVE_EXODUS_API 
  274           std::ostringstream eigenvector_output_name;
 
  275           eigenvector_output_name << mesh_name << 
"_evec.e";
 
  277 #endif // #ifdef LIBMESH_HAVE_EXODUS_API 
  283 #endif // LIBMESH_HAVE_SLEPC 
  292                        const std::string & libmesh_dbg_var(system_name))
 
  297   libmesh_assert_equal_to (system_name, 
"Eigensystem");
 
  299 #ifdef LIBMESH_HAVE_SLEPC 
  326   QGauss qrule (
dim, fe_type.default_quadrature_order());
 
  329   fe->attach_quadrature_rule (&qrule);
 
  332   const std::vector<Real> & JxW = fe->get_JxW();
 
  335   const std::vector<std::vector<Real>> & phi = fe->get_phi();
 
  339   const std::vector<std::vector<RealGradient>> & dphi = fe->get_dphi();
 
  353   std::vector<dof_id_type> dof_indices;
 
  382       const unsigned int n_dofs =
 
  383         cast_int<unsigned int>(dof_indices.size());
 
  384       Ke.
resize (n_dofs, n_dofs);
 
  385       Me.
resize (n_dofs, n_dofs);
 
  393       for (
unsigned int qp=0; qp<qrule.n_points(); qp++)
 
  394         for (
unsigned int i=0; i<n_dofs; i++)
 
  395           for (
unsigned int j=0; j<n_dofs; j++)
 
  397               Me(i,j) += JxW[qp]*phi[i][qp]*phi[j][qp];
 
  398               Ke(i,j) += JxW[qp]*(dphi[i][qp]*dphi[j][qp]);
 
  422 #endif // LIBMESH_HAVE_SLEPC 
  
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
 
std::unique_ptr< SparseMatrix< Number > > matrix_A
The system matrix for standard eigenvalue problems.
 
virtual System & add_system(const std::string &system_type, const std::string &name)
Add the system of type system_type named name to the systems array.
 
void assemble_matrices(EquationSystems &es, const std::string &system_name)
 
const MeshBase & get_mesh() const
 
void get_dirichlet_dofs(EquationSystems &es, const std::string &system_name, std::set< unsigned int > &global_dirichlet_dofs_set)
 
virtual void read(const std::string &name, void *mesh_data=nullptr, bool skip_renumber_nodes_and_elements=false, bool skip_find_neighbors=false)=0
Interfaces for reading/writing a mesh to/from a file.
 
const BoundaryInfo & get_boundary_info() const
The information about boundary ids on the mesh.
 
This class implements specific orders of Gauss quadrature.
 
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
Fills the vector di with the global degree of freedom indices for the element.
 
virtual void solve() override
Override to solve the condensed eigenproblem with the dofs in local_non_condensed_dofs_vector strippe...
 
void add_dirichlet_boundary(const DirichletBoundary &dirichlet_boundary)
Adds a copy of the specified Dirichlet boundary to the system.
 
virtual SimpleRange< element_iterator > active_local_element_ptr_range()=0
 
The libMesh namespace provides an interface to certain functionality in the library.
 
const T_sys & get_system(const std::string &name) const
 
static const Real TOLERANCE
 
std::unique_ptr< EigenSolver< Number > > eigen_solver
The EigenSolver, defining which interface, i.e solver package to use.
 
virtual std::pair< Real, Real > get_eigenpair(dof_id_type i) override
Override get_eigenpair() to retrieve the eigenpair for the condensed eigensolve.
 
void set_eigenproblem_type(EigenProblemType ept)
Sets the type of the current eigen problem.
 
unsigned int mesh_dimension() const
 
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
 
void resize(const unsigned int new_m, const unsigned int new_n)
Resize the matrix.
 
unsigned int get_n_converged() const
 
std::unique_ptr< SparseMatrix< Number > > matrix_B
A second system matrix for generalized eigenvalue problems.
 
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
 
virtual SimpleRange< element_iterator > element_ptr_range()=0
 
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.
 
This is the MeshBase class.
 
void libmesh_ignore(const Args &...)
 
static std::unique_ptr< FEGenericBase > build(const unsigned int dim, const FEType &type)
Builds a specific finite element type.
 
unsigned int add_variable(const std::string &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.
 
virtual void init()
Initialize all the systems.
 
This class extends EigenSystem to allow a simple way of solving (standard or generalized) eigenvalue ...
 
double pow(double a, int b)
 
const FEType & variable_type(const unsigned int c) const
 
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
 
ConstFunction that simply returns 0.
 
void initialize_condensed_dofs(const std::set< dof_id_type > &global_condensed_dofs_set=std::set< dof_id_type >())
Loop over the dofs on each processor to initialize the list of non-condensed dofs.
 
void print_info(std::ostream &os=libMesh::out) const
Prints information about the equation systems, by default to libMesh::out.
 
This is the EquationSystems class.
 
T & set(const std::string &)
 
virtual void write_equation_systems(const std::string &, const EquationSystems &, const std::set< std::string > *system_names=nullptr)
This method implements writing a mesh with data to a specified file where the data is taken from the ...
 
int main(int argc, char **argv)
 
void constrain_element_matrix(DenseMatrix< Number > &matrix, std::vector< dof_id_type > &elem_dofs, bool asymmetric_constraint_rows=true) const
Constrains the element matrix.
 
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.
 
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
 
Manages consistently variables, degrees of freedom, and coefficient vectors for eigenvalue problems.
 
This class handles the numbering of degrees of freedom on a mesh.
 
void print_info(std::ostream &os=libMesh::out) const
Prints relevant information about the mesh.
 
This class allows one to associate Dirichlet boundary values with a given set of mesh boundary ids an...
 
const DofMap & get_dof_map() const
 
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
 
void add_side(const dof_id_type elem, const unsigned short int side, const boundary_id_type id)
Add side side of element number elem with boundary id id to the boundary information data structure.
 
Parameters parameters
Data structure holding arbitrary parameters.