1727da7e7SJeremy L Thompson // Copyright (c) 2017-2022, 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 11a515125bSLeila Ghaffari #include "../navierstokes.h" 12a515125bSLeila Ghaffari 13a515125bSLeila Ghaffari // Utility function - essential BC dofs are encoded in closure indices as -(i+1). 14a515125bSLeila Ghaffari PetscInt Involute(PetscInt i) { 15a515125bSLeila Ghaffari return i >= 0 ? i : -(i+1); 16a515125bSLeila Ghaffari } 17a515125bSLeila Ghaffari 18a515125bSLeila Ghaffari // Utility function to create local CEED restriction 196b1ccf21SJeremy L Thompson PetscErrorCode CreateRestrictionFromPlex(Ceed ceed, DM dm, CeedInt height, 206b1ccf21SJeremy L Thompson DMLabel domain_label, CeedInt value, CeedElemRestriction *elem_restr) { 216b1ccf21SJeremy L Thompson PetscInt num_elem, elem_size, num_dof, num_comp, *elem_restr_offsets; 22a515125bSLeila Ghaffari PetscErrorCode ierr; 236b1ccf21SJeremy L Thompson 24a515125bSLeila Ghaffari PetscFunctionBeginUser; 256b1ccf21SJeremy L Thompson ierr = DMPlexGetLocalOffsets(dm, domain_label, value, height, 0, &num_elem, 266b1ccf21SJeremy L Thompson &elem_size, &num_comp, &num_dof, &elem_restr_offsets); 276b1ccf21SJeremy L Thompson CHKERRQ(ierr); 28a515125bSLeila Ghaffari 296b1ccf21SJeremy L Thompson CeedElemRestrictionCreate(ceed, num_elem, elem_size, num_comp, 306b1ccf21SJeremy L Thompson 1, num_dof, CEED_MEM_HOST, CEED_COPY_VALUES, 316b1ccf21SJeremy L Thompson elem_restr_offsets, elem_restr); 326b1ccf21SJeremy L Thompson ierr = PetscFree(elem_restr_offsets); CHKERRQ(ierr); 33a515125bSLeila Ghaffari 34a515125bSLeila Ghaffari PetscFunctionReturn(0); 35a515125bSLeila Ghaffari } 36a515125bSLeila Ghaffari 37a515125bSLeila Ghaffari // Utility function to get Ceed Restriction for each domain 38a515125bSLeila Ghaffari PetscErrorCode GetRestrictionForDomain(Ceed ceed, DM dm, CeedInt height, 39a515125bSLeila Ghaffari DMLabel domain_label, PetscInt value, 406b1ccf21SJeremy L Thompson CeedInt Q, CeedInt q_data_size, 41a515125bSLeila Ghaffari CeedElemRestriction *elem_restr_q, 42a515125bSLeila Ghaffari CeedElemRestriction *elem_restr_x, 43a515125bSLeila Ghaffari CeedElemRestriction *elem_restr_qd_i) { 44a515125bSLeila Ghaffari DM dm_coord; 45a515125bSLeila Ghaffari CeedInt dim, loc_num_elem; 46a515125bSLeila Ghaffari CeedInt Q_dim; 47395c96d3SJed Brown CeedElemRestriction elem_restr_tmp; 48a515125bSLeila Ghaffari PetscErrorCode ierr; 49a515125bSLeila Ghaffari PetscFunctionBeginUser; 50a515125bSLeila Ghaffari 51a515125bSLeila Ghaffari ierr = DMGetDimension(dm, &dim); CHKERRQ(ierr); 52a515125bSLeila Ghaffari dim -= height; 53a515125bSLeila Ghaffari Q_dim = CeedIntPow(Q, dim); 54395c96d3SJed Brown ierr = CreateRestrictionFromPlex(ceed, dm, height, domain_label, value, 55395c96d3SJed Brown &elem_restr_tmp); 56395c96d3SJed Brown CHKERRQ(ierr); 57395c96d3SJed Brown if (elem_restr_q) *elem_restr_q = elem_restr_tmp; 58395c96d3SJed Brown if (elem_restr_x) { 59cac8aa24SJed Brown ierr = DMGetCellCoordinateDM(dm, &dm_coord); CHKERRQ(ierr); 60cac8aa24SJed Brown if (!dm_coord) { 61a515125bSLeila Ghaffari ierr = DMGetCoordinateDM(dm, &dm_coord); CHKERRQ(ierr); 62cac8aa24SJed Brown } 63a515125bSLeila Ghaffari ierr = DMPlexSetClosurePermutationTensor(dm_coord, PETSC_DETERMINE, NULL); 64a515125bSLeila Ghaffari CHKERRQ(ierr); 656b1ccf21SJeremy L Thompson ierr = CreateRestrictionFromPlex(ceed, dm_coord, height, domain_label, value, 666b1ccf21SJeremy L Thompson elem_restr_x); 676b1ccf21SJeremy L Thompson CHKERRQ(ierr); 68395c96d3SJed Brown } 69395c96d3SJed Brown if (elem_restr_qd_i) { 70395c96d3SJed Brown CeedElemRestrictionGetNumElements(elem_restr_tmp, &loc_num_elem); 71a515125bSLeila Ghaffari CeedElemRestrictionCreateStrided(ceed, loc_num_elem, Q_dim, 72a515125bSLeila Ghaffari q_data_size, q_data_size*loc_num_elem*Q_dim, 73a515125bSLeila Ghaffari CEED_STRIDES_BACKEND, elem_restr_qd_i); 74395c96d3SJed Brown } 75395c96d3SJed Brown if (!elem_restr_q) CeedElemRestrictionDestroy(&elem_restr_tmp); 76a515125bSLeila Ghaffari PetscFunctionReturn(0); 77a515125bSLeila Ghaffari } 78a515125bSLeila Ghaffari 79368c645fSJames Wright PetscErrorCode AddBCSubOperator(Ceed ceed, DM dm, CeedData ceed_data, 80368c645fSJames Wright DMLabel domain_label, PetscInt value, 81368c645fSJames Wright CeedInt height, CeedInt Q_sur, 82368c645fSJames Wright CeedInt q_data_size_sur, CeedInt jac_data_size_sur, 83368c645fSJames Wright CeedQFunction qf_apply_bc, CeedQFunction qf_apply_bc_jacobian, 84368c645fSJames Wright CeedOperator *op_apply, CeedOperator *op_apply_ijacobian) { 85368c645fSJames Wright CeedVector q_data_sur, jac_data_sur; 86368c645fSJames Wright CeedOperator op_setup_sur, op_apply_bc, 87368c645fSJames Wright op_apply_bc_jacobian = NULL; 88368c645fSJames Wright CeedElemRestriction elem_restr_x_sur, elem_restr_q_sur, elem_restr_qd_i_sur, 89368c645fSJames Wright elem_restr_jd_i_sur; 90368c645fSJames Wright CeedInt num_qpts_sur; 91368c645fSJames Wright PetscFunctionBeginUser; 92368c645fSJames Wright 93368c645fSJames Wright // --- Get number of quadrature points for the boundaries 94368c645fSJames Wright CeedBasisGetNumQuadraturePoints(ceed_data->basis_q_sur, &num_qpts_sur); 95368c645fSJames Wright 96368c645fSJames Wright 97368c645fSJames Wright // ---- CEED Restriction 98368c645fSJames Wright PetscCall(GetRestrictionForDomain(ceed, dm, height, domain_label, value, Q_sur, 99368c645fSJames Wright q_data_size_sur, &elem_restr_q_sur, &elem_restr_x_sur, &elem_restr_qd_i_sur)); 100368c645fSJames Wright if (jac_data_size_sur > 0) { 101368c645fSJames Wright // State-dependent data will be passed from residual to Jacobian. This will be collocated. 102368c645fSJames Wright PetscCall(GetRestrictionForDomain(ceed, dm, height, domain_label, value, Q_sur, 103368c645fSJames Wright jac_data_size_sur, NULL, NULL, &elem_restr_jd_i_sur)); 104368c645fSJames Wright CeedElemRestrictionCreateVector(elem_restr_jd_i_sur, &jac_data_sur, NULL); 105368c645fSJames Wright } else { 106368c645fSJames Wright elem_restr_jd_i_sur = NULL; 107368c645fSJames Wright jac_data_sur = NULL; 108368c645fSJames Wright } 109368c645fSJames Wright 110368c645fSJames Wright // ---- CEED Vector 111368c645fSJames Wright PetscInt loc_num_elem_sur; 112368c645fSJames Wright CeedElemRestrictionGetNumElements(elem_restr_q_sur, &loc_num_elem_sur); 113368c645fSJames Wright CeedVectorCreate(ceed, q_data_size_sur*loc_num_elem_sur*num_qpts_sur, 114368c645fSJames Wright &q_data_sur); 115368c645fSJames Wright 116368c645fSJames Wright // ---- CEED Operator 117368c645fSJames Wright // ----- CEED Operator for Setup (geometric factors) 118368c645fSJames Wright CeedOperatorCreate(ceed, ceed_data->qf_setup_sur, NULL, NULL, &op_setup_sur); 119368c645fSJames Wright CeedOperatorSetField(op_setup_sur, "dx", elem_restr_x_sur, 120368c645fSJames Wright ceed_data->basis_x_sur, CEED_VECTOR_ACTIVE); 121368c645fSJames Wright CeedOperatorSetField(op_setup_sur, "weight", CEED_ELEMRESTRICTION_NONE, 122368c645fSJames Wright ceed_data->basis_x_sur, CEED_VECTOR_NONE); 123368c645fSJames Wright CeedOperatorSetField(op_setup_sur, "surface qdata", elem_restr_qd_i_sur, 124368c645fSJames Wright CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); 125368c645fSJames Wright 126368c645fSJames Wright // ----- CEED Operator for Physics 127368c645fSJames Wright CeedOperatorCreate(ceed, qf_apply_bc, NULL, NULL, &op_apply_bc); 128368c645fSJames Wright CeedOperatorSetField(op_apply_bc, "q", elem_restr_q_sur, ceed_data->basis_q_sur, 129368c645fSJames Wright CEED_VECTOR_ACTIVE); 130368c645fSJames Wright CeedOperatorSetField(op_apply_bc, "Grad_q", elem_restr_q_sur, 131368c645fSJames Wright ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 132368c645fSJames Wright CeedOperatorSetField(op_apply_bc, "surface qdata", elem_restr_qd_i_sur, 133368c645fSJames Wright CEED_BASIS_COLLOCATED, q_data_sur); 134368c645fSJames Wright CeedOperatorSetField(op_apply_bc, "x", elem_restr_x_sur, ceed_data->basis_x_sur, 135368c645fSJames Wright ceed_data->x_coord); 136368c645fSJames Wright CeedOperatorSetField(op_apply_bc, "v", elem_restr_q_sur, ceed_data->basis_q_sur, 137368c645fSJames Wright CEED_VECTOR_ACTIVE); 138368c645fSJames Wright if (elem_restr_jd_i_sur) 139368c645fSJames Wright CeedOperatorSetField(op_apply_bc, "surface jacobian data", 140368c645fSJames Wright elem_restr_jd_i_sur, 141368c645fSJames Wright CEED_BASIS_COLLOCATED, jac_data_sur); 142368c645fSJames Wright 143368c645fSJames Wright if (qf_apply_bc_jacobian) { 144368c645fSJames Wright CeedOperatorCreate(ceed, qf_apply_bc_jacobian, NULL, NULL, 145368c645fSJames Wright &op_apply_bc_jacobian); 146368c645fSJames Wright CeedOperatorSetField(op_apply_bc_jacobian, "dq", elem_restr_q_sur, 147368c645fSJames Wright ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 148368c645fSJames Wright CeedOperatorSetField(op_apply_bc_jacobian, "Grad_dq", elem_restr_q_sur, 149368c645fSJames Wright ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 150368c645fSJames Wright CeedOperatorSetField(op_apply_bc_jacobian, "surface qdata", elem_restr_qd_i_sur, 151368c645fSJames Wright CEED_BASIS_COLLOCATED, q_data_sur); 152368c645fSJames Wright CeedOperatorSetField(op_apply_bc_jacobian, "x", elem_restr_x_sur, 153368c645fSJames Wright ceed_data->basis_x_sur, ceed_data->x_coord); 154368c645fSJames Wright CeedOperatorSetField(op_apply_bc_jacobian, "surface jacobian data", 155368c645fSJames Wright elem_restr_jd_i_sur, CEED_BASIS_COLLOCATED, jac_data_sur); 156368c645fSJames Wright CeedOperatorSetField(op_apply_bc_jacobian, "v", elem_restr_q_sur, 157368c645fSJames Wright ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 158368c645fSJames Wright } 159368c645fSJames Wright 160368c645fSJames Wright // ----- Apply CEED operator for Setup 161368c645fSJames Wright CeedOperatorApply(op_setup_sur, ceed_data->x_coord, q_data_sur, 162368c645fSJames Wright CEED_REQUEST_IMMEDIATE); 163368c645fSJames Wright 164368c645fSJames Wright // ----- Apply Sub-Operator for Physics 165368c645fSJames Wright CeedCompositeOperatorAddSub(*op_apply, op_apply_bc); 166368c645fSJames Wright if (op_apply_bc_jacobian) 167368c645fSJames Wright CeedCompositeOperatorAddSub(*op_apply_ijacobian, op_apply_bc_jacobian); 168368c645fSJames Wright 169368c645fSJames Wright // ----- Cleanup 170368c645fSJames Wright CeedVectorDestroy(&q_data_sur); 171368c645fSJames Wright CeedVectorDestroy(&jac_data_sur); 172368c645fSJames Wright CeedElemRestrictionDestroy(&elem_restr_q_sur); 173368c645fSJames Wright CeedElemRestrictionDestroy(&elem_restr_x_sur); 174368c645fSJames Wright CeedElemRestrictionDestroy(&elem_restr_qd_i_sur); 175368c645fSJames Wright CeedElemRestrictionDestroy(&elem_restr_jd_i_sur); 176368c645fSJames Wright CeedOperatorDestroy(&op_setup_sur); 177368c645fSJames Wright CeedOperatorDestroy(&op_apply_bc); 178368c645fSJames Wright CeedOperatorDestroy(&op_apply_bc_jacobian); 179368c645fSJames Wright 180368c645fSJames Wright PetscFunctionReturn(0); 181368c645fSJames Wright } 182368c645fSJames Wright 183a515125bSLeila Ghaffari // Utility function to create CEED Composite Operator for the entire domain 184a515125bSLeila Ghaffari PetscErrorCode CreateOperatorForDomain(Ceed ceed, DM dm, SimpleBC bc, 185a515125bSLeila Ghaffari CeedData ceed_data, Physics phys, 186f0b65372SJed Brown CeedOperator op_apply_vol, 187f0b65372SJed Brown CeedOperator op_apply_ijacobian_vol, 188f0b65372SJed Brown CeedInt height, 189f0b65372SJed Brown CeedInt P_sur, CeedInt Q_sur, 190f0b65372SJed Brown CeedInt q_data_size_sur, CeedInt jac_data_size_sur, 191f0b65372SJed Brown CeedOperator *op_apply, CeedOperator *op_apply_ijacobian) { 192a515125bSLeila Ghaffari DMLabel domain_label; 193a515125bSLeila Ghaffari PetscErrorCode ierr; 194a515125bSLeila Ghaffari PetscFunctionBeginUser; 195a515125bSLeila Ghaffari 196a515125bSLeila Ghaffari // Create Composite Operaters 197a515125bSLeila Ghaffari CeedCompositeOperatorCreate(ceed, op_apply); 198f0b65372SJed Brown if (op_apply_ijacobian) 199f0b65372SJed Brown CeedCompositeOperatorCreate(ceed, op_apply_ijacobian); 200a515125bSLeila Ghaffari 201a515125bSLeila Ghaffari // --Apply Sub-Operator for the volume 202a515125bSLeila Ghaffari CeedCompositeOperatorAddSub(*op_apply, op_apply_vol); 203f0b65372SJed Brown if (op_apply_ijacobian) 204f0b65372SJed Brown CeedCompositeOperatorAddSub(*op_apply_ijacobian, op_apply_ijacobian_vol); 205a515125bSLeila Ghaffari 206a515125bSLeila Ghaffari // -- Create Sub-Operator for in/outflow BCs 207bb8a0c61SJames Wright if (phys->has_neumann || 1) { 208a515125bSLeila Ghaffari // --- Setup 209a515125bSLeila Ghaffari ierr = DMGetLabel(dm, "Face Sets", &domain_label); CHKERRQ(ierr); 210a515125bSLeila Ghaffari 211002797a3SLeila Ghaffari // --- Create Sub-Operator for inflow boundaries 212002797a3SLeila Ghaffari for (CeedInt i=0; i < bc->num_inflow; i++) { 213368c645fSJames Wright PetscCall(AddBCSubOperator(ceed, dm, ceed_data, domain_label, bc->inflows[i], 214368c645fSJames Wright height, Q_sur, q_data_size_sur, jac_data_size_sur, 215368c645fSJames Wright ceed_data->qf_apply_inflow, ceed_data->qf_apply_inflow_jacobian, 216368c645fSJames Wright op_apply, op_apply_ijacobian)); 217a515125bSLeila Ghaffari } 218a515125bSLeila Ghaffari 219002797a3SLeila Ghaffari // --- Create Sub-Operator for outflow boundaries 220002797a3SLeila Ghaffari for (CeedInt i=0; i < bc->num_outflow; i++) { 221368c645fSJames Wright PetscCall(AddBCSubOperator(ceed, dm, ceed_data, domain_label, bc->outflows[i], 222368c645fSJames Wright height, Q_sur, q_data_size_sur, jac_data_size_sur, 223368c645fSJames Wright ceed_data->qf_apply_outflow, ceed_data->qf_apply_outflow_jacobian, 224368c645fSJames Wright op_apply, op_apply_ijacobian)); 225002797a3SLeila Ghaffari } 226002797a3SLeila Ghaffari } 22792ada588SJames Wright 22892ada588SJames Wright // ----- Get Context Labels for Operator 22992ada588SJames Wright CeedOperatorContextGetFieldLabel(*op_apply, "solution time", 23092ada588SJames Wright &phys->solution_time_label); 231bb8a0c61SJames Wright CeedOperatorContextGetFieldLabel(*op_apply, "timestep size", 232bb8a0c61SJames Wright &phys->timestep_size_label); 23392ada588SJames Wright 234a515125bSLeila Ghaffari PetscFunctionReturn(0); 235a515125bSLeila Ghaffari } 236a515125bSLeila Ghaffari 237*25988f00SJames Wright PetscErrorCode SetupBCQFunctions(Ceed ceed, PetscInt dim_sur, 238*25988f00SJames Wright PetscInt num_comp_x, PetscInt num_comp_q, 239*25988f00SJames Wright PetscInt q_data_size_sur, PetscInt jac_data_size_sur, 240*25988f00SJames Wright ProblemQFunctionSpec apply_bc, ProblemQFunctionSpec apply_bc_jacobian, 241*25988f00SJames Wright CeedQFunction *qf_apply_bc, CeedQFunction *qf_apply_bc_jacobian) { 242*25988f00SJames Wright PetscFunctionBeginUser; 243*25988f00SJames Wright 244*25988f00SJames Wright if (apply_bc.qfunction) { 245*25988f00SJames Wright // *INDENT-OFF* 246*25988f00SJames Wright CeedQFunctionCreateInterior(ceed, 1, apply_bc.qfunction, apply_bc.qfunction_loc, qf_apply_bc); 247*25988f00SJames Wright CeedQFunctionSetContext(*qf_apply_bc, apply_bc.qfunction_context); 248*25988f00SJames Wright CeedQFunctionContextDestroy(&apply_bc.qfunction_context); 249*25988f00SJames Wright CeedQFunctionAddInput(*qf_apply_bc, "q", num_comp_q, CEED_EVAL_INTERP); 250*25988f00SJames Wright CeedQFunctionAddInput(*qf_apply_bc, "Grad_q", num_comp_q*dim_sur, CEED_EVAL_GRAD); 251*25988f00SJames Wright CeedQFunctionAddInput(*qf_apply_bc, "surface qdata", q_data_size_sur, CEED_EVAL_NONE); 252*25988f00SJames Wright CeedQFunctionAddInput(*qf_apply_bc, "x", num_comp_x, CEED_EVAL_INTERP); 253*25988f00SJames Wright CeedQFunctionAddOutput(*qf_apply_bc, "v", num_comp_q, CEED_EVAL_INTERP); 254*25988f00SJames Wright // *INDENT-ON* 255*25988f00SJames Wright if (jac_data_size_sur) 256*25988f00SJames Wright CeedQFunctionAddOutput(*qf_apply_bc, "surface jacobian data", jac_data_size_sur, 257*25988f00SJames Wright CEED_EVAL_NONE); 258*25988f00SJames Wright } 259*25988f00SJames Wright if (apply_bc_jacobian.qfunction) { 260*25988f00SJames Wright // *INDENT-OFF* 261*25988f00SJames Wright CeedQFunctionCreateInterior(ceed, 1, apply_bc_jacobian.qfunction, 262*25988f00SJames Wright apply_bc_jacobian.qfunction_loc, qf_apply_bc_jacobian); 263*25988f00SJames Wright CeedQFunctionSetContext(*qf_apply_bc_jacobian, apply_bc_jacobian.qfunction_context); 264*25988f00SJames Wright CeedQFunctionContextDestroy(&apply_bc_jacobian.qfunction_context); 265*25988f00SJames Wright CeedQFunctionAddInput(*qf_apply_bc_jacobian, "dq", num_comp_q, CEED_EVAL_INTERP); 266*25988f00SJames Wright CeedQFunctionAddInput(*qf_apply_bc_jacobian, "Grad_dq", num_comp_q*dim_sur, CEED_EVAL_GRAD); 267*25988f00SJames Wright CeedQFunctionAddInput(*qf_apply_bc_jacobian, "surface qdata", q_data_size_sur, CEED_EVAL_NONE); 268*25988f00SJames Wright CeedQFunctionAddInput(*qf_apply_bc_jacobian, "x", num_comp_x, CEED_EVAL_INTERP); 269*25988f00SJames Wright CeedQFunctionAddInput(*qf_apply_bc_jacobian, "surface jacobian data", 270*25988f00SJames Wright jac_data_size_sur, CEED_EVAL_NONE); 271*25988f00SJames Wright CeedQFunctionAddOutput(*qf_apply_bc_jacobian, "v", num_comp_q, CEED_EVAL_INTERP); 272*25988f00SJames Wright // *INDENT-ON* 273*25988f00SJames Wright } 274*25988f00SJames Wright PetscFunctionReturn(0); 275*25988f00SJames Wright } 276*25988f00SJames Wright 277a515125bSLeila Ghaffari PetscErrorCode SetupLibceed(Ceed ceed, CeedData ceed_data, DM dm, User user, 278c848b8b7SJed Brown AppCtx app_ctx, ProblemData *problem, SimpleBC bc) { 279a515125bSLeila Ghaffari PetscErrorCode ierr; 280a515125bSLeila Ghaffari PetscFunctionBeginUser; 281a515125bSLeila Ghaffari 282a515125bSLeila Ghaffari // ***************************************************************************** 283a515125bSLeila Ghaffari // Set up CEED objects for the interior domain (volume) 284a515125bSLeila Ghaffari // ***************************************************************************** 285a515125bSLeila Ghaffari const PetscInt num_comp_q = 5; 286a515125bSLeila Ghaffari const CeedInt dim = problem->dim, 287a515125bSLeila Ghaffari num_comp_x = problem->dim, 288a515125bSLeila Ghaffari q_data_size_vol = problem->q_data_size_vol, 289f0b65372SJed Brown jac_data_size_vol = num_comp_q + 6 + 3, 290a515125bSLeila Ghaffari P = app_ctx->degree + 1, 291a515125bSLeila Ghaffari Q = P + app_ctx->q_extra; 292752f40e3SJed Brown CeedElemRestriction elem_restr_jd_i; 293752f40e3SJed Brown CeedVector jac_data; 294a515125bSLeila Ghaffari 295a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 296a515125bSLeila Ghaffari // CEED Bases 297a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 298a515125bSLeila Ghaffari CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_q, P, Q, CEED_GAUSS, 299a515125bSLeila Ghaffari &ceed_data->basis_q); 300a515125bSLeila Ghaffari CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_x, 2, Q, CEED_GAUSS, 301a515125bSLeila Ghaffari &ceed_data->basis_x); 302a515125bSLeila Ghaffari CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_x, 2, P, 303a515125bSLeila Ghaffari CEED_GAUSS_LOBATTO, &ceed_data->basis_xc); 304a515125bSLeila Ghaffari 305a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 306a515125bSLeila Ghaffari // CEED Restrictions 307a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 308a515125bSLeila Ghaffari // -- Create restriction 3096b1ccf21SJeremy L Thompson ierr = GetRestrictionForDomain(ceed, dm, 0, 0, 0, Q, q_data_size_vol, 3106b1ccf21SJeremy L Thompson &ceed_data->elem_restr_q, &ceed_data->elem_restr_x, 311a515125bSLeila Ghaffari &ceed_data->elem_restr_qd_i); CHKERRQ(ierr); 312752f40e3SJed Brown 313752f40e3SJed Brown ierr = GetRestrictionForDomain(ceed, dm, 0, 0, 0, Q, jac_data_size_vol, 314752f40e3SJed Brown NULL, NULL, 315752f40e3SJed Brown &elem_restr_jd_i); CHKERRQ(ierr); 316a515125bSLeila Ghaffari // -- Create E vectors 317a515125bSLeila Ghaffari CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->q_ceed, NULL); 318a515125bSLeila Ghaffari CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->q_dot_ceed, 319a515125bSLeila Ghaffari NULL); 320a515125bSLeila Ghaffari CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->g_ceed, NULL); 321a515125bSLeila Ghaffari 322a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 323a515125bSLeila Ghaffari // CEED QFunctions 324a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 325a515125bSLeila Ghaffari // -- Create QFunction for quadrature data 3269785fe93SJed Brown CeedQFunctionCreateInterior(ceed, 1, problem->setup_vol.qfunction, 3279785fe93SJed Brown problem->setup_vol.qfunction_loc, 328a515125bSLeila Ghaffari &ceed_data->qf_setup_vol); 32915a3537eSJed Brown if (problem->setup_vol.qfunction_context) { 33015a3537eSJed Brown CeedQFunctionSetContext(ceed_data->qf_setup_vol, 33115a3537eSJed Brown problem->setup_vol.qfunction_context); 33215a3537eSJed Brown CeedQFunctionContextDestroy(&problem->setup_vol.qfunction_context); 33315a3537eSJed Brown } 334a515125bSLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_setup_vol, "dx", num_comp_x*dim, 335a515125bSLeila Ghaffari CEED_EVAL_GRAD); 336a515125bSLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_setup_vol, "weight", 1, CEED_EVAL_WEIGHT); 3373b1e209bSJeremy L Thompson CeedQFunctionAddOutput(ceed_data->qf_setup_vol, "qdata", q_data_size_vol, 338a515125bSLeila Ghaffari CEED_EVAL_NONE); 339a515125bSLeila Ghaffari 340a515125bSLeila Ghaffari // -- Create QFunction for ICs 3419785fe93SJed Brown CeedQFunctionCreateInterior(ceed, 1, problem->ics.qfunction, 3429785fe93SJed Brown problem->ics.qfunction_loc, 343a515125bSLeila Ghaffari &ceed_data->qf_ics); 34415a3537eSJed Brown CeedQFunctionSetContext(ceed_data->qf_ics, problem->ics.qfunction_context); 34515a3537eSJed Brown CeedQFunctionContextDestroy(&problem->ics.qfunction_context); 346a515125bSLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_ics, "x", num_comp_x, CEED_EVAL_INTERP); 347a515125bSLeila Ghaffari CeedQFunctionAddOutput(ceed_data->qf_ics, "q0", num_comp_q, CEED_EVAL_NONE); 348a515125bSLeila Ghaffari 349a515125bSLeila Ghaffari // -- Create QFunction for RHS 3509785fe93SJed Brown if (problem->apply_vol_rhs.qfunction) { 3519785fe93SJed Brown CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_rhs.qfunction, 3529785fe93SJed Brown problem->apply_vol_rhs.qfunction_loc, &ceed_data->qf_rhs_vol); 35315a3537eSJed Brown CeedQFunctionSetContext(ceed_data->qf_rhs_vol, 35415a3537eSJed Brown problem->apply_vol_rhs.qfunction_context); 35515a3537eSJed Brown CeedQFunctionContextDestroy(&problem->apply_vol_rhs.qfunction_context); 356a515125bSLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "q", num_comp_q, CEED_EVAL_INTERP); 357752f40e3SJed Brown CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "Grad_q", num_comp_q*dim, 358a515125bSLeila Ghaffari CEED_EVAL_GRAD); 3593b1e209bSJeremy L Thompson CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "qdata", q_data_size_vol, 360a515125bSLeila Ghaffari CEED_EVAL_NONE); 361a515125bSLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "x", num_comp_x, CEED_EVAL_INTERP); 362a515125bSLeila Ghaffari CeedQFunctionAddOutput(ceed_data->qf_rhs_vol, "v", num_comp_q, 363a515125bSLeila Ghaffari CEED_EVAL_INTERP); 364752f40e3SJed Brown CeedQFunctionAddOutput(ceed_data->qf_rhs_vol, "Grad_v", num_comp_q*dim, 365a515125bSLeila Ghaffari CEED_EVAL_GRAD); 366a515125bSLeila Ghaffari } 367a515125bSLeila Ghaffari 368a515125bSLeila Ghaffari // -- Create QFunction for IFunction 3699785fe93SJed Brown if (problem->apply_vol_ifunction.qfunction) { 3709785fe93SJed Brown CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_ifunction.qfunction, 3719785fe93SJed Brown problem->apply_vol_ifunction.qfunction_loc, &ceed_data->qf_ifunction_vol); 37215a3537eSJed Brown CeedQFunctionSetContext(ceed_data->qf_ifunction_vol, 37315a3537eSJed Brown problem->apply_vol_ifunction.qfunction_context); 37415a3537eSJed Brown CeedQFunctionContextDestroy(&problem->apply_vol_ifunction.qfunction_context); 375a515125bSLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "q", num_comp_q, 376a515125bSLeila Ghaffari CEED_EVAL_INTERP); 377752f40e3SJed Brown CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "Grad_q", num_comp_q*dim, 378a515125bSLeila Ghaffari CEED_EVAL_GRAD); 3793b1e209bSJeremy L Thompson CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "q dot", num_comp_q, 380a515125bSLeila Ghaffari CEED_EVAL_INTERP); 3813b1e209bSJeremy L Thompson CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "qdata", q_data_size_vol, 382a515125bSLeila Ghaffari CEED_EVAL_NONE); 383a515125bSLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "x", num_comp_x, 384a515125bSLeila Ghaffari CEED_EVAL_INTERP); 385a515125bSLeila Ghaffari CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "v", num_comp_q, 386a515125bSLeila Ghaffari CEED_EVAL_INTERP); 387752f40e3SJed Brown CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "Grad_v", num_comp_q*dim, 388a515125bSLeila Ghaffari CEED_EVAL_GRAD); 389752f40e3SJed Brown CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "jac_data", 390752f40e3SJed Brown jac_data_size_vol, CEED_EVAL_NONE); 391a515125bSLeila Ghaffari } 392a515125bSLeila Ghaffari 393f0b65372SJed Brown CeedQFunction qf_ijacobian_vol = NULL; 394f0b65372SJed Brown if (problem->apply_vol_ijacobian.qfunction) { 395f0b65372SJed Brown CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_ijacobian.qfunction, 396f0b65372SJed Brown problem->apply_vol_ijacobian.qfunction_loc, &qf_ijacobian_vol); 397f0b65372SJed Brown CeedQFunctionSetContext(qf_ijacobian_vol, 398f0b65372SJed Brown problem->apply_vol_ijacobian.qfunction_context); 399f0b65372SJed Brown CeedQFunctionContextDestroy(&problem->apply_vol_ijacobian.qfunction_context); 400f0b65372SJed Brown CeedQFunctionAddInput(qf_ijacobian_vol, "dq", num_comp_q, 401f0b65372SJed Brown CEED_EVAL_INTERP); 402f0b65372SJed Brown CeedQFunctionAddInput(qf_ijacobian_vol, "Grad_dq", num_comp_q*dim, 403f0b65372SJed Brown CEED_EVAL_GRAD); 404f0b65372SJed Brown CeedQFunctionAddInput(qf_ijacobian_vol, "qdata", q_data_size_vol, 405f0b65372SJed Brown CEED_EVAL_NONE); 406f0b65372SJed Brown CeedQFunctionAddInput(qf_ijacobian_vol, "x", num_comp_x, 407f0b65372SJed Brown CEED_EVAL_INTERP); 408f0b65372SJed Brown CeedQFunctionAddInput(qf_ijacobian_vol, "jac_data", 409f0b65372SJed Brown jac_data_size_vol, CEED_EVAL_NONE); 410f0b65372SJed Brown CeedQFunctionAddOutput(qf_ijacobian_vol, "v", num_comp_q, 411f0b65372SJed Brown CEED_EVAL_INTERP); 412f0b65372SJed Brown CeedQFunctionAddOutput(qf_ijacobian_vol, "Grad_v", num_comp_q*dim, 413f0b65372SJed Brown CEED_EVAL_GRAD); 414f0b65372SJed Brown } 415f0b65372SJed Brown 416a515125bSLeila Ghaffari // --------------------------------------------------------------------------- 417a515125bSLeila Ghaffari // Element coordinates 418a515125bSLeila Ghaffari // --------------------------------------------------------------------------- 419a515125bSLeila Ghaffari // -- Create CEED vector 420a515125bSLeila Ghaffari CeedElemRestrictionCreateVector(ceed_data->elem_restr_x, &ceed_data->x_coord, 421a515125bSLeila Ghaffari NULL); 422a515125bSLeila Ghaffari 423a515125bSLeila Ghaffari // -- Copy PETSc vector in CEED vector 424a515125bSLeila Ghaffari Vec X_loc; 425a515125bSLeila Ghaffari const PetscScalar *X_loc_array; 426cac8aa24SJed Brown { 427cac8aa24SJed Brown DM cdm; 428cac8aa24SJed Brown ierr = DMGetCellCoordinateDM(dm, &cdm); CHKERRQ(ierr); 429cac8aa24SJed Brown if (cdm) {ierr = DMGetCellCoordinatesLocal(dm, &X_loc); CHKERRQ(ierr);} 430cac8aa24SJed Brown else {ierr = DMGetCoordinatesLocal(dm, &X_loc); CHKERRQ(ierr);} 431cac8aa24SJed Brown } 43205a512bdSLeila Ghaffari ierr = VecScale(X_loc, problem->dm_scale); CHKERRQ(ierr); 433a515125bSLeila Ghaffari ierr = VecGetArrayRead(X_loc, &X_loc_array); CHKERRQ(ierr); 434a515125bSLeila Ghaffari CeedVectorSetArray(ceed_data->x_coord, CEED_MEM_HOST, CEED_COPY_VALUES, 435a515125bSLeila Ghaffari (PetscScalar *)X_loc_array); 436a515125bSLeila Ghaffari ierr = VecRestoreArrayRead(X_loc, &X_loc_array); CHKERRQ(ierr); 437a515125bSLeila Ghaffari 438a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 439a515125bSLeila Ghaffari // CEED vectors 440a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 441a515125bSLeila Ghaffari // -- Create CEED vector for geometric data 442a515125bSLeila Ghaffari CeedInt num_qpts_vol; 443a515125bSLeila Ghaffari PetscInt loc_num_elem_vol; 444a515125bSLeila Ghaffari CeedBasisGetNumQuadraturePoints(ceed_data->basis_q, &num_qpts_vol); 445a515125bSLeila Ghaffari CeedElemRestrictionGetNumElements(ceed_data->elem_restr_q, &loc_num_elem_vol); 446a515125bSLeila Ghaffari CeedVectorCreate(ceed, q_data_size_vol*loc_num_elem_vol*num_qpts_vol, 447a515125bSLeila Ghaffari &ceed_data->q_data); 448a515125bSLeila Ghaffari 449752f40e3SJed Brown CeedElemRestrictionCreateVector(elem_restr_jd_i, &jac_data, NULL); 450a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 451a515125bSLeila Ghaffari // CEED Operators 452a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 453a515125bSLeila Ghaffari // -- Create CEED operator for quadrature data 454a515125bSLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_setup_vol, NULL, NULL, 455a515125bSLeila Ghaffari &ceed_data->op_setup_vol); 456a515125bSLeila Ghaffari CeedOperatorSetField(ceed_data->op_setup_vol, "dx", ceed_data->elem_restr_x, 457a515125bSLeila Ghaffari ceed_data->basis_x, CEED_VECTOR_ACTIVE); 458a515125bSLeila Ghaffari CeedOperatorSetField(ceed_data->op_setup_vol, "weight", 459139613f2SLeila Ghaffari CEED_ELEMRESTRICTION_NONE, ceed_data->basis_x, CEED_VECTOR_NONE); 4603b1e209bSJeremy L Thompson CeedOperatorSetField(ceed_data->op_setup_vol, "qdata", 461139613f2SLeila Ghaffari ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); 462a515125bSLeila Ghaffari 463a515125bSLeila Ghaffari // -- Create CEED operator for ICs 464a515125bSLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_ics, NULL, NULL, &ceed_data->op_ics); 465a515125bSLeila Ghaffari CeedOperatorSetField(ceed_data->op_ics, "x", ceed_data->elem_restr_x, 466a515125bSLeila Ghaffari ceed_data->basis_xc, CEED_VECTOR_ACTIVE); 467a515125bSLeila Ghaffari CeedOperatorSetField(ceed_data->op_ics, "q0", ceed_data->elem_restr_q, 468a515125bSLeila Ghaffari CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); 46915a3537eSJed Brown CeedOperatorContextGetFieldLabel(ceed_data->op_ics, "evaluation time", 47015a3537eSJed Brown &user->phys->ics_time_label); 471a515125bSLeila Ghaffari 472a515125bSLeila Ghaffari // Create CEED operator for RHS 473a515125bSLeila Ghaffari if (ceed_data->qf_rhs_vol) { 474a515125bSLeila Ghaffari CeedOperator op; 475a515125bSLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_rhs_vol, NULL, NULL, &op); 476a515125bSLeila Ghaffari CeedOperatorSetField(op, "q", ceed_data->elem_restr_q, ceed_data->basis_q, 477a515125bSLeila Ghaffari CEED_VECTOR_ACTIVE); 478752f40e3SJed Brown CeedOperatorSetField(op, "Grad_q", ceed_data->elem_restr_q, ceed_data->basis_q, 479a515125bSLeila Ghaffari CEED_VECTOR_ACTIVE); 4803b1e209bSJeremy L Thompson CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i, 481139613f2SLeila Ghaffari CEED_BASIS_COLLOCATED, ceed_data->q_data); 482a515125bSLeila Ghaffari CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x, 483a515125bSLeila Ghaffari ceed_data->x_coord); 484a515125bSLeila Ghaffari CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q, 485a515125bSLeila Ghaffari CEED_VECTOR_ACTIVE); 486752f40e3SJed Brown CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q, 487a515125bSLeila Ghaffari CEED_VECTOR_ACTIVE); 488a515125bSLeila Ghaffari user->op_rhs_vol = op; 489a515125bSLeila Ghaffari } 490a515125bSLeila Ghaffari 491a515125bSLeila Ghaffari // -- CEED operator for IFunction 492a515125bSLeila Ghaffari if (ceed_data->qf_ifunction_vol) { 493a515125bSLeila Ghaffari CeedOperator op; 494a515125bSLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_ifunction_vol, NULL, NULL, &op); 495a515125bSLeila Ghaffari CeedOperatorSetField(op, "q", ceed_data->elem_restr_q, ceed_data->basis_q, 496a515125bSLeila Ghaffari CEED_VECTOR_ACTIVE); 497752f40e3SJed Brown CeedOperatorSetField(op, "Grad_q", ceed_data->elem_restr_q, ceed_data->basis_q, 498a515125bSLeila Ghaffari CEED_VECTOR_ACTIVE); 4993b1e209bSJeremy L Thompson CeedOperatorSetField(op, "q dot", ceed_data->elem_restr_q, ceed_data->basis_q, 500a515125bSLeila Ghaffari user->q_dot_ceed); 5013b1e209bSJeremy L Thompson CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i, 502139613f2SLeila Ghaffari CEED_BASIS_COLLOCATED, ceed_data->q_data); 503a515125bSLeila Ghaffari CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x, 504a515125bSLeila Ghaffari ceed_data->x_coord); 505a515125bSLeila Ghaffari CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q, 506a515125bSLeila Ghaffari CEED_VECTOR_ACTIVE); 507752f40e3SJed Brown CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q, 508a515125bSLeila Ghaffari CEED_VECTOR_ACTIVE); 509752f40e3SJed Brown CeedOperatorSetField(op, "jac_data", elem_restr_jd_i, 510752f40e3SJed Brown CEED_BASIS_COLLOCATED, jac_data); 511752f40e3SJed Brown 512a515125bSLeila Ghaffari user->op_ifunction_vol = op; 513a515125bSLeila Ghaffari } 514a515125bSLeila Ghaffari 515f0b65372SJed Brown CeedOperator op_ijacobian_vol = NULL; 516f0b65372SJed Brown if (qf_ijacobian_vol) { 517f0b65372SJed Brown CeedOperator op; 518f0b65372SJed Brown CeedOperatorCreate(ceed, qf_ijacobian_vol, NULL, NULL, &op); 519f0b65372SJed Brown CeedOperatorSetField(op, "dq", ceed_data->elem_restr_q, ceed_data->basis_q, 520f0b65372SJed Brown CEED_VECTOR_ACTIVE); 521f0b65372SJed Brown CeedOperatorSetField(op, "Grad_dq", ceed_data->elem_restr_q, ceed_data->basis_q, 522f0b65372SJed Brown CEED_VECTOR_ACTIVE); 523f0b65372SJed Brown CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i, 524f0b65372SJed Brown CEED_BASIS_COLLOCATED, ceed_data->q_data); 525f0b65372SJed Brown CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x, 526f0b65372SJed Brown ceed_data->x_coord); 527f0b65372SJed Brown CeedOperatorSetField(op, "jac_data", elem_restr_jd_i, 528f0b65372SJed Brown CEED_BASIS_COLLOCATED, jac_data); 529f0b65372SJed Brown CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q, 530f0b65372SJed Brown CEED_VECTOR_ACTIVE); 531f0b65372SJed Brown CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q, 532f0b65372SJed Brown CEED_VECTOR_ACTIVE); 533f0b65372SJed Brown op_ijacobian_vol = op; 534f0b65372SJed Brown CeedQFunctionDestroy(&qf_ijacobian_vol); 535f0b65372SJed Brown } 536f0b65372SJed Brown 537a515125bSLeila Ghaffari // ***************************************************************************** 538a515125bSLeila Ghaffari // Set up CEED objects for the exterior domain (surface) 539a515125bSLeila Ghaffari // ***************************************************************************** 540a515125bSLeila Ghaffari CeedInt height = 1, 541a515125bSLeila Ghaffari dim_sur = dim - height, 542a515125bSLeila Ghaffari P_sur = app_ctx->degree + 1, 543a515125bSLeila Ghaffari Q_sur = P_sur + app_ctx->q_extra; 544f0b65372SJed Brown const CeedInt q_data_size_sur = problem->q_data_size_sur, 545f0b65372SJed Brown jac_data_size_sur = problem->jac_data_size_sur; 546a515125bSLeila Ghaffari 547a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 548a515125bSLeila Ghaffari // CEED Bases 549a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 550a515125bSLeila Ghaffari CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_q, P_sur, Q_sur, 551a515125bSLeila Ghaffari CEED_GAUSS, &ceed_data->basis_q_sur); 552a515125bSLeila Ghaffari CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_x, 2, Q_sur, CEED_GAUSS, 553a515125bSLeila Ghaffari &ceed_data->basis_x_sur); 554da7e3aacSJames Wright CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_x, 2, P_sur, 555da7e3aacSJames Wright CEED_GAUSS_LOBATTO, &ceed_data->basis_xc_sur); 556a515125bSLeila Ghaffari 557a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 558a515125bSLeila Ghaffari // CEED QFunctions 559a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 560a515125bSLeila Ghaffari // -- Create QFunction for quadrature data 5619785fe93SJed Brown CeedQFunctionCreateInterior(ceed, 1, problem->setup_sur.qfunction, 5629785fe93SJed Brown problem->setup_sur.qfunction_loc, 563a515125bSLeila Ghaffari &ceed_data->qf_setup_sur); 56415a3537eSJed Brown if (problem->setup_sur.qfunction_context) { 56515a3537eSJed Brown CeedQFunctionSetContext(ceed_data->qf_setup_sur, 56615a3537eSJed Brown problem->setup_sur.qfunction_context); 56715a3537eSJed Brown CeedQFunctionContextDestroy(&problem->setup_sur.qfunction_context); 56815a3537eSJed Brown } 569a515125bSLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_setup_sur, "dx", num_comp_x*dim_sur, 570a515125bSLeila Ghaffari CEED_EVAL_GRAD); 571a515125bSLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_setup_sur, "weight", 1, CEED_EVAL_WEIGHT); 5723b1e209bSJeremy L Thompson CeedQFunctionAddOutput(ceed_data->qf_setup_sur, "surface qdata", 573002797a3SLeila Ghaffari q_data_size_sur, CEED_EVAL_NONE); 574a515125bSLeila Ghaffari 575*25988f00SJames Wright PetscCall(SetupBCQFunctions(ceed, dim_sur, num_comp_x, num_comp_q, 576*25988f00SJames Wright q_data_size_sur, jac_data_size_sur, 577*25988f00SJames Wright problem->apply_inflow, problem->apply_inflow_jacobian, 578*25988f00SJames Wright &ceed_data->qf_apply_inflow, &ceed_data->qf_apply_inflow_jacobian)); 579002797a3SLeila Ghaffari 580*25988f00SJames Wright // -- Create QFunction for outflow boundaries 581*25988f00SJames Wright PetscCall(SetupBCQFunctions(ceed, dim_sur, num_comp_x, num_comp_q, 582*25988f00SJames Wright q_data_size_sur, jac_data_size_sur, 583*25988f00SJames Wright problem->apply_outflow, problem->apply_outflow_jacobian, 584*25988f00SJames Wright &ceed_data->qf_apply_outflow, &ceed_data->qf_apply_outflow_jacobian)); 585a515125bSLeila Ghaffari 586a515125bSLeila Ghaffari // ***************************************************************************** 587a515125bSLeila Ghaffari // CEED Operator Apply 588a515125bSLeila Ghaffari // ***************************************************************************** 589a515125bSLeila Ghaffari // -- Apply CEED Operator for the geometric data 590a515125bSLeila Ghaffari CeedOperatorApply(ceed_data->op_setup_vol, ceed_data->x_coord, 591a515125bSLeila Ghaffari ceed_data->q_data, CEED_REQUEST_IMMEDIATE); 592a515125bSLeila Ghaffari 593a515125bSLeila Ghaffari // -- Create and apply CEED Composite Operator for the entire domain 594a515125bSLeila Ghaffari if (!user->phys->implicit) { // RHS 595a515125bSLeila Ghaffari ierr = CreateOperatorForDomain(ceed, dm, bc, ceed_data, user->phys, 596f0b65372SJed Brown user->op_rhs_vol, NULL, height, P_sur, Q_sur, 597f0b65372SJed Brown q_data_size_sur, 0, 598f0b65372SJed Brown &user->op_rhs, NULL); CHKERRQ(ierr); 599a515125bSLeila Ghaffari } else { // IFunction 600a515125bSLeila Ghaffari ierr = CreateOperatorForDomain(ceed, dm, bc, ceed_data, user->phys, 601f0b65372SJed Brown user->op_ifunction_vol, op_ijacobian_vol, 602f0b65372SJed Brown height, P_sur, Q_sur, 603f0b65372SJed Brown q_data_size_sur, jac_data_size_sur, 604f0b65372SJed Brown &user->op_ifunction, 605f0b65372SJed Brown op_ijacobian_vol ? &user->op_ijacobian : NULL); CHKERRQ(ierr); 606f0b65372SJed Brown if (user->op_ijacobian) { 607f0b65372SJed Brown CeedOperatorContextGetFieldLabel(user->op_ijacobian, "ijacobian time shift", 608f0b65372SJed Brown &user->phys->ijacobian_time_shift_label); 609f0b65372SJed Brown } 6106d0190e2SJames Wright if (problem->use_dirichlet_ceed) { 6116d0190e2SJames Wright PetscCall(SetupStrongBC_Ceed(ceed, ceed_data, dm, user, app_ctx, problem, bc, 6126d0190e2SJames Wright Q_sur, q_data_size_sur)); 6136d0190e2SJames Wright } 614f0b65372SJed Brown 615a515125bSLeila Ghaffari } 616752f40e3SJed Brown CeedElemRestrictionDestroy(&elem_restr_jd_i); 617e22e0f1cSLeila Ghaffari CeedOperatorDestroy(&op_ijacobian_vol); 618752f40e3SJed Brown CeedVectorDestroy(&jac_data); 619a515125bSLeila Ghaffari PetscFunctionReturn(0); 620a515125bSLeila Ghaffari } 621