BioCMAMC-ST
traits.hpp
1#ifndef __MODELS_TRAITS_HPP__
2#define __MODELS_TRAITS_HPP__
3
4#include <Kokkos_Core_fwd.hpp>
5#include <Kokkos_Random.hpp>
6#include <Kokkos_ScatterView.hpp>
7#include <common/common.hpp>
8#include <common/traits.hpp>
9#include <concepts>
10#include <cstdint>
11#include <mc/alias.hpp>
12#include <mc/macros.hpp>
13#include <mc/prng/prng.hpp>
14#include <optional>
15#include <type_traits>
16
18template <std::size_t N1, std::size_t N2>
19constexpr std::array<std::string_view, N1 + N2>
20concat_arrays(const std::array<std::string_view, N1>& arr1,
21 const std::array<std::string_view, N2>& arr2)
22{
23 std::array<std::string_view, N1 + N2> result;
24 std::copy(arr1.begin(), arr1.end(), result.begin());
25 std::copy(arr2.begin(), arr2.end(), result.begin() + N1);
26 return result;
27}
28
29namespace MC
30{
31
32 // NOLINTBEGIN(hicpp-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays)
33 template <uint64_t Nd, FloatingPointType F>
34 using ParticlesModel = Kokkos::View<F* [Nd], Kokkos::LayoutRight>;
35 template <FloatingPointType F>
36 using DynParticlesModel = Kokkos::View<F**, Kokkos::LayoutRight>;
37 // NOLINTEND(hicpp-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays)
38
39}; // namespace MC
40
41template <typename T>
42concept ConfigurableInit = requires(T model,
43 const std::size_t size,
44 const MC::KPRNG::pool_type& random_pool,
45 std::size_t idx,
46 const typename T::SelfParticle& arr,
47 const T::Config& config) {
48 { model.init(random_pool, idx, arr, config) } -> std::same_as<void>;
49
50 { model.get_config(size) } -> std::same_as<typename T::Config>;
51};
52
53template <typename T>
54concept NonConfigurableInit = requires(T model,
55 const MC::KPRNG::pool_type& random_pool,
56 std::size_t idx,
57 const typename T::SelfParticle& arr) {
58 { model.init(random_pool, idx, arr) } -> std::same_as<void>;
59};
60using NonConfigType = std::nullopt_t;
67template <typename T, typename ViewType>
68concept CommonModelType = requires(T model,
69 T::FloatType d_t,
70 std::size_t idx,
71 std::size_t idx2,
72 double weight,
73 const T::SelfParticle& arr,
74 const T::SelfParticle& buffer_arr,
76 std::size_t position,
77 const MC::ContributionView& contributions,
78 const MC::KPRNG::pool_type& random_pool,
79 const T::Config& config) {
80 {
81 T::n_var
82 } -> std::convertible_to<std::size_t>;
84 typename T::FloatType;
86 typename T::SelfParticle;
88 typename T::Self;
89 typename T::Config;
90
91 // Check if the model is configurable
92 // requires(std::is_same_v<typename T::Config, std::nullopt_t> ?
93 // NonConfigurableInit<T>
94 // :
95 // ConfigurableInit<T>);
96
97 requires ConfigurableInit<T> ||
98 (std::is_same_v<typename T::Config, NonConfigType> &&
100
101 // {
102 // T::init(random_pool, idx, arr, config)
103 // } -> std::same_as<void>; ///< Main init function applied to each MC
104 // particle at the begin of the
105 // ///< simulation
106
107 {
108 T::mass(idx, arr)
109 } -> std::same_as<double>;
110
111 {
112 T::update(random_pool, d_t, idx, arr, c)
113 } -> std::convertible_to<MC::Status>;
114
115 // {
116 // T::contribution(idx, position, weight, arr, contributions)
117 // } -> std::same_as<void>; ///< Get the individual contribution for the MC
118 // particle
119
120 { T::get_bounds() } -> std::same_as<MC::ContribIndexBounds>;
121
122 {
123 T::division(random_pool, idx, idx2, arr, buffer_arr)
124 } -> std::same_as<void>;
126
128};
129
133template <typename T>
136
141template <typename T>
144
147template <typename T>
149
150template <typename T>
152
153template <typename T>
155
158template <std::size_t n, typename T>
159concept _HasExportProperties = requires(const T obj) {
160 { T::names() } -> std::convertible_to<std::array<std::string_view, n>>;
161};
162
164template <typename T>
165concept HasExportPropertiesFull = FixedModelType<T> && requires(const T obj) {
166 { T::names() } -> std::convertible_to<std::array<std::string_view, T::n_var>>;
167};
168
170template <typename T>
171concept HasExportPropertiesPartial = ModelType<T> && requires(const T obj) {
172 { T::names() } -> std::convertible_to<std::vector<std::string_view>>;
173 { T::get_number() } -> std::convertible_to<std::vector<std::size_t>>;
174};
175
177template <typename T>
180
181// Helper to detect if `uniform_weight` exists as a type alias (using `using`
182// keyword)
183template <typename T, typename = void>
184struct has_uniform_weight : std::false_type
185{
186};
187
188template <typename T>
189struct has_uniform_weight<T, std::void_t<typename T::uniform_weight>>
190 : std::true_type
191{
192};
193
195template <typename T>
197
199template <typename T>
200concept PreInitModel = ModelType<T> && requires(T model) { T::preinit(); };
201
202#endif
Kokkos::Random_XorShift1024_Pool< Kokkos::DefaultExecutionSpace > pool_type
Definition prng.hpp:33
Concept to define a correct Model.
Definition traits.hpp:68
Definition traits.hpp:42
Definition traits.hpp:154
Concept to check if a model type has uniform_weight
Definition traits.hpp:196
SFNIAE wau to declare a model with number of internal properties not known at compile time Alows to p...
Definition traits.hpp:142
SFNIAE way to declare a model with number of internal properties known at compile time.
Definition traits.hpp:134
Definition traits.hpp:20
SFNIAE way to check whether model allow all value saving.
Definition traits.hpp:165
SFNIAE way to check whether model allow partial value saving.
Definition traits.hpp:171
Model that can export properties.
Definition traits.hpp:178
Model type.
Definition traits.hpp:148
Definition traits.hpp:54
Definition traits.hpp:151
Concept to check if a model type has uniform_weight
Definition traits.hpp:200
SFNIAE way to check whether model allow internal value saving or not.
Definition traits.hpp:159
Namespace that contains classes and structures related to Monte Carlo (MC) simulations.
Definition alias.hpp:9
decltype(Kokkos::Experimental::create_scatter_view(kernelContribution())) ContributionView
Definition alias.hpp:64
Kokkos::Subview< KernelConcentrationType, int, decltype(Kokkos::ALL)> LocalConcentration
Definition alias.hpp:72
Kokkos::View< F *[Nd], Kokkos::LayoutRight > ParticlesModel
Definition traits.hpp:34
Kokkos::View< F **, Kokkos::LayoutRight > DynParticlesModel
Definition traits.hpp:36
Definition traits.hpp:185