LHEEA / meshmagick

A command line tool and a python package to manipulate hydrodynamics meshes
GNU General Public License v3.0
48 stars 27 forks source link

set COG and calc moments of inertia #22

Closed ryancoe closed 3 years ago

ryancoe commented 3 years ago

Allows user to set the location of the center of gravity (gravity_center) and use this for calculating the moments of inertia.

For example

```python import meshmagick.mmio as mmio from meshmagick.mesh import Mesh from math import pi, fabs import pytest # analytic solution vertices, faces = mmio.load_VTP('meshmagick/tests/data/Cylinder.vtp') cylinder = Mesh(vertices, faces) xmin, xmax, ymin, ymax, zmin, zmax = cylinder.axis_aligned_bbox R = (xmax-xmin)/2. h = zmax-zmin V = pi*R**2*h Ixx = Iyy = V*(R**2+h**2/3)/4 Izz = V*R**2/2 # parallel axis theorem to find MOI at base of cylinder Ixx_base = Ixx + V*(h/2)**2 # use meshmagick to find moments of inertia inertia = cylinder.eval_plain_mesh_inertias(rho_medium=1.) # shift calculation to new cog (at base of cylinder) inertia.set_cog((0,0,-h/2)) inertia.shift_at_cog() assert pytest.approx(Ixx_base, rel=1e-1) == inertia.xx ``` image

ryancoe commented 3 years ago

All tests passed

$ pytest meshmagick/tests -q --disable-pytest-warnings
..............................                                                                                                                                       [100%]
30 passed, 3408 warnings in 13.29s
frongere commented 3 years ago

Hi Ryan,

Thank you for this PR! That was indeed needed. And my apologies for the late action (quite busy) For your information, I worked the last few days on a far much better implementation for the hydrostatics module. Now data of the hydrostatics report are expressed in the initial vessel frame, not in a frame obtained after successive iterations to the Newton-Raphson solver. The hydrostatic stiffness matrix is well expressed with respect to COG/buoyancy centre and no more with respect to a frame origin.

BR