[Gmsh] Calculation of the area of a plane surface

Christophe Geuzaine cgeuzaine at ulg.ac.be
Thu Apr 2 21:05:26 CEST 2015


> On 02 Apr 2015, at 18:43, Pavel Ponomarev <Pavel.Ponomarev at lut.fi> wrote:
> 
> Hello,
> 
> Is there a way to calculate area of a surface within the .geo file?
> 
> Let's say I have a plane surface defined by a complex shaped line loop 
> 
> 	Line Loop(58) = {23, 47, -15, -14, -13, 18, 24, 21, 22};
> 	Plane Surface(59) = {58};
> 
> Is there a way to save the are in square meters of this Plane Surface to a separate file using printf like:
> 	Printf("%f", Area(59) ) >> "file.txt";
> ?
> 

You'll need to mesh the surface first; then you can simply integrate 1 over the surface, e.g. using Plugin(Integrate). Adding this at the end of your script would do the trick:

Mesh 2; // mesh
Plugin(NewView).Run; // create new post-pro view
Plugin(ModifyComponent).View = 0;
Plugin(ModifyComponent).Expression = "1"; 
Plugin(ModifyComponent).Run; // assign 1 on this view
Plugin(Integrate).Dimension = 2;
Plugin(Integrate).Run; // integrate 1 (only on 2D elements)
Printf("Area = %g", View[1].Max); // print out the result


> Best Regards,
> Pavel Ponomarev
> 
> =================================================
> Dr. Pavel Ponomarev
> Researcher
> Laboratory of Electrical Drives Technology, 
> LUT Energy, Lappeenranta University of Technology
> pavel.ponomarev at lut.fi
> 
> 
> 
> _______________________________________________
> gmsh mailing list
> gmsh at geuz.org
> http://www.geuz.org/mailman/listinfo/gmsh

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