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

Namespaces

 erf_detail_SBMAMRTransfer
 
 erf_detail_SBMTransport
 
 qualification
 
 remap_detail
 

Classes

struct  AdvectionFacePolicyInput
 
struct  AdvectionFacePolicy
 
class  SBMAMRFluxRegister
 
struct  SBMTransferAllocationCensus
 
struct  SBMAMRStateView
 
struct  SBMRegridCellCounts
 
struct  BulkProjection
 
class  SBMBulkProjection
 
struct  ConstraintTerm
 
struct  LinearConstraint
 
struct  ConstraintGroup
 
struct  ConstraintDescriptor
 
struct  FlattenedConstraintSet
 
struct  AttachedPropertySupportDescriptor
 
struct  ConstraintClosureChunk
 
struct  FixtureInitialStateCanonicality
 
struct  InventoryRoundoff
 
struct  SpectralPopulationSpec
 
struct  LiquidProjectionSpec
 
struct  AttachedPropertyDescriptor
 
struct  PopulationLayout
 
struct  SBMLayoutSpec
 
struct  LayoutValidation
 
class  SBMLayout
 
struct  ParticleMixingConfig
 
struct  SBMPhysicalBoundaryConfig
 
struct  SBMBoundaryLedger
 
struct  PopulationRemapView
 
struct  RouteDestination
 
struct  PacketRoutingPlan
 
struct  PacketApplicationCoreResult
 
struct  ReconstructionDeltaView
 
struct  IntegratedMomentsCoreResult
 
struct  PacketApplicationResult
 
struct  ReconstructionDelta
 
struct  IntegratedMoments
 
struct  RepresentationIdentity
 
class  SBMStateAdmission
 
class  SBMStateManager
 
struct  SBMAMRStageGhostProbe
 
struct  SBMAMRStageParent
 
struct  SBMStageMixingInputs
 
struct  TerrainMixingQualification
 
class  SBMTransport
 
struct  SpectralGridSpec
 
struct  GridValidation
 
struct  EndpointTransform
 
class  SpectralGrid
 

Enumerations

enum class  AdvectionFaceKind : int { Periodic , ImpermeableWall , AdvectiveOutflow , PrescribedInflow }
 
enum class  AdvectionFaceAction : int {
  PeriodicSharedFace , ZeroNormalFlux , InteriorDonor , ExplicitSpectralInflow ,
  RejectInwardOutflow , RejectMissingInflowState , RejectIncompleteInflowState
}
 
enum class  PropertyKind { ExtensiveMass , NumberCarried , MassBoundedSubset }
 
enum class  PropertyRemapPolicy { CarrierBinConservative , Independent }
 
enum class  SupportRequirement { None , PositiveMass , PositiveNumber }
 
enum class  PopulationPhase { Liquid , Ice , Aerosol , Generic }
 
enum class  HostWritePath {
  Advection , Diffusion , Source , Positivity ,
  Microphysics , Wall , Boundary
}
 
enum class  ParticleMixingPolicy { None , ConstantReference , HostPassiveScalar }
 
enum class  RemapStatus {
  Ok , ZeroWaterResidual , BelowSupportedGrid , Overflow ,
  NumericalUnderflow , Invalid
}
 
enum class  ReconstructionStatus { Populated , Empty , Invalid }
 
enum class  CoordinateKind { Mass , Radius }
 
enum class  MomentMode { OneMoment , TwoMoment }
 

Functions

constexpr AMREX_GPU_HOST_DEVICE AdvectionFacePolicy make_advection_face_policy (const AdvectionFacePolicyInput &input) noexcept
 
bool semantic_time_matches (const double lhs, const double rhs, const double dt_min) noexcept
 
bool semantic_time_matches_exact (const double lhs, const double rhs) noexcept
 
bool level_time_matches (const double state_time, const double level_time, const double level_dt) noexcept
 
bool ApplyMappedRefluxCorrectionChunk (MultiFab &private_candidate, const MultiFab &mapped_correction, const MultiFab &mapped_measure, const MultiFab &covered_parent_mask, const std::vector< int > &global_components, MultiFab &invalid_mask, std::string &diagnostic)
 
bool MappedRefluxCorrectionMaskIsValid (const MultiFab &invalid_mask, std::string &diagnostic)
 
static bool restrict_mapped_spectrum_impl (const SBMLayout &layout, const SBMAMRStateView &fine, const SBMAMRStateView &coarse, const amrex::IntVect &ratio, const int coarse_level, MultiFab &coarse_candidate, const bool candidate_is_private, const int max_groups_per_chunk, const bool reverse_chunk_order, const SBMStateAdmission *admission, SBMTransferAllocationCensus *allocation_census, const std::optional< double > cross_level_dt_min, const MultiFab *covered_parent_mask, std::string &diagnostic)
 
bool RestrictMappedSpectrum (const SBMLayout &layout, const SBMAMRStateView &fine, const SBMAMRStateView &coarse, const amrex::IntVect &ratio, const int coarse_level, MultiFab &coarse_candidate, std::string &diagnostic, const int max_groups_per_chunk, const bool reverse_chunk_order, const SBMStateAdmission *admission, SBMTransferAllocationCensus *allocation_census, const std::optional< double > cross_level_dt_min)
 
bool RestrictMappedSpectrumPrivate (const SBMLayout &layout, const SBMAMRStateView &fine, const SBMAMRStateView &coarse, const amrex::IntVect &ratio, const int coarse_level, MultiFab &private_candidate, std::string &diagnostic, const int max_groups_per_chunk, const bool reverse_chunk_order, const SBMStateAdmission *admission, SBMTransferAllocationCensus *allocation_census, const std::optional< double > cross_level_dt_min, const MultiFab *covered_parent_mask)
 
static bool prolong_carrier_relative_chunks (const SBMLayout &layout, const SBMAMRStateView &coarse, const SBMAMRStateView &fine_target, const amrex::Geometry &coarse_geometry, const amrex::Geometry &fine_geometry, const amrex::IntVect &ratio, MultiFab &work, const int max_groups_per_chunk, const bool reverse_chunk_order, SBMTransferAllocationCensus *allocation_census, std::string &diagnostic, const MultiFab *prolonged_mask=nullptr)
 
static bool prolong_carrier_relative_spectrum_impl (const SBMLayout &layout, const SBMAMRStateView &coarse, const SBMAMRStateView &fine_target, const amrex::Geometry &coarse_geometry, const amrex::Geometry &fine_geometry, const amrex::IntVect &ratio, const int fine_level, MultiFab &fine_candidate, const bool candidate_is_private, const int max_groups_per_chunk, const bool reverse_chunk_order, const SBMStateAdmission *admission, SBMTransferAllocationCensus *allocation_census, std::string &diagnostic)
 
bool ProlongCarrierRelativeSpectrum (const SBMLayout &layout, const SBMAMRStateView &coarse, const SBMAMRStateView &fine_target, const amrex::Geometry &coarse_geometry, const amrex::Geometry &fine_geometry, const amrex::IntVect &ratio, const int fine_level, MultiFab &fine_candidate, std::string &diagnostic, const int max_groups_per_chunk, const bool reverse_chunk_order, const SBMStateAdmission *admission, SBMTransferAllocationCensus *allocation_census)
 
bool ProlongCarrierRelativeSpectrumPrivate (const SBMLayout &layout, const SBMAMRStateView &coarse, const SBMAMRStateView &fine_target, const amrex::Geometry &coarse_geometry, const amrex::Geometry &fine_geometry, const amrex::IntVect &ratio, const int fine_level, MultiFab &private_candidate, std::string &diagnostic, const int max_groups_per_chunk, const bool reverse_chunk_order, const SBMStateAdmission *admission, SBMTransferAllocationCensus *allocation_census)
 
SBMRegridCellCounts CountRegridCells (const amrex::BoxArray &old_grids, const amrex::BoxArray &new_grids)
 
bool RemapRegriddedSpectrumPrivate (const SBMLayout &layout, const SBMAMRStateView &coarse, const MultiFab &retained_spectrum, const MultiFab &fine_density, const int density_component, const MultiFab &fine_measure, const int measure_component, const double semantic_time, const amrex::Geometry &coarse_geometry, const amrex::Geometry &fine_geometry, const amrex::IntVect &ratio, const int fine_level, MultiFab &private_candidate, std::string &diagnostic, const int max_groups_per_chunk, const SBMStateAdmission *coarse_admission, const SBMStateAdmission *fine_admission, SBMTransferAllocationCensus *allocation_census)
 
bool RestrictMappedSpectrum (const SBMLayout &layout, const SBMAMRStateView &fine, const SBMAMRStateView &coarse, const amrex::IntVect &ratio, int coarse_level, amrex::MultiFab &coarse_candidate, std::string &diagnostic, int max_groups_per_chunk=16, bool reverse_chunk_order=false, const SBMStateAdmission *admission=nullptr, SBMTransferAllocationCensus *allocation_census=nullptr, std::optional< double > cross_level_dt_min=std::nullopt)
 
bool RestrictMappedSpectrumPrivate (const SBMLayout &layout, const SBMAMRStateView &fine, const SBMAMRStateView &coarse, const amrex::IntVect &ratio, int coarse_level, amrex::MultiFab &private_candidate, std::string &diagnostic, int max_groups_per_chunk=16, bool reverse_chunk_order=false, const SBMStateAdmission *admission=nullptr, SBMTransferAllocationCensus *allocation_census=nullptr, std::optional< double > cross_level_dt_min=std::nullopt, const amrex::MultiFab *covered_parent_mask=nullptr)
 
bool ProlongCarrierRelativeSpectrum (const SBMLayout &layout, const SBMAMRStateView &coarse, const SBMAMRStateView &fine_target, const amrex::Geometry &coarse_geometry, const amrex::Geometry &fine_geometry, const amrex::IntVect &ratio, int fine_level, amrex::MultiFab &fine_candidate, std::string &diagnostic, int max_groups_per_chunk=16, bool reverse_chunk_order=false, const SBMStateAdmission *admission=nullptr, SBMTransferAllocationCensus *allocation_census=nullptr)
 
bool ProlongCarrierRelativeSpectrumPrivate (const SBMLayout &layout, const SBMAMRStateView &coarse, const SBMAMRStateView &fine_target, const amrex::Geometry &coarse_geometry, const amrex::Geometry &fine_geometry, const amrex::IntVect &ratio, int fine_level, amrex::MultiFab &private_candidate, std::string &diagnostic, int max_groups_per_chunk=16, bool reverse_chunk_order=false, const SBMStateAdmission *admission=nullptr, SBMTransferAllocationCensus *allocation_census=nullptr)
 
bool RemapRegriddedSpectrumPrivate (const SBMLayout &layout, const SBMAMRStateView &coarse, const amrex::MultiFab &retained_spectrum, const amrex::MultiFab &fine_density, int density_component, const amrex::MultiFab &fine_measure, int measure_component, double semantic_time, const amrex::Geometry &coarse_geometry, const amrex::Geometry &fine_geometry, const amrex::IntVect &ratio, int fine_level, amrex::MultiFab &private_candidate, std::string &diagnostic, int max_groups_per_chunk=16, const SBMStateAdmission *coarse_admission=nullptr, const SBMStateAdmission *fine_admission=nullptr, SBMTransferAllocationCensus *allocation_census=nullptr)
 
bool ApplyMappedRefluxCorrectionChunk (amrex::MultiFab &private_candidate, const amrex::MultiFab &mapped_correction, const amrex::MultiFab &mapped_measure, const amrex::MultiFab &covered_parent_mask, const std::vector< int > &global_components, amrex::MultiFab &invalid_mask, std::string &diagnostic)
 
bool MappedRefluxCorrectionMaskIsValid (const amrex::MultiFab &invalid_mask, std::string &diagnostic)
 
template<typename T >
std::string canonical_decimal (const T value)
 
std::string canonical_real (const amrex::Real value, const bool allow_unbounded_nan=false)
 
std::vector< ConstraintGroup > make_constraint_groups (const SBMLayout &layout)
 
FlattenedConstraintSet flatten_constraint_groups (const std::vector< ConstraintGroup > &groups, const int state_components)
 
FlattenedConstraintSet make_constraint_descriptors (const SBMLayout &layout)
 
std::vector< AttachedPropertySupportDescriptor > make_attached_property_support_descriptors (const SBMLayout &layout)
 
std::vector< ConstraintClosureChunk > make_constraint_closure_chunks (const SBMLayout &layout, const int max_groups)
 
EndpointTransform transform_two_moment (const amrex::Real C, const amrex::Real M, const amrex::Real lower, const amrex::Real upper)
 
std::pair< amrex::Real, amrex::Real > inverse_two_moment (const amrex::Real L, const amrex::Real H, const amrex::Real lower, const amrex::Real upper)
 
bool property_support_is_admissible (const amrex::Real property, const amrex::Real carrier_number, const amrex::Real lower, const amrex::Real upper, const amrex::Real tolerance) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real evaluate_constraint_descriptor (const ConstraintDescriptor &constraint, const ConstraintTerm *terms, const amrex::Real *state) noexcept
 
FixtureInitialStateCanonicality validate_fixture_initial_state_canonicality (const SBMLayout &layout, const std::vector< amrex::Real > &state) noexcept
 
InventoryRoundoff composite_inventory_roundoff (const std::uint64_t coarse_cells, const std::uint64_t fine_cells, const amrex::IntVect &ratio, const bool with_prolongation, const std::uint64_t leaf_updates=0, const std::uint64_t boundary_face_terms=0)
 
const char * host_write_path_name (const HostWritePath path) noexcept
 
bool host_write_allowed (const bool sbm_active, const int component) noexcept
 
bool host_write_range_allowed (const bool sbm_active, const int start_component, const int num_components) noexcept
 
void require_host_write_allowed (const bool sbm_active, const int component, const HostWritePath path)
 
void require_host_write_range_allowed (const bool sbm_active, const int start_component, const int num_components, const HostWritePath path)
 
const char * particle_mixing_name (const ParticleMixingPolicy policy) noexcept
 
bool parse_particle_mixing_policy (const std::string &name, ParticleMixingPolicy &policy)
 
bool validate_particle_mixing_config (const ParticleMixingConfig &config, std::string &reason)
 
bool make_particle_mixing_config (const std::string &name, const amrex::Real reference_kh, const amrex::Real reference_kv, ParticleMixingConfig &config, std::string &reason)
 
bool validate_particle_mixing_host (const ParticleMixingConfig &config, const std::vector< TurbChoice > &turbulence, const MolecDiffType molecular, const MeshType mesh, std::string &reason)
 
bool validate_particle_mixing_host (const ParticleMixingConfig &config, const std::vector< TurbChoice > &turbulence, const MolecDiffType molecular, const MeshType mesh, const bool terrain_qualification, std::string &reason)
 
bool validate_particle_mixing_boundaries (const ParticleMixingConfig &config, const SBMPhysicalBoundaryConfig &boundaries, std::string &reason)
 
std::string particle_mixing_schema (const ParticleMixingConfig &config)
 
std::string particle_mixing_schema (const ParticleMixingConfig &config, const SBMPhysicalBoundaryConfig &boundaries)
 
std::string particle_mixing_schema (const ParticleMixingConfig &config, const SBMPhysicalBoundaryConfig &boundaries, const erf_auxiliary::DiffusionMesh mesh)
 
bool particle_mixing_coefficients (const ParticleMixingConfig &config, erf_auxiliary::MappedDiffusionCoefficients &coefficients, std::string &reason)
 
bool particle_mixing_mesh (const MeshType mesh_type, erf_auxiliary::DiffusionMesh &mesh, std::string &reason, const bool terrain_qualification)
 
bool build_particle_mixing_transmissibility (const ParticleMixingConfig &config, const amrex::Geometry &geom, const erf_auxiliary::MappedDiffusionMetrics &metrics, const amrex::MultiFab &density, const int density_component, const amrex::MultiFab *eddy_diffusivity, erf_auxiliary::MappedFaceTransmissibility &transmissibility, std::string &diagnostic)
 
bool build_particle_mixing_transmissibility (const ParticleMixingConfig &config, const amrex::Geometry &geom, const erf_auxiliary::MappedDiffusionMetrics &metrics, const amrex::MultiFab &density, const int density_component, const amrex::MultiFab *eddy_diffusivity, const erf_auxiliary::MappedDiffusionBoundary &boundary, erf_auxiliary::MappedFaceTransmissibility &transmissibility, std::string &diagnostic)
 
bool admit_terrain_mixing_geometry (const amrex::MultiFab &z_nd, const amrex::BoxArray &cells, const amrex::Real max_drop, std::string &reason)
 
erf_auxiliary::MappedDiffusionBoundary particle_mixing_boundary (const SBMPhysicalBoundaryConfig &boundaries, const std::array< const amrex::MultiFab *, AMREX_SPACEDIM > &carrier)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real matched_diffusion_fraction (const amrex::Real high, const amrex::Real low) noexcept
 
const char * face_name (const int face) noexcept
 
const char * face_kind_name (const AdvectionFaceKind kind) noexcept
 
const char * diffusion_face_kind_name (const erf_auxiliary::DiffusionFaceKind kind) noexcept
 
erf_auxiliary::DiffusionFaceKind map_erf_diffusion (const ERF_BC bc) noexcept
 
bool map_erf_boundary (const ERF_BC bc, AdvectionFaceKind &kind, std::string &reason)
 
bool validate_inflow_state (const SBMLayout &layout, const std::vector< amrex::Real > &z, std::string &reason)
 
PopulationRemapView population_remap_view (const SBMLayout &layout, const int population_id) noexcept
 
PacketApplicationResult apply_packet_routing (const SBMLayout &layout, const PacketRoutingPlan &plan, const std::vector< amrex::Real > &property_packet_amounts, std::vector< amrex::Real > &candidate_state)
 
ReconstructionStatus reconstruct_bin (const SBMLayout &layout, const int population_id, const int bin, const std::vector< amrex::Real > &persisted_state, ReconstructionDelta &reconstruction)
 
bool integrate_interval (const ReconstructionDelta &reconstruction, const amrex::Real lower, const amrex::Real upper, const bool include_upper, IntegratedMoments &integral)
 
bool project_reconstruction_bin (const SBMLayout &layout, const ReconstructionDelta &reconstruction, std::vector< amrex::Real > &candidate_state)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool valid_population_remap_context (const PopulationRemapView &population) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool valid_population_remap_view (const PopulationRemapView &population) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool same_population_context (const PopulationRemapView &left, const PopulationRemapView &right) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE PacketRoutingPlan plan_packet_routing (const PopulationRemapView population, const amrex::Real packet_number, const amrex::Real particle_mass) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE PacketApplicationCoreResult apply_packet_routing_core (const PopulationRemapView population, const PacketRoutingPlan plan, const amrex::Real *property_packet_amounts, const int property_count, amrex::Real *residual_properties, const int residual_capacity, amrex::Real *candidate_state, const int state_count) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE ReconstructionStatus reconstruct_bin_core (const PopulationRemapView population, const int bin, const amrex::Real *persisted_state, const int state_count, amrex::Real *property_per_particle, const int property_capacity, ReconstructionDeltaView &reconstruction) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool integrate_interval_core (const ReconstructionDeltaView reconstruction, const amrex::Real lower, const amrex::Real upper, const bool include_upper, amrex::Real *attached_properties, const int property_capacity, IntegratedMomentsCoreResult &integral) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool project_reconstruction_bin_core (const PopulationRemapView population, const ReconstructionDeltaView reconstruction, amrex::Real *candidate_state, const int state_count) noexcept
 
constexpr RepresentationIdentity representation_identity (const MomentMode mode) noexcept
 
std::string restart_schema (const SBMLayout &layout, const std::string &boundary_identity, const std::string &mixing_identity)
 
bool restart_schema_matches (const SBMLayout &layout, const std::string &persisted, const std::string &boundary_identity, const std::string &mixing_identity)
 
bool authoritative_state_admissible (const amrex::MultiFab &spectrum, const SBMLayout &layout, const int level, std::string *diagnostic)
 
bool restart_projection_matches (const amrex::MultiFab &spectrum, const amrex::MultiFab &persisted_core, const SBMBulkProjection &projection, const int qc_component, const int qr_component, const amrex::Real tolerance_scale)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void copy_host_slow_component (const amrex::Array4< amrex::Real > &current, const amrex::Array4< const amrex::Real > &predictor, const int i, const int j, const int k, const int component, const bool sbm_active, const int qc_component, const int qr_component) noexcept
 
SBMStageMixingInputs make_stage_mixing_inputs (const SBMTransport &transport, const MultiFab *eddy_diffusivity, const amrex::Vector< std::unique_ptr< MultiFab >> &mapfac, const MultiFab *ax, const MultiFab *ay, const Real *stretched_dz, const MultiFab *z_nd, const MultiFab *z_cc)
 
SBMStageMixingInputs make_stage_mixing_inputs (const SBMTransport &transport, const amrex::MultiFab *eddy_diffusivity, const amrex::Vector< std::unique_ptr< amrex::MultiFab >> &mapfac, const amrex::MultiFab *ax, const amrex::MultiFab *ay, const amrex::Real *stretched_dz, const amrex::MultiFab *z_nd=nullptr, const amrex::MultiFab *z_cc=nullptr)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool try_two_moment_to_endpoints (const amrex::Real C, const amrex::Real M, const amrex::Real lower, const amrex::Real upper, EndpointTransform &result) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool try_endpoints_to_two_moment (const amrex::Real L, const amrex::Real H, const amrex::Real lower, const amrex::Real upper, amrex::Real &C, amrex::Real &M) noexcept
 

Variables

constexpr int physical_face_count = 2 * AMREX_SPACEDIM
 

Enumeration Type Documentation

◆ AdvectionFaceAction

enum erf_sbm::AdvectionFaceAction : int
strong

Result of applying the M3 spectral state policy at one oriented face.

Enumerator
PeriodicSharedFace 
ZeroNormalFlux 
InteriorDonor 
ExplicitSpectralInflow 
RejectInwardOutflow 
RejectMissingInflowState 
RejectIncompleteInflowState 

◆ AdvectionFaceKind

enum erf_sbm::AdvectionFaceKind : int
strong

Physical face categories understood by the bounded M3 advection contract.

Enumerator
Periodic 
ImpermeableWall 
AdvectiveOutflow 
PrescribedInflow 

◆ CoordinateKind

Enumerator
Mass 
Radius 

◆ HostWritePath

Enumerator
Advection 
Diffusion 
Source 
Positivity 
Microphysics 
Wall 
Boundary 
10  {
11  Advection,
12  Diffusion,
13  Source,
14  Positivity,
16  Wall,
17  Boundary
18 };
Base class for microphysics interface.
Definition: ERF_Microphysics.H:18
amrex::GpuArray< FaceWall, 2 *AMREX_SPACEDIM > Boundary
Definition: ERF_WallThermodynamics.H:133

◆ MomentMode

enum erf_sbm::MomentMode
strong
Enumerator
OneMoment 
TwoMoment 

◆ ParticleMixingPolicy

Turbulent gradient mixing of spectral particles. One coefficient acts on every member of every bin group, and particle molecular (Brownian) diffusion is zero under every policy.

HostPassiveScalar consumes ERF's Scalar_h/Scalar_v eddy channels, which are already density weighted and Schmidt scaled. Under ERF's LES closures they equal the Q channels that diffuse moisture, but the PBL schemes other than SHOC fill Q_v and not Scalar_v, so this policy is for LES closures only and enabling it must reject a PBL scheme. ConstantReference multiplies kinematic reference diffusivities by the face-averaged dry-air density.

Enumerator
None 
ConstantReference 
HostPassiveScalar 

◆ PopulationPhase

◆ PropertyKind

enum erf_sbm::PropertyKind
strong

Semantic class of an attached carrier-bin extensive quantity.

ExtensiveMass is nonnegative additional mass and is not part of the water projection. NumberCarried is a nonnegative count-like quantity. A MassBoundedSubset is nonnegative and may be constrained by its carrier mass when that future physics is implemented.

Enumerator
ExtensiveMass 
NumberCarried 
MassBoundedSubset 

◆ PropertyRemapPolicy

P1/P2 remap contract; independent remapping is reserved for future work.

Enumerator
CarrierBinConservative 
Independent 

◆ ReconstructionStatus

◆ RemapStatus

enum erf_sbm::RemapStatus
strong
Enumerator
Ok 
ZeroWaterResidual 
BelowSupportedGrid 
Overflow 
NumericalUnderflow 
Invalid 

◆ SupportRequirement

Enumerator
None 
PositiveMass 
PositiveNumber 

Function Documentation

◆ admit_terrain_mixing_geometry()

bool erf_sbm::admit_terrain_mixing_geometry ( const amrex::MultiFab &  z_nd,
const amrex::BoxArray &  cells,
amrex::Real  max_drop,
std::string &  reason 
)

