specfem::units Parsing

AnyQuantity

using specfem::units::AnyQuantity = std::variant<Dimensionless, Seconds, Hertz, Omega, Meters, Kilometers, MetersPerSecond, KilometersPerSecond, Radians, Grams, Kilograms, GramPerCubicMeter, KilogramPerCubicMeter, Pascal, Megapascal, DyneCentimeter, NewtonMeter>

Runtime variant of all supported physical quantity types.

Holds exactly one of the known Quantity specializations, allowing quantities parsed from strings to be stored without knowing the concrete type at compile time. Use quantity_cast<To>() to recover a statically-typed value.

See also

parse()

See also

quantity_cast()

parse

inline AnyQuantity specfem::units::parse(std::string_view s)

Parse a string representation of a physical quantity.

The string must contain a decimal number (including optional sign and scientific notation) optionally separated from a unit symbol by whitespace, e.g.:

parse("20.0 Hz")    // Hertz(20.0)
parse("1.5 km/s")   // KilometersPerSecond(1.5)
parse("10.0 ms")    // Seconds(0.01)
parse("2.0 kHz")    // Hertz(2000.0)
parse("20.0Hz")     // Hertz(20.0)  — no whitespace is fine

Supported scaling symbols are SI prefixes: k ( \( \times 10^3 \)), M ( \( \times 10^6 \)), m ( \( \times 10^{-3} \)), u/mu/µ ( \( \times 10^{-6} \)). The table below shows a non-exhaustive list of supported unit symbols; any symbol not in the table may still be parsed if the SI prefix and base unit are both supported.

(Some) supported unit symbols (case-sensitive):

Category

Symbols

Dimensionless

1

Time

s, ms, us, µs

Frequency

Hz, kHz, MHz, mHz

Angular freq

rad/s

Angle

rad

Length

m, km

Velocity

m/s, km/s

Mass

g, kg

Density

g/m3, kg/m3

Pressure

Pa, kPa, MPa, GPa

For unit strings not in the table above, an SI prefix (k, M, m, µ/u/mu) is stripped and the remainder is looked up in the same table.

Parameters:

s – Input string.

Throws:

std::invalid_argument – on malformed number or unknown unit.

Returns:

AnyQuantity variant holding the parsed quantity.

quantity_cast

Warning

doxygenfunction: Cannot find function “specfem::units::quantity_cast” in doxygen xml output for project “specfem++” from directory: _build/doxygen/xml

Warning

doxygenfunction: Cannot find function “specfem::units::quantity_cast” in doxygen xml output for project “specfem++” from directory: _build/doxygen/xml