DFT-FE 1.1.0-pre
Density Functional Theory With Finite-Elements
Loading...
Searching...
No Matches
linearSolverCGDevice.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
19#if defined(DFTFE_WITH_DEVICE)
20# ifndef linearSolverCGDevice_H_
21# define linearSolverCGDevice_H_
22
23# include <linearSolverDevice.h>
25# include <MemoryStorage.h>
26# include <BLASWrapper.h>
27namespace dftfe
28{
29 /**
30 * @brief conjugate gradient device linear solver class wrapper
31 *
32 * @author Gourab Panigrahi
33 */
34 class linearSolverCGDevice : public linearSolverDevice
35 {
36 public:
37 enum solverType
38 {
39 CG = 0,
40 GMRES
41 };
42
43 /**
44 * @brief Constructor
45 *
46 * @param mpi_comm_parent parent mpi communicato
47 * @param mpi_comm_domain domain mpi communicator
48 * @param type enum specifying the choice of the linear solver
49 */
50 linearSolverCGDevice(
51 const MPI_Comm & mpi_comm_parent,
52 const MPI_Comm & mpi_comm_domain,
53 const solverType type,
54 const std::shared_ptr<
55 dftfe::linearAlgebra::BLASWrapper<dftfe::utils::MemorySpace::DEVICE>>
56 BLASWrapperPtr);
57
58 /**
59 * @brief Solve linear system, A*x=Rhs
60 *
61 * @param problem linearSolverProblemDevice object (functor) to compute Rhs and A*x, and preconditioning
62 * @param relTolerance Tolerance (relative) required for convergence.
63 * @param maxNumberIterations Maximum number of iterations.
64 * @param debugLevel Debug output level:
65 * 0 - no debug output
66 * 1 - limited debug output
67 * 2 - all debug output.
68 */
69 void
70 solve(linearSolverProblemDevice &problem,
71 const double absTolerance,
72 const unsigned int maxNumberIterations,
73 const int debugLevel = 0,
74 bool distributeFlag = true);
75
76 private:
77 /// enum denoting the choice of the linear solver
78 const solverType d_type;
79
80 /// define some temporary vectors
81 distributedDeviceVec<double> d_qvec, d_rvec, d_dvec;
82
83 int d_xLocalDof;
84 double *d_devSumPtr;
85 dftfe::utils::MemoryStorage<double, dftfe::utils::MemorySpace::DEVICE>
86 d_devSum;
87
88 const MPI_Comm d_mpiCommParent;
89 const MPI_Comm mpi_communicator;
90 const unsigned int n_mpi_processes;
91 const unsigned int this_mpi_process;
92 dealii::ConditionalOStream pcout;
93 std::shared_ptr<
94 dftfe::linearAlgebra::BLASWrapper<dftfe::utils::MemorySpace::DEVICE>>
95 d_BLASWrapperPtr;
96
97 /**
98 * @brief Combines precondition and dot product
99 *
100 */
101 double
102 applyPreconditionAndComputeDotProduct(const double *jacobi);
103
104 /**
105 * @brief Combines precondition, sadd and dot product
106 *
107 */
108 double
109 applyPreconditionComputeDotProductAndSadd(const double *jacobi);
110
111 /**
112 * @brief Combines scaling and norm
113 *
114 */
115 double
116 scaleXRandComputeNorm(double *x, const double &alpha);
117 };
118
119} // namespace dftfe
120# endif // linearSolverCGDevice_H_
121#endif
Definition pseudoPotentialToDftfeConverter.cc:34