ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
erf_sbm::SBMAMRFluxRegister Class Reference

#include <ERF_SBMAMRFluxRegister.H>

Collaboration diagram for erf_sbm::SBMAMRFluxRegister:

Classes

struct  SideState
 

Public Member Functions

 SBMAMRFluxRegister ()=default
 
 SBMAMRFluxRegister (const SBMAMRFluxRegister &)=delete
 
SBMAMRFluxRegister & operator= (const SBMAMRFluxRegister &)=delete
 
void define (const amrex::BoxArray &fine_ba, const amrex::BoxArray &coarse_ba, const amrex::DistributionMapping &fine_dm, const amrex::DistributionMapping &coarse_dm, const amrex::Geometry &fine_geom, const amrex::Geometry &coarse_geom, const amrex::IntVect &ratio, int fine_level, int ncomp)
 
void clear ()
 
bool begin_interval (double coarse_begin, double coarse_end, int expected_fine_steps, std::string &diagnostic)
 
bool begin_level_step (bool coarse_side, double step_begin, double step_end, std::string &diagnostic)
 
bool begin_stage (bool coarse_side, erf_auxiliary::HostIntegrator method, int stage, double step_begin, std::string &diagnostic)
 
bool add_stage_rates (bool coarse_side, const erf_auxiliary::MappedFaceFluxRate &accepted_rate, const std::vector< int > &register_components, double completed_ledger_time, std::string &diagnostic)
 
bool finish_stage (bool coarse_side, std::string &diagnostic)
 
bool accept_level_step (bool coarse_side, double step_begin, double step_end, std::string &diagnostic)
 
bool ready_to_reflux () const noexcept
 
bool has_outstanding_amount () const noexcept
 
double minimum_fine_dt () const noexcept
 
std::uint64_t reflux_call_count () const noexcept
 
std::uint64_t reflux_sync_count () const noexcept
 
const amrex::MultiFab & covered_parent_mask () const noexcept
 
bool reflux (amrex::MultiFab &mapped_candidate, std::string &diagnostic)
 
bool reflux_components (amrex::MultiFab &mapped_correction, const std::vector< int > &global_components, std::string &diagnostic)
 
bool can_accept_reflux (std::string &diagnostic) const
 
bool accept_reflux (std::string &diagnostic)
 
bool discard_interval (std::string &diagnostic)
 

Private Member Functions

int stage_count (erf_auxiliary::HostIntegrator method) const noexcept
 
void reset_side (SideState &side) const
 
bool collective_check (bool local_ok, const std::string &local_diagnostic, const char *remote_diagnostic, std::string &diagnostic) const
 

Private Attributes

std::unique_ptr< amrex::YAFluxRegister > m_register
 
amrex::MultiFab m_covered_parent_mask
 
amrex::BoxArray m_fine_ba
 
amrex::BoxArray m_coarse_ba
 
amrex::DistributionMapping m_fine_dm
 
amrex::DistributionMapping m_coarse_dm
 
amrex::Geometry m_fine_geom
 
amrex::Geometry m_coarse_geom
 
amrex::IntVect m_ratio {1}
 
int m_fine_level {0}
 
int m_ncomp {0}
 
bool m_interval_active {false}
 
bool m_coarse_step_accepted {false}
 
bool m_reflux_applied {false}
 
std::vector< unsigned char > m_reflux_components_seen
 
bool m_consumed {true}
 
double m_interval_begin {0.0}
 
double m_interval_end {0.0}
 
double m_min_fine_dt {0.0}
 
int m_expected_fine_steps {0}
 
int m_accepted_fine_steps {0}
 
std::uint64_t m_reflux_call_count {0}
 
std::uint64_t m_reflux_sync_count {0}
 
SideState m_coarse
 
SideState m_fine
 

Detailed Description

Transactional owner for one SBM coarse/fine interface.

Accepted chunk-local mapped stage rates are added directly to YA using the stage's completed-step time coefficient. The register is only refluxable after the coarse step and every expected fine substep have been accepted. The authoritative spectrum and the mapped candidate remain externally owned.

Constructor & Destructor Documentation

◆ SBMAMRFluxRegister() [1/2]

erf_sbm::SBMAMRFluxRegister::SBMAMRFluxRegister ( )
default

◆ SBMAMRFluxRegister() [2/2]

erf_sbm::SBMAMRFluxRegister::SBMAMRFluxRegister ( const SBMAMRFluxRegister &  )
delete

Member Function Documentation

◆ accept_level_step()