The terrain geometry terrain mixing is qualified on: in every valid cell, the drop sqrt(dx_drop^2 + dy_drop^2) of ComputeTerrainCellDrops, unclamped, at most max_drop cell thicknesses, and a finite, positive thickness. Fails with the worst cell and its drop otherwise. An engineering envelope, not a stability bound.

372 {
373  reason.clear();
374  if (z_nd.boxArray() != amrex::convert(cells, amrex::IntVect(1))) {
375  reason = "the terrain admission requires nodal heights on the cell layout";
376  return false;
377  }
378  // The worst drop, with -1 for a nonfinite or nonpositive thickness, then
379  // the first cell (in a fixed linear order) attaining it.
380  const amrex::Box domain = cells.minimalBox();
381  const auto lo = amrex::lbound(domain);
382  const auto len = amrex::length(domain);
383  amrex::ReduceOps<amrex::ReduceOpMax> max_op;
384  amrex::ReduceData<amrex::Real> max_data(max_op);
385  for (amrex::MFIter mfi(z_nd, false); mfi.isValid(); ++mfi) {
386  const auto z = z_nd.const_array(mfi);
387  max_op.eval(amrex::enclosedCells(mfi.validbox()), max_data,
388  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept -> amrex::GpuTuple<amrex::Real> {
389  return {terrain_cell_drop(z, i, j, k)};
390  });
391  }
392  amrex::Real worst = amrex::get<0>(max_data.value(max_op));
393  amrex::ParallelAllReduce::Max(worst, amrex::ParallelContext::CommunicatorSub());
394  if (worst <= max_drop) { return true; }
395 
396  amrex::ReduceOps<amrex::ReduceOpMin> min_op;
397  amrex::ReduceData<amrex::Long> min_data(min_op);
398  for (amrex::MFIter mfi(z_nd, false); mfi.isValid(); ++mfi) {
399  const auto z = z_nd.const_array(mfi);
400  min_op.eval(amrex::enclosedCells(mfi.validbox()), min_data,
401  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept -> amrex::GpuTuple<amrex::Long> {
402  const amrex::Real drop = terrain_cell_drop(z, i, j, k);
403  const amrex::Long index = (i - lo.x) + amrex::Long(len.x) *
404  ((j - lo.y) + amrex::Long(len.y) * (k - lo.z));
405  return {drop >= worst ? index : std::numeric_limits<amrex::Long>::max()};
406  });
407  }
408  amrex::Long first = amrex::get<0>(min_data.value(min_op));
409  amrex::ParallelAllReduce::Min(first, amrex::ParallelContext::CommunicatorSub());
410  const amrex::Long i = first % len.x;
411  const amrex::Long j = (first / len.x) % len.y;
412  const amrex::Long k = first / (amrex::Long(len.x) * len.y);
413  std::ostringstream message;
414  message.precision(6);
415  message << "SBM terrain particle mixing is qualified for terrain dropping at most "
416  << max_drop << " cell thickness across a cell; cell (" << i + lo.x << ","
417  << j + lo.y << "," << k + lo.z << ") drops ";
418  if (std::isfinite(worst)) {
419  message << worst;
420  } else {
421  message << "with a nonfinite or nonpositive thickness";
422  }
423  reason = message.str();
424  return false;
425 }
const Real length
Definition: ERF_InitCustomPert_AnelasticWallDiffusion.H:16
std::string message
Definition: ERF_InputPreflight.cpp:25

Referenced by erf_sbm::SBMTransport::admit_terrain_geometry().

Here is the caller graph for this function:

◆ apply_packet_routing()

PacketApplicationResult erf_sbm::apply_packet_routing ( const SBMLayout &  layout,
const PacketRoutingPlan &  plan,
const std::vector< amrex::Real > &  property_packet_amounts,
std::vector< amrex::Real > &  candidate_state 
)
43 {
44  PacketApplicationResult result;
45  result.status = plan.status;
46  if (plan.status != RemapStatus::Ok && plan.status != RemapStatus::ZeroWaterResidual) {
47  return result;
48  }
49  if (&property_packet_amounts == &candidate_state) {
50  result.status = RemapStatus::Invalid;
51  return result;
52  }
53  const auto population = population_remap_view(layout, plan.population.population_id);
54  if (population.property_count >= 0) {
55  result.residual_properties.resize(static_cast<std::size_t>(population.property_count),
56  amrex::Real(0.0));
57  }
58  const auto core = apply_packet_routing_core(
59  population, plan,
60  property_packet_amounts.data(), static_cast<int>(property_packet_amounts.size()),
61  result.residual_properties.data(), static_cast<int>(result.residual_properties.size()),
62  candidate_state.data(), static_cast<int>(candidate_state.size()));
63  result.status = core.status;
64  result.residual_number = core.residual_number;
65  result.residual_water_mass = core.residual_water_mass;
66  result.roundoff_water_mass_correction = core.roundoff_water_mass_correction;
67  result.normalized_roundoff = core.normalized_roundoff;
68  return result;
69 }
PopulationRemapView population_remap_view(const SBMLayout &layout, const int population_id) noexcept
Definition: ERF_SBMRemapping.cpp:8
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE PacketApplicationCoreResult apply_packet_routing_core(const PopulationRemapView population, const PacketRoutingPlan plan, const amrex::Real *property_packet_amounts, const int property_count, amrex::Real *residual_properties, const int residual_capacity, amrex::Real *candidate_state, const int state_count) noexcept
Definition: ERF_SBMRemapping.H:640
Here is the call graph for this function:

◆ apply_packet_routing_core()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE PacketApplicationCoreResult erf_sbm::apply_packet_routing_core ( const PopulationRemapView  population,
const PacketRoutingPlan  plan,
const amrex::Real *  property_packet_amounts,
const int  property_count,
amrex::Real *  residual_properties,
const int  residual_capacity,
amrex::Real *  candidate_state,
const int  state_count 
)
noexcept

Allocation-free packet application. The first pass validates the complete plan, residual outputs, and every candidate increment. The second pass commits only after all failure paths have been ruled out. Input/output and property/state storage supplied by the caller must not overlap.

645 {
646  PacketApplicationCoreResult result;
647  result.status = plan.status;
648  if (plan.status != RemapStatus::Ok && plan.status != RemapStatus::ZeroWaterResidual) {
649  return result;
650  }
651  if (!valid_population_remap_context(population) ||
652  !same_population_context(population, plan.population) ||
653  !amrex::Math::isfinite(plan.packet_number) ||
654  !amrex::Math::isfinite(plan.packet_particle_mass) ||
655  plan.packet_number < amrex::Real(0.0) || plan.packet_particle_mass < amrex::Real(0.0) ||
656  property_count != population.property_count ||
657  (property_count > 0 && (property_packet_amounts == nullptr || residual_properties == nullptr)) ||
658  residual_capacity < property_count || candidate_state == nullptr ||
659  state_count != population.state_components || plan.destination_count < 0 ||
660  plan.destination_count > 2 || !amrex::Math::isfinite(plan.residual_number_weight) ||
661  plan.residual_number_weight < amrex::Real(0.0) ||
662  plan.residual_number_weight > amrex::Real(1.0)) {
663  result.status = RemapStatus::Invalid;
664  return result;
665  }
666  if (!remap_detail::route_plan_is_consistent(population, plan)) {
667  result.status = RemapStatus::Invalid;
668  return result;
669  }
670  for (int property = 0; property < property_count; ++property) {
671  if (!remap_detail::finite_nonnegative(property_packet_amounts[property])) {
672  result.status = RemapStatus::Invalid;
673  return result;
674  }
675  }
676  if (plan.packet_number == amrex::Real(0.0)) {
677  for (int property = 0; property < property_count; ++property) {
678  if (property_packet_amounts[property] != amrex::Real(0.0)) {
679  result.status = RemapStatus::Invalid;
680  return result;
681  }
682  }
683  }
684  amrex::Real weight_sum = plan.residual_number_weight;
685  for (int destination = 0; destination < plan.destination_count; ++destination) {
686  const auto& route = plan.destinations[destination];
687  if (route.bin < 0 || route.bin >= population.nbins ||
688  !amrex::Math::isfinite(route.number_weight) || route.number_weight < amrex::Real(0.0) ||
689  route.number_weight > amrex::Real(1.0) ||
690  !remap_detail::finite_nonnegative(route.particle_mass)) {
691  result.status = RemapStatus::Invalid;
692  return result;
693  }
694  for (int previous = 0; previous < destination; ++previous) {
695  if (plan.destinations[previous].bin == route.bin) {
696  result.status = RemapStatus::Invalid;
697  return result;
698  }
699  }
700  weight_sum += route.number_weight;
701  }
702  if (plan.packet_number > amrex::Real(0.0)) {
703  const amrex::Real weight_tolerance = amrex::Real(16.0) *
705  if (!amrex::Math::isfinite(weight_sum) ||
706  std::abs(weight_sum - amrex::Real(1.0)) > weight_tolerance ||
707  ((plan.status == RemapStatus::ZeroWaterResidual) !=
708  (plan.residual_number_weight > amrex::Real(0.0)))) {
709  result.status = RemapStatus::Invalid;
710  return result;
711  }
712  } else if (plan.destination_count != 0 ||
713  plan.residual_number_weight != amrex::Real(0.0)) {
714  result.status = RemapStatus::Invalid;
715  return result;
716  }
717 
718  amrex::Real residual_number = amrex::Real(0.0);
719  auto product_status = remap_detail::checked_product(
720  plan.packet_number, plan.residual_number_weight, residual_number);
721  if (product_status != remap_detail::ProductStatus::Ok) {
722  result.status = remap_detail::remap_product_status(product_status);
723  return result;
724  }
725  amrex::Real roundoff_water_mass_correction = amrex::Real(0.0);
726  // Validate all outputs and candidate increments before changing either.
727  for (int property = 0; property < property_count; ++property) {
728  amrex::Real residual = amrex::Real(0.0);
729  product_status = remap_detail::checked_product(
730  property_packet_amounts[property], plan.residual_number_weight, residual);
731  if (product_status != remap_detail::ProductStatus::Ok) {
732  result.status = remap_detail::remap_product_status(product_status);
733  return result;
734  }
735  }
736  for (int destination = 0; destination < plan.destination_count; ++destination) {
737  const auto& route = plan.destinations[destination];
738  amrex::Real number_increment = amrex::Real(0.0);
739  amrex::Real mass_increment = amrex::Real(0.0);
740  const amrex::Real deposited_mass = route.particle_mass;
741  product_status = remap_detail::checked_product(
742  plan.packet_number, route.number_weight, number_increment);
743  if (product_status == remap_detail::ProductStatus::Ok) {
744  product_status = remap_detail::checked_product(
745  number_increment, deposited_mass, mass_increment);
746  }
747  if (product_status != remap_detail::ProductStatus::Ok) {
748  result.status = remap_detail::remap_product_status(product_status);
749  return result;
750  }
751  if (population.moment_mode == MomentMode::TwoMoment && plan.normalized_roundoff) {
752  const amrex::Real mass_delta =
753  route.particle_mass - plan.packet_particle_mass;
754  if (!amrex::Math::isfinite(mass_delta) ||
755  mass_delta == amrex::Real(0.0)) {
756  result.status = RemapStatus::Invalid;
757  return result;
758  }
759  const amrex::Real mass_delta_magnitude = mass_delta < amrex::Real(0.0) ?
760  -mass_delta : mass_delta;
761  amrex::Real correction_magnitude = amrex::Real(0.0);
762  product_status = remap_detail::checked_product(
763  plan.packet_number, mass_delta_magnitude, correction_magnitude);
764  if (product_status != remap_detail::ProductStatus::Ok) {
765  result.status = remap_detail::remap_product_status(product_status);
766  return result;
767  }
768  const amrex::Real correction = mass_delta < amrex::Real(0.0) ?
769  -correction_magnitude : correction_magnitude;
770  if (!amrex::Math::isfinite(correction) ||
771  !amrex::Math::isfinite(roundoff_water_mass_correction + correction)) {
772  result.status = RemapStatus::Invalid;
773  return result;
774  }
775  roundoff_water_mass_correction += correction;
776  }
777  const int mass_component = population.mass_offset + route.bin;
778  const amrex::Real old_mass = candidate_state[mass_component];
779  if (!remap_detail::finite_nonnegative(old_mass) ||
780  !remap_detail::finite_nonnegative(old_mass + mass_increment)) {
781  result.status = RemapStatus::Invalid;
782  return result;
783  }
784  const amrex::Real next_mass = old_mass + mass_increment;
785  amrex::Real next_number = amrex::Real(0.0);
786  if (population.number_offset >= 0) {
787  const int number_component = population.number_offset + route.bin;
788  const amrex::Real old_number = candidate_state[number_component];
789  if (!remap_detail::finite_nonnegative(old_number)) {
790  result.status = RemapStatus::Invalid;
791  return result;
792  }
793  next_number = old_number + number_increment;
794  if (!remap_detail::finite_nonnegative(next_number)) {
795  result.status = RemapStatus::Invalid;
796  return result;
797  }
798  if (next_number == amrex::Real(0.0)) {
799  if (next_mass != amrex::Real(0.0)) {
800  result.status = RemapStatus::Invalid;
801  return result;
802  }
803  } else {
804  amrex::Real mean = amrex::Real(0.0);
805  const auto quotient_status = remap_detail::checked_quotient(
806  next_mass, next_number, mean);
807  if (quotient_status != remap_detail::QuotientStatus::Ok) {
808  result.status = remap_detail::remap_quotient_status(quotient_status);
809  return result;
810  }
812  population, route.bin, next_number, next_mass)) {
813  result.status = RemapStatus::Invalid;
814  return result;
815  }
816  }
817  } else {
818  const auto quotient_status = remap_detail::checked_quotient(
819  next_mass, population.pivots[route.bin], next_number);
820  if (quotient_status != remap_detail::QuotientStatus::Ok) {
821  result.status = remap_detail::remap_quotient_status(quotient_status);
822  return result;
823  }
824  }
825  for (int property = 0; property < property_count; ++property) {
826  amrex::Real increment = amrex::Real(0.0);
827  const int component = population.property_component_offsets[property] + route.bin;
828  const amrex::Real old_value = candidate_state[component];
829  product_status = remap_detail::checked_product(
830  property_packet_amounts[property], route.number_weight, increment);
831  if (product_status != remap_detail::ProductStatus::Ok) {
832  result.status = remap_detail::remap_product_status(product_status);
833  return result;
834  }
835  if (!remap_detail::finite_nonnegative(old_value)) {
836  result.status = RemapStatus::Invalid;
837  return result;
838  }
839  const amrex::Real next_value = old_value + increment;
840  if (!remap_detail::finite_nonnegative(next_value)) {
841  result.status = RemapStatus::Invalid;
842  return result;
843  }
844  if (next_number == amrex::Real(0.0)) {
845  if (next_value != amrex::Real(0.0)) {
846  result.status = RemapStatus::Invalid;
847  return result;
848  }
849  } else {
850  amrex::Real per_particle = amrex::Real(0.0);
851  const auto quotient_status = remap_detail::checked_quotient(
852  next_value, next_number, per_particle);
853  if (quotient_status != remap_detail::QuotientStatus::Ok) {
854  result.status = remap_detail::remap_quotient_status(quotient_status);
855  return result;
856  }
857  }
858  }
859  }
860 
861  for (int destination = 0; destination < plan.destination_count; ++destination) {
862  const auto& route = plan.destinations[destination];
863  const amrex::Real number_increment = plan.packet_number * route.number_weight;
864  const amrex::Real deposited_mass = route.particle_mass;
865  candidate_state[population.mass_offset + route.bin] += number_increment * deposited_mass;
866  if (population.number_offset >= 0) {
867  candidate_state[population.number_offset + route.bin] += number_increment;
868  }
869  for (int property = 0; property < property_count; ++property) {
870  candidate_state[population.property_component_offsets[property] + route.bin] +=
871  property_packet_amounts[property] * route.number_weight;
872  }
873  }
874  for (int property = 0; property < property_count; ++property) {
875  residual_properties[property] =
876  property_packet_amounts[property] * plan.residual_number_weight;
877  }
878  result.residual_number = residual_number;
879  result.residual_water_mass = amrex::Real(0.0);
880  result.roundoff_water_mass_correction = roundoff_water_mass_correction;
881  result.normalized_roundoff = plan.normalized_roundoff;
882  return result;
883 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool canonical_two_moment_moments(const PopulationRemapView &population, const int bin, const amrex::Real number, const amrex::Real mass) noexcept
Definition: ERF_SBMRemapping.H:345
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE ProductStatus checked_product(const amrex::Real left, const amrex::Real right, amrex::Real &result) noexcept
Definition: ERF_SBMRemapping.H:171
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool finite_nonnegative(const amrex::Real value) noexcept
Definition: ERF_SBMRemapping.H:165
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RemapStatus remap_product_status(const ProductStatus status) noexcept
Definition: ERF_SBMRemapping.H:205
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool route_plan_is_consistent(const PopulationRemapView &population, const PacketRoutingPlan &plan) noexcept
Definition: ERF_SBMRemapping.H:235
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE QuotientStatus checked_quotient(const amrex::Real numerator, const amrex::Real denominator, amrex::Real &result) noexcept
Definition: ERF_SBMRemapping.H:183
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RemapStatus remap_quotient_status(const QuotientStatus status) noexcept
Definition: ERF_SBMRemapping.H:212
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool same_population_context(const PopulationRemapView &left, const PopulationRemapView &right) noexcept
Definition: ERF_SBMRemapping.H:127
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool valid_population_remap_context(const PopulationRemapView &population) noexcept
Definition: ERF_SBMRemapping.H:53
real(c_double), parameter epsilon
Definition: ERF_module_model_constants.F90:12

Referenced by apply_packet_routing().

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

◆ ApplyMappedRefluxCorrectionChunk() [1/2]

bool erf_sbm::ApplyMappedRefluxCorrectionChunk ( amrex::MultiFab &  private_candidate,
const amrex::MultiFab &  mapped_correction,
const amrex::MultiFab &  mapped_measure,
const amrex::MultiFab &  covered_parent_mask,
const std::vector< int > &  global_components,
amrex::MultiFab &  invalid_mask,
std::string &  diagnostic 
)

Add one bounded YA correction chunk in mapped H coordinates only where the scalar covered-parent mask proves a coarse/fine face interface. The candidate and invalid mask are private scratch; invalid is accumulated across chunks and checked collectively after the final chunk.

◆ ApplyMappedRefluxCorrectionChunk() [2/2]

bool erf_sbm::ApplyMappedRefluxCorrectionChunk ( MultiFab &  private_candidate,
const MultiFab &  mapped_correction,
const MultiFab &  mapped_measure,
const MultiFab &  covered_parent_mask,
const std::vector< int > &  global_components,
MultiFab &  invalid_mask,
std::string &  diagnostic 
)
500 {
501  diagnostic.clear();
502  bool local_layout_ok = !global_components.empty() &&
503  mapped_correction.nComp() >= static_cast<int>(global_components.size()) &&
504  invalid_mask.nComp() == 1 && mapped_measure.nComp() > 0 &&
505  covered_parent_mask.nComp() == 1 &&
506  private_candidate.boxArray() == mapped_correction.boxArray() &&
507  private_candidate.boxArray() == mapped_measure.boxArray() &&
508  private_candidate.boxArray() == covered_parent_mask.boxArray() &&
509  private_candidate.boxArray() == invalid_mask.boxArray() &&
510  private_candidate.DistributionMap() == mapped_correction.DistributionMap() &&
511  private_candidate.DistributionMap() == mapped_measure.DistributionMap() &&
512  private_candidate.DistributionMap() == covered_parent_mask.DistributionMap() &&
513  private_candidate.DistributionMap() == invalid_mask.DistributionMap();
514  for (int direction = 0; direction < AMREX_SPACEDIM; ++direction) {
515  local_layout_ok = local_layout_ok &&
516  covered_parent_mask.nGrowVect()[direction] >= 1;
517  }
518  for (const int component : global_components) {
519  local_layout_ok = local_layout_ok && component >= 0 &&
520  component < private_candidate.nComp();
521  }
522  if (!collective_all_true(
523  local_layout_ok,
524  "localized SBM YA correction fields or component map are incompatible",
525  "localized SBM YA correction fields are incompatible on another MPI rank",
526  diagnostic)) {
527  return false;
528  }
529 
530  amrex::Gpu::DeviceVector<int> device_components(global_components.size());
531  amrex::Gpu::copy(amrex::Gpu::hostToDevice, global_components.begin(),
532  global_components.end(), device_components.begin());
533  const int* components = device_components.data();
534  const int ncomponents = static_cast<int>(global_components.size());
535  for (amrex::MFIter mfi(private_candidate, amrex::TilingIfNotGPU());
536  mfi.isValid(); ++mfi) {
537  const amrex::Box box = mfi.tilebox();
538  const auto values = private_candidate.array(mfi);
539  const auto delta = mapped_correction.const_array(mfi);
540  const auto omega = mapped_measure.const_array(mfi);
541  const auto is_covered = covered_parent_mask.const_array(mfi);
542  const auto bad = invalid_mask.array(mfi);
543  amrex::ParallelFor(box, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
544  int cell_bad = bad(i, j, k, 0) > Real(0.0) ? 1 : 0;
545  bool has_covered_face_neighbor = false;
546  for (int direction = 0; direction < AMREX_SPACEDIM; ++direction) {
547  int lo_i = i, lo_j = j, lo_k = k;
548  int hi_i = i, hi_j = j, hi_k = k;
549  if (direction == 0) { --lo_i; ++hi_i; }
550  if (direction == 1) { --lo_j; ++hi_j; }
551  if (direction == 2) { --lo_k; ++hi_k; }
552  has_covered_face_neighbor = has_covered_face_neighbor ||
553  is_covered(lo_i, lo_j, lo_k, 0) > Real(0.5) ||
554  is_covered(hi_i, hi_j, hi_k, 0) > Real(0.5);
555  }
556  const Real scale = omega(i, j, k, 0);
557  for (int local = 0; local < ncomponents; ++local) {
558  const Real h_correction = delta(i, j, k, local);
559  if (h_correction == Real(0.0)) continue;
560  if (is_covered(i, j, k, 0) > Real(0.5) ||
561  !has_covered_face_neighbor) {
562  cell_bad = 1;
563  continue;
564  }
565  Real mapped_old = Real(0.0);
566  const auto map_status = remap_detail::checked_product(
567  scale, values(i, j, k, components[local]), mapped_old);
568  const Real mapped_new = mapped_old + h_correction;
569  Real physical_new = Real(0.0);
570  const auto quotient_status = remap_detail::checked_quotient(
571  mapped_new, scale, physical_new);
572  if (map_status != remap_detail::ProductStatus::Ok ||
573  quotient_status != remap_detail::QuotientStatus::Ok ||
574  !amrex::Math::isfinite(h_correction) ||
575  !amrex::Math::isfinite(mapped_new)) {
576  cell_bad = 1;
577  continue;
578  }
579  values(i, j, k, components[local]) = physical_new;
580  }
581  bad(i, j, k, 0) = static_cast<Real>(cell_bad);
582  });
583  }
584  return true;
585 }
ParallelFor(fab_box, [=] AMREX_GPU_DEVICE(int i, int j, int k) { qrcuten_arr(i, j, k)=Real(0);qscuten_arr(i, j, k)=Real(0);qicuten_arr(i, j, k)=Real(0);})
@ omega
Definition: ERF_Morrison.H:57
bool collective_all_true(const bool local_ok, const std::string &local_diagnostic, const char *remote_failure_message, std::string &diagnostic)
Definition: ERF_SBMAMRTransfer.cpp:46

Referenced by ERF::sbm_synchronize_levels().

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

◆ authoritative_state_admissible()

bool erf_sbm::authoritative_state_admissible ( const amrex::MultiFab &  spectrum,
const SBMLayout &  layout,
int  level,
std::string *  diagnostic = nullptr 
)

Validate every valid-cell value against the layout's runtime constraints.

