1ae2b091fSJames Wright // SPDX-FileCopyrightText: Copyright (c) 2017-2024, HONEE contributors. 2ae2b091fSJames Wright // SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause 3a515125bSLeila Ghaffari 4a515125bSLeila Ghaffari /// @file 5a515125bSLeila Ghaffari /// Setup libCEED for Navier-Stokes example using PETSc 6a515125bSLeila Ghaffari 7e419654dSJeremy L Thompson #include <ceed.h> 8e419654dSJeremy L Thompson #include <petscdmplex.h> 9e419654dSJeremy L Thompson 10149fb536SJames Wright #include <navierstokes.h> 11a515125bSLeila Ghaffari 12a78efa86SJames Wright // @brief Create CeedOperator for unstabilized mass KSP for explicit timestepping 130c373b74SJames Wright static PetscErrorCode CreateKSPMassOperator_Unstabilized(Honee honee, CeedOperator *op_mass) { 140c373b74SJames Wright Ceed ceed = honee->ceed; 15a78efa86SJames Wright CeedInt num_comp_q, q_data_size; 16a78efa86SJames Wright CeedQFunction qf_mass; 17a78efa86SJames Wright CeedElemRestriction elem_restr_q, elem_restr_qd_i; 18a78efa86SJames Wright CeedBasis basis_q; 19a78efa86SJames Wright CeedVector q_data; 20a78efa86SJames Wright 21a78efa86SJames Wright PetscFunctionBeginUser; 22a78efa86SJames Wright { // Get restriction and basis from the RHS function 23a78efa86SJames Wright CeedOperator *sub_ops; 24a78efa86SJames Wright CeedOperatorField field; 25a78efa86SJames Wright PetscInt sub_op_index = 0; // will be 0 for the volume op 26a78efa86SJames Wright 270c373b74SJames Wright PetscCallCeed(ceed, CeedCompositeOperatorGetSubList(honee->op_rhs_ctx->op, &sub_ops)); 28a78efa86SJames Wright PetscCallCeed(ceed, CeedOperatorGetFieldByName(sub_ops[sub_op_index], "q", &field)); 29a78efa86SJames Wright PetscCallCeed(ceed, CeedOperatorFieldGetElemRestriction(field, &elem_restr_q)); 30a78efa86SJames Wright PetscCallCeed(ceed, CeedOperatorFieldGetBasis(field, &basis_q)); 31a78efa86SJames Wright 32a78efa86SJames Wright PetscCallCeed(ceed, CeedOperatorGetFieldByName(sub_ops[sub_op_index], "qdata", &field)); 33a78efa86SJames Wright PetscCallCeed(ceed, CeedOperatorFieldGetElemRestriction(field, &elem_restr_qd_i)); 34a78efa86SJames Wright PetscCallCeed(ceed, CeedOperatorFieldGetVector(field, &q_data)); 35a78efa86SJames Wright } 36a78efa86SJames Wright 37a78efa86SJames Wright PetscCallCeed(ceed, CeedElemRestrictionGetNumComponents(elem_restr_q, &num_comp_q)); 38a78efa86SJames Wright PetscCallCeed(ceed, CeedElemRestrictionGetNumComponents(elem_restr_qd_i, &q_data_size)); 39a78efa86SJames Wright 40a78efa86SJames Wright PetscCall(CreateMassQFunction(ceed, num_comp_q, q_data_size, &qf_mass)); 41a78efa86SJames Wright PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_mass, NULL, NULL, op_mass)); 42a78efa86SJames Wright PetscCallCeed(ceed, CeedOperatorSetField(*op_mass, "u", elem_restr_q, basis_q, CEED_VECTOR_ACTIVE)); 43a78efa86SJames Wright PetscCallCeed(ceed, CeedOperatorSetField(*op_mass, "qdata", elem_restr_qd_i, CEED_BASIS_NONE, q_data)); 44a78efa86SJames Wright PetscCallCeed(ceed, CeedOperatorSetField(*op_mass, "v", elem_restr_q, basis_q, CEED_VECTOR_ACTIVE)); 45a78efa86SJames Wright 46*fff85bd3SJames Wright PetscCallCeed(ceed, CeedVectorDestroy(&q_data)); 47*fff85bd3SJames Wright PetscCallCeed(ceed, CeedBasisDestroy(&basis_q)); 48*fff85bd3SJames Wright PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_q)); 49*fff85bd3SJames Wright PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_qd_i)); 50a78efa86SJames Wright PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_mass)); 51a78efa86SJames Wright PetscFunctionReturn(PETSC_SUCCESS); 52a78efa86SJames Wright } 53a78efa86SJames Wright 54a78efa86SJames Wright // @brief Create KSP to solve the inverse mass operator for explicit time stepping schemes 550c373b74SJames Wright static PetscErrorCode CreateKSPMass(Honee honee, ProblemData problem) { 560c373b74SJames Wright Ceed ceed = honee->ceed; 570c373b74SJames Wright DM dm = honee->dm; 58a78efa86SJames Wright CeedOperator op_mass; 59a78efa86SJames Wright 60a78efa86SJames Wright PetscFunctionBeginUser; 610c373b74SJames Wright if (problem->create_mass_operator) PetscCall(problem->create_mass_operator(honee, &op_mass)); 620c373b74SJames Wright else PetscCall(CreateKSPMassOperator_Unstabilized(honee, &op_mass)); 63a78efa86SJames Wright 64a78efa86SJames Wright { // -- Setup KSP for mass operator 65a78efa86SJames Wright Mat mat_mass; 66a78efa86SJames Wright Vec Zeros_loc; 67a78efa86SJames Wright MPI_Comm comm = PetscObjectComm((PetscObject)dm); 68a78efa86SJames Wright 69a78efa86SJames Wright PetscCall(DMCreateLocalVector(dm, &Zeros_loc)); 70a78efa86SJames Wright PetscCall(VecZeroEntries(Zeros_loc)); 71000d2032SJeremy L Thompson PetscCall(MatCreateCeed(dm, dm, op_mass, NULL, &mat_mass)); 72a78efa86SJames Wright PetscCall(MatCeedSetLocalVectors(mat_mass, Zeros_loc, NULL)); 73a78efa86SJames Wright 740c373b74SJames Wright PetscCall(KSPCreate(comm, &honee->mass_ksp)); 750c373b74SJames Wright PetscCall(KSPSetOptionsPrefix(honee->mass_ksp, "mass_")); 76a78efa86SJames Wright { // lumped by default 77a78efa86SJames Wright PC pc; 780c373b74SJames Wright PetscCall(KSPGetPC(honee->mass_ksp, &pc)); 79a78efa86SJames Wright PetscCall(PCSetType(pc, PCJACOBI)); 80a78efa86SJames Wright PetscCall(PCJacobiSetType(pc, PC_JACOBI_ROWSUM)); 810c373b74SJames Wright PetscCall(KSPSetType(honee->mass_ksp, KSPPREONLY)); 82a78efa86SJames Wright } 830c373b74SJames Wright PetscCall(KSPSetFromOptions_WithMatCeed(honee->mass_ksp, mat_mass)); 84a78efa86SJames Wright PetscCall(VecDestroy(&Zeros_loc)); 85a78efa86SJames Wright PetscCall(MatDestroy(&mat_mass)); 86a78efa86SJames Wright } 87a78efa86SJames Wright 88a78efa86SJames Wright PetscCallCeed(ceed, CeedOperatorDestroy(&op_mass)); 89a78efa86SJames Wright PetscFunctionReturn(PETSC_SUCCESS); 90a78efa86SJames Wright } 91a78efa86SJames Wright 92e3663b90SJames Wright static PetscErrorCode AddBCSubOperator(Ceed ceed, DM dm, Honee honee, DMLabel domain_label, PetscInt label_value, CeedInt height, CeedInt Q_sur, 93e3663b90SJames Wright CeedInt q_data_size_sur, CeedInt jac_data_size_sur, CeedBasis basis_q_sur, CeedBasis basis_x_sur, 94e3663b90SJames Wright CeedQFunction qf_apply_bc, CeedQFunction qf_apply_bc_jacobian, CeedOperator op_apply, 95866f9b4aSJames Wright CeedOperator op_apply_ijacobian) { 9615c18037SJames Wright CeedVector q_data_sur, jac_data_sur = NULL; 97866f9b4aSJames Wright CeedOperator op_apply_bc, op_apply_bc_jacobian = NULL; 9815c18037SJames Wright CeedElemRestriction elem_restr_x_sur, elem_restr_q_sur, elem_restr_qd_i_sur, elem_restr_jd_i_sur = NULL; 99866f9b4aSJames Wright PetscInt dm_field = 0; 100368c645fSJames Wright 10106f41313SJames Wright PetscFunctionBeginUser; 10215c18037SJames Wright PetscCall(DMPlexCeedElemRestrictionCreate(ceed, dm, domain_label, label_value, height, dm_field, &elem_restr_q_sur)); 10315c18037SJames Wright PetscCall(DMPlexCeedElemRestrictionCoordinateCreate(ceed, dm, domain_label, label_value, height, &elem_restr_x_sur)); 104368c645fSJames Wright if (jac_data_size_sur > 0) { 105368c645fSJames Wright // State-dependent data will be passed from residual to Jacobian. This will be collocated. 10615c18037SJames Wright PetscCall(DMPlexCeedElemRestrictionQDataCreate(ceed, dm, domain_label, label_value, height, jac_data_size_sur, &elem_restr_jd_i_sur)); 107b4c37c5cSJames Wright PetscCallCeed(ceed, CeedElemRestrictionCreateVector(elem_restr_jd_i_sur, &jac_data_sur, NULL)); 108368c645fSJames Wright } 109368c645fSJames Wright 110e3663b90SJames Wright PetscCall(QDataBoundaryGet(ceed, dm, domain_label, label_value, elem_restr_x_sur, basis_x_sur, honee->x_coord, &elem_restr_qd_i_sur, &q_data_sur, 111e3663b90SJames Wright &q_data_size_sur)); 112866f9b4aSJames Wright 113bbc90103SJames Wright // CEED Operator for Physics 114b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_apply_bc, NULL, NULL, &op_apply_bc)); 115866f9b4aSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_apply_bc, "q", elem_restr_q_sur, basis_q_sur, CEED_VECTOR_ACTIVE)); 116866f9b4aSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_apply_bc, "Grad_q", elem_restr_q_sur, basis_q_sur, CEED_VECTOR_ACTIVE)); 11758e1cbfdSJeremy L Thompson PetscCallCeed(ceed, CeedOperatorSetField(op_apply_bc, "surface qdata", elem_restr_qd_i_sur, CEED_BASIS_NONE, q_data_sur)); 118e3663b90SJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_apply_bc, "x", elem_restr_x_sur, basis_x_sur, honee->x_coord)); 119866f9b4aSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_apply_bc, "v", elem_restr_q_sur, basis_q_sur, CEED_VECTOR_ACTIVE)); 120b4c37c5cSJames Wright if (elem_restr_jd_i_sur) 12158e1cbfdSJeremy L Thompson PetscCallCeed(ceed, CeedOperatorSetField(op_apply_bc, "surface jacobian data", elem_restr_jd_i_sur, CEED_BASIS_NONE, jac_data_sur)); 122368c645fSJames Wright 1234b96a86bSJames Wright if (qf_apply_bc_jacobian && elem_restr_jd_i_sur) { 124b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_apply_bc_jacobian, NULL, NULL, &op_apply_bc_jacobian)); 125866f9b4aSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_apply_bc_jacobian, "dq", elem_restr_q_sur, basis_q_sur, CEED_VECTOR_ACTIVE)); 126866f9b4aSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_apply_bc_jacobian, "Grad_dq", elem_restr_q_sur, basis_q_sur, CEED_VECTOR_ACTIVE)); 12758e1cbfdSJeremy L Thompson PetscCallCeed(ceed, CeedOperatorSetField(op_apply_bc_jacobian, "surface qdata", elem_restr_qd_i_sur, CEED_BASIS_NONE, q_data_sur)); 128e3663b90SJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_apply_bc_jacobian, "x", elem_restr_x_sur, basis_x_sur, honee->x_coord)); 12958e1cbfdSJeremy L Thompson PetscCallCeed(ceed, CeedOperatorSetField(op_apply_bc_jacobian, "surface jacobian data", elem_restr_jd_i_sur, CEED_BASIS_NONE, jac_data_sur)); 130866f9b4aSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_apply_bc_jacobian, "v", elem_restr_q_sur, basis_q_sur, CEED_VECTOR_ACTIVE)); 131368c645fSJames Wright } 132368c645fSJames Wright 133bbc90103SJames Wright // Apply Sub-Operator for Physics 134866f9b4aSJames Wright PetscCallCeed(ceed, CeedCompositeOperatorAddSub(op_apply, op_apply_bc)); 135866f9b4aSJames Wright if (op_apply_bc_jacobian) PetscCallCeed(ceed, CeedCompositeOperatorAddSub(op_apply_ijacobian, op_apply_bc_jacobian)); 136368c645fSJames Wright 137b4c37c5cSJames Wright PetscCallCeed(ceed, CeedVectorDestroy(&q_data_sur)); 138b4c37c5cSJames Wright PetscCallCeed(ceed, CeedVectorDestroy(&jac_data_sur)); 139b4c37c5cSJames Wright PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_q_sur)); 140b4c37c5cSJames Wright PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_x_sur)); 141b4c37c5cSJames Wright PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_qd_i_sur)); 142b4c37c5cSJames Wright PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_jd_i_sur)); 143b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorDestroy(&op_apply_bc)); 144b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorDestroy(&op_apply_bc_jacobian)); 145d949ddfcSJames Wright PetscFunctionReturn(PETSC_SUCCESS); 146368c645fSJames Wright } 147368c645fSJames Wright 148866f9b4aSJames Wright static PetscErrorCode SetupBCQFunctions(Ceed ceed, PetscInt dim_sur, PetscInt num_comp_x, PetscInt num_comp_q, PetscInt q_data_size_sur, 1492b916ea7SJeremy L Thompson PetscInt jac_data_size_sur, ProblemQFunctionSpec apply_bc, ProblemQFunctionSpec apply_bc_jacobian, 15025988f00SJames Wright CeedQFunction *qf_apply_bc, CeedQFunction *qf_apply_bc_jacobian) { 15125988f00SJames Wright PetscFunctionBeginUser; 152e07531f7SJames Wright if (apply_bc.qf_func_ptr) { 153e07531f7SJames Wright PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, apply_bc.qf_func_ptr, apply_bc.qf_loc, qf_apply_bc)); 154e07531f7SJames Wright PetscCallCeed(ceed, CeedQFunctionSetContext(*qf_apply_bc, apply_bc.qfctx)); 155ebfabadfSJames Wright PetscCallCeed(ceed, CeedQFunctionSetUserFlopsEstimate(*qf_apply_bc, 0)); 156b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(*qf_apply_bc, "q", num_comp_q, CEED_EVAL_INTERP)); 157b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(*qf_apply_bc, "Grad_q", num_comp_q * dim_sur, CEED_EVAL_GRAD)); 158b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(*qf_apply_bc, "surface qdata", q_data_size_sur, CEED_EVAL_NONE)); 159b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(*qf_apply_bc, "x", num_comp_x, CEED_EVAL_INTERP)); 160b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddOutput(*qf_apply_bc, "v", num_comp_q, CEED_EVAL_INTERP)); 161b4c37c5cSJames Wright if (jac_data_size_sur) PetscCallCeed(ceed, CeedQFunctionAddOutput(*qf_apply_bc, "surface jacobian data", jac_data_size_sur, CEED_EVAL_NONE)); 16225988f00SJames Wright } 163e07531f7SJames Wright if (apply_bc_jacobian.qf_func_ptr) { 164e07531f7SJames Wright PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, apply_bc_jacobian.qf_func_ptr, apply_bc_jacobian.qf_loc, qf_apply_bc_jacobian)); 165e07531f7SJames Wright PetscCallCeed(ceed, CeedQFunctionSetContext(*qf_apply_bc_jacobian, apply_bc_jacobian.qfctx)); 166ebfabadfSJames Wright PetscCallCeed(ceed, CeedQFunctionSetUserFlopsEstimate(*qf_apply_bc_jacobian, 0)); 167b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(*qf_apply_bc_jacobian, "dq", num_comp_q, CEED_EVAL_INTERP)); 168b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(*qf_apply_bc_jacobian, "Grad_dq", num_comp_q * dim_sur, CEED_EVAL_GRAD)); 169b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(*qf_apply_bc_jacobian, "surface qdata", q_data_size_sur, CEED_EVAL_NONE)); 170b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(*qf_apply_bc_jacobian, "x", num_comp_x, CEED_EVAL_INTERP)); 171b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(*qf_apply_bc_jacobian, "surface jacobian data", jac_data_size_sur, CEED_EVAL_NONE)); 172b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddOutput(*qf_apply_bc_jacobian, "v", num_comp_q, CEED_EVAL_INTERP)); 17325988f00SJames Wright } 174d949ddfcSJames Wright PetscFunctionReturn(PETSC_SUCCESS); 17525988f00SJames Wright } 17625988f00SJames Wright 177bbc90103SJames Wright // Utility function to add boundary operators to the composite operator 178e3663b90SJames Wright static PetscErrorCode AddBCSubOperators(Honee honee, Ceed ceed, DM dm, SimpleBC bc, ProblemData problem, CeedOperator op_apply, 179866f9b4aSJames Wright CeedOperator op_apply_ijacobian) { 180866f9b4aSJames Wright CeedInt height = 1, num_comp_q, num_comp_x; 1810c373b74SJames Wright CeedInt P_sur = honee->app_ctx->degree + 1, Q_sur = P_sur + honee->app_ctx->q_extra, dim_sur, q_data_size_sur; 1820c373b74SJames Wright const CeedInt jac_data_size_sur = honee->phys->implicit ? problem->jac_data_size_sur : 0; 183866f9b4aSJames Wright PetscInt dim; 184866f9b4aSJames Wright DMLabel face_sets_label; 185866f9b4aSJames Wright CeedBasis basis_q_sur, basis_x_sur; 186866f9b4aSJames Wright 187866f9b4aSJames Wright PetscFunctionBeginUser; 188866f9b4aSJames Wright PetscCall(DMGetDimension(dm, &dim)); 189c864c5abSJames Wright PetscCall(QDataBoundaryGetNumComponents(dm, &q_data_size_sur)); 190866f9b4aSJames Wright dim_sur = dim - height; 191866f9b4aSJames Wright { // Get number of components and coordinate dimension from op_apply 192866f9b4aSJames Wright CeedOperator *sub_ops; 193866f9b4aSJames Wright CeedOperatorField field; 194866f9b4aSJames Wright PetscInt sub_op_index = 0; // will be 0 for the volume op 195866f9b4aSJames Wright CeedElemRestriction elem_restr_q, elem_restr_x; 196866f9b4aSJames Wright 197866f9b4aSJames Wright PetscCallCeed(ceed, CeedCompositeOperatorGetSubList(op_apply, &sub_ops)); 198866f9b4aSJames Wright PetscCallCeed(ceed, CeedOperatorGetFieldByName(sub_ops[sub_op_index], "q", &field)); 199866f9b4aSJames Wright PetscCallCeed(ceed, CeedOperatorFieldGetElemRestriction(field, &elem_restr_q)); 200866f9b4aSJames Wright PetscCallCeed(ceed, CeedElemRestrictionGetNumComponents(elem_restr_q, &num_comp_q)); 201*fff85bd3SJames Wright PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_q)); 202866f9b4aSJames Wright 203866f9b4aSJames Wright PetscCallCeed(ceed, CeedOperatorGetFieldByName(sub_ops[sub_op_index], "x", &field)); 204866f9b4aSJames Wright PetscCallCeed(ceed, CeedOperatorFieldGetElemRestriction(field, &elem_restr_x)); 205866f9b4aSJames Wright PetscCallCeed(ceed, CeedElemRestrictionGetNumComponents(elem_restr_x, &num_comp_x)); 206*fff85bd3SJames Wright PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_x)); 207866f9b4aSJames Wright } 208866f9b4aSJames Wright 209866f9b4aSJames Wright { // Get bases 210866f9b4aSJames Wright DM dm_coord; 211866f9b4aSJames Wright 212866f9b4aSJames Wright PetscCall(DMGetCoordinateDM(dm, &dm_coord)); 213866f9b4aSJames Wright DMLabel label = NULL; 214866f9b4aSJames Wright PetscInt label_value = 0; 215bbc90103SJames Wright PetscInt field = 0; 216866f9b4aSJames Wright PetscCall(CreateBasisFromPlex(ceed, dm, label, label_value, height, field, &basis_q_sur)); 217866f9b4aSJames Wright PetscCall(CreateBasisFromPlex(ceed, dm_coord, label, label_value, height, field, &basis_x_sur)); 218866f9b4aSJames Wright } 219866f9b4aSJames Wright 220866f9b4aSJames Wright PetscCall(DMGetLabel(dm, "Face Sets", &face_sets_label)); 221866f9b4aSJames Wright 222866f9b4aSJames Wright { // --- Create Sub-Operator for inflow boundaries 223866f9b4aSJames Wright CeedQFunction qf_apply_inflow = NULL, qf_apply_inflow_jacobian = NULL; 224866f9b4aSJames Wright 225866f9b4aSJames Wright PetscCall(SetupBCQFunctions(ceed, dim_sur, num_comp_x, num_comp_q, q_data_size_sur, jac_data_size_sur, problem->apply_inflow, 226866f9b4aSJames Wright problem->apply_inflow_jacobian, &qf_apply_inflow, &qf_apply_inflow_jacobian)); 227866f9b4aSJames Wright for (CeedInt i = 0; i < bc->num_inflow; i++) { 228e3663b90SJames Wright PetscCall(AddBCSubOperator(ceed, dm, honee, face_sets_label, bc->inflows[i], height, Q_sur, q_data_size_sur, jac_data_size_sur, basis_q_sur, 229866f9b4aSJames Wright basis_x_sur, qf_apply_inflow, qf_apply_inflow_jacobian, op_apply, op_apply_ijacobian)); 230866f9b4aSJames Wright } 231866f9b4aSJames Wright PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_apply_inflow)); 232866f9b4aSJames Wright PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_apply_inflow_jacobian)); 233866f9b4aSJames Wright } 234866f9b4aSJames Wright 235866f9b4aSJames Wright { // --- Create Sub-Operator for outflow boundaries 236866f9b4aSJames Wright CeedQFunction qf_apply_outflow = NULL, qf_apply_outflow_jacobian = NULL; 237866f9b4aSJames Wright 238866f9b4aSJames Wright PetscCall(SetupBCQFunctions(ceed, dim_sur, num_comp_x, num_comp_q, q_data_size_sur, jac_data_size_sur, problem->apply_outflow, 239866f9b4aSJames Wright problem->apply_outflow_jacobian, &qf_apply_outflow, &qf_apply_outflow_jacobian)); 240866f9b4aSJames Wright for (CeedInt i = 0; i < bc->num_outflow; i++) { 241e3663b90SJames Wright PetscCall(AddBCSubOperator(ceed, dm, honee, face_sets_label, bc->outflows[i], height, Q_sur, q_data_size_sur, jac_data_size_sur, basis_q_sur, 242e3663b90SJames Wright basis_x_sur, qf_apply_outflow, qf_apply_outflow_jacobian, op_apply, op_apply_ijacobian)); 243866f9b4aSJames Wright } 244866f9b4aSJames Wright PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_apply_outflow)); 245866f9b4aSJames Wright PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_apply_outflow_jacobian)); 246866f9b4aSJames Wright } 247866f9b4aSJames Wright 248866f9b4aSJames Wright { // --- Create Sub-Operator for freestream boundaries 249866f9b4aSJames Wright CeedQFunction qf_apply_freestream = NULL, qf_apply_freestream_jacobian = NULL; 250866f9b4aSJames Wright 251866f9b4aSJames Wright PetscCall(SetupBCQFunctions(ceed, dim_sur, num_comp_x, num_comp_q, q_data_size_sur, jac_data_size_sur, problem->apply_freestream, 252866f9b4aSJames Wright problem->apply_freestream_jacobian, &qf_apply_freestream, &qf_apply_freestream_jacobian)); 253866f9b4aSJames Wright for (CeedInt i = 0; i < bc->num_freestream; i++) { 254e3663b90SJames Wright PetscCall(AddBCSubOperator(ceed, dm, honee, face_sets_label, bc->freestreams[i], height, Q_sur, q_data_size_sur, jac_data_size_sur, basis_q_sur, 255e3663b90SJames Wright basis_x_sur, qf_apply_freestream, qf_apply_freestream_jacobian, op_apply, op_apply_ijacobian)); 256866f9b4aSJames Wright } 257866f9b4aSJames Wright PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_apply_freestream)); 258866f9b4aSJames Wright PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_apply_freestream_jacobian)); 259866f9b4aSJames Wright } 260866f9b4aSJames Wright 261866f9b4aSJames Wright { // --- Create Sub-Operator for slip boundaries 262866f9b4aSJames Wright CeedQFunction qf_apply_slip = NULL, qf_apply_slip_jacobian = NULL; 263866f9b4aSJames Wright 264866f9b4aSJames Wright PetscCall(SetupBCQFunctions(ceed, dim_sur, num_comp_x, num_comp_q, q_data_size_sur, jac_data_size_sur, problem->apply_slip, 265866f9b4aSJames Wright problem->apply_slip_jacobian, &qf_apply_slip, &qf_apply_slip_jacobian)); 266866f9b4aSJames Wright for (CeedInt i = 0; i < bc->num_slip; i++) { 267e3663b90SJames Wright PetscCall(AddBCSubOperator(ceed, dm, honee, face_sets_label, bc->slips[i], height, Q_sur, q_data_size_sur, jac_data_size_sur, basis_q_sur, 268866f9b4aSJames Wright basis_x_sur, qf_apply_slip, qf_apply_slip_jacobian, op_apply, op_apply_ijacobian)); 269866f9b4aSJames Wright } 270866f9b4aSJames Wright PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_apply_slip)); 271866f9b4aSJames Wright PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_apply_slip_jacobian)); 272866f9b4aSJames Wright } 273866f9b4aSJames Wright 274866f9b4aSJames Wright PetscCallCeed(ceed, CeedBasisDestroy(&basis_q_sur)); 275866f9b4aSJames Wright PetscCallCeed(ceed, CeedBasisDestroy(&basis_x_sur)); 276866f9b4aSJames Wright PetscFunctionReturn(PETSC_SUCCESS); 277866f9b4aSJames Wright } 278866f9b4aSJames Wright 279e3663b90SJames Wright PetscErrorCode SetupLibceed(Ceed ceed, DM dm, Honee honee, AppCtx app_ctx, ProblemData problem, SimpleBC bc) { 280a515125bSLeila Ghaffari const PetscInt num_comp_q = 5; 28166d54740SJames Wright PetscInt dim; 28228160fc2SJames Wright CeedInt jac_data_size_vol = problem->jac_data_size_vol, num_comp_x, q_data_size_vol; 283be29160dSJames Wright CeedElemRestriction elem_restr_jd_i = NULL, elem_restr_qd; 284be29160dSJames Wright CeedVector jac_data = NULL, q_data; 285bbc90103SJames Wright CeedOperator op_ifunction_vol = NULL, op_rhs_vol = NULL, op_ijacobian_vol = NULL; 286bbc90103SJames Wright 287bbc90103SJames Wright PetscFunctionBeginUser; 28866d54740SJames Wright PetscCall(DMGetDimension(dm, &dim)); 28966d54740SJames Wright num_comp_x = dim; 29094a7b3d2SKenneth E. Jansen 2918c85b835SJames Wright CeedElemRestriction elem_restr_diff_flux = NULL; 2920880fbb6SJames Wright CeedVector div_diff_flux_ceed = NULL; 2938c85b835SJames Wright CeedBasis basis_diff_flux = NULL; 2948c85b835SJames Wright CeedEvalMode eval_mode_diff_flux = -1; 295bbc90103SJames Wright { // Create bases and element restrictions 29615c18037SJames Wright DMLabel domain_label = NULL; 29715c18037SJames Wright PetscInt label_value = 0, height = 0, dm_field = 0; 29867263decSKenneth E. Jansen DM dm_coord; 29967263decSKenneth E. Jansen 300bbc90103SJames Wright PetscCall(DMGetCoordinateDM(dm, &dm_coord)); 301e3663b90SJames Wright PetscCall(CreateBasisFromPlex(ceed, dm, domain_label, label_value, height, dm_field, &honee->basis_q)); 302e3663b90SJames Wright PetscCall(CreateBasisFromPlex(ceed, dm_coord, domain_label, label_value, height, dm_field, &honee->basis_x)); 303a515125bSLeila Ghaffari 304e3663b90SJames Wright PetscCall(DMPlexCeedElemRestrictionCreate(ceed, dm, domain_label, label_value, height, 0, &honee->elem_restr_q)); 305e3663b90SJames Wright PetscCall(DMPlexCeedElemRestrictionCoordinateCreate(ceed, dm, domain_label, label_value, height, &honee->elem_restr_x)); 30628160fc2SJames Wright if (jac_data_size_vol) { 30715c18037SJames Wright PetscCall(DMPlexCeedElemRestrictionQDataCreate(ceed, dm, domain_label, label_value, height, jac_data_size_vol, &elem_restr_jd_i)); 30828160fc2SJames Wright PetscCallCeed(ceed, CeedElemRestrictionCreateVector(elem_restr_jd_i, &jac_data, NULL)); 30928160fc2SJames Wright } 310ce8bebb6SJames Wright 311e3663b90SJames Wright PetscCallCeed(ceed, CeedElemRestrictionCreateVector(honee->elem_restr_q, &honee->q_ceed, NULL)); 312e3663b90SJames Wright PetscCallCeed(ceed, CeedElemRestrictionCreateVector(honee->elem_restr_q, &honee->q_dot_ceed, NULL)); 313e3663b90SJames Wright PetscCallCeed(ceed, CeedElemRestrictionCreateVector(honee->elem_restr_q, &honee->g_ceed, NULL)); 314e3663b90SJames Wright PetscCallCeed(ceed, CeedElemRestrictionCreateVector(honee->elem_restr_x, &honee->x_coord, NULL)); 315a515125bSLeila Ghaffari 316ce8bebb6SJames Wright { // -- Copy PETSc coordinate vector into CEED vector 317a515125bSLeila Ghaffari Vec X_loc; 318cac8aa24SJed Brown DM cdm; 319ce8bebb6SJames Wright 3202b916ea7SJeremy L Thompson PetscCall(DMGetCellCoordinateDM(dm, &cdm)); 3212b916ea7SJeremy L Thompson if (cdm) { 3222b916ea7SJeremy L Thompson PetscCall(DMGetCellCoordinatesLocal(dm, &X_loc)); 3232b916ea7SJeremy L Thompson } else { 3242b916ea7SJeremy L Thompson PetscCall(DMGetCoordinatesLocal(dm, &X_loc)); 325cac8aa24SJed Brown } 3260c373b74SJames Wright PetscCall(VecScale(X_loc, honee->units->meter)); 327e3663b90SJames Wright PetscCall(VecCopyPetscToCeed(X_loc, honee->x_coord)); 328ce8bebb6SJames Wright } 329a515125bSLeila Ghaffari 330e3663b90SJames Wright PetscCall(QDataGet(ceed, dm, domain_label, label_value, honee->elem_restr_x, honee->basis_x, honee->x_coord, &elem_restr_qd, &q_data, 331be29160dSJames Wright &q_data_size_vol)); 332ce8bebb6SJames Wright } 333ce8bebb6SJames Wright 3347cea0f50SJames Wright if (app_ctx->divFdiffproj_method != DIV_DIFF_FLUX_PROJ_NONE) { 3350c373b74SJames Wright PetscCheck(honee->diff_flux_proj, honee->comm, PETSC_ERR_ARG_WRONGSTATE, 3367cea0f50SJames Wright "Divergence of diffusive flux projection requested but object not created"); 3370c373b74SJames Wright PetscCall(DivDiffFluxProjectionGetOperatorFieldData(honee->diff_flux_proj, &elem_restr_diff_flux, &basis_diff_flux, &div_diff_flux_ceed, 3380880fbb6SJames Wright &eval_mode_diff_flux)); 3397cea0f50SJames Wright } 3408c85b835SJames Wright 341ce8bebb6SJames Wright { // -- Create QFunction for ICs 342866f9b4aSJames Wright CeedBasis basis_xc; 343ce8bebb6SJames Wright CeedQFunction qf_ics; 3448f18bb8bSJames Wright CeedOperator op_ics; 345ce8bebb6SJames Wright 346e3663b90SJames Wright PetscCallCeed(ceed, CeedBasisCreateProjection(honee->basis_x, honee->basis_q, &basis_xc)); 347e07531f7SJames Wright PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, problem->ics.qf_func_ptr, problem->ics.qf_loc, &qf_ics)); 348e07531f7SJames Wright PetscCallCeed(ceed, CeedQFunctionSetContext(qf_ics, problem->ics.qfctx)); 349ce8bebb6SJames Wright PetscCallCeed(ceed, CeedQFunctionSetUserFlopsEstimate(qf_ics, 0)); 350ce8bebb6SJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(qf_ics, "x", num_comp_x, CEED_EVAL_INTERP)); 351ce8bebb6SJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(qf_ics, "dx", num_comp_x * dim, CEED_EVAL_GRAD)); 352ce8bebb6SJames Wright PetscCallCeed(ceed, CeedQFunctionAddOutput(qf_ics, "q0", num_comp_q, CEED_EVAL_NONE)); 353ce8bebb6SJames Wright 354ce8bebb6SJames Wright PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_ics, NULL, NULL, &op_ics)); 355e3663b90SJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_ics, "x", honee->elem_restr_x, basis_xc, CEED_VECTOR_ACTIVE)); 356e3663b90SJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_ics, "dx", honee->elem_restr_x, basis_xc, CEED_VECTOR_ACTIVE)); 357e3663b90SJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_ics, "q0", honee->elem_restr_q, CEED_BASIS_NONE, CEED_VECTOR_ACTIVE)); 3580c373b74SJames Wright PetscCallCeed(ceed, CeedOperatorGetContextFieldLabel(op_ics, "evaluation time", &honee->phys->ics_time_label)); 359e3663b90SJames Wright PetscCall(OperatorApplyContextCreate(NULL, dm, honee->ceed, op_ics, honee->x_coord, NULL, NULL, honee->Q_loc, &honee->op_ics_ctx)); 360a515125bSLeila Ghaffari 361866f9b4aSJames Wright PetscCallCeed(ceed, CeedBasisDestroy(&basis_xc)); 362ce8bebb6SJames Wright PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_ics)); 363ce8bebb6SJames Wright PetscCallCeed(ceed, CeedOperatorDestroy(&op_ics)); 364ce8bebb6SJames Wright } 365ce8bebb6SJames Wright 366e07531f7SJames Wright if (problem->apply_vol_rhs.qf_func_ptr) { 367ce8bebb6SJames Wright CeedQFunction qf_rhs_vol; 368ce8bebb6SJames Wright 369e07531f7SJames Wright PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_rhs.qf_func_ptr, problem->apply_vol_rhs.qf_loc, &qf_rhs_vol)); 370e07531f7SJames Wright PetscCallCeed(ceed, CeedQFunctionSetContext(qf_rhs_vol, problem->apply_vol_rhs.qfctx)); 371ce8bebb6SJames Wright PetscCallCeed(ceed, CeedQFunctionSetUserFlopsEstimate(qf_rhs_vol, 0)); 372ce8bebb6SJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(qf_rhs_vol, "q", num_comp_q, CEED_EVAL_INTERP)); 373ce8bebb6SJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(qf_rhs_vol, "Grad_q", num_comp_q * dim, CEED_EVAL_GRAD)); 37489de3142SJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(qf_rhs_vol, "qdata", q_data_size_vol, CEED_EVAL_NONE)); 375ce8bebb6SJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(qf_rhs_vol, "x", num_comp_x, CEED_EVAL_INTERP)); 3765f952e8dSJames Wright if (app_ctx->divFdiffproj_method != DIV_DIFF_FLUX_PROJ_NONE) 3770c373b74SJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(qf_rhs_vol, "div F_diff", honee->diff_flux_proj->num_diff_flux_comps, eval_mode_diff_flux)); 378ce8bebb6SJames Wright PetscCallCeed(ceed, CeedQFunctionAddOutput(qf_rhs_vol, "v", num_comp_q, CEED_EVAL_INTERP)); 379ce8bebb6SJames Wright PetscCallCeed(ceed, CeedQFunctionAddOutput(qf_rhs_vol, "Grad_v", num_comp_q * dim, CEED_EVAL_GRAD)); 380ce8bebb6SJames Wright 381bbc90103SJames Wright PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_rhs_vol, NULL, NULL, &op_rhs_vol)); 382e3663b90SJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_rhs_vol, "q", honee->elem_restr_q, honee->basis_q, CEED_VECTOR_ACTIVE)); 383e3663b90SJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_rhs_vol, "Grad_q", honee->elem_restr_q, honee->basis_q, CEED_VECTOR_ACTIVE)); 384be29160dSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_rhs_vol, "qdata", elem_restr_qd, CEED_BASIS_NONE, q_data)); 385e3663b90SJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_rhs_vol, "x", honee->elem_restr_x, honee->basis_x, honee->x_coord)); 3865f952e8dSJames Wright if (app_ctx->divFdiffproj_method != DIV_DIFF_FLUX_PROJ_NONE) 3875f952e8dSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_rhs_vol, "div F_diff", elem_restr_diff_flux, basis_diff_flux, div_diff_flux_ceed)); 388e3663b90SJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_rhs_vol, "v", honee->elem_restr_q, honee->basis_q, CEED_VECTOR_ACTIVE)); 389e3663b90SJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_rhs_vol, "Grad_v", honee->elem_restr_q, honee->basis_q, CEED_VECTOR_ACTIVE)); 390ce8bebb6SJames Wright 391ce8bebb6SJames Wright PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_rhs_vol)); 392a515125bSLeila Ghaffari } 393a515125bSLeila Ghaffari 394e07531f7SJames Wright if (problem->apply_vol_ifunction.qf_func_ptr) { 395ce8bebb6SJames Wright CeedQFunction qf_ifunction_vol; 396ce8bebb6SJames Wright 397e07531f7SJames Wright PetscCallCeed( 398e07531f7SJames Wright ceed, CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_ifunction.qf_func_ptr, problem->apply_vol_ifunction.qf_loc, &qf_ifunction_vol)); 399e07531f7SJames Wright PetscCallCeed(ceed, CeedQFunctionSetContext(qf_ifunction_vol, problem->apply_vol_ifunction.qfctx)); 400ce8bebb6SJames Wright PetscCallCeed(ceed, CeedQFunctionSetUserFlopsEstimate(qf_ifunction_vol, 0)); 401ce8bebb6SJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(qf_ifunction_vol, "q", num_comp_q, CEED_EVAL_INTERP)); 402ce8bebb6SJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(qf_ifunction_vol, "Grad_q", num_comp_q * dim, CEED_EVAL_GRAD)); 403ce8bebb6SJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(qf_ifunction_vol, "q dot", num_comp_q, CEED_EVAL_INTERP)); 40489de3142SJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(qf_ifunction_vol, "qdata", q_data_size_vol, CEED_EVAL_NONE)); 405ce8bebb6SJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(qf_ifunction_vol, "x", num_comp_x, CEED_EVAL_INTERP)); 4060880fbb6SJames Wright if (app_ctx->divFdiffproj_method != DIV_DIFF_FLUX_PROJ_NONE) 4070c373b74SJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(qf_ifunction_vol, "div F_diff", honee->diff_flux_proj->num_diff_flux_comps, eval_mode_diff_flux)); 408ce8bebb6SJames Wright PetscCallCeed(ceed, CeedQFunctionAddOutput(qf_ifunction_vol, "v", num_comp_q, CEED_EVAL_INTERP)); 409ce8bebb6SJames Wright PetscCallCeed(ceed, CeedQFunctionAddOutput(qf_ifunction_vol, "Grad_v", num_comp_q * dim, CEED_EVAL_GRAD)); 41028160fc2SJames Wright if (jac_data_size_vol) PetscCallCeed(ceed, CeedQFunctionAddOutput(qf_ifunction_vol, "jac_data", jac_data_size_vol, CEED_EVAL_NONE)); 411ce8bebb6SJames Wright 412bbc90103SJames Wright PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_ifunction_vol, NULL, NULL, &op_ifunction_vol)); 413e3663b90SJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_ifunction_vol, "q", honee->elem_restr_q, honee->basis_q, CEED_VECTOR_ACTIVE)); 414e3663b90SJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_ifunction_vol, "Grad_q", honee->elem_restr_q, honee->basis_q, CEED_VECTOR_ACTIVE)); 415e3663b90SJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_ifunction_vol, "q dot", honee->elem_restr_q, honee->basis_q, honee->q_dot_ceed)); 416be29160dSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_ifunction_vol, "qdata", elem_restr_qd, CEED_BASIS_NONE, q_data)); 417e3663b90SJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_ifunction_vol, "x", honee->elem_restr_x, honee->basis_x, honee->x_coord)); 4188c85b835SJames Wright if (app_ctx->divFdiffproj_method != DIV_DIFF_FLUX_PROJ_NONE) 4190880fbb6SJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_ifunction_vol, "div F_diff", elem_restr_diff_flux, basis_diff_flux, div_diff_flux_ceed)); 420e3663b90SJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_ifunction_vol, "v", honee->elem_restr_q, honee->basis_q, CEED_VECTOR_ACTIVE)); 421e3663b90SJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_ifunction_vol, "Grad_v", honee->elem_restr_q, honee->basis_q, CEED_VECTOR_ACTIVE)); 42228160fc2SJames Wright if (jac_data_size_vol) PetscCallCeed(ceed, CeedOperatorSetField(op_ifunction_vol, "jac_data", elem_restr_jd_i, CEED_BASIS_NONE, jac_data)); 423752f40e3SJed Brown 424ce8bebb6SJames Wright PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_ifunction_vol)); 425a515125bSLeila Ghaffari } 426a515125bSLeila Ghaffari 427e07531f7SJames Wright if (problem->apply_vol_ijacobian.qf_func_ptr) { 428ce8bebb6SJames Wright CeedQFunction qf_ijacobian_vol; 429ce8bebb6SJames Wright 430e07531f7SJames Wright PetscCallCeed( 431e07531f7SJames Wright ceed, CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_ijacobian.qf_func_ptr, problem->apply_vol_ijacobian.qf_loc, &qf_ijacobian_vol)); 432e07531f7SJames Wright PetscCallCeed(ceed, CeedQFunctionSetContext(qf_ijacobian_vol, problem->apply_vol_ijacobian.qfctx)); 433ce8bebb6SJames Wright PetscCallCeed(ceed, CeedQFunctionSetUserFlopsEstimate(qf_ijacobian_vol, 0)); 434ce8bebb6SJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(qf_ijacobian_vol, "dq", num_comp_q, CEED_EVAL_INTERP)); 435ce8bebb6SJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(qf_ijacobian_vol, "Grad_dq", num_comp_q * dim, CEED_EVAL_GRAD)); 43689de3142SJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(qf_ijacobian_vol, "qdata", q_data_size_vol, CEED_EVAL_NONE)); 43728160fc2SJames Wright if (jac_data_size_vol) PetscCallCeed(ceed, CeedQFunctionAddInput(qf_ijacobian_vol, "jac_data", jac_data_size_vol, CEED_EVAL_NONE)); 438ce8bebb6SJames Wright PetscCallCeed(ceed, CeedQFunctionAddOutput(qf_ijacobian_vol, "v", num_comp_q, CEED_EVAL_INTERP)); 439ce8bebb6SJames Wright PetscCallCeed(ceed, CeedQFunctionAddOutput(qf_ijacobian_vol, "Grad_v", num_comp_q * dim, CEED_EVAL_GRAD)); 440ce8bebb6SJames Wright 441bbc90103SJames Wright PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_ijacobian_vol, NULL, NULL, &op_ijacobian_vol)); 442e3663b90SJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_ijacobian_vol, "dq", honee->elem_restr_q, honee->basis_q, CEED_VECTOR_ACTIVE)); 443e3663b90SJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_ijacobian_vol, "Grad_dq", honee->elem_restr_q, honee->basis_q, CEED_VECTOR_ACTIVE)); 444be29160dSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_ijacobian_vol, "qdata", elem_restr_qd, CEED_BASIS_NONE, q_data)); 44528160fc2SJames Wright if (jac_data_size_vol) PetscCallCeed(ceed, CeedOperatorSetField(op_ijacobian_vol, "jac_data", elem_restr_jd_i, CEED_BASIS_NONE, jac_data)); 446e3663b90SJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_ijacobian_vol, "v", honee->elem_restr_q, honee->basis_q, CEED_VECTOR_ACTIVE)); 447e3663b90SJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_ijacobian_vol, "Grad_v", honee->elem_restr_q, honee->basis_q, CEED_VECTOR_ACTIVE)); 448ce8bebb6SJames Wright 449b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_ijacobian_vol)); 450f0b65372SJed Brown } 451f0b65372SJed Brown 452a515125bSLeila Ghaffari // -- Create and apply CEED Composite Operator for the entire domain 4530c373b74SJames Wright if (!honee->phys->implicit) { // RHS 454da5fe0e4SJames Wright CeedOperator op_rhs; 455866f9b4aSJames Wright 456866f9b4aSJames Wright PetscCallCeed(ceed, CeedCompositeOperatorCreate(ceed, &op_rhs)); 457bbc90103SJames Wright PetscCallCeed(ceed, CeedCompositeOperatorAddSub(op_rhs, op_rhs_vol)); 458e3663b90SJames Wright PetscCall(AddBCSubOperators(honee, ceed, dm, bc, problem, op_rhs, NULL)); 459866f9b4aSJames Wright 4600c373b74SJames Wright PetscCall(OperatorApplyContextCreate(dm, dm, ceed, op_rhs, honee->q_ceed, honee->g_ceed, honee->Q_loc, NULL, &honee->op_rhs_ctx)); 461866f9b4aSJames Wright 462866f9b4aSJames Wright // ----- Get Context Labels for Operator 4630c373b74SJames Wright PetscCallCeed(ceed, CeedOperatorGetContextFieldLabel(op_rhs, "solution time", &honee->phys->solution_time_label)); 4640c373b74SJames Wright PetscCallCeed(ceed, CeedOperatorGetContextFieldLabel(op_rhs, "timestep size", &honee->phys->timestep_size_label)); 465866f9b4aSJames Wright 466b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorDestroy(&op_rhs)); 4670c373b74SJames Wright PetscCall(CreateKSPMass(honee, problem)); 4680c373b74SJames Wright PetscCheck(app_ctx->sgs_model_type == SGS_MODEL_NONE, honee->comm, PETSC_ERR_SUP, "SGS modeling not implemented for explicit timestepping"); 469a515125bSLeila Ghaffari } else { // IFunction 470ebfabadfSJames Wright CeedOperator op_ijacobian = NULL; 471ebfabadfSJames Wright 472866f9b4aSJames Wright // Create Composite Operaters 4730c373b74SJames Wright PetscCallCeed(ceed, CeedCompositeOperatorCreate(ceed, &honee->op_ifunction)); 4740c373b74SJames Wright PetscCallCeed(ceed, CeedCompositeOperatorAddSub(honee->op_ifunction, op_ifunction_vol)); 475866f9b4aSJames Wright if (op_ijacobian_vol) { 476866f9b4aSJames Wright PetscCallCeed(ceed, CeedCompositeOperatorCreate(ceed, &op_ijacobian)); 477866f9b4aSJames Wright PetscCallCeed(ceed, CeedCompositeOperatorAddSub(op_ijacobian, op_ijacobian_vol)); 478866f9b4aSJames Wright } 479e3663b90SJames Wright PetscCall(AddBCSubOperators(honee, ceed, dm, bc, problem, honee->op_ifunction, op_ijacobian)); 480866f9b4aSJames Wright 481866f9b4aSJames Wright // ----- Get Context Labels for Operator 4820c373b74SJames Wright PetscCallCeed(ceed, CeedOperatorGetContextFieldLabel(honee->op_ifunction, "solution time", &honee->phys->solution_time_label)); 4830c373b74SJames Wright PetscCallCeed(ceed, CeedOperatorGetContextFieldLabel(honee->op_ifunction, "timestep size", &honee->phys->timestep_size_label)); 484866f9b4aSJames Wright 485ebfabadfSJames Wright if (op_ijacobian) { 4860c373b74SJames Wright PetscCall(MatCreateCeed(honee->dm, honee->dm, op_ijacobian, NULL, &honee->mat_ijacobian)); 4870c373b74SJames Wright PetscCall(MatCeedSetLocalVectors(honee->mat_ijacobian, honee->Q_dot_loc, NULL)); 488ebfabadfSJames Wright PetscCallCeed(ceed, CeedOperatorDestroy(&op_ijacobian)); 489f0b65372SJed Brown } 490e3663b90SJames Wright if (app_ctx->sgs_model_type == SGS_MODEL_DATA_DRIVEN) PetscCall(SgsDDSetup(ceed, honee, problem)); 4916d0190e2SJames Wright } 49291933550SJames Wright 493e3663b90SJames Wright if (problem->use_strong_bc_ceed) PetscCall(SetupStrongBC_Ceed(ceed, dm, honee, problem, bc)); 494e3663b90SJames Wright if (app_ctx->turb_spanstats_enable) PetscCall(TurbulenceStatisticsSetup(ceed, honee, problem)); 495e3663b90SJames Wright if (app_ctx->diff_filter_monitor && !honee->diff_filter) PetscCall(DifferentialFilterSetup(ceed, honee, problem)); 496e3663b90SJames Wright if (app_ctx->sgs_train_enable) PetscCall(SGS_DD_TrainingSetup(ceed, honee, problem)); 497e3663b90SJames Wright if (app_ctx->divFdiffproj_method != DIV_DIFF_FLUX_PROJ_NONE) PetscCall(DivDiffFluxProjectionSetup(honee, honee->diff_flux_proj)); 49891933550SJames Wright 499be29160dSJames Wright PetscCallCeed(ceed, CeedVectorDestroy(&q_data)); 5008c85b835SJames Wright PetscCallCeed(ceed, CeedVectorDestroy(&jac_data)); 501be29160dSJames Wright PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_qd)); 5028c85b835SJames Wright PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_jd_i)); 5038c85b835SJames Wright PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_diff_flux)); 5048c85b835SJames Wright PetscCallCeed(ceed, CeedBasisDestroy(&basis_diff_flux)); 5050880fbb6SJames Wright PetscCallCeed(ceed, CeedVectorDestroy(&div_diff_flux_ceed)); 506b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorDestroy(&op_ijacobian_vol)); 507bbc90103SJames Wright PetscCallCeed(ceed, CeedOperatorDestroy(&op_ifunction_vol)); 508bbc90103SJames Wright PetscCallCeed(ceed, CeedOperatorDestroy(&op_rhs_vol)); 509d949ddfcSJames Wright PetscFunctionReturn(PETSC_SUCCESS); 510a515125bSLeila Ghaffari } 511