GFem language documentation -- 5.2 Scalar examples

Previous: 5.1 Triangulations examples
Up: 5 Examples
Next: 5.3 Complex number example

## 5.2 Scalar examples

- ELECTROSTATIC CONDENSOR

      /* a circle of radius 5 centered at (0,0) */
      border(1,0,2*pi,60) begin x := 5 * cos(t); y := 5 * sin(t) end ;
      /* The rectangle on the right */
      border(2,0,1,4) begin x:=1+t; y:=3 end ;
      border(2,0,1,24) begin x:=2; y:=3-6*t end ;
      border(2,0,1,4) begin x:=2-t; y:=-3 end ;
      border(2,0,1,24) begin x:=1; y:=-3+6*t end ;
      /* The rectangle on the left */
      border(3,0,1,4) begin x:=-2+t; y:=3 end ;
      border(3,0,1,24) begin x:=-1; y:=3-6*t end ;
      border(3,0,1,4) begin x:=-1-t; y:=-3 end ;
      border(3,0,1,24) begin x:=-2; y:=-3+6*t end ;
      buildmesh(800);

      /* Boundary conditions and PDE */
      solve(v)
      begin
         onbdy(1) v = 0;
         onbdy(2) v = 1;
         onbdy(3) v = -1;
         pde(v) -laplace(v) =0;
      end;
      plot(v);

- HEAT CONDUCTION AND RADIATION

      border(1,0,22,89)
      begin
       if(t<=10)then begin x:= t; y:=0 ; ib:=3 end;
       if((t>10)and(t<11))then begin x:=10; y:=t-10; ib:=2 end;
       if((t>=11)and(t<=21))then begin x:=21-t; y:=1; ib:=4  end;
       if(t>21)then begin x:=0; y:=22-t end;
      end;
      buildmesh(800);

      changewait;
      t0 := 10;  t1 := 100;  te := 25; b=0.1; c = 5.0e-8;
      w =  (b + 2*c * (te+546)*(te+273)*(te+273));
      solve(v,1)
      begin
        onbdy(1) v=t0; onbdy(2) v = t1; onbdy(3) dnu(v)=0;
        onbdy(4) id(v) * w + dnu(v) = te * w;
        pde(v) -laplace(v) * y =0;
      end;
      iter(10)
      begin u=v;
        w =  (b + c * (u+te + 546)*((u+273)*(u+273) + (te+273)*(te+273)));
      solve(v,-1) begin
        onbdy(1) v=t0; onbdy(2) v = t1;
        onbdy(3) dnu(v)=0; onbdy(4) id(v)*w  + dnu(v)= te * w;
        pde(v) -laplace(v) * y =0; plot(v);
      end;
      end

- HEAT: NON HOMOGENEOUS MATERIAL

      r0 := 1.0; r1 := 2.0;
      border(1,0,22,89)
      begin
       region :=1;
       if(t<10)then  begin x:= t; y:=0 ; ib:=3 end;
       if((t>=10)and(t<=11))then  begin x:=10; y:=r1*(t-10); ib:=2 end;
       if((t>11)and(t<21))then begin x:=21-t; y:=r1; ib:=4  end;
       if(t>=21)then begin x:=0; y:=r1*(22-t) end;
      end;
      border(0,0,10,41) begin x:= t; y:=r0 end;
      buildmesh(800);

      t0 = 10;  t1 = 100;  te := 25; kappa =0.01 +  max(y-1,0)/(y-1.0001);
      solve(v)
      begin
      onbdy(1) v=t0;
      onbdy(2) v = t1;
      onbdy(4) dnu(v)=0.2;
      onbdy(3) dnu(v)=0;
      pde(v) -laplace(v)*kappa*y +id(v)*kappa*y =0;
      plot(v);
      end;

- COMPRESSIBLE POTENTIAL FLOW

      changewait;/* gamma = 1.4, outer circle radius is 5 */
      mach1 := 1/sqrt(6); machinfty = 0.85*mach1;
      rhoinfty=sqrt((1-machinfty^2)^5);
      solve(phi) begin
      onbdy(1) dnu(phi) = rhoinfty*machinfty*x/5; onbdy(2) dnu(phi) = 0;
      pde(phi) id(phi)*0.0001-laplace(phi) = 0;
      end;
      u1 = dx(phi); u2 = dy(phi); rho=sqrt((1-(u1^2+ u2^2))^5); plot(phi);

      iter(5)
      begin
       solve(phi)
         onbdy(1)  dnu(phi) =rhoinfty*machinfty*x/5; onbdy(2) dnu(phi) = 0;
         pde(phi)  id(phi)*0.0001-laplace(phi)*rhop=0;
       end;
       u1 = dx(phi); u2 = dy(phi); rho=sqrt((1-(u1^2+ u2^2))^5);
       rhop = convect(rho,u1,u2,0.1); plot(rho)
      end;
      plot(sqrt((u1^2+u2^2))/mach1);

- NAVIER STOKES EQUATIONS

      /* 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);