13#ifndef dealii_lac_utilities_h
14#define dealii_lac_utilities_h
61 template <
typename NumberType>
62 std::array<NumberType, 3>
91 template <
typename NumberType>
92 std::array<NumberType, 3>
118 template <
typename OperatorType,
typename VectorType>
121 const VectorType &
v0,
122 const unsigned int k,
162 template <
typename OperatorType,
typename VectorType>
165 const OperatorType &H,
166 const unsigned int n,
167 const std::pair<double, double> unwanted_spectrum,
182 namespace UtilitiesImplementation
189 template <
typename Number>
206 template <
typename NumberType>
207 std::array<std::complex<NumberType>, 3>
209 const std::complex<NumberType> & )
212 std::array<NumberType, 3> res;
218 template <
typename NumberType>
219 std::array<NumberType, 3>
223 const NumberType tau = g / f;
226 "real-valued Hyperbolic rotation does not exist for (" +
227 std::to_string(f) +
"," + std::to_string(g) +
")"));
229 std::copysign(
std::sqrt((1. - tau) * (1. + tau)),
231 std::array<NumberType, 3> csr;
233 csr[1] = csr[0] * tau;
240 template <
typename NumberType>
241 std::array<std::complex<NumberType>, 3>
243 const std::complex<NumberType> & )
246 std::array<NumberType, 3> res;
252 template <
typename NumberType>
253 std::array<NumberType, 3>
256 std::array<NumberType, 3> res;
270 if (g == NumberType())
272 res[0] = std::copysign(1., f);
273 res[1] = NumberType();
276 else if (f == NumberType())
278 res[0] = NumberType();
279 res[1] = std::copysign(1., g);
284 const NumberType tau = g / f;
285 const NumberType u = std::copysign(
std::sqrt(1. + tau * tau), f);
287 res[1] = res[0] * tau;
292 const NumberType tau = f / g;
293 const NumberType u = std::copysign(
std::sqrt(1. + tau * tau), g);
295 res[0] = res[1] * tau;
304 template <
typename OperatorType,
typename VectorType>
307 const VectorType &v0_,
308 const unsigned int k,
325 std::vector<double> subdiagonal;
329 double a = v->l2_norm();
340 for (
unsigned int i = 1; i < k; ++i)
343 const double b = f->l2_norm();
357 subdiagonal.push_back(b);
366 std::vector<double> Z;
368 std::vector<double> work;
392 return diagonal[k - 1] + f->l2_norm();
396 template <
typename OperatorType,
typename VectorType>
399 const OperatorType &op,
400 const unsigned int degree,
401 const std::pair<double, double> unwanted_spectrum,
405 const double a = unwanted_spectrum.first;
406 const double b = unwanted_spectrum.second;
413 "Lower bound of the unwanted spectrum should be smaller than the upper bound."));
415 Assert(a_L <= a || a_L >= b || !scale,
417 "Scaling point should be outside of the unwanted spectrum."));
443 const double e = (
b - a) / 2.;
444 const double c = (a +
b) / 2.;
445 const double alpha = 1. /
e;
446 const double beta = -c /
e;
448 const double sigma1 =
450 double sigma =
scale ? sigma1 : 1.;
451 const double tau = 2. / sigma;
453 y.sadd(alpha * sigma, beta * sigma, x);
455 for (
unsigned int i = 2; i <= degree; ++i)
457 const double sigma_new =
scale ? 1. / (tau - sigma) : 1.;
459 yn.sadd(2. * alpha * sigma_new, 2. * beta * sigma_new, y);
460 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.
Tpetra::Vector< Number, LO, GO, NodeType< MemorySpace > > VectorType
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)