281 {
282  auto reject = [diagnostic](std::string message) {
283  if (diagnostic) *diagnostic = std::move(message);
284  return false;
285  };
286  if (diagnostic) diagnostic->clear();
287  if (level < 0) return reject("SBM authoritative restart state has an invalid level");
288  if (spectrum.nComp() != layout.ncomp()) {
289  return reject("SBM authoritative restart state component count does not match its layout");
290  }
291 
292  const auto groups = make_constraint_groups(layout);
293  std::vector<PopulationRemapView> remap_views;
294  remap_views.reserve(layout.populations().size());
295  for (const auto& population : layout.populations()) {
296  remap_views.push_back(population_remap_view(layout, population.population_id));
297  }
298  std::vector<amrex::Real> state(static_cast<std::size_t>(layout.ncomp()));
299  const int precision = std::numeric_limits<amrex::Real>::max_digits10;
300 
301  for (amrex::MFIter mfi(spectrum); mfi.isValid(); ++mfi) {
302  const amrex::FArrayBox& source_fab = spectrum[mfi];
303  const amrex::FArrayBox* host_source = &source_fab;
304  std::unique_ptr<amrex::FArrayBox> host_fab;
305 #ifdef AMREX_USE_GPU
306  if (source_fab.arena()->isManaged() || source_fab.arena()->isDevice()) {
307  host_fab = std::make_unique<amrex::FArrayBox>(
308  source_fab.box(), source_fab.nComp(), amrex::The_Pinned_Arena());
309  amrex::Gpu::dtoh_memcpy_async(
310  host_fab->dataPtr(), source_fab.dataPtr(),
311  static_cast<std::size_t>(source_fab.size()) * sizeof(amrex::Real));
312  amrex::Gpu::streamSynchronize();
313  host_source = host_fab.get();
314  }
315 #endif
316  const auto values = host_source->const_array();
317  for (amrex::BoxIterator iterator(mfi.validbox()); iterator.ok(); ++iterator) {
318  const amrex::IntVect cell = iterator();
319  for (int component = 0; component < layout.ncomp(); ++component) {
320  const amrex::Real value = values(cell, component);
321  if (!std::isfinite(value)) {
322  std::ostringstream message;
323  message << "SBM authoritative restart state is inadmissible"
324  << ": level=" << level << ", cell=(";
325  for (int direction = 0; direction < AMREX_SPACEDIM; ++direction) {
326  if (direction != 0) message << ',';
327  message << cell[direction];
328  }
329  message << "), component=" << component
330  << ", constraint=finite, value="
331  << std::setprecision(precision) << value;
332  const auto group = std::find_if(groups.begin(), groups.end(),
333  [component](const ConstraintGroup& candidate) {
334  return candidate.contains(component);
335  });
336  if (group != groups.end()) {
337  message << ", population=" << group->population_id
338  << " (" << group->semantic_id << ")"
339  << ", bin=" << group->bin;
340  }
341  return reject(message.str());
342  }
343  state[static_cast<std::size_t>(component)] = value;
344  }
345 
346  for (std::size_t population_index = 0;
347  population_index < remap_views.size(); ++population_index) {
348  const auto& view = remap_views[population_index];
349  if (view.moment_mode != MomentMode::TwoMoment) continue;
350  for (int bin = 0; bin < view.nbins; ++bin) {
352  view, bin, state.data(), static_cast<int>(state.size()))) continue;
353  std::ostringstream message;
354  message << "SBM authoritative restart state is inadmissible"
355  << ": level=" << level << ", cell=(";
356  for (int direction = 0; direction < AMREX_SPACEDIM; ++direction) {
357  if (direction != 0) message << ',';
358  message << cell[direction];
359  }
360  message << "), population=" << view.population_id
361  << ", bin=" << bin
362  << ", constraint=canonical-two-moment-bin-state";
363  return reject(message.str());
364  }
365  }
366 
367  for (const auto& group : groups) {
368  amrex::Real margin = amrex::Real(0.0);
369  std::string failed_constraint;
370  if (group.admissible(state, &margin, &failed_constraint)) continue;
371 
372  std::ostringstream message;
373  message << "SBM authoritative restart state is inadmissible"
374  << ": level=" << level << ", cell=(";
375  for (int direction = 0; direction < AMREX_SPACEDIM; ++direction) {
376  if (direction != 0) message << ',';
377  message << cell[direction];
378  }
379  message << "), population=" << group.population_id
380  << " (" << group.semantic_id << ")"
381  << ", bin=" << group.bin
382  << ", constraint=" << failed_constraint
383  << ", margin=" << std::setprecision(precision) << margin
384  << ", components={";
385  for (std::size_t member = 0; member < group.members.size(); ++member) {
386  if (member != 0) message << ',';
387  const int component = group.members[member];
388  message << component << ':'
389  << std::setprecision(precision)
390  << state[static_cast<std::size_t>(component)];
391  }
392  message << '}';
393  return reject(message.str());
394  }
395 
396  for (std::size_t population_index = 0;
397  population_index < remap_views.size(); ++population_index) {
398  const auto& view = remap_views[population_index];
399  if (view.moment_mode != MomentMode::OneMoment) continue;
400  for (int bin = 0; bin < view.nbins; ++bin) {
402  view, bin, state.data(), static_cast<int>(state.size()))) continue;
403  std::ostringstream message;
404  message << "SBM authoritative restart state is inadmissible"
405  << ": level=" << level << ", cell=(";
406  for (int direction = 0; direction < AMREX_SPACEDIM; ++direction) {
407  if (direction != 0) message << ',';
408  message << cell[direction];
409  }
410  message << "), population=" << view.population_id
411  << ", bin=" << bin
412  << ", constraint=canonical-one-moment-bin-state";
413  return reject(message.str());
414  }
415  }
416  }
417  }
418  return true;
419 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool canonical_two_moment_bin_state(const PopulationRemapView &population, const int bin, const amrex::Real *state, const int state_count) noexcept
Definition: ERF_SBMRemapping.H:407
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool canonical_persisted_bin_state(const PopulationRemapView &population, const int bin, const amrex::Real *state, const int state_count) noexcept
Definition: ERF_SBMRemapping.H:475
std::vector< ConstraintGroup > make_constraint_groups(const SBMLayout &layout)
Definition: ERF_SBMConstraintGroups.cpp:77

Referenced by erf_sbm::SBMStateAdmission::admissible(), prolong_carrier_relative_spectrum_impl(), ERF::ReadCheckpointFile(), RemapRegriddedSpectrumPrivate(), restrict_mapped_spectrum_impl(), and erf_sbm::erf_detail_SBMAMRTransfer::validate_view_spectrum().

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

◆ build_particle_mixing_transmissibility() [1/2]

bool erf_sbm::build_particle_mixing_transmissibility ( const ParticleMixingConfig &  config,
const amrex::Geometry &  geom,
const erf_auxiliary::MappedDiffusionMetrics &  metrics,
const amrex::MultiFab &  density,
int  density_component,
const amrex::MultiFab *  eddy_diffusivity,
const erf_auxiliary::MappedDiffusionBoundary &  boundary,
erf_auxiliary::MappedFaceTransmissibility &  transmissibility,
std::string &  diagnostic 
)

As above, with the diffusive faces of boundary open.

329 {
330  if (!validate_particle_mixing_config(config, diagnostic)) { return false; }
331  if (config.policy == ParticleMixingPolicy::None) {
332  if (!transmissibility.is_defined() || transmissibility.nComp() != 1) {
333  diagnostic = "particle mixing transmissibility requires one face component";
334  return false;
335  }
336  transmissibility.setVal(amrex::Real(0.0));
337  return true;
338  }
340  if (!particle_mixing_coefficients(config, coefficients, diagnostic)) { return false; }
342  transmissibility, geom, metrics, coefficients, density, density_component,
343  eddy_diffusivity, boundary, diagnostic)) {
344  diagnostic = std::string("SBM particle mixing ") +
345  particle_mixing_name(config.policy) + ": " + diagnostic;
346  return false;
347  }
348  return true;
349 }
const auto config
Definition: ERF_InitCustomPert_CloudChamber.H:38
bool BuildMappedDiffusionTransmissibility(MappedFaceTransmissibility &transmissibility, const amrex::Geometry &geom, const MappedDiffusionMetrics &metrics, const MappedDiffusionCoefficients &coefficients, const MultiFab &density, const int density_component, const MultiFab *eddy_diffusivity, std::string &diagnostic)
Definition: ERF_AuxiliaryDiffusion.cpp:292
const char * particle_mixing_name(const ParticleMixingPolicy policy) noexcept
Definition: ERF_SBMParticleMixing.cpp:17
bool validate_particle_mixing_config(const ParticleMixingConfig &config, std::string &reason)
Definition: ERF_SBMParticleMixing.cpp:57
bool particle_mixing_coefficients(const ParticleMixingConfig &config, erf_auxiliary::MappedDiffusionCoefficients &coefficients, std::string &reason)
Definition: ERF_SBMParticleMixing.cpp:247
Definition: ERF_AuxiliaryDiffusion.H:63
Here is the call graph for this function:

◆ build_particle_mixing_transmissibility() [2/2]

bool erf_sbm::build_particle_mixing_transmissibility ( const ParticleMixingConfig &  config,
const amrex::Geometry &  geom,
const erf_auxiliary::MappedDiffusionMetrics &  metrics,
const amrex::MultiFab &  density,
int  density_component,
const amrex::MultiFab *  eddy_diffusivity,
erf_auxiliary::MappedFaceTransmissibility &  transmissibility,
std::string &  diagnostic 
)

The face transmissibility of a policy; None gives zero on every face. density must be the dry-air density (ERF's Rho_comp), which ConstantReference multiplies by.

312 {
314  config, geom, metrics, density, density_component, eddy_diffusivity,
315  erf_auxiliary::MappedDiffusionBoundary{}, transmissibility, diagnostic);
316 }
bool build_particle_mixing_transmissibility(const ParticleMixingConfig &config, const amrex::Geometry &geom, const erf_auxiliary::MappedDiffusionMetrics &metrics, const amrex::MultiFab &density, const int density_component, const amrex::MultiFab *eddy_diffusivity, const erf_auxiliary::MappedDiffusionBoundary &boundary, erf_auxiliary::MappedFaceTransmissibility &transmissibility, std::string &diagnostic)
Definition: ERF_SBMParticleMixing.cpp:319
Definition: ERF_AuxiliaryDiffusion.H:102

Referenced by erf_sbm::SBMTransport::advance_stage(), and ERF::estTimeStep().

Here is the caller graph for this function:

◆ canonical_decimal()

template<typename T >
std::string erf_sbm::canonical_decimal ( const T  value)
20 {
21  std::ostringstream out;
22  out.imbue(std::locale::classic());
23  out.setf(std::ios_base::scientific, std::ios_base::floatfield);
24  out << std::setprecision(std::numeric_limits<T>::max_digits10) << value;
25  return out.str();
26 }

Referenced by canonical_real(), and erf_sbm::SBMBoundaryLedger::serialize().

Here is the caller graph for this function:

◆ canonical_real()

std::string erf_sbm::canonical_real ( const amrex::Real  value,
const bool  allow_unbounded_nan = false 
)
inline
30 {
31  if (allow_unbounded_nan && std::isnan(value)) return "unbounded";
32  return canonical_decimal(value);
33 }
std::string canonical_decimal(const T value)
Definition: ERF_SBMCanonicalIdentity.H:19

Referenced by erf_sbm::ParticleMixingConfig::identity(), erf_sbm::SBMPhysicalBoundaryConfig::identity(), erf_sbm::SpectralGrid::identity(), and erf_sbm::SBMLayout::SBMLayout().

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

◆ composite_inventory_roundoff()

InventoryRoundoff erf_sbm::composite_inventory_roundoff ( const std::uint64_t  coarse_cells,
const std::uint64_t  fine_cells,
const amrex::IntVect &  ratio,
const bool  with_prolongation,
const std::uint64_t  leaf_updates = 0,
const std::uint64_t  boundary_face_terms = 0 
)
inline

Operation-count bound on the difference of two composite leaf inventories, shared by the per-step, regrid and boundary-budget conservation checks. Each positive leaf term uses up to three multiplies and one local accumulation; bound both inventories, the final subtraction, and a pairwise MPI reduction with eight operations per leaf plus two reduction-tree levels per depth. A regrid adds the prolongation of a new fine cell from its parent, every leaf update between the two inventories re-forms each leaf, and each physical-face term of the boundary ledger takes a product, a mask and two sums.

40 {
41  std::uint64_t refinement_volume = 1U;
42  for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
43  refinement_volume *= static_cast<std::uint64_t>(ratio[dir]);
44  }
45  AMREX_ALWAYS_ASSERT(refinement_volume > 0U &&
46  fine_cells % refinement_volume == 0U &&
47  coarse_cells >= fine_cells / refinement_volume);
48  InventoryRoundoff roundoff;
49  roundoff.leaf_cell_terms = coarse_cells - fine_cells / refinement_volume + fine_cells;
50  for (int ranks = amrex::ParallelDescriptor::NProcs(); ranks > 1;
51  ranks = (ranks + 1) / 2) {
52  ++roundoff.reduction_depth;
53  }
54  roundoff.operation_count =
55  8U * roundoff.leaf_cell_terms * (1U + leaf_updates) + 6U * boundary_face_terms +
56  2U * static_cast<std::uint64_t>(roundoff.reduction_depth) + 1U +
57  (with_prolongation ? refinement_volume + 6U : 0U);
58  const amrex::Real q = static_cast<amrex::Real>(roundoff.operation_count) *
60  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(q < amrex::Real(1.0),
61  "SBM composite inventory check: operation count times machine epsilon "
62  "reaches one, so this grid cannot be checked at this precision");
63  roundoff.rounding_factor = q / (amrex::Real(1.0) - q);
64  return roundoff;
65 }
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(axis >=0 &&axis< AMREX_SPACEDIM, "prob.axis must be 0, 1 or 2")
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
@ U
Definition: ERF_IndexDefines.H:178
@ q
Definition: ERF_WSM6.H:296

Referenced by ERF::sbm_check_budget(), ERF::sbm_qualification_check_regrid(), and ERF::sbm_qualification_check_step().

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

◆ copy_host_slow_component()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void erf_sbm::copy_host_slow_component ( const amrex::Array4< amrex::Real > &  current,
const amrex::Array4< const amrex::Real > &  predictor,
const int  i,
const int  j,
const int  k,
const int  component,
const bool  sbm_active,
const int  qc_component,
const int  qr_component 
)
noexcept

Perform ERF's predictor-to-current copy for one slow state component.

20 {
21  const bool sbm_projected_liquid =
22  sbm_active &&
23  (component == qc_component || component == qr_component);
24  if (!sbm_projected_liquid) {
25  current(i, j, k, component) = predictor(i, j, k, component);
26  }
27 }

Referenced by erf_slow_rhs_post().

Here is the caller graph for this function:

◆ CountRegridCells()

SBMRegridCellCounts erf_sbm::CountRegridCells ( const amrex::BoxArray &  old_grids,
const amrex::BoxArray &  new_grids 
)
1193 {
1194  SBMRegridCellCounts counts;
1195  counts.cells = new_grids.numPts();
1196  for (int box = 0; !old_grids.empty() && box < new_grids.size(); ++box) {
1197  for (const auto& overlap : old_grids.intersections(new_grids[box])) {
1198  counts.retained += overlap.second.numPts();
1199  }
1200  }
1201  counts.prolonged = counts.cells - counts.retained;
1202  counts.released = old_grids.numPts() - counts.retained;
1203  return counts;
1204 }

Referenced by ERF::remake_sbm_level().

Here is the caller graph for this function:

◆ diffusion_face_kind_name()

const char * erf_sbm::diffusion_face_kind_name ( const erf_auxiliary::DiffusionFaceKind  kind)
noexcept
91 {
92  switch (kind) {
93  case erf_auxiliary::DiffusionFaceKind::Closed: return "closed";
94  case erf_auxiliary::DiffusionFaceKind::Dirichlet: return "dirichlet";
95  case erf_auxiliary::DiffusionFaceKind::DirichletWhereInward: return "dirichlet-where-inward";
96  }
97  return "unknown";
98 }

Referenced by particle_mixing_schema().

Here is the caller graph for this function:

◆ evaluate_constraint_descriptor()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_sbm::evaluate_constraint_descriptor ( const ConstraintDescriptor &  constraint,
const ConstraintTerm *  terms,
const amrex::Real *  state 
)
noexcept

Evaluate a validated flattened constraint in host or device code.

73 {
74  amrex::Real result = amrex::Real(0.0);
75  for (int i = 0; i < constraint.term_count; ++i) {
76  const auto& term = terms[constraint.term_offset + i];
77  result = std::fma(term.coefficient, state[term.component], result);
78  }
79  return result;
80 }

◆ face_kind_name()

const char * erf_sbm::face_kind_name ( const AdvectionFaceKind  kind)
noexcept
79 {
80  switch (kind) {
81  case AdvectionFaceKind::Periodic: return "periodic";
82  case AdvectionFaceKind::ImpermeableWall: return "wall";
83  case AdvectionFaceKind::AdvectiveOutflow: return "outflow";
84  case AdvectionFaceKind::PrescribedInflow: return "inflow";
85  }
86  return "unknown";
87 }

Referenced by erf_sbm::SBMPhysicalBoundaryConfig::identity(), and validate_particle_mixing_boundaries().

Here is the caller graph for this function:

◆ face_name()

const char * erf_sbm::face_name ( const int  face)
noexcept
71 {
72  static constexpr const char* names[physical_face_count] =
73  {"xlo", "ylo", "zlo", "xhi", "yhi", "zhi"};
74  return face >= 0 && face < physical_face_count ? names[face] : "unknown";
75 }
constexpr int physical_face_count
Definition: ERF_SBMPhysicalBoundary.H:19

Referenced by erf_sbm::SBMTransport::advance_stage(), erf_sbm::erf_detail_SBMTransport::check_physical_face_carriers(), ERF::configure_sbm_physical_boundaries(), erf_sbm::SBMPhysicalBoundaryConfig::identity(), erf_sbm::SBMBoundaryLedger::parse(), particle_mixing_schema(), ERF::ReadVelsOnlyFromCheckpointFile(), erf_sbm::SBMBoundaryLedger::serialize(), erf_sbm::SBMTransport::set_physical_boundaries(), and validate_particle_mixing_boundaries().

Here is the caller graph for this function:

◆ flatten_constraint_groups()

FlattenedConstraintSet erf_sbm::flatten_constraint_groups ( const std::vector< ConstraintGroup > &  groups,
int  state_components 
)

Flatten arbitrary semantic groups through the production sparse format.

169 {
170  if (state_components < 0) {
171  throw std::invalid_argument("SBM production constraints require a nonnegative state size");
172  }
173  FlattenedConstraintSet flattened;
174  for (std::size_t gi = 0; gi < groups.size(); ++gi) {
175  const auto& group = groups[gi];
176  for (std::size_t ci = 0; ci < group.constraints.size(); ++ci) {
177  const auto& constraint = group.constraints[ci];
178  if (constraint.terms.empty() ||
179  constraint.terms.size() > static_cast<std::size_t>(std::numeric_limits<int>::max()) ||
180  flattened.terms.size() > static_cast<std::size_t>(std::numeric_limits<int>::max()) -
181  constraint.terms.size()) {
182  throw std::invalid_argument(
183  "SBM production constraints require a nonempty representable sparse term range: " +
184  constraint.semantic_id);
185  }
186  ConstraintDescriptor descriptor;
187  descriptor.group_index = static_cast<int>(gi);
188  descriptor.population_id = group.population_id;
189  descriptor.bin = group.bin;
190  descriptor.constraint_index = static_cast<int>(ci);
191  descriptor.term_offset = static_cast<int>(flattened.terms.size());
192  descriptor.term_count = static_cast<int>(constraint.terms.size());
193  for (const auto& term : constraint.terms) {
194  if (term.component < 0 || term.component >= state_components ||
195  !finite(term.coefficient)) {
196  throw std::invalid_argument(
197  "SBM production constraint has an invalid sparse term: " +
198  constraint.semantic_id);
199  }
200  flattened.terms.push_back(term);
201  }
202  flattened.constraints.push_back(descriptor);
203  }
204  }
205  return flattened;
206 }
DiagnosticDescriptor descriptor
Definition: ERF_Plotfile2DCatalog.cpp:142
bool finite(amrex::Real value) noexcept
Definition: ERF_CloudChamber.H:362
real(c_double), private ci
Definition: ERF_module_mp_morr_two_moment.F90:203

Referenced by make_constraint_descriptors().

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

◆ host_write_allowed()

bool erf_sbm::host_write_allowed ( bool  sbm_active,
int  component 
)
noexcept

The native host retains qv; SBM exclusively owns the compact liquid lanes.

24 {
25  return host_write_range_allowed(sbm_active, component, 1);
26 }
bool host_write_range_allowed(const bool sbm_active, const int start_component, const int num_components) noexcept
Definition: ERF_SBMOwnership.cpp:28
Here is the call graph for this function:

◆ host_write_path_name()

const char * erf_sbm::host_write_path_name ( const HostWritePath  path)
noexcept
10 {
11  switch (path) {
12  case HostWritePath::Advection: return "advection";
13  case HostWritePath::Diffusion: return "diffusion";
14  case HostWritePath::Source: return "source";
15  case HostWritePath::Positivity: return "positivity";
16  case HostWritePath::Microphysics: return "microphysics";
17  case HostWritePath::Wall: return "wall";
18  case HostWritePath::Boundary: return "boundary";
19  }
20  return "unknown";
21 }

Referenced by require_host_write_range_allowed().

Here is the caller graph for this function:

◆ host_write_range_allowed()

bool erf_sbm::host_write_range_allowed ( bool  sbm_active,
int  start_component,
int  num_components 
)
noexcept

Check every component in a native writer's complete, non-empty write range.

30 {
31  if (start_component < 0 || num_components <= 0 ||
32  num_components > std::numeric_limits<int>::max() - start_component) {
33  return false;
34  }
35  if (!sbm_active) return true;
36  const int end_component = start_component + num_components;
37  return !(start_component <= RhoQ2_comp && RhoQ2_comp < end_component) &&
38  !(start_component <= RhoQ3_comp && RhoQ3_comp < end_component);
39 }
#define RhoQ2_comp
Definition: ERF_IndexDefines.H:79
#define RhoQ3_comp
Definition: ERF_IndexDefines.H:80

Referenced by host_write_allowed(), and require_host_write_range_allowed().

Here is the caller graph for this function:

◆ integrate_interval()

