DFT-EFE
 
Loading...
Searching...
No Matches
HamiltonianSpinBlockCopyKernels.h
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (c) 2021. *
3 * The Regents of the University of Michigan and DFT-EFE developers. *
4 * *
5 * This file is part of the DFT-EFE code. *
6 * *
7 * DFT-EFE is free software: you can redistribute it and/or modify *
8 * it under the terms of the Lesser GNU General Public License as *
9 * published by the Free Software Foundation, either version 3 of *
10 * the License, or (at your option) any later version. *
11 * *
12 * DFT-EFE is distributed in the hope that it will be useful, but *
13 * WITHOUT ANY WARRANTY; without even the implied warranty *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
15 * See the Lesser GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License at the top level of DFT-EFE distribution. If not, see *
19 * <https://www.gnu.org/licenses/>. *
20 ******************************************************************************/
21
22/*
23 * @author Avirup Sircar
24 */
25
26#ifndef dftefe_HamiltonianSpinBlockCopyKernels_h
27#define dftefe_HamiltonianSpinBlockCopyKernels_h
28
29#include <utils/MemoryStorage.h>
30#include <utils/TypeConfig.h>
32#include <utility>
33#include <vector>
34
35namespace dftefe
36{
37 namespace ksdft
38 {
40 {
43 };
44
45 template <typename ValueType, utils::MemorySpace memorySpace>
47 {
48 public:
49 /*
50 * Copy K source spin blocks into the (S·d_c)×(S·d_c) cell destination.
51 * spinIdsFilled[k] = (sRow, sCol): the destination spin block for
52 * source block k. Caller must zero dst when K < S².
53 *
54 * src: [k (0..K-1)][cell c][col j (0..d_c-1)][row i (0..d_c-1)]
55 * flat = k·Σd_c² + cellSrcOffset_c + j·d_c + i
56 *
57 * dst (DofFastest):
58 * flat = cellDstOffset_c + (sCol·d_c + j)·(S·d_c) + sRow·d_c + i
59 *
60 * dst (SpinFastest):
61 * flat = cellDstOffset_c + (j·S + sCol)·(S·d_c) + i·S + sRow
62 *
63 * cellDstOffset_c = Σ_{c'<c} (S·d_{c'})²
64 */
65 static void
69 size_type S,
70 SpinStorageLayout layout,
71 const std::vector<std::pair<size_type, size_type>> &spinIdsFilled,
72 const std::vector<size_type> & numCellDofs,
74 };
75
76 template <typename ValueType, utils::MemorySpace memorySpace>
77 void
81 size_type S,
82 SpinStorageLayout layout,
83 const std::vector<std::pair<size_type, size_type>> &spinIdsFilled,
84 const std::vector<size_type> & numCellDofs,
86 {
87 const size_type K = spinIdsFilled.size();
88 size_type basisOverlapSize = 0;
89 for (const size_type d : numCellDofs)
90 basisOverlapSize += d * d;
91
92 const ValueType *srcPtr = src.begin();
93 ValueType * dstPtr = dst.begin();
94
95 for (size_type k = 0; k < K; ++k)
96 {
97 const size_type sRow = spinIdsFilled[k].first;
98 const size_type sCol = spinIdsFilled[k].second;
99 size_type cellSrcOffset = 0;
100 size_type cellDstOffset = 0;
101 for (const size_type d : numCellDofs)
102 {
103 const size_type Sd = S * d;
104 for (size_type j = 0; j < d; ++j)
105 for (size_type i = 0; i < d; ++i)
106 {
107 const size_type dstIdx =
109 cellDstOffset + (sCol * d + j) * Sd + sRow * d + i :
110 cellDstOffset + (j * S + sCol) * Sd + i * S + sRow;
111 dstPtr[dstIdx] =
112 srcPtr[k * basisOverlapSize + cellSrcOffset + j * d + i];
113 }
114 cellSrcOffset += d * d;
115 cellDstOffset += Sd * Sd;
116 }
117 }
118 }
119
120#ifdef DFTEFE_WITH_DEVICE
121 template <typename ValueType>
122 class HamiltonianSpinBlockCopyKernels<ValueType, utils::MemorySpace::DEVICE>
123 {
124 public:
125 static void
129 size_type S,
130 SpinStorageLayout layout,
131 const std::vector<std::pair<size_type, size_type>> &spinIdsFilled,
132 const std::vector<size_type> & numCellDofs,
134 &linAlgOpContext);
135 };
136#endif
137
138 } // namespace ksdft
139} // namespace dftefe
140#endif // dftefe_HamiltonianSpinBlockCopyKernels_h
Definition: HamiltonianSpinBlockCopyKernels.h:47
static void copyIntoBlock(const utils::MemoryStorage< ValueType, memorySpace > &src, utils::MemoryStorage< ValueType, memorySpace > &dst, size_type S, SpinStorageLayout layout, const std::vector< std::pair< size_type, size_type > > &spinIdsFilled, const std::vector< size_type > &numCellDofs, linearAlgebra::LinAlgOpContext< memorySpace > &linAlgOpContext)
Definition: HamiltonianSpinBlockCopyKernels.h:78
Definition: LinAlgOpContext.h:52
Definition: MemoryStorage.h:38
iterator begin()
Return iterator pointing to the beginning of point data.
Definition: MemoryStorage.t.cpp:127
SpinStorageLayout
Definition: HamiltonianSpinBlockCopyKernels.h:40
dealii includes
Definition: AtomFieldDataSpherical.cpp:31
std::uint64_t size_type
Definition: TypeConfig.h:9