-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschnackenberg_final.edp
193 lines (191 loc) · 6.01 KB
/
schnackenberg_final.edp
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
//************Schnakenberg model transient+steady state code****************************//
//************Authors: Pratik Aghor, Ruchir Dwivedi*************************************//
real a,b,d;
real lambda=1.00;
//parameter definition// [a,b,d]=[0.1,1.1,12] or [0.9,2,24]
a=0;
b=lambda;
d=60;
real t=0.00;
real dt = 0.05;
real tmax=180;
real Lx = 39.9;
real Ly = 19.94;
int it=0;
real gamma=1;
real theta=0.49;
//real alpha= 0.5;
int icase=1;
//
mesh Th=square(90, 90, [-Lx/2+Lx*x, -Ly/2+Ly*y],flags=icase);
plot(Th, wait=0);
fespace Vh(Th, P1);
Vh u,uold,uh,uf;
Vh v,vold,vh,vf;
fespace Wh(Th, P1);
Wh dxu, dyu, dxv, dyv;
//weak form for u
problem heatu (u, uh) =
int2d(Th)(u*uh/dt)
-int2d(Th)(uold*uh/dt)
+int2d(Th)((1-theta)*dx(u)*dx(uh)
+(1-theta)*dy(u)*dy(uh))
+int2d(Th)((theta)*dx(uold)*dx(uh)
+(theta)*dy(uold)*dy(uh));
//
//weak form for v
problem heatv (v, vh) =
int2d(Th)(v*vh/dt)
-int2d(Th)(vold*vh/dt)
+int2d(Th)(d*(1-theta)*dx(v)*dx(vh)
+d*(1-theta)*dy(v)*dy(vh))
+int2d(Th)(d*(theta)*dx(vold)*dx(vh)
+d*(theta)*dy(vold)*dy(vh));
//Initializing
real m=1;
real kc=0.63;
real epsilon=1e-10;
real A=6;
real B=4;
u =1+0.5*cos(kc*sqrt(3)*(y)/2)*cos(kc*(x)/2)+0.75*cos(kc*x);
uold = u;
plot(u,value=1,fill=1,grey=1,cmm="initialize u",ps="initial u.jpg");
v = 1+0.5*sin(kc*(x)/2)*cos(kc*(x)/2);
vold = v;
plot(v,value=1,fill=1,grey=1,cmm="initialize v",ps="initial v.jpg");
//**********************Fractional Step Method********************************//
//**********************Step 1************************************************//
for(real t=0;t <=tmax;t=t+dt)
{
/////////4rth order Ruge-Kutta to solve reaction system:
//eqn is u’=f(t,u); time is from t1 to t2; time step h=(t2-t1)/N; u(t1)=u0;
//step1:
real t2=dt/2,t1=0;
real N=5;
real h= (t2-t1)/N;
//step2:
for(real t=t1;t < t2;t=t+h)
{
Vh K1,K2,K3,K4;
K1=h*(-uold+uold^2*vold); //K1=h*f(t,u(t1));
K2=h*(-(uold+K1/2)+(uold+K1/2)^2*vold);//K2=h*f(t+h/2,u(t1)+K1/2);
K3=h*(-(uold+K2/2)+(uold+K2/2)^2*vold);//K3=h*f(t+h/2,u(t1)+K2/2);
K4=h*(-(uold+K3)+(uold+K3)^2*vold);//K4=h*f(t+h,u(t1)+K3);
uold=uold+(K1+2*K2+2*K3+K4)/6;
//plot(uold,value=1,fill=0);
//t=t1+i*h;
}
for(real t=t1;t < 2*t2;t=t+h)
{
Vh A1,A2,A3,A4;
A1=h*(lambda-uold^2*vold);//A1=h*g(t,v(t1));
A2=h*(lambda-uold^2*(vold+A1/2));//A2=h*g(t+h/2,v(t1)+K1/2);
A3=h*(lambda-uold^2*(vold+A2/2));//A3=h*g(t+h/2,v(t1)+K2/2);
A4=h*(lambda-uold^2*(vold+A3));//A4=h*g(t+h,v(t1)+K3);
vold=vold+(A1+2*A2+2*A3+A4)/6;
//t=t1+j*h;
//plot(v,value=1,fill=0);
}
for(real t=t1;t < t2;t=t+h)
{
Vh K1,K2,K3,K4;
K1=h*(-uold+uold^2*vold); //K1=h*f(t,u(t1));
K2=h*(-(uold+K1/2)+(uold+K1/2)^2*vold);//K2=h*f(t+h/2,u(t1)+K1/2);
K3=h*(-(uold+K2/2)+(uold+K2/2)^2*vold);//K3=h*f(t+h/2,u(t1)+K2/2);
K4=h*(-(uold+K3)+(uold+K3)^2*vold);//K4=h*f(t+h,u(t1)+K3);
uold=uold+(K1+2*K2+2*K3+K4)/6;
//plot(uold,value=1,fill=0);
//t=t1+i*h;
}
//***********************************end of step 1******************************************//
//***********************************Step 2************************************************//
// over time ( dt )
heatv; vold = v;
//plot(v,fill=1,value=1);
heatu;
uold = u;
//plot(u,fill=1,value=1);
//***********************************end of step 2*****************************************//
//***********************************Step 3************************************************//
for(real t=t1;t < t2;t=t+h)
{
Vh K1,K2,K3,K4;
K1=h*(-uold+uold^2*vold); //K1=h*f(t,u(t1));
K2=h*(-(uold+K1/2)+(uold+K1/2)^2*vold);//K2=h*f(t+h/2,u(t1)+K1/2);
K3=h*(-(uold+K2/2)+(uold+K2/2)^2*vold);//K3=h*f(t+h/2,u(t1)+K2/2);
K4=h*(-(uold+K3)+(uold+K3)^2*vold);//K4=h*f(t+h,u(t1)+K3);
uold=uold+(K1+2*K2+2*K3+K4)/6;
//plot(uold,value=1,fill=0);
//t=t1+i*h;
}
for(real t=t1;t < 2*t2;t=t+h)
{
Vh A1,A2,A3,A4;
A1=h*(lambda-uold^2*vold);//A1=h*g(t,v(t1));
A2=h*(lambda-uold^2*(vold+A1/2));//A2=h*g(t+h/2,v(t1)+K1/2);
A3=h*(lambda-uold^2*(vold+A2/2));//A3=h*g(t+h/2,v(t1)+K2/2);
A4=h*(lambda-uold^2*(vold+A3));//A4=h*g(t+h,v(t1)+K3);
vold=vold+(A1+2*A2+2*A3+A4)/6;
//t=t1+j*h;
//plot(v,value=1,fill=0);
}
for(real t=t1;t < t2;t=t+h)
{
Vh K1,K2,K3,K4;
K1=h*(-uold+uold^2*vold); //K1=h*f(t,u(t1));
K2=h*(-(uold+K1/2)+(uold+K1/2)^2*vold);//K2=h*f(t+h/2,u(t1)+K1/2);
K3=h*(-(uold+K2/2)+(uold+K2/2)^2*vold);//K3=h*f(t+h/2,u(t1)+K2/2);
K4=h*(-(uold+K3)+(uold+K3)^2*vold);//K4=h*f(t+h,u(t1)+K3);
uold=uold+(K1+2*K2+2*K3+K4)/6;
//plot(uold,value=1,fill=0);
//t=t1+i*h;
}
//***********************************end of step 3*********************************//
//plot(v,fill=1,value=1);
u=uold;v=vold;
cout << "t=" << t << endl;
}
plot(u,fill=1,grey=1,value=1,cmm="u at t="+t,
wait=1,ps="u(t)("+t+").jpg");
plot(v,fill=1,grey=1,value=1,cmm="v at t="+t,
wait=1,ps="v(t)("+t+").jpg");
//*********************************end of transient code*************************//
fespace Ph(Th,[P1,P1]);
Ph [uh1,vh1],[u1,v1],[du,dv],[up,vp];
[u1,v1]=[uold,vold];
//******************************Weak Form(Steady State)**************************//
varf F([du,dv],[uh1,vh1])= int2d(Th)
(gamma*(((a-u1+u1^2*v1)*uh1)
+((b-u1^2*v1)*vh1))
-(dx(u1)*dx(uh1)+dy(u1)*dy(uh1))
-d*(dx(v1)*dx(vh1)+dy(v1)*dy(vh1)));
//****************Linearization***************************************************//
varf DF([du,dv],[uh1,vh1])=int2d(Th)(
gamma*(-uh1*du+2*u1*v1*uh1*du-2*u1*v1*vh1*du
+u1^2*uh1*dv-u1^2*vh1*dv)-(dx(du)*dx(uh1)+dy(du)*dy(uh1))
-d*(dx(dv)*dx(vh1)+dy(dv)*dy(vh1))
)
;
//********************End of linearization****************************************//
//********************Newton-Raphson**********************************************//
Ph [up1,up2];
for (int i=0;i < 400;i++)
{
up[]=u1[];
real[int] B= F(0,Ph);
//real res= B[]’*B[];
//cout << i << " residu^2 = " << res << endl;
matrix J;
J= DF(Ph,Ph,solver=UMFPACK);
real[int] w=J^-1*B;
u1[] -= w;
cout << " iter = " << i << " " << " w.linfty= " << w.linfty << endl;
if( w.linfty < 1e-6) break;
plot (u1,fill=1,value=1,cmm="solution with Newton Raphson u"
,ps="nrSolu("+i+").jpg",grey=1);
plot (v1,fill=1,value=1,cmm="solution with Newton Raphson v"
,ps="nrSolv("+i+").jpg",grey=1);
ofstream f("J.dat");
f << J << endl;
}
//******************End of Newton-Raphson*******************************************//