bool erf_sbm::integrate_interval ( const ReconstructionDelta &  reconstruction,
const amrex::Real  lower,
const amrex::Real  upper,
const bool  include_upper,
IntegratedMoments &  integral 
)
101 {
102  std::vector<amrex::Real> properties(reconstruction.property_per_particle.size(),
103  amrex::Real(0.0));
104  ReconstructionDeltaView view;
105  view.bin = reconstruction.bin;
106  view.empty = reconstruction.empty;
107  view.normalized_roundoff = reconstruction.normalized_roundoff;
108  view.number = reconstruction.number;
109  view.particle_mass = reconstruction.particle_mass;
110  view.property_per_particle = reconstruction.property_per_particle.data();
111  view.property_count = static_cast<int>(reconstruction.property_per_particle.size());
112  IntegratedMomentsCoreResult core;
113  if (!integrate_interval_core(view, lower, upper, include_upper,
114  properties.data(), static_cast<int>(properties.size()), core)) {
115  return false;
116  }
117  IntegratedMoments next;
118  next.number = core.number;
119  next.water_mass = core.water_mass;
120  next.attached_properties = std::move(properties);
121  integral = std::move(next);
122  return true;
123 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool integrate_interval_core(const ReconstructionDeltaView reconstruction, const amrex::Real lower, const amrex::Real upper, const bool include_upper, amrex::Real *attached_properties, const int property_capacity, IntegratedMomentsCoreResult &integral) noexcept
Definition: ERF_SBMRemapping.H:990
Here is the call graph for this function:

◆ integrate_interval_core()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool erf_sbm::integrate_interval_core ( const ReconstructionDeltaView  reconstruction,
const amrex::Real  lower,
const amrex::Real  upper,
const bool  include_upper,
amrex::Real *  attached_properties,
const int  property_capacity,
IntegratedMomentsCoreResult &  integral 
)
noexcept

Integrate one reconstructed delta over [lower, upper), optionally including upper.

995 {
996  if (!amrex::Math::isfinite(lower) || !amrex::Math::isfinite(upper) || !(lower < upper) ||
997  !remap_detail::finite_nonnegative(reconstruction.number) ||
998  !remap_detail::finite_nonnegative(reconstruction.particle_mass) ||
999  reconstruction.property_count < 0 || property_capacity < reconstruction.property_count ||
1000  (reconstruction.property_count > 0 &&
1001  (reconstruction.property_per_particle == nullptr || attached_properties == nullptr)) ||
1002  (!reconstruction.empty && reconstruction.number <= amrex::Real(0.0)) ||
1003  (reconstruction.empty && (reconstruction.number != amrex::Real(0.0) ||
1004  reconstruction.particle_mass != amrex::Real(0.0)))) {
1005  return false;
1006  }
1007  for (int property = 0; property < reconstruction.property_count; ++property) {
1008  const amrex::Real value = reconstruction.property_per_particle[property];
1009  if (!remap_detail::finite_nonnegative(value) ||
1010  (reconstruction.empty && value != amrex::Real(0.0))) {
1011  return false;
1012  }
1013  }
1014  const bool contains = !reconstruction.empty && reconstruction.particle_mass >= lower &&
1015  (reconstruction.particle_mass < upper ||
1016  (include_upper && reconstruction.particle_mass == upper));
1017  IntegratedMomentsCoreResult next;
1018  if (contains) {
1019  next.number = reconstruction.number;
1020  if (!remap_detail::finite_product(reconstruction.number,
1021  reconstruction.particle_mass, next.water_mass)) {
1022  return false;
1023  }
1024  for (int property = 0; property < reconstruction.property_count; ++property) {
1025  amrex::Real amount = amrex::Real(0.0);
1026  if (!remap_detail::finite_product(reconstruction.number,
1027  reconstruction.property_per_particle[property], amount)) {
1028  return false;
1029  }
1030  }
1031  }
1032  for (int property = 0; property < reconstruction.property_count; ++property) {
1033  amrex::Real amount = amrex::Real(0.0);
1034  if (contains && !remap_detail::finite_product(reconstruction.number,
1035  reconstruction.property_per_particle[property], amount)) {
1036  return false;
1037  }
1038  attached_properties[property] = amount;
1039  }
1040  integral = next;
1041  return true;
1042 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool finite_product(const amrex::Real left, const amrex::Real right, amrex::Real &result) noexcept
Definition: ERF_SBMRemapping.H:198

Referenced by integrate_interval().

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

◆ inverse_two_moment()

std::pair< amrex::Real, amrex::Real > erf_sbm::inverse_two_moment ( amrex::Real  L,
amrex::Real  H,
amrex::Real  lower,
amrex::Real  upper 
)

Inverse transform with finite-state and nonnegative-endpoint checks.

288 {
289  return SpectralGrid::endpoints_to_two_moment(L, H, lower, upper);
290 }
Real H
Definition: ERF_InitCustomPert_MovingTerrain.H:8

◆ level_time_matches()

bool erf_sbm::level_time_matches ( const double  state_time,
const double  level_time,
const double  level_dt 
)
inlinenoexcept

Whether a level's accepted state is at the host level time: to roundoff of the level's step, or exactly before any step has been taken.

44 {
45  return level_dt > 0.0
46  ? semantic_time_matches(state_time, level_time, level_dt)
47  : semantic_time_matches_exact(state_time, level_time);
48 }
bool semantic_time_matches(const double lhs, const double rhs, const double dt_min) noexcept
Definition: ERF_SBMAMRTime.H:14
bool semantic_time_matches_exact(const double lhs, const double rhs) noexcept
Definition: ERF_SBMAMRTime.H:32

Referenced by ERF::remake_sbm_level(), and ERF::WriteCheckpointFile().

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

◆ make_advection_face_policy()

constexpr AMREX_GPU_HOST_DEVICE AdvectionFacePolicy erf_sbm::make_advection_face_policy ( const AdvectionFacePolicyInput &  input)
constexprnoexcept

Decide the face-level spectral advection semantics; the transport fills the physical ghosts. At a physical face whose high-order stencil is not qualified, the admissible donor proposal remains available and high-order transport falls back to it.

61 {
62  using Action = AdvectionFaceAction;
63  if (input.kind == AdvectionFaceKind::Periodic) {
64  return {Action::PeriodicSharedFace, false, false, true};
65  }
66  if (input.kind == AdvectionFaceKind::ImpermeableWall ||
67  input.outward_carrier == amrex::Real(0.0)) {
68  return {Action::ZeroNormalFlux, false, false, false};
69  }
70 
71  if (input.outward_carrier > amrex::Real(0.0)) {
72  // Outward flow uses the interior spectrum. The donor path is always
73  // defined; high order is used only with a qualified physical stencil.
74  return {Action::InteriorDonor, true, false,
75  input.high_order_stencil_available};
76  }
77 
78  // Reverse flow contradicts a face declared as advective outflow. External
79  // spectral data must not silently change that declared boundary policy.
80  if (input.kind == AdvectionFaceKind::AdvectiveOutflow) {
81  return {Action::RejectInwardOutflow, false, false, false};
82  }
83 
84  // The remaining negative-carrier boundary category is prescribed inflow.
85  // A complete explicit atomic-group spectrum is required; qc/qr cannot
86  // supply missing bin or attached-property composition.
87  if (!input.explicit_spectral_state_present) {
88  return {Action::RejectMissingInflowState, false, false, false};
89  }
90  if (!input.explicit_spectral_group_complete) {
91  return {Action::RejectIncompleteInflowState, false, false, false};
92  }
93  return {Action::ExplicitSpectralInflow, false, true,
94  input.high_order_stencil_available};
95 }
std::string input
Definition: ERF_InputPreflight.cpp:29
AdvectionFaceAction
Definition: ERF_SBMAdvectionBoundary.H:18

Referenced by erf_sbm::erf_detail_SBMTransport::check_physical_face_carriers().

Here is the caller graph for this function:

◆ make_attached_property_support_descriptors()

std::vector< AttachedPropertySupportDescriptor > erf_sbm::make_attached_property_support_descriptors ( const SBMLayout &  layout)
215 {
216  std::vector<AttachedPropertySupportDescriptor> result;
217  const auto groups = make_constraint_groups(layout);
218  for (std::size_t group_index = 0; group_index < groups.size(); ++group_index) {
219  const auto& group = groups[group_index];
220  const auto population = std::find_if(layout.populations().begin(), layout.populations().end(),
221  [&](const PopulationLayout& candidate) {
222  return candidate.population_id == group.population_id;
223  });
224  if (population == layout.populations().end()) {
225  throw std::logic_error("SBM attached-property group references an unknown population");
226  }
227  for (const int property_index : group.attached_property_indices) {
228  const auto& property = layout.attached_properties()[static_cast<std::size_t>(property_index)];
229  AttachedPropertySupportDescriptor descriptor;
230  descriptor.group_index = static_cast<int>(group_index);
231  descriptor.property_index = property_index;
232  descriptor.property_component = layout.property_offset(property_index) + group.bin;
233  descriptor.mass_component = population->mass_offset + group.bin;
234  descriptor.number_component = population->number_offset >= 0 ?
235  population->number_offset + group.bin : -1;
236  descriptor.two_moment = descriptor.number_component >= 0 ? 1 : 0;
237  descriptor.carrier_component = descriptor.two_moment ?
238  descriptor.number_component : descriptor.mass_component;
239  descriptor.pivot = population->grid.pivot(group.bin);
240  // The transport envelope is expressed as S/carrier. For a
241  // two-moment carrier this is S/C, while a one-moment property
242  // uses C=M/m_pivot and therefore has normalized bounds
243  // (support_min/m_pivot, support_max/m_pivot).
244  const amrex::Real support_scale = descriptor.two_moment ?
245  amrex::Real(1.0) : descriptor.pivot;
246  descriptor.hard_min = property.support_min / support_scale;
247  descriptor.hard_max = property.support_max / support_scale;
248  descriptor.has_hard_min = finite(property.support_min) ? 1 : 0;
249  descriptor.has_hard_max = finite(property.support_max) ? 1 : 0;
250  result.push_back(descriptor);
251  }
252  }
253  return result;
254 }
Here is the call graph for this function:

◆ make_constraint_closure_chunks()

std::vector< ConstraintClosureChunk > erf_sbm::make_constraint_closure_chunks ( const SBMLayout &  layout,
const int  max_groups 
)
258 {
259  if (max_groups <= 0) {
260  throw std::invalid_argument("SBM scratch chunk size must be a positive number of complete groups");
261  }
262  const auto groups = make_constraint_groups(layout);
263  std::vector<ConstraintClosureChunk> chunks;
264  for (std::size_t group_index = 0; group_index < groups.size(); ++group_index) {
265  if (chunks.empty() ||
266  static_cast<int>(chunks.back().group_indices.size()) >= max_groups) {
267  chunks.push_back({});
268  }
269  auto& chunk = chunks.back();
270  chunk.group_indices.push_back(static_cast<int>(group_index));
271  for (const int component : groups[group_index].members) {
272  if (std::find(chunk.components.begin(), chunk.components.end(), component) == chunk.components.end()) {
273  chunk.components.push_back(component);
274  }
275  }
276  }
277  return chunks;
278 }

Referenced by prolong_carrier_relative_chunks(), and restrict_mapped_spectrum_impl().

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

◆ make_constraint_descriptors()

FlattenedConstraintSet erf_sbm::make_constraint_descriptors ( const SBMLayout &  layout)

Flatten complete semantic groups into bounded device descriptors.

209 {
210  return flatten_constraint_groups(make_constraint_groups(layout), layout.ncomp());
211 }
FlattenedConstraintSet flatten_constraint_groups(const std::vector< ConstraintGroup > &groups, const int state_components)
Definition: ERF_SBMConstraintGroups.cpp:167
Here is the call graph for this function:

◆ make_constraint_groups()

std::vector< ConstraintGroup > erf_sbm::make_constraint_groups ( const SBMLayout &  layout)

Build deterministic groups from the immutable runtime layout.

78 {
79  std::vector<ConstraintGroup> groups;
80  for (const auto& population : layout.populations()) {
81  const int nbins = population.grid.nbins();
82  for (int bin = 0; bin < nbins; ++bin) {
83  ConstraintGroup group;
84  group.population_id = population.population_id;
85  group.bin = bin;
86  group.semantic_id = population.semantic_id + ".bin." + std::to_string(bin);
87  group.moment_mode = population.moment_mode;
88  const int mass = population.mass_offset + bin;
89  group.members.push_back(mass);
90  group.transport_members.push_back(mass);
91  const int number = population.number_offset >= 0 ? population.number_offset + bin : -1;
92  if (number >= 0) {
93  group.members.push_back(number);
94  group.transport_members.push_back(number);
95  const amrex::Real lower = population.grid.edges()[static_cast<std::size_t>(bin)];
96  const amrex::Real upper = population.grid.edges()[static_cast<std::size_t>(bin + 1)];
97  const amrex::Real denominator = upper - lower;
98  add_constraint(group, "number_nonnegative", {{number, amrex::Real(1.0)}});
99  add_constraint(group, "endpoint_low",
100  {{number, upper / denominator},
101  {mass, -amrex::Real(1.0) / denominator}});
102  add_constraint(group, "endpoint_high",
103  {{mass, amrex::Real(1.0) / denominator},
104  {number, -lower / denominator}});
105  } else {
106  add_constraint(group, "mass_nonnegative", {{mass, amrex::Real(1.0)}});
107  }
108 
109  for (std::size_t property_index = 0;
110  property_index < layout.attached_properties().size(); ++property_index) {
111  const auto& property = layout.attached_properties()[property_index];
112  if (property.carrier_population != population.population_id) continue;
113  const int property_component = layout.property_offset(static_cast<int>(property_index)) + bin;
114  group.members.push_back(property_component);
115  group.transport_members.push_back(property_component);
116  group.attached_property_indices.push_back(static_cast<int>(property_index));
117  add_constraint(group, property.semantic_id + ".nonnegative", {{property_component, amrex::Real(1.0)}});
118 
119  const bool has_lower = finite(property.support_min) && property.support_min > amrex::Real(0.0);
120  const bool has_upper = finite(property.support_max) &&
121  property.support_max >= property.support_min;
122  if (has_upper) {
123  if (number >= 0) {
124  // Two-moment storage is physical (M,C), so support
125  // bounds are bounds on the carrier number C.
126  add_constraint(group, property.semantic_id + ".support_upper",
127  {{number, property.support_max},
128  {property_component, -amrex::Real(1.0)}});
129  } else {
130  const amrex::Real pivot = population.grid.pivot(bin);
131  add_constraint(group, property.semantic_id + ".support_upper",
132  {{mass, property.support_max / pivot},
133  {property_component, -1.0}});
134  }
135  }
136  if (has_lower) {
137  if (number >= 0) {
138  add_constraint(group, property.semantic_id + ".support_lower",
139  {{number, -property.support_min},
140  {property_component, amrex::Real(1.0)}});
141  } else {
142  const amrex::Real pivot = population.grid.pivot(bin);
143  add_constraint(group, property.semantic_id + ".support_lower",
144  {{mass, -property.support_min / pivot},
145  {property_component, amrex::Real(1.0)}});
146  }
147  }
148 
149  if (property.kind == PropertyKind::MassBoundedSubset) {
150  if (number >= 0) {
151  // The carrier mass is already the authoritative M
152  // component in two-moment storage.
153  add_constraint(group, property.semantic_id + ".carrier_mass_minus_subset",
154  {{mass, amrex::Real(1.0)}, {property_component, -amrex::Real(1.0)}});
155  } else {
156  add_constraint(group, property.semantic_id + ".carrier_mass_minus_subset",
157  {{mass, amrex::Real(1.0)}, {property_component, -amrex::Real(1.0)}});
158  }
159  }
160  }
161  groups.push_back(std::move(group));
162  }
163  }
164  return groups;
165 }

Referenced by authoritative_state_admissible(), make_attached_property_support_descriptors(), make_constraint_closure_chunks(), make_constraint_descriptors(), and validate_inflow_state().

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

◆ make_particle_mixing_config()

bool erf_sbm::make_particle_mixing_config ( const std::string &  name,
amrex::Real  reference_kh,
amrex::Real  reference_kv,
ParticleMixingConfig &  config,
std::string &  reason 
)

The policy named by erf.sbm_particle_mixing and its reference diffusivities.

83 {
84  reason.clear();
85  config = {};
87  reason = "erf.sbm_particle_mixing must be None, ConstantReference or "
88  "HostPassiveScalar, not '" + name + "'";
89  return false;
90  }
91  config.reference_kh = reference_kh;
92  config.reference_kv = reference_kv;
94  reason = "erf.sbm_particle_mixing: " + reason;
95  return false;
96  }
97  return true;
98 }
std::string name
Definition: ERF_Plotfile2DCatalog.cpp:139
bool parse_particle_mixing_policy(const std::string &name, ParticleMixingPolicy &policy)
Definition: ERF_SBMParticleMixing.cpp:28
Here is the call graph for this function:

◆ make_stage_mixing_inputs() [1/2]

SBMStageMixingInputs erf_sbm::make_stage_mixing_inputs ( const SBMTransport &  transport,
const amrex::MultiFab *  eddy_diffusivity,
const amrex::Vector< std::unique_ptr< amrex::MultiFab >> &  mapfac,
const amrex::MultiFab *  ax,
const amrex::MultiFab *  ay,
const amrex::Real *  stretched_dz,
const amrex::MultiFab *  z_nd = nullptr,
const amrex::MultiFab *  z_cc = nullptr 
)

Stage mixing inputs from ERF's level fields: map factors indexed by MapFacType, the face areas of a stretched or terrain-fitted mesh, the vertical spacing of a stretched one, the nodal and cell-centre heights of a terrain-fitted one, and the eddy diffusivity, which only HostPassiveScalar reads.

◆ make_stage_mixing_inputs() [2/2]

SBMStageMixingInputs erf_sbm::make_stage_mixing_inputs ( const SBMTransport &  transport,
const MultiFab *  eddy_diffusivity,
const amrex::Vector< std::unique_ptr< MultiFab >> &  mapfac,
const MultiFab *  ax,
const MultiFab *  ay,
const Real *  stretched_dz,
const MultiFab *  z_nd,
const MultiFab *  z_cc 
)
2469 {
2470  SBMStageMixingInputs inputs;
2471  if (transport.particle_mixing().policy == ParticleMixingPolicy::HostPassiveScalar) {
2472  inputs.eddy_diffusivity = eddy_diffusivity;
2473  }
2474  auto& metrics = inputs.metrics;
2475  metrics.mesh = transport.mixing_mesh();
2476  metrics.mf_ux = mapfac[MapFacType::u_x].get();
2477  metrics.mf_uy = mapfac[MapFacType::u_y].get();
2478  metrics.mf_vx = mapfac[MapFacType::v_x].get();
2479  metrics.mf_vy = mapfac[MapFacType::v_y].get();
2480  metrics.mf_mx = mapfac[MapFacType::m_x].get();
2481  metrics.mf_my = mapfac[MapFacType::m_y].get();
2482  if (metrics.mesh == erf_auxiliary::DiffusionMesh::StretchedDz) {
2483  metrics.ax = ax;
2484  metrics.ay = ay;
2485  metrics.stretched_dz = stretched_dz;
2486  } else if (metrics.mesh == erf_auxiliary::DiffusionMesh::VariableDz) {
2487  metrics.ax = ax;
2488  metrics.ay = ay;
2489  metrics.z_nd = z_nd;
2490  inputs.z_cc = z_cc;
2491  }
2492  return inputs;
2493 }
@ v_x
Definition: ERF_DataStruct.H:40
@ u_y
Definition: ERF_DataStruct.H:41
@ v_y
Definition: ERF_DataStruct.H:41
@ m_y
Definition: ERF_DataStruct.H:41
@ u_x
Definition: ERF_DataStruct.H:40
@ m_x
Definition: ERF_DataStruct.H:40

Referenced by erf_slow_rhs_post(), and ERF::estTimeStep().

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

◆ map_erf_boundary()

bool erf_sbm::map_erf_boundary ( ERF_BC  bc,
AdvectionFaceKind &  kind,
std::string &  reason 
)

Map one ERF physical boundary type, or explain why SBM rejects it.

115 {
116  reason.clear();
117  switch (bc) {
118  case ERF_BC::periodic:
119  kind = AdvectionFaceKind::Periodic;
120  return true;
121  case ERF_BC::slip_wall:
123  // A surface layer holds the normal carrier at zero, and particles cross it
124  // by no diffusive or depositional transfer.
126  kind = AdvectionFaceKind::ImpermeableWall;
127  return true;
128  case ERF_BC::symmetry:
129  reason = "ERF does not hold the normal dry-air carrier of a symmetry face "
130  "at zero, so it is not an impermeable spectral wall";
131  return false;
132  case ERF_BC::outflow:
133  case ERF_BC::ho_outflow:
134  kind = AdvectionFaceKind::AdvectiveOutflow;
135  return true;
136  case ERF_BC::inflow:
138  kind = AdvectionFaceKind::PrescribedInflow;
139  return true;
140  case ERF_BC::open:
141  reason = "open boundaries advect with a characteristic scheme that the "
142  "spectral transport does not share";
143  return false;
144  case ERF_BC::undefined:
145  break;
146  }
147  reason = "the boundary type is undefined";
148  return false;
149 }
@ ho_outflow
@ inflow_outflow
@ no_slip_wall
@ surface_layer
real(c_double), private bc
Definition: ERF_module_mp_morr_two_moment.F90:182

Referenced by ERF::configure_sbm_physical_boundaries().

Here is the caller graph for this function:

◆ map_erf_diffusion()

erf_auxiliary::DiffusionFaceKind erf_sbm::map_erf_diffusion ( ERF_BC  bc)
noexcept

The particle-mixing semantics of one ERF physical boundary type.

102 {
103  // ERF diffuses its scalars against an ext_dir ghost at an inflow face and an
104  // ext_dir_upwind one at an inflow_outflow face; every other face SBM accepts
105  // carries no particle mixing.
107  if (bc == ERF_BC::inflow_outflow) {
109  }
111 }

Referenced by ERF::configure_sbm_physical_boundaries().

Here is the caller graph for this function:

◆ MappedRefluxCorrectionMaskIsValid() [1/2]

bool erf_sbm::MappedRefluxCorrectionMaskIsValid ( const amrex::MultiFab &  invalid_mask,
std::string &  diagnostic 
)

◆ MappedRefluxCorrectionMaskIsValid() [2/2]

bool erf_sbm::MappedRefluxCorrectionMaskIsValid ( const MultiFab &  invalid_mask,
std::string &  diagnostic 
)
589 {
590  const bool local_ok = invalid_mask.max(0, 0, true) <= Real(0.0);
591  return collective_all_true(
592  local_ok,
593  "YA reflux produced a correction outside the uncovered coarse/fine interface mask or its mapped update was unrepresentable",
594  "YA reflux correction support or mapped update was invalid on another MPI rank",
595  diagnostic);
596 }

Referenced by ERF::sbm_synchronize_levels().

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

◆ matched_diffusion_fraction()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_sbm::matched_diffusion_fraction ( const amrex::Real  high,
const amrex::Real  low 
)
noexcept

Terrain-fitted mixing only: the fraction theta in [0, 1] of one matched coordinate's nominal low-order diffusive rate low that a face carries, given that coordinate's native rate high: 1 for low = 0, 0 where high is zero or opposes low, |high| / |low| where it is smaller, and 1 otherwise, so theta low lies between zero and high. A nonfinite rate gives NaN, which the caller rejects. A face's group takes the least fraction of its coordinates.

171 {
172  if (!amrex::Math::isfinite(high) || !amrex::Math::isfinite(low)) {
173  return std::numeric_limits<amrex::Real>::quiet_NaN();
174  }
175  if (low == amrex::Real(0.0)) { return amrex::Real(1.0); }
176  if (high == amrex::Real(0.0) || (high > amrex::Real(0.0)) != (low > amrex::Real(0.0))) {
177  return amrex::Real(0.0);
178  }
179  const amrex::Real h = amrex::Math::abs(high);
180  const amrex::Real l = amrex::Math::abs(low);
181  return h < l ? h / l : amrex::Real(1.0);
182 }

Referenced by erf_sbm::erf_detail_SBMTransport::add_matched_terrain_mixing().

Here is the caller graph for this function:

◆ parse_particle_mixing_policy()

bool erf_sbm::parse_particle_mixing_policy ( const std::string &  name,
ParticleMixingPolicy &  policy 
)
29 {
30  for (const auto candidate : {ParticleMixingPolicy::None,
31  ParticleMixingPolicy::ConstantReference,
32  ParticleMixingPolicy::HostPassiveScalar}) {
33  if (name == particle_mixing_name(candidate)) {
34  policy = candidate;
35  return true;
36  }
37  }
38  return false;
39 }

Referenced by make_particle_mixing_config().

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

◆ particle_mixing_boundary()

erf_auxiliary::MappedDiffusionBoundary erf_sbm::particle_mixing_boundary ( const SBMPhysicalBoundaryConfig &  boundaries,
const std::array< const amrex::MultiFab *, AMREX_SPACEDIM > &  carrier 
)

The diffusive faces of a boundary configuration, with the dry-air carrier of each direction.

430 {
432  boundary.kind = boundaries.diffusion;
433  boundary.carrier = carrier;
434  return boundary;
435 }
std::array< DiffusionFaceKind, 2 *AMREX_SPACEDIM > kind
Definition: ERF_AuxiliaryDiffusion.H:103
std::array< const amrex::MultiFab *, AMREX_SPACEDIM > carrier
Definition: ERF_AuxiliaryDiffusion.H:104

Referenced by erf_sbm::SBMTransport::advance_stage(), and ERF::estTimeStep().

Here is the caller graph for this function:

◆ particle_mixing_coefficients()

bool erf_sbm::particle_mixing_coefficients ( const ParticleMixingConfig &  config,
erf_auxiliary::MappedDiffusionCoefficients &  coefficients,
std::string &  reason 
)

The host coefficient semantics of a mixing policy other than None.

250 {
251  if (!validate_particle_mixing_config(config, reason)) { return false; }
252  coefficients = {};
253  switch (config.policy) {
255  reason = "particle mixing policy None has no diffusion coefficients";
256  return false;
257  case ParticleMixingPolicy::ConstantReference:
258  coefficients.horizontal.molecular_coeff = config.reference_kh;
259  coefficients.vertical.molecular_coeff = config.reference_kv;
260  coefficients.mode.molecular_is_kinematic = true;
261  coefficients.mode.add_turbulence = false;
262  return true;
263  case ParticleMixingPolicy::HostPassiveScalar:
264  for (auto* channel : {&coefficients.horizontal, &coefficients.vertical}) {
265  channel->molecular_coeff = amrex::Real(0.0);
266  channel->eddy_h_comp = EddyDiff::Scalar_h;
267  channel->eddy_v_comp = EddyDiff::Scalar_v;
268  }
269  coefficients.mode.molecular_is_kinematic = false;
270  coefficients.mode.add_turbulence = true;
271  return true;
272  }
273  reason = "unknown particle mixing policy";
274  return false;
275 }
@ Scalar_v
Definition: ERF_IndexDefines.H:269
@ Scalar_h
Definition: ERF_IndexDefines.H:264
bool molecular_is_kinematic
Definition: ERF_ScalarDiffusion.H:51
bool add_turbulence
Definition: ERF_ScalarDiffusion.H:52
amrex::Real molecular_coeff
Definition: ERF_ScalarDiffusion.H:25
ScalarDiffusionCoefficients vertical
Definition: ERF_AuxiliaryDiffusion.H:65
ScalarDiffusionCoefficientMode mode
Definition: ERF_AuxiliaryDiffusion.H:66
ScalarDiffusionCoefficients horizontal
Definition: ERF_AuxiliaryDiffusion.H:64

