-
Notifications
You must be signed in to change notification settings - Fork 8
/
processfile.m
177 lines (131 loc) · 3.76 KB
/
processfile.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
function [ndim, ndof, nnode, nelem, coords, elemConn, elemData, LM, neq, assy4r, dof_force, Fext, maxloadSteps, loadincr, outputlist] = processfile(fname)
clc
% coords: global coordinates of the nodes, x, y, and z
% elemConn: element connectivities
% nelem: total number of elements
% nnode: total number of nodes
% nperelem: number of nodes per element for all elements
% ndof: number of degrees of per node
fid=fopen(fname,'r');
% ndim
line=fgets(fid);
linestr = strsplit(line, ",");
ndim = int32(str2num(linestr{1,2}))
% ndof
line=fgets(fid);
linestr = strsplit(line, ",");
ndof = int32(str2num(linestr{1,2}))
% nodes
line=fgets(fid);
linestr = strsplit(line, ",");
nnode = int32(str2num(linestr{1,2}))
nperelem = 2;
nsize = nperelem*ndof;
neq = nnode*ndof;
%if(arclen)
% neq = neq+1;
%end
%neq
coords = zeros(nnode,ndim);
for i=1:nnode
line = fgets(fid);
linestr = strsplit(line, ",");
coords(i,1) = double(str2num(linestr{1,2}));
coords(i,2) = double(str2num(linestr{1,3}));
if(ndim == 3)
coords(i,3) = double(str2num(linestr{1,4}));
end
end
% element data
line=fgets(fid);
linestr = strsplit(line, ",");
nelemData = int32(str2num(linestr{1,2}))
elemData = zeros(nelemData, 10);
for i=1:nelemData
line = fgets(fid);
linestr = strsplit(line, ",");
for j=1:10
elemData(i,j) = double(str2num(linestr{1,j+1}));
end
end
% elements
line=fgets(fid);
linestr = strsplit(line, ",");
nelem = int32(str2num(linestr{1,2}))
elemConn = zeros(nelem, 4, "int32");
for i=1:nelem
line = fgets(fid);
linestr = strsplit(line, ",");
elemConn(i,1) = int32(str2num(linestr{1,2}));
elemConn(i,2) = int32(str2num(linestr{1,3}));
elemConn(i,3) = int32(str2num(linestr{1,4}));
elemConn(i,4) = int32(str2num(linestr{1,5}));
end
% Dirichlet boundary conditions
line=fgets(fid);
linestr = strsplit(line, ",");
nDBC = int32(str2num(linestr{1,2}))
%dbclist = zeros(nDBC, 3);
dbcnodes = zeros(nDBC, 1, "int32");
for i=1:nDBC
line = fgets(fid);
linestr = strsplit(line, ",");
n1 = int32(str2num(linestr{1,1}));
n2 = int32(str2num(linestr{1,2}));
% dbclist(i,3) = double(str2num(linestr{1,3}));
dbcnodes(i) = (n1-1)*ndof+n2;
end
assy4r = setdiff([1:neq], dbcnodes)';
% Force boundary conditions
line=fgets(fid);
linestr = strsplit(line, ",");
nFBC = int32(str2num(linestr{1,2}))
fbclist = zeros(nFBC, 3);
dof_force = zeros(nFBC, 1, "int32");
Fext = zeros(neq, 1);
for i=1:nFBC
line = fgets(fid);
linestr = strsplit(line, ",");
n1 = int32(str2num(linestr{1,1}));
n2 = int32(str2num(linestr{1,2}));
ind = (n1-1)*ndof + n2;
dof_force(i) = ind;
Fext(ind) = double(str2num(linestr{1,3}));
end
% for output
line=fgets(fid);
linestr = strsplit(line, ",");
nOutput = int32(str2num(linestr{1,2}))
outputlist = zeros(nOutput, 1, "int32");
for i=1:nOutput
line = fgets(fid);
linestr = strsplit(line, ",");
n1 = int32(str2num(linestr{1,1}));
n2 = int32(str2num(linestr{1,2}));
outputlist(i,1) = (n1-1)*ndof+n2;
end
% Arclength parameters
line=fgets(fid);
linestr = strsplit(line, ",");
arclen = (int32(linestr{1,2}) == 1);
line=fgets(fid)
linestr = strsplit(line, ",");
maxloadSteps = int32(str2num(linestr{1,1}));
line=fgets(fid)
linestr = strsplit(line, ",");
loadincr = double(str2num(linestr{1,1}));
fclose(fid);
% data structures
LM = zeros(nelem, nsize);
for e=1:nelem
count = 1;
for jj=1:nperelem
ind = ndof*(elemConn(e,jj+2)-1)+1;
for kk=1:ndof
LM(e,count) = ind;
ind = ind + 1;
count = count + 1;
end
end
count = count - 1;
end