DFT-FE 1.1.0-pre
Density Functional Theory With Finite-Elements
Loading...
Searching...
No Matches
linearAlgebraOperations.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (c) 2017-2025 The Regents of the University of Michigan and DFT-FE
4// authors.
5//
6// This file is part of the DFT-FE code.
7//
8// The DFT-FE code is free software; you can use it, redistribute
9// it, and/or modify it under the terms of the GNU Lesser General
10// Public License as published by the Free Software Foundation; either
11// version 2.1 of the License, or (at your option) any later version.
12// The full text of the license can be found in the file LICENSE at
13// the top level of the DFT-FE distribution.
14//
15// ---------------------------------------------------------------------
16
17
18#ifndef linearAlgebraOperations_h
19#define linearAlgebraOperations_h
20
21#include <elpaScalaManager.h>
22#include <headers.h>
23#include <operator.h>
24#include "process_grid.h"
25#include "scalapackWrapper.h"
26#include "dftParameters.h"
27#include <BLASWrapper.h>
28namespace dftfe
29{
30 //
31 // extern declarations for blas-lapack routines
32 //
33#ifndef DOXYGEN_SHOULD_SKIP_THIS
34 extern "C"
35 {
36 void
37 dgemv_(const char * TRANS,
38 const unsigned int *M,
39 const unsigned int *N,
40 const double * alpha,
41 const double * A,
42 const unsigned int *LDA,
43 const double * X,
44 const unsigned int *INCX,
45 const double * beta,
46 double * C,
47 const unsigned int *INCY);
48
49 void
50 sgemv_(const char * TRANS,
51 const unsigned int *M,
52 const unsigned int *N,
53 const float * alpha,
54 const float * A,
55 const unsigned int *LDA,
56 const float * X,
57 const unsigned int *INCX,
58 const float * beta,
59 float * C,
60 const unsigned int *INCY);
61
62 void
63 zgemv_(const char * TRANS,
64 const unsigned int * M,
65 const unsigned int * N,
66 const std::complex<double> *alpha,
67 const std::complex<double> *A,
68 const unsigned int * LDA,
69 const std::complex<double> *X,
70 const unsigned int * INCX,
71 const std::complex<double> *beta,
72 std::complex<double> * C,
73 const unsigned int * INCY);
74
75 void
76 cgemv_(const char * TRANS,
77 const unsigned int * M,
78 const unsigned int * N,
79 const std::complex<float> *alpha,
80 const std::complex<float> *A,
81 const unsigned int * LDA,
82 const std::complex<float> *X,
83 const unsigned int * INCX,
84 const std::complex<float> *beta,
85 std::complex<float> * C,
86 const unsigned int * INCY);
87 void
88 dsymv_(const char * UPLO,
89 const unsigned int *N,
90 const double * alpha,
91 const double * A,
92 const unsigned int *LDA,
93 const double * X,
94 const unsigned int *INCX,
95 const double * beta,
96 double * C,
97 const unsigned int *INCY);
98 void
99 dgesv_(int * n,
100 int * nrhs,
101 double *a,
102 int * lda,
103 int * ipiv,
104 double *b,
105 int * ldb,
106 int * info);
107 void
108 dsysv_(const char *UPLO,
109 const int * n,
110 const int * nrhs,
111 double * a,
112 const int * lda,
113 int * ipiv,
114 double * b,
115 const int * ldb,
116 double * work,
117 const int * lwork,
118 int * info);
119 void
120 dscal_(const unsigned int *n,
121 const double * alpha,
122 double * x,
123 const unsigned int *inc);
124 void
125 sscal_(const unsigned int *n,
126 const float * alpha,
127 float * x,
128 const unsigned int *inc);
129 void
130 zscal_(const unsigned int * n,
131 const std::complex<double> *alpha,
132 std::complex<double> * x,
133 const unsigned int * inc);
134 void
135 zdscal_(const unsigned int * n,
136 const double * alpha,
137 std::complex<double> *x,
138 const unsigned int * inc);
139 void
140 daxpy_(const unsigned int *n,
141 const double * alpha,
142 const double * x,
143 const unsigned int *incx,
144 double * y,
145 const unsigned int *incy);
146 void
147 saxpy_(const unsigned int *n,
148 const float * alpha,
149 const float * x,
150 const unsigned int *incx,
151 float * y,
152 const unsigned int *incy);
153 void
154 dgemm_(const char * transA,
155 const char * transB,
156 const unsigned int *m,
157 const unsigned int *n,
158 const unsigned int *k,
159 const double * alpha,
160 const double * A,
161 const unsigned int *lda,
162 const double * B,
163 const unsigned int *ldb,
164 const double * beta,
165 double * C,
166 const unsigned int *ldc);
167 void
168 sgemm_(const char * transA,
169 const char * transB,
170 const unsigned int *m,
171 const unsigned int *n,
172 const unsigned int *k,
173 const float * alpha,
174 const float * A,
175 const unsigned int *lda,
176 const float * B,
177 const unsigned int *ldb,
178 const float * beta,
179 float * C,
180 const unsigned int *ldc);
181 void
182 dsyevd_(const char * jobz,
183 const char * uplo,
184 const unsigned int *n,
185 double * A,
186 const unsigned int *lda,
187 double * w,
188 double * work,
189 const unsigned int *lwork,
190 int * iwork,
191 const unsigned int *liwork,
192 int * info);
193 void
194 dsygvx_(const int * itype,
195 const char * jobz,
196 const char * range,
197 const char * uplo,
198 const int * n,
199 double * a,
200 const int * lda,
201 double * b,
202 const int * ldb,
203 const double *vl,
204 const double *vu,
205 const int * il,
206 const int * iu,
207 const double *abstol,
208 int * m,
209 double * w,
210 double * z,
211 const int * ldz,
212 double * work,
213 const int * lwork,
214 int * iwork,
215 int * ifail,
216 int * info);
217 void
218 dsyevx_(const char * jobz,
219 const char * range,
220 const char * uplo,
221 const int * n,
222 double * a,
223 const int * lda,
224 const double *vl,
225 const double *vu,
226 const int * il,
227 const int * iu,
228 const double *abstol,
229 int * m,
230 double * w,
231 double * z,
232 const int * ldz,
233 double * work,
234 const int * lwork,
235 int * iwork,
236 int * ifail,
237 int * info);
238 double
239 dlamch_(const char *cmach);
240 void
241 dsyevr_(const char * jobz,
242 const char * range,
243 const char * uplo,
244 const unsigned int *n,
245 double * A,
246 const unsigned int *lda,
247 const double * vl,
248 const double * vu,
249 const unsigned int *il,
250 const unsigned int *iu,
251 const double * abstol,
252 const unsigned int *m,
253 double * w,
254 double * Z,
255 const unsigned int *ldz,
256 unsigned int * isuppz,
257 double * work,
258 const int * lwork,
259 int * iwork,
260 const int * liwork,
261 int * info);
262 void
263 dsyrk_(const char * uplo,
264 const char * trans,
265 const unsigned int *n,
266 const unsigned int *k,
267 const double * alpha,
268 const double * A,
269 const unsigned int *lda,
270 const double * beta,
271 double * C,
272 const unsigned int *ldc);
273 void
274 dsyr_(const char * uplo,
275 const unsigned int *n,
276 const double * alpha,
277 const double * X,
278 const unsigned int *incx,
279 double * A,
280 const unsigned int *lda);
281 void
282 dsyr2_(const char * uplo,
283 const unsigned int *n,
284 const double * alpha,
285 const double * x,
286 const unsigned int *incx,
287 const double * y,
288 const unsigned int *incy,
289 double * a,
290 const unsigned int *lda);
291 void
292 dcopy_(const unsigned int *n,
293 const double * x,
294 const unsigned int *incx,
295 double * y,
296 const unsigned int *incy);
297 void
298 scopy_(const unsigned int *n,
299 const float * x,
300 const unsigned int *incx,
301 float * y,
302 const unsigned int *incy);
303 void
304 zgemm_(const char * transA,
305 const char * transB,
306 const unsigned int * m,
307 const unsigned int * n,
308 const unsigned int * k,
309 const std::complex<double> *alpha,
310 const std::complex<double> *A,
311 const unsigned int * lda,
312 const std::complex<double> *B,
313 const unsigned int * ldb,
314 const std::complex<double> *beta,
315 std::complex<double> * C,
316 const unsigned int * ldc);
317 void
318 cgemm_(const char * transA,
319 const char * transB,
320 const unsigned int * m,
321 const unsigned int * n,
322 const unsigned int * k,
323 const std::complex<float> *alpha,
324 const std::complex<float> *A,
325 const unsigned int * lda,
326 const std::complex<float> *B,
327 const unsigned int * ldb,
328 const std::complex<float> *beta,
329 std::complex<float> * C,
330 const unsigned int * ldc);
331 void
332 zheevd_(const char * jobz,
333 const char * uplo,
334 const unsigned int * n,
335 std::complex<double> *A,
336 const unsigned int * lda,
337 double * w,
338 std::complex<double> *work,
339 const unsigned int * lwork,
340 double * rwork,
341 const unsigned int * lrwork,
342 int * iwork,
343 const unsigned int * liwork,
344 int * info);
345 void
346 zheevr_(const char * jobz,
347 const char * range,
348 const char * uplo,
349 const unsigned int * n,
350 std::complex<double> *A,
351 const unsigned int * lda,
352 const double * vl,
353 const double * vu,
354 const unsigned int * il,
355 const unsigned int * iu,
356 const double * abstol,
357 const unsigned int * m,
358 double * w,
359 std::complex<double> *Z,
360 const unsigned int * ldz,
361 unsigned int * isuppz,
362 std::complex<double> *work,
363 const int * lwork,
364 double * rwork,
365 const int * lrwork,
366 int * iwork,
367 const int * liwork,
368 int * info);
369 void
370 zherk_(const char * uplo,
371 const char * trans,
372 const unsigned int * n,
373 const unsigned int * k,
374 const double * alpha,
375 const std::complex<double> *A,
376 const unsigned int * lda,
377 const double * beta,
378 std::complex<double> * C,
379 const unsigned int * ldc);
380 void
381 zcopy_(const unsigned int * n,
382 const std::complex<double> *x,
383 const unsigned int * incx,
384 std::complex<double> * y,
385 const unsigned int * incy);
386
387 void
388 ccopy_(const unsigned int * n,
389 const std::complex<float> *x,
390 const unsigned int * incx,
391 std::complex<float> * y,
392 const unsigned int * incy);
393
394 std::complex<double>
395 zdotc_(const unsigned int * N,
396 const std::complex<double> *X,
397 const unsigned int * INCX,
398 const std::complex<double> *Y,
399 const unsigned int * INCY);
400 double
401 ddot_(const unsigned int *N,
402 const double * X,
403 const unsigned int *INCX,
404 const double * Y,
405 const unsigned int *INCY);
406
407 double
408 dnrm2_(const unsigned int *n, const double *x, const unsigned int *incx);
409
410 double
411 dznrm2_(const unsigned int * n,
412 const std::complex<double> *x,
413 const unsigned int * incx);
414 void
415 zaxpy_(const unsigned int * n,
416 const std::complex<double> *alpha,
417 const std::complex<double> *x,
418 const unsigned int * incx,
419 std::complex<double> * y,
420 const unsigned int * incy);
421 void
422 caxpy_(const unsigned int * n,
423 const std::complex<float> *alpha,
424 const std::complex<float> *x,
425 const unsigned int * incx,
426 std::complex<float> * y,
427 const unsigned int * incy);
428 void
429 dpotrf_(const char * uplo,
430 const unsigned int *n,
431 double * a,
432 const unsigned int *lda,
433 int * info);
434 void
435 dpotri_(const char * uplo,
436 const unsigned int *n,
437 double * A,
438 const unsigned int *lda,
439 int * info);
440
441 void
442 zpotrf_(const char * uplo,
443 const unsigned int * n,
444 std::complex<double> *a,
445 const unsigned int * lda,
446 int * info);
447 void
448 dtrtri_(const char * uplo,
449 const char * diag,
450 const unsigned int *n,
451 double * a,
452 const unsigned int *lda,
453 int * info);
454 void
455 ztrtri_(const char * uplo,
456 const char * diag,
457 const unsigned int * n,
458 std::complex<double> *a,
459 const unsigned int * lda,
460 int * info);
461
462 // LU decomoposition of a general matrix
463 void
464 dgetrf_(int *M, int *N, double *A, int *lda, int *IPIV, int *INFO);
465
466 // generate inverse of a matrix given its LU decomposition
467 void
468 dgetri_(int * N,
469 double *A,
470 int * lda,
471 int * IPIV,
472 double *WORK,
473 int * lwork,
474 int * INFO);
475 // LU decomoposition of a general matrix
476 void
477 zgetrf_(int * M,
478 int * N,
479 std::complex<double> *A,
480 int * lda,
481 int * IPIV,
482 int * INFO);
483
484 // generate inverse of a matrix given its LU decomposition
485 void
486 zgetri_(int * N,
487 std::complex<double> *A,
488 int * lda,
489 int * IPIV,
490 std::complex<double> *WORK,
491 int * lwork,
492 int * INFO);
493 }
494#endif
495
496 /**
497 * @brief Contains linear algebra functions used in the implementation of an eigen solver
498 *
499 * @author Phani Motamarri, Sambit Das
500 */
502 {
503 /** @brief Compute inverse of serial matrix using LAPACK LU factorization
504 */
505 void
506 inverse(double *A, int N);
507
508 /** @brief Compute inverse of serial matrix using LAPACK LU factorization
509 */
510 void
511 inverse(std::complex<double> *A, int N);
512
513
514 /** @brief Calculates an estimate of lower and upper bounds of a matrix using
515 * k-step Generalised Lanczos method. Algo is present in PAW PRB paper
516 *
517 * @param operatorMatrix An object which has access to the given matrix
518 * @param vect A dummy vector
519 * @return std::pair<double,double> An estimate of the lower and upper bound of the given matrix
520 */
521 template <typename T, dftfe::utils::MemorySpace memorySpace>
522 std::pair<double, double>
525 & BLASWrapperPtr,
526 operatorDFTClass<memorySpace> & operatorMatrix,
531 const dftParameters & dftParams);
532
533
534
535 /** @brief Apply Chebyshev filter to a given subspace
536 *
537 * @param[in] operatorMatrix An object which has access to the given matrix
538 * @param[in,out] X Given subspace as a dealii array representing multiple
539 * fields as a flattened array. In-place update of the given subspace.
540 * @param[in] numberComponents Number of multiple-fields
541 * @param[in] m Chebyshev polynomial degree
542 * @param[in] a lower bound of unwanted spectrum
543 * @param[in] b upper bound of unwanted spectrum
544 * @param[in] a0 lower bound of wanted spectrum
545 */
546 template <typename T, dftfe::utils::MemorySpace memorySpace>
547 void
551 const unsigned int m,
552 const double a,
553 const double b,
554 const double a0);
555
556 /** @brief Apply Residual based Chebyshev filter to a given subspace
557 *
558 * @param[in] operatorMatrix An object which has access to the given matrix
559 * @param[in,out] X Given subspace as a dealii array representing multiple
560 * fields as a flattened array. In-place update of the given subspace.
561 * @param[in] eigenvalues estimate of eigenvalues, usually the eigenvalues
562 * from previous pass
563 * @param[in] m Chebyshev polynomial degree
564 * @param[in] a lower bound of unwanted spectrum
565 * @param[in] b upper bound of unwanted spectrum
566 * @param[in] a0 lower bound of wanted spectrum
567 * @param[in] approxOverlapMatrix to use approximate overlap matrix while
568 * computing initial residual
569 */
570
571 template <typename T1, typename T2, dftfe::utils::MemorySpace memorySpace>
572 void
575 & BLASWrapperPtr,
576 operatorDFTClass<memorySpace> & operatorMatrix,
581 std::vector<double> eigenvalues,
582 const unsigned int m,
583 const double a,
584 const double b,
585 const double a0,
586 const bool approxOverlapMatrix);
587
588
589 } // namespace linearAlgebraOperations
590
591} // namespace dftfe
592#endif
Namespace which declares the input parameters and the functions to parse them from the input paramete...
Definition dftParameters.h:35
Definition BLASWrapper.h:35
An class template to encapsulate a MultiVector. A MultiVector is a collection of vectors belonging t...
Definition MultiVector.h:127
Base class for building the DFT operator and the action of operator on a vector.
Definition operator.h:43
void dgesv_(int *N, int *NRHS, double *A, int *LDA, int *IPIV, double *B, int *LDB, int *INFO)
Contains linear algebra functions used in the implementation of an eigen solver.
Definition linearAlgebraOperations.h:502
void reformulatedChebyshevFilter(const std::shared_ptr< dftfe::linearAlgebra::BLASWrapper< memorySpace > > &BLASWrapperPtr, operatorDFTClass< memorySpace > &operatorMatrix, dftfe::linearAlgebra::MultiVector< T1, memorySpace > &X, dftfe::linearAlgebra::MultiVector< T1, memorySpace > &Y, dftfe::linearAlgebra::MultiVector< T2, memorySpace > &Residual, dftfe::linearAlgebra::MultiVector< T2, memorySpace > &ResidualNew, std::vector< double > eigenvalues, const unsigned int m, const double a, const double b, const double a0, const bool approxOverlapMatrix)
Apply Residual based Chebyshev filter to a given subspace.
void chebyshevFilter(operatorDFTClass< memorySpace > &operatorMatrix, dftfe::linearAlgebra::MultiVector< T, memorySpace > &X, dftfe::linearAlgebra::MultiVector< T, memorySpace > &Y, const unsigned int m, const double a, const double b, const double a0)
Apply Chebyshev filter to a given subspace.
void inverse(double *A, int N)
Compute inverse of serial matrix using LAPACK LU factorization.
std::pair< double, double > generalisedLanczosLowerUpperBoundEigenSpectrum(const std::shared_ptr< dftfe::linearAlgebra::BLASWrapper< memorySpace > > &BLASWrapperPtr, operatorDFTClass< memorySpace > &operatorMatrix, dftfe::linearAlgebra::MultiVector< T, memorySpace > &X, dftfe::linearAlgebra::MultiVector< T, memorySpace > &Y, dftfe::linearAlgebra::MultiVector< T, memorySpace > &Z, dftfe::linearAlgebra::MultiVector< T, memorySpace > &tempVec, const dftParameters &dftParams)
Calculates an estimate of lower and upper bounds of a matrix using k-step Generalised Lanczos method....
Definition pseudoPotentialToDftfeConverter.cc:34
@ Residual
Definition hubbardClass.h:59
@ LDA
Definition ExcSSDFunctionalBaseClass.h:29