# [Gmsh] Size functions in gmsh

Christophe Geuzaine cgeuzaine at ulg.ac.be
Thu Nov 20 08:03:07 CET 2008

```Srinath Madhavan wrote:
> Hi all,
>
> Is it possible to define a virtual line/curve in the center of a unit cube and get gmsh to refine the mesh all around the line/curve and coarsen the mesh as it moves away from the line toward the walls?
>
> In gambit, I would simply create a virtual line/curve and apply a size function to it. How would I do this in gmsh?

Here's an example:

// a cube
lc = 0.3;
Point(1) = {0, 0, 0, lc};
Point(2) = {1, 0,  0, lc} ;
Point(3) = {1, 1, 0, lc} ;
Point(4) = {0, 1, 0, lc} ;
Line(1) = {1,2} ;
Line(2) = {3,2} ;
Line(3) = {3,4} ;
Line(4) = {4,1} ;
Line Loop(5) = {4,1,-2,3} ;
Plane Surface(6) = {5} ;
Extrude {0,0,1} { Surface{6}; }

// the "virtual" curve
Point(15) = {0.1, 0.3, 0.5};
Point(16) = {0.2, 0.3, 0.3};
Point(17) = {0.3, 0.2, 0.3};
Point(18) = {0.4, 0.1, 0.4};
Point(19) = {0.5, 0.2, 0.4};
Spline(29) = {15, 16, 17, 18, 19};

// Attractor field returns the distance to the curve (actually, the
// distance to 100 equidistant points on the curve)
Field[1] = Attractor;
Field[1].NNodesByEdge = 100;
Field[1].EdgesList = {29};

// Matheval field returns "distance squared + lc/20"
Field[2] = MathEval;
Field[2].F = Sprintf("F1^2 + %g", lc / 20);

// Use the minimum of "distance squared + lc/20" and the char lengths
// defined at geometrical points as the new char length
Background Field = 2;

>
> Thanks & Best Regards,
>
> Free as in Freedom. May the source be with you!
>
>
>
>
> _______________________________________________
> 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

```