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 <type_traits>
15#include <optional>
16
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
30namespace MC
31{
32
33 // NOLINTBEGIN(hicpp-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays)
34 template <uint64_t Nd, FloatingPointType F> using ParticlesModel = Kokkos::View<F* [Nd]>;
35 template <FloatingPointType F> using DynParticlesModel = Kokkos::View<F**>;
36 // NOLINTEND(hicpp-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays)
37
38}; // namespace MC
39
40template <typename T>
41concept ConfigurableInit = requires(T model,
42 const MC::KPRNG::pool_type& random_pool,
43 std::size_t idx,
44 const typename T::SelfParticle& arr,
45 const T::Config& config) {
46 { model.init(random_pool, idx, arr, config) } -> std::same_as<void>;
47};
48
49template <typename T>
50concept NonConfigurableInit = requires(T model,
51 const MC::KPRNG::pool_type& random_pool,
52 std::size_t idx,
53 const typename T::SelfParticle& arr) {
54 { model.init(random_pool, idx, arr) } -> std::same_as<void>;
55};
56
63template <typename T, typename ViewType>
64concept CommonModelType = requires(T model,
65 T::FloatType d_t,
66 std::size_t idx,
67 std::size_t idx2,
68 double weight,
69 const T::SelfParticle& arr,
70 const T::SelfParticle& buffer_arr,
72 std::size_t position,
73 const MC::ContributionView& contributions,
74 const MC::KPRNG::pool_type& random_pool,
75 const T::Config& config) {
76 {
77 T::n_var
78 } -> std::convertible_to<std::size_t>;
79 typename T::FloatType;
81 typename T::SelfParticle;
82 typename T::Self;
83 typename T::Config;
84
85 // Check if the model is configurable
86 // requires(std::is_same_v<typename T::Config, std::nullopt_t> ? NonConfigurableInit<T>
87 // : ConfigurableInit<T>);
88
89 requires ConfigurableInit<T> || (std::is_same_v<typename T::Config, std::nullopt_t> && NonConfigurableInit<T>);
90
91
92 // {
93 // T::init(random_pool, idx, arr, config)
94 // } -> std::same_as<void>; ///< Main init function applied to each MC particle at the begin of the
95 // ///< simulation
96
97 { T::mass(idx, arr) } -> std::same_as<double>;
98
99 {
100 T::update(random_pool, d_t, idx, arr, c)
101 } -> std::convertible_to<MC::Status>;
102
103 {
104 T::contribution(idx, position, weight, arr, contributions)
105 } -> std::same_as<void>;
106
107 {
108 T::division(random_pool, idx, idx2, arr, buffer_arr)
109 } -> std::same_as<void>;
110
112};
113
114
115
118template <typename T>
120
124template <typename T>
126
129template <typename T>
131
132template <typename T>
134
135template <typename T>
137
139template <std::size_t n, typename T>
140concept _HasExportProperties = requires(const T obj) {
141 { T::names() } -> std::convertible_to<std::array<std::string_view, n>>;
142};
143
145template <typename T>
146concept HasExportPropertiesFull = FixedModelType<T> && requires(const T obj) {
147 { T::names() } -> std::convertible_to<std::array<std::string_view, T::n_var>>;
148};
149
151template <typename T>
152concept HasExportPropertiesPartial = ModelType<T> && requires(const T obj) {
153 { T::names() } -> std::convertible_to<std::vector<std::string_view>>;
154 { T::get_number() } -> std::convertible_to<std::vector<std::size_t>>;
155};
156
158template <typename T>
160
161// Helper to detect if `uniform_weight` exists as a type alias (using `using` keyword)
162template <typename T, typename = void> struct has_uniform_weight : std::false_type
163{
164};
165
166template <typename T>
167struct has_uniform_weight<T, std::void_t<typename T::uniform_weight>> : std::true_type
168{
169};
170
172template <typename T>
174
176template <typename T>
177concept PreInitModel = ModelType<T> && requires(T model) { T::preinit(); };
178
179#endif
Kokkos::Random_XorShift1024_Pool< Kokkos::DefaultExecutionSpace > pool_type
Definition prng.hpp:17
Concept to define a correct Model.
Definition traits.hpp:64
Definition traits.hpp:41
Definition traits.hpp:136
Concept to check if a model type has uniform_weight
Definition traits.hpp:173
SFNIAE wau to declare a model with number of internal properties not known at compile time Alows to p...
Definition traits.hpp:125
SFNIAE way to declare a model with number of internal properties known at compile time.
Definition traits.hpp:119
Definition traits.hpp:20
SFNIAE way to check whether model allow all value saving.
Definition traits.hpp:146
SFNIAE way to check whether model allow partial value saving.
Definition traits.hpp:152
Model that can export properties.
Definition traits.hpp:159
Model type.
Definition traits.hpp:130
Definition traits.hpp:50
Definition traits.hpp:133
Concept to check if a model type has uniform_weight
Definition traits.hpp:177
SFNIAE way to check whether model allow internal value saving or not
Definition traits.hpp:140
Namespace that contains classes and structures related to Monte Carlo (MC) simulations.
Definition alias.hpp:9
Kokkos::Subview< KernelConcentrationType, int, decltype(Kokkos::ALL)> LocalConcentration
Definition alias.hpp:42
Kokkos::Experimental::ScatterView< double **, Kokkos::LayoutRight > ContributionView
Definition alias.hpp:31
Kokkos::View< F *[Nd]> ParticlesModel
Definition traits.hpp:34
Kokkos::View< F ** > DynParticlesModel
Definition traits.hpp:35
Definition traits.hpp:163