https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Namespaces | Functions
Units.C File Reference

Go to the source code of this file.

Namespaces

namespace  std
 

Functions

MooseUnits std::pow (const MooseUnits &, int)
 
std::ostream & operator<< (std::ostream &os, const MooseUnits &u)
 

Function Documentation

◆ operator<<()

std::ostream & operator<< ( std::ostream &  os,
const MooseUnits u 
)

Definition at line 568 of file Units.C.

570{
571 bool latex = (os.iword(MooseUnits::geti()) == 1);
572 static const std::vector<std::string> base_unit = {"m", "kg", "s", "A", "K", "at", "cd"};
573
574 if (u._factor != 1.0 || u._base.empty())
575 {
576 os << u._factor;
577 if (!u._base.empty())
578 os << ' ';
579 }
580
581 for (const auto i : index_range(u._base))
582 {
583 os << (i ? (latex ? "\\cdot " : "*") : "");
584
585 const auto & unit = base_unit[int(u._base[i].first)];
586 if (latex)
587 os << "\\text{" << unit << "}";
588 else
589 os << unit;
590
591 if (u._base[i].second != 1)
592 {
593 if (latex)
594 os << "^{" << u._base[i].second << '}';
595 else
596 os << '^' << u._base[i].second;
597 }
598 }
599
600 return os;
601}
void ErrorVector unsigned int
static int geti()
iosteam manipulator helper to toggle latex / text output
Definition Units.C:562
std::vector< std::pair< BaseUnit, int > > _base
base SI units and their exponents
Definition Units.h:118
Real _factor
conversion factor w.r.t. the base SI units
Definition Units.h:109
auto index_range(const T &sizable)