From 8a41558d94174a4f4e93103e47fd5379dc7dbf08 Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Thu, 20 Jul 2023 15:55:44 -0400 Subject: [PATCH] refactor KDEF macros into meep_internals.hpp --- src/meep_internals.hpp | 19 +++++++++++++++++++ src/step_generic.cpp | 18 ------------------ 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/meep_internals.hpp b/src/meep_internals.hpp index 859cbedbf..939f6a1b6 100644 --- a/src/meep_internals.hpp +++ b/src/meep_internals.hpp @@ -179,4 +179,23 @@ void reduce_array_dimensions(volume where, int full_rank, size_t dims[3], direct size_t stride[3], int &reduced_rank, size_t reduced_dims[3], direction reduced_dirs[3], size_t reduced_stride[3]); +/**** macros used internally by step_generic and friends: ****/ +/* These macros get into the guts of the PLOOP_OVER_VOL loops to + efficiently construct the index k into a PML sigma array. + Basically, k needs to increment by 2 for each increment of one of + LOOP's for-loops, starting at the appropriate corner of the grid_volume, + and these macros define the relevant strides etc. for each loop. + KSTRIDE_DEF defines the relevant strides etc. and goes outside the + LOOP, wheras KDEF defines the k index and goes inside the LOOP. */ +#define KSTRIDE_DEF(dsig, k, is, gv) \ + const int k##0 = is.in_direction(dsig) - gv.little_corner().in_direction(dsig); \ + const int s##k##1 = gv.yucky_direction(0) == dsig ? 2 : 0; \ + const int s##k##2 = gv.yucky_direction(1) == dsig ? 2 : 0; \ + const int s##k##3 = gv.yucky_direction(2) == dsig ? 2 : 0 +#define KDEF(k, dsig) \ + const int k = ((k##0 + s##k##1 * loop_i1) + s##k##2 * loop_i2) + s##k##3 * loop_i3 +#define DEF_k KDEF(k, dsig) +#define DEF_ku KDEF(ku, dsigu) +#define DEF_kw KDEF(kw, dsigw) + } // namespace meep diff --git a/src/step_generic.cpp b/src/step_generic.cpp index 59e0bdc5e..60c27b354 100644 --- a/src/step_generic.cpp +++ b/src/step_generic.cpp @@ -21,24 +21,6 @@ #define RPR realnum *restrict -/* These macros get into the guts of the PLOOP_OVER_VOL loops to - efficiently construct the index k into a PML sigma array. - Basically, k needs to increment by 2 for each increment of one of - LOOP's for-loops, starting at the appropriate corner of the grid_volume, - and these macros define the relevant strides etc. for each loop. - KSTRIDE_DEF defines the relevant strides etc. and goes outside the - LOOP, wheras KDEF defines the k index and goes inside the LOOP. */ -#define KSTRIDE_DEF(dsig, k, is, gv) \ - const int k##0 = is.in_direction(dsig) - gv.little_corner().in_direction(dsig); \ - const int s##k##1 = gv.yucky_direction(0) == dsig ? 2 : 0; \ - const int s##k##2 = gv.yucky_direction(1) == dsig ? 2 : 0; \ - const int s##k##3 = gv.yucky_direction(2) == dsig ? 2 : 0 -#define KDEF(k, dsig) \ - const int k = ((k##0 + s##k##1 * loop_i1) + s##k##2 * loop_i2) + s##k##3 * loop_i3 -#define DEF_k KDEF(k, dsig) -#define DEF_ku KDEF(ku, dsigu) -#define DEF_kw KDEF(kw, dsigw) - using namespace std; namespace meep {