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# include "BLASWrapper.h"
32# include "MatrixFreeWrapper.h"
33# include <DeviceAPICalls.h>
34
35namespace dftfe
36{
37 /**
38 * @brief helmholtz solver problem class template. template parameter FEOrderElectro
39 * is the finite element polynomial order for electrostatics
40 *
41 * @author Gourab Panigrahi
42 */
43 template <dftfe::uInt FEOrderElectro>
44 class kerkerSolverProblemDevice : public linearSolverProblemDevice
45 {
46 public:
47 /// Constructor
48 kerkerSolverProblemDevice(const MPI_Comm &mpi_comm_parent,
49 const MPI_Comm &mpi_comm_domain);
50
51
52 /**
53 * @brief initialize the matrix-free data structures
54 *
55 * @param matrixFreeData structure to hold quadrature rule, constraints vector and appropriate dofHandler
56 * @param constraintMatrix to hold constraints in the given problem
57 * @param x vector to be initialized using matrix-free object
58 *
59 */
60 void
61 init(std::shared_ptr<
62 dftfe::basis::
63 FEBasisOperations<double, double, dftfe::utils::MemorySpace::HOST>>
64 &basisOperationsPtr,
65 dealii::AffineConstraints<double> &constraintMatrix,
66 distributedCPUVec<double> &x,
67 double kerkerMixingParameter,
68 const dftfe::uInt matrixFreeVectorComponent,
69 const dftfe::uInt matrixFreeQuadratureComponent,
70 const dftfe::uInt matrixFreeAxQuadratureComponent);
71
72
73 /**
74 * @brief reinitialize data structures .
75 *
76 * @param x vector to store initial guess and solution
77 * @param gradResidualValues stores the gradient of difference of input electron-density and output electron-density
78 * @param kerkerMixingParameter used in Kerker mixing scheme which usually represents Thomas Fermi wavevector (k_{TF}**2).
79 *
80 */
81 void
82 reinit(
83 distributedCPUVec<double> &x,
84 const dftfe::utils::MemoryStorage<double, dftfe::utils::MemorySpace::HOST>
85 &quadPointValues);
86
87
88 /**
89 * @brief get the reference to x field
90 *
91 * @return reference to x field. Assumes x field data structure is already initialized
92 */
93 distributedDeviceVec<double> &
94 getX();
95
96
97 /**
98 * @brief get the reference to Preconditioner
99 *
100 * @return reference to Preconditioner
101 */
102 distributedDeviceVec<double> &
103 getPreconditioner();
104
105
106 /**
107 * @brief Compute A matrix multipled by x.
108 *
109 */
110 void
111 computeAX(distributedDeviceVec<double> &Ax,
112 distributedDeviceVec<double> &x);
113
114
115 void
116 setX();
117
118
119 /**
120 * @brief Compute right hand side vector for the problem Ax = rhs.
121 *
122 * @param rhs vector for the right hand side values
123 */
124 void
125 computeRhs(distributedCPUVec<double> &rhs);
126
127
128 /**
129 * @brief distribute x to the constrained nodes.
130 *
131 */
132 void
133 distributeX();
134
135
136 /**
137 * @brief Copies x from Device to Host
138 *
139 */
140 void
141 copyXfromDeviceToHost();
142
143 private:
144 /**
145 * @brief Sets up the matrixfree shapefunction, gradient, jacobian and map for matrixfree computeAX
146 *
147 */
148 void
149 setupMatrixFree();
150
151 /**
152 * @brief Sets up the constraints matrix
153 *
154 */
155 void
156 setupConstraints();
157
158 /**
159 * @brief Compute the diagonal of A.
160 *
161 */
162 void
163 computeDiagonalA();
164
165
166 /// storage for diagonal of the A matrix
167 distributedCPUVec<double> d_diagonalA;
168 distributedDeviceVec<double> d_diagonalAdevice;
169
170 /// pointer to the x vector being solved for
171 distributedCPUVec<double> *d_xPtr;
172
173 /// Device x vector being solved for
174 distributedDeviceVec<double> d_xDevice;
175
176 // number of cells local to each mpi task, number of degrees of freedom
177 // locally owned and total degrees of freedom including ghost
178 dftfe::Int d_nLocalCells, d_xLocalDof, d_xLen;
179
180 // kerker mixing constant
181 double d_gamma;
182
183 // Matrix free wrapper object
184 std::unique_ptr<
185 dftfe::MatrixFreeWrapperClass<double,
188 false>>
189 d_matrixFreeWrapperDevice;
190
191 // constraints
192 dftUtils::constraintMatrixInfo<dftfe::utils::MemorySpace::DEVICE>
193 d_constraintsTotalPotentialInfo;
194
195 /// matrix free index required to access the DofHandler and
196 /// dealii::AffineConstraints<double> objects corresponding to the problem
197 dftfe::uInt d_matrixFreeVectorComponent;
198
199 /// matrix free quadrature index
200 dftfe::uInt d_matrixFreeQuadratureComponent;
201 dftfe::uInt d_matrixFreeAxQuadratureComponent;
202
203 /// pointer to electron density cell and grad residual data
204 const dftfe::utils::MemoryStorage<double, dftfe::utils::MemorySpace::HOST>
205 *d_residualQuadValuesPtr;
206 const dealii::DoFHandler<3> *d_dofHandlerPRefinedPtr;
207 const dealii::AffineConstraints<double> *d_constraintMatrixPRefinedPtr;
208 const dealii::MatrixFree<3, double> *d_matrixFreeDataPRefinedPtr;
209 std::shared_ptr<
210 dftfe::basis::
211 FEBasisOperations<double, double, dftfe::utils::MemorySpace::HOST>>
212 d_basisOperationsPtr;
213
214 const MPI_Comm d_mpiCommParent;
215 const MPI_Comm mpi_communicator;
216 const dftfe::uInt n_mpi_processes;
217 const dftfe::uInt this_mpi_process;
218 dealii::ConditionalOStream pcout;
219 };
220
221} // namespace dftfe
222# endif // kerkerSolverProblemDevice_H_
223#endif
@ DEVICE
Definition MemorySpaceType.h:36
Definition pseudoPotentialToDftfeConverter.cc:34
std::uint32_t uInt
Definition TypeConfig.h:10
@ Helmholtz
Definition MatrixFreeDevice.h:39
std::int32_t Int
Definition TypeConfig.h:11