www.mooseframework.org
Eigenvalues.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "Eigenvalues.h"
11 
12 // MOOSE includes
13 #include "NonlinearEigenSystem.h"
14 
15 #include "libmesh/libmesh_config.h"
16 
17 #include <complex>
18 
19 registerMooseObject("MooseApp", Eigenvalues);
20 
23 {
25  params.addClassDescription("Returns the Eigen values from the nonlinear Eigen system.");
26  params.addParam<bool>("inverse_eigenvalue", false, "True to evaluate the inverse of eigenvalues");
27  return params;
28 }
29 
31  : GeneralVectorPostprocessor(parameters),
32  _inverse(getParam<bool>("inverse_eigenvalue")),
33  _eigen_values_real(declareVector("eigen_values_real")),
34  _eigen_values_imag(declareVector("eigen_values_imag")),
35  _nl_eigen(dynamic_cast<const NonlinearEigenSystem *>(&_sys))
36 {
37  if (!_nl_eigen)
38  mooseError("Given system is not a NonlinearEigenSystem \n");
39 }
40 
41 void
43 {
44  _eigen_values_real.clear();
45  _eigen_values_imag.clear();
46 }
47 
48 void
50 {
51 #ifdef LIBMESH_HAVE_SLEPC
52  const std::vector<std::pair<Real, Real>> & eigenvalues = _nl_eigen->getAllConvergedEigenvalues();
53  unsigned int n_converged_eigenvalues = eigenvalues.size();
54  _eigen_values_real.resize(n_converged_eigenvalues);
55  _eigen_values_imag.resize(n_converged_eigenvalues);
56  for (unsigned int n = 0; n < n_converged_eigenvalues; n++)
57  {
58  std::complex<Real> e(eigenvalues[n].first, eigenvalues[n].second);
59  std::complex<Real> inv = _inverse ? 1. / e : e;
60  _eigen_values_real[n] = inv.real();
61  _eigen_values_imag[n] = inv.imag();
62  }
63 #else
64  _eigen_values_real.clear();
65  _eigen_values_imag.clear();
66 #endif
67 }
Nonlinear eigenvalue system to be solved.
const NonlinearEigenSystem *const _nl_eigen
Nonlinear eigen-system to get the eigenvalues from.
Definition: Eigenvalues.h:37
This class is here to combine the VectorPostprocessor interface and the base class VectorPostprocesso...
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
static InputParameters validParams()
Definition: Eigenvalues.C:22
const std::vector< std::pair< Real, Real > > & getAllConvergedEigenvalues() const
Get the number of converged eigenvalues.
const bool _inverse
Whether to report the inverse of the eigenvalues.
Definition: Eigenvalues.h:28
Eigenvalues(const InputParameters &parameters)
Definition: Eigenvalues.C:30
registerMooseObject("MooseApp", Eigenvalues)
static InputParameters validParams()
VectorPostprocessorValue & _eigen_values_real
Real part of the eigenvalues.
Definition: Eigenvalues.h:31
virtual void execute() override
Execute method.
Definition: Eigenvalues.C:49
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
Definition: Eigenvalues.C:42
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
VectorPostprocessorValue & _eigen_values_imag
Imaginary part of the eigenvalues.
Definition: Eigenvalues.h:34