Skip to content

Speed up initialization of boundary conditions onto the grid #85

Open

Description

@lmh91

Before the electric potential is calculated via SOR, the initial boundary conditions are applied onto the grid
and some constant weights (needed in the SOR) are precalculated. This also happens after each grid refinement.

If there are many objects in the world, e.g. highly pixelated detectors, and the grid becomes finer and finer,
these precalculations actually can take quite some time.

There are some ways to improve this:

  • Get rid of unnecessary point conversions
    The time critical part is the lookup to which object each individual point belongs: the in-method.
    Right now, we only parse the grid point in form of the coordinate system of the world, e.g. cylindrical coordinates, to this method. Depending on the geometry of the object, the parsed point might be converted into the other coordinate system, e.g. cartesian. And this several times. We should do this just once and parse the point in both forms to the in methods.

  • Parallize (Improve application of boundary conditions #206)
    Right now, no multithreading is used here.
    But the loop running over the grid points can be parallized.

  • Remove allocations in in method for larger CSG's
    See Allocations in pt in CSG for large CSG's #207

  • Clustering of objects
    Divide the grid in subgrids and add an external additinal loop running over those subgrids (in parallel).
    But before executing this loop, all objects should be assigned to all subgrids in which they might be located.
    Thus, in each subgrid there are less objects to be checked reducing the calls of in.
    This might also be used in order to speed up the charge drift.

Activity

  1. added
    performance
    on Oct 30, 2020
  2. added this to the milestone on Oct 16, 2021
  3. modified the milestones: , v1.0.0 on Mar 10, 2022
  4. oschulz commented on Jul 19, 2026

    @oschulz
    Member

    Status update from the 2026-07 review branch:

    • Per-object bounding-sphere culling (commit d55919c): every classification
      loop now skips the CSG in tree walk for grid points provably outside a
      conservative bounding sphere of the object (primitive extremum + set-algebra
      for union/difference/intersection). Point classification on a 3.4M-point BEGe
      grid drops 2.2 s → 1.1 s with bit-identical potentials, point types and
      impurity scales. This is a lightweight take on the "clustering of objects"
      idea — per-object bounding volume against the point instead of subgrid
      assignment — with none of the bookkeeping.
    • Single coordinate conversion (commit 8d04cb3): the culling already needs
      the Cartesian form of each cylindrical grid point; it is now passed to the
      containment test too, so primitives no longer re-convert the CylindricalPoint —
      the first unchecked item of this issue, for the classification loops.
      Honest numbers: after culling this is only ~2 % further (culled points never
      reach the tree walk), so the box is checked mostly structurally; it matters
      more for many-object detectors.

    Remaining from the original list, still open:

    • The conversion is still performed once per object sweep, not once per grid
      point — sharing it requires inverting the loop nesting (objects outer → points
      outer), which would also fix the current thread oversubscription when several
      classification passes run.
    • True spatial clustering/subgrids would further help highly pixelated
      detectors, where many objects' spheres overlap each grid region — and could,
      as noted here originally, speed up charge drift too.
  5. fhagemann commented on Nov 17, 2026

    @fhagemann
    Collaborator

    Check whether the bounding_sphere implementation in #644 is considered a fix for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

performance

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions