Re: [Gmsh] help in reading element connectivity

2018-02-22 Thread Christophe Geuzaine

PS: there are also some scripts here: 
https://gitlab.onelab.info/gmsh/gmsh/tree/master/utils/converters/matlab

> On 21 Feb 2018, at 19:16, Octavio Castillo Reyes  
> wrote:
> 
> Dear Preety, 
> 
> You need to write a Matlab script to import your mesh. This task is quite 
> simple, for instance:
> 
> % Formats
> fstring  = '%s';
> finteger = '%d';
> fnodes   = '%d %f %f %f';
> felems   = '%f %f %f %f %f %f %f %f';
> % Open file
> Idfile = fopen(mesh_file,'r');
> % Read 4 lines (Header)
> n = 4; textscan(Idfile,fstring,n,'Delimiter','\n');
> % Read number of subdomains
> n = 1; input = textscan(Idfile,finteger,n,'Delimiter','\n');
> nsubdomains = input{1}(1);
> % Read 2 + nsubdomains lines
> n = 2 + nsubdomains; textscan(Idfile,fstring,n,'Delimiter','\n');
> % Read number of nodes
> n = 1; input = textscan(Idfile,finteger,n,'Delimiter','\n');
> nNodes = input{1}(1);
> % Read spatial positions of the nodes
> n = nNodes; input = textscan(Idfile,fnodes,n,'Delimiter','\n');
> nodes = transpose(horzcat(input{2},input{3},input{4}));
> % Read 2 lines
> n = 2; input = textscan(Idfile,fstring,n,'Delimiter', '\n');
> % Read number of elements
> n = 1; input = textscan(Idfile,finteger,n,'Delimiter','\n');
> nElems = input{1}(1);
> % Read nodal/elements connectivity
> n = nElems; input = textscan(Idfile,felems,n,'Delimiter','\n');
> elemsN = transpose(horzcat(input{6},input{7},input{8}));
> % Read physical groups
> phy_groups = input{4};
> fclose(Idfile);
> 
> 
> Otherwise, you can use the python parser by José A. Abell 
> (https://github.com/jaabell/gmshtranslator 
> )
> 
> Best regards
> 
> O.
> 
> 
> 
> On Wed, Feb 21, 2018 at 5:41 PM, preety...@gmail.com 
>   > wrote:
> Hi,
> I have created a 2D mesh in gmsh but able to understand how it is providing 
> the elements connectivity also if possible provide me help regarding how to 
> read this file in mathlab.
> 
> Thank you
> Preety
> 
> Send from my vivo smart phone
> ___
> gmsh mailing list
> gmsh@onelab.info 
> http://onelab.info/mailman/listinfo/gmsh 
> 
> 
> ___
> gmsh mailing list
> gmsh@onelab.info
> http://onelab.info/mailman/listinfo/gmsh

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

Free software: http://gmsh.info | http://getdp.info | http://onelab.info

___
gmsh mailing list
gmsh@onelab.info
http://onelab.info/mailman/listinfo/gmsh


Re: [Gmsh] help in reading element connectivity

2018-02-21 Thread Octavio Castillo Reyes
Dear Preety,

You need to write a Matlab script to import your mesh. This task is quite
simple, for instance:

% Formats
fstring  = '%s';
finteger = '%d';
fnodes   = '%d %f %f %f';
felems   = '%f %f %f %f %f %f %f %f';
% Open file
Idfile = fopen(mesh_file,'r');
% Read 4 lines (Header)
n = 4; textscan(Idfile,fstring,n,'Delimiter','\n');
% Read number of subdomains
n = 1; input = textscan(Idfile,finteger,n,'Delimiter','\n');
nsubdomains = input{1}(1);
% Read 2 + nsubdomains lines
n = 2 + nsubdomains; textscan(Idfile,fstring,n,'Delimiter','\n');
% Read number of nodes
n = 1; input = textscan(Idfile,finteger,n,'Delimiter','\n');
nNodes = input{1}(1);
% Read spatial positions of the nodes
n = nNodes; input = textscan(Idfile,fnodes,n,'Delimiter','\n');
nodes = transpose(horzcat(input{2},input{3},input{4}));
% Read 2 lines
n = 2; input = textscan(Idfile,fstring,n,'Delimiter', '\n');
% Read number of elements
n = 1; input = textscan(Idfile,finteger,n,'Delimiter','\n');
nElems = input{1}(1);
% Read nodal/elements connectivity
n = nElems; input = textscan(Idfile,felems,n,'Delimiter','\n');
elemsN = transpose(horzcat(input{6},input{7},input{8}));
% Read physical groups
phy_groups = input{4};
fclose(Idfile);


Otherwise, you can use the python parser by José A. Abell (
https://github.com/jaabell/gmshtranslator)

Best regards

O.



On Wed, Feb 21, 2018 at 5:41 PM, preety...@gmail.com 
wrote:

> Hi,
> I have created a 2D mesh in gmsh but able to understand how it is
> providing the elements connectivity also if possible provide me help
> regarding how to read this file in mathlab.
>
> Thank you
> Preety
>
> Send from my vivo smart phone
> ___
> gmsh mailing list
> gmsh@onelab.info
> http://onelab.info/mailman/listinfo/gmsh
>
___
gmsh mailing list
gmsh@onelab.info
http://onelab.info/mailman/listinfo/gmsh