7 #ifndef GEN_EIGS_COMPLEX_SHIFT_SOLVER_H 8 #define GEN_EIGS_COMPLEX_SHIFT_SOLVER_H 37 template <
typename Scalar = double,
39 typename OpType = DenseGenComplexShiftSolve<double> >
77 SimpleRandom<Scalar>
rng(0);
78 const Scalar shiftr = rng.random() * m_sigmar + rng.random();
83 Vector v_real(this->
m_n), v_imag(this->
m_n), OPv_real(this->
m_n), OPv_imag(this->
m_n);
85 for (Index
i = 0;
i < this->
m_nev;
i++)
89 this->
m_op->perform_op(v_real.data(), OPv_real.data());
90 this->
m_op->perform_op(v_imag.data(), OPv_imag.
data());
94 const Complex root_part1 = m_sigmar +
Scalar(0.5) / nu;
95 const Complex root_part2 =
Scalar(0.5) *
sqrt(
Scalar(1) -
Scalar(4) * m_sigmai * m_sigmai * (nu * nu)) / nu;
96 const Complex root1 = root_part1 + root_part2;
97 const Complex root2 = root_part1 - root_part2;
101 for (
int k = 0; k < this->
m_n; k++)
103 const Complex rhs1 =
Complex(v_real[k], v_imag[k]) / (root1 - shift);
104 const Complex rhs2 =
Complex(v_real[k], v_imag[k]) / (root2 - shift);
105 const Complex OPv =
Complex(OPv_real[k], OPv_imag[k]);
106 err1 += norm(OPv - rhs1);
107 err2 += norm(OPv - rhs2);
110 const Complex lambdaj = (err1 < err2) ? root1 : root2;
149 m_sigmar(sigmar), m_sigmai(sigmai)
151 this->
m_op->set_shift(m_sigmar, m_sigmai);
157 #endif // GEN_EIGS_COMPLEX_SHIFT_SOLVER_H Eigen::Matrix< Complex, Eigen::Dynamic, 1 > ComplexVector
std::complex< Scalar > Complex
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar * data() const
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > Vector
const Matrix & matrix_V() const
AnnoyingScalar conj(const AnnoyingScalar &x)
GenEigsComplexShiftSolver(OpType *op, Index nev, Index ncv, const Scalar &sigmar, const Scalar &sigmai)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
virtual void sort_ritzpair(int sort_rule)
EIGEN_DEVICE_FUNC const ImagReturnType imag() const
Jet< T, N > sqrt(const Jet< T, N > &f)
void sort_ritzpair(int sort_rule)