bool erf_sbm::SBMAMRFluxRegister::accept_level_step ( bool  coarse_side,
double  step_begin,
double  step_end,
std::string &  diagnostic 
)
367 {
368  diagnostic.clear();
369  SideState& side = coarse_side ? m_coarse : m_fine;
370  const bool stages_complete = side.next_stage == stage_count(side.method);
371  bool local_ok = side.step_active && !side.stage_active && stages_complete &&
372  semantic_time_matches(step_begin, side.step_begin, m_min_fine_dt) &&
373  semantic_time_matches(step_end, side.step_end, m_min_fine_dt);
374  std::string local_diagnostic = !side.step_active
375  ? "SBM interface level-step acceptance has no active step"
376  : side.stage_active ? "SBM interface level-step acceptance found an open stage"
377  : !stages_complete ? "SBM interface level step omitted one or more host stages"
378  : "SBM interface level-step acceptance changed its semantic times";
379  if (local_ok && coarse_side) {
380  local_ok = semantic_time_matches(step_begin, m_interval_begin,
381  m_min_fine_dt) &&
383  m_min_fine_dt) &&
385  if (!local_ok) {
386  local_diagnostic = "accepted coarse SBM step does not match its interval";
387  }
388  } else if (local_ok) {
389  const double fine_dt = (m_interval_end - m_interval_begin) /
390  static_cast<double>(m_expected_fine_steps);
391  const double expected_begin = m_interval_begin +
392  static_cast<double>(m_accepted_fine_steps) * fine_dt;
393  local_ok = m_coarse_step_accepted &&
394  semantic_time_matches(step_begin, expected_begin, m_min_fine_dt) &&
395  semantic_time_matches(step_end, expected_begin + fine_dt,
396  m_min_fine_dt) &&
398  if (!local_ok) {
399  local_diagnostic = "accepted fine SBM step is missing, duplicated, or out of order";
400  }
401  }
402  if (!collective_check(local_ok, local_diagnostic,
403  "SBM interface level step was rejected on another MPI rank",
404  diagnostic)) {
405  return false;
406  }
407  side.step_active = false;
408  side.step_accepted = true;
409  if (coarse_side) {
410  m_coarse_step_accepted = true;
411  } else {
413  }
414  return true;
415 }
int stage_count(erf_auxiliary::HostIntegrator method) const noexcept
Definition: ERF_SBMAMRFluxRegister.cpp:94
SideState m_fine
Definition: ERF_SBMAMRFluxRegister.H:132
int m_expected_fine_steps
Definition: ERF_SBMAMRFluxRegister.H:127
SideState m_coarse
Definition: ERF_SBMAMRFluxRegister.H:131
int m_accepted_fine_steps
Definition: ERF_SBMAMRFluxRegister.H:128
double m_interval_begin
Definition: ERF_SBMAMRFluxRegister.H:124
bool m_coarse_step_accepted
Definition: ERF_SBMAMRFluxRegister.H:120
double m_interval_end
Definition: ERF_SBMAMRFluxRegister.H:125
bool collective_check(bool local_ok, const std::string &local_diagnostic, const char *remote_diagnostic, std::string &diagnostic) const
Definition: ERF_SBMAMRFluxRegister.cpp:101
double m_min_fine_dt
Definition: ERF_SBMAMRFluxRegister.H:126
bool semantic_time_matches(const double lhs, const double rhs, const double dt_min) noexcept
Definition: ERF_SBMAMRTime.H:14
int next_stage
Definition: ERF_SBMAMRFluxRegister.H:97
Here is the call graph for this function:

◆ accept_reflux()

bool erf_sbm::SBMAMRFluxRegister::accept_reflux ( std::string &  diagnostic)

Consume the pending amount only after the refluxed full candidate admits.

572 {
573  if (!can_accept_reflux(diagnostic)) { return false; }
574  m_register->reset();
575  m_consumed = true;
576  m_interval_active = false;
577  m_reflux_applied = false;
578  m_coarse_step_accepted = false;
579  m_min_fine_dt = 0.0;
582  m_reflux_components_seen.end(), 0);
585  return true;
586 }
bool m_interval_active
Definition: ERF_SBMAMRFluxRegister.H:119
bool can_accept_reflux(std::string &diagnostic) const
Definition: ERF_SBMAMRFluxRegister.cpp:554
bool m_reflux_applied
Definition: ERF_SBMAMRFluxRegister.H:121
std::vector< unsigned char > m_reflux_components_seen
Definition: ERF_SBMAMRFluxRegister.H:122
bool m_consumed
Definition: ERF_SBMAMRFluxRegister.H:123
std::unique_ptr< amrex::YAFluxRegister > m_register
Definition: ERF_SBMAMRFluxRegister.H:107
void reset_side(SideState &side) const
Definition: ERF_SBMAMRFluxRegister.cpp:20
void fill(MultiFab &dst, int temperature_comp, int mixing_ratio_comp, int source_comp, const Sources &sources, Real missing_value)
Definition: ERF_NearSurfaceDiagnostics.cpp:42
Here is the call graph for this function:

