Matter and normalization
Normalization
Norm::NUMBER and Norm::NUMBER_FRACTION interpret component amounts as
number or count weights. Norm::NUMBER_FRACTION is the default for
Material. Let \(p_i\) be a number weight, \(m_i\) a component
mass, and \(\rho\) a mass density:
The raw Norm::NUMBER mode retains the supplied batch size, so
2 <H2O> 3 <NaCl> has a reference count of five formula units. Fraction
modes normalize the number fractions to one but retain the same physical
batch-mass calculation.
For Norm::MASS_FRACTION, let \(w_i\) be a mass weight:
Here \(\bar m\) is the mean species mass and get_composite_mass() returns
that mean. This makes mass-fraction mixtures dimensionally consistent when a
density is supplied.
Component weights and their accumulated sums must be finite. Values outside the supported numeric range are rejected rather than returned as infinite counts or undefined fractions.
Matter semantics
MatterSpec uses std::optional<puq::Quantity> so an omitted value is
distinct from a supplied zero. Each input must contain a single value;
arrays with multiple entries are rejected. MAT derives missing quantities when enough
independent information is present:
mass density and volume determine mass;
mass and volume determine mass density;
mass and mass density determine volume;
mass density and the reference mass determine number density.
Inconsistent supplied and derived quantities raise mat::MatterException.
Supplying volume alone leaves mass and density unset rather than guessing.
Supplying a density for an empty composition is also rejected.
Material::add() and Substance::add() regenerate the composition and
derive matter values again from the original MatterSpec. Thus a supplied
mass density stays fixed while the number density follows the new reference
mass. If both densities were supplied and the new composition makes them
inconsistent, the addition raises an exception and leaves the object intact.
Composition and derived properties are encapsulated. Use add() to change
composition and set_matter(MatterSpec) to replace physical constraints.
These operations validate a copy before updating the object; invalid inputs
leave the original state intact. set_matter({}) clears matter constraints.
Accessors such as get_composite_mass(), get_reference_count(),
get_mass_density(), and get_number_density() replace direct field
access. Quantities and matter specifications are returned as independent
snapshots, so modifying a returned value cannot change the original object.
components() returns a const map whose references remain valid until the
next object mutation. Typed result records are caller-owned snapshots.
Element, Substance, and Material are final classes. Their Set,
Part, and Matter bases are private implementation details, preventing
updates through base classes that would bypass normalization. To change
isotope selection, formula identity, or normalization mode, construct a new
object with the desired settings.
Substance addition requires matching natural-abundance settings, as material
addition does. A mismatch raises mat::SyntaxException so an operand’s
isotope masses cannot be silently reinterpreted.
Matter inputs and derived values must be finite. Relative consistency checks use a documented tolerance of \(10^{-6}\) so values printed by MAT can be re-entered together, while genuinely contradictory inputs remain rejected.
number_density is the density of reference units. For a substance one
reference unit is a formula unit; for a material it is one mixture reference
batch. total_number_density is the sum of the species number densities.
For a substance the species are its constituent elements, so the total is the
atom density. For a material the species are its substances, so the total is
the formula-unit density of those substances.
Typed results
The data_components(), data_composite(), and data_matter() methods
return value records from snt/mat/data.h. They are programmatic APIs;
string formatting is only a presentation layer. CompositeData::sum is the
reference-batch aggregate. CompositeData::avg and MatterData::avg are
descriptive arithmetic means of their component rows, not physical mixture
means.