-
Notifications
You must be signed in to change notification settings - Fork 2
/
initial.m
executable file
·59 lines (51 loc) · 1.37 KB
/
initial.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
function phi = initial()
global indexi indexj ip im
global x y xx yy
global h N_interface
% global phi
%----------------inital configuration-------------------
% global domain descritization
N = 100 ;
h = 10/(N-1); % grid spacing
x = -5: h: 5;
y = x;
% ip = zeros(N,1);
% im = zeros(N,1);
for i=1:N
ip(i) = i+1;
im(i) = i-1;
end
im(1)=N;
ip(N)=1;
indexi = N;
indexj = N;
phi= zeros(indexi,indexj); % phi initial
% interface descritization
N_interface = 400;
s = linspace(0,2*pi,N_interface+1);
s(N_interface+1) = [];
xx = cos(s);
yy = sin(s);
%-------------setting initial phi(only near interface) as SDF
for i=1:N_interface
labelx = ceil((xx(i)+5)/h);
labely = ceil((yy(i)+5)/h);
phi(labelx:labelx+1, labely:labely+1) = 1;
end
distance = 2*ones(N_interface,1);
% ------------- SDF -----------------
for j1= 1:indexi
for j2 = 1:indexj
if phi(j1,j2) == 1
for i = 1: N_interface;
distance(i) = sum(([x(j1),y(j2)] - [xx(i),yy(i)]).^2).^0.5;
end
Dij = min(distance);
if x(j1)^2+y(j2)^2-1<0 % in circle
Dij = - Dij;
end
phi(j1,j2) = Dij;
end
end
end
% surf(x,y,phi);