So I am trying a molecular dynamics simulation, and trying to populate a 3D rectangular volume with random particles which are uniformly distributed throughout the volume. Each molecule has a fixed radius r(sphere), where r can be different for each molecule. So I would want the sphere to be generated in the volume, and then no other sphere should exist within ( 2(r+tolerance) ) distance from that point(the tolerance will be really small, like 10^-6).
Also, the channel will have a specified length, breadth and width, so the randomization should be done within those limits in a single direction with a similar condition above i.e. the molecule should not be generated if the molecule is closer to the wall than its radius+tolerance.
I was initially trying a structured lattice, but that would mean I the number of molecules would be correlated to the dimensions, which is does not work for me. So I wrote the following algorithm(I wanted to paste my code, but it doesn't work and its a big, exaggerated mess right now, and has almost crashed my computer once.
So the logic is
1.) For each particle, make max_X=X-(radius+tol). Do it same for Y and Z.
2.) For each particle, generate random number between 0 and max_X.
3.) calculate distance between each particle and create a list of particles which violate any of the above conditions.
4.) Go over the list and re-generate those particles.
5.) Create another list of violating particle pairs.
6.) Go over. Rinse and repeat until the size of the list is zero.
So, it doesn't work. And I need this code to perform eventually for a large number of particles, so I need it as efficient and OpenMP paralleizable as possible. I am using the standard cliched #pragma omp parallel for method in front of the for loop for parallelizing the calculations, but it doesn't work with or without the pragma, at runtime, after like 5-10 minutes of a superpowered fan noise.
I am someone from a non-coding background who recently started learning writing complex code in C++, so I cannot do something fancy like structures or classes or pointers right now. I am working with std::vectors though. Would love it if you guys could show me a way out, and if you are in and around Raleigh, I will personally drive over and hand you an ice cold beer. Have been trying to do this for days, and is the only major non-functional thing in my code.
Help?!!!
PS: Just to be clear, this isn't homework, else I would have asked the professor by now. Its part of an independent project which I will be freely distributing after completion.