/* nag_mesh2d_inc (d06aac) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include #include #define EDGE(I, J) edge[3*((J) -1)+(I) -1] #define CONN(I, J) conn[3*((J) -1)+(I) -1] #define COOR(I, J) coor[2*((J) -1)+(I) -1] int main(int argc, char *argv[]) { FILE *fpin, *fpout; const Integer nvmax = 250; double coef, power; Integer exit_status, i1, i, itrace, k, nedge, nelt, nv, nvb, reftk; Nag_Boolean smooth; NagError fail; char pmesh[2]; double *bspace = 0, *coor = 0; Integer *conn = 0, *edge = 0; INIT_FAIL(fail); /* Check for command-line IO options */ fpin = nag_example_file_io(argc, argv, "-data", NULL); fpout = nag_example_file_io(argc, argv, "-results", NULL); exit_status = 0; fprintf(fpout, "nag_mesh2d_inc (d06aac) Example Program Results\n\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n] "); /* Reading of the geometry */ fscanf(fpin, "%ld%ld%*[^\n] ", &nvb, &nedge); if (nvb > nvmax) { fprintf(fpout, "Problem with the array dimensions\n"); fprintf(fpout, " nvb nvmax %6ld%6ld\n", nvb, nvmax); fprintf(fpout, " Please increase the value of nvmax\n"); exit_status = -1; goto END; } /* Allocate memory */ if (!(bspace = NAG_ALLOC(nvb, double)) || !(coor = NAG_ALLOC(2*nvmax, double)) || !(conn = NAG_ALLOC(3*(2*nvmax-1), Integer)) || !(edge = NAG_ALLOC(3*nedge, Integer))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } /* Coordinates of the boundary mesh vertices and boundary edges */ for (i = 1; i <= nvb; ++i) { fscanf(fpin, "%ld", &i1); fscanf(fpin, "%lf", &COOR(1, i)); fscanf(fpin, "%lf", &COOR(2, i)); fscanf(fpin, "%*[^\n] "); } for (i = 1; i <= nedge; ++i) { fscanf(fpin, "%ld", &i1); fscanf(fpin, "%ld", &EDGE(1, i)); fscanf(fpin, "%ld", &EDGE(2, i)); fscanf(fpin, "%ld", &EDGE(3, i)); fscanf(fpin, "%*[^\n] "); } fscanf(fpin, " ' %1s '%*[^\n]", pmesh); /* Initialise mesh control parameters */ for (i = 0; i < nvb; ++i) bspace[i] = 0.05; smooth = Nag_TRUE; itrace = 0; coef = 0.75; power = 0.25; /* Call to the mesh generator */ /* nag_mesh2d_inc (d06aac). * Generates a two-dimensional mesh using a simple * incremental method */ nag_mesh2d_inc(nvb, nvmax, nedge, edge, &nv, &nelt, coor, conn, bspace, smooth, coef, power, itrace, 0, &fail); if (fail.code == NE_NOERROR) { if (pmesh[0] == 'N') { fprintf(fpout, " nv =%6ld\n", nv); fprintf(fpout, " nelt =%6ld\n", nelt); } else if (pmesh[0] == 'Y') { /* Output the mesh to view it using the NAG Graphics Library */ fprintf(fpout, " %10ld%10ld\n", nv, nelt); for (i = 1; i <= nv; ++i) fprintf(fpout, " %15.6e %15.6e\n", COOR(1, i), COOR(2, i)); reftk = 0; for (k = 1; k <= nelt; ++k) { fprintf(fpout, " %10ld%10ld%10ld%10ld\n", CONN(1, k), CONN(2, k), CONN(3, k), reftk); } } else { fprintf(fpout, "Problem with the printing option Y or N\n"); exit_status = -1; goto END; } } else { fprintf(fpout, "Error from nag_mesh2d_inc (d06aac).\n%s\n", fail.message); exit_status = 1; goto END; } END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (bspace) NAG_FREE(bspace); if (coor) NAG_FREE(coor); if (conn) NAG_FREE(conn); if (edge) NAG_FREE(edge); return exit_status; }