forked from Tree-Yang/Process_Oriented_PDEM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPDEM_solve.m
215 lines (209 loc) · 8.5 KB
/
PDEM_solve.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
function [tm, rm, prob] = PDEM_solve(asgn_prob, d, v, t, dt, thres)
%number of representative points
np = length(asgn_prob);
%number of time step
nt = length(t);
d_max = max(max(abs(d))); %maximum displacement
v_max = max(max(abs(v))); %maximum velocity
%range of the mesh
f_r = 2; %parameters for the range of the mesh
if length(thres(:)) == 1
% circle boundary, i.e., the upper threshold is equal to
% the lower threshold in terms of absolute value
if isinf(thres)
thres0 = f_r*abs(d_max);
end
bd_absorb(1) = -thres0;
bd_absorb(2) = thres0;
elseif length(thres(:)) == 2 && thres(1) ~= thres(2)
thres0 = thres;
%two-sided boundary
for k = 1:1:2
if isinf(thres(k))
thres0(k) = sign(thres(k))*f_r*abs(d_max);
end
end
bd_absorb(1) = min(thres0);
bd_absorb(2) = max(thres0);
elseif length(thres(:)) == 2 && thres(1) == thres(2)
thres0 = thres(1);
if isinf(thres0)
thres0 = f_r*abs(d_max);
end
bd_absorb(1) = -thres0;
bd_absorb(2) = thres0;
else
n_in = length(thres);
error('The dimension of <thres> must be 1 or 2 rather than %d!', n_in);
end
%factor for mesh adjustion
f_msh_adj = 0.95;
%mesh size in response
dr = dt/(f_msh_adj/abs(v_max));
%number of mesh
nr1 = abs(bd_absorb(1))/dr;
nr2 = abs(bd_absorb(2))/dr;
%adjusted number of mesh in response
if bd_absorb(1) * bd_absorb(2) <= 0
nr = ceil(nr1) + ceil(nr2);
elseif bd_absorb(1) > 0 && bd_absorb(2) > 0
nr = ceil(nr2) - floor(nr1);
elseif bd_absorb(1) < 0 && bd_absorb(2) < 0
nr = ceil(nr1) - floor(nr2);
end
%adjusted mesh size in response
dr = (bd_absorb(2) - bd_absorb(1))/nr;
%adjusted mesh ratio
mesh_ratio = dt / dr;
if bd_absorb(1) <= 0 && bd_absorb(2) >= 0
grid_r1 = -(ceil(nr1):-1:0)' * dr;
grid_r2 = (1:1:ceil(nr2))' * dr;
grid_r = [grid_r1; grid_r2];
elseif bd_absorb(1) <= 0 && bd_absorb(2) < 0
grid_r = -(ceil(nr1):-1:floor(nr2))' * dr;
elseif bd_absorb(1) > 0 && bd_absorb(2) > 0
grid_r = (floor(nr1):1:ceil(nr2))' * dr;
end
%mesh in time
grid_t = t;
%grid of mesh
[tm, rm] = meshgrid(grid_t, grid_r);
%information display
fprintf('The number of the representative points is %15d.\n', np);
fprintf('The maximum value of the response is %15.6f.\n', d_max);
fprintf('The lower boundary of the mesh domain is %15.6f.\n', bd_absorb(1));
fprintf('The upper boundary of the mesh domain is %15.6f.\n', bd_absorb(2));
fprintf('The mesh size for response is %15.6f.\n', dr);
fprintf('The mesh size for time is %15.6f.\n', dt);
fprintf('The mesh ratio is %15.6f.\n', mesh_ratio);
fprintf('The number of grid for response is %15d.\n', length(grid_r));
fprintf('The number of grid for time is %15d.\n', length(grid_t));
prob = zeros(size(tm));
% for each of the representative point
for nn = 1:1:np
fprintf('Representative point: %15d/%6d.\n',nn,np);
%initial condition
prob0 = zeros(size(tm));
%location of the initial response
n_ini = round(abs(d(1,nn)-bd_absorb(1))/dr);
prob0(n_ini+1, 1) = 1/dr;
if d(1,nn) > bd_absorb(2) || d(1,nn) < bd_absorb(1)
error('The initial response is out of the mesh domain!');
end
%for each time step
for kk = 1:1:nt-1
% the velocity at current time step
a = v(kk,nn);
%for each response grid
for jj = 1:1:nr
%flux limiter
%-------------------------------------------------------------------------
%r_j+1/2^+, r3
if jj == nr
r11 = 1;
elseif jj == nr-1
if prob0(jj+1, kk) == prob0(jj, kk)
r11 = 1;
else
r11 = -prob0(jj+1, kk)/(prob0(jj+1, kk)-prob0(jj, kk));
end
else
if prob0(jj+1, kk) == prob0(jj, kk)
r11 = 1;
else
r11 = (prob0(jj+2, kk)-prob0(jj+1, kk))/(prob0(jj+1, kk)-prob0(jj, kk));
end
end
%-------------------------------------------------------------------------
%r_j+1/2^-, r1
if jj == nr
if prob0(jj, kk) == 0
r12 = 1;
else
r12 = (prob0(jj, kk)-prob0(jj-1, kk))/(-prob0(jj, kk));
end
elseif jj == 1
if prob0(jj+1, kk) == prob0(jj, kk)
r12 = 1;
else
r12 = prob0(jj, kk)/(prob0(jj+1, kk)-prob0(jj, kk));
end
else
if prob0(jj+1, kk) == prob0(jj, kk)
r12 = 1;
else
r12 = (prob0(jj, kk)-prob0(jj-1, kk))/(prob0(jj+1, kk)-prob0(jj, kk));
end
end
%-------------------------------------------------------------------------
%r_j-1/2^+, r4
if jj == nr
if prob0(jj, kk) == prob0(jj-1, kk)
r21 = 1;
else
r21 = (-prob0(jj, kk))/(prob0(jj, kk)-prob0(jj-1, kk));
end
elseif jj == 1
if prob0(jj, kk) == 0
r21 = 1;
else
r21 = (prob0(jj+1, kk)-prob0(jj, kk))/(prob0(jj, kk));
end
else
if prob0(jj, kk) == prob0(jj-1, kk)
r21 = 1;
else
r21 = (prob0(jj+1, kk)-prob0(jj, kk))/(prob0(jj, kk)-prob0(jj-1, kk));
end
end
%-------------------------------------------------------------------------
%r_j-1/2^-, r2
if jj == 1
r22 = 1;
elseif jj == 2
if prob0(jj, kk) == prob0(jj-1, kk)
r22 = 1;
else
r22 = prob0(jj-1, kk)/(prob0(jj, kk)-prob0(jj-1, kk));
end
else
if prob0(jj, kk) == prob0(jj-1, kk)
r22 = 1;
else
r22 = (prob0(jj-1, kk)-prob0(jj-2, kk))/(prob0(jj, kk)-prob0(jj-1, kk));
end
end
%phi
phi11 = max(max(0,min(2*r11,1)),min(r11,2)); %r3
phi12 = max(max(0,min(2*r12,1)),min(r12,2)); %r1
phi21 = max(max(0,min(2*r21,1)),min(r21,2)); %r4
phi22 = max(max(0,min(2*r22,1)),min(r22,2)); %r2
phi1 = heaviside(-a)*phi11 + heaviside(a)*phi12;
phi2 = heaviside(-a)*phi21 + heaviside(a)*phi22;
%finite difference update with tvd scheme
if jj == 1
d_prob_1 = prob0(jj+1, kk) - prob0(jj, kk);
d_prob_2 = prob0(jj, kk);
elseif jj == nr
d_prob_1 = -prob0(jj, kk);
d_prob_2 = prob0(jj, kk) - prob0(jj-1, kk);
else
d_prob_1 = prob0(jj+1, kk) - prob0(jj, kk);
d_prob_2 = prob0(jj, kk) - prob0(jj-1, kk);
end
tmp = mesh_ratio*a;
%check the CFL conditon
if abs(tmp) > 1
warining('The CFL condition is not verified at current time step!')
end
prob0(jj, kk+1) = prob0(jj, kk) - 1/2*(tmp-abs(tmp))*d_prob_1...
- 1/2*(tmp+abs(tmp))*d_prob_2...
- 1/2*(abs(tmp)-tmp^2)*(phi1*d_prob_1-phi2*d_prob_2);
if grid_r(jj)>bd_absorb(2) || grid_r(jj)<bd_absorb(1)
prob0(jj, kk+1) = 0;
end
end
end
prob = prob + asgn_prob(nn)*prob0;
end
end