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 <mc/alias.hpp>
11#include <mc/macros.hpp>
12#include <mc/prng/prng.hpp>
13#include <optional>
14#include <type_traits>
15
17template <std::size_t N1, std::size_t N2>
18constexpr std::array<std::string_view, N1 + N2>
19concat_arrays(const std::array<std::string_view, N1>& arr1,
20 const std::array<std::string_view, N2>& arr2)
21{
22 std::array<std::string_view, N1 + N2> result;
23 std::copy(arr1.begin(), arr1.end(), result.begin());
24 std::copy(arr2.begin(), arr2.end(), result.begin() + N1);
25 return result;
26}
27
28template <typename T>
29concept ConfigurableInit = requires(T model,
30 const std::size_t size,
31 const MC::pool_type& random_pool,
32 std::size_t idx,
33 const typename T::SelfParticle& arr,
34 const T::Config& config) {
35 { model.init(random_pool, idx, arr, config) } -> std::same_as<void>;
36
37 { model.get_config(size) } -> std::same_as<typename T::Config>;
38};
39
40template <typename T>
41concept NonConfigurableInit = requires(T model,
42 const MC::pool_type& random_pool,
43 std::size_t idx,
44 const typename T::SelfParticle& arr) {
45 { model.init(random_pool, idx, arr) } -> std::same_as<void>;
46};
47using NonConfigType = std::nullopt_t;
54template <typename T, typename ViewType>
55concept CommonModelType = requires(T model,
56 T::FloatType d_t,
57 std::size_t idx,
58 std::size_t idx2,
59 double weight,
60 const T::SelfParticle& arr,
61 const T::SelfParticle& buffer_arr,
63 std::size_t position,
64 const MC::ContributionView& contributions,
65 const MC::pool_type& random_pool,
66 const T::Config& config) {
67 {
68 T::n_var
69 } -> std::convertible_to<std::size_t>;
71 typename T::FloatType;
73 typename T::SelfParticle;
75 typename T::Self;
76 typename T::Config;
77
78 // Check if the model is configurable
79 // requires(std::is_same_v<typename T::Config, std::nullopt_t> ?
80 // NonConfigurableInit<T>
81 // :
82 // ConfigurableInit<T>);
83
84 requires ConfigurableInit<T> ||
85 (std::is_same_v<typename T::Config, NonConfigType> &&
87
88 // {
89 // T::init(random_pool, idx, arr, config)
90 // } -> std::same_as<void>; ///< Main init function applied to each MC
91 // particle at the begin of the
92 // ///< simulation
93
94 {
95 T::mass(idx, arr)
96 } -> std::same_as<double>;
97
98 {
99 T::update(random_pool, d_t, idx, arr, c)
100 } -> std::convertible_to<MC::Status>;
101
102 // {
103 // T::contribution(idx, position, weight, arr, contributions)
104 // } -> std::same_as<void>; ///< Get the individual contribution for the MC
105 // particle
106
107 { T::get_bounds() } -> std::same_as<MC::ContribIndexBounds>;
108
109 {
110 T::division(random_pool, idx, idx2, arr, buffer_arr)
111 } -> std::same_as<void>;
113
115};
116
120template <typename T>
123
128template <typename T>
131
134template <typename T>
136
137template <typename T>
139
140template <typename T>
142
145template <std::size_t n, typename T>
146concept _HasExportProperties = requires(const T obj) {
147 { T::names() } -> std::convertible_to<std::array<std::string_view, n>>;
148};
149
151template <typename T>
152concept HasExportPropertiesFull = FixedModelType<T> && requires(const T obj) {
153 { T::names() } -> std::convertible_to<std::array<std::string_view, T::n_var>>;
154};
155
157template <typename T>
158concept HasExportPropertiesPartial = ModelType<T> && requires(const T obj) {
159 { T::names() } -> std::convertible_to<std::vector<std::string_view>>;
160 { T::get_number() } -> std::convertible_to<std::vector<std::size_t>>;
161};
162
164template <typename T>
167
168// Helper to detect if `uniform_weight` exists as a type alias (using `using`
169// keyword)
170template <typename T, typename = void>
171struct has_uniform_weight : std::false_type
172{
173};
174
175template <typename T>
176struct has_uniform_weight<T, std::void_t<typename T::uniform_weight>>
177 : std::true_type
178{
179};
180
182template <typename T>
184
186template <typename T>
187concept PreInitModel = ModelType<T> && requires(T model) { T::preinit(); };
188
189#endif
Concept to define a correct Model.
Definition traits.hpp:55
Definition traits.hpp:29
Definition traits.hpp:141
Concept to check if a model type has uniform_weight
Definition traits.hpp:183
SFNIAE wau to declare a model with number of internal properties not known at compile time Alows to p...
Definition traits.hpp:129
SFNIAE way to declare a model with number of internal properties known at compile time.
Definition traits.hpp:121
Definition traits.hpp:20
SFNIAE way to check whether model allow all value saving.
Definition traits.hpp:152
SFNIAE way to check whether model allow partial value saving.
Definition traits.hpp:158
Model that can export properties.
Definition traits.hpp:165
Model type.
Definition traits.hpp:135
Definition traits.hpp:41
Definition traits.hpp:138
Concept to check if a model type has uniform_weight
Definition traits.hpp:187
SFNIAE way to check whether model allow internal value saving or not.
Definition traits.hpp:146
gen_pool_type< Kokkos::DefaultExecutionSpace > pool_type
Definition alias.hpp:38
decltype(Kokkos::Experimental::create_scatter_view(kernelContribution())) ContributionView
Definition alias.hpp:87
Kokkos::Subview< KernelConcentrationType, int, decltype(Kokkos::ALL)> LocalConcentration
Definition alias.hpp:95
Definition traits.hpp:172