/* nag_mesh2d_renum (d06ccc) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #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[]) { 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); exit_status = 0; Vprintf(" nag_mesh2d_renum (d06ccc) Example Program Results\n\n"); /* Skip heading in data file */ Vscanf("%*[^\n] "); /* Reading of the geometry */ Vscanf("%ld", &nv); Vscanf("%ld", &nelt); Vscanf("%ld", &nedge); Vscanf("%*[^\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)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } for (i = 1; i <= nv; ++i) { Vscanf("%lf", &COOR(1,i)); Vscanf("%lf", &COOR(2,i)); Vscanf("%*[^\n] "); } for (i = 1; i <= nelt; ++i) { Vscanf("%ld", &CONN(1,i)); Vscanf("%ld", &CONN(2,i)); Vscanf("%ld", &CONN(3,i)); Vscanf("%ld", &reftk); Vscanf("%*[^\n] "); } for (i = 1; i <= nedge; ++i) { Vscanf("%ld", &reftk); Vscanf("%ld", &EDGE(1,i)); Vscanf("%ld", &EDGE(2,i)); Vscanf("%ld", &EDGE(3,i)); Vscanf("%*[^\n] "); } Vscanf(" ' %1s '", pmesh); Vscanf("%*[^\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') { Vprintf(" The Matrix Sparsity characteristics\n"); Vprintf(" before the renumbering\n"); Vprintf(" nv =%6ld\n", nv); Vprintf(" nnz =%6ld\n", nnz); } else if (pmesh[0] == 'Y') { /* Output the sparsity of the mesh to view */ /* it using the NAG Graphics Library */ Vprintf(" %10ld%10ld\n", nv, nnz); for (i = 0; i < nnz; ++i) Vprintf(" %10ld%10ld\n", irow[i], icol[i]); } else { Vprintf("Problem with the printing option Y or N\n"); exit_status = -1; goto END; } } else { Vprintf("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 */ nag_mesh2d_renum(nv, nelt, nedge, nnzmax, &nnz, coor, edge, conn, irow, icol, itrace, 0, &fail); if (fail.code == NE_NOERROR) { if (pmesh[0] == 'N') { Vprintf("\n The Matrix Sparsity characteristics\n"); Vprintf(" after the renumbering\n"); Vprintf(" nv =%6ld\n", nv); Vprintf(" nnz =%6ld\n", nnz); Vprintf(" nelt =%6ld\n", nelt); } else if (pmesh[0] == 'Y') { /* Output the sparsity of the renumbered mesh */ /* to view it using the NAG Graphics Library */ Vprintf("%10ld%10ld\n", nv, nnz); for (i = 0; i < nnz; ++i) Vprintf(" %10ld%10ld\n", irow[i], icol[i]); /* Output the renumbered mesh to view */ /* it using the NAG Graphics Library */ Vprintf(" %10ld%10ld\n", nv, nelt); for (i = 1; i <= nv; ++i) Vprintf(" %12.6e %12.6e \n", COOR(1,i), COOR(2,i)); reftk = 0; for (i = 1; i <= nelt; ++i) Vprintf(" %10ld%10ld%10ld%10ld\n", CONN(1,i), CONN(2,i), CONN(3,i), reftk); } } else { Vprintf("Error from nag_mesh2d_renum (d06ccc).\n%s\n", fail.message); exit_status = 1; goto END; } END: 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; }