16#ifndef dealii_lac_utilities_h
17#define dealii_lac_utilities_h
64 template <
typename NumberType>
65 std::array<NumberType, 3>
94 template <
typename NumberType>
95 std::array<NumberType, 3>
133 template <
typename OperatorType,
typename VectorType>
136 const VectorType &
v0,
137 const unsigned int k,
188 template <
typename OperatorType,
typename VectorType>
191 const OperatorType & H,
192 const unsigned int n,
193 const std::pair<double, double> unwanted_spectrum,
208 namespace UtilitiesImplementation
215 template <
typename Number>
232 template <
typename NumberType>
233 std::array<std::complex<NumberType>, 3>
235 const std::complex<NumberType> & )
238 std::array<NumberType, 3> res;
244 template <
typename NumberType>
245 std::array<NumberType, 3>
249 const NumberType tau = g / f;
252 "real-valued Hyperbolic rotation does not exist for (" +
253 std::to_string(f) +
"," + std::to_string(g) +
")"));
255 std::copysign(
std::sqrt((1. - tau) * (1. + tau)),
257 std::array<NumberType, 3> csr;
259 csr[1] = csr[0] * tau;
266 template <
typename NumberType>
267 std::array<std::complex<NumberType>, 3>
269 const std::complex<NumberType> & )
272 std::array<NumberType, 3> res;
278 template <
typename NumberType>
279 std::array<NumberType, 3>
282 std::array<NumberType, 3> res;
296 if (g == NumberType())
298 res[0] = std::copysign(1., f);
299 res[1] = NumberType();
302 else if (f == NumberType())
304 res[0] = NumberType();
305 res[1] = std::copysign(1., g);
310 const NumberType tau = g / f;
311 const NumberType u = std::copysign(
std::sqrt(1. + tau * tau), f);
313 res[1] = res[0] * tau;
318 const NumberType tau = f / g;
319 const NumberType u = std::copysign(
std::sqrt(1. + tau * tau), g);
321 res[0] = res[1] * tau;
330 template <
typename OperatorType,
typename VectorType>
333 const VectorType & v0_,
334 const unsigned int k,
351 std::vector<double> subdiagonal;
355 double a = v->l2_norm();
366 for (
unsigned int i = 1; i < k; ++i)
369 const double b = f->l2_norm();
383 subdiagonal.push_back(b);
392 std::vector<double> Z;
394 std::vector<double> work;
418 return diagonal[k - 1] + f->l2_norm();
422 template <
typename OperatorType,
typename VectorType>
425 const OperatorType & op,
426 const unsigned int degree,
427 const std::pair<double, double> unwanted_spectrum,
431 const double a = unwanted_spectrum.first;
432 const double b = unwanted_spectrum.second;
439 "Lower bound of the unwanted spectrum should be smaller than the upper bound."));
441 Assert(a_L <= a || a_L >= b || !scale,
443 "Scaling point should be outside of the unwanted spectrum."));
453 VectorType &y = *p_y;
454 VectorType &yn = *p_yn;
469 const double e = (
b - a) / 2.;
470 const double c = (a +
b) / 2.;
471 const double alpha = 1. /
e;
472 const double beta = -c /
e;
474 const double sigma1 =
476 double sigma =
scale ? sigma1 : 1.;
477 const double tau = 2. / sigma;
479 y.sadd(alpha * sigma, beta * sigma, x);
481 for (
unsigned int i = 2; i <= degree; ++i)
483 const double sigma_new =
scale ? 1. / (tau - sigma) : 1.;
485 yn.sadd(2. * alpha * sigma_new, 2. * beta * sigma_new, y);
486 yn.add(-sigma * sigma_new, x);
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcNotImplemented()
static ::ExceptionBase & ExcErrorCode(std::string arg1, types::blas_int arg2)
#define Assert(cond, exc)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcDivideByZero()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
@ diagonal
Matrix is diagonal.
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
void chebyshev_filter(VectorType &x, const OperatorType &H, const unsigned int n, const std::pair< double, double > unwanted_spectrum, const double tau, VectorMemory< VectorType > &vector_memory)
std::array< NumberType, 3 > givens_rotation(const NumberType &x, const NumberType &y)
std::array< NumberType, 3 > hyperbolic_rotation(const NumberType &x, const NumberType &y)
double lanczos_largest_eigenvalue(const OperatorType &H, const VectorType &v0, const unsigned int k, VectorMemory< VectorType > &vector_memory, std::vector< double > *eigenvalues=nullptr)
void call_stev(const char jobz, const types::blas_int n, Number *d, Number *e, Number *z, const types::blas_int ldz, Number *work, types::blas_int *info)
bool is_finite(const double x)
::VectorizedArray< Number, width > sqrt(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > abs(const ::VectorizedArray< Number, width > &)
std::array< Number, 1 > eigenvalues(const SymmetricTensor< 2, 1, Number > &T)