◆ add_stage_rates()

bool erf_sbm::SBMAMRFluxRegister::add_stage_rates ( bool  coarse_side,
const erf_auxiliary::MappedFaceFluxRate &  accepted_rate,
const std::vector< int > &  register_components,
double  completed_ledger_time,
std::string &  diagnostic 
)
254 {
255  diagnostic.clear();
256  SideState& side = coarse_side ? m_coarse : m_fine;
257  bool local_ok = m_register != nullptr && side.stage_active &&
258  std::isfinite(completed_ledger_time) && completed_ledger_time >= 0.0 &&
260  accepted_rate, coarse_side ? m_coarse_ba : m_fine_ba,
261  coarse_side ? m_coarse_dm : m_fine_dm);
262  std::string local_diagnostic = m_register == nullptr
263  ? "SBM interface register is undefined"
264  : !side.stage_active ? "accepted SBM face rates arrived outside a stage"
265  : !std::isfinite(completed_ledger_time) || completed_ledger_time < 0.0
266  ? "SBM accepted face rates have an invalid completed-step coefficient"
267  : "accepted SBM face-rate layout does not match the interface grid";
268  if (local_ok && (register_components.empty() || register_components.size() >
269  static_cast<std::size_t>(accepted_rate.nComp()))) {
270  local_ok = false;
271  local_diagnostic = "SBM chunk component map does not match its accepted-rate FAB";
272  }
273  if (local_ok) {
274  std::vector<unsigned char> local_seen(static_cast<std::size_t>(m_ncomp), 0);
275  for (const int component : register_components) {
276  if (component < 0 || component >= m_ncomp ||
277  side.components_seen[static_cast<std::size_t>(component)] != 0 ||
278  local_seen[static_cast<std::size_t>(component)] != 0) {
279  local_ok = false;
280  local_diagnostic = "SBM chunk contains an invalid or duplicate global component";
281  break;
282  }
283  local_seen[static_cast<std::size_t>(component)] = 1;
284  }
285  }
286  if (!collective_check(local_ok, local_diagnostic,
287  "accepted SBM face-rate chunk is invalid on another MPI rank",
288  diagnostic)) {
289  return false;
290  }
291 
292  if (completed_ledger_time != 0.0) {
293  const auto& grids = coarse_side ? m_coarse_ba : m_fine_ba;
294  const auto& mapping = coarse_side ? m_coarse_dm : m_fine_dm;
295  amrex::MultiFab cell_layout(grids, mapping, 1, 0,
296  amrex::MFInfo().SetAlloc(false));
297  const auto dx = (coarse_side ? m_coarse_geom : m_fine_geom).CellSizeArray();
298  const amrex::RunOn run_on = amrex::Gpu::inLaunchRegion()
299  ? amrex::RunOn::Gpu : amrex::RunOn::Host;
300  for (amrex::MFIter mfi(cell_layout, amrex::TilingIfNotGPU());
301  mfi.isValid(); ++mfi) {
302  std::array<amrex::FArrayBox const*, AMREX_SPACEDIM> fluxes{};
303  for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
304  fluxes[static_cast<std::size_t>(dir)] =
305  &accepted_rate.dir(dir)[mfi];
306  }
307  for (std::size_t first = 0; first < register_components.size();) {
308  std::size_t end = first + 1U;
309  while (end < register_components.size() &&
310  register_components[end] ==
311  register_components[end - 1U] + 1) {
312  ++end;
313  }
314  const int local = static_cast<int>(first);
315  const int global_component = register_components[first];
316  const int count = static_cast<int>(end - first);
317  if (coarse_side) {
318  m_register->CrseAdd(mfi, fluxes, dx.data(),
319  static_cast<amrex::Real>(completed_ledger_time),
320  local, global_component, count, run_on);
321  } else {
322  m_register->FineAdd(mfi, fluxes, dx.data(),
323  static_cast<amrex::Real>(completed_ledger_time),
324  local, global_component, count, run_on);
325  }
326  first = end;
327  }
328  }
329  // accepted_rate is reused by the next chunk; finish all YA readers
330  // before that storage can be overwritten on an asynchronous backend.
331  amrex::Gpu::streamSynchronize();
332  }
333  for (const int component : register_components) {
334  side.components_seen[static_cast<std::size_t>(component)] = 1;
335  }
336  return true;
337 }
GpuArray< Real, AMREX_SPACEDIM > dx
Definition: ERF_ActuatorSpreading.cpp:131
int count
Definition: ERF_ActuatorSpreading.cpp:264
int nComp() const noexcept
Definition: ERF_AuxiliaryMappedTransport.H:44
amrex::MultiFab & dir(const int direction)
Definition: ERF_AuxiliaryMappedTransport.H:46
amrex::DistributionMapping m_coarse_dm
Definition: ERF_SBMAMRFluxRegister.H:112
int m_ncomp
Definition: ERF_SBMAMRFluxRegister.H:117
amrex::Geometry m_fine_geom
Definition: ERF_SBMAMRFluxRegister.H:113
amrex::BoxArray m_coarse_ba
Definition: ERF_SBMAMRFluxRegister.H:110
amrex::Geometry m_coarse_geom
Definition: ERF_SBMAMRFluxRegister.H:114
amrex::BoxArray m_fine_ba
Definition: ERF_SBMAMRFluxRegister.H:109
amrex::DistributionMapping m_fine_dm
Definition: ERF_SBMAMRFluxRegister.H:111
bool MappedFaceLayoutMatchesCellLayout(const MappedFaceField< Tag > &faces, const amrex::BoxArray &cell_ba, const amrex::DistributionMapping &dm)
Definition: ERF_AuxiliaryMappedTransport.H:83
Here is the call graph for this function:

