@@ -1316,12 +1316,14 @@ struct ParentCellStack {
13161316 visited_cells_;
13171317};
13181318
1319- vector<ParentCell> Cell::find_parent_cells (int32_t instance) const
1319+ vector<ParentCell> Cell::find_parent_cells (
1320+ int32_t instance, Position* hint) const
13201321{
13211322 ParentCellStack stack;
13221323 // start with this cell's universe
13231324 int32_t prev_univ_idx;
13241325 int32_t univ_idx = this ->universe_ ;
1326+ bool hint_used = false ;
13251327
13261328 while (true ) {
13271329 const auto & univ = model::universes[univ_idx];
@@ -1350,26 +1352,38 @@ vector<ParentCell> Cell::find_parent_cells(int32_t instance) const
13501352 const auto & lattice = model::lattices[cell->fill_ ];
13511353 const auto & lattice_univs = lattice->universes_ ;
13521354
1353- // start search for universe
1354- auto lat_it = lattice_univs.begin ();
1355- while (true ) {
1356- // find the next lattice cell with this universe
1357- lat_it = std::find (lat_it, lattice_univs.end (), univ_idx);
1358- if (lat_it == lattice_univs.end ())
1355+ // if a hint position is provided, look up the lattice cell
1356+ // for that position
1357+ if (hint && !hint_used) {
1358+ std::array<int , 3 > hint_idx;
1359+ lattice->get_indices (*hint, Direction (0.0 , 0.0 , 0.0 ), hint_idx);
1360+ int hint_offset = lattice->get_flat_index (hint_idx);
1361+ if (univ_idx == lattice_univs[hint_offset]) {
1362+ hint_used = true ;
1363+ stack.push (univ_idx, {model::cell_map[cell->id_ ], hint_offset});
1364+ }
1365+ } else {
1366+ // start search for universe
1367+ auto lat_it = lattice_univs.begin ();
1368+ while (true ) {
1369+ // find the next lattice cell with this universe
1370+ lat_it = std::find (lat_it, lattice_univs.end (), univ_idx);
1371+ if (lat_it == lattice_univs.end ())
1372+ break ;
1373+
1374+ int lattice_idx = lat_it - lattice_univs.begin ();
1375+
1376+ // move iterator forward one to avoid finding the same entry
1377+ lat_it++;
1378+ if (stack.visited (
1379+ univ_idx, {model::cell_map[cell->id_ ], lattice_idx}))
1380+ continue ;
1381+
1382+ // add this cell and lattice index to the stack and exit loop
1383+ stack.push (univ_idx, {model::cell_map[cell->id_ ], lattice_idx});
1384+ univ_idx = cell->universe_ ;
13591385 break ;
1360-
1361- int lattice_idx = lat_it - lattice_univs.begin ();
1362-
1363- // move iterator forward one to avoid finding the same entry
1364- lat_it++;
1365- if (stack.visited (
1366- univ_idx, {model::cell_map[cell->id_ ], lattice_idx}))
1367- continue ;
1368-
1369- // add this cell and lattice index to the stack and exit loop
1370- stack.push (univ_idx, {model::cell_map[cell->id_ ], lattice_idx});
1371- univ_idx = cell->universe_ ;
1372- break ;
1386+ }
13731387 }
13741388 }
13751389 // if we've updated the universe, break
@@ -1403,7 +1417,7 @@ vector<ParentCell> Cell::find_parent_cells(int32_t instance) const
14031417}
14041418
14051419std::unordered_map<int32_t , vector<int32_t >> Cell::get_contained_cells (
1406- int32_t instance) const
1420+ int32_t instance, Position* hint ) const
14071421{
14081422 std::unordered_map<int32_t , vector<int32_t >> contained_cells;
14091423
@@ -1412,7 +1426,7 @@ std::unordered_map<int32_t, vector<int32_t>> Cell::get_contained_cells(
14121426 return contained_cells;
14131427
14141428 // find the pathway through the geometry to this cell
1415- vector<ParentCell> parent_cells = this ->find_parent_cells (instance);
1429+ vector<ParentCell> parent_cells = this ->find_parent_cells (instance, hint );
14161430
14171431 // if this cell is filled w/ a material, it contains no other cells
14181432 if (type_ != Fill::MATERIAL) {
0 commit comments