void runPass(double *mesh, double dt, int n, int dir){ int bndL,bndH; int np,nt; double dx,dy; char dirCh, outfile[30]; if(dir==0){ np=Hp->nx; nt=Hp->ny; bndL=Hp->bndL; bndH=Hp->bndR; dx=Hp->dx; dy=Hp->dy; dirCh='x'; toPrimX(q,mesh); }else{ np=Hp->ny; nt=Hp->nx; bndL=Hp->bndU; bndH=Hp->bndD; dx=Hp->dy; dy=Hp->dx; dirCh='y'; toPrimY(q,mesh); } setBndCnd(q,bndL,bndH,np,nt); trace(ql,qr,q,dt/dx,np,nt); riemann(flx,ql,qr,np,nt); if(dir==0){ addFluxX(mesh,flx,dt/dx,np,nt); }else{ addFluxY(mesh,flx,dt/dx,np,nt); } }
void Godunov::detachedRiemann(Cell const & leftCell, Cell const & rightCell, const unsigned i, unsigned phase) { RiemannSolver riemann(leftCell, rightCell, phase); riemann.solve(); riemann.phase_star_[0].Sample(0, setCell()[i].setPhase()[phase].setU_half(), setCell()[i].setPhase()[phase].setP_half(), setCell()[i].setPhase()[phase].setD_half(), riemann.phase_star_[0].pstar[0], riemann.phase_star_[0].ustar[0]); setCell()[i].setPhase()[phase].InterCellFlux(); }
int main(int argc, char* argv[]) { if (argc < 3) { std::cout << "Usage: " << argv[0] << " <t_end> <filename> " << std::endl; return 1; } double t_end = atof(argv[1]); Mesh1DED<double> mesh(0, 1, 100); Euler riemann(&mesh); riemann.InitialValue(Init); riemann.Run(t_end); riemann.OutputData(argv[2]); return 0; }
void Godunov::SinglePhase(const double & CFL) { double t = 0; while (t < getMax()) { BoundaryConditions(); for (unsigned i = 0; i < getCell().size(); ++i) { if (i == getCell().size() - 2) continue; RiemannSolver riemann(getCell()[i % getCell().size()], getCell()[(i + 1) % getCell().size()], 1); riemann.solve(); riemann.phase_star_[0].Sample(0, setCell()[i].setPhase()[0].setU_half(), setCell()[i].setPhase()[0].setP_half(), setCell()[i].setPhase()[0].setD_half(), riemann.phase_star_[0].pstar[0] , riemann.phase_star_[0].ustar[0]); setCell()[i].setPhase()[0].InterCellFlux(); } computeDT(CFL); timeIntegration(); for (unsigned i = 0; i < getCell().size(); ++i) { setCell()[i].setPhase()[0].computeScalFromCons(); } t += getDt(); } }
void Godunov::multiphaseRiemann(const Cell& leftCell, const Cell& rightCell, const unsigned i, unsigned phase) { RiemannSolver riemann(leftCell, rightCell, phase); }
void hydro_godunov(long idim, double dt, const hydroparam_t H, hydrovar_t * Hv, hydrowork_t * Hw, hydrovarwork_t * Hvw) { // Local variables long i, j; double dtdx; double *dq; double *e; double *flux; double *q; double *qleft, *qright; double *qxm, *qxp; double *u; double *c; double *uold; double *rl, *ul, *pl, *cl, *wl, *rr, *ur, *pr, *cr, *wr, *ro, *uo, *po, *co, *wo, *rstar, *ustar, *pstar, *cstar, *spin, *spout, *ushock, *frac, *scr, *delp, *pold; long *sgnm, *ind, *ind2; double *qgdnv; WHERE("hydro_godunov"); // constant dtdx = dt / H.dx; // Update boundary conditions if (H.prt) { fprintf(stdout, "godunov %ld\n", idim); PRINTUOLD(H, Hv); } make_boundary(idim, H, Hv); PRINTUOLD(H, Hv); // Allocate work space for 1D sweeps allocate_work_space(H, Hw, Hvw); uold = Hv->uold; qgdnv = Hvw->qgdnv; flux = Hvw->flux; c = Hw->c; q = Hvw->q; e = Hw->e; u = Hvw->u; qxm = Hvw->qxm; qxp = Hvw->qxp; qleft = Hvw->qleft; qright = Hvw->qright; dq = Hvw->dq; rl = Hw->rl; ul = Hw->ul; pl = Hw->pl; cl = Hw->cl; wl = Hw->wl; rr = Hw->rr; ur = Hw->ur; pr = Hw->pr; cr = Hw->cr; wr = Hw->wr; ro = Hw->ro; uo = Hw->uo; po = Hw->po; co = Hw->co; wo = Hw->wo; rstar = Hw->rstar; ustar = Hw->ustar; pstar = Hw->pstar; cstar = Hw->cstar; sgnm = Hw->sgnm; spin = Hw->spin; spout = Hw->spout; ushock = Hw->ushock; frac = Hw->frac; scr = Hw->scr; delp = Hw->delp; pold = Hw->pold; ind = Hw->ind; ind2 = Hw->ind2; if (idim == 1) { for (j = H.jmin + ExtraLayer; j < H.jmax - ExtraLayer; j++) { double *qID = &q[IHvw(0, ID)]; double *qIP = &q[IHvw(0, IP)]; gatherConservativeVars(idim, j, uold, u, H.imin, H.imax, H.jmin, H.jmax, H.nvar, H.nxt, H.nyt, H.nxyt); // Convert to primitive variables constoprim(u, q, e, H.nxt, H.nxyt, H.nvar, H.smallr); equation_of_state(qID, e, qIP, c, 0, H.nxt, H.smallc, H.gamma); Dmemset(dq, 0, (H.nxyt + 2) * H.nvar); // Characteristic tracing if (H.iorder != 1) { slope(q, dq, H.nxt, H.nvar, H.nxyt, H.slope_type); } trace(q, dq, c, qxm, qxp, dtdx, H.nxt, H.scheme, H.nvar, H.nxyt); qleftright(idim, H.nx, H.ny, H.nxyt, H.nvar, qxm, qxp, qleft, qright); // Solve Riemann problem at interfaces riemann(qleft, qright, qgdnv, rl, ul, pl, cl, wl, rr, ur, pr, cr, wr, ro, uo, po, co, wo, rstar, ustar, pstar, cstar, sgnm, spin, spout, ushock, frac, scr, delp, pold, ind, ind2, H.nx + 1, H.smallr, H.smallc, H.gamma, H.niter_riemann, H.nvar, H.nxyt); // Compute fluxes cmpflx(qgdnv, flux, H.nxt, H.nxyt, H.nvar, H.gamma); updateConservativeVars(idim, j, dtdx, uold, u, flux, H.imin, H.imax, H.jmin, H.jmax, H.nvar, H.nxt, H.nyt, H.nxyt); } // for j if (H.prt) { printf("After pass %ld\n", idim); PRINTUOLD(H, Hv); } } else { for (i = H.imin + ExtraLayer; i < H.imax - ExtraLayer; i++) { double *qID = &Hvw->q[IHvw(0, ID)]; double *qIP = &Hvw->q[IHvw(0, IP)]; gatherConservativeVars(idim, i, uold, u, H.imin, H.imax, H.jmin, H.jmax, H.nvar, H.nxt, H.nyt, H.nxyt); PRINTARRAYV(Hvw->u, H.nyt, "uY", H); // Convert to primitive variables constoprim(u, q, e, H.nyt, H.nxyt, H.nvar, H.smallr); equation_of_state(qID, e, qIP, c, 0, H.nyt, H.smallc, H.gamma); PRINTARRAY(Hw->c, H.nyt, "cY", H); // Characteristic tracing // compute slopes Dmemset(dq, 0, H.nyt * H.nvar); if (H.iorder != 1) { slope(q, dq, H.nyt, H.nvar, H.nxyt, H.slope_type); } PRINTARRAYV(Hvw->dq, H.nyt, "dqY", H); trace(q, dq, c, qxm, qxp, dtdx, H.nyt, H.scheme, H.nvar, H.nxyt); qleftright(idim, H.nx, H.ny, H.nxyt, H.nvar, qxm, qxp, qleft, qright); PRINTARRAYV(Hvw->qleft, H.ny + 1, "qleftY", H); PRINTARRAYV(Hvw->qright, H.ny + 1, "qrightY", H); // Solve Riemann problem at interfaces riemann(qleft, qright, qgdnv, rl, ul, pl, cl, wl, rr, ur, pr, cr, wr, ro, uo, po, co, wo, rstar, ustar, pstar, cstar, sgnm, spin, spout, ushock, frac, scr, delp, pold, ind, ind2, H.ny + 1, H.smallr, H.smallc, H.gamma, H.niter_riemann, H.nvar, H.nxyt); // Compute fluxes cmpflx(qgdnv, flux, H.nyt, H.nxyt, H.nvar, H.gamma); PRINTARRAYV(Hvw->flux, H.ny + 1, "fluxY", H); // updateConservativeVars(idim, i, dtdx, H, Hv, Hvw); updateConservativeVars(idim, i, dtdx, uold, u, flux, H.imin, H.imax, H.jmin, H.jmax, H.nvar, H.nxt, H.nyt, H.nxyt); } // else if (H.prt) { printf("After pass %ld\n", idim); PRINTUOLD(H, Hv); } } // Deallocate work space deallocate_work_space(H, Hw, Hvw); } // hydro_godunov
// variables auxiliaires pour mettre en place le mode resident de HMPP void hydro_godunov(int idimStart, real_t dt, const hydroparam_t H, hydrovar_t * Hv, hydrowork_t * Hw, hydrovarwork_t * Hvw) { // Local variables struct timespec start, end; int j; real_t dtdx; int clear=0; real_t (*e)[H.nxyt]; real_t (*flux)[H.nxystep][H.nxyt]; real_t (*qleft)[H.nxystep][H.nxyt]; real_t (*qright)[H.nxystep][H.nxyt]; real_t (*c)[H.nxyt]; real_t *uold; int (*sgnm)[H.nxyt]; real_t (*qgdnv)[H.nxystep][H.nxyt]; real_t (*u)[H.nxystep][H.nxyt]; real_t (*qxm)[H.nxystep][H.nxyt]; real_t (*qxp)[H.nxystep][H.nxyt]; real_t (*q)[H.nxystep][H.nxyt]; real_t (*dq)[H.nxystep][H.nxyt]; static FILE *fic = NULL; if (fic == NULL && H.prt == 1) { char logname[256]; sprintf(logname, "TRACE.%04d_%04d.txt", H.nproc, H.mype); fic = fopen(logname, "w"); } WHERE("hydro_godunov"); // int hmppGuard = 1; int idimIndex = 0; for (idimIndex = 0; idimIndex < 2; idimIndex++) { int idim = (idimStart - 1 + idimIndex) % 2 + 1; // constant dtdx = dt / H.dx; // Update boundary conditions if (H.prt) { fprintf(fic, "godunov %d\n", idim); PRINTUOLD(fic, H, Hv); } // if (H.mype == 1) fprintf(fic, "Hydro makes boundary.\n"); start = cclock(); make_boundary(idim, H, Hv); end = cclock(); functim[TIM_MAKBOU] += ccelaps(start, end); if (H.prt) {fprintf(fic, "MakeBoundary\n");} PRINTUOLD(fic, H, Hv); uold = Hv->uold; qgdnv = (real_t (*)[H.nxystep][H.nxyt]) Hvw->qgdnv; flux = (real_t (*)[H.nxystep][H.nxyt]) Hvw->flux; c = (real_t (*)[H.nxyt]) Hw->c; e = (real_t (*)[H.nxyt]) Hw->e; qleft = (real_t (*)[H.nxystep][H.nxyt]) Hvw->qleft; qright = (real_t (*)[H.nxystep][H.nxyt]) Hvw->qright; sgnm = (int (*)[H.nxyt]) Hw->sgnm; q = (real_t (*)[H.nxystep][H.nxyt]) Hvw->q; dq = (real_t (*)[H.nxystep][H.nxyt]) Hvw->dq; u = (real_t (*)[H.nxystep][H.nxyt]) Hvw->u; qxm = (real_t (*)[H.nxystep][H.nxyt]) Hvw->qxm; qxp = (real_t (*)[H.nxystep][H.nxyt]) Hvw->qxp; int Hmin, Hmax, Hstep; int Hdimsize; int Hndim_1; if (idim == 1) { Hmin = H.jmin + ExtraLayer; Hmax = H.jmax - ExtraLayer; Hdimsize = H.nxt; Hndim_1 = H.nx + 1; Hstep = H.nxystep; } else { Hmin = H.imin + ExtraLayer; Hmax = H.imax - ExtraLayer; Hdimsize = H.nyt; Hndim_1 = H.ny + 1; Hstep = H.nxystep; } if (!H.nstep && idim == 1) { /* LM -- HERE a more secure implementation should be used: a new parameter ? */ } // if (H.mype == 1) fprintf(fic, "Hydro computes slices.\n"); for (j = Hmin; j < Hmax; j += Hstep) { // we try to compute many slices each pass int jend = j + Hstep; if (jend >= Hmax) jend = Hmax; int slices = jend - j; // numbre of slices to compute // fprintf(stderr, "Godunov idim=%d, j=%d %d \n", idim, j, slices); if (clear) Dmemset((H.nxyt) * H.nxystep * H.nvar, (real_t *) dq, 0); start = cclock(); gatherConservativeVars(idim, j, H.imin, H.imax, H.jmin, H.jmax, H.nvar, H.nxt, H.nyt, H.nxyt, slices, Hstep, uold, u); end = cclock(); functim[TIM_GATCON] += ccelaps(start, end); if (H.prt) {fprintf(fic, "ConservativeVars %d %d %d %d %d %d\n", H.nvar, H.nxt, H.nyt, H.nxyt, slices, Hstep);} PRINTARRAYV2(fic, u, Hdimsize, "u", H); if (clear) Dmemset((H.nxyt) * H.nxystep * H.nvar, (real_t *) dq, 0); // Convert to primitive variables start = cclock(); constoprim(Hdimsize, H.nxyt, H.nvar, H.smallr, slices, Hstep, u, q, e); end = cclock(); functim[TIM_CONPRI] += ccelaps(start, end); PRINTARRAY(fic, e, Hdimsize, "e", H); PRINTARRAYV2(fic, q, Hdimsize, "q", H); start = cclock(); equation_of_state(0, Hdimsize, H.nxyt, H.nvar, H.smallc, H.gamma, slices, Hstep, e, q, c); end = cclock(); functim[TIM_EOS] += ccelaps(start, end); PRINTARRAY(fic, c, Hdimsize, "c", H); PRINTARRAYV2(fic, q, Hdimsize, "q", H); // Characteristic tracing if (H.iorder != 1) { start = cclock(); slope(Hdimsize, H.nvar, H.nxyt, H.slope_type, slices, Hstep, q, dq); end = cclock(); functim[TIM_SLOPE] += ccelaps(start, end); PRINTARRAYV2(fic, dq, Hdimsize, "dq", H); } if (clear) Dmemset(H.nxyt * H.nxystep * H.nvar, (real_t *) qxm, 0); if (clear) Dmemset(H.nxyt * H.nxystep * H.nvar, (real_t *) qxp, 0); if (clear) Dmemset(H.nxyt * H.nxystep * H.nvar, (real_t *) qleft, 0); if (clear) Dmemset(H.nxyt * H.nxystep * H.nvar, (real_t *) qright, 0); if (clear) Dmemset(H.nxyt * H.nxystep * H.nvar, (real_t *) flux, 0); if (clear) Dmemset(H.nxyt * H.nxystep * H.nvar, (real_t *) qgdnv, 0); start = cclock(); trace(dtdx, Hdimsize, H.scheme, H.nvar, H.nxyt, slices, Hstep, q, dq, c, qxm, qxp); end = cclock(); functim[TIM_TRACE] += ccelaps(start, end); PRINTARRAYV2(fic, qxm, Hdimsize, "qxm", H); PRINTARRAYV2(fic, qxp, Hdimsize, "qxp", H); start = cclock(); qleftright(idim, H.nx, H.ny, H.nxyt, H.nvar, slices, Hstep, qxm, qxp, qleft, qright); end = cclock(); functim[TIM_QLEFTR] += ccelaps(start, end); PRINTARRAYV2(fic, qleft, Hdimsize, "qleft", H); PRINTARRAYV2(fic, qright, Hdimsize, "qright", H); start = cclock(); riemann(Hndim_1, H.smallr, H.smallc, H.gamma, H.niter_riemann, H.nvar, H.nxyt, slices, Hstep, qleft, qright, qgdnv, sgnm, Hw); end = cclock(); functim[TIM_RIEMAN] += ccelaps(start, end); PRINTARRAYV2(fic, qgdnv, Hdimsize, "qgdnv", H); start = cclock(); cmpflx(Hdimsize, H.nxyt, H.nvar, H.gamma, slices, Hstep, qgdnv, flux); end = cclock(); functim[TIM_CMPFLX] += ccelaps(start, end); PRINTARRAYV2(fic, flux, Hdimsize, "flux", H); PRINTARRAYV2(fic, u, Hdimsize, "u", H); start = cclock(); updateConservativeVars(idim, j, dtdx, H.imin, H.imax, H.jmin, H.jmax, H.nvar, H.nxt, H.nyt, H.nxyt, slices, Hstep, uold, u, flux); end = cclock(); functim[TIM_UPDCON] += ccelaps(start, end); PRINTUOLD(fic, H, Hv); } // for j if (H.prt) { // printf("[%d] After pass %d\n", H.mype, idim); PRINTUOLD(fic, H, Hv); } } if ((H.t + dt >= H.tend) || (H.nstep + 1 >= H.nstepmax)) { /* LM -- HERE a more secure implementation should be used: a new parameter ? */ } } // hydro_godunov