Referenced by erf_sbm::erf_detail_SBMTransport::add_high_order_mixing(), build_particle_mixing_transmissibility(), and erf_sbm::erf_detail_SBMTransport::build_terrain_high_order_mixing().

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

◆ particle_mixing_mesh()

bool erf_sbm::particle_mixing_mesh ( MeshType  mesh_type,
erf_auxiliary::DiffusionMesh &  mesh,
std::string &  reason,
bool  terrain_qualification = false 
)

The low-order operator mesh; terrain-fitted (VariableDz) meshes are rejected unless terrain_qualification is set, for qualification only.

282 {
283  reason.clear();
284  if (mesh_type == MeshType::VariableDz && terrain_qualification) {
286  return true;
287  }
288  if (mesh_type == MeshType::ConstantDz) {
290  return true;
291  }
292  if (mesh_type == MeshType::StretchedDz) {
294  return true;
295  }
296  reason = "SBM particle mixing on a terrain-fitted (VariableDz) mesh has not passed its "
297  "release gates; erf.sbm_particle_mixing_terrain_qualification enables it for "
298  "qualification only";
299  return false;
300 }

Referenced by ERF::ERF_shared(), and validate_particle_mixing_host().

Here is the caller graph for this function:

◆ particle_mixing_name()

const char * erf_sbm::particle_mixing_name ( const ParticleMixingPolicy  policy)
noexcept
18 {
19  switch (policy) {
20  case ParticleMixingPolicy::None: return "None";
21  case ParticleMixingPolicy::ConstantReference: return "ConstantReference";
22  case ParticleMixingPolicy::HostPassiveScalar: return "HostPassiveScalar";
23  }
24  return "Unknown";
25 }

Referenced by erf_sbm::SBMTransport::advance_stage(), build_particle_mixing_transmissibility(), parse_particle_mixing_policy(), validate_particle_mixing_boundaries(), validate_particle_mixing_config(), and validate_particle_mixing_host().

Here is the caller graph for this function:

◆ particle_mixing_schema() [1/3]

std::string erf_sbm::particle_mixing_schema ( const ParticleMixingConfig &  config)

Restart-schema lines of a mixing policy; empty for None.

211 {
212  if (config.policy == ParticleMixingPolicy::None) { return {}; }
213  return config.identity() + "\ndiffusion=two-point-low-host-high-group-fct-v1";
214 }

Referenced by particle_mixing_schema(), ERF::ReadCheckpointFile(), and ERF::WriteCheckpointFile().

Here is the caller graph for this function:

◆ particle_mixing_schema() [2/3]

std::string erf_sbm::particle_mixing_schema ( const ParticleMixingConfig &  config,
const SBMPhysicalBoundaryConfig &  boundaries 
)

As above, followed with a line of the diffusive semantics of every face that is neither periodic nor a wall, when there is one.

219 {
220  std::string schema = particle_mixing_schema(config);
221  if (schema.empty() || !boundaries.has_inflow_or_outflow_face()) { return schema; }
222  schema += "\nboundary-diffusion=open-faces-v1";
223  for (const int face : {0, 3, 1, 4, 2, 5}) {
224  const auto kind = boundaries.kind[static_cast<std::size_t>(face)];
225  if (kind == AdvectionFaceKind::Periodic || kind == AdvectionFaceKind::ImpermeableWall) {
226  continue;
227  }
228  schema += std::string(";") + face_name(face) + '=' +
229  diffusion_face_kind_name(boundaries.diffusion[static_cast<std::size_t>(face)]);
230  }
231  return schema;
232 }
std::string particle_mixing_schema(const ParticleMixingConfig &config, const SBMPhysicalBoundaryConfig &boundaries, const erf_auxiliary::DiffusionMesh mesh)
Definition: ERF_SBMParticleMixing.cpp:235
const char * face_name(const int face) noexcept
Definition: ERF_SBMPhysicalBoundary.cpp:70
const char * diffusion_face_kind_name(const erf_auxiliary::DiffusionFaceKind kind) noexcept
Definition: ERF_SBMPhysicalBoundary.cpp:90
Here is the call graph for this function:

◆ particle_mixing_schema() [3/3]

std::string erf_sbm::particle_mixing_schema ( const ParticleMixingConfig &  config,
const SBMPhysicalBoundaryConfig &  boundaries,
erf_auxiliary::DiffusionMesh  mesh 
)

As particle_mixing_schema with boundaries, for the mixing mesh: a terrain-fitted (VariableDz) mesh adds a line naming its operator and boundary policy; every other mesh leaves the schema unchanged.

238 {
239  std::string schema = particle_mixing_schema(config, boundaries);
240  if (schema.empty() || mesh != erf_auxiliary::DiffusionMesh::VariableDz) { return schema; }
241  return schema + "\nterrain-diffusion=diagonal-low-matched-native-high-v1;"
242  "walls=complete-mapped-closure,quadratic-height-ghosts;"
243  "sides=face-trace";
244 }
Here is the call graph for this function:

◆ plan_packet_routing()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE PacketRoutingPlan erf_sbm::plan_packet_routing ( const PopulationRemapView  population,
const amrex::Real  packet_number,
const amrex::Real  particle_mass 
)
noexcept

Classify one packet without allocation or state mutation. Two-moment routing uses half-open intervals, includes the global top edge, and admits only four representable steps of outer-boundary roundoff. The plan keeps the original packet mass while its destination records the exact boundary mass. The immutable metadata must have been fully qualified once before this call; the per-packet path performs only constant-time context checks and a logarithmic interval search.

510 {
511  PacketRoutingPlan plan;
512  plan.population = population;
513  plan.packet_number = packet_number;
514  plan.packet_particle_mass = particle_mass;
515  if (!valid_population_remap_context(population) ||
516  !amrex::Math::isfinite(packet_number) || !amrex::Math::isfinite(particle_mass) ||
517  packet_number < amrex::Real(0.0) || particle_mass < amrex::Real(0.0)) {
518  return plan;
519  }
520  if (packet_number == amrex::Real(0.0)) {
521  plan.status = RemapStatus::Ok;
522  return plan;
523  }
524 
525  if (population.moment_mode == MomentMode::TwoMoment) {
526  // A dry positive-number packet is residual material, not a populated
527  // zero-water liquid interval, even when the first edge is exactly zero.
528  if (particle_mass == amrex::Real(0.0)) {
529  plan.status = RemapStatus::ZeroWaterResidual;
530  plan.residual_number_weight = amrex::Real(1.0);
531  return plan;
532  }
533  if (particle_mass < population.edges[0]) {
535  particle_mass, population.edges[0], true)) {
536  plan.status = RemapStatus::BelowSupportedGrid;
537  return plan;
538  }
539  plan.status = RemapStatus::Ok;
540  plan.destination_count = 1;
541  plan.destinations[0] = {0, amrex::Real(1.0), population.edges[0]};
542  plan.normalized_roundoff = true;
543  return plan;
544  }
545  if (particle_mass > population.edges[population.nbins]) {
547  particle_mass, population.edges[population.nbins], false)) {
548  plan.status = RemapStatus::Overflow;
549  return plan;
550  }
551  plan.status = RemapStatus::Ok;
552  plan.destination_count = 1;
553  plan.destinations[0] = {population.nbins - 1, amrex::Real(1.0),
554  population.edges[population.nbins]};
555  plan.normalized_roundoff = true;
556  return plan;
557  }
558  const int bin = particle_mass == population.edges[population.nbins] ?
559  population.nbins - 1 :
560  amrex::bisect(population.edges, 0, population.nbins, particle_mass);
561  plan.status = RemapStatus::Ok;
562  plan.destination_count = 1;
563  plan.destinations[0] = {bin, amrex::Real(1.0), particle_mass};
564  return plan;
565  }
566 
567  if (particle_mass == amrex::Real(0.0)) {
568  plan.status = RemapStatus::ZeroWaterResidual;
569  plan.residual_number_weight = amrex::Real(1.0);
570  return plan;
571  }
572  if (particle_mass < population.pivots[0]) {
573  amrex::Real wet_weight = amrex::Real(0.0);
574  const auto quotient_status = remap_detail::checked_quotient(
575  particle_mass, population.pivots[0], wet_weight);
576  if (quotient_status != remap_detail::QuotientStatus::Ok) {
577  plan.status = remap_detail::remap_quotient_status(quotient_status);
578  return plan;
579  }
580  plan.status = RemapStatus::ZeroWaterResidual;
581  plan.destination_count = 1;
582  plan.destinations[0] = {0, wet_weight, population.pivots[0]};
583  plan.residual_number_weight = amrex::Real(1.0) - wet_weight;
584  return plan;
585  }
586  if (particle_mass > population.pivots[population.nbins - 1]) {
587  plan.status = RemapStatus::Overflow;
588  return plan;
589  }
590  const int lower_bin = particle_mass == population.pivots[population.nbins - 1] ?
591  population.nbins - 1 :
592  amrex::bisect(population.pivots, 0, population.nbins - 1, particle_mass);
593  if (particle_mass == population.pivots[lower_bin]) {
594  plan.status = RemapStatus::Ok;
595  plan.destination_count = 1;
596  plan.destinations[0] = {lower_bin, amrex::Real(1.0), population.pivots[lower_bin]};
597  return plan;
598  }
599  if (lower_bin + 1 < population.nbins) {
600  const amrex::Real lower = population.pivots[lower_bin];
601  const amrex::Real upper = population.pivots[lower_bin + 1];
602  const amrex::Real width = upper - lower;
603  amrex::Real lower_weight = amrex::Real(0.0);
604  amrex::Real upper_weight = amrex::Real(0.0);
605  const auto lower_status = remap_detail::checked_quotient(
606  upper - particle_mass, width, lower_weight);
607  const auto upper_status = remap_detail::checked_quotient(
608  particle_mass - lower, width, upper_weight);
609  if (lower_status != remap_detail::QuotientStatus::Ok ||
610  upper_status != remap_detail::QuotientStatus::Ok) {
611  const auto quotient_status =
612  lower_status != remap_detail::QuotientStatus::Ok ? lower_status : upper_status;
613  plan.status = remap_detail::remap_quotient_status(quotient_status);
614  return plan;
615  }
616  plan.status = RemapStatus::Ok;
617  plan.destination_count = 2;
618  plan.destinations[0] = {lower_bin, lower_weight, lower};
619  plan.destinations[1] = {lower_bin + 1, upper_weight, upper};
620  return plan;
621  }
622  return plan;
623 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool within_boundary_roundoff(const amrex::Real value, const amrex::Real endpoint, const bool lower_boundary) noexcept
Definition: ERF_SBMRemapping.H:220
Here is the call graph for this function:

◆ population_remap_view()

PopulationRemapView erf_sbm::population_remap_view ( const SBMLayout &  layout,
int  population_id 
)
noexcept

Host adapter building a stable view into the immutable SBMLayout.

10 {
11  const auto& populations = layout.populations();
12  const auto found = std::find_if(populations.begin(), populations.end(),
13  [population_id](const PopulationLayout& population) {
14  return population.population_id == population_id;
15  });
16  if (found == populations.end()) return {};
17 
18  PopulationRemapView view;
19  view.population_id = found->population_id;
20  view.moment_mode = found->moment_mode;
21  view.coordinate_kind = found->grid.coordinate_kind();
22  view.edges = found->grid.edges().data();
23  view.pivots = found->grid.pivots().data();
24  view.nbins = found->grid.nbins();
25  view.mass_offset = found->mass_offset;
26  view.number_offset = found->number_offset;
27  view.state_components = layout.ncomp();
28  view.property_component_offsets = found->property_component_offsets.data();
29  view.property_count = static_cast<int>(found->property_component_offsets.size());
30  // SBMLayout validates these immutable arrays and constructs the component
31  // offsets. This adapter is used on per-packet paths, so do not repeat the
32  // O(nbins + properties^2) full qualification here. Keep the full validator
33  // for arbitrary raw views; this layout-derived view needs only a constant-
34  // time context check before entering the device/core routines.
35  if (!valid_population_remap_context(view)) return {};
36  return view;
37 }

Referenced by apply_packet_routing(), authoritative_state_admissible(), erf_sbm::SBMStateAdmission::Impl::Impl(), project_reconstruction_bin(), reconstruct_bin(), erf_sbm::SBMTransport::SBMTransport(), and validate_fixture_initial_state_canonicality().

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

◆ project_reconstruction_bin()

bool erf_sbm::project_reconstruction_bin ( const SBMLayout &  layout,
const ReconstructionDelta &  reconstruction,
std::vector< amrex::Real > &  candidate_state 
)
128 {
129  const auto population = population_remap_view(layout, reconstruction.population_id);
130  ReconstructionDeltaView view;
131  view.population = population;
132  view.bin = reconstruction.bin;
133  view.empty = reconstruction.empty;
134  view.normalized_roundoff = reconstruction.normalized_roundoff;
135  view.number = reconstruction.number;
136  view.particle_mass = reconstruction.particle_mass;
137  view.property_per_particle = reconstruction.property_per_particle.data();
138  view.property_count = static_cast<int>(reconstruction.property_per_particle.size());
139  return project_reconstruction_bin_core(population, view, candidate_state.data(),
140  static_cast<int>(candidate_state.size()));
141 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool project_reconstruction_bin_core(const PopulationRemapView population, const ReconstructionDeltaView reconstruction, amrex::Real *candidate_state, const int state_count) noexcept
Definition: ERF_SBMRemapping.H:1046
Here is the call graph for this function:

◆ project_reconstruction_bin_core()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool erf_sbm::project_reconstruction_bin_core ( const PopulationRemapView  population,
const ReconstructionDeltaView  reconstruction,
amrex::Real *  candidate_state,
const int  state_count 
)
noexcept

Project one reconstructed bin into caller-owned state after full validation.

1050 {
1051  if (!valid_population_remap_context(population) ||
1052  !same_population_context(population, reconstruction.population) ||
1053  reconstruction.bin < 0 || reconstruction.bin >= population.nbins ||
1054  candidate_state == nullptr || state_count != population.state_components ||
1055  reconstruction.property_count != population.property_count ||
1056  (reconstruction.property_count > 0 && reconstruction.property_per_particle == nullptr) ||
1057  !remap_detail::finite_nonnegative(reconstruction.number) ||
1058  !remap_detail::finite_nonnegative(reconstruction.particle_mass) ||
1059  (!reconstruction.empty && reconstruction.number <= amrex::Real(0.0)) ||
1060  (reconstruction.empty && (reconstruction.number != amrex::Real(0.0) ||
1061  reconstruction.particle_mass != amrex::Real(0.0)))) {
1062  return false;
1063  }
1064  if (!reconstruction.empty) {
1065  if (population.moment_mode == MomentMode::OneMoment) {
1066  if (reconstruction.particle_mass != population.pivots[reconstruction.bin]) return false;
1067  }
1068  }
1069  amrex::Real mass = amrex::Real(0.0);
1070  if (!remap_detail::finite_product(reconstruction.number,
1071  reconstruction.particle_mass, mass)) {
1072  return false;
1073  }
1074  amrex::Real projected_number = reconstruction.number;
1075  if (population.moment_mode == MomentMode::OneMoment) {
1077  mass, population.pivots[reconstruction.bin], projected_number) !=
1078  remap_detail::QuotientStatus::Ok) return false;
1080  population, reconstruction.bin, projected_number, mass)) {
1081  return false;
1082  }
1083  for (int property = 0; property < population.property_count; ++property) {
1084  const amrex::Real value = reconstruction.property_per_particle[property];
1085  amrex::Real amount = amrex::Real(0.0);
1086  if (!remap_detail::finite_nonnegative(value) ||
1087  (reconstruction.empty && value != amrex::Real(0.0)) ||
1088  !remap_detail::finite_product(reconstruction.number, value, amount)) {
1089  return false;
1090  }
1091  if (projected_number == amrex::Real(0.0)) {
1092  if (amount != amrex::Real(0.0)) return false;
1093  } else {
1094  amrex::Real per_particle = amrex::Real(0.0);
1096  amount, projected_number, per_particle) !=
1097  remap_detail::QuotientStatus::Ok) return false;
1098  }
1099  }
1100  const int bin = reconstruction.bin;
1101  candidate_state[population.mass_offset + bin] = mass;
1102  if (population.number_offset >= 0) {
1103  candidate_state[population.number_offset + bin] = reconstruction.number;
1104  }
1105  for (int property = 0; property < population.property_count; ++property) {
1106  candidate_state[population.property_component_offsets[property] + bin] =
1107  reconstruction.number * reconstruction.property_per_particle[property];
1108  }
1109  return true;
1110 }

Referenced by project_reconstruction_bin().

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

◆ prolong_carrier_relative_chunks()

static bool erf_sbm::prolong_carrier_relative_chunks ( const SBMLayout &  layout,
const SBMAMRStateView &  coarse,
const SBMAMRStateView &  fine_target,
const amrex::Geometry &  coarse_geometry,
const amrex::Geometry &  fine_geometry,
const amrex::IntVect &  ratio,
MultiFab &  work,
const int  max_groups_per_chunk,
const bool  reverse_chunk_order,
SBMTransferAllocationCensus *  allocation_census,
std::string &  diagnostic,
const MultiFab *  prolonged_mask = nullptr 
)
static
908 {
909  if (max_groups_per_chunk <= 0) {
910  diagnostic = "SBM prolongation chunk group limit must be positive";
911  return collective_all_true(false, diagnostic,
912  "SBM prolongation chunk group limit is invalid on another MPI rank",
913  diagnostic);
914  }
915  const auto chunks = make_constraint_closure_chunks(
916  layout, max_groups_per_chunk);
917  int max_chunk_components = 0;
918  for (const auto& chunk : chunks) {
919  max_chunk_components = std::max(
920  max_chunk_components, static_cast<int>(chunk.components.size()));
921  }
922  if (!collective_all_true(
923  max_chunk_components > 0,
924  "SBM prolongation layout has no complete semantic component groups",
925  "SBM prolongation layout has no complete semantic component groups on another MPI rank",
926  diagnostic)) {
927  return false;
928  }
929 
930  MultiFab coarse_z_chunk(coarse.spectrum->boxArray(),
931  coarse.spectrum->DistributionMap(),
932  max_chunk_components, 0);
933  MultiFab fine_z_chunk(work.boxArray(), work.DistributionMap(),
934  max_chunk_components, 0);
935  MultiFab coarse_invalid(coarse.spectrum->boxArray(),
936  coarse.spectrum->DistributionMap(), 1, 0);
937  MultiFab fine_invalid(work.boxArray(), work.DistributionMap(), 1, 0);
938  coarse_invalid.setVal(Real(0.0));
939  fine_invalid.setVal(Real(0.0));
940  // With a mask, only the parents of prolonged cells must form a ratio.
941  MultiFab parent_mask;
942  if (prolonged_mask != nullptr) {
943  parent_mask.define(coarse.spectrum->boxArray(),
944  coarse.spectrum->DistributionMap(), 1, 0);
945  parent_mask.setVal(Real(0.0));
946  amrex::average_down(*prolonged_mask, parent_mask, 0, 1, ratio);
947  }
948  if (allocation_census != nullptr) allocation_census->sample();
949 
950  amrex::Gpu::DeviceVector<int> device_components(
951  static_cast<std::size_t>(max_chunk_components));
952  amrex::PhysBCFunctNoOp no_physical_boundary;
953  for (std::size_t pass = 0; pass < chunks.size(); ++pass) {
954  const std::size_t chunk_index = reverse_chunk_order
955  ? chunks.size() - 1U - pass : pass;
956  const auto& chunk = chunks[chunk_index];
957  if (allocation_census != nullptr && !chunk.components.empty()) {
958  allocation_census->processed_chunk_first_components.push_back(
959  chunk.components.front());
960  }
961  const int chunk_components = static_cast<int>(chunk.components.size());
962  amrex::Gpu::copy(amrex::Gpu::hostToDevice, chunk.components.begin(),
963  chunk.components.end(), device_components.begin());
965  *coarse.spectrum, *coarse.dry_air_density,
966  coarse.density_component, chunk.components, device_components,
967  coarse_z_chunk, coarse_invalid,
968  prolonged_mask != nullptr ? &parent_mask : nullptr);
969 
970  amrex::Vector<amrex::BCRec> bcs(
971  static_cast<std::size_t>(chunk_components));
972  // Valid fine cells only: piecewise-constant prolongation reads the
973  // in-domain parent and never these records or a physical ghost.
974  for (auto& bc : bcs) {
975  for (int direction = 0; direction < AMREX_SPACEDIM; ++direction) {
976  const int type = fine_geometry.isPeriodic(direction)
978  bc.setLo(direction, type);
979  bc.setHi(direction, type);
980  }
981  }
982  amrex::InterpFromCoarseLevel(
983  fine_z_chunk, amrex::IntVect(0),
984  static_cast<Real>(coarse.spectrum_time), coarse_z_chunk, 0, 0,
985  chunk_components, coarse_geometry, fine_geometry,
986  no_physical_boundary, 0, no_physical_boundary, 0, ratio,
987  &amrex::pc_interp, bcs, 0);
989  fine_z_chunk, *fine_target.dry_air_density,
990  fine_target.density_component, *fine_target.mapped_measure,
991  fine_target.measure_component, chunk.components, device_components,
992  work, fine_invalid, prolonged_mask);
993  }
994 
995  const bool reconstructed_ok =
996  coarse_invalid.max(0, 0, true) <= Real(0.0) &&
997  fine_invalid.max(0, 0, true) <= Real(0.0);
998  return collective_all_true(
999  reconstructed_ok,
1000  "forming or reconstructing a chunked carrier-relative SBM state overflowed or underflowed",
1001  "forming or reconstructing a chunked carrier-relative SBM state failed on another MPI rank",
1002  diagnostic);
1003 }
@ foextrap
Definition: ERF_IndexDefines.H:316
@ int_dir
Definition: ERF_IndexDefines.H:314
bool form_carrier_relative_chunk(const MultiFab &spectrum, const MultiFab &density, const int density_component, const std::vector< int > &components, const amrex::Gpu::DeviceVector< int > &device_components, MultiFab &intensive, MultiFab &invalid, const MultiFab *used_mask)
Definition: ERF_SBMAMRTransfer.cpp:225
bool reconstruct_carrier_relative_chunk(const MultiFab &intensive, const MultiFab &density, const int density_component, const MultiFab &measure, const int measure_component, const std::vector< int > &components, const amrex::Gpu::DeviceVector< int > &device_components, MultiFab &candidate, MultiFab &invalid, const MultiFab *used_mask)
Definition: ERF_SBMAMRTransfer.cpp:259
std::vector< ConstraintClosureChunk > make_constraint_closure_chunks(const SBMLayout &layout, const int max_groups)
Definition: ERF_SBMConstraintGroups.cpp:257

Referenced by prolong_carrier_relative_spectrum_impl(), and RemapRegriddedSpectrumPrivate().

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

◆ prolong_carrier_relative_spectrum_impl()