◆ begin_interval()

bool erf_sbm::SBMAMRFluxRegister::begin_interval ( double  coarse_begin,
double  coarse_end,
int  expected_fine_steps,
std::string &  diagnostic 
)
120 {
121  diagnostic.clear();
122  const bool local_ok = m_register != nullptr && !m_interval_active &&
123  m_consumed && std::isfinite(coarse_begin) &&
124  std::isfinite(coarse_end) && coarse_end > coarse_begin &&
125  std::isfinite(coarse_end - coarse_begin) && expected_fine_steps > 0 &&
126  std::isfinite((coarse_end - coarse_begin) /
127  static_cast<double>(expected_fine_steps)) &&
128  (coarse_end - coarse_begin) / static_cast<double>(expected_fine_steps) > 0.0;
129  const std::string local_diagnostic = m_register == nullptr
130  ? "SBM interface register is undefined"
132  ? "SBM interface register still owns an unconsumed interval"
133  : "SBM interface interval has invalid times or fine-substep count";
134  if (!collective_check(local_ok, local_diagnostic,
135  "SBM interface interval is invalid on another MPI rank",
136  diagnostic)) {
137  return false;
138  }
139  m_register->reset();
140  m_interval_begin = coarse_begin;
141  m_interval_end = coarse_end;
142  m_expected_fine_steps = expected_fine_steps;
143  m_min_fine_dt = (coarse_end - coarse_begin) /
144  static_cast<double>(expected_fine_steps);
148  m_coarse_step_accepted = false;
149  m_reflux_applied = false;
151  m_reflux_components_seen.end(), 0);
152  m_interval_active = true;
153  m_consumed = false;
156  return true;
157 }
std::uint64_t m_reflux_sync_count
Definition: ERF_SBMAMRFluxRegister.H:130
std::uint64_t m_reflux_call_count
Definition: ERF_SBMAMRFluxRegister.H:129
Here is the call graph for this function:

◆ begin_level_step()

bool erf_sbm::SBMAMRFluxRegister::begin_level_step ( bool  coarse_side,
double  step_begin,
double  step_end,
std::string &  diagnostic 
)
164 {
165  diagnostic.clear();
166  SideState& side = coarse_side ? m_coarse : m_fine;
167  bool local_ok = m_interval_active && !m_consumed && !side.step_active &&
168  std::isfinite(step_begin) && std::isfinite(step_end) &&
169  step_end > step_begin;
170  std::string local_diagnostic = !m_interval_active || m_consumed
171  ? "SBM level step arrived outside an active interface interval"
172  : side.step_active ? "SBM interface level step is already active"
173  : "SBM interface level step has invalid times";
174  if (local_ok && coarse_side) {
175  local_ok = !m_coarse_step_accepted &&
177  m_min_fine_dt) &&
179  m_min_fine_dt);
180  if (!local_ok) {
181  local_diagnostic = "coarse SBM step does not match its interface interval";
182  }
183  } else if (local_ok) {
184  const double fine_dt = (m_interval_end - m_interval_begin) /
185  static_cast<double>(m_expected_fine_steps);
186  const double expected_begin = m_interval_begin +
187  static_cast<double>(m_accepted_fine_steps) * fine_dt;
188  const double expected_end = expected_begin + fine_dt;
189  local_ok = m_coarse_step_accepted &&
191  semantic_time_matches(step_begin, expected_begin, m_min_fine_dt) &&
192  semantic_time_matches(step_end, expected_end, m_min_fine_dt);
193  if (!local_ok) {
194  local_diagnostic = "fine SBM substep is missing, duplicated, or outside the coarse interval";
195  }
196  }
197  if (!collective_check(local_ok, local_diagnostic,
198  "SBM interface level step is invalid on another MPI rank",
199  diagnostic)) {
200  return false;
201  }
202  side.step_active = true;
203  side.stage_active = false;
204  side.step_accepted = false;
205  side.step_begin = step_begin;
206  side.step_end = step_end;
207  side.current_stage_time = step_begin;
208  side.next_stage = 0;
209  side.components_seen.assign(static_cast<std::size_t>(m_ncomp), 0);
210  return true;
211 }
Here is the call graph for this function:

