Cannot get the correct surface area
I would like to get the surface area by writing the API. I wrote a test code based on some comments online but it cannot give me the result. Please find the codes below:
gmsh.initialize()
gmsh.option.setNumber("General.Terminal", 0)
gmsh.model.add("example")
lc = 0.05
gmsh.model.geo.addPoint( -1.0, -1.0, 0, lc, 1)
gmsh.model.geo.addPoint( 1.0, -1.0, 0, lc, 2)
gmsh.model.geo.addPoint( 1.0, 1.0, 0, lc, 3)
gmsh.model.geo.addPoint( -1.0, 1.0, 0, lc, 4)
gmsh.model.geo.addLine( 1, 2, 1)
gmsh.model.geo.addLine( 2, 3, 2)
gmsh.model.geo.addLine( 3, 4, 3)
gmsh.model.geo.addLine( 4, 1, 4)
gmsh.model.geo.addCurveLoop([1,2,3,4],1)
gmsh.model.geo.addPlaneSurface([1], 1)
gmsh.model.geo.synchronize()
p = gmsh.model.addPhysicalGroup(2, [1])
gmsh.model.mesh.generate(2)
gmsh.model.mesh.setOrder(2)
gmsh.plugin.run("NewView")
gmsh.plugin.setNumber("MeshVolume", "Dimension", 2)
gmsh.plugin.setNumber("MeshVolume", "Physical", p)
gmsh.plugin.run("MeshVolume")
views = gmsh.view.getTags()
_, _, data = gmsh.view.getListData(views[-1])
volume = data[0][-1]
mshfile = 'test.msh'
gmsh.write(mshfile)
gmsh.finalize()
print (volume)
The error is that "data" is empty. I guess that the MeshVolume has not been associated with the views. I also tried to get the surface area from GUI, the result is still not right. The above codes generate a square with an area equal to 1, but it gives me a very small number when I used Plugin->Mesh volume.
Any suggestions or comments are greatly appreciated.
Edited by Célestin Marot