-
Notifications
You must be signed in to change notification settings - Fork 3
/
Dendritic_Solidification.asv
151 lines (119 loc) · 3.44 KB
/
Dendritic_Solidification.asv
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
Mesh_X = 1;
Mesh_Y = 1;
MeshX = 1;
MeshY = 1;
WidthX = 299;
HeightY = 299;
CenterX = (WidthX - 1) / 2;
CenterY = (HeightY - 1) / 2;
a1 = 1.25 / (sqrt(2.0));
a2 = 0.64;
epsilon = 0.05;
k = 6;
beta0 = 0;
W0 = 1;
D = 2;
d0 = 0.5;
lambda = (W0 * a1) / d0;
tau0 = (((W0^3) * a1 * a2) / (d0 * D)) + (((W0^2) * beta0) / d0);
delta = 0.8;
r0 = 5;
deltaT = 0.1;
phi_OLD = zeros(WidthX,HeightY);
phi_NEW = zeros(WidthX,HeightY);
u_OLD=zeros(WidthX,HeightY);
u_NEW=zeros(WidthX,HeightY);
Theta_1=zeros(WidthX,HeightY);
%Initial Condition
for X = 1:WidthX
for Y = 1:HeightY
r=sqrt((X-CenterX)^2+(Y-CenterY)^2);
if r < r0
phi_OLD(X,Y)=1;
u_OLD(X,Y)=0;
elseif r>=r0
phi_OLD(X,Y)=-1;
u_OLD(X,Y)=-delta*(1-exp((-r-r0)));
end
end
end
%Initial Condition
max_phi=max(phi_OLD(:));
min_u=min(u_OLD(:));
index_phi=100/max_phi;
index_u=100/min_u;
figure(1)
image(phi_OLD*index_phi)
colormap('jet')
figure(2)
image(u_OLD*index_u)
colormap('jet')
for t=1:4000
for X=1:WidthX
for Y=1:HeightY
if (X>1 && Y>1)
if (X<WidthX && Y<HeightY)
Theta_1(X,Y)=Theta(phi_OLD,X,Y,Mesh_X,Mesh_Y);
end
end
end
end
for X=1:WidthX
for Y=1:HeightY
if (X>1 && Y>1)
if(X<WidthX && Y<HeightY)
phi_NEW(X,Y)=phi_OLD(X,Y)+(deltaT/Tau(Theta_1(X,Y),epsilon,k,tau0))*(2*(W0^2)*B(Theta_1(X,Y),epsilon,k)*Inner_Multiply(Grad(phi_OLD,X,Y,Mesh_X,Mesh_Y,MeshX,MeshY),Grad(Theta_1,X,Y,Mesh_X,Mesh_Y,MeshX,MeshY))+(W0^2)*(f_A(Theta_1(X,Y),epsilon,k)^2)*Laplacian(phi_OLD,X,Y,Mesh_X,Mesh_Y,MeshX,MeshY)+(W0^2)*D_B(Theta_1(X,Y),epsilon,k)*Outter_Multiply(Grad(phi_OLD,X,Y,Mesh_X,Mesh_Y,MeshX,MeshY),Grad(Theta_1,X,Y,Mesh_X,Mesh_Y,MeshX,MeshY))-DF(phi_OLD(X,Y),u_OLD(X,Y),lambda));
end
end
end
end
for X=1:WidthX
for Y=1:HeightY
if (X>1 && Y>1)
if(X<WidthX && Y<HeightY)
u_NEW(X,Y)=u_OLD(X,Y)+D*deltaT*Laplacian(u_OLD,X,Y,Mesh_X,Mesh_Y,MeshX,MeshY)+(0.5)*(phi_NEW(X,Y)-phi_OLD(X,Y));
end
end
end
end
%Boundary Conditions
for X=1:WidthX
for Y=1:HeightY
if (X==1 && Y~=1 && Y~=HeightY)
phi_NEW(X,Y)=phi_NEW(X+1,Y);
elseif (Y==1 && X~=1 && X~=WidthX)
phi_NEW(X,Y)=phi_NEW(X,Y+1);
end
end
end
phi_NEW(1,1)= (phi_NEW(2, 1) + phi_NEW(1, 2)) / 2;
for X=1:WidthX
for Y=1:HeightY
if (X==WidthX && Y~=1 && Y~=HeightY)
phi_NEW(X,Y)=phi_NEW(1,Y);
elseif (Y==HeightY && X~=1 && X~=WidthX)
phi_NEW(X,Y)=phi_NEW(X,1);
end
end
end
u_NEW(WidthX, 1, i) = (u_NEW(WidthX - 1, 1, i) + u_NEW(WidthX, 2, i)) / 2
u_NEW(WidthX, HeightY, i) = (u_NEW(WidthX, HeightY - 1, i) + u_NEW(WidthX - 1, HeightY, i)) / 2
u_NEW(1, HeightY, i) = (u_NEW(1, HeightY - 1, i) + u_NEW(2, HeightY, i)) / 2
%Boundary Conditions
for X=1:WidthX
for Y=1:HeightY
phi_OLD(X,Y)=phi_NEW(X,Y);
u_OLD(X,Y)=u_NEW(X,Y);
end
end
max_phi=max(phi_OLD(:));
min_u=min(u_OLD(:));
index_phi=100/max_phi;
index_u=100/min_u;
figure(3)
image(phi_OLD*index_phi)
colormap('jet')
figure(4)
image(u_OLD*index_u)
colormap('jet')
end