8 main::main(CkArgMsg *m)
10 mesh = CProxy_chunk::ckNew();
12 CkGetChareID(&mainhandle);
13 CProxy_main M(mainhandle);
16 CmiAbort("Usage: tri <meshfile>\n");
17 CkPrintf("Opening file %s...\n", m->argv[1]);
20 M.performRefinements();
23 void main::readMesh(char *filename)
26 int numC, cid, numNodes, numEdges, numElements, i, j, k;
32 CkPrintf("Reading mesh from file %s... \n", filename);
33 fp = fopen(filename, "r");
34 fscanf(fp, "%d", &numC);
35 CkPrintf("%d chunk(s)...", numC);
37 CkPrintf("\n ...Reading chunks...\n");
38 for (i=0; i<numC; i++) {
39 fscanf(fp, "%d", &cid);
40 fscanf(fp, "%d%d%d", &numNodes, &numEdges, &numElements);
41 CkPrintf("Chunk %d has %d nodes, %d edges, %d elements.\n", cid,
42 numNodes, numEdges, numElements);
47 for (j=0; j<numNodes; j++) {
49 fscanf(fp, "%lf%lf", &nm->x, &nm->y);
50 mesh[cid].addNode(nm);
52 for (j=0; j<numEdges; j++) {
55 fscanf(fp, "%d%d", &edm->nodes[k].idx, &edm->nodes[k].cid);
57 fscanf(fp, "%d%d", &edm->elements[k].idx, &edm->elements[k].cid);
58 mesh[cid].addEdge(edm);
60 for (j=0; j<numElements; j++) {
63 fscanf(fp, "%d%d", &elm->nodes[k].idx, &elm->nodes[k].cid);
65 fscanf(fp, "%d%d", &elm->edges[k].idx, &elm->edges[k].cid);
66 mesh[cid].addElement(elm);
72 CkPrintf("\nDone.\n");
75 void main::performRefinements()
77 refineMsg *rm = new refineMsg;
78 coarsenMsg *cm = new coarsenMsg;
82 CkPrintf("Awaiting mesh construction completion...\n");
85 mesh.deriveBorderNodes();
88 CkPrintf("Printing start mesh... \n");
92 CkPrintf("Beginning meshing around... \n");
97 mesh[0].refineElement(rm);
100 CkPrintf("Printing mesh after 1st refine... \n");
108 CkPrintf("Printing mesh after improvement... \n");
117 mesh[0].refineElement(rm);
120 CkPrintf("Printing mesh after 2nd refine... \n");
128 mesh[0].refineElement(rm);
131 CkPrintf("Printing mesh after 3rd refine... \n");
139 mesh[0].setTargetArea(dm);
143 mesh[0].setTargetArea(dm);
148 mesh[0].refineElement(rm);
151 CkPrintf("Printing mesh after 4th refine... \n");
159 mesh[0].setTargetArea(dm);
163 mesh[0].setTargetArea(dm);
167 mesh[0].setTargetArea(dm);
171 mesh[0].setTargetArea(dm);
175 mesh[0].setTargetArea(dm);
180 mesh[0].refineElement(rm);
183 CkPrintf("Printing mesh after 5th refine... \n");
189 // Freshen the mesh first!
193 for (int p=0; p<200; p++) {
197 mesh[0].resetTargetArea(dm);
202 mesh[0].coarsenElement(cm);
205 CkPrintf("Printing mesh after 1st coarsen... \n");
214 mesh[3].coarsenElement(cm);
217 CkPrintf("Printing mesh after 2nd coarsen... \n");
225 mesh[0].coarsenElement(cm);
228 CkPrintf("Printing mesh after 6th coarsen... \n");
236 mesh[0].coarsenElement(cm);
239 CkPrintf("Printing mesh after 6th coarsen... \n");
244 CkPrintf("Done meshing around... exiting.\n");