BioCMAMC-ST
domain.hpp
1#ifndef __MC_REACTORDOMAIN_HPP__
2#define __MC_REACTORDOMAIN_HPP__
3
4#include <Kokkos_Core.hpp>
5#include <cassert>
6#include <common/common.hpp>
7#include <cstddef>
8#include <cstdint>
9#include <mc/alias.hpp>
10#include <mc/traits.hpp>
11#include <span>
12
13namespace MC
14{
15
18 {
19 using float_type = double;
20 std::size_t index;
23 };
24
37
57 {
58 public:
59 using n_cells_view_type = Kokkos::View<uint64_t*, ComputeSpace>;
60 ReactorDomain(const ReactorDomain&) = delete;
62
67
71 ReactorDomain(ReactorDomain&& other) noexcept = default;
72
76 explicit ReactorDomain(std::span<double> volumes);
77
78 ReactorDomain(double total_volume, std::size_t size);
79
83 ~ReactorDomain() = default;
84
88 ReactorDomain& operator=(ReactorDomain&& other) noexcept;
89
90 void update(std::span<const double> newliquid_volume,
91 std::span<const std::size_t> neighors_flat,
92 std::span<const double> out_flows,
93 std::span<const double> proba_flat);
94
95 void set_leaving_flow(std::size_t i,
96 std::size_t i_flow,
97 double flow,
98 double volume) const;
99
103 void set_move_probability(double d_t) const;
104
105 void init_inner(std::size_t n_flows);
106
108
112 [[nodiscard]] size_t getNumberCompartments() const noexcept;
113
117 [[nodiscard]] double getTotalVolume() const noexcept;
118
122 template <class Archive>
123 void
124 save(Archive& ar) const
125 {
126
127 ar(id, size, _total_volume);
128 }
129
130 template <class Archive>
131 void
132 load(Archive& ar)
133 {
134 ar(id, size, _total_volume);
135 }
136
137 private:
138 double _total_volume = 0.;
139 size_t id = 0;
140 size_t size = 0;
142
147 Kokkos::View<double*, HostSpace> host_liquid_volume;
148 Kokkos::View<double*, HostSpace> host_diag_transition;
149 Kokkos::View<double*, HostSpace> host_move_probability;
150
154 void setVolumes(std::span<double const> volumes_liq);
155
159 void setLiquidNeighbors(std::size_t e1,
160 std::size_t e2,
161 std::span<const size_t> flat_data);
162 };
163
164 // inline NeighborsView<ComputeSpace, true> ReactorDomain::getNeighbors() const
165 // {
166 // return this->inner.neighbors;
167 // }
168
169 inline size_t
171 {
172 return size;
173 }
174
175 inline double
177 {
178 return this->_total_volume;
179 }
180
181 [[nodiscard]] inline DomainState<ComputeSpace, true>
183 {
184
185 return {
186 inner.neighbors, inner.diag_transition, inner.cumulative_probability,
187 inner.leaving_flow, inner.liquid_volume, inner.move_probability
188 };
189 }
190
191} // namespace MC
192
193#endif //__MC_REACTORDOMAIN_HPP__
void update(std::span< const double > newliquid_volume, std::span< const std::size_t > neighors_flat, std::span< const double > out_flows, std::span< const double > proba_flat)
Definition domain.cpp:45
double _total_volume
Domain total volume.
Definition domain.hpp:138
DomainState< ComputeSpace, true > get_const_inner()
Definition domain.hpp:182
ReactorDomain & operator=(const ReactorDomain &)=delete
~ReactorDomain()=default
Default destructor.
Kokkos::View< uint64_t *, ComputeSpace > n_cells_view_type
Definition domain.hpp:59
void load(Archive &ar)
Definition domain.hpp:132
double getTotalVolume() const noexcept
Return total volume of domain.
Definition domain.hpp:176
ReactorDomain()
Default constructor.
Definition domain.cpp:32
void setLiquidNeighbors(std::size_t e1, std::size_t e2, std::span< const size_t > flat_data)
Update neigbors of compartments.
Definition domain.cpp:79
void init_inner(std::size_t n_flows)
Definition domain.cpp:145
size_t size
Number of compartment.
Definition domain.hpp:140
void set_move_probability(double d_t) const
Refresh the per-compartment move probability for this time step. Must be called before the move kerne...
Definition domain.cpp:125
void save(Archive &ar) const
Return a const reference to neighbors.
Definition domain.hpp:124
Kokkos::View< double *, HostSpace > host_diag_transition
Definition domain.hpp:148
void setVolumes(std::span< double const > volumes_liq)
Set volume of liquid and gas of each compartment.
Definition domain.cpp:14
void set_leaving_flow(std::size_t i, std::size_t i_flow, double flow, double volume) const
Definition domain.cpp:99
ReactorDomain(const ReactorDomain &)=delete
Kokkos::View< double *, HostSpace > host_liquid_volume
Definition domain.hpp:147
DomainState< ComputeSpace, false > inner
Definition domain.hpp:141
size_t getNumberCompartments() const noexcept
Return the number of compartment in the domain.
Definition domain.hpp:170
Kokkos::View< double *, HostSpace > host_move_probability
Definition domain.hpp:149
ReactorDomain(ReactorDomain &&other) noexcept=default
Move constructor.
Namespace that contains classes and structures related to Monte Carlo (MC) simulations.
Definition alias.hpp:16
std::conditional_t< is_const, Kokkos::View< const std::size_t **, Kokkos::LayoutRight, ExecSpace, Kokkos::MemoryTraits< Kokkos::RandomAccess > >, Kokkos::View< std::size_t **, Kokkos::LayoutRight, ExecSpace > > NeighborsView
Definition alias.hpp:215
std::conditional_t< is_const, Kokkos::View< const double *, ExecSpace, Kokkos::MemoryTraits< Kokkos::RandomAccess > >, Kokkos::View< double *, ExecSpace > > MoveProbabilityView
d_t * flow / volume per compartment. Owned by ReactorDomain
Definition alias.hpp:182
std::conditional_t< is_const, Kokkos::View< const double *, ExecSpace, Kokkos::MemoryTraits< Kokkos::RandomAccess > >, Kokkos::View< double *, ExecSpace > > VolumeView
Definition alias.hpp:173
std::conditional_t< is_const, Kokkos::View< const LeavingFlow *, Kokkos::SharedHostPinnedSpace >, Kokkos::View< LeavingFlow *, Kokkos::SharedHostPinnedSpace > > LeavingFlowView
Definition alias.hpp:199
std::conditional_t< is_const, Kokkos::View< const double **, Kokkos::LayoutRight, ExecSpace, Kokkos::MemoryTraits< Kokkos::RandomAccess > >, Kokkos::View< double **, Kokkos::LayoutRight, ExecSpace > > CumulativeProbabilityView
Definition alias.hpp:206
std::conditional_t< is_const, Kokkos::View< const double *, Kokkos::LayoutLeft, ExecSpace, Kokkos::MemoryTraits< Kokkos::RandomAccess > >, Kokkos::View< double *, Kokkos::LayoutLeft, ExecSpace > > DiagonalView
Definition alias.hpp:190
Structure to store information about domain needed during MC cycle data is likely to change between e...
Definition domain.hpp:29
MoveProbabilityView< ExecSpace, is_const > move_probability
Definition domain.hpp:35
VolumeView< ExecSpace, is_const > liquid_volume
Definition domain.hpp:34
MC::NeighborsView< ExecSpace, is_const > neighbors
Definition domain.hpp:30
DiagonalView< ExecSpace, is_const > diag_transition
Definition domain.hpp:31
LeavingFlowView< is_const > leaving_flow
Definition domain.hpp:33
CumulativeProbabilityView< ExecSpace, is_const > cumulative_probability
Definition domain.hpp:32
Store position and value of volumic flow at outlet.
Definition domain.hpp:18
std::size_t index
Definition domain.hpp:20
float_type flow
Definition domain.hpp:21
float_type volume
Definition domain.hpp:22
double float_type
Definition domain.hpp:19