DFT-FE 1.3.0-pre
Density Functional Theory With Finite-Elements
Loading...
Searching...
No Matches
MatrixFreeWrapper.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (c) 2017-2022 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 * @author Gourab Panigrahi
20 *
21 */
22
23#ifndef MatrixFreeWrapper_H_
24#define MatrixFreeWrapper_H_
25#include <variant>
26#include <memory>
27#include <headers.h>
29#include <MatrixFree.h>
30
31namespace dftfe
32{
33 /**
34 * @brief Datastructure to hold different MatrixFree class objects
35 *
36 * @author Gourab Panigrahi
37 *
38 */
39 using MatrixFreeObject = std::variant<
40#define MatrixFreeWrapperTemplates(NDOFSPERDIM) \
41 std::shared_ptr<dftfe::MatrixFree<double, \
42 dftfe::operatorList::Laplace, \
43 dftfe::utils::MemorySpace::DEVICE, \
44 false, \
45 NDOFSPERDIM, \
46 NDOFSPERDIM, \
47 1, \
48 1>>, \
49 std::shared_ptr<dftfe::MatrixFree<double, \
50 dftfe::operatorList::Helmholtz, \
51 dftfe::utils::MemorySpace::DEVICE, \
52 false, \
53 NDOFSPERDIM, \
54 NDOFSPERDIM, \
55 1, \
56 1>>,
57#define MatrixFreeWrapperTemplatesL(NDOFSPERDIM) \
58 std::shared_ptr<dftfe::MatrixFree<double, \
59 dftfe::operatorList::Laplace, \
60 dftfe::utils::MemorySpace::DEVICE, \
61 false, \
62 NDOFSPERDIM, \
63 NDOFSPERDIM, \
64 1, \
65 1>>, \
66 std::shared_ptr<dftfe::MatrixFree<double, \
67 dftfe::operatorList::Helmholtz, \
68 dftfe::utils::MemorySpace::DEVICE, \
69 false, \
70 NDOFSPERDIM, \
71 NDOFSPERDIM, \
72 1, \
73 1>>
74#include "MatrixFreeWrapper.def"
75#undef MatrixFreeWrapperTemplates
76#undef MatrixFreeWrapperTemplatesL
77 >;
78
79 /**
80 * @brief Factory function to create MatrixFree object
81 *
82 */
83 template <typename T,
84 dftfe::operatorList operatorID,
85 dftfe::utils::MemorySpace memorySpace,
86 bool isComplex,
87 class... Args>
88 inline MatrixFreeObject
89 createMatrixFreeObject(std::uint32_t nDofsPerDim, Args &&...args)
90 {
91 switch (nDofsPerDim)
92 {
93#define MatrixFreeWrapperTemplates(NDOFSPERDIM) \
94 case NDOFSPERDIM: \
95 return MatrixFreeObject( \
96 std::make_shared<dftfe::MatrixFree<T, \
97 operatorID, \
98 memorySpace, \
99 isComplex, \
100 NDOFSPERDIM, \
101 NDOFSPERDIM, \
102 1, \
103 1>>(std::forward<Args>(args)...));
104#define MatrixFreeWrapperTemplatesL(NDOFSPERDIM) \
105 case NDOFSPERDIM: \
106 return MatrixFreeObject( \
107 std::make_shared<dftfe::MatrixFree<T, \
108 operatorID, \
109 memorySpace, \
110 isComplex, \
111 NDOFSPERDIM, \
112 NDOFSPERDIM, \
113 1, \
114 1>>(std::forward<Args>(args)...));
115#include "MatrixFreeWrapper.def"
116#undef MatrixFreeWrapperTemplates
117#undef MatrixFreeWrapperTemplatesL
118 default:
119 throw std::logic_error{"createMatrixFreeObject dispatch failed"};
120 }
121 }
122
123 /**
124 * @brief MatrixFreeWrapper class
125 *
126 */
127 template <typename T,
128 dftfe::operatorList operatorID,
129 dftfe::utils::MemorySpace memorySpace,
130 bool isComplex>
132 {
133 public:
134 /// Constructor
136 std::uint32_t nDofsPerDim,
137 const MPI_Comm &mpi_comm,
138 const dealii::MatrixFree<3, double> *matrixFreeDataPtr,
139 const dealii::AffineConstraints<double> &constraintMatrix,
141 BLASWrapperPtr,
142 const std::uint32_t dofHandlerID,
143 const std::uint32_t quadratureID,
144 const dftfe::uInt nVectors)
146 createMatrixFreeObject<T, operatorID, memorySpace, isComplex>(
147 nDofsPerDim,
148 mpi_comm,
149 matrixFreeDataPtr,
150 constraintMatrix,
151 BLASWrapperPtr,
152 dofHandlerID,
153 quadratureID,
154 nVectors))
155 {}
156
157 /**
158 * @brief Initialize data structures for MatrixFree class
159 *
160 */
161 inline void
163 {
164 std::visit([&](auto &t) { t->init(); }, d_MatrixFreeObject);
165 }
166
167 /**
168 * @brief Initialize Helmholtz operator coefficient
169 *
170 */
171 inline void
172 initOperatorCoeffs(T coeffHelmholtz)
173 {
174 std::visit([&](auto &t) { t->initOperatorCoeffs(coeffHelmholtz); },
176 }
177
178 /**
179 * @brief Compute Laplace operator multipled by X
180 *
181 */
182 inline void
183 computeAX(T *dst, T *src)
184 {
185 std::visit([&](auto &t) { t->computeAX(dst, src); }, d_MatrixFreeObject);
186 }
187
188 /**
189 * @brief Distribute constraints on vector src
190 *
191 */
192 inline void
194 {
195 std::visit([&](auto &t) { t->constraintsDistribute(src); },
197 }
198
199 /**
200 * @brief Distribute transpose constraints on vector src
201 *
202 */
203 inline void
205 {
206 std::visit([&](auto &t) { t->constraintsDistributeTranspose(dst, src); },
208 }
209
210 private:
212 };
213
214} // namespace dftfe
215#endif // MatrixFreeWrapper_H_
MatrixFreeWrapperClass(std::uint32_t nDofsPerDim, const MPI_Comm &mpi_comm, const dealii::MatrixFree< 3, double > *matrixFreeDataPtr, const dealii::AffineConstraints< double > &constraintMatrix, const std::shared_ptr< dftfe::linearAlgebra::BLASWrapper< memorySpace > > BLASWrapperPtr, const std::uint32_t dofHandlerID, const std::uint32_t quadratureID, const dftfe::uInt nVectors)
Constructor.
Definition MatrixFreeWrapper.h:135
void initOperatorCoeffs(T coeffHelmholtz)
Initialize Helmholtz operator coefficient.
Definition MatrixFreeWrapper.h:172
void computeAX(T *dst, T *src)
Compute Laplace operator multipled by X.
Definition MatrixFreeWrapper.h:183
void constraintsDistribute(T *src)
Distribute constraints on vector src.
Definition MatrixFreeWrapper.h:193
void constraintsDistributeTranspose(T *dst, T *src)
Distribute transpose constraints on vector src.
Definition MatrixFreeWrapper.h:204
MatrixFreeObject d_MatrixFreeObject
Definition MatrixFreeWrapper.h:211
void init()
Initialize data structures for MatrixFree class.
Definition MatrixFreeWrapper.h:162
Definition BLASWrapper.h:35
MemorySpace
Definition MemorySpaceType.h:33
Definition pseudoPotentialToDftfeConverter.cc:34
std::variant< #define MatrixFreeWrapperTemplates(NDOFSPERDIM) \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ #define MatrixFreeWrapperTemplatesL(NDOFSPERDIM) \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ # 1 "/github/workspace/include/MatrixFreeWrapper.def" 1 MatrixFreeWrapperTemplates(2) MatrixFreeWrapperTemplates(3) MatrixFreeWrapperTemplates(4) MatrixFreeWrapperTemplates(5) MatrixFreeWrapperTemplates(6) MatrixFreeWrapperTemplates(7) MatrixFreeWrapperTemplates(8) MatrixFreeWrapperTemplates(9) MatrixFreeWrapperTemplates(10) MatrixFreeWrapperTemplates(11) MatrixFreeWrapperTemplates(12) MatrixFreeWrapperTemplates(13) MatrixFreeWrapperTemplates(14) MatrixFreeWrapperTemplates(15) MatrixFreeWrapperTemplates(16) MatrixFreeWrapperTemplatesL(17) # 74 "/github/workspace/include/MatrixFreeWrapper.h" 2 > MatrixFreeObject
Datastructure to hold different MatrixFree class objects.
Definition MatrixFreeWrapper.h:39
std::uint32_t uInt
Definition TypeConfig.h:10
operatorList
Definition MatrixFreeDevice.h:37
MatrixFreeObject createMatrixFreeObject(std::uint32_t nDofsPerDim, Args &&...args)
Factory function to create MatrixFree object.
Definition MatrixFreeWrapper.h:106