Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-13 11:00:06

0001 //===-- VecGeom/management/BVHSubdivisionOptions.h ------------------*- C++ -*-===//
0002 //
0003 /// @file BVHSubdivisionOptions.h
0004 /// @brief Shared host-side configuration selectors for BVH AABB subdivision.
0005 //
0006 //===----------------------------------------------------------------------===//
0007 
0008 #ifndef VECGEOM_MANAGEMENT_BVHSUBDIVISIONOPTIONS_H_
0009 #define VECGEOM_MANAGEMENT_BVHSUBDIVISIONOPTIONS_H_
0010 
0011 #include "VecGeom/base/Global.h"
0012 
0013 namespace vecgeom {
0014 
0015 /// Largest supported number of uniform slabs for one daughter split.
0016 ///
0017 /// Current automatic-mode defaults are at most 20. This higher structural
0018 /// bound leaves room for expert studies while preventing accidental or
0019 /// malformed inputs from requesting impractical allocations.
0020 inline constexpr int kMaximumAABBSubdivisionM = 1024;
0021 
0022 /// Build/navigation trade-off used by automatic daughter-AABB subdivision.
0023 enum class AABBSubdivisionMode {
0024   kOff,        ///< Never split; use one AABB per daughter.
0025   kFast,       ///< Bounded clipped-extent search with low build cost.
0026   kBalanced,   ///< Moderate build/memory cost for stronger pruning.
0027   kNavigation, ///< Higher build/memory cost, optimized for navigation speed.
0028 };
0029 
0030 /// Configuration for automatic AABB subdivision.
0031 ///
0032 /// The automatic modes are heuristic selectors for build/navigation trade-offs.
0033 /// They never change the geometric candidate id: every returned slab remains a
0034 /// conservative mother-frame AABB for the original placed volume. These knobs
0035 /// are host-side BVH build inputs and must be set before BVHManager::Init().
0036 struct AABBSubdividerConfig {
0037   /// Automatic search mode.
0038   AABBSubdivisionMode mode = AABBSubdivisionMode::kOff;
0039 
0040   /// Hard upper limit on M in navigation mode.
0041   int autoMaxM = 20;
0042 
0043   /// Maximum M in fast mode. This keeps build cost bounded.
0044   int fastMaxM = 4;
0045 
0046   /// Maximum M in balanced mode.
0047   int balancedMaxM = 8;
0048 
0049   /// Minimum unpenalized slab/original surface-area reduction required in fast mode.
0050   Precision fastMinReduction = Precision(0.15);
0051 
0052   /// Minimum transformed-AABB/local-extent surface-area ratio for fast mode.
0053   Precision fastMinAABBInflation = Precision(5.0);
0054 
0055   /// Minimum unpenalized slab/original surface-area reduction required in balanced mode.
0056   Precision balancedMinReduction = Precision(0.15);
0057 
0058   /// Minimum transformed-AABB/local-extent surface-area ratio tried by balanced mode.
0059   Precision balancedMinAABBInflation = Precision(1.5);
0060 
0061   /// Balanced-mode transformed/local AABB surface-area ratio above which all axes are tested.
0062   ///
0063   /// Candidate daughters with a lower ratio still use the cheaper one-axis
0064   /// search, so balanced mode spends the expensive all-axis search only on
0065   /// very inefficient transformed AABBs.
0066   Precision balancedFullSearchAABBInflation = Precision(3.0);
0067 
0068   /// Minimum unpenalized slab/original surface-area reduction required in navigation mode.
0069   Precision navigationMinReduction = Precision(0.02);
0070 
0071   /// Stop balanced/navigation M scans after this many non-improving M values.
0072   int nonImprovingStopCount = 2;
0073 
0074   /// Objective penalty per extra slab in fast mode, in units of SA(M=1).
0075   Precision fastBoxPenalty = Precision(0.030);
0076 
0077   /// Objective penalty per extra slab in balanced mode, in units of SA(M=1).
0078   Precision balancedBoxPenalty = Precision(0.020);
0079 
0080   /// Objective penalty per extra slab in navigation mode, in units of SA(M=1).
0081   Precision navigationBoxPenalty = Precision(0.002);
0082 
0083   /// Minimum estimated whole-mother BVH traversal-cost reduction required in fast mode; negative disables the gate.
0084   Precision fastMinCostReduction = Precision(0.35);
0085 
0086   /// Minimum estimated whole-mother BVH traversal-cost reduction required in balanced mode; negative disables the gate.
0087   Precision balancedMinCostReduction = Precision(0.20);
0088 
0089   /// Minimum estimated whole-mother BVH traversal-cost reduction required in navigation mode; negative disables the
0090   /// gate.
0091   Precision navigationMinCostReduction = Precision(0.20);
0092 
0093   /// Relative cost assigned to visiting one BVH node by the post-build gate.
0094   Precision nodeCost = Precision(1.0);
0095 
0096   /// Relative cost assigned to testing one primitive AABB by the post-build gate.
0097   Precision boxCost = Precision(1.0);
0098 
0099   /// Relative cost assigned to one daughter solid distance call by the post-build gate.
0100   Precision solidCost = Precision(5.0);
0101 
0102   /// Maximum mother daughter count eligible for subdivision in fast mode.
0103   ///
0104   /// Larger mothers keep identity-mapped BVHs. This bounds the temporary build
0105   /// products and avoids duplicating full-mother AABB/id arrays when only a
0106   /// sparse subset of daughters would benefit.
0107   int fastMaxDaughtersPerMother = 100000;
0108 
0109   /// Minimum fraction of a mother's daughters that must pass the fast prefilter.
0110   ///
0111   /// Requiring a representative fraction amortizes the mapped split-box
0112   /// representation over enough useful daughters. A value of 0 disables this
0113   /// fast-mode gate.
0114   Precision fastMinCandidateFractionPerMother = Precision(0.15);
0115 };
0116 
0117 /// Return a stable lower-case label for an AABB subdivision mode.
0118 inline const char *AABBSubdivisionModeName(AABBSubdivisionMode mode)
0119 {
0120   switch (mode) {
0121   case AABBSubdivisionMode::kOff:
0122     return "off";
0123   case AABBSubdivisionMode::kFast:
0124     return "fast";
0125   case AABBSubdivisionMode::kBalanced:
0126     return "balanced";
0127   case AABBSubdivisionMode::kNavigation:
0128     return "navigation";
0129   }
0130   return "unknown";
0131 }
0132 
0133 } // namespace vecgeom
0134 
0135 #endif // VECGEOM_MANAGEMENT_BVHSUBDIVISIONOPTIONS_H_