-
Notifications
You must be signed in to change notification settings - Fork 12
/
Euler_IC2d.m
258 lines (218 loc) · 8.8 KB
/
Euler_IC2d.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
function [r_0,u_0,v_0,p_0] = Euler_IC2d(x,y,input)
% Load the IC of a 1D Riemann classical schok tube problem configuration.
% In the notation we take advantage of the matlab array notation as follows
%
% 1.0 +-----------+-----------+
% | | |
% | reg 2 | reg 1 |
% | | |
% 0.5 +-----------+-----------+
% | | |
% | reg 3 | reg 4 |
% | | |
% 0.0 +-----------+-----------+
% 0.0 0.5 1.0
%
% prop = [prop_reg1 , prop_reg2 , prop_reg3 , prop_reg4]
%
% r = rho/density
% u = velocity in x direction
% v = velocity in y direction
% p = Pressure
%
% Manuel Diaz, NTU, 2014.06.27
%% Initial Physical Properties per case:
switch input
case{1} % Configuration 1
fprintf('Configuration 1 \n');
p = [1.0 0.4 0.0439 0.15 ];
r = [1.0 0.5197 0.1072 0.2579];
u = [0.0 -0.7259 -0.7259 0.0 ];
v = [0.0 -0.0 -1.4045 -1.4045];
case{2} % Configuration 2
fprintf('Configuration 2 \n');
p = [1.0 0.4 1.0 0.4 ];
r = [1.0 0.5197 1.0 0.5197];
u = [0.0 -0.7259 -0.7259 0.0 ];
v = [0.0 0.0 -0.7259 -0.7259];
case{3} % Configuration 3
fprintf('Configuration 3 \n');
p = [1.5 0.3 0.029 0.3 ];
r = [1.5 0.5323 0.138 0.5323];
u = [0.0 1.206 1.206 0.0 ];
v = [0.0 0.0 1.206 1.206 ];
case{4} % Configuration 4
fprintf('Configuration 4 \n');
p = [1.1 0.35 1.1 0.35 ];
r = [1.1 0.5065 1.1 0.5065];
u = [0.0 0.8939 0.8939 0.0 ];
v = [0.0 0.0 0.8939 0.8939];
case{5} % Configuration 5
fprintf('Configuration 5 \n');
p = [ 1.0 1.0 1.0 1.0 ];
r = [ 1.0 2.0 1.0 3.0 ];
u = [-0.75 -0.75 0.75 0.75];
v = [-0.5 0.5 0.5 -0.5 ];
case{6} % Configuration 6
fprintf('Configuration 6 \n');
p = [ 1.0 1.0 1.0 1.0 ];
r = [ 1.0 2.0 1.0 3.0 ];
u = [ 0.75 0.75 -0.75 -0.75];
v = [-0.5 0.5 0.5 -0.5 ];
case{7} % Configuration 7
fprintf('Configuration 7 \n');
p = [1.0 0.4 0.4 0.4 ];
r = [1.0 0.5197 0.8 0.5197];
u = [0.1 -0.6259 0.1 0.1 ];
v = [0.1 0.1 0.1 -0.6259];
case{8} % Configuration 8
fprintf('Configuration 8 \n');
p = [0.4 1.0 1.0 1.0 ];
r = [0.5197 1.0 0.8 1.0 ];
u = [0.1 -0.6259 0.1 0.1 ];
v = [0.1 0.1 0.1 -0.6259];
case{9} % Configuration 9
fprintf('Configuration 9 \n');
p = [1.0 1.0 0.4 0.4 ];
r = [1.0 2.0 1.039 0.5197];
u = [0.0 0.0 0.0 0.0 ];
v = [0.3 -0.3 -0.8133 -0.4259];
case{10} % Configuration 10
fprintf('Configuration 10 \n');
p = [1.0 1.0 0.3333 0.3333];
r = [1.0 0.5 0.2281 0.4562];
u = [0.0 0.0 0.0 0.0 ];
v = [0.4297 0.6076 -0.6076 -0.4297];
case{11} % Configuration 11
fprintf('Configuration 11 \n');
p = [1.0 0.4 0.4 0.4 ];
r = [1.0 0.5313 0.8 0.5313];
u = [0.1 0.8276 0.1 0.1 ];
v = [0.0 0.0 0.0 0.7276];
case{12} % Configuration 12
fprintf('Configuration 12 \n');
p = [0.4 1.0 1.0 1.0 ];
r = [0.5313 1.0 0.8 1.0 ];
u = [0.0 0.7276 0.0 0.0 ];
v = [0.0 0.0 0.0 0.7276];
case{13} % Configuration 13
fprintf('Configuration 13 \n');
p = [ 1.0 1.0 0.4 0.4 ];
r = [ 1.0 2.0 1.0625 0.5313];
u = [ 0.0 0.0 0.0 0.0 ];
v = [-0.3 0.3 0.8145 0.4276];
case{14} % Configuration 14
fprintf('Configuration 14 \n');
p = [ 8.0 8.0 2.6667 2.6667];
r = [ 2.0 1.0 0.4736 0.9474];
u = [ 0.0 0.0 0.0 0.0 ];
v = [-0.5606 -1.2172 1.2172 1.1606];
case{15} % Configuration 15
fprintf('Configuration 15 \n');
p = [ 1.0 0.4 0.4 0.4 ];
r = [ 1.0 0.5197 0.8 0.5313];
u = [ 0.1 -0.6259 0.1 0.1 ];
v = [-0.3 -0.3 -0.3 0.4276];
case{16} % Configuration 16
fprintf('Configuration 16 \n');
p = [0.4 1.0 1.0 1.0 ];
r = [0.5313 1.0222 0.8 1.0 ];
u = [0.1 -0.6179 0.1 0.1 ];
v = [0.1 0.1 0.1 0.8276];
case{17} % Configuration 17
fprintf('Configuration 17 \n');
p = [ 1.0 1.0 0.4 0.4 ];
r = [ 1.0 2.0 1.0625 0.5197];
u = [ 0.0 0.0 0.0 0.0 ];
v = [-0.4 -0.3 0.2145 -1.1259];
case{18} % Configuration 18
fprintf('Configuration 18 \n');
p = [1.0 1.0 0.4 0.4 ];
r = [1.0 2.0 1.0625 0.5197];
u = [0.0 0.0 0.0 0.0 ];
v = [1.0 -0.3 0.2145 0.2741];
case{19} % Configuration 19
fprintf('Configuration 19 \n');
p = [1.0 1.0 0.4 0.4 ];
r = [1.0 2.0 1.0625 0.5197];
u = [0.0 0.0 0.0 0.0 ];
v = [0.3 -0.3 0.2145 -0.4259];
case 'test'
fprintf('Sods Shocktube configuration in 2d \n');
p = [0.1 1 1 0.1 ];
r = [0.125 1 1 0.125];
u = [0 0 0 0 ];
v = [0 0 0 0 ];
case 'test2'
fprintf('Sods Shocktube configuration in 2d \n');
p = [1 1 0.1 0.1 ];
r = [1 1 0.125 0.125] ;
u = [0 0 0 0 ];
v = [0 0 0 0 ];
otherwise
error('only 18 cases are available');
end
%% Print configuration of selected IC
fprintf('\n');
fprintf(' reg 1 reg 2 reg 3 reg 4\n');
fprintf('density : %2.4f %2.4f %2.4f %2.4f \n',r);
fprintf(' x-vel : %2.4f %2.4f %2.4f %2.4f \n',u);
fprintf(' y-vel : %2.4f %2.4f %2.4f %2.4f \n',v);
fprintf('Presure : %2.4f %2.4f %2.4f %2.4f \n',p);
fprintf('\n');
%% Load Selected case Initial condition:
[nN,nE] = size(x); domain = 'non-square';
switch domain
case 'square' % for Quad elements in a square domain!
% Calculate number of nodes and elements
r_0 = zeros(nN,nE); u_0 = zeros(nN,nE);
v_0 = zeros(nN,nE); p_0 = zeros(nN,nE);
% Only valid for square domain
zero = zeros(sqrt(nE)/2); one = ones(sqrt(nE)/2);
% Parameters of regions dimensions
reg1 = [zero,zero;zero,one]==1; % region 1
reg2 = [zero,zero;one,zero]==1; % region 2
reg3 = [one,zero;zero,zero]==1; % region 3
reg4 = [zero,one;zero,zero]==1; % region 4
% Initial Condition for our 2D domain
r_0(:,reg1) = r(1); r_0(:,reg2) = r(2);
r_0(:,reg3) = r(3); r_0(:,reg4) = r(4);
u_0(:,reg1) = u(1); u_0(:,reg2) = u(2);
u_0(:,reg3) = u(3); u_0(:,reg4) = u(4);
v_0(:,reg1) = v(1); v_0(:,reg2) = v(2);
v_0(:,reg3) = v(3); v_0(:,reg4) = v(4);
p_0(:,reg1) = p(1); p_0(:,reg2) = p(2);
p_0(:,reg3) = p(3); p_0(:,reg4) = p(4);
case 'squareT' % for Triangular elements in a square domain!
% Calculate number of nodes and elements
r_0 = zeros(nN,nE); u_0 = zeros(nN,nE);
v_0 = zeros(nN,nE); p_0 = zeros(nN,nE);
% Only valid for square domain
zero = zeros(sqrt(nE/2),sqrt(nE/2)/2);
one = ones(sqrt(nE/2),sqrt(nE/2)/2);
% Parameters of regions dimensions
reg1 = [zero,zero;zero,one]==1; % region 1
reg2 = [zero,zero;one,zero]==1; % region 2
reg3 = [one,zero;zero,zero]==1; % region 3
reg4 = [zero,one;zero,zero]==1; % region 4
% Initial Condition for our 2D domain
r_0(:,reg1) = r(1); r_0(:,reg2) = r(2);
r_0(:,reg3) = r(3); r_0(:,reg4) = r(4);
u_0(:,reg1) = u(1); u_0(:,reg2) = u(2);
u_0(:,reg3) = u(3); u_0(:,reg4) = u(4);
v_0(:,reg1) = v(1); v_0(:,reg2) = v(2);
v_0(:,reg3) = v(3); v_0(:,reg4) = v(4);
p_0(:,reg1) = p(1); p_0(:,reg2) = p(2);
p_0(:,reg3) = p(3); p_0(:,reg4) = p(4);
case 'non-square' % domain is not square!
% Parameters of regions dimensions
reg1 = (x>=0.5 & y>=0.5); % region 1
reg2 = (x <0.5 & y>=0.5); % region 2
reg3 = (x <0.5 & y <0.5); % region 3
reg4 = (x>=0.5 & y <0.5); % region 4
% Initial Condition for our 2D domain
r_0 = r(1)*reg1 + r(2)*reg2 + r(3)*reg3 + r(4)*reg4; % Density, rho
u_0 = u(1)*reg1 + u(2)*reg2 + u(3)*reg3 + u(4)*reg4; % velocity in x
v_0 = v(1)*reg1 + v(2)*reg2 + v(3)*reg3 + v(4)*reg4; % velocity in y
p_0 = p(1)*reg1 + p(2)*reg2 + p(3)*reg3 + p(4)*reg4; % temperature.
end