Potential Bug in converting Force Units

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
Post Reply
rcase
Posts: 1
Joined: Sat Oct 23, 2021 3:26 pm

Potential Bug in converting Force Units

Post by rcase »

Units.Quantity('1.0 lbf').getValueAs('N') does not produce the correct numerical value - it produces the reciprocal of the correct result instead. The correct numerical result is ~4.448 whereas the actual result produced is 0.22481 which is equal to 1/4.448. I apologize in advance if this issue is covered elsewhere in the forum or as a bug report. I've searched for it but didn't find anything.

To reproduce this result, use the following in the Python Console:
from FreeCAD import Units
Units.Quantity('1.0 lbf').getValueAs('N')

Other units work as expected. For example, Units.Quantity('1.0 in').getValueAs('mm') produces a result of 25.4 which means the same as 1 in = 25.4 mm. Using that same logic, applied to force units, the result produced by FreeCAD implies that 1 lbf = 0.22481 N but that is incorrect as 1 lbf is equivalent ~4.448 N.

This apparent error also appears when using other units that include force units. I first found it when I entered a quantity for fluid density in the CfdOF module using density units of lbf*s^2/in^4.

Can someone please confirm (or refute) this result?

This result occurs in FreeCAD 0.19 on both Ubuntu and Windows platforms.

My FreeCAD version info:
Version: 0.19
Revision Number: --
Release Date: 2021/07/21 08:10:00
Operating System: Ubuntu 20.04.3 LTS
Word Size: 64-bit
Branch: unknown
Hash: 0d9536ed3e8c7f40197b5606e1b7873625e1d6fe
Python version: 2.7.18

In Windows, my version info is:
OS: Windows 10 Version 1803
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.24291 (Git)
Build type: Release
Branch: releases/FreeCAD-0-19
Hash: 7b5e18a0759de778b74d3a5c17eba9cb815035ac
Python version: 3.8.6+
Qt version: 5.15.2
Coin version: 4.0.1
OCC version: 7.5.0
Locale: English/United States (en_US)
GeneFC
Veteran
Posts: 5373
Joined: Sat Mar 19, 2016 3:36 pm
Location: Punta Gorda, FL

Re: Potential Bug in converting Force Units

Post by GeneFC »

This is what I get when I try your recipe.

Capture.PNG
Capture.PNG (2.35 KiB) Viewed 553 times

OS: Windows 7 Version 6.1 (Build 7601: SP 1)
Word size of FreeCAD: 64-bit
Version: 0.20.26155 (Git)
Build type: Release
Branch: master
Hash: 0926a4148bcff11249fd4f56bc30256102ffe105
Python version: 3.8.6+
Qt version: 5.15.2
Coin version: 4.0.1
OCC version: 7.5.0
Locale: English/United States (en_US)

Gene
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Potential Bug in converting Force Units

Post by TheMarkster »

>>> from FreeCAD import Units
>>> Units.Quantity('1.0 lbf').getValueAs('N')
0.22481
>>>

OS: Windows 10 (10.0)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.24267 (Git)
Build type: Release
Branch: master
Hash: b2ca86d8d72b636011a73394bf9bcdedb3b109b7
Python version: 3.8.8
Qt version: 5.12.5
Coin version: 4.0.0
OCC version: 7.4.0
Locale: English/United States (en_US)


But in 0.20:

>>> from FreeCAD import Units
>>> Units.Quantity('1.0 lbf').getValueAs('N')
4.44822
>>>

OS: Windows 10 (10.0)
Word size of FreeCAD: 64-bit
Version: 0.20.25997 (Git)
Build type: Release
Branch: master
Hash: 77b198048a63f1e9ca15eef64c8042d599a14cf3
Python version: 3.8.12
Qt version: 5.12.9
Coin version: 4.0.0
OCC version: 7.5.2
Locale: English/United States (en_US)


Evidently the bug has already been fixed.
heda
Veteran
Posts: 1348
Joined: Sat Dec 12, 2015 5:49 pm

Re: Potential Bug in converting Force Units

Post by heda »

seems like a missing unit test...

something that should be part of 0.19.3, rather than 0.20?

Code: Select all

>>> '.'.join((s for s in App.Version()[:3] if s))
'0.18.4'
>>> from FreeCAD import Units
>>> Units.Quantity('1.0 lbf').getValueAs('N')
0.22481 
>>> 

Code: Select all

>>> '.'.join((s for s in App.Version()[:3] if s))
'0.19.24276 (Git)'
>>> from FreeCAD import Units
>>> Units.Quantity('1.0 lbf').getValueAs('N')
0.22481
>>> 
Post Reply