celeritas-project / celeritas

Celeritas is a new Monte Carlo transport code designed to accelerate scientific discovery in high energy physics by improving detector simulation throughput and energy efficiency using GPUs.
https://celeritas-project.github.io/celeritas/
Other
65 stars 35 forks source link

Implement short-circuit volume evaluation using infix notation #1282

Open sethrj opened 5 months ago

sethrj commented 5 months ago

Based off some still unpublished but available research by @paulromano et al., there could be substantial savings in the way that we evaluate point-in-volume for initialization and surface crossing in ORANGE. (It's also used for distance-to-boundary for "complex" and "background" volumes since internal surface crossings have to be evaluated.)

I think we can break it down into the following steps:

  1. Develop an on-device InfixEvaluator that applies a function f(literal) -> bool (where literal usually means a surface index possibly with negation) and returns the evaulated result, using short circuit logic. (#1286)
  2. Add a CSG "simplifier" that replaces negated joins with the opposite kind of join using DeMorgan's laws. (#1289)
  3. Add a utility to generate infix notation from the simplified tree
  4. Add a utility to import from postfix notation (external JSON) to CSG tree for SCALE compatibility (@sethrj )
  5. Pass an infix logic representation rather than prefix through the OrangeInput into the params data

After using the infix evalutor and comparing performance, then we can replace the "precalculate surface senses" operation with "on-the-fly surface senses".

sethrj commented 5 months ago

Question for @paulromano : on-the-fly sense evaluation works for "point in volume" but might be difficult for "distance to boundary" in the case with internal surface crossings. To do that right now, we precalculate all the surfaces with the starting point, progressively move through nearest surfaces, flip the senses as we cross them, and evaluate "inside" at each one of those points. For the internal surface case, do you re-evaluate at every internal surface crossing? (I guess we could probably cache just a single surface state rather than all of them...?)