OpenStudio:utilities
Loading...
Searching...
No Matches
openstudio::Quantity Class Reference

#include <Quantity.hpp>

Public Member Functions

Constructors
 Quantity (const UnitSystem &system=UnitSystem::Mixed)
 
 Quantity (double value, const UnitSystem &system=UnitSystem::Mixed)
 
 Quantity (double value, const Unit &units)
 
 Quantity (const Quantity &q)
 
Quantityoperator= (const Quantity &q)
 
virtual ~Quantity ()=default
 
Value
double value () const
 
void setValue (double newValue)
 Value setter.
 
Units
Unit units () const
 Returns deep copy (clone) of this Quantity's units.
 
UnitSystem system () const
 
bool isTemperature () const
 Returns true if units().optionalCast<TemperatureUnit>().
 
std::vector< std::string > baseUnits () const
 Vector of base units available to the Quantity.
 
int baseUnitExponent (const std::string &baseUnit) const
 Base unit exponent getter.
 
void setBaseUnitExponent (const std::string &baseUnit, int exponent)
 Sets the exponent of a base unit in this Quantity's m_units.
 
std::string standardUnitsString (bool withScale=true) const
 Units in string form.
 
std::string prettyUnitsString (bool withScale=true) const
 Pretty string for this quantity's units.
 
void setPrettyUnitsString (const std::string &str)
 Sets the prettystring for this Quantity's m_units.
 
Scale scale () const
 Scale getter.
 
bool setScale (int scaleExponent)
 Sets the scale to the one registered in ScaleFactory for 10^scaleExponent.
 
bool setScale (const std::string &scaleAbbreviation)
 Sets the scale to the one registered in ScaleFactory under scaleAbbreviation.
 
Temperature Methods

Quantities that have units of temperature need several extra functions to distinguish between absolute and relative measures.

bool isAbsolute () const
 Throws if !units().optionalCast<TemperatureUnit>().
 
bool isRelative () const
 Throws if !units().optionalCast<TemperatureUnit>().
 
void setAsAbsolute ()
 Set temperature as absolute.
 
void setAsRelative ()
 Set temperature as relative.
 
IP Methods
void lbmToLbf ()
 Conversions for pounds mass to pounds force.
 
void lbfToLbm ()
 Conversions for pounds mass to pounds force.
 

Related Symbols

(Note that these are not member symbols.)

std::ostream & operator<< (std::ostream &os, const Quantity &q)
 
using OptionalQuantity = boost::optional<Quantity>
 
using QuantityVector = std::vector<Quantity>
 

Mathematical Operators

double m_value
 
Unit m_units
 
Quantityoperator+= (const Quantity &rQuantity)
 Add and assign operator.
 
Quantityoperator-= (const Quantity &rQuantity)
 Subtract and assign operator.
 
Quantityoperator*= (const Quantity &rQuantity)
 Multiply and assign operator.
 
Quantityoperator/= (const Quantity &rQuantity)
 Divide and assign operator.
 
Quantityoperator*= (double d)
 Multiply by double.
 
Quantityoperator/= (double d)
 Divide by double.
 
Quantitypow (int expNum, int expDenom=1)
 Raise Quantity to a rational power.
 

Detailed Description

Quantity class defines value, unit pairs.

Units are set at construction and are modified by arithmetic operations. The constructors and assignment operator ensure that this class behaves as "plain old data" (POD) by cloning any units information (to avoid multiple objects pointing to the exact same unit data).

Constructor & Destructor Documentation

◆ Quantity() [1/4]

openstudio::Quantity::Quantity ( const UnitSystem & system = UnitSystem::Mixed)
explicit

◆ Quantity() [2/4]

openstudio::Quantity::Quantity ( double value,
const UnitSystem & system = UnitSystem::Mixed )
explicit

◆ Quantity() [3/4]

openstudio::Quantity::Quantity ( double value,
const Unit & units )

◆ Quantity() [4/4]

openstudio::Quantity::Quantity ( const Quantity & q)

◆ ~Quantity()

virtual openstudio::Quantity::~Quantity ( )
virtualdefault

Member Function Documentation

◆ baseUnitExponent()

int openstudio::Quantity::baseUnitExponent ( const std::string & baseUnit) const

Base unit exponent getter.

Returns 0 if baseUnit not present.

◆ baseUnits()

std::vector< std::string > openstudio::Quantity::baseUnits ( ) const

Vector of base units available to the Quantity.

◆ isAbsolute()

bool openstudio::Quantity::isAbsolute ( ) const

Throws if !units().optionalCast<TemperatureUnit>().

◆ isRelative()

bool openstudio::Quantity::isRelative ( ) const

Throws if !units().optionalCast<TemperatureUnit>().

◆ isTemperature()

