5#ifndef IPPL_LAPLACE_HELPERS_H
6#define IPPL_LAPLACE_HELPERS_H
12 constexpr static unsigned dim = E::dim;
18 template <
typename... Idx>
19 KOKKOS_INLINE_FUNCTION
auto operator()(
const Idx... args)
const {
20 using index_type = std::tuple_element_t<0, std::tuple<Idx...>>;
21 using T =
typename E::Mesh_t::value_type;
23 index_type coords[dim] = {args...};
24 auto&& center =
apply(u_m, coords);
25 for (
unsigned d = 0; d < dim; d++) {
26 index_type coords[dim] = {args...};
29 auto&& left =
apply(u_m, coords);
32 auto&& right =
apply(u_m, coords);
33 res += (2.0 * center - left - right);
45 sizeof(E) + sizeof(typename E::Mesh_t::vector_type)
46 + 2 * sizeof(typename E::Layout_t::NDIndex_t)
48 constexpr static unsigned dim = E::dim;
49 using value_type =
typename E::value_type;
53 unsigned nghosts,
const typename E::Layout_t::NDIndex_t& ldom,
54 const typename E::Layout_t::NDIndex_t& domain)
64 template <
typename... Idx>
65 KOKKOS_INLINE_FUNCTION
auto operator()(
const Idx... args)
const {
66 using index_type = std::tuple_element_t<0, std::tuple<Idx...>>;
67 using T =
typename E::Mesh_t::value_type;
70 for (
unsigned d = 0; d < dim; d++) {
71 index_type coords[dim] = {args...};
72 const int global_index = coords[d] + ldom_m[d].first() - nghosts_m;
73 const int size = domain_m.length()[d];
74 const bool not_left_boundary = (global_index != 0);
75 const bool right_boundary = (global_index == size - 1);
78 auto&& left =
apply(u_m, coords);
81 auto&& right =
apply(u_m, coords);
86 res += hvector_m[d] * (not_left_boundary * left + right_boundary * right);
92 using Mesh_t =
typename E::Mesh_t;
93 using Layout_t =
typename E::Layout_t;
95 using domain_type =
typename Layout_t::NDIndex_t;
97 const vector_type hvector_m;
98 const unsigned nghosts_m;
99 const domain_type ldom_m;
100 const domain_type domain_m;
103 template <
typename E>
106 sizeof(E) + sizeof(typename E::Mesh_t::vector_type)
107 + 2 * sizeof(typename E::Layout_t::NDIndex_t)
108 + sizeof(unsigned)> {
109 constexpr static unsigned dim = E::dim;
110 using value_type =
typename E::value_type;
114 unsigned nghosts,
const typename E::Layout_t::NDIndex_t& ldom,
115 const typename E::Layout_t::NDIndex_t& domain)
120 , domain_m(domain) {}
125 template <
typename... Idx>
126 KOKKOS_INLINE_FUNCTION
auto operator()(
const Idx... args)
const {
127 using index_type = std::tuple_element_t<0, std::tuple<Idx...>>;
128 using T =
typename E::Mesh_t::value_type;
131 for (
unsigned d = 0; d < dim; d++) {
132 index_type coords[dim] = {args...};
133 const int global_index = coords[d] + ldom_m[d].first() - nghosts_m;
134 const int size = domain_m.length()[d];
135 const bool left_boundary = (global_index == 0);
136 const bool not_right_boundary = (global_index != size - 1);
139 auto&& left =
apply(u_m, coords);
142 auto&& right =
apply(u_m, coords);
147 res += hvector_m[d] * (left_boundary * left + not_right_boundary * right);
153 using Mesh_t =
typename E::Mesh_t;
154 using Layout_t =
typename E::Layout_t;
156 using domain_type =
typename Layout_t::NDIndex_t;
158 const vector_type hvector_m;
159 const unsigned nghosts_m;
160 const domain_type ldom_m;
161 const domain_type domain_m;
164 template <
typename E>
166 :
public Expression<meta_upper_and_lower_laplace<E>,
167 sizeof(E) + sizeof(typename E::Mesh_t::vector_type)> {
168 constexpr static unsigned dim = E::dim;
169 using value_type =
typename E::value_type;
174 , hvector_m(hvector) {}
179 template <
typename... Idx>
180 KOKKOS_INLINE_FUNCTION
auto operator()(
const Idx... args)
const {
181 using index_type = std::tuple_element_t<0, std::tuple<Idx...>>;
182 using T =
typename E::Mesh_t::value_type;
184 for (
unsigned d = 0; d < dim; d++) {
185 index_type coords[dim] = {args...};
187 auto&& left =
apply(u_m, coords);
189 auto&& right =
apply(u_m, coords);
190 res += hvector_m[d] * (left + right);
196 using vector_type =
typename E::Mesh_t::vector_type;
198 const vector_type hvector_m;
206 template <
typename Field>
208 constexpr unsigned Dim = Field::dim;
221 template <
typename Field>
223 constexpr unsigned Dim = Field::dim;
236 template <
typename Field>
238 constexpr unsigned Dim = Field::dim;
240 using mesh_type =
typename Field::Mesh_t;
241 mesh_type& mesh = u.get_mesh();
242 typename mesh_type::vector_type hvector(0);
243 for (
unsigned d = 0; d < Dim; d++) {
244 hvector[d] = 1.0 / Kokkos::pow(mesh.getMeshSpacing(d), 2);
246 const auto& layout = u.getLayout();
247 unsigned nghosts = u.getNghost();
248 const auto& ldom = layout.getLocalNDIndex();
249 const auto& domain = layout.getDomain();
257 template <
typename Field>
259 constexpr unsigned Dim = Field::dim;
272 template <
typename Field>
274 constexpr unsigned Dim = Field::dim;
276 using mesh_type =
typename Field::Mesh_t;
277 mesh_type& mesh = u.get_mesh();
278 typename mesh_type::vector_type hvector(0);
279 for (
unsigned d = 0; d < Dim; d++) {
280 hvector[d] = 1.0 / Kokkos::pow(mesh.getMeshSpacing(d), 2);
282 const auto& layout = u.getLayout();
283 unsigned nghosts = u.getNghost();
284 const auto& ldom = layout.getLocalNDIndex();
285 const auto& domain = layout.getDomain();
293 template <
typename Field>
295 constexpr unsigned Dim = Field::dim;
308 template <
typename Field>
310 constexpr unsigned Dim = Field::dim;
312 using mesh_type =
typename Field::Mesh_t;
313 mesh_type& mesh = u.get_mesh();
314 typename mesh_type::vector_type hvector(0);
315 for (
unsigned d = 0; d < Dim; d++) {
316 hvector[d] = 1.0 / Kokkos::pow(mesh.getMeshSpacing(d), 2);
328 template <
typename Field>
330 constexpr unsigned Dim = Field::dim;
331 using mesh_type =
typename Field::Mesh_t;
332 mesh_type& mesh = u.get_mesh();
335 typename mesh_type::vector_type hvector(0);
336 for (
unsigned d = 0; d < Dim; ++d) {
337 hvector[d] = Kokkos::pow(mesh.getMeshSpacing(d), 2);
338 sum += hvector[d] * Kokkos::pow(mesh.getMeshSpacing((d + 1) % Dim), 2);
339 factor *= hvector[d];
342 return 0.5 * (factor / sum);
345 template <
typename Field>
346 double diagonal_laplace(
Field& u) {
347 constexpr unsigned Dim = Field::dim;
348 using mesh_type =
typename Field::Mesh_t;
349 mesh_type& mesh = u.get_mesh();
351 for (
unsigned d = 0; d < Dim; ++d) {
352 sum += 1 / (Kokkos::pow(mesh.getMeshSpacing(d), 2));
359 template <
typename Field>
360 void mult(
Field& u,
const double c) {
361 using view_type =
typename Field::view_type;
363 view_type view = u.getView();
365 Kokkos::parallel_for(
367 KOKKOS_LAMBDA(
int i,
int j,
int k) { view(i, j, k) *= c; });
policy_type< execution_space, PolicyArgs... > getFieldRangePolicy(const int nghost=0) const
Definition BareField.h:183
KOKKOS_INLINE_FUNCTION constexpr decltype(auto) apply(const View &view, const Coords &coords)
Definition IpplOperations.h:64
detail::meta_poisson< Field > poisson(Field &u)
Definition LaplaceHelpers.h:207
detail::meta_upper_laplace< Field > upper_laplace(Field &u)
Definition LaplaceHelpers.h:258
detail::meta_upper_and_lower_laplace< Field > upper_and_lower_laplace_no_comm(Field &u)
Definition LaplaceHelpers.h:309
detail::meta_lower_laplace< Field > lower_laplace(Field &u)
Definition LaplaceHelpers.h:222
double negative_inverse_diagonal_laplace(Field &u)
Definition LaplaceHelpers.h:329
detail::meta_upper_laplace< Field > upper_laplace_no_comm(Field &u)
Definition LaplaceHelpers.h:273
detail::meta_lower_laplace< Field > lower_laplace_no_comm(Field &u)
Definition LaplaceHelpers.h:237
detail::meta_upper_and_lower_laplace< Field > upper_and_lower_laplace(Field &u)
Definition LaplaceHelpers.h:294
Definition IpplExpressions.h:26