42 {
"*D", { 9.869233E-13,
UnitSI().
m(2) } },
43 {
"*l", { 1e-3,
UnitSI().
m(3) } },
48 {
"min", { 60,
UnitSI().
s() } },
49 {
"h", { 3600,
UnitSI().
s() } },
50 {
"d", { 24*3600,
UnitSI().
s() } },
51 {
"y", { 365.2425*24*3600,
UnitSI().
s() } },
80 for (it=base_units_map.begin(); it!=base_units_map.end(); ++it) {
81 if (it->first.at(0)==
'*') {
82 std::string shortcut = it->first.substr(1);
83 double coef = it->second.coef_;
86 std::string key = prefix_it->first + shortcut;
87 units_map_.insert(std::pair<std::string, DerivedUnit>( key, { coef*prefix_it->second, it->second.unit_ } ));
90 units_map_.insert( std::pair<std::string, DerivedUnit>( it->first, it->second ) );
102 "Specify the unit of an input value. " 103 "Evaluation of the unit formula results into a coeficient and a " 104 "unit in terms of powers of base SI units. The unit must match the" 105 "expected SI unit of the value, while the value provided on the input " 106 "is multiplied by the coefficient before further processing. " 107 "The unit formula have a form:\n" 109 "<UnitExpr>;<Variable>=<Number>*<UnitExpr>;...,\n" 111 "where ```<Variable>``` is a variable name and ```<UnitExpr>``` is a units expression " 112 "which consists of products and divisions of terms.\n\n" 113 "A term has a form: " 114 "```<Base>^<N>```, where ```<N>``` is an integer exponent and ```<Base>``` " 115 "is either a base SI unit, a derived unit, or a variable defined in the same unit formula. " 116 "Example, unit for the pressure head:\n\n" 117 "```MPa/rho/g_; rho = 990*kg*m^-3; g_ = 9.8*m*s^-2```" 121 "Definition of unit." )
135 typedef spirit_namespace::position_iterator< std::string::iterator > PosnIterT;
137 std::string::iterator begin = s.begin();
138 std::string::iterator end = s.end();
140 const PosnIterT posn_begin( begin, end );
141 const PosnIterT posn_end( end, end );
146 spirit_namespace::parse( begin, end,
148 spirit_namespace::space_p );
150 }
catch (ExcInvalidUnit &e) {
151 e << EI_UnitDefinition(s);
164 Formula &formula = unit_data.find(
"")->second;
176 ASSERT_DBG(it != UnitConverter::basic_factors.units_map_.end())(factor.
factor_).error(
"Undefined unit.");
177 coef *= pow(it->second.coef_, factor.
exponent_);
182 coef *= pow(it->second.coef_, factor.
exponent_);
Helper class. Defines basic factors of SI, non-SI and derived units.
UnitsMap units_map_
Define all base and derived units given by their symbol.
UnitData read_unit(std::string s)
Parse and check unit defined in string format.
bool basic_
unit is basic (strict defined in application) / derived (defined by user as formula) ...
static const Input::Type::Record & get_input_type()
UnitSI unit_si() const
Return unit_si_.
void check_unit_data()
Check unit_data_ object.
Definition of unit grammar.
UnitConverter()
Constructor.
void add_converted_unit(Factor factor, UnitData &unit_data, UnitSI &unit_si, double &coef)
Calculates UnitSi and coeficient of Factor, recursively calls this method for user defined formula...
Class manages parsing of user defined field unit.
double convert(std::string actual_unit)
void multiply(const UnitSI &other, int exp=1)
Multiply with power of given unit.
std::string factor_
string represantation of unit or user defined constant
UnitData unit_data() const
Store structure given by parser.
void reset()
Reset UnitSI object (set vector of exponents to zeros and set undef flag)
BasicFactors()
Constructor.
UnitSI & m(int exp=1)
Methods set values of exponents for SI units with similar name.
Class for representation SI units of Fields.
static const BasicFactors basic_factors
Define all base and derived units given by their symbol.