Skip to content

Commit

Permalink
Define geometry traits (#1190)
Browse files Browse the repository at this point in the history
* Define geometry traits
* Explicitly default geoparams class
  • Loading branch information
sethrj committed Apr 17, 2024
1 parent fe26115 commit 4e9676e
Show file tree
Hide file tree
Showing 10 changed files with 216 additions and 49 deletions.
4 changes: 4 additions & 0 deletions src/geocel/GeoParamsInterface.hh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//---------------------------------------------------------------------------//
#pragma once

#include "corecel/Macros.hh"
#include "corecel/cont/Span.hh" // IWYU pragma: export
#include "corecel/io/Label.hh" // IWYU pragma: export

Expand Down Expand Up @@ -64,6 +65,9 @@ class GeoParamsInterface
protected:
// Protected destructor prevents deletion of pointer-to-interface
~GeoParamsInterface() = default;

GeoParamsInterface() = default;
CELER_DEFAULT_COPY_MOVE(GeoParamsInterface);
};

//---------------------------------------------------------------------------//
Expand Down
53 changes: 53 additions & 0 deletions src/geocel/GeoTraits.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//----------------------------------*-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 geocel/GeoTraits.hh
//---------------------------------------------------------------------------//
#pragma once

#include <type_traits>

#include "corecel/Types.hh"

namespace celeritas
{
//---------------------------------------------------------------------------//
class GeoParamsInterface;

//---------------------------------------------------------------------------//
/*!
* Traits class for defining params and device data.
* \tparam G Geometry params class, e.g. VecgeomParams
*
* This traits class \em must be defined for all geometry types. The generic
* instance here is provided as a synopsis and to improve error checking.
*/
template<class G>
struct GeoTraits
{
static_assert(std::is_base_of_v<GeoParamsInterface, G>,
"G must be a geometry params, not params data");
static_assert(std::is_void_v<G>, "Geo traits must be specialized");

//! Params data used during runtime
template<Ownership W, MemSpace M>
using ParamsData = void;

//! State data used during runtime
template<Ownership W, MemSpace M>
using StateData = void;

//! Geometry track view
using TrackView = void;

//! Descriptive name for the geometry
static inline char const* name = nullptr;

//! TO BE REMOVED: "native" file extension for this geometry
static inline char const* ext = nullptr;
};

//---------------------------------------------------------------------------//
} // namespace celeritas
48 changes: 48 additions & 0 deletions src/geocel/g4/GeantGeoTraits.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//----------------------------------*-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 geocel/g4/GeantGeoTraits.hh
//---------------------------------------------------------------------------//
#pragma once

#include "geocel/GeoTraits.hh"

namespace celeritas
{
//---------------------------------------------------------------------------//
class GeantGeoParams;
class GeantGeoTrackView;
template<Ownership W, MemSpace M>
struct GeantGeoParamsData;
template<Ownership W, MemSpace M>
struct GeantGeoStateData;

//---------------------------------------------------------------------------//
/*!
* Traits specialization for Geant4 geometry.
*/
template<>
struct GeoTraits<GeantGeoParams>
{
//! Params data used during runtime
template<Ownership W, MemSpace M>
using ParamsData = GeantGeoParamsData<W, M>;

//! State data used during runtime
template<Ownership W, MemSpace M>
using StateData = GeantGeoStateData<W, M>;

//! Geometry track view
using TrackView = GeantGeoTrackView;

//! Descriptive name for the geometry
static inline char const* name = "Geant4";

//! TO BE REMOVED: "native" file extension for this geometry
static inline char const* ext = ".gdml";
};

//---------------------------------------------------------------------------//
} // namespace celeritas
48 changes: 48 additions & 0 deletions src/geocel/vg/VecgeomGeoTraits.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//----------------------------------*-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 geocel/vg/VecgeomGeoTraits.hh
//---------------------------------------------------------------------------//
#pragma once

#include "geocel/GeoTraits.hh"