static bool erf_sbm::prolong_carrier_relative_spectrum_impl ( const SBMLayout &  layout,
const SBMAMRStateView &  coarse,
const SBMAMRStateView &  fine_target,
const amrex::Geometry &  coarse_geometry,
const amrex::Geometry &  fine_geometry,
const amrex::IntVect &  ratio,
const int  fine_level,
MultiFab &  fine_candidate,
const bool  candidate_is_private,
const int  max_groups_per_chunk,
const bool  reverse_chunk_order,
const SBMStateAdmission *  admission,
SBMTransferAllocationCensus *  allocation_census,
std::string &  diagnostic 
)
static
1016 {
1017  diagnostic.clear();
1018  if (allocation_census != nullptr) allocation_census->begin();
1019  std::string ratio_diagnostic;
1020  const bool ratio_ok = valid_ratio(ratio, ratio_diagnostic);
1021  const bool level_ok = fine_level > 0;
1022 
1023  std::string coarse_structure_diagnostic;
1024  std::string fine_structure_diagnostic;
1025  const bool coarse_structure_ok = validate_view_structure(
1026  coarse, layout, "coarse", coarse_structure_diagnostic);
1027  const bool fine_structure_ok = validate_view_structure(
1028  fine_target, layout, "fine target", fine_structure_diagnostic);
1029  const bool same_time = semantic_time_matches_exact(coarse.spectrum_time,
1030  fine_target.spectrum_time);
1031  const bool local_structure_ok = ratio_ok && level_ok && coarse_structure_ok &&
1032  fine_structure_ok && same_time;
1033  const std::string structure_diagnostic =
1034  !ratio_ok ? ratio_diagnostic
1035  : !level_ok ? "prolongation fine level must be greater than zero"
1036  : !coarse_structure_ok ? coarse_structure_diagnostic
1037  : !fine_structure_ok ? fine_structure_diagnostic
1038  : !same_time ? "prolongation requires same-time source and target tuples"
1039  : std::string{};
1040  if (!collective_all_true(
1041  local_structure_ok, structure_diagnostic,
1042  "SBM prolongation input tuple is invalid on another MPI rank",
1043  diagnostic)) {
1044  return false;
1045  }
1046 
1047  const bool candidate_layout_ok =
1048  fine_candidate.nComp() == layout.ncomp() &&
1049  erf_auxiliary::SameCellLayout(fine_candidate, *fine_target.spectrum);
1050  const bool separate_from_coarse = candidate_is_separate(fine_candidate, coarse);
1051  const bool separate_from_fine_target =
1052  candidate_is_separate(fine_candidate, fine_target);
1053  bool local_candidate_ok = candidate_layout_ok && separate_from_coarse &&
1054  separate_from_fine_target;
1055  std::string local_candidate_diagnostic =
1056  "prolongation candidate must be separate from both input tuples and match the fine SBM layout";
1057  if (local_candidate_ok) {
1058  for (int direction = 0; direction < AMREX_SPACEDIM; ++direction) {
1059  if (coarse_geometry.isPeriodic(direction) !=
1060  fine_geometry.isPeriodic(direction)) {
1061  local_candidate_ok = false;
1062  local_candidate_diagnostic =
1063  "carrier-relative prolongation requires matching coarse and "
1064  "fine periodicity";
1065  break;
1066  }
1067  }
1068  }
1069  if (local_candidate_ok) {
1070  amrex::Box refined_coarse_domain = coarse_geometry.Domain();
1071  refined_coarse_domain.refine(ratio);
1072  if (refined_coarse_domain != fine_geometry.Domain()) {
1073  local_candidate_ok = false;
1074  local_candidate_diagnostic =
1075  "prolongation refinement ratio does not map the coarse domain "
1076  "to the fine domain";
1077  }
1078  }
1079  if (!collective_all_true(
1080  local_candidate_ok, local_candidate_diagnostic,
1081  "SBM prolongation candidate or geometry is invalid on another MPI rank",
1082  diagnostic)) {
1083  return false;
1084  }
1085 
1086  std::string coarse_carrier_diagnostic;
1087  std::string fine_carrier_diagnostic;
1088  const bool coarse_carriers_ok = validate_view_carriers(
1089  coarse, "coarse", coarse_carrier_diagnostic);
1090  const bool fine_carriers_ok = validate_view_carriers(
1091  fine_target, "fine target", fine_carrier_diagnostic);
1092  std::string coarse_spectrum_diagnostic;
1093  const bool coarse_spectrum_ok = validate_view_spectrum(
1094  coarse, layout, fine_level - 1, admission, "coarse",
1095  coarse_spectrum_diagnostic);
1096  const bool local_sources_ok = coarse_carriers_ok && fine_carriers_ok &&
1097  coarse_spectrum_ok;
1098  const std::string source_diagnostic =
1099  !coarse_carriers_ok ? coarse_carrier_diagnostic
1100  : !fine_carriers_ok ? fine_carrier_diagnostic
1101  : !coarse_spectrum_ok ? coarse_spectrum_diagnostic
1102  : std::string{};
1103  if (!collective_all_true(
1104  local_sources_ok, source_diagnostic,
1105  "SBM prolongation source is inadmissible on another MPI rank",
1106  diagnostic)) {
1107  return false;
1108  }
1109 
1110  if (!validate_mapped_carrier_inventory(coarse, fine_target, ratio,
1111  allocation_census,
1112  diagnostic)) {
1113  return false;
1114  }
1115 
1116  MultiFab private_candidate;
1117  MultiFab* work = &fine_candidate;
1118  if (!candidate_is_private) {
1119  private_candidate.define(fine_target.spectrum->boxArray(),
1120  fine_target.spectrum->DistributionMap(),
1121  layout.ncomp(), 0);
1122  work = &private_candidate;
1123  }
1125  layout, coarse, fine_target, coarse_geometry, fine_geometry,
1126  ratio, *work, max_groups_per_chunk, reverse_chunk_order,
1127  allocation_census, diagnostic)) {
1128  return false;
1129  }
1130 
1131  std::string candidate_admission_diagnostic;
1132  const bool candidate_admissible = admission != nullptr
1133  ? admission->admissible(*work, fine_level,
1134  candidate_admission_diagnostic)
1135  : authoritative_state_admissible(*work, layout, fine_level,
1136  &candidate_admission_diagnostic);
1137  const bool local_candidate_admissible = candidate_admissible;
1138  const std::string candidate_diagnostic = !candidate_admissible
1139  ? "prolonged SBM candidate is inadmissible: " +
1140  candidate_admission_diagnostic
1141  : std::string{};
1142  if (!collective_all_true(
1143  local_candidate_admissible, candidate_diagnostic,
1144  "prolonged SBM candidate is inadmissible on another MPI rank",
1145  diagnostic)) {
1146  return false;
1147  }
1148  if (!candidate_is_private) {
1149  MultiFab::Copy(fine_candidate, *work, 0, 0, layout.ncomp(), 0);
1150  }
1151  return true;
1152 }
bool SameCellLayout(const amrex::MultiFab &lhs, const amrex::MultiFab &rhs)
Definition: ERF_AuxiliaryMappedTransport.cpp:33
bool validate_view_structure(const SBMAMRStateView &view, const SBMLayout &layout, const char *label, std::string &diagnostic)
Definition: ERF_SBMAMRTransfer.cpp:63
bool valid_ratio(const amrex::IntVect &ratio, std::string &diagnostic)
Definition: ERF_SBMAMRTransfer.cpp:136
bool validate_view_spectrum(const SBMAMRStateView &view, const SBMLayout &layout, const int level, const SBMStateAdmission *admission, const char *label, std::string &diagnostic)
Definition: ERF_SBMAMRTransfer.cpp:119
bool validate_view_carriers(const SBMAMRStateView &view, const char *label, std::string &diagnostic)
Definition: ERF_SBMAMRTransfer.cpp:96
bool validate_mapped_carrier_inventory(const SBMAMRStateView &coarse, const SBMAMRStateView &fine, const amrex::IntVect &ratio, SBMTransferAllocationCensus *allocation_census, std::string &diagnostic, const MultiFab *prolonged_mask=nullptr)
Definition: ERF_SBMAMRTransfer.cpp:302
bool candidate_is_separate(const MultiFab &candidate, const SBMAMRStateView &view)
Definition: ERF_SBMAMRTransfer.cpp:456
static bool prolong_carrier_relative_chunks(const SBMLayout &layout, const SBMAMRStateView &coarse, const SBMAMRStateView &fine_target, const amrex::Geometry &coarse_geometry, const amrex::Geometry &fine_geometry, const amrex::IntVect &ratio, MultiFab &work, const int max_groups_per_chunk, const bool reverse_chunk_order, SBMTransferAllocationCensus *allocation_census, std::string &diagnostic, const MultiFab *prolonged_mask=nullptr)
Definition: ERF_SBMAMRTransfer.cpp:898
bool authoritative_state_admissible(const amrex::MultiFab &spectrum, const SBMLayout &layout, const int level, std::string *diagnostic)
Definition: ERF_SBMRestart.cpp:277

Referenced by ProlongCarrierRelativeSpectrum(), and ProlongCarrierRelativeSpectrumPrivate().

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

◆ ProlongCarrierRelativeSpectrum() [1/2]

bool erf_sbm::ProlongCarrierRelativeSpectrum ( const SBMLayout &  layout,
const SBMAMRStateView &  coarse,
const SBMAMRStateView &  fine_target,
const amrex::Geometry &  coarse_geometry,
const amrex::Geometry &  fine_geometry,
const amrex::IntVect &  ratio,
const int  fine_level,
MultiFab &  fine_candidate,
std::string &  diagnostic,
const int  max_groups_per_chunk,
const bool  reverse_chunk_order,
const SBMStateAdmission *  admission,
SBMTransferAllocationCensus *  allocation_census 
)
1167 {
1169  layout, coarse, fine_target, coarse_geometry, fine_geometry, ratio,
1170  fine_level, fine_candidate, false, max_groups_per_chunk,
1171  reverse_chunk_order, admission, allocation_census, diagnostic);
1172 }
static bool prolong_carrier_relative_spectrum_impl(const SBMLayout &layout, const SBMAMRStateView &coarse, const SBMAMRStateView &fine_target, const amrex::Geometry &coarse_geometry, const amrex::Geometry &fine_geometry, const amrex::IntVect &ratio, const int fine_level, MultiFab &fine_candidate, const bool candidate_is_private, const int max_groups_per_chunk, const bool reverse_chunk_order, const SBMStateAdmission *admission, SBMTransferAllocationCensus *allocation_census, std::string &diagnostic)
Definition: ERF_SBMAMRTransfer.cpp:1005
Here is the call graph for this function:

◆ ProlongCarrierRelativeSpectrum() [2/2]

bool erf_sbm::ProlongCarrierRelativeSpectrum ( const SBMLayout &  layout,
const SBMAMRStateView &  coarse,
const SBMAMRStateView &  fine_target,
const amrex::Geometry &  coarse_geometry,
const amrex::Geometry &  fine_geometry,
const amrex::IntVect &  ratio,
int  fine_level,
amrex::MultiFab &  fine_candidate,
std::string &  diagnostic,
int  max_groups_per_chunk = 16,
bool  reverse_chunk_order = false,
const SBMStateAdmission *  admission = nullptr,
SBMTransferAllocationCensus *  allocation_census = nullptr 
)

Form a same-time piecewise-constant carrier-relative fine candidate. On success, overwrite the destination's valid cells with the complete, admitted result. On failure (including a rejection on another MPI rank), leave every destination valid cell and all source views unchanged. This operator does not itself commit authoritative SBM state.

◆ ProlongCarrierRelativeSpectrumPrivate() [1/2]

bool erf_sbm::ProlongCarrierRelativeSpectrumPrivate ( const SBMLayout &  layout,
const SBMAMRStateView &  coarse,
const SBMAMRStateView &  fine_target,
const amrex::Geometry &  coarse_geometry,
const amrex::Geometry &  fine_geometry,
const amrex::IntVect &  ratio,
const int  fine_level,
MultiFab &  private_candidate,
std::string &  diagnostic,
const int  max_groups_per_chunk,
const bool  reverse_chunk_order,
const SBMStateAdmission *  admission,
SBMTransferAllocationCensus *  allocation_census 
)
1184 {
1186  layout, coarse, fine_target, coarse_geometry, fine_geometry, ratio,
1187  fine_level, private_candidate, true, max_groups_per_chunk,
1188  reverse_chunk_order, admission, allocation_census, diagnostic);
1189 }

Referenced by ERF::init_sbm_level_from_coarse().

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

◆ ProlongCarrierRelativeSpectrumPrivate() [2/2]

bool erf_sbm::ProlongCarrierRelativeSpectrumPrivate ( const SBMLayout &  layout,
const SBMAMRStateView &  coarse,
const SBMAMRStateView &  fine_target,
const amrex::Geometry &  coarse_geometry,
const amrex::Geometry &  fine_geometry,
const amrex::IntVect &  ratio,
int  fine_level,
amrex::MultiFab &  private_candidate,
std::string &  diagnostic,
int  max_groups_per_chunk = 16,
bool  reverse_chunk_order = false,
const SBMStateAdmission *  admission = nullptr,
SBMTransferAllocationCensus *  allocation_census = nullptr 
)

Private-candidate prolongation for a new level. The caller supplies the one unpublished full fine spectrum; it may be overwritten on failure. Intensive interpolation scratch remains bounded by complete constraint-group chunks.

◆ property_support_is_admissible()

bool erf_sbm::property_support_is_admissible ( amrex::Real  property,
amrex::Real  carrier_number,
amrex::Real  lower,
amrex::Real  upper,
amrex::Real  tolerance = 0.0 
)
noexcept

Host reference for the finite property-support constraints.

297 {
298  if (!finite(property) || !finite(carrier_number) || !finite(lower) || !finite(upper) ||
299  carrier_number < amrex::Real(0.0) || lower < amrex::Real(0.0) || upper < lower) return false;
300  if (carrier_number == amrex::Real(0.0)) {
301  return std::abs(property) <= tolerance;
302  }
303  return property >= lower * carrier_number - tolerance &&
304  property <= upper * carrier_number + tolerance;
305 }
Here is the call graph for this function:

◆ reconstruct_bin()

ReconstructionStatus erf_sbm::reconstruct_bin ( const SBMLayout &  layout,
const int  population_id,
const int  bin,
const std::vector< amrex::Real > &  persisted_state,
ReconstructionDelta &  reconstruction 
)
75 {
76  const auto population = population_remap_view(layout, population_id);
77  std::vector<amrex::Real> properties(
78  population.property_count >= 0 ? static_cast<std::size_t>(population.property_count) : 0u,
79  amrex::Real(0.0));
80  ReconstructionDeltaView view;
81  const auto status = reconstruct_bin_core(
82  population, bin, persisted_state.data(), static_cast<int>(persisted_state.size()),
83  properties.data(), static_cast<int>(properties.size()), view);
84  if (status == ReconstructionStatus::Invalid) return status;
85 
86  ReconstructionDelta next;
87  next.population_id = population_id;
88  next.bin = bin;
89  next.empty = view.empty;
90  next.normalized_roundoff = view.normalized_roundoff;
91  next.number = view.number;
92  next.particle_mass = view.particle_mass;
93  next.property_per_particle = std::move(properties);
94  reconstruction = std::move(next);
95  return status;
96 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE ReconstructionStatus reconstruct_bin_core(const PopulationRemapView population, const int bin, const amrex::Real *persisted_state, const int state_count, amrex::Real *property_per_particle, const int property_capacity, ReconstructionDeltaView &reconstruction) noexcept
Definition: ERF_SBMRemapping.H:898
Here is the call graph for this function:

◆ reconstruct_bin_core()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE ReconstructionStatus erf_sbm::reconstruct_bin_core ( const PopulationRemapView  population,
const int  bin,
const amrex::Real *  persisted_state,
const int  state_count,
amrex::Real *  property_per_particle,
const int  property_capacity,
ReconstructionDeltaView &  reconstruction 
)
noexcept
903 {
904  if (!valid_population_remap_context(population) || bin < 0 || bin >= population.nbins ||
905  persisted_state == nullptr || state_count != population.state_components ||
906  property_capacity < population.property_count ||
907  (population.property_count > 0 && property_per_particle == nullptr)) {
908  return ReconstructionStatus::Invalid;
909  }
911  population, bin, persisted_state, state_count)) {
912  return ReconstructionStatus::Invalid;
913  }
914  const amrex::Real mass = persisted_state[population.mass_offset + bin];
915  if (!remap_detail::finite_nonnegative(mass)) return ReconstructionStatus::Invalid;
916  ReconstructionDeltaView next;
917  next.population = population;
918  next.bin = bin;
919  next.property_per_particle = property_per_particle;
920  next.property_count = population.property_count;
921  if (population.moment_mode == MomentMode::OneMoment) {
922  next.particle_mass = population.pivots[bin];
924  mass, next.particle_mass, next.number) != remap_detail::QuotientStatus::Ok) {
925  return ReconstructionStatus::Invalid;
926  }
927  } else {
928  const amrex::Real number = persisted_state[population.number_offset + bin];
929  if (!remap_detail::finite_nonnegative(number)) return ReconstructionStatus::Invalid;
931  population, bin, persisted_state, state_count)) {
932  return ReconstructionStatus::Invalid;
933  }
934  const amrex::Real lower = population.edges[bin];
935  const amrex::Real upper = population.edges[bin + 1];
936  EndpointTransform endpoints;
937  if (!try_two_moment_to_endpoints(number, mass, lower, upper, endpoints)) {
938  return ReconstructionStatus::Invalid;
939  }
940  next.number = number;
941  // Endpoint tolerance is only a realizability aid for the transform.
942  // Persisted state has already passed strict canonical ownership and is
943  // never normalized by no-process reconstruction.
944  next.normalized_roundoff = false;
945  if (number > amrex::Real(0.0)) {
947  mass, number, next.particle_mass) != remap_detail::QuotientStatus::Ok) {
948  return ReconstructionStatus::Invalid;
949  }
950  }
951  }
952  next.empty = next.number == amrex::Real(0.0);
953  if (next.empty) next.particle_mass = amrex::Real(0.0);
954  for (int property = 0; property < population.property_count; ++property) {
955  const amrex::Real amount = persisted_state[
956  population.property_component_offsets[property] + bin];
957  if (!remap_detail::finite_nonnegative(amount)) return ReconstructionStatus::Invalid;
958  if (next.empty) {
959  if (amount != amrex::Real(0.0)) return ReconstructionStatus::Invalid;
960  } else {
961  amrex::Real per_particle = amrex::Real(0.0);
963  amount, next.number, per_particle) != remap_detail::QuotientStatus::Ok) {
964  return ReconstructionStatus::Invalid;
965  }
966  }
967  }
968  for (int property = 0; property < population.property_count; ++property) {
969  const amrex::Real amount = persisted_state[
970  population.property_component_offsets[property] + bin];
971  if (next.empty) {
972  property_per_particle[property] = amrex::Real(0.0);
974  amount, next.number, property_per_particle[property]) !=
975  remap_detail::QuotientStatus::Ok) {
976  return ReconstructionStatus::Invalid;
977  }
978  }
979  reconstruction = next;
980  return next.empty ? ReconstructionStatus::Empty : ReconstructionStatus::Populated;
981 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool canonical_two_moment_bin_state(const PopulationRemapView &population, const int bin, const RemapCellStateView &state, const int state_count) noexcept
Definition: ERF_SBMRemapping.H:416
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool canonical_persisted_bin_state(const PopulationRemapView &population, const int bin, const RemapCellStateView &state, const int state_count) noexcept
Definition: ERF_SBMRemapping.H:485
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool try_two_moment_to_endpoints(const amrex::Real C, const amrex::Real M, const amrex::Real lower, const amrex::Real upper, EndpointTransform &result) noexcept
Definition: ERF_SpectralGrid.H:48

Referenced by reconstruct_bin().

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

◆ RemapRegriddedSpectrumPrivate() [1/2]

bool erf_sbm::RemapRegriddedSpectrumPrivate ( const SBMLayout &  layout,
const SBMAMRStateView &  coarse,
const amrex::MultiFab &  retained_spectrum,
const amrex::MultiFab &  fine_density,
int  density_component,
const amrex::MultiFab &  fine_measure,
int  measure_component,
double  semantic_time,
const amrex::Geometry &  coarse_geometry,
const amrex::Geometry &  fine_geometry,
const amrex::IntVect &  ratio,
int  fine_level,
amrex::MultiFab &  private_candidate,
std::string &  diagnostic,
int  max_groups_per_chunk = 16,
const SBMStateAdmission *  coarse_admission = nullptr,
const SBMStateAdmission *  fine_admission = nullptr,
SBMTransferAllocationCensus *  allocation_census = nullptr 
)

Private candidate for a fine level remade on new grids at a synchronized instant. Cells the retained old-grid spectrum covers keep its values bitwise; every other cell takes the same-time carrier-relative prolongation of its parent. The new-grid density and measure, the retained spectrum, and the coarse tuple must all carry semantic_time. Every parent of the new grids must satisfy the mapped carrier identity and the complete candidate must be admissible. Inputs are never modified; the candidate may be overwritten on failure.

◆ RemapRegriddedSpectrumPrivate() [2/2]

bool erf_sbm::RemapRegriddedSpectrumPrivate ( const SBMLayout &  layout,
const SBMAMRStateView &  coarse,
const MultiFab &  retained_spectrum,
const MultiFab &  fine_density,
const int  density_component,
const MultiFab &  fine_measure,
const int  measure_component,
const double  semantic_time,
const amrex::Geometry &  coarse_geometry,
const amrex::Geometry &  fine_geometry,
const amrex::IntVect &  ratio,
const int  fine_level,
MultiFab &  private_candidate,
std::string &  diagnostic,
const int  max_groups_per_chunk,
const SBMStateAdmission *  coarse_admission,
const SBMStateAdmission *  fine_admission,
SBMTransferAllocationCensus *  allocation_census 
)
1220 {
1221  diagnostic.clear();
1222  if (allocation_census != nullptr) allocation_census->begin();
1223  // The candidate supplies the new-grid layout; it is never read.
1224  const SBMAMRStateView fine_target{
1225  &private_candidate, semantic_time, &fine_density, density_component,
1226  semantic_time, &fine_measure, measure_component, semantic_time};
1227  const SBMAMRStateView retained{
1228  &retained_spectrum, semantic_time, &fine_density, density_component,
1229  semantic_time, &fine_measure, measure_component, semantic_time};
1230 
1231  std::string ratio_diagnostic;
1232  const bool ratio_ok = valid_ratio(ratio, ratio_diagnostic);
1233  const bool level_ok = fine_level > 0;
1234  std::string coarse_structure_diagnostic;
1235  std::string fine_structure_diagnostic;
1236  const bool coarse_structure_ok = validate_view_structure(
1237  coarse, layout, "coarse", coarse_structure_diagnostic);
1238  const bool fine_structure_ok = validate_view_structure(
1239  fine_target, layout, "regrid target", fine_structure_diagnostic);
1240  const bool same_time = semantic_time_matches_exact(coarse.spectrum_time,
1241  semantic_time);
1242  const bool retained_ok = retained_spectrum.ok() &&
1243  retained_spectrum.nComp() == layout.ncomp();
1244  const bool local_structure_ok = ratio_ok && level_ok && coarse_structure_ok &&
1245  fine_structure_ok && same_time && retained_ok;
1246  const std::string structure_diagnostic =
1247  !ratio_ok ? ratio_diagnostic
1248  : !level_ok ? "regrid fine level must be greater than zero"
1249  : !coarse_structure_ok ? coarse_structure_diagnostic
1250  : !fine_structure_ok ? fine_structure_diagnostic
1251  : !same_time ? "regrid requires same-time coarse and fine tuples"
1252  : !retained_ok ? "retained regrid spectrum does not match the SBM layout"
1253  : std::string{};
1254  if (!collective_all_true(
1255  local_structure_ok, structure_diagnostic,
1256  "SBM regrid input tuple is invalid on another MPI rank",
1257  diagnostic)) {
1258  return false;
1259  }
1260 
1261  bool local_candidate_ok = candidate_is_separate(private_candidate, coarse) &&
1262  candidate_is_separate(private_candidate, retained);
1263  std::string local_candidate_diagnostic =
1264  "regrid candidate must be separate from the coarse, retained, and carrier inputs";
1265  if (local_candidate_ok) {
1266  for (int direction = 0; direction < AMREX_SPACEDIM; ++direction) {
1267  if (coarse_geometry.isPeriodic(direction) !=
1268  fine_geometry.isPeriodic(direction)) {
1269  local_candidate_ok = false;
1270  local_candidate_diagnostic =
1271  "carrier-relative regrid requires matching coarse and fine "
1272  "periodicity";
1273  break;
1274  }
1275  }
1276  }
1277  if (local_candidate_ok) {
1278  amrex::Box refined_coarse_domain = coarse_geometry.Domain();
1279  refined_coarse_domain.refine(ratio);
1280  if (refined_coarse_domain != fine_geometry.Domain() ||
1281  (!retained_spectrum.boxArray().empty() &&
1282  !fine_geometry.Domain().contains(
1283  retained_spectrum.boxArray().minimalBox()))) {
1284  local_candidate_ok = false;
1285  local_candidate_diagnostic =
1286  "regrid refinement ratio or retained grids do not match the fine domain";
1287  }
1288  }
1289  if (!collective_all_true(
1290  local_candidate_ok, local_candidate_diagnostic,
1291  "SBM regrid candidate or geometry is invalid on another MPI rank",
1292  diagnostic)) {
1293  return false;
1294  }
1295 
1296  std::string coarse_carrier_diagnostic;
1297  std::string fine_carrier_diagnostic;
1298  const bool coarse_carriers_ok = validate_view_carriers(
1299  coarse, "coarse", coarse_carrier_diagnostic);
1300  const bool fine_carriers_ok = validate_view_carriers(
1301  fine_target, "regrid target", fine_carrier_diagnostic);
1302  std::string coarse_spectrum_diagnostic;
1303  const bool coarse_spectrum_ok = validate_view_spectrum(
1304  coarse, layout, fine_level - 1, coarse_admission, "coarse",
1305  coarse_spectrum_diagnostic);
1306  const bool local_sources_ok = coarse_carriers_ok && fine_carriers_ok &&
1307  coarse_spectrum_ok;
1308  const std::string source_diagnostic =
1309  !coarse_carriers_ok ? coarse_carrier_diagnostic
1310  : !fine_carriers_ok ? fine_carrier_diagnostic
1311  : !coarse_spectrum_ok ? coarse_spectrum_diagnostic
1312  : std::string{};
1313  if (!collective_all_true(
1314  local_sources_ok, source_diagnostic,
1315  "SBM regrid source is inadmissible on another MPI rank",
1316  diagnostic)) {
1317  return false;
1318  }
1319 
1320  // Retained cells are copied, so only newly covered cells and their parents
1321  // are prolonged and checked.
1322  MultiFab prolonged_mask(private_candidate.boxArray(),
1323  private_candidate.DistributionMap(), 1, 0);
1324  prolonged_mask.setVal(Real(1.0));
1325  const amrex::BoxArray& retained_grids = retained_spectrum.boxArray();
1326  if (!retained_grids.empty()) {
1327  for (amrex::MFIter mfi(prolonged_mask); mfi.isValid(); ++mfi) {
1328  const auto mask = prolonged_mask.array(mfi);
1329  for (const auto& overlap : retained_grids.intersections(mfi.validbox())) {
1330  amrex::ParallelFor(overlap.second,
1331  [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
1332  mask(i, j, k, 0) = Real(0.0);
1333  });
1334  }
1335  }
1336  }
1337  if (!validate_mapped_carrier_inventory(coarse, fine_target, ratio,
1338  allocation_census, diagnostic,
1339  &prolonged_mask)) {
1340  return false;
1341  }
1343  layout, coarse, fine_target, coarse_geometry, fine_geometry,
1344  ratio, private_candidate, max_groups_per_chunk, false,
1345  allocation_census, diagnostic, &prolonged_mask)) {
1346  return false;
1347  }
1348  private_candidate.ParallelCopy(retained_spectrum, 0, 0, layout.ncomp());
1349 
1350  std::string candidate_admission_diagnostic;
1351  const bool candidate_admissible = fine_admission != nullptr
1352  ? fine_admission->admissible(private_candidate, fine_level,
1353  candidate_admission_diagnostic)
1354  : authoritative_state_admissible(private_candidate, layout, fine_level,
1355  &candidate_admission_diagnostic);
1356  return collective_all_true(
1357  candidate_admissible,
1358  candidate_admissible ? std::string{}
1359  : "regridded SBM candidate is inadmissible: " +
1360  candidate_admission_diagnostic,
1361  "regridded SBM candidate is inadmissible on another MPI rank",
1362  diagnostic);
1363 }

