ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_SBMStateManager.H
Go to the documentation of this file.
1 #ifndef ERF_SBM_STATE_MANAGER_H_
2 #define ERF_SBM_STATE_MANAGER_H_
3 
5 
6 #include <AMReX_MultiFab.H>
7 
8 #include <memory>
9 #include <stdexcept>
10 #include <string>
11 #include <vector>
12 
13 namespace erf_sbm {
14 
15 /** Owns the authoritative old/new spectral state and its semantic times. */
17 public:
19 
20  [[nodiscard]] const SBMLayout& layout () const noexcept { return m_layout; }
21  [[nodiscard]] int nlevels () const noexcept { return static_cast<int>(m_levels.size()); }
22  [[nodiscard]] bool is_defined (int lev) const;
23 
24  void define (int lev, const amrex::BoxArray& grids,
25  const amrex::DistributionMapping& mapping,
26  double current_time, int ngrow = 0);
27  void destroy (int lev);
28 
29  /** Accepted state at the beginning of an active physical step. */
30  [[nodiscard]] const amrex::MultiFab& old_state (int lev) const;
31  [[nodiscard]] double old_time (int lev) const;
32  [[nodiscard]] bool old_valid (int lev) const;
33 
34  /** Accepted/current state. Throws while the target buffer is invalid. */
35  [[nodiscard]] const amrex::MultiFab& new_state (int lev) const;
36  [[nodiscard]] double new_time (int lev) const;
37  [[nodiscard]] bool new_valid (int lev) const;
38 
39  /** Mutable accepted state for initialization and synchronized restart I/O. */
40  [[nodiscard]] amrex::MultiFab& new_state_for_initialization (int lev);
41 
42  /** Mutable target storage for transport; semantic reads remain invalid until accepted. */
43  [[nodiscard]] amrex::MultiFab& new_target_storage (int lev);
44 
45  /** Rotate accepted new state into old state at the ERF::Advance seam. */
46  bool begin_step (int lev, double step_old_time, std::string& diagnostic);
47 
48  /** Publish a candidate accepted by the host stage sequence. */
49  bool accept_stage_target (int lev, double target_time,
50  bool physical_step_complete,
51  std::string& diagnostic);
52  [[nodiscard]] bool step_active (int lev) const;
53 
54  /** One-way projection from the spectrum into ERF's compact qc and qr lanes. */
55  void project_to_core (int lev, amrex::MultiFab& core,
56  int qc_component, int qr_component) const;
57 
58 private:
59  struct LevelState {
60  std::unique_ptr<amrex::MultiFab> old_state;
61  std::unique_ptr<amrex::MultiFab> new_state;
62  double old_time{0.0};
63  double new_time{0.0};
64  bool old_valid{false};
65  bool new_valid{false};
66  bool step_active{false};
67  };
68 
69  [[nodiscard]] LevelState& level (int lev);
70  [[nodiscard]] const LevelState& level (int lev) const;
71 
74  std::vector<LevelState> m_levels;
75 };
76 
77 } // namespace erf_sbm
78 
79 #endif
Definition: ERF_SBMBulkProjection.H:18
Definition: ERF_SBMLayout.H:94
Definition: ERF_SBMStateManager.H:16
bool old_valid(int lev) const
Definition: ERF_SBMStateManager.cpp:84
bool is_defined(int lev) const
Definition: ERF_SBMStateManager.cpp:30
double new_time(int lev) const
Definition: ERF_SBMStateManager.cpp:98
std::vector< LevelState > m_levels
Definition: ERF_SBMStateManager.H:74
SBMBulkProjection m_projection
Definition: ERF_SBMStateManager.H:73
bool begin_step(int lev, double step_old_time, std::string &diagnostic)
Definition: ERF_SBMStateManager.cpp:128
void project_to_core(int lev, amrex::MultiFab &core, int qc_component, int qr_component) const
Definition: ERF_SBMStateManager.cpp:195
void destroy(int lev)
Definition: ERF_SBMStateManager.cpp:64
SBMStateManager(SBMLayout layout, int nlevels)
Definition: ERF_SBMStateManager.cpp:11
bool new_valid(int lev) const
Definition: ERF_SBMStateManager.cpp:104
SBMLayout m_layout
Definition: ERF_SBMStateManager.H:72
const SBMLayout & layout() const noexcept
Definition: ERF_SBMStateManager.H:20
int nlevels() const noexcept
Definition: ERF_SBMStateManager.H:21
bool step_active(int lev) const
Definition: ERF_SBMStateManager.cpp:190
const amrex::MultiFab & new_state(int lev) const
Definition: ERF_SBMStateManager.cpp:89
amrex::MultiFab & new_target_storage(int lev)
Definition: ERF_SBMStateManager.cpp:119
LevelState & level(int lev)
Definition: ERF_SBMStateManager.cpp:18
bool accept_stage_target(int lev, double target_time, bool physical_step_complete, std::string &diagnostic)
Definition: ERF_SBMStateManager.cpp:170
void define(int lev, const amrex::BoxArray &grids, const amrex::DistributionMapping &mapping, double current_time, int ngrow=0)
Definition: ERF_SBMStateManager.cpp:36
amrex::MultiFab & new_state_for_initialization(int lev)
Definition: ERF_SBMStateManager.cpp:109
const amrex::MultiFab & old_state(int lev) const
Definition: ERF_SBMStateManager.cpp:69
double old_time(int lev) const
Definition: ERF_SBMStateManager.cpp:78
Definition: ERF.H:108
Definition: ERF_SBMStateManager.H:59
std::unique_ptr< amrex::MultiFab > new_state
Definition: ERF_SBMStateManager.H:61
std::unique_ptr< amrex::MultiFab > old_state
Definition: ERF_SBMStateManager.H:60
bool new_valid
Definition: ERF_SBMStateManager.H:65
double new_time
Definition: ERF_SBMStateManager.H:63
bool old_valid
Definition: ERF_SBMStateManager.H:64
bool step_active
Definition: ERF_SBMStateManager.H:66
double old_time
Definition: ERF_SBMStateManager.H:62