> On 8 Mar 2019, at 17:50, Johannes <[email protected]> wrote:
> 
> Hello,
> 
> thanks! I use the plugin in my script, but unfortunately I encounter a 
> problem:
> I build various parametric meshes in a row, e.g. in the function 
> `build_model` (see following source code). The second function call fails in 
> the gmsh.view.getListData function with a non-zero return code.
> 

It'a bit weird to initialize/finalize gmsh several times, but indeed you can do 
so. The issue is that the global numbering of views is not reset (we will 
correct that). So to get the correct view tag you could do:

import gmsh

def build_model():
   gmsh.initialize()

   gmsh.option.setNumber("General.Terminal", 1)

   s = gmsh.model.occ.addRectangle(0,0,0, 3,2)
   gmsh.model.occ.synchronize()
   p = gmsh.model.addPhysicalGroup(2, [s])
   gmsh.model.mesh.generate(2)

   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]

   gmsh.finalize()

   return volume


vol1 = build_model()
vol2 = build_model()



> 
> 
> import gmsh
> 
> def build_model():
>    gmsh.initialize()
> 
>    gmsh.option.setNumber("General.Terminal", 1)
> 
>    s = gmsh.model.occ.addRectangle(0,0,0, 3,2)
>    gmsh.model.occ.synchronize()
>    p = gmsh.model.addPhysicalGroup(2, [s])
>    gmsh.model.mesh.generate(2)
> 
>    gmsh.plugin.setNumber("MeshVolume", "Dimension", 2)
>    gmsh.plugin.setNumber("MeshVolume", "Physical", p)
>    gmsh.plugin.run("MeshVolume")
> 
>    _, _, data = gmsh.view.getListData(0)
>    volume = data[0][-1]
> 
>    gmsh.finalize()
> 
>    return volume
> 
> 
> vol1 = build_model()
> vol2 = build_model()
> 
> 
> 
> Is there a way to fix this?
> 
> Kind regards,
> Johannes
> 
> 
> 
> 
>>> On 8 Mar 2019, at 17:19, Johannes [email protected] wrote:
>>> Hello,
>>> thank you very much for your help!
>>> The plugin works great, but I still have a question regarding its 
>>> implementation: What's the idea behind pushing the coordinates of the 
>>> models bounding box center also into the vector `data2->SP`?
>> 
>> Just so that when execute the plugin interactively, you'll see the value in 
>> the middle of the volume.
>> 
>> Christophe
>> 
>>> Kind regards,
>>> Johannes
>>> 
>>>>> On 6 Mar 2019, at 17:46, Max Orok [email protected] wrote:
>>>>> Hello Johannes,
>>>>> Volume case:
>>>>> I think you can use the Plugin "MeshVolume" for this, calling it through 
>>>>> the plugin API interface.
>>>>> Here is a link to the implementation:
>>>>> https://gitlab.onelab.info/gmsh/gmsh/blob/master/Plugin/MeshVolume.cpp
>>>> 
>>>> Indeed; I've just modified the implementation a little bit so that it 
>>>> returns a post-processing view with the result (the version in Gmsh 4.2.0 
>>>> only outputs a message). It will work for 1D, 2D and 3D. With the latest 
>>>> development snapshot, you can then just do something like this (here in 
>>>> Python):
>>>> import gmsh
>>>> gmsh.initialize()
>>>> gmsh.option.setNumber("General.Terminal", 1)
>>>> s = gmsh.model.occ.addRectangle(0,0,0, 3,2)
>>>> gmsh.model.occ.synchronize()
>>>> p = gmsh.model.addPhysicalGroup(2, [s])
>>>> gmsh.model.mesh.generate(2)
>>>> gmsh.plugin.setNumber("MeshVolume", "Dimension", 2)
>>>> gmsh.plugin.setNumber("MeshVolume", "Physical", p)
>>>> gmsh.plugin.run("MeshVolume")
>>>> _, _, data = gmsh.view.getListData(0)
>>>> print(data)
>>>> gmsh.finalize()
>>>> 
>>>>> Surface case:
>>>>> Perhaps you could use the Integrate Plugin? I think you would have to 
>>>>> first have to make a physical group of just the 2D boundary elements and 
>>>>> then use the integrate plugin with a value of 1 (see discussion in link 
>>>>> for more info)
>>>>> https://gitlab.onelab.info/gmsh/gmsh/merge_requests/197
>>>> 
>>>> Plugin(Integrate) is indeed also a possibility, that will also work in 1D, 
>>>> 2D and 3D. It's a bit more complicated, tough, as you need to create a 
>>>> post-processing view first (e.g. with "NewView"), then set the value to 1 
>>>> (e.g. with "ModifyComponents"), then hide the parts of the mesh that you 
>>>> don't want consider, and finally call "Integrate". But it's of course more 
>>>> general, as you can integrate any function.
>>>> Cheers,
>>>> Christophe
>>>> 
>>>>> I hope this helps!
>>>>> Max
>>>>> On Wed, Mar 6, 2019 at 11:23 AM Johannes [email protected] wrote:
>>>>> 
>>>>>> Hello,
>>>>>> is there a way to get the surface area or volume of a physical group via 
>>>>>> the Gmsh API?
>>>>>> Kind Regards
>>>>>> Johannes
>>>>>> 
>>>>>> gmsh mailing list
>>>>>> [email protected]
>>>>>> http://onelab.info/mailman/listinfo/gmsh
>>>>> 
>>>>> --
>>>>> Max Orok
>>>>> Contractor
>>>>> www.mevex.com
>>>>> 
>>>>> gmsh mailing list
>>>>> [email protected]
>>>>> http://onelab.info/mailman/listinfo/gmsh
>>>> 
>>>> —
>>>> Prof. Christophe Geuzaine
>>>> University of Liege, Electrical Engineering and Computer Science
>>>> http://www.montefiore.ulg.ac.be/~geuzaine
>> 
>> —
>> Prof. Christophe Geuzaine
>> University of Liege, Electrical Engineering and Computer Science
>> http://www.montefiore.ulg.ac.be/~geuzaine
> 
> 

— 
Prof. Christophe Geuzaine
University of Liege, Electrical Engineering and Computer Science 
http://www.montefiore.ulg.ac.be/~geuzaine




_______________________________________________
gmsh mailing list
[email protected]
http://onelab.info/mailman/listinfo/gmsh

Reply via email to