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

Getting Python error when calling meshmagick.hydrostatics.Hidrostatics() #21

Open joaoantoniocardoso opened 3 years ago

joaoantoniocardoso commented 3 years ago

Hi, first I want to say thank you to the developer and contributors of this software/package, I was just looking for a way for computing hydrostatics from Python and finally found it! :smile:

Well, I just executed some of the example lines from cli mentioned in the documentation and all worked fine.

But then I moved to the Python package, but I am facing some trouble here. I tried with both python2.7 and python3.8 using a fresh virtualenv/venv, installing it by running
pip install https://github.com/LHEEA/meshmagick/archive/master.zip.

Minimal example

from meshmagick import mmio, hydrostatics
mesh = mmio.load_VTP("./meshmagick/tests/data/SEAREV.vtp")
hydrostatics.Hydrostatics(mesh)

and got:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "meshmagick/hydrostatics.py", line 143, in __init__
    self.backup['init_mesh'] = working_mesh.copy()
AttributeError: 'tuple' object has no attribute 'copy'

Let me know If you need more information or some help, I am a developer too and I am open to contribute to open source projects :+1:

Thank you!

frongere commented 3 years ago

Hi Joao,

Thank you for using Meshmagick :)

Concerning your problem, just note that the IO functions like load_VTP are not returning a Mesh instance but two arrays V and F containing vertices coordinates and faces definition that are used to instantiate a Mesh object. Something like (not tested) should do the job:

from meshmagick import mmio, hydrostatics, mesh
V, F = mmio.load_VTP("./meshmagick/tests/data/SEAREV.vtp")
mymesh = mesh.Mesh(V, F)
hydrostatics.Hydrostatics(mymesh)

Have a good day, François

joaoantoniocardoso commented 3 years ago

Hi @frongere,

Thank you for your attention, you are absolutely right! Reading the meshmagick_cli.py I ended with the following example. Maybe we could add something like this as a basic usage example?

from meshmagick import mmio, hydrostatics, mesh

V, F = mmio.load_VTP("./meshmagick/tests/data/SEAREV.vtp")
mymesh = mesh.Mesh(V, F)
mymesh.heal_triangles()

hs_solver = hydrostatics.Hydrostatics(mymesh, verbose=True)

disp = 1500
cog = (0, 4, -2)

hs_solver.mass = disp
hs_solver.gravity_center = cog
hs_solver.equilibrate(init_disp=False)

print(hs_solver.get_hydrostatic_report())

hs_solver.show()