CRPropa / CRPropa3

CRPropa is a public astrophysical simulation framework for propagating extraterrestrial ultra-high energy particles. https://crpropa.github.io/CRPropa3/
https://crpropa.desy.de
GNU General Public License v3.0
68 stars 68 forks source link

Flush of Output.Event3D in a loop for different files names #248

Closed JohnUSP closed 4 years ago

JohnUSP commented 4 years ago

Hy guys, I have the next ishue. I am trying to do a loop to detect the simulated particles at diferent distances of the source, so at each iteration I change the radius of the observer (an Sphere in this case) and the name of the output file where the detected particules should be recorded, but somehow all the particles are flushing to the first file of the loop only. The others files are being generated in blank. The portion of the code with the loop is attached. I would also like to know if there is a more practical way to change the radius of the Sphere Surface at each steap of the loop. Thanks in advantage. outputloop

avvliet commented 4 years ago

What is happening now is that you add an additional observer to the module list each time the loop is run. So the 'n'th run will have 'n' observer spheres all with different radii. You only get output from the first observer sphere because the simulation is stopped when the particle reaches this observer. You can prevent this by setting obs.setDeactivateOnDetection(False)

JohnUSP commented 4 years ago

Yes... but then at each steap of the loop the particules are written down in all the files difined previously, i.e, the fist output file records not only the particles detected in the first loop but also, those simulated in the second and so on. What I want is to record in different files the particles detected for each radius of the sphere.

JohnUSP commented 4 years ago

Yes but in that case, the first file, for example is recording not only the particles of the first loop but also those of the second and so on. What I want is to record in each different file the particules detected for each radius of the sphere.

avvliet commented 4 years ago

To do that you should take the 'sim.run' part out of the loop. Now the simulation is run multiple times each time with 1 more observer. You can just run the simulations once with multiple observers. In this case the particles will be recorded in each different file where each file corresponds to one observer. So take your line 74 and line 76 out of the loop.