◆ begin_stage()

bool erf_sbm::SBMAMRFluxRegister::begin_stage ( bool  coarse_side,
erf_auxiliary::HostIntegrator  method,
int  stage,
double  step_begin,
std::string &  diagnostic 
)
217 {
218  diagnostic.clear();
219  SideState& side = coarse_side ? m_coarse : m_fine;
220  const int count = stage_count(method);
221  const bool local_ok = m_interval_active && side.step_active &&
222  !side.stage_active && stage == side.next_stage && count > 0 &&
223  stage < count && semantic_time_matches(side.step_begin, step_begin,
224  m_min_fine_dt) &&
225  (stage == 0 || side.method == method);
226  std::string local_diagnostic = !m_interval_active || !side.step_active
227  ? "SBM interface stage arrived without an active physical step"
228  : side.stage_active ? "SBM interface stage is already active"
229  : count == 0 ? "SBM interface does not support this host integrator"
230  : stage != side.next_stage
231  ? "SBM interface stage is duplicate, skipped, or out of order"
232  : !semantic_time_matches(side.step_begin, step_begin,
234  ? "SBM interface stage changed its physical-step start time"
235  : "SBM interface host integrator changed during a step";
236  if (!collective_check(local_ok, local_diagnostic,
237  "SBM interface stage is invalid on another MPI rank",
238  diagnostic)) {
239  return false;
240  }
241  if (stage == 0) { side.method = method; }
242  side.stage_active = true;
243  side.components_seen.assign(static_cast<std::size_t>(m_ncomp), 0);
244  return true;
245 }
Here is the call graph for this function:

◆ can_accept_reflux()

bool erf_sbm::SBMAMRFluxRegister::can_accept_reflux ( std::string &  diagnostic) const
555 {
556  diagnostic.clear();
557  const bool all_components_refluxed = std::all_of(
559  [] (const unsigned char seen) { return seen != 0; });
560  const bool local_ok = ready_to_reflux() && m_reflux_applied &&
561  all_components_refluxed;
562  const std::string local_diagnostic = !ready_to_reflux()
563  ? "SBM YA amount cannot be consumed before all level steps are accepted"
564  : "SBM YA amount cannot be consumed before a reflux candidate was formed";
565  return collective_check(local_ok, local_diagnostic,
566  "SBM YA amount consumption was rejected on another MPI rank",
567  diagnostic);
568 }
bool ready_to_reflux() const noexcept
Definition: ERF_SBMAMRFluxRegister.cpp:418

Referenced by accept_reflux().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clear()

void erf_sbm::SBMAMRFluxRegister::clear ( )
64 {
65  if (m_register) { m_register->clear(); }
66  m_register.reset();
67  m_covered_parent_mask.clear();
68  m_fine_ba.clear();
69  m_coarse_ba.clear();
70  m_fine_dm = amrex::DistributionMapping();
71  m_coarse_dm = amrex::DistributionMapping();
72  m_fine_geom = amrex::Geometry();
73  m_coarse_geom = amrex::Geometry();
74  m_ratio = amrex::IntVect(1);
75  m_fine_level = 0;
76  m_ncomp = 0;
77  m_interval_active = false;
78  m_coarse_step_accepted = false;
79  m_reflux_applied = false;
81  m_consumed = true;
82  m_interval_begin = 0.0;
83  m_interval_end = 0.0;
84  m_min_fine_dt = 0.0;
89  m_coarse = {};
90  m_fine = {};
91 }
amrex::MultiFab m_covered_parent_mask
Definition: ERF_SBMAMRFluxRegister.H:108
amrex::IntVect m_ratio
Definition: ERF_SBMAMRFluxRegister.H:115
int m_fine_level
Definition: ERF_SBMAMRFluxRegister.H:116

Referenced by define().

Here is the caller graph for this function:

◆ collective_check()

bool erf_sbm::SBMAMRFluxRegister::collective_check ( bool  local_ok,
const std::string &  local_diagnostic,
const char *  remote_diagnostic,
std::string &  diagnostic 
) const
private
104 {
105  int vote = local_ok ? 1 : 0;
106  amrex::ParallelDescriptor::ReduceIntMin(vote);
107  if (vote != 0) {
108  diagnostic.clear();
109  return true;
110  }
111  diagnostic = local_ok ? remote_diagnostic : local_diagnostic;
112  return false;
113 }

Referenced by accept_level_step(), add_stage_rates(), begin_interval(), begin_level_step(), begin_stage(), can_accept_reflux(), discard_interval(), finish_stage(), reflux(), and reflux_components().

Here is the caller graph for this function:

◆ covered_parent_mask()

const amrex::MultiFab& erf_sbm::SBMAMRFluxRegister::covered_parent_mask ( ) const
inlinenoexcept

Coarse cells covered by the fine level (1) or not (0), one periodic ghost.

71  { return m_covered_parent_mask; }

◆ define()

void erf_sbm::SBMAMRFluxRegister::define ( const amrex::BoxArray &  fine_ba,
const amrex::BoxArray &  coarse_ba,
const amrex::DistributionMapping &  fine_dm,
const amrex::DistributionMapping &  coarse_dm,
const amrex::Geometry &  fine_geom,
const amrex::Geometry &  coarse_geom,
const amrex::IntVect &  ratio,
int  fine_level,
int  ncomp 
)
36 {
37  clear();
38  AMREX_ALWAYS_ASSERT(fine_level > 0 && ncomp > 0);
39  m_fine_ba = fine_ba;
40  m_coarse_ba = coarse_ba;
41  m_fine_dm = fine_dm;
42  m_coarse_dm = coarse_dm;
43  m_fine_geom = fine_geom;
44  m_coarse_geom = coarse_geom;
45  m_ratio = ratio;
46  m_fine_level = fine_level;
47  m_ncomp = ncomp;
48  m_reflux_components_seen.assign(static_cast<std::size_t>(m_ncomp), 0);
49  m_register = std::make_unique<amrex::YAFluxRegister>(
52  amrex::MultiFab fine_coverage(m_fine_ba, m_fine_dm, 1, 0);
54  fine_coverage.setVal(amrex::Real(1.0));
55  m_covered_parent_mask.setVal(amrex::Real(0.0));
56  amrex::average_down(fine_coverage, m_covered_parent_mask, 0, 1, m_ratio);
57  m_covered_parent_mask.FillBoundary(m_coarse_geom.periodicity());
60 }
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
void clear()
Definition: ERF_SBMAMRFluxRegister.cpp:63
Here is the call graph for this function:

◆ discard_interval()

bool erf_sbm::SBMAMRFluxRegister::discard_interval ( std::string &  diagnostic)

Drop a rejected private candidate and its unpublishable interval.

527 {
528  diagnostic.clear();
529  const bool local_ok = m_register != nullptr && m_interval_active &&
530  !m_consumed;
531  const std::string local_diagnostic = m_register == nullptr
532  ? "SBM interface register is undefined"
533  : "SBM interface interval has no pending amount to discard";
534  if (!collective_check(local_ok, local_diagnostic,
535  "SBM rejected interface interval is invalid on another MPI rank",
536  diagnostic)) {
537  return false;
538  }
539  m_register->reset();
540  m_interval_active = false;
541  m_consumed = true;
542  m_reflux_applied = false;
543  m_coarse_step_accepted = false;
544  m_min_fine_dt = 0.0;
547  m_reflux_components_seen.end(), 0);
550  return true;
551 }
Here is the call graph for this function:

◆ finish_stage()

bool erf_sbm::SBMAMRFluxRegister::finish_stage ( bool  coarse_side,
std::string &  diagnostic 
)
342 {
343  diagnostic.clear();
344  SideState& side = coarse_side ? m_coarse : m_fine;
345  const bool all_components_seen = std::all_of(
346  side.components_seen.begin(), side.components_seen.end(),
347  [](const unsigned char seen) { return seen != 0; });
348  const bool local_ok = side.stage_active && all_components_seen;
349  const std::string local_diagnostic = !side.stage_active
350  ? "SBM interface stage finish requires an open stage"
351  : "SBM interface stage omitted one or more global spectral components";
352  if (!collective_check(local_ok, local_diagnostic,
353  "SBM interface stage is incomplete on another MPI rank",
354  diagnostic)) {
355  return false;
356  }
357  side.stage_active = false;
358  ++side.next_stage;
359  return true;
360 }
Here is the call graph for this function:

◆ has_outstanding_amount()

bool erf_sbm::SBMAMRFluxRegister::has_outstanding_amount ( ) const
noexcept
428 {
429  return m_interval_active && !m_consumed;
430 }

◆ minimum_fine_dt()

double erf_sbm::SBMAMRFluxRegister::minimum_fine_dt ( ) const
inlinenoexcept

Actual smallest physical timestep represented by the active interval.

64  { return m_min_fine_dt; }

◆ operator=()

SBMAMRFluxRegister& erf_sbm::SBMAMRFluxRegister::operator= ( const SBMAMRFluxRegister &  )
delete

◆ ready_to_reflux()

bool erf_sbm::SBMAMRFluxRegister::ready_to_reflux ( ) const
noexcept
419 {
424 }
bool step_active
Definition: ERF_SBMAMRFluxRegister.H:89
bool stage_active
Definition: ERF_SBMAMRFluxRegister.H:90

Referenced by can_accept_reflux(), reflux(), and reflux_components().

Here is the caller graph for this function:

◆ reflux()

bool erf_sbm::SBMAMRFluxRegister::reflux ( amrex::MultiFab &  mapped_candidate,
std::string &  diagnostic 
)
435 {
436  diagnostic.clear();
437  const bool candidate_matches = m_register != nullptr &&
438  mapped_candidate.nComp() == m_ncomp &&
439  mapped_candidate.boxArray() == m_coarse_ba &&
440  mapped_candidate.DistributionMap() == m_coarse_dm;
441  const bool no_component_was_refluxed = std::none_of(
443  [] (const unsigned char seen) { return seen != 0; });
444  const bool local_ok = ready_to_reflux() && !m_reflux_applied &&
445  candidate_matches && no_component_was_refluxed;
446  const std::string local_diagnostic = !ready_to_reflux()
447  ? "SBM YA reflux requires one accepted coarse step and every accepted fine substep"
448  : m_reflux_applied || !no_component_was_refluxed
449  ? "SBM YA reflux candidate was already applied for this pending interval"
450  : "SBM YA reflux candidate does not match the coarse full-component layout";
451  if (!collective_check(local_ok, local_diagnostic,
452  "SBM YA reflux preflight failed on another MPI rank",
453  diagnostic)) {
454  return false;
455  }
456  m_register->Reflux(mapped_candidate, 0, 0, m_ncomp);
457  amrex::Gpu::streamSynchronize();
459  m_reflux_components_seen.end(), 1);
460  m_reflux_applied = true;
461  return true;
462 }
Here is the call graph for this function:

