diff --git a/CMakeLists.txt b/CMakeLists.txt index e7b076ddb..741a3cda2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -168,6 +168,8 @@ if( DETRAY_SETUP_BENCHMARK ) endif() endif() +add_subdirectory( extern/covfie ) + # Set up all of the libraries of the project. add_subdirectory( core ) add_subdirectory( plugins ) diff --git a/extern/covfie/CMakeLists.txt b/extern/covfie/CMakeLists.txt new file mode 100644 index 000000000..e7e7156e3 --- /dev/null +++ b/extern/covfie/CMakeLists.txt @@ -0,0 +1,32 @@ +# Detray library, part of the ACTS project (R&D line) +# +# (c) 2022 CERN for the benefit of the ACTS project +# +# Mozilla Public License Version 2.0 + +# CMake include(s). +cmake_minimum_required( VERSION 3.14 ) +include( FetchContent ) + +# Tell the user what's happening. +message( STATUS "Fetching covfie as part of the Detray project" ) + +# Declare where to get covfie from. +set( DETRAY_COVFIE_SOURCE + "URL;https://github.com/acts-project/covfie/archive/refs/tags/v0.2.0.tar.gz;URL_MD5;7cf83f2a4d5dcc3dad8fb952cef36fd4" + CACHE STRING "Source for covfie, when built as part of this project" ) +mark_as_advanced( DETRAY_COVFIE_SOURCE ) +FetchContent_Declare( covfie ${DETRAY_COVFIE_SOURCE} ) + +# Options used for covfie. +set( COVFIE_BUILD_EXAMPLES Off CACHE BOOL "Build covfie examples") +set( COVFIE_BUILD_TESTS Off CACHE BOOL "Build covfie tests") +set( COVFIE_BUILD_BENCHMARKS Off CACHE BOOL "Build covfie benchmarks") + +set( COVFIE_PLATFORM_CPU On CACHE BOOL "Enable covfie CPU platform") +set( COVFIE_PLATFORM_CUDA On CACHE BOOL "Enable covfie CUDA platform") + +set( COVFIE_REQUIRE_CXX20 Off CACHE BOOL "Enable covfie C++20 requirement") + +# Get it into the current directory. +FetchContent_MakeAvailable( covfie ) diff --git a/extern/covfie/README.md b/extern/covfie/README.md new file mode 100644 index 000000000..19e66af64 --- /dev/null +++ b/extern/covfie/README.md @@ -0,0 +1,4 @@ +# Build Recipe for covfie + +This directory holds a simple build recipe for the +[covfie](https://github.com/acts-project/covfie) project. diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt index e4d77df00..4a9d79980 100644 --- a/tests/unit_tests/CMakeLists.txt +++ b/tests/unit_tests/CMakeLists.txt @@ -21,3 +21,5 @@ endif() if( DETRAY_BUILD_CUDA ) add_subdirectory( cuda ) endif() + +add_subdirectory( covfie ) diff --git a/tests/unit_tests/covfie/CMakeLists.txt b/tests/unit_tests/covfie/CMakeLists.txt new file mode 100644 index 000000000..d0162c100 --- /dev/null +++ b/tests/unit_tests/covfie/CMakeLists.txt @@ -0,0 +1,10 @@ +# Detray library, part of the ACTS project (R&D line) +# +# (c) 2022 CERN for the benefit of the ACTS project +# +# Mozilla Public License Version 2.0 + +# Set up the covfie tests. +detray_add_test( covfie + "constant_field.cpp" + LINK_LIBRARIES GTest::gtest_main detray_tests_common covfie_core ) diff --git a/tests/unit_tests/covfie/constant_field.cpp b/tests/unit_tests/covfie/constant_field.cpp new file mode 100644 index 000000000..d469c4b0e --- /dev/null +++ b/tests/unit_tests/covfie/constant_field.cpp @@ -0,0 +1,64 @@ +/** Detray library, part of the ACTS project (R&D line) + * + * (c) 2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#include + +// detray test +#include "tests/common/test_defs.hpp" + +// covfie core +#include +#include +#include + +TEST(Covfie, ConstantField1D) { + using field_t = + covfie::field>; + + field_t f(field_t::backend_t::configuration_t{2.f}); + field_t::view_t v(f); + + for (float x = -100.f; x <= 100.f; x += 1.) { + EXPECT_EQ(v.at(x)[0], 2.f); + } +} + +TEST(Covfie, ConstantField2D) { + using field_t = + covfie::field>; + + field_t f(field_t::backend_t::configuration_t{2.f, 5.f}); + field_t::view_t v(f); + + for (float x = -100.f; x <= 100.f; x += 1.) { + for (float y = -100.f; y <= 100.f; y += 1.) { + EXPECT_EQ(v.at(x, y)[0], 2.f); + EXPECT_EQ(v.at(x, y)[1], 5.f); + } + } +} + +TEST(Covfie, ConstantField3D) { + using field_t = + covfie::field>; + + field_t f(field_t::backend_t::configuration_t{2.f, 5.f, -4.f}); + field_t::view_t v(f); + + for (float x = -10.f; x <= 10.f; x += 1.) { + for (float y = -10.f; y <= 10.f; y += 1.) { + for (float z = -10.f; z <= 10.f; z += 1.) { + EXPECT_EQ(v.at(x, y, z)[0], 2.f); + EXPECT_EQ(v.at(x, y, z)[1], 5.f); + EXPECT_EQ(v.at(x, y, z)[2], -4.f); + } + } + } +}