/* Poor but better than none algorithm*/
changewait;
border(1,0,1,6) begin x:=0; y:=1-t end;
border(2,0,1,15) begin x:=2*t; y:=0 end;
border(2,0,1,10) begin x:=2; y:=-t end;
border(2,0,1,20) begin x:=2+3*t; y:=-1 end;
border(2,0,1,35) begin x:=5+15*t; y:=-1 end;
border(3,0,1,10) begin x:=20; y:=-1+2*t end;
border(4,0,1,35) begin x:=5+15*(1-t); y:=1 end;
border(4,0,1,40) begin x:=5*(1-t);y:=1 end;
buildmesh(900);
nu = 0.002; dt := 0.4;
/* initial pressure */
solve(p,1)
onbdy(1)dnu(p) =-2*nu;
onbdy(3) p=0; onbdy(2,4) dnu(p) = 0;
pde(p) - laplace(p)= 0;
end;
/* initial horizontal velocity */
solve(u,2) begin
onbdy(1) u = y*(1-y);
onbdy(3) dnu(u) = 0; onbdy(2,4) u = 0;
pde(u) id(u)/dt-laplace(u)*nu = -min(y*y-y,0)/dt;
end;
/* initial vertical velocity */
solve(v,3)begin
onbdy(1,3)v = 0; onbdy(2,4) v = 0;
pde(v) id(v)/dt-laplace(v)*nu =0;
end;
un = u; vn = v;
iter(80)
begin f=convect(un,u,v,dt); g=convect(vn,u,v,dt);
/*Horizontal velocity*/
solve(u,-2) begin
onbdy(1) u = y*(1-y); onbdy(2,4) u = 0;
onbdy(3)dnu(u)=0;
pde(u) id(u)/dt-laplace(u)*nu = f/dt -dx(p);
end;
plot(u);
/* Vertical velocity */
solve(v,-3) begin
onbdy(1,2,3,4) v = 0;
pde(v) id(v)/dt-laplace(v)*nu = g/dt -dy(p);
end;
/* Pressure */
solve(p,-1) begin
onbdy(1)dnu(p) =-2*nu;
onbdy(3) p=0; onbdy(2,4) dnu(p) = 0;
pde(p) -laplace(p)= -(dx(f) + dy(g))/dt;
end;
un = u; vn = v;
end ;
save('u.dta',u); save('v.dta',v); save('p.dta',p); plot(u);
|