1
$\begingroup$

I'm new to Gmsh and after browsing many sites I haven't found the answer for this silly error.

Using the native language of the software, I'm assigning a value to the Transfinite property of a bunch of lines (with no consecutive ID's) in my model, using this syntax:

value = 10;
For i In [81, 83, 85, 87, 72, 73, 75, 77, 79]
    Transfinite Curve{i} = value;
EndFor

When loading the file, in all the For loops on my script I get the same error message: "syntax error ([)". Documentation states the loop as:

For i In {1:3}
    x~{i} = i;
EndFor

followed by:

The brackets [] permit to extract one item from a list (parentheses can also be used instead of brackets).

It's still not really clear about my case, and the script seems to work but I prefer to be completely sure. Does anyone knows how to do in this case?

Thanks in advance.

$\endgroup$

1 Answer 1

2
$\begingroup$

It seems for-loops in gmsh are made for consecutive numbering only, so I would define an array to map from consecutive index numbers to arbitrary entity numbers.

lc = 1e-2;

Point(1) = {0 ,  0, 0, lc};
Point(2) = {.3,  0, 0, lc};
Point(3) = {.3, .1, 0, lc};
Point(4) = {0 , .1, 0, lc};

Line(1) = {1, 2}; 
Line(2) = {2, 3}; 
Line(3) = {3, 4}; 
Line(4) = {4, 1}; 

Curve Loop(1) = {1, 2, 3, 4}; 
Plane Surface(1) = {1};

long_sides = {1, 3};   // this could be any numbers
long_side_divisions = 10; 
For i In {0:1}   // array indexing starts with zero
  Transfinite Curve(long_sides[i]) = long_side_divisions;
EndFor

short_sides = {2, 4}; 
short_side_divisions = 4; 
For i In {0:1} 
  Transfinite Curve(short_sides[i]) = short_side_divisions;
EndFor

Transfinite Surface{1}; 

Physical Curve(5) = {1, 2, 4}; 
Physical Surface("My surface") = {1};

Just for illustration, this example (save to mwe.geo and run gmsh -2 mwe.geo) creates a structured mesh on a rectangle with 3 elements along the short side and 9 along the long side. enter image description here I hope this answers your question, because the syntax you looked up the documentation is about string generation (tilde becomes underscore).

P.S.: You do not need to count the items in the list manually, just use something like

number_of_short_sides = #short_sides[];
...
For i In {0:number_of_short_sides - 1}
...
$\endgroup$
1
  • $\begingroup$ It solved the problem, thank you very much! $\endgroup$
    – Julio
    Oct 19, 2022 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.