Referenced by ERF::remake_sbm_level().

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

◆ representation_identity()

constexpr RepresentationIdentity erf_sbm::representation_identity ( const MomentMode  mode)
constexprnoexcept
17 {
18  switch (mode) {
19  case MomentMode::OneMoment:
20  return {"fixed-pivot-1m-v1", "fixed-pivot-delta-v1", "fixed-pivot-two-center-v1"};
21  case MomentMode::TwoMoment:
22  return {"interval-2m-v1", "mean-delta-2m-v1", "actual-mass-interval-v1"};
23  }
24  return {"invalid-representation", "invalid-reconstruction", "invalid-packet-remap"};
25 }

Referenced by erf_sbm::SBMLayout::inspection(), and erf_sbm::SBMLayout::SBMLayout().

Here is the caller graph for this function:

◆ require_host_write_allowed()

void erf_sbm::require_host_write_allowed ( bool  sbm_active,
int  component,
HostWritePath  path 
)

Fail closed when a native host writer reaches a component owned by SBM.

43 {
44  require_host_write_range_allowed(sbm_active, component, 1, path);
45 }
void require_host_write_range_allowed(const bool sbm_active, const int start_component, const int num_components, const HostWritePath path)
Definition: ERF_SBMOwnership.cpp:47
Here is the call graph for this function:

◆ require_host_write_range_allowed()

void erf_sbm::require_host_write_range_allowed ( bool  sbm_active,
int  start_component,
int  num_components,
HostWritePath  path 
)

Fail closed when any component in a native writer's range is owned by SBM.

49 {
50  if (!host_write_range_allowed(sbm_active, start_component, num_components)) {
51  const std::string range = num_components > 0 && start_component >= 0 &&
52  num_components <= std::numeric_limits<int>::max() - start_component
53  ? " [" + std::to_string(start_component) + "," +
54  std::to_string(start_component + num_components) + ")"
55  : " (invalid range)";
56  amrex::Abort(std::string("SBM owns compact qc/qr; native ") +
57  host_write_path_name(path) + " write denied for component range" + range);
58  }
59 }
const char * host_write_path_name(const HostWritePath path) noexcept
Definition: ERF_SBMOwnership.cpp:9

Referenced by erf_slow_rhs_post(), if(), and require_host_write_allowed().

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

◆ restart_projection_matches()

bool erf_sbm::restart_projection_matches ( const amrex::MultiFab &  spectrum,
const amrex::MultiFab &  persisted_core,
const SBMBulkProjection &  projection,
int  qc_component,
int  qr_component,
amrex::Real  tolerance_scale = amrex::Real(128.0) 
)

Compare the projected spectrum to checkpointed qc/qr without mutating core.

426 {
427  if (spectrum.boxArray() != persisted_core.boxArray() ||
428  spectrum.DistributionMap() != persisted_core.DistributionMap() ||
429  qc_component < 0 || qr_component < 0 ||
430  qc_component >= persisted_core.nComp() || qr_component >= persisted_core.nComp() ||
431  !std::isfinite(tolerance_scale) || !(tolerance_scale >= amrex::Real(0.0)) ||
432  !spectrum.is_finite(0, spectrum.nComp(), 0) ||
433  !persisted_core.is_finite(qc_component, 1, 0) ||
434  !persisted_core.is_finite(qr_component, 1, 0)) {
435  return false;
436  }
437 
438  amrex::MultiFab expected(persisted_core.boxArray(), persisted_core.DistributionMap(), 2, 0);
439  amrex::MultiFab stored(persisted_core.boxArray(), persisted_core.DistributionMap(), 2, 0);
440  expected.setVal(amrex::Real(0.0));
441  for (amrex::MFIter mfi(expected); mfi.isValid(); ++mfi) {
442  projection.apply_to_core(mfi.validbox(), spectrum.const_array(mfi),
443  expected.array(mfi), 0, 1);
444  }
445  if (!expected.is_finite(0, 2, 0)) return false;
446  amrex::MultiFab::Copy(stored, persisted_core, qc_component, 0, 1, 0);
447  amrex::MultiFab::Copy(stored, persisted_core, qr_component, 1, 1, 0);
448  if (!stored.is_finite(0, 2, 0)) return false;
449 
450  const amrex::Real scale = std::max({expected.norm0(0), expected.norm0(1),
451  stored.norm0(0), stored.norm0(1)});
452  amrex::MultiFab::Subtract(expected, stored, 0, 0, 2, 0);
453  if (!expected.is_finite(0, 2, 0)) return false;
454  const amrex::Real difference = std::max(expected.norm0(0), expected.norm0(1));
455  const amrex::Real tolerance = tolerance_scale *
457  std::max(scale, std::numeric_limits<amrex::Real>::min());
458  return std::isfinite(scale) && std::isfinite(difference) &&
459  std::isfinite(tolerance) && difference <= tolerance;
460 }

Referenced by ERF::ReadCheckpointFile().

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

◆ restart_schema()

std::string erf_sbm::restart_schema ( const SBMLayout &  layout,
const std::string &  boundary_identity = "boundary=triply-periodic-v1",
const std::string &  mixing_identity = "" 
)

Exact semantic restart schema; no implicit checkpoint migration is performed. An empty mixing identity (no particle mixing) keeps the earlier schema.

249 {
250  std::ostringstream schema;
251  schema << "ERF-SBM-RESTART-v2\n"
252  << "layout=" << layout.schema_identity() << '\n'
253  << "constraint-policy=linear-groups-plus-canonical-persisted-v1\n"
254  << "projection=liquid-mass-sum-to-qc-qr-v1\n"
255  << "transport=sbm-m3-mapped-group-fct-v1\n"
256  << "high-order=endpoint-number-wenoz3-v1\n"
257  << "lifecycle=accepted-current-state-per-level-v1\n"
258  << "restriction=mapped-amount-average-v1\n"
259  << "prolongation=carrier-relative-piecewise-constant-v1\n"
260  << "reflux=accepted-stage-rate-flux-register-v1\n"
261  << "synchronization=private-candidate-canonical-admission-v1\n"
262  << "regrid=retained-copy-plus-carrier-relative-prolongation-v1\n"
263  << boundary_identity << '\n';
264  if (!mixing_identity.empty()) {
265  schema << mixing_identity << '\n';
266  }
267  return schema.str();
268 }

Referenced by restart_schema_matches(), and ERF::WriteCheckpointFile().

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

◆ restart_schema_matches()

bool erf_sbm::restart_schema_matches ( const SBMLayout &  layout,
const std::string &  persisted,
const std::string &  boundary_identity = "boundary=triply-periodic-v1",
const std::string &  mixing_identity = "" 
)

Compare persisted and expected schemas byte-for-byte.

273 {
274  return restart_schema(layout, boundary_identity, mixing_identity) == persisted;
275 }
std::string restart_schema(const SBMLayout &layout, const std::string &boundary_identity, const std::string &mixing_identity)
Definition: ERF_SBMRestart.cpp:246

Referenced by ERF::ReadCheckpointFile().

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

◆ restrict_mapped_spectrum_impl()

static bool erf_sbm::restrict_mapped_spectrum_impl ( const SBMLayout &  layout,
const SBMAMRStateView &  fine,
const SBMAMRStateView &  coarse,
const amrex::IntVect &  ratio,
const int  coarse_level,
MultiFab &  coarse_candidate,
const bool  candidate_is_private,
const int  max_groups_per_chunk,
const bool  reverse_chunk_order,
const SBMStateAdmission *  admission,
SBMTransferAllocationCensus *  allocation_census,
const std::optional< double >  cross_level_dt_min,
const MultiFab *  covered_parent_mask,
std::string &  diagnostic 
)
static
608 {
609  diagnostic.clear();
610  if (allocation_census != nullptr) allocation_census->begin();
611  std::string ratio_diagnostic;
612  const bool ratio_ok = valid_ratio(ratio, ratio_diagnostic);
613  const bool level_ok = coarse_level >= 0;
614  std::string fine_structure_diagnostic;
615  std::string coarse_structure_diagnostic;
616  const bool fine_structure_ok = validate_view_structure(
617  fine, layout, "fine", fine_structure_diagnostic);
618  const bool coarse_structure_ok = validate_view_structure(
619  coarse, layout, "coarse", coarse_structure_diagnostic);
620  const bool same_time = cross_level_dt_min.has_value()
621  ? semantic_time_matches(fine.spectrum_time, coarse.spectrum_time,
622  *cross_level_dt_min)
623  : semantic_time_matches_exact(fine.spectrum_time,
624  coarse.spectrum_time);
625  // average_down requires complete fine children. Do not query coarsenability
626  // until the ratio is positive and the fine spectrum pointer is valid.
627  const bool fine_boxes_coarsenable =
628  ratio_ok && fine_structure_ok &&
629  fine.spectrum->boxArray().coarsenable(ratio);
630  const bool local_structure_ok = ratio_ok && level_ok && fine_structure_ok &&
631  coarse_structure_ok && same_time &&
632  fine_boxes_coarsenable;
633  const std::string structure_diagnostic =
634  !ratio_ok ? ratio_diagnostic
635  : !level_ok ? "restriction coarse level must be nonnegative"
636  : !fine_structure_ok ? fine_structure_diagnostic
637  : !coarse_structure_ok ? coarse_structure_diagnostic
638  : !same_time ? "restriction requires fine and coarse state tuples at the same semantic time"
639  : !fine_boxes_coarsenable
640  ? "restriction fine BoxArray is not coarsenable by the refinement ratio; fine boxes must align to complete coarse cells"
641  : std::string{};
642  if (!collective_all_true(
643  local_structure_ok, structure_diagnostic,
644  "SBM restriction input tuple is invalid on another MPI rank",
645  diagnostic)) {
646  return false;
647  }
648 
649  const bool candidate_layout_ok =
650  coarse_candidate.nComp() == layout.ncomp() &&
651  erf_auxiliary::SameCellLayout(coarse_candidate, *coarse.spectrum);
652  const bool coverage_layout_ok = covered_parent_mask == nullptr ||
653  (covered_parent_mask->nComp() >= 1 &&
654  covered_parent_mask->boxArray() == coarse.spectrum->boxArray() &&
655  covered_parent_mask->DistributionMap() ==
656  coarse.spectrum->DistributionMap());
657  const bool separate_from_fine = candidate_is_separate(coarse_candidate, fine);
658  const bool separate_from_coarse = candidate_is_separate(coarse_candidate, coarse);
659  const bool local_candidate_ok = candidate_layout_ok && coverage_layout_ok &&
660  separate_from_fine && separate_from_coarse;
661  if (!collective_all_true(
662  local_candidate_ok,
663  "restriction candidate must be separate from both input tuples and match the coarse SBM layout, as must any covered-parent mask",
664  "SBM restriction candidate aliases an input on another MPI rank",
665  diagnostic)) {
666  return false;
667  }
668 
669  std::string fine_carrier_diagnostic;
670  std::string coarse_carrier_diagnostic;
671  const bool fine_carriers_ok = validate_view_carriers(
672  fine, "fine", fine_carrier_diagnostic);
673  const bool coarse_carriers_ok = validate_view_carriers(
674  coarse, "coarse", coarse_carrier_diagnostic);
675  std::string fine_spectrum_diagnostic;
676  std::string coarse_spectrum_diagnostic;
677  const bool fine_spectrum_ok = validate_view_spectrum(
678  fine, layout, coarse_level + 1, admission, "fine",
679  fine_spectrum_diagnostic);
680  const bool coarse_spectrum_ok = validate_view_spectrum(
681  coarse, layout, coarse_level, admission, "coarse",
682  coarse_spectrum_diagnostic);
683  const bool local_sources_ok = fine_carriers_ok && coarse_carriers_ok &&
684  fine_spectrum_ok && coarse_spectrum_ok;
685  const std::string source_diagnostic =
686  !fine_carriers_ok ? fine_carrier_diagnostic
687  : !coarse_carriers_ok ? coarse_carrier_diagnostic
688  : !fine_spectrum_ok ? fine_spectrum_diagnostic
689  : !coarse_spectrum_ok ? coarse_spectrum_diagnostic
690  : std::string{};
691  if (!collective_all_true(
692  local_sources_ok, source_diagnostic,
693  "SBM restriction source is inadmissible on another MPI rank",
694  diagnostic)) {
695  return false;
696  }
697 
698  if (max_groups_per_chunk <= 0) {
699  diagnostic = "SBM restriction chunk group limit must be positive";
700  return collective_all_true(false, diagnostic,
701  "SBM restriction chunk group limit is invalid on another MPI rank",
702  diagnostic);
703  }
704  const auto chunks = make_constraint_closure_chunks(
705  layout, max_groups_per_chunk);
706  int max_chunk_components = 0;
707  for (std::size_t pass = 0; pass < chunks.size(); ++pass) {
708  const std::size_t chunk_index = reverse_chunk_order
709  ? chunks.size() - 1U - pass : pass;
710  const auto& chunk = chunks[chunk_index];
711  max_chunk_components = std::max(
712  max_chunk_components, static_cast<int>(chunk.components.size()));
713  }
714  if (!collective_all_true(
715  max_chunk_components > 0,
716  "SBM restriction layout has no complete semantic component groups",
717  "SBM restriction layout has no complete semantic component groups on another MPI rank",
718  diagnostic)) {
719  return false;
720  }
721 
722  MultiFab fine_h_chunk(fine.spectrum->boxArray(),
723  fine.spectrum->DistributionMap(),
724  max_chunk_components, 0);
725  MultiFab fine_support_chunk(fine.spectrum->boxArray(),
726  fine.spectrum->DistributionMap(),
727  max_chunk_components, 0);
728  MultiFab coarse_h_chunk(coarse.spectrum->boxArray(),
729  coarse.spectrum->DistributionMap(),
730  max_chunk_components, 0);
731  MultiFab coarse_support_chunk(coarse.spectrum->boxArray(),
732  coarse.spectrum->DistributionMap(),
733  max_chunk_components, 0);
734  MultiFab fine_coverage;
735  MultiFab coarse_coverage_scratch;
736  if (covered_parent_mask == nullptr) {
737  fine_coverage.define(fine.spectrum->boxArray(),
738  fine.spectrum->DistributionMap(), 1, 0);
739  coarse_coverage_scratch.define(coarse.spectrum->boxArray(),
740  coarse.spectrum->DistributionMap(), 1, 0);
741  }
742  MultiFab lost_positive_support(coarse.spectrum->boxArray(),
743  coarse.spectrum->DistributionMap(), 1, 0);
744  MultiFab fine_invalid(fine.spectrum->boxArray(),
745  fine.spectrum->DistributionMap(), 1, 0);
746  MultiFab coarse_invalid(coarse.spectrum->boxArray(),
747  coarse.spectrum->DistributionMap(), 1, 0);
748  MultiFab owned_candidate_scratch;
749  MultiFab* work = &coarse_candidate;
750  if (!candidate_is_private) {
751  owned_candidate_scratch.define(coarse.spectrum->boxArray(),
752  coarse.spectrum->DistributionMap(),
753  layout.ncomp(), 0);
754  work = &owned_candidate_scratch;
755  }
756  if (allocation_census != nullptr) allocation_census->sample();
757  // One full private coarse candidate starts as accepted coarse U. Only
758  // covered parents are replaced by H-restricted values; uncovered U never
759  // takes a mapped round trip.
760  MultiFab::Copy(*work, *coarse.spectrum, 0, 0, layout.ncomp(), 0);
761  fine_invalid.setVal(Real(0.0));
762  coarse_invalid.setVal(Real(0.0));
763  lost_positive_support.setVal(Real(0.0));
764  if (covered_parent_mask == nullptr) {
765  fine_coverage.setVal(Real(1.0));
766  coarse_coverage_scratch.setVal(Real(0.0));
767  amrex::average_down(fine_coverage, coarse_coverage_scratch, 0, 1, ratio);
768  }
769  const MultiFab& coarse_coverage = covered_parent_mask != nullptr
770  ? *covered_parent_mask : coarse_coverage_scratch;
771  amrex::Gpu::DeviceVector<int> device_components(
772  static_cast<std::size_t>(max_chunk_components));
773  for (std::size_t pass = 0; pass < chunks.size(); ++pass) {
774  const std::size_t chunk_index = reverse_chunk_order
775  ? chunks.size() - 1U - pass : pass;
776  const auto& chunk = chunks[chunk_index];
777  if (allocation_census != nullptr && !chunk.components.empty()) {
778  allocation_census->processed_chunk_first_components.push_back(
779  chunk.components.front());
780  }
781  const int chunk_components = static_cast<int>(chunk.components.size());
782  amrex::Gpu::copy(amrex::Gpu::hostToDevice, chunk.components.begin(),
783  chunk.components.end(), device_components.begin());
784  form_mapped_chunk(*fine.spectrum, *fine.mapped_measure,
785  fine.measure_component, chunk.components,
786  device_components, fine_h_chunk,
787  fine_support_chunk, fine_invalid);
788  amrex::average_down(fine_h_chunk, coarse_h_chunk, 0,
789  chunk_components, ratio);
790  amrex::average_down(fine_support_chunk, coarse_support_chunk, 0,
791  chunk_components, ratio);
792  write_restricted_chunk(coarse_h_chunk, coarse_support_chunk,
793  *coarse.mapped_measure,
794  coarse.measure_component, coarse_coverage,
795  chunk.components, device_components, *work,
796  lost_positive_support, coarse_invalid);
797  }
798 
799  // Support loss is tracked for every component and decided collectively
800  // once. average_down retains its required AMReX data communication.
801  const bool fine_mapping_valid = fine_invalid.max(0, 0, true) <= Real(0.0);
802  const bool coarse_quotient_valid =
803  coarse_invalid.max(0, 0, true) <= Real(0.0);
804  const bool support_preserved =
805  lost_positive_support.max(0, 0, true) <= Real(0.0);
806  const bool local_support_preserved = fine_mapping_valid &&
807  coarse_quotient_valid &&
808  support_preserved;
809  const std::string local_transfer_diagnostic =
810  !fine_mapping_valid
811  ? "forming fine mapped amount H=omega*U overflowed or underflowed"
812  : !coarse_quotient_valid
813  ? "recovering coarse spectrum U=H/omega overflowed or underflowed"
814  : !support_preserved
815  ? "restriction averaging underflow erased positive mapped support to zero"
816  : std::string{};
817  if (allocation_census != nullptr) {
818  ++allocation_census->support_loss_collective_votes;
819  }
820  if (!collective_all_true(local_support_preserved,
821  local_transfer_diagnostic,
822  "mapped restriction overflowed, underflowed, or erased positive support on another MPI rank",
823  diagnostic)) {
824  return false;
825  }
826 
827  std::string candidate_admission_diagnostic;
828  const bool candidate_admissible = admission != nullptr
829  ? admission->admissible(*work, coarse_level,
830  candidate_admission_diagnostic)
831  : authoritative_state_admissible(*work, layout, coarse_level,
832  &candidate_admission_diagnostic);
833  const bool local_candidate_admissible = candidate_admissible;
834  const std::string candidate_diagnostic = !candidate_admissible
835  ? "restricted SBM candidate is inadmissible: " +
836  candidate_admission_diagnostic
837  : std::string{};
838  if (!collective_all_true(
839  local_candidate_admissible, candidate_diagnostic,
840  "restricted SBM candidate is inadmissible on another MPI rank",
841  diagnostic)) {
842  return false;
843  }
844  if (!candidate_is_private) {
845  MultiFab::Copy(coarse_candidate, *work, 0, 0, layout.ncomp(), 0);
846  }
847  return true;
848 }
bool form_mapped_chunk(const MultiFab &spectrum, const MultiFab &measure, const int measure_component, const std::vector< int > &components, const amrex::Gpu::DeviceVector< int > &device_components, MultiFab &mapped, MultiFab &support, MultiFab &invalid)
Definition: ERF_SBMAMRTransfer.cpp:147
void write_restricted_chunk(const MultiFab &mapped, const MultiFab &coarse_support, const MultiFab &measure, const int measure_component, const MultiFab &coverage, const std::vector< int > &components, const amrex::Gpu::DeviceVector< int > &device_components, MultiFab &candidate, MultiFab &lost_support, MultiFab &invalid)
Definition: ERF_SBMAMRTransfer.cpp:182

Referenced by RestrictMappedSpectrum(), and RestrictMappedSpectrumPrivate().

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

◆ RestrictMappedSpectrum() [1/2]

bool erf_sbm::RestrictMappedSpectrum ( const SBMLayout &  layout,
const SBMAMRStateView &  fine,
const SBMAMRStateView &  coarse,
const amrex::IntVect &  ratio,
const int  coarse_level,
MultiFab &  coarse_candidate,
std::string &  diagnostic,
const int  max_groups_per_chunk,
const bool  reverse_chunk_order,
const SBMStateAdmission *  admission,
SBMTransferAllocationCensus *  allocation_census,
const std::optional< double >  cross_level_dt_min 
)
862 {
863  return restrict_mapped_spectrum_impl(layout, fine, coarse, ratio,
864  coarse_level, coarse_candidate, false,
865  max_groups_per_chunk,
866  reverse_chunk_order, admission,
867  allocation_census,
868  cross_level_dt_min, nullptr,
869  diagnostic);
870 }
static bool restrict_mapped_spectrum_impl(const SBMLayout &layout, const SBMAMRStateView &fine, const SBMAMRStateView &coarse, const amrex::IntVect &ratio, const int coarse_level, MultiFab &coarse_candidate, const bool candidate_is_private, const int max_groups_per_chunk, const bool reverse_chunk_order, const SBMStateAdmission *admission, SBMTransferAllocationCensus *allocation_census, const std::optional< double > cross_level_dt_min, const MultiFab *covered_parent_mask, std::string &diagnostic)
Definition: ERF_SBMAMRTransfer.cpp:598
Here is the call graph for this function:

◆ RestrictMappedSpectrum() [2/2]

