/* fempt_bihar2dps_la.c Galerkin FEM biharmonic 4th order * using pthreads * * 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 #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 */ /* nx, ny, xg, yg needed by galk or galf, available at call*/ static double xg[nx]; /* X grig */ static double yg[ny]; /* Y grid */ static double hx, hy; static double ug[nx*ny]; /* solution */ static double kg[nx*ny][nx*ny]; static double fg[nx*ny]; /* npx, npy Gauss Legendre integration order */ static double xx[npx]; static double wx[npx]; static double yy[npy]; static double wy[npy]; /* function prototypes */ double F(double x, double y); /* RHS */ double ub(double x, double y); /* Galerkin k function for this problem */ double galk(double x, double y, int i, int j, int ii, int jj); /* Galerkin f function for this problem */ double galf(double x, double y, int i, int ii); void write_soln(); void check_soln(); void *compute(void *arg); int main(int argc, char * argv[]) { int nxy = nx*ny; double x, y; double Ua[nx*ny]; int stat; int worker; int ids[nx]; /* worker id number */ pthread_t threads[nx]; /* holds thread info */ int errcode; /* holds pthread error code */ int *status; /* holds return code */ double pnow, wnow; /* time CPU and wall */ int i, j, ii, jj; double val, maxerr, err, avgerr; printf("fempt_bihar2dps_la.c running.\n"); now = (double)time(NULL); start = now; prev = now; printf("solve uxxxx(x,y) + 2*uxxyy(x,y) + uyyyy(x,y) = f(x,y)\n"); printf(" \n"); printf("f(x,y) := 4.0*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 wall time = %f seconds \n", now-start); printf("total wall time = %f seconds \n", now-start); printf("calling gnuplot \n"); fflush(stdout); stat = execl("/usr/bin/gnuplot","-persist","fempt_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 fempt_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); } /* Galerkin k stiffness function for this problem */ /* solve uxxxx(x,y) + 2*uxxyy(x,y) + uyyyy(x,y) = f(x,y) */ double galk(double x, double y, int i, int j, int ii, int jj) { 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 */ /* Galerkin f function for this problem */ double galf(double x, double y, int i, int ii) { 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; int i, ii; fout = fopen("fempt_bihar2dps_la_c.dat", "w"); if(fout==NULL) { printf("file fempt_bihar2dps_la_c.dat can not be opened for writing\n"); return; } printf("writing fempt_bihar2dps_la_c.dat \n"); for(i=0; i