◆ reflux_call_count()

std::uint64_t erf_sbm::SBMAMRFluxRegister::reflux_call_count ( ) const
inlinenoexcept
66  { return m_reflux_call_count; }

◆ reflux_components()

bool erf_sbm::SBMAMRFluxRegister::reflux_components ( amrex::MultiFab &  mapped_correction,
const std::vector< int > &  global_components,
std::string &  diagnostic 
)

Apply selected global components into matching local slots of a bounded correction MultiFab; all components must be covered before the pending amount can be consumed.

468 {
469  diagnostic.clear();
470  bool mapping_ok = m_register != nullptr && !global_components.empty() &&
471  mapped_correction.nComp() >= static_cast<int>(global_components.size()) &&
472  mapped_correction.boxArray() == m_coarse_ba &&
473  mapped_correction.DistributionMap() == m_coarse_dm &&
474  m_reflux_components_seen.size() == static_cast<std::size_t>(m_ncomp);
475  std::vector<int> seen_now(static_cast<std::size_t>(m_ncomp), 0);
476  for (const int component : global_components) {
477  if (component < 0 || component >= m_ncomp ||
478  (component >= 0 && component < m_ncomp &&
479  (m_reflux_components_seen[static_cast<std::size_t>(component)] != 0 ||
480  seen_now[static_cast<std::size_t>(component)] != 0))) {
481  mapping_ok = false;
482  } else {
483  seen_now[static_cast<std::size_t>(component)] = 1;
484  }
485  }
486  const bool local_ok = ready_to_reflux() && !m_reflux_applied && mapping_ok;
487  const std::string local_diagnostic = !ready_to_reflux()
488  ? "SBM YA reflux requires one accepted coarse step and every accepted fine substep"
490  ? "SBM YA reflux candidate was already applied for this pending interval"
491  : "SBM YA correction chunk has an invalid layout or repeated component mapping";
492  if (!collective_check(local_ok, local_diagnostic,
493  "SBM YA reflux preflight failed on another MPI rank",
494  diagnostic)) {
495  return false;
496  }
497 
498  std::size_t first = 0;
499  while (first < global_components.size()) {
500  std::size_t end = first + 1U;
501  while (end < global_components.size() &&
502  global_components[end] == global_components[end - 1U] + 1) {
503  ++end;
504  }
505  const int source_component = global_components[first];
506  const int destination_component = static_cast<int>(first);
507  const int count = static_cast<int>(end - first);
508  m_register->Reflux(mapped_correction, source_component,
509  destination_component, count);
511  amrex::Gpu::streamSynchronize();
513  for (std::size_t index = first; index < end; ++index) {
514  m_reflux_components_seen[static_cast<std::size_t>(
515  global_components[index])] = 1;
516  }
517  first = end;
518  }
519  m_reflux_applied = std::all_of(m_reflux_components_seen.begin(),
521  [] (const unsigned char seen) { return seen != 0; });
522  return true;
523 }
Here is the call graph for this function:

