/* nag_pde_parab_1d_coll (d03pdc) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include #include #include static void uinit(Integer, Integer, const double[], double[], Nag_Comm *); static void pdedef(Integer, double, const double[], Integer, const double[], const double[], double[], double[], double[], Integer *, Nag_Comm *); static void bndary(Integer, double, const double[], const double[], Integer, double[], double[], Integer *, Nag_Comm *); #define U(I,J) u[npde*((J)-1)+(I)-1] #define UOUT(I,J,K) uout[npde*(intpts*((K)-1)+(J)-1)+(I)-1] #define P(I,J,K) p[npde*(npde*((K)-1)+(J)-1)+(I)-1] #define Q(I,J) q[npde*((J)-1)+(I)-1] #define R(I,J) r[npde*((J)-1)+(I)-1] #define UX(I,J) ux[npde*((J)-1)+(I)-1] int main(void) { const Integer nbkpts=10, nelts=nbkpts-1, npde=2, npoly=3, m=0, itype=1, npts=nelts*npoly+1, neqn=npde*npts, intpts=6, npl1=npoly+1, lisave=neqn+24, mu=npde*(npoly+1)-1, lenode=(3*mu+1)*neqn, nwkres=3*npl1*npl1+npl1*(npde*npde+6*npde+nbkpts+1) +13*npde+5, lrsave=11*neqn+50+nwkres+lenode; static double xout[6] = { -1.,-.6,-.2,.2,.6,1. }; double acc, tout, ts, piby2; Integer exit_status, i, ind, it, itask, itrace; double *rsave=0, *u=0, *uout=0, *x=0, *xbkpts=0; Integer *isave=0; NagError fail; Nag_Comm comm; Nag_D03_Save saved; /* Allocate memory */ if ( !(rsave = NAG_ALLOC(lrsave, double)) || !(u = NAG_ALLOC(npde*npts, double)) || !(uout = NAG_ALLOC(npde*intpts*itype, double)) || !(x = NAG_ALLOC(npts, double)) || !(xbkpts = NAG_ALLOC(nbkpts, double)) || !(isave = NAG_ALLOC(lisave, Integer)) ) { Vprintf("Allocation failure\n"); exit_status = 1; goto END; } INIT_FAIL(fail); exit_status = 0; Vprintf("d03pdc Example Program Results\n\n"); piby2 = 0.5*nag_pi; acc = 1e-4; itrace = 0; /* Set the break-points */ for (i = 0; i < 10; ++i) { xbkpts[i] = i*2.0/9.0- 1.0; } ind = 0; itask = 1; ts = 0.0; tout = 1e-5; Vprintf(" Polynomial degree =%4ld", npoly); Vprintf(" No. of elements = %4ld\n\n", nelts); Vprintf(" Accuracy requirement = %9.3e", acc); Vprintf(" Number of points = %5ld\n\n", npts); Vprintf(" t / x "); for (i = 0; i < 6; ++i) { Vprintf("%8.4f", xout[i]); Vprintf((i+1)%6 == 0 || i == 5 ?"\n":""); } Vprintf("\n"); /* Loop over output values of t */ for (it = 0; it < 5; ++it) { tout *= 10.0; d03pdc(npde, m, &ts, tout, pdedef, bndary, u, nbkpts, xbkpts, npoly, npts, x, uinit, acc, rsave, lrsave, isave, lisave, itask, itrace, 0, &ind, &comm, &saved, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from d03pdc.\n%s\n", fail.message); exit_status = 1; goto END; } /* Interpolate at required spatial points */ d03pyc(npde, u, nbkpts, xbkpts, npoly, npts, xout, intpts, itype, uout, rsave, lrsave, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from d03pyc.\n%s\n", fail.message); exit_status = 1; goto END; } Vprintf("\n %6.4f u(1)", tout); for (i = 1; i <= 6; ++i) { Vprintf("%8.4f", UOUT(1,i,1)); Vprintf(i%6 == 0 || i == 6 ?"\n":""); } Vprintf(" u(2)"); for (i = 1; i <= 6; ++i) { Vprintf("%8.4f", UOUT(2,i,1)); Vprintf(i%6 == 0 || i == 6 ?"\n":""); } } /* Print integration statistics */ Vprintf("\n"); Vprintf(" Number of integration steps in time "); Vprintf("%4ld\n",isave[0]); Vprintf(" Number of residual evaluations of resulting ODE system "); Vprintf("%4ld\n",isave[1]); Vprintf(" Number of Jacobian evaluations "); Vprintf("%4ld\n",isave[2]); Vprintf(" Number of iterations of nonlinear solver "); Vprintf("%4ld\n",isave[4]); END: if (rsave) NAG_FREE(rsave); if (u) NAG_FREE(u); if (uout) NAG_FREE(uout); if (x) NAG_FREE(x); if (xbkpts) NAG_FREE(xbkpts); if (isave) NAG_FREE(isave); return exit_status; } static void uinit(Integer npde, Integer npts, const double x[], double u[], Nag_Comm *comm) { Integer i; double piby2; piby2 = 0.5*nag_pi; for (i = 1; i <= npts; ++i) { U(1, i) = -sin(piby2*x[i-1]); U(2, i) = -piby2*piby2*U(1, i); } return; } static void pdedef(Integer npde, double t, const double x[], Integer nptl, const double u[], const double ux[], double p[], double q[], double r[], Integer *ires, Nag_Comm *comm) { Integer i; for (i = 1; i <= nptl; ++i) { Q(1, i) = U(2, i); Q(2, i) = U(1, i)*UX(2, i) - UX(1, i)*U(2, i); R(1, i) = UX(1, i); R(2, i) = UX(2, i); P(1, 1, i) = 0.0; P(1, 2, i) = 0.0; P(2, 1, i) = 0.0; P(2, 2, i) = 1.0; } return; } static void bndary(Integer npde, double t, const double u[], const double ux[], Integer ibnd, double beta[], double gamma[], Integer *ires, Nag_Comm *comm) { if (ibnd == 0) { beta[0] = 1.0; gamma[0] = 0.0; beta[1] = 0.0; gamma[1] = u[0] - 1.0; } else { beta[0] = 1.0; gamma[0] = 0.0; beta[1] = 0.0; gamma[1] = u[0] + 1.0; } return; }