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