Skip to content

Commit a51b0f5

Browse files
authored
Fix PEC_insulators (#6424)
The vectors holding the parsers were not being setup correctly, leading to out of bounds access. The fix is to add empty parsers for the fields that are normal to the boundaries so that the vectors have the correct length (the number of dimensions). Also, comments were cleaned up for clarity.
1 parent 2376509 commit a51b0f5

File tree

1 file changed

+29
-26
lines changed

1 file changed

+29
-26
lines changed

Source/BoundaryConditions/PEC_Insulator.cpp

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -247,24 +247,24 @@ namespace
247247
/* \brief Sets up the parsers, taking the input data and arranging it as needed
248248
* for the loops, and compiling the parser expressions.
249249
*
250-
* \param[in] set_field_lo flags whether the insulator expressions were specified
251-
* \param[in] set_field_hi flags whether the insulator expressions were specified
252-
* \param[in] parser_field1_lo the parser for the first transverse field at the low boundary
253-
* \param[in] parser_field2_lo the parser for the second transverse field at the low boundary
254-
* \param[in] parser_field1_hi the parser for the first transverse field at the high boundary
255-
* \param[in] parser_field2_hi the parser for the second transverse field at the high boundary
256-
* \param[out] set_fields_x_lo the flags for the field along x at the lower boundary
257-
* \param[out] set_fields_y_lo the flags for the field along y at the lower boundary
258-
* \param[out] set_fields_z_lo the flags for the field along z at the lower boundary
259-
* \param[out] set_fields_x_hi the flags for the field along x at the upper boundary
260-
* \param[out] set_fields_y_hi the flags for the field along y at the upper boundary
261-
* \param[out] set_fields_z_hi the flags for the field along z at the upper boundary
262-
* \param[out] Fx_parsers_lo the parsers for the field along x at the lower boundary
263-
* \param[out] Fy_parsers_lo the parsers for the field along y at the lower boundary
264-
* \param[out] Fz_parsers_lo the parsers for the field along z at the lower boundary
265-
* \param[out] Fx_parsers_hi the parsers for the field along x at the upper boundary
266-
* \param[out] Fy_parsers_hi the parsers for the field along y at the upper boundary
267-
* \param[out] Fz_parsers_hi the parsers for the field along z at the upper boundary
250+
* \param[in] set_field_lo flags whether the insulator expressions were specified at the lower boundaries
251+
* \param[in] set_field_hi flags whether the insulator expressions were specified at the upper boundaries
252+
* \param[in] parser_field1_lo the parser for the first transverse field at the lower boundaries
253+
* \param[in] parser_field2_lo the parser for the second transverse field at the lower boundaries
254+
* \param[in] parser_field1_hi the parser for the first transverse field at the upper boundaries
255+
* \param[in] parser_field2_hi the parser for the second transverse field at the upper boundaries
256+
* \param[out] set_fields_x_lo the flags for the x-field at the lower boundaries
257+
* \param[out] set_fields_y_lo the flags for the y-field at the lower boundaries
258+
* \param[out] set_fields_z_lo the flags for the z-field at the lower boundaries
259+
* \param[out] set_fields_x_hi the flags for the x-field at the upper boundaries
260+
* \param[out] set_fields_y_hi the flags for the y-field at the upper boundaries
261+
* \param[out] set_fields_z_hi the flags for the z-field at the upper boundaries
262+
* \param[out] Fx_parsers_lo the parsers for the x-field at the lower boundaries
263+
* \param[out] Fy_parsers_lo the parsers for the y-field at the lower boundaries
264+
* \param[out] Fz_parsers_lo the parsers for the z-field at the lower boundaries
265+
* \param[out] Fx_parsers_hi the parsers for the x-field at the upper boundaries
266+
* \param[out] Fy_parsers_hi the parsers for the y-field at the upper boundaries
267+
* \param[out] Fz_parsers_hi the parsers for the z-field at the upper boundaries
268268
*/
269269
void SetupFieldParsers(amrex::Vector<int> const & set_field_lo,
270270
amrex::Vector<int> const & set_field_hi,
@@ -292,13 +292,18 @@ namespace
292292
set_fields_y_hi.resize(AMREX_SPACEDIM, false);
293293
set_fields_z_hi.resize(AMREX_SPACEDIM, false);
294294

295+
// For the fields normal to the boundaries, empty parsers are added to the vectors as
296+
// place holders. They will not be used.
297+
295298
#ifndef WARPX_DIM_1D_Z
296299
set_fields_y_lo[0] = set_field_lo[0];
297300
set_fields_z_lo[0] = set_field_lo[0];
298301
set_fields_y_hi[0] = set_field_hi[0];
299302
set_fields_z_hi[0] = set_field_hi[0];
303+
Fx_parsers_lo.push_back(amrex::ParserExecutor<3>());
300304
Fy_parsers_lo.push_back(parser_field1_lo[0]->compile<3>());
301305
Fz_parsers_lo.push_back(parser_field2_lo[0]->compile<3>());
306+
Fx_parsers_hi.push_back(amrex::ParserExecutor<3>());
302307
Fy_parsers_hi.push_back(parser_field1_hi[0]->compile<3>());
303308
Fz_parsers_hi.push_back(parser_field2_hi[0]->compile<3>());
304309
#endif
@@ -308,8 +313,10 @@ namespace
308313
set_fields_x_hi[1] = set_field_hi[1];
309314
set_fields_z_hi[1] = set_field_hi[1];
310315
Fx_parsers_lo.push_back(parser_field1_lo[1]->compile<3>());
316+
Fy_parsers_lo.push_back(amrex::ParserExecutor<3>());
311317
Fz_parsers_lo.push_back(parser_field2_lo[1]->compile<3>());
312318
Fx_parsers_hi.push_back(parser_field1_hi[1]->compile<3>());
319+
Fy_parsers_hi.push_back(amrex::ParserExecutor<3>());
313320
Fz_parsers_hi.push_back(parser_field2_hi[1]->compile<3>());
314321
#endif
315322
#if defined(WARPX_ZINDEX)
@@ -319,8 +326,10 @@ namespace
319326
set_fields_y_hi[WARPX_ZINDEX] = set_field_hi[WARPX_ZINDEX];
320327
Fx_parsers_lo.push_back(parser_field1_lo[WARPX_ZINDEX]->compile<3>());
321328
Fy_parsers_lo.push_back(parser_field2_lo[WARPX_ZINDEX]->compile<3>());
329+
Fz_parsers_lo.push_back(amrex::ParserExecutor<3>());
322330
Fx_parsers_hi.push_back(parser_field1_hi[WARPX_ZINDEX]->compile<3>());
323331
Fy_parsers_hi.push_back(parser_field2_hi[WARPX_ZINDEX]->compile<3>());
332+
Fz_parsers_hi.push_back(amrex::ParserExecutor<3>());
324333
#endif
325334
}
326335

@@ -593,15 +602,9 @@ PEC_Insulator::ApplyPEC_InsulatortoField (
593602

594603
amrex::ParserExecutor<2> const & area_parser = ( (iside == -1) ? m_area_parsers_lo[idim] : m_area_parsers_hi[idim]);
595604

596-
// A special check is needed for Fx and Fz since in 1D cases no parsers will be defined for one
597-
// or the other. Instead, create a dummy ParserExecutor.
598-
amrex::ParserExecutor<3> const & Fx_parser = ( Fx_parsers_lo.size() > 0 ?
599-
( (iside == -1) ? Fx_parsers_lo[idim] : Fx_parsers_hi[idim]) :
600-
amrex::ParserExecutor<3>() );
605+
amrex::ParserExecutor<3> const & Fx_parser = ( (iside == -1) ? Fx_parsers_lo[idim] : Fx_parsers_hi[idim]);
601606
amrex::ParserExecutor<3> const & Fy_parser = ( (iside == -1) ? Fy_parsers_lo[idim] : Fy_parsers_hi[idim]);
602-
amrex::ParserExecutor<3> const & Fz_parser = ( Fz_parsers_lo.size() > 0 ?
603-
( (iside == -1) ? Fz_parsers_lo[idim] : Fz_parsers_hi[idim]) :
604-
amrex::ParserExecutor<3>() );
607+
amrex::ParserExecutor<3> const & Fz_parser = ( (iside == -1) ? Fz_parsers_lo[idim] : Fz_parsers_hi[idim]);
605608

606609
// loop over cells and update fields
607610
amrex::ParallelFor(

0 commit comments

Comments
 (0)