Skip to content

Commit

Permalink
Merge pull request #220 from tdixon97/main
Browse files Browse the repository at this point in the history
Updates to sampling for intersections and subtractions
  • Loading branch information
gipert authored Jan 7, 2025
2 parents d484480 + 2320dde commit c4dadf9
Show file tree
Hide file tree
Showing 19 changed files with 1,261 additions and 135 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
run: |
mkdir build
cd build
cmake -DRMG_BUILD_EXAMPLES=1 ..
cmake -DRMG_BUILD_EXAMPLES=1 -DBUILD_TESTING=ON -DRMG_BUILD_DOCS=OFF ..
make
make install
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ if(RMG_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

message(STATUS "Test/validation suite support: BUILD_TESTING=${BUILD_TESTING}")
include(CTest)
add_subdirectory(tests)

Expand Down
22 changes: 21 additions & 1 deletion docs/rmg-commands.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 22 additions & 4 deletions include/RMGVertexConfinement.hh
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,15 @@ class RMGVertexConfinement : public RMGVVertexGenerator {

enum class SamplingMode {
kIntersectPhysicalWithGeometrical,
kUnionAll
kUnionAll,
kSubtractGeometrical,
};

enum class VolumeType {
kPhysical,
kGeometrical,
kUnset,
};
RMGVertexConfinement();

void BeginOfRunAction(const G4Run* run) override;
Expand All @@ -79,6 +85,7 @@ class RMGVertexConfinement : public RMGVVertexGenerator {
void Reset();

inline void SetSamplingMode(SamplingMode mode) { fSamplingMode = mode; }
inline void SetFirstSamplingVolumeType(VolumeType type) { fFirstSamplingVolumeType = type; }

inline std::vector<GenericGeometricalSolidData>& GetGeometricalSolidDataList() {
return fGeomVolumeData;
Expand All @@ -93,6 +100,8 @@ class RMGVertexConfinement : public RMGVVertexGenerator {
// NOTE: G4 volume/solid pointers should be fully owned by G4, avoid trying to delete them
~SampleableObject() = default;
[[nodiscard]] bool IsInside(const G4ThreeVector& vertex) const;
[[nodiscard]] bool Sample(G4ThreeVector& vertex, int max_attempts, bool sample_on_surface,
bool force_containment_check, long int& n_trials) const;

G4VPhysicalVolume* physical_volume = nullptr;
G4VSolid* sampling_solid = nullptr;
Expand Down Expand Up @@ -123,7 +132,7 @@ class RMGVertexConfinement : public RMGVVertexGenerator {
for (size_t i = 0; i < other.size(); ++i) this->emplace_back(other.at(i));
}

std::vector<SampleableObject> data;
std::vector<SampleableObject> data = {};
double total_volume = 0;
double total_surface = 0;
};
Expand All @@ -144,13 +153,14 @@ class RMGVertexConfinement : public RMGVVertexGenerator {
};

void InitializePhysicalVolumes();
void InitializeGeometricalVolumes();
void InitializeGeometricalVolumes(bool useExcludedVolumes);
bool ActualGenerateVertex(G4ThreeVector& v);

std::vector<std::string> fPhysicalVolumeNameRegexes;
std::vector<std::string> fPhysicalVolumeCopyNrRegexes;

std::vector<GenericGeometricalSolidData> fGeomVolumeData;
std::vector<GenericGeometricalSolidData> fExcludedGeomVolumeData;

static G4Mutex fGeometryMutex;
// the final geometry data is shared between all threads and protected by fGeometryMutex.
Expand All @@ -159,19 +169,27 @@ class RMGVertexConfinement : public RMGVVertexGenerator {
// mutate the G4SolidStore temporarily, e.g. G4SubstractionSolid::GetCubicVolume()
static SampleableObjectCollection fPhysicalVolumes;
static SampleableObjectCollection fGeomVolumeSolids;
static SampleableObjectCollection fExcludedGeomVolumeSolids;

static bool fVolumesInitialized;

SamplingMode fSamplingMode = SamplingMode::kUnionAll;
VolumeType fFirstSamplingVolumeType = VolumeType::kUnset;

bool fOnSurface = false;
bool fForceContainmentCheck = false;

bool fLastSolidExcluded = false;
// counters used for the current run.
long fTrials = 0;
std::chrono::nanoseconds fVertexGenerationTime;

std::vector<std::unique_ptr<G4GenericMessenger>> fMessengers;
void SetSamplingModeString(std::string mode);
void SetFirstSamplingVolumeTypeString(std::string type);

void AddGeometricalVolumeString(std::string solid);
void AddExcludedGeometricalVolumeString(std::string solid);

GenericGeometricalSolidData& SafeBack(
std::optional<GeometricalSolidType> solid_type = std::nullopt);

Expand Down
2 changes: 1 addition & 1 deletion python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ add_custom_command(
cp
${CMAKE_CURRENT_BINARY_DIR}/cpp_config.build.py # now we want to use the cpp_config for the build area
${CMAKE_CURRENT_SOURCE_DIR}/remage/cpp_config.py
COMMAND ${VENV_DIR}/bin/python -m uv -q pip install --reinstall ${_pkg_install}
COMMAND ${VENV_DIR}/bin/python -m uv pip -q install --reinstall ${_pkg_install}
DEPENDS python-virtualenv ${PYTHON_SOURCES}
COMMENT "Installing remage Python wrapper into the virtual environment")

Expand Down
Loading

0 comments on commit c4dadf9

Please sign in to comment.