1 | function md=BamgCallFromMetric(md,metric,gradation),
|
---|
2 | %BAMGCALL - call bam
|
---|
3 | %
|
---|
4 | % call Bamg and the output mesh is plugged onto the model
|
---|
5 | % -gradation = maximum edge length gradation between 2 elements
|
---|
6 | %
|
---|
7 | % Usage:
|
---|
8 | % md=BamgCallFromMetric(md,metric,gradation);
|
---|
9 | %
|
---|
10 | % Example:
|
---|
11 | % md=BamgCall(md,metric,1500,10^8,1.3,0.9);
|
---|
12 |
|
---|
13 | global ISSM_DIR
|
---|
14 |
|
---|
15 | %2d geometric parameter (do not change)
|
---|
16 | scale=2/9;
|
---|
17 |
|
---|
18 | %write files
|
---|
19 | t1=clock; fprintf('%s',' writing initial mesh files...');
|
---|
20 | fid=fopen('carre0.met','w');
|
---|
21 | fprintf(fid,'%i %i\n',md.numberofgrids,3);
|
---|
22 | fprintf(fid,'%i %i %i\n',metric');
|
---|
23 | fclose(fid);
|
---|
24 |
|
---|
25 | fid=fopen('carre0.mesh','w');
|
---|
26 |
|
---|
27 | %initialiation
|
---|
28 | fprintf(fid,'%s %i\n','MeshVersionFormatted',0);
|
---|
29 |
|
---|
30 | %dimension
|
---|
31 | fprintf(fid,'\n%s\n%i\n','Dimension',2);
|
---|
32 |
|
---|
33 | %Vertices
|
---|
34 | fprintf(fid,'\n%s\n%i\n\n','Vertices',md.numberofgrids);
|
---|
35 | fprintf(fid,'%8g %8g %i\n',[md.x md.y ones(md.numberofgrids,1)]');
|
---|
36 |
|
---|
37 | %Triangles
|
---|
38 | fprintf(fid,'\n\n%s\n%i\n\n','Triangles',md.numberofelements);
|
---|
39 | fprintf(fid,'%i %i %i %i\n',[md.elements ones(md.numberofelements,1)]');
|
---|
40 | numberofelements1=md.numberofelements;
|
---|
41 |
|
---|
42 | %close
|
---|
43 | fclose(fid);
|
---|
44 | t2=clock;fprintf('%s\n',[' done (' num2str(etime(t2,t1)) ' seconds)']);
|
---|
45 |
|
---|
46 | %call bamg
|
---|
47 | fprintf('%s\n',' call Bamg...');
|
---|
48 | system(['bamg -ratio ' num2str(gradation) ' -splitpbedge -nbv 1000000 -M carre0.met -b carre0.mesh -o carre1.mesh']);
|
---|
49 |
|
---|
50 | %plug new mesh
|
---|
51 | t1=clock; fprintf('\n%s',' reading final mesh files...');
|
---|
52 | A=meshread('carre1.mesh');
|
---|
53 | md.x=A.x;
|
---|
54 | md.y=A.y;
|
---|
55 | md.z=zeros(A.nods,1);
|
---|
56 | md.elements=A.index;
|
---|
57 | md.numberofgrids=A.nods;
|
---|
58 | md.numberofelements=A.nels;
|
---|
59 | numberofelements2=md.numberofelements;
|
---|
60 | t2=clock;fprintf('%s\n\n',[' done (' num2str(etime(t2,t1)) ' seconds)']);
|
---|
61 |
|
---|
62 | %display number of elements
|
---|
63 | fprintf('\n%s %i',' inital number of elements:',numberofelements1);
|
---|
64 | fprintf('\n%s %i\n\n',' new number of elements:',numberofelements2);
|
---|
65 |
|
---|
66 | %clean up:
|
---|
67 | system('rm carre0.mesh carre0.met carre1.mesh carre1.mesh.gmsh');
|
---|