BioCMAMC-ST
transitionner.hpp
1#ifndef __CMA_UTILS_TRANSITIONNER_HPP__
2#define __CMA_UTILS_TRANSITIONNER_HPP__
3
4#include "cma_read/reactorstate.hpp"
5#include "cma_utils/cache_hydro_state.hpp"
6#include "cma_utils/iteration_state.hpp"
7#include <cma_read/flow_iterator.hpp>
8#include <cma_read/neighbors.hpp>
9#include <cstddef>
10#include <memory>
11#include <transitionner/proxy_cache.hpp>
12
13namespace CmaUtils
14{
19 enum class FlowmapTransitionMethod : char
20 {
23 };
24
25 // Forward declaration
26 class ProxyPreCalculatedHydroState;
27
38 {
39 public:
43
46
47 FlowMapTransitionner(std::size_t _n_flowmap,
48 std::size_t _n_per_flowmap,
49 std::size_t number_time_step,
50 std::unique_ptr<CmaRead::FlowIterator>&& _iterator,
52
53 virtual ~FlowMapTransitionner() = default;
54
64
73 IterationState advance_worker(std::span<double> flows,
74 std::span<double> volumeLiq,
75 std::span<double> volumeGas,
76 const CmaRead::Neighbors::Neighbors_const_view_t& neighbors);
77
84 [[nodiscard]] bool is_two_phase_flow() const noexcept;
85
89 [[nodiscard]] std::size_t get_n_timestep() const noexcept;
90
97 [[nodiscard]] virtual const CmaRead::ReactorState&
98 get_current_reactor_state() const noexcept = 0;
99
109 static NeighborsView<HostSpace>
110 get_neighbors_view(const CmaRead::Neighbors::Neighbors_const_view_t& liquid_neighbors);
111
112 protected:
116 [[nodiscard]] bool need_liquid_state_calculation() const noexcept;
117
121 IterationState common_advance(NeighborsView<HostSpace> host_view,
122 std::unordered_map<std::string, std::span<const double>>&& info);
123
128 virtual void update_flow() = 0;
129
134 void update_flow_worker(std::span<double> flows,
135 std::span<double> volumeLiq,
136 std::span<double> volumeGas,
137 const CmaRead::Neighbors::Neighbors_const_view_t& neighbors);
138
147
151 void calculate_full_state(const CmaRead::ReactorState& reactor_state,
152 CmaUtils::ProxyPreCalculatedHydroState& liq_hydro_state,
153 CmaUtils::ProxyPreCalculatedHydroState& gas_hydro_state) const;
154
158 [[nodiscard]] size_t getFlowIndex() const noexcept;
159
163 [[nodiscard]] size_t size() const noexcept;
164
168 [[nodiscard]] const CmaRead::ReactorState& get_unchecked(size_t index) const noexcept;
169
170 // Buffer for caching, vector have the same size which is the number of flowmap read from case
173
174 private:
178 void update_counters();
179
181 std::size_t n_per_flowmap{};
182 std::size_t n_flowmap{};
183 std::size_t n_timestep{};
184 std::size_t repetition_count{};
185 std::size_t current_flowmap_count{};
187 std::unique_ptr<CmaRead::FlowIterator> iterator;
188 };
189
190 [[nodiscard]] inline size_t FlowMapTransitionner::getFlowIndex() const noexcept
191 {
192 //Modulo is used to select correct index into buffers.
193 //During the first loop we have repetition_count<n_flowmap but after looping we have repetition_count>n_flowmap
194 return this->repetition_count % this->n_flowmap;
195 }
196
197 [[nodiscard]] inline size_t FlowMapTransitionner::size() const noexcept
198 {
199 return iterator->size();
200 }
201
202 [[nodiscard]] inline bool FlowMapTransitionner::is_two_phase_flow() const noexcept
203 {
204 return two_phase_flow;
205 }
206
207 [[nodiscard]] inline bool FlowMapTransitionner::need_liquid_state_calculation() const noexcept
208 {
209 // We need to calculated new state if:
210 //- it is the first time we have this flowmap (this->current_flowmap_count)
211 // We have not already looped through all the flowmap
212 return repetition_count < n_flowmap && this->current_flowmap_count == 0;
213 }
214
215 [[nodiscard]] inline const CmaRead::ReactorState&
216 FlowMapTransitionner::get_unchecked(const std::size_t index) const noexcept
217 {
218 return iterator->get_unchecked(index);
219 };
220
221}; // namespace CmaUtils
222
223#endif
Manages the reading, caching, and transitioning of flowmaps for simulation timesteps.
Definition transitionner.hpp:38
bool two_phase_flow
Is two_phase_flow.
Definition transitionner.hpp:180
std::unique_ptr< CmaRead::FlowIterator > iterator
Iterator that reads flowmap.
Definition transitionner.hpp:187
std::size_t n_flowmap
Number of flowmap.
Definition transitionner.hpp:182
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:207
FlowMapTransitionner & operator=(FlowMapTransitionner &&)=default
virtual CmaUtils::ProxyPreCalculatedHydroState & current_liq_hydro_state()=0
Get current liquid state read from CmaRead.
std::size_t repetition_count
How many flowmaps (different or not) have been used.
Definition transitionner.hpp:184
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:141
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:52
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:190
std::size_t n_timestep
Total number of timestep.
Definition transitionner.hpp:183
IterationState advance()
Advances the simulation by one timestep.
Definition transitionner.cpp:116
std::vector< CmaUtils::ProxyPreCalculatedHydroState > liquid_pc
Buffer for liquid state.
Definition transitionner.hpp:171
std::size_t current_flowmap_count
Definition transitionner.hpp:185
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:72
std::vector< CmaUtils::ProxyPreCalculatedHydroState > gas_pc
Buffer for gas state.
Definition transitionner.hpp:172
bool is_two_phase_flow() const noexcept
Checks whether a gas flowmap is provided.
Definition transitionner.hpp:202
size_t size() const noexcept
Get the number of load flowmap.
Definition transitionner.hpp:197
std::size_t n_per_flowmap
Number of iteration per flowmap.
Definition transitionner.hpp:181
void update_counters()
Update flow and iteration counters.
Definition transitionner.cpp:152
const CmaRead::ReactorState & get_unchecked(size_t index) const noexcept
Direct read state from iterator.
Definition transitionner.hpp:216
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:129
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:96
std::size_t get_n_timestep() const noexcept
Returns the total number of expected simulation timesteps.
Definition transitionner.cpp:166
Proxy class for PreCalculatedHydroState used to fill this struct with data from an external library.
Definition proxy_cache.hpp:20
Namespace to handle algorithms and structures related to reading compartment mesh.
Definition host_specific.hpp:17
FlowmapTransitionMethod
Defines the transition methods used between flowmaps.
Definition transitionner.hpp:20
@ Discontinuous
Represents a sharp, abrupt transition.
@ InterpolationFO
Represents a smooth transition using first-order interpolation.
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:21