DFT-FE 1.3.0-pre
Density Functional Theory With Finite-Elements
Loading...
Searching...
No Matches
poissonSolverProblemDevice.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#if defined(DFTFE_WITH_DEVICE)
19# ifndef poissonSolverProblemDevice_H_
20# define poissonSolverProblemDevice_H_
21
23# include <constraintMatrixInfo.h>
24# include <constants.h>
25# include <dftUtils.h>
26# include <headers.h>
27# include "FEBasisOperations.h"
28# include "BLASWrapper.h"
29
30namespace dftfe
31{
32 /**
33 * @brief poisson solver problem device class template. template parameter FEOrderElectro
34 * is the finite element polynomial order. The class should not be used with
35 * FLOATING NUCLEAR CHARGES = false or POINT WISE DIRICHLET CONSTRAINT = true
36 *
37 * @author Gourab Panigrahi
38 */
39 template <dftfe::uInt FEOrderElectro>
40 class poissonSolverProblemDevice : public linearSolverProblemDevice
41 {
42 public:
43 /// Constructor
44 poissonSolverProblemDevice(const MPI_Comm &mpi_comm);
45
46 /**
47 * @brief clears all datamembers and reset to original state.
48 *
49 *
50 */
51 void
52 clear();
53
54 /**
55 * @brief reinitialize data structures for total electrostatic potential solve.
56 *
57 * For Hartree electrostatic potential solve give an empty map to the atoms
58 * parameter.
59 *
60 */
61 void
62 reinit(
63 const std::shared_ptr<
64 dftfe::basis::
65 FEBasisOperations<double, double, dftfe::utils::MemorySpace::HOST>>
66 &basisOperationsPtr,
67 distributedCPUVec<double> &x,
68 const dealii::AffineConstraints<double> &constraintMatrix,
69 const dftfe::uInt matrixFreeVectorComponent,
70 const dftfe::uInt matrixFreeQuadratureComponentRhsDensity,
71 const dftfe::uInt matrixFreeQuadratureComponentAX,
72 const std::map<dealii::types::global_dof_index, double> &atoms,
73 const std::map<dealii::CellId, std::vector<double>> &smearedChargeValues,
74 const dftfe::uInt smearedChargeQuadratureId,
75 const dftfe::utils::MemoryStorage<double, dftfe::utils::MemorySpace::HOST>
76 &rhoValues,
77 const std::shared_ptr<
78 dftfe::linearAlgebra::BLASWrapper<dftfe::utils::MemorySpace::DEVICE>>
79 BLASWrapperPtr,
80 const bool isComputeDiagonalA = true,
81 const bool isComputeMeanValueConstraints = false,
82 const bool smearedNuclearCharges = false,
83 const bool isRhoValues = true,
84 const bool isGradSmearedChargeRhs = false,
85 const dftfe::uInt smearedChargeGradientComponentId = 0,
86 const bool storeSmearedChargeRhs = false,
87 const bool reuseSmearedChargeRhs = false,
88 const bool reinitializeFastConstraints = false);
89
90 /**
91 * @brief Compute A matrix multipled by x.
92 *
93 */
94 void
95 computeAX(distributedDeviceVec<double> &Ax,
96 distributedDeviceVec<double> &x);
97
98 /**
99 * @brief Compute right hand side vector for the problem Ax = rhs.
100 *
101 * @param rhs vector for the right hand side values
102 */
103 void
104 computeRhs(distributedCPUVec<double> &rhs);
105
106 /**
107 * @brief get the reference to x field
108 *
109 * @return reference to x field. Assumes x field data structure is already initialized
110 */
111 distributedDeviceVec<double> &
112 getX();
113
114 /**
115 * @brief get the reference to Preconditioner
116 *
117 * @return reference to Preconditioner
118 */
119 distributedDeviceVec<double> &
120 getPreconditioner();
121
122 /**
123 * @brief Copies x from Device to Host
124 *
125 */
126 void
127 copyXfromDeviceToHost();
128
129 /**
130 * @brief distribute x to the constrained nodes.
131 *
132 */
133 void
134 distributeX();
135
136
137 void
138 setX();
139
140
141 private:
142 /**
143 * @brief Sets up the matrixfree shapefunction, gradient, jacobian and map for matrixfree computeAX
144 *
145 */
146 void
147 setupMatrixFree();
148
149 /**
150 * @brief Sets up the constraints matrix
151 *
152 */
153 void
154 setupConstraints();
155
156 /**
157 * @brief Compute the diagonal of A.
158 *
159 */
160 void
161 computeDiagonalA();
162
163 /**
164 * @brief Compute mean value constraint which is required in case of fully periodic
165 * boundary conditions.
166 *
167 */
168 void
169 computeMeanValueConstraint();
170
171 /**
172 * @brief Mean value constraint distibute
173 *
174 */
175 void
176 meanValueConstraintDistribute(distributedDeviceVec<double> &vec) const;
177
178 /**
179 * @brief Mean value constraint distibute slave to master
180 *
181 */
182 void
183 meanValueConstraintDistributeSlaveToMaster(
184 distributedDeviceVec<double> &vec) const;
185
186 void
187 meanValueConstraintDistributeSlaveToMaster(
188 distributedCPUVec<double> &vec) const;
189
190 /**
191 * @brief Mean value constraint set zero
192 *
193 */
194 void
195 meanValueConstraintSetZero(distributedDeviceVec<double> &vec) const;
196
197 void
198 meanValueConstraintSetZero(distributedCPUVec<double> &vec) const;
199
200 /// storage for diagonal of the A matrix
201 distributedCPUVec<double> d_diagonalA;
202 distributedDeviceVec<double> d_diagonalAdevice;
203
204 /// storage for smeared charge rhs in case of total potential solve (doesn't
205 /// change every scf)
206 distributedCPUVec<double> d_rhsSmearedCharge;
207
208 /// pointer to dealii MatrixFree object
209 const dealii::MatrixFree<3, double> *d_matrixFreeDataPtr;
210
211 /// pointer to the x vector being solved for
212 distributedCPUVec<double> *d_xPtr;
213 distributedDeviceVec<double> d_xDevice;
214
215 // number of cells local to each mpi task, number of degrees of freedom
216 // locally owned and total degrees of freedom including ghost
217 dftfe::Int d_nLocalCells, d_xLocalDof, d_xLen;
218
219 // shape function value, gradient, jacobian and map for matrixfree
220 dftfe::utils::MemoryStorage<double, dftfe::utils::MemorySpace::DEVICE>
221 d_shapeFunction, d_jacobianFactor;
222 dftfe::utils::MemoryStorage<dftfe::Int, dftfe::utils::MemorySpace::DEVICE>
223 d_map;
224
225 // Pointers to shape function value, gradient, jacobian and map for
226 // matrixfree
227 double *d_shapeFunctionPtr;
228 double *d_jacobianFactorPtr;
229 dftfe::Int *d_mapPtr;
230
231
232 // constraints
233 dftUtils::constraintMatrixInfo<dftfe::utils::MemorySpace::DEVICE>
234 d_constraintsTotalPotentialInfo,
235 d_inhomogenousConstraintsTotalPotentialInfo;
236
237 /// pointer to dealii dealii::AffineConstraints<double> object
238 const dealii::AffineConstraints<double> *d_constraintMatrixPtr;
239
240 /// matrix free index required to access the DofHandler and
241 /// dealii::AffineConstraints<double> objects corresponding to the problem
242 dftfe::uInt d_matrixFreeVectorComponent;
243
244 /// matrix free quadrature index
245 dftfe::uInt d_matrixFreeQuadratureComponentRhsDensity;
246
247 /// matrix free quadrature index
248 dftfe::uInt d_matrixFreeQuadratureComponentAX;
249
250 /// pointer to electron density cell quadrature data
251 const dftfe::utils::MemoryStorage<double, dftfe::utils::MemorySpace::HOST>
252 *d_rhoValuesPtr;
253
254 /// pointer to smeared charge cell quadrature data
255 const std::map<dealii::CellId, std::vector<double>>
256 *d_smearedChargeValuesPtr;
257
258 ///
259 dftfe::uInt d_smearedChargeQuadratureId;
260
261 /// pointer to map between global dof index in current processor and the
262 /// atomic charge on that dof
263 const std::map<dealii::types::global_dof_index, double> *d_atomsPtr;
264
265 /// shape function gradient integral storage
266 std::vector<double> d_cellShapeFunctionGradientIntegralFlattened;
267
268 /// storage for mean value constraint vector
269 distributedCPUVec<double> d_meanValueConstraintVec;
270
271 /// storage for mean value constraint device vector
272 distributedDeviceVec<double> d_meanValueConstraintDeviceVec;
273
274 /// boolean flag to query if mean value constraint datastructures are
275 /// precomputed
276 bool d_isMeanValueConstraintComputed;
277
278 ///
279 bool d_isGradSmearedChargeRhs;
280
281 ///
282 bool d_isStoreSmearedChargeRhs;
283
284 ///
285 bool d_isReuseSmearedChargeRhs;
286
287 ///
288 dftfe::uInt d_smearedChargeGradientComponentId;
289
290 /// mean value constraints: mean value constrained node
291 dealii::types::global_dof_index d_meanValueConstraintNodeId;
292
293 /// mean value constrained node local id
294 dealii::types::global_dof_index d_meanValueConstraintNodeIdLocal;
295
296 /// mean value constraints: constrained proc id containing the mean value
297 /// constrained node
298 dftfe::uInt d_meanValueConstraintProcId;
299
300 /// duplicate constraints object with flattened maps for faster access
301 dftUtils::constraintMatrixInfo<dftfe::utils::MemorySpace::HOST>
302 d_constraintsInfo;
303 std::shared_ptr<
304 dftfe::basis::
305 FEBasisOperations<double, double, dftfe::utils::MemorySpace::HOST>>
306 d_basisOperationsPtr;
307 ///
308 std::shared_ptr<
309 dftfe::linearAlgebra::BLASWrapper<dftfe::utils::MemorySpace::DEVICE>>
310 d_BLASWrapperPtr;
311 bool d_isFastConstraintsInitialized;
312 bool d_isHomogenousConstraintsInitialized;
313
314 const MPI_Comm mpi_communicator;
315 const dftfe::uInt n_mpi_processes;
316 const dftfe::uInt this_mpi_process;
317 dealii::ConditionalOStream pcout;
318 };
319
320} // namespace dftfe
321# endif // poissonSolverProblemDevice_H_
322#endif
Definition pseudoPotentialToDftfeConverter.cc:34
std::uint32_t uInt
Definition TypeConfig.h:10
std::int32_t Int
Definition TypeConfig.h:11