Skip to content

Commit

Permalink
bddc - use Vec[Read][P2C, C2P]
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylt committed Dec 4, 2023
1 parent 03a4d13 commit c6fc698
Showing 1 changed file with 33 additions and 83 deletions.
116 changes: 33 additions & 83 deletions examples/petsc/src/matops.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ PetscErrorCode PCShellSetup_BDDC(PC pc) {
BDDCApplyContext bddc_ctx;

PetscFunctionBeginUser;

PetscCall(PCShellGetContext(pc, (void *)&bddc_ctx));

// Assemble mat for element Schur AMG
Expand All @@ -190,7 +189,6 @@ PetscErrorCode PCShellSetup_BDDC(PC pc) {
PetscCall(SNESComputeJacobianDefaultColor(bddc_ctx->snes_Pi, bddc_ctx->X_Pi, bddc_ctx->mat_S_Pi, bddc_ctx->mat_S_Pi, NULL));
PetscCall(MatAssemblyBegin(bddc_ctx->mat_S_Pi, MAT_FINAL_ASSEMBLY));
PetscCall(MatAssemblyEnd(bddc_ctx->mat_S_Pi, MAT_FINAL_ASSEMBLY));

PetscFunctionReturn(PETSC_SUCCESS);
};

Expand All @@ -199,16 +197,12 @@ PetscErrorCode PCShellSetup_BDDC(PC pc) {
// -----------------------------------------------------------------------------
PetscErrorCode MatMult_BDDCElementSchur(BDDCApplyContext bddc_ctx, Vec X_Pi_r_loc, Vec Y_Pi_r_loc) {
CeedDataBDDC data = bddc_ctx->ceed_data_bddc;
PetscScalar *x, *y;
PetscMemType x_mem_type, y_mem_type;

PetscFunctionBeginUser;

// Set arrays in libCEED
PetscCall(VecGetArrayReadAndMemType(X_Pi_r_loc, (const PetscScalar **)&x, &x_mem_type));
PetscCall(VecGetArrayAndMemType(Y_Pi_r_loc, &y, &y_mem_type));
CeedVectorSetArray(data->x_Pi_r_ceed, MemTypeP2C(x_mem_type), CEED_USE_POINTER, x);
CeedVectorSetArray(data->y_Pi_r_ceed, MemTypeP2C(y_mem_type), CEED_USE_POINTER, y);
PetscCall(VecReadP2C(X_Pi_r_loc, &x_mem_type, data->x_Pi_r_ceed));
PetscCall(VecP2C(Y_Pi_r_loc, &y_mem_type, data->y_Pi_r_ceed));

// Apply action on Schur compliment
// Y_Pi_r = -B A_r,r^-1 B^T X_Pi_r
Expand All @@ -221,11 +215,8 @@ PetscErrorCode MatMult_BDDCElementSchur(BDDCApplyContext bddc_ctx, Vec X_Pi_r_lo
CeedVectorScale(data->y_Pi_r_ceed, -1.0);

// Restore arrays
CeedVectorTakeArray(data->x_Pi_r_ceed, MemTypeP2C(x_mem_type), &x);
CeedVectorTakeArray(data->y_Pi_r_ceed, MemTypeP2C(y_mem_type), &y);
PetscCall(VecRestoreArrayReadAndMemType(X_Pi_r_loc, (const PetscScalar **)&x));
PetscCall(VecRestoreArrayAndMemType(Y_Pi_r_loc, &y));

PetscCall(VecReadC2P(data->x_Pi_r_ceed, x_mem_type, X_Pi_r_loc));
PetscCall(VecC2P(data->y_Pi_r_ceed, y_mem_type, Y_Pi_r_loc));
PetscFunctionReturn(PETSC_SUCCESS);
};

Expand All @@ -236,9 +227,7 @@ PetscErrorCode FormResidual_BDDCElementSchur(SNES snes, Vec X_Pi_r_loc, Vec Y_Pi
BDDCApplyContext bddc_ctx = (BDDCApplyContext)ctx;

PetscFunctionBeginUser;

PetscCall(MatMult_BDDCElementSchur(bddc_ctx, X_Pi_r_loc, Y_Pi_r_loc));

PetscFunctionReturn(PETSC_SUCCESS);
};

Expand All @@ -247,33 +236,26 @@ PetscErrorCode FormResidual_BDDCElementSchur(SNES snes, Vec X_Pi_r_loc, Vec Y_Pi
// -----------------------------------------------------------------------------
PetscErrorCode BDDCArrInv(BDDCApplyContext bddc_ctx, CeedVector x_r_ceed, CeedVector y_r_ceed) {
CeedDataBDDC data = bddc_ctx->ceed_data_bddc;
PetscScalar *x, *y;
PetscMemType x_mem_type, y_mem_type;

PetscFunctionBeginUser;

// Y_r = A_r,r^-1 (I + B S^-1 B^T A_r,r^-1) X_r
// -- X_r = (I + B S^-1 B^T A_r,r^-1) X_r
// ---- Y_r = A_r,r^-1 X_r
CeedVectorPointwiseMult(x_r_ceed, x_r_ceed, data->mask_r_ceed);
CeedOperatorApply(data->op_r_r_inv, x_r_ceed, y_r_ceed, CEED_REQUEST_IMMEDIATE);
// ---- Y_Pi_r = B^T Y_r
PetscCall(VecGetArrayAndMemType(bddc_ctx->Y_Pi_r_loc, &y, &y_mem_type));
CeedVectorSetArray(data->y_Pi_r_ceed, MemTypeP2C(y_mem_type), CEED_USE_POINTER, y);
PetscCall(VecP2C(bddc_ctx->Y_Pi_r_loc, &y_mem_type, data->y_Pi_r_ceed));
CeedOperatorApply(data->op_restrict_Pi_r, y_r_ceed, data->y_Pi_r_ceed, CEED_REQUEST_IMMEDIATE);
CeedVectorTakeArray(data->y_Pi_r_ceed, MemTypeP2C(y_mem_type), &y);
PetscCall(VecRestoreArrayAndMemType(bddc_ctx->Y_Pi_r_loc, &y));
PetscCall(VecC2P(data->y_Pi_r_ceed, y_mem_type, bddc_ctx->Y_Pi_r_loc));
// ---- X_Pi_r = S^-1 Y_Pi_r
PetscCall(KSPSolve(bddc_ctx->ksp_S_Pi_r, bddc_ctx->Y_Pi_r_loc, bddc_ctx->X_Pi_r_loc));
// ---- X_r += B X_Pi_r
PetscCall(VecGetArrayReadAndMemType(bddc_ctx->X_Pi_r_loc, (const PetscScalar **)&x, &x_mem_type));
CeedVectorSetArray(data->x_Pi_r_ceed, MemTypeP2C(x_mem_type), CEED_USE_POINTER, x);
PetscCall(VecReadP2C(bddc_ctx->X_Pi_r_loc, &x_mem_type, data->x_Pi_r_ceed));
CeedOperatorApplyAdd(data->op_inject_Pi_r, data->x_Pi_r_ceed, x_r_ceed, CEED_REQUEST_IMMEDIATE);
CeedVectorTakeArray(data->x_Pi_r_ceed, MemTypeP2C(x_mem_type), &x);
PetscCall(VecRestoreArrayReadAndMemType(bddc_ctx->X_Pi_r_loc, (const PetscScalar **)&x));
PetscCall(VecReadC2P(data->x_Pi_r_ceed, x_mem_type, bddc_ctx->X_Pi_r_loc));
// -- Y_r = A_r,r^-1 X_r
CeedOperatorApply(data->op_r_r_inv, x_r_ceed, y_r_ceed, CEED_REQUEST_IMMEDIATE);

PetscFunctionReturn(PETSC_SUCCESS);
};

Expand All @@ -282,19 +264,15 @@ PetscErrorCode BDDCArrInv(BDDCApplyContext bddc_ctx, CeedVector x_r_ceed, CeedVe
// -----------------------------------------------------------------------------
PetscErrorCode MatMult_BDDCSchur(BDDCApplyContext bddc_ctx, Vec X_Pi, Vec Y_Pi) {
CeedDataBDDC data = bddc_ctx->ceed_data_bddc;
PetscScalar *x, *y;
PetscMemType x_mem_type, y_mem_type;

PetscFunctionBeginUser;

// Global-to-Local
PetscCall(VecZeroEntries(bddc_ctx->X_Pi_loc));
PetscCall(DMGlobalToLocal(bddc_ctx->dm_Pi, X_Pi, INSERT_VALUES, bddc_ctx->X_Pi_loc));
// Set arrays in libCEED
PetscCall(VecGetArrayReadAndMemType(bddc_ctx->X_Pi_loc, (const PetscScalar **)&x, &x_mem_type));
PetscCall(VecGetArrayAndMemType(bddc_ctx->Y_Pi_loc, &y, &y_mem_type));
CeedVectorSetArray(data->x_Pi_ceed, MemTypeP2C(x_mem_type), CEED_USE_POINTER, x);
CeedVectorSetArray(data->y_Pi_ceed, MemTypeP2C(y_mem_type), CEED_USE_POINTER, y);
PetscCall(VecReadP2C(bddc_ctx->X_Pi_loc, &x_mem_type, data->x_Pi_ceed));
PetscCall(VecP2C(bddc_ctx->Y_Pi_loc, &y_mem_type, data->y_Pi_ceed));

// Apply action on Schur compliment
// Y_Pi = (A_Pi,Pi - A_Pi,r A_r,r^-1 A_r,Pi) X_Pi
Expand All @@ -310,14 +288,11 @@ PetscErrorCode MatMult_BDDCSchur(BDDCApplyContext bddc_ctx, Vec X_Pi, Vec Y_Pi)
CeedOperatorApplyAdd(data->op_Pi_Pi, data->x_Pi_ceed, data->y_Pi_ceed, CEED_REQUEST_IMMEDIATE);

// Restore arrays
CeedVectorTakeArray(data->x_Pi_ceed, MemTypeP2C(x_mem_type), &x);
CeedVectorTakeArray(data->y_Pi_ceed, MemTypeP2C(y_mem_type), &y);
PetscCall(VecRestoreArrayReadAndMemType(bddc_ctx->X_Pi_loc, (const PetscScalar **)&x));
PetscCall(VecRestoreArrayAndMemType(bddc_ctx->Y_Pi_loc, &y));
PetscCall(VecReadC2P(data->x_Pi_ceed, x_mem_type, bddc_ctx->X_Pi_loc));
PetscCall(VecC2P(data->y_Pi_ceed, y_mem_type, bddc_ctx->Y_Pi_loc));
// Local-to-Global
PetscCall(VecZeroEntries(Y_Pi));
PetscCall(DMLocalToGlobal(bddc_ctx->dm_Pi, bddc_ctx->Y_Pi_loc, ADD_VALUES, Y_Pi));

PetscFunctionReturn(PETSC_SUCCESS);
};

Expand All @@ -328,9 +303,7 @@ PetscErrorCode FormResidual_BDDCSchur(SNES snes, Vec X_Pi, Vec Y_Pi, void *ctx)
BDDCApplyContext bddc_ctx = (BDDCApplyContext)ctx;

PetscFunctionBeginUser;

PetscCall(MatMult_BDDCSchur(bddc_ctx, X_Pi, Y_Pi));

PetscFunctionReturn(PETSC_SUCCESS);
};

Expand All @@ -340,11 +313,9 @@ PetscErrorCode FormResidual_BDDCSchur(SNES snes, Vec X_Pi, Vec Y_Pi, void *ctx)
PetscErrorCode PCShellApply_BDDC(PC pc, Vec X, Vec Y) {
BDDCApplyContext bddc_ctx;
CeedDataBDDC data;
PetscScalar *x, *y;
PetscMemType x_mem_type, y_mem_type;

PetscFunctionBeginUser;

PetscCall(PCShellGetContext(pc, (void *)&bddc_ctx));
data = bddc_ctx->ceed_data_bddc;

Expand All @@ -354,11 +325,9 @@ PetscErrorCode PCShellApply_BDDC(PC pc, Vec X, Vec Y) {
PetscCall(VecZeroEntries(bddc_ctx->X_loc));
PetscCall(DMGlobalToLocal(bddc_ctx->dm, X, INSERT_VALUES, bddc_ctx->X_loc));
// ---- Inject to Y_r
PetscCall(VecGetArrayReadAndMemType(bddc_ctx->X_loc, (const PetscScalar **)&x, &x_mem_type));
CeedVectorSetArray(data->x_ceed, MemTypeP2C(x_mem_type), CEED_USE_POINTER, x);
PetscCall(VecReadP2C(bddc_ctx->X_loc, &x_mem_type, data->x_ceed));
CeedOperatorApply(data->op_inject_r, data->x_ceed, data->y_r_ceed, CEED_REQUEST_IMMEDIATE);
CeedVectorTakeArray(data->x_ceed, MemTypeP2C(x_mem_type), &x);
PetscCall(VecRestoreArrayReadAndMemType(bddc_ctx->X_loc, (const PetscScalar **)&x));
PetscCall(VecReadC2P(data->x_ceed, x_mem_type, bddc_ctx->X_loc));
// -- Harmonic injection, scaled with jump map
if (bddc_ctx->is_harmonic) {
CeedVectorPointwiseMult(data->x_r_ceed, data->y_r_ceed, data->mask_I_ceed);
Expand All @@ -371,18 +340,15 @@ PetscErrorCode PCShellApply_BDDC(PC pc, Vec X, Vec Y) {
// ---- J^T (jump map)
CeedVectorPointwiseMult(data->z_r_ceed, data->x_r_ceed, data->mult_ceed);
// ------ Local-to-Global
PetscCall(VecGetArrayAndMemType(bddc_ctx->Y_loc, &y, &y_mem_type));
CeedVectorSetArray(data->y_ceed, MemTypeP2C(y_mem_type), CEED_USE_POINTER, y);
PetscCall(VecP2C(bddc_ctx->Y_loc, &y_mem_type, data->y_ceed));
CeedOperatorApply(data->op_restrict_r, data->z_r_ceed, data->y_ceed, CEED_REQUEST_IMMEDIATE);
CeedVectorTakeArray(data->y_ceed, MemTypeP2C(y_mem_type), &y);
PetscCall(VecRestoreArrayAndMemType(bddc_ctx->Y_loc, &y));
PetscCall(VecC2P(data->y_ceed, y_mem_type, bddc_ctx->Y_loc));
PetscCall(VecZeroEntries(Y));
PetscCall(DMLocalToGlobal(bddc_ctx->dm, bddc_ctx->Y_loc, ADD_VALUES, Y));
// ------ Global-to-Local
PetscCall(VecZeroEntries(bddc_ctx->Y_loc));
PetscCall(DMGlobalToLocal(bddc_ctx->dm, Y, INSERT_VALUES, bddc_ctx->Y_loc));
PetscCall(VecGetArrayReadAndMemType(bddc_ctx->Y_loc, (const PetscScalar **)&y, &y_mem_type));
CeedVectorSetArray(data->y_ceed, MemTypeP2C(y_mem_type), CEED_USE_POINTER, y);
PetscCall(VecReadP2C(bddc_ctx->Y_loc, &y_mem_type, data->y_ceed));
CeedOperatorApply(data->op_inject_r, data->y_ceed, data->z_r_ceed, CEED_REQUEST_IMMEDIATE);
CeedVectorAXPY(data->z_r_ceed, -1.0, data->x_r_ceed);
// ---- Y_r -= J^T (- A_Gamma,I A_I,I^-1) Y_r
Expand All @@ -392,11 +358,9 @@ PetscErrorCode PCShellApply_BDDC(PC pc, Vec X, Vec Y) {
CeedVectorPointwiseMult(data->y_r_ceed, data->y_r_ceed, data->mult_ceed);
}
// ---- Inject to Y_Pi
PetscCall(VecGetArrayAndMemType(bddc_ctx->Y_Pi_loc, &y, &y_mem_type));
CeedVectorSetArray(data->y_Pi_ceed, MemTypeP2C(y_mem_type), CEED_USE_POINTER, y);
PetscCall(VecP2C(bddc_ctx->Y_Pi_loc, &y_mem_type, data->y_Pi_ceed));
CeedOperatorApply(data->op_inject_Pi, data->y_r_ceed, data->y_Pi_ceed, CEED_REQUEST_IMMEDIATE);
CeedVectorTakeArray(data->y_Pi_ceed, MemTypeP2C(y_mem_type), &y);
PetscCall(VecRestoreArrayAndMemType(bddc_ctx->Y_Pi_loc, &y));
PetscCall(VecC2P(data->y_Pi_ceed, y_mem_type, bddc_ctx->Y_Pi_loc));
// ---- Global-To-Local
PetscCall(VecZeroEntries(bddc_ctx->Y_Pi));
PetscCall(DMLocalToGlobal(bddc_ctx->dm_Pi, bddc_ctx->Y_Pi_loc, ADD_VALUES, bddc_ctx->Y_Pi));
Expand All @@ -406,12 +370,10 @@ PetscErrorCode PCShellApply_BDDC(PC pc, Vec X, Vec Y) {
// -- X_r = A_r,r^-1 Y_r
PetscCall(BDDCArrInv(bddc_ctx, data->y_r_ceed, data->x_r_ceed));
// -- X_Pi = A_Pi,r X_r
PetscCall(VecGetArrayAndMemType(bddc_ctx->X_Pi_loc, &x, &x_mem_type));
CeedVectorSetArray(data->x_Pi_ceed, MemTypeP2C(x_mem_type), CEED_USE_POINTER, x);
PetscCall(VecP2C(bddc_ctx->X_Pi_loc, &x_mem_type, data->x_Pi_ceed));
CeedVectorPointwiseMult(data->x_r_ceed, data->x_r_ceed, data->mask_r_ceed);
CeedOperatorApply(data->op_Pi_r, data->x_r_ceed, data->x_Pi_ceed, CEED_REQUEST_IMMEDIATE);
CeedVectorTakeArray(data->x_Pi_ceed, MemTypeP2C(x_mem_type), &x);
PetscCall(VecRestoreArrayAndMemType(bddc_ctx->X_Pi_loc, &x));
PetscCall(VecC2P(data->x_Pi_ceed, x_mem_type, bddc_ctx->X_Pi_loc));
PetscCall(VecZeroEntries(bddc_ctx->X_Pi));
PetscCall(DMLocalToGlobal(bddc_ctx->dm_Pi, bddc_ctx->X_Pi_loc, ADD_VALUES, bddc_ctx->X_Pi));
// -- Y_Pi -= A_Pi_r A_r,r^-1 Y_r == X_Pi
Expand All @@ -429,11 +391,9 @@ PetscErrorCode PCShellApply_BDDC(PC pc, Vec X, Vec Y) {
// -- Y_r = A_r,Pi X_Pi
PetscCall(VecZeroEntries(bddc_ctx->X_Pi_loc));
PetscCall(DMGlobalToLocal(bddc_ctx->dm_Pi, bddc_ctx->X_Pi, INSERT_VALUES, bddc_ctx->X_Pi_loc));
PetscCall(VecGetArrayReadAndMemType(bddc_ctx->X_Pi_loc, (const PetscScalar **)&x, &x_mem_type));
CeedVectorSetArray(data->x_Pi_ceed, MemTypeP2C(x_mem_type), CEED_USE_POINTER, x);
PetscCall(VecReadP2C(bddc_ctx->X_Pi_loc, &x_mem_type, data->x_Pi_ceed));
CeedOperatorApply(data->op_r_Pi, data->x_Pi_ceed, data->y_r_ceed, CEED_REQUEST_IMMEDIATE);
CeedVectorTakeArray(data->x_Pi_ceed, MemTypeP2C(x_mem_type), &x);
PetscCall(VecRestoreArrayReadAndMemType(bddc_ctx->X_Pi_loc, (const PetscScalar **)&x));
PetscCall(VecReadC2P(data->x_Pi_ceed, x_mem_type, bddc_ctx->X_Pi_loc));
// -- Z_r = A_r,r^-1 Y_r
PetscCall(BDDCArrInv(bddc_ctx, data->y_r_ceed, data->z_r_ceed));
// -- X_r -= A_r,r^-1 A_r,Pi X_Pi == Z_r
Expand All @@ -443,33 +403,27 @@ PetscErrorCode PCShellApply_BDDC(PC pc, Vec X, Vec Y) {
// Restrict to fine space
// -- Scaled restriction, point multiply by 1/multiplicity
// ---- Copy X_Pi to X_r
PetscCall(VecGetArrayReadAndMemType(bddc_ctx->X_Pi_loc, (const PetscScalar **)&x, &x_mem_type));
CeedVectorSetArray(data->x_Pi_ceed, MemTypeP2C(x_mem_type), CEED_USE_POINTER, x);
PetscCall(VecReadP2C(bddc_ctx->X_Pi_loc, &x_mem_type, data->x_Pi_ceed));
CeedVectorPointwiseMult(data->x_r_ceed, data->x_r_ceed, data->mask_r_ceed);
CeedOperatorApplyAdd(data->op_restrict_Pi, data->x_Pi_ceed, data->x_r_ceed, CEED_REQUEST_IMMEDIATE);
CeedVectorTakeArray(data->x_Pi_ceed, MemTypeP2C(x_mem_type), &x);
PetscCall(VecRestoreArrayReadAndMemType(bddc_ctx->X_Pi_loc, (const PetscScalar **)&x));
PetscCall(VecReadC2P(data->x_Pi_ceed, x_mem_type, bddc_ctx->X_Pi_loc));
// -- Harmonic injection, scaled with jump map
if (bddc_ctx->is_harmonic) {
// ---- J^T (jump map)
CeedVectorPointwiseMult(data->z_r_ceed, data->x_r_ceed, data->mult_ceed);
// ------ Local-to-Global
PetscCall(VecGetArrayAndMemType(bddc_ctx->Y_loc, &y, &y_mem_type));
CeedVectorSetArray(data->y_ceed, MemTypeP2C(y_mem_type), CEED_USE_POINTER, y);
PetscCall(VecP2C(bddc_ctx->Y_loc, &y_mem_type, data->y_ceed));
CeedOperatorApply(data->op_restrict_r, data->z_r_ceed, data->y_ceed, CEED_REQUEST_IMMEDIATE);
CeedVectorTakeArray(data->y_ceed, MemTypeP2C(y_mem_type), &y);
PetscCall(VecRestoreArrayAndMemType(bddc_ctx->Y_loc, &y));
PetscCall(VecC2P(data->y_ceed, y_mem_type, bddc_ctx->Y_loc));
PetscCall(VecZeroEntries(Y));
PetscCall(DMLocalToGlobal(bddc_ctx->dm, bddc_ctx->Y_loc, ADD_VALUES, Y));
// ------ Global-to-Local
PetscCall(VecZeroEntries(bddc_ctx->Y_loc));
PetscCall(DMGlobalToLocal(bddc_ctx->dm, Y, INSERT_VALUES, bddc_ctx->Y_loc));
PetscCall(VecGetArrayReadAndMemType(bddc_ctx->Y_loc, (const PetscScalar **)&y, &y_mem_type));
CeedVectorSetArray(data->y_ceed, MemTypeP2C(y_mem_type), CEED_USE_POINTER, y);
PetscCall(VecReadP2C(bddc_ctx->Y_loc, &y_mem_type, data->y_ceed));
CeedOperatorApply(data->op_inject_r, data->y_ceed, data->z_r_ceed, CEED_REQUEST_IMMEDIATE);
CeedVectorAXPY(data->z_r_ceed, -1.0, data->x_r_ceed);
CeedVectorTakeArray(data->y_ceed, MemTypeP2C(y_mem_type), &y);
PetscCall(VecRestoreArrayAndMemType(bddc_ctx->Y_loc, &y));
PetscCall(VecReadC2P(data->y_ceed, y_mem_type, bddc_ctx->Y_loc));
// ---- Y_r = A_I,Gamma Z_r
CeedVectorPointwiseMult(data->z_r_ceed, data->z_r_ceed, data->mask_Gamma_ceed);
CeedOperatorApply(data->op_r_r, data->z_r_ceed, data->y_r_ceed, CEED_REQUEST_IMMEDIATE);
Expand All @@ -483,30 +437,26 @@ PetscErrorCode PCShellApply_BDDC(PC pc, Vec X, Vec Y) {
CeedVectorPointwiseMult(data->x_r_ceed, data->x_r_ceed, data->mult_ceed);
}
// ---- Restrict to Y
PetscCall(VecGetArrayAndMemType(bddc_ctx->Y_loc, &y, &y_mem_type));
CeedVectorSetArray(data->y_ceed, MemTypeP2C(y_mem_type), CEED_USE_POINTER, y);
PetscCall(VecP2C(bddc_ctx->Y_loc, &y_mem_type, data->y_ceed));
CeedOperatorApply(data->op_restrict_r, data->x_r_ceed, data->y_ceed, CEED_REQUEST_IMMEDIATE);
CeedVectorTakeArray(data->y_ceed, MemTypeP2C(y_mem_type), &y);
PetscCall(VecRestoreArrayAndMemType(bddc_ctx->Y_loc, &y));
PetscCall(VecC2P(data->y_ceed, y_mem_type, bddc_ctx->Y_loc));
// ---- Local-to-Global
PetscCall(VecZeroEntries(Y));
PetscCall(DMLocalToGlobal(bddc_ctx->dm, bddc_ctx->Y_loc, ADD_VALUES, Y));
// Note: current values in Y

PetscFunctionReturn(PETSC_SUCCESS);
};

// -----------------------------------------------------------------------------
// This function calculates the error in the final solution
// -----------------------------------------------------------------------------
PetscErrorCode ComputeL2Error(Vec X, PetscScalar *l2_error, OperatorApplyContext op_error_ctx) {
Vec E;
PetscScalar error_sq = 1.0;
Vec E;

PetscFunctionBeginUser;

PetscCall(VecDuplicate(X, &E));
PetscCall(ApplyLocal_Ceed(X, E, op_error_ctx));
PetscScalar error_sq = 1.0;
PetscCall(VecSum(E, &error_sq));
*l2_error = sqrt(error_sq);
PetscFunctionReturn(PETSC_SUCCESS);
Expand Down

0 comments on commit c6fc698

Please sign in to comment.