-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSetBCs.m
156 lines (150 loc) · 3.79 KB
/
SetBCs.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
function [bccode,bcvalue,nomstress] = SetBCs(m,loadcode,nomstrain,neperversionnumber,varargin)
% SetBCs - Write boundary conditions based on loadcode parameter
%
% INPUT:
%
% the code is defined as follows:
% loadcode = 1 -- x-tension
% loadcode = 2 -- y-tension
% loadcode = 3 -- z-tension
% loadcode = 4 -- x-y biaxial tension
% loadcode = 5 -- y-z biaxial tension
% loadcode = 6 -- z-x biaxial tension
%
% Boundary conditions are specified by a CODE and VALUE for each
% of the three coordinate directions. A BC specification is a
% 3 x 2 matrix. The first column contains the CODES, nonzero for
% an essential BC, zero for no essential BC. The second column
% gives the value of the applied displacement.
%
% OUTPUT:
%
% bccode and bcvalue arrays with codes for applying bc's
%
%
xcode =0;
ycode =0;
zcode =0;
xval =0;
yval =0;
zval =0;
if(loadcode==1)
xcode =1;
xval = nomstrain(1);
nomstress = [1;0;0;0;0;0];
end
if(loadcode==2)
ycode =1;
yval = nomstrain(2);
nomstress = [0;1;0;0;0;0];
end
if(loadcode==3)
zcode =1;
zval = nomstrain(3);
nomstress = [0;0;1;0;0;0];
end
if(loadcode==4)
xcode =1;
xval = nomstrain(1);
ycode =1;
yval = nomstrain(2);
nomstress = [1;1;0;0;0;0];
end
if(loadcode==5)
ycode =1;
yval = nomstrain(2);
zcode =1;
zval = nomstrain(3);
nomstress = [0;1;1;0;0;0];
end
if(loadcode==6)
zcode =1;
zval = nomstrain(3);
xcode =1;
xval = nomstrain(1);
nomstress = [1;0;1;0;0;0];
end
optcell = {...
'BCXMin', [1 0; 0 0; 0 0;], ...
'BCXMax', [xcode xval; 0 0; 0 0;], ...
'BCYMin', [0 0; 1 0; 0 0;], ...
'BCYMax', [0 0; ycode yval; 0 0;], ...
'BCZMin', [0 0; 0 0; 1 0;], ...
'BCZMax', [0 0; 0 0; zcode zval;] ...
};
%
options = OptArgs(optcell, varargin);
%
%-------------------- *
%
if nargin < 4
error(sprintf('Not enough args:\nUsage: %s', Usage))
end
%
CODE = 1; VAL = 2;
%
% Apply BC's.
%
%bcfile = sprintf('%s.bcs', fname);
%fprintf('boundary conditions file:\n %s\n', bcfile);
%
surfopts = {'minx', 1, 'miny', 1, 'minz', 1, 'maxx', 1, 'maxy', 1, 'maxz', 1};
if(neperversionnumber==3)
surfs = RectMeshSurfaces(m, surfopts{:});
else
surfs = NeperMeshSurfaces(m, surfopts{:});
end
surfspecs = struct('name', {'minx', 'miny', 'minz', 'maxx', 'maxy', 'maxz'}, ...
'bcname', {'BCXMin', 'BCYMin', 'BCZMin', 'BCXMax', 'BCYMax', 'BCZMax'} ...
); % to be continued ...2006-02-28 16:18
%
nnps = size(m.crd, 2);
bc_codes = zeros(3, nnps);
bc_vals = zeros(3, nnps);
%
for spec=surfspecs
numpts = length(surfs.(spec.name));
i = repmat([1;2;3], [1 numpts]);
j = repmat(surfs.(spec.name), [3 1]);
v = repmat(options.(spec.bcname)(:, CODE), [1 numpts]);
bc_codes = bc_codes + sparse(i(:), j(:), v(:), 3, nnps);
v = repmat(options.(spec.bcname)(:, VAL), [1 numpts]);
bc_vals = bc_vals + sparse(i(:), j(:), v(:), 3, nnps);
end
%
bc_codes(bc_codes ~=0) = 1;
bcnz = find(sum(bc_codes));
nbc = length(bcnz);
%
vfmt = '%20.12e %20.12e %20.12e\n';
for node=bcnz
bc = bc_codes(:, node)';
bv = bc_vals(:, node)';
sc = [(node - 1), bc];
sv = [(node - 1), bv];
% fprintf(f, s);
if (node==bcnz(1))
sctotal = sc;
svtotal = sv;
else
sctotal = cat(1,sctotal,sc);
svtotal = cat(1,svtotal,sv);
end
end
%
% fprintf(f, '0\n');
% fclose(f);
bccode = sctotal;
bcvalue = svtotal;
%
%--------------------*--------------------------------------------------
%
function s = TrueFalse(code)
% TRUEFALSE -
%
FT = 'FT';
code = code + 1;
sp = ' ';
%
s = [sp, FT(code(1)), sp, FT(code(2)), sp, FT(code(3)), sp];
%