DFT-FE 1.1.0-pre
Density Functional Theory With Finite-Elements
Loading...
Searching...
No Matches
kerkerSolverProblemDevice.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (c) 2019-2020 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
20#if defined(DFTFE_WITH_DEVICE)
21
22# ifndef kerkerSolverProblemDevice_H_
23# define kerkerSolverProblemDevice_H_
24
26# include <triangulationManager.h>
27# include <constraintMatrixInfo.h>
28# include <MemoryStorage.h>
29# include <dftUtils.h>
30# include <FEBasisOperations.h>
31
32
33namespace dftfe
34{
35 /**
36 * @brief helmholtz solver problem class template. template parameter FEOrderElectro
37 * is the finite element polynomial order for electrostatics
38 *
39 * @author Gourab Panigrahi
40 */
41 template <unsigned int FEOrderElectro>
42 class kerkerSolverProblemDevice : public linearSolverProblemDevice
43 {
44 public:
45 /// Constructor
46 kerkerSolverProblemDevice(const MPI_Comm &mpi_comm_parent,
47 const MPI_Comm &mpi_comm_domain);
48
49
50 /**
51 * @brief initialize the matrix-free data structures
52 *
53 * @param matrixFreeData structure to hold quadrature rule, constraints vector and appropriate dofHandler
54 * @param constraintMatrix to hold constraints in the given problem
55 * @param x vector to be initialized using matrix-free object
56 *
57 */
58 void
59 init(
60 std::shared_ptr<
61 dftfe::basis::
62 FEBasisOperations<double, double, dftfe::utils::MemorySpace::DEVICE>>
63 & basisOperationsPtr,
64 dealii::AffineConstraints<double> &constraintMatrix,
65 distributedCPUVec<double> & x,
66 double kerkerMixingParameter,
67 const unsigned int matrixFreeVectorComponent,
68 const unsigned int matrixFreeQuadratureComponent);
69
70
71 /**
72 * @brief reinitialize data structures .
73 *
74 * @param x vector to store initial guess and solution
75 * @param gradResidualValues stores the gradient of difference of input electron-density and output electron-density
76 * @param kerkerMixingParameter used in Kerker mixing scheme which usually represents Thomas Fermi wavevector (k_{TF}**2).
77 *
78 */
79 void
80 reinit(
81 distributedCPUVec<double> &x,
82 const dftfe::utils::MemoryStorage<double, dftfe::utils::MemorySpace::HOST>
83 &quadPointValues);
84
85
86 /**
87 * @brief get the reference to x field
88 *
89 * @return reference to x field. Assumes x field data structure is already initialized
90 */
91 distributedDeviceVec<double> &
92 getX();
93
94
95 /**
96 * @brief get the reference to Preconditioner
97 *
98 * @return reference to Preconditioner
99 */
100 distributedDeviceVec<double> &
101 getPreconditioner();
102
103
104 /**
105 * @brief Compute A matrix multipled by x.
106 *
107 */
108 void
109 computeAX(distributedDeviceVec<double> &Ax,
110 distributedDeviceVec<double> &x);
111
112
113 void
114 setX();
115
116
117 /**
118 * @brief Compute right hand side vector for the problem Ax = rhs.
119 *
120 * @param rhs vector for the right hand side values
121 */
122 void
123 computeRhs(distributedCPUVec<double> &rhs);
124
125
126 /**
127 * @brief distribute x to the constrained nodes.
128 *
129 */
130 void
131 distributeX();
132
133
134 /**
135 * @brief Copies x from Device to Host
136 *
137 */
138 void
139 copyXfromDeviceToHost();
140
141
142 /// function needed by dealii to mimic SparseMatrix for Jacobi
143 /// preconditioning
144 void
145 subscribe(std::atomic<bool> *const validity,
146 const std::string & identifier = "") const {};
147
148
149 /// function needed by dealii to mimic SparseMatrix for Jacobi
150 /// preconditioning
151 void
152 unsubscribe(std::atomic<bool> *const validity,
153 const std::string & identifier = "") const {};
154
155
156 /// function needed by dealii to mimic SparseMatrix
157 bool
158 operator!=(double val) const
159 {
160 return true;
161 };
162
163
164 private:
165 /**
166 * @brief Sets up the matrixfree shapefunction, gradient, jacobian and map for matrixfree computeAX
167 *
168 */
169 void
170 setupMatrixFree();
171
172 /**
173 * @brief Sets up the constraints matrix
174 *
175 */
176 void
177 setupConstraints();
178
179 /**
180 * @brief Compute the diagonal of A.
181 *
182 */
183 void
184 computeDiagonalA();
185
186
187 /// storage for diagonal of the A matrix
188 distributedCPUVec<double> d_diagonalA;
189 distributedDeviceVec<double> d_diagonalAdevice;
190
191 /// pointer to the x vector being solved for
192 distributedCPUVec<double> *d_xPtr;
193
194 /// Device x vector being solved for
195 distributedDeviceVec<double> d_xDevice;
196
197 // number of cells local to each mpi task, number of degrees of freedom
198 // locally owned and total degrees of freedom including ghost
199 int d_nLocalCells, d_xLocalDof, d_xLen;
200
201 // kerker mixing constant
202 double d_gamma;
203
204 // shape function value, gradient, jacobian and map for matrixfree
205 dftfe::utils::MemoryStorage<double, dftfe::utils::MemorySpace::DEVICE>
206 d_shapeFunction, d_jacobianFactor;
207 dftfe::utils::MemoryStorage<int, dftfe::utils::MemorySpace::DEVICE> d_map;
208
209 // Pointers to shape function value, gradient, jacobian and map for
210 // matrixfree
211 double *d_shapeFunctionPtr;
212 double *d_jacobianFactorPtr;
213 int * d_mapPtr;
214
215 // constraints
216 dftUtils::constraintMatrixInfo<dftfe::utils::MemorySpace::DEVICE>
217 d_constraintsTotalPotentialInfo;
218
219 /// matrix free index required to access the DofHandler and
220 /// dealii::AffineConstraints<double> objects corresponding to the problem
221 unsigned int d_matrixFreeVectorComponent;
222
223 /// matrix free quadrature index
224 unsigned int d_matrixFreeQuadratureComponent;
225
226
227 /// pointer to electron density cell and grad residual data
228 const dftfe::utils::MemoryStorage<double, dftfe::utils::MemorySpace::HOST>
229 * d_residualQuadValuesPtr;
230 const dealii::DoFHandler<3> * d_dofHandlerPRefinedPtr;
231 const dealii::AffineConstraints<double> *d_constraintMatrixPRefinedPtr;
232 const dealii::MatrixFree<3, double> * d_matrixFreeDataPRefinedPtr;
233 std::shared_ptr<
234 dftfe::basis::
235 FEBasisOperations<double, double, dftfe::utils::MemorySpace::DEVICE>>
236 d_basisOperationsPtr;
237
238
239
240 const MPI_Comm d_mpiCommParent;
241 const MPI_Comm mpi_communicator;
242 const unsigned int n_mpi_processes;
243 const unsigned int this_mpi_process;
244 dealii::ConditionalOStream pcout;
245 };
246
247} // namespace dftfe
248# endif // kerkerSolverProblemDevice_H_
249#endif
Definition pseudoPotentialToDftfeConverter.cc:34