sandbox/yixian/Poisson2Daxicyl.c
We solve an axisymmetric Poisson’s Problem from Wang’s thesis.
The longitudinal coordinate (z-axis) is x, and the radial coordinate (\rho- or r-axis) is y. Note that y (and so Y0) cannot be negative.
\frac {\partial_y (y \epsilon \partial_y \phi)}{y} + \partial_x(\epsilon \partial_x \phi) = - \frac{sin(y)}{e^{x} y}
with Boundary Condition : \phi(0,y) =cos(y) \phi(1,y) =e^{-1}cos(y) \phi(x,1) =e^{-x}cos(1) The exact solution of the above axisymmetric problem is given by \phi = e^{-x} cos y
#include "grid/multigrid.h"
#include "axi.h"
#include "run.h"
#include "poisson.h"
#define LEVEL 6
mgstats mg;
scalar phi[];
face vector epsilon[];
face vector a[], alpha[];
face vector gradphi[];
double dx,dy;
The source term
#define RHOE(x,y) sin(y)/(y*exp(x))
The exact solution
#define PHIE(x,y) exp(-x)*cos(y)
The boundary condition
[right] = dirichlet(exp(-1)*cos(y));
phi[left] = dirichlet(cos(y));
phi[top] = dirichlet(exp(-x)*cos(1.)); phi
Main Program
int main()
{
= 1.;
L0 = 1 << LEVEL;
N = 1./N;
dx = 1./N;
dy run();
}
event init (i = 0) {
scalar rhoe[], rhs[];
foreach() {
[] = RHOE(x,y);
rhoe[] = -rhoe[]*cm[];
rhs[] = 0.;
phi}
foreach_face()
.x[] = fm.x[];
epsilonboundary ((scalar *){rhoe, phi, epsilon});
= poisson (phi, rhs, epsilon);
mg }
save field
event interface (t = 0 ) {
char s[80];
sprintf (s, "field-%g.txt", t);
FILE * fp = fopen (s, "w");
output_field ({phi}, fp, linear = true);
fclose (fp);
analytical solution
FILE * fpx = fopen("Fce.txt", "w");
for (double x = 0 ; x <=1; x += dx){
for (double y = 0; y <= 1; y += dy){
fprintf (fpx, "%g %g %g \n", x, y, PHIE (x,y));}
fprintf (fpx,"\n");}
fclose(fpx);
Error
FILE * fpe = fopen("Fcerror.txt", "w");
static double cerror=0., ce=0., cs=0.;
for (double x = 0 ; x <=1; x += dx){
for (double y = 0; y <= 1; y += dy){
= fabs(PHIE (x,y));
ce = fabs( interpolate (phi, x, y));
cs +=(ce-cs)*(ce-cs);
cerror}}
fprintf (fpe, " %g \n", fabs(cerror));
fclose(fpe);
}
Run
to run
qcc -g -O2 -Wall -o Poisson Poisson2Daxicyl.c -lm
./Poisson > out
sp 'field-0.txt', 'Fce.txt'
Bibliography
Kaichun Wang, BEM simulation for glass parisons, Ph.D. thesis, Eindhoven Technical University, the Netherlands, 2002.