91{
92
94
95
96#ifndef LIBMESH_HAVE_EXODUS_API
97 libmesh_example_requires(false, "--enable-exodus");
98#endif
99
100
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!"
105 << std::endl;
106
107 return 0;
108#else
109
110#ifdef LIBMESH_DEFAULT_SINGLE_PRECISION
111
112 libmesh_example_requires(false, "--disable-singleprecision");
113#endif
114
115#if defined(LIBMESH_USE_COMPLEX_NUMBERS) && SLEPC_VERSION_LESS_THAN(3,6,2)
116
117
118 libmesh_example_requires(false, "--disable-complex or use SLEPc>=3.6.2");
119#endif
120
121
122#ifndef LIBMESH_ENABLE_DIRICHLET
123 libmesh_example_requires(false, "--enable-dirichlet");
124#endif
125
126
127 {
129
130 for (int i=1; i<argc; i++)
132
134 }
135
136
137 libmesh_example_requires(2 <= LIBMESH_DIM, "2D support");
138
139
140 GetPot command_line (argc, argv);
141
142
143 const std::string mesh_name =
145
146
147
148 const unsigned int plotting_index =
150
151
152 const unsigned int n_evals =
154
155
156 std::ostringstream mesh_name_exodus;
157 mesh_name_exodus << mesh_name << "_mesh.e";
158
159
160
162
164
165
166
167
168 for (
const auto & elem :
mesh.element_ptr_range())
169 for (auto side : elem->side_index_range())
170 if (elem->neighbor_ptr (side) == nullptr)
171 mesh.get_boundary_info().add_side(elem, side, BOUNDARY_ID);
172
174
175
177
178
180
181
182
185
186
187
188
190
191
192
194
195
196
197 equation_systems.parameters.set<unsigned int>("eigenpairs") = n_evals;
198 equation_systems.parameters.set<unsigned int>("basis vectors") = n_evals*3;
199
200
201 equation_systems.parameters.set<
Real>(
"linear solver tolerance") =
pow(
TOLERANCE, 5./3.);
202 equation_systems.parameters.set<unsigned int>
203 ("linear solver maximum iterations") = 1000;
204
205
206
208
209
211
212 {
214
215#ifdef LIBMESH_ENABLE_DIRICHLET
216
217
220
222#endif
223 }
224
225
226 equation_systems.init();
227
228
229 equation_systems.print_info();
230
232
233
234 eigen_system.
solve();
235
236
238
240 << nconv
241 << "\n"
242 << std::endl;
243
244 if (plotting_index > n_evals)
245 {
246 libMesh::out <<
"WARNING: Solver did not converge for the requested eigenvector!" << std::endl;
247 }
248
249
250 std::ostringstream eigenvalue_output_name;
251 eigenvalue_output_name << mesh_name << "_evals.txt";
252 std::ofstream evals_file(eigenvalue_output_name.str().c_str());
253
254 for (unsigned int i=0; i<nconv; i++)
255 {
257
258
259 libmesh_assert_less (eval.second,
TOLERANCE);
260 evals_file << eval.first << std::endl;
261
262
263 if (i == plotting_index)
264 {
265#ifdef LIBMESH_HAVE_EXODUS_API
266
267 std::ostringstream eigenvector_output_name;
268 eigenvector_output_name << mesh_name << "_evec.e";
270#endif
271 }
272 }
273
274 evals_file.close();
275
276#endif
277
278
279 return 0;
280}
void regenerate_id_sets()
Clears and regenerates the cached sets of ids.
This class extends EigenSystem to allow a simple way of solving (standard or generalized) eigenvalue ...
virtual void solve() override
Override to solve the condensed eigenproblem with the dofs in local_non_condensed_dofs_vector strippe...
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.
virtual std::pair< Real, Real > get_eigenpair(dof_id_type i) override
Override get_eigenpair() to retrieve the eigenpair for the condensed eigensolve.
This class allows one to associate Dirichlet boundary values with a given set of mesh boundary ids an...
void add_dirichlet_boundary(const DirichletBoundary &dirichlet_boundary)
Adds a copy of the specified Dirichlet boundary to the system.
void set_eigenproblem_type(EigenProblemType ept)
Sets the type of the current eigen problem.
unsigned int get_n_converged() const
const EigenSolver< Number > & get_eigen_solver() const
This is the EquationSystems class.
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.
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
const BoundaryInfo & get_boundary_info() const
The information about boundary ids on the mesh.
virtual void read(const std::string &name, void *mesh_data=nullptr, bool skip_renumber_nodes_and_elements=false, bool skip_find_neighbors=false, bool skip_detect_interior_parents=false)=0
Interfaces for reading/writing a mesh to/from a file.
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.
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.
ConstFunction that simply returns 0.
void assemble_matrices(EquationSystems &es, const std::string &system_name)
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
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