/* nag_mesh2d_renum (d06ccc) 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; char *outfile = 0; Integer exit_status, i, itrace, nedge, nelt, nnz, nnzmax, nv, reftk; NagError fail; char pmesh[2]; double *coor = 0; Integer *conn = 0, *edge = 0, *icol = 0, *irow = 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); (void) nag_example_file_io(argc, argv, "-nag_write", &outfile); exit_status = 0; fprintf(fpout, " nag_mesh2d_renum (d06ccc) Example Program Results\n\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n] "); /* Reading of the geometry */ fscanf(fpin, "%ld", &nv); fscanf(fpin, "%ld", &nelt); fscanf(fpin, "%ld", &nedge); fscanf(fpin, "%*[^\n] "); nnzmax = 10*nv; /* Allocate memory */ if (!(coor = NAG_ALLOC(2*nv, double)) || !(conn = NAG_ALLOC(3*nelt, Integer)) || !(edge = NAG_ALLOC(3*nedge, Integer)) || !(irow = NAG_ALLOC(nnzmax, Integer)) || !(icol = NAG_ALLOC(nnzmax, Integer))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } for (i = 1; i <= nv; ++i) { fscanf(fpin, "%lf", &COOR(1, i)); fscanf(fpin, "%lf", &COOR(2, i)); fscanf(fpin, "%*[^\n] "); } for (i = 1; i <= nelt; ++i) { fscanf(fpin, "%ld", &CONN(1, i)); fscanf(fpin, "%ld", &CONN(2, i)); fscanf(fpin, "%ld", &CONN(3, i)); fscanf(fpin, "%ld", &reftk); fscanf(fpin, "%*[^\n] "); } for (i = 1; i <= nedge; ++i) { fscanf(fpin, "%ld", &reftk); fscanf(fpin, "%ld", &EDGE(1, i)); fscanf(fpin, "%ld", &EDGE(2, i)); fscanf(fpin, "%ld", &EDGE(3, i)); fscanf(fpin, "%*[^\n] "); } fscanf(fpin, " ' %1s '", pmesh); fscanf(fpin, "%*[^\n] "); /* Compute the sparsity of the FE matrix */ /* from the input geometry */ /* nag_mesh2d_sparse (d06cbc). * Generates a sparsity pattern of a Finite Element matrix * associated with a given mesh */ nag_mesh2d_sparse(nv, nelt, nnzmax, conn, &nnz, irow, icol, &fail); if (fail.code == NE_NOERROR) { if (pmesh[0] == 'N') { fprintf(fpout, " The Matrix Sparsity characteristics\n"); fprintf(fpout, " before the renumbering\n"); fprintf(fpout, " nv =%6ld\n", nv); fprintf(fpout, " nnz =%6ld\n", nnz); } else if (pmesh[0] == 'Y') { /* Output the sparsity of the mesh to view */ /* it using the NAG Graphics Library */ fprintf(fpout, " %10ld%10ld\n", nv, nnz); for (i = 0; i < nnz; ++i) fprintf(fpout, " %10ld%10ld\n", irow[i], icol[i]); } else { fprintf(fpout, "Problem with the printing option Y or N\n"); exit_status = -1; goto END; } } else { fprintf(fpout, "Error from nag_mesh2d_sparse (d06cbc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Call the renumbering routine and get the new sparsity */ itrace = 1; /* nag_mesh2d_renum (d06ccc). * Renumbers a given mesh using Gibbs method */ if (outfile) fclose(fpout); nag_mesh2d_renum(nv, nelt, nedge, nnzmax, &nnz, coor, edge, conn, irow, icol, itrace, outfile, &fail); if (outfile && !(fpout = fopen(outfile, "a"))) { exit_status = 2; goto END; } if (fail.code == NE_NOERROR) { if (pmesh[0] == 'N') { fprintf(fpout, "\n The Matrix Sparsity characteristics\n"); fprintf(fpout, " after the renumbering\n"); fprintf(fpout, " nv =%6ld\n", nv); fprintf(fpout, " nnz =%6ld\n", nnz); fprintf(fpout, " nelt =%6ld\n", nelt); } else if (pmesh[0] == 'Y') { /* Output the sparsity of the renumbered mesh */ /* to view it using the NAG Graphics Library */ fprintf(fpout, "%10ld%10ld\n", nv, nnz); for (i = 0; i < nnz; ++i) fprintf(fpout, " %10ld%10ld\n", irow[i], icol[i]); /* Output the renumbered 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 (i = 1; i <= nelt; ++i) fprintf(fpout, " %10ld%10ld%10ld%10ld\n", CONN(1, i), CONN(2, i), CONN(3, i), reftk); } } else { fprintf(fpout, "Error from nag_mesh2d_renum (d06ccc).\n%s\n", fail.message); exit_status = 1; goto END; } END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (coor) NAG_FREE(coor); if (conn) NAG_FREE(conn); if (edge) NAG_FREE(edge); if (irow) NAG_FREE(irow); if (icol) NAG_FREE(icol); return exit_status; }