◆ reflux_sync_count()

std::uint64_t erf_sbm::SBMAMRFluxRegister::reflux_sync_count ( ) const
inlinenoexcept
68  { return m_reflux_sync_count; }

◆ reset_side()

void erf_sbm::SBMAMRFluxRegister::reset_side ( SideState &  side) const
private
21 {
22  side = {};
23  side.components_seen.assign(static_cast<std::size_t>(m_ncomp), 0);
24 }

Referenced by accept_reflux(), begin_interval(), define(), and discard_interval().

Here is the caller graph for this function:

◆ stage_count()

int erf_sbm::SBMAMRFluxRegister::stage_count ( erf_auxiliary::HostIntegrator  method) const
privatenoexcept
96 {
98 }
int HostIntegratorStageCount(const HostIntegrator method) noexcept
Definition: ERF_AuxiliaryStage.cpp:47

Referenced by accept_level_step(), and begin_stage().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_accepted_fine_steps

int erf_sbm::SBMAMRFluxRegister::m_accepted_fine_steps {0}
private

◆ m_coarse

◆ m_coarse_ba

amrex::BoxArray erf_sbm::SBMAMRFluxRegister::m_coarse_ba
private

◆ m_coarse_dm

amrex::DistributionMapping erf_sbm::SBMAMRFluxRegister::m_coarse_dm
private

