Question about mesh generating by Matlab

Mesh generators, CAD programs, and other tools

Question about mesh generating by Matlab

Postby Dragonghost » 13 Jun 2016, 12:21

Hi everyone,

I am starting using Matlab to generate a Elmermesh structure. The part I want to generate is the boundary of the structure and the sequence has been described by the Note.

The Code as follow:

Code: Select all
g=zeros((yges+xges)*2+yges*xges,4);
yges=40;
xges=10;

%Flaeche 1 und 2
k_2=yges*2+2;
for i=1:2
    g(i,:)=[i*2+2 i*2 i*2-1 i*2+1];
    g(yges+i,:)=[k_2+i*2 k_2+i*2+2, k_2+i*2+1 k_2+i*2-1];
end
for i=3:yges-1
    g(i,:)=[i*2+2 i*2+1, i*2-1 i*2];
    g(yges+i,:)=[k_2+i*2+1 k_2+i*2+2, k_2+i*2 k_2+i*2-1];
end

g(yges,:)=[yges*2-1 yges*2 yges*2+2 yges*2+1];
g(2*yges,:)=[k_2+yges*2-1 k_2+yges*2 k_2+yges*2+2 k_2+yges*2+1];

%Flaeche 3
k_3=k_2+2*yges+2;
g(2*yges+1,:)=[1 k_3+1 k_3+2 3];
for i=2:xges-1
    g(2*yges+i,:)=[k_3+2*i-3 k_3+2*i-1 k_3+2*i k_3+2*i-2];
end
g(2*yges+xges,:)=[k_3+2*(xges-1)-1 yges*2+3 yges*2+5 k_3+2*(xges-1)];

%Flaeche 4
k_4=k_3+2*(xges-1);
g(2*yges+xges+1,:)=[k_4+2 k_4+1 k_2-1 k_2];
for i=2:xges-1
    g(2*yges+i,:)=[k_4+2*i k_4+2*i-1 k_4+2*i-3 k_3+2*i-2];
end
g(2*(yges+xges),:)=[k_3 k_3-1 k_4+2*(xges-1)-1 k_4+2*(xges-1)];

%Flaeche 5
k_5=k_4+2*(xges-1);
%Allgemein
for j=0:xges-1
    for i=1:yges
        g(2*(xges+yges)+j*yges+i,:)=[k_5+(j-1)*(yges-1)+i k_5+j*(yges-1)+i k_5+j*(yges-1)+i-1 k_5+(j-1)*(yges-1)+i-1];
    end
end
%Rand x=0(ausser y_max)
%erst zwei Quadrats
g(2*(yges+xges)+1,1)=2;
g(2*(yges+xges)+1,4)=1;
g(2*(yges+xges)+2,1)=5;
g(2*(yges+xges)+2,4)=2;
for i=3:yges-1
    g(2*(yges+xges)+i,1)=2*i+1;
    g(2*(yges+xges)+i,4)=2*i-1;
end
%Rand x=max(ausser y_max)
%erst zwei Quadrats
g(2*(yges+xges)+yges*(xges-1)+1,2)=k_2+2;
g(2*(yges+xges)+yges*(xges-1)+1,3)=k_2+1;
g(2*(yges+xges)+yges*(xges-1)+2,2)=k_2+5;
g(2*(yges+xges)+yges*(xges-1)+2,3)=k_2+2;
for i=3:yges-1
    g(2*(yges+xges)+yges*(xges-1)+i,2)=k_2+2*i+1;
    g(2*(yges+xges)+yges*(xges-1)+i,3)=k_2+2*i-1;
end
%Rand y=0
g(2*(yges+xges)+1,3)=k_3+1;
g(2*(yges+xges)+yges*(xges-1)+1,4)=k_3+2*(xges-1)-1;
for i=2:xges-1
    g(2*(yges+xges)+i,3)=k_3+2*i-1;
    g(2*(yges+xges)+i,4)=k_3+2*i-3;
end
%Rand y=max(4 nodes)
g(2*(yges+xges)+yges,:)=[k_4+1 k_5+yges-2 yges*2-1 yges*2+1];
for i=2:xges-1
    g(2*(yges+xges)+i*yges,:)=[k_4+2*i-1 k_5+i*(yges-2) k_5+(i-1)*(yges-2) k_4+2*i-3];
end
g(2*(yges+xges)+yges*xges,:)=[k_3-1 k_3-3 k_5+(xges-1)*(yges-1) k_5-1];

%Flaeche 6
k_6=k_5+(xges-1)*(yges-1);
%Allgemein
for j=0:xges-1
    for i=1:yges
        g(2*(xges+yges)+xges*yges+j*yges+i,:)=[k_6+(j-1)*(yges-1)+i k_6+j*(yges-1)+i k_6+j*(yges-1)+i-1 k_6+(j-1)*(yges-1)+i-1];
    end
