-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Complete GDML-to-ORANGE geometry converter (#1180)
* Add geometry converter * Add ORANGE geometry constructor * Don't inline child if it's transformed
- Loading branch information
Showing
17 changed files
with
642 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
//----------------------------------*-C++-*----------------------------------// | ||
// Copyright 2024 UT-Battelle, LLC, and other Celeritas developers. | ||
// See the top-level COPYRIGHT file for details. | ||
// SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||
//---------------------------------------------------------------------------// | ||
//! \file orange/g4org/Converter.cc | ||
//---------------------------------------------------------------------------// | ||
#include "Converter.hh" | ||
|
||
#include "corecel/io/Logger.hh" | ||
#include "geocel/detail/LengthUnits.hh" | ||
|
||
#include "PhysicalVolumeConverter.hh" | ||
#include "ProtoConstructor.hh" | ||
|
||
namespace celeritas | ||
{ | ||
namespace g4org | ||
{ | ||
//---------------------------------------------------------------------------// | ||
/*! | ||
* Construct with options. | ||
*/ | ||
Converter::Converter(Options&& opts) : opts_{std::move(opts)} | ||
{ | ||
if (!opts_.tol) | ||
{ | ||
opts_.tol = Tolerance<>::from_default(lengthunits::millimeter); | ||
} | ||
|
||
if (real_type{1} - ipow<2>(opts_.tol.rel) == real_type{1}) | ||
{ | ||
CELER_LOG(warning) | ||
<< "Requested relative tolerance (" << opts_.tol.rel | ||
<< ") for ORANGE is very small: tracking errors may result due to " | ||
"incomplete geometry simplification"; | ||
} | ||
|
||
CELER_ENSURE(opts_.tol); | ||
} | ||
|
||
//---------------------------------------------------------------------------// | ||
/*! | ||
* Convert the world. | ||
*/ | ||
auto Converter::operator()(arg_type g4world) -> result_type | ||
{ | ||
CELER_EXPECT(g4world); | ||
|
||
CELER_LOG(debug) << "Converting Geant4 geometry elements"; | ||
|
||
// Convert solids, logical volumes, physical volumes | ||
PhysicalVolumeConverter::Options options; | ||
options.verbose = opts_.verbose; | ||
PhysicalVolumeConverter convert_pv(std::move(options)); | ||
PhysicalVolume world = convert_pv(*g4world); | ||
CELER_VALIDATE(std::holds_alternative<NoTransformation>(world.transform), | ||
<< "world volume should not have a transformation"); | ||
|
||
CELER_LOG(debug) << "Building protos"; | ||
// Convert logical volumes into protos | ||
auto global_proto = ProtoConstructor{opts_.verbose}(*world.lv); | ||
|
||
CELER_LOG(debug) << "Building universes"; | ||
// Build universes from protos | ||
result_type result; | ||
result.input = build_input(opts_.tol, *global_proto); | ||
return result; | ||
} | ||
|
||
//---------------------------------------------------------------------------// | ||
} // namespace g4org | ||
} // namespace celeritas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
//----------------------------------*-C++-*----------------------------------// | ||
// Copyright 2023-2024 UT-Battelle, LLC, and other Celeritas developers. | ||
// See the top-level COPYRIGHT file for details. | ||
// SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||
//---------------------------------------------------------------------------// | ||
//! \file orange/g4org/Converter.hh | ||
//---------------------------------------------------------------------------// | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <unordered_map> | ||
|
||
#include "celeritas_config.h" | ||
#include "orange/OrangeInput.hh" | ||
#include "orange/OrangeTypes.hh" | ||
|
||
//---------------------------------------------------------------------------// | ||
// Forward declarations | ||
//---------------------------------------------------------------------------// | ||
|
||
class G4LogicalVolume; | ||
class G4VPhysicalVolume; | ||
|
||
namespace celeritas | ||
{ | ||
namespace g4org | ||
{ | ||
//---------------------------------------------------------------------------// | ||
/*! | ||
* Create an ORANGE geometry model from an in-memory Geant4 model. | ||
* | ||
* Return the new world volume and a mapping of Geant4 logical volumes to | ||
* VecGeom-based volume IDs. | ||
* | ||
* The default Geant4 "tolerance" (often used as surface "thickness") is 1e-9 | ||
* mm, and the relative tolerance when specifying a length scale is 1e-11 (so | ||
* the default macro length scale is expected to be 100 mm = 10 cm). | ||
* That relative tolerance is *much* too small for any quadric operations or | ||
* angular rotations to be differentiated, so for now we'll stick with the | ||
* ORANGE default tolerance of 1e-8 relative, and we assume a 1mm length scale. | ||
*/ | ||
class Converter | ||
{ | ||
public: | ||
//!@{ | ||
//! \name Type aliases | ||
using arg_type = G4VPhysicalVolume const*; | ||
using MapLvVolId = std::unordered_map<G4LogicalVolume const*, VolumeId>; | ||
//!@} | ||
|
||
//! Input options for the conversion | ||
struct Options | ||
{ | ||
//! Write output about volumes being converted | ||
bool verbose{false}; | ||
//! Manually specify a tracking/construction tolerance | ||
Tolerance<> tol; | ||
}; | ||
|
||
struct result_type | ||
{ | ||
OrangeInput input; | ||
MapLvVolId volumes; //! TODO | ||
}; | ||
|
||
public: | ||
// Construct with options | ||
explicit Converter(Options&&); | ||
|
||
//! Construct with default options | ||
Converter() : Converter{Options{}} {} | ||
|
||
// Convert the world | ||
result_type operator()(arg_type); | ||
|
||
private: | ||
Options opts_; | ||
}; | ||
|
||
//---------------------------------------------------------------------------// | ||
|
||
#if !(CELERITAS_USE_GEANT4 \ | ||
&& CELERITAS_REAL_TYPE == CELERITAS_REAL_TYPE_DOUBLE) | ||
inline Converter::Converter(Options&&) | ||
{ | ||
CELER_DISCARD(opts_); | ||
} | ||
|
||
inline auto Converter::operator()(arg_type) -> result_type | ||
{ | ||
CELER_NOT_CONFIGURED("Geant4 with double-precision real_type"); | ||
} | ||
#endif | ||
|
||
//---------------------------------------------------------------------------// | ||
} // namespace g4org | ||
} // namespace celeritas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.