Skip to content

Commit

Permalink
Remove b-field from detector
Browse files Browse the repository at this point in the history
  • Loading branch information
niermann999 committed Oct 11, 2023
1 parent c79e73b commit 8e37a0f
Show file tree
Hide file tree
Showing 60 changed files with 366 additions and 733 deletions.
2 changes: 1 addition & 1 deletion core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ file( GLOB _detray_core_private_headers
detray_add_library( detray_core core
${_detray_core_public_headers} ${_detray_core_private_headers} )
target_link_libraries( detray_core
INTERFACE covfie::core vecmem::core detray::Thrust )
INTERFACE vecmem::core detray::Thrust )

# Generate a version header for the project.
configure_file( "cmake/version.hpp.in"
Expand Down
91 changes: 23 additions & 68 deletions core/include/detray/core/detector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "detray/core/detail/container_buffers.hpp"
#include "detray/core/detail/container_views.hpp"
#include "detray/core/detector_metadata.hpp"
#include "detray/definitions/bfield_backends.hpp"
#include "detray/definitions/containers.hpp"
#include "detray/definitions/qualifiers.hpp"
#include "detray/geometry/detail/volume_descriptor.hpp"
Expand All @@ -32,7 +31,7 @@
namespace detray {

/// @brief Forward declaration of a detector view type
template <typename device_bfield_bknd_t, typename metadata, typename bfield_t>
template <typename metadata>
struct detector_view;

/// @brief The detector definition.
Expand All @@ -46,13 +45,11 @@ struct detector_view;
/// @tparam container_t type collection of the underlying containers
/// @tparam source_link the surface source link
template <typename metadata_t = default_metadata,
typename bfield_t = covfie::field<bfield::const_bknd_t>,
typename container_t = host_container_types>
class detector {

// Allow the building of the detector containers
friend class volume_builder_interface<
detector<metadata_t, bfield_t, container_t>>;
friend class volume_builder_interface<detector<metadata_t, container_t>>;

public:
/// Algebra types
Expand All @@ -65,8 +62,6 @@ class detector {

using metadata = metadata_t;

using bfield_type = bfield_t;

/// Raw container types
template <typename T, std::size_t N>
using array_type = typename container_t::template array_type<T, N>;
Expand Down Expand Up @@ -129,9 +124,7 @@ class detector {
typename metadata::template volume_finder<container_t>;

// TODO: Remove
template <typename device_bfield_t>
using detector_view_type =
detector_view<device_bfield_t, metadata, bfield_t>;
using detector_view_type = detector_view<metadata>;

// TODO: rename back to 'view_type' etc, once covfie is wrapped in the
// container view/buffer formalism
Expand Down Expand Up @@ -179,22 +172,7 @@ class detector {
_surfaces(resource),
_surface_lookup(&resource),
_volume_finder(resource),
_resource(&resource),
_bfield() {}

/// @param resource memory resource for the allocation of members and
/// externally provided magnetic field @param field
DETRAY_HOST
detector(vecmem::memory_resource &resource, bfield_type &&field)
: _volumes(&resource),
_transforms(resource),
_masks(resource),
_materials(resource),
_surfaces(resource),
_surface_lookup(&resource),
_volume_finder(resource),
_resource(&resource),
_bfield(std::move(field)) {}
_resource(&resource) {}

/// Constructor with detector_data
template <typename detector_data_type,
Expand All @@ -210,8 +188,7 @@ class detector {
_surface_lookup(
detray::detail::get<5>(det_data._detector_data.m_view)),
_volume_finder(
detray::detail::get<6>(det_data._detector_data.m_view)),
_bfield(det_data._bfield_view) {}
detray::detail::get<6>(det_data._detector_data.m_view)) {}
/// @}

/// Add a new volume and retrieve a reference to it.
Expand Down Expand Up @@ -542,15 +519,6 @@ class detector {
return *std::max_element(n_candidates.begin(), n_candidates.end());
}

/// @brief Add a bfield to the detector
DETRAY_HOST
void set_bfield(bfield_type &&field) {
_bfield = std::forward<bfield_type>(field);
}

DETRAY_HOST_DEVICE
inline const bfield_type &get_bfield() const { return _bfield; }

/// @param names maps a volume to its string representation.
/// @returns a string representation of the detector.
DETRAY_HOST
Expand Down Expand Up @@ -618,19 +586,16 @@ class detector {
/// The memory resource represents how and where (host, device, managed)
/// the memory for the detector containers is allocated
vecmem::memory_resource *_resource = nullptr;

/// Storage for magnetic field data
bfield_type _bfield;
};

/// @brief The detector data buffer
///
/// Contains the buffers for all detector components plus the covfie device
/// field type, which is being copied to device when this type gets constructed
template <typename device_bfield_bknd_t, typename metadata_t, typename bfield_t>
template <typename metadata_t>
struct detector_buffer {

using detector_type = detector<metadata_t, bfield_t, host_container_types>;
using detector_type = detector<metadata_t, host_container_types>;

/// Automatic buffer creation with the given parameters
detector_buffer(detector_type &det, vecmem::memory_resource &mr,
Expand All @@ -651,12 +616,10 @@ struct detector_buffer {
detray::get_buffer(det.surface_lookup(), mr, cpy,
cpy_type, buff_type),
detray::get_buffer(det.volume_search_grid(), mr, cpy,
cpy_type, buff_type)),
_bfield(det.get_bfield()) {}
cpy_type, buff_type)) {}

/// Buffers were created manually
detector_buffer(
const detector_type &det,
detail::get_buffer_t<typename detector_type::volume_container>
&&vol_buffer,
typename detector_type::transform_container::buffer_type &&trf_buffer,
Expand All @@ -669,23 +632,20 @@ struct detector_buffer {
: _detector_buffer(std::move(vol_buffer), std::move(trf_buffer),
std::move(msk_buffer), std::move(mat_buffer),
std::move(sf_buffer), std::move(sf_lkp_buffer),
std::move(vgrd_buffer)),
_bfield(det.get_bfield()) {}
std::move(vgrd_buffer)) {}

/// Buffers for the vecemem types
typename detector_type::buffer_t _detector_buffer;
/// Covfie device field
covfie::field<device_bfield_bknd_t> _bfield;
};

/// @brief The detector view
///
/// Contains the views for all detector components, including the device view
/// of the bfield
template <typename device_bfield_bknd_t, typename metadata_t, typename bfield_t>
template <typename metadata_t>
struct detector_view {

using detector_type = detector<metadata_t, bfield_t, host_container_types>;
using detector_type = detector<metadata_t, host_container_types>;

detector_view(detector_type &det)
: _detector_data(detray::get_data(det.volumes()),
Expand All @@ -694,37 +654,32 @@ struct detector_view {
detray::get_data(det.material_store()),
detray::get_data(det.surface_store()),
detray::get_data(det.surface_lookup()),
detray::get_data(det.volume_search_grid())),
_bfield_view(det.get_bfield()) {}
detray::get_data(det.volume_search_grid())) {}

detector_view(
detector_buffer<device_bfield_bknd_t, metadata_t, bfield_t> &det_buff)
: _detector_data(detray::get_data(det_buff._detector_buffer)),
_bfield_view(det_buff._bfield) {}
detector_view(detector_buffer<metadata_t> &det_buff)
: _detector_data(detray::get_data(det_buff._detector_buffer)) {}

/// Views for the vecmem types
typename detector_type::view_t _detector_data;
/// Covfie field view
covfie::field_view<device_bfield_bknd_t> _bfield_view;
};

/// Stand-alone function that @returns the detector view for transfer to
/// device.
///
/// @param detector the detector to be tranferred
template <typename device_bfield_bknd_t, typename metadata_t, typename bfield_t>
inline detector_view<device_bfield_bknd_t, metadata_t, bfield_t> get_data(
detector<metadata_t, bfield_t, host_container_types> &det) {
template <typename metadata_t>
inline detector_view<metadata_t> get_data(
detector<metadata_t, host_container_types> &det) {
return {det};
}

/// Stand-alone function that @returns the detector buffer for transfer to
/// device.
///
/// @param detector the detector to be transferred
template <typename device_bfield_bknd_t, typename metadata_t, typename bfield_t>
inline detector_buffer<device_bfield_bknd_t, metadata_t, bfield_t> get_buffer(
detector<metadata_t, bfield_t, host_container_types> &det,
template <typename metadata_t>
inline detector_buffer<metadata_t> get_buffer(
detector<metadata_t, host_container_types> &det,
vecmem::memory_resource &mr, vecmem::copy &cpy,
detray::copy cpy_type = detray::copy::sync,
vecmem::data::buffer_type buff_type =
Expand All @@ -736,9 +691,9 @@ inline detector_buffer<device_bfield_bknd_t, metadata_t, bfield_t> get_buffer(
/// device.
///
/// @param detector the detector to be transferred
template <typename device_bfield_bknd_t, typename metadata_t, typename bfield_t>
inline detector_view<device_bfield_bknd_t, metadata_t, bfield_t> get_data(
detector_buffer<device_bfield_bknd_t, metadata_t, bfield_t> &det_buff) {
template <typename metadata_t>
inline detector_view<metadata_t> get_data(
detector_buffer<metadata_t> &det_buff) {
return {det_buff};
}

Expand Down
9 changes: 3 additions & 6 deletions core/include/detray/propagator/rk_stepper.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@ bool detray::rk_stepper<magnetic_field_t, transform3_t, constraint_t, policy_t,
// First Runge-Kutta point
const vector3 pos = stepping().pos();
const vector3 dir = stepping().dir();
const typename magnetic_field_t::output_t bvec =
magnetic_field.at(pos[0], pos[1], pos[2]);
const auto bvec = magnetic_field.at(pos[0], pos[1], pos[2]);
sd.b_first[0] = bvec[0];
sd.b_first[1] = bvec[1];
sd.b_first[2] = bvec[2];
Expand All @@ -190,8 +189,7 @@ bool detray::rk_stepper<magnetic_field_t, transform3_t, constraint_t, policy_t,

// Second Runge-Kutta point
const vector3 pos1 = pos + half_h * dir + h2 * 0.125f * sd.k1;
const typename magnetic_field_t::output_t bvec1 =
magnetic_field.at(pos1[0], pos1[1], pos1[2]);
const auto bvec1 = magnetic_field.at(pos1[0], pos1[1], pos1[2]);
sd.b_middle[0] = bvec1[0];
sd.b_middle[1] = bvec1[1];
sd.b_middle[2] = bvec1[2];
Expand All @@ -202,8 +200,7 @@ bool detray::rk_stepper<magnetic_field_t, transform3_t, constraint_t, policy_t,

// Last Runge-Kutta point
const vector3 pos2 = pos + h * dir + h2 * 0.5f * sd.k3;
const typename magnetic_field_t::output_t bvec2 =
magnetic_field.at(pos2[0], pos2[1], pos2[2]);
const auto bvec2 = magnetic_field.at(pos2[0], pos2[1], pos2[2]);
sd.b_last[0] = bvec2[0];
sd.b_last[1] = bvec2[1];
sd.b_last[2] = bvec2[2];
Expand Down
14 changes: 1 addition & 13 deletions core/include/detray/tools/detector_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
// Project include(s).
#include "detray/core/detector.hpp"
#include "detray/core/detector_metadata.hpp"
#include "detray/definitions/bfield_backends.hpp"
#include "detray/definitions/geometry.hpp"
#include "detray/tools/grid_factory.hpp"
#include "detray/tools/volume_builder.hpp"
Expand All @@ -34,13 +33,11 @@ namespace detray {
/// geometry data
/// @tparam volume_data_t the data structure that holds the volume builders
template <typename metadata = default_metadata,
typename bfield_bknd_t = bfield::const_bknd_t,
template <typename> class volume_builder_t = volume_builder,
template <typename...> class volume_data_t = std::vector>
class detector_builder {
public:
using detector_type =
detector<metadata, covfie::field<bfield_bknd_t>, host_container_types>;
using detector_type = detector<metadata, host_container_types>;

/// Empty detector builder
detector_builder() = default;
Expand Down Expand Up @@ -88,20 +85,13 @@ class detector_builder {
vol_builder->build(det);
}

det.set_bfield(std::move(m_bfield));
det.set_volume_finder(std::move(m_vol_finder));

// TODO: Add sorting, data deduplication etc. here later...

return det;
}

/// Assembles the detector, without a magnetic field
DETRAY_HOST
void set_bfield(typename detector_type::bfield_type&& field) {
m_bfield = std::forward<typename detector_type::bfield_type>(field);
}

/// Put the volumes into a search data structure
template <typename... Args>
DETRAY_HOST void set_volume_finder(Args&&... /*args*/) {
Expand Down Expand Up @@ -133,8 +123,6 @@ class detector_builder {
m_volumes{};
/// Data structure to find volumes
typename detector_type::volume_finder m_vol_finder{};
/// The detector bfield
typename detector_type::bfield_type m_bfield;
};

} // namespace detray
2 changes: 1 addition & 1 deletion io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ file( GLOB _detray_io_public_headers
detray_add_library( detray_io io
${_detray_io_public_headers} )
target_link_libraries( detray_io INTERFACE
dfelibs::dfelibs nlohmann_json::nlohmann_json vecmem::core detray::core )
dfelibs::dfelibs nlohmann_json::nlohmann_json vecmem::core covfie::core detray::core )

# Set up libraries using particular algebra plugins.
detray_add_library( detray_io_array io_array )
Expand Down
Loading

0 comments on commit 8e37a0f

Please sign in to comment.