DFT-FE 1.3.0-pre
Density Functional Theory With Finite-Elements
Loading...
Searching...
No Matches
feevaluationWrapper.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
18
19#ifndef FEEvaluationWrapper_H_
20#define FEEvaluationWrapper_H_
21#include <variant>
22#include <memory>
23#include <headers.h>
24namespace dftfe
25{
26 constexpr dftfe::Int
28 {
29 return a * 100 + b;
30 }
31
32 template <dftfe::Int components>
34 {
35 using type = std::variant<
36#define FEEvaluationWrapperTemplates(T1, T2) \
37 std::shared_ptr<dealii::FEEvaluation<3, T1, T2, components>>,
38#include "feevaluationWrapper.def"
39#undef FEEvaluationWrapperTemplates
40 std::shared_ptr<dealii::FEEvaluation<3, -1, 1, components>>>;
41 };
42
43 template <>
44 struct FEEvalTrait<3>
45 {
46 using type = std::variant<
47#define FEEvaluationWrapperTemplates(T1, T2) \
48 std::shared_ptr<dealii::FEEvaluation<3, T1, T2, 3>>,
49#include "feevaluationWrapper3Comp.def"
50#undef FEEvaluationWrapperTemplates
51 std::shared_ptr<dealii::FEEvaluation<3, -1, 1, 3>>>;
52 };
53
54
55 template <dftfe::Int components>
57
58
59 template <dftfe::Int components, class... Args>
62 dftfe::Int quadrature,
63 Args &&...args)
64 {
65 const dftfe::Int key = encodeFEEvaluation(feOrder, quadrature);
66 if constexpr (components == 1)
67 {
68 switch (key)
69 {
70#define FEEvaluationWrapperTemplates(T1, T2) \
71 case encodeFEEvaluation(T1, T2): \
72 return FEEvaluationObject<components>( \
73 std::make_shared<dealii::FEEvaluation<3, T1, T2, components>>( \
74 std::forward<Args>(args)...));
75#include "feevaluationWrapper.def"
76#undef FEEvaluationWrapperTemplates
77 default:
79 std::make_shared<dealii::FEEvaluation<3, -1, 1, components>>(
80 std::forward<Args>(args)...));
81 };
82 }
83 if constexpr (components == 3)
84 {
85 switch (key)
86 {
87#define FEEvaluationWrapperTemplates(T1, T2) \
88 case encodeFEEvaluation(T1, T2): \
89 return FEEvaluationObject<components>( \
90 std::make_shared<dealii::FEEvaluation<3, T1, T2, components>>( \
91 std::forward<Args>(args)...));
92#include "feevaluationWrapper3Comp.def"
93#undef FEEvaluationWrapperTemplates
94 default:
96 std::make_shared<dealii::FEEvaluation<3, -1, 1, components>>(
97 std::forward<Args>(args)...));
98 };
99 }
100 }
101
102 template <dftfe::Int components>
104 {
105 public:
106 /// Constructor
108 const dealii::MatrixFree<3, double> &matrixFreeData,
109 const dftfe::uInt matrixFreeVectorComponent,
110 const dftfe::uInt matrixFreeQuadratureComponent)
111 : n_q_points(matrixFreeData.get_n_q_points(matrixFreeQuadratureComponent))
112 {
113 dftfe::Int feOrder =
114 matrixFreeData.get_dof_handler(matrixFreeVectorComponent)
115 .get_fe()
116 .tensor_degree();
117 dftfe::Int quadrature = static_cast<dftfe::Int>(
118 std::round(std::cbrt(static_cast<double>(n_q_points))));
119 d_FEEvaluationObject = std::move(
121 quadrature,
122 matrixFreeData,
123 matrixFreeVectorComponent,
124 matrixFreeQuadratureComponent));
125 }
126
127 template <typename... Args>
128 void
129 reinit(Args &&...args)
130 {
131 std::visit([&](auto &t) { t->reinit(std::forward<Args>(args)...); },
133 }
134
135 template <typename... Args>
136 void
137 read_dof_values(Args &&...args)
138 {
139 std::visit(
140 [&](auto &t) { t->read_dof_values(std::forward<Args>(args)...); },
142 }
143
144 template <typename... Args>
145 void
146 read_dof_values_plain(Args &&...args)
147 {
148 std::visit(
149 [&](auto &t) { t->read_dof_values_plain(std::forward<Args>(args)...); },
151 }
152
153 template <typename... Args>
154 void
155 evaluate(Args &&...args)
156 {
157 std::visit([&](auto &t) { t->evaluate(std::forward<Args>(args)...); },
159 }
160
161 template <typename... Args>
162 void
163 submit_gradient(Args &&...args)
164 {
165 std::visit(
166 [&](auto &t) { t->submit_gradient(std::forward<Args>(args)...); },
168 }
169
170 template <typename... Args>
171 void
172 submit_value(Args &&...args)
173 {
174 std::visit([&](auto &t) { t->submit_value(std::forward<Args>(args)...); },
176 }
177
178 template <typename... Args>
179 decltype(auto)
180 get_value(Args &&...args)
181 {
182 return std::visit(
183 [&](auto &t) -> decltype(auto) {
184 return t->get_value(std::forward<Args>(args)...);
185 },
187 }
188
189 template <typename... Args>
190 decltype(auto)
191 get_gradient(Args &&...args)
192 {
193 return std::visit(
194 [&](auto &t) -> decltype(auto) {
195 return t->get_gradient(std::forward<Args>(args)...);
196 },
198 }
199
200 template <typename... Args>
201 decltype(auto)
202 integrate_value(Args &&...args)
203 {
204 return std::visit(
205 [&](auto &t) -> decltype(auto) {
206 return t->integrate_value(std::forward<Args>(args)...);
207 },
209 }
210
211 template <typename... Args>
212 decltype(auto)
213 get_hessian(Args &&...args)
214 {
215 return std::visit(
216 [&](auto &t) -> decltype(auto) {
217 return t->get_hessian(std::forward<Args>(args)...);
218 },
220 }
221
222 template <typename... Args>
223 void
224 integrate(Args &&...args)
225 {
226 std::visit([&](auto &t) { t->integrate(std::forward<Args>(args)...); },
228 }
229
230 template <typename... Args>
231 decltype(auto)
232 quadrature_point(Args &&...args)
233 {
234 return std::visit(
235 [&](auto &t) -> decltype(auto) {
236 return t->quadrature_point(std::forward<Args>(args)...);
237 },
239 }
240
241 template <typename... Args>
242 decltype(auto)
243 JxW(Args &&...args)
244 {
245 return std::visit(
246 [&](auto &t) -> decltype(auto) {
247 return t->JxW(std::forward<Args>(args)...);
248 },
250 }
251
252 template <typename... Args>
253 void
255 {
256 std::visit(
257 [&](auto &t) {
258 t->distribute_local_to_global(std::forward<Args>(args)...);
259 },
261 }
262
263
265
266 private:
268 };
269
270} // namespace dftfe
271
272#endif
const dftfe::uInt n_q_points
Definition feevaluationWrapper.h:264
FEEvaluationWrapperClass(const dealii::MatrixFree< 3, double > &matrixFreeData, const dftfe::uInt matrixFreeVectorComponent, const dftfe::uInt matrixFreeQuadratureComponent)
Constructor.
Definition feevaluationWrapper.h:107
decltype(auto) quadrature_point(Args &&...args)
Definition feevaluationWrapper.h:232
void read_dof_values(Args &&...args)
Definition feevaluationWrapper.h:137
decltype(auto) get_value(Args &&...args)
Definition feevaluationWrapper.h:180
void read_dof_values_plain(Args &&...args)
Definition feevaluationWrapper.h:146
void submit_gradient(Args &&...args)
Definition feevaluationWrapper.h:163
void integrate(Args &&...args)
Definition feevaluationWrapper.h:224
decltype(auto) JxW(Args &&...args)
Definition feevaluationWrapper.h:243
FEEvaluationObject< components > d_FEEvaluationObject
Definition feevaluationWrapper.h:267
decltype(auto) integrate_value(Args &&...args)
Definition feevaluationWrapper.h:202
void reinit(Args &&...args)
Definition feevaluationWrapper.h:129
void distribute_local_to_global(Args &&...args)
Definition feevaluationWrapper.h:254
decltype(auto) get_hessian(Args &&...args)
Definition feevaluationWrapper.h:213
decltype(auto) get_gradient(Args &&...args)
Definition feevaluationWrapper.h:191
void evaluate(Args &&...args)
Definition feevaluationWrapper.h:155
void submit_value(Args &&...args)
Definition feevaluationWrapper.h:172
Definition pseudoPotentialToDftfeConverter.cc:34
FEEvaluationObject< components > createFEEvaluationObject(dftfe::Int feOrder, dftfe::Int quadrature, Args &&...args)
Definition feevaluationWrapper.h:61
constexpr dftfe::Int encodeFEEvaluation(dftfe::Int a, dftfe::Int b)
Definition feevaluationWrapper.h:27
typename FEEvalTrait< components >::type FEEvaluationObject
Definition feevaluationWrapper.h:56
std::uint32_t uInt
Definition TypeConfig.h:10
std::int32_t Int
Definition TypeConfig.h:11
std::variant< #define FEEvaluationWrapperTemplates(T1, T2) \ # 1 "/github/workspace/include/feevaluationWrapper3Comp.def" 1 FEEvaluationWrapperTemplates(1, 2) FEEvaluationWrapperTemplates(1, 3) FEEvaluationWrapperTemplates(1, 4) FEEvaluationWrapperTemplates(1, 5) FEEvaluationWrapperTemplates(1, 6) FEEvaluationWrapperTemplates(1, 7) FEEvaluationWrapperTemplates(1, 8) FEEvaluationWrapperTemplates(1, 9) FEEvaluationWrapperTemplates(1, 10) FEEvaluationWrapperTemplates(1, 11) FEEvaluationWrapperTemplates(1, 12) FEEvaluationWrapperTemplates(1, 13) FEEvaluationWrapperTemplates(1, 14) # 49 "/github/workspace/include/feevaluationWrapper.h" 2 std::shared_ptr< dealii::FEEvaluation< 3, -1, 1, 3 > > > type
Definition feevaluationWrapper.h:46
Definition feevaluationWrapper.h:34
std::variant< #define FEEvaluationWrapperTemplates(T1, T2) \ # 1 "/github/workspace/include/feevaluationWrapper.def" 1 FEEvaluationWrapperTemplates(1, 2) FEEvaluationWrapperTemplates(1, 4) FEEvaluationWrapperTemplates(2, 3) FEEvaluationWrapperTemplates(2, 5) FEEvaluationWrapperTemplates(3, 4) FEEvaluationWrapperTemplates(3, 6) FEEvaluationWrapperTemplates(4, 5) FEEvaluationWrapperTemplates(4, 7) FEEvaluationWrapperTemplates(5, 6) FEEvaluationWrapperTemplates(5, 8) FEEvaluationWrapperTemplates(6, 7) FEEvaluationWrapperTemplates(6, 9) FEEvaluationWrapperTemplates(7, 8) FEEvaluationWrapperTemplates(7, 10) FEEvaluationWrapperTemplates(8, 9) FEEvaluationWrapperTemplates(8, 11) FEEvaluationWrapperTemplates(9, 10) FEEvaluationWrapperTemplates(9, 12) FEEvaluationWrapperTemplates(10, 11) FEEvaluationWrapperTemplates(10, 13) FEEvaluationWrapperTemplates(11, 12) FEEvaluationWrapperTemplates(11, 14) FEEvaluationWrapperTemplates(12, 13) FEEvaluationWrapperTemplates(12, 15) FEEvaluationWrapperTemplates(13, 14) FEEvaluationWrapperTemplates(13, 16) FEEvaluationWrapperTemplates(14, 15) FEEvaluationWrapperTemplates(14, 17)# 38 "/github/workspace/include/feevaluationWrapper.h" 2 std::shared_ptr< dealii::FEEvaluation< 3, -1, 1, components > > > type
Definition feevaluationWrapper.h:35