1dc936754SJeremy L Thompson // Copyright (c) 2017-2024, Lawrence Livermore National Security, LLC and other CEED contributors. 2727da7e7SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 3a515125bSLeila Ghaffari // 4727da7e7SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause 5a515125bSLeila Ghaffari // 6727da7e7SJeremy L Thompson // This file is part of CEED: http://github.com/ceed 7a515125bSLeila Ghaffari 8a515125bSLeila Ghaffari /// @file 9a515125bSLeila Ghaffari /// Setup libCEED for Navier-Stokes example using PETSc 10a515125bSLeila Ghaffari 11e419654dSJeremy L Thompson #include <ceed.h> 12e419654dSJeremy L Thompson #include <petscdmplex.h> 13e419654dSJeremy L Thompson 14a515125bSLeila Ghaffari #include "../navierstokes.h" 15a515125bSLeila Ghaffari 16a78efa86SJames Wright // @brief Create CeedOperator for unstabilized mass KSP for explicit timestepping 17a78efa86SJames Wright static PetscErrorCode CreateKSPMassOperator_Unstabilized(User user, CeedOperator *op_mass) { 18a78efa86SJames Wright Ceed ceed = user->ceed; 19a78efa86SJames Wright CeedInt num_comp_q, q_data_size; 20a78efa86SJames Wright CeedQFunction qf_mass; 21a78efa86SJames Wright CeedElemRestriction elem_restr_q, elem_restr_qd_i; 22a78efa86SJames Wright CeedBasis basis_q; 23a78efa86SJames Wright CeedVector q_data; 24a78efa86SJames Wright 25a78efa86SJames Wright PetscFunctionBeginUser; 26a78efa86SJames Wright { // Get restriction and basis from the RHS function 27a78efa86SJames Wright CeedOperator *sub_ops; 28a78efa86SJames Wright CeedOperatorField field; 29a78efa86SJames Wright PetscInt sub_op_index = 0; // will be 0 for the volume op 30a78efa86SJames Wright 31a78efa86SJames Wright PetscCallCeed(ceed, CeedCompositeOperatorGetSubList(user->op_rhs_ctx->op, &sub_ops)); 32a78efa86SJames Wright PetscCallCeed(ceed, CeedOperatorGetFieldByName(sub_ops[sub_op_index], "q", &field)); 33a78efa86SJames Wright PetscCallCeed(ceed, CeedOperatorFieldGetElemRestriction(field, &elem_restr_q)); 34a78efa86SJames Wright PetscCallCeed(ceed, CeedOperatorFieldGetBasis(field, &basis_q)); 35a78efa86SJames Wright 36a78efa86SJames Wright PetscCallCeed(ceed, CeedOperatorGetFieldByName(sub_ops[sub_op_index], "qdata", &field)); 37a78efa86SJames Wright PetscCallCeed(ceed, CeedOperatorFieldGetElemRestriction(field, &elem_restr_qd_i)); 38a78efa86SJames Wright PetscCallCeed(ceed, CeedOperatorFieldGetVector(field, &q_data)); 39a78efa86SJames Wright } 40a78efa86SJames Wright 41a78efa86SJames Wright PetscCallCeed(ceed, CeedElemRestrictionGetNumComponents(elem_restr_q, &num_comp_q)); 42a78efa86SJames Wright PetscCallCeed(ceed, CeedElemRestrictionGetNumComponents(elem_restr_qd_i, &q_data_size)); 43a78efa86SJames Wright 44a78efa86SJames Wright PetscCall(CreateMassQFunction(ceed, num_comp_q, q_data_size, &qf_mass)); 45a78efa86SJames Wright PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_mass, NULL, NULL, op_mass)); 46a78efa86SJames Wright PetscCallCeed(ceed, CeedOperatorSetField(*op_mass, "u", elem_restr_q, basis_q, CEED_VECTOR_ACTIVE)); 47a78efa86SJames Wright PetscCallCeed(ceed, CeedOperatorSetField(*op_mass, "qdata", elem_restr_qd_i, CEED_BASIS_NONE, q_data)); 48a78efa86SJames Wright PetscCallCeed(ceed, CeedOperatorSetField(*op_mass, "v", elem_restr_q, basis_q, CEED_VECTOR_ACTIVE)); 49a78efa86SJames Wright 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 55*991aef52SJames Wright static PetscErrorCode CreateKSPMass(User user, ProblemData problem) { 56a78efa86SJames Wright Ceed ceed = user->ceed; 57a78efa86SJames Wright DM dm = user->dm; 58a78efa86SJames Wright CeedOperator op_mass; 59a78efa86SJames Wright 60a78efa86SJames Wright PetscFunctionBeginUser; 61a78efa86SJames Wright if (problem->create_mass_operator) PetscCall(problem->create_mass_operator(user, &op_mass)); 62a78efa86SJames Wright else PetscCall(CreateKSPMassOperator_Unstabilized(user, &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)); 71a78efa86SJames Wright PetscCall(MatCeedCreate(dm, dm, op_mass, NULL, &mat_mass)); 72a78efa86SJames Wright PetscCall(MatCeedSetLocalVectors(mat_mass, Zeros_loc, NULL)); 73a78efa86SJames Wright 74a78efa86SJames Wright PetscCall(KSPCreate(comm, &user->mass_ksp)); 75a78efa86SJames Wright PetscCall(KSPSetOptionsPrefix(user->mass_ksp, "mass_")); 76a78efa86SJames Wright { // lumped by default 77a78efa86SJames Wright PC pc; 78a78efa86SJames Wright PetscCall(KSPGetPC(user->mass_ksp, &pc)); 79a78efa86SJames Wright PetscCall(PCSetType(pc, PCJACOBI)); 80a78efa86SJames Wright PetscCall(PCJacobiSetType(pc, PC_JACOBI_ROWSUM)); 81a78efa86SJames Wright PetscCall(KSPSetType(user->mass_ksp, KSPPREONLY)); 82a78efa86SJames Wright } 83a78efa86SJames Wright PetscCall(KSPSetFromOptions_WithMatCeed(user->mass_ksp, mat_mass)); 84a78efa86SJames Wright PetscCall(KSPSetFromOptions(user->mass_ksp)); 85a78efa86SJames Wright PetscCall(VecDestroy(&Zeros_loc)); 86a78efa86SJames Wright PetscCall(MatDestroy(&mat_mass)); 87a78efa86SJames Wright } 88a78efa86SJames Wright 89a78efa86SJames Wright PetscCallCeed(ceed, CeedOperatorDestroy(&op_mass)); 90a78efa86SJames Wright PetscFunctionReturn(PETSC_SUCCESS); 91a78efa86SJames Wright } 92a78efa86SJames Wright 9336c6cbc8SJames Wright PetscErrorCode AddBCSubOperator(Ceed ceed, DM dm, CeedData ceed_data, DMLabel domain_label, PetscInt label_value, CeedInt height, CeedInt Q_sur, 942b916ea7SJeremy L Thompson CeedInt q_data_size_sur, CeedInt jac_data_size_sur, CeedQFunction qf_apply_bc, CeedQFunction qf_apply_bc_jacobian, 95368c645fSJames Wright CeedOperator *op_apply, CeedOperator *op_apply_ijacobian) { 9615c18037SJames Wright CeedVector q_data_sur, jac_data_sur = NULL; 972b916ea7SJeremy L Thompson CeedOperator op_setup_sur, 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; 9915c18037SJames Wright CeedInt num_qpts_sur, dm_field = 0; 100368c645fSJames Wright 10106f41313SJames Wright PetscFunctionBeginUser; 102368c645fSJames Wright // --- Get number of quadrature points for the boundaries 103b4c37c5cSJames Wright PetscCallCeed(ceed, CeedBasisGetNumQuadraturePoints(ceed_data->basis_q_sur, &num_qpts_sur)); 104368c645fSJames Wright 105368c645fSJames Wright // ---- CEED Restriction 10615c18037SJames Wright PetscCall(DMPlexCeedElemRestrictionCreate(ceed, dm, domain_label, label_value, height, dm_field, &elem_restr_q_sur)); 10715c18037SJames Wright PetscCall(DMPlexCeedElemRestrictionCoordinateCreate(ceed, dm, domain_label, label_value, height, &elem_restr_x_sur)); 10815c18037SJames Wright PetscCall(DMPlexCeedElemRestrictionQDataCreate(ceed, dm, domain_label, label_value, height, q_data_size_sur, &elem_restr_qd_i_sur)); 109368c645fSJames Wright if (jac_data_size_sur > 0) { 110368c645fSJames Wright // State-dependent data will be passed from residual to Jacobian. This will be collocated. 11115c18037SJames Wright PetscCall(DMPlexCeedElemRestrictionQDataCreate(ceed, dm, domain_label, label_value, height, jac_data_size_sur, &elem_restr_jd_i_sur)); 112b4c37c5cSJames Wright PetscCallCeed(ceed, CeedElemRestrictionCreateVector(elem_restr_jd_i_sur, &jac_data_sur, NULL)); 113368c645fSJames Wright } 114368c645fSJames Wright 115368c645fSJames Wright // ---- CEED Vector 116defe8520SJames Wright CeedInt loc_num_elem_sur; 117b4c37c5cSJames Wright PetscCallCeed(ceed, CeedElemRestrictionGetNumElements(elem_restr_q_sur, &loc_num_elem_sur)); 118b4c37c5cSJames Wright PetscCallCeed(ceed, CeedVectorCreate(ceed, q_data_size_sur * loc_num_elem_sur * num_qpts_sur, &q_data_sur)); 119368c645fSJames Wright 120368c645fSJames Wright // ---- CEED Operator 121368c645fSJames Wright // ----- CEED Operator for Setup (geometric factors) 122b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorCreate(ceed, ceed_data->qf_setup_sur, NULL, NULL, &op_setup_sur)); 123b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_setup_sur, "dx", elem_restr_x_sur, ceed_data->basis_x_sur, CEED_VECTOR_ACTIVE)); 124b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_setup_sur, "weight", CEED_ELEMRESTRICTION_NONE, ceed_data->basis_x_sur, CEED_VECTOR_NONE)); 12558e1cbfdSJeremy L Thompson PetscCallCeed(ceed, CeedOperatorSetField(op_setup_sur, "surface qdata", elem_restr_qd_i_sur, CEED_BASIS_NONE, CEED_VECTOR_ACTIVE)); 126368c645fSJames Wright 127368c645fSJames Wright // ----- CEED Operator for Physics 128b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_apply_bc, NULL, NULL, &op_apply_bc)); 129b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_apply_bc, "q", elem_restr_q_sur, ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE)); 130b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_apply_bc, "Grad_q", elem_restr_q_sur, ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE)); 13158e1cbfdSJeremy L Thompson PetscCallCeed(ceed, CeedOperatorSetField(op_apply_bc, "surface qdata", elem_restr_qd_i_sur, CEED_BASIS_NONE, q_data_sur)); 132b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_apply_bc, "x", elem_restr_x_sur, ceed_data->basis_x_sur, ceed_data->x_coord)); 133b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_apply_bc, "v", elem_restr_q_sur, ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE)); 134b4c37c5cSJames Wright if (elem_restr_jd_i_sur) 13558e1cbfdSJeremy L Thompson PetscCallCeed(ceed, CeedOperatorSetField(op_apply_bc, "surface jacobian data", elem_restr_jd_i_sur, CEED_BASIS_NONE, jac_data_sur)); 136368c645fSJames Wright 1374b96a86bSJames Wright if (qf_apply_bc_jacobian && elem_restr_jd_i_sur) { 138b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_apply_bc_jacobian, NULL, NULL, &op_apply_bc_jacobian)); 139b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_apply_bc_jacobian, "dq", elem_restr_q_sur, ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE)); 140b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_apply_bc_jacobian, "Grad_dq", elem_restr_q_sur, ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE)); 14158e1cbfdSJeremy L Thompson PetscCallCeed(ceed, CeedOperatorSetField(op_apply_bc_jacobian, "surface qdata", elem_restr_qd_i_sur, CEED_BASIS_NONE, q_data_sur)); 142b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_apply_bc_jacobian, "x", elem_restr_x_sur, ceed_data->basis_x_sur, ceed_data->x_coord)); 14358e1cbfdSJeremy L Thompson PetscCallCeed(ceed, CeedOperatorSetField(op_apply_bc_jacobian, "surface jacobian data", elem_restr_jd_i_sur, CEED_BASIS_NONE, jac_data_sur)); 144b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_apply_bc_jacobian, "v", elem_restr_q_sur, ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE)); 145368c645fSJames Wright } 146368c645fSJames Wright 147368c645fSJames Wright // ----- Apply CEED operator for Setup 148b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorApply(op_setup_sur, ceed_data->x_coord, q_data_sur, CEED_REQUEST_IMMEDIATE)); 149368c645fSJames Wright 150368c645fSJames Wright // ----- Apply Sub-Operator for Physics 151b4c37c5cSJames Wright PetscCallCeed(ceed, CeedCompositeOperatorAddSub(*op_apply, op_apply_bc)); 152b4c37c5cSJames Wright if (op_apply_bc_jacobian) PetscCallCeed(ceed, CeedCompositeOperatorAddSub(*op_apply_ijacobian, op_apply_bc_jacobian)); 153368c645fSJames Wright 154368c645fSJames Wright // ----- Cleanup 155b4c37c5cSJames Wright PetscCallCeed(ceed, CeedVectorDestroy(&q_data_sur)); 156b4c37c5cSJames Wright PetscCallCeed(ceed, CeedVectorDestroy(&jac_data_sur)); 157b4c37c5cSJames Wright PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_q_sur)); 158b4c37c5cSJames Wright PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_x_sur)); 159b4c37c5cSJames Wright PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_qd_i_sur)); 160b4c37c5cSJames Wright PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_jd_i_sur)); 161b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorDestroy(&op_setup_sur)); 162b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorDestroy(&op_apply_bc)); 163b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorDestroy(&op_apply_bc_jacobian)); 164d949ddfcSJames Wright PetscFunctionReturn(PETSC_SUCCESS); 165368c645fSJames Wright } 166368c645fSJames Wright 167a515125bSLeila Ghaffari // Utility function to create CEED Composite Operator for the entire domain 1682b916ea7SJeremy L Thompson PetscErrorCode CreateOperatorForDomain(Ceed ceed, DM dm, SimpleBC bc, CeedData ceed_data, Physics phys, CeedOperator op_apply_vol, 1692b916ea7SJeremy L Thompson CeedOperator op_apply_ijacobian_vol, CeedInt height, CeedInt P_sur, CeedInt Q_sur, CeedInt q_data_size_sur, 1702b916ea7SJeremy L Thompson CeedInt jac_data_size_sur, CeedOperator *op_apply, CeedOperator *op_apply_ijacobian) { 171a515125bSLeila Ghaffari DMLabel domain_label; 172a515125bSLeila Ghaffari 17306f41313SJames Wright PetscFunctionBeginUser; 174a515125bSLeila Ghaffari // Create Composite Operaters 175b4c37c5cSJames Wright PetscCallCeed(ceed, CeedCompositeOperatorCreate(ceed, op_apply)); 176b4c37c5cSJames Wright if (op_apply_ijacobian) PetscCallCeed(ceed, CeedCompositeOperatorCreate(ceed, op_apply_ijacobian)); 177a515125bSLeila Ghaffari 178a515125bSLeila Ghaffari // --Apply Sub-Operator for the volume 179b4c37c5cSJames Wright PetscCallCeed(ceed, CeedCompositeOperatorAddSub(*op_apply, op_apply_vol)); 180b4c37c5cSJames Wright if (op_apply_ijacobian) PetscCallCeed(ceed, CeedCompositeOperatorAddSub(*op_apply_ijacobian, op_apply_ijacobian_vol)); 181a515125bSLeila Ghaffari 182a515125bSLeila Ghaffari // -- Create Sub-Operator for in/outflow BCs 1832b916ea7SJeremy L Thompson PetscCall(DMGetLabel(dm, "Face Sets", &domain_label)); 184a515125bSLeila Ghaffari 185002797a3SLeila Ghaffari // --- Create Sub-Operator for inflow boundaries 186002797a3SLeila Ghaffari for (CeedInt i = 0; i < bc->num_inflow; i++) { 1872b916ea7SJeremy L Thompson PetscCall(AddBCSubOperator(ceed, dm, ceed_data, domain_label, bc->inflows[i], height, Q_sur, q_data_size_sur, jac_data_size_sur, 1882b916ea7SJeremy L Thompson ceed_data->qf_apply_inflow, ceed_data->qf_apply_inflow_jacobian, op_apply, op_apply_ijacobian)); 189a515125bSLeila Ghaffari } 190002797a3SLeila Ghaffari // --- Create Sub-Operator for outflow boundaries 191002797a3SLeila Ghaffari for (CeedInt i = 0; i < bc->num_outflow; i++) { 1922b916ea7SJeremy L Thompson PetscCall(AddBCSubOperator(ceed, dm, ceed_data, domain_label, bc->outflows[i], height, Q_sur, q_data_size_sur, jac_data_size_sur, 1932b916ea7SJeremy L Thompson ceed_data->qf_apply_outflow, ceed_data->qf_apply_outflow_jacobian, op_apply, op_apply_ijacobian)); 1942556a851SJed Brown } 195df55ba5fSJames Wright // --- Create Sub-Operator for freestream boundaries 196df55ba5fSJames Wright for (CeedInt i = 0; i < bc->num_freestream; i++) { 1972b916ea7SJeremy L Thompson PetscCall(AddBCSubOperator(ceed, dm, ceed_data, domain_label, bc->freestreams[i], height, Q_sur, q_data_size_sur, jac_data_size_sur, 1982b916ea7SJeremy L Thompson ceed_data->qf_apply_freestream, ceed_data->qf_apply_freestream_jacobian, op_apply, op_apply_ijacobian)); 199002797a3SLeila Ghaffari } 2009ed3d70dSJames Wright // --- Create Sub-Operator for slip boundaries 2019ed3d70dSJames Wright for (CeedInt i = 0; i < bc->num_slip; i++) { 2029ed3d70dSJames Wright PetscCall(AddBCSubOperator(ceed, dm, ceed_data, domain_label, bc->slips[i], height, Q_sur, q_data_size_sur, jac_data_size_sur, 2039ed3d70dSJames Wright ceed_data->qf_apply_slip, ceed_data->qf_apply_slip_jacobian, op_apply, op_apply_ijacobian)); 2049ed3d70dSJames Wright } 20592ada588SJames Wright 20692ada588SJames Wright // ----- Get Context Labels for Operator 207b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorGetContextFieldLabel(*op_apply, "solution time", &phys->solution_time_label)); 208b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorGetContextFieldLabel(*op_apply, "timestep size", &phys->timestep_size_label)); 209d949ddfcSJames Wright PetscFunctionReturn(PETSC_SUCCESS); 210a515125bSLeila Ghaffari } 211a515125bSLeila Ghaffari 2122b916ea7SJeremy L Thompson PetscErrorCode SetupBCQFunctions(Ceed ceed, PetscInt dim_sur, PetscInt num_comp_x, PetscInt num_comp_q, PetscInt q_data_size_sur, 2132b916ea7SJeremy L Thompson PetscInt jac_data_size_sur, ProblemQFunctionSpec apply_bc, ProblemQFunctionSpec apply_bc_jacobian, 21425988f00SJames Wright CeedQFunction *qf_apply_bc, CeedQFunction *qf_apply_bc_jacobian) { 21525988f00SJames Wright PetscFunctionBeginUser; 21625988f00SJames Wright if (apply_bc.qfunction) { 217b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, apply_bc.qfunction, apply_bc.qfunction_loc, qf_apply_bc)); 218b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionSetContext(*qf_apply_bc, apply_bc.qfunction_context)); 219ebfabadfSJames Wright PetscCallCeed(ceed, CeedQFunctionSetUserFlopsEstimate(*qf_apply_bc, 0)); 220b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(*qf_apply_bc, "q", num_comp_q, CEED_EVAL_INTERP)); 221b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(*qf_apply_bc, "Grad_q", num_comp_q * dim_sur, CEED_EVAL_GRAD)); 222b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(*qf_apply_bc, "surface qdata", q_data_size_sur, CEED_EVAL_NONE)); 223b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(*qf_apply_bc, "x", num_comp_x, CEED_EVAL_INTERP)); 224b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddOutput(*qf_apply_bc, "v", num_comp_q, CEED_EVAL_INTERP)); 225b4c37c5cSJames Wright if (jac_data_size_sur) PetscCallCeed(ceed, CeedQFunctionAddOutput(*qf_apply_bc, "surface jacobian data", jac_data_size_sur, CEED_EVAL_NONE)); 22625988f00SJames Wright } 22725988f00SJames Wright if (apply_bc_jacobian.qfunction) { 228b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, apply_bc_jacobian.qfunction, apply_bc_jacobian.qfunction_loc, qf_apply_bc_jacobian)); 229b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionSetContext(*qf_apply_bc_jacobian, apply_bc_jacobian.qfunction_context)); 230ebfabadfSJames Wright PetscCallCeed(ceed, CeedQFunctionSetUserFlopsEstimate(*qf_apply_bc_jacobian, 0)); 231b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(*qf_apply_bc_jacobian, "dq", num_comp_q, CEED_EVAL_INTERP)); 232b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(*qf_apply_bc_jacobian, "Grad_dq", num_comp_q * dim_sur, CEED_EVAL_GRAD)); 233b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(*qf_apply_bc_jacobian, "surface qdata", q_data_size_sur, CEED_EVAL_NONE)); 234b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(*qf_apply_bc_jacobian, "x", num_comp_x, CEED_EVAL_INTERP)); 235b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(*qf_apply_bc_jacobian, "surface jacobian data", jac_data_size_sur, CEED_EVAL_NONE)); 236b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddOutput(*qf_apply_bc_jacobian, "v", num_comp_q, CEED_EVAL_INTERP)); 23725988f00SJames Wright } 238d949ddfcSJames Wright PetscFunctionReturn(PETSC_SUCCESS); 23925988f00SJames Wright } 24025988f00SJames Wright 241*991aef52SJames Wright PetscErrorCode SetupLibceed(Ceed ceed, CeedData ceed_data, DM dm, User user, AppCtx app_ctx, ProblemData problem, SimpleBC bc) { 242a515125bSLeila Ghaffari PetscFunctionBeginUser; 243a515125bSLeila Ghaffari // ***************************************************************************** 244a515125bSLeila Ghaffari // Set up CEED objects for the interior domain (volume) 245a515125bSLeila Ghaffari // ***************************************************************************** 246a515125bSLeila Ghaffari const PetscInt num_comp_q = 5; 24794a7b3d2SKenneth E. Jansen const CeedInt dim = problem->dim, num_comp_x = problem->dim, q_data_size_vol = problem->q_data_size_vol; 24894a7b3d2SKenneth E. Jansen CeedInt jac_data_size_vol = num_comp_q + 6 + 3; 24994a7b3d2SKenneth E. Jansen 2507d8a615bSJames Wright if (problem->apply_vol_ifunction.qfunction && problem->uses_newtonian) { 25194a7b3d2SKenneth E. Jansen NewtonianIdealGasContext gas; 25294a7b3d2SKenneth E. Jansen PetscCallCeed(ceed, CeedQFunctionContextGetDataRead(problem->apply_vol_ifunction.qfunction_context, CEED_MEM_HOST, &gas)); 25394a7b3d2SKenneth E. Jansen jac_data_size_vol += (gas->idl_enable ? 1 : 0); 25494a7b3d2SKenneth E. Jansen PetscCallCeed(ceed, CeedQFunctionContextRestoreDataRead(problem->apply_vol_ifunction.qfunction_context, &gas)); 25594a7b3d2SKenneth E. Jansen } 25694a7b3d2SKenneth E. Jansen 257752f40e3SJed Brown CeedElemRestriction elem_restr_jd_i; 258752f40e3SJed Brown CeedVector jac_data; 25967263decSKenneth E. Jansen CeedInt num_qpts; 26015c18037SJames Wright DMLabel domain_label = NULL; 26115c18037SJames Wright PetscInt label_value = 0, height = 0, dm_field = 0; 262a515125bSLeila Ghaffari 263a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 264a515125bSLeila Ghaffari // CEED Bases 265a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 26667263decSKenneth E. Jansen DM dm_coord; 26767263decSKenneth E. Jansen PetscCall(DMGetCoordinateDM(dm, &dm_coord)); 26867263decSKenneth E. Jansen 26915c18037SJames Wright PetscCall(CreateBasisFromPlex(ceed, dm, domain_label, label_value, height, dm_field, &ceed_data->basis_q)); 27015c18037SJames Wright PetscCall(CreateBasisFromPlex(ceed, dm_coord, domain_label, label_value, height, dm_field, &ceed_data->basis_x)); 271b4c37c5cSJames Wright PetscCallCeed(ceed, CeedBasisCreateProjection(ceed_data->basis_x, ceed_data->basis_q, &ceed_data->basis_xc)); 272b4c37c5cSJames Wright PetscCallCeed(ceed, CeedBasisGetNumQuadraturePoints(ceed_data->basis_q, &num_qpts)); 273a515125bSLeila Ghaffari 274a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 275a515125bSLeila Ghaffari // CEED Restrictions 276a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 277a515125bSLeila Ghaffari // -- Create restriction 27815c18037SJames Wright PetscCall(DMPlexCeedElemRestrictionCreate(ceed, dm, domain_label, label_value, height, 0, &ceed_data->elem_restr_q)); 27915c18037SJames Wright PetscCall(DMPlexCeedElemRestrictionCoordinateCreate(ceed, dm, domain_label, label_value, height, &ceed_data->elem_restr_x)); 28015c18037SJames Wright PetscCall(DMPlexCeedElemRestrictionQDataCreate(ceed, dm, domain_label, label_value, height, q_data_size_vol, &ceed_data->elem_restr_qd_i)); 28115c18037SJames Wright PetscCall(DMPlexCeedElemRestrictionQDataCreate(ceed, dm, domain_label, label_value, height, jac_data_size_vol, &elem_restr_jd_i)); 282a515125bSLeila Ghaffari // -- Create E vectors 283b4c37c5cSJames Wright PetscCallCeed(ceed, CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->q_ceed, NULL)); 284b4c37c5cSJames Wright PetscCallCeed(ceed, CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->q_dot_ceed, NULL)); 285b4c37c5cSJames Wright PetscCallCeed(ceed, CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->g_ceed, NULL)); 286a515125bSLeila Ghaffari 287a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 288a515125bSLeila Ghaffari // CEED QFunctions 289a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 290a515125bSLeila Ghaffari // -- Create QFunction for quadrature data 291b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, problem->setup_vol.qfunction, problem->setup_vol.qfunction_loc, &ceed_data->qf_setup_vol)); 29215a3537eSJed Brown if (problem->setup_vol.qfunction_context) { 293b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionSetContext(ceed_data->qf_setup_vol, problem->setup_vol.qfunction_context)); 29415a3537eSJed Brown } 295ebfabadfSJames Wright PetscCallCeed(ceed, CeedQFunctionSetUserFlopsEstimate(ceed_data->qf_setup_vol, 0)); 296b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(ceed_data->qf_setup_vol, "dx", num_comp_x * dim, CEED_EVAL_GRAD)); 297b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(ceed_data->qf_setup_vol, "weight", 1, CEED_EVAL_WEIGHT)); 298b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddOutput(ceed_data->qf_setup_vol, "qdata", q_data_size_vol, CEED_EVAL_NONE)); 299a515125bSLeila Ghaffari 300a515125bSLeila Ghaffari // -- Create QFunction for ICs 301b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, problem->ics.qfunction, problem->ics.qfunction_loc, &ceed_data->qf_ics)); 302b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionSetContext(ceed_data->qf_ics, problem->ics.qfunction_context)); 303ebfabadfSJames Wright PetscCallCeed(ceed, CeedQFunctionSetUserFlopsEstimate(ceed_data->qf_ics, 0)); 304b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(ceed_data->qf_ics, "x", num_comp_x, CEED_EVAL_INTERP)); 305b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(ceed_data->qf_ics, "dx", num_comp_x * dim, CEED_EVAL_GRAD)); 306b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddOutput(ceed_data->qf_ics, "q0", num_comp_q, CEED_EVAL_NONE)); 307a515125bSLeila Ghaffari 308a515125bSLeila Ghaffari // -- Create QFunction for RHS 3099785fe93SJed Brown if (problem->apply_vol_rhs.qfunction) { 310b4c37c5cSJames Wright PetscCallCeed( 311b4c37c5cSJames Wright ceed, CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_rhs.qfunction, problem->apply_vol_rhs.qfunction_loc, &ceed_data->qf_rhs_vol)); 312b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionSetContext(ceed_data->qf_rhs_vol, problem->apply_vol_rhs.qfunction_context)); 313ebfabadfSJames Wright PetscCallCeed(ceed, CeedQFunctionSetUserFlopsEstimate(ceed_data->qf_rhs_vol, 0)); 314b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "q", num_comp_q, CEED_EVAL_INTERP)); 315b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "Grad_q", num_comp_q * dim, CEED_EVAL_GRAD)); 316b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "qdata", q_data_size_vol, CEED_EVAL_NONE)); 317b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "x", num_comp_x, CEED_EVAL_INTERP)); 318b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddOutput(ceed_data->qf_rhs_vol, "v", num_comp_q, CEED_EVAL_INTERP)); 319b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddOutput(ceed_data->qf_rhs_vol, "Grad_v", num_comp_q * dim, CEED_EVAL_GRAD)); 320a515125bSLeila Ghaffari } 321a515125bSLeila Ghaffari 322a515125bSLeila Ghaffari // -- Create QFunction for IFunction 3239785fe93SJed Brown if (problem->apply_vol_ifunction.qfunction) { 324b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_ifunction.qfunction, problem->apply_vol_ifunction.qfunction_loc, 325b4c37c5cSJames Wright &ceed_data->qf_ifunction_vol)); 326b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionSetContext(ceed_data->qf_ifunction_vol, problem->apply_vol_ifunction.qfunction_context)); 327ebfabadfSJames Wright PetscCallCeed(ceed, CeedQFunctionSetUserFlopsEstimate(ceed_data->qf_ifunction_vol, 0)); 328b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "q", num_comp_q, CEED_EVAL_INTERP)); 329b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "Grad_q", num_comp_q * dim, CEED_EVAL_GRAD)); 330b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "q dot", num_comp_q, CEED_EVAL_INTERP)); 331b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "qdata", q_data_size_vol, CEED_EVAL_NONE)); 332b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "x", num_comp_x, CEED_EVAL_INTERP)); 333b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "v", num_comp_q, CEED_EVAL_INTERP)); 334b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "Grad_v", num_comp_q * dim, CEED_EVAL_GRAD)); 335b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "jac_data", jac_data_size_vol, CEED_EVAL_NONE)); 336a515125bSLeila Ghaffari } 337a515125bSLeila Ghaffari 338f0b65372SJed Brown CeedQFunction qf_ijacobian_vol = NULL; 339f0b65372SJed Brown if (problem->apply_vol_ijacobian.qfunction) { 340b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_ijacobian.qfunction, problem->apply_vol_ijacobian.qfunction_loc, 341b4c37c5cSJames Wright &qf_ijacobian_vol)); 342b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionSetContext(qf_ijacobian_vol, problem->apply_vol_ijacobian.qfunction_context)); 343ebfabadfSJames Wright PetscCallCeed(ceed, CeedQFunctionSetUserFlopsEstimate(qf_ijacobian_vol, 0)); 344b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(qf_ijacobian_vol, "dq", num_comp_q, CEED_EVAL_INTERP)); 345b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(qf_ijacobian_vol, "Grad_dq", num_comp_q * dim, CEED_EVAL_GRAD)); 346b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(qf_ijacobian_vol, "qdata", q_data_size_vol, CEED_EVAL_NONE)); 347b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(qf_ijacobian_vol, "jac_data", jac_data_size_vol, CEED_EVAL_NONE)); 348b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddOutput(qf_ijacobian_vol, "v", num_comp_q, CEED_EVAL_INTERP)); 349b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddOutput(qf_ijacobian_vol, "Grad_v", num_comp_q * dim, CEED_EVAL_GRAD)); 350f0b65372SJed Brown } 351f0b65372SJed Brown 352a515125bSLeila Ghaffari // --------------------------------------------------------------------------- 353a515125bSLeila Ghaffari // Element coordinates 354a515125bSLeila Ghaffari // --------------------------------------------------------------------------- 355a515125bSLeila Ghaffari // -- Create CEED vector 356b4c37c5cSJames Wright PetscCallCeed(ceed, CeedElemRestrictionCreateVector(ceed_data->elem_restr_x, &ceed_data->x_coord, NULL)); 357a515125bSLeila Ghaffari 358a515125bSLeila Ghaffari // -- Copy PETSc vector in CEED vector 359a515125bSLeila Ghaffari Vec X_loc; 360cac8aa24SJed Brown { 361cac8aa24SJed Brown DM cdm; 3622b916ea7SJeremy L Thompson PetscCall(DMGetCellCoordinateDM(dm, &cdm)); 3632b916ea7SJeremy L Thompson if (cdm) { 3642b916ea7SJeremy L Thompson PetscCall(DMGetCellCoordinatesLocal(dm, &X_loc)); 3652b916ea7SJeremy L Thompson } else { 3662b916ea7SJeremy L Thompson PetscCall(DMGetCoordinatesLocal(dm, &X_loc)); 367cac8aa24SJed Brown } 3682b916ea7SJeremy L Thompson } 3692b916ea7SJeremy L Thompson PetscCall(VecScale(X_loc, problem->dm_scale)); 370a7dac1d5SJames Wright PetscCall(VecCopyPetscToCeed(X_loc, ceed_data->x_coord)); 371a515125bSLeila Ghaffari 372a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 373a515125bSLeila Ghaffari // CEED vectors 374a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 375a515125bSLeila Ghaffari // -- Create CEED vector for geometric data 376b4c37c5cSJames Wright PetscCallCeed(ceed, CeedElemRestrictionCreateVector(ceed_data->elem_restr_qd_i, &ceed_data->q_data, NULL)); 377b4c37c5cSJames Wright PetscCallCeed(ceed, CeedElemRestrictionCreateVector(elem_restr_jd_i, &jac_data, NULL)); 3780b0430b7SJames Wright 379a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 380a515125bSLeila Ghaffari // CEED Operators 381a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 382a515125bSLeila Ghaffari // -- Create CEED operator for quadrature data 383b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorCreate(ceed, ceed_data->qf_setup_vol, NULL, NULL, &ceed_data->op_setup_vol)); 384b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(ceed_data->op_setup_vol, "dx", ceed_data->elem_restr_x, ceed_data->basis_x, CEED_VECTOR_ACTIVE)); 385b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(ceed_data->op_setup_vol, "weight", CEED_ELEMRESTRICTION_NONE, ceed_data->basis_x, CEED_VECTOR_NONE)); 38658e1cbfdSJeremy L Thompson PetscCallCeed(ceed, CeedOperatorSetField(ceed_data->op_setup_vol, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_NONE, CEED_VECTOR_ACTIVE)); 387a515125bSLeila Ghaffari 388a515125bSLeila Ghaffari // -- Create CEED operator for ICs 3898f18bb8bSJames Wright CeedOperator op_ics; 390b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorCreate(ceed, ceed_data->qf_ics, NULL, NULL, &op_ics)); 391b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_ics, "x", ceed_data->elem_restr_x, ceed_data->basis_xc, CEED_VECTOR_ACTIVE)); 392b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_ics, "dx", ceed_data->elem_restr_x, ceed_data->basis_xc, CEED_VECTOR_ACTIVE)); 39358e1cbfdSJeremy L Thompson PetscCallCeed(ceed, CeedOperatorSetField(op_ics, "q0", ceed_data->elem_restr_q, CEED_BASIS_NONE, CEED_VECTOR_ACTIVE)); 394b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorGetContextFieldLabel(op_ics, "evaluation time", &user->phys->ics_time_label)); 3958f18bb8bSJames Wright PetscCall(OperatorApplyContextCreate(NULL, dm, user->ceed, op_ics, ceed_data->x_coord, NULL, NULL, user->Q_loc, &ceed_data->op_ics_ctx)); 396b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorDestroy(&op_ics)); 397a515125bSLeila Ghaffari 398a515125bSLeila Ghaffari // Create CEED operator for RHS 399a515125bSLeila Ghaffari if (ceed_data->qf_rhs_vol) { 400a515125bSLeila Ghaffari CeedOperator op; 401b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorCreate(ceed, ceed_data->qf_rhs_vol, NULL, NULL, &op)); 402b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op, "q", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE)); 403b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op, "Grad_q", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE)); 40458e1cbfdSJeremy L Thompson PetscCallCeed(ceed, CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_NONE, ceed_data->q_data)); 405b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord)); 406b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE)); 407b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE)); 408a515125bSLeila Ghaffari user->op_rhs_vol = op; 409a515125bSLeila Ghaffari } 410a515125bSLeila Ghaffari 411a515125bSLeila Ghaffari // -- CEED operator for IFunction 412a515125bSLeila Ghaffari if (ceed_data->qf_ifunction_vol) { 413a515125bSLeila Ghaffari CeedOperator op; 414b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorCreate(ceed, ceed_data->qf_ifunction_vol, NULL, NULL, &op)); 415b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op, "q", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE)); 416b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op, "Grad_q", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE)); 417b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op, "q dot", ceed_data->elem_restr_q, ceed_data->basis_q, user->q_dot_ceed)); 41858e1cbfdSJeremy L Thompson PetscCallCeed(ceed, CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_NONE, ceed_data->q_data)); 419b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord)); 420b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE)); 421b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE)); 42258e1cbfdSJeremy L Thompson PetscCallCeed(ceed, CeedOperatorSetField(op, "jac_data", elem_restr_jd_i, CEED_BASIS_NONE, jac_data)); 423752f40e3SJed Brown 424a515125bSLeila Ghaffari user->op_ifunction_vol = op; 425a515125bSLeila Ghaffari } 426a515125bSLeila Ghaffari 427f0b65372SJed Brown CeedOperator op_ijacobian_vol = NULL; 428f0b65372SJed Brown if (qf_ijacobian_vol) { 429f0b65372SJed Brown CeedOperator op; 430b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_ijacobian_vol, NULL, NULL, &op)); 431b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op, "dq", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE)); 432b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op, "Grad_dq", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE)); 43358e1cbfdSJeremy L Thompson PetscCallCeed(ceed, CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_NONE, ceed_data->q_data)); 43458e1cbfdSJeremy L Thompson PetscCallCeed(ceed, CeedOperatorSetField(op, "jac_data", elem_restr_jd_i, CEED_BASIS_NONE, jac_data)); 435b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE)); 436b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE)); 437f0b65372SJed Brown op_ijacobian_vol = op; 438b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_ijacobian_vol)); 439f0b65372SJed Brown } 440f0b65372SJed Brown 441a515125bSLeila Ghaffari // ***************************************************************************** 442a515125bSLeila Ghaffari // Set up CEED objects for the exterior domain (surface) 443a515125bSLeila Ghaffari // ***************************************************************************** 44415c18037SJames Wright height = 1; 44515c18037SJames Wright CeedInt dim_sur = dim - height, P_sur = app_ctx->degree + 1, Q_sur = P_sur + app_ctx->q_extra; 4464b96a86bSJames Wright const CeedInt q_data_size_sur = problem->q_data_size_sur, jac_data_size_sur = user->phys->implicit ? problem->jac_data_size_sur : 0; 447a515125bSLeila Ghaffari 448a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 449a515125bSLeila Ghaffari // CEED Bases 450a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 45167263decSKenneth E. Jansen 45267263decSKenneth E. Jansen DMLabel label = 0; 45367263decSKenneth E. Jansen PetscInt face_id = 0; 45467263decSKenneth E. Jansen PetscInt field = 0; // Still want the normal, default field 45567263decSKenneth E. Jansen PetscCall(CreateBasisFromPlex(ceed, dm, label, face_id, height, field, &ceed_data->basis_q_sur)); 45667263decSKenneth E. Jansen PetscCall(CreateBasisFromPlex(ceed, dm_coord, label, face_id, height, field, &ceed_data->basis_x_sur)); 457a515125bSLeila Ghaffari 458a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 459a515125bSLeila Ghaffari // CEED QFunctions 460a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 461a515125bSLeila Ghaffari // -- Create QFunction for quadrature data 462b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, problem->setup_sur.qfunction, problem->setup_sur.qfunction_loc, &ceed_data->qf_setup_sur)); 46315a3537eSJed Brown if (problem->setup_sur.qfunction_context) { 464b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionSetContext(ceed_data->qf_setup_sur, problem->setup_sur.qfunction_context)); 46515a3537eSJed Brown } 466ebfabadfSJames Wright PetscCallCeed(ceed, CeedQFunctionSetUserFlopsEstimate(ceed_data->qf_setup_sur, 0)); 467b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(ceed_data->qf_setup_sur, "dx", num_comp_x * dim_sur, CEED_EVAL_GRAD)); 468b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(ceed_data->qf_setup_sur, "weight", 1, CEED_EVAL_WEIGHT)); 469b4c37c5cSJames Wright PetscCallCeed(ceed, CeedQFunctionAddOutput(ceed_data->qf_setup_sur, "surface qdata", q_data_size_sur, CEED_EVAL_NONE)); 470a515125bSLeila Ghaffari 4712b916ea7SJeremy L Thompson PetscCall(SetupBCQFunctions(ceed, dim_sur, num_comp_x, num_comp_q, q_data_size_sur, jac_data_size_sur, problem->apply_inflow, 4722b916ea7SJeremy L Thompson problem->apply_inflow_jacobian, &ceed_data->qf_apply_inflow, &ceed_data->qf_apply_inflow_jacobian)); 4732b916ea7SJeremy L Thompson PetscCall(SetupBCQFunctions(ceed, dim_sur, num_comp_x, num_comp_q, q_data_size_sur, jac_data_size_sur, problem->apply_outflow, 4742b916ea7SJeremy L Thompson problem->apply_outflow_jacobian, &ceed_data->qf_apply_outflow, &ceed_data->qf_apply_outflow_jacobian)); 4752b916ea7SJeremy L Thompson PetscCall(SetupBCQFunctions(ceed, dim_sur, num_comp_x, num_comp_q, q_data_size_sur, jac_data_size_sur, problem->apply_freestream, 4762b916ea7SJeremy L Thompson problem->apply_freestream_jacobian, &ceed_data->qf_apply_freestream, &ceed_data->qf_apply_freestream_jacobian)); 4779ed3d70dSJames Wright PetscCall(SetupBCQFunctions(ceed, dim_sur, num_comp_x, num_comp_q, q_data_size_sur, jac_data_size_sur, problem->apply_slip, 4789ed3d70dSJames Wright problem->apply_slip_jacobian, &ceed_data->qf_apply_slip, &ceed_data->qf_apply_slip_jacobian)); 479a515125bSLeila Ghaffari 480a515125bSLeila Ghaffari // ***************************************************************************** 481a515125bSLeila Ghaffari // CEED Operator Apply 482a515125bSLeila Ghaffari // ***************************************************************************** 483a515125bSLeila Ghaffari // -- Apply CEED Operator for the geometric data 484b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorApply(ceed_data->op_setup_vol, ceed_data->x_coord, ceed_data->q_data, CEED_REQUEST_IMMEDIATE)); 485a515125bSLeila Ghaffari 486a515125bSLeila Ghaffari // -- Create and apply CEED Composite Operator for the entire domain 487a515125bSLeila Ghaffari if (!user->phys->implicit) { // RHS 488da5fe0e4SJames Wright CeedOperator op_rhs; 489da5fe0e4SJames Wright 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, 490da5fe0e4SJames Wright NULL)); 491da5fe0e4SJames Wright PetscCall(OperatorApplyContextCreate(dm, dm, ceed, op_rhs, user->q_ceed, user->g_ceed, user->Q_loc, NULL, &user->op_rhs_ctx)); 492b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorDestroy(&op_rhs)); 493a78efa86SJames Wright PetscCall(CreateKSPMass(user, problem)); 494c2376cc9SJames Wright PetscCheck(app_ctx->sgs_model_type == SGS_MODEL_NONE, user->comm, PETSC_ERR_SUP, "SGS modeling not implemented for explicit timestepping"); 495a515125bSLeila Ghaffari } else { // IFunction 496ebfabadfSJames Wright CeedOperator op_ijacobian = NULL; 497ebfabadfSJames Wright 4982b916ea7SJeremy L Thompson PetscCall(CreateOperatorForDomain(ceed, dm, bc, ceed_data, user->phys, user->op_ifunction_vol, op_ijacobian_vol, height, P_sur, Q_sur, 499ebfabadfSJames Wright q_data_size_sur, jac_data_size_sur, &user->op_ifunction, op_ijacobian_vol ? &op_ijacobian : NULL)); 500ebfabadfSJames Wright if (op_ijacobian) { 501ebfabadfSJames Wright PetscCall(MatCeedCreate(user->dm, user->dm, op_ijacobian, NULL, &user->mat_ijacobian)); 502ebfabadfSJames Wright PetscCall(MatCeedSetLocalVectors(user->mat_ijacobian, user->Q_dot_loc, NULL)); 503ebfabadfSJames Wright PetscCallCeed(ceed, CeedOperatorGetContextFieldLabel(op_ijacobian, "ijacobian time shift", &user->phys->ijacobian_time_shift_label)); 504ebfabadfSJames Wright PetscCallCeed(ceed, CeedOperatorDestroy(&op_ijacobian)); 505f0b65372SJed Brown } 506ad494f68SJames Wright if (app_ctx->sgs_model_type == SGS_MODEL_DATA_DRIVEN) PetscCall(SgsDDSetup(ceed, user, ceed_data, problem)); 5076d0190e2SJames Wright } 50891933550SJames Wright 509c2376cc9SJames Wright if (problem->use_strong_bc_ceed) PetscCall(SetupStrongBC_Ceed(ceed, ceed_data, dm, user, problem, bc)); 51091933550SJames Wright if (app_ctx->turb_spanstats_enable) PetscCall(TurbulenceStatisticsSetup(ceed, user, ceed_data, problem)); 511aa0b7f76SJames Wright if (app_ctx->diff_filter_monitor && !user->diff_filter) PetscCall(DifferentialFilterSetup(ceed, user, ceed_data, problem)); 5121c17f66aSJames Wright if (app_ctx->sgs_train_enable) PetscCall(SGS_DD_TrainingSetup(ceed, user, ceed_data, problem)); 51391933550SJames Wright 514b4c37c5cSJames Wright PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_jd_i)); 515b4c37c5cSJames Wright PetscCallCeed(ceed, CeedOperatorDestroy(&op_ijacobian_vol)); 516b4c37c5cSJames Wright PetscCallCeed(ceed, CeedVectorDestroy(&jac_data)); 517d949ddfcSJames Wright PetscFunctionReturn(PETSC_SUCCESS); 518a515125bSLeila Ghaffari } 519