-
Notifications
You must be signed in to change notification settings - Fork 4
/
IC2d.m
177 lines (130 loc) · 5.22 KB
/
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
function u0 = IC2d(x,y,option)
%% Initial Condition (IC)
% This subroutine creates an special IC for testing purposes.
% The present IC models a rectangular domain with four equally sized
% regions with diferrent initial state value, u, an adimensional value.
%
% by Manuel Diaz, manuel.ade'at'gmail.com
% Institute of Applied Mechanics, 2012.09.06
%% Select your IC
switch option
case 1 % 4 quadrants in Domain [0,1]^2
[nN,nE] = size(x); domain = 'square';
switch domain
case 'square' % for Quad elements in a square domain!
% Calculate number of nodes and elements
u0 = zeros(nN,nE);
% Only valid for square domain
zero = zeros(sqrt(nE)/2); one = ones(sqrt(nE)/2);
% Initial Condition for our 2D domain
u0(:,[zero,zero;zero,one]==1) = 0.50;
u0(:,[zero,zero;one,zero]==1) = 0.70;
u0(:,[one,zero;zero,zero]==1) = 0.10;
u0(:,[zero,one;zero,zero]==1) = 0.90;
case 'squareT' % for Triangular elements in a square domain!
% Calculate number of nodes and elements
u0 = 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);
% Initial Condition for our 2D domain
u0(:,[zero,zero;zero,one]==1) = 0.50;
u0(:,[zero,zero;one,zero]==1) = 0.70;
u0(:,[one,zero;zero,zero]==1) = 0.10;
u0(:,[zero,one;zero,zero]==1) = 0.90;
case 'non-square' % domain is not square!
% set center
x0 = 0.5; y0 = 0.5;
% Preallocate u0,
u0 = zeros(nN,nE);
% Initial Condition for our 2D domain
u0(x >x0 & y >y0) = 0.50; % region 1
u0(x<=x0 & y >y0) = 0.70; % region 2
u0(x<=x0 & y<=y0) = 0.10; % region 3
u0(x >x0 & y<=y0) = 0.90; % region 4
end
case 2 % Square Jump
% set center
x0 = 0.5*(x(end)+x(1))+0.00;
y0 = 0.5*(y(end)+y(1))+0.25;
% parameters
Lx = x(end)-x(1);
Ly = y(end)-y(1);
% Preallocate u0
u0 = ones(size(x));
% Parameters of region
x1 = x0+Lx/12; x2 = x0-Lx/12;
y1 = y0+Ly/12; y2 = y0-Ly/12;
% Build Jump
u0(x>x1) = 0.001; u0(x<x2) = 0.001;
u0(y>y1) = 0.001; u0(y<y2) = 0.001;
case 3 % Sine*Cosine 2-D in Domain [-1,1]^2
u0 = sin(pi*x).*cos(pi*y);
case 4 % Gaussian Jump
% set center
x0 = (x(end)-x(1))/2; y0 = (y(end)-y(1))/2;
% Gaussian
u0 = 0.1 + 0.5*exp(-20*((x-x0).^2+(y-y0).^2));
case 5 % Cylindrical Jump
% set center
x0 = 0.5*(x(end)+x(1));
y0 = 0.5*(y(end)+y(1));
y0 = y0 + 0.25
% radious
r = 0.15;
% Gaussian
u0 = 0.1*ones(size(x));
u0(sqrt((x+x0).^2+(y+y0).^2)<r) = 1.0;
u0 = zeros(size(x));
u0(sqrt((x-x0).^2+(y-y0).^2)<r) = 1.0;
case 6 % rectangle in x direction
% set center
x0 = 0.0;
% parameters
Lx = x(end)-x(1);
% Preallocate u0
u0 = ones(size(x));
% Parameters of region
x1 = x0+Lx/10; x2 = x0-Lx/10;
% Build Jump
u0(x>x1) = 0.1; u0(x<x2) = 0.1;
case 7 % rectangle in y direction
% set center
y0 = 0.0;
% parameters
Ly = y(end)-y(1);
% Preallocate u0
u0 = ones(size(y));
% Parameters of region
y1 = y0+Ly/10; y2 = y0-Ly/10;
% Build Jump
u0(y>y1) = 0.1; u0(y<y2) = 0.1;
case 8 % Riemann for range [-1,1]
[nN,nE] = size(x);
% Calculate number of nodes and elements
u0 = zeros(nN,nE);
% Only valid for square domain
zero = zeros(sqrt(nE)/2); one = ones(sqrt(nE)/2);
% Initial Condition for our 2D domain
u0(:,[zero,one;zero,one]==1) = 0.10;
u0(:,[one,zero;one,zero]==1) = 1.00;
case 9 % Shu's 0.5 + Sin(x+y) for Burgers with periodic conditions
% make sure is on a domina of size [0,2*pi]x[0,2*pi].
u0 = 0.5 + sin(x+y);
case 10 % Steady wave for a square domain of size [-1,1]x[-1,1]
[nN,nE] = size(x);
% Calculate number of nodes and elements
u0 = zeros(nN,nE);
% Only valid for square domain
zero = zeros(sqrt(nE)/2); one = ones(sqrt(nE)/2);
% Initial Riemann Condition for our 2D domain
u0(:,[one,one;zero,zero]==1) = 0.10;
u0(:,[zero,zero;one,one]==1) = 1.00;
case 11 % Gaussian wave for [-3,3]
% for diffusion test with Dirichlet BCs. See ref [1].
mu = 0.01;
xmid = (x(end) + x(1))/2;
u0 = exp(-(x-xmid).^2/(4*mu));
otherwise
error('case not listed :P')
end