OGS
ChemistryLib::PhreeqcIOData::ClampingStats Struct Reference

Detailed Description

Statistics for clamping negative input concentrations to zero before speciation. PHREEQC rejects negative concentrations, so every negative value is clamped to zero unconditionally; the warning threshold (a negative value, see ChemistryLib parameter concentration_warning_threshold) only decides whether a clamp is reported. Values in \([\text{warning\_threshold}, 0)\) are treated as floating-point noise and clamped silently; values \(<\text{warning\_threshold}\) are clamped and counted as "severe" so an aggregated warning can be emitted.

The same type is used both as a per-cell leaf (built by clamp()) and as a run-level accumulator (folded by operator+=). It is an aggregate (no user-declared constructor, no private data) so brace-init and = {} reset work.

Definition at line 26 of file ClampingStats.h.

#include <ClampingStats.h>

Public Member Functions

double clamp (double c, double warning_threshold, std::string_view name)
ClampingStatsoperator+= (ClampingStats const &other)
 Folds another stats object into this accumulator (identity = {}).
void report (double warning_threshold) const
 WARN for severe clamps, DBUG for silent noise clamps. No-op when empty.

Public Attributes

std::string_view worst_component_name
 aliases Component::name
std::size_t n_cells = 0
 cells with any clamping
std::size_t n_values = 0
 total values clamped
std::size_t n_severe_cells = 0
 cells with a severe clamp
std::size_t n_severe_values = 0
 total severe values clamped
double total_clamped_amount = 0.0
double worst_negative_value = 0.0

Member Function Documentation

◆ clamp()

double ChemistryLib::PhreeqcIOData::ClampingStats::clamp ( double c,
double warning_threshold,
std::string_view name )

Clamps one concentration: negative values are returned as 0 and the value-level counters are updated; non-negative input is returned unchanged. A value below warning_threshold (which is negative) is recorded as severe and may update the worst value/name. The cell-level counters (n_cells / n_severe_cells) are set by the caller after the per-component loop.

Definition at line 12 of file ClampingStats.cpp.

14{
15 if (c >= 0.0)
16 {
17 return c;
18 }
19 if (c < warning_threshold)
20 {
23 {
26 }
27 }
28 ++n_values;
30 return 0.0;
31}
std::string_view worst_component_name
aliases Component::name
std::size_t n_severe_values
total severe values clamped
std::size_t n_values
total values clamped

References n_severe_values, n_values, total_clamped_amount, worst_component_name, and worst_negative_value.

Referenced by ChemistryLib::PhreeqcIOData::setAqueousSolution().

◆ operator+=()

ClampingStats & ChemistryLib::PhreeqcIOData::ClampingStats::operator+= ( ClampingStats const & other)

Folds another stats object into this accumulator (identity = {}).

Definition at line 33 of file ClampingStats.cpp.

34{
35 n_cells += other.n_cells;
36 n_values += other.n_values;
37 n_severe_cells += other.n_severe_cells;
38 n_severe_values += other.n_severe_values;
39 total_clamped_amount += other.total_clamped_amount;
40 if (other.worst_negative_value < worst_negative_value)
41 {
42 worst_negative_value = other.worst_negative_value;
43 worst_component_name = other.worst_component_name;
44 }
45 return *this;
46}
std::size_t n_severe_cells
cells with a severe clamp
std::size_t n_cells
cells with any clamping

References n_cells, n_severe_cells, n_severe_values, n_values, total_clamped_amount, worst_component_name, and worst_negative_value.

◆ report()

void ChemistryLib::PhreeqcIOData::ClampingStats::report ( double warning_threshold) const

WARN for severe clamps, DBUG for silent noise clamps. No-op when empty.

Definition at line 48 of file ClampingStats.cpp.

49{
50 if (n_severe_values > 0)
51 {
52 WARN(
53 "Clamped {:d} concentration value(s) more negative than the "
54 "warning threshold ({:g} mol/kgw) to zero across {:d} chemical "
55 "system(s) before speciation; worst: '{:s}' = {:g} mol/kgw.",
56 n_severe_values, warning_threshold, n_severe_cells,
58 }
59 if (n_values > 0)
60 {
61 DBUG(
62 "PhreeqcIO: clamped {:d} negative concentration value(s) to zero "
63 "across {:d} chemical system(s) before speciation (total clamped: "
64 "{:g} mol/kgw).",
66 }
67}
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:22
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:34

References DBUG(), n_cells, n_severe_cells, n_severe_values, n_values, total_clamped_amount, WARN(), worst_component_name, and worst_negative_value.

Member Data Documentation

◆ n_cells

std::size_t ChemistryLib::PhreeqcIOData::ClampingStats::n_cells = 0

cells with any clamping

Definition at line 29 of file ClampingStats.h.

Referenced by operator+=(), report(), and ChemistryLib::PhreeqcIOData::setAqueousSolution().

◆ n_severe_cells

std::size_t ChemistryLib::PhreeqcIOData::ClampingStats::n_severe_cells = 0

cells with a severe clamp

Definition at line 31 of file ClampingStats.h.

Referenced by operator+=(), report(), and ChemistryLib::PhreeqcIOData::setAqueousSolution().

◆ n_severe_values

std::size_t ChemistryLib::PhreeqcIOData::ClampingStats::n_severe_values = 0

total severe values clamped

Definition at line 32 of file ClampingStats.h.

Referenced by clamp(), operator+=(), report(), and ChemistryLib::PhreeqcIOData::setAqueousSolution().

◆ n_values

std::size_t ChemistryLib::PhreeqcIOData::ClampingStats::n_values = 0

total values clamped

Definition at line 30 of file ClampingStats.h.

Referenced by clamp(), operator+=(), report(), and ChemistryLib::PhreeqcIOData::setAqueousSolution().

◆ total_clamped_amount

double ChemistryLib::PhreeqcIOData::ClampingStats::total_clamped_amount = 0.0

Definition at line 33 of file ClampingStats.h.

Referenced by clamp(), operator+=(), and report().

◆ worst_component_name

std::string_view ChemistryLib::PhreeqcIOData::ClampingStats::worst_component_name

aliases Component::name

Definition at line 28 of file ClampingStats.h.

Referenced by clamp(), operator+=(), and report().

◆ worst_negative_value

double ChemistryLib::PhreeqcIOData::ClampingStats::worst_negative_value = 0.0

Definition at line 34 of file ClampingStats.h.

Referenced by clamp(), operator+=(), and report().


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