namespace celeritas
{
//---------------------------------------------------------------------------//
class VecgeomParams;
class VecgeomTrackView;
template<Ownership W, MemSpace M>
struct VecgeomParamsData;
template<Ownership W, MemSpace M>
struct VecgeomStateData;

//---------------------------------------------------------------------------//
/*!
* Traits specialization for VecGeom geometry.
*/
template<>
struct GeoTraits<VecgeomParams>
{
//! Params data used during runtime
template<Ownership W, MemSpace M>
using ParamsData = VecgeomParamsData<W, M>;

//! State data used during runtime
template<Ownership W, MemSpace M>
using StateData = VecgeomStateData<W, M>;

//! Geometry track view
using TrackView = VecgeomTrackView;

//! Descriptive name for the geometry
static inline char const* name = "VecGeom";

//! TO BE REMOVED: "native" file extension for this geometry
static inline char const* ext = ".gdml";
};

//---------------------------------------------------------------------------//
} // namespace celeritas
48 changes: 48 additions & 0 deletions src/orange/OrangeGeoTraits.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//----------------------------------*-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/OrangeGeoTraits.hh
//---------------------------------------------------------------------------//
#pragma once

#include "geocel/GeoTraits.hh"

namespace celeritas
{
//---------------------------------------------------------------------------//
class OrangeParams;
class OrangeTrackView;
template<Ownership W, MemSpace M>
struct OrangeParamsData;
template<Ownership W, MemSpace M>
struct OrangeStateData;

//---------------------------------------------------------------------------//
/*!
* Traits specialization for ORANGE geometry.
*/
template<>
struct GeoTraits<OrangeParams>
{
//! Params data used during runtime
template<Ownership W, MemSpace M>
using ParamsData = OrangeParamsData<W, M>;

//! State data used during runtime
template<Ownership W, MemSpace M>
using StateData = OrangeStateData<W, M>;

//! Geometry track view
using TrackView = OrangeTrackView;

//! Descriptive name for the geometry
static inline char const* name = "ORANGE";

//! TO BE REMOVED: "native" file extension for this geometry
static inline char const* ext = ".org.json";
};

//---------------------------------------------------------------------------//
} // namespace celeritas
4 changes: 2 additions & 2 deletions test/celeritas/AllGeoTypedTestBase.hh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class AllGeoTypedTestBase : public GenericGeoTestBase<HP>
public:
using SPConstGeo = typename GenericGeoTestBase<HP>::SPConstGeo;

static std::string geo_name() { return GenericGeoTraits<HP>::name; }
static std::string geo_name() { return GeoTraits<HP>::name; }

SPConstGeo build_geometry() override
{
Expand All @@ -87,7 +87,7 @@ struct AllGeoTestingTypeNames
template<class U>
static std::string GetName(int)
{
return GenericGeoTraits<U>::name;
return GeoTraits<U>::name;
}
};

Expand Down
23 changes: 10 additions & 13 deletions test/geocel/GenericGeoTestBase.hh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <type_traits>

#include "corecel/data/CollectionStateStore.hh"
#include "geocel/GeoTraits.hh"
#include "geocel/detail/LengthUnits.hh"

#include "LazyGeoManager.hh"
Expand Down Expand Up @@ -50,33 +51,28 @@ struct GenericGeoGeantImportVolumeResult
void print_expected() const;
};

//---------------------------------------------------------------------------//
//! Traits class templated on host params, to be extended by downstream files
template<class HP>
struct GenericGeoTraits;

