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 const T::FloatType d_t,
57 const std::size_t idx,
58 const std::size_t idx2,
59 const double weight,
60 const T::SelfParticle& arr,
61 const T::SelfContribs& contribs_arr,
62 const T::SelfParticle& buffer_arr,
64 const std::size_t position,
65 const MC::ContributionView& contributions,
66 const MC::pool_type& random_pool,
67 const T::Config& config) {
68 {
69 T::n_var
70 } -> std::convertible_to<std::size_t>;
71
72 // FIXME doesnt work with n_c==0
73 {
74 T::n_c
75 } -> std::convertible_to<std::size_t>;
76
78 typename T::FloatType;
80
81 typename T::SelfParticle;
83
84 typename T::SelfContribs;
86
87 typename T::Self;
88 typename T::Config;
89
90 requires ConfigurableInit<T>
91 || (std::is_same_v<typename T::Config, NonConfigType>
93
94 // {
95 // T::init(random_pool, idx, arr, config)
96 // } -> std::same_as<void>; ///< Main init function applied to each MC
97 // particle at the begin of the
98 // ///< simulation
99
100 {
101 T::mass(idx, arr)
102 } -> std::same_as<double>;
103
104 {
105 T::update(random_pool, d_t, idx, arr, contribs_arr, position, c)
106 } -> std::convertible_to<MC::Status>;
107
108 // {
109 // T::contribution(idx, position, weight, arr, contributions)
110 // } -> std::same_as<void>; ///< Get the individual contribution for the MC
111 // particle
112
113 // { T::get_bounds() } -> std::same_as<MC::ContribIndexBounds>;
114
115 {
116 T::division(random_pool, idx, idx2, arr, buffer_arr)
117 } -> std::same_as<void>;
119
121};
122
126template <typename T>
129
134template <typename T>
137
140template <typename T>
142
143template <typename T>
145
146template <typename T>
148
151template <std::size_t n, typename T>
152concept _HasExportProperties = requires(const T obj) {
153 { T::names() } -> std::convertible_to<std::array<std::string_view, n>>;
154};
155
157template <typename T>
158concept HasExportPropertiesFull = FixedModelType<T> && requires(const T obj) {
159 { T::names() } -> std::convertible_to<std::array<std::string_view, T::n_var>>;
160};
161
163template <typename T>
164concept HasExportPropertiesPartial = ModelType<T> && requires(const T obj) {
165 { T::names() } -> std::convertible_to<std::vector<std::string_view>>;
166 { T::get_number() } -> std::convertible_to<std::vector<std::size_t>>;
167};
168
170template <typename T>
173
174// Helper to detect if `uniform_weight` exists as a type alias (using `using`
175// keyword)
176template <typename T, typename = void>
177struct has_uniform_weight : std::false_type
178{
179};
180
181template <typename T>
182struct has_uniform_weight<T, std::void_t<typename T::uniform_weight>>
183 : std::true_type
184{
185};
186
188template <typename T>
190
192template <typename T>
193concept PreInitModel = ModelType<T> && requires(T model) { T::preinit(); };
194
195#endif
Concept to define a correct Model.
Definition traits.hpp:55
Definition traits.hpp:29
Definition traits.hpp:147
Concept to check if a model type has uniform_weight
Definition traits.hpp:189
SFNIAE wau to declare a model with number of internal properties not known at compile time Alows to p...
Definition traits.hpp:136
SFNIAE way to declare a model with number of internal properties known at compile time.
Definition traits.hpp:128
Definition traits.hpp:20
SFNIAE way to check whether model allow all value saving.
Definition traits.hpp:158
SFNIAE way to check whether model allow partial value saving.
Definition traits.hpp:164
Model that can export properties.
Definition traits.hpp:172
Model type.
Definition traits.hpp:141
Definition traits.hpp:41
Definition traits.hpp:144
Concept to check if a model type has uniform_weight
Definition traits.hpp:193
SFNIAE way to check whether model allow internal value saving or not.
Definition traits.hpp:152
decltype(Kokkos::Experimental::create_scatter_view( kernelContribution())) ContributionView
Definition alias.hpp:162
gen_pool_type< Kokkos::DefaultExecutionSpace > pool_type
Definition alias.hpp:100
KernelConcentrationType LocalConcentration
Definition alias.hpp:170
Definition traits.hpp:178