Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validation check in loop_in_chunks #2040

Merged
merged 9 commits into from
Apr 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/loop_in_chunks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,18 @@ void fields::loop_in_chunks(field_chunkloop chunkloop, void *chunkloop_data, con
vec s0(gv.dim), e0(gv.dim), s1(gv.dim), e1(gv.dim);
compute_boundary_weights(gv, where, is, ie, snap_empty_dimensions, s0, e0, s1, e1);

int original_vol = 1;
LOOP_OVER_DIRECTIONS(gv.dim, d){
if (boundaries[High][d] == Periodic && boundaries[Low][d] == Periodic) {
original_vol *= (ie.in_direction(d) - is.in_direction(d))/2+1;
} else {
int vol_size_d = (min(user_volume.big_owned_corner(cgrid), ie).in_direction(d) - max(user_volume.little_owned_corner(cgrid),is).in_direction(d))/2+1;
stevengj marked this conversation as resolved.
Show resolved Hide resolved
original_vol *= (vol_size_d > 0 ? vol_size_d : 0);
}
}

// loop over symmetry transformations of the chunks:
int vol_sum = 0;
for (int sn = 0; sn < (use_symmetry ? S.multiplicity() : 1); ++sn) {
component cS = S.transform(cgrid, -sn);
volume gvS = S.transform(gv.surroundings(), sn);
Expand Down Expand Up @@ -406,7 +417,7 @@ void fields::loop_in_chunks(field_chunkloop chunkloop, void *chunkloop_data, con
grid_volume gvu(chunks[i]->gv);
ivec _iscoS(S.transform(gvu.little_owned_corner(cS), sn));
ivec _iecoS(S.transform(gvu.big_owned_corner(cS), sn));
ivec iscoS(max(user_volume.little_owned_corner(cgrid), min(_iscoS, _iecoS))), iecoS(max(_iscoS, _iecoS)); // fix ordering due to to transform
ivec iscoS(max(user_volume.little_owned_corner(cgrid), min(_iscoS, _iecoS))), iecoS(min(user_volume.big_owned_corner(cgrid), max(_iscoS, _iecoS))); // fix ordering due to to transform
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A potential bug of #1895 is exposed and fixed by this PR. Previously, the grid_volume gvu was thought to be always inside the big_owned_corner of the user_volume so min wasn't taken.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to know the source of this being violated…


//With symmetry, the upper half of the original chunk is kept and includes one extra pixel.
//When looped over all symmetries, pixels outside the lower boundary "user_volume.little_owned_corner(cgrid)" is excluded.
Expand Down Expand Up @@ -496,6 +507,11 @@ void fields::loop_in_chunks(field_chunkloop chunkloop, void *chunkloop_data, con

chunkloop(chunks[i], i, cS, isc, iec, s0c, s1c, e0c, e1c, dV0, dV1,
shifti, ph, S, sn, chunkloop_data);
int loop_vol = 1;
LOOP_OVER_DIRECTIONS(gv.dim, d){
loop_vol *= (iec.in_direction(d) - isc.in_direction(d))/2+1;
}
vol_sum += loop_vol;
}
}

Expand All @@ -508,6 +524,8 @@ void fields::loop_in_chunks(field_chunkloop chunkloop, void *chunkloop_data, con
}
} while (ishift != min_ishift);
}
int vol_sum_all = sum_to_all(vol_sum);
if (use_symmetry && vol_sum_all != original_vol) master_printf("WARNING vol mismatch:, original_vol %i, looped vol_sum %i \n", original_vol, vol_sum_all);
stevengj marked this conversation as resolved.
Show resolved Hide resolved
}

} // namespace meep