◆ m_coarse_geom

amrex::Geometry erf_sbm::SBMAMRFluxRegister::m_coarse_geom
private

Referenced by add_stage_rates(), clear(), and define().

◆ m_coarse_step_accepted

bool erf_sbm::SBMAMRFluxRegister::m_coarse_step_accepted {false}
private

◆ m_consumed

bool erf_sbm::SBMAMRFluxRegister::m_consumed {true}
private

◆ m_covered_parent_mask

amrex::MultiFab erf_sbm::SBMAMRFluxRegister::m_covered_parent_mask
private

Referenced by clear(), covered_parent_mask(), and define().

◆ m_expected_fine_steps

int erf_sbm::SBMAMRFluxRegister::m_expected_fine_steps {0}
private

◆ m_fine

◆ m_fine_ba

amrex::BoxArray erf_sbm::SBMAMRFluxRegister::m_fine_ba
private

Referenced by add_stage_rates(), clear(), and define().

◆ m_fine_dm

amrex::DistributionMapping erf_sbm::SBMAMRFluxRegister::m_fine_dm
private

Referenced by add_stage_rates(), clear(), and define().

◆ m_fine_geom

amrex::Geometry erf_sbm::SBMAMRFluxRegister::m_fine_geom
private

Referenced by add_stage_rates(), clear(), and define().

◆ m_fine_level

int erf_sbm::SBMAMRFluxRegister::m_fine_level {0}
private

Referenced by clear(), and define().

◆ m_interval_active

bool erf_sbm::SBMAMRFluxRegister::m_interval_active {false}
private

◆ m_interval_begin

double erf_sbm::SBMAMRFluxRegister::m_interval_begin {0.0}
private

◆ m_interval_end

double erf_sbm::SBMAMRFluxRegister::m_interval_end {0.0}
private

◆ m_min_fine_dt

double erf_sbm::SBMAMRFluxRegister::m_min_fine_dt {0.0}
private

◆ m_ncomp

int erf_sbm::SBMAMRFluxRegister::m_ncomp {0}
private

◆ m_ratio

amrex::IntVect erf_sbm::SBMAMRFluxRegister::m_ratio {1}
private

Referenced by clear(), and define().

◆ m_reflux_applied

bool erf_sbm::SBMAMRFluxRegister::m_reflux_applied {false}
private

◆ m_reflux_call_count

std::uint64_t erf_sbm::SBMAMRFluxRegister::m_reflux_call_count {0}
private

◆ m_reflux_components_seen

std::vector<unsigned char> erf_sbm::SBMAMRFluxRegister::m_reflux_components_seen
private

◆ m_reflux_sync_count

std::uint64_t erf_sbm::SBMAMRFluxRegister::m_reflux_sync_count {0}
private

◆ m_register

std::unique_ptr<amrex::YAFluxRegister> erf_sbm::SBMAMRFluxRegister::m_register
private

The documentation for this class was generated from the following files: