-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinput_run.m
342 lines (317 loc) · 12.6 KB
/
input_run.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
clear; clc; clf;
%% Memory structures (Modules)
mesh = struct(); % mesh-related parameters
fprop = struct(); % fluid properties
sprop = struct(); % solid properties
time = struct(); % time-related parameters
iter = struct(); % iteration-related parameters
gauss = struct(); % Gaussian quadrature
plots = struct(); % plotting-related values
coeff = struct(); % coefficients needed in local grad and res
solver = struct(); % encasing structure
% Mesh option
mesh_opt = 'meshgen';
%% Inputs
% Dimensions and mesh specified within mesh_gen function
if (strcmp(mesh_opt,'uniform'))
mesh.nx = 17;
mesh.ny = 17;
mesh.nnode = mesh.nx*mesh.ny;
mesh.Lx = 1.0;
mesh.Ly = 1.0;
mesh.filename = 'mesh';
elseif (strcmp(mesh_opt,'bar'))
mesh.nx = 17;
mesh.ny = 5;
mesh.nnode = mesh.nx*mesh.ny;
mesh.Lx = 10.0;
mesh.Ly = 1.0;
mesh.filename = 'mesh';
elseif (strcmp(mesh_opt,'cavity'))
mesh.nx = 17;
mesh.ny = 17;
mesh.nnode = mesh.nx*mesh.ny;
mesh.Lx = 1.0;
mesh.Ly = 1.0;
mesh.filename = 'mesh';
elseif (strcmp(mesh_opt,'poiseuille'))
mesh.nx = 17;
mesh.ny = 17;
mesh.nnode = mesh.nx*mesh.ny;
mesh.Lx = 1.0;
mesh.Ly = 1.0;
mesh.filename = 'mesh';
end
% Solid properties
sprop.rho = 0.1; %1; %0.1;
sprop.nu = 0.35; %0.3; %0.35;
sprop.E = 2.5e6; %1e8; %2.5e6;
% Fluid properties
fprop.mu = 1.82e-4;
fprop.rho = 1.18e-3;
% Mesh properties
mprop.nu = 0.35;
mprop.alpha = 3; % related to Jacobian-dependent stiffness
% Problem-designated parameters
ndim_out = 2;
temp_sim = 1;
% User-designated parameters
init_var = zeros(1,4); % u(:), y(:)
init_var(1) = 51.3;
init_var(2) = 10; %10; % perturb the y velocity
time.dt = 1e-2;
time.endtime = 3;
time.max_tstep = 5e6;
time.rho = 0.2;
time.outputint = 2e-2;
iter.tol = 1e-2;
iter.max_iter = 10;
plots.plotnow = 0;
c1 = 4;
% Output filename
filename = 'mesh1_i10_dt01';
text_file = [filename '.txt'];
data_file = [filename '.dat'];
meta_file = [filename '.met'];
%% Body forces
fxmag = 0; % 1e8;
fymag = 0; %-1e4;
phasem = 0; phaseoff = 0.5;
f1 = @(t) fxmag*cos(phasem*pi()*t+phaseoff);
f2 = @(t) fymag*sin(phasem*pi()*t+phaseoff);
% Set up force vector function, 2D
Ff = {f1, f2}; % functions
f = zeros(2,1); % values
%% Constants and Parameters Calculated from Inputs
sprop.lambda = sprop.nu*sprop.E/((1+sprop.nu)*(1-2*sprop.nu));
sprop.mu = sprop.E/(2+2*sprop.nu);
mprop.lambda = mprop.nu/((1+mprop.nu)*(1-2*mprop.nu));
mprop.mu = 1/(2+2*mprop.nu);
time.outputint = time.outputint-eps;
time.alpha_m = (3-time.rho)/(2*(1+time.rho));
time.alpha_f = 1/(1+time.rho);
time.gamma = 0.5+time.alpha_m-time.alpha_f;
time.beta = 1/4*((1+time.alpha_m-time.alpha_f)^2);
plots.disp_nodes = [];
%% Mesh
% Get initial mesh and
% Designate which nodes are solid or fluid (fluid = 0, solid = 1)
switch (mesh_opt)
case('meshgen')
mesh = meshgen_nofile(mesh);
% mesh.tag(:) = 0; % All fluid
% mesh.tag(:) = 1; % All solid
case('uniform')
mesh = uniform_tri(mesh);
mesh.tag = zeros(size(mesh.conn,1),1); % All fluid
mesh.tag([314,42,318,444,307,317,289,76]) = 1; % Obstacle
mesh.block_elem = [314,42,318,444,307,317,289,76];
mesh.block_base = [144 145 146];
mesh.block_intf = [144 146 161 163 178 179 180];
% mesh.tag = ones(size(mesh.conn,1),1); % All solid
% % Putting a defect in the mesh
% mesh.y((3*mesh.nx+1)/2:mesh.nx:((mesh.nx+1)/2+mesh.nx*(mesh.ny-2)))=...
% mesh.y((3*mesh.nx+1)/2:mesh.nx:((mesh.nx+1)/2+mesh.nx*(mesh.ny-2)))...
% -mesh.Ly/(mesh.ny-1)*0.5;
case('bar')
mesh = uniform_tri(mesh);
mesh.tag = ones(size(mesh.conn,1),1); % All solid
mesh.block_base = [1 18 35 52 69];
case('cavity')
mesh = uniform_tri(mesh);
mesh.tag = zeros(size(mesh.conn,1),1); % All fluid
case('poiseuille')
mesh = uniform_tri(mesh);
mesh.tag = zeros(size(mesh.conn,1),1); % All fluid
end
%% Set up Gauss pts (linear triangle, ng = 3)
gauss.ng = 3;
[gauss.ksi_G,gauss.eta_G,gauss.W_G] = tri_Gpts_3();
%% Boundary Conditions
% Set boundary conditions
% Locations where mesh is fixed should also be where solid is fixed
% At interface nodes, I should have a pressure BC where nothing is done,
% and at the remaining solid nodes, I'll set the pressure diagonal to 1
switch (mesh_opt)
case('meshgen')
nBC = 19;
BC = cell(nBC,3);
% cell(number of BCs, BC parameters)
% BC parameters
% 1: component of solution designated by BC
% 2: value of solution at BC
% 3: node list for BC location
iBC = 1;
% Fluid BCs
% Inlet
BC{iBC,1} = 'dxf'; BC{iBC,2} = init_var(1); BC{iBC,3} = mesh.inlet; iBC=iBC+1;
BC{iBC,1} = 'dyf'; BC{iBC,2} = 0 ; BC{iBC,3} = mesh.inlet; iBC=iBC+1;
% Obstacle
BC{iBC,1} = 'dxf'; BC{iBC,2} = 0; BC{iBC,3} = mesh.wall; iBC=iBC+1;
BC{iBC,1} = 'dyf'; BC{iBC,2} = 0; BC{iBC,3} = mesh.wall; iBC=iBC+1;
% Top and bottom
BC{iBC,1} = 'dyf'; BC{iBC,2} = 0; BC{iBC,3} = mesh.top; iBC=iBC+1;
BC{iBC,1} = 'dyf'; BC{iBC,2} = 0; BC{iBC,3} = mesh.bottom; iBC=iBC+1;
% Fix mesh at edges of domain and at obstacle
% Inlet
BC{iBC,1} = 'dxm'; BC{iBC,2} = 0; BC{iBC,3} = mesh.inlet; iBC=iBC+1;
BC{iBC,1} = 'dym'; BC{iBC,2} = 0; BC{iBC,3} = mesh.inlet; iBC=iBC+1;
% Obstacle
BC{iBC,1} = 'dxm'; BC{iBC,2} = 0; BC{iBC,3} = mesh.wall; iBC=iBC+1;
BC{iBC,1} = 'dym'; BC{iBC,2} = 0; BC{iBC,3} = mesh.wall; iBC=iBC+1;
% Top
BC{iBC,1} = 'dxm'; BC{iBC,2} = 0; BC{iBC,3} = mesh.top; iBC=iBC+1;
BC{iBC,1} = 'dym'; BC{iBC,2} = 0; BC{iBC,3} = mesh.top; iBC=iBC+1;
% Bottom
BC{iBC,1} = 'dxm'; BC{iBC,2} = 0; BC{iBC,3} = mesh.bottom; iBC=iBC+1;
BC{iBC,1} = 'dym'; BC{iBC,2} = 0; BC{iBC,3} = mesh.bottom; iBC=iBC+1;
% Outlet
BC{iBC,1} = 'dxm'; BC{iBC,2} = 0; BC{iBC,3} = mesh.outlet; iBC=iBC+1;
BC{iBC,1} = 'dym'; BC{iBC,2} = 0; BC{iBC,3} = mesh.outlet; iBC=iBC+1;
% Fix solid at base of bar
BC{iBC,1} = 'dxs'; BC{iBC,2} = 0; BC{iBC,3} = mesh.bar_base; iBC=iBC+1;
BC{iBC,1} = 'dys'; BC{iBC,2} = 0; BC{iBC,3} = mesh.bar_base; iBC=iBC+1;
% Matching BC at bar
BC{iBC,1} = 'm'; BC{iBC,2} = mesh.bar_intf_elem;
BC{iBC,3} = mesh.bar_intf; iBC=iBC+1;
case('cavity')
nBC = 16;
BC = cell(nBC,3);
iBC = 1;
% Left
BC{iBC,1} = 'dxf'; BC{iBC,2} = 0; BC{iBC,3} = mesh.lnodes; iBC=iBC+1;
BC{iBC,1} = 'dyf'; BC{iBC,2} = 0; BC{iBC,3} = mesh.lnodes; iBC=iBC+1;
% Top and bottom
BC{iBC,1} = 'dxf'; BC{iBC,2} = 100*fprop.mu/fprop.rho; BC{iBC,3} = mesh.tnodes; iBC=iBC+1;
BC{iBC,1} = 'dyf'; BC{iBC,2} = 0; BC{iBC,3} = mesh.tnodes; iBC=iBC+1;
BC{iBC,1} = 'dxf'; BC{iBC,2} = 0; BC{iBC,3} = mesh.bnodes; iBC=iBC+1;
BC{iBC,1} = 'dyf'; BC{iBC,2} = 0; BC{iBC,3} = mesh.bnodes; iBC=iBC+1;
% Right
BC{iBC,1} = 'dxf'; BC{iBC,2} = 0; BC{iBC,3} = mesh.rnodes; iBC=iBC+1;
BC{iBC,1} = 'dyf'; BC{iBC,2} = 0; BC{iBC,3} = mesh.rnodes; iBC=iBC+1;
% Fix mesh at boundaries
% Lefts
BC{iBC,1} = 'dxm'; BC{iBC,2} = 0; BC{iBC,3} = mesh.lnodes; iBC=iBC+1;
BC{iBC,1} = 'dym'; BC{iBC,2} = 0; BC{iBC,3} = mesh.lnodes; iBC=iBC+1;
% Top and bottom
BC{iBC,1} = 'dxm'; BC{iBC,2} = 0; BC{iBC,3} = mesh.tnodes; iBC=iBC+1;
BC{iBC,1} = 'dym'; BC{iBC,2} = 0; BC{iBC,3} = mesh.tnodes; iBC=iBC+1;
BC{iBC,1} = 'dxm'; BC{iBC,2} = 0; BC{iBC,3} = mesh.bnodes; iBC=iBC+1;
BC{iBC,1} = 'dym'; BC{iBC,2} = 0; BC{iBC,3} = mesh.bnodes; iBC=iBC+1;
% Right
BC{iBC,1} = 'dxm'; BC{iBC,2} = 0; BC{iBC,3} = mesh.bnodes; iBC=iBC+1;
BC{iBC,1} = 'dym'; BC{iBC,2} = 0; BC{iBC,3} = mesh.bnodes; iBC=iBC+1;
case('poiseuille')
nBC = 14;
BC = cell(nBC,3);
iBC = 1;
% Left
BC{iBC,1} = 'dxf'; BC{iBC,2} = 100*fprop.mu/fprop.rho; BC{iBC,3} = mesh.lnodes; iBC=iBC+1;
BC{iBC,1} = 'dyf'; BC{iBC,2} = 0; BC{iBC,3} = mesh.lnodes; iBC=iBC+1;
% Top and bottom
BC{iBC,1} = 'dxf'; BC{iBC,2} = 0; BC{iBC,3} = mesh.tnodes; iBC=iBC+1;
BC{iBC,1} = 'dyf'; BC{iBC,2} = 0; BC{iBC,3} = mesh.tnodes; iBC=iBC+1;
BC{iBC,1} = 'dxf'; BC{iBC,2} = 0; BC{iBC,3} = mesh.bnodes; iBC=iBC+1;
BC{iBC,1} = 'dyf'; BC{iBC,2} = 0; BC{iBC,3} = mesh.bnodes; iBC=iBC+1;
% Fix mesh at boundaries
% Lefts
BC{iBC,1} = 'dxm'; BC{iBC,2} = 0; BC{iBC,3} = mesh.lnodes; iBC=iBC+1;
BC{iBC,1} = 'dym'; BC{iBC,2} = 0; BC{iBC,3} = mesh.lnodes; iBC=iBC+1;
% Top and bottom
BC{iBC,1} = 'dxm'; BC{iBC,2} = 0; BC{iBC,3} = mesh.tnodes; iBC=iBC+1;
BC{iBC,1} = 'dym'; BC{iBC,2} = 0; BC{iBC,3} = mesh.tnodes; iBC=iBC+1;
BC{iBC,1} = 'dxm'; BC{iBC,2} = 0; BC{iBC,3} = mesh.bnodes; iBC=iBC+1;
BC{iBC,1} = 'dym'; BC{iBC,2} = 0; BC{iBC,3} = mesh.bnodes; iBC=iBC+1;
% Right
BC{iBC,1} = 'dxm'; BC{iBC,2} = 0; BC{iBC,3} = mesh.bnodes; iBC=iBC+1;
BC{iBC,1} = 'dym'; BC{iBC,2} = 0; BC{iBC,3} = mesh.bnodes; iBC=iBC+1;
case('uniform')
nBC = 17;
BC = cell(nBC,3);
iBC = 1;
% Inlet
BC{iBC,1} = 'dxf'; BC{iBC,2} = init_var(1); BC{iBC,3} = mesh.lnodes; iBC=iBC+1;
BC{iBC,1} = 'dyf'; BC{iBC,2} = 0; BC{iBC,3} = mesh.lnodes; iBC=iBC+1;
% Top and bottom
BC{iBC,1} = 'dxf'; BC{iBC,2} = 0; BC{iBC,3} = mesh.tnodes; iBC=iBC+1;
BC{iBC,1} = 'dyf'; BC{iBC,2} = 0; BC{iBC,3} = mesh.tnodes; iBC=iBC+1;
BC{iBC,1} = 'dxf'; BC{iBC,2} = 0; BC{iBC,3} = mesh.bnodes; iBC=iBC+1;
BC{iBC,1} = 'dyf'; BC{iBC,2} = 0; BC{iBC,3} = mesh.bnodes; iBC=iBC+1;
% Base of obstacle
BC{iBC,1} = 'dxf'; BC{iBC,2} = 0; BC{iBC,3} = [144 161 178]; iBC=iBC+1;
BC{iBC,1} = 'dyf'; BC{iBC,2} = 0; BC{iBC,3} = [144 161 178]; iBC=iBC+1;
% Fix mesh at boundaries, done by setting 'solid' BCs
% Inlet
BC{iBC,1} = 'dxm'; BC{iBC,2} = 0; BC{iBC,3} = mesh.lnodes; iBC=iBC+1;
BC{iBC,1} = 'dym'; BC{iBC,2} = 0; BC{iBC,3} = mesh.lnodes; iBC=iBC+1;
% Top and bottom
BC{iBC,1} = 'dxm'; BC{iBC,2} = 0; BC{iBC,3} = mesh.tnodes; iBC=iBC+1;
BC{iBC,1} = 'dym'; BC{iBC,2} = 0; BC{iBC,3} = mesh.tnodes; iBC=iBC+1;
BC{iBC,1} = 'dxm'; BC{iBC,2} = 0; BC{iBC,3} = mesh.bnodes; iBC=iBC+1;
BC{iBC,1} = 'dym'; BC{iBC,2} = 0; BC{iBC,3} = mesh.bnodes; iBC=iBC+1;
% Fix mesh at base of obstacle
BC{iBC,1} = 'dxs'; BC{iBC,2} = 0; BC{iBC,3} = mesh.block_base; iBC=iBC+1;
BC{iBC,1} = 'dys'; BC{iBC,2} = 0; BC{iBC,3} = mesh.block_base; iBC=iBC+1;
% Obstacle - match (interface nodes only)
BC{iBC,1} = 'm'; BC{iBC,2} = mesh.block_elem;
BC{iBC,3} = mesh.block_intf; iBC=iBC+1;
case('bar')
nBC = 2;
BC = cell(nBC,3);
iBC = 1;
BC{iBC,1} = 'dxs'; BC{iBC,2} = 0; BC{iBC,3} = mesh.block_base; iBC=iBC+1;
BC{iBC,1} = 'dys'; BC{iBC,2} = 0; BC{iBC,3} = mesh.block_base; iBC=iBC+1;
plots.disp_nodes = zeros(1,mesh.ny);
for nn = 1:mesh.ny
plots.disp_nodes(nn) = mesh.nx+(nn-1)*mesh.ny;
end
end
%% Initialization routines
plots = plots_init(mesh,plots,ndim_out);
%% Coefficients for local routines
coeff.rho_f = fprop.rho;
coeff.mu_f = fprop.mu;
coeff.rho_s = sprop.rho;
coeff.mu_s = sprop.mu;
coeff.lambda_s = sprop.lambda;
coeff.mu_m = mprop.mu;
coeff.ma = mprop.alpha;
coeff.lambda_m = mprop.lambda;
coeff.am = time.alpha_m;
coeff.afgdt = time.alpha_f*time.gamma*time.dt;
coeff.afbdt2= time.alpha_f*time.beta*time.dt^2;
coeff.c1 = c1;
coeff.dt = time.dt;
coeff.f = f;
%% Run Solver
% Initialize arrays
if (temp_sim)
% If simulation is temporal, use temporal loop
% Put variables in structure 'solver'
solver.BC = BC;
solver.Ff = Ff;
solver.sprop = sprop;
solver.fprop = fprop;
solver.gauss = gauss;
solver.iter = iter;
solver.time = time;
solver.ndim_out = ndim_out;
solver.plots = plots;
solver.coeff = coeff;
solver.mesh = mesh;
solver.ftxt = text_file;
solver.fdat = data_file;
solver.fmet = meta_file;
% Initial guess/starting point
[u0,udot0,p0,yddot0,ydot0,y0] = set_initial_state(mesh,BC,init_var);
% Initialize global arrays
gradG0 = zeros(5*mesh.nnode+1,5*mesh.nnode);
resG0 = zeros(5*mesh.nnode+1,1);
% Solve time evolving problem
[u,udot,p,yddot,ydot,y] = time_loop(gradG0,resG0,...
u0,udot0,p0,yddot0,ydot0,y0,solver);
else
% Call solver function
[u,f,x,y,conn] = main_fem(mesh.filename,Ff,BC,sprop,ndim_out);
plots_current(mesh,plots,ndim_out,u);
end