diff --git a/examples/fluids/navierstokes.c b/examples/fluids/navierstokes.c index 157485dc77..9be32c16b0 100644 --- a/examples/fluids/navierstokes.c +++ b/examples/fluids/navierstokes.c @@ -104,22 +104,24 @@ int main(int argc, char **argv) { // --------------------------------------------------------------------------- // -- Initialize backend Ceed ceed; - CeedInit(app_ctx->ceed_resource, &ceed); + PetscCheck(CeedInit(app_ctx->ceed_resource, &ceed) == CEED_ERROR_SUCCESS, comm, PETSC_ERR_LIB, "Ceed initialization failed"); user->ceed = ceed; + PetscCheck(CeedSetErrorHandler(ceed, CeedErrorStore) == CEED_ERROR_SUCCESS, comm, PETSC_ERR_LIB, "Setting libCEED error handler failed"); + // -- Check preferred MemType CeedMemType mem_type_backend; - CeedGetPreferredMemType(ceed, &mem_type_backend); + PetscCallCeed(ceed, CeedGetPreferredMemType(ceed, &mem_type_backend)); { const char *resource; - CeedGetResource(ceed, &resource); + PetscCallCeed(ceed, CeedGetResource(ceed, &resource)); if (strstr(resource, "/gpu/sycl")) { PetscDeviceContext dctx; PetscCall(PetscDeviceContextGetCurrentContext(&dctx)); void *stream_handle; PetscCall(PetscDeviceContextGetStreamHandle(dctx, &stream_handle)); - CeedSetStream(ceed, stream_handle); + PetscCallCeed(ceed, CeedSetStream(ceed, stream_handle)); } } @@ -136,7 +138,7 @@ int main(int argc, char **argv) { break; case CEED_MEM_DEVICE: { const char *resolved; - CeedGetResource(ceed, &resolved); + PetscCallCeed(ceed, CeedGetResource(ceed, &resolved)); if (strstr(resolved, "/gpu/cuda")) vec_type = VECCUDA; else if (strstr(resolved, "/gpu/hip")) vec_type = VECKOKKOS; else if (strstr(resolved, "/gpu/sycl")) vec_type = VECKOKKOS; @@ -256,65 +258,65 @@ int main(int argc, char **argv) { PetscCall(DifferentialFilterDataDestroy(user->diff_filter)); // -- Vectors - CeedVectorDestroy(&ceed_data->x_coord); - CeedVectorDestroy(&ceed_data->q_data); - CeedVectorDestroy(&user->q_ceed); - CeedVectorDestroy(&user->q_dot_ceed); - CeedVectorDestroy(&user->g_ceed); - CeedVectorDestroy(&user->coo_values_amat); - CeedVectorDestroy(&user->coo_values_pmat); + PetscCallCeed(ceed, CeedVectorDestroy(&ceed_data->x_coord)); + PetscCallCeed(ceed, CeedVectorDestroy(&ceed_data->q_data)); + PetscCallCeed(ceed, CeedVectorDestroy(&user->q_ceed)); + PetscCallCeed(ceed, CeedVectorDestroy(&user->q_dot_ceed)); + PetscCallCeed(ceed, CeedVectorDestroy(&user->g_ceed)); + PetscCallCeed(ceed, CeedVectorDestroy(&user->coo_values_amat)); + PetscCallCeed(ceed, CeedVectorDestroy(&user->coo_values_pmat)); // -- Bases - CeedBasisDestroy(&ceed_data->basis_q); - CeedBasisDestroy(&ceed_data->basis_x); - CeedBasisDestroy(&ceed_data->basis_xc); - CeedBasisDestroy(&ceed_data->basis_q_sur); - CeedBasisDestroy(&ceed_data->basis_x_sur); + PetscCallCeed(ceed, CeedBasisDestroy(&ceed_data->basis_q)); + PetscCallCeed(ceed, CeedBasisDestroy(&ceed_data->basis_x)); + PetscCallCeed(ceed, CeedBasisDestroy(&ceed_data->basis_xc)); + PetscCallCeed(ceed, CeedBasisDestroy(&ceed_data->basis_q_sur)); + PetscCallCeed(ceed, CeedBasisDestroy(&ceed_data->basis_x_sur)); // -- Restrictions - CeedElemRestrictionDestroy(&ceed_data->elem_restr_q); - CeedElemRestrictionDestroy(&ceed_data->elem_restr_x); - CeedElemRestrictionDestroy(&ceed_data->elem_restr_qd_i); + PetscCallCeed(ceed, CeedElemRestrictionDestroy(&ceed_data->elem_restr_q)); + PetscCallCeed(ceed, CeedElemRestrictionDestroy(&ceed_data->elem_restr_x)); + PetscCallCeed(ceed, CeedElemRestrictionDestroy(&ceed_data->elem_restr_qd_i)); // Destroy QFunction contexts after using // ToDo: Simplify tracked libCEED objects, smaller struct { - CeedQFunctionContextDestroy(&problem->apply_inflow_jacobian.qfunction_context); - CeedQFunctionContextDestroy(&problem->apply_inflow_jacobian.qfunction_context); - CeedQFunctionContextDestroy(&problem->apply_outflow_jacobian.qfunction_context); - CeedQFunctionContextDestroy(&problem->apply_outflow_jacobian.qfunction_context); - CeedQFunctionContextDestroy(&problem->apply_freestream_jacobian.qfunction_context); - CeedQFunctionContextDestroy(&problem->apply_freestream_jacobian.qfunction_context); - CeedQFunctionContextDestroy(&problem->setup_sur.qfunction_context); - CeedQFunctionContextDestroy(&problem->setup_vol.qfunction_context); - CeedQFunctionContextDestroy(&problem->ics.qfunction_context); - CeedQFunctionContextDestroy(&problem->apply_vol_rhs.qfunction_context); - CeedQFunctionContextDestroy(&problem->apply_vol_ifunction.qfunction_context); - CeedQFunctionContextDestroy(&problem->apply_vol_ijacobian.qfunction_context); + PetscCallCeed(ceed, CeedQFunctionContextDestroy(&problem->apply_inflow_jacobian.qfunction_context)); + PetscCallCeed(ceed, CeedQFunctionContextDestroy(&problem->apply_inflow_jacobian.qfunction_context)); + PetscCallCeed(ceed, CeedQFunctionContextDestroy(&problem->apply_outflow_jacobian.qfunction_context)); + PetscCallCeed(ceed, CeedQFunctionContextDestroy(&problem->apply_outflow_jacobian.qfunction_context)); + PetscCallCeed(ceed, CeedQFunctionContextDestroy(&problem->apply_freestream_jacobian.qfunction_context)); + PetscCallCeed(ceed, CeedQFunctionContextDestroy(&problem->apply_freestream_jacobian.qfunction_context)); + PetscCallCeed(ceed, CeedQFunctionContextDestroy(&problem->setup_sur.qfunction_context)); + PetscCallCeed(ceed, CeedQFunctionContextDestroy(&problem->setup_vol.qfunction_context)); + PetscCallCeed(ceed, CeedQFunctionContextDestroy(&problem->ics.qfunction_context)); + PetscCallCeed(ceed, CeedQFunctionContextDestroy(&problem->apply_vol_rhs.qfunction_context)); + PetscCallCeed(ceed, CeedQFunctionContextDestroy(&problem->apply_vol_ifunction.qfunction_context)); + PetscCallCeed(ceed, CeedQFunctionContextDestroy(&problem->apply_vol_ijacobian.qfunction_context)); } // -- QFunctions - CeedQFunctionDestroy(&ceed_data->qf_setup_vol); - CeedQFunctionDestroy(&ceed_data->qf_ics); - CeedQFunctionDestroy(&ceed_data->qf_rhs_vol); - CeedQFunctionDestroy(&ceed_data->qf_ifunction_vol); - CeedQFunctionDestroy(&ceed_data->qf_setup_sur); - CeedQFunctionDestroy(&ceed_data->qf_apply_inflow); - CeedQFunctionDestroy(&ceed_data->qf_apply_inflow_jacobian); - CeedQFunctionDestroy(&ceed_data->qf_apply_freestream); - CeedQFunctionDestroy(&ceed_data->qf_apply_freestream_jacobian); + PetscCallCeed(ceed, CeedQFunctionDestroy(&ceed_data->qf_setup_vol)); + PetscCallCeed(ceed, CeedQFunctionDestroy(&ceed_data->qf_ics)); + PetscCallCeed(ceed, CeedQFunctionDestroy(&ceed_data->qf_rhs_vol)); + PetscCallCeed(ceed, CeedQFunctionDestroy(&ceed_data->qf_ifunction_vol)); + PetscCallCeed(ceed, CeedQFunctionDestroy(&ceed_data->qf_setup_sur)); + PetscCallCeed(ceed, CeedQFunctionDestroy(&ceed_data->qf_apply_inflow)); + PetscCallCeed(ceed, CeedQFunctionDestroy(&ceed_data->qf_apply_inflow_jacobian)); + PetscCallCeed(ceed, CeedQFunctionDestroy(&ceed_data->qf_apply_freestream)); + PetscCallCeed(ceed, CeedQFunctionDestroy(&ceed_data->qf_apply_freestream_jacobian)); // -- Operators - CeedOperatorDestroy(&ceed_data->op_setup_vol); + PetscCallCeed(ceed, CeedOperatorDestroy(&ceed_data->op_setup_vol)); PetscCall(OperatorApplyContextDestroy(ceed_data->op_ics_ctx)); - CeedOperatorDestroy(&user->op_rhs_vol); - CeedOperatorDestroy(&user->op_ifunction_vol); + PetscCallCeed(ceed, CeedOperatorDestroy(&user->op_rhs_vol)); + PetscCallCeed(ceed, CeedOperatorDestroy(&user->op_ifunction_vol)); PetscCall(OperatorApplyContextDestroy(user->op_rhs_ctx)); - CeedOperatorDestroy(&user->op_ifunction); - CeedOperatorDestroy(&user->op_ijacobian); + PetscCallCeed(ceed, CeedOperatorDestroy(&user->op_ifunction)); + PetscCallCeed(ceed, CeedOperatorDestroy(&user->op_ijacobian)); // -- Ceed - CeedDestroy(&ceed); + PetscCheck(CeedDestroy(&ceed) == CEED_ERROR_SUCCESS, comm, PETSC_ERR_LIB, "Destroying Ceed object failed"); if (app_ctx->test_type != TESTTYPE_NONE) { PetscInt num_options_left = 0; diff --git a/examples/fluids/navierstokes.h b/examples/fluids/navierstokes.h index b8086af5c9..5a53e7a719 100644 --- a/examples/fluids/navierstokes.h +++ b/examples/fluids/navierstokes.h @@ -16,13 +16,25 @@ #include "qfunctions/newtonian_types.h" #include "qfunctions/stabilization_types.h" -// ----------------------------------------------------------------------------- -// PETSc Version -// ----------------------------------------------------------------------------- #if PETSC_VERSION_LT(3, 19, 0) #error "PETSc v3.19 or later is required" #endif +#define PetscCeedChk(ceed, ierr) \ + do { \ + if (ierr != CEED_ERROR_SUCCESS) { \ + const char *error_message; \ + CeedGetErrorMessage(ceed, &error_message); \ + SETERRQ(PETSC_COMM_SELF, PETSC_ERR_LIB, "%s", error_message); \ + } \ + } while (0) + +#define PetscCallCeed(ceed, ...) \ + do { \ + int ierr_q_ = __VA_ARGS__; \ + PetscCeedChk(ceed, ierr_q_); \ + } while (0) + // ----------------------------------------------------------------------------- // Enums // ----------------------------------------------------------------------------- @@ -279,7 +291,7 @@ struct ProblemData_private { apply_freestream, apply_inflow_jacobian, apply_outflow_jacobian, apply_freestream_jacobian; bool non_zero_time; PetscBool bc_from_ics, use_strong_bc_ceed; - PetscErrorCode (*print_info)(ProblemData *, AppCtx); + PetscErrorCode (*print_info)(User, ProblemData *, AppCtx); }; extern int FreeContextPetsc(void *); @@ -299,15 +311,15 @@ extern PetscErrorCode NS_ADVECTION(ProblemData *problem, DM dm, void *ctx, Simpl extern PetscErrorCode NS_ADVECTION2D(ProblemData *problem, DM dm, void *ctx, SimpleBC bc); // Print function for each problem -extern PetscErrorCode PRINT_NEWTONIAN(ProblemData *problem, AppCtx app_ctx); +extern PetscErrorCode PRINT_NEWTONIAN(User user, ProblemData *problem, AppCtx app_ctx); -extern PetscErrorCode PRINT_EULER_VORTEX(ProblemData *problem, AppCtx app_ctx); +extern PetscErrorCode PRINT_EULER_VORTEX(User user, ProblemData *problem, AppCtx app_ctx); -extern PetscErrorCode PRINT_SHOCKTUBE(ProblemData *problem, AppCtx app_ctx); +extern PetscErrorCode PRINT_SHOCKTUBE(User user, ProblemData *problem, AppCtx app_ctx); -extern PetscErrorCode PRINT_ADVECTION(ProblemData *problem, AppCtx app_ctx); +extern PetscErrorCode PRINT_ADVECTION(User user, ProblemData *problem, AppCtx app_ctx); -extern PetscErrorCode PRINT_ADVECTION2D(ProblemData *problem, AppCtx app_ctx); +extern PetscErrorCode PRINT_ADVECTION2D(User user, ProblemData *problem, AppCtx app_ctx); PetscErrorCode PrintRunInfo(User user, Physics phys_ctx, ProblemData *problem, MPI_Comm comm); diff --git a/examples/fluids/problems/advection.c b/examples/fluids/problems/advection.c index df9fbd7f8e..a814dd78b0 100644 --- a/examples/fluids/problems/advection.c +++ b/examples/fluids/problems/advection.c @@ -23,7 +23,8 @@ PetscErrorCode NS_ADVECTION(ProblemData *problem, DM dm, void *ctx, SimpleBC bc) StabilizationType stab; SetupContextAdv setup_context; User user = *(User *)ctx; - MPI_Comm comm = PETSC_COMM_WORLD; + MPI_Comm comm = user->comm; + Ceed ceed = user->ceed; PetscBool implicit; PetscBool has_curr_time = PETSC_FALSE; AdvectionContext advection_ctx; @@ -173,27 +174,29 @@ PetscErrorCode NS_ADVECTION(ProblemData *problem, DM dm, void *ctx, SimpleBC bc) advection_ctx->strong_form = strong_form; advection_ctx->stabilization = stab; - CeedQFunctionContextCreate(user->ceed, &problem->ics.qfunction_context); - CeedQFunctionContextSetData(problem->ics.qfunction_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*setup_context), setup_context); - CeedQFunctionContextSetDataDestroy(problem->ics.qfunction_context, CEED_MEM_HOST, FreeContextPetsc); + PetscCallCeed(ceed, CeedQFunctionContextCreate(user->ceed, &problem->ics.qfunction_context)); + PetscCallCeed(ceed, + CeedQFunctionContextSetData(problem->ics.qfunction_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*setup_context), setup_context)); + PetscCallCeed(ceed, CeedQFunctionContextSetDataDestroy(problem->ics.qfunction_context, CEED_MEM_HOST, FreeContextPetsc)); - CeedQFunctionContextCreate(user->ceed, &advection_context); - CeedQFunctionContextSetData(advection_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*advection_ctx), advection_ctx); - CeedQFunctionContextSetDataDestroy(advection_context, CEED_MEM_HOST, FreeContextPetsc); + PetscCallCeed(ceed, CeedQFunctionContextCreate(user->ceed, &advection_context)); + PetscCallCeed(ceed, CeedQFunctionContextSetData(advection_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*advection_ctx), advection_ctx)); + PetscCallCeed(ceed, CeedQFunctionContextSetDataDestroy(advection_context, CEED_MEM_HOST, FreeContextPetsc)); problem->apply_vol_rhs.qfunction_context = advection_context; - CeedQFunctionContextReferenceCopy(advection_context, &problem->apply_vol_ifunction.qfunction_context); - CeedQFunctionContextReferenceCopy(advection_context, &problem->apply_inflow.qfunction_context); + PetscCallCeed(ceed, CeedQFunctionContextReferenceCopy(advection_context, &problem->apply_vol_ifunction.qfunction_context)); + PetscCallCeed(ceed, CeedQFunctionContextReferenceCopy(advection_context, &problem->apply_inflow.qfunction_context)); PetscFunctionReturn(PETSC_SUCCESS); } -PetscErrorCode PRINT_ADVECTION(ProblemData *problem, AppCtx app_ctx) { - MPI_Comm comm = PETSC_COMM_WORLD; +PetscErrorCode PRINT_ADVECTION(User user, ProblemData *problem, AppCtx app_ctx) { + MPI_Comm comm = user->comm; + Ceed ceed = user->ceed; SetupContextAdv setup_ctx; AdvectionContext advection_ctx; PetscFunctionBeginUser; - CeedQFunctionContextGetData(problem->ics.qfunction_context, CEED_MEM_HOST, &setup_ctx); - CeedQFunctionContextGetData(problem->apply_vol_rhs.qfunction_context, CEED_MEM_HOST, &advection_ctx); + PetscCallCeed(ceed, CeedQFunctionContextGetData(problem->ics.qfunction_context, CEED_MEM_HOST, &setup_ctx)); + PetscCallCeed(ceed, CeedQFunctionContextGetData(problem->apply_vol_rhs.qfunction_context, CEED_MEM_HOST, &advection_ctx)); PetscCall(PetscPrintf(comm, " Problem:\n" " Problem Name : %s\n" @@ -208,7 +211,7 @@ PetscErrorCode PRINT_ADVECTION(ProblemData *problem, AppCtx app_ctx) { if (setup_ctx->wind_type == WIND_TRANSLATION) { PetscCall(PetscPrintf(comm, " Background Wind : %f,%f,%f\n", setup_ctx->wind[0], setup_ctx->wind[1], setup_ctx->wind[2])); } - CeedQFunctionContextRestoreData(problem->ics.qfunction_context, &setup_ctx); - CeedQFunctionContextRestoreData(problem->apply_vol_rhs.qfunction_context, &advection_ctx); + PetscCallCeed(ceed, CeedQFunctionContextRestoreData(problem->ics.qfunction_context, &setup_ctx)); + PetscCallCeed(ceed, CeedQFunctionContextRestoreData(problem->apply_vol_rhs.qfunction_context, &advection_ctx)); PetscFunctionReturn(PETSC_SUCCESS); } diff --git a/examples/fluids/problems/advection2d.c b/examples/fluids/problems/advection2d.c index b074a5ae8d..692e09a989 100644 --- a/examples/fluids/problems/advection2d.c +++ b/examples/fluids/problems/advection2d.c @@ -21,7 +21,8 @@ PetscErrorCode NS_ADVECTION2D(ProblemData *problem, DM dm, void *ctx, SimpleBC b StabilizationType stab; SetupContextAdv2D setup_context; User user = *(User *)ctx; - MPI_Comm comm = PETSC_COMM_WORLD; + MPI_Comm comm = user->comm; + Ceed ceed = user->ceed; PetscBool implicit; PetscBool has_curr_time = PETSC_FALSE; AdvectionContext advection_ctx; @@ -156,27 +157,29 @@ PetscErrorCode NS_ADVECTION2D(ProblemData *problem, DM dm, void *ctx, SimpleBC b advection_ctx->strong_form = strong_form; advection_ctx->stabilization = stab; - CeedQFunctionContextCreate(user->ceed, &problem->ics.qfunction_context); - CeedQFunctionContextSetData(problem->ics.qfunction_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*setup_context), setup_context); - CeedQFunctionContextSetDataDestroy(problem->ics.qfunction_context, CEED_MEM_HOST, FreeContextPetsc); + PetscCallCeed(ceed, CeedQFunctionContextCreate(user->ceed, &problem->ics.qfunction_context)); + PetscCallCeed(ceed, + CeedQFunctionContextSetData(problem->ics.qfunction_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*setup_context), setup_context)); + PetscCallCeed(ceed, CeedQFunctionContextSetDataDestroy(problem->ics.qfunction_context, CEED_MEM_HOST, FreeContextPetsc)); - CeedQFunctionContextCreate(user->ceed, &advection_context); - CeedQFunctionContextSetData(advection_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*advection_ctx), advection_ctx); - CeedQFunctionContextSetDataDestroy(advection_context, CEED_MEM_HOST, FreeContextPetsc); + PetscCallCeed(ceed, CeedQFunctionContextCreate(user->ceed, &advection_context)); + PetscCallCeed(ceed, CeedQFunctionContextSetData(advection_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*advection_ctx), advection_ctx)); + PetscCallCeed(ceed, CeedQFunctionContextSetDataDestroy(advection_context, CEED_MEM_HOST, FreeContextPetsc)); problem->apply_vol_rhs.qfunction_context = advection_context; - CeedQFunctionContextReferenceCopy(advection_context, &problem->apply_vol_ifunction.qfunction_context); - CeedQFunctionContextReferenceCopy(advection_context, &problem->apply_inflow.qfunction_context); + PetscCallCeed(ceed, CeedQFunctionContextReferenceCopy(advection_context, &problem->apply_vol_ifunction.qfunction_context)); + PetscCallCeed(ceed, CeedQFunctionContextReferenceCopy(advection_context, &problem->apply_inflow.qfunction_context)); PetscFunctionReturn(PETSC_SUCCESS); } -PetscErrorCode PRINT_ADVECTION2D(ProblemData *problem, AppCtx app_ctx) { - MPI_Comm comm = PETSC_COMM_WORLD; +PetscErrorCode PRINT_ADVECTION2D(User user, ProblemData *problem, AppCtx app_ctx) { + MPI_Comm comm = user->comm; + Ceed ceed = user->ceed; SetupContextAdv2D setup_ctx; AdvectionContext advection_ctx; PetscFunctionBeginUser; - CeedQFunctionContextGetData(problem->ics.qfunction_context, CEED_MEM_HOST, &setup_ctx); - CeedQFunctionContextGetData(problem->apply_vol_rhs.qfunction_context, CEED_MEM_HOST, &advection_ctx); + PetscCallCeed(ceed, CeedQFunctionContextGetData(problem->ics.qfunction_context, CEED_MEM_HOST, &setup_ctx)); + PetscCallCeed(ceed, CeedQFunctionContextGetData(problem->apply_vol_rhs.qfunction_context, CEED_MEM_HOST, &advection_ctx)); PetscCall(PetscPrintf(comm, " Problem:\n" " Problem Name : %s\n" @@ -187,7 +190,7 @@ PetscErrorCode PRINT_ADVECTION2D(ProblemData *problem, AppCtx app_ctx) { if (setup_ctx->wind_type == WIND_TRANSLATION) { PetscCall(PetscPrintf(comm, " Background Wind : %f,%f\n", setup_ctx->wind[0], setup_ctx->wind[1])); } - CeedQFunctionContextRestoreData(problem->ics.qfunction_context, &setup_ctx); - CeedQFunctionContextRestoreData(problem->apply_vol_rhs.qfunction_context, &advection_ctx); + PetscCallCeed(ceed, CeedQFunctionContextRestoreData(problem->ics.qfunction_context, &setup_ctx)); + PetscCallCeed(ceed, CeedQFunctionContextRestoreData(problem->apply_vol_rhs.qfunction_context, &advection_ctx)); PetscFunctionReturn(PETSC_SUCCESS); } diff --git a/examples/fluids/problems/blasius.c b/examples/fluids/problems/blasius.c index f1c5c504f9..acc9394884 100644 --- a/examples/fluids/problems/blasius.c +++ b/examples/fluids/problems/blasius.c @@ -232,6 +232,7 @@ static PetscErrorCode ModifyMesh(MPI_Comm comm, DM dm, PetscInt dim, PetscReal g PetscErrorCode NS_BLASIUS(ProblemData *problem, DM dm, void *ctx, SimpleBC bc) { User user = *(User *)ctx; MPI_Comm comm = user->comm; + Ceed ceed = user->ceed; PetscBool use_stg = PETSC_FALSE; BlasiusContext blasius_ctx; NewtonianIdealGasContext newtonian_ig_ctx; @@ -302,7 +303,7 @@ PetscErrorCode NS_BLASIUS(ProblemData *problem, DM dm, void *ctx, SimpleBC bc) { PetscCall(ModifyMesh(comm, dm, problem->dim, mesh_growth, mesh_Ndelta, mesh_refine_height, mesh_top_angle, &mesh_ynodes, &mesh_nynodes)); // Some properties depend on parameters from NewtonianIdealGas - CeedQFunctionContextGetData(problem->apply_vol_rhs.qfunction_context, CEED_MEM_HOST, &newtonian_ig_ctx); + PetscCallCeed(ceed, CeedQFunctionContextGetData(problem->apply_vol_rhs.qfunction_context, CEED_MEM_HOST, &newtonian_ig_ctx)); blasius_ctx->weakT = weakT; blasius_ctx->U_inf = U_inf; @@ -325,13 +326,13 @@ PetscErrorCode NS_BLASIUS(ProblemData *problem, DM dm, void *ctx, SimpleBC bc) { PetscCall(PetscOptionsGetBool(NULL, NULL, "-diff_filter_mms", &diff_filter_mms, NULL)); if (!use_stg && !diff_filter_mms) PetscCall(ComputeChebyshevCoefficients(blasius_ctx)); - CeedQFunctionContextRestoreData(problem->apply_vol_rhs.qfunction_context, &newtonian_ig_ctx); + PetscCallCeed(ceed, CeedQFunctionContextRestoreData(problem->apply_vol_rhs.qfunction_context, &newtonian_ig_ctx)); - CeedQFunctionContextCreate(user->ceed, &blasius_context); - CeedQFunctionContextSetData(blasius_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*blasius_ctx), blasius_ctx); - CeedQFunctionContextSetDataDestroy(blasius_context, CEED_MEM_HOST, FreeContextPetsc); + PetscCallCeed(ceed, CeedQFunctionContextCreate(user->ceed, &blasius_context)); + PetscCallCeed(ceed, CeedQFunctionContextSetData(blasius_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*blasius_ctx), blasius_ctx)); + PetscCallCeed(ceed, CeedQFunctionContextSetDataDestroy(blasius_context, CEED_MEM_HOST, FreeContextPetsc)); - CeedQFunctionContextDestroy(&problem->ics.qfunction_context); + PetscCallCeed(ceed, CeedQFunctionContextDestroy(&problem->ics.qfunction_context)); problem->ics.qfunction_context = blasius_context; if (use_stg) { PetscCall(SetupSTG(comm, dm, problem, user, weakT, T_inf, P0, mesh_ynodes, mesh_nynodes)); @@ -342,8 +343,8 @@ PetscErrorCode NS_BLASIUS(ProblemData *problem, DM dm, void *ctx, SimpleBC bc) { problem->apply_inflow.qfunction_loc = Blasius_Inflow_loc; problem->apply_inflow_jacobian.qfunction = Blasius_Inflow_Jacobian; problem->apply_inflow_jacobian.qfunction_loc = Blasius_Inflow_Jacobian_loc; - CeedQFunctionContextReferenceCopy(blasius_context, &problem->apply_inflow.qfunction_context); - CeedQFunctionContextReferenceCopy(blasius_context, &problem->apply_inflow_jacobian.qfunction_context); + PetscCallCeed(ceed, CeedQFunctionContextReferenceCopy(blasius_context, &problem->apply_inflow.qfunction_context)); + PetscCallCeed(ceed, CeedQFunctionContextReferenceCopy(blasius_context, &problem->apply_inflow_jacobian.qfunction_context)); } PetscCall(PetscFree(mesh_ynodes)); PetscFunctionReturn(PETSC_SUCCESS); diff --git a/examples/fluids/problems/channel.c b/examples/fluids/problems/channel.c index 974e7a54a8..946972c705 100644 --- a/examples/fluids/problems/channel.c +++ b/examples/fluids/problems/channel.c @@ -17,7 +17,8 @@ PetscErrorCode NS_CHANNEL(ProblemData *problem, DM dm, void *ctx, SimpleBC bc) { User user = *(User *)ctx; - MPI_Comm comm = PETSC_COMM_WORLD; + MPI_Comm comm = user->comm; + Ceed ceed = user->ceed; ChannelContext channel_ctx; NewtonianIdealGasContext newtonian_ig_ctx; CeedQFunctionContext channel_context; @@ -29,7 +30,7 @@ PetscErrorCode NS_CHANNEL(ProblemData *problem, DM dm, void *ctx, SimpleBC bc) { // ------------------------------------------------------ // SET UP Channel // ------------------------------------------------------ - CeedQFunctionContextDestroy(&problem->ics.qfunction_context); + PetscCallCeed(ceed, CeedQFunctionContextDestroy(&problem->ics.qfunction_context)); problem->ics.qfunction = ICsChannel; problem->ics.qfunction_loc = ICsChannel_loc; if (user->phys->state_var == STATEVAR_CONSERVATIVE) { @@ -72,7 +73,7 @@ PetscErrorCode NS_CHANNEL(ProblemData *problem, DM dm, void *ctx, SimpleBC bc) { } // Some properties depend on parameters from NewtonianIdealGas - CeedQFunctionContextGetData(problem->apply_vol_rhs.qfunction_context, CEED_MEM_HOST, &newtonian_ig_ctx); + PetscCallCeed(ceed, CeedQFunctionContextGetData(problem->apply_vol_rhs.qfunction_context, CEED_MEM_HOST, &newtonian_ig_ctx)); channel_ctx->center = center; channel_ctx->H = H; @@ -91,14 +92,14 @@ PetscErrorCode NS_CHANNEL(ProblemData *problem, DM dm, void *ctx, SimpleBC bc) { PetscCall(PetscArraycpy(newtonian_ig_ctx->g, g, 3)); } channel_ctx->newtonian_ctx = *newtonian_ig_ctx; - CeedQFunctionContextRestoreData(problem->apply_vol_rhs.qfunction_context, &newtonian_ig_ctx); + PetscCallCeed(ceed, CeedQFunctionContextRestoreData(problem->apply_vol_rhs.qfunction_context, &newtonian_ig_ctx)); - CeedQFunctionContextCreate(user->ceed, &channel_context); - CeedQFunctionContextSetData(channel_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*channel_ctx), channel_ctx); - CeedQFunctionContextSetDataDestroy(channel_context, CEED_MEM_HOST, FreeContextPetsc); + PetscCallCeed(ceed, CeedQFunctionContextCreate(user->ceed, &channel_context)); + PetscCallCeed(ceed, CeedQFunctionContextSetData(channel_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*channel_ctx), channel_ctx)); + PetscCallCeed(ceed, CeedQFunctionContextSetDataDestroy(channel_context, CEED_MEM_HOST, FreeContextPetsc)); problem->ics.qfunction_context = channel_context; - CeedQFunctionContextReferenceCopy(channel_context, &problem->apply_inflow.qfunction_context); - CeedQFunctionContextReferenceCopy(channel_context, &problem->apply_outflow.qfunction_context); + PetscCallCeed(ceed, CeedQFunctionContextReferenceCopy(channel_context, &problem->apply_inflow.qfunction_context)); + PetscCallCeed(ceed, CeedQFunctionContextReferenceCopy(channel_context, &problem->apply_outflow.qfunction_context)); PetscFunctionReturn(PETSC_SUCCESS); } diff --git a/examples/fluids/problems/densitycurrent.c b/examples/fluids/problems/densitycurrent.c index 6bb2aba9c7..58a8125882 100644 --- a/examples/fluids/problems/densitycurrent.c +++ b/examples/fluids/problems/densitycurrent.c @@ -16,8 +16,9 @@ #include "../navierstokes.h" PetscErrorCode NS_DENSITY_CURRENT(ProblemData *problem, DM dm, void *ctx, SimpleBC bc) { - MPI_Comm comm = PETSC_COMM_WORLD; User user = *(User *)ctx; + MPI_Comm comm = user->comm; + Ceed ceed = user->ceed; DensityCurrentContext dc_ctx; CeedQFunctionContext density_current_context; NewtonianIdealGasContext newtonian_ig_ctx; @@ -28,7 +29,7 @@ PetscErrorCode NS_DENSITY_CURRENT(ProblemData *problem, DM dm, void *ctx, Simple // ------------------------------------------------------ // SET UP DENSITY_CURRENT // ------------------------------------------------------ - CeedQFunctionContextDestroy(&problem->ics.qfunction_context); + PetscCallCeed(ceed, CeedQFunctionContextDestroy(&problem->ics.qfunction_context)); problem->ics.qfunction = ICsDC; problem->ics.qfunction_loc = ICsDC_loc; @@ -94,12 +95,12 @@ PetscErrorCode NS_DENSITY_CURRENT(ProblemData *problem, DM dm, void *ctx, Simple dc_ctx->dc_axis[1] = dc_axis[1]; dc_ctx->dc_axis[2] = dc_axis[2]; - CeedQFunctionContextGetData(problem->apply_vol_rhs.qfunction_context, CEED_MEM_HOST, &newtonian_ig_ctx); + PetscCallCeed(ceed, CeedQFunctionContextGetData(problem->apply_vol_rhs.qfunction_context, CEED_MEM_HOST, &newtonian_ig_ctx)); dc_ctx->newtonian_ctx = *newtonian_ig_ctx; - CeedQFunctionContextRestoreData(problem->apply_vol_rhs.qfunction_context, &newtonian_ig_ctx); - CeedQFunctionContextCreate(user->ceed, &density_current_context); - CeedQFunctionContextSetData(density_current_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*dc_ctx), dc_ctx); - CeedQFunctionContextSetDataDestroy(density_current_context, CEED_MEM_HOST, FreeContextPetsc); + PetscCallCeed(ceed, CeedQFunctionContextRestoreData(problem->apply_vol_rhs.qfunction_context, &newtonian_ig_ctx)); + PetscCallCeed(ceed, CeedQFunctionContextCreate(user->ceed, &density_current_context)); + PetscCallCeed(ceed, CeedQFunctionContextSetData(density_current_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*dc_ctx), dc_ctx)); + PetscCallCeed(ceed, CeedQFunctionContextSetDataDestroy(density_current_context, CEED_MEM_HOST, FreeContextPetsc)); problem->ics.qfunction_context = density_current_context; PetscFunctionReturn(PETSC_SUCCESS); diff --git a/examples/fluids/problems/eulervortex.c b/examples/fluids/problems/eulervortex.c index ff432054ae..c65636b74a 100644 --- a/examples/fluids/problems/eulervortex.c +++ b/examples/fluids/problems/eulervortex.c @@ -20,7 +20,8 @@ PetscErrorCode NS_EULER_VORTEX(ProblemData *problem, DM dm, void *ctx, SimpleBC EulerTestType euler_test; User user = *(User *)ctx; StabilizationType stab; - MPI_Comm comm = PETSC_COMM_WORLD; + MPI_Comm comm = user->comm; + Ceed ceed = user->ceed; PetscBool implicit; PetscBool has_curr_time = PETSC_TRUE; PetscBool has_neumann = PETSC_TRUE; @@ -140,24 +141,26 @@ PetscErrorCode NS_EULER_VORTEX(ProblemData *problem, DM dm, void *ctx, SimpleBC euler_ctx->mean_velocity[2] = mean_velocity[2]; euler_ctx->stabilization = stab; - CeedQFunctionContextCreate(user->ceed, &euler_context); - CeedQFunctionContextSetData(euler_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*euler_ctx), euler_ctx); - CeedQFunctionContextSetDataDestroy(euler_context, CEED_MEM_HOST, FreeContextPetsc); - CeedQFunctionContextRegisterDouble(euler_context, "solution time", offsetof(struct EulerContext_, curr_time), 1, "Physical time of the solution"); - CeedQFunctionContextReferenceCopy(euler_context, &problem->ics.qfunction_context); - CeedQFunctionContextReferenceCopy(euler_context, &problem->apply_vol_rhs.qfunction_context); - CeedQFunctionContextReferenceCopy(euler_context, &problem->apply_vol_ifunction.qfunction_context); - CeedQFunctionContextReferenceCopy(euler_context, &problem->apply_inflow.qfunction_context); - CeedQFunctionContextReferenceCopy(euler_context, &problem->apply_outflow.qfunction_context); + PetscCallCeed(ceed, CeedQFunctionContextCreate(user->ceed, &euler_context)); + PetscCallCeed(ceed, CeedQFunctionContextSetData(euler_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*euler_ctx), euler_ctx)); + PetscCallCeed(ceed, CeedQFunctionContextSetDataDestroy(euler_context, CEED_MEM_HOST, FreeContextPetsc)); + PetscCallCeed(ceed, CeedQFunctionContextRegisterDouble(euler_context, "solution time", offsetof(struct EulerContext_, curr_time), 1, + "Physical time of the solution")); + PetscCallCeed(ceed, CeedQFunctionContextReferenceCopy(euler_context, &problem->ics.qfunction_context)); + PetscCallCeed(ceed, CeedQFunctionContextReferenceCopy(euler_context, &problem->apply_vol_rhs.qfunction_context)); + PetscCallCeed(ceed, CeedQFunctionContextReferenceCopy(euler_context, &problem->apply_vol_ifunction.qfunction_context)); + PetscCallCeed(ceed, CeedQFunctionContextReferenceCopy(euler_context, &problem->apply_inflow.qfunction_context)); + PetscCallCeed(ceed, CeedQFunctionContextReferenceCopy(euler_context, &problem->apply_outflow.qfunction_context)); PetscFunctionReturn(PETSC_SUCCESS); } -PetscErrorCode PRINT_EULER_VORTEX(ProblemData *problem, AppCtx app_ctx) { - MPI_Comm comm = PETSC_COMM_WORLD; +PetscErrorCode PRINT_EULER_VORTEX(User user, ProblemData *problem, AppCtx app_ctx) { + MPI_Comm comm = user->comm; + Ceed ceed = user->ceed; EulerContext euler_ctx; PetscFunctionBeginUser; - CeedQFunctionContextGetData(problem->ics.qfunction_context, CEED_MEM_HOST, &euler_ctx); + PetscCallCeed(ceed, CeedQFunctionContextGetData(problem->ics.qfunction_context, CEED_MEM_HOST, &euler_ctx)); PetscCall(PetscPrintf(comm, " Problem:\n" " Problem Name : %s\n" @@ -167,6 +170,6 @@ PetscErrorCode PRINT_EULER_VORTEX(ProblemData *problem, AppCtx app_ctx) { app_ctx->problem_name, EulerTestTypes[euler_ctx->euler_test], euler_ctx->mean_velocity[0], euler_ctx->mean_velocity[1], euler_ctx->mean_velocity[2], StabilizationTypes[euler_ctx->stabilization])); - CeedQFunctionContextRestoreData(problem->ics.qfunction_context, &euler_ctx); + PetscCallCeed(ceed, CeedQFunctionContextRestoreData(problem->ics.qfunction_context, &euler_ctx)); PetscFunctionReturn(PETSC_SUCCESS); } diff --git a/examples/fluids/problems/freestream_bc.c b/examples/fluids/problems/freestream_bc.c index d19d5189aa..1bf357fe3c 100644 --- a/examples/fluids/problems/freestream_bc.c +++ b/examples/fluids/problems/freestream_bc.c @@ -21,6 +21,7 @@ static const char *const RiemannSolverTypes[] = {"hll", "hllc", "RiemannSolverTy PetscErrorCode FreestreamBCSetup(ProblemData *problem, DM dm, void *ctx, NewtonianIdealGasContext newtonian_ig_ctx, const StatePrimitive *reference) { User user = *(User *)ctx; MPI_Comm comm = user->comm; + Ceed ceed = user->ceed; FreestreamContext freestream_ctx; CeedQFunctionContext freestream_context; RiemannFluxType riemann = RIEMANN_HLLC; @@ -93,11 +94,11 @@ PetscErrorCode FreestreamBCSetup(ProblemData *problem, DM dm, void *ctx, Newtoni freestream_ctx->newtonian_ctx = *newtonian_ig_ctx; freestream_ctx->S_infty = S_infty; - CeedQFunctionContextCreate(user->ceed, &freestream_context); - CeedQFunctionContextSetData(freestream_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*freestream_ctx), freestream_ctx); - CeedQFunctionContextSetDataDestroy(freestream_context, CEED_MEM_HOST, FreeContextPetsc); + PetscCallCeed(ceed, CeedQFunctionContextCreate(user->ceed, &freestream_context)); + PetscCallCeed(ceed, CeedQFunctionContextSetData(freestream_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*freestream_ctx), freestream_ctx)); + PetscCallCeed(ceed, CeedQFunctionContextSetDataDestroy(freestream_context, CEED_MEM_HOST, FreeContextPetsc)); problem->apply_freestream.qfunction_context = freestream_context; - CeedQFunctionContextReferenceCopy(freestream_context, &problem->apply_freestream_jacobian.qfunction_context); + PetscCallCeed(ceed, CeedQFunctionContextReferenceCopy(freestream_context, &problem->apply_freestream_jacobian.qfunction_context)); PetscFunctionReturn(PETSC_SUCCESS); } @@ -109,6 +110,7 @@ typedef enum { PetscErrorCode OutflowBCSetup(ProblemData *problem, DM dm, void *ctx, NewtonianIdealGasContext newtonian_ig_ctx, const StatePrimitive *reference) { User user = *(User *)ctx; + Ceed ceed = user->ceed; OutflowContext outflow_ctx; OutflowType outflow_type = OUTFLOW_RIEMANN; CeedQFunctionContext outflow_context; @@ -175,10 +177,10 @@ PetscErrorCode OutflowBCSetup(ProblemData *problem, DM dm, void *ctx, NewtonianI outflow_ctx->pressure = pressure; outflow_ctx->temperature = temperature; - CeedQFunctionContextCreate(user->ceed, &outflow_context); - CeedQFunctionContextSetData(outflow_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*outflow_ctx), outflow_ctx); - CeedQFunctionContextSetDataDestroy(outflow_context, CEED_MEM_HOST, FreeContextPetsc); + PetscCallCeed(ceed, CeedQFunctionContextCreate(user->ceed, &outflow_context)); + PetscCallCeed(ceed, CeedQFunctionContextSetData(outflow_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*outflow_ctx), outflow_ctx)); + PetscCallCeed(ceed, CeedQFunctionContextSetDataDestroy(outflow_context, CEED_MEM_HOST, FreeContextPetsc)); problem->apply_outflow.qfunction_context = outflow_context; - CeedQFunctionContextReferenceCopy(outflow_context, &problem->apply_outflow_jacobian.qfunction_context); + PetscCallCeed(ceed, CeedQFunctionContextReferenceCopy(outflow_context, &problem->apply_outflow_jacobian.qfunction_context)); PetscFunctionReturn(PETSC_SUCCESS); } diff --git a/examples/fluids/problems/gaussianwave.c b/examples/fluids/problems/gaussianwave.c index 9c364a22f6..f4aca72b8d 100644 --- a/examples/fluids/problems/gaussianwave.c +++ b/examples/fluids/problems/gaussianwave.c @@ -18,7 +18,8 @@ PetscErrorCode NS_GAUSSIAN_WAVE(ProblemData *problem, DM dm, void *ctx, SimpleBC bc) { User user = *(User *)ctx; - MPI_Comm comm = PETSC_COMM_WORLD; + MPI_Comm comm = user->comm; + Ceed ceed = user->ceed; GaussianWaveContext gausswave_ctx; FreestreamContext freestream_ctx; NewtonianIdealGasContext newtonian_ig_ctx; @@ -56,8 +57,8 @@ PetscErrorCode NS_GAUSSIAN_WAVE(ProblemData *problem, DM dm, void *ctx, SimpleBC // -- Set gausswave_ctx struct values PetscCall(PetscCalloc1(1, &gausswave_ctx)); - CeedQFunctionContextGetData(problem->apply_vol_rhs.qfunction_context, CEED_MEM_HOST, &newtonian_ig_ctx); - CeedQFunctionContextGetData(problem->apply_freestream.qfunction_context, CEED_MEM_HOST, &freestream_ctx); + PetscCallCeed(ceed, CeedQFunctionContextGetData(problem->apply_vol_rhs.qfunction_context, CEED_MEM_HOST, &newtonian_ig_ctx)); + PetscCallCeed(ceed, CeedQFunctionContextGetData(problem->apply_freestream.qfunction_context, CEED_MEM_HOST, &freestream_ctx)); gausswave_ctx->amplitude = amplitude; gausswave_ctx->width = width; @@ -65,13 +66,13 @@ PetscErrorCode NS_GAUSSIAN_WAVE(ProblemData *problem, DM dm, void *ctx, SimpleBC gausswave_ctx->newt_ctx = *newtonian_ig_ctx; PetscCall(PetscArraycpy(gausswave_ctx->epicenter, epicenter, 3)); - CeedQFunctionContextRestoreData(problem->apply_vol_rhs.qfunction_context, &newtonian_ig_ctx); - CeedQFunctionContextRestoreData(problem->apply_freestream.qfunction_context, &freestream_ctx); + PetscCallCeed(ceed, CeedQFunctionContextRestoreData(problem->apply_vol_rhs.qfunction_context, &newtonian_ig_ctx)); + PetscCallCeed(ceed, CeedQFunctionContextRestoreData(problem->apply_freestream.qfunction_context, &freestream_ctx)); - CeedQFunctionContextCreate(user->ceed, &gausswave_context); - CeedQFunctionContextSetData(gausswave_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*gausswave_ctx), gausswave_ctx); - CeedQFunctionContextSetDataDestroy(gausswave_context, CEED_MEM_HOST, FreeContextPetsc); - CeedQFunctionContextDestroy(&problem->ics.qfunction_context); + PetscCallCeed(ceed, CeedQFunctionContextCreate(user->ceed, &gausswave_context)); + PetscCallCeed(ceed, CeedQFunctionContextSetData(gausswave_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*gausswave_ctx), gausswave_ctx)); + PetscCallCeed(ceed, CeedQFunctionContextSetDataDestroy(gausswave_context, CEED_MEM_HOST, FreeContextPetsc)); + PetscCallCeed(ceed, CeedQFunctionContextDestroy(&problem->ics.qfunction_context)); problem->ics.qfunction_context = gausswave_context; PetscFunctionReturn(PETSC_SUCCESS); diff --git a/examples/fluids/problems/newtonian.c b/examples/fluids/problems/newtonian.c index 92379df3d0..12d1fb8499 100644 --- a/examples/fluids/problems/newtonian.c +++ b/examples/fluids/problems/newtonian.c @@ -70,7 +70,8 @@ PetscErrorCode NS_NEWTONIAN_IG(ProblemData *problem, DM dm, void *ctx, SimpleBC CeedInt degree = user->app_ctx->degree; StabilizationType stab; StateVariable state_var; - MPI_Comm comm = PETSC_COMM_WORLD; + MPI_Comm comm = user->comm; + Ceed ceed = user->ceed; PetscBool implicit; PetscBool has_curr_time = PETSC_FALSE, unit_tests; NewtonianIdealGasContext newtonian_ig_ctx; @@ -286,27 +287,30 @@ PetscErrorCode NS_NEWTONIAN_IG(ProblemData *problem, DM dm, void *ctx, SimpleBC if (bc->num_freestream > 0) PetscCall(FreestreamBCSetup(problem, dm, ctx, newtonian_ig_ctx, &reference)); if (bc->num_outflow > 0) PetscCall(OutflowBCSetup(problem, dm, ctx, newtonian_ig_ctx, &reference)); - CeedQFunctionContextCreate(user->ceed, &problem->ics.qfunction_context); - CeedQFunctionContextSetData(problem->ics.qfunction_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*setup_context), setup_context); - CeedQFunctionContextSetDataDestroy(problem->ics.qfunction_context, CEED_MEM_HOST, FreeContextPetsc); - CeedQFunctionContextRegisterDouble(problem->ics.qfunction_context, "evaluation time", offsetof(struct SetupContext_, time), 1, - "Time of evaluation"); - - CeedQFunctionContextCreate(user->ceed, &newtonian_ig_context); - CeedQFunctionContextSetData(newtonian_ig_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*newtonian_ig_ctx), newtonian_ig_ctx); - CeedQFunctionContextSetDataDestroy(newtonian_ig_context, CEED_MEM_HOST, FreeContextPetsc); - CeedQFunctionContextRegisterDouble(newtonian_ig_context, "timestep size", offsetof(struct NewtonianIdealGasContext_, dt), 1, - "Size of timestep, delta t"); - CeedQFunctionContextRegisterDouble(newtonian_ig_context, "ijacobian time shift", offsetof(struct NewtonianIdealGasContext_, ijacobian_time_shift), - 1, "Shift for mass matrix in IJacobian"); - CeedQFunctionContextRegisterDouble(newtonian_ig_context, "solution time", offsetof(struct NewtonianIdealGasContext_, time), 1, - "Current solution time"); + PetscCallCeed(ceed, CeedQFunctionContextCreate(user->ceed, &problem->ics.qfunction_context)); + PetscCallCeed(ceed, + CeedQFunctionContextSetData(problem->ics.qfunction_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*setup_context), setup_context)); + PetscCallCeed(ceed, CeedQFunctionContextSetDataDestroy(problem->ics.qfunction_context, CEED_MEM_HOST, FreeContextPetsc)); + PetscCallCeed(ceed, CeedQFunctionContextRegisterDouble(problem->ics.qfunction_context, "evaluation time", offsetof(struct SetupContext_, time), 1, + "Time of evaluation")); + + PetscCallCeed(ceed, CeedQFunctionContextCreate(user->ceed, &newtonian_ig_context)); + PetscCallCeed(ceed, + CeedQFunctionContextSetData(newtonian_ig_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*newtonian_ig_ctx), newtonian_ig_ctx)); + PetscCallCeed(ceed, CeedQFunctionContextSetDataDestroy(newtonian_ig_context, CEED_MEM_HOST, FreeContextPetsc)); + PetscCallCeed(ceed, CeedQFunctionContextRegisterDouble(newtonian_ig_context, "timestep size", offsetof(struct NewtonianIdealGasContext_, dt), 1, + "Size of timestep, delta t")); + PetscCallCeed(ceed, CeedQFunctionContextRegisterDouble(newtonian_ig_context, "ijacobian time shift", + offsetof(struct NewtonianIdealGasContext_, ijacobian_time_shift), 1, + "Shift for mass matrix in IJacobian")); + PetscCallCeed(ceed, CeedQFunctionContextRegisterDouble(newtonian_ig_context, "solution time", offsetof(struct NewtonianIdealGasContext_, time), 1, + "Current solution time")); problem->apply_vol_rhs.qfunction_context = newtonian_ig_context; - CeedQFunctionContextReferenceCopy(newtonian_ig_context, &problem->apply_vol_ifunction.qfunction_context); - CeedQFunctionContextReferenceCopy(newtonian_ig_context, &problem->apply_vol_ijacobian.qfunction_context); - CeedQFunctionContextReferenceCopy(newtonian_ig_context, &problem->apply_inflow.qfunction_context); - CeedQFunctionContextReferenceCopy(newtonian_ig_context, &problem->apply_inflow_jacobian.qfunction_context); + PetscCallCeed(ceed, CeedQFunctionContextReferenceCopy(newtonian_ig_context, &problem->apply_vol_ifunction.qfunction_context)); + PetscCallCeed(ceed, CeedQFunctionContextReferenceCopy(newtonian_ig_context, &problem->apply_vol_ijacobian.qfunction_context)); + PetscCallCeed(ceed, CeedQFunctionContextReferenceCopy(newtonian_ig_context, &problem->apply_inflow.qfunction_context)); + PetscCallCeed(ceed, CeedQFunctionContextReferenceCopy(newtonian_ig_context, &problem->apply_inflow_jacobian.qfunction_context)); if (unit_tests) { PetscCall(UnitTests_Newtonian(user, newtonian_ig_ctx)); @@ -314,17 +318,18 @@ PetscErrorCode NS_NEWTONIAN_IG(ProblemData *problem, DM dm, void *ctx, SimpleBC PetscFunctionReturn(PETSC_SUCCESS); } -PetscErrorCode PRINT_NEWTONIAN(ProblemData *problem, AppCtx app_ctx) { - MPI_Comm comm = PETSC_COMM_WORLD; +PetscErrorCode PRINT_NEWTONIAN(User user, ProblemData *problem, AppCtx app_ctx) { + MPI_Comm comm = user->comm; + Ceed ceed = user->ceed; NewtonianIdealGasContext newtonian_ctx; PetscFunctionBeginUser; - CeedQFunctionContextGetData(problem->apply_vol_rhs.qfunction_context, CEED_MEM_HOST, &newtonian_ctx); + PetscCallCeed(ceed, CeedQFunctionContextGetData(problem->apply_vol_rhs.qfunction_context, CEED_MEM_HOST, &newtonian_ctx)); PetscCall(PetscPrintf(comm, " Problem:\n" " Problem Name : %s\n" " Stabilization : %s\n", app_ctx->problem_name, StabilizationTypes[newtonian_ctx->stabilization])); - CeedQFunctionContextRestoreData(problem->apply_vol_rhs.qfunction_context, &newtonian_ctx); + PetscCallCeed(ceed, CeedQFunctionContextRestoreData(problem->apply_vol_rhs.qfunction_context, &newtonian_ctx)); PetscFunctionReturn(PETSC_SUCCESS); } diff --git a/examples/fluids/problems/sgs_dd_model.c b/examples/fluids/problems/sgs_dd_model.c index 99138a98fc..f14bb75012 100644 --- a/examples/fluids/problems/sgs_dd_model.c +++ b/examples/fluids/problems/sgs_dd_model.c @@ -18,11 +18,14 @@ typedef struct { } *SGS_DD_ModelSetupData; PetscErrorCode SGS_DD_ModelSetupDataDestroy(SGS_DD_ModelSetupData sgs_dd_setup_data) { + Ceed ceed; + PetscFunctionBeginUser; - CeedElemRestrictionDestroy(&sgs_dd_setup_data->elem_restr_grid_aniso); - CeedElemRestrictionDestroy(&sgs_dd_setup_data->elem_restr_sgs); - CeedVectorDestroy(&sgs_dd_setup_data->grid_aniso_ceed); - CeedQFunctionContextDestroy(&sgs_dd_setup_data->sgsdd_qfctx); + PetscCall(CeedElemRestrictionGetCeed(sgs_dd_setup_data->elem_restr_sgs, &ceed)); + PetscCallCeed(ceed, CeedElemRestrictionDestroy(&sgs_dd_setup_data->elem_restr_grid_aniso)); + PetscCallCeed(ceed, CeedElemRestrictionDestroy(&sgs_dd_setup_data->elem_restr_sgs)); + PetscCallCeed(ceed, CeedVectorDestroy(&sgs_dd_setup_data->grid_aniso_ceed)); + PetscCallCeed(ceed, CeedQFunctionContextDestroy(&sgs_dd_setup_data->sgsdd_qfctx)); PetscCall(PetscFree(sgs_dd_setup_data)); PetscFunctionReturn(PETSC_SUCCESS); @@ -74,45 +77,49 @@ PetscErrorCode SGS_DD_ModelSetupNodalEvaluation(Ceed ceed, User user, CeedData c PetscFunctionBeginUser; PetscCall(DMGetDimension(user->dm, &dim)); - CeedElemRestrictionGetNumComponents(ceed_data->elem_restr_x, &num_comp_x); - CeedElemRestrictionGetNumComponents(ceed_data->elem_restr_q, &num_comp_q); - CeedElemRestrictionGetNumComponents(sgs_dd_setup_data->elem_restr_grid_aniso, &num_comp_grid_aniso); - CeedElemRestrictionGetNumElements(ceed_data->elem_restr_q, &num_elem); - CeedElemRestrictionGetElementSize(ceed_data->elem_restr_q, &elem_size); + PetscCallCeed(ceed, CeedElemRestrictionGetNumComponents(ceed_data->elem_restr_x, &num_comp_x)); + PetscCallCeed(ceed, CeedElemRestrictionGetNumComponents(ceed_data->elem_restr_q, &num_comp_q)); + PetscCallCeed(ceed, CeedElemRestrictionGetNumComponents(sgs_dd_setup_data->elem_restr_grid_aniso, &num_comp_grid_aniso)); + PetscCallCeed(ceed, CeedElemRestrictionGetNumElements(ceed_data->elem_restr_q, &num_elem)); + PetscCallCeed(ceed, CeedElemRestrictionGetElementSize(ceed_data->elem_restr_q, &elem_size)); { // Get velocity gradient information CeedOperatorField op_field; - CeedOperatorGetFieldByName(user->grad_velo_proj->l2_rhs_ctx->op, "velocity gradient", &op_field); - CeedOperatorFieldGetElemRestriction(op_field, &elem_restr_grad_velo); - CeedElemRestrictionGetNumComponents(elem_restr_grad_velo, &num_comp_grad_velo); + PetscCallCeed(ceed, CeedOperatorGetFieldByName(user->grad_velo_proj->l2_rhs_ctx->op, "velocity gradient", &op_field)); + PetscCallCeed(ceed, CeedOperatorFieldGetElemRestriction(op_field, &elem_restr_grad_velo)); + PetscCallCeed(ceed, CeedElemRestrictionGetNumComponents(elem_restr_grad_velo, &num_comp_grad_velo)); } PetscCall(GetRestrictionForDomain(ceed, sgs_dd_data->dm_sgs, 0, 0, 0, 0, -1, 0, &elem_restr_sgs, NULL, NULL)); - CeedElemRestrictionCreateVector(elem_restr_sgs, &sgs_dd_data->sgs_nodal_ceed, NULL); + PetscCallCeed(ceed, CeedElemRestrictionCreateVector(elem_restr_sgs, &sgs_dd_data->sgs_nodal_ceed, NULL)); // -- Create inverse multiplicity for correcting nodal assembly - CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &multiplicity, NULL); - CeedElemRestrictionGetMultiplicity(ceed_data->elem_restr_q, multiplicity); - CeedElemRestrictionCreateStrided(ceed, num_elem, elem_size, 1, num_elem * elem_size, CEED_STRIDES_BACKEND, &elem_restr_inv_multiplicity); - CeedElemRestrictionCreateVector(elem_restr_inv_multiplicity, &inv_multiplicity, NULL); + PetscCallCeed(ceed, CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &multiplicity, NULL)); + PetscCallCeed(ceed, CeedElemRestrictionGetMultiplicity(ceed_data->elem_restr_q, multiplicity)); + PetscCallCeed( + ceed, CeedElemRestrictionCreateStrided(ceed, num_elem, elem_size, 1, num_elem * elem_size, CEED_STRIDES_BACKEND, &elem_restr_inv_multiplicity)); + PetscCallCeed(ceed, CeedElemRestrictionCreateVector(elem_restr_inv_multiplicity, &inv_multiplicity, NULL)); - CeedQFunctionCreateInterior(ceed, 1, InverseMultiplicity, InverseMultiplicity_loc, &qf_multiplicity); - CeedQFunctionAddInput(qf_multiplicity, "multiplicity", num_comp_q, CEED_EVAL_NONE); - CeedQFunctionAddOutput(qf_multiplicity, "inverse multiplicity", 1, CEED_EVAL_NONE); + PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, InverseMultiplicity, InverseMultiplicity_loc, &qf_multiplicity)); + PetscCallCeed(ceed, CeedQFunctionAddInput(qf_multiplicity, "multiplicity", num_comp_q, CEED_EVAL_NONE)); + PetscCallCeed(ceed, CeedQFunctionAddOutput(qf_multiplicity, "inverse multiplicity", 1, CEED_EVAL_NONE)); - CeedOperatorCreate(ceed, qf_multiplicity, NULL, NULL, &op_multiplicity); - CeedOperatorSetName(op_multiplicity, "SGS DD Model - Create Multiplicity Scaling"); - CeedOperatorSetField(op_multiplicity, "multiplicity", ceed_data->elem_restr_q, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_multiplicity, "inverse multiplicity", elem_restr_inv_multiplicity, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); + PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_multiplicity, NULL, NULL, &op_multiplicity)); + PetscCallCeed(ceed, CeedOperatorSetName(op_multiplicity, "SGS DD Model - Create Multiplicity Scaling")); + PetscCallCeed(ceed, CeedOperatorSetField(op_multiplicity, "multiplicity", ceed_data->elem_restr_q, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE)); + PetscCallCeed( + ceed, CeedOperatorSetField(op_multiplicity, "inverse multiplicity", elem_restr_inv_multiplicity, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE)); - CeedOperatorApply(op_multiplicity, multiplicity, inv_multiplicity, CEED_REQUEST_IMMEDIATE); + PetscCallCeed(ceed, CeedOperatorApply(op_multiplicity, multiplicity, inv_multiplicity, CEED_REQUEST_IMMEDIATE)); // -- Create operator for SGS DD model nodal evaluation switch (user->phys->state_var) { case STATEVAR_PRIMITIVE: - CeedQFunctionCreateInterior(ceed, 1, ComputeSGS_DDAnisotropicNodal_Prim, ComputeSGS_DDAnisotropicNodal_Prim_loc, &qf_sgs_dd_nodal); + PetscCallCeed( + ceed, CeedQFunctionCreateInterior(ceed, 1, ComputeSGS_DDAnisotropicNodal_Prim, ComputeSGS_DDAnisotropicNodal_Prim_loc, &qf_sgs_dd_nodal)); break; case STATEVAR_CONSERVATIVE: - CeedQFunctionCreateInterior(ceed, 1, ComputeSGS_DDAnisotropicNodal_Conserv, ComputeSGS_DDAnisotropicNodal_Conserv_loc, &qf_sgs_dd_nodal); + PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, ComputeSGS_DDAnisotropicNodal_Conserv, ComputeSGS_DDAnisotropicNodal_Conserv_loc, + &qf_sgs_dd_nodal)); break; default: SETERRQ(PetscObjectComm((PetscObject)user->dm), PETSC_ERR_SUP, @@ -121,38 +128,39 @@ PetscErrorCode SGS_DD_ModelSetupNodalEvaluation(Ceed ceed, User user, CeedData c // Mesh/geometry order and solution basis order may differ, therefore must interpolate CeedBasis basis_x_to_q; - PetscCall(CeedBasisCreateProjection(ceed_data->basis_x, ceed_data->basis_q, &basis_x_to_q)); - - CeedQFunctionSetContext(qf_sgs_dd_nodal, sgs_dd_setup_data->sgsdd_qfctx); - CeedQFunctionAddInput(qf_sgs_dd_nodal, "q", num_comp_q, CEED_EVAL_NONE); - CeedQFunctionAddInput(qf_sgs_dd_nodal, "x", num_comp_x, CEED_EVAL_INTERP); - CeedQFunctionAddInput(qf_sgs_dd_nodal, "gradient velocity", num_comp_grad_velo, CEED_EVAL_NONE); - CeedQFunctionAddInput(qf_sgs_dd_nodal, "anisotropy tensor", num_comp_grid_aniso, CEED_EVAL_NONE); - CeedQFunctionAddInput(qf_sgs_dd_nodal, "inverse multiplicity", 1, CEED_EVAL_NONE); - CeedQFunctionAddOutput(qf_sgs_dd_nodal, "km_sgs", sgs_dd_data->num_comp_sgs, CEED_EVAL_NONE); - - CeedOperatorCreate(ceed, qf_sgs_dd_nodal, NULL, NULL, &op_sgs_dd_nodal); - CeedOperatorSetField(op_sgs_dd_nodal, "q", ceed_data->elem_restr_q, CEED_BASIS_COLLOCATED, user->q_ceed); - CeedOperatorSetField(op_sgs_dd_nodal, "x", ceed_data->elem_restr_x, basis_x_to_q, ceed_data->x_coord); - CeedOperatorSetField(op_sgs_dd_nodal, "gradient velocity", elem_restr_grad_velo, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_sgs_dd_nodal, "anisotropy tensor", sgs_dd_setup_data->elem_restr_grid_aniso, CEED_BASIS_COLLOCATED, - sgs_dd_setup_data->grid_aniso_ceed); - CeedOperatorSetField(op_sgs_dd_nodal, "inverse multiplicity", elem_restr_inv_multiplicity, CEED_BASIS_COLLOCATED, inv_multiplicity); - CeedOperatorSetField(op_sgs_dd_nodal, "km_sgs", elem_restr_sgs, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); + PetscCallCeed(ceed, CeedBasisCreateProjection(ceed_data->basis_x, ceed_data->basis_q, &basis_x_to_q)); + + PetscCallCeed(ceed, CeedQFunctionSetContext(qf_sgs_dd_nodal, sgs_dd_setup_data->sgsdd_qfctx)); + PetscCallCeed(ceed, CeedQFunctionAddInput(qf_sgs_dd_nodal, "q", num_comp_q, CEED_EVAL_NONE)); + PetscCallCeed(ceed, CeedQFunctionAddInput(qf_sgs_dd_nodal, "x", num_comp_x, CEED_EVAL_INTERP)); + PetscCallCeed(ceed, CeedQFunctionAddInput(qf_sgs_dd_nodal, "gradient velocity", num_comp_grad_velo, CEED_EVAL_NONE)); + PetscCallCeed(ceed, CeedQFunctionAddInput(qf_sgs_dd_nodal, "anisotropy tensor", num_comp_grid_aniso, CEED_EVAL_NONE)); + PetscCallCeed(ceed, CeedQFunctionAddInput(qf_sgs_dd_nodal, "inverse multiplicity", 1, CEED_EVAL_NONE)); + PetscCallCeed(ceed, CeedQFunctionAddOutput(qf_sgs_dd_nodal, "km_sgs", sgs_dd_data->num_comp_sgs, CEED_EVAL_NONE)); + + PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_sgs_dd_nodal, NULL, NULL, &op_sgs_dd_nodal)); + PetscCallCeed(ceed, CeedOperatorSetField(op_sgs_dd_nodal, "q", ceed_data->elem_restr_q, CEED_BASIS_COLLOCATED, user->q_ceed)); + PetscCallCeed(ceed, CeedOperatorSetField(op_sgs_dd_nodal, "x", ceed_data->elem_restr_x, basis_x_to_q, ceed_data->x_coord)); + PetscCallCeed(ceed, CeedOperatorSetField(op_sgs_dd_nodal, "gradient velocity", elem_restr_grad_velo, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorSetField(op_sgs_dd_nodal, "anisotropy tensor", sgs_dd_setup_data->elem_restr_grid_aniso, CEED_BASIS_COLLOCATED, + sgs_dd_setup_data->grid_aniso_ceed)); + PetscCallCeed(ceed, + CeedOperatorSetField(op_sgs_dd_nodal, "inverse multiplicity", elem_restr_inv_multiplicity, CEED_BASIS_COLLOCATED, inv_multiplicity)); + PetscCallCeed(ceed, CeedOperatorSetField(op_sgs_dd_nodal, "km_sgs", elem_restr_sgs, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE)); PetscCall(OperatorApplyContextCreate(user->grad_velo_proj->dm, sgs_dd_data->dm_sgs, ceed, op_sgs_dd_nodal, NULL, sgs_dd_data->sgs_nodal_ceed, NULL, NULL, &sgs_dd_data->op_nodal_evaluation_ctx)); sgs_dd_setup_data->elem_restr_sgs = elem_restr_sgs; - CeedVectorDestroy(&multiplicity); - CeedVectorDestroy(&inv_multiplicity); - CeedBasisDestroy(&basis_x_to_q); - CeedElemRestrictionDestroy(&elem_restr_inv_multiplicity); - CeedQFunctionDestroy(&qf_multiplicity); - CeedQFunctionDestroy(&qf_sgs_dd_nodal); - CeedOperatorDestroy(&op_multiplicity); - CeedOperatorDestroy(&op_sgs_dd_nodal); + PetscCallCeed(ceed, CeedVectorDestroy(&multiplicity)); + PetscCallCeed(ceed, CeedVectorDestroy(&inv_multiplicity)); + PetscCallCeed(ceed, CeedBasisDestroy(&basis_x_to_q)); + PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_inv_multiplicity)); + PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_multiplicity)); + PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_sgs_dd_nodal)); + PetscCallCeed(ceed, CeedOperatorDestroy(&op_multiplicity)); + PetscCallCeed(ceed, CeedOperatorDestroy(&op_sgs_dd_nodal)); PetscFunctionReturn(PETSC_SUCCESS); } @@ -167,42 +175,44 @@ PetscErrorCode SGS_ModelSetupNodalIFunction(Ceed ceed, User user, CeedData ceed_ PetscFunctionBeginUser; PetscCall(DMGetDimension(user->dm, &dim)); - CeedElemRestrictionGetNumComponents(ceed_data->elem_restr_q, &num_comp_q); - CeedElemRestrictionGetNumComponents(ceed_data->elem_restr_qd_i, &num_comp_qd); - CeedElemRestrictionGetNumComponents(ceed_data->elem_restr_x, &num_comp_x); + PetscCallCeed(ceed, CeedElemRestrictionGetNumComponents(ceed_data->elem_restr_q, &num_comp_q)); + PetscCallCeed(ceed, CeedElemRestrictionGetNumComponents(ceed_data->elem_restr_qd_i, &num_comp_qd)); + PetscCallCeed(ceed, CeedElemRestrictionGetNumComponents(ceed_data->elem_restr_x, &num_comp_x)); PetscCall(CreateBasisFromPlex(ceed, sgs_dd_data->dm_sgs, 0, 0, 0, 0, &basis_sgs)); switch (user->phys->state_var) { case STATEVAR_PRIMITIVE: - CeedQFunctionCreateInterior(ceed, 1, IFunction_NodalSubgridStress_Prim, IFunction_NodalSubgridStress_Prim_loc, &qf_sgs_apply); + PetscCallCeed(ceed, + CeedQFunctionCreateInterior(ceed, 1, IFunction_NodalSubgridStress_Prim, IFunction_NodalSubgridStress_Prim_loc, &qf_sgs_apply)); break; case STATEVAR_CONSERVATIVE: - CeedQFunctionCreateInterior(ceed, 1, IFunction_NodalSubgridStress_Conserv, IFunction_NodalSubgridStress_Conserv_loc, &qf_sgs_apply); + PetscCallCeed( + ceed, CeedQFunctionCreateInterior(ceed, 1, IFunction_NodalSubgridStress_Conserv, IFunction_NodalSubgridStress_Conserv_loc, &qf_sgs_apply)); break; default: SETERRQ(PetscObjectComm((PetscObject)user->dm), PETSC_ERR_SUP, "Nodal SGS evaluation not available for chosen state variable"); } - CeedQFunctionSetContext(qf_sgs_apply, sgs_dd_setup_data->sgsdd_qfctx); - CeedQFunctionAddInput(qf_sgs_apply, "q", num_comp_q, CEED_EVAL_INTERP); - CeedQFunctionAddInput(qf_sgs_apply, "qdata", num_comp_qd, CEED_EVAL_NONE); - CeedQFunctionAddInput(qf_sgs_apply, "x", num_comp_x, CEED_EVAL_INTERP); - CeedQFunctionAddInput(qf_sgs_apply, "km_sgs", sgs_dd_data->num_comp_sgs, CEED_EVAL_INTERP); - CeedQFunctionAddOutput(qf_sgs_apply, "Grad_v", num_comp_q * dim, CEED_EVAL_GRAD); + PetscCallCeed(ceed, CeedQFunctionSetContext(qf_sgs_apply, sgs_dd_setup_data->sgsdd_qfctx)); + PetscCallCeed(ceed, CeedQFunctionAddInput(qf_sgs_apply, "q", num_comp_q, CEED_EVAL_INTERP)); + PetscCallCeed(ceed, CeedQFunctionAddInput(qf_sgs_apply, "qdata", num_comp_qd, CEED_EVAL_NONE)); + PetscCallCeed(ceed, CeedQFunctionAddInput(qf_sgs_apply, "x", num_comp_x, CEED_EVAL_INTERP)); + PetscCallCeed(ceed, CeedQFunctionAddInput(qf_sgs_apply, "km_sgs", sgs_dd_data->num_comp_sgs, CEED_EVAL_INTERP)); + PetscCallCeed(ceed, CeedQFunctionAddOutput(qf_sgs_apply, "Grad_v", num_comp_q * dim, CEED_EVAL_GRAD)); - CeedOperatorCreate(ceed, qf_sgs_apply, NULL, NULL, &op_sgs_apply); - CeedOperatorSetField(op_sgs_apply, "q", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_sgs_apply, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, ceed_data->q_data); - CeedOperatorSetField(op_sgs_apply, "x", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord); - CeedOperatorSetField(op_sgs_apply, "km_sgs", sgs_dd_setup_data->elem_restr_sgs, basis_sgs, sgs_dd_data->sgs_nodal_ceed); - CeedOperatorSetField(op_sgs_apply, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE); + PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_sgs_apply, NULL, NULL, &op_sgs_apply)); + PetscCallCeed(ceed, CeedOperatorSetField(op_sgs_apply, "q", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorSetField(op_sgs_apply, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, ceed_data->q_data)); + PetscCallCeed(ceed, CeedOperatorSetField(op_sgs_apply, "x", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord)); + PetscCallCeed(ceed, CeedOperatorSetField(op_sgs_apply, "km_sgs", sgs_dd_setup_data->elem_restr_sgs, basis_sgs, sgs_dd_data->sgs_nodal_ceed)); + PetscCallCeed(ceed, CeedOperatorSetField(op_sgs_apply, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE)); PetscCall( OperatorApplyContextCreate(user->dm, user->dm, ceed, op_sgs_apply, user->q_ceed, user->g_ceed, NULL, NULL, &sgs_dd_data->op_sgs_apply_ctx)); - CeedOperatorDestroy(&op_sgs_apply); - CeedQFunctionDestroy(&qf_sgs_apply); + PetscCallCeed(ceed, CeedOperatorDestroy(&op_sgs_apply)); + PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_sgs_apply)); PetscFunctionReturn(PETSC_SUCCESS); } @@ -332,12 +342,13 @@ PetscErrorCode SGS_DD_ModelSetup(Ceed ceed, User user, CeedData ceed_data, Probl PetscCall(PetscNew(&sgs_dd_setup_data)); - CeedQFunctionContextGetDataRead(problem->apply_vol_ifunction.qfunction_context, CEED_MEM_HOST, &gas); + PetscCallCeed(ceed, CeedQFunctionContextGetDataRead(problem->apply_vol_ifunction.qfunction_context, CEED_MEM_HOST, &gas)); sgsdd_ctx->gas = *gas; - CeedQFunctionContextRestoreDataRead(problem->apply_vol_ifunction.qfunction_context, &gas); - CeedQFunctionContextCreate(user->ceed, &sgs_dd_setup_data->sgsdd_qfctx); - CeedQFunctionContextSetData(sgs_dd_setup_data->sgsdd_qfctx, CEED_MEM_HOST, CEED_USE_POINTER, sgsdd_ctx->total_bytes, sgsdd_ctx); - CeedQFunctionContextSetDataDestroy(sgs_dd_setup_data->sgsdd_qfctx, CEED_MEM_HOST, FreeContextPetsc); + PetscCallCeed(ceed, CeedQFunctionContextRestoreDataRead(problem->apply_vol_ifunction.qfunction_context, &gas)); + PetscCallCeed(ceed, CeedQFunctionContextCreate(user->ceed, &sgs_dd_setup_data->sgsdd_qfctx)); + PetscCallCeed(ceed, + CeedQFunctionContextSetData(sgs_dd_setup_data->sgsdd_qfctx, CEED_MEM_HOST, CEED_USE_POINTER, sgsdd_ctx->total_bytes, sgsdd_ctx)); + PetscCallCeed(ceed, CeedQFunctionContextSetDataDestroy(sgs_dd_setup_data->sgsdd_qfctx, CEED_MEM_HOST, FreeContextPetsc)); // -- Compute and store anisotropy tensor PetscCall(GridAnisotropyTensorProjectionSetupApply(ceed, user, ceed_data, &sgs_dd_setup_data->elem_restr_grid_aniso, @@ -356,8 +367,9 @@ PetscErrorCode SGS_DD_ModelSetup(Ceed ceed, User user, CeedData ceed_data, Probl PetscErrorCode SGS_DD_DataDestroy(SGS_DD_Data sgs_dd_data) { PetscFunctionBeginUser; if (!sgs_dd_data) PetscFunctionReturn(PETSC_SUCCESS); + Ceed ceed = sgs_dd_data->op_sgs_apply_ctx->ceed; - CeedVectorDestroy(&sgs_dd_data->sgs_nodal_ceed); + PetscCallCeed(ceed, CeedVectorDestroy(&sgs_dd_data->sgs_nodal_ceed)); PetscCall(OperatorApplyContextDestroy(sgs_dd_data->op_nodal_evaluation_ctx)); PetscCall(DMDestroy(&sgs_dd_data->dm_sgs)); PetscCall(PetscFree(sgs_dd_data)); diff --git a/examples/fluids/problems/shocktube.c b/examples/fluids/problems/shocktube.c index 974f281b67..21c45310f0 100644 --- a/examples/fluids/problems/shocktube.c +++ b/examples/fluids/problems/shocktube.c @@ -19,7 +19,8 @@ PetscErrorCode NS_SHOCKTUBE(ProblemData *problem, DM dm, void *ctx, SimpleBC bc) { SetupContextShock setup_context; User user = *(User *)ctx; - MPI_Comm comm = PETSC_COMM_WORLD; + MPI_Comm comm = user->comm; + Ceed ceed = user->ceed; PetscBool implicit; PetscBool yzb; PetscInt stab; @@ -137,19 +138,20 @@ PetscErrorCode NS_SHOCKTUBE(ProblemData *problem, DM dm, void *ctx, SimpleBC bc) shocktube_ctx->Byzb = Byzb; shocktube_ctx->c_tau = c_tau; - CeedQFunctionContextCreate(user->ceed, &problem->ics.qfunction_context); - CeedQFunctionContextSetData(problem->ics.qfunction_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*setup_context), setup_context); - CeedQFunctionContextSetDataDestroy(problem->ics.qfunction_context, CEED_MEM_HOST, FreeContextPetsc); + PetscCallCeed(ceed, CeedQFunctionContextCreate(user->ceed, &problem->ics.qfunction_context)); + PetscCallCeed(ceed, + CeedQFunctionContextSetData(problem->ics.qfunction_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*setup_context), setup_context)); + PetscCallCeed(ceed, CeedQFunctionContextSetDataDestroy(problem->ics.qfunction_context, CEED_MEM_HOST, FreeContextPetsc)); - CeedQFunctionContextCreate(user->ceed, &shocktube_context); - CeedQFunctionContextSetData(shocktube_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*shocktube_ctx), shocktube_ctx); - CeedQFunctionContextSetDataDestroy(shocktube_context, CEED_MEM_HOST, FreeContextPetsc); + PetscCallCeed(ceed, CeedQFunctionContextCreate(user->ceed, &shocktube_context)); + PetscCallCeed(ceed, CeedQFunctionContextSetData(shocktube_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*shocktube_ctx), shocktube_ctx)); + PetscCallCeed(ceed, CeedQFunctionContextSetDataDestroy(shocktube_context, CEED_MEM_HOST, FreeContextPetsc)); problem->apply_vol_rhs.qfunction_context = shocktube_context; PetscFunctionReturn(PETSC_SUCCESS); } -PetscErrorCode PRINT_SHOCKTUBE(ProblemData *problem, AppCtx app_ctx) { - MPI_Comm comm = PETSC_COMM_WORLD; +PetscErrorCode PRINT_SHOCKTUBE(User user, ProblemData *problem, AppCtx app_ctx) { + MPI_Comm comm = user->comm; PetscFunctionBeginUser; PetscCall(PetscPrintf(comm, diff --git a/examples/fluids/problems/stg_shur14.c b/examples/fluids/problems/stg_shur14.c index 06f26dd2a4..93a6b9344c 100644 --- a/examples/fluids/problems/stg_shur14.c +++ b/examples/fluids/problems/stg_shur14.c @@ -228,6 +228,7 @@ PetscErrorCode GetSTGContextData(const MPI_Comm comm, const DM dm, char stg_infl PetscErrorCode SetupSTG(const MPI_Comm comm, const DM dm, ProblemData *problem, User user, const bool prescribe_T, const CeedScalar theta0, const CeedScalar P0, const CeedScalar ynodes[], const CeedInt nynodes) { + Ceed ceed = user->ceed; char stg_inflow_path[PETSC_MAX_PATH_LEN] = "./STGInflow.dat"; char stg_rand_path[PETSC_MAX_PATH_LEN] = "./STGRand.dat"; PetscBool mean_only = PETSC_FALSE, use_stgstrong = PETSC_FALSE, use_fluctuating_IC = PETSC_FALSE; @@ -271,18 +272,19 @@ PetscErrorCode SetupSTG(const MPI_Comm comm, const DM dm, ProblemData *problem, global_stg_ctx->dz = domain_size[2] / faces[2]; } - CeedQFunctionContextGetData(problem->apply_vol_rhs.qfunction_context, CEED_MEM_HOST, &newtonian_ig_ctx); + PetscCallCeed(ceed, CeedQFunctionContextGetData(problem->apply_vol_rhs.qfunction_context, CEED_MEM_HOST, &newtonian_ig_ctx)); global_stg_ctx->newtonian_ctx = *newtonian_ig_ctx; - CeedQFunctionContextRestoreData(problem->apply_vol_rhs.qfunction_context, &newtonian_ig_ctx); + PetscCallCeed(ceed, CeedQFunctionContextRestoreData(problem->apply_vol_rhs.qfunction_context, &newtonian_ig_ctx)); PetscCall(GetSTGContextData(comm, dm, stg_inflow_path, stg_rand_path, &global_stg_ctx, ynodes)); - CeedQFunctionContextCreate(user->ceed, &stg_context); - CeedQFunctionContextSetData(stg_context, CEED_MEM_HOST, CEED_USE_POINTER, global_stg_ctx->total_bytes, global_stg_ctx); - CeedQFunctionContextSetDataDestroy(stg_context, CEED_MEM_HOST, FreeContextPetsc); - CeedQFunctionContextRegisterDouble(stg_context, "solution time", offsetof(struct STGShur14Context_, time), 1, "Physical time of the solution"); + PetscCallCeed(ceed, CeedQFunctionContextCreate(user->ceed, &stg_context)); + PetscCallCeed(ceed, CeedQFunctionContextSetData(stg_context, CEED_MEM_HOST, CEED_USE_POINTER, global_stg_ctx->total_bytes, global_stg_ctx)); + PetscCallCeed(ceed, CeedQFunctionContextSetDataDestroy(stg_context, CEED_MEM_HOST, FreeContextPetsc)); + PetscCallCeed(ceed, CeedQFunctionContextRegisterDouble(stg_context, "solution time", offsetof(struct STGShur14Context_, time), 1, + "Physical time of the solution")); - CeedQFunctionContextDestroy(&problem->ics.qfunction_context); + PetscCallCeed(ceed, CeedQFunctionContextDestroy(&problem->ics.qfunction_context)); problem->ics.qfunction = ICsSTG; problem->ics.qfunction_loc = ICsSTG_loc; problem->ics.qfunction_context = stg_context; @@ -296,8 +298,8 @@ PetscErrorCode SetupSTG(const MPI_Comm comm, const DM dm, ProblemData *problem, problem->apply_inflow.qfunction_loc = STGShur14_Inflow_loc; problem->apply_inflow_jacobian.qfunction = STGShur14_Inflow_Jacobian; problem->apply_inflow_jacobian.qfunction_loc = STGShur14_Inflow_Jacobian_loc; - CeedQFunctionContextReferenceCopy(stg_context, &problem->apply_inflow.qfunction_context); - CeedQFunctionContextReferenceCopy(stg_context, &problem->apply_inflow_jacobian.qfunction_context); + PetscCallCeed(ceed, CeedQFunctionContextReferenceCopy(stg_context, &problem->apply_inflow.qfunction_context)); + PetscCallCeed(ceed, CeedQFunctionContextReferenceCopy(stg_context, &problem->apply_inflow_jacobian.qfunction_context)); problem->bc_from_ics = PETSC_TRUE; } @@ -386,25 +388,25 @@ PetscErrorCode SetupStrongSTG(DM dm, SimpleBC bc, ProblemData *problem, Physics PetscErrorCode SetupStrongSTG_QF(Ceed ceed, ProblemData *problem, CeedInt num_comp_x, CeedInt num_comp_q, CeedInt stg_data_size, CeedInt q_data_size_sur, CeedQFunction *qf_strongbc) { PetscFunctionBeginUser; - CeedQFunctionCreateInterior(ceed, 1, STGShur14_Inflow_StrongQF, STGShur14_Inflow_StrongQF_loc, qf_strongbc); - CeedQFunctionAddInput(*qf_strongbc, "surface qdata", q_data_size_sur, CEED_EVAL_NONE); - CeedQFunctionAddInput(*qf_strongbc, "x", num_comp_x, CEED_EVAL_NONE); - CeedQFunctionAddInput(*qf_strongbc, "scale", 1, CEED_EVAL_NONE); - CeedQFunctionAddInput(*qf_strongbc, "stg data", stg_data_size, CEED_EVAL_NONE); - CeedQFunctionAddOutput(*qf_strongbc, "q", num_comp_q, CEED_EVAL_NONE); - - CeedQFunctionSetContext(*qf_strongbc, problem->ics.qfunction_context); + PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, STGShur14_Inflow_StrongQF, STGShur14_Inflow_StrongQF_loc, qf_strongbc)); + PetscCallCeed(ceed, CeedQFunctionAddInput(*qf_strongbc, "surface qdata", q_data_size_sur, CEED_EVAL_NONE)); + PetscCallCeed(ceed, CeedQFunctionAddInput(*qf_strongbc, "x", num_comp_x, CEED_EVAL_NONE)); + PetscCallCeed(ceed, CeedQFunctionAddInput(*qf_strongbc, "scale", 1, CEED_EVAL_NONE)); + PetscCallCeed(ceed, CeedQFunctionAddInput(*qf_strongbc, "stg data", stg_data_size, CEED_EVAL_NONE)); + PetscCallCeed(ceed, CeedQFunctionAddOutput(*qf_strongbc, "q", num_comp_q, CEED_EVAL_NONE)); + + PetscCallCeed(ceed, CeedQFunctionSetContext(*qf_strongbc, problem->ics.qfunction_context)); PetscFunctionReturn(PETSC_SUCCESS); } PetscErrorCode SetupStrongSTG_PreProcessing(Ceed ceed, ProblemData *problem, CeedInt num_comp_x, CeedInt stg_data_size, CeedInt q_data_size_sur, CeedQFunction *qf_strongbc) { PetscFunctionBeginUser; - CeedQFunctionCreateInterior(ceed, 1, Preprocess_STGShur14, Preprocess_STGShur14_loc, qf_strongbc); - CeedQFunctionAddInput(*qf_strongbc, "surface qdata", q_data_size_sur, CEED_EVAL_NONE); - CeedQFunctionAddInput(*qf_strongbc, "x", num_comp_x, CEED_EVAL_NONE); - CeedQFunctionAddOutput(*qf_strongbc, "stg data", stg_data_size, CEED_EVAL_NONE); + PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, Preprocess_STGShur14, Preprocess_STGShur14_loc, qf_strongbc)); + PetscCallCeed(ceed, CeedQFunctionAddInput(*qf_strongbc, "surface qdata", q_data_size_sur, CEED_EVAL_NONE)); + PetscCallCeed(ceed, CeedQFunctionAddInput(*qf_strongbc, "x", num_comp_x, CEED_EVAL_NONE)); + PetscCallCeed(ceed, CeedQFunctionAddOutput(*qf_strongbc, "stg data", stg_data_size, CEED_EVAL_NONE)); - CeedQFunctionSetContext(*qf_strongbc, problem->ics.qfunction_context); + PetscCallCeed(ceed, CeedQFunctionSetContext(*qf_strongbc, problem->ics.qfunction_context)); PetscFunctionReturn(PETSC_SUCCESS); } diff --git a/examples/fluids/src/differential_filter.c b/examples/fluids/src/differential_filter.c index 114dbc72b5..f49c758f4d 100644 --- a/examples/fluids/src/differential_filter.c +++ b/examples/fluids/src/differential_filter.c @@ -22,42 +22,42 @@ PetscErrorCode DifferentialFilterCreateOperators(Ceed ceed, User user, CeedData PetscFunctionBeginUser; PetscCall(DMGetDimension(user->dm, &dim)); - CeedElemRestrictionGetNumComponents(ceed_data->elem_restr_x, &num_comp_x); - CeedElemRestrictionGetNumComponents(ceed_data->elem_restr_q, &num_comp_q); - CeedElemRestrictionGetNumComponents(ceed_data->elem_restr_qd_i, &num_comp_qd); + PetscCallCeed(ceed, CeedElemRestrictionGetNumComponents(ceed_data->elem_restr_x, &num_comp_x)); + PetscCallCeed(ceed, CeedElemRestrictionGetNumComponents(ceed_data->elem_restr_q, &num_comp_q)); + PetscCallCeed(ceed, CeedElemRestrictionGetNumComponents(ceed_data->elem_restr_qd_i, &num_comp_qd)); { // -- Create RHS MatopApplyContext CeedQFunction qf_rhs; CeedOperator op_rhs; switch (user->phys->state_var) { case STATEVAR_PRIMITIVE: - CeedQFunctionCreateInterior(ceed, 1, DifferentialFilter_RHS_Prim, DifferentialFilter_RHS_Prim_loc, &qf_rhs); + PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, DifferentialFilter_RHS_Prim, DifferentialFilter_RHS_Prim_loc, &qf_rhs)); break; case STATEVAR_CONSERVATIVE: - CeedQFunctionCreateInterior(ceed, 1, DifferentialFilter_RHS_Conserv, DifferentialFilter_RHS_Conserv_loc, &qf_rhs); + PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, DifferentialFilter_RHS_Conserv, DifferentialFilter_RHS_Conserv_loc, &qf_rhs)); break; default: SETERRQ(PetscObjectComm((PetscObject)user->dm), PETSC_ERR_SUP, "Differential filtering not available for chosen state variable"); } if (diff_filter->do_mms_test) { - CeedQFunctionDestroy(&qf_rhs); - CeedQFunctionCreateInterior(ceed, 1, DifferentialFilter_MMS_RHS, DifferentialFilter_MMS_RHS_loc, &qf_rhs); + PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_rhs)); + PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, DifferentialFilter_MMS_RHS, DifferentialFilter_MMS_RHS_loc, &qf_rhs)); } - CeedQFunctionSetContext(qf_rhs, diff_filter_qfctx); - CeedQFunctionAddInput(qf_rhs, "q", num_comp_q, CEED_EVAL_INTERP); - CeedQFunctionAddInput(qf_rhs, "qdata", num_comp_qd, CEED_EVAL_NONE); - CeedQFunctionAddInput(qf_rhs, "x", num_comp_x, CEED_EVAL_INTERP); + PetscCallCeed(ceed, CeedQFunctionSetContext(qf_rhs, diff_filter_qfctx)); + PetscCallCeed(ceed, CeedQFunctionAddInput(qf_rhs, "q", num_comp_q, CEED_EVAL_INTERP)); + PetscCallCeed(ceed, CeedQFunctionAddInput(qf_rhs, "qdata", num_comp_qd, CEED_EVAL_NONE)); + PetscCallCeed(ceed, CeedQFunctionAddInput(qf_rhs, "x", num_comp_x, CEED_EVAL_INTERP)); for (PetscInt i = 0; i < diff_filter->num_filtered_fields; i++) { char field_name[PETSC_MAX_PATH_LEN]; PetscCall(PetscSNPrintf(field_name, PETSC_MAX_PATH_LEN, "v%" PetscInt_FMT, i)); - CeedQFunctionAddOutput(qf_rhs, field_name, diff_filter->num_field_components[i], CEED_EVAL_INTERP); + PetscCallCeed(ceed, CeedQFunctionAddOutput(qf_rhs, field_name, diff_filter->num_field_components[i], CEED_EVAL_INTERP)); } - CeedOperatorCreate(ceed, qf_rhs, NULL, NULL, &op_rhs); - CeedOperatorSetField(op_rhs, "q", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_rhs, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, ceed_data->q_data); - CeedOperatorSetField(op_rhs, "x", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord); + PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_rhs, NULL, NULL, &op_rhs)); + PetscCallCeed(ceed, CeedOperatorSetField(op_rhs, "q", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorSetField(op_rhs, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, ceed_data->q_data)); + PetscCallCeed(ceed, CeedOperatorSetField(op_rhs, "x", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord)); for (PetscInt i = 0; i < diff_filter->num_filtered_fields; i++) { char field_name[PETSC_MAX_PATH_LEN]; CeedElemRestriction elem_restr_filter; @@ -66,13 +66,13 @@ PetscErrorCode DifferentialFilterCreateOperators(Ceed ceed, User user, CeedData PetscCall(CreateBasisFromPlex(ceed, dm_filter, 0, 0, 0, i, &basis_filter)); PetscCall(PetscSNPrintf(field_name, PETSC_MAX_PATH_LEN, "v%" PetscInt_FMT, i)); - CeedOperatorSetField(op_rhs, field_name, elem_restr_filter, basis_filter, CEED_VECTOR_ACTIVE); + PetscCallCeed(ceed, CeedOperatorSetField(op_rhs, field_name, elem_restr_filter, basis_filter, CEED_VECTOR_ACTIVE)); } PetscCall(OperatorApplyContextCreate(user->dm, dm_filter, ceed, op_rhs, NULL, NULL, user->Q_loc, NULL, &diff_filter->op_rhs_ctx)); - CeedQFunctionDestroy(&qf_rhs); - CeedOperatorDestroy(&op_rhs); + PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_rhs)); + PetscCallCeed(ceed, CeedOperatorDestroy(&op_rhs)); } { // Setup LHS Operator and KSP for the differential filtering solve @@ -85,12 +85,12 @@ PetscErrorCode DifferentialFilterCreateOperators(Ceed ceed, User user, CeedData CeedVector grid_aniso_ceed; PetscCall(DMGetDimension(user->dm, &dim)); - CeedElemRestrictionGetNumComponents(ceed_data->elem_restr_qd_i, &num_comp_qd); + PetscCallCeed(ceed, CeedElemRestrictionGetNumComponents(ceed_data->elem_restr_qd_i, &num_comp_qd)); // -- Get Grid anisotropy tensor PetscCall(GridAnisotropyTensorCalculateCollocatedVector(ceed, user, ceed_data, &elem_restr_grid_aniso, &grid_aniso_ceed, &num_comp_grid_aniso)); - CeedCompositeOperatorCreate(ceed, &op_lhs); + PetscCallCeed(ceed, CeedCompositeOperatorCreate(ceed, &op_lhs)); for (PetscInt i = 0; i < diff_filter->num_filtered_fields; i++) { CeedQFunction qf_lhs; PetscInt num_comp_filter = diff_filter->num_field_components[i]; @@ -100,52 +100,52 @@ PetscErrorCode DifferentialFilterCreateOperators(Ceed ceed, User user, CeedData switch (num_comp_filter) { case 1: - CeedQFunctionCreateInterior(ceed, 1, DifferentialFilter_LHS_1, DifferentialFilter_LHS_1_loc, &qf_lhs); + PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, DifferentialFilter_LHS_1, DifferentialFilter_LHS_1_loc, &qf_lhs)); break; case 5: - CeedQFunctionCreateInterior(ceed, 1, DifferentialFilter_LHS_5, DifferentialFilter_LHS_5_loc, &qf_lhs); + PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, DifferentialFilter_LHS_5, DifferentialFilter_LHS_5_loc, &qf_lhs)); break; case 6: - CeedQFunctionCreateInterior(ceed, 1, DifferentialFilter_LHS_6, DifferentialFilter_LHS_6_loc, &qf_lhs); + PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, DifferentialFilter_LHS_6, DifferentialFilter_LHS_6_loc, &qf_lhs)); break; case 11: - CeedQFunctionCreateInterior(ceed, 1, DifferentialFilter_LHS_11, DifferentialFilter_LHS_11_loc, &qf_lhs); + PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, DifferentialFilter_LHS_11, DifferentialFilter_LHS_11_loc, &qf_lhs)); break; default: SETERRQ(PetscObjectComm((PetscObject)user->dm), PETSC_ERR_SUP, "Differential filtering not available for (%" PetscInt_FMT ") components", num_comp_filter); } - CeedQFunctionSetContext(qf_lhs, diff_filter_qfctx); - CeedQFunctionAddInput(qf_lhs, "q", num_comp_filter, CEED_EVAL_INTERP); - CeedQFunctionAddInput(qf_lhs, "Grad_q", num_comp_filter * dim, CEED_EVAL_GRAD); - CeedQFunctionAddInput(qf_lhs, "anisotropy tensor", num_comp_grid_aniso, CEED_EVAL_NONE); - CeedQFunctionAddInput(qf_lhs, "x", num_comp_x, CEED_EVAL_INTERP); - CeedQFunctionAddInput(qf_lhs, "qdata", num_comp_qd, CEED_EVAL_NONE); - CeedQFunctionAddOutput(qf_lhs, "v", num_comp_filter, CEED_EVAL_INTERP); - CeedQFunctionAddOutput(qf_lhs, "Grad_v", num_comp_filter * dim, CEED_EVAL_GRAD); + PetscCallCeed(ceed, CeedQFunctionSetContext(qf_lhs, diff_filter_qfctx)); + PetscCallCeed(ceed, CeedQFunctionAddInput(qf_lhs, "q", num_comp_filter, CEED_EVAL_INTERP)); + PetscCallCeed(ceed, CeedQFunctionAddInput(qf_lhs, "Grad_q", num_comp_filter * dim, CEED_EVAL_GRAD)); + PetscCallCeed(ceed, CeedQFunctionAddInput(qf_lhs, "anisotropy tensor", num_comp_grid_aniso, CEED_EVAL_NONE)); + PetscCallCeed(ceed, CeedQFunctionAddInput(qf_lhs, "x", num_comp_x, CEED_EVAL_INTERP)); + PetscCallCeed(ceed, CeedQFunctionAddInput(qf_lhs, "qdata", num_comp_qd, CEED_EVAL_NONE)); + PetscCallCeed(ceed, CeedQFunctionAddOutput(qf_lhs, "v", num_comp_filter, CEED_EVAL_INTERP)); + PetscCallCeed(ceed, CeedQFunctionAddOutput(qf_lhs, "Grad_v", num_comp_filter * dim, CEED_EVAL_GRAD)); { CeedOperatorField op_field; char field_name[PETSC_MAX_PATH_LEN]; PetscCall(PetscSNPrintf(field_name, PETSC_MAX_PATH_LEN, "v%" PetscInt_FMT, i)); - CeedOperatorGetFieldByName(diff_filter->op_rhs_ctx->op, field_name, &op_field); - CeedOperatorFieldGetElemRestriction(op_field, &elem_restr_filter); - CeedOperatorFieldGetBasis(op_field, &basis_filter); + PetscCallCeed(ceed, CeedOperatorGetFieldByName(diff_filter->op_rhs_ctx->op, field_name, &op_field)); + PetscCallCeed(ceed, CeedOperatorFieldGetElemRestriction(op_field, &elem_restr_filter)); + PetscCallCeed(ceed, CeedOperatorFieldGetBasis(op_field, &basis_filter)); } - CeedOperatorCreate(ceed, qf_lhs, NULL, NULL, &op_lhs_sub); - CeedOperatorSetField(op_lhs_sub, "q", elem_restr_filter, basis_filter, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_lhs_sub, "Grad_q", elem_restr_filter, basis_filter, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_lhs_sub, "anisotropy tensor", elem_restr_grid_aniso, CEED_BASIS_COLLOCATED, grid_aniso_ceed); - CeedOperatorSetField(op_lhs_sub, "x", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord); - CeedOperatorSetField(op_lhs_sub, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, ceed_data->q_data); - CeedOperatorSetField(op_lhs_sub, "v", elem_restr_filter, basis_filter, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_lhs_sub, "Grad_v", elem_restr_filter, basis_filter, CEED_VECTOR_ACTIVE); - - CeedCompositeOperatorAddSub(op_lhs, op_lhs_sub); - CeedQFunctionDestroy(&qf_lhs); - CeedOperatorDestroy(&op_lhs_sub); + PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_lhs, NULL, NULL, &op_lhs_sub)); + PetscCallCeed(ceed, CeedOperatorSetField(op_lhs_sub, "q", elem_restr_filter, basis_filter, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorSetField(op_lhs_sub, "Grad_q", elem_restr_filter, basis_filter, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorSetField(op_lhs_sub, "anisotropy tensor", elem_restr_grid_aniso, CEED_BASIS_COLLOCATED, grid_aniso_ceed)); + PetscCallCeed(ceed, CeedOperatorSetField(op_lhs_sub, "x", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord)); + PetscCallCeed(ceed, CeedOperatorSetField(op_lhs_sub, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, ceed_data->q_data)); + PetscCallCeed(ceed, CeedOperatorSetField(op_lhs_sub, "v", elem_restr_filter, basis_filter, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorSetField(op_lhs_sub, "Grad_v", elem_restr_filter, basis_filter, CEED_VECTOR_ACTIVE)); + + PetscCallCeed(ceed, CeedCompositeOperatorAddSub(op_lhs, op_lhs_sub)); + PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_lhs)); + PetscCallCeed(ceed, CeedOperatorDestroy(&op_lhs_sub)); } PetscCall(OperatorApplyContextCreate(dm_filter, dm_filter, ceed, op_lhs, NULL, NULL, NULL, NULL, &mat_ctx)); PetscCall(CreateMatShell_Ceed(mat_ctx, &mat_lhs)); @@ -164,7 +164,7 @@ PetscErrorCode DifferentialFilterCreateOperators(Ceed ceed, User user, CeedData PetscCall(KSPSetOperators(diff_filter->ksp, mat_lhs, mat_lhs)); PetscCall(KSPSetFromOptions(diff_filter->ksp)); - CeedOperatorDestroy(&op_lhs); + PetscCallCeed(ceed, CeedOperatorDestroy(&op_lhs)); } PetscFunctionReturn(PETSC_SUCCESS); } @@ -266,18 +266,18 @@ PetscErrorCode DifferentialFilterSetup(Ceed ceed, User user, CeedData ceed_data, diff_filter_ctx->friction_length *= units->meter; // -- Create QFContext - CeedQFunctionContextGetDataRead(problem->apply_vol_ifunction.qfunction_context, CEED_MEM_HOST, &gas); + PetscCallCeed(ceed, CeedQFunctionContextGetDataRead(problem->apply_vol_ifunction.qfunction_context, CEED_MEM_HOST, &gas)); diff_filter_ctx->gas = *gas; - CeedQFunctionContextRestoreDataRead(problem->apply_vol_ifunction.qfunction_context, &gas); + PetscCallCeed(ceed, CeedQFunctionContextRestoreDataRead(problem->apply_vol_ifunction.qfunction_context, &gas)); - CeedQFunctionContextCreate(ceed, &diff_filter_qfctx); - CeedQFunctionContextSetData(diff_filter_qfctx, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*diff_filter_ctx), diff_filter_ctx); - CeedQFunctionContextSetDataDestroy(diff_filter_qfctx, CEED_MEM_HOST, FreeContextPetsc); + PetscCallCeed(ceed, CeedQFunctionContextCreate(ceed, &diff_filter_qfctx)); + PetscCallCeed(ceed, CeedQFunctionContextSetData(diff_filter_qfctx, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*diff_filter_ctx), diff_filter_ctx)); + PetscCallCeed(ceed, CeedQFunctionContextSetDataDestroy(diff_filter_qfctx, CEED_MEM_HOST, FreeContextPetsc)); // -- Setup Operators PetscCall(DifferentialFilterCreateOperators(ceed, user, ceed_data, diff_filter_qfctx)); - CeedQFunctionContextDestroy(&diff_filter_qfctx); + PetscCallCeed(ceed, CeedQFunctionContextDestroy(&diff_filter_qfctx)); PetscFunctionReturn(PETSC_SUCCESS); } diff --git a/examples/fluids/src/grid_anisotropy_tensor.c b/examples/fluids/src/grid_anisotropy_tensor.c index 2e19354629..dd7ffeadcb 100644 --- a/examples/fluids/src/grid_anisotropy_tensor.c +++ b/examples/fluids/src/grid_anisotropy_tensor.c @@ -56,28 +56,28 @@ PetscErrorCode GridAnisotropyTensorProjectionSetupApply(Ceed ceed, User user, Ce } // -- Get Pre-requisite things - CeedElemRestrictionGetNumComponents(ceed_data->elem_restr_qd_i, &q_data_size); + PetscCallCeed(ceed, CeedElemRestrictionGetNumComponents(ceed_data->elem_restr_qd_i, &q_data_size)); PetscCall(GetRestrictionForDomain(ceed, grid_aniso_proj->dm, 0, 0, 0, 0, -1, grid_aniso_proj->num_comp, elem_restr_grid_aniso, NULL, NULL)); PetscCall(CreateBasisFromPlex(ceed, grid_aniso_proj->dm, 0, 0, 0, 0, &basis_grid_aniso)); // -- Build RHS operator - CeedQFunctionCreateInterior(ceed, 1, AnisotropyTensorProjection, AnisotropyTensorProjection_loc, &qf_rhs_assemble); - CeedQFunctionAddInput(qf_rhs_assemble, "qdata", q_data_size, CEED_EVAL_NONE); - CeedQFunctionAddOutput(qf_rhs_assemble, "v", grid_aniso_proj->num_comp, CEED_EVAL_INTERP); + PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, AnisotropyTensorProjection, AnisotropyTensorProjection_loc, &qf_rhs_assemble)); + PetscCallCeed(ceed, CeedQFunctionAddInput(qf_rhs_assemble, "qdata", q_data_size, CEED_EVAL_NONE)); + PetscCallCeed(ceed, CeedQFunctionAddOutput(qf_rhs_assemble, "v", grid_aniso_proj->num_comp, CEED_EVAL_INTERP)); - CeedOperatorCreate(ceed, qf_rhs_assemble, NULL, NULL, &op_rhs_assemble); - CeedOperatorSetField(op_rhs_assemble, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, ceed_data->q_data); - CeedOperatorSetField(op_rhs_assemble, "v", *elem_restr_grid_aniso, basis_grid_aniso, CEED_VECTOR_ACTIVE); + PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_rhs_assemble, NULL, NULL, &op_rhs_assemble)); + PetscCallCeed(ceed, CeedOperatorSetField(op_rhs_assemble, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, ceed_data->q_data)); + PetscCallCeed(ceed, CeedOperatorSetField(op_rhs_assemble, "v", *elem_restr_grid_aniso, basis_grid_aniso, CEED_VECTOR_ACTIVE)); PetscCall(OperatorApplyContextCreate(user->dm, grid_aniso_proj->dm, ceed, op_rhs_assemble, CEED_VECTOR_NONE, NULL, NULL, NULL, &l2_rhs_ctx)); // -- Build Mass Operator PetscCall(CreateMassQFunction(ceed, grid_aniso_proj->num_comp, q_data_size, &qf_mass)); - CeedOperatorCreate(ceed, qf_mass, NULL, NULL, &op_mass); - CeedOperatorSetField(op_mass, "u", *elem_restr_grid_aniso, basis_grid_aniso, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_mass, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, ceed_data->q_data); - CeedOperatorSetField(op_mass, "v", *elem_restr_grid_aniso, basis_grid_aniso, CEED_VECTOR_ACTIVE); + PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_mass, NULL, NULL, &op_mass)); + PetscCallCeed(ceed, CeedOperatorSetField(op_mass, "u", *elem_restr_grid_aniso, basis_grid_aniso, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorSetField(op_mass, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, ceed_data->q_data)); + PetscCallCeed(ceed, CeedOperatorSetField(op_mass, "v", *elem_restr_grid_aniso, basis_grid_aniso, CEED_VECTOR_ACTIVE)); { // -- Setup KSP for L^2 projection Mat mat_mass; @@ -112,7 +112,7 @@ PetscErrorCode GridAnisotropyTensorProjectionSetupApply(Ceed ceed, User user, Ce // Copy anisotropy tensor data to CeedVector PetscCall(DMGetLocalVector(grid_aniso_proj->dm, &grid_anisotropy_loc)); - CeedElemRestrictionCreateVector(*elem_restr_grid_aniso, grid_aniso_vector, NULL); + PetscCallCeed(ceed, CeedElemRestrictionCreateVector(*elem_restr_grid_aniso, grid_aniso_vector, NULL)); PetscCall(DMGlobalToLocal(grid_aniso_proj->dm, Grid_Anisotropy, INSERT_VALUES, grid_anisotropy_loc)); PetscCall(VecCopyP2C(grid_anisotropy_loc, *grid_aniso_vector)); PetscCall(DMRestoreLocalVector(grid_aniso_proj->dm, &grid_anisotropy_loc)); @@ -123,11 +123,11 @@ PetscErrorCode GridAnisotropyTensorProjectionSetupApply(Ceed ceed, User user, Ce PetscCall(NodalProjectionDataDestroy(grid_aniso_proj)); PetscCall(OperatorApplyContextDestroy(l2_rhs_ctx)); PetscCall(OperatorApplyContextDestroy(mass_matop_ctx)); - CeedQFunctionDestroy(&qf_rhs_assemble); - CeedQFunctionDestroy(&qf_mass); - CeedBasisDestroy(&basis_grid_aniso); - CeedOperatorDestroy(&op_rhs_assemble); - CeedOperatorDestroy(&op_mass); + PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_rhs_assemble)); + PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_mass)); + PetscCallCeed(ceed, CeedBasisDestroy(&basis_grid_aniso)); + PetscCallCeed(ceed, CeedOperatorDestroy(&op_rhs_assemble)); + PetscCallCeed(ceed, CeedOperatorDestroy(&op_mass)); PetscCall(KSPDestroy(&ksp)); PetscFunctionReturn(PETSC_SUCCESS); } @@ -140,24 +140,24 @@ PetscErrorCode GridAnisotropyTensorCalculateCollocatedVector(Ceed ceed, User use PetscFunctionBeginUser; *num_comp_aniso = 7; - CeedBasisGetNumNodes(ceed_data->basis_q, &num_nodes); - CeedElemRestrictionGetNumComponents(ceed_data->elem_restr_qd_i, &q_data_size); + PetscCallCeed(ceed, CeedBasisGetNumNodes(ceed_data->basis_q, &num_nodes)); + PetscCallCeed(ceed, CeedElemRestrictionGetNumComponents(ceed_data->elem_restr_qd_i, &q_data_size)); PetscCall(GetRestrictionForDomain(ceed, user->dm, 0, 0, 0, 0, num_nodes, *num_comp_aniso, NULL, NULL, elem_restr_grid_aniso)); // -- Build collocation operator - CeedQFunctionCreateInterior(ceed, 1, AnisotropyTensorCollocate, AnisotropyTensorCollocate_loc, &qf_colloc); - CeedQFunctionAddInput(qf_colloc, "qdata", q_data_size, CEED_EVAL_NONE); - CeedQFunctionAddOutput(qf_colloc, "v", *num_comp_aniso, CEED_EVAL_NONE); + PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, AnisotropyTensorCollocate, AnisotropyTensorCollocate_loc, &qf_colloc)); + PetscCallCeed(ceed, CeedQFunctionAddInput(qf_colloc, "qdata", q_data_size, CEED_EVAL_NONE)); + PetscCallCeed(ceed, CeedQFunctionAddOutput(qf_colloc, "v", *num_comp_aniso, CEED_EVAL_NONE)); - CeedOperatorCreate(ceed, qf_colloc, NULL, NULL, &op_colloc); - CeedOperatorSetField(op_colloc, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, ceed_data->q_data); - CeedOperatorSetField(op_colloc, "v", *elem_restr_grid_aniso, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); + PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_colloc, NULL, NULL, &op_colloc)); + PetscCallCeed(ceed, CeedOperatorSetField(op_colloc, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, ceed_data->q_data)); + PetscCallCeed(ceed, CeedOperatorSetField(op_colloc, "v", *elem_restr_grid_aniso, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE)); - CeedElemRestrictionCreateVector(*elem_restr_grid_aniso, aniso_colloc_ceed, NULL); + PetscCallCeed(ceed, CeedElemRestrictionCreateVector(*elem_restr_grid_aniso, aniso_colloc_ceed, NULL)); - CeedOperatorApply(op_colloc, CEED_VECTOR_NONE, *aniso_colloc_ceed, CEED_REQUEST_IMMEDIATE); + PetscCallCeed(ceed, CeedOperatorApply(op_colloc, CEED_VECTOR_NONE, *aniso_colloc_ceed, CEED_REQUEST_IMMEDIATE)); - CeedQFunctionDestroy(&qf_colloc); - CeedOperatorDestroy(&op_colloc); + PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_colloc)); + PetscCallCeed(ceed, CeedOperatorDestroy(&op_colloc)); PetscFunctionReturn(PETSC_SUCCESS); } diff --git a/examples/fluids/src/misc.c b/examples/fluids/src/misc.c index 91652130ee..7e3769ba5a 100644 --- a/examples/fluids/src/misc.c +++ b/examples/fluids/src/misc.c @@ -17,19 +17,20 @@ #include "../qfunctions/mass.h" PetscErrorCode ICs_FixMultiplicity(DM dm, CeedData ceed_data, User user, Vec Q_loc, Vec Q, CeedScalar time) { + Ceed ceed = user->ceed; PetscFunctionBeginUser; // --------------------------------------------------------------------------- // Update time for evaluation // --------------------------------------------------------------------------- - if (user->phys->ics_time_label) CeedOperatorSetContextDouble(ceed_data->op_ics_ctx->op, user->phys->ics_time_label, &time); + if (user->phys->ics_time_label) PetscCallCeed(ceed, CeedOperatorSetContextDouble(ceed_data->op_ics_ctx->op, user->phys->ics_time_label, &time)); // --------------------------------------------------------------------------- // ICs // --------------------------------------------------------------------------- // -- CEED Restriction CeedVector q0_ceed; - CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &q0_ceed, NULL); + PetscCallCeed(ceed, CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &q0_ceed, NULL)); // -- Place PETSc vector in CEED vector PetscCall(ApplyCeedOperatorLocalToGlobal(NULL, Q, ceed_data->op_ics_ctx)); @@ -39,7 +40,7 @@ PetscErrorCode ICs_FixMultiplicity(DM dm, CeedData ceed_data, User user, Vec Q_l // --------------------------------------------------------------------------- // -- CEED Restriction CeedVector mult_vec; - CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &mult_vec, NULL); + PetscCallCeed(ceed, CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &mult_vec, NULL)); // -- Place PETSc vector in CEED vector PetscMemType m_mem_type; @@ -48,7 +49,7 @@ PetscErrorCode ICs_FixMultiplicity(DM dm, CeedData ceed_data, User user, Vec Q_l PetscCall(VecP2C(multiplicity_loc, &m_mem_type, mult_vec)); // -- Get multiplicity - CeedElemRestrictionGetMultiplicity(ceed_data->elem_restr_q, mult_vec); + PetscCallCeed(ceed, CeedElemRestrictionGetMultiplicity(ceed_data->elem_restr_q, mult_vec)); // -- Restore vectors PetscCall(VecC2P(mult_vec, m_mem_type, multiplicity_loc)); @@ -68,8 +69,8 @@ PetscErrorCode ICs_FixMultiplicity(DM dm, CeedData ceed_data, User user, Vec Q_l PetscCall(DMRestoreGlobalVector(dm, &multiplicity)); // Cleanup - CeedVectorDestroy(&mult_vec); - CeedVectorDestroy(&q0_ceed); + PetscCallCeed(ceed, CeedVectorDestroy(&mult_vec)); + PetscCallCeed(ceed, CeedVectorDestroy(&q0_ceed)); PetscFunctionReturn(PETSC_SUCCESS); } @@ -262,27 +263,27 @@ PetscErrorCode CreateMassQFunction(Ceed ceed, CeedInt N, CeedInt q_data_size, Ce switch (N) { case 1: - CeedQFunctionCreateInterior(ceed, 1, Mass_1, Mass_1_loc, qf); + PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, Mass_1, Mass_1_loc, qf)); break; case 5: - CeedQFunctionCreateInterior(ceed, 1, Mass_5, Mass_5_loc, qf); + PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, Mass_5, Mass_5_loc, qf)); break; case 7: - CeedQFunctionCreateInterior(ceed, 1, Mass_7, Mass_7_loc, qf); + PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, Mass_7, Mass_7_loc, qf)); break; case 9: - CeedQFunctionCreateInterior(ceed, 1, Mass_9, Mass_9_loc, qf); + PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, Mass_9, Mass_9_loc, qf)); break; case 22: - CeedQFunctionCreateInterior(ceed, 1, Mass_22, Mass_22_loc, qf); + PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, Mass_22, Mass_22_loc, qf)); break; default: SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_SUP, "Could not find mass qfunction of size %d", N); } - CeedQFunctionAddInput(*qf, "u", N, CEED_EVAL_INTERP); - CeedQFunctionAddInput(*qf, "qdata", q_data_size, CEED_EVAL_NONE); - CeedQFunctionAddOutput(*qf, "v", N, CEED_EVAL_INTERP); + PetscCallCeed(ceed, CeedQFunctionAddInput(*qf, "u", N, CEED_EVAL_INTERP)); + PetscCallCeed(ceed, CeedQFunctionAddInput(*qf, "qdata", q_data_size, CEED_EVAL_NONE)); + PetscCallCeed(ceed, CeedQFunctionAddOutput(*qf, "v", N, CEED_EVAL_INTERP)); PetscFunctionReturn(PETSC_SUCCESS); } @@ -451,6 +452,7 @@ PetscErrorCode IntArrayP2C(PetscInt num_entries, PetscInt **array_petsc, CeedInt // Print information about the given simulation run PetscErrorCode PrintRunInfo(User user, Physics phys_ctx, ProblemData *problem, MPI_Comm comm) { + Ceed ceed = user->ceed; PetscFunctionBeginUser; // Header and rank char host_name[PETSC_MAX_PATH_LEN]; @@ -466,13 +468,13 @@ PetscErrorCode PrintRunInfo(User user, Physics phys_ctx, ProblemData *problem, M host_name, comm_size)); // Problem specific info - PetscCall(problem->print_info(problem, user->app_ctx)); + PetscCall(problem->print_info(user, problem, user->app_ctx)); // libCEED const char *used_resource; CeedMemType mem_type_backend; - CeedGetResource(user->ceed, &used_resource); - CeedGetPreferredMemType(user->ceed, &mem_type_backend); + PetscCallCeed(ceed, CeedGetResource(user->ceed, &used_resource)); + PetscCallCeed(ceed, CeedGetPreferredMemType(user->ceed, &mem_type_backend)); PetscCall(PetscPrintf(comm, " libCEED:\n" " libCEED Backend : %s\n" diff --git a/examples/fluids/src/petsc_ops.c b/examples/fluids/src/petsc_ops.c index 939b259580..453f9bbb18 100644 --- a/examples/fluids/src/petsc_ops.c +++ b/examples/fluids/src/petsc_ops.c @@ -61,7 +61,7 @@ PetscErrorCode OperatorApplyContextCreate(DM dm_x, DM dm_y, Ceed ceed, CeedOpera CeedSize x_size, y_size; PetscFunctionBeginUser; - CeedOperatorGetActiveVectorLengths(op_apply, &x_size, &y_size); + PetscCallCeed(ceed, CeedOperatorGetActiveVectorLengths(op_apply, &x_size, &y_size)); { // Verify sizes PetscInt X_size, Y_size, dm_X_size, dm_Y_size; CeedSize x_ceed_size, y_ceed_size; @@ -84,7 +84,7 @@ PetscErrorCode OperatorApplyContextCreate(DM dm_x, DM dm_y, Ceed ceed, CeedOpera "Y_loc size (%" PetscInt_FMT ") does not match dm_y local vector size (%" PetscInt_FMT ")", Y_size, dm_Y_size); } if (x_ceed && x_ceed != CEED_VECTOR_NONE) { - CeedVectorGetLength(x_ceed, &x_ceed_size); + PetscCallCeed(ceed, CeedVectorGetLength(x_ceed, &x_ceed_size)); PetscCheck(x_size >= 0 ? x_ceed_size == x_size : true, PETSC_COMM_WORLD, PETSC_ERR_ARG_SIZ, "x_ceed (%" CeedSize_FMT ") not correct size for CeedOperator active input size (%" CeedSize_FMT ")", x_ceed_size, x_size); if (dm_x) @@ -92,7 +92,7 @@ PetscErrorCode OperatorApplyContextCreate(DM dm_x, DM dm_y, Ceed ceed, CeedOpera "x_ceed size (%" CeedSize_FMT ") does not match dm_x local vector size (%" PetscInt_FMT ")", x_ceed_size, dm_X_size); } if (y_ceed && y_ceed != CEED_VECTOR_NONE) { - CeedVectorGetLength(y_ceed, &y_ceed_size); + PetscCallCeed(ceed, CeedVectorGetLength(y_ceed, &y_ceed_size)); PetscCheck(y_ceed_size == y_size, PETSC_COMM_WORLD, PETSC_ERR_ARG_SIZ, "y_ceed (%" CeedSize_FMT ") not correct size for CeedOperator active input size (%" CeedSize_FMT ")", y_ceed_size, y_size); if (dm_y) @@ -115,14 +115,14 @@ PetscErrorCode OperatorApplyContextCreate(DM dm_x, DM dm_y, Ceed ceed, CeedOpera (*ctx)->Y_loc = Y_loc; // Copy libCEED objects - if (x_ceed) CeedVectorReferenceCopy(x_ceed, &(*ctx)->x_ceed); - else CeedVectorCreate(ceed, x_size, &(*ctx)->x_ceed); + if (x_ceed) PetscCallCeed(ceed, CeedVectorReferenceCopy(x_ceed, &(*ctx)->x_ceed)); + else PetscCallCeed(ceed, CeedVectorCreate(ceed, x_size, &(*ctx)->x_ceed)); - if (y_ceed) CeedVectorReferenceCopy(y_ceed, &(*ctx)->y_ceed); - else CeedVectorCreate(ceed, y_size, &(*ctx)->y_ceed); + if (y_ceed) PetscCallCeed(ceed, CeedVectorReferenceCopy(y_ceed, &(*ctx)->y_ceed)); + else PetscCallCeed(ceed, CeedVectorCreate(ceed, y_size, &(*ctx)->y_ceed)); - CeedOperatorReferenceCopy(op_apply, &(*ctx)->op); - CeedReferenceCopy(ceed, &(*ctx)->ceed); + PetscCallCeed(ceed, CeedOperatorReferenceCopy(op_apply, &(*ctx)->op)); + PetscCallCeed(ceed, CeedReferenceCopy(ceed, &(*ctx)->ceed)); PetscFunctionReturn(PETSC_SUCCESS); } @@ -134,8 +134,8 @@ PetscErrorCode OperatorApplyContextCreate(DM dm_x, DM dm_y, Ceed ceed, CeedOpera */ PetscErrorCode OperatorApplyContextDestroy(OperatorApplyContext ctx) { PetscFunctionBeginUser; - if (!ctx) PetscFunctionReturn(PETSC_SUCCESS); + Ceed ceed = ctx->ceed; // Destroy PETSc Objects PetscCall(DMDestroy(&ctx->dm_x)); @@ -144,10 +144,10 @@ PetscErrorCode OperatorApplyContextDestroy(OperatorApplyContext ctx) { PetscCall(VecDestroy(&ctx->Y_loc)); // Destroy libCEED Objects - CeedVectorDestroy(&ctx->x_ceed); - CeedVectorDestroy(&ctx->y_ceed); - CeedOperatorDestroy(&ctx->op); - CeedDestroy(&ctx->ceed); + PetscCallCeed(ceed, CeedVectorDestroy(&ctx->x_ceed)); + PetscCallCeed(ceed, CeedVectorDestroy(&ctx->y_ceed)); + PetscCallCeed(ceed, CeedOperatorDestroy(&ctx->op)); + PetscCallCeed(ceed, CeedDestroy(&ctx->ceed)); PetscCall(PetscFree(ctx)); @@ -167,15 +167,17 @@ PetscErrorCode VecP2C(Vec X_petsc, PetscMemType *mem_type, CeedVector x_ceed) { PetscScalar *x; PetscInt X_size; CeedSize x_size; + Ceed ceed; PetscFunctionBeginUser; + PetscCall(CeedVectorGetCeed(x_ceed, &ceed)); PetscCall(VecGetLocalSize(X_petsc, &X_size)); - CeedVectorGetLength(x_ceed, &x_size); + PetscCallCeed(ceed, CeedVectorGetLength(x_ceed, &x_size)); PetscCheck(X_size == x_size, PETSC_COMM_WORLD, PETSC_ERR_ARG_SIZ, "X_petsc (%" PetscInt_FMT ") and x_ceed (%" CeedSize_FMT ") must be same size", X_size, x_size); PetscCall(VecGetArrayAndMemType(X_petsc, &x, mem_type)); - CeedVectorSetArray(x_ceed, MemTypeP2C(*mem_type), CEED_USE_POINTER, x); + PetscCallCeed(ceed, CeedVectorSetArray(x_ceed, MemTypeP2C(*mem_type), CEED_USE_POINTER, x)); PetscFunctionReturn(PETSC_SUCCESS); } @@ -193,14 +195,16 @@ PetscErrorCode VecC2P(CeedVector x_ceed, PetscMemType mem_type, Vec X_petsc) { PetscScalar *x; PetscInt X_size; CeedSize x_size; + Ceed ceed; PetscFunctionBeginUser; + PetscCall(CeedVectorGetCeed(x_ceed, &ceed)); PetscCall(VecGetLocalSize(X_petsc, &X_size)); - CeedVectorGetLength(x_ceed, &x_size); + PetscCallCeed(ceed, CeedVectorGetLength(x_ceed, &x_size)); PetscCheck(X_size == x_size, PETSC_COMM_WORLD, PETSC_ERR_ARG_SIZ, "X_petsc (%" PetscInt_FMT ") and x_ceed (%" CeedSize_FMT ") must be same size", X_size, x_size); - CeedVectorTakeArray(x_ceed, MemTypeP2C(mem_type), &x); + PetscCallCeed(ceed, CeedVectorTakeArray(x_ceed, MemTypeP2C(mem_type), &x)); PetscCall(VecRestoreArrayAndMemType(X_petsc, &x)); PetscFunctionReturn(PETSC_SUCCESS); @@ -219,15 +223,17 @@ PetscErrorCode VecReadP2C(Vec X_petsc, PetscMemType *mem_type, CeedVector x_ceed PetscScalar *x; PetscInt X_size; CeedSize x_size; + Ceed ceed; PetscFunctionBeginUser; + PetscCall(CeedVectorGetCeed(x_ceed, &ceed)); PetscCall(VecGetLocalSize(X_petsc, &X_size)); - CeedVectorGetLength(x_ceed, &x_size); + PetscCallCeed(ceed, CeedVectorGetLength(x_ceed, &x_size)); PetscCheck(X_size == x_size, PETSC_COMM_WORLD, PETSC_ERR_ARG_SIZ, "X_petsc (%" PetscInt_FMT ") and x_ceed (%" CeedSize_FMT ") must be same size", X_size, x_size); PetscCall(VecGetArrayReadAndMemType(X_petsc, (const PetscScalar **)&x, mem_type)); - CeedVectorSetArray(x_ceed, MemTypeP2C(*mem_type), CEED_USE_POINTER, x); + PetscCallCeed(ceed, CeedVectorSetArray(x_ceed, MemTypeP2C(*mem_type), CEED_USE_POINTER, x)); PetscFunctionReturn(PETSC_SUCCESS); } @@ -245,14 +251,16 @@ PetscErrorCode VecReadC2P(CeedVector x_ceed, PetscMemType mem_type, Vec X_petsc) PetscScalar *x; PetscInt X_size; CeedSize x_size; + Ceed ceed; PetscFunctionBeginUser; + PetscCall(CeedVectorGetCeed(x_ceed, &ceed)); PetscCall(VecGetLocalSize(X_petsc, &X_size)); - CeedVectorGetLength(x_ceed, &x_size); + PetscCallCeed(ceed, CeedVectorGetLength(x_ceed, &x_size)); PetscCheck(X_size == x_size, PETSC_COMM_WORLD, PETSC_ERR_ARG_SIZ, "X_petsc (%" PetscInt_FMT ") and x_ceed (%" CeedSize_FMT ") must be same size", X_size, x_size); - CeedVectorTakeArray(x_ceed, MemTypeP2C(mem_type), &x); + PetscCallCeed(ceed, CeedVectorTakeArray(x_ceed, MemTypeP2C(mem_type), &x)); PetscCall(VecRestoreArrayReadAndMemType(X_petsc, (const PetscScalar **)&x)); PetscFunctionReturn(PETSC_SUCCESS); @@ -271,15 +279,17 @@ PetscErrorCode VecCopyP2C(Vec X_petsc, CeedVector x_ceed) { PetscMemType mem_type; PetscInt X_size; CeedSize x_size; + Ceed ceed; PetscFunctionBeginUser; + PetscCall(CeedVectorGetCeed(x_ceed, &ceed)); PetscCall(VecGetLocalSize(X_petsc, &X_size)); - CeedVectorGetLength(x_ceed, &x_size); + PetscCallCeed(ceed, CeedVectorGetLength(x_ceed, &x_size)); PetscCheck(X_size == x_size, PETSC_COMM_WORLD, PETSC_ERR_ARG_SIZ, "X_petsc (%" PetscInt_FMT ") and x_ceed (%" CeedSize_FMT ") must be same size", X_size, x_size); PetscCall(VecGetArrayReadAndMemType(X_petsc, (const PetscScalar **)&x, &mem_type)); - CeedVectorSetArray(x_ceed, MemTypeP2C(mem_type), CEED_COPY_VALUES, x); + PetscCallCeed(ceed, CeedVectorSetArray(x_ceed, MemTypeP2C(mem_type), CEED_COPY_VALUES, x)); PetscCall(VecRestoreArrayReadAndMemType(X_petsc, (const PetscScalar **)&x)); PetscFunctionReturn(PETSC_SUCCESS); @@ -307,9 +317,11 @@ VecType DMReturnVecType(DM dm) { */ PetscErrorCode CeedOperatorCreateLocalVecs(CeedOperator op, VecType vec_type, MPI_Comm comm, Vec *input, Vec *output) { CeedSize input_size, output_size; + Ceed ceed; PetscFunctionBeginUser; - CeedOperatorGetActiveVectorLengths(op, &input_size, &output_size); + PetscCall(CeedOperatorGetCeed(op, &ceed)); + PetscCallCeed(ceed, CeedOperatorGetActiveVectorLengths(op, &input_size, &output_size)); if (input) { PetscCall(VecCreate(comm, input)); PetscCall(VecSetType(*input, vec_type)); @@ -339,6 +351,7 @@ PetscErrorCode CeedOperatorCreateLocalVecs(CeedOperator op, VecType vec_type, MP PetscErrorCode ApplyCeedOperator_Core(Vec X, Vec X_loc, CeedVector x_ceed, CeedVector y_ceed, Vec Y_loc, Vec Y, OperatorApplyContext ctx, bool use_apply_add) { PetscMemType x_mem_type, y_mem_type; + Ceed ceed = ctx->ceed; PetscFunctionBeginUser; if (X) PetscCall(DMGlobalToLocal(ctx->dm_x, X, INSERT_VALUES, X_loc)); @@ -348,8 +361,8 @@ PetscErrorCode ApplyCeedOperator_Core(Vec X, Vec X_loc, CeedVector x_ceed, CeedV PetscCall(PetscLogEventBegin(FLUIDS_CeedOperatorApply, X, Y, 0, 0)); PetscCall(PetscLogGpuTimeBegin()); - if (use_apply_add) CeedOperatorApplyAdd(ctx->op, x_ceed, y_ceed, CEED_REQUEST_IMMEDIATE); - else CeedOperatorApply(ctx->op, x_ceed, y_ceed, CEED_REQUEST_IMMEDIATE); + if (use_apply_add) PetscCallCeed(ceed, CeedOperatorApplyAdd(ctx->op, x_ceed, y_ceed, CEED_REQUEST_IMMEDIATE)); + else PetscCallCeed(ceed, CeedOperatorApply(ctx->op, x_ceed, y_ceed, CEED_REQUEST_IMMEDIATE)); PetscCall(PetscLogGpuTimeEnd()); PetscCall(PetscLogEventEnd(FLUIDS_CeedOperatorApply, X, Y, 0, 0)); @@ -447,6 +460,7 @@ PetscErrorCode MatGetDiag_Ceed(Mat A, Vec D) { PetscFunctionBeginUser; PetscCall(MatShellGetContext(A, &ctx)); + Ceed ceed = ctx->ceed; if (ctx->Y_loc) Y_loc = ctx->Y_loc; else PetscCall(DMGetLocalVector(ctx->dm_y, &Y_loc)); @@ -456,7 +470,7 @@ PetscErrorCode MatGetDiag_Ceed(Mat A, Vec D) { // -- Compute Diagonal PetscCall(PetscLogEventBegin(FLUIDS_CeedOperatorAssembleDiagonal, A, D, 0, 0)); PetscCall(PetscLogGpuTimeBegin()); - CeedOperatorLinearAssembleDiagonal(ctx->op, ctx->y_ceed, CEED_REQUEST_IMMEDIATE); + PetscCallCeed(ceed, CeedOperatorLinearAssembleDiagonal(ctx->op, ctx->y_ceed, CEED_REQUEST_IMMEDIATE)); PetscCall(PetscLogGpuTimeEnd()); PetscCall(PetscLogEventEnd(FLUIDS_CeedOperatorAssembleDiagonal, A, D, 0, 0)); diff --git a/examples/fluids/src/setuplibceed.c b/examples/fluids/src/setuplibceed.c index 4f763a1488..3843effb4a 100644 --- a/examples/fluids/src/setuplibceed.c +++ b/examples/fluids/src/setuplibceed.c @@ -25,7 +25,8 @@ PetscErrorCode CreateRestrictionFromPlex(Ceed ceed, DM dm, CeedInt height, DMLab DMPlexGetLocalOffsets(dm, domain_label, label_value, height, dm_field, &num_elem, &elem_size, &num_comp, &num_dof, &elem_restr_offsets_petsc)); PetscCall(IntArrayP2C(num_elem * elem_size, &elem_restr_offsets_petsc, &elem_restr_offsets_ceed)); - CeedElemRestrictionCreate(ceed, num_elem, elem_size, num_comp, 1, num_dof, CEED_MEM_HOST, CEED_COPY_VALUES, elem_restr_offsets_ceed, elem_restr); + PetscCallCeed(ceed, CeedElemRestrictionCreate(ceed, num_elem, elem_size, num_comp, 1, num_dof, CEED_MEM_HOST, CEED_COPY_VALUES, + elem_restr_offsets_ceed, elem_restr)); PetscCall(PetscFree(elem_restr_offsets_ceed)); PetscFunctionReturn(PETSC_SUCCESS); @@ -54,10 +55,11 @@ PetscErrorCode GetRestrictionForDomain(Ceed ceed, DM dm, CeedInt height, DMLabel PetscCall(CreateRestrictionFromPlex(ceed, dm_coord, height, domain_label, label_value, dm_field, elem_restr_x)); } if (elem_restr_qd_i) { - CeedElemRestrictionGetNumElements(elem_restr_tmp, &loc_num_elem); - CeedElemRestrictionCreateStrided(ceed, loc_num_elem, Q, q_data_size, q_data_size * loc_num_elem * Q, CEED_STRIDES_BACKEND, elem_restr_qd_i); + PetscCallCeed(ceed, CeedElemRestrictionGetNumElements(elem_restr_tmp, &loc_num_elem)); + PetscCallCeed(ceed, CeedElemRestrictionCreateStrided(ceed, loc_num_elem, Q, q_data_size, q_data_size * loc_num_elem * Q, CEED_STRIDES_BACKEND, + elem_restr_qd_i)); } - if (!elem_restr_q) CeedElemRestrictionDestroy(&elem_restr_tmp); + if (!elem_restr_q) PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_tmp)); PetscFunctionReturn(PETSC_SUCCESS); } @@ -71,7 +73,7 @@ PetscErrorCode AddBCSubOperator(Ceed ceed, DM dm, CeedData ceed_data, DMLabel do PetscFunctionBeginUser; // --- Get number of quadrature points for the boundaries - CeedBasisGetNumQuadraturePoints(ceed_data->basis_q_sur, &num_qpts_sur); + PetscCallCeed(ceed, CeedBasisGetNumQuadraturePoints(ceed_data->basis_q_sur, &num_qpts_sur)); // ---- CEED Restriction PetscCall(GetRestrictionForDomain(ceed, dm, height, domain_label, label_value, 0, num_qpts_sur, q_data_size_sur, &elem_restr_q_sur, @@ -80,7 +82,7 @@ PetscErrorCode AddBCSubOperator(Ceed ceed, DM dm, CeedData ceed_data, DMLabel do // State-dependent data will be passed from residual to Jacobian. This will be collocated. PetscCall( GetRestrictionForDomain(ceed, dm, height, domain_label, label_value, 0, num_qpts_sur, jac_data_size_sur, NULL, NULL, &elem_restr_jd_i_sur)); - CeedElemRestrictionCreateVector(elem_restr_jd_i_sur, &jac_data_sur, NULL); + PetscCallCeed(ceed, CeedElemRestrictionCreateVector(elem_restr_jd_i_sur, &jac_data_sur, NULL)); } else { elem_restr_jd_i_sur = NULL; jac_data_sur = NULL; @@ -88,52 +90,54 @@ PetscErrorCode AddBCSubOperator(Ceed ceed, DM dm, CeedData ceed_data, DMLabel do // ---- CEED Vector CeedInt loc_num_elem_sur; - CeedElemRestrictionGetNumElements(elem_restr_q_sur, &loc_num_elem_sur); - CeedVectorCreate(ceed, q_data_size_sur * loc_num_elem_sur * num_qpts_sur, &q_data_sur); + PetscCallCeed(ceed, CeedElemRestrictionGetNumElements(elem_restr_q_sur, &loc_num_elem_sur)); + PetscCallCeed(ceed, CeedVectorCreate(ceed, q_data_size_sur * loc_num_elem_sur * num_qpts_sur, &q_data_sur)); // ---- CEED Operator // ----- CEED Operator for Setup (geometric factors) - CeedOperatorCreate(ceed, ceed_data->qf_setup_sur, NULL, NULL, &op_setup_sur); - CeedOperatorSetField(op_setup_sur, "dx", elem_restr_x_sur, ceed_data->basis_x_sur, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_setup_sur, "weight", CEED_ELEMRESTRICTION_NONE, ceed_data->basis_x_sur, CEED_VECTOR_NONE); - CeedOperatorSetField(op_setup_sur, "surface qdata", elem_restr_qd_i_sur, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); + PetscCallCeed(ceed, CeedOperatorCreate(ceed, ceed_data->qf_setup_sur, NULL, NULL, &op_setup_sur)); + PetscCallCeed(ceed, CeedOperatorSetField(op_setup_sur, "dx", elem_restr_x_sur, ceed_data->basis_x_sur, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorSetField(op_setup_sur, "weight", CEED_ELEMRESTRICTION_NONE, ceed_data->basis_x_sur, CEED_VECTOR_NONE)); + PetscCallCeed(ceed, CeedOperatorSetField(op_setup_sur, "surface qdata", elem_restr_qd_i_sur, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE)); // ----- CEED Operator for Physics - CeedOperatorCreate(ceed, qf_apply_bc, NULL, NULL, &op_apply_bc); - CeedOperatorSetField(op_apply_bc, "q", elem_restr_q_sur, ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_apply_bc, "Grad_q", elem_restr_q_sur, ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_apply_bc, "surface qdata", elem_restr_qd_i_sur, CEED_BASIS_COLLOCATED, q_data_sur); - CeedOperatorSetField(op_apply_bc, "x", elem_restr_x_sur, ceed_data->basis_x_sur, ceed_data->x_coord); - CeedOperatorSetField(op_apply_bc, "v", elem_restr_q_sur, ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); - if (elem_restr_jd_i_sur) CeedOperatorSetField(op_apply_bc, "surface jacobian data", elem_restr_jd_i_sur, CEED_BASIS_COLLOCATED, jac_data_sur); + PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_apply_bc, NULL, NULL, &op_apply_bc)); + PetscCallCeed(ceed, CeedOperatorSetField(op_apply_bc, "q", elem_restr_q_sur, ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorSetField(op_apply_bc, "Grad_q", elem_restr_q_sur, ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorSetField(op_apply_bc, "surface qdata", elem_restr_qd_i_sur, CEED_BASIS_COLLOCATED, q_data_sur)); + PetscCallCeed(ceed, CeedOperatorSetField(op_apply_bc, "x", elem_restr_x_sur, ceed_data->basis_x_sur, ceed_data->x_coord)); + PetscCallCeed(ceed, CeedOperatorSetField(op_apply_bc, "v", elem_restr_q_sur, ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE)); + if (elem_restr_jd_i_sur) + PetscCallCeed(ceed, CeedOperatorSetField(op_apply_bc, "surface jacobian data", elem_restr_jd_i_sur, CEED_BASIS_COLLOCATED, jac_data_sur)); if (qf_apply_bc_jacobian) { - CeedOperatorCreate(ceed, qf_apply_bc_jacobian, NULL, NULL, &op_apply_bc_jacobian); - CeedOperatorSetField(op_apply_bc_jacobian, "dq", elem_restr_q_sur, ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_apply_bc_jacobian, "Grad_dq", elem_restr_q_sur, ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_apply_bc_jacobian, "surface qdata", elem_restr_qd_i_sur, CEED_BASIS_COLLOCATED, q_data_sur); - CeedOperatorSetField(op_apply_bc_jacobian, "x", elem_restr_x_sur, ceed_data->basis_x_sur, ceed_data->x_coord); - CeedOperatorSetField(op_apply_bc_jacobian, "surface jacobian data", elem_restr_jd_i_sur, CEED_BASIS_COLLOCATED, jac_data_sur); - CeedOperatorSetField(op_apply_bc_jacobian, "v", elem_restr_q_sur, ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); + PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_apply_bc_jacobian, NULL, NULL, &op_apply_bc_jacobian)); + PetscCallCeed(ceed, CeedOperatorSetField(op_apply_bc_jacobian, "dq", elem_restr_q_sur, ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorSetField(op_apply_bc_jacobian, "Grad_dq", elem_restr_q_sur, ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorSetField(op_apply_bc_jacobian, "surface qdata", elem_restr_qd_i_sur, CEED_BASIS_COLLOCATED, q_data_sur)); + PetscCallCeed(ceed, CeedOperatorSetField(op_apply_bc_jacobian, "x", elem_restr_x_sur, ceed_data->basis_x_sur, ceed_data->x_coord)); + PetscCallCeed(ceed, + CeedOperatorSetField(op_apply_bc_jacobian, "surface jacobian data", elem_restr_jd_i_sur, CEED_BASIS_COLLOCATED, jac_data_sur)); + PetscCallCeed(ceed, CeedOperatorSetField(op_apply_bc_jacobian, "v", elem_restr_q_sur, ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE)); } // ----- Apply CEED operator for Setup - CeedOperatorApply(op_setup_sur, ceed_data->x_coord, q_data_sur, CEED_REQUEST_IMMEDIATE); + PetscCallCeed(ceed, CeedOperatorApply(op_setup_sur, ceed_data->x_coord, q_data_sur, CEED_REQUEST_IMMEDIATE)); // ----- Apply Sub-Operator for Physics - CeedCompositeOperatorAddSub(*op_apply, op_apply_bc); - if (op_apply_bc_jacobian) CeedCompositeOperatorAddSub(*op_apply_ijacobian, op_apply_bc_jacobian); + PetscCallCeed(ceed, CeedCompositeOperatorAddSub(*op_apply, op_apply_bc)); + if (op_apply_bc_jacobian) PetscCallCeed(ceed, CeedCompositeOperatorAddSub(*op_apply_ijacobian, op_apply_bc_jacobian)); // ----- Cleanup - CeedVectorDestroy(&q_data_sur); - CeedVectorDestroy(&jac_data_sur); - CeedElemRestrictionDestroy(&elem_restr_q_sur); - CeedElemRestrictionDestroy(&elem_restr_x_sur); - CeedElemRestrictionDestroy(&elem_restr_qd_i_sur); - CeedElemRestrictionDestroy(&elem_restr_jd_i_sur); - CeedOperatorDestroy(&op_setup_sur); - CeedOperatorDestroy(&op_apply_bc); - CeedOperatorDestroy(&op_apply_bc_jacobian); + PetscCallCeed(ceed, CeedVectorDestroy(&q_data_sur)); + PetscCallCeed(ceed, CeedVectorDestroy(&jac_data_sur)); + PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_q_sur)); + PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_x_sur)); + PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_qd_i_sur)); + PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_jd_i_sur)); + PetscCallCeed(ceed, CeedOperatorDestroy(&op_setup_sur)); + PetscCallCeed(ceed, CeedOperatorDestroy(&op_apply_bc)); + PetscCallCeed(ceed, CeedOperatorDestroy(&op_apply_bc_jacobian)); PetscFunctionReturn(PETSC_SUCCESS); } @@ -146,12 +150,12 @@ PetscErrorCode CreateOperatorForDomain(Ceed ceed, DM dm, SimpleBC bc, CeedData c PetscFunctionBeginUser; // Create Composite Operaters - CeedCompositeOperatorCreate(ceed, op_apply); - if (op_apply_ijacobian) CeedCompositeOperatorCreate(ceed, op_apply_ijacobian); + PetscCallCeed(ceed, CeedCompositeOperatorCreate(ceed, op_apply)); + if (op_apply_ijacobian) PetscCallCeed(ceed, CeedCompositeOperatorCreate(ceed, op_apply_ijacobian)); // --Apply Sub-Operator for the volume - CeedCompositeOperatorAddSub(*op_apply, op_apply_vol); - if (op_apply_ijacobian) CeedCompositeOperatorAddSub(*op_apply_ijacobian, op_apply_ijacobian_vol); + PetscCallCeed(ceed, CeedCompositeOperatorAddSub(*op_apply, op_apply_vol)); + if (op_apply_ijacobian) PetscCallCeed(ceed, CeedCompositeOperatorAddSub(*op_apply_ijacobian, op_apply_ijacobian_vol)); // -- Create Sub-Operator for in/outflow BCs if (phys->has_neumann || 1) { @@ -176,8 +180,8 @@ PetscErrorCode CreateOperatorForDomain(Ceed ceed, DM dm, SimpleBC bc, CeedData c } // ----- Get Context Labels for Operator - CeedOperatorGetContextFieldLabel(*op_apply, "solution time", &phys->solution_time_label); - CeedOperatorGetContextFieldLabel(*op_apply, "timestep size", &phys->timestep_size_label); + PetscCallCeed(ceed, CeedOperatorGetContextFieldLabel(*op_apply, "solution time", &phys->solution_time_label)); + PetscCallCeed(ceed, CeedOperatorGetContextFieldLabel(*op_apply, "timestep size", &phys->timestep_size_label)); PetscFunctionReturn(PETSC_SUCCESS); } @@ -188,24 +192,24 @@ PetscErrorCode SetupBCQFunctions(Ceed ceed, PetscInt dim_sur, PetscInt num_comp_ PetscFunctionBeginUser; if (apply_bc.qfunction) { - CeedQFunctionCreateInterior(ceed, 1, apply_bc.qfunction, apply_bc.qfunction_loc, qf_apply_bc); - CeedQFunctionSetContext(*qf_apply_bc, apply_bc.qfunction_context); - CeedQFunctionAddInput(*qf_apply_bc, "q", num_comp_q, CEED_EVAL_INTERP); - CeedQFunctionAddInput(*qf_apply_bc, "Grad_q", num_comp_q * dim_sur, CEED_EVAL_GRAD); - CeedQFunctionAddInput(*qf_apply_bc, "surface qdata", q_data_size_sur, CEED_EVAL_NONE); - CeedQFunctionAddInput(*qf_apply_bc, "x", num_comp_x, CEED_EVAL_INTERP); - CeedQFunctionAddOutput(*qf_apply_bc, "v", num_comp_q, CEED_EVAL_INTERP); - if (jac_data_size_sur) CeedQFunctionAddOutput(*qf_apply_bc, "surface jacobian data", jac_data_size_sur, CEED_EVAL_NONE); + PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, apply_bc.qfunction, apply_bc.qfunction_loc, qf_apply_bc)); + PetscCallCeed(ceed, CeedQFunctionSetContext(*qf_apply_bc, apply_bc.qfunction_context)); + PetscCallCeed(ceed, CeedQFunctionAddInput(*qf_apply_bc, "q", num_comp_q, CEED_EVAL_INTERP)); + PetscCallCeed(ceed, CeedQFunctionAddInput(*qf_apply_bc, "Grad_q", num_comp_q * dim_sur, CEED_EVAL_GRAD)); + PetscCallCeed(ceed, CeedQFunctionAddInput(*qf_apply_bc, "surface qdata", q_data_size_sur, CEED_EVAL_NONE)); + PetscCallCeed(ceed, CeedQFunctionAddInput(*qf_apply_bc, "x", num_comp_x, CEED_EVAL_INTERP)); + PetscCallCeed(ceed, CeedQFunctionAddOutput(*qf_apply_bc, "v", num_comp_q, CEED_EVAL_INTERP)); + if (jac_data_size_sur) PetscCallCeed(ceed, CeedQFunctionAddOutput(*qf_apply_bc, "surface jacobian data", jac_data_size_sur, CEED_EVAL_NONE)); } if (apply_bc_jacobian.qfunction) { - CeedQFunctionCreateInterior(ceed, 1, apply_bc_jacobian.qfunction, apply_bc_jacobian.qfunction_loc, qf_apply_bc_jacobian); - CeedQFunctionSetContext(*qf_apply_bc_jacobian, apply_bc_jacobian.qfunction_context); - CeedQFunctionAddInput(*qf_apply_bc_jacobian, "dq", num_comp_q, CEED_EVAL_INTERP); - CeedQFunctionAddInput(*qf_apply_bc_jacobian, "Grad_dq", num_comp_q * dim_sur, CEED_EVAL_GRAD); - CeedQFunctionAddInput(*qf_apply_bc_jacobian, "surface qdata", q_data_size_sur, CEED_EVAL_NONE); - CeedQFunctionAddInput(*qf_apply_bc_jacobian, "x", num_comp_x, CEED_EVAL_INTERP); - CeedQFunctionAddInput(*qf_apply_bc_jacobian, "surface jacobian data", jac_data_size_sur, CEED_EVAL_NONE); - CeedQFunctionAddOutput(*qf_apply_bc_jacobian, "v", num_comp_q, CEED_EVAL_INTERP); + PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, apply_bc_jacobian.qfunction, apply_bc_jacobian.qfunction_loc, qf_apply_bc_jacobian)); + PetscCallCeed(ceed, CeedQFunctionSetContext(*qf_apply_bc_jacobian, apply_bc_jacobian.qfunction_context)); + PetscCallCeed(ceed, CeedQFunctionAddInput(*qf_apply_bc_jacobian, "dq", num_comp_q, CEED_EVAL_INTERP)); + PetscCallCeed(ceed, CeedQFunctionAddInput(*qf_apply_bc_jacobian, "Grad_dq", num_comp_q * dim_sur, CEED_EVAL_GRAD)); + PetscCallCeed(ceed, CeedQFunctionAddInput(*qf_apply_bc_jacobian, "surface qdata", q_data_size_sur, CEED_EVAL_NONE)); + PetscCallCeed(ceed, CeedQFunctionAddInput(*qf_apply_bc_jacobian, "x", num_comp_x, CEED_EVAL_INTERP)); + PetscCallCeed(ceed, CeedQFunctionAddInput(*qf_apply_bc_jacobian, "surface jacobian data", jac_data_size_sur, CEED_EVAL_NONE)); + PetscCallCeed(ceed, CeedQFunctionAddOutput(*qf_apply_bc_jacobian, "v", num_comp_q, CEED_EVAL_INTERP)); } PetscFunctionReturn(PETSC_SUCCESS); } @@ -344,7 +348,7 @@ PetscErrorCode BasisCreateFromTabulation(Ceed ceed, DM dm, DMLabel domain_label, } // Finally, create libCEED basis - CeedBasisCreateH1(ceed, elem_topo, num_comp, P, Q, interp, grad, q_points, q_weights, basis); + PetscCallCeed(ceed, CeedBasisCreateH1(ceed, elem_topo, num_comp, P, Q, interp, grad, q_points, q_weights, basis)); PetscCall(PetscFree(q_points)); PetscCall(PetscFree(interp)); PetscCall(PetscFree(grad)); @@ -396,7 +400,7 @@ PetscErrorCode CreateBasisFromPlex(Ceed ceed, DM dm, DMLabel domain_label, CeedI CeedInt P_1d = (CeedInt)round(pow(P, 1.0 / dim)); CeedInt Q_1d = (CeedInt)round(pow(Q, 1.0 / dim)); - CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp, P_1d, Q_1d, CEED_GAUSS, basis); + PetscCallCeed(ceed, CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp, P_1d, Q_1d, CEED_GAUSS, basis)); } PetscFunctionReturn(PETSC_SUCCESS); @@ -422,8 +426,8 @@ PetscErrorCode SetupLibceed(Ceed ceed, CeedData ceed_data, DM dm, User user, App PetscCall(CreateBasisFromPlex(ceed, dm, 0, 0, 0, 0, &ceed_data->basis_q)); PetscCall(CreateBasisFromPlex(ceed, dm_coord, 0, 0, 0, 0, &ceed_data->basis_x)); - PetscCall(CeedBasisCreateProjection(ceed_data->basis_x, ceed_data->basis_q, &ceed_data->basis_xc)); - CeedBasisGetNumQuadraturePoints(ceed_data->basis_q, &num_qpts); + PetscCallCeed(ceed, CeedBasisCreateProjection(ceed_data->basis_x, ceed_data->basis_q, &ceed_data->basis_xc)); + PetscCallCeed(ceed, CeedBasisGetNumQuadraturePoints(ceed_data->basis_q, &num_qpts)); // ----------------------------------------------------------------------------- // CEED Restrictions @@ -434,74 +438,76 @@ PetscErrorCode SetupLibceed(Ceed ceed, CeedData ceed_data, DM dm, User user, App PetscCall(GetRestrictionForDomain(ceed, dm, 0, 0, 0, 0, num_qpts, jac_data_size_vol, NULL, NULL, &elem_restr_jd_i)); // -- Create E vectors - CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->q_ceed, NULL); - CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->q_dot_ceed, NULL); - CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->g_ceed, NULL); + PetscCallCeed(ceed, CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->q_ceed, NULL)); + PetscCallCeed(ceed, CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->q_dot_ceed, NULL)); + PetscCallCeed(ceed, CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->g_ceed, NULL)); // ----------------------------------------------------------------------------- // CEED QFunctions // ----------------------------------------------------------------------------- // -- Create QFunction for quadrature data - CeedQFunctionCreateInterior(ceed, 1, problem->setup_vol.qfunction, problem->setup_vol.qfunction_loc, &ceed_data->qf_setup_vol); + PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, problem->setup_vol.qfunction, problem->setup_vol.qfunction_loc, &ceed_data->qf_setup_vol)); if (problem->setup_vol.qfunction_context) { - CeedQFunctionSetContext(ceed_data->qf_setup_vol, problem->setup_vol.qfunction_context); + PetscCallCeed(ceed, CeedQFunctionSetContext(ceed_data->qf_setup_vol, problem->setup_vol.qfunction_context)); } - CeedQFunctionAddInput(ceed_data->qf_setup_vol, "dx", num_comp_x * dim, CEED_EVAL_GRAD); - CeedQFunctionAddInput(ceed_data->qf_setup_vol, "weight", 1, CEED_EVAL_WEIGHT); - CeedQFunctionAddOutput(ceed_data->qf_setup_vol, "qdata", q_data_size_vol, CEED_EVAL_NONE); + PetscCallCeed(ceed, CeedQFunctionAddInput(ceed_data->qf_setup_vol, "dx", num_comp_x * dim, CEED_EVAL_GRAD)); + PetscCallCeed(ceed, CeedQFunctionAddInput(ceed_data->qf_setup_vol, "weight", 1, CEED_EVAL_WEIGHT)); + PetscCallCeed(ceed, CeedQFunctionAddOutput(ceed_data->qf_setup_vol, "qdata", q_data_size_vol, CEED_EVAL_NONE)); // -- Create QFunction for ICs - CeedQFunctionCreateInterior(ceed, 1, problem->ics.qfunction, problem->ics.qfunction_loc, &ceed_data->qf_ics); - CeedQFunctionSetContext(ceed_data->qf_ics, problem->ics.qfunction_context); - CeedQFunctionAddInput(ceed_data->qf_ics, "x", num_comp_x, CEED_EVAL_INTERP); - CeedQFunctionAddInput(ceed_data->qf_ics, "dx", num_comp_x * dim, CEED_EVAL_GRAD); - CeedQFunctionAddOutput(ceed_data->qf_ics, "q0", num_comp_q, CEED_EVAL_NONE); + PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, problem->ics.qfunction, problem->ics.qfunction_loc, &ceed_data->qf_ics)); + PetscCallCeed(ceed, CeedQFunctionSetContext(ceed_data->qf_ics, problem->ics.qfunction_context)); + PetscCallCeed(ceed, CeedQFunctionAddInput(ceed_data->qf_ics, "x", num_comp_x, CEED_EVAL_INTERP)); + PetscCallCeed(ceed, CeedQFunctionAddInput(ceed_data->qf_ics, "dx", num_comp_x * dim, CEED_EVAL_GRAD)); + PetscCallCeed(ceed, CeedQFunctionAddOutput(ceed_data->qf_ics, "q0", num_comp_q, CEED_EVAL_NONE)); // -- Create QFunction for RHS if (problem->apply_vol_rhs.qfunction) { - CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_rhs.qfunction, problem->apply_vol_rhs.qfunction_loc, &ceed_data->qf_rhs_vol); - CeedQFunctionSetContext(ceed_data->qf_rhs_vol, problem->apply_vol_rhs.qfunction_context); - CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "q", num_comp_q, CEED_EVAL_INTERP); - CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "Grad_q", num_comp_q * dim, CEED_EVAL_GRAD); - CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "qdata", q_data_size_vol, CEED_EVAL_NONE); - CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "x", num_comp_x, CEED_EVAL_INTERP); - CeedQFunctionAddOutput(ceed_data->qf_rhs_vol, "v", num_comp_q, CEED_EVAL_INTERP); - CeedQFunctionAddOutput(ceed_data->qf_rhs_vol, "Grad_v", num_comp_q * dim, CEED_EVAL_GRAD); + PetscCallCeed( + ceed, CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_rhs.qfunction, problem->apply_vol_rhs.qfunction_loc, &ceed_data->qf_rhs_vol)); + PetscCallCeed(ceed, CeedQFunctionSetContext(ceed_data->qf_rhs_vol, problem->apply_vol_rhs.qfunction_context)); + PetscCallCeed(ceed, CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "q", num_comp_q, CEED_EVAL_INTERP)); + PetscCallCeed(ceed, CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "Grad_q", num_comp_q * dim, CEED_EVAL_GRAD)); + PetscCallCeed(ceed, CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "qdata", q_data_size_vol, CEED_EVAL_NONE)); + PetscCallCeed(ceed, CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "x", num_comp_x, CEED_EVAL_INTERP)); + PetscCallCeed(ceed, CeedQFunctionAddOutput(ceed_data->qf_rhs_vol, "v", num_comp_q, CEED_EVAL_INTERP)); + PetscCallCeed(ceed, CeedQFunctionAddOutput(ceed_data->qf_rhs_vol, "Grad_v", num_comp_q * dim, CEED_EVAL_GRAD)); } // -- Create QFunction for IFunction if (problem->apply_vol_ifunction.qfunction) { - CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_ifunction.qfunction, problem->apply_vol_ifunction.qfunction_loc, - &ceed_data->qf_ifunction_vol); - CeedQFunctionSetContext(ceed_data->qf_ifunction_vol, problem->apply_vol_ifunction.qfunction_context); - CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "q", num_comp_q, CEED_EVAL_INTERP); - CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "Grad_q", num_comp_q * dim, CEED_EVAL_GRAD); - CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "q dot", num_comp_q, CEED_EVAL_INTERP); - CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "qdata", q_data_size_vol, CEED_EVAL_NONE); - CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "x", num_comp_x, CEED_EVAL_INTERP); - CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "v", num_comp_q, CEED_EVAL_INTERP); - CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "Grad_v", num_comp_q * dim, CEED_EVAL_GRAD); - CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "jac_data", jac_data_size_vol, CEED_EVAL_NONE); + PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_ifunction.qfunction, problem->apply_vol_ifunction.qfunction_loc, + &ceed_data->qf_ifunction_vol)); + PetscCallCeed(ceed, CeedQFunctionSetContext(ceed_data->qf_ifunction_vol, problem->apply_vol_ifunction.qfunction_context)); + PetscCallCeed(ceed, CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "q", num_comp_q, CEED_EVAL_INTERP)); + PetscCallCeed(ceed, CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "Grad_q", num_comp_q * dim, CEED_EVAL_GRAD)); + PetscCallCeed(ceed, CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "q dot", num_comp_q, CEED_EVAL_INTERP)); + PetscCallCeed(ceed, CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "qdata", q_data_size_vol, CEED_EVAL_NONE)); + PetscCallCeed(ceed, CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "x", num_comp_x, CEED_EVAL_INTERP)); + PetscCallCeed(ceed, CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "v", num_comp_q, CEED_EVAL_INTERP)); + PetscCallCeed(ceed, CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "Grad_v", num_comp_q * dim, CEED_EVAL_GRAD)); + PetscCallCeed(ceed, CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "jac_data", jac_data_size_vol, CEED_EVAL_NONE)); } CeedQFunction qf_ijacobian_vol = NULL; if (problem->apply_vol_ijacobian.qfunction) { - CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_ijacobian.qfunction, problem->apply_vol_ijacobian.qfunction_loc, &qf_ijacobian_vol); - CeedQFunctionSetContext(qf_ijacobian_vol, problem->apply_vol_ijacobian.qfunction_context); - CeedQFunctionAddInput(qf_ijacobian_vol, "dq", num_comp_q, CEED_EVAL_INTERP); - CeedQFunctionAddInput(qf_ijacobian_vol, "Grad_dq", num_comp_q * dim, CEED_EVAL_GRAD); - CeedQFunctionAddInput(qf_ijacobian_vol, "qdata", q_data_size_vol, CEED_EVAL_NONE); - CeedQFunctionAddInput(qf_ijacobian_vol, "x", num_comp_x, CEED_EVAL_INTERP); - CeedQFunctionAddInput(qf_ijacobian_vol, "jac_data", jac_data_size_vol, CEED_EVAL_NONE); - CeedQFunctionAddOutput(qf_ijacobian_vol, "v", num_comp_q, CEED_EVAL_INTERP); - CeedQFunctionAddOutput(qf_ijacobian_vol, "Grad_v", num_comp_q * dim, CEED_EVAL_GRAD); + PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_ijacobian.qfunction, problem->apply_vol_ijacobian.qfunction_loc, + &qf_ijacobian_vol)); + PetscCallCeed(ceed, CeedQFunctionSetContext(qf_ijacobian_vol, problem->apply_vol_ijacobian.qfunction_context)); + PetscCallCeed(ceed, CeedQFunctionAddInput(qf_ijacobian_vol, "dq", num_comp_q, CEED_EVAL_INTERP)); + PetscCallCeed(ceed, CeedQFunctionAddInput(qf_ijacobian_vol, "Grad_dq", num_comp_q * dim, CEED_EVAL_GRAD)); + PetscCallCeed(ceed, CeedQFunctionAddInput(qf_ijacobian_vol, "qdata", q_data_size_vol, CEED_EVAL_NONE)); + PetscCallCeed(ceed, CeedQFunctionAddInput(qf_ijacobian_vol, "x", num_comp_x, CEED_EVAL_INTERP)); + PetscCallCeed(ceed, CeedQFunctionAddInput(qf_ijacobian_vol, "jac_data", jac_data_size_vol, CEED_EVAL_NONE)); + PetscCallCeed(ceed, CeedQFunctionAddOutput(qf_ijacobian_vol, "v", num_comp_q, CEED_EVAL_INTERP)); + PetscCallCeed(ceed, CeedQFunctionAddOutput(qf_ijacobian_vol, "Grad_v", num_comp_q * dim, CEED_EVAL_GRAD)); } // --------------------------------------------------------------------------- // Element coordinates // --------------------------------------------------------------------------- // -- Create CEED vector - CeedElemRestrictionCreateVector(ceed_data->elem_restr_x, &ceed_data->x_coord, NULL); + PetscCallCeed(ceed, CeedElemRestrictionCreateVector(ceed_data->elem_restr_x, &ceed_data->x_coord, NULL)); // -- Copy PETSc vector in CEED vector Vec X_loc; @@ -521,53 +527,53 @@ PetscErrorCode SetupLibceed(Ceed ceed, CeedData ceed_data, DM dm, User user, App // CEED vectors // ----------------------------------------------------------------------------- // -- Create CEED vector for geometric data - CeedElemRestrictionCreateVector(ceed_data->elem_restr_qd_i, &ceed_data->q_data, NULL); - CeedElemRestrictionCreateVector(elem_restr_jd_i, &jac_data, NULL); + PetscCallCeed(ceed, CeedElemRestrictionCreateVector(ceed_data->elem_restr_qd_i, &ceed_data->q_data, NULL)); + PetscCallCeed(ceed, CeedElemRestrictionCreateVector(elem_restr_jd_i, &jac_data, NULL)); // ----------------------------------------------------------------------------- // CEED Operators // ----------------------------------------------------------------------------- // -- Create CEED operator for quadrature data - CeedOperatorCreate(ceed, ceed_data->qf_setup_vol, NULL, NULL, &ceed_data->op_setup_vol); - CeedOperatorSetField(ceed_data->op_setup_vol, "dx", ceed_data->elem_restr_x, ceed_data->basis_x, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(ceed_data->op_setup_vol, "weight", CEED_ELEMRESTRICTION_NONE, ceed_data->basis_x, CEED_VECTOR_NONE); - CeedOperatorSetField(ceed_data->op_setup_vol, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); + PetscCallCeed(ceed, CeedOperatorCreate(ceed, ceed_data->qf_setup_vol, NULL, NULL, &ceed_data->op_setup_vol)); + PetscCallCeed(ceed, CeedOperatorSetField(ceed_data->op_setup_vol, "dx", ceed_data->elem_restr_x, ceed_data->basis_x, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorSetField(ceed_data->op_setup_vol, "weight", CEED_ELEMRESTRICTION_NONE, ceed_data->basis_x, CEED_VECTOR_NONE)); + PetscCallCeed(ceed, CeedOperatorSetField(ceed_data->op_setup_vol, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE)); // -- Create CEED operator for ICs CeedOperator op_ics; - CeedOperatorCreate(ceed, ceed_data->qf_ics, NULL, NULL, &op_ics); - CeedOperatorSetField(op_ics, "x", ceed_data->elem_restr_x, ceed_data->basis_xc, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_ics, "dx", ceed_data->elem_restr_x, ceed_data->basis_xc, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_ics, "q0", ceed_data->elem_restr_q, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); - CeedOperatorGetContextFieldLabel(op_ics, "evaluation time", &user->phys->ics_time_label); + PetscCallCeed(ceed, CeedOperatorCreate(ceed, ceed_data->qf_ics, NULL, NULL, &op_ics)); + PetscCallCeed(ceed, CeedOperatorSetField(op_ics, "x", ceed_data->elem_restr_x, ceed_data->basis_xc, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorSetField(op_ics, "dx", ceed_data->elem_restr_x, ceed_data->basis_xc, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorSetField(op_ics, "q0", ceed_data->elem_restr_q, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorGetContextFieldLabel(op_ics, "evaluation time", &user->phys->ics_time_label)); PetscCall(OperatorApplyContextCreate(NULL, dm, user->ceed, op_ics, ceed_data->x_coord, NULL, NULL, user->Q_loc, &ceed_data->op_ics_ctx)); - CeedOperatorDestroy(&op_ics); + PetscCallCeed(ceed, CeedOperatorDestroy(&op_ics)); // Create CEED operator for RHS if (ceed_data->qf_rhs_vol) { CeedOperator op; - CeedOperatorCreate(ceed, ceed_data->qf_rhs_vol, NULL, NULL, &op); - CeedOperatorSetField(op, "q", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op, "Grad_q", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, ceed_data->q_data); - CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord); - CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE); + PetscCallCeed(ceed, CeedOperatorCreate(ceed, ceed_data->qf_rhs_vol, NULL, NULL, &op)); + PetscCallCeed(ceed, CeedOperatorSetField(op, "q", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorSetField(op, "Grad_q", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, ceed_data->q_data)); + PetscCallCeed(ceed, CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord)); + PetscCallCeed(ceed, CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE)); user->op_rhs_vol = op; } // -- CEED operator for IFunction if (ceed_data->qf_ifunction_vol) { CeedOperator op; - CeedOperatorCreate(ceed, ceed_data->qf_ifunction_vol, NULL, NULL, &op); - CeedOperatorSetField(op, "q", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op, "Grad_q", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op, "q dot", ceed_data->elem_restr_q, ceed_data->basis_q, user->q_dot_ceed); - CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, ceed_data->q_data); - CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord); - CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op, "jac_data", elem_restr_jd_i, CEED_BASIS_COLLOCATED, jac_data); + PetscCallCeed(ceed, CeedOperatorCreate(ceed, ceed_data->qf_ifunction_vol, NULL, NULL, &op)); + PetscCallCeed(ceed, CeedOperatorSetField(op, "q", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorSetField(op, "Grad_q", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorSetField(op, "q dot", ceed_data->elem_restr_q, ceed_data->basis_q, user->q_dot_ceed)); + PetscCallCeed(ceed, CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, ceed_data->q_data)); + PetscCallCeed(ceed, CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord)); + PetscCallCeed(ceed, CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorSetField(op, "jac_data", elem_restr_jd_i, CEED_BASIS_COLLOCATED, jac_data)); user->op_ifunction_vol = op; } @@ -575,16 +581,16 @@ PetscErrorCode SetupLibceed(Ceed ceed, CeedData ceed_data, DM dm, User user, App CeedOperator op_ijacobian_vol = NULL; if (qf_ijacobian_vol) { CeedOperator op; - CeedOperatorCreate(ceed, qf_ijacobian_vol, NULL, NULL, &op); - CeedOperatorSetField(op, "dq", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op, "Grad_dq", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, ceed_data->q_data); - CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord); - CeedOperatorSetField(op, "jac_data", elem_restr_jd_i, CEED_BASIS_COLLOCATED, jac_data); - CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE); + PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_ijacobian_vol, NULL, NULL, &op)); + PetscCallCeed(ceed, CeedOperatorSetField(op, "dq", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorSetField(op, "Grad_dq", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, ceed_data->q_data)); + PetscCallCeed(ceed, CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord)); + PetscCallCeed(ceed, CeedOperatorSetField(op, "jac_data", elem_restr_jd_i, CEED_BASIS_COLLOCATED, jac_data)); + PetscCallCeed(ceed, CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE)); op_ijacobian_vol = op; - CeedQFunctionDestroy(&qf_ijacobian_vol); + PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_ijacobian_vol)); } // ***************************************************************************** @@ -602,19 +608,19 @@ PetscErrorCode SetupLibceed(Ceed ceed, CeedData ceed_data, DM dm, User user, App PetscInt field = 0; // Still want the normal, default field PetscCall(CreateBasisFromPlex(ceed, dm, label, face_id, height, field, &ceed_data->basis_q_sur)); PetscCall(CreateBasisFromPlex(ceed, dm_coord, label, face_id, height, field, &ceed_data->basis_x_sur)); - PetscCall(CeedBasisCreateProjection(ceed_data->basis_x_sur, ceed_data->basis_q_sur, &ceed_data->basis_xc_sur)); + PetscCallCeed(ceed, CeedBasisCreateProjection(ceed_data->basis_x_sur, ceed_data->basis_q_sur, &ceed_data->basis_xc_sur)); // ----------------------------------------------------------------------------- // CEED QFunctions // ----------------------------------------------------------------------------- // -- Create QFunction for quadrature data - CeedQFunctionCreateInterior(ceed, 1, problem->setup_sur.qfunction, problem->setup_sur.qfunction_loc, &ceed_data->qf_setup_sur); + PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, problem->setup_sur.qfunction, problem->setup_sur.qfunction_loc, &ceed_data->qf_setup_sur)); if (problem->setup_sur.qfunction_context) { - CeedQFunctionSetContext(ceed_data->qf_setup_sur, problem->setup_sur.qfunction_context); + PetscCallCeed(ceed, CeedQFunctionSetContext(ceed_data->qf_setup_sur, problem->setup_sur.qfunction_context)); } - CeedQFunctionAddInput(ceed_data->qf_setup_sur, "dx", num_comp_x * dim_sur, CEED_EVAL_GRAD); - CeedQFunctionAddInput(ceed_data->qf_setup_sur, "weight", 1, CEED_EVAL_WEIGHT); - CeedQFunctionAddOutput(ceed_data->qf_setup_sur, "surface qdata", q_data_size_sur, CEED_EVAL_NONE); + PetscCallCeed(ceed, CeedQFunctionAddInput(ceed_data->qf_setup_sur, "dx", num_comp_x * dim_sur, CEED_EVAL_GRAD)); + PetscCallCeed(ceed, CeedQFunctionAddInput(ceed_data->qf_setup_sur, "weight", 1, CEED_EVAL_WEIGHT)); + PetscCallCeed(ceed, CeedQFunctionAddOutput(ceed_data->qf_setup_sur, "surface qdata", q_data_size_sur, CEED_EVAL_NONE)); PetscCall(SetupBCQFunctions(ceed, dim_sur, num_comp_x, num_comp_q, q_data_size_sur, jac_data_size_sur, problem->apply_inflow, problem->apply_inflow_jacobian, &ceed_data->qf_apply_inflow, &ceed_data->qf_apply_inflow_jacobian)); @@ -627,7 +633,7 @@ PetscErrorCode SetupLibceed(Ceed ceed, CeedData ceed_data, DM dm, User user, App // CEED Operator Apply // ***************************************************************************** // -- Apply CEED Operator for the geometric data - CeedOperatorApply(ceed_data->op_setup_vol, ceed_data->x_coord, ceed_data->q_data, CEED_REQUEST_IMMEDIATE); + PetscCallCeed(ceed, CeedOperatorApply(ceed_data->op_setup_vol, ceed_data->x_coord, ceed_data->q_data, CEED_REQUEST_IMMEDIATE)); // -- Create and apply CEED Composite Operator for the entire domain if (!user->phys->implicit) { // RHS @@ -635,12 +641,12 @@ PetscErrorCode SetupLibceed(Ceed ceed, CeedData ceed_data, DM dm, User user, App PetscCall(CreateOperatorForDomain(ceed, dm, bc, ceed_data, user->phys, user->op_rhs_vol, NULL, height, P_sur, Q_sur, q_data_size_sur, 0, &op_rhs, NULL)); PetscCall(OperatorApplyContextCreate(dm, dm, ceed, op_rhs, user->q_ceed, user->g_ceed, user->Q_loc, NULL, &user->op_rhs_ctx)); - CeedOperatorDestroy(&op_rhs); + PetscCallCeed(ceed, CeedOperatorDestroy(&op_rhs)); } else { // IFunction PetscCall(CreateOperatorForDomain(ceed, dm, bc, ceed_data, user->phys, user->op_ifunction_vol, op_ijacobian_vol, height, P_sur, Q_sur, q_data_size_sur, jac_data_size_sur, &user->op_ifunction, op_ijacobian_vol ? &user->op_ijacobian : NULL)); if (user->op_ijacobian) { - CeedOperatorGetContextFieldLabel(user->op_ijacobian, "ijacobian time shift", &user->phys->ijacobian_time_shift_label); + PetscCallCeed(ceed, CeedOperatorGetContextFieldLabel(user->op_ijacobian, "ijacobian time shift", &user->phys->ijacobian_time_shift_label)); } if (problem->use_strong_bc_ceed) PetscCall(SetupStrongBC_Ceed(ceed, ceed_data, dm, user, problem, bc, q_data_size_sur)); if (app_ctx->sgs_model_type == SGS_MODEL_DATA_DRIVEN) PetscCall(SGS_DD_ModelSetup(ceed, user, ceed_data, problem)); @@ -649,8 +655,8 @@ PetscErrorCode SetupLibceed(Ceed ceed, CeedData ceed_data, DM dm, User user, App if (app_ctx->turb_spanstats_enable) PetscCall(TurbulenceStatisticsSetup(ceed, user, ceed_data, problem)); if (app_ctx->diff_filter_monitor) PetscCall(DifferentialFilterSetup(ceed, user, ceed_data, problem)); - CeedElemRestrictionDestroy(&elem_restr_jd_i); - CeedOperatorDestroy(&op_ijacobian_vol); - CeedVectorDestroy(&jac_data); + PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_jd_i)); + PetscCallCeed(ceed, CeedOperatorDestroy(&op_ijacobian_vol)); + PetscCallCeed(ceed, CeedVectorDestroy(&jac_data)); PetscFunctionReturn(PETSC_SUCCESS); } diff --git a/examples/fluids/src/setupts.c b/examples/fluids/src/setupts.c index f789f58f72..869a358467 100644 --- a/examples/fluids/src/setupts.c +++ b/examples/fluids/src/setupts.c @@ -25,17 +25,17 @@ PetscErrorCode ComputeLumpedMassMatrix(Ceed ceed, DM dm, CeedData ceed_data, Vec PetscFunctionBeginUser; // CEED Restriction - CeedElemRestrictionGetNumComponents(ceed_data->elem_restr_q, &num_comp_q); - CeedElemRestrictionGetNumComponents(ceed_data->elem_restr_qd_i, &q_data_size); + PetscCallCeed(ceed, CeedElemRestrictionGetNumComponents(ceed_data->elem_restr_q, &num_comp_q)); + PetscCallCeed(ceed, CeedElemRestrictionGetNumComponents(ceed_data->elem_restr_qd_i, &q_data_size)); // CEED QFunction PetscCall(CreateMassQFunction(ceed, num_comp_q, q_data_size, &qf_mass)); // CEED Operator - CeedOperatorCreate(ceed, qf_mass, NULL, NULL, &op_mass); - CeedOperatorSetField(op_mass, "u", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_mass, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, ceed_data->q_data); - CeedOperatorSetField(op_mass, "v", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE); + PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_mass, NULL, NULL, &op_mass)); + PetscCallCeed(ceed, CeedOperatorSetField(op_mass, "u", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorSetField(op_mass, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, ceed_data->q_data)); + PetscCallCeed(ceed, CeedOperatorSetField(op_mass, "v", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE)); PetscCall(OperatorApplyContextCreate(NULL, dm, ceed, op_mass, NULL, NULL, NULL, NULL, &op_mass_ctx)); @@ -49,8 +49,8 @@ PetscErrorCode ComputeLumpedMassMatrix(Ceed ceed, DM dm, CeedData ceed_data, Vec // Cleanup PetscCall(OperatorApplyContextDestroy(op_mass_ctx)); PetscCall(DMRestoreLocalVector(dm, &Ones_loc)); - CeedQFunctionDestroy(&qf_mass); - CeedOperatorDestroy(&op_mass); + PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_mass)); + PetscCallCeed(ceed, CeedOperatorDestroy(&op_mass)); PetscFunctionReturn(PETSC_SUCCESS); } @@ -67,7 +67,7 @@ PetscErrorCode UpdateBoundaryValues(User user, Vec Q_loc, PetscReal t) { // @brief Update the context label value to new value if necessary. // @note This only supports labels with scalar label values (ie. not arrays) -PetscErrorCode UpdateContextLabel(MPI_Comm comm, PetscScalar update_value, CeedOperator op, CeedContextFieldLabel label) { +PetscErrorCode UpdateContextLabel(Ceed ceed, MPI_Comm comm, PetscScalar update_value, CeedOperator op, CeedContextFieldLabel label) { PetscScalar label_value; PetscFunctionBeginUser; @@ -76,15 +76,15 @@ PetscErrorCode UpdateContextLabel(MPI_Comm comm, PetscScalar update_value, CeedO { size_t num_elements; const PetscScalar *label_values; - CeedOperatorGetContextDoubleRead(op, label, &num_elements, &label_values); + PetscCallCeed(ceed, CeedOperatorGetContextDoubleRead(op, label, &num_elements, &label_values)); PetscCheck(num_elements == 1, comm, PETSC_ERR_SUP, "%s does not support labels with more than 1 value. Label has %zu values", __func__, num_elements); label_value = *label_values; - CeedOperatorRestoreContextDoubleRead(op, label, &label_values); + PetscCallCeed(ceed, CeedOperatorRestoreContextDoubleRead(op, label, &label_values)); } if (label_value != update_value) { - CeedOperatorSetContextDouble(op, label, &update_value); + PetscCallCeed(ceed, CeedOperatorSetContextDouble(op, label, &update_value)); } PetscFunctionReturn(PETSC_SUCCESS); } @@ -101,9 +101,9 @@ PetscErrorCode RHS_NS(TS ts, PetscReal t, Vec Q, Vec G, void *user_data) { // Update time dependent data PetscCall(UpdateBoundaryValues(user, Q_loc, t)); - if (user->phys->solution_time_label) PetscCall(UpdateContextLabel(comm, t, user->op_rhs_ctx->op, user->phys->solution_time_label)); + if (user->phys->solution_time_label) PetscCall(UpdateContextLabel(user->ceed, comm, t, user->op_rhs_ctx->op, user->phys->solution_time_label)); PetscCall(TSGetTimeStep(ts, &dt)); - if (user->phys->timestep_size_label) PetscCall(UpdateContextLabel(comm, dt, user->op_rhs_ctx->op, user->phys->timestep_size_label)); + if (user->phys->timestep_size_label) PetscCall(UpdateContextLabel(user->ceed, comm, dt, user->op_rhs_ctx->op, user->phys->timestep_size_label)); PetscCall(ApplyCeedOperatorGlobalToGlobal(Q, G, user->op_rhs_ctx)); @@ -174,9 +174,9 @@ PetscErrorCode IFunction_NS(TS ts, PetscReal t, Vec Q, Vec Q_dot, Vec G, void *u // Update time dependent data PetscCall(UpdateBoundaryValues(user, Q_loc, t)); - if (user->phys->solution_time_label) PetscCall(UpdateContextLabel(comm, t, user->op_ifunction, user->phys->solution_time_label)); + if (user->phys->solution_time_label) PetscCall(UpdateContextLabel(user->ceed, comm, t, user->op_ifunction, user->phys->solution_time_label)); PetscCall(TSGetTimeStep(ts, &dt)); - if (user->phys->timestep_size_label) PetscCall(UpdateContextLabel(comm, dt, user->op_ifunction, user->phys->timestep_size_label)); + if (user->phys->timestep_size_label) PetscCall(UpdateContextLabel(user->ceed, comm, dt, user->op_ifunction, user->phys->timestep_size_label)); // Global-to-local PetscCall(DMGlobalToLocalBegin(user->dm, Q, INSERT_VALUES, Q_loc)); @@ -192,7 +192,7 @@ PetscErrorCode IFunction_NS(TS ts, PetscReal t, Vec Q, Vec Q_dot, Vec G, void *u // Apply CEED operator PetscCall(PetscLogEventBegin(FLUIDS_CeedOperatorApply, Q, G, 0, 0)); PetscCall(PetscLogGpuTimeBegin()); - CeedOperatorApply(user->op_ifunction, user->q_ceed, user->g_ceed, CEED_REQUEST_IMMEDIATE); + PetscCallCeed(user->ceed, CeedOperatorApply(user->op_ifunction, user->q_ceed, user->g_ceed, CEED_REQUEST_IMMEDIATE)); PetscCall(PetscLogGpuTimeEnd()); PetscCall(PetscLogEventEnd(FLUIDS_CeedOperatorApply, Q, G, 0, 0)); @@ -222,7 +222,7 @@ static PetscErrorCode FormPreallocation(User user, PetscBool pbdiagonal, Mat J, PetscFunctionBeginUser; if (pbdiagonal) { CeedSize l_size; - CeedOperatorGetActiveVectorLengths(user->op_ijacobian, &l_size, NULL); + PetscCallCeed(user->ceed, CeedOperatorGetActiveVectorLengths(user->op_ijacobian, &l_size, NULL)); ncoo = l_size * 5; rows_petsc = malloc(ncoo * sizeof(rows_petsc)); cols_petsc = malloc(ncoo * sizeof(cols_petsc)); @@ -236,14 +236,14 @@ static PetscErrorCode FormPreallocation(User user, PetscBool pbdiagonal, Mat J, } } else { CeedInt *rows_ceed, *cols_ceed; - PetscCall(CeedOperatorLinearAssembleSymbolic(user->op_ijacobian, &ncoo, &rows_ceed, &cols_ceed)); + PetscCallCeed(user->ceed, CeedOperatorLinearAssembleSymbolic(user->op_ijacobian, &ncoo, &rows_ceed, &cols_ceed)); PetscCall(IntArrayC2P(ncoo, &rows_ceed, &rows_petsc)); PetscCall(IntArrayC2P(ncoo, &cols_ceed, &cols_petsc)); } PetscCall(MatSetPreallocationCOOLocal(J, ncoo, rows_petsc, cols_petsc)); free(rows_petsc); free(cols_petsc); - CeedVectorCreate(user->ceed, ncoo, coo_values); + PetscCallCeed(user->ceed, CeedVectorCreate(user->ceed, ncoo, coo_values)); PetscFunctionReturn(PETSC_SUCCESS); } @@ -258,27 +258,29 @@ static PetscErrorCode FormSetValues(User user, PetscBool pbdiagonal, Mat J, Ceed if (pbdiagonal) { PetscCall(PetscLogEventBegin(FLUIDS_CeedOperatorAssemblePointBlockDiagonal, J, 0, 0, 0)); PetscCall(PetscLogGpuTimeBegin()); - CeedOperatorLinearAssemblePointBlockDiagonal(user->op_ijacobian, coo_values, CEED_REQUEST_IMMEDIATE); + PetscCallCeed(user->ceed, CeedOperatorLinearAssemblePointBlockDiagonal(user->op_ijacobian, coo_values, CEED_REQUEST_IMMEDIATE)); PetscCall(PetscLogGpuTimeEnd()); PetscCall(PetscLogEventEnd(FLUIDS_CeedOperatorAssemblePointBlockDiagonal, J, 0, 0, 0)); } else { PetscCall(PetscLogEventBegin(FLUIDS_CeedOperatorAssemble, J, 0, 0, 0)); PetscCall(PetscLogGpuTimeBegin()); - CeedOperatorLinearAssemble(user->op_ijacobian, coo_values); + PetscCallCeed(user->ceed, CeedOperatorLinearAssemble(user->op_ijacobian, coo_values)); PetscCall(PetscLogGpuTimeEnd()); PetscCall(PetscLogEventEnd(FLUIDS_CeedOperatorAssemble, J, 0, 0, 0)); } - CeedVectorGetArrayRead(coo_values, mem_type, &values); + PetscCallCeed(user->ceed, CeedVectorGetArrayRead(coo_values, mem_type, &values)); PetscCall(MatSetValuesCOO(J, values, INSERT_VALUES)); - CeedVectorRestoreArrayRead(coo_values, &values); + PetscCallCeed(user->ceed, CeedVectorRestoreArrayRead(coo_values, &values)); PetscFunctionReturn(PETSC_SUCCESS); } PetscErrorCode FormIJacobian_NS(TS ts, PetscReal t, Vec Q, Vec Q_dot, PetscReal shift, Mat J, Mat J_pre, void *user_data) { User user = *(User *)user_data; + Ceed ceed = user->ceed; PetscBool J_is_shell, J_is_mffd, J_pre_is_shell; PetscFunctionBeginUser; - if (user->phys->ijacobian_time_shift_label) CeedOperatorSetContextDouble(user->op_ijacobian, user->phys->ijacobian_time_shift_label, &shift); + if (user->phys->ijacobian_time_shift_label) + PetscCallCeed(ceed, CeedOperatorSetContextDouble(user->op_ijacobian, user->phys->ijacobian_time_shift_label, &shift)); PetscCall(PetscObjectTypeCompare((PetscObject)J, MATMFFD, &J_is_mffd)); PetscCall(PetscObjectTypeCompare((PetscObject)J, MATSHELL, &J_is_shell)); PetscCall(PetscObjectTypeCompare((PetscObject)J_pre, MATSHELL, &J_pre_is_shell)); @@ -500,7 +502,8 @@ PetscErrorCode TSSolve_NS(DM dm, User user, AppCtx app_ctx, Physics phys, Vec *Q if (app_ctx->turb_spanstats_enable) { PetscCall(TSMonitorSet(*ts, TSMonitor_TurbulenceStatistics, user, NULL)); CeedScalar previous_time = app_ctx->cont_time * user->units->second; - CeedOperatorSetContextDouble(user->spanstats.op_stats_collect_ctx->op, user->spanstats.previous_time_label, &previous_time); + PetscCallCeed(user->ceed, + CeedOperatorSetContextDouble(user->spanstats.op_stats_collect_ctx->op, user->spanstats.previous_time_label, &previous_time)); } if (app_ctx->diff_filter_monitor) PetscCall(TSMonitorSet(*ts, TSMonitor_DifferentialFilter, user, NULL)); diff --git a/examples/fluids/src/strong_boundary_conditions.c b/examples/fluids/src/strong_boundary_conditions.c index 8cd11b281e..eb9ab64f73 100644 --- a/examples/fluids/src/strong_boundary_conditions.c +++ b/examples/fluids/src/strong_boundary_conditions.c @@ -28,17 +28,17 @@ PetscErrorCode SetupStrongSTG_Ceed(Ceed ceed, CeedData ceed_data, DM dm, Problem // Basis CeedInt height = 1; - PetscCall(CeedBasisCreateProjection(ceed_data->basis_x_sur, ceed_data->basis_q_sur, &basis_x_to_q_sur)); + PetscCallCeed(ceed, CeedBasisCreateProjection(ceed_data->basis_x_sur, ceed_data->basis_q_sur, &basis_x_to_q_sur)); // --- Get number of quadrature points for the boundaries CeedInt num_qpts_sur; - CeedBasisGetNumQuadraturePoints(ceed_data->basis_q_sur, &num_qpts_sur); + PetscCallCeed(ceed, CeedBasisGetNumQuadraturePoints(ceed_data->basis_q_sur, &num_qpts_sur)); // Setup QFunction - CeedQFunctionCreateInterior(ceed, 1, SetupStrongBC, SetupStrongBC_loc, &qf_setup); - CeedQFunctionAddInput(qf_setup, "x", num_comp_x, CEED_EVAL_INTERP); - CeedQFunctionAddInput(qf_setup, "multiplicity", num_comp_q, CEED_EVAL_NONE); - CeedQFunctionAddOutput(qf_setup, "x stored", num_comp_x, CEED_EVAL_NONE); - CeedQFunctionAddOutput(qf_setup, "scale", 1, CEED_EVAL_NONE); + PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, SetupStrongBC, SetupStrongBC_loc, &qf_setup)); + PetscCallCeed(ceed, CeedQFunctionAddInput(qf_setup, "x", num_comp_x, CEED_EVAL_INTERP)); + PetscCallCeed(ceed, CeedQFunctionAddInput(qf_setup, "multiplicity", num_comp_q, CEED_EVAL_NONE)); + PetscCallCeed(ceed, CeedQFunctionAddOutput(qf_setup, "x stored", num_comp_x, CEED_EVAL_NONE)); + PetscCallCeed(ceed, CeedQFunctionAddOutput(qf_setup, "scale", 1, CEED_EVAL_NONE)); // Setup STG Setup QFunction PetscCall(SetupStrongSTG_PreProcessing(ceed, problem, num_comp_x, stg_data_size, q_data_size_sur, &qf_stgdata)); @@ -47,88 +47,90 @@ PetscErrorCode SetupStrongSTG_Ceed(Ceed ceed, CeedData ceed_data, DM dm, Problem for (CeedInt i = 0; i < bc->num_inflow; i++) { // -- Restrictions PetscCall(GetRestrictionForDomain(ceed, dm, height, domain_label, bc->inflows[i], 0, -1, -1, &elem_restr_q_sur, &elem_restr_x_sur, NULL)); - CeedElemRestrictionCreateVector(elem_restr_q_sur, &multiplicity, NULL); - CeedElemRestrictionGetMultiplicity(elem_restr_q_sur, multiplicity); - CeedElemRestrictionGetNumElements(elem_restr_q_sur, &num_elem); - CeedElemRestrictionGetElementSize(elem_restr_q_sur, &elem_size); + PetscCallCeed(ceed, CeedElemRestrictionCreateVector(elem_restr_q_sur, &multiplicity, NULL)); + PetscCallCeed(ceed, CeedElemRestrictionGetMultiplicity(elem_restr_q_sur, multiplicity)); + PetscCallCeed(ceed, CeedElemRestrictionGetNumElements(elem_restr_q_sur, &num_elem)); + PetscCallCeed(ceed, CeedElemRestrictionGetElementSize(elem_restr_q_sur, &elem_size)); PetscCall(GetRestrictionForDomain(ceed, dm, height, domain_label, bc->inflows[i], 0, elem_size, q_data_size_sur, NULL, NULL, &elem_restr_qd_sur)); - CeedElemRestrictionCreateStrided(ceed, num_elem, elem_size, num_comp_x, num_elem * elem_size * num_comp_x, CEED_STRIDES_BACKEND, - &elem_restr_x_stored); - CeedElemRestrictionCreateVector(elem_restr_x_stored, &x_stored, NULL); + PetscCallCeed(ceed, CeedElemRestrictionCreateStrided(ceed, num_elem, elem_size, num_comp_x, num_elem * elem_size * num_comp_x, + CEED_STRIDES_BACKEND, &elem_restr_x_stored)); + PetscCallCeed(ceed, CeedElemRestrictionCreateVector(elem_restr_x_stored, &x_stored, NULL)); - CeedElemRestrictionCreateStrided(ceed, num_elem, elem_size, 1, num_elem * elem_size, CEED_STRIDES_BACKEND, &elem_restr_scale); - CeedElemRestrictionCreateVector(elem_restr_scale, &scale_stored, NULL); + PetscCallCeed(ceed, + CeedElemRestrictionCreateStrided(ceed, num_elem, elem_size, 1, num_elem * elem_size, CEED_STRIDES_BACKEND, &elem_restr_scale)); + PetscCallCeed(ceed, CeedElemRestrictionCreateVector(elem_restr_scale, &scale_stored, NULL)); - CeedElemRestrictionCreateStrided(ceed, num_elem, elem_size, stg_data_size, num_elem * elem_size, CEED_STRIDES_BACKEND, &elem_restr_stgdata); - CeedElemRestrictionCreateVector(elem_restr_stgdata, &stg_data, NULL); + PetscCallCeed(ceed, CeedElemRestrictionCreateStrided(ceed, num_elem, elem_size, stg_data_size, num_elem * elem_size, CEED_STRIDES_BACKEND, + &elem_restr_stgdata)); + PetscCallCeed(ceed, CeedElemRestrictionCreateVector(elem_restr_stgdata, &stg_data, NULL)); - CeedVectorCreate(ceed, q_data_size_sur * num_elem * elem_size, &q_data_sur); + PetscCallCeed(ceed, CeedVectorCreate(ceed, q_data_size_sur * num_elem * elem_size, &q_data_sur)); // -- Setup Operator - CeedOperatorCreate(ceed, qf_setup, NULL, NULL, &op_setup); - CeedOperatorSetName(op_setup, "surface geometric data"); - CeedOperatorSetField(op_setup, "x", elem_restr_x_sur, basis_x_to_q_sur, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_setup, "multiplicity", elem_restr_q_sur, CEED_BASIS_COLLOCATED, multiplicity); - CeedOperatorSetField(op_setup, "x stored", elem_restr_x_stored, CEED_BASIS_COLLOCATED, x_stored); - CeedOperatorSetField(op_setup, "scale", elem_restr_scale, CEED_BASIS_COLLOCATED, scale_stored); + PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_setup, NULL, NULL, &op_setup)); + PetscCallCeed(ceed, CeedOperatorSetName(op_setup, "surface geometric data")); + PetscCallCeed(ceed, CeedOperatorSetField(op_setup, "x", elem_restr_x_sur, basis_x_to_q_sur, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorSetField(op_setup, "multiplicity", elem_restr_q_sur, CEED_BASIS_COLLOCATED, multiplicity)); + PetscCallCeed(ceed, CeedOperatorSetField(op_setup, "x stored", elem_restr_x_stored, CEED_BASIS_COLLOCATED, x_stored)); + PetscCallCeed(ceed, CeedOperatorSetField(op_setup, "scale", elem_restr_scale, CEED_BASIS_COLLOCATED, scale_stored)); // -- Compute geometric factors - CeedOperatorApply(op_setup, ceed_data->x_coord, CEED_VECTOR_NONE, CEED_REQUEST_IMMEDIATE); + PetscCallCeed(ceed, CeedOperatorApply(op_setup, ceed_data->x_coord, CEED_VECTOR_NONE, CEED_REQUEST_IMMEDIATE)); // -- Compute QData for the surface - CeedOperatorCreate(ceed, ceed_data->qf_setup_sur, NULL, NULL, &op_setup_sur); - CeedOperatorSetField(op_setup_sur, "dx", elem_restr_x_sur, ceed_data->basis_xc_sur, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_setup_sur, "weight", CEED_ELEMRESTRICTION_NONE, ceed_data->basis_xc_sur, CEED_VECTOR_NONE); - CeedOperatorSetField(op_setup_sur, "surface qdata", elem_restr_qd_sur, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); + PetscCallCeed(ceed, CeedOperatorCreate(ceed, ceed_data->qf_setup_sur, NULL, NULL, &op_setup_sur)); + PetscCallCeed(ceed, CeedOperatorSetField(op_setup_sur, "dx", elem_restr_x_sur, ceed_data->basis_xc_sur, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorSetField(op_setup_sur, "weight", CEED_ELEMRESTRICTION_NONE, ceed_data->basis_xc_sur, CEED_VECTOR_NONE)); + PetscCallCeed(ceed, CeedOperatorSetField(op_setup_sur, "surface qdata", elem_restr_qd_sur, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE)); - CeedOperatorApply(op_setup_sur, ceed_data->x_coord, q_data_sur, CEED_REQUEST_IMMEDIATE); + PetscCallCeed(ceed, CeedOperatorApply(op_setup_sur, ceed_data->x_coord, q_data_sur, CEED_REQUEST_IMMEDIATE)); // -- Compute STGData - CeedOperatorCreate(ceed, qf_stgdata, NULL, NULL, &op_stgdata); - CeedOperatorSetField(op_stgdata, "surface qdata", elem_restr_qd_sur, CEED_BASIS_COLLOCATED, q_data_sur); - CeedOperatorSetField(op_stgdata, "x", elem_restr_x_stored, CEED_BASIS_COLLOCATED, x_stored); - CeedOperatorSetField(op_stgdata, "stg data", elem_restr_stgdata, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); + PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_stgdata, NULL, NULL, &op_stgdata)); + PetscCallCeed(ceed, CeedOperatorSetField(op_stgdata, "surface qdata", elem_restr_qd_sur, CEED_BASIS_COLLOCATED, q_data_sur)); + PetscCallCeed(ceed, CeedOperatorSetField(op_stgdata, "x", elem_restr_x_stored, CEED_BASIS_COLLOCATED, x_stored)); + PetscCallCeed(ceed, CeedOperatorSetField(op_stgdata, "stg data", elem_restr_stgdata, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE)); - CeedOperatorApply(op_stgdata, CEED_VECTOR_NONE, stg_data, CEED_REQUEST_IMMEDIATE); + PetscCallCeed(ceed, CeedOperatorApply(op_stgdata, CEED_VECTOR_NONE, stg_data, CEED_REQUEST_IMMEDIATE)); // -- Setup BC QFunctions SetupStrongSTG_QF(ceed, problem, num_comp_x, num_comp_q, stg_data_size, q_data_size_sur, &qf_strongbc); - CeedOperatorCreate(ceed, qf_strongbc, NULL, NULL, &op_strong_bc_sub); - CeedOperatorSetName(op_strong_bc_sub, "Strong STG"); + PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_strongbc, NULL, NULL, &op_strong_bc_sub)); + PetscCallCeed(ceed, CeedOperatorSetName(op_strong_bc_sub, "Strong STG")); - CeedOperatorSetField(op_strong_bc_sub, "surface qdata", elem_restr_qd_sur, CEED_BASIS_COLLOCATED, q_data_sur); - CeedOperatorSetField(op_strong_bc_sub, "x", elem_restr_x_stored, CEED_BASIS_COLLOCATED, x_stored); - CeedOperatorSetField(op_strong_bc_sub, "scale", elem_restr_scale, CEED_BASIS_COLLOCATED, scale_stored); - CeedOperatorSetField(op_strong_bc_sub, "stg data", elem_restr_stgdata, CEED_BASIS_COLLOCATED, stg_data); - CeedOperatorSetField(op_strong_bc_sub, "q", elem_restr_q_sur, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); + PetscCallCeed(ceed, CeedOperatorSetField(op_strong_bc_sub, "surface qdata", elem_restr_qd_sur, CEED_BASIS_COLLOCATED, q_data_sur)); + PetscCallCeed(ceed, CeedOperatorSetField(op_strong_bc_sub, "x", elem_restr_x_stored, CEED_BASIS_COLLOCATED, x_stored)); + PetscCallCeed(ceed, CeedOperatorSetField(op_strong_bc_sub, "scale", elem_restr_scale, CEED_BASIS_COLLOCATED, scale_stored)); + PetscCallCeed(ceed, CeedOperatorSetField(op_strong_bc_sub, "stg data", elem_restr_stgdata, CEED_BASIS_COLLOCATED, stg_data)); + PetscCallCeed(ceed, CeedOperatorSetField(op_strong_bc_sub, "q", elem_restr_q_sur, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE)); // -- Add to composite operator - CeedCompositeOperatorAddSub(op_strong_bc, op_strong_bc_sub); - - CeedVectorDestroy(&q_data_sur); - CeedVectorDestroy(&multiplicity); - CeedVectorDestroy(&x_stored); - CeedVectorDestroy(&scale_stored); - CeedVectorDestroy(&stg_data); - CeedElemRestrictionDestroy(&elem_restr_x_sur); - CeedElemRestrictionDestroy(&elem_restr_q_sur); - CeedElemRestrictionDestroy(&elem_restr_qd_sur); - CeedElemRestrictionDestroy(&elem_restr_x_stored); - CeedElemRestrictionDestroy(&elem_restr_scale); - CeedElemRestrictionDestroy(&elem_restr_stgdata); - CeedQFunctionDestroy(&qf_strongbc); - CeedQFunctionDestroy(&qf_stgdata); - CeedOperatorDestroy(&op_setup_sur); - CeedOperatorDestroy(&op_strong_bc_sub); - CeedOperatorDestroy(&op_setup); - CeedOperatorDestroy(&op_stgdata); + PetscCallCeed(ceed, CeedCompositeOperatorAddSub(op_strong_bc, op_strong_bc_sub)); + + PetscCallCeed(ceed, CeedVectorDestroy(&q_data_sur)); + PetscCallCeed(ceed, CeedVectorDestroy(&multiplicity)); + PetscCallCeed(ceed, CeedVectorDestroy(&x_stored)); + PetscCallCeed(ceed, CeedVectorDestroy(&scale_stored)); + PetscCallCeed(ceed, CeedVectorDestroy(&stg_data)); + PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_x_sur)); + PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_q_sur)); + PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_qd_sur)); + PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_x_stored)); + PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_scale)); + PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_stgdata)); + PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_strongbc)); + PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_stgdata)); + PetscCallCeed(ceed, CeedOperatorDestroy(&op_setup_sur)); + PetscCallCeed(ceed, CeedOperatorDestroy(&op_strong_bc_sub)); + PetscCallCeed(ceed, CeedOperatorDestroy(&op_setup)); + PetscCallCeed(ceed, CeedOperatorDestroy(&op_stgdata)); } - CeedOperatorGetContextFieldLabel(op_strong_bc, "solution time", &phys->stg_solution_time_label); + PetscCallCeed(ceed, CeedOperatorGetContextFieldLabel(op_strong_bc, "solution time", &phys->stg_solution_time_label)); - CeedBasisDestroy(&basis_x_to_q_sur); - CeedQFunctionDestroy(&qf_setup); + PetscCallCeed(ceed, CeedBasisDestroy(&basis_x_to_q_sur)); + PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_setup)); PetscFunctionReturn(PETSC_SUCCESS); } @@ -142,7 +144,7 @@ PetscErrorCode DMPlexInsertBoundaryValues_StrongBCCeed(DM dm, PetscBool insert_e PetscCall(DMGetApplicationContext(dm, &user)); if (user->phys->stg_solution_time_label) { - CeedOperatorSetContextDouble(user->op_strong_bc_ctx->op, user->phys->stg_solution_time_label, &time); + PetscCallCeed(user->ceed, CeedOperatorSetContextDouble(user->op_strong_bc_ctx->op, user->phys->stg_solution_time_label, &time)); } // Mask Strong BC entries @@ -171,7 +173,7 @@ PetscErrorCode SetupStrongBC_Ceed(Ceed ceed, CeedData ceed_data, DM dm, User use PetscCall(DMRestoreGlobalVector(dm, &global_vec)); } - CeedCompositeOperatorCreate(ceed, &op_strong_bc); + PetscCallCeed(ceed, CeedCompositeOperatorCreate(ceed, &op_strong_bc)); { PetscBool use_strongstg = PETSC_FALSE; PetscCall(PetscOptionsGetBool(NULL, NULL, "-stg_strong", &use_strongstg, NULL)); diff --git a/examples/fluids/src/turb_spanstats.c b/examples/fluids/src/turb_spanstats.c index 634226c615..564c9365c8 100644 --- a/examples/fluids/src/turb_spanstats.c +++ b/examples/fluids/src/turb_spanstats.c @@ -129,12 +129,12 @@ PetscErrorCode CreateElemRestrColloc(Ceed ceed, CeedInt num_comp, CeedBasis basi CeedInt num_elem_qpts, loc_num_elem; PetscFunctionBeginUser; - CeedBasisGetNumQuadraturePoints(basis, &num_elem_qpts); - CeedElemRestrictionGetNumElements(elem_restr_base, &loc_num_elem); + PetscCallCeed(ceed, CeedBasisGetNumQuadraturePoints(basis, &num_elem_qpts)); + PetscCallCeed(ceed, CeedElemRestrictionGetNumElements(elem_restr_base, &loc_num_elem)); const CeedInt strides[] = {num_comp, 1, num_elem_qpts * num_comp}; - CeedElemRestrictionCreateStrided(ceed, loc_num_elem, num_elem_qpts, num_comp, num_comp * loc_num_elem * num_elem_qpts, strides, - elem_restr_collocated); + PetscCallCeed(ceed, CeedElemRestrictionCreateStrided(ceed, loc_num_elem, num_elem_qpts, num_comp, num_comp * loc_num_elem * num_elem_qpts, strides, + elem_restr_collocated)); PetscFunctionReturn(PETSC_SUCCESS); } @@ -149,19 +149,19 @@ PetscErrorCode GetQuadratureCoords(Ceed ceed, DM dm, CeedElemRestriction elem_re PetscFunctionBeginUser; // Create Element Restriction and CeedVector for quadrature coordinates - CeedBasisGetNumQuadraturePoints(basis_x, &num_elem_qpts); - CeedElemRestrictionGetNumElements(elem_restr_x, &loc_num_elem); - CeedElemRestrictionGetNumComponents(elem_restr_x, &num_comp_x); + PetscCallCeed(ceed, CeedBasisGetNumQuadraturePoints(basis_x, &num_elem_qpts)); + PetscCallCeed(ceed, CeedElemRestrictionGetNumElements(elem_restr_x, &loc_num_elem)); + PetscCallCeed(ceed, CeedElemRestrictionGetNumComponents(elem_restr_x, &num_comp_x)); *total_nqpnts = num_elem_qpts * loc_num_elem; PetscCall(CreateElemRestrColloc(ceed, num_comp_x, basis_x, elem_restr_x, &elem_restr_qx)); // Create QFunction - CeedQFunctionCreateIdentity(ceed, num_comp_x, CEED_EVAL_INTERP, CEED_EVAL_NONE, &qf_quad_coords); + PetscCallCeed(ceed, CeedQFunctionCreateIdentity(ceed, num_comp_x, CEED_EVAL_INTERP, CEED_EVAL_NONE, &qf_quad_coords)); // Create Operator - CeedOperatorCreate(ceed, qf_quad_coords, NULL, NULL, &op_quad_coords); - CeedOperatorSetField(op_quad_coords, "input", elem_restr_x, basis_x, x_coords); - CeedOperatorSetField(op_quad_coords, "output", elem_restr_qx, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); + PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_quad_coords, NULL, NULL, &op_quad_coords)); + PetscCallCeed(ceed, CeedOperatorSetField(op_quad_coords, "input", elem_restr_x, basis_x, x_coords)); + PetscCallCeed(ceed, CeedOperatorSetField(op_quad_coords, "output", elem_restr_qx, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE)); PetscCall(CeedOperatorCreateLocalVecs(op_quad_coords, DMReturnVecType(dm), PetscObjectComm((PetscObject)dm), NULL, Qx_coords)); PetscCall(OperatorApplyContextCreate(NULL, NULL, ceed, op_quad_coords, CEED_VECTOR_NONE, NULL, NULL, NULL, &op_quad_coords_ctx)); @@ -169,9 +169,9 @@ PetscErrorCode GetQuadratureCoords(Ceed ceed, DM dm, CeedElemRestriction elem_re PetscCall(ApplyCeedOperatorLocalToLocal(NULL, *Qx_coords, op_quad_coords_ctx)); PetscCall(OperatorApplyContextDestroy(op_quad_coords_ctx)); - CeedElemRestrictionDestroy(&elem_restr_qx); - CeedQFunctionDestroy(&qf_quad_coords); - CeedOperatorDestroy(&op_quad_coords); + PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_qx)); + PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_quad_coords)); + PetscCallCeed(ceed, CeedOperatorDestroy(&op_quad_coords)); PetscFunctionReturn(PETSC_SUCCESS); } @@ -185,13 +185,13 @@ PetscErrorCode SpanStatsSetupDataCreate(Ceed ceed, User user, CeedData ceed_data PetscCall(PetscNew(stats_data)); PetscCall(DMGetDimension(dm, &dim)); - CeedBasisGetNumQuadraturePoints1D(ceed_data->basis_q, &num_qpts_child1d); + PetscCallCeed(ceed, CeedBasisGetNumQuadraturePoints1D(ceed_data->basis_q, &num_qpts_child1d)); CeedInt num_qpts_parent = CeedIntPow(num_qpts_child1d, dim); PetscCall(GetRestrictionForDomain(ceed, dm, 0, 0, 0, 0, num_qpts_parent, problem->q_data_size_sur, &(*stats_data)->elem_restr_parent_stats, &(*stats_data)->elem_restr_parent_x, &(*stats_data)->elem_restr_parent_qd)); - CeedElemRestrictionGetNumComponents((*stats_data)->elem_restr_parent_x, &num_comp_x); - CeedElemRestrictionCreateVector((*stats_data)->elem_restr_parent_x, &(*stats_data)->x_coord, NULL); - CeedElemRestrictionCreateVector((*stats_data)->elem_restr_parent_qd, &(*stats_data)->q_data, NULL); + PetscCallCeed(ceed, CeedElemRestrictionGetNumComponents((*stats_data)->elem_restr_parent_x, &num_comp_x)); + PetscCallCeed(ceed, CeedElemRestrictionCreateVector((*stats_data)->elem_restr_parent_x, &(*stats_data)->x_coord, NULL)); + PetscCallCeed(ceed, CeedElemRestrictionCreateVector((*stats_data)->elem_restr_parent_qd, &(*stats_data)->q_data, NULL)); { DM dm_coord; @@ -220,19 +220,21 @@ PetscErrorCode SpanStatsSetupDataCreate(Ceed ceed, User user, CeedData ceed_data } PetscErrorCode SpanStatsSetupDataDestroy(SpanStatsSetupData data) { - PetscFunctionBeginUser; + Ceed ceed; - CeedElemRestrictionDestroy(&data->elem_restr_parent_x); - CeedElemRestrictionDestroy(&data->elem_restr_parent_stats); - CeedElemRestrictionDestroy(&data->elem_restr_parent_qd); - CeedElemRestrictionDestroy(&data->elem_restr_parent_colloc); - CeedElemRestrictionDestroy(&data->elem_restr_child_colloc); + PetscFunctionBeginUser; + PetscCall(CeedElemRestrictionGetCeed(data->elem_restr_parent_x, &ceed)); + PetscCallCeed(ceed, CeedElemRestrictionDestroy(&data->elem_restr_parent_x)); + PetscCallCeed(ceed, CeedElemRestrictionDestroy(&data->elem_restr_parent_stats)); + PetscCallCeed(ceed, CeedElemRestrictionDestroy(&data->elem_restr_parent_qd)); + PetscCallCeed(ceed, CeedElemRestrictionDestroy(&data->elem_restr_parent_colloc)); + PetscCallCeed(ceed, CeedElemRestrictionDestroy(&data->elem_restr_child_colloc)); - CeedBasisDestroy(&data->basis_x); - CeedBasisDestroy(&data->basis_stats); + PetscCallCeed(ceed, CeedBasisDestroy(&data->basis_x)); + PetscCallCeed(ceed, CeedBasisDestroy(&data->basis_stats)); - CeedVectorDestroy(&data->x_coord); - CeedVectorDestroy(&data->q_data); + PetscCallCeed(ceed, CeedVectorDestroy(&data->x_coord)); + PetscCallCeed(ceed, CeedVectorDestroy(&data->q_data)); PetscCall(PetscFree(data)); PetscFunctionReturn(PETSC_SUCCESS); @@ -248,7 +250,7 @@ PetscErrorCode CreateStatsSF(Ceed ceed, CeedData ceed_data, SpanStatsSetupData s PetscCall(PetscSFCreate(PetscObjectComm((PetscObject)childdm), statssf)); // Assume that child and parent have the same number of components - CeedBasisGetNumComponents(ceed_data->basis_x, &num_comp_x); + PetscCallCeed(ceed, CeedBasisGetNumComponents(ceed_data->basis_x, &num_comp_x)); const PetscInt num_comp_sf = num_comp_x - 1; // Number of coord components used in the creation of the SF // Get quad_coords for child and parent DM @@ -297,32 +299,33 @@ PetscErrorCode SetupL2ProjectionStats(Ceed ceed, User user, CeedData ceed_data, // -- Create Operator for RHS of L^2 projection of statistics // Simply take collocated parent data (with quadrature weight already applied) and multiply by weight function. // Therefore, an Identity QF is sufficient - CeedQFunctionCreateIdentity(ceed, num_comp_stats, CEED_EVAL_NONE, CEED_EVAL_INTERP, &qf_stats_proj); + PetscCallCeed(ceed, CeedQFunctionCreateIdentity(ceed, num_comp_stats, CEED_EVAL_NONE, CEED_EVAL_INTERP, &qf_stats_proj)); - CeedOperatorCreate(ceed, qf_stats_proj, NULL, NULL, &op_proj_rhs); - CeedOperatorSetField(op_proj_rhs, "input", stats_data->elem_restr_parent_colloc, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_proj_rhs, "output", stats_data->elem_restr_parent_stats, stats_data->basis_stats, CEED_VECTOR_ACTIVE); + PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_stats_proj, NULL, NULL, &op_proj_rhs)); + PetscCallCeed(ceed, CeedOperatorSetField(op_proj_rhs, "input", stats_data->elem_restr_parent_colloc, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorSetField(op_proj_rhs, "output", stats_data->elem_restr_parent_stats, stats_data->basis_stats, CEED_VECTOR_ACTIVE)); PetscCall(OperatorApplyContextCreate(NULL, user->spanstats.dm, ceed, op_proj_rhs, NULL, NULL, NULL, NULL, &user->spanstats.op_proj_rhs_ctx)); PetscCall(CeedOperatorCreateLocalVecs(op_proj_rhs, DMReturnVecType(user->spanstats.dm), comm, &user->spanstats.Parent_Stats_loc, NULL)); // -- Setup LHS of L^2 projection // Get q_data for mass matrix operator - CeedOperatorCreate(ceed, ceed_data->qf_setup_sur, NULL, NULL, &op_setup_sur); - CeedOperatorSetField(op_setup_sur, "dx", stats_data->elem_restr_parent_x, stats_data->basis_x, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_setup_sur, "weight", CEED_ELEMRESTRICTION_NONE, stats_data->basis_x, CEED_VECTOR_NONE); - CeedOperatorSetField(op_setup_sur, "surface qdata", stats_data->elem_restr_parent_qd, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); - CeedOperatorApply(op_setup_sur, stats_data->x_coord, stats_data->q_data, CEED_REQUEST_IMMEDIATE); + PetscCallCeed(ceed, CeedOperatorCreate(ceed, ceed_data->qf_setup_sur, NULL, NULL, &op_setup_sur)); + PetscCallCeed(ceed, CeedOperatorSetField(op_setup_sur, "dx", stats_data->elem_restr_parent_x, stats_data->basis_x, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorSetField(op_setup_sur, "weight", CEED_ELEMRESTRICTION_NONE, stats_data->basis_x, CEED_VECTOR_NONE)); + PetscCallCeed(ceed, + CeedOperatorSetField(op_setup_sur, "surface qdata", stats_data->elem_restr_parent_qd, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorApply(op_setup_sur, stats_data->x_coord, stats_data->q_data, CEED_REQUEST_IMMEDIATE)); // CEED Restriction - CeedElemRestrictionGetNumComponents(stats_data->elem_restr_parent_qd, &q_data_size); + PetscCallCeed(ceed, CeedElemRestrictionGetNumComponents(stats_data->elem_restr_parent_qd, &q_data_size)); // Create Mass CeedOperator PetscCall(CreateMassQFunction(ceed, num_comp_stats, q_data_size, &qf_mass)); - CeedOperatorCreate(ceed, qf_mass, NULL, NULL, &op_mass); - CeedOperatorSetField(op_mass, "u", stats_data->elem_restr_parent_stats, stats_data->basis_stats, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_mass, "qdata", stats_data->elem_restr_parent_qd, CEED_BASIS_COLLOCATED, stats_data->q_data); - CeedOperatorSetField(op_mass, "v", stats_data->elem_restr_parent_stats, stats_data->basis_stats, CEED_VECTOR_ACTIVE); + PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_mass, NULL, NULL, &op_mass)); + PetscCallCeed(ceed, CeedOperatorSetField(op_mass, "u", stats_data->elem_restr_parent_stats, stats_data->basis_stats, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorSetField(op_mass, "qdata", stats_data->elem_restr_parent_qd, CEED_BASIS_COLLOCATED, stats_data->q_data)); + PetscCallCeed(ceed, CeedOperatorSetField(op_mass, "v", stats_data->elem_restr_parent_stats, stats_data->basis_stats, CEED_VECTOR_ACTIVE)); { // Setup KSP for L^2 projection OperatorApplyContext M_ctx; @@ -349,11 +352,11 @@ PetscErrorCode SetupL2ProjectionStats(Ceed ceed, User user, CeedData ceed_data, } // Cleanup - CeedQFunctionDestroy(&qf_mass); - CeedQFunctionDestroy(&qf_stats_proj); - CeedOperatorDestroy(&op_mass); - CeedOperatorDestroy(&op_setup_sur); - CeedOperatorDestroy(&op_proj_rhs); + PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_mass)); + PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_stats_proj)); + PetscCallCeed(ceed, CeedOperatorDestroy(&op_mass)); + PetscCallCeed(ceed, CeedOperatorDestroy(&op_setup_sur)); + PetscCallCeed(ceed, CeedOperatorDestroy(&op_proj_rhs)); PetscFunctionReturn(PETSC_SUCCESS); } @@ -367,57 +370,58 @@ PetscErrorCode CreateStatisticCollectionOperator(Ceed ceed, User user, CeedData CeedOperator op_stats_collect; PetscFunctionBeginUser; - CeedBasisGetNumComponents(ceed_data->basis_q, &num_comp_q); + PetscCallCeed(ceed, CeedBasisGetNumComponents(ceed_data->basis_q, &num_comp_q)); // Create Operator for statistics collection switch (user->phys->state_var) { case STATEVAR_PRIMITIVE: - CeedQFunctionCreateInterior(ceed, 1, ChildStatsCollection_Prim, ChildStatsCollection_Prim_loc, &qf_stats_collect); + PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, ChildStatsCollection_Prim, ChildStatsCollection_Prim_loc, &qf_stats_collect)); break; case STATEVAR_CONSERVATIVE: - CeedQFunctionCreateInterior(ceed, 1, ChildStatsCollection_Conserv, ChildStatsCollection_Conserv_loc, &qf_stats_collect); + PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, ChildStatsCollection_Conserv, ChildStatsCollection_Conserv_loc, &qf_stats_collect)); break; default: SETERRQ(PetscObjectComm((PetscObject)user->dm), PETSC_ERR_SUP, "No statisics collection available for chosen state variable"); } if (user->spanstats.do_mms_test) { - CeedQFunctionDestroy(&qf_stats_collect); - CeedQFunctionCreateInterior(ceed, 1, ChildStatsCollectionMMSTest, ChildStatsCollectionMMSTest_loc, &qf_stats_collect); + PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_stats_collect)); + PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, ChildStatsCollectionMMSTest, ChildStatsCollectionMMSTest_loc, &qf_stats_collect)); } { // Setup Collection Context PetscCall(PetscNew(&collect_ctx)); - CeedQFunctionContextGetData(problem->apply_vol_rhs.qfunction_context, CEED_MEM_HOST, &newtonian_ig_ctx); + PetscCallCeed(ceed, CeedQFunctionContextGetData(problem->apply_vol_rhs.qfunction_context, CEED_MEM_HOST, &newtonian_ig_ctx)); collect_ctx->gas = *newtonian_ig_ctx; - CeedQFunctionContextCreate(user->ceed, &collect_context); - CeedQFunctionContextSetData(collect_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*collect_ctx), collect_ctx); - CeedQFunctionContextSetDataDestroy(collect_context, CEED_MEM_HOST, FreeContextPetsc); + PetscCallCeed(ceed, CeedQFunctionContextCreate(user->ceed, &collect_context)); + PetscCallCeed(ceed, CeedQFunctionContextSetData(collect_context, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*collect_ctx), collect_ctx)); + PetscCallCeed(ceed, CeedQFunctionContextSetDataDestroy(collect_context, CEED_MEM_HOST, FreeContextPetsc)); - CeedQFunctionContextRegisterDouble(collect_context, "solution time", offsetof(struct Turbulence_SpanStatsContext_, solution_time), 1, - "Current solution time"); - CeedQFunctionContextRegisterDouble(collect_context, "previous time", offsetof(struct Turbulence_SpanStatsContext_, previous_time), 1, - "Previous time statistics collection was done"); + PetscCallCeed(ceed, CeedQFunctionContextRegisterDouble(collect_context, "solution time", + offsetof(struct Turbulence_SpanStatsContext_, solution_time), 1, "Current solution time")); + PetscCallCeed( + ceed, CeedQFunctionContextRegisterDouble(collect_context, "previous time", offsetof(struct Turbulence_SpanStatsContext_, previous_time), 1, + "Previous time statistics collection was done")); - CeedQFunctionContextRestoreData(problem->apply_vol_rhs.qfunction_context, &newtonian_ig_ctx); + PetscCallCeed(ceed, CeedQFunctionContextRestoreData(problem->apply_vol_rhs.qfunction_context, &newtonian_ig_ctx)); } - CeedQFunctionSetContext(qf_stats_collect, collect_context); - CeedQFunctionContextDestroy(&collect_context); - CeedQFunctionAddInput(qf_stats_collect, "q", num_comp_q, CEED_EVAL_INTERP); - CeedQFunctionAddInput(qf_stats_collect, "q_data", problem->q_data_size_vol, CEED_EVAL_NONE); - CeedQFunctionAddInput(qf_stats_collect, "x", num_comp_x, CEED_EVAL_INTERP); - CeedQFunctionAddOutput(qf_stats_collect, "v", num_comp_stats, CEED_EVAL_NONE); + PetscCallCeed(ceed, CeedQFunctionSetContext(qf_stats_collect, collect_context)); + PetscCallCeed(ceed, CeedQFunctionContextDestroy(&collect_context)); + PetscCallCeed(ceed, CeedQFunctionAddInput(qf_stats_collect, "q", num_comp_q, CEED_EVAL_INTERP)); + PetscCallCeed(ceed, CeedQFunctionAddInput(qf_stats_collect, "q_data", problem->q_data_size_vol, CEED_EVAL_NONE)); + PetscCallCeed(ceed, CeedQFunctionAddInput(qf_stats_collect, "x", num_comp_x, CEED_EVAL_INTERP)); + PetscCallCeed(ceed, CeedQFunctionAddOutput(qf_stats_collect, "v", num_comp_stats, CEED_EVAL_NONE)); - CeedOperatorCreate(ceed, qf_stats_collect, NULL, NULL, &op_stats_collect); - CeedOperatorSetField(op_stats_collect, "q", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_stats_collect, "q_data", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, ceed_data->q_data); - CeedOperatorSetField(op_stats_collect, "x", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord); - CeedOperatorSetField(op_stats_collect, "v", stats_data->elem_restr_child_colloc, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); + PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_stats_collect, NULL, NULL, &op_stats_collect)); + PetscCallCeed(ceed, CeedOperatorSetField(op_stats_collect, "q", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorSetField(op_stats_collect, "q_data", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, ceed_data->q_data)); + PetscCallCeed(ceed, CeedOperatorSetField(op_stats_collect, "x", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord)); + PetscCallCeed(ceed, CeedOperatorSetField(op_stats_collect, "v", stats_data->elem_restr_child_colloc, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE)); - CeedOperatorGetContextFieldLabel(op_stats_collect, "solution time", &user->spanstats.solution_time_label); - CeedOperatorGetContextFieldLabel(op_stats_collect, "previous time", &user->spanstats.previous_time_label); + PetscCallCeed(ceed, CeedOperatorGetContextFieldLabel(op_stats_collect, "solution time", &user->spanstats.solution_time_label)); + PetscCallCeed(ceed, CeedOperatorGetContextFieldLabel(op_stats_collect, "previous time", &user->spanstats.previous_time_label)); PetscCall(OperatorApplyContextCreate(user->dm, user->spanstats.dm, user->ceed, op_stats_collect, user->q_ceed, NULL, NULL, NULL, &user->spanstats.op_stats_collect_ctx)); @@ -426,8 +430,8 @@ PetscErrorCode CreateStatisticCollectionOperator(Ceed ceed, User user, CeedData &user->spanstats.Child_Stats_loc)); PetscCall(VecZeroEntries(user->spanstats.Child_Stats_loc)); - CeedQFunctionDestroy(&qf_stats_collect); - CeedOperatorDestroy(&op_stats_collect); + PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_stats_collect)); + PetscCallCeed(ceed, CeedOperatorDestroy(&op_stats_collect)); PetscFunctionReturn(PETSC_SUCCESS); } @@ -439,30 +443,30 @@ PetscErrorCode SetupMMSErrorChecking(Ceed ceed, User user, CeedData ceed_data, S CeedVector x_ceed, y_ceed; PetscFunctionBeginUser; - CeedElemRestrictionGetNumComponents(stats_data->elem_restr_parent_qd, &q_data_size); - CeedBasisGetNumComponents(stats_data->basis_x, &num_comp_x); + PetscCallCeed(ceed, CeedElemRestrictionGetNumComponents(stats_data->elem_restr_parent_qd, &q_data_size)); + PetscCallCeed(ceed, CeedBasisGetNumComponents(stats_data->basis_x, &num_comp_x)); - CeedQFunctionCreateInterior(ceed, 1, ChildStatsCollectionMMSTest_Error, ChildStatsCollectionMMSTest_Error_loc, &qf_error); - CeedQFunctionAddInput(qf_error, "q", num_comp_stats, CEED_EVAL_INTERP); - CeedQFunctionAddInput(qf_error, "qdata", q_data_size, CEED_EVAL_NONE); - CeedQFunctionAddInput(qf_error, "x", num_comp_x, CEED_EVAL_INTERP); - CeedQFunctionAddOutput(qf_error, "v", num_comp_stats, CEED_EVAL_INTERP); + PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, ChildStatsCollectionMMSTest_Error, ChildStatsCollectionMMSTest_Error_loc, &qf_error)); + PetscCallCeed(ceed, CeedQFunctionAddInput(qf_error, "q", num_comp_stats, CEED_EVAL_INTERP)); + PetscCallCeed(ceed, CeedQFunctionAddInput(qf_error, "qdata", q_data_size, CEED_EVAL_NONE)); + PetscCallCeed(ceed, CeedQFunctionAddInput(qf_error, "x", num_comp_x, CEED_EVAL_INTERP)); + PetscCallCeed(ceed, CeedQFunctionAddOutput(qf_error, "v", num_comp_stats, CEED_EVAL_INTERP)); - CeedOperatorCreate(ceed, qf_error, NULL, NULL, &op_error); - CeedOperatorSetField(op_error, "q", stats_data->elem_restr_parent_stats, stats_data->basis_stats, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_error, "qdata", stats_data->elem_restr_parent_qd, CEED_BASIS_COLLOCATED, stats_data->q_data); - CeedOperatorSetField(op_error, "x", stats_data->elem_restr_parent_x, stats_data->basis_x, stats_data->x_coord); - CeedOperatorSetField(op_error, "v", stats_data->elem_restr_parent_stats, stats_data->basis_stats, CEED_VECTOR_ACTIVE); + PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_error, NULL, NULL, &op_error)); + PetscCallCeed(ceed, CeedOperatorSetField(op_error, "q", stats_data->elem_restr_parent_stats, stats_data->basis_stats, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorSetField(op_error, "qdata", stats_data->elem_restr_parent_qd, CEED_BASIS_COLLOCATED, stats_data->q_data)); + PetscCallCeed(ceed, CeedOperatorSetField(op_error, "x", stats_data->elem_restr_parent_x, stats_data->basis_x, stats_data->x_coord)); + PetscCallCeed(ceed, CeedOperatorSetField(op_error, "v", stats_data->elem_restr_parent_stats, stats_data->basis_stats, CEED_VECTOR_ACTIVE)); - CeedElemRestrictionCreateVector(stats_data->elem_restr_parent_stats, &x_ceed, NULL); - CeedElemRestrictionCreateVector(stats_data->elem_restr_parent_stats, &y_ceed, NULL); + PetscCallCeed(ceed, CeedElemRestrictionCreateVector(stats_data->elem_restr_parent_stats, &x_ceed, NULL)); + PetscCallCeed(ceed, CeedElemRestrictionCreateVector(stats_data->elem_restr_parent_stats, &y_ceed, NULL)); PetscCall(OperatorApplyContextCreate(user->spanstats.dm, user->spanstats.dm, user->ceed, op_error, x_ceed, y_ceed, NULL, NULL, &user->spanstats.mms_error_ctx)); - CeedOperatorDestroy(&op_error); - CeedQFunctionDestroy(&qf_error); - CeedVectorDestroy(&x_ceed); - CeedVectorDestroy(&y_ceed); + PetscCallCeed(ceed, CeedOperatorDestroy(&op_error)); + PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_error)); + PetscCallCeed(ceed, CeedVectorDestroy(&x_ceed)); + PetscCallCeed(ceed, CeedVectorDestroy(&y_ceed)); PetscFunctionReturn(PETSC_SUCCESS); } @@ -521,11 +525,11 @@ PetscErrorCode CollectStatistics(User user, PetscScalar solution_time, Vec Q) { PetscCall(PetscLogStagePush(stage_stats_collect)); PetscCall(UpdateBoundaryValues(user, user->Q_loc, solution_time)); - CeedOperatorSetContextDouble(user_stats.op_stats_collect_ctx->op, user_stats.solution_time_label, &solution_time); + PetscCallCeed(user->ceed, CeedOperatorSetContextDouble(user_stats.op_stats_collect_ctx->op, user_stats.solution_time_label, &solution_time)); PetscCall(DMGlobalToLocal(user->dm, Q, INSERT_VALUES, user->Q_loc)); PetscCall(ApplyAddCeedOperatorLocalToLocal(user->Q_loc, user_stats.Child_Stats_loc, user_stats.op_stats_collect_ctx)); - CeedOperatorSetContextDouble(user_stats.op_stats_collect_ctx->op, user_stats.previous_time_label, &solution_time); + PetscCallCeed(user->ceed, CeedOperatorSetContextDouble(user_stats.op_stats_collect_ctx->op, user_stats.previous_time_label, &solution_time)); PetscCall(PetscLogStagePop()); PetscFunctionReturn(PETSC_SUCCESS); diff --git a/examples/fluids/src/velocity_gradient_projection.c b/examples/fluids/src/velocity_gradient_projection.c index 75730096e1..a187d70a01 100644 --- a/examples/fluids/src/velocity_gradient_projection.c +++ b/examples/fluids/src/velocity_gradient_projection.c @@ -65,9 +65,9 @@ PetscErrorCode VelocityGradientProjectionSetup(Ceed ceed, User user, CeedData ce // -- Get Pre-requisite things PetscCall(DMGetDimension(grad_velo_proj->dm, &dim)); - CeedBasisGetNumComponents(ceed_data->basis_x, &num_comp_x); - CeedBasisGetNumComponents(ceed_data->basis_q, &num_comp_q); - CeedElemRestrictionGetNumComponents(ceed_data->elem_restr_qd_i, &q_data_size); + PetscCallCeed(ceed, CeedBasisGetNumComponents(ceed_data->basis_x, &num_comp_x)); + PetscCallCeed(ceed, CeedBasisGetNumComponents(ceed_data->basis_q, &num_comp_q)); + PetscCallCeed(ceed, CeedElemRestrictionGetNumComponents(ceed_data->elem_restr_qd_i, &q_data_size)); PetscCall(GetRestrictionForDomain(ceed, grad_velo_proj->dm, 0, 0, 0, 0, -1, 0, &elem_restr_grad_velo, NULL, NULL)); PetscCall(CreateBasisFromPlex(ceed, grad_velo_proj->dm, 0, 0, 0, 0, &basis_grad_velo)); @@ -75,37 +75,39 @@ PetscErrorCode VelocityGradientProjectionSetup(Ceed ceed, User user, CeedData ce // -- Build RHS operator switch (user->phys->state_var) { case STATEVAR_PRIMITIVE: - CeedQFunctionCreateInterior(ceed, 1, VelocityGradientProjectionRHS_Prim, VelocityGradientProjectionRHS_Prim_loc, &qf_rhs_assemble); + PetscCallCeed( + ceed, CeedQFunctionCreateInterior(ceed, 1, VelocityGradientProjectionRHS_Prim, VelocityGradientProjectionRHS_Prim_loc, &qf_rhs_assemble)); break; case STATEVAR_CONSERVATIVE: - CeedQFunctionCreateInterior(ceed, 1, VelocityGradientProjectionRHS_Conserv, VelocityGradientProjectionRHS_Conserv_loc, &qf_rhs_assemble); + PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, VelocityGradientProjectionRHS_Conserv, VelocityGradientProjectionRHS_Conserv_loc, + &qf_rhs_assemble)); break; default: SETERRQ(PetscObjectComm((PetscObject)user->dm), PETSC_ERR_SUP, "No velocity gradient projection QFunction for chosen state variable"); } - CeedQFunctionSetContext(qf_rhs_assemble, problem->apply_vol_ifunction.qfunction_context); - CeedQFunctionAddInput(qf_rhs_assemble, "q", num_comp_q, CEED_EVAL_INTERP); - CeedQFunctionAddInput(qf_rhs_assemble, "Grad_q", num_comp_q * dim, CEED_EVAL_GRAD); - CeedQFunctionAddInput(qf_rhs_assemble, "qdata", q_data_size, CEED_EVAL_NONE); - CeedQFunctionAddInput(qf_rhs_assemble, "x", num_comp_x, CEED_EVAL_INTERP); - CeedQFunctionAddOutput(qf_rhs_assemble, "velocity gradient", grad_velo_proj->num_comp, CEED_EVAL_INTERP); + PetscCallCeed(ceed, CeedQFunctionSetContext(qf_rhs_assemble, problem->apply_vol_ifunction.qfunction_context)); + PetscCallCeed(ceed, CeedQFunctionAddInput(qf_rhs_assemble, "q", num_comp_q, CEED_EVAL_INTERP)); + PetscCallCeed(ceed, CeedQFunctionAddInput(qf_rhs_assemble, "Grad_q", num_comp_q * dim, CEED_EVAL_GRAD)); + PetscCallCeed(ceed, CeedQFunctionAddInput(qf_rhs_assemble, "qdata", q_data_size, CEED_EVAL_NONE)); + PetscCallCeed(ceed, CeedQFunctionAddInput(qf_rhs_assemble, "x", num_comp_x, CEED_EVAL_INTERP)); + PetscCallCeed(ceed, CeedQFunctionAddOutput(qf_rhs_assemble, "velocity gradient", grad_velo_proj->num_comp, CEED_EVAL_INTERP)); - CeedOperatorCreate(ceed, qf_rhs_assemble, NULL, NULL, &op_rhs_assemble); - CeedOperatorSetField(op_rhs_assemble, "q", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_rhs_assemble, "Grad_q", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_rhs_assemble, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, ceed_data->q_data); - CeedOperatorSetField(op_rhs_assemble, "x", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord); - CeedOperatorSetField(op_rhs_assemble, "velocity gradient", elem_restr_grad_velo, basis_grad_velo, CEED_VECTOR_ACTIVE); + PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_rhs_assemble, NULL, NULL, &op_rhs_assemble)); + PetscCallCeed(ceed, CeedOperatorSetField(op_rhs_assemble, "q", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorSetField(op_rhs_assemble, "Grad_q", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorSetField(op_rhs_assemble, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, ceed_data->q_data)); + PetscCallCeed(ceed, CeedOperatorSetField(op_rhs_assemble, "x", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord)); + PetscCallCeed(ceed, CeedOperatorSetField(op_rhs_assemble, "velocity gradient", elem_restr_grad_velo, basis_grad_velo, CEED_VECTOR_ACTIVE)); PetscCall(OperatorApplyContextCreate(user->dm, grad_velo_proj->dm, ceed, op_rhs_assemble, NULL, NULL, NULL, NULL, &grad_velo_proj->l2_rhs_ctx)); // -- Build Mass operator PetscCall(CreateMassQFunction(ceed, grad_velo_proj->num_comp, q_data_size, &qf_mass)); - CeedOperatorCreate(ceed, qf_mass, NULL, NULL, &op_mass); - CeedOperatorSetField(op_mass, "u", elem_restr_grad_velo, basis_grad_velo, CEED_VECTOR_ACTIVE); - CeedOperatorSetField(op_mass, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, ceed_data->q_data); - CeedOperatorSetField(op_mass, "v", elem_restr_grad_velo, basis_grad_velo, CEED_VECTOR_ACTIVE); + PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_mass, NULL, NULL, &op_mass)); + PetscCallCeed(ceed, CeedOperatorSetField(op_mass, "u", elem_restr_grad_velo, basis_grad_velo, CEED_VECTOR_ACTIVE)); + PetscCallCeed(ceed, CeedOperatorSetField(op_mass, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, ceed_data->q_data)); + PetscCallCeed(ceed, CeedOperatorSetField(op_mass, "v", elem_restr_grad_velo, basis_grad_velo, CEED_VECTOR_ACTIVE)); { // -- Setup KSP for L^2 projection with lumped mass operator Mat mat_mass; @@ -129,12 +131,12 @@ PetscErrorCode VelocityGradientProjectionSetup(Ceed ceed, User user, CeedData ce PetscCall(KSPSetFromOptions(grad_velo_proj->ksp)); } - CeedBasisDestroy(&basis_grad_velo); - CeedElemRestrictionDestroy(&elem_restr_grad_velo); - CeedQFunctionDestroy(&qf_rhs_assemble); - CeedQFunctionDestroy(&qf_mass); - CeedOperatorDestroy(&op_rhs_assemble); - CeedOperatorDestroy(&op_mass); + PetscCallCeed(ceed, CeedBasisDestroy(&basis_grad_velo)); + PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_grad_velo)); + PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_rhs_assemble)); + PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_mass)); + PetscCallCeed(ceed, CeedOperatorDestroy(&op_rhs_assemble)); + PetscCallCeed(ceed, CeedOperatorDestroy(&op_mass)); PetscFunctionReturn(PETSC_SUCCESS); }