-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoperator.h
337 lines (278 loc) · 11.6 KB
/
operator.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
//
// -------------------------------------------------------------------------------------
//
// Copyright (c) 2017-2022 The Regents of the University of Michigan and DFT-FE
// authors.
//
// This file is part of the DFT-FE code.
//
// The DFT-FE code is free software; you can use it, redistribute
// it, and/or modify it under the terms of the GNU Lesser General
// Public License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// The full text of the license can be found in the file LICENSE at
// the top level of the DFT-FE distribution.
//
// --------------------------------------------------------------------------------------
//
// @author Phani Motamarri
//
#ifndef operatorDFTClass_h
#define operatorDFTClass_h
#include "constraintMatrixInfo.h"
#include "headers.h"
#include "process_grid.h"
#include "scalapackWrapper.h"
#include "elpaScalaManager.h"
#include <vector>
namespace dftfe
{
/**
* @brief Base class for building the DFT operator and the action of operator on a vector
*
* @author Phani Motamarri, Sambit Das
*/
class operatorDFTClass
{
//
// methods
//
public:
/**
* @brief Destructor.
*/
virtual ~operatorDFTClass() = 0;
/**
* @brief initialize operatorClass
*
*/
virtual void
init() = 0;
/**
* @brief initializes parallel layouts and index maps for HX, XtHX and creates a flattened array format for X
*
* @param wavefunBlockSize number of wavefunction vector (block size of X).
* @param flag controls the creation of flattened array format and index maps or only index maps
*
* @return X format to store a multi-vector array
* in a flattened format with all the wavefunction values corresponding to a
* given node being stored contiguously
*
*/
virtual void
reinit(const unsigned int wavefunBlockSize,
distributedCPUVec<dataTypes::number> &X,
bool flag) = 0;
virtual void
reinit(const unsigned int wavefunBlockSize) = 0;
virtual void
reinitkPointSpinIndex(const unsigned int kPointIndex,
const unsigned int spinIndex) = 0;
virtual void
initCellWaveFunctionMatrix(
const unsigned int numberWaveFunctions,
distributedCPUVec<dataTypes::number> &X,
std::vector<dataTypes::number> & cellWaveFunctionMatrix) = 0;
virtual void
fillGlobalArrayFromCellWaveFunctionMatrix(
const unsigned int wavefunBlockSize,
const std::vector<dataTypes::number> &cellWaveFunctionMatrix,
distributedCPUVec<dataTypes::number> &X) = 0;
virtual void
initWithScalar(const unsigned int numberWaveFunctions,
double scalarValue,
std::vector<dataTypes::number> &cellWaveFunctionMatrix) = 0;
virtual void
axpby(double scalarA,
double scalarB,
const unsigned int numberWaveFunctions,
const std::vector<dataTypes::number> &cellXWaveFunctionMatrix,
std::vector<dataTypes::number> & cellYWaveFunctionMatrix) = 0;
virtual void
getInteriorSurfaceNodesMapFromGlobalArray(
std::vector<unsigned int> &globalArrayClassificationMap) = 0;
/**
* @brief compute diagonal mass matrix
*
* @param dofHandler dofHandler associated with the current mesh
* @param constraintMatrix constraints to be used
* @param sqrtMassVec output the value of square root of diagonal mass matrix
* @param invSqrtMassVec output the value of inverse square root of diagonal mass matrix
*/
virtual void
computeMassVector(const dealii::DoFHandler<3> & dofHandler,
const dealii::AffineConstraints<double> &constraintMatrix,
distributedCPUVec<double> & sqrtMassVec,
distributedCPUVec<double> &invSqrtMassVec) = 0;
/**
* @brief Compute operator times multi-field vectors
*
* @param X Vector containing multi-wavefunction fields (though X does not
* change inside the function it is scaled and rescaled back to
* avoid duplication of memory and hence is not const)
* @param numberComponents number of wavefunctions associated with a given node
* @param Y Vector containing multi-component fields after operator times vectors product
*/
virtual void
HX(distributedCPUVec<dataTypes::number> &X,
const unsigned int numberComponents,
const bool scaleFlag,
const double scalar,
distributedCPUVec<dataTypes::number> &Y,
const bool onlyHPrimePartForFirstOrderDensityMatResponse = false) = 0;
virtual void
HX(distributedCPUVec<dataTypes::number> &src,
std::vector<dataTypes::number> & cellSrcWaveFunctionMatrix,
const unsigned int numberWaveFunctions,
const bool scaleFlag,
const double scalar,
const double scalarA,
const double scalarB,
distributedCPUVec<dataTypes::number> &dst,
std::vector<dataTypes::number> & cellDstWaveFunctionMatrix) = 0;
virtual void
computeNonLocalProjectorKetTimesXTimesV(
distributedCPUVec<dataTypes::number> &src,
distributedCPUVec<dataTypes::number> &projectorKetTimesVectorFlattened,
const unsigned int numberWaveFunctions) = 0;
/**
* @brief Compute projection of the operator into a subspace spanned by a given orthogonal basis HProjConj=X^{T}*HConj*XConj
*
* @param X Vector of Vectors containing multi-wavefunction fields
* @param numberComponents number of wavefunctions associated with a given node
* @param ProjMatrix projected small matrix
*/
virtual void
XtHX(const std::vector<dataTypes::number> &X,
const unsigned int numberComponents,
std::vector<dataTypes::number> & ProjHam) = 0;
/**
* @brief Compute projection of the operator into a subspace spanned by a given orthogonal basis HProjConj=X^{T}*HConj*XConj
*
* @param X Vector of Vectors containing multi-wavefunction fields
* @param numberComponents number of wavefunctions associated with a given node
* @param processGrid two-dimensional processor grid corresponding to the parallel projHamPar
* @param projHamPar parallel ScaLAPACKMatrix which stores the computed projection
* of the operation into the given subspace
*/
virtual void
XtHX(const std::vector<dataTypes::number> & X,
const unsigned int numberComponents,
const std::shared_ptr<const dftfe::ProcessGrid> &processGrid,
dftfe::ScaLAPACKMatrix<dataTypes::number> & projHamPar,
const bool onlyHPrimePartForFirstOrderDensityMatResponse = false) = 0;
/**
* @brief Compute projection of the operator into a subspace spanned by a given orthogonal basis HProjConj=X^{T}*HConj*XConj
*
* @param X Vector of Vectors containing multi-wavefunction fields
* @param totalNumberComponents number of wavefunctions associated with a given node
* @param singlePrecComponents number of wavecfuntions starting from the first for
* which the project Hamiltionian block will be computed in single
* procession. However the cross blocks will still be computed in double
* precision.
* @param processGrid two-dimensional processor grid corresponding to the parallel projHamPar
* @param projHamPar parallel ScaLAPACKMatrix which stores the computed projection
* of the operation into the given subspace
*/
virtual void
XtHXMixedPrec(
const std::vector<dataTypes::number> & X,
const unsigned int totalNumberComponents,
const unsigned int singlePrecComponents,
const std::shared_ptr<const dftfe::ProcessGrid> &processGrid,
dftfe::ScaLAPACKMatrix<dataTypes::number> & projHamPar,
const bool onlyHPrimePartForFirstOrderDensityMatResponse = false) = 0;
void
setInvSqrtMassVector(distributedCPUVec<double> &X);
distributedCPUVec<double> &
getInvSqrtMassVector();
/**
* @brief Get constraint matrix eigen
*
* @return pointer to constraint matrix eigen
*/
dftUtils::constraintMatrixInfo *
getOverloadedConstraintMatrix() const;
/**
* @brief Get matrix free data
*
* @return pointer to matrix free data
*/
const dealii::MatrixFree<3, double> *
getMatrixFreeData() const;
/**
* @brief Get relevant mpi communicator
*
* @return mpi communicator
*/
const MPI_Comm &
getMPICommunicator() const;
/**
* @brief Get index map of flattened array to cell based numbering
*
* @return pointer to constraint matrix eigen
*/
virtual const std::vector<dealii::types::global_dof_index> &
getFlattenedArrayCellLocalProcIndexIdMap() const = 0;
virtual distributedCPUVec<dataTypes::number> &
getParallelProjectorKetTimesBlockVector() = 0;
virtual const std::vector<double> &
getShapeFunctionValuesDensityGaussQuad() const = 0;
virtual const std::vector<double> &
getShapeFunctionGradValuesDensityGaussQuad() const = 0;
virtual const std::vector<double> &
getShapeFunctionValuesDensityGaussLobattoQuad() const = 0;
virtual const std::vector<double> &
getShapeFunctionValuesDensityTransposed() const = 0;
virtual const std::vector<double> &
getShapeFunctionValuesNLPTransposed() const = 0;
virtual const std::vector<double> &
getShapeFunctionGradientValuesNLPTransposed() const = 0;
virtual const std::vector<double> &
getInverseJacobiansNLP() const = 0;
protected:
/**
* @brief default Constructor.
*/
operatorDFTClass();
/**
* @brief Constructor.
*/
operatorDFTClass(const MPI_Comm & mpi_comm_replica,
const dealii::MatrixFree<3, double> &matrix_free_data,
dftUtils::constraintMatrixInfo & constraintMatrixNone);
protected:
//
// Get overloaded constraint matrix object constructed using 1-component FE
// object
//
dftUtils::constraintMatrixInfo *d_constraintMatrixData;
//
// matrix-free data
//
const dealii::MatrixFree<3, double> *d_matrix_free_data;
//
// inv sqrt mass vector
//
distributedCPUVec<double> d_invSqrtMassVector;
/// index map
std::vector<dealii::types::global_dof_index>
d_FullflattenedArrayCellLocalProcIndexIdMap;
/// density quad rule shape function data for FEOrder mesh with node index
/// being the fastest index
std::vector<double> d_densityGaussQuadShapeFunctionValues;
std::vector<double> d_densityGaussQuadShapeFunctionGradientValues;
/// FEOrderRhoNodal+1 Gauss Lobotto quadrature shape function data for
/// FEOrder mesh with node index being the fastest index
std::vector<double> d_densityGlQuadShapeFunctionValues;
std::vector<double> d_shapeFunctionValueDensityTransposed;
std::vector<double> d_shapeFunctionValueNLPTransposed;
std::vector<double> d_shapeFunctionGradientValueNLPTransposed;
std::vector<double> d_inverseJacobiansNLP;
//
// mpi communicator
//
MPI_Comm d_mpi_communicator;
};
} // namespace dftfe
#endif