0% found this document useful (0 votes)
14 views8 pages

Lisa

This document contains source code in the FreeFem programming language for solving the Navier-Stokes equations numerically. It defines the geometry and mesh, sets up function spaces, solves an initial Stokes problem, then time steps the Navier-Stokes equations over 50 time steps while plotting the streamlines and velocity at each step. Key steps include defining borders and building a mesh, solving Stokes for initial velocity, solving for streamlines, time stepping the Navier-Stokes equations with convection terms using previous time step velocities, and plotting various outputs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views8 pages

Lisa

This document contains source code in the FreeFem programming language for solving the Navier-Stokes equations numerically. It defines the geometry and mesh, sets up function spaces, solves an initial Stokes problem, then time steps the Navier-Stokes equations over 50 time steps while plotting the streamlines and velocity at each step. Key steps include defining borders and building a mesh, solving Stokes for initial velocity, solving for streamlines, time stepping the Navier-Stokes equations with convection terms using previous time step velocities, and plotting various outputs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

LISA

Velocity X

Velocity Y

pressure
Vorticity Z

Velocity Magnitude

Vorticity Magnitude
Freefem

U1

U2
Streamline
Source code FreeFem

real L=5;

real ratio=L;

border floor (t=1,4) {x=t; y=1; label=1;};

border IN2 (t=1,2) {x=4; y=t; label=2;};

border datar1 (t=4,3) {x=t; y=2; label=3;};

border naik2 (t=2,8) {x=3; y=t; label=4;};

border datar2 (t=3,2) {x=t; y=8; label=5;};

border turun1 (t=2,1) {x=t; y=x+6; label=6;};

border OUT (t=7,6) {x=1; y=t; label=7;};

border naik3 (t=1,2) {x=t; y=x+5; label=8;};

border turun3 (t=7,2) {x=2; y=t; label=9;};

border datar3 (t=2,1) {x=t; y=2; label=10;};

border IN1 (t=2,1) {x=1; y=t; label=11;};

int n=10;

mesh Th= buildmesh(floor(ratio*n)+IN2(ratio*n)+datar1(ratio*n)+naik2(ratio*n)+

datar2(ratio*n)+turun1(ratio*n)+OUT(ratio*n)+naik3(ratio*n)+turun3(ratio*n)

+datar3(ratio*n)+IN1(ratio*n));

plot (Th,wait=1);

//plot(floor(n),IN2(n),datar1(n),naik2(n),datar2(n),turun1(n),OUT(n),naik3(n),wait=1);

fespace Xh(Th,P2);

fespace Mh(Th,P1);
Xh u2,v2;

Xh u1,v1;

Mh p,q;

//solve stokes problem for initial value of u

solve Stokes ([u1,u2,p],[v1,v2,q],solver=Crout) =

int2d(Th)( ( dx(u1)*dx(v1) + dy(u1)*dy(v1)

+ dx(u2)*dx(v2) + dy(u2)*dy(v2) )

+ p*q*(0.000001)

+ p*dx(v1)+ p*dy(v2)

+ dx(u1)*q+ dy(u2)*q

+ on(1,u1=0,u2=0)

+ on(2,u1=-1,u2=0)

+ on(3,u1=0,u2=0)

+ on(4,u1=0,u2=0)

+ on(5,u1=0,u2=0)

+ on(6,u1=0,u2=0)

//+ on(7,u1=0,u2=0)

+ on(8,u1=0,u2=0)

+ on(9,u1=0,u2=0)

+ on(10,u1=0,u2=0)

+ on(11,u1=1,u2=0)

Xh psi,phi;

solve streamlines(psi,phi) =

int2d(Th)( dx(psi)*dx(phi) + dy(psi)*dy(phi))


+ int2d(Th)( -phi*(dy(u1)-dx(u2)))

+ on(1,psi=0);

plot(psi);

int i=0;

real nu=1./4000.; //reynold = 100

real dt=0.1;

real alpha=1/dt;

Xh up1,up2;

problem NS ([u1,u2,p],[v1,v2,q],solver=Crout,init=i) =

int2d(Th)(

alpha*( u1*v1 + u2*v2)

+ nu * ( dx(u1)*dx(v1) + dy(u1)*dy(v1)

+ dx(u2)*dx(v2) + dy(u2)*dy(v2) )

+ p*q*(0.000001)

+ p*dx(v1)+ p*dy(v2)

+ dx(u1)*q+ dy(u2)*q

+ int2d(Th) ( -alpha*convect([up1,up2],-dt,up1)*v1 -alpha*convect([up1,up2],-dt,up2)*v2 )

+ on(1,u1=0,u2=0)

+ on(2,u1=-1,u2=0)

+ on(3,u1=0,u2=0)

+ on(4,u1=0,u2=0)

+ on(5,u1=0,u2=0)

+ on(6,u1=0,u2=0)

// + on(7,u1=0,u2=0)
+ on(8,u1=0,u2=0)

+ on(9,u1=0,u2=0)

+ on(10,u1=0,u2=0)

+ on(11,u1=1,u2=0)

for (i=0;i<=50;i++)

up1=u1;

up2=u2;

NS;

streamlines;

plot(cmm=i,psi);

};

plot(cmm="u1",u1,wait=1,fill=1);

plot(cmm="u2",u2,wait=1,fill=1);

plot(coef=0.2,cmm=" [u1,u2] and streamlines ",psi,[u1,u2],wait=1);

You might also like