void Particle::find_current_cell(unsigned int depth){ bool cell_found=false; for (auto it = patch_around_cell.begin(); it != patch_around_cell.end(); ++it){ if ((*it)->point_inside(pos)){ current_cell=*it; old_cell=current_cell; cell_found=true; build_patch(1); break; } } if(!cell_found){ ++depth; build_patch(depth); this->find_current_cell(depth); } }
I am suspecting a brutal acceleration of the electrons motion to happen somewhere around 300 iterations. Which is physically acceptable but could nevertheless cause the patching method to fail.Yet, if the patch depth is indeed going to "infinity" (according to the implementation of find_current_cell hereabove), I would rather expect the patch to grow bigger until it includes the cell which contains the particle.
I fixed a number of issues and the patching method is now operational.
It works significantly faster than the global search I had implemented before, and I think that I can still improve the code.
More specifically, each patch around a particle only contains the cell where the particle was found at the last iteration.
If the particle is no longer inside this cell, the patch grows until it eventually contains the particle.
The issue here is that when the patch grows in size, it is comprised that are mostly empty ( since they already were in the old patch)
Therefore, I would need a way to compare the old patch and the new patch in order to derive their difference ( in the same meaning as in std::set_difference), so that their difference new_cell can be searched for the particle.
However, a naive implementation of std::set_difference (old_patch.begin (), old_patch.end (), new_patch.begin (), new_patch.end (), std::inserter (new_cell)) did not yield the expected result, as new_cells remained empty.
A patch is defined as a std::set <dealii <DoFHandler<2>::cell_iterator > ( see line 410 of the linked page)
Is there an alternative way to extract the new cells from the knowledge of the old_patch and the new patch? If I had a way to compare two cell_iterators, I could come up with something doing the job. But I would prefer to use std::set_difference instead...
Thank you,
Benjamin Bercovici
Ps: you can find the implementation of Particle::build_patch () at the following location https://github.com/bbercovici/uiuc-cpp/blob/master/pic7.0/mycode/source/Particle.cc