Coder Social home page Coder Social logo

Comments (4)

akeeste avatar akeeste commented on June 21, 2024 2

@ryancoe Good idea, the python workflow I use to get around this issue is below. The 'body' object is a Capytaine Floating Body, though of course these parameters could be input however required. For reference, my entire Capytaine workflow can be found in the WEC-Sim repo here.

I'll work on a PR to implement this in meshmagick and resolve this and issue #7 simultaneously.

import meshmagick.mesh as mmm
import meshmagick.hydrostatics as mmhs

# use meshmagick to compute hydrostatic stiffness matrix
       # NOTE: meshmagick currently has issue if a body is completely submerged (e.g. OSWEC base)
       # See issues #7, #19 on meshmagick GitHub page.
       # use try-except statement to catch this error and use alternate function for cb/vo
body_mesh = mmm.Mesh(body.mesh.vertices, body.mesh.faces, name=body.mesh.name)
try:
    body_hs = mmhs.Hydrostatics(working_mesh=body_mesh,
                                cog=body.center_of_mass,
                                rho_water=1023.0,
                                grav=9.81)
    vo = body_hs.displacement_volume
    cb = body_hs.buoyancy_center
    khs = body_hs.hydrostatic_stiffness_matrix
except:
    # Exception if body is fully submerged.
    # if fully submerged:
        # stiffness is 0 as small displacements do not change the displaced volume or hydrostatic force
        # displaced volume is the total mesh volume
        # center of buoyancy is equal to the center of gravity of the mesh with a constant density 
    vo = body_mesh.volume
    khs = np.zeros((3,3))
    inertia = body_mesh.eval_plain_mesh_inertias()
    cb = inertia.gravity_center

from meshmagick.

ryancoe avatar ryancoe commented on June 21, 2024

@akeeste - Not sure if you already solved this, but I recently stumbled across a workable solution using the methods in meshmagick that generate RigidBodyInertia objects. For example, you can use the eval_plain_mesh_inertias method as follows.

def eval_plain_mesh_inertias(self, rho_medium=1023.):

from meshmagick.mmio import load_mesh
from meshmagick.mesh import Mesh
import pygmsh
import pytest

r = 1
geom = pygmsh.opencascade.Geometry()
sphere = geom.add_ball([0,0,-1], r)
mshArgs = ['-clscale', str(0.25),
           '-clcurv', str(360/50)]

fbname = 'mmtest'
_ = pygmsh.generate_mesh(geom,
                            dim=2,
                            extra_gmsh_arguments=mshArgs,
                            remove_lower_dim_cells=True,
                            geo_filename=fbname + '.geo',
                            msh_filename=fbname + '.stl',
                            mesh_file_type="stl")

mesh = Mesh(*load_mesh(fbname + '.stl', 'stl'))


inertia = mesh.eval_plain_mesh_inertias()
cob = inertia.gravity_center

assert pytest.approx(-1, rel=1e-4) == cob[2]

image

from meshmagick.

akeeste avatar akeeste commented on June 21, 2024

@ryancoe Thanks for pointing this out! I hadn't found a solution for this yet, this is very helpful. Now in the instance where the body is fully submerged, I can catch the hydrostatics error and just use the mesh to get the cb.

from meshmagick.

ryancoe avatar ryancoe commented on June 21, 2024

@akeeste - Happy to help. Would you mind posting an example of your workflow here? Or (even better) submit a PR that would make this seamless?

from meshmagick.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.