end
%Rand x=0(ausser y_max)
%erst zwei Quadrats
g(2*(yges+xges)+xges*yges+1,1)=4;
g(2*(yges+xges)+1,4)=3;
g(2*(yges+xges)+2,1)=6;
g(2*(yges+xges)+2,4)=4;
for i=3:yges-1
    g(2*(yges+xges)+i,1)=2*i+2;
    g(2*(yges+xges)+i,4)=2*i;
end
%Rand x=max(ausser y_max)
%erst zwei Quadrats
g(2*(yges+xges)+xges*yges+yges*(xges-1)+1,2)=k_2+4;
g(2*(yges+xges)+xges*yges+yges*(xges-1)+1,3)=k_2+3;
g(2*(yges+xges)+xges*yges+yges*(xges-1)+2,2)=k_2+6;
g(2*(yges+xges)+xges*yges+yges*(xges-1)+2,3)=k_2+4;
for i=3:yges-1
    g(2*(yges+xges)+xges*yges+yges*(xges-1)+i,2)=k_2+2*i+2;
    g(2*(yges+xges)+xges*yges+yges*(xges-1)+i,3)=k_2+2*i;
end
%Rand y=0
g(2*(yges+xges)+1,3)=k_3+3;
g(2*(yges+xges)+yges*(xges-1)+1,4)=k_3+2*(xges-1);
for i=2:xges-1
    g(2*(yges+xges)+xges*yges+i,3)=k_3+2*i;
    g(2*(yges+xges)+xges*yges+i,4)=k_3+2*i-2;
end
%Rand y=max(4 nodes)
g(2*(yges+xges)+xges*yges+yges,:)=[k_4+2 k_6+yges-2 yges*2 yges*2+2];
for i=2:xges-1
    g(2*(yges+xges)+xges*yges+i*yges,:)=[k_4+2*i k_6+i*(yges-2) k_6+(i-1)*(yges-2) k_4+2*i-2];
end
g(2*(yges+xges)+2*yges*xges,:)=[k_3 k_3-2 k_6+(xges-1)*(yges-1) k_5];

meshBoundary=zeros(2*(xges+yges)+2*xges*yges,5);
for i=1:2*(xges+yges)+2*xges*yges
    meshBoundary(i,1)=i;
    meshBoundary(i,2)=g(i,1);
    meshBoundary(i,3)=g(i,2);
    meshBoundary(i,4)=g(i,3);
    meshBoundary(i,5)=g(i,4);
end

[file_out_me,path_out_l] = uiputfile('mesh.boundary','Save file name');                         
FileOut_me=[path_out_l,file_out_me];
fid=fopen(FileOut_me,'wt');
for k = 1:(2*(xges+yges)+2*xges*yges)
fprintf(fid, '%i %i %i %i %i\n',meshBoundary(g,:));
end;
fclose('all');


xges and yges are the numbers of the elements in each side.
The problem is I cannot get results from the program.
I am an beginner about this and maybe I have not explained so clearly. If you guys have questions, please tell me. Thank you all!
Attachments
Mesh Boundary.png
(69.04 KiB) Not downloaded yet
Dragonghost
 
Posts: 2
Joined: 10 Jun 2016, 11:56

Re: Question about mesh generating by Matlab

Postby mzenker » 13 Jun 2016, 12:34

Hi,

what do you mean by

Dragonghost wrote:The problem is I cannot get results from the program.

?

If you wan to use your mesh in Elmer, you need to write out a file in a format Elmer can read, see Elmergrid Manual.

HTH,

Matthias
mzenker
 
Posts: 1578
Joined: 07 Dec 2009, 11:49
Location: Germany

Re: Question about mesh generating by Matlab

Postby Dragonghost » 18 Jun 2016, 11:09

mzenker wrote:Hi,

what do you mean by

Dragonghost wrote:The problem is I cannot get results from the program.

?

If you wan to use your mesh in Elmer, you need to write out a file in a format Elmer can read, see Elmergrid Manual.

HTH,

Matthias


Hi,

thank you for the answer. I mean I want to use Matlab to generate the mesh in Elmer, but now from this matlab programm I cannot get any result. The problem must be in the Matlab Problem.

I know it is not so common to generate a mesh with Matlab but I think it will simplify the process. A Elmer mesh must have header, nodes, elements and boundary, is that right? But I am not sure why it is necessary. So with these four documents can mesh be read by Elmer?

Thanks a lot.

Best regards.
Dragonghost
 
Posts: 2
Joined: 10 Jun 2016, 11:56

Re: Question about mesh generating by Matlab

Postby mzenker » 20 Jun 2016, 11:42

Hi,

if the "result" you are talking about is a mesh that Elmer can read, then either consult Appendix A of the ElmerSolver Manual where the Elmer mesh format is documented, or choose any other mesh format which you may find easier to implement (e.g. gmsh format, see http://geuz.org/gmsh) and which can be imported by Elmer, see Elmergrid Manual for a list of possible input formats.

HTH,

Matthias
mzenker
 
Posts: 1578
Joined: 07 Dec 2009, 11:49
Location: Germany


Return to External tools

Who is online

Users browsing this forum: No registered users and 1 guest