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

Improve statistical particle generation #1127

Conversation

gassmoeller
Copy link
Member

@bangerth: These are some of the changes we talked about on Tuesday, and they partly adress #1035. For a model on my laptop with 1 process, 256 cells, and 500,000 particles and Q1 mapping it saves approximately 40% of the particle generation time (0.45 -> 0.25 seconds), but that will of course change with different number of cells, different geometries, and so on.
Sadly all tests change, because the random number generator is called in a different order (now it first selects cells for all particles, then selects positions for all particles, instead of alternating between the two).
It is hard to see in the test results if the statistical distributions are still correct, but upon visual inspection they look ok (on 1 process and also using multiple processes).
A nice visual side effect of the change is that particle ids at model start are now more regular, because they also increase cell-by-cell, not only process-by-process as before.
In principle this change also allows the more complex creation of particles on the reference cell as we discussed, but since I compute the cell_weight as cell-wise-constant at the moment, it would not be more accurate, it would only save some more time unless we change that as well. Let's first make a note that this is now theoretically possible.

for (types::particle_index current_particle_index = 0; current_particle_index < n_local_particles; ++current_particle_index)
{
// Draw the random number that determines the cell of the particle
const double random_weight = accumulated_cell_weights.back() * uniform_distribution_01(this->random_number_generator);
Copy link
Contributor

Choose a reason for hiding this comment

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

break this line.

Is there a way to just generate a random number in the range [0,accumulated_cell_weights.back()]? This would avoid the multiplication every time. (Not that it's going to make a runtime difference, the multiplication has to happen somewhere. I think it may just be simpler to read.)

@bangerth
Copy link
Contributor

Yes, delightfully short and simple! See if you can do something with the one comment I had, and then merge yourself (assuming the tester is happy).

Thanks!

@bangerth
Copy link
Contributor

Can you squash this into self-contained commits (it's a sequence of fix-ups right now :-)?

There are currently two tests that fail, but they are unrelated to your work. Please merge after squashing.

@gassmoeller gassmoeller force-pushed the improve_statistical_particle_generation branch from 9eaadb2 to 68d32a9 Compare July 18, 2016 16:19
@gassmoeller gassmoeller merged commit bc0cacd into geodynamics:master Jul 18, 2016
@gassmoeller gassmoeller deleted the improve_statistical_particle_generation branch July 18, 2016 16:56
@gassmoeller gassmoeller mentioned this pull request Jul 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants