yade-dev team mailing list archive
-
yade-dev team
-
Mailing list archive
-
Message #11894
[Bug 1427380] [NEW] Inertia calculation is not correct for box bodies!
Public bug reported:
Hi,
I'm using Yade 2015-02-20.git-0e42755 version.
The inertia calculation for box bodies in utils.py has a problem.
We need to have the following equation as we have in Shop_01.cpp:
body->state->inertia=Vector3r(mass*(4*extents[1]*extents[1]+4*extents[2]*extents[2])/12.,mass*(4*extents[0]*extents[0]+4*extents[2]*extents[2])/12.,mass*(4*extents[0]*extents[0]+4*extents[1]*extents[1])/12.);
However, in py/utils.py the equation is using density instead of mass. This, obviously, give an wrong value of inertia for the boxes.
There're two issues:
1- It doesn't include the 1/12 coefficient:
def box(center,extents,orientation=Quaternion(1,0,0,0),dynamic=None,fixed=False,wire=False,color=None,highlight=False,material=-1,mask=1):
"""Create box (cuboid) with given parameters.
:param Vector3 extents: half-sizes along x,y,z axes
See :yref:`yade.utils.sphere`'s documentation for meaning of other parameters."""
b=Body()
b.shape=Box(extents=extents,color=color if color else randomColor(),wire=wire,highlight=highlight)
V=8*extents[0]*extents[1]*extents[2]
geomInert=Vector3(4*(extents[1]**2+extents[2]**2),4*(extents[0]**2+extents[2]**2),4*(extents[0]**2+extents[1]**2))
_commonBodySetup(b,V,geomInert,material,pos=center,dynamic=dynamic,fixed=fixed)
b.state.ori=orientation
b.mask=mask
b.aspherical=True
return b
2- It is using density instead of mass.
def _commonBodySetup(b,volume,geomInertia,material,pos,noBound=False,resetState=True,dynamic=None,fixed=False):
"""Assign common body parameters."""
if isinstance(material,int):
if material<0 and len(O.materials)==0: O.materials.append(defaultMaterial());
b.mat=O.materials[material]
elif isinstance(material,str): b.mat=O.materials[material]
elif isinstance(material,Material): b.mat=material
elif callable(material): b.mat=material()
else: raise TypeError("The 'material' argument must be None (for defaultMaterial), string (for shared material label), int (for shared material id) or Material instance.");
## resets state (!!)
if resetState: b.state=b.mat.newAssocState()
mass=volume*b.mat.density
b.state.mass,b.state.inertia=mass,geomInertia*b.mat.density
b.state.pos=b.state.refPos=pos
b.bounded=(not noBound)
if dynamic!=None:
import warnings
warnings.warn('dynamic=%s is deprecated, use fixed=%s instead'%(str(dynamic),str(not dynamic)),category=DeprecationWarning,stacklevel=2)
fixed=not dynamic
b.state.blockedDOFs=('xyzXYZ' if fixed else '')
** Affects: yade
Importance: Undecided
Status: New
--
You received this bug notification because you are a member of Yade
developers, which is subscribed to Yade.
https://bugs.launchpad.net/bugs/1427380
Title:
Inertia calculation is not correct for box bodies!
Status in Yet Another Dynamic Engine:
New
Bug description:
Hi,
I'm using Yade 2015-02-20.git-0e42755 version.
The inertia calculation for box bodies in utils.py has a problem.
We need to have the following equation as we have in Shop_01.cpp:
body->state->inertia=Vector3r(mass*(4*extents[1]*extents[1]+4*extents[2]*extents[2])/12.,mass*(4*extents[0]*extents[0]+4*extents[2]*extents[2])/12.,mass*(4*extents[0]*extents[0]+4*extents[1]*extents[1])/12.);
However, in py/utils.py the equation is using density instead of mass. This, obviously, give an wrong value of inertia for the boxes.
There're two issues:
1- It doesn't include the 1/12 coefficient:
def box(center,extents,orientation=Quaternion(1,0,0,0),dynamic=None,fixed=False,wire=False,color=None,highlight=False,material=-1,mask=1):
"""Create box (cuboid) with given parameters.
:param Vector3 extents: half-sizes along x,y,z axes
See :yref:`yade.utils.sphere`'s documentation for meaning of other parameters."""
b=Body()
b.shape=Box(extents=extents,color=color if color else randomColor(),wire=wire,highlight=highlight)
V=8*extents[0]*extents[1]*extents[2]
geomInert=Vector3(4*(extents[1]**2+extents[2]**2),4*(extents[0]**2+extents[2]**2),4*(extents[0]**2+extents[1]**2))
_commonBodySetup(b,V,geomInert,material,pos=center,dynamic=dynamic,fixed=fixed)
b.state.ori=orientation
b.mask=mask
b.aspherical=True
return b
2- It is using density instead of mass.
def _commonBodySetup(b,volume,geomInertia,material,pos,noBound=False,resetState=True,dynamic=None,fixed=False):
"""Assign common body parameters."""
if isinstance(material,int):
if material<0 and len(O.materials)==0: O.materials.append(defaultMaterial());
b.mat=O.materials[material]
elif isinstance(material,str): b.mat=O.materials[material]
elif isinstance(material,Material): b.mat=material
elif callable(material): b.mat=material()
else: raise TypeError("The 'material' argument must be None (for defaultMaterial), string (for shared material label), int (for shared material id) or Material instance.");
## resets state (!!)
if resetState: b.state=b.mat.newAssocState()
mass=volume*b.mat.density
b.state.mass,b.state.inertia=mass,geomInertia*b.mat.density
b.state.pos=b.state.refPos=pos
b.bounded=(not noBound)
if dynamic!=None:
import warnings
warnings.warn('dynamic=%s is deprecated, use fixed=%s instead'%(str(dynamic),str(not dynamic)),category=DeprecationWarning,stacklevel=2)
fixed=not dynamic
b.state.blockedDOFs=('xyzXYZ' if fixed else '')
To manage notifications about this bug go to:
https://bugs.launchpad.net/yade/+bug/1427380/+subscriptions
Follow ups
References