DFT-FE 1.3.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 <dftfe::uInt 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 dftfe::uInt matrixFreeVectorComponent,
68 const dftfe::uInt matrixFreeQuadratureComponent,
69 const dftfe::uInt matrixFreeAxQuadratureComponent);
70
71
72 /**
73 * @brief reinitialize data structures .
74 *
75 * @param x vector to store initial guess and solution
76 * @param gradResidualValues stores the gradient of difference of input electron-density and output electron-density
77 * @param kerkerMixingParameter used in Kerker mixing scheme which usually represents Thomas Fermi wavevector (k_{TF}**2).
78 *
79 */
80 void
81 reinit(
82 distributedCPUVec<double> &x,
83 const dftfe::utils::MemoryStorage<double, dftfe::utils::MemorySpace::HOST>
84 &quadPointValues);
85
86
87 /**
88 * @brief get the reference to x field
89 *
90 * @return reference to x field. Assumes x field data structure is already initialized
91 */
92 distributedDeviceVec<double> &
93 getX();
94
95
96 /**
97 * @brief get the reference to Preconditioner
98 *
99 * @return reference to Preconditioner
100 */
101 distributedDeviceVec<double> &
102 getPreconditioner();
103
104
105 /**
106 * @brief Compute A matrix multipled by x.
107 *
108 */
109 void
110 computeAX(distributedDeviceVec<double> &Ax,
111 distributedDeviceVec<double> &x);
112
113
114 void
115 setX();
116
117
118 /**
119 * @brief Compute right hand side vector for the problem Ax = rhs.
120 *
121 * @param rhs vector for the right hand side values
122 */
123 void
124 computeRhs(distributedCPUVec<double> &rhs);
125
126
127 /**
128 * @brief distribute x to the constrained nodes.
129 *
130 */
131 void
132 distributeX();
133
134
135 /**
136 * @brief Copies x from Device to Host
137 *
138 */
139 void
140 copyXfromDeviceToHost();
141
142 private:
143 /**
144 * @brief Sets up the matrixfree shapefunction, gradient, jacobian and map for matrixfree computeAX
145 *
146 */
147 void
148 setupMatrixFree();
149
150 /**
151 * @brief Sets up the constraints matrix
152 *
153 */
154 void
155 setupConstraints();
156
157 /**
158 * @brief Compute the diagonal of A.
159 *
160 */
161 void
162 computeDiagonalA();
163
164
165 /// storage for diagonal of the A matrix
166 distributedCPUVec<double> d_diagonalA;
167 distributedDeviceVec<double> d_diagonalAdevice;
168
169 /// pointer to the x vector being solved for
170 distributedCPUVec<double> *d_xPtr;
171
172 /// Device x vector being solved for
173 distributedDeviceVec<double> d_xDevice;
174
175 // number of cells local to each mpi task, number of degrees of freedom
176 // locally owned and total degrees of freedom including ghost
177 dftfe::Int d_nLocalCells, d_xLocalDof, d_xLen;
178
179 // kerker mixing constant
180 double d_gamma;
181
182 // shape function value, gradient, jacobian and map for matrixfree
183 dftfe::utils::MemoryStorage<double, dftfe::utils::MemorySpace::DEVICE>
184 d_shapeFunction, d_jacobianFactor;
185 dftfe::utils::MemoryStorage<dftfe::Int, dftfe::utils::MemorySpace::DEVICE>
186 d_map;
187
188 // Pointers to shape function value, gradient, jacobian and map for
189 // matrixfree
190 double *d_shapeFunctionPtr;
191 double *d_jacobianFactorPtr;
192 dftfe::Int *d_mapPtr;
193
194 // constraints
195 dftUtils::constraintMatrixInfo<dftfe::utils::MemorySpace::DEVICE>
196 d_constraintsTotalPotentialInfo;
197
198 /// matrix free index required to access the DofHandler and
199 /// dealii::AffineConstraints<double> objects corresponding to the problem
200 dftfe::uInt d_matrixFreeVectorComponent;
201
202 /// matrix free quadrature index
203 dftfe::uInt d_matrixFreeQuadratureComponent;
204 dftfe::uInt d_matrixFreeAxQuadratureComponent;
205
206
207 /// pointer to electron density cell and grad residual data
208 const dftfe::utils::MemoryStorage<double, dftfe::utils::MemorySpace::HOST>
209 *d_residualQuadValuesPtr;
210 const dealii::DoFHandler<3> *d_dofHandlerPRefinedPtr;
211 const dealii::AffineConstraints<double> *d_constraintMatrixPRefinedPtr;
212 const dealii::MatrixFree<3, double> *d_matrixFreeDataPRefinedPtr;
213 std::shared_ptr<
214 dftfe::basis::
215 FEBasisOperations<double, double, dftfe::utils::MemorySpace::DEVICE>>
216 d_basisOperationsPtr;
217
218
219
220 const MPI_Comm d_mpiCommParent;
221 const MPI_Comm mpi_communicator;
222 const dftfe::uInt n_mpi_processes;
223 const dftfe::uInt this_mpi_process;
224 dealii::ConditionalOStream pcout;
225 };
226
227} // namespace dftfe
228# endif // kerkerSolverProblemDevice_H_
229#endif
Definition pseudoPotentialToDftfeConverter.cc:34
std::uint32_t uInt
Definition TypeConfig.h:10
std::int32_t Int
Definition TypeConfig.h:11