Elements and materials

Elements, substances, materials, matter calculations, and typed composition records.

enum class snt::mat::IsotopeSelection : std::uint8_t

Method used to select the isotope of an element.

Values:

enumerator EXPLICIT

An isotope was requested explicitly.

enumerator NATURAL

Natural-abundance weighted isotope distribution.

enumerator DEFAULT

Most abundant isotope, NIST representative isotope, or first table isotope.

enumerator PARTICLE

Proton, neutron, or electron.

std::string_view snt::mat::PT_SOURCE_URL
std::string_view snt::mat::PT_SOURCE_SHA256
std::array<std::string_view, 2> snt::mat::PT_HEADER
std::array<RepresentativeIsotope, 10> snt::mat::PT_REPRESENTATIVE
std::array<Isotope, 354> snt::mat::PT_DATA
size_t snt::mat::PT_NUM_DATA
size_t snt::mat::PT_NUM_REPRESENTATIVE
struct ComponentData

A component of a chemical formula or material mixture.

Dimensional fields describe one unit of the component. number_fraction and mass_fraction describe its contribution to the whole composite.

Public Members

std::string expression

Component expression.

double proportion

Amount supplied by the caller.

double count

Number contribution in one reference batch.

puq::Quantity mass

Mass of one component unit.

double protons

Protons per component unit.

double neutrons

Neutrons per component unit.

double electrons

Electrons per component unit.

double number_fraction

Normalized number fraction.

double mass_fraction

Normalized mass fraction.

bool ion_mass_approximation

Ion binding-energy corrections are omitted.

bool ion_mass_correction

A component uses NIST reference ionization corrections.

struct CompositeData

Composition of a formula or mixture.

sum describes one reference batch. avg is a descriptive arithmetic mean of the component rows and is not a physical mixture mean.

Public Members

std::vector<CompositeRow> components

Component contributions.

CompositeRow sum

Aggregate contribution.

CompositeRow avg

Descriptive arithmetic mean.

struct CompositeRow

One row of a composite composition. Contributions are multiplied by the component count.

Public Members

std::string expression

Component, sum, or avg.

double count

Number contribution in one reference batch.

puq::Quantity mass

Mass contribution.

double protons

Proton contribution.

double neutrons

Neutron contribution.

double electrons

Electron contribution.

double number_fraction

Normalized number fraction.

double mass_fraction

Normalized mass fraction.

bool ion_mass_approximation

A contributing ion omits its binding-energy correction.

bool ion_mass_correction

A contributing ion uses NIST reference ionization corrections.

class Element : private snt::mat::Part<int>, private snt::mat::Matter

An element is a pure substance that consists entirely of one type of atom.

The signed value in braces is the conventional electric charge in units of the elementary charge: H{1+1} is a proton and H{1-1} is a hydride anion. Positive charge removes electrons from the neutral atom; negative charge adds them.

Public Functions

inline const std::string &get_symbol() const
inline unsigned int get_isotope() const
inline int get_charge() const
inline bool get_natural() const
inline IsotopeSelection get_selection() const
inline double get_effective_isotope_number() const
inline double get_natural_abundance_sum() const
inline MatterData data_matter() const

Return matter rows for this atom or free particle.

Element(const std::string &expr, int prop = 1, bool nat = true, const MatterSpec &matter = {})

Construct an element.

Parameters:
  • expr – Element string representation

  • prop – Component proportion in a composite

  • nat – Indicate if the element uses the natural isotope distribution

  • matter – Optional matter inputs

inline double protons() const

Return the number of protons per atom.

inline double neutrons() const

Return the abundance-weighted number of neutrons per atom.

inline double electrons() const

Return the number of electrons per atom or ion.

inline bool uses_ion_mass_approximation() const

Whether the atomic ion mass omits a required binding-energy correction.

inline bool uses_ion_mass_correction() const

Whether a complete NIST reference-element ionization correction was applied.

ElementData data() const

Return a typed view of the element’s physical facts.