bool erf_sbm::RestrictMappedSpectrum ( const SBMLayout &  layout,
const SBMAMRStateView &  fine,
const SBMAMRStateView &  coarse,
const amrex::IntVect &  ratio,
int  coarse_level,
amrex::MultiFab &  coarse_candidate,
std::string &  diagnostic,
int  max_groups_per_chunk = 16,
bool  reverse_chunk_order = false,
const SBMStateAdmission *  admission = nullptr,
SBMTransferAllocationCensus *  allocation_census = nullptr,
std::optional< double >  cross_level_dt_min = std::nullopt 
)

Form an H-conservative coarse candidate from matching-time spectral views. Cross-level endpoint labels may use a timestep-bounded comparison when the caller supplies the interval's actual minimum physical timestep; each input tuple's spectrum/density/measure labels remain exactly identical. On success, overwrite the destination's valid cells with the complete, admitted result. On failure (including a rejection on another MPI rank), leave every destination valid cell and all source views unchanged. This operator does not itself commit authoritative SBM state.

◆ RestrictMappedSpectrumPrivate() [1/2]

bool erf_sbm::RestrictMappedSpectrumPrivate ( const SBMLayout &  layout,
const SBMAMRStateView &  fine,
const SBMAMRStateView &  coarse,
const amrex::IntVect &  ratio,
const int  coarse_level,
MultiFab &  private_candidate,
std::string &  diagnostic,
const int  max_groups_per_chunk,
const bool  reverse_chunk_order,
const SBMStateAdmission *  admission,
SBMTransferAllocationCensus *  allocation_census,
const std::optional< double >  cross_level_dt_min,
const MultiFab *  covered_parent_mask 
)
885 {
886  return restrict_mapped_spectrum_impl(layout, fine, coarse, ratio,
887  coarse_level, private_candidate, true,
888  max_groups_per_chunk,
889  reverse_chunk_order, admission,
890  allocation_census,
891  cross_level_dt_min,
892  covered_parent_mask, diagnostic);
893 }

Referenced by ERF::sbm_synchronize_levels().

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

◆ RestrictMappedSpectrumPrivate() [2/2]

bool erf_sbm::RestrictMappedSpectrumPrivate ( const SBMLayout &  layout,
const SBMAMRStateView &  fine,
const SBMAMRStateView &  coarse,
const amrex::IntVect &  ratio,
int  coarse_level,
amrex::MultiFab &  private_candidate,
std::string &  diagnostic,
int  max_groups_per_chunk = 16,
bool  reverse_chunk_order = false,
const SBMStateAdmission *  admission = nullptr,
SBMTransferAllocationCensus *  allocation_census = nullptr,
std::optional< double >  cross_level_dt_min = std::nullopt,
const amrex::MultiFab *  covered_parent_mask = nullptr 
)

Private-candidate variant for coarse synchronization. The caller supplies an unpublished full-spectrum buffer; it may be overwritten on failure. The routine reuses it for the restricted mapped amount and final spectrum.

◆ same_population_context()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool erf_sbm::same_population_context ( const PopulationRemapView &  left,
const PopulationRemapView &  right 
)
noexcept
129 {
130  return left.population_id == right.population_id &&
131  left.moment_mode == right.moment_mode &&
132  left.coordinate_kind == right.coordinate_kind &&
133  left.edges == right.edges && left.pivots == right.pivots &&
134  left.nbins == right.nbins && left.mass_offset == right.mass_offset &&
135  left.number_offset == right.number_offset &&
136  left.state_components == right.state_components &&
137  left.property_component_offsets == right.property_component_offsets &&
138  left.property_count == right.property_count;
139 }

Referenced by apply_packet_routing_core(), project_reconstruction_bin_core(), and erf_sbm::remap_detail::route_plan_is_consistent().

Here is the caller graph for this function:

◆ semantic_time_matches()

bool erf_sbm::semantic_time_matches ( const double  lhs,
const double  rhs,
const double  dt_min 
)
inlinenoexcept

Compare values carrying one semantic time identity without admitting a neighboring physical substep. Callers must provide the smallest physical step represented by the comparison.

17 {
18  if (!std::isfinite(lhs) || !std::isfinite(rhs) ||
19  !std::isfinite(dt_min) || !(dt_min > 0.0)) {
20  return false;
21  }
22  const double scale = std::max({1.0, std::abs(lhs), std::abs(rhs)});
23  const double roundoff =
24  16.0 * std::numeric_limits<double>::epsilon() * scale;
25  const double tolerance = std::min(roundoff, dt_min / 32.0);
26  return std::abs(lhs - rhs) <= tolerance;
27 }

Referenced by erf_sbm::SBMAMRFluxRegister::accept_level_step(), erf_sbm::SBMAMRFluxRegister::begin_level_step(), erf_sbm::SBMAMRFluxRegister::begin_stage(), erf_sbm::SBMStateManager::begin_step(), erf_sbm::erf_detail_SBMTransport::coarse_stage_theta(), erf_sbm::erf_detail_SBMTransport::fill_coarse_parent_ghosts(), ERF::init_sbm_level_from_coarse(), level_time_matches(), restrict_mapped_spectrum_impl(), and ERF::sbm_synchronize_levels().

Here is the caller graph for this function:

◆ semantic_time_matches_exact()

bool erf_sbm::semantic_time_matches_exact ( const double  lhs,
const double  rhs 
)
inlinenoexcept

Transfer tuples without a physical-step scale must share the exact finite timestamp supplied by their owner.

34 {
35  return std::isfinite(lhs) && std::isfinite(rhs) && lhs == rhs;
36 }

Referenced by erf_sbm::SBMStateManager::begin_step(), level_time_matches(), prolong_carrier_relative_spectrum_impl(), RemapRegriddedSpectrumPrivate(), restrict_mapped_spectrum_impl(), and erf_sbm::erf_detail_SBMAMRTransfer::validate_view_structure().

Here is the caller graph for this function:

◆ transform_two_moment()

EndpointTransform erf_sbm::transform_two_moment ( amrex::Real  C,
amrex::Real  M,
amrex::Real  lower,
amrex::Real  upper 
)

Compatibility entry point delegating to the canonical grid-layer transform.

282 {
283  return SpectralGrid::two_moment_to_endpoints(C, M, lower, upper);
284 }

◆ try_endpoints_to_two_moment()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool erf_sbm::try_endpoints_to_two_moment ( const amrex::Real  L,
const amrex::Real  H,
const amrex::Real  lower,
const amrex::Real  upper,
amrex::Real &  C,
amrex::Real &  M 
)
noexcept

Allocation-free canonical inverse transform for host and device callers.

92 {
93  if (!amrex::Math::isfinite(L) || !amrex::Math::isfinite(H) || !amrex::Math::isfinite(lower) ||
94  !amrex::Math::isfinite(upper) || L < amrex::Real(0.0) || H < amrex::Real(0.0) ||
95  lower < amrex::Real(0.0) || !(lower < upper)) {
96  return false;
97  }
98  const amrex::Real count = L + H;
99  const amrex::Real mass = std::fma(lower, L, upper * H);
100  if (!amrex::Math::isfinite(count) || !amrex::Math::isfinite(mass) ||
101  count < amrex::Real(0.0) || mass < amrex::Real(0.0)) {
102  return false;
103  }
104  C = count;
105  M = mass;
106  return true;
107 }
int count
Definition: ERF_ActuatorSpreading.cpp:264

Referenced by erf_sbm::SpectralGrid::endpoints_to_two_moment().

Here is the caller graph for this function:

◆ try_two_moment_to_endpoints()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool erf_sbm::try_two_moment_to_endpoints ( const amrex::Real  C,
const amrex::Real  M,
const amrex::Real  lower,
const amrex::Real  upper,
EndpointTransform &  result 
)
noexcept

Allocation-free canonical forward transform used by host and device code. Returns false instead of throwing when the state is invalid or materially unrealizable. The throwing host API below delegates to this function.

51 {
52  if (!amrex::Math::isfinite(C) || !amrex::Math::isfinite(M) || !amrex::Math::isfinite(lower) ||
53  !amrex::Math::isfinite(upper) || lower < amrex::Real(0.0) ||
54  !(lower < upper) || C < amrex::Real(0.0)) {
55  return false;
56  }
57  const amrex::Real scale = std::abs(M) + std::abs(lower * C) + std::abs(upper * C);
58  const amrex::Real moment_tolerance = amrex::Real(128.0) *
60  const amrex::Real low_numerator = std::fma(upper, C, -M);
61  const amrex::Real high_numerator = std::fma(-lower, C, M);
62  if (!amrex::Math::isfinite(scale) || !amrex::Math::isfinite(moment_tolerance) ||
63  !amrex::Math::isfinite(low_numerator) || !amrex::Math::isfinite(high_numerator) ||
64  low_numerator < -moment_tolerance || high_numerator < -moment_tolerance) {
65  return false;
66  }
67  if (C == amrex::Real(0.0)) {
68  if (std::abs(M) > moment_tolerance) return false;
69  result = {amrex::Real(0.0), amrex::Real(0.0), moment_tolerance,
70  moment_tolerance / (upper - lower), M != amrex::Real(0.0)};
71  return amrex::Math::isfinite(result.endpoint_tolerance);
72  }
73  const amrex::Real denominator = upper - lower;
74  amrex::Real L = low_numerator / denominator;
75  amrex::Real H = high_numerator / denominator;
76  const amrex::Real endpoint_tolerance = moment_tolerance / denominator;
77  if (!amrex::Math::isfinite(L) || !amrex::Math::isfinite(H) || !amrex::Math::isfinite(endpoint_tolerance)) {
78  return false;
79  }
80  const bool normalized = L < amrex::Real(0.0) || H < amrex::Real(0.0);
81  if (L < amrex::Real(0.0)) L = amrex::Real(0.0);
82  if (H < amrex::Real(0.0)) H = amrex::Real(0.0);
83  result = {L, H, moment_tolerance, endpoint_tolerance, normalized};
84  return true;
85 }

Referenced by erf_sbm::SBMTransport::advance_stage(), reconstruct_bin_core(), erf_sbm::SpectralGrid::two_moment_realizable(), and erf_sbm::SpectralGrid::two_moment_to_endpoints().

Here is the caller graph for this function:

◆ valid_population_remap_context()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool erf_sbm::valid_population_remap_context ( const PopulationRemapView &  population)
noexcept

Constant-time structural/context checks for already qualified immutable metadata. Callers must derive views from a validated SBMLayout or call the full validator below once before using a raw view in the remapping cores.

54 {
55  if (population.population_id < 0 ||
56  population.coordinate_kind != CoordinateKind::Mass ||
57  (population.moment_mode != MomentMode::OneMoment &&
58  population.moment_mode != MomentMode::TwoMoment) ||
59  population.nbins <= 0 || population.edges == nullptr ||
60  population.state_components < population.nbins || population.mass_offset < 0 ||
61  population.property_count < 0 ||
62  population.property_count > population.state_components / population.nbins ||
63  (population.property_count > 0 && population.property_component_offsets == nullptr)) {
64  return false;
65  }
66  if (population.mass_offset > population.state_components - population.nbins) return false;
67  if (population.moment_mode == MomentMode::OneMoment) {
68  if (population.number_offset != -1 || population.pivots == nullptr) return false;
69  } else if (population.number_offset < 0 ||
70  population.number_offset > population.state_components - population.nbins) {
71  return false;
72  }
73  if (population.moment_mode == MomentMode::TwoMoment &&
74  population.number_offset < population.mass_offset + population.nbins &&
75  population.mass_offset < population.number_offset + population.nbins) {
76  return false;
77  }
78  return true;
79 }

Referenced by apply_packet_routing_core(), erf_sbm::remap_detail::canonical_one_moment_bin_state_view(), erf_sbm::remap_detail::canonical_two_moment_bin_state_view(), erf_sbm::remap_detail::canonical_two_moment_moments(), plan_packet_routing(), population_remap_view(), project_reconstruction_bin_core(), reconstruct_bin_core(), erf_sbm::remap_detail::route_plan_is_consistent(), and valid_population_remap_view().

Here is the caller graph for this function:

◆ valid_population_remap_view()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool erf_sbm::valid_population_remap_view ( const PopulationRemapView &  population)
noexcept

Full O(nbins + properties^2) validator for untrusted/arbitrary views.

84 {
85  if (!valid_population_remap_context(population)) return false;
86  for (int edge = 0; edge <= population.nbins; ++edge) {
87  const amrex::Real value = population.edges[edge];
88  if (!amrex::Math::isfinite(value) || value < amrex::Real(0.0) ||
89  (edge > 0 && !(population.edges[edge - 1] < value))) {
90  return false;
91  }
92  }
93  if (population.moment_mode == MomentMode::OneMoment) {
94  for (int bin = 0; bin < population.nbins; ++bin) {
95  const amrex::Real pivot = population.pivots[bin];
96  if (!amrex::Math::isfinite(pivot) || pivot <= amrex::Real(0.0) ||
97  pivot < population.edges[bin] || pivot > population.edges[bin + 1] ||
98  (bin > 0 && !(population.pivots[bin - 1] < pivot))) {
99  return false;
100  }
101  }
102  }
103  for (int property = 0; property < population.property_count; ++property) {
104  const int offset = population.property_component_offsets[property];
105  if (offset < 0 || offset > population.state_components - population.nbins ||
106  (offset < population.mass_offset + population.nbins &&
107  population.mass_offset < offset + population.nbins)) {
108  return false;
109  }
110  if (population.moment_mode == MomentMode::TwoMoment &&
111  offset < population.number_offset + population.nbins &&
112  population.number_offset < offset + population.nbins) {
113  return false;
114  }
115  for (int previous = 0; previous < property; ++previous) {
116  const int previous_offset = population.property_component_offsets[previous];
117  if (offset < previous_offset + population.nbins &&
118  previous_offset < offset + population.nbins) {
119  return false;
120  }
121  }
122  }
123  return true;
124 }
AMREX_FORCE_INLINE IntVect offset(const int face_dir, const int normal)
Definition: ERF_ReadBndryPlanes.cpp:36
Here is the call graph for this function:

◆ validate_fixture_initial_state_canonicality()

FixtureInitialStateCanonicality erf_sbm::validate_fixture_initial_state_canonicality ( const SBMLayout &  layout,
const std::vector< amrex::Real > &  state 
)
inlinenoexcept

Apply the persisted-state admission rule to each bin before ERF accepts a user/fixture initial spectrum. Kept as the constructor's shared validation seam so unit tests can exercise the exact candidate-layout check.

26 {
27  FixtureInitialStateCanonicality result;
28  if (state.size() != static_cast<std::size_t>(layout.ncomp())) return result;
29 
30  result.canonical = true;
31  const int state_count = static_cast<int>(state.size());
32  for (const auto& population : layout.populations()) {
33  const auto view = population_remap_view(layout, population.population_id);
34  for (int bin = 0; bin < population.grid.nbins(); ++bin) {
36  view, bin, state.data(), state_count)) {
37  result.canonical = false;
38  result.population_id = population.population_id;
39  result.bin = bin;
40  result.moment_mode = population.moment_mode;
41  return result;
42  }
43  }
44  }
45  return result;
46 }

Referenced by validate_inflow_state().

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

◆ validate_inflow_state()

bool erf_sbm::validate_inflow_state ( const SBMLayout &  layout,
const std::vector< amrex::Real > &  z,
std::string &  reason 
)

Require a complete, canonical, group-admissible inflow spectrum.

155 {
156  reason.clear();
157  if (z.size() != static_cast<std::size_t>(layout.ncomp())) {
158  reason = "it has " + std::to_string(z.size()) + " values but the SBM layout has " +
159  std::to_string(layout.ncomp()) + " components";
160  return false;
161  }
162  for (std::size_t n = 0; n < z.size(); ++n) {
163  if (!std::isfinite(z[n]) || z[n] < amrex::Real(0.0)) {
164  reason = "component " + std::to_string(n) + " is not finite and nonnegative";
165  return false;
166  }
167  }
168  const auto canonicality = validate_fixture_initial_state_canonicality(layout, z);
169  if (!canonicality.canonical) {
170  reason = "population " + std::to_string(canonicality.population_id) + " bin " +
171  std::to_string(canonicality.bin) +
172  " is not canonical for its spectral representation";
173  return false;
174  }
175  for (const auto& group : make_constraint_groups(layout)) {
176  std::string failed_constraint;
177  if (!group.admissible(z, nullptr, &failed_constraint)) {
178  reason = "population " + std::to_string(group.population_id) + " bin " +
179  std::to_string(group.bin) + " (" + group.semantic_id +
180  ") fails " + failed_constraint;
181  return false;
182  }
183  }
184  return true;
185 }
FixtureInitialStateCanonicality validate_fixture_initial_state_canonicality(const SBMLayout &layout, const std::vector< amrex::Real > &state) noexcept
Definition: ERF_SBMFixtureValidation.H:24

Referenced by ERF::configure_sbm_physical_boundaries(), and erf_sbm::SBMTransport::set_physical_boundaries().

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

◆ validate_particle_mixing_boundaries()

bool erf_sbm::validate_particle_mixing_boundaries ( const ParticleMixingConfig &  config,
const SBMPhysicalBoundaryConfig &  boundaries,
std::string &  reason 
)

Mixing accepts periodic, wall, outflow and inflow faces. An inflow_outflow z face is rejected: ERF's own vertical scalar diffusion has no inward-only rule there to follow, and ERF accepts inflow_outflow on x and y faces only.

183 {
184  reason.clear();
185  for (int face = 0; face < physical_face_count; ++face) {
186  const auto kind = boundaries.kind[static_cast<std::size_t>(face)];
187  const auto diffusion = boundaries.diffusion[static_cast<std::size_t>(face)];
188  if (diffusion != erf_auxiliary::DiffusionFaceKind::Closed &&
189  kind != AdvectionFaceKind::PrescribedInflow) {
190  reason = std::string("SBM particle mixing can exchange only through an inflow "
191  "face, not the ") + face_kind_name(kind) + " face " +
192  face_name(face);
193  return false;
194  }
195  }
196  if (config.policy == ParticleMixingPolicy::None) { return true; }
197  for (const int face : {2, 2 + AMREX_SPACEDIM}) {
198  if (boundaries.diffusion[static_cast<std::size_t>(face)] ==
200  reason = std::string("SBM particle mixing ") + particle_mixing_name(config.policy) +
201  " does not support an inflow_outflow " + face_name(face) +
202  " face: ERF's vertical scalar diffusion has no inward-only rule to follow";
203  return false;
204  }
205  }
206  return true;
207 }
const char * face_kind_name(const AdvectionFaceKind kind) noexcept
Definition: ERF_SBMPhysicalBoundary.cpp:78

Referenced by ERF::configure_sbm_physical_boundaries(), erf_sbm::SBMTransport::set_particle_mixing(), and erf_sbm::SBMTransport::set_physical_boundaries().

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

◆ validate_particle_mixing_config()

bool erf_sbm::validate_particle_mixing_config ( const ParticleMixingConfig &  config,
std::string &  reason 
)
58 {
59  reason.clear();
60  if (config.policy == ParticleMixingPolicy::ConstantReference) {
61  for (const amrex::Real value : {config.reference_kh, config.reference_kv}) {
62  if (!(std::isfinite(value) && value >= amrex::Real(0.0))) {
63  reason = "ConstantReference diffusivities must be finite and nonnegative";
64  return false;
65  }
66  }
67  return true;
68  }
69  if (config.reference_kh != amrex::Real(0.0) || config.reference_kv != amrex::Real(0.0)) {
70  reason = std::string("reference diffusivities apply only to ConstantReference, not ") +
72  return false;
73  }
74  return true;
75 }

Referenced by build_particle_mixing_transmissibility(), make_particle_mixing_config(), particle_mixing_coefficients(), erf_sbm::SBMTransport::set_particle_mixing(), and validate_particle_mixing_host().

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

◆ validate_particle_mixing_host() [1/2]

bool erf_sbm::validate_particle_mixing_host ( const ParticleMixingConfig &  config,
const std::vector< TurbChoice > &  turbulence,
MolecDiffType  molecular,
MeshType  mesh,
bool  terrain_qualification,
std::string &  reason 
)

As above. With terrain_qualification, for qualification only, a policy other than None also accepts a terrain-fitted (VariableDz) mesh on one level; the stage still checks the geometry admission below.

117 {
118  if (!validate_particle_mixing_config(config, reason)) { return false; }
119  const std::string policy = particle_mixing_name(config.policy);
120  if (molecular != MolecDiffType::None) {
121  reason = "SBM does not support molecular diffusion (erf.molec_diff_type must be "
122  "None): particle molecular diffusion is zero, and molecular vapor "
123  "diffusion has not been qualified with SBM";
124  return false;
125  }
126  for (std::size_t lev = 0; lev < turbulence.size(); ++lev) {
127  const TurbChoice& turb = turbulence[lev];
128  const std::string at_level = " (level " + std::to_string(lev) + ")";
129  if (turb.pbl_type != PBLType::None) {
130  reason = "SBM does not support a PBL closure (erf.pbl_type = " +
131  amrex::getEnumNameString(turb.pbl_type) + at_level +
132  "): ERF's PBL schemes other than SHOC set the moisture eddy "
133  "diffusivity but not the passive-scalar one particles use, and "
134  "several add nonlocal transport a local coefficient does not represent";
135  return false;
136  }
137  if (turb.rans_type != RANSType::None) {
138  reason = "SBM does not support a RANS closure (erf.rans_type)" + at_level;
139  return false;
140  }
141  if (config.policy == ParticleMixingPolicy::HostPassiveScalar) {
142  if (turb.les_type != LESType::Smagorinsky && turb.les_type != LESType::Deardorff) {
143  reason = "SBM particle mixing HostPassiveScalar requires erf.les_type = "
144  "Smagorinsky or Deardorff on every level" + at_level;
145  return false;
146  }
147  // ERF reads Smagorinsky2D as Smagorinsky with smag2d set
148  if (turb.smag2d) {
149  reason = "SBM particle mixing HostPassiveScalar does not support erf.les_type = "
150  "Smagorinsky2D" + at_level + ": its horizontal-only closure "
151  "leaves vertical mixing to a PBL scheme, which SBM does not support";
152  return false;
153  }
154  if (turb.les_type != turbulence.front().les_type) {
155  reason = "SBM particle mixing HostPassiveScalar requires the same "
156  "erf.les_type on every level";
157  return false;
158  }
159  } else if (turb.les_type != LESType::None) {
160  reason = "SBM particle mixing " + policy + " does not mix the spectrum with "
161  "ERF's LES closure (erf.les_type)" + at_level +
162  "; set erf.sbm_particle_mixing = HostPassiveScalar";
163  return false;
164  }
165  }
166  if (config.policy == ParticleMixingPolicy::None) { return true; }
168  if (!particle_mixing_mesh(mesh, diffusion_mesh, reason, terrain_qualification)) {
169  return false;
170  }
171  if (diffusion_mesh == erf_auxiliary::DiffusionMesh::VariableDz && turbulence.size() != 1) {
172  reason = "SBM particle mixing on a terrain-fitted (VariableDz) mesh is qualified on "
173  "one level only";
174  return false;
175  }
176  return true;
177 }
DiffusionMesh
Definition: ERF_AuxiliaryDiffusion.H:32
bool particle_mixing_mesh(const MeshType mesh_type, erf_auxiliary::DiffusionMesh &mesh, std::string &reason, const bool terrain_qualification)
Definition: ERF_SBMParticleMixing.cpp:278
Definition: ERF_TurbStruct.H:129
RANSType rans_type
Selected RANS closure.
Definition: ERF_TurbStruct.H:960
LESType les_type
Selected LES closure.
Definition: ERF_TurbStruct.H:909
PBLType pbl_type
Selected PBL closure.
Definition: ERF_TurbStruct.H:1003
bool smag2d
Whether the 2-D Smagorinsky formulation is used.
Definition: ERF_TurbStruct.H:921
Here is the call graph for this function:

◆ validate_particle_mixing_host() [2/2]

bool erf_sbm::validate_particle_mixing_host ( const ParticleMixingConfig &  config,
const std::vector< TurbChoice > &  turbulence,
MolecDiffType  molecular,
MeshType  mesh,
std::string &  reason 
)

The ERF configuration a policy is qualified with: no molecular, PBL or RANS diffusion; ERF turbulence only as the same Smagorinsky or Deardorff LES on every level, and only with HostPassiveScalar, which requires it; and a constant- or stretched-dz mesh. SBM's own AMR envelope (two levels, a constant-dz mesh) bounds the levels.

106 {
107  return validate_particle_mixing_host(config, turbulence, molecular, mesh, false, reason);
108 }
bool validate_particle_mixing_host(const ParticleMixingConfig &config, const std::vector< TurbChoice > &turbulence, const MolecDiffType molecular, const MeshType mesh, const bool terrain_qualification, std::string &reason)
Definition: ERF_SBMParticleMixing.cpp:111

Variable Documentation

◆ physical_face_count