bool openstudio::Quantity::isTemperature ( ) const

Returns true if units().optionalCast<TemperatureUnit>().

◆ lbfToLbm()

void openstudio::Quantity::lbfToLbm ( )

Conversions for pounds mass to pounds force.

These functions will throw if !units().optionalCast<IPUnit>().

◆ lbmToLbf()

void openstudio::Quantity::lbmToLbf ( )

Conversions for pounds mass to pounds force.

These functions will throw if !units().optionalCast<IPUnit>().

◆ operator*=() [1/2]

Quantity & openstudio::Quantity::operator*= ( const Quantity & rQuantity)

Multiply and assign operator.

Throws if Quantity is a particular system and rQuantity is not the same system.

◆ operator*=() [2/2]

Quantity & openstudio::Quantity::operator*= ( double d)

Multiply by double.

No impact to units or scale. Does not throw.

◆ operator+=()

Quantity & openstudio::Quantity::operator+= ( const Quantity & rQuantity)

Add and assign operator.

Throws if units are not equal.

◆ operator-=()

Quantity & openstudio::Quantity::operator-= ( const Quantity & rQuantity)

Subtract and assign operator.

Throws if units are not equal.

◆ operator/=() [1/2]

Quantity & openstudio::Quantity::operator/= ( const Quantity & rQuantity)

Divide and assign operator.

Throws if Quantity is a particular system and rQuantity is not the same system.

◆ operator/=() [2/2]

Quantity & openstudio::Quantity::operator/= ( double d)

Divide by double.

No impact to units or scale. Does not throw.

◆ operator=()

Quantity & openstudio::Quantity::operator= ( const Quantity & q)

◆ pow()

Quantity & openstudio::Quantity::pow ( int expNum,
int expDenom = 1 )

Raise Quantity to a rational power.

Throws openstudio::Exception if expDenom is not a common divisor for all baseUnit and scale exponents. Returned scale exponent may differ from expectation based on initialization of openstudio::ScaleFactory, see Scale operators declared in ScaleFactory.hpp.

◆ prettyUnitsString()

std::string openstudio::Quantity::prettyUnitsString ( bool withScale = true) const

Pretty string for this quantity's units.

For instance N = kg*m/s^2.

See also
Unit::prettyUnitsString

◆ scale()

Scale openstudio::Quantity::scale ( ) const

Scale getter.

◆ setAsAbsolute()

void openstudio::Quantity::setAsAbsolute ( )

Set temperature as absolute.

Throws if !units().optionalCast<TemperatureUnit>().

◆ setAsRelative()

void openstudio::Quantity::setAsRelative ( )

Set temperature as relative.

Throws if !units().optionalCast<TemperatureUnit>().

◆ setBaseUnitExponent()

void openstudio::Quantity::setBaseUnitExponent ( const std::string & baseUnit,
int exponent )

Sets the exponent of a base unit in this Quantity's m_units.

This function will throw if baseUnit is not a valid option for this type of unit. A generic Unit allows any base unit to be set.

◆ setPrettyUnitsString()

void openstudio::Quantity::setPrettyUnitsString ( const std::string & str)

Sets the prettystring for this Quantity's m_units.

openstudio::Unit attempts to keep up with prettyStrings, but makes no promises. Precondition: isCompoundUnit(str). Otherwise throws.

◆ setScale() [1/2]

bool openstudio::Quantity::setScale ( const std::string & scaleAbbreviation)

Sets the scale to the one registered in ScaleFactory under scaleAbbreviation.

◆ setScale() [2/2]

bool openstudio::Quantity::setScale ( int scaleExponent)

Sets the scale to the one registered in ScaleFactory for 10^scaleExponent.

◆ setValue()

void openstudio::Quantity::setValue ( double newValue)

Value setter.

◆ standardUnitsString()

std::string openstudio::Quantity::standardUnitsString ( bool withScale = true) const

Units in string form.

LaTeX mathematical formatting–_ for subscripting, ^ for superscripting. Curly braces {} are used for grouping.

See also
Unit::standardUnitsString

◆ system()

UnitSystem openstudio::Quantity::system ( ) const

◆ units()

Unit openstudio::Quantity::units ( ) const

Returns deep copy (clone) of this Quantity's units.

◆ value()

double openstudio::Quantity::value ( ) const

Friends And Related Symbol Documentation

◆ operator<<()

std::ostream & operator<< ( std::ostream & os,
const Quantity & q )
related

◆ OptionalQuantity

using OptionalQuantity = boost::optional<Quantity>
related

◆ QuantityVector

using QuantityVector = std::vector<Quantity>
related

Member Data Documentation

◆ m_units

Unit openstudio::Quantity::m_units
protected

◆ m_value

double openstudio::Quantity::m_value
protected