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
16using NonConfigType = std::nullopt_t;
17
19template <std::size_t N1, std::size_t N2>
20constexpr std::array<std::string_view, N1 + N2>
21concat_arrays(const std::array<std::string_view, N1>& arr1,
22 const std::array<std::string_view, N2>& arr2)
23{
24 std::array<std::string_view, N1 + N2> result;
25 std::copy(arr1.begin(), arr1.end(), result.begin());
26 std::copy(arr2.begin(), arr2.end(), result.begin() + N1);
27 return result;
28}
29
30template <typename T>
31concept ConfigurableInit = requires(T model,
32 const std::size_t size,
33 const MC::pool_type& random_pool,
34 std::size_t idx,
35 const typename T::SelfParticle& arr,
36 const T::Config& config) {
37 { model.init(random_pool, idx, arr, config) } -> std::same_as<void>;
38
39 { model.get_config(size) } -> std::same_as<typename T::Config>;
40};
41
42template <typename T>
43concept NonConfigurableInit = requires(T model,
44 const MC::pool_type& random_pool,
45 std::size_t idx,
46 const typename T::SelfParticle& arr) {
47 { model.init(random_pool, idx, arr) } -> std::same_as<void>;
48};
49
50template <typename T>
51concept has_name = requires(T t) {
52 { T::name } -> std::convertible_to<std::string_view>;
53};
54
55template <typename T>
56concept has_species_name = requires(T t) {
57 { T::species() } -> std::ranges::range;
58} && std::convertible_to<std::ranges::range_value_t<decltype(T::species())>, std::string_view>;
59
66template <typename T, typename ViewType>
67concept CommonModelType = requires(T model,
68 const T::FloatType d_t,
69 const std::size_t idx,
70 const std::size_t idx2,
71 const double weight,
72 const T::SelfParticle& arr,
73 const T::SelfContribs& contribs_arr,
74 const T::SelfParticle& buffer_arr,
76 const std::size_t position,
77 const MC::ContributionView& contributions,
78 const MC::pool_type& random_pool,
79 const T::Config& config) {
80 {
81 T::n_var
82 } -> std::convertible_to<std::size_t>;
83
84 // FIXME doesnt work with n_c==0
85 {
86 T::n_c
87 } -> std::convertible_to<std::size_t>;
88
90 typename T::FloatType;
92
93 typename T::SelfParticle;
95
96 typename T::SelfContribs;
98
99 typename T::Self;
100 typename T::Config;
101
102 requires ConfigurableInit<T>
103 || (std::is_same_v<typename T::Config, NonConfigType>
105
106 // {
107 // T::init(random_pool, idx, arr, config)
108 // } -> std::same_as<void>; ///< Main init function applied to each MC
109 // particle at the begin of the
110 // ///< simulation
111
112 {
113 T::mass(idx, arr)
114 } -> std::same_as<double>;
115
116 {
117 T::update(random_pool, d_t, idx, arr, contribs_arr, position, c)
118 } -> std::convertible_to<MC::Status>;
119
120 // {
121 // T::contribution(idx, position, weight, arr, contributions)
122 // } -> std::same_as<void>; ///< Get the individual contribution for the MC
123 // particle
124
125 // { T::get_bounds() } -> std::same_as<MC::ContribIndexBounds>;
126
127 {
128 T::division(random_pool, idx, idx2, arr, buffer_arr)
129 } -> std::same_as<void>;
131
133};
134
138template <typename T>
141
146template <typename T>
149
152template <typename T>
154
155template <typename T>
157
158template <typename T>
160
163template <std::size_t n, typename T>
164concept _HasExportProperties = requires(const T obj) {
165 { T::names() } -> std::convertible_to<std::array<std::string_view, n>>;
166};
167
169template <typename T>
170concept HasExportPropertiesFull = FixedModelType<T> && requires(const T obj) {
171 { T::names() } -> std::convertible_to<std::array<std::string_view, T::n_var>>;
172};
173
175template <typename T>
176concept HasExportPropertiesPartial = ModelType<T> && requires(const T obj) {
177 { T::names() } -> std::convertible_to<std::vector<std::string_view>>;
178 { T::get_number() } -> std::convertible_to<std::vector<std::size_t>>;
179};
180
182template <typename T>
185
186// Helper to detect if `uniform_weight` exists as a type alias (using `using`
187// keyword)
188template <typename T, typename = void>
189struct has_uniform_weight : std::false_type
190{
191};
192
193template <typename T>
194struct has_uniform_weight<T, std::void_t<typename T::uniform_weight>>
195 : std::true_type
196{
197};
198
200template <typename T>
202
204template <typename T>
205concept PreInitModel = ModelType<T> && requires(T model) { T::preinit(); };
206
207#endif
Concept to define a correct Model.
Definition traits.hpp:67
Definition traits.hpp:31
Definition traits.hpp:159
Concept to check if a model type has uniform_weight
Definition traits.hpp:201
SFNIAE wau to declare a model with number of internal properties not known at compile time Alows to p...
Definition traits.hpp:148
SFNIAE way to declare a model with number of internal properties known at compile time.
Definition traits.hpp:140
Definition traits.hpp:20
SFNIAE way to check whether model allow all value saving.
Definition traits.hpp:170
SFNIAE way to check whether model allow partial value saving.
Definition traits.hpp:176
Model that can export properties.
Definition traits.hpp:184
Model type.
Definition traits.hpp:153
Definition traits.hpp:43
Definition traits.hpp:156
Concept to check if a model type has uniform_weight
Definition traits.hpp:205
SFNIAE way to check whether model allow internal value saving or not.
Definition traits.hpp:164
Definition traits.hpp:51
Definition traits.hpp:56
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:190