CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Special Topics > Mesh Generation & Pre-Processing

GMSH: defining an array to generate points

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 17, 2019, 04:16
Default GMSH: defining an array to generate points
  #1
Member
 
Hüseyin Can Önel
Join Date: Sep 2018
Location: Ankara, Turkey
Posts: 46
Rep Power: 7
hconel is on a distinguished road
Hello there,
In GMSH, I am able to create a series of points using For loop. I know that people are using external scripts (Matlab, Fortran etc.) to generate files in the

Point(i)={x,y,z,c};

format from a data file (which is in x,y,z,c format). What I am trying to do is, use the data file directly in the .geo file without a format conversion. For that, I need to store the array in a variable in .geo file. Is there a way to do that?

Thanks in advance,
Hüseyin
hconel is offline   Reply With Quote

Old   October 22, 2019, 12:09
Default
  #2
Senior Member
 
Mikko
Join Date: Jul 2014
Location: The Hague, The Netherlands
Posts: 243
Rep Power: 12
Flowkersma is on a distinguished road
Hi Hüseyin,

I don't know how if it's possible to store 2D arrays in GMSH .geo format but you can store 2 or 3 1D arrays. Here is an example of a script which contains NACA 0012 coordinates as arrays. It also contains a for loop which creates points from the arrays and a BSpline from the points. Obviously, this would be very straight-forward by using the Python interface of GMSH.

Best, Mikko

Code:
x = {1.0,0.991677,0.980364,0.9672594,0.9527094,0.9371906,0.9211098,0.9047307,0.888199,0.871589,0.8549374,0.838262,0.8215722,0.8048727,0.7881664,0.7714554,0.7547412,0.7380253,0.7213088,0.7045932,0.6878796,0.6711694,0.6544637,0.637764,0.6210716,0.6043879,0.5877143,0.5710523,0.5544034,0.5377692,0.5211515,0.504552,0.4879725,0.4714152,0.4548821,0.4383756,0.4218982,0.4054527,0.389042,0.3726696,0.3563391,0.3400549,0.3238215,0.3076446,0.2915302,0.2754859,0.2595202,0.2436435,0.2278683,0.2122105,0.1966898,0.181332,0.1661718,0.151256,0.1366496,0.1224422,0.1087546,0.09573936,0.08357044,0.07241381,0.06238752,0.05353091,0.04580157,0.03909828,0.03329271,0.02825461,0.02386618,0.02002762,0.01665766,0.01369187,0.01108041,0.008785821,0.006781149,0.005048426,0.003577154,0.002362688,0.001403607,0.0006990502,0.0002434807,2.600131e-05,2.600131e-05,0.0002434807,0.0006990502,0.001403607,0.002362688,0.003577154,0.005048426,0.006781149,0.008785821,0.01108041,0.01369187,0.01665766,0.02002762,0.02386618,0.02825461,0.03329271,0.03909828,0.04580157,0.05353091,0.06238752,0.07241381,0.08357044,0.09573936,0.1087546,0.1224422,0.1366496,0.151256,0.1661718,0.181332,0.1966898,0.2122105,0.2278683,0.2436435,0.2595202,0.2754859,0.2915302,0.3076446,0.3238215,0.3400549,0.3563391,0.3726696,0.389042,0.4054527,0.4218982,0.4383756,0.4548821,0.4714152,0.4879725,0.504552,0.5211515,0.5377692,0.5544034,0.5710523,0.5877143,0.6043879,0.6210716,0.637764,0.6544637,0.6711694,0.6878796,0.7045932,0.7213088,0.7380253,0.7547412,0.7714554,0.7881664,0.8048727,0.8215722,0.838262,0.8549374,0.871589,0.888199,0.9047307,0.9211098,0.9371906,0.9527094,0.9672594,0.980364,0.991677,1.0};
y = {0.00126,0.002421811,0.003982079,0.005762782,0.00770723,0.009744292,0.01181606,0.0138865,0.01593654,0.01795702,0.01994386,0.02189533,0.02381076,0.02568989,0.02753259,0.02933869,0.03110797,0.03284008,0.03453454,0.03619074,0.03780792,0.03938518,0.04092147,0.04241557,0.04386613,0.04527161,0.04663031,0.04794038,0.04919976,0.05040625,0.05155744,0.05265072,0.05368329,0.05465216,0.05555408,0.05638562,0.05714307,0.0578225,0.05841969,0.05893014,0.05934906,0.05967133,0.05989147,0.06000362,0.06000152,0.05987849,0.05962734,0.0592404,0.05870947,0.05802584,0.05718031,0.05616342,0.05496573,0.05357861,0.05199553,0.05021437,0.04824084,0.0460927,0.04380301,0.04141953,0.03899781,0.03659002,0.03423525,0.03195587,0.02975941,0.02764309,0.02559815,0.02361286,0.0216745,0.01977036,0.01788831,0.01601718,0.01414714,0.01227025,0.01038132,0.008479151,0.006567428,0.004656927,0.002761035,0.0009055955,-0.0009055955,-0.002761035,-0.004656927,-0.006567428,-0.008479151,-0.01038132,-0.01227025,-0.01414714,-0.01601718,-0.01788831,-0.01977036,-0.0216745,-0.02361286,-0.02559815,-0.02764309,-0.02975941,-0.03195587,-0.03423525,-0.03659002,-0.03899781,-0.04141953,-0.04380301,-0.0460927,-0.04824084,-0.05021437,-0.05199553,-0.05357861,-0.05496573,-0.05616342,-0.05718031,-0.05802584,-0.05870947,-0.0592404,-0.05962734,-0.05987849,-0.06000152,-0.06000362,-0.05989147,-0.05967133,-0.05934906,-0.05893014,-0.05841969,-0.0578225,-0.05714307,-0.05638562,-0.05555408,-0.05465216,-0.05368329,-0.05265072,-0.05155744,-0.05040625,-0.04919976,-0.04794038,-0.04663031,-0.04527161,-0.04386613,-0.04241557,-0.04092147,-0.03938518,-0.03780792,-0.03619074,-0.03453454,-0.03284008,-0.03110797,-0.02933869,-0.02753259,-0.02568989,-0.02381076,-0.02189533,-0.01994386,-0.01795702,-0.01593654,-0.0138865,-0.01181606,-0.009744292,-0.00770723,-0.005762782,-0.003982079,-0.002421811,-0.00126};

