DFT-FE 1.1.0-pre
Density Functional Theory With Finite-Elements
Loading...
Searching...
No Matches
AtomicCenteredNonLocalOperator.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// @author Kartick Ramakrishnan, Vishal Subramanian, Sambit Das
18//
19
20#ifndef DFTFE_ATOMICCENTEREDNONLOCALOPERATOR_H
21#define DFTFE_ATOMICCENTEREDNONLOCALOPERATOR_H
22#include <MultiVector.h>
23#include <headers.h>
26#include <BLASWrapper.h>
27#include <memory>
28#include <MemorySpaceType.h>
29#include "FEBasisOperations.h"
30#include <headers.h>
31#include <dftUtils.h>
32#include <pseudoUtils.h>
33#include <vectorUtilities.h>
34#include <MPIPatternP2P.h>
35#include <MultiVector.h>
36#include <DeviceTypeConfig.h>
37#include <cmath>
39
40namespace dftfe
41{
42 /**
43 * @brief Enum class that lists
44 * used in the non-local Operator
45 *
46 */
53
54
55
56 template <typename ValueType, dftfe::utils::MemorySpace memorySpace>
58 {
59 public:
62 BLASWrapperPtr,
63 std::shared_ptr<
65 basisOperatorPtr,
66 std::shared_ptr<AtomCenteredSphericalFunctionContainer>
67 atomCenteredSphericalFunctionContainer,
68 const MPI_Comm &mpi_comm_parent,
69 const bool memOptMode = false,
70 const bool computeSphericalFnTimesX = true,
71 const bool useGlobalCMatrix = false);
72
73 /**
74 * @brief Resizes various internal data members and selects the kpoint of interest.
75 * @param[in] kPointIndex specifies the k-point of interest
76 */
77 void
79 /**
80 * @brief initialises the multivector object, waveFunctionBlockSize and resizes various internal data members.
81 * @param[in] waveFunctionBlockSize sets the wavefunction block size for the
82 * action of the nonlocal operator.
83 * @param[out] sphericalFunctionKetTimesVectorParFlattened, the multivector
84 * that is initialised based on blocksize and partitioner.
85 */
86 void
88 dftfe::uInt waveFunctionBlockSize,
90 &sphericalFunctionKetTimesVectorParFlattened);
91 /**
92 * @brief calls internal function: initialisePartitioner, initialiseKpoint and computeCMatrixEntries
93 * @param[in] updateSparsity flag on whether the sparstiy patten was
94 * updated, hence the partitioner is updated.
95 * @param[in] kPointWeights std::vector<double> of size number of kPoints
96 * @param[out] kPointCoordinates std::vector<double> of kPoint coordinates
97 * @param[in] basisOperationsPtr HOST FEBasisOperations shared_ptr required
98 * to indetify the element ids and quad points
99 * @param[in] quadratureIndex quadrature index for sampling the spherical
100 * function. Quadrature Index is used to reinit basisOperationsPtr
101 */
102 void
104 const bool updateSparsity,
105 const std::vector<double> &kPointWeights,
106 const std::vector<double> &kPointCoordinates,
107 std::shared_ptr<
109 double,
111 basisOperationsPtr,
112 std::shared_ptr<
114 BLASWrapperHostPtr,
115 const dftfe::uInt quadratureIndex);
116 /**
117 * @brief calls internal function: initialisePartitioner, initialiseKpoint and computeCMatrixEntries
118 * @param[in] updateSparsity flag on whether the sparstiy patten was
119 * updated, hence the partitioner is updated.
120 * @param[in] kPointWeights std::vector<double> of size number of kPoints
121 * @param[out] kPointCoordinates std::vector<double> of kPoint coordinates
122 * @param[in] basisOperationsPtr HOST FEBasisOperations shared_ptr required
123 * to indetify the element ids and quad points
124 * @param[in] BLASWrapperHostPtr CPU blasWrapperPtr, used for xcopy calls
125 * @param[in] quadratureIndex quadrature index for sampling the spherical
126 * function. Quadrature Index is used to reinit basisOperationsPtr
127 * @param[in] nonLocalOperatorSrc The source nonLocalOpertor from where the
128 * CMatrix and partitioner is copied. Generally, it is of higher precision.
129 */
130 template <typename ValueTypeSrc>
131 void
133 const bool updateSparsity,
134 const std::vector<double> &kPointWeights,
135 const std::vector<double> &kPointCoordinates,
136 std::shared_ptr<
138 double,
140 basisOperationsPtr,
141 std::shared_ptr<
143 BLASWrapperHostPtr,
144 const dftfe::uInt quadratureIndex,
145 const std::shared_ptr<
147 nonLocalOperatorSrc);
148#if defined(DFTFE_WITH_DEVICE)
149 // for device specific initialise
150 /**
151 * @brief
152 * @param[in] totalAtomsInCurrentProcessor number of atoms in current
153 * processor based on compact support
154 * @param[out] totalNonLocalElements number of nonLocal elements in current
155 * processor
156 * @param[out] numberCellsForEachAtom number of cells associated which each
157 * atom in the current processor. vecot of size totalAtomsInCurrentProcessor
158 * @param[out] numberCellsAccumNonLocalAtoms number of cells accumulated
159 * till iatom in current processor. vector of size
160 * totalAtomsInCurrentProcessor
161 */
162 void
163 initialiseCellWaveFunctionPointers(
165 &cellWaveFunctionMatrix);
166
167 void
168 freeDeviceVectors();
169#endif
170
171 // Getter functions
172 // Returns the vector that takes in nonlocalElementIndex and returns the
173 // cellID
174 const std::vector<dftfe::uInt> &
176 // Returns the number of atoms in current processor
179
182
185
188
191
192 bool
194
197 const dftfe::uInt alpha) const;
198
201
202 std::vector<dftfe::uInt> &
204
205 std::vector<dftfe::uInt> &
207
208 std::vector<dftfe::uInt> &
210
211 const std::vector<ValueType> &
213
214 const std::vector<ValueType> &
216
217 const std::map<dftfe::uInt, std::vector<dftfe::uInt>> &
219
220 const std::vector<dftfe::uInt> &
222
223 const std::vector<dftfe::uInt> &
225
226 const dftfe::uInt
228
229
230 const std::vector<dftfe::uInt> &
232
233 /**
234 * @brief Required in configurational forces. Cummulative sphercial Fn Id. The size is numCells in processor
235 */
236 const std::map<dftfe::uInt, std::vector<dftfe::uInt>> &
238
239 /**
240 * @brief Returns the Flattened vector of sphericalFunctionIDs in order of atomIDs of atoms in processor.
241 */
242 const std::vector<dftfe::uInt> &
244
245 const std::vector<dftfe::uInt> &
247 /**
248 * @brief Computes C^{T}D^{-1}C at the global level for atomId. This is required in PAW
249 */
250 void
252 const dftfe::uInt atomId,
253 std::shared_ptr<
255 BLASWrapperPtr,
257 &Dinverse,
259 PconjtransposePmatrix);
260 // Calls for both device and host
261 /**
262 * @brief compute the action of coupling matrix on sphericalFunctionKetTimesVectorParFlattened.
263 * @param[in] couplingtype structure of coupling matrix
264 * @param[in] couplingMatrix entires of the coupling matrix V in
265 * CVCconjtrans. Ensure that the coupling matrix is padded. Refer to
266 * ONCVclass for template
267 * @param[out] sphericalFunctionKetTimesVectorParFlattened multivector to
268 * store results of CconjtransX which is initiliased using
269 * initialiseFlattenedVector call. The results are stored in
270 * sphericalFunctionKetTimesVectorParFlattened or internal data member based
271 * on flagCopyResultsToMatrix.
272 * @param[in] flagCopyResultsToMatrix flag to confirm whether to scal the
273 * multivector sphericalFunctionKetTimesVectorParFlattened or store results
274 * in internal data member.
275 */
276 void
278 const CouplingStructure couplingtype,
281 &sphericalFunctionKetTimesVectorParFlattened,
282 const bool flagCopyResultsToMatrix = true,
283 const dftfe::uInt kPointIndex = 0);
284
285 /**
286 * @brief After AllReduce function is called this will copy to the nonLocalOperatorClassDatastructure.
287 */
288 void
291 &sphericalFunctionKetTimesVectorParFlattened,
293 /**
294 * @brief copies the results from internal member to sphericalFunctionKetTimesVectorParFlattened, on which ghost values are called.
295 * crucial operation for completion of the full CconjtranX on all cells
296 * @param[in] sphericalFunctionKetTimesVectorParFlattened multivector to
297 * store results of CconjtransX which is initiliased using
298 * initialiseFlattenedVector call
299 * @param[in] skip1 flag for compute-communication overlap in ChFSI on GPUs
300 * @param[in] skip2 flag for compute-communication overlap in ChFSI on GPUs
301 */
302 void
305 &sphericalFunctionKetTimesVectorParFlattened,
306 const bool skipComm = false);
307
308 /**
309 * @brief computes the results of CconjtransX on the cells of interst specied by cellRange
310 * @param[in] X input cell level vector
311 * @param[in] cellRange start and end element id in list of nonlocal
312 * elements
313 */
314 void
315 applyCconjtransOnX(const ValueType *X,
316 const std::pair<dftfe::uInt, dftfe::uInt> cellRange);
317
318
319 /**
320 * @brief computes the results of CconjtransX on nodal X vector
321 * @param[in] X input X nodal vector
322 * elements
323 */
324 void
327
328
329 // Returns the pointer of CTX stored in HOST memory for the atom Index in
330 // the list of atoms with support in the processor.
331 /**
332 * @brief Returns the pointer of CTX stored in HOST memory
333 * @param[in] iAtom atomIndex in the list of atoms with support in the
334 * current processor. NOTE!! One must be careful here
335 */
336 const ValueType *
338
339 /**
340 * @brief completes the VCconjX on nodal vector src. The src vector must have all ghost nodes and constraint nodes updated.
341 * @param[in] src input nodal vector on which operator acts on.
342 * @param[in] kPointIndex kPoint of interest for current operation
343 * @param[in] couplingtype structure of coupling matrix
344 * @param[in] couplingMatrix entries of the coupling matrix V in
345 * CVCconjtrans. Ensure the coupling matrix is padded
346 * @param[out] sphericalFunctionKetTimesVectorParFlattened multivector to
347 * store results of CconjtransX which is initiliased using
348 * initialiseFlattenedVector call
349 */
350 void
353 const dftfe::uInt kPointIndex,
354 const CouplingStructure couplingtype,
357 &sphericalFunctionKetTimesVectorParFlattened,
358 const bool flagScaleInternalMatrix = false);
359
360
361 /**
362 * @brief completes the action of CVCconjtranspose on nodal vector src. The src vector must have all ghost nodes and contraint nodes updated.
363 * @param[in] src input nodal vector on which operator acts on.
364 * @param[in] kPointIndex kPoint of interst for current operation
365 * @param[in] couplingtype structure of coupling matrix
366 * @param[in] couplingMatrix entires of the coupling matrix V in
367 * CVCconjtrans
368 * @param[in] sphericalFunctionKetTimesVectorParFlattened multivector to
369 * store results of CconjtransX which is initiliased using
370 * initialiseFlattenedVector call
371 * @param[out] dst output nodal vector where the results of the operator is
372 * copied into.
373 */
374 void
377 const dftfe::uInt kPointIndex,
378 const CouplingStructure couplingtype,
381 &sphericalFunctionKetTimesVectorParFlattened,
383
384 /**
385 * @brief adds the result of CVCtX onto Xout for both CPU and GPU calls
386 * @param[out] Xout memoryStorage object of size
387 * cells*numberOfNodex*BlockSize. Typical case holds the results of H_{loc}X
388 * @param[in] cellRange start and end element id in list of nonlocal
389 * elements
390 */
391 void
392 applyCOnVCconjtransX(ValueType *Xout,
393 const std::pair<dftfe::uInt, dftfe::uInt> cellRange);
394
395
396 /**
397 * @brief adds the result of CVCtX onto Xout for both CPU and GPU calls
398 * @param[out] Xout memoryStorage object of size
399 * cells*numberOfNodex*BlockSize. Typical case holds the results of H_{loc}X
400 * @param[in] cellRange start and end element id in list of nonlocal
401 * elements
402 */
403 void
406
407 std::vector<ValueType>
409 dftfe::uInt atomId,
410 dftfe::Int iElem) const;
411
412 bool
414 const std::pair<dftfe::uInt, dftfe::uInt> cellRange) const;
415 /**
416 * @brief Called only for GPU runs where the coupling matrix has to be padded
417 * @param[in] entries COupling matrix entries without padding in the atomId
418 * order
419 * @param[out] entriesPadded Padding of coupling matrix entries
420 * @param[in] couplingtype Determines the dimension of entriesPadded and the
421 * padding mechanism elements
422 */
423 void
424 paddingCouplingMatrix(const std::vector<ValueType> &entries,
425 std::vector<ValueType> &entriesPadded,
426 const CouplingStructure couplingtype);
427
428 /**
429 * @brief Returns C matrix entries for chargeId and it compact support element Id.
430 */
431 const std::vector<ValueType> &
433 const dftfe::uInt iElemComp) const;
434 /**
435 * @brief Returns C conj matrix entries for chargeId and it compact support element Id.
436 */
437 const std::vector<ValueType> &
439 const dftfe::uInt iElemComp) const;
440 /**
441 * @brief Returns global C matrix of all atoms.
442 */
443 const std::vector<
444 std::vector<dftfe::utils::MemoryStorage<ValueType, memorySpace>>> &
446
447
448 protected:
449 /**
450 * @brief completes the VCconjX on nodal vector src. The src vector must have all ghost nodes and constraint nodes updated.
451 * @param[in] src input nodal vector on which operator acts on.
452 * @param[in] kPointIndex kPoint of interest for current operation
453 * @param[in] couplingtype structure of coupling matrix
454 * @param[in] couplingMatrix entries of the coupling matrix V in
455 * CVCconjtrans. Ensure the coupling matrix is padded
456 * @param[out] sphericalFunctionKetTimesVectorParFlattened multivector to
457 * store results of CconjtransX which is initiliased using
458 * initialiseFlattenedVector call
459 */
460 void
463 const dftfe::uInt kPointIndex,
464 const CouplingStructure couplingtype,
467 &sphericalFunctionKetTimesVectorParFlattened,
468 const bool flagScaleInternalMatrix = false);
469
470 /**
471 * @brief completes the VCconjX on nodal vector src using global C matrix.
472 * The global C matrix mush have been computed before.
473 * The src vector must have all ghost nodes and constraint nodes updated.
474 * @param[in] src input nodal vector on which operator acts on.
475 * @param[in] kPointIndex kPoint of interest for current operation
476 * @param[in] couplingtype structure of coupling matrix
477 * @param[in] couplingMatrix entries of the coupling matrix V in
478 * CVCconjtrans. Ensure the coupling matrix is padded
479 * @param[out] sphericalFunctionKetTimesVectorParFlattened multivector to
480 * store results of CconjtransX which is initiliased using
481 * initialiseFlattenedVector call
482 */
483 void
486 const dftfe::uInt kPointIndex,
487 const CouplingStructure couplingtype,
490 &sphericalFunctionKetTimesVectorParFlattened,
491 const bool flagScaleInternalMatrix = false);
492
494 std::vector<double> d_kPointWeights;
495 std::vector<double> d_kPointCoordinates;
496 std::shared_ptr<dftfe::linearAlgebra::BLASWrapper<memorySpace>>
498 std::shared_ptr<AtomCenteredSphericalFunctionContainer>
500 std::shared_ptr<
503 std::vector<dftfe::uInt> d_numberCellsForEachAtom;
504
505 std::shared_ptr<
508
509
510 // Required by force.cc
512 // Required for stress compute
513 std::vector<ValueType>
515
516 /// map from cell number to set of non local atom ids (local numbering)
517 std::map<dftfe::uInt, std::vector<dftfe::uInt>>
519
520 /// vector of size num physical cells
521 std::vector<dftfe::uInt> d_nonTrivialSphericalFnPerCell;
522
523 /// vector of size num physical cell with starting index for each cell for
524 /// the above array
526
528
529 /// map from local nonlocal atomid to vector over cells
530 std::map<dftfe::uInt, std::vector<dftfe::uInt>>
532
534
536
537 // The above set of variables are needed in force class
538
539#ifdef USE_COMPLEX
540 std::vector<distributedCPUVec<std::complex<double>>>
542
543#else
544 std::vector<distributedCPUVec<double>> d_SphericalFunctionKetTimesVectorPar;
545#endif
546
547 std::map<std::pair<dftfe::uInt, dftfe::uInt>, dftfe::uInt>
549
550 std::vector<dftfe::uInt> d_OwnedAtomIdsInCurrentProcessor;
553 std::map<std::pair<dftfe::uInt, dftfe::uInt>, dftfe::uInt>
555 std::vector<std::vector<
556 std::vector<dftfe::utils::MemoryStorage<ValueType, memorySpace>>>>
558 dealii::ConditionalOStream pcout;
559 const MPI_Comm d_mpi_communicator;
564
565 dftfe::uInt d_totalAtomsInCurrentProc; // number of atoms of interst with
566 // compact in current processor
568 d_totalNonlocalElems; // number of nonlocal FE celss having nonlocal
569 // contribution in current processor
570 dftfe::uInt d_totalNonLocalEntries; // Total number of nonlocal components
572 d_maxSingleAtomContribution; // maximum number of nonlocal indexes across
573 // all atoms of interset
574 std::vector<dftfe::uInt> d_numberCellsAccumNonLocalAtoms;
577 dftfe::uInt d_numberNodesPerElement; // Access from BasisOperator WHile
578 // filling CMatrixEntries
583 bool d_isMallocCalled = false;
584 // Host CMatrix Entries are stored here
585 std::vector<std::vector<std::vector<ValueType>>> d_CMatrixEntriesConjugate,
587
588
589
590 private:
591 /**
592 * @brief stores the d_kpointWeights, d_kpointCoordinates. Other data members regarding are computed from container data object
593 * @param[in] kPointWeights std::vector<double> of size number of kPoints
594 * @param[out] kPointCoordinates std::vector<double> of kPoint coordinates
595 */
596 void
597 initKpoints(const std::vector<double> &kPointWeights,
598 const std::vector<double> &kPointCoordinates);
599 /**
600 * @brief creates the partitioner for the distributed vector based on sparsity patten from sphericalFn container.
601 * @param[in] basisOperationsPtr HOST FEBasisOperations shared_ptr required
602 * to indetify the element ids and quad points.
603 */
604 void
606 /**
607 * @brief computes the entries in C matrix for CPUs and GPUs. On GPUs the entries are copied to a flattened vector on device memory.
608 * Further on GPUs, various maps are created crucial for accessing and
609 * padding entries in Cmatrix flattened device.
610 * @param[in] basisOperationsPtr HOST FEBasisOperations shared_ptr required
611 * to indetify the element ids and quad points
612 * @param[in] quadratureIndex quadrature index for sampling the spherical
613 * function. Quadrature Index is used to reinit basisOperationsPtr
614 */
615 void
617 std::shared_ptr<dftfe::basis::FEBasisOperations<
619 double,
620 dftfe::utils::MemorySpace::HOST>> basisOperationsPtr,
621 const dftfe::uInt quadratureIndex);
622
623 template <typename ValueTypeSrc>
624 void
626 const std::shared_ptr<
628 nonLocalOperatorSrc,
629 std::shared_ptr<
631 double,
633 basisOperationsPtr,
634 const dftfe::uInt quadratureIndex);
635
636 template <typename ValueTypeSrc>
637 void
639 const std::shared_ptr<
641 nonLocalOperatorSrc,
642 std::shared_ptr<
644 double,
646 basisOperationsPtr,
647 const dftfe::uInt quadratureIndex);
648
649
650 std::map<
654 std::vector<dftfe::uInt>
658 std::vector<dftfe::uInt> d_nonlocalElemIdToCellIdVector;
661 std::vector<dftfe::uInt> d_atomStartIndexGlobal;
663
664 std::vector<
665 std::vector<dftfe::utils::MemoryStorage<ValueType, memorySpace>>>
667
668 std::set<dftfe::uInt> d_setOfAtomicNumber;
669 std::vector<dftfe::uInt> d_mapAtomIdToSpeciesIndex,
671 std::vector<dftfe::utils::MemoryStorage<ValueType, memorySpace>>
673 std::vector<dftfe::uInt> d_mapIAtomicNumToDotProd;
674 std::vector<dftfe::uInt> d_mapiAtomToDotProd;
675
677
678 std::vector<dftfe::uInt> d_mapiAtomTosphFuncWaveStart;
679 std::map<dftfe::uInt, std::vector<dftfe::uInt>> d_listOfiAtomInSpecies;
680
681 /**
682 * @brief computes Global Cmatrix on HOST.
683 * @param[in] basisOperationsPtr HOST FEBasisOperations shared_ptr required
684 * to indetify the element ids and quad points
685 * @param[in] BLASWrapperHostPtr HOST BLASWrapper
686 */
687 void
689 std::shared_ptr<dftfe::basis::FEBasisOperations<
691 double,
692 dftfe::utils::MemorySpace::HOST>> basisOperationsPtr,
693 std::shared_ptr<
695 BLASWrapperHostPtr);
696
697#if defined(DFTFE_WITH_DEVICE)
698 /**
699 * @brief Copies the data from distributed Vector to Padded Memory storage object.
700 * @param[in] sphericalFunctionKetTimesVectorParFlattened Distributed Vector
701 * @param[out] paddedVector Padded Vector of size
702 * noAtomsInProc*maxSingleAtomContribution*Nwfc
703 */
704 void
705 copyDistributedVectorToPaddedMemoryStorageVectorDevice(
707 &sphericalFunctionKetTimesVectorParFlattened,
709
710 /**
711 * @brief Copies Padded Memory storage object to Distributed vector.
712 * @param[in] paddedVector Padded Vector of size
713 * noAtomsInProc*maxSingleAtomContribution*Nwfc
714 * @param[out] sphericalFunctionKetTimesVectorParFlattened Distributed
715 * Vector
716 *
717 */
718 void
719 copyPaddedMemoryStorageVectorToDistributeVectorDevice(
722 &sphericalFunctionKetTimesVectorParFlattened);
723
724
726 d_tempConjtansX;
728 d_sphericalFnTimesWavefunctionMatrix;
729 ValueType **hostPointerCDagger, **hostPointerCDaggeOutTemp,
730 **hostWfcPointers;
731 ValueType *d_wfcStartPointer;
732 ValueType **devicePointerCDagger, **devicePointerCDaggerOutTemp,
733 **deviceWfcPointers;
734 std::vector<dftfe::uInt> d_nonlocalElemIdToLocalElemIdMap;
735
736 // The below memory storage objects receives the copy of the distributed
737 // ketTimesWfc data in a padded form. THe padding is done by
738 // copyDistributedVectorToPaddedMemoryStorageVector
740 d_sphericalFnTimesVectorDevice;
741 // Data structures moved from KSOperatorDevice
742 std::vector<ValueType> d_cellHamiltonianMatrixNonLocalFlattenedConjugate;
744 d_cellHamiltonianMatrixNonLocalFlattenedConjugateDevice;
745 std::vector<ValueType> d_cellHamiltonianMatrixNonLocalFlattenedTranspose;
747 d_cellHamiltonianMatrixNonLocalFlattenedTransposeDevice;
749 d_cellHamMatrixTimesWaveMatrixNonLocalDevice;
751 d_sphericalFnTimesVectorAllCellsDevice;
752 std::vector<ValueType> d_sphericalFnTimesVectorAllCellsReduction;
754 d_sphericalFnTimesVectorAllCellsReductionDevice;
755
756 std::vector<dftfe::uInt> d_mapSphericalFnTimesVectorAllCellsReduction;
758 d_mapSphericalFnTimesVectorAllCellsReductionDevice;
760 d_couplingMatrixTimesVectorDevice;
761
762 std::vector<dftfe::uInt> d_sphericalFnIdsParallelNumberingMap;
763 std::vector<dftfe::Int> d_sphericalFnIdsPaddedParallelNumberingMap;
765 d_sphericalFnIdsParallelNumberingMapDevice;
767 d_sphericalFnIdsPaddedParallelNumberingMapDevice;
768 std::vector<dftfe::Int>
769 d_indexMapFromPaddedNonLocalVecToParallelNonLocalVec;
771 d_indexMapFromPaddedNonLocalVecToParallelNonLocalVecDevice;
772 std::vector<dftfe::uInt> d_cellNodeIdMapNonLocalToLocal;
773
775 d_cellNodeIdMapNonLocalToLocalDevice;
776#endif
777 };
778
779
780
781} // namespace dftfe
782#endif // DFTFE_ATOMICCENTEREDNONLOCALOPERATOR_H
void computeCMatrixEntries(std::shared_ptr< dftfe::basis::FEBasisOperations< dataTypes::number, double, dftfe::utils::MemorySpace::HOST > > basisOperationsPtr, const dftfe::uInt quadratureIndex)
computes the entries in C matrix for CPUs and GPUs. On GPUs the entries are copied to a flattened vec...
bool atomPresentInCellRange(const std::pair< dftfe::uInt, dftfe::uInt > cellRange) const
void initKpoints(const std::vector< double > &kPointWeights, const std::vector< double > &kPointCoordinates)
stores the d_kpointWeights, d_kpointCoordinates. Other data members regarding are computed from conta...
std::vector< ValueType > d_atomCenteredKpointIndexedSphericalFnQuadValues
Definition AtomicCenteredNonLocalOperator.h:511
void applyVCconjtransOnX(const dftfe::linearAlgebra::MultiVector< ValueType, memorySpace > &src, const dftfe::uInt kPointIndex, const CouplingStructure couplingtype, const dftfe::utils::MemoryStorage< ValueType, memorySpace > &couplingMatrix, dftfe::linearAlgebra::MultiVector< ValueType, memorySpace > &sphericalFunctionKetTimesVectorParFlattened, const bool flagScaleInternalMatrix=false)
completes the VCconjX on nodal vector src. The src vector must have all ghost nodes and constraint no...
AtomicCenteredNonLocalOperator(std::shared_ptr< dftfe::linearAlgebra::BLASWrapper< memorySpace > > BLASWrapperPtr, std::shared_ptr< dftfe::basis::FEBasisOperations< dataTypes::number, double, memorySpace > > basisOperatorPtr, std::shared_ptr< AtomCenteredSphericalFunctionContainer > atomCenteredSphericalFunctionContainer, const MPI_Comm &mpi_comm_parent, const bool memOptMode=false, const bool computeSphericalFnTimesX=true, const bool useGlobalCMatrix=false)
std::vector< dftfe::uInt > d_mapiAtomToDotProd
Definition AtomicCenteredNonLocalOperator.h:674
dftfe::uInt d_totalNumSphericalFunctionsGlobal
Definition AtomicCenteredNonLocalOperator.h:662
dealii::IndexSet d_locallyOwnedAtomCenteredFnIdsCurrentProcess
Definition AtomicCenteredNonLocalOperator.h:551
std::map< dftfe::uInt, std::vector< dftfe::uInt > > d_atomIdToNonTrivialSphericalFnCellStartIndex
map from local nonlocal atomid to vector over cells
Definition AtomicCenteredNonLocalOperator.h:531
dftfe::uInt getTotalAtomInCurrentProcessor() const
std::vector< dftfe::utils::MemoryStorage< ValueType, memorySpace > > d_dotProductAtomicWaveInputWaveTemp
Definition AtomicCenteredNonLocalOperator.h:672
const std::vector< dftfe::uInt > & getSphericalFnTimesVectorFlattenedVectorLocalIds() const
Returns the Flattened vector of sphericalFunctionIDs in order of atomIDs of atoms in processor.
bool d_useGlobalCMatrix
Definition AtomicCenteredNonLocalOperator.h:660
const std::vector< ValueType > & getCmatrixEntriesConjugate(const dftfe::uInt chargeId, const dftfe::uInt iElemComp) const
Returns C matrix entries for chargeId and it compact support element Id.
std::vector< double > d_kPointWeights
Definition AtomicCenteredNonLocalOperator.h:494
const dftfe::uInt d_n_mpi_processes
Definition AtomicCenteredNonLocalOperator.h:561
std::vector< ValueType > getCmatrixEntries(dftfe::Int kPointIndex, dftfe::uInt atomId, dftfe::Int iElem) const
bool d_AllReduceCompleted
Definition AtomicCenteredNonLocalOperator.h:493
const std::map< dftfe::uInt, std::vector< dftfe::uInt > > & getAtomIdToNonTrivialSphericalFnCellStartIndex() const
Required in configurational forces. Cummulative sphercial Fn Id. The size is numCells in processor.
std::map< dftfe::uInt, std::vector< dftfe::uInt > > d_cellIdToAtomIdsLocalCompactSupportMap
map from cell number to set of non local atom ids (local numbering)
Definition AtomicCenteredNonLocalOperator.h:518
std::vector< dftfe::uInt > d_flattenedNonLocalCellDofIndexToProcessDofIndexVector
Definition AtomicCenteredNonLocalOperator.h:655
void copyPartitionerKPointsAndComputeCMatrixEntries(const bool updateSparsity, const std::vector< double > &kPointWeights, const std::vector< double > &kPointCoordinates, std::shared_ptr< dftfe::basis::FEBasisOperations< dataTypes::number, double, dftfe::utils::MemorySpace::HOST > > basisOperationsPtr, std::shared_ptr< dftfe::linearAlgebra::BLASWrapper< dftfe::utils::MemorySpace::HOST > > BLASWrapperHostPtr, const dftfe::uInt quadratureIndex, const std::shared_ptr< AtomicCenteredNonLocalOperator< ValueTypeSrc, memorySpace > > nonLocalOperatorSrc)
calls internal function: initialisePartitioner, initialiseKpoint and computeCMatrixEntries
const std::vector< ValueType > & getAtomCenteredKpointTimesSphericalFnTimesDistFromAtomQuadValues() const
std::map< std::pair< dftfe::uInt, dftfe::uInt >, dftfe::uInt > d_AtomCenteredFnIdsNumberingMapCurrentProcess
Definition AtomicCenteredNonLocalOperator.h:554
dftfe::uInt d_numberWaveFunctions
Definition AtomicCenteredNonLocalOperator.h:580
std::vector< dftfe::uInt > d_nonlocalElemIdToCellIdVector
Definition AtomicCenteredNonLocalOperator.h:658
const MPI_Comm d_mpi_communicator
Definition AtomicCenteredNonLocalOperator.h:559
std::vector< dftfe::uInt > d_mapiAtomTosphFuncWaveStart
Definition AtomicCenteredNonLocalOperator.h:678
dftfe::uInt d_locallyOwnedCells
Definition AtomicCenteredNonLocalOperator.h:579
std::map< dftfe::uInt, std::vector< dftfe::uInt > > d_listOfiAtomInSpecies
Definition AtomicCenteredNonLocalOperator.h:679
std::set< dftfe::uInt > d_setOfAtomicNumber
Definition AtomicCenteredNonLocalOperator.h:668
dftfe::utils::MemoryStorage< dftfe::uInt, memorySpace > d_iElemNonLocalToElemIndexMap
Definition AtomicCenteredNonLocalOperator.h:576
dftfe::uInt d_kPointIndex
Definition AtomicCenteredNonLocalOperator.h:581
void paddingCouplingMatrix(const std::vector< ValueType > &entries, std::vector< ValueType > &entriesPadded, const CouplingStructure couplingtype)
Called only for GPU runs where the coupling matrix has to be padded.
dftfe::uInt d_maxSingleAtomContribution
Definition AtomicCenteredNonLocalOperator.h:572
dealii::IndexSet d_ghostSphericalFunctionIdsCurrentProcess
Definition AtomicCenteredNonLocalOperator.h:563
std::vector< std::vector< std::vector< ValueType > > > d_CMatrixEntriesConjugate
Definition AtomicCenteredNonLocalOperator.h:585
std::vector< dftfe::uInt > d_nonTrivialSphericalFnsCellStartIndex
Definition AtomicCenteredNonLocalOperator.h:525
std::shared_ptr< dftfe::basis::FEBasisOperations< dataTypes::number, double, memorySpace > > d_basisOperatorPtr
Definition AtomicCenteredNonLocalOperator.h:507
std::vector< std::vector< std::vector< ValueType > > > d_CMatrixEntriesTranspose
Definition AtomicCenteredNonLocalOperator.h:586
const std::vector< dftfe::uInt > & getNonTrivialAllCellsSphericalFnAlphaToElemIdMap() const
dftfe::uInt d_totalAtomsInCurrentProc
Definition AtomicCenteredNonLocalOperator.h:565
std::vector< distributedCPUVec< double > > d_SphericalFunctionKetTimesVectorPar
Definition AtomicCenteredNonLocalOperator.h:544
void intitialisePartitionerKPointsAndComputeCMatrixEntries(const bool updateSparsity, const std::vector< double > &kPointWeights, const std::vector< double > &kPointCoordinates, std::shared_ptr< dftfe::basis::FEBasisOperations< dataTypes::number, double, dftfe::utils::MemorySpace::HOST > > basisOperationsPtr, std::shared_ptr< dftfe::linearAlgebra::BLASWrapper< dftfe::utils::MemorySpace::HOST > > BLASWrapperHostPtr, const dftfe::uInt quadratureIndex)
calls internal function: initialisePartitioner, initialiseKpoint and computeCMatrixEntries
dftfe::uInt d_sumNonTrivialSphericalFnOverAllCells
Definition AtomicCenteredNonLocalOperator.h:533
bool d_computeSphericalFnTimesX
Definition AtomicCenteredNonLocalOperator.h:659
std::map< dftfe::uInt, dftfe::utils::MemoryStorage< ValueType, dftfe::utils::MemorySpace::HOST > > d_sphericalFnTimesWavefunMatrix
Definition AtomicCenteredNonLocalOperator.h:653
dftfe::uInt d_totalLocallyOwnedNodes
Definition AtomicCenteredNonLocalOperator.h:676
std::vector< std::vector< dftfe::utils::MemoryStorage< ValueType, memorySpace > > > d_CMatrixGlobal
Definition AtomicCenteredNonLocalOperator.h:666
const std::vector< dftfe::uInt > & getOwnedAtomIdsInCurrentProcessor() const
const std::vector< ValueType > & getAtomCenteredKpointIndexedSphericalFnQuadValues() const
std::vector< dftfe::uInt > d_nonTrivialSphericalFnPerCell
vector of size num physical cells
Definition AtomicCenteredNonLocalOperator.h:521
std::vector< dftfe::uInt > d_numberCellsAccumNonLocalAtoms
Definition AtomicCenteredNonLocalOperator.h:574
void applyAllReduceOnCconjtransX(dftfe::linearAlgebra::MultiVector< ValueType, memorySpace > &sphericalFunctionKetTimesVectorParFlattened, const bool skipComm=false)
copies the results from internal member to sphericalFunctionKetTimesVectorParFlattened,...
void applyCOnVCconjtransX(dftfe::linearAlgebra::MultiVector< ValueType, memorySpace > &Xout)
adds the result of CVCtX onto Xout for both CPU and GPU calls
std::vector< dftfe::uInt > & getAtomWiseNumberCellsInCompactSupport() const
std::shared_ptr< dftfe::linearAlgebra::BLASWrapper< memorySpace > > d_BLASWrapperPtr
Definition AtomicCenteredNonLocalOperator.h:497
void copyCMatrixEntries(const std::shared_ptr< AtomicCenteredNonLocalOperator< ValueTypeSrc, memorySpace > > nonLocalOperatorSrc, std::shared_ptr< dftfe::basis::FEBasisOperations< dataTypes::number, double, dftfe::utils::MemorySpace::HOST > > basisOperationsPtr, const dftfe::uInt quadratureIndex)
std::vector< dftfe::uInt > d_mapiAtomToSpeciesIndex
Definition AtomicCenteredNonLocalOperator.h:670
void copyBackFromDistributedVectorToLocalDataStructure(dftfe::linearAlgebra::MultiVector< ValueType, memorySpace > &sphericalFunctionKetTimesVectorParFlattened, const dftfe::utils::MemoryStorage< double, memorySpace > &scalingVector)
After AllReduce function is called this will copy to the nonLocalOperatorClassDatastructure.
dftfe::uInt getGlobalDofAtomIdSphericalFnPair(const dftfe::uInt atomId, const dftfe::uInt alpha) const
void applyVCconjtransOnXCellLevel(const dftfe::linearAlgebra::MultiVector< ValueType, memorySpace > &src, const dftfe::uInt kPointIndex, const CouplingStructure couplingtype, const dftfe::utils::MemoryStorage< ValueType, memorySpace > &couplingMatrix, dftfe::linearAlgebra::MultiVector< ValueType, memorySpace > &sphericalFunctionKetTimesVectorParFlattened, const bool flagScaleInternalMatrix=false)
completes the VCconjX on nodal vector src. The src vector must have all ghost nodes and constraint no...
std::vector< dftfe::uInt > d_numberCellsForEachAtom
Definition AtomicCenteredNonLocalOperator.h:503
std::shared_ptr< AtomCenteredSphericalFunctionContainer > d_atomCenteredSphericalFunctionContainer
Definition AtomicCenteredNonLocalOperator.h:499
void initialisePartitioner()
creates the partitioner for the distributed vector based on sparsity patten from sphericalFn containe...
std::vector< dftfe::uInt > d_atomStartIndexGlobal
Definition AtomicCenteredNonLocalOperator.h:661
bool atomSupportInElement(dftfe::uInt iElem) const
std::vector< dftfe::uInt > d_sphericalFnTimesVectorFlattenedVectorLocalIds
Definition AtomicCenteredNonLocalOperator.h:535
std::vector< dftfe::uInt > d_mapAtomIdToSpeciesIndex
Definition AtomicCenteredNonLocalOperator.h:669
const std::vector< dftfe::uInt > & getNonTrivialSphericalFnsCellStartIndex() const
const dftfe::utils::MemoryStorage< dftfe::uInt, memorySpace > & getFlattenedNonLocalCellDofIndexToProcessDofIndexMap() const
std::vector< std::vector< std::vector< dftfe::utils::MemoryStorage< ValueType, memorySpace > > > > d_CMatrixEntries
Definition AtomicCenteredNonLocalOperator.h:557
const std::vector< dftfe::uInt > & getNonlocalElementToCellIdVector() const
dftfe::utils::MemoryStorage< dftfe::uInt, memorySpace > d_flattenedNonLocalCellDofIndexToProcessDofIndexMap
Definition AtomicCenteredNonLocalOperator.h:657
void applyCconjtransOnX(const dftfe::linearAlgebra::MultiVector< ValueType, memorySpace > &X)
computes the results of CconjtransX on nodal X vector
dftfe::uInt d_numberNodesPerElement
Definition AtomicCenteredNonLocalOperator.h:577
bool d_isMallocCalled
Definition AtomicCenteredNonLocalOperator.h:583
std::shared_ptr< const utils::mpi::MPIPatternP2P< dftfe::utils::MemorySpace::HOST > > d_mpiPatternP2P
Definition AtomicCenteredNonLocalOperator.h:502
void applyCconjtransOnX(const ValueType *X, const std::pair< dftfe::uInt, dftfe::uInt > cellRange)
computes the results of CconjtransX on the cells of interst specied by cellRange
std::vector< dftfe::uInt > & getAtomWiseNumberCellsAccumulated() const
dftfe::uInt d_totalNonLocalEntries
Definition AtomicCenteredNonLocalOperator.h:570
void initialiseOperatorActionOnX(dftfe::uInt kPointIndex)
Resizes various internal data members and selects the kpoint of interest.
dealii::ConditionalOStream pcout
Definition AtomicCenteredNonLocalOperator.h:558
void initialiseFlattenedDataStructure(dftfe::uInt waveFunctionBlockSize, dftfe::linearAlgebra::MultiVector< ValueType, memorySpace > &sphericalFunctionKetTimesVectorParFlattened)
initialises the multivector object, waveFunctionBlockSize and resizes various internal data members.
void applyCOnVCconjtransX(ValueType *Xout, const std::pair< dftfe::uInt, dftfe::uInt > cellRange)
adds the result of CVCtX onto Xout for both CPU and GPU calls
std::vector< dftfe::uInt > d_mapIAtomicNumToDotProd
Definition AtomicCenteredNonLocalOperator.h:673
void applyCVCconjtransOnX(const dftfe::linearAlgebra::MultiVector< ValueType, memorySpace > &src, const dftfe::uInt kPointIndex, const CouplingStructure couplingtype, const dftfe::utils::MemoryStorage< ValueType, memorySpace > &couplingMatrix, dftfe::linearAlgebra::MultiVector< ValueType, memorySpace > &sphericalFunctionKetTimesVectorParFlattened, dftfe::linearAlgebra::MultiVector< ValueType, memorySpace > &dst)
completes the action of CVCconjtranspose on nodal vector src. The src vector must have all ghost node...
const std::map< dftfe::uInt, std::vector< dftfe::uInt > > & getCellIdToAtomIdsLocalCompactSupportMap() const
void applyVCconjtransOnXUsingGlobalC(const dftfe::linearAlgebra::MultiVector< ValueType, memorySpace > &src, const dftfe::uInt kPointIndex, const CouplingStructure couplingtype, const dftfe::utils::MemoryStorage< ValueType, memorySpace > &couplingMatrix, dftfe::linearAlgebra::MultiVector< ValueType, memorySpace > &sphericalFunctionKetTimesVectorParFlattened, const bool flagScaleInternalMatrix=false)
completes the VCconjX on nodal vector src using global C matrix. The global C matrix mush have been c...
const ValueType * getCconjtansXLocalDataStructure(const dftfe::uInt iAtom) const
Returns the pointer of CTX stored in HOST memory.
const dftfe::uInt getTotalNonTrivialSphericalFnsOverAllCells() const
void applyVOnCconjtransX(const CouplingStructure couplingtype, const dftfe::utils::MemoryStorage< ValueType, memorySpace > &couplingMatrix, dftfe::linearAlgebra::MultiVector< ValueType, memorySpace > &sphericalFunctionKetTimesVectorParFlattened, const bool flagCopyResultsToMatrix=true, const dftfe::uInt kPointIndex=0)
compute the action of coupling matrix on sphericalFunctionKetTimesVectorParFlattened.
const std::vector< dftfe::uInt > & getNonTrivialSphericalFnsPerCell() const
std::map< std::pair< dftfe::uInt, dftfe::uInt >, dftfe::uInt > d_sphericalFunctionIdsNumberingMapCurrentProcess
Definition AtomicCenteredNonLocalOperator.h:548
std::vector< dftfe::uInt > d_OwnedAtomIdsInCurrentProcessor
Definition AtomicCenteredNonLocalOperator.h:550
std::vector< dftfe::uInt > d_nonTrivialAllCellsSphericalFnAlphaToElemIdMap
Definition AtomicCenteredNonLocalOperator.h:527
std::vector< double > d_kPointCoordinates
Definition AtomicCenteredNonLocalOperator.h:495
dftfe::uInt getMaxSingleAtomEntries() const
bool d_memoryOptMode
Definition AtomicCenteredNonLocalOperator.h:582
const std::vector< std::vector< dftfe::utils::MemoryStorage< ValueType, memorySpace > > > & getGlobalCMatrix() const
Returns global C matrix of all atoms.
void copyGlobalCMatrix(const std::shared_ptr< AtomicCenteredNonLocalOperator< ValueTypeSrc, memorySpace > > nonLocalOperatorSrc, std::shared_ptr< dftfe::basis::FEBasisOperations< dataTypes::number, double, dftfe::utils::MemorySpace::HOST > > basisOperationsPtr, const dftfe::uInt quadratureIndex)
dftfe::uInt getLocalIdOfDistributedVec(const dftfe::uInt globalId) const
const std::vector< ValueType > & getCmatrixEntriesTranspose(const dftfe::uInt chargeId, const dftfe::uInt iElemComp) const
Returns C conj matrix entries for chargeId and it compact support element Id.
const dftfe::uInt d_this_mpi_process
Definition AtomicCenteredNonLocalOperator.h:560
dftfe::uInt getTotalNonLocalEntriesCurrentProcessor() const
void computeGlobalCMatrixVector(std::shared_ptr< dftfe::basis::FEBasisOperations< dataTypes::number, double, dftfe::utils::MemorySpace::HOST > > basisOperationsPtr, std::shared_ptr< dftfe::linearAlgebra::BLASWrapper< dftfe::utils::MemorySpace::HOST > > BLASWrapperHostPtr)
computes Global Cmatrix on HOST.
dealii::IndexSet d_locallyOwnedSphericalFunctionIdsCurrentProcess
Definition AtomicCenteredNonLocalOperator.h:562
void computeCconjtransCMatrix(const dftfe::uInt atomId, std::shared_ptr< dftfe::linearAlgebra::BLASWrapper< dftfe::utils::MemorySpace::HOST > > BLASWrapperPtr, const dftfe::utils::MemoryStorage< double, dftfe::utils::MemorySpace::HOST > &Dinverse, dftfe::utils::MemoryStorage< ValueType, dftfe::utils::MemorySpace::HOST > PconjtransposePmatrix)
Computes C^{T}D^{-1}C at the global level for atomId. This is required in PAW.
dftfe::uInt getTotalNonLocalElementsInCurrentProcessor() const
std::vector< dftfe::uInt > & getNonLocalElemIdToLocalElemIdMap() const
std::vector< ValueType > d_atomCenteredKpointTimesSphericalFnTimesDistFromAtomQuadValues
Definition AtomicCenteredNonLocalOperator.h:514
dealii::IndexSet d_ghostAtomCenteredFnIdsCurrentProcess
Definition AtomicCenteredNonLocalOperator.h:552
dftfe::uInt d_totalNonlocalElems
Definition AtomicCenteredNonLocalOperator.h:568
Definition FEBasisOperations.h:85
Definition BLASWrapper.h:35
An class template to encapsulate a MultiVector. A MultiVector is a collection of vectors belonging t...
Definition MultiVector.h:127
Definition MemoryStorage.h:33
A class template to store the communication pattern (i.e., which entries/nodes to receive from which ...
Definition MPIPatternP2P.h:57
double number
Definition dftfeDataTypes.h:42
@ HOST
Definition MemorySpaceType.h:34
Definition pseudoPotentialToDftfeConverter.cc:34
CouplingStructure
Enum class that lists used in the non-local Operator.
Definition AtomicCenteredNonLocalOperator.h:48
@ dense
Definition AtomicCenteredNonLocalOperator.h:50
@ blockDiagonal
Definition AtomicCenteredNonLocalOperator.h:51
@ diagonal
Definition AtomicCenteredNonLocalOperator.h:49
std::uint32_t uInt
Definition TypeConfig.h:10
std::int32_t Int
Definition TypeConfig.h:11