Actual source code: dmplextsceed.c

  1: #include <petsc/private/dmpleximpl.h>
  2: #include <petsc/private/tsimpl.h>
  3: #include <petsc/private/snesimpl.h>
  4: #include <petscds.h>
  5: #include <petscfv.h>

  7: /*@C
  8:   DMPlexTSComputeRHSFunctionFVMCEED - Assemble the right-hand-side vector of a finite-volume `TS` step using the libCEED operator attached to a `DMPLEX`

 10:   Collective

 12:   Input Parameters:
 13: + dm   - the `DMPLEX` for which libCEED operators have been created by `DMCeedCreate()`
 14: . time - the current time
 15: . locX - local solution vector including ghost values
 16: . F    - the global right-hand-side vector to assemble
 17: - ctx  - application context (unused)

 19:   Level: developer

 21:   Note:
 22:   This is normally installed as the `TS` RHS function callback via `DMTSSetRHSFunctionLocal()` when using libCEED for the finite-volume evaluation.

 24: .seealso: [](ch_ts), `TS`, `DMPLEX`, `DMCeedCreate()`, `DMPlexSNESComputeResidualCEED()`, `DMTSSetRHSFunctionLocal()`
 25: @*/
 26: PetscErrorCode DMPlexTSComputeRHSFunctionFVMCEED(DM dm, PetscReal time, Vec locX, Vec F, PetscCtx ctx)
 27: {
 28:   PetscFV    fv;
 29:   Vec        locF;
 30:   Ceed       ceed;
 31:   DMCeed     sd = dm->dmceed;
 32:   CeedVector clocX, clocF;

 34:   PetscFunctionBegin;
 35:   PetscCall(DMGetCeed(dm, &ceed));
 36:   PetscCheck(sd, PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_WRONGSTATE, "This DM has no CEED data. Call DMCeedCreate() before computing the residual.");
 37:   if (time == 0.) PetscCall(DMCeedComputeGeometry(dm, sd));
 38:   PetscCall(DMGetField(dm, 0, NULL, (PetscObject *)&fv));
 39:   PetscCall(DMPlexInsertBoundaryValuesFVM(dm, fv, locX, time, NULL));
 40:   PetscCall(DMGetLocalVector(dm, &locF));
 41:   PetscCall(VecZeroEntries(locF));
 42:   PetscCall(VecGetCeedVectorRead(locX, ceed, &clocX));
 43:   PetscCall(VecGetCeedVector(locF, ceed, &clocF));
 44:   PetscCallCEED(CeedOperatorApplyAdd(sd->op, clocX, clocF, CEED_REQUEST_IMMEDIATE));
 45:   PetscCall(VecRestoreCeedVectorRead(locX, &clocX));
 46:   PetscCall(VecRestoreCeedVector(locF, &clocF));
 47:   PetscCall(DMLocalToGlobalBegin(dm, locF, ADD_VALUES, F));
 48:   PetscCall(DMLocalToGlobalEnd(dm, locF, ADD_VALUES, F));
 49:   PetscCall(DMRestoreLocalVector(dm, &locF));
 50:   PetscCall(VecViewFromOptions(F, NULL, "-fv_rhs_view"));
 51:   PetscFunctionReturn(PETSC_SUCCESS);
 52: }