MCPcopy Create free account
hub / github.com/NanoComp/meep / get_source_slice_chunkloop

Function get_source_slice_chunkloop

src/array_slice.cpp:195–246  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

193}
194
195static void get_source_slice_chunkloop(fields_chunk *fc, int ichnk, component cgrid, ivec is,
196 ivec ie, vec s0, vec s1, vec e0, vec e1, double dV0,
197 double dV1, ivec shift, complex<double> shift_phase,
198 const symmetry &S, int sn, void *data_) {
199
200 UNUSED(ichnk);
201 UNUSED(cgrid);
202 UNUSED(is);
203 UNUSED(ie);
204 UNUSED(s0);
205 UNUSED(s1);
206 UNUSED(e0);
207 UNUSED(e1);
208 UNUSED(dV0);
209 UNUSED(dV1);
210 UNUSED(shift_phase);
211
212 source_slice_data *data = (source_slice_data *)data_;
213 ivec slice_imin = data->slice_imin, slice_imax = data->slice_imax;
214 ndim dim = fc->gv.dim;
215
216 // the following works in all cases except cylindrical coordinates
217 ptrdiff_t NY = 1, NZ = 1;
218 if (has_direction(dim, Z)) NZ = ((slice_imax - slice_imin).in_direction(Z) / 2) + 1;
219 if (has_direction(dim, Y)) NY = ((slice_imax - slice_imin).in_direction(Y) / 2) + 1;
220
221 for (int ft = 0; ft < NUM_FIELD_TYPES; ft++)
222 for (const src_vol &s : fc->get_sources(static_cast<field_type>(ft))) {
223 component cS = S.transform(data->source_component, -sn);
224 if (s.c != cS) continue;
225
226 // loop over point sources in this src_vol. for each point source,
227 // the src_vol stores the amplitude and the global index of the
228 // symmetry-parent grid point, from which we need to compute the
229 // local index of the symmetry-child grid point within this
230 // slice (that is, if it even lies within the slice)
231 for (size_t npt = 0; npt < s.num_points(); npt++) {
232 const complex<double> &amp = s.amplitude_at(npt);
233 ptrdiff_t chunk_index = s.index_at(npt);
234 ivec iloc_parent = fc->gv.iloc(Dielectric, chunk_index);
235 ivec iloc_child = S.transform(iloc_parent, sn) + shift;
236 if (!in_subgrid(slice_imin, iloc_child, slice_imax)) continue; // source point outside slice
237 ivec slice_offset = iloc_child - slice_imin;
238 ptrdiff_t slice_index = 0;
239 // the following works to set the slice_index in all cases except cylindrical coordinates
240 if (has_direction(dim, Z)) slice_index += slice_offset.in_direction(Z) / 2;
241 if (has_direction(dim, Y)) slice_index += NZ * slice_offset.in_direction(Y) / 2;
242 if (has_direction(dim, X)) slice_index += NY * NZ * slice_offset.in_direction(X) / 2;
243 data->slice[slice_index] = amp;
244 }
245 }
246}
247
248/***************************************************************/
249/* callback function passed to loop_in_chunks to fill array slice */

Callers

nothing calls this directly

Calls 7

has_directionFunction · 0.85
in_subgridFunction · 0.85
num_pointsMethod · 0.80
index_atMethod · 0.80
ilocMethod · 0.80
in_directionMethod · 0.45
transformMethod · 0.45

Tested by

no test coverage detected