WeBWorK Main Forum

Why Giga newton is not allowed

Why Giga newton is not allowed

by Ever Barbero -
Number of replies: 3

In Webwork 12, why Giga newton is not allowed but Gima Pascal is?

See screenshot below or in: http://forum.cadec-online.com/viewtopic.php?f=9&t=115

The questions are set up with lb, in, psi, N, mm, MPa, to show students various ways to enter units.

Unfortunately, G works for GPa, but not for GN.

The prefix "m" for milli, does not work for anything. See screenshot in http://forum.cadec-online.com/viewtopic.php?f=9&t=115

I know the correct prefix for milli is "m" without a space between the "m" and the base unit because the National Institute of Standards NIST says so. See screenshot in http://forum.cadec-online.com/viewtopic.php?f=9&t=115

I can't say don't use Giga because we have a lot of data in the range of GPa, but if I say that G is a prefix meaning 10^9 and someone uses it for GN in an exam, the student is toast, his answer will be marked WRONG! 

 

Attachment units_problem.png
Tags:
In reply to Ever Barbero

Re: Why Giga newton is not allowed

by Robert Mařík -

Did not use units, but it seems that the code is at https://github.com/openwebwork/pg/blob/master/lib/Units.pm and to allow GN you should add the corresponding lines to the section where multiples of Newton are defined.

Looking at the code, the "mili" prefix should work at least for millimeter and some other units.

Robert

In reply to Robert Mařík

Re: Why Giga newton is not allowed

by Ever Barbero -

Can I just modify the code in my running server, then restart Apache? 

In reply to Ever Barbero

Re: Why Giga newton is not allowed

by Alex Jordan -

Yes, you can do that. It could lead to git conflicts when you upgrade in the future, but it is not too likely.

There is a way to add arbitrary units to the units parser though, via the problem or a macro library. If giganewtons and other things are common for you, perhaps it is worth doing this. See the commentary at the top of:

https://github.com/openwebwork/pg/blob/master/macros/parserNumberWithUnits.pl

for how to add new units. It is something like this:

$newUnits = [

   {name => 'GN', conversion => {factor =>10**9, kg=>1, m=>1, s=>-2}},
   {name => 'TN', conversion => {factor =>10**12, kg=>1, m=>1, s=>-2}},
];

Then make the answer like:

$answer = NumberWithUnits("3 GN",{newUnit=>$newUnits});

As I said, if you;d use this a lot, then it is worth the effort to not put the $newUnits declaration into each problem. Instead you could make a macro library file that loads parserNumberWithUnits.pl and then sets the $newUnits array ref. I'm not immediately sure how you could write the `{newUnit=>$newUnits}` part into the macro library though. A NumberWithUnits object uses some legacy code and I didn't look into how to work with that.