std::string to_string() const

Return a string representation of an element instance.

void math_add(Element *other)

Add another instance of the same element.

void math_multiply(Element *other)

Multiply the proportion by another element’s proportion.

Element operator*(int factor) const

Return a copy with the proportion scaled by a scalar factor.

Element operator+(const Element &other) const

Return the sum of two instances of the same element.

void set_matter(const MatterSpec &spec)

Replace matter constraints, derive values, and commit only when consistent.

inline std::optional<puq::Quantity> get_mass() const
inline std::optional<puq::Quantity> get_mass_density() const
inline MatterSpec get_matter_spec() const

Return the original constraints, without derived values.

inline std::optional<puq::Quantity> get_number_density() const
inline std::optional<puq::Quantity> get_total_number_density() const
inline std::optional<puq::Quantity> get_volume() const

Return independent snapshots of derived matter values.

Public Static Functions

static Element from_string(const std::string &expr)

Get an instance of an Element from an expression.

Parameters:

expr – String expression

Returns:

An instance of the Element class

struct ElementData

Physical facts about an element expression.

Public Members

std::string expression

Source expression.

std::string element

Element or particle symbol.

unsigned int declared_isotope

Explicitly requested mass number, or zero.

double effective_isotope_number

Mass number or abundance-weighted mean mass number.

int charge

Conventional electric charge.

puq::Quantity mass

Mass of one atom or particle.

double protons

Number of protons.

double neutrons

Number of neutrons.

double electrons

Number of electrons.

IsotopeSelection selection

Isotope selection method.

bool natural

True for natural-abundance selection.

bool ion_mass_approximation

Ion binding-energy correction is omitted.

bool ion_mass_correction

NIST reference ionization energies were applied.

std::optional<double> applied_ionization_energy_eV

Sum of all required ionization stages.

struct Isotope

Public Members

std::string_view symbol
unsigned int protons
unsigned int isotope_number
double relative_atomic_mass
double natural_abundance
std::optional<double> mass_uncertainty_u
std::optional<double> abundance_uncertainty
bool mass_extrapolated
class Material : private snt::mat::Set<Substance, double>, private snt::mat::Matter

A material represented as a mixture of substances.

Number modes treat amounts as species counts. Mass-fraction mode treats amounts as mass weights and derives the mean species mass from sum(w_i) / sum(w_i / m_i).

Public Functions

Material()

Construct an empty material.

Material(const SubstanceMap &comp, Norm norm = Norm::NUMBER_FRACTION, bool natural = true, const MatterSpec &matter = {})

Construct a material from a map of substances and amounts.

Material(std::initializer_list<SubstanceMap::value_type> comp, Norm norm = Norm::NUMBER_FRACTION, bool natural = true, const MatterSpec &matter = {})

Construct a material from braced substance amounts.

This disambiguates single-entry construction such as Material({{"H2O", 1.0}}) from copy construction.

Material(const SubstanceMap &comp, Norm norm, const MatterSpec &matter, bool natural = true)

Construct a material from a map with optional matter and natural selection.

Material(const std::string &expr, Norm norm = Norm::NUMBER_FRACTION, bool natural = true, const MatterSpec &matter = {})

Construct a material from an expression such as 0.2 <H2O> 0.8 <NaCl>.

Material(const std::string &expr, Norm norm, const MatterSpec &matter, bool natural = true)

Construct a material from an expression with matter and natural selection.

Material(const std::string &expr, bool natural, Norm norm, const MatterSpec &matter = {})

Construct a material with Python-style natural-before-norm argument order.

void add(const std::string &expr, double prop = 1.0)

Add a substance and recompute composition and matter from the supplied inputs.

inline std::vector<ComponentData> data_components() const

Return substance rows with normalized composition fractions.

inline CompositeData data_composite() const

Return mixture composition contributions and summaries.

inline MatterData data_matter() const

Return species and aggregate matter values.

double protons() const

Return the number of protons in one reference mixture batch.

double neutrons() const

