BioCMAMC-ST
transitionner.hpp
1#ifndef __CMA_UTILS_TRANSITIONNER_HPP__
2#define __CMA_UTILS_TRANSITIONNER_HPP__
3
4#include <cma_read/flow_iterator.hpp>
5#include <cma_read/neighbors.hpp>
6#include <cma_read/reactorstate.hpp>
7#include <cma_utils/cache_hydro_state.hpp>
8#include <cma_utils/iteration_state.hpp>
9#include <cstddef>
10#include <memory>
11#include <transitionner/proxy_cache.hpp>
12
13namespace CmaUtils
14{
25
26 // Forward declaration
27 class ProxyPreCalculatedHydroState;
28
41 {
42 public:
46
49
50 FlowMapTransitionner(std::size_t _n_flowmap,
51 std::size_t _n_per_flowmap,
52 std::size_t number_time_step,
53 std::unique_ptr<CmaRead::FlowIterator>&& _iterator,
55
56 virtual ~FlowMapTransitionner() = default;
57
67
77 advance_worker(std::span<double> flows,
78 std::span<double> volumeLiq,
79 std::span<double> volumeGas,
80 const CmaRead::Neighbors::Neighbors_const_view_t& neighbors);
81
88 [[nodiscard]] bool is_two_phase_flow() const noexcept;
89
93 [[nodiscard]] std::size_t get_n_timestep() const noexcept;
94
101 [[nodiscard]] virtual const CmaRead::ReactorState&
102 get_current_reactor_state() const noexcept = 0;
103
113 static NeighborsView<HostSpace> get_neighbors_view(
114 const CmaRead::Neighbors::Neighbors_const_view_t& liquid_neighbors);
115
116 protected:
120 [[nodiscard]] bool need_liquid_state_calculation() const noexcept;
121
127 NeighborsView<HostSpace> host_view,
128 std::unordered_map<std::string, std::span<const double>>&& info);
129
134 virtual void update_flow() = 0;
135
141 std::span<double> flows,
142 std::span<double> volumeLiq,
143 std::span<double> volumeGas,
144 const CmaRead::Neighbors::Neighbors_const_view_t& neighbors);
145
156
162 const CmaRead::ReactorState& reactor_state,
163 CmaUtils::ProxyPreCalculatedHydroState& liq_hydro_state,
164 CmaUtils::ProxyPreCalculatedHydroState& gas_hydro_state) const;
165
169 [[nodiscard]] size_t getFlowIndex() const noexcept;
170
174 [[nodiscard]] size_t size() const noexcept;
175
179 [[nodiscard]] const CmaRead::ReactorState&
180 get_unchecked(size_t index) const noexcept;
181
182 // Buffer for caching, vector have the same size which is the number of
183 // flowmap read from case
188
189 private:
193 void update_counters();
194
196 std::size_t n_per_flowmap{};
197 std::size_t n_flowmap{};
198 std::size_t n_timestep{};
199 std::size_t repetition_count{};
201 std::size_t
204 std::unique_ptr<CmaRead::FlowIterator>
206 };
207
208 [[nodiscard]] inline size_t
210 {
211 // Modulo is used to select correct index into buffers.
212 // During the first loop we have repetition_count<n_flowmap but after
213 // looping we have repetition_count>n_flowmap
214 return this->repetition_count % this->n_flowmap;
215 }
216
217 [[nodiscard]] inline size_t FlowMapTransitionner::size() const noexcept
218 {
219 return iterator->size();
220 }
221
222 [[nodiscard]] inline bool
224 {
225 return two_phase_flow;
226 }
227
228 [[nodiscard]] inline bool
230 {
231 // We need to calculated new state if:
232 //- it is the first time we have this flowmap (this->current_flowmap_count)
233 // We have not already looped through all the flowmap
234 return repetition_count < n_flowmap && this->current_flowmap_count == 0;
235 }
236
237 [[nodiscard]] inline const CmaRead::ReactorState&
238 FlowMapTransitionner::get_unchecked(const std::size_t index) const noexcept
239 {
240 return iterator->get_unchecked(index);
241 };
242
243}; // namespace CmaUtils
244
245#endif
bool two_phase_flow
Is two_phase_flow.
Definition transitionner.hpp:195
std::unique_ptr< CmaRead::FlowIterator > iterator
Iterator that reads flowmap.
Definition transitionner.hpp:205
std::size_t n_flowmap
Number of flowmap.
Definition transitionner.hpp:197
virtual ~FlowMapTransitionner()=default
virtual void update_flow()=0
Calculate the current state based on the selected method, may be caching or direct calculation.
bool need_liquid_state_calculation() const noexcept
Check if liquid state has to calculated or can be use via caching.
Definition transitionner.hpp:229
FlowMapTransitionner & operator=(FlowMapTransitionner &&)=default
virtual CmaUtils::ProxyPreCalculatedHydroState & current_liq_hydro_state()=0
Get current liquid state read from CmaRead.
std::size_t repetition_count
Definition transitionner.hpp:199
virtual CmaUtils::ProxyPreCalculatedHydroState & current_gas_hydro_state()=0
Get current gas state read from CmaRead.
IterationState common_advance(NeighborsView< HostSpace > host_view, std::unordered_map< std::string, std::span< const double > > &&info)
Operation required by all methods in order to perform advance function .
Definition transitionner.cpp:162
static NeighborsView< HostSpace > get_neighbors_view(const CmaRead::Neighbors::Neighbors_const_view_t &liquid_neighbors)
Converts the provided neighbors' data into a Kokkos view.
Definition transitionner.cpp:55
FlowMapTransitionner(FlowMapTransitionner &&)=default
FlowMapTransitionner(const FlowMapTransitionner &)=delete
virtual const CmaRead::ReactorState & get_current_reactor_state() const noexcept=0
Provides a const reference to the current reactor state.
FlowMapTransitionner(std::size_t _n_flowmap, std::size_t _n_per_flowmap, std::size_t number_time_step, std::unique_ptr< CmaRead::FlowIterator > &&_iterator, bool is_two_phase_flow)
FlowMapTransitionner & operator=(const FlowMapTransitionner &)=delete
size_t getFlowIndex() const noexcept
Return the index of the current ProxyPreCalculatedHydroState.
Definition transitionner.hpp:209
std::size_t n_timestep
Total number of timestep.
Definition transitionner.hpp:198
IterationState advance()
Advances the simulation by one timestep.
Definition transitionner.cpp:132
std::vector< CmaUtils::ProxyPreCalculatedHydroState > liquid_pc
Buffer for liquid state.
Definition transitionner.hpp:185
std::size_t current_flowmap_count
Definition transitionner.hpp:202
void update_flow_worker(std::span< double > flows, std::span< double > volumeLiq, std::span< double > volumeGas, const CmaRead::Neighbors::Neighbors_const_view_t &neighbors)
ONLY for MPI_WORKER Calculate the current state based on the selected method, may be caching or direc...
Definition transitionner.cpp:78
std::vector< CmaUtils::ProxyPreCalculatedHydroState > gas_pc
Buffer for gas state.
Definition transitionner.hpp:187
bool is_two_phase_flow() const noexcept
Checks whether a gas flowmap is provided.
Definition transitionner.hpp:223
size_t size() const noexcept
Get the number of load flowmap.
Definition transitionner.hpp:217
std::size_t n_per_flowmap
Number of iteration per flowmap.
Definition transitionner.hpp:196
void update_counters()
Update flow and iteration counters.
Definition transitionner.cpp:176
const CmaRead::ReactorState & get_unchecked(size_t index) const noexcept
Direct read state from iterator.
Definition transitionner.hpp:238
IterationState advance_worker(std::span< double > flows, std::span< double > volumeLiq, std::span< double > volumeGas, const CmaRead::Neighbors::Neighbors_const_view_t &neighbors)
Advances the simulation by one timestep from a MPI Wroker.
Definition transitionner.cpp:147
void calculate_full_state(const CmaRead::ReactorState &reactor_state, CmaUtils::ProxyPreCalculatedHydroState &liq_hydro_state, CmaUtils::ProxyPreCalculatedHydroState &gas_hydro_state) const
Calculate the whole state (liquid+gas+neighbor) for the current time step.
Definition transitionner.cpp:105
std::size_t get_n_timestep() const noexcept
Returns the total number of expected simulation timesteps.
Definition transitionner.cpp:192
Proxy class for PreCalculatedHydroState used to fill this struct with data from an external library.
Definition proxy_cache.hpp:28
Namespace to handle algorithms and structures related to reading compartment mesh.
Definition host_specific.hpp:18
FlowmapTransitionMethod
Defines the transition methods used between flowmaps.
Definition transitionner.hpp:20
@ Discontinuous
Represents a sharp, abrupt transition.
Definition transitionner.hpp:21
@ InterpolationFO
Definition transitionner.hpp:22
Kokkos::View< std::size_t **, Kokkos::LayoutRight, Space, Kokkos::MemoryTraits< Kokkos::RandomAccess > > NeighborsView
Definition iteration_state.hpp:11
Structure to store information about the reactor state during simulation.
Definition iteration_state.hpp:25