Skip to content

Commit

Permalink
refactor KDEF macros into meep_internals.hpp
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj committed Jul 20, 2023
1 parent c6015c7 commit 8a41558
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
19 changes: 19 additions & 0 deletions src/meep_internals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 0 additions & 18 deletions src/step_generic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8a41558

Please sign in to comment.