Lines Matching refs:ctx
48 AdvectCtx *ctx = (AdvectCtx *)vctx; in PhysicsRiemann_Advect() local
52 speed = ctx->a; in PhysicsRiemann_Advect()
63 AdvectCtx *ctx = (AdvectCtx *)vctx; in PhysicsCharacteristic_Advect() local
68 if (x < 0) speeds[0] = ctx->a[0]; /* x is discontinuous point of a */ in PhysicsCharacteristic_Advect()
69 else speeds[0] = ctx->a[1]; in PhysicsCharacteristic_Advect()
75 AdvectCtx *ctx = (AdvectCtx *)vctx; in PhysicsSample_Advect() local
76 PetscReal *a = ctx->a, x0; in PhysicsSample_Advect()
161 static PetscErrorCode PhysicsCreate_Advect(FVCtx *ctx) in PhysicsCreate_Advect() argument
167 ctx->physics.sample = PhysicsSample_Advect; in PhysicsCreate_Advect()
168 ctx->physics.riemann = PhysicsRiemann_Advect; in PhysicsCreate_Advect()
169 ctx->physics.characteristic = PhysicsCharacteristic_Advect; in PhysicsCreate_Advect()
170 ctx->physics.destroy = PhysicsDestroy_SimpleFree; in PhysicsCreate_Advect()
171 ctx->physics.user = user; in PhysicsCreate_Advect()
172 ctx->physics.dof = 1; in PhysicsCreate_Advect()
173 PetscCall(PetscStrallocpy("u", &ctx->physics.fieldname[0])); in PhysicsCreate_Advect()
176 PetscOptionsBegin(ctx->comm, ctx->prefix, "Options for advection", ""); in PhysicsCreate_Advect()
189 FVCtx *ctx = (FVCtx *)vctx; in FVRHSFunctionslow() local
200 hx = (ctx->xmax - ctx->xmin) / Mx; in FVRHSFunctionslow()
208 PetscCall(ISGetSize(ctx->iss, &len_slow)); in FVRHSFunctionslow()
210 if (ctx->bctype == FVBC_OUTFLOW) { in FVRHSFunctionslow()
223 …PetscCall((*ctx->physics.characteristic)(ctx->physics.user, dof, &x[i * dof], ctx->R, ctx->Rinv, c… in FVRHSFunctionslow()
225 PetscCall(PetscArrayzero(ctx->cjmpLR, 2 * dof)); in FVRHSFunctionslow()
226 cjmpL = &ctx->cjmpLR[0]; in FVRHSFunctionslow()
227 cjmpR = &ctx->cjmpLR[dof]; in FVRHSFunctionslow()
233 cjmpL[k] += ctx->Rinv[k + j * dof] * jmpL; in FVRHSFunctionslow()
234 cjmpR[k] += ctx->Rinv[k + j * dof] * jmpR; in FVRHSFunctionslow()
240 (*ctx->limit)(&info, cjmpL, cjmpR, ctx->cslope); in FVRHSFunctionslow()
241 for (j = 0; j < dof; j++) ctx->cslope[j] /= hx; /* rescale to a slope */ in FVRHSFunctionslow()
244 for (k = 0; k < dof; k++) tmp += ctx->R[j + k * dof] * ctx->cslope[k]; in FVRHSFunctionslow()
254 uL = &ctx->uLR[0]; in FVRHSFunctionslow()
255 uR = &ctx->uLR[dof]; in FVRHSFunctionslow()
260 …PetscCall((*ctx->physics.riemann)(ctx->physics.user, dof, uL, uR, ctx->flux, &maxspeed, ctx->xmin … in FVRHSFunctionslow()
263 for (j = 0; j < dof; j++) f[(i - 1) * dof + j] -= ctx->flux[j] / hx; in FVRHSFunctionslow()
266 for (j = 0; j < dof; j++) f[i * dof + j] += ctx->flux[j] / hx; in FVRHSFunctionslow()
270 uL = &ctx->uLR[0]; in FVRHSFunctionslow()
271 uR = &ctx->uLR[dof]; in FVRHSFunctionslow()
276 …PetscCall((*ctx->physics.riemann)(ctx->physics.user, dof, uL, uR, ctx->flux, &maxspeed, ctx->xmin … in FVRHSFunctionslow()
279 for (j = 0; j < dof; j++) f[(i - 1) * dof + j] -= ctx->flux[j] / hx; in FVRHSFunctionslow()
294 FVCtx *ctx = (FVCtx *)vctx; in FVRHSFunctionfast() local
305 hx = (ctx->xmax - ctx->xmin) / Mx; in FVRHSFunctionfast()
313 PetscCall(ISGetSize(ctx->iss, &len_slow)); in FVRHSFunctionfast()
315 if (ctx->bctype == FVBC_OUTFLOW) { in FVRHSFunctionfast()
327 …PetscCall((*ctx->physics.characteristic)(ctx->physics.user, dof, &x[i * dof], ctx->R, ctx->Rinv, c… in FVRHSFunctionfast()
328 PetscCall(PetscArrayzero(ctx->cjmpLR, 2 * dof)); in FVRHSFunctionfast()
329 cjmpL = &ctx->cjmpLR[0]; in FVRHSFunctionfast()
330 cjmpR = &ctx->cjmpLR[dof]; in FVRHSFunctionfast()
336 cjmpL[k] += ctx->Rinv[k + j * dof] * jmpL; in FVRHSFunctionfast()
337 cjmpR[k] += ctx->Rinv[k + j * dof] * jmpR; in FVRHSFunctionfast()
343 (*ctx->limit)(&info, cjmpL, cjmpR, ctx->cslope); in FVRHSFunctionfast()
344 for (j = 0; j < dof; j++) ctx->cslope[j] /= hx; /* rescale to a slope */ in FVRHSFunctionfast()
347 for (k = 0; k < dof; k++) tmp += ctx->R[j + k * dof] * ctx->cslope[k]; in FVRHSFunctionfast()
357 uL = &ctx->uLR[0]; in FVRHSFunctionfast()
358 uR = &ctx->uLR[dof]; in FVRHSFunctionfast()
363 …PetscCall((*ctx->physics.riemann)(ctx->physics.user, dof, uL, uR, ctx->flux, &maxspeed, ctx->xmin … in FVRHSFunctionfast()
366 for (j = 0; j < dof; j++) f[(i - len_slow - 1) * dof + j] -= ctx->flux[j] / hx; in FVRHSFunctionfast()
369 for (j = 0; j < dof; j++) f[(i - len_slow) * dof + j] += ctx->flux[j] / hx; in FVRHSFunctionfast()
373 uL = &ctx->uLR[0]; in FVRHSFunctionfast()
374 uR = &ctx->uLR[dof]; in FVRHSFunctionfast()
379 …PetscCall((*ctx->physics.riemann)(ctx->physics.user, dof, uL, uR, ctx->flux, &maxspeed, ctx->xmin … in FVRHSFunctionfast()
382 for (j = 0; j < dof; j++) f[(i - len_slow) * dof + j] += ctx->flux[j] / hx; in FVRHSFunctionfast()
395 FVCtx *ctx = (FVCtx *)vctx; in FVRHSFunctionslow2() local
406 hx = (ctx->xmax - ctx->xmin) / Mx; in FVRHSFunctionslow2()
414 PetscCall(ISGetSize(ctx->iss, &len_slow1)); in FVRHSFunctionslow2()
415 PetscCall(ISGetSize(ctx->iss2, &len_slow2)); in FVRHSFunctionslow2()
416 if (ctx->bctype == FVBC_OUTFLOW) { in FVRHSFunctionslow2()
428 …PetscCall((*ctx->physics.characteristic)(ctx->physics.user, dof, &x[i * dof], ctx->R, ctx->Rinv, c… in FVRHSFunctionslow2()
429 PetscCall(PetscArrayzero(ctx->cjmpLR, 2 * dof)); in FVRHSFunctionslow2()
430 cjmpL = &ctx->cjmpLR[0]; in FVRHSFunctionslow2()
431 cjmpR = &ctx->cjmpLR[dof]; in FVRHSFunctionslow2()
437 cjmpL[k] += ctx->Rinv[k + j * dof] * jmpL; in FVRHSFunctionslow2()
438 cjmpR[k] += ctx->Rinv[k + j * dof] * jmpR; in FVRHSFunctionslow2()
444 (*ctx->limit)(&info, cjmpL, cjmpR, ctx->cslope); in FVRHSFunctionslow2()
445 for (j = 0; j < dof; j++) ctx->cslope[j] /= hx; /* rescale to a slope */ in FVRHSFunctionslow2()
448 for (k = 0; k < dof; k++) tmp += ctx->R[j + k * dof] * ctx->cslope[k]; in FVRHSFunctionslow2()
458 uL = &ctx->uLR[0]; in FVRHSFunctionslow2()
459 uR = &ctx->uLR[dof]; in FVRHSFunctionslow2()
464 …PetscCall((*ctx->physics.riemann)(ctx->physics.user, dof, uL, uR, ctx->flux, &maxspeed, ctx->xmin … in FVRHSFunctionslow2()
467 for (j = 0; j < dof; j++) f[(i - len_slow1 - 1) * dof + j] -= ctx->flux[j] / hx; in FVRHSFunctionslow2()
470 for (j = 0; j < dof; j++) f[(i - len_slow1) * dof + j] += ctx->flux[j] / hx; in FVRHSFunctionslow2()
474 uL = &ctx->uLR[0]; in FVRHSFunctionslow2()
475 uR = &ctx->uLR[dof]; in FVRHSFunctionslow2()
480 …PetscCall((*ctx->physics.riemann)(ctx->physics.user, dof, uL, uR, ctx->flux, &maxspeed, ctx->xmin … in FVRHSFunctionslow2()
483 for (j = 0; j < dof; j++) f[(i - len_slow1 - 1) * dof + j] -= ctx->flux[j] / hx; in FVRHSFunctionslow2()
487 uL = &ctx->uLR[0]; in FVRHSFunctionslow2()
488 uR = &ctx->uLR[dof]; in FVRHSFunctionslow2()
493 …PetscCall((*ctx->physics.riemann)(ctx->physics.user, dof, uL, uR, ctx->flux, &maxspeed, ctx->xmin … in FVRHSFunctionslow2()
496 for (j = 0; j < dof; j++) f[(i - len_slow1) * dof + j] += ctx->flux[j] / hx; in FVRHSFunctionslow2()
510 FVCtx *ctx = (FVCtx *)vctx; in FVRHSFunctionfast2() local
521 hx = (ctx->xmax - ctx->xmin) / Mx; in FVRHSFunctionfast2()
529 PetscCall(ISGetSize(ctx->iss, &len_slow1)); in FVRHSFunctionfast2()
530 PetscCall(ISGetSize(ctx->iss2, &len_slow2)); in FVRHSFunctionfast2()
532 if (ctx->bctype == FVBC_OUTFLOW) { in FVRHSFunctionfast2()
544 …PetscCall((*ctx->physics.characteristic)(ctx->physics.user, dof, &x[i * dof], ctx->R, ctx->Rinv, c… in FVRHSFunctionfast2()
545 PetscCall(PetscArrayzero(ctx->cjmpLR, 2 * dof)); in FVRHSFunctionfast2()
546 cjmpL = &ctx->cjmpLR[0]; in FVRHSFunctionfast2()
547 cjmpR = &ctx->cjmpLR[dof]; in FVRHSFunctionfast2()
553 cjmpL[k] += ctx->Rinv[k + j * dof] * jmpL; in FVRHSFunctionfast2()
554 cjmpR[k] += ctx->Rinv[k + j * dof] * jmpR; in FVRHSFunctionfast2()
560 (*ctx->limit)(&info, cjmpL, cjmpR, ctx->cslope); in FVRHSFunctionfast2()
561 for (j = 0; j < dof; j++) ctx->cslope[j] /= hx; /* rescale to a slope */ in FVRHSFunctionfast2()
564 for (k = 0; k < dof; k++) tmp += ctx->R[j + k * dof] * ctx->cslope[k]; in FVRHSFunctionfast2()
574 uL = &ctx->uLR[0]; in FVRHSFunctionfast2()
575 uR = &ctx->uLR[dof]; in FVRHSFunctionfast2()
580 …PetscCall((*ctx->physics.riemann)(ctx->physics.user, dof, uL, uR, ctx->flux, &maxspeed, ctx->xmin … in FVRHSFunctionfast2()
583 for (j = 0; j < dof; j++) f[(i - len_slow1 - len_slow2 - 1) * dof + j] -= ctx->flux[j] / hx; in FVRHSFunctionfast2()
586 for (j = 0; j < dof; j++) f[(i - len_slow1 - len_slow2) * dof + j] += ctx->flux[j] / hx; in FVRHSFunctionfast2()
590 uL = &ctx->uLR[0]; in FVRHSFunctionfast2()
591 uR = &ctx->uLR[dof]; in FVRHSFunctionfast2()
596 …PetscCall((*ctx->physics.riemann)(ctx->physics.user, dof, uL, uR, ctx->flux, &maxspeed, ctx->xmin … in FVRHSFunctionfast2()
599 for (j = 0; j < dof; j++) f[(i - len_slow1 - len_slow2) * dof + j] += ctx->flux[j] / hx; in FVRHSFunctionfast2()
618 FVCtx ctx; in main() local
626 PetscCall(PetscMemzero(&ctx, sizeof(ctx))); in main()
651 ctx.comm = comm; in main()
652 ctx.cfl = 0.9; in main()
653 ctx.bctype = FVBC_PERIODIC; in main()
654 ctx.xmin = -1.0; in main()
655 ctx.xmax = 1.0; in main()
657 PetscCall(PetscOptionsReal("-xmin", "X min", "", ctx.xmin, &ctx.xmin, NULL)); in main()
658 PetscCall(PetscOptionsReal("-xmax", "X max", "", ctx.xmax, &ctx.xmax, NULL)); in main()
662 …nsInt("-initial", "Initial condition (depends on the physics)", "", ctx.initial, &ctx.initial, NUL… in main()
663 …Bool("-simulation", "Compare errors with reference solution", "", ctx.simulation, &ctx.simulation,… in main()
664 PetscCall(PetscOptionsReal("-cfl", "CFL number to time step at", "", ctx.cfl, &ctx.cfl, NULL)); in main()
665 …m("-bc_type", "Boundary condition", "", FVBCTypes, (PetscEnum)ctx.bctype, (PetscEnum *)&ctx.bctype… in main()
666 …ptionsBool("-recursive_split", "Split the domain recursively", "", ctx.recursive, &ctx.recursive, … in main()
670 PetscCall(PetscFunctionListFind(limiters, lname, &ctx.limit)); in main()
671 …PetscCheck(ctx.limit, PETSC_COMM_SELF, PETSC_ERR_ARG_UNKNOWN_TYPE, "Limiter '%s' not found", lname… in main()
679 PetscCall((*r)(&ctx)); in main()
683 PetscCall(DMDACreate1d(comm, DM_BOUNDARY_PERIODIC, 50, ctx.physics.dof, 2, NULL, &da)); in main()
688 …for (i = 0; i < ctx.physics.dof; i++) PetscCall(DMDASetFieldName(da, i, ctx.physics.fieldname[i])); in main()
693 …tscCall(DMDASetUniformCoordinates(da, ctx.xmin + 0.5 * (ctx.xmax - ctx.xmin) / Mx, ctx.xmax + 0.5 … in main()
696 …PetscCall(PetscMalloc4(dof * dof, &ctx.R, dof * dof, &ctx.Rinv, 2 * dof, &ctx.cjmpLR, 1 * dof, &ct… in main()
697 PetscCall(PetscMalloc3(2 * dof, &ctx.uLR, dof, &ctx.flux, dof, &ctx.speeds)); in main()
708 …if (ctx.xmin + i * (ctx.xmax - ctx.xmin) / (PetscReal)Mx + 0.5 * (ctx.xmax - ctx.xmin) / (PetscRea… in main()
713 PetscCall(ISCreateGeneral(PETSC_COMM_WORLD, islow, index_slow, PETSC_COPY_VALUES, &ctx.iss)); in main()
714 PetscCall(ISCreateGeneral(PETSC_COMM_WORLD, ifast, index_fast, PETSC_COPY_VALUES, &ctx.isf)); in main()
719 PetscCall(TSSetRHSFunction(ts, R, FVRHSFunction, &ctx)); in main()
720 PetscCall(TSRHSSplitSetIS(ts, "slow", ctx.iss)); in main()
721 PetscCall(TSRHSSplitSetIS(ts, "fast", ctx.isf)); in main()
722 PetscCall(TSRHSSplitSetRHSFunction(ts, "slow", NULL, FVRHSFunctionslow, &ctx)); in main()
723 PetscCall(TSRHSSplitSetRHSFunction(ts, "fast", NULL, FVRHSFunctionfast, &ctx)); in main()
725 if (ctx.recursive) { in main()
730 …PetscReal coord = ctx.xmin + i * (ctx.xmax - ctx.xmin) / (PetscReal)Mx + 0.5 * (ctx.xmax - ctx.xmi… in main()
731 if (coord >= 0 && coord < ctx.xmin + (ctx.xmax - ctx.xmin) * 3 / 4.) in main()
733 if (coord >= ctx.xmin + (ctx.xmax - ctx.xmin) * 3 / 4.) in main()
736 PetscCall(ISCreateGeneral(PETSC_COMM_WORLD, islow, index_slow, PETSC_COPY_VALUES, &ctx.iss2)); in main()
737 PetscCall(ISCreateGeneral(PETSC_COMM_WORLD, ifast, index_fast, PETSC_COPY_VALUES, &ctx.isf2)); in main()
740 PetscCall(TSRHSSplitSetIS(subts, "slow", ctx.iss2)); in main()
741 PetscCall(TSRHSSplitSetIS(subts, "fast", ctx.isf2)); in main()
742 PetscCall(TSRHSSplitSetRHSFunction(subts, "slow", NULL, FVRHSFunctionslow2, &ctx)); in main()
743 PetscCall(TSRHSSplitSetRHSFunction(subts, "fast", NULL, FVRHSFunctionfast2, &ctx)); in main()
752 PetscCall(FVSample(&ctx, da, 0, X0)); in main()
753 …PetscCall(FVRHSFunction(ts, 0, X0, X, (void *)&ctx)); /* Initial function evaluation, only used to… in main()
755 PetscCall(TSSetTimeStep(ts, ctx.cfl / ctx.cfl_idt)); in main()
771 mass_difference = (ctx.xmax - ctx.xmin) / (PetscScalar)Mx * (mass_final - mass_initial); in main()
773 if (ctx.simulation) { in main()
801 PetscCall(FVSample(&ctx, da, ptime, Y)); in main()
817 PetscCall((*ctx.physics.destroy)(ctx.physics.user)); in main()
818 for (i = 0; i < ctx.physics.dof; i++) PetscCall(PetscFree(ctx.physics.fieldname[i])); in main()
819 PetscCall(PetscFree4(ctx.R, ctx.Rinv, ctx.cjmpLR, ctx.cslope)); in main()
820 PetscCall(PetscFree3(ctx.uLR, ctx.flux, ctx.speeds)); in main()
821 PetscCall(ISDestroy(&ctx.iss)); in main()
822 PetscCall(ISDestroy(&ctx.isf)); in main()
823 PetscCall(ISDestroy(&ctx.iss2)); in main()
824 PetscCall(ISDestroy(&ctx.isf2)); in main()