Return the abundance-weighted number of neutrons in one reference mixture batch.

double electrons() const

Return the number of electrons in one reference mixture batch.

std::string to_string() const

Return a compact description of the mixture amounts.

Material operator*(double factor) const

Return a material with all input amounts scaled by a factor.

Material operator+(const Material &other) const

Return a material with merged amounts from both materials.

void set_matter(const MatterSpec &spec)

Replace matter constraints, derive values, and commit only when consistent.

inline std::optional<puq::Quantity> get_mass() const
inline std::optional<puq::Quantity> get_mass_density() const
inline MatterSpec get_matter_spec() const

Return the original constraints, without derived values.

inline std::optional<puq::Quantity> get_number_density() const
inline std::optional<puq::Quantity> get_total_number_density() const
inline std::optional<puq::Quantity> get_volume() const

Return independent snapshots of derived matter values.

class Matter

Matter is anything that has mass and occupies space.

Optional fields distinguish omitted values from supplied zeros. number_density is the density of reference units (atoms, formula units, or mixture reference batches). total_number_density is the sum of species number densities.

Subclassed by snt::mat::Element, snt::mat::Material, snt::mat::Substance

Public Functions

inline std::optional<puq::Quantity> get_volume() const

Return independent snapshots of derived matter values.

inline std::optional<puq::Quantity> get_mass() const
inline std::optional<puq::Quantity> get_mass_density() const
inline std::optional<puq::Quantity> get_number_density() const
inline std::optional<puq::Quantity> get_total_number_density() const
inline MatterSpec get_matter_spec() const

Return the original constraints, without derived values.

struct MatterData

Composite matter values and component rows.

Public Members

std::optional<puq::Quantity> volume

Volume, if supplied or derived.

std::optional<puq::Quantity> mass

Material mass, if supplied or derived.

std::optional<puq::Quantity> mass_density

Material mass density.

std::optional<puq::Quantity> number_density

Reference-unit number density.

std::optional<puq::Quantity> total_number_density

Sum of species number densities.

std::vector<MatterRow> components

Species rows.

MatterRow sum

Aggregate row.

MatterRow avg

Descriptive arithmetic mean.

struct MatterRow

One row of component matter values. A value is absent when its input is unknown.

Public Members

std::string expression

Component, sum, or avg.

std::optional<puq::Quantity> number_density

Species number density.

std::optional<puq::Quantity> mass_density

Species mass density.

std::optional<puq::Quantity> count

Species count in the volume.

std::optional<puq::Quantity> mass

Species mass in the volume.

struct MatterSpec

Optional physical inputs for a matter calculation.

Public Members

std::optional<puq::Quantity> number_density

Reference-unit number density.

std::optional<puq::Quantity> mass_density

Material mass density.

std::optional<puq::Quantity> volume

Volume.

std::optional<puq::Quantity> mass

Total material mass.

struct MatterSpecies

A species used to derive component matter values.

Public Members

std::string expression

Species expression.

double number_fraction

Normalized number fraction.

puq::Quantity mass

Mass of one species unit.

template<typename PROPORTION>
class Part

A part is an individual substance or part that combines with others to form a larger whole

Template Parameters:

PROPORTION – proportion coefficient type (double or integer)

Public Functions

inline PROPORTION get_proportion() const

Return the component amount used by the containing composite.

inline const std::string &get_expression() const

Return the source expression of this part.

inline bool has_component_mass() const

Return whether a component mass has been assigned.

puq::Quantity get_component_mass() const

Return an independent mass snapshot, or throw when it has not been assigned.

struct RepresentativeIsotope

Public Members

std::string_view symbol
unsigned int isotope_number
template<typename MEMBER, typename PROPORTION>
class Set

A collection of physical members and their proportions.

Number modes interpret proportions as counts. Mass-fraction mode interprets them as mass weights. In both cases normalized number and mass fractions are available and the reference-batch mass is computed dimensionally.

Template Parameters:
  • MEMBER – Type of set members

  • PROPORTION – Proportion data type

