00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <string.h>
00004 #include "chunk.h"
00005 #include "pgm.h"
00006 #include "Pgm.def.h"
00007
00008 main::main(CkArgMsg *m)
00009 {
00010 mesh = CProxy_chunk::ckNew();
00011
00012 CkGetChareID(&mainhandle);
00013 CProxy_main M(mainhandle);
00014
00015 if (m->argc != 2)
00016 CmiAbort("Usage: pmaf <meshfile>\n");
00017 strcpy(filename, m->argv[1]);
00018 CkPrintf("Opening file %s...\n", filename);
00019
00020 M.readMesh();
00021 }
00022
00023 void main::readMesh()
00024 {
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 FILE *fp;
00040 int numElements, numGhosts, numSurfaces, idxOffset, numNodes, numFixed,
00041 cid, i, j, k;
00042 int *conn, *gid, *surface, *fixedNodes;
00043 double *nodeCoords;
00044 meshMsg *mm;
00045 coordMsg *cm;
00046
00047 CkPrintf("Reading mesh from file %s... \n", filename);
00048 fp = fopen(filename, "r");
00049 fscanf(fp, "%d", &numChunks);
00050 CkPrintf("%d chunk(s)", numChunks);
00051
00052
00053 CkPrintf("\n ...Reading chunks...\n");
00054 for (i=0; i<numChunks; i++) {
00055
00056 mesh[i].insert(numChunks);
00057
00058 fscanf(fp, "%d", &cid);
00059 fscanf(fp, "%d%d%d%d", &numElements, &numGhosts, &numSurfaces, &idxOffset);
00060 CkPrintf("Chunk %d has %d elements, %d ghosts, %d surfaces.\n", cid,
00061 numElements, numGhosts, numSurfaces);
00062
00063
00064 numNodes = 0;
00065 conn = new int[numGhosts*4];
00066 gid = new int[numGhosts*2];
00067 surface = new int[numSurfaces*3];
00068 CkPrintf("Reading elements...\n");
00069 for (j=0; j<numGhosts; j++) {
00070 for (k=0; k<4; k++) {
00071 fscanf(fp, "%d", &conn[j*4+k]);
00072 CkPrintf("Node is %d!\n", conn[j*4+k]);
00073 if (conn[j*4+k]+1 > numNodes)
00074 numNodes = conn[j*4+k]+1;
00075 }
00076 }
00077 CkPrintf("Detected %d nodes on chunk %d...\n", numNodes, i);
00078 for (j=0; j<numGhosts; j++)
00079 for (k=0; k<2; k++)
00080 fscanf(fp, "%d", &gid[j*2+k]);
00081
00082 for (j=0; j<numSurfaces; j++)
00083 for (k=0; k<3; k++)
00084 fscanf(fp, "%d", &surface[j*3+k]);
00085
00086
00087
00088 CkPrintf("Sending elements to chunk...\n");
00089 mm = new(numGhosts*4, numGhosts*2, numSurfaces*3, 0) meshMsg;
00090 mm->numElements = numElements;
00091 mm->numGhosts = numGhosts;
00092 mm->numSurFaces = numSurfaces;
00093 mm->idxOffset = idxOffset;
00094 for (j=0; j<numGhosts*4; j++) mm->conn[j] = conn[j];
00095 for (j=0; j<numGhosts*2; j++) mm->gid[j] = gid[j];
00096 for (j=0; j<numSurfaces*3; j++) mm->surface[j] = surface[j];
00097 mesh[i].newMesh(mm);
00098
00099
00100 CkPrintf("Reading node values...\n");
00101 nodeCoords = new double[numNodes*3];
00102 for (j=0; j<numNodes; j++) {
00103 for (k=0; k<3; k++)
00104 fscanf(fp, "%lf", &nodeCoords[j*3+k]);
00105 }
00106 fscanf(fp, "%d", &numFixed);
00107 fixedNodes = new int[numFixed];
00108 for (j=0; j<numFixed; j++)
00109 fscanf(fp, "%d", &fixedNodes[j]);
00110
00111
00112
00113 CkPrintf("Sending node values to chunk...\n");
00114 cm = new(numNodes*3, numFixed, 0) coordMsg;
00115 cm->numNodes = numNodes;
00116 cm->numElements = numElements;
00117 cm->numFixed = numFixed;
00118 for (j=0; j<numNodes*3; j++) {
00119 cm->coords[j] = nodeCoords[j];
00120 CkPrintf(" %lf ", nodeCoords[j]);
00121 }
00122 for (j=0; j<numFixed; j++)
00123 cm->fixedNodes[j] = fixedNodes[j];
00124 CkPrintf("\n");
00125 CkPrintf("\n");
00126 mesh[i].updateNodeCoords(cm);
00127
00128
00129 delete[] conn;
00130 delete[] gid;
00131 delete[] nodeCoords;
00132 delete[] surface;
00133 delete[] fixedNodes;
00134 CkPrintf("Done reading chunk %d.\n", i);
00135 }
00136 mesh.doneInserting();
00137
00138 fclose(fp);
00139 CkPrintf("\nDone reading 3D mesh file.\n");
00140 CkWaitQD();
00141 mesh.deriveFaces();
00142 CkWaitQD();
00143
00144 CkPrintf("Printing start mesh... \n");
00145 for (i=0; i<numChunks; i++)
00146 mesh[i].print();
00147 CkWaitQD();
00148
00149 CkPrintf("Beginning meshing around... \n");
00150 for (i=0; i<numChunks; i++) {
00151 mesh[i].refine();
00152 }
00153 for (i=0; i<numChunks; i++)
00154 mesh[i].start();
00155 CkWaitQD();
00156
00157 CkPrintf("Done refining.\n");
00158 CkPrintf("Printing refined mesh... \n");
00159 for (i=0; i<numChunks; i++)
00160 mesh[i].print();
00161 CkWaitQD();
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187 CkExit();
00188 }