mcvine / acc

Accelerated mcvine engine
0 stars 1 forks source link

Add some initial code for the simple guide component. #19

Closed mtbc closed 2 years ago

mtbc commented 2 years ago

This is very much work in progress, reflecting my initial attempts to get my head into MCViNE and geometry with Python and NumPy. There are many clear to-do's but, as I'm about to take a couple more days off, also catch up with another project, this seems like a good point at which to have @yxqd issue any early course corrections and for @ckendrick to compare with what they've been doing and maybe build on it. Among other things, even if it's a useful start, we still need better testing, any notion of time (depending on how we handle particle speed), handling of reflectivity, vectorized mapping over many neutrons, etc. but, with luck, incremental steps can carry us forward.

yxqd commented 2 years ago

@mtbc That looks like a nice start! I am adding some comments to the code now

mtbc commented 2 years ago

Good point, time should now be sorted. I should have thought of that before: I wasn't enough thinking of per-neutron speeds because, in past related work with light and sound and such, I knew the speed simply from the kind of particle and where it was in the possibly inhomogeneous medium so, given knowledge of the medium, direction was all I needed to figure time. But, not in this application domain!

Please allow position and direction to be 2D arrays of shape (N, 3)

Is the thought that N would range across the neutrons? And position and direction for the whole set of neutrons would be in two different arrays? But we wouldn't be passing an index into the N dimension? Trying to figure what the N is here. If it helps, we can talk about it in our Monday meeting.

Seeing as numba can get LLVM to inline functions, I'd been thinking to have a per-neutron function then wrap it in something that can be vectorized across all the neutrons, having it see just per-row slices (like with apply_along_axis) and mapping any None to numpy.nan values or similar, that a process method would then apply across all the neutrons. I may well be on completely the wrong page though and should add a for loop or use nditer or suchlike. @ckendrick: If it's clear to you, please feel free to go ahead and make the indicated changes on top of my work, as I'm on leave for the rest of the week.

yxqd commented 2 years ago

Sorry for the confusion. The position should be (N,3) numpy array where N is number of neutrons. The direction should really be velocity and it should also be a (N, 3) numpy array so that time of travel (progress in current code) can be calculated. Yes let us talk in the Monday meeting.

Yes I agree for the numba implementation we can create a per-neutron function and then we could use the guvectorize method to process a bunch of neutrons (here is an example: https://github.com/mcvine/acc/blob/7d4fc02509df5a5f2332f74855ba4c58435c9a1a/acc/geometry/onbox.py#L57). But for this exercise we just implement it using numpy method