Public Types

using PartMap = std::map<std::string, PROPORTION>

Map of parts and their proportions.

using MemberMap = std::map<std::string, MEMBER>

Map of materialized members.

Public Functions

inline const std::string &get_expression() const

Return the source composition expression.

inline bool get_natural() const

Return the isotope-selection policy for unspecified isotopes.

inline Norm normalization() const

Return the interpretation of component amounts.

inline double get_reference_count() const

Return the species count in one reference batch.

inline puq::Quantity get_composite_mass() const

Return an independent copy of the reference-batch mass.

inline bool empty() const

Return whether this set has no members.

inline const MemberMap &components() const

Return the stored members in deterministic expression order.

inline bool uses_ion_mass_approximation() const

Whether a nonzero component uses an approximate atomic ion mass.

inline bool uses_ion_mass_correction() const

Whether a nonzero component uses NIST reference ionization corrections.

inline double reference_count_of(const MEMBER &member) const

Number contribution of a member to one reference batch.

inline double number_fraction(const MEMBER &member) const

Normalized number fraction of a member.

inline double mass_fraction(const MEMBER &member) const

Normalized mass fraction of a member.

inline std::vector<ComponentData> data_components() const

Return component rows with normalized fractions.

inline CompositeData data_composite() const

Return component contributions plus aggregate and descriptive average rows.

inline std::vector<MatterSpecies> matter_species() const

Return species fractions and masses used for matter calculations.

class Substance : private snt::mat::Set<Element, int>, private snt::mat::Part<double>, private snt::mat::Matter

A form of matter with uniform and definite composition and distinct physical and chemical properties.

Public Functions

Substance()

Construct an empty substance.

explicit Substance(double num)

Substance class constructor from a scalar number

Parameters:

num – Number

Substance(const ElementMap &comp, double prop = 1, bool nat = true, const MatterSpec &matter = {})

Substance class constructor from a map of components and their proportions

Parameters:
  • comp – Map of components and their proportions

  • prop – Component proportion in a Composite

  • nat – Indicate if substance atoms should use natural abundance

Substance(std::initializer_list<ElementMap::value_type> comp, double prop = 1, bool nat = true, const MatterSpec &matter = {})

Construct a substance from braced element counts.

This disambiguates single-entry construction such as Substance({{"H", 2}}) from copy construction.

Substance(const std::string &expr, double prop = 1, bool nat = true, const MatterSpec &matter = {})

Substance class constructor from an expression

Parameters:
  • expr – Element string representation

  • prop – Component proportion in a Composite

  • nat – Indicate if substance atoms should use natural abundance

std::string to_string() const

Convert element to a string

Returns:

String representation of a substance

void add(const std::string &expr, int prop = 1)

Add an element, regenerate the formula, and recompute matter from supplied inputs.

inline std::string formula() const

Return the formula expression of this substance.

double protons() const

Return the number of protons in one formula unit.

double neutrons() const

Return the abundance-weighted number of neutrons in one formula unit.

double electrons() const

Return the number of electrons in one formula unit.

inline std::vector<ComponentData> data_components() const

Return element rows with normalized composition fractions.

inline CompositeData data_composite() const

Return formula composition contributions and summaries.

inline MatterData data_matter() const

Return component and aggregate matter values.

Substance operator*(double factor) const

Return a copy with a different component proportion.

Substance operator+(const Substance &other) const

Return merged element compositions; requires matching natural-abundance settings.

void set_matter(const MatterSpec &spec)

Replace matter constraints, derive values, and commit only when consistent.

inline std::optional<puq::Quantity> get_mass() const
inline std::optional<puq::Quantity> get_mass_density() const
inline MatterSpec get_matter_spec() const

Return the original constraints, without derived values.

inline std::optional<puq::Quantity> get_number_density() const
inline std::optional<puq::Quantity> get_total_number_density() const
inline std::optional<puq::Quantity> get_volume() const

Return independent snapshots of derived matter values.