86{
87 std::vector<std::string> argv;
88 argv.insert(argv.begin(), args.begin(), args.end());
89
90
91 if (argv.size() == 2)
92 {
93 n->setVal(n->val(), hit::Field::Kind::Float);
94 return argv[0];
95 }
96
97
98 if (argv.size() != 4 || (argv.size() >= 3 && argv[2] != "->"))
99 {
100 exp.errors.emplace_back(
"units error: Expected 4 arguments ${units number from_unit -> "
101 "to_unit} or 2 arguments ${units number unit} in '" +
102 n->fullpath() + "'",
103 n);
104 return n->val();
105 }
106
107
110 if (!from_unit.conformsTo(to_unit))
111 {
112 std::ostringstream
err;
113 err <<
"units error: " << argv[1] <<
" (" << from_unit <<
") does not convert to " << argv[3]
114 << " (" << to_unit << ") in '" << n->fullpath() << "'";
115 exp.errors.emplace_back(
err.str(), n);
116 return n->val();
117 }
118
119
120 Real num = MooseUtils::convert<Real>(argv[0]);
121
122
123 std::stringstream ss;
124 ss << std::setprecision(17) << to_unit.convert(num, from_unit);
125
126#ifndef NDEBUG
129 num,
130 ' ',
131 argv[1],
132 " -> ",
133 ss.str(),
134 ' ',
135 argv[3]);
136#endif
137
138
139 n->setVal(n->val(), hit::Field::Kind::Float);
140 return ss.str();
141}
void mooseInfoRepeated(Args &&... args)
Emit an informational message with the given stringified, concatenated args.
Physical unit management class with runtime unit string parsing, unit checking, unit conversion,...
std::string stringify(const T &t)
conversion to string
OStreamProxy err(std::cerr)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real