-
Notifications
You must be signed in to change notification settings - Fork 0
/
Validation_Mesh_format_convert.m
executable file
·102 lines (87 loc) · 2.02 KB
/
Validation_Mesh_format_convert.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
clc
clear all
close all
%cd ('Mesh_convert_test')
%fid = fopen('Single_cylinder_regular.msh','r');
fid = fopen('Validation2.msh','r');
i = 0;
while true
i = i+1;
tline = fgetl(fid);
txt{i} = tline;
tf1 = strcmp(txt{i},'$Nodes');
if tf1
Nodes=i;
end
tf2 = strcmp(txt{i},'$Elements');
if tf2
Elements=i;
end
if ischar(tline)
txt{i}=str2num(txt{i});
else
break
end
end
fclose(fid);
num_Nodes=txt{Nodes+1};
num_Elements=txt{Elements+1};
%txtout{}
NodesMat=cell(1,num_Nodes);
j=0;%first two lines for preset
for i = (Nodes+2):(Nodes+num_Nodes+1)
j=j+1;
NodesMat{j}=txt{i}(2:3);
end
k1=0;k2=0;k3=0;k4=0;
for i = (Elements+2):(Elements+num_Elements+1)
if txt{i}(4)==2 %1 2 "Cylinder 1"
k1=k1+1;
cylinder1{k1}=[2 3 txt{i}(6:7)];
end
% if txt{i}(4)==3 % 1 3 "Cylinder 2"
% k2=k2+1;
% cylinder2{k2}=[2 3 txt{i}(6:7)];
% end
if txt{i}(4)==4 % 1 79 "Outer Wall"
k3=k3+1;
outerwall{k3}=[2 1 txt{i}(6:7)];
end
if txt{i}(4)==1 % 2 1 "Main mesh"
k4=k4+1;
if txt{i}(2)==2
quadcells{k4}=[4 txt{i}(6:8) txt{i}(8)];
elseif txt{i}(2)==3
quadcells{k4}=[4 txt{i}(6:9)];
else
disp('error:',i)
end
end
end
%meshtxt=cell(1,num_Nodes+num_Elements+2);
premeshtxt{1}=[4 2];
premeshtxt{2}=[num_Nodes k4 (k1+k2+k3)];
boundary=[cylinder1 outerwall];
meshtxt=[premeshtxt NodesMat quadcells boundary];
fid = fopen('MESH.TXT', 'w');
for i = 1:length(meshtxt)
fprintf(fid,'%s\n', num2str(meshtxt{i},20));
end
fclose(fid);
%FORCE_PARA.TXT
num=k1+k2;
for i=1:num
if i<=k1
forcetxt{i}=[i 1];
else
forcetxt{i}=[i 2];
end
end
numc{1}=num;
forcetxt=[num forcetxt];
fid = fopen('FORCE_PARA.TXT', 'w');
for i = 1:length(forcetxt)
fprintf(fid,'%s\n', num2str(forcetxt{i},20));
end
fclose(fid);
disp('done')