/* fem_bihar2dps_la.c Galerkin FEM biharmonic 4th order * * solve uxxxx(x,y) + uyyyy(x,y) + 2*uxxyy(x,y) = f(x,y) * * f(x,y) := 4.0*sin(x)*sin(y) * * in the rectangle xmin< x #include #include #include #include #include "simeq.h" #include "laphi.h" #include "deriv.h" #include "gaulegf.h" #undef abs #define abs(a) ((a)<0.0?(-(a)):(a)) #undef max #define max(a,b) ((a)>(b)?(a):(b)) #define nx 9 #define ny 9 #define npx 9 #define npy 9 static double xmin = 0.0; /* problem parameters */ static double xmax = 3.14159; static double ymin = 0.0; static double ymax = 3.14159; static double start, now, prev; /* timing */ /* i, j, nx, ii, jj, ny, xg, yg needed by galk or galf, available at call*/ static int i, j, ii, jj; static double xg[nx]; /* X grig */ static double yg[ny]; /* Y grid */ static double hx, hy; static double ug[nx*ny]; /* solution */ static double maxerr; /* function prototypes */ double F(double x, double y); /* RHS */ double ub(double x, double y); double galk(double x, double y); /* Galerkin k function for this problem */ double galf(double x, double y); /* Galerkin f function for this problem */ void write_soln(); void check_soln(); int main(int argc, char * argv[]) { int nxy = nx*ny; double x, y; /* npx, npy Gauss Legendre integration order */ double xx[npx]; double wx[npx]; double yy[npy]; double wy[npy]; double val, err, avgerr; int px, py; double kg[nx*ny][nx*ny]; double fg[nx*ny]; double Ua[nx*ny]; int stat; printf("fem_bihar2dps_la.c fourth order biharmonic PDE\n"); start = (double)time(NULL); prev = start; printf("solve uxxxx(x,y) + 2*uxxyy(x,y) + uyyyy(x,y) = f(x,y)\n"); printf("f(x,y) := 4*sin(x)*sin(y) \n"); printf(" \n"); printf("in the rectangle xmin< x maxerr) maxerr = err; avgerr = avgerr + err; /* printf("ug[%d,%d]=%f, Ua=%f, err=%g \n", */ /* i,ii,ug[i*ny+ii],Ua[i*ny+ii],ug[i*ny+ii]-Ua[i*ny+ii]); */ } } printf("xmax=%f, ymax=%f, nx=%d, ny=%d, npx=%d, npy=%d \n", xmax,ymax,nx,ny,npx,npy); printf(" maxerr=%g, avgerr=%g \n", maxerr,avgerr/(double)(nx*ny)); printf("\n"); now = (double)time(NULL); fprintf(stderr, "total CPU time = %f seconds \n", now-start); printf("total CPU time = %f seconds \n", now-start); printf("calling gnuplot \n"); fflush(stdout); stat = execl("/usr/bin/gnuplot","-persist","fem_bihar2dps_la_c.plot", NULL); /* only returns upon error, no return on sucess */ printf("returned from gnuplot with stat= %d \n", stat); return 0; } /* end fem_bihar2dps_la main */ /* PDE problem definition functions f and ub */ double F(double x, double y) { return 4.0*sin(x)*sin(y); } double ub(double x, double y) { return sin(x)*sin(y); } double galk(double x, double y) { /* Galerkin k stiffness function for this problem */ /* solve uxxxx(x,y) + 2*uxxyy(x,y) + uyyyy(x,y) = f(x,y) */ return ( phipppp(x,j,nx-1,xg)* phi(y,jj,ny-1,yg) + 2.0* phipp(x,j,nx-1,xg)* phipp(y,jj,ny-1,yg) + phi(x,j,nx-1,xg)* phipppp(y,jj,ny-1,yg) )* phi(x,i,nx-1,xg)* phi(y,ii,ny-1,yg); } /* end galk used by integration */ double galf(double x, double y) /* Galerkin f function for this problem */ { return F(x,y)*phi(x,i,nx-1,xg)*phi(y,ii,ny-1,yg); } /* end galf used by integration */ void write_soln() { FILE * fout; fout = fopen("fem_bihar2dps_la_c.dat", "w"); if(fout==NULL) { printf("file fem_bihar2dps_la_c.dat can not be opened for writing\n"); return; } printf("writing fem_bihar2dps_la_c.dat \n"); for(i=0; i