DFT-EFE
 
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
48#ifndef MatrixFreeWrapper_H_
49#define MatrixFreeWrapper_H_
50#include <variant>
51#include <memory>
52#include "MatrixFree.h"
53
54namespace dftefe
55{
62 using MatrixFreeObject = std::variant<
63#define MatrixFreeWrapperTemplates(NDOFSPERDIM) \
64 std::shared_ptr<dftefe::MatrixFree<double, \
65 dftefe::operatorList::Laplace, \
66 dftefe::utils::MemorySpace::DEVICE, \
67 false, \
68 NDOFSPERDIM, \
69 NDOFSPERDIM, \
70 1, \
71 1>>, \
72 std::shared_ptr<dftefe::MatrixFree<double, \
73 dftefe::operatorList::Helmholtz, \
74 dftefe::utils::MemorySpace::DEVICE, \
75 false, \
76 NDOFSPERDIM, \
77 NDOFSPERDIM, \
78 1, \
79 1>>,
80#define MatrixFreeWrapperTemplatesL(NDOFSPERDIM) \
81 std::shared_ptr<dftefe::MatrixFree<double, \
82 dftefe::operatorList::Laplace, \
83 dftefe::utils::MemorySpace::DEVICE, \
84 false, \
85 NDOFSPERDIM, \
86 NDOFSPERDIM, \
87 1, \
88 1>>, \
89 std::shared_ptr<dftefe::MatrixFree<double, \
90 dftefe::operatorList::Helmholtz, \
91 dftefe::utils::MemorySpace::DEVICE, \
92 false, \
93 NDOFSPERDIM, \
94 NDOFSPERDIM, \
95 1, \
96 1>>
97#include "MatrixFreeWrapper.def"
98#undef MatrixFreeWrapperTemplates
99#undef MatrixFreeWrapperTemplatesL
100 >;
101
106 template <typename T,
107 dftefe::operatorList operatorID,
108 dftefe::utils::MemorySpace memorySpace,
109 bool isComplex,
110 class... Args>
111 inline MatrixFreeObject
112 createMatrixFreeObject(std::uint32_t nDofsPerDim, Args &&...args)
113 {
114 switch (nDofsPerDim)
115 {
116#define MatrixFreeWrapperTemplates(NDOFSPERDIM) \
117 case NDOFSPERDIM: \
118 return MatrixFreeObject( \
119 std::make_shared<dftefe::MatrixFree<T, \
120 operatorID, \
121 memorySpace, \
122 isComplex, \
123 NDOFSPERDIM, \
124 NDOFSPERDIM, \
125 1, \
126 1>>(std::forward<Args>(args)...));
127#define MatrixFreeWrapperTemplatesL(NDOFSPERDIM) \
128 case NDOFSPERDIM: \
129 return MatrixFreeObject( \
130 std::make_shared<dftefe::MatrixFree<T, \
131 operatorID, \
132 memorySpace, \
133 isComplex, \
134 NDOFSPERDIM, \
135 NDOFSPERDIM, \
136 1, \
137 1>>(std::forward<Args>(args)...));
138#include "MatrixFreeWrapper.def"
139#undef MatrixFreeWrapperTemplates
140#undef MatrixFreeWrapperTemplatesL
141 default:
142 throw std::logic_error{"createMatrixFreeObject dispatch failed"};
143 }
144 }
145
150 template <typename T,
151 dftefe::operatorList operatorID,
152 dftefe::utils::MemorySpace memorySpace,
153 bool isComplex>
155 {
156 public:
159 std::uint32_t nDofsPerDim,
160 const MPI_Comm & mpi_comm,
161 const dealii::MatrixFree<3, double> * matrixFreeDataPtr,
162 const dealii::AffineConstraints<double> &constraintMatrix,
163 const std::uint32_t dofHandlerID,
164 const std::uint32_t quadratureID,
165 const dftefe::uInt nVectors)
167 createMatrixFreeObject<T, operatorID, memorySpace, isComplex>(
168 nDofsPerDim,
169 mpi_comm,
170 matrixFreeDataPtr,
171 constraintMatrix,
172 dofHandlerID,
173 quadratureID,
174 nVectors))
175 {}
176
181 inline void
183 {
184 std::visit([&](auto &t) { t->init(); }, d_MatrixFreeObject);
185 }
186
191 inline void
192 initOperatorCoeffs(T coeffHelmholtz)
193 {
194 std::visit([&](auto &t) { t->initOperatorCoeffs(coeffHelmholtz); },
196 }
197
202 inline void
203 computeAX(T *dst, T *src)
204 {
205 std::visit([&](auto &t) { t->computeAX(dst, src); }, d_MatrixFreeObject);
206 }
207
212 inline void
214 {
215 std::visit([&](auto &t) { t->constraintsDistribute(src); },
217 }
218
223 inline void
225 {
226 std::visit([&](auto &t) { t->constraintsDistributeTranspose(dst, src); },
228 }
229
230 private:
232 };
233
234} // namespace dftefe
235#endif // MatrixFreeWrapper_H_
MatrixFreeWrapper class.
Definition: MatrixFreeWrapper.h:155
MatrixFreeWrapperClass(std::uint32_t nDofsPerDim, const MPI_Comm &mpi_comm, const dealii::MatrixFree< 3, double > *matrixFreeDataPtr, const dealii::AffineConstraints< double > &constraintMatrix, const std::uint32_t dofHandlerID, const std::uint32_t quadratureID, const dftefe::uInt nVectors)
Constructor.
Definition: MatrixFreeWrapper.h:158
MatrixFreeObject d_MatrixFreeObject
Definition: MatrixFreeWrapper.h:231
void init()
Initialize data structures for MatrixFree class.
Definition: MatrixFreeWrapper.h:182
void computeAX(T *dst, T *src)
Compute Laplace operator multipled by X.
Definition: MatrixFreeWrapper.h:203
void constraintsDistributeTranspose(T *dst, T *src)
Distribute transpose constraints on vector src.
Definition: MatrixFreeWrapper.h:224
void constraintsDistribute(T *src)
Distribute constraints on vector src.
Definition: MatrixFreeWrapper.h:213
void initOperatorCoeffs(T coeffHelmholtz)
Initialize Helmholtz operator coefficient.
Definition: MatrixFreeWrapper.h:192
MemorySpace
Definition: MemorySpaceType.h:37
dealii includes
Definition: AtomFieldDataSpherical.cpp:31
std::variant< #define MatrixFreeWrapperTemplates(NDOFSPERDIM) #define MatrixFreeWrapperTemplatesL(NDOFSPERDIM) # 97 "/github/workspace/src/electrostatics/MatrixFreeWrapper.h" 2 > MatrixFreeObject
Datastructure to hold different MatrixFree class objects.
Definition: MatrixFreeWrapper.h:100
std::uint64_t uInt
Definition: TypeConfig.h:11
MatrixFreeObject createMatrixFreeObject(std::uint32_t nDofsPerDim, Args &&...args)
Factory function to create MatrixFree object.
Definition: MatrixFreeWrapper.h:112
operatorList
Definition: MatrixFreeDevice.h:33