pde .

“msharpmath”, The Simple is the Best

[100] 008 Tutorial pde              partial differential equations

Click the above button for full-text tutorial of  ‘pde’.

//————————————————————————————————————

//==================================================================================
//  Umbrella  ‘bvp’  for Initial Boundary Value Problems (parabolic PDE)
//  Umbrella  ‘pde’  for elliptic Partial Differential Equations (elliptic PDE)
//==================================================================================

//———————————————————-
//  parabolic  PDE
//———————————————————-
time variable t (parabolic character)
space variable x (elliptic character)
dependent variable u

Partial differentiations are defined as
u’ = u_x
u” = u_xx
u”’ = u_xxx
u”” = u_xxxx
@u = u_t
@u’ = u_tx
@u” = u_txx

(Syntax)

bvp .@ t[n,g=1](to,tf) .x[n,g=1] (a,b)
{ IC }  // initial conditions
{ PDE, [BCs] }   // BCs are  in orders of x-start, x-end
.plot(num)( … )

%> conduction in a slab =============================================
bvp .@ t[21](0, 0.12) .x[21](0,1)     // domain
{ u = 0 }  (        // IC
-{@u} + {u”} = 0,    // PDE
[ {u'} = 0,  {u} = 1 ]   // BCs at  x(0), x(1)
) .plot2[11](u) ;

%> conduction in a sphere ===========================================
bvp .@ t[21](0, 0.12) .r[21](0,1)     // domain
{ u = 0 }  (        // IC
-(r^2)*{@u} + {(r^2)u’}’ = 0,    // PDE  in conservative form, note outside ‘
[ {u'} = 0,  {u} = 1 ]   // BCs at r(0), r(1)
) .plot2[11](u) ;

%>  initial BVP
#{
bvp .@t[21](0,2) .x[21](0,1)        // Hub span
{ u = sin(pi*x) }                              // Hub field (initial condition)
(                                                         // Stem
-pi*pi*{@u} + {u”} = 0,
[ {u} = 0,  pi*exp(-t)+{u'} = 0 ]  // boundary conditions at x(0), x(1)
)
.peep .plot2[6](u) ;                       // Spoke
#}

when plot2  is replaced by plot, we get

 

%> system of initial BVP,  coupled PDE


#{
bvp .@t[5](0,2) .x[10](0,1) {      // Hub span
u = [ 1+0.5*cos(2*pi*x), -pi*sin(2*pi*x) ],
v = [ 1-0.5*cos(2*pi*x),  pi*sin(2*pi*x) ]   // Hub field
} (
-{@u} + 0.05*{u”} + 0.1/(1+v*v) = 0,   [ {u'} = 0, {u'} = 0 ],  // x(0), x(1)
-{@v} + 0.05*{v”} + 0.1/(1+u*u) = 0,   [ {v'} = 0, {v'} = 0 ]    // x(0), x(1)
)
.peep
.togo( U = u, U1 = u’, V = v, V1 = v’, KE = 0.5*(u’*u’+v’*v’) )
.plot[6](u,v+2, 4 + 0.5*(u’*u’+v’*v’));
#}

#> u; v; U; U1; V; V1; KE;

 

%>  boundary layers and rapid change in small time


#> tout = [0, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 1.5, 2];;

#{
bvp.@t[21,1.4](0,2) .x[21,-1.1](0,1) { u = 1, v = 0 }
(
-{@u}+0.024*{u”}-( exp(5.73*(u-v))-exp(-11.46*(u-v)) ) = 0, [ {u'} = 0, {u} = 1 ],
-{@v}+0.170*{v”}+( exp(5.73*(u-v))-exp(-11.46*(u-v)) ) = 0, [ {v} = 0,  {v'} = 0 ]
)
.relax(0.4) .maxiter(400) .peep
.plot[tout](u, 2+v );
#}

 

 

//———————————————————-
//  elliptic  PDE
//———————————————————-
space variable x, y (elliptic character)
dependent variable u

Partial differentiations are defined as
u’  = u_x
u” = u_xx
u^  = u_y
u^^ = u_yy

(Syntax)

PDE : cuxx*{u”}+cuyy*{u^^}+cux*{u’}+cuy*{u^}+cu*{u} = cs

BCs :  bux*{u’}+buy*{u^}+bu*{u} = bs

pde .x[n,g=1](xa,xb) .y[n,g=1](c(x),d(x))
{ PDE, [BCs] }    // BCs are in order of x-start, x-end, y-start, y-end
.plot(num)( … )

   // BCs are [ x-left BC, x-right BC, y-left BC, y-right BC ]

 

%>  PDE with exact solution     //  elliptic PDE


#{
pde .x[10](-1,1) .y[10](-1,1) (
{u”} + {u^^} = 6,
[ {u} = 1+2*y*y, {u} = 1+2*y*y,    // x(-1), x(1)
{u} = x*x+2, {u} = x*x+2 ]          // y(-1), y(1)
)
.plot( u, -u+x*x+2*y*y )
.togo( Error = -u+x*x+2*y*y );
#}
#> Error;

 

//   conservative forms (d means partial differentiation)

{(p)u’}’ = d/dx ( p du/dx )
{(p)u^}^ = d/dy ( p du/dy )

%> PDE in conservative form


#> pde .xi[21](-1,1) .eta[21]( -1,1 ) (
{(exp(5*xi)+1)u’}’ + {(exp(5*eta)+1)u^}^ + 10 = 0,
[ {u} = 0, {u} = 0, {u} = 0, {u} = 0 ]
)
.plot(u);

%> PDE with nonuniform grid


#> pde .x[21](-3,3) .y[21]( -sqrt(10-x*x),4-x/2 ) (
{(exp(x)+1)u’}’ + {(exp(y)+1)u^}^ + u*{u’} + {u^} + u + 2 = 0,
[ {u} = 0, {u} = 0, {u} = 0, {u} = 0 ]
)
.plot(u);

%> System of steady elliptic PDEs (coupled PDEs)


#> pde .x[30](0,1) .y[30](0,1) (
{u”} + {u^^} + 5 – u*{u’}-v*{u^} = 0, [ {u} = 0, {u} = 0, {u} = 0, {u} = 0 ],
{v”} + {v^^} – 3 – u*{v’}-v*{v^} = 0, [ {v} = 0, {v} = 0, {v} = 0, {v} = 0 ]
).plot( u,v-0.1  );

 

%> Data extraction


#> pde .x[4](0,1) .y[5](0,1) (
{u”} + {u^^} + 5 = 0, [ {u} = 1, {u} = 1, {u} = 1, {u} = 1 ]
)
.plot( u )
.togo( X = x, Y = y, U = u );

#>  X; Y; U;

X =
[             0      0.166667           0.5      0.833333             1 ]
[             0      0.166667           0.5      0.833333             1 ]
[             0      0.166667           0.5      0.833333             1 ]
[             0      0.166667           0.5      0.833333             1 ]
[             0      0.166667           0.5      0.833333             1 ]
[             0      0.166667           0.5      0.833333             1 ]
Y =
[             0             0             0             0             0 ]
[         0.125         0.125         0.125         0.125         0.125 ]
[         0.375         0.375         0.375         0.375         0.375 ]
[         0.625         0.625         0.625         0.625         0.625 ]
[         0.875         0.875         0.875         0.875         0.875 ]
[             1             1             1             1             1 ]
U =
[             1             1             1             1             1 ]
[             1       1.14447       1.20626       1.14447             1 ]
[             1       1.24869       1.37578       1.24869             1 ]
[             1       1.24869       1.37578       1.24869             1 ]
[             1       1.14447       1.20626       1.14447             1 ]
[             1             1             1             1             1 ]

Comments are closed.