p = newp;
For i In {0: #x[]-1}
    Point(p + i) = {x[i], y[i], 0, 0.1};
EndFor
BSpline(1) = {1:#x[],1};
Flowkersma is offline   Reply With Quote

Old   October 22, 2019, 12:56
Default
  #3
Member
 
Hüseyin Can Önel
Join Date: Sep 2018
Location: Ankara, Turkey
Posts: 46
Rep Power: 7
hconel is on a distinguished road
Quote:
Originally Posted by Flowkersma View Post
Hi Hüseyin,

I don't know how if it's possible to store 2D arrays in GMSH .geo format but you can store 2 or 3 1D arrays. Here is an example of a script which contains NACA 0012 coordinates as arrays. It also contains a for loop which creates points from the arrays and a BSpline from the points. Obviously, this would be very straight-forward by using the Python interface of GMSH.

Best, Mikko

Code:
x = {1.0,0.991677,0.980364,0.9672594,0.9527094,0.9371906,0.9211098,0.9047307,0.888199,0.871589,0.8549374,0.838262,0.8215722,0.8048727,0.7881664,0.7714554,0.7547412,0.7380253,0.7213088,0.7045932,0.6878796,0.6711694,0.6544637,0.637764,0.6210716,0.6043879,0.5877143,0.5710523,0.5544034,0.5377692,0.5211515,0.504552,0.4879725,0.4714152,0.4548821,0.4383756,0.4218982,0.4054527,0.389042,0.3726696,0.3563391,0.3400549,0.3238215,0.3076446,0.2915302,0.2754859,0.2595202,0.2436435,0.2278683,0.2122105,0.1966898,0.181332,0.1661718,0.151256,0.1366496,0.1224422,0.1087546,0.09573936,0.08357044,0.07241381,0.06238752,0.05353091,0.04580157,0.03909828,0.03329271,0.02825461,0.02386618,0.02002762,0.01665766,0.01369187,0.01108041,0.008785821,0.006781149,0.005048426,0.003577154,0.002362688,0.001403607,0.0006990502,0.0002434807,2.600131e-05,2.600131e-05,0.0002434807,0.0006990502,0.001403607,0.002362688,0.003577154,0.005048426,0.006781149,0.008785821,0.01108041,0.01369187,0.01665766,0.02002762,0.02386618,0.02825461,0.03329271,0.03909828,0.04580157,0.05353091,0.06238752,0.07241381,0.08357044,0.09573936,0.1087546,0.1224422,0.1366496,0.151256,0.1661718,0.181332,0.1966898,0.2122105,0.2278683,0.2436435,0.2595202,0.2754859,0.2915302,0.3076446,0.3238215,0.3400549,0.3563391,0.3726696,0.389042,0.4054527,0.4218982,0.4383756,0.4548821,0.4714152,0.4879725,0.504552,0.5211515,0.5377692,0.5544034,0.5710523,0.5877143,0.6043879,0.6210716,0.637764,0.6544637,0.6711694,0.6878796,0.7045932,0.7213088,0.7380253,0.7547412,0.7714554,0.7881664,0.8048727,0.8215722,0.838262,0.8549374,0.871589,0.888199,0.9047307,0.9211098,0.9371906,0.9527094,0.9672594,0.980364,0.991677,1.0};
y = {0.00126,0.002421811,0.003982079,0.005762782,0.00770723,0.009744292,0.01181606,0.0138865,0.01593654,0.01795702,0.01994386,0.02189533,0.02381076,0.02568989,0.02753259,0.02933869,0.03110797,0.03284008,0.03453454,0.03619074,0.03780792,0.03938518,0.04092147,0.04241557,0.04386613,0.04527161,0.04663031,0.04794038,0.04919976,0.05040625,0.05155744,0.05265072,0.05368329,0.05465216,0.05555408,0.05638562,0.05714307,0.0578225,0.05841969,0.05893014,0.05934906,0.05967133,0.05989147,0.06000362,0.06000152,0.05987849,0.05962734,0.0592404,0.05870947,0.05802584,0.05718031,0.05616342,0.05496573,0.05357861,0.05199553,0.05021437,0.04824084,0.0460927,0.04380301,0.04141953,0.03899781,0.03659002,0.03423525,0.03195587,0.02975941,0.02764309,0.02559815,0.02361286,0.0216745,0.01977036,0.01788831,0.01601718,0.01414714,0.01227025,0.01038132,0.008479151,0.006567428,0.004656927,0.002761035,0.0009055955,-0.0009055955,-0.002761035,-0.004656927,-0.006567428,-0.008479151,-0.01038132,-0.01227025,-0.01414714,-0.01601718,-0.01788831,-0.01977036,-0.0216745,-0.02361286,-0.02559815,-0.02764309,-0.02975941,-0.03195587,-0.03423525,-0.03659002,-0.03899781,-0.04141953,-0.04380301,-0.0460927,-0.04824084,-0.05021437,-0.05199553,-0.05357861,-0.05496573,-0.05616342,-0.05718031,-0.05802584,-0.05870947,-0.0592404,-0.05962734,-0.05987849,-0.06000152,-0.06000362,-0.05989147,-0.05967133,-0.05934906,-0.05893014,-0.05841969,-0.0578225,-0.05714307,-0.05638562,-0.05555408,-0.05465216,-0.05368329,-0.05265072,-0.05155744,-0.05040625,-0.04919976,-0.04794038,-0.04663031,-0.04527161,-0.04386613,-0.04241557,-0.04092147,-0.03938518,-0.03780792,-0.03619074,-0.03453454,-0.03284008,-0.03110797,-0.02933869,-0.02753259,-0.02568989,-0.02381076,-0.02189533,-0.01994386,-0.01795702,-0.01593654,-0.0138865,-0.01181606,-0.009744292,-0.00770723,-0.005762782,-0.003982079,-0.002421811,-0.00126};

p = newp;
For i In {0: #x[]-1}
    Point(p + i) = {x[i], y[i], 0, 0.1};
EndFor
BSpline(1) = {1:#x[],1};
Thanks so much for the neat idea!
The thing is, I am trying to read the x-y data from a file, which is usually in column format, such as x_column, y_column. In your case, I guess my only option is to provide x and y data externally in separate files (one for x and one for y) in row format and then include them in the .geo file.

Example:

contents of x_coords.dat file:
Code:
1.0,0.991677,0.980364,0.9672594,0.9527094,0.9371906,................
Then in the .geo file:
Code:
x={Include "x_coords.dat"};
Although I am not sure whether or not Include can be used in that way.
hconel is offline   Reply With Quote

Old   October 23, 2019, 04:29
Default
  #4
Senior Member
 
Mikko
Join Date: Jul 2014
Location: The Hague, The Netherlands
Posts: 243
Rep Power: 12
Flowkersma is on a distinguished road
I would suggest using the API. Here is an example code in Python how to open a .dat file and create similar BSpline with it.
Code:
import gmsh
datFile = 'naca0012.dat'
gmsh.initialize()
model = gmsh.model
factory = model.geo

with open(datFile) as fin:
    for line in fin:
        try:
            x, y = map(float,line.split())
            factory.addPoint(x, y, 0)
        except ValueError:
            print("Skipped line: ", line)

factory.synchronize()
ids = list(range(1, len(model.getEntities())+1))
ids.append(1) # [1,2,3,...,N,1]
spline = factory.addBSpline(ids)
factory.synchronize()
gmsh.fltk.run()
gmsh.finalize()
Flowkersma is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[snappyHexMesh] SHM Layer Addition Phase dickcruz OpenFOAM Meshing & Mesh Conversion 4 November 1, 2018 07:05
[blockMesh] BlockMeshmergePatchPairs hjasak OpenFOAM Meshing & Mesh Conversion 11 August 15, 2008 07:36
Defining a surface from points or edges in CFXpost Gui CFX 9 July 26, 2007 15:12
Defining a surface from edges or points in CFXpost Gui CFX 0 July 25, 2007 16:03
Defining points at real dimensions John CFX 0 February 21, 2002 05:21


All times are GMT -4. The time now is 12:11.