//---------------------------------------------------------------------------//
/*!
* Templated base class for loading geometry.
*
* \tparam HP Geometry host Params class
* \tparam G Geometry host params class, e.g. OrangeParams
*
* \sa AllGeoTypedTestBase
*
* \note This class is instantiated in XTestBase.cc for geometry type X.
*/
template<class HP>
template<class G>
class GenericGeoTestBase : virtual public Test, private LazyGeoManager
{
static_assert(std::is_base_of_v<GeoParamsInterface, HP>);
static_assert(std::is_base_of_v<GeoParamsInterface, G>);

using TraitsT = GenericGeoTraits<HP>;
using TraitsT = GeoTraits<G>;

public:
//!@{
//! \name Type aliases
using SPConstGeo = std::shared_ptr<HP const>;
using GeoTrackView = typename GenericGeoTraits<HP>::TrackView;
using SPConstGeo = std::shared_ptr<G const>;
using GeoTrackView = typename TraitsT::TrackView;
using TrackingResult = GenericGeoTrackingResult;
using GeantVolResult = GenericGeoGeantImportVolumeResult;
//!@}
Expand Down Expand Up @@ -130,8 +126,9 @@ class GenericGeoTestBase : virtual public Test, private LazyGeoManager
}

private:
using HostStateStore =
typename TraitsT::template StateStore<MemSpace::host>;
template<Ownership W, MemSpace M>
using StateData = typename TraitsT::template StateData<W, M>;
using HostStateStore = CollectionStateStore<StateData, MemSpace::host>;

SPConstGeo geo_;
HostStateStore host_state_;
Expand Down
14 changes: 1 addition & 13 deletions test/geocel/g4/GeantGeoTestBase.hh
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,13 @@
#include "geocel/g4/GeantGeoData.hh"
#include "geocel/g4/GeantGeoParams.hh"
#include "geocel/g4/GeantGeoTrackView.hh"
#include "geocel/g4/GeantGeoTraits.hh"

namespace celeritas
{
//---------------------------------------------------------------------------//
class GeantGeoTrackView;

namespace test
{
//---------------------------------------------------------------------------//
template<>
struct GenericGeoTraits<GeantGeoParams>
{
template<MemSpace M>
using StateStore = CollectionStateStore<GeantGeoStateData, M>;
using TrackView = GeantGeoTrackView;
static inline char const* ext = ".gdml";
static inline char const* name = "Geant4";
};

using GeantGeoTestBase = GenericGeoTestBase<GeantGeoParams>;

//---------------------------------------------------------------------------//
Expand Down
11 changes: 1 addition & 10 deletions test/geocel/vg/VecgeomTestBase.hh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "geocel/GenericGeoTestBase.hh"
#include "geocel/vg/VecgeomData.hh"
#include "geocel/vg/VecgeomGeoTraits.hh"
#include "geocel/vg/VecgeomParams.hh"
#include "geocel/vg/VecgeomTrackView.hh"

Expand All @@ -17,16 +18,6 @@ namespace celeritas
namespace test
{
//---------------------------------------------------------------------------//
template<>
struct GenericGeoTraits<VecgeomParams>
{
template<MemSpace M>
using StateStore = CollectionStateStore<VecgeomStateData, M>;
using TrackView = VecgeomTrackView;
static inline char const* ext = ".gdml";
static inline char const* name = "VecGeom";
};

using VecgeomTestBase = GenericGeoTestBase<VecgeomParams>;

//---------------------------------------------------------------------------//
Expand Down
12 changes: 1 addition & 11 deletions test/orange/OrangeTestBase.hh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "geocel/GenericGeoTestBase.hh"
#include "orange/OrangeData.hh"
#include "orange/OrangeGeoTraits.hh"
#include "orange/OrangeParams.hh"
#include "orange/OrangeTrackView.hh"

Expand All @@ -17,17 +18,6 @@ namespace celeritas
namespace test
{
//---------------------------------------------------------------------------//
template<>
struct GenericGeoTraits<OrangeParams>
{
template<MemSpace M>
using StateStore = CollectionStateStore<OrangeStateData, M>;

using TrackView = OrangeTrackView;
static inline char const* ext = ".org.json";
static inline char const* name = "ORANGE";
};

using OrangeTestBase = GenericGeoTestBase<OrangeParams>;

//---------------------------------------------------------------------------//
Expand Down

0 comments on commit 4e9676e

Please sign in to comment.