xref: /libCEED/examples/fluids/src/setuplibceed.c (revision 2b730f8b5a9c809740a0b3b302db43a719c636b1)
13d8e8822SJeremy L Thompson // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
23d8e8822SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
377841947SLeila Ghaffari //
43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
577841947SLeila Ghaffari //
63d8e8822SJeremy L Thompson // This file is part of CEED:  http://github.com/ceed
777841947SLeila Ghaffari 
877841947SLeila Ghaffari /// @file
977841947SLeila Ghaffari /// Setup libCEED for Navier-Stokes example using PETSc
1077841947SLeila Ghaffari 
1177841947SLeila Ghaffari #include "../navierstokes.h"
1277841947SLeila Ghaffari 
1377841947SLeila Ghaffari // Utility function - essential BC dofs are encoded in closure indices as -(i+1).
14*2b730f8bSJeremy L Thompson PetscInt Involute(PetscInt i) { return i >= 0 ? i : -(i + 1); }
1577841947SLeila Ghaffari 
1677841947SLeila Ghaffari // Utility function to create local CEED restriction
17*2b730f8bSJeremy L Thompson PetscErrorCode CreateRestrictionFromPlex(Ceed ceed, DM dm, CeedInt height, DMLabel domain_label, CeedInt value, CeedElemRestriction *elem_restr) {
187ed3e4cdSJeremy L Thompson   PetscInt num_elem, elem_size, num_dof, num_comp, *elem_restr_offsets;
197ed3e4cdSJeremy L Thompson 
2077841947SLeila Ghaffari   PetscFunctionBeginUser;
21*2b730f8bSJeremy L Thompson   PetscCall(DMPlexGetLocalOffsets(dm, domain_label, value, height, 0, &num_elem, &elem_size, &num_comp, &num_dof, &elem_restr_offsets));
2277841947SLeila Ghaffari 
23*2b730f8bSJeremy L Thompson   CeedElemRestrictionCreate(ceed, num_elem, elem_size, num_comp, 1, num_dof, CEED_MEM_HOST, CEED_COPY_VALUES, elem_restr_offsets, elem_restr);
24*2b730f8bSJeremy L Thompson   PetscCall(PetscFree(elem_restr_offsets));
2577841947SLeila Ghaffari 
2677841947SLeila Ghaffari   PetscFunctionReturn(0);
2777841947SLeila Ghaffari }
2877841947SLeila Ghaffari 
2977841947SLeila Ghaffari // Utility function to get Ceed Restriction for each domain
30*2b730f8bSJeremy L Thompson PetscErrorCode GetRestrictionForDomain(Ceed ceed, DM dm, CeedInt height, DMLabel domain_label, PetscInt value, CeedInt Q, CeedInt q_data_size,
31*2b730f8bSJeremy L Thompson                                        CeedElemRestriction *elem_restr_q, CeedElemRestriction *elem_restr_x, CeedElemRestriction *elem_restr_qd_i) {
3277841947SLeila Ghaffari   DM                  dm_coord;
3377841947SLeila Ghaffari   CeedInt             dim, loc_num_elem;
3477841947SLeila Ghaffari   CeedInt             Q_dim;
352534dcc8SJed Brown   CeedElemRestriction elem_restr_tmp;
3677841947SLeila Ghaffari   PetscFunctionBeginUser;
3777841947SLeila Ghaffari 
38*2b730f8bSJeremy L Thompson   PetscCall(DMGetDimension(dm, &dim));
3977841947SLeila Ghaffari   dim -= height;
4077841947SLeila Ghaffari   Q_dim = CeedIntPow(Q, dim);
41*2b730f8bSJeremy L Thompson   PetscCall(CreateRestrictionFromPlex(ceed, dm, height, domain_label, value, &elem_restr_tmp));
422534dcc8SJed Brown   if (elem_restr_q) *elem_restr_q = elem_restr_tmp;
432534dcc8SJed Brown   if (elem_restr_x) {
44*2b730f8bSJeremy L Thompson     PetscCall(DMGetCellCoordinateDM(dm, &dm_coord));
453796c488SJed Brown     if (!dm_coord) {
46*2b730f8bSJeremy L Thompson       PetscCall(DMGetCoordinateDM(dm, &dm_coord));
473796c488SJed Brown     }
48*2b730f8bSJeremy L Thompson     PetscCall(DMPlexSetClosurePermutationTensor(dm_coord, PETSC_DETERMINE, NULL));
49*2b730f8bSJeremy L Thompson     PetscCall(CreateRestrictionFromPlex(ceed, dm_coord, height, domain_label, value, elem_restr_x));
502534dcc8SJed Brown   }
512534dcc8SJed Brown   if (elem_restr_qd_i) {
522534dcc8SJed Brown     CeedElemRestrictionGetNumElements(elem_restr_tmp, &loc_num_elem);
53*2b730f8bSJeremy L Thompson     CeedElemRestrictionCreateStrided(ceed, loc_num_elem, Q_dim, q_data_size, q_data_size * loc_num_elem * Q_dim, CEED_STRIDES_BACKEND,
54*2b730f8bSJeremy L Thompson                                      elem_restr_qd_i);
552534dcc8SJed Brown   }
562534dcc8SJed Brown   if (!elem_restr_q) CeedElemRestrictionDestroy(&elem_restr_tmp);
5777841947SLeila Ghaffari   PetscFunctionReturn(0);
5877841947SLeila Ghaffari }
5977841947SLeila Ghaffari 
60*2b730f8bSJeremy L Thompson PetscErrorCode AddBCSubOperator(Ceed ceed, DM dm, CeedData ceed_data, DMLabel domain_label, PetscInt value, CeedInt height, CeedInt Q_sur,
61*2b730f8bSJeremy L Thompson                                 CeedInt q_data_size_sur, CeedInt jac_data_size_sur, CeedQFunction qf_apply_bc, CeedQFunction qf_apply_bc_jacobian,
629eb9c072SJames Wright                                 CeedOperator *op_apply, CeedOperator *op_apply_ijacobian) {
639eb9c072SJames Wright   CeedVector          q_data_sur, jac_data_sur;
64*2b730f8bSJeremy L Thompson   CeedOperator        op_setup_sur, op_apply_bc, op_apply_bc_jacobian = NULL;
65*2b730f8bSJeremy L Thompson   CeedElemRestriction elem_restr_x_sur, elem_restr_q_sur, elem_restr_qd_i_sur, elem_restr_jd_i_sur;
669eb9c072SJames Wright   CeedInt             num_qpts_sur;
679eb9c072SJames Wright   PetscFunctionBeginUser;
689eb9c072SJames Wright 
699eb9c072SJames Wright   // --- Get number of quadrature points for the boundaries
709eb9c072SJames Wright   CeedBasisGetNumQuadraturePoints(ceed_data->basis_q_sur, &num_qpts_sur);
719eb9c072SJames Wright 
729eb9c072SJames Wright   // ---- CEED Restriction
73*2b730f8bSJeremy L Thompson   PetscCall(GetRestrictionForDomain(ceed, dm, height, domain_label, value, Q_sur, q_data_size_sur, &elem_restr_q_sur, &elem_restr_x_sur,
74*2b730f8bSJeremy L Thompson                                     &elem_restr_qd_i_sur));
759eb9c072SJames Wright   if (jac_data_size_sur > 0) {
769eb9c072SJames Wright     // State-dependent data will be passed from residual to Jacobian. This will be collocated.
77*2b730f8bSJeremy L Thompson     PetscCall(GetRestrictionForDomain(ceed, dm, height, domain_label, value, Q_sur, jac_data_size_sur, NULL, NULL, &elem_restr_jd_i_sur));
789eb9c072SJames Wright     CeedElemRestrictionCreateVector(elem_restr_jd_i_sur, &jac_data_sur, NULL);
799eb9c072SJames Wright   } else {
809eb9c072SJames Wright     elem_restr_jd_i_sur = NULL;
819eb9c072SJames Wright     jac_data_sur        = NULL;
829eb9c072SJames Wright   }
839eb9c072SJames Wright 
849eb9c072SJames Wright   // ---- CEED Vector
859eb9c072SJames Wright   PetscInt loc_num_elem_sur;
869eb9c072SJames Wright   CeedElemRestrictionGetNumElements(elem_restr_q_sur, &loc_num_elem_sur);
87*2b730f8bSJeremy L Thompson   CeedVectorCreate(ceed, q_data_size_sur * loc_num_elem_sur * num_qpts_sur, &q_data_sur);
889eb9c072SJames Wright 
899eb9c072SJames Wright   // ---- CEED Operator
909eb9c072SJames Wright   // ----- CEED Operator for Setup (geometric factors)
919eb9c072SJames Wright   CeedOperatorCreate(ceed, ceed_data->qf_setup_sur, NULL, NULL, &op_setup_sur);
92*2b730f8bSJeremy L Thompson   CeedOperatorSetField(op_setup_sur, "dx", elem_restr_x_sur, ceed_data->basis_x_sur, CEED_VECTOR_ACTIVE);
93*2b730f8bSJeremy L Thompson   CeedOperatorSetField(op_setup_sur, "weight", CEED_ELEMRESTRICTION_NONE, ceed_data->basis_x_sur, CEED_VECTOR_NONE);
94*2b730f8bSJeremy L Thompson   CeedOperatorSetField(op_setup_sur, "surface qdata", elem_restr_qd_i_sur, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE);
959eb9c072SJames Wright 
969eb9c072SJames Wright   // ----- CEED Operator for Physics
979eb9c072SJames Wright   CeedOperatorCreate(ceed, qf_apply_bc, NULL, NULL, &op_apply_bc);
98*2b730f8bSJeremy L Thompson   CeedOperatorSetField(op_apply_bc, "q", elem_restr_q_sur, ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
99*2b730f8bSJeremy L Thompson   CeedOperatorSetField(op_apply_bc, "Grad_q", elem_restr_q_sur, ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
100*2b730f8bSJeremy L Thompson   CeedOperatorSetField(op_apply_bc, "surface qdata", elem_restr_qd_i_sur, CEED_BASIS_COLLOCATED, q_data_sur);
101*2b730f8bSJeremy L Thompson   CeedOperatorSetField(op_apply_bc, "x", elem_restr_x_sur, ceed_data->basis_x_sur, ceed_data->x_coord);
102*2b730f8bSJeremy L Thompson   CeedOperatorSetField(op_apply_bc, "v", elem_restr_q_sur, ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
103*2b730f8bSJeremy L Thompson   if (elem_restr_jd_i_sur) CeedOperatorSetField(op_apply_bc, "surface jacobian data", elem_restr_jd_i_sur, CEED_BASIS_COLLOCATED, jac_data_sur);
1049eb9c072SJames Wright 
1059eb9c072SJames Wright   if (qf_apply_bc_jacobian) {
106*2b730f8bSJeremy L Thompson     CeedOperatorCreate(ceed, qf_apply_bc_jacobian, NULL, NULL, &op_apply_bc_jacobian);
107*2b730f8bSJeremy L Thompson     CeedOperatorSetField(op_apply_bc_jacobian, "dq", elem_restr_q_sur, ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
108*2b730f8bSJeremy L Thompson     CeedOperatorSetField(op_apply_bc_jacobian, "Grad_dq", elem_restr_q_sur, ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
109*2b730f8bSJeremy L Thompson     CeedOperatorSetField(op_apply_bc_jacobian, "surface qdata", elem_restr_qd_i_sur, CEED_BASIS_COLLOCATED, q_data_sur);
110*2b730f8bSJeremy L Thompson     CeedOperatorSetField(op_apply_bc_jacobian, "x", elem_restr_x_sur, ceed_data->basis_x_sur, ceed_data->x_coord);
111*2b730f8bSJeremy L Thompson     CeedOperatorSetField(op_apply_bc_jacobian, "surface jacobian data", elem_restr_jd_i_sur, CEED_BASIS_COLLOCATED, jac_data_sur);
112*2b730f8bSJeremy L Thompson     CeedOperatorSetField(op_apply_bc_jacobian, "v", elem_restr_q_sur, ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
1139eb9c072SJames Wright   }
1149eb9c072SJames Wright 
1159eb9c072SJames Wright   // ----- Apply CEED operator for Setup
116*2b730f8bSJeremy L Thompson   CeedOperatorApply(op_setup_sur, ceed_data->x_coord, q_data_sur, CEED_REQUEST_IMMEDIATE);
1179eb9c072SJames Wright 
1189eb9c072SJames Wright   // ----- Apply Sub-Operator for Physics
1199eb9c072SJames Wright   CeedCompositeOperatorAddSub(*op_apply, op_apply_bc);
120*2b730f8bSJeremy L Thompson   if (op_apply_bc_jacobian) CeedCompositeOperatorAddSub(*op_apply_ijacobian, op_apply_bc_jacobian);
1219eb9c072SJames Wright 
1229eb9c072SJames Wright   // ----- Cleanup
1239eb9c072SJames Wright   CeedVectorDestroy(&q_data_sur);
1249eb9c072SJames Wright   CeedVectorDestroy(&jac_data_sur);
1259eb9c072SJames Wright   CeedElemRestrictionDestroy(&elem_restr_q_sur);
1269eb9c072SJames Wright   CeedElemRestrictionDestroy(&elem_restr_x_sur);
1279eb9c072SJames Wright   CeedElemRestrictionDestroy(&elem_restr_qd_i_sur);
1289eb9c072SJames Wright   CeedElemRestrictionDestroy(&elem_restr_jd_i_sur);
1299eb9c072SJames Wright   CeedOperatorDestroy(&op_setup_sur);
1309eb9c072SJames Wright   CeedOperatorDestroy(&op_apply_bc);
1319eb9c072SJames Wright   CeedOperatorDestroy(&op_apply_bc_jacobian);
1329eb9c072SJames Wright 
1339eb9c072SJames Wright   PetscFunctionReturn(0);
1349eb9c072SJames Wright }
1359eb9c072SJames Wright 
13677841947SLeila Ghaffari // Utility function to create CEED Composite Operator for the entire domain
137*2b730f8bSJeremy L Thompson PetscErrorCode CreateOperatorForDomain(Ceed ceed, DM dm, SimpleBC bc, CeedData ceed_data, Physics phys, CeedOperator op_apply_vol,
138*2b730f8bSJeremy L Thompson                                        CeedOperator op_apply_ijacobian_vol, CeedInt height, CeedInt P_sur, CeedInt Q_sur, CeedInt q_data_size_sur,
139*2b730f8bSJeremy L Thompson                                        CeedInt jac_data_size_sur, CeedOperator *op_apply, CeedOperator *op_apply_ijacobian) {
14077841947SLeila Ghaffari   DMLabel domain_label;
14177841947SLeila Ghaffari   PetscFunctionBeginUser;
14277841947SLeila Ghaffari 
14377841947SLeila Ghaffari   // Create Composite Operaters
14477841947SLeila Ghaffari   CeedCompositeOperatorCreate(ceed, op_apply);
145*2b730f8bSJeremy L Thompson   if (op_apply_ijacobian) CeedCompositeOperatorCreate(ceed, op_apply_ijacobian);
14677841947SLeila Ghaffari 
14777841947SLeila Ghaffari   // --Apply Sub-Operator for the volume
14877841947SLeila Ghaffari   CeedCompositeOperatorAddSub(*op_apply, op_apply_vol);
149*2b730f8bSJeremy L Thompson   if (op_apply_ijacobian) CeedCompositeOperatorAddSub(*op_apply_ijacobian, op_apply_ijacobian_vol);
15077841947SLeila Ghaffari 
15177841947SLeila Ghaffari   // -- Create Sub-Operator for in/outflow BCs
15288626eedSJames Wright   if (phys->has_neumann || 1) {
15377841947SLeila Ghaffari     // --- Setup
154*2b730f8bSJeremy L Thompson     PetscCall(DMGetLabel(dm, "Face Sets", &domain_label));
15577841947SLeila Ghaffari 
1562fe7aee7SLeila Ghaffari     // --- Create Sub-Operator for inflow boundaries
1572fe7aee7SLeila Ghaffari     for (CeedInt i = 0; i < bc->num_inflow; i++) {
158*2b730f8bSJeremy L Thompson       PetscCall(AddBCSubOperator(ceed, dm, ceed_data, domain_label, bc->inflows[i], height, Q_sur, q_data_size_sur, jac_data_size_sur,
159*2b730f8bSJeremy L Thompson                                  ceed_data->qf_apply_inflow, ceed_data->qf_apply_inflow_jacobian, op_apply, op_apply_ijacobian));
16077841947SLeila Ghaffari     }
16177841947SLeila Ghaffari 
1622fe7aee7SLeila Ghaffari     // --- Create Sub-Operator for outflow boundaries
1632fe7aee7SLeila Ghaffari     for (CeedInt i = 0; i < bc->num_outflow; i++) {
164*2b730f8bSJeremy L Thompson       PetscCall(AddBCSubOperator(ceed, dm, ceed_data, domain_label, bc->outflows[i], height, Q_sur, q_data_size_sur, jac_data_size_sur,
165*2b730f8bSJeremy L Thompson                                  ceed_data->qf_apply_outflow, ceed_data->qf_apply_outflow_jacobian, op_apply, op_apply_ijacobian));
16639c69132SJed Brown     }
1672fe7aee7SLeila Ghaffari 
168f4ca79c2SJames Wright     // --- Create Sub-Operator for freestream boundaries
169f4ca79c2SJames Wright     for (CeedInt i = 0; i < bc->num_freestream; i++) {
170*2b730f8bSJeremy L Thompson       PetscCall(AddBCSubOperator(ceed, dm, ceed_data, domain_label, bc->freestreams[i], height, Q_sur, q_data_size_sur, jac_data_size_sur,
171*2b730f8bSJeremy L Thompson                                  ceed_data->qf_apply_freestream, ceed_data->qf_apply_freestream_jacobian, op_apply, op_apply_ijacobian));
1722fe7aee7SLeila Ghaffari     }
1732fe7aee7SLeila Ghaffari   }
17411436a05SJames Wright 
17511436a05SJames Wright   // ----- Get Context Labels for Operator
176*2b730f8bSJeremy L Thompson   CeedOperatorContextGetFieldLabel(*op_apply, "solution time", &phys->solution_time_label);
177*2b730f8bSJeremy L Thompson   CeedOperatorContextGetFieldLabel(*op_apply, "timestep size", &phys->timestep_size_label);
17811436a05SJames Wright 
17977841947SLeila Ghaffari   PetscFunctionReturn(0);
18077841947SLeila Ghaffari }
18177841947SLeila Ghaffari 
182*2b730f8bSJeremy L Thompson PetscErrorCode SetupBCQFunctions(Ceed ceed, PetscInt dim_sur, PetscInt num_comp_x, PetscInt num_comp_q, PetscInt q_data_size_sur,
183*2b730f8bSJeremy L Thompson                                  PetscInt jac_data_size_sur, ProblemQFunctionSpec apply_bc, ProblemQFunctionSpec apply_bc_jacobian,
1845b881d11SJames Wright                                  CeedQFunction *qf_apply_bc, CeedQFunction *qf_apply_bc_jacobian) {
1855b881d11SJames Wright   PetscFunctionBeginUser;
1865b881d11SJames Wright 
1875b881d11SJames Wright   if (apply_bc.qfunction) {
1885b881d11SJames Wright     // *INDENT-OFF*
1895b881d11SJames Wright     CeedQFunctionCreateInterior(ceed, 1, apply_bc.qfunction, apply_bc.qfunction_loc, qf_apply_bc);
1905b881d11SJames Wright     CeedQFunctionSetContext(*qf_apply_bc, apply_bc.qfunction_context);
1915b881d11SJames Wright     CeedQFunctionContextDestroy(&apply_bc.qfunction_context);
1925b881d11SJames Wright     CeedQFunctionAddInput(*qf_apply_bc, "q", num_comp_q, CEED_EVAL_INTERP);
1935b881d11SJames Wright     CeedQFunctionAddInput(*qf_apply_bc, "Grad_q", num_comp_q * dim_sur, CEED_EVAL_GRAD);
1945b881d11SJames Wright     CeedQFunctionAddInput(*qf_apply_bc, "surface qdata", q_data_size_sur, CEED_EVAL_NONE);
1955b881d11SJames Wright     CeedQFunctionAddInput(*qf_apply_bc, "x", num_comp_x, CEED_EVAL_INTERP);
1965b881d11SJames Wright     CeedQFunctionAddOutput(*qf_apply_bc, "v", num_comp_q, CEED_EVAL_INTERP);
1975b881d11SJames Wright     // *INDENT-ON*
198*2b730f8bSJeremy L Thompson     if (jac_data_size_sur) CeedQFunctionAddOutput(*qf_apply_bc, "surface jacobian data", jac_data_size_sur, CEED_EVAL_NONE);
1995b881d11SJames Wright   }
2005b881d11SJames Wright   if (apply_bc_jacobian.qfunction) {
2015b881d11SJames Wright     // *INDENT-OFF*
202*2b730f8bSJeremy L Thompson     CeedQFunctionCreateInterior(ceed, 1, apply_bc_jacobian.qfunction, apply_bc_jacobian.qfunction_loc, qf_apply_bc_jacobian);
2035b881d11SJames Wright     CeedQFunctionSetContext(*qf_apply_bc_jacobian, apply_bc_jacobian.qfunction_context);
2045b881d11SJames Wright     CeedQFunctionContextDestroy(&apply_bc_jacobian.qfunction_context);
2055b881d11SJames Wright     CeedQFunctionAddInput(*qf_apply_bc_jacobian, "dq", num_comp_q, CEED_EVAL_INTERP);
2065b881d11SJames Wright     CeedQFunctionAddInput(*qf_apply_bc_jacobian, "Grad_dq", num_comp_q * dim_sur, CEED_EVAL_GRAD);
2075b881d11SJames Wright     CeedQFunctionAddInput(*qf_apply_bc_jacobian, "surface qdata", q_data_size_sur, CEED_EVAL_NONE);
2085b881d11SJames Wright     CeedQFunctionAddInput(*qf_apply_bc_jacobian, "x", num_comp_x, CEED_EVAL_INTERP);
209*2b730f8bSJeremy L Thompson     CeedQFunctionAddInput(*qf_apply_bc_jacobian, "surface jacobian data", jac_data_size_sur, CEED_EVAL_NONE);
2105b881d11SJames Wright     CeedQFunctionAddOutput(*qf_apply_bc_jacobian, "v", num_comp_q, CEED_EVAL_INTERP);
2115b881d11SJames Wright     // *INDENT-ON*
2125b881d11SJames Wright   }
2135b881d11SJames Wright   PetscFunctionReturn(0);
2145b881d11SJames Wright }
2155b881d11SJames Wright 
216*2b730f8bSJeremy L Thompson PetscErrorCode SetupLibceed(Ceed ceed, CeedData ceed_data, DM dm, User user, AppCtx app_ctx, ProblemData *problem, SimpleBC bc) {
21777841947SLeila Ghaffari   PetscFunctionBeginUser;
21877841947SLeila Ghaffari 
21977841947SLeila Ghaffari   // *****************************************************************************
22077841947SLeila Ghaffari   // Set up CEED objects for the interior domain (volume)
22177841947SLeila Ghaffari   // *****************************************************************************
22277841947SLeila Ghaffari   const PetscInt num_comp_q = 5;
223*2b730f8bSJeremy L Thompson   const CeedInt  dim = problem->dim, num_comp_x = problem->dim, q_data_size_vol = problem->q_data_size_vol, jac_data_size_vol = num_comp_q + 6 + 3,
224*2b730f8bSJeremy L Thompson                 P = app_ctx->degree + 1, Q = P + app_ctx->q_extra;
225a3ae0734SJed Brown   CeedElemRestriction elem_restr_jd_i;
226a3ae0734SJed Brown   CeedVector          jac_data;
22777841947SLeila Ghaffari 
22877841947SLeila Ghaffari   // -----------------------------------------------------------------------------
22977841947SLeila Ghaffari   // CEED Bases
23077841947SLeila Ghaffari   // -----------------------------------------------------------------------------
231*2b730f8bSJeremy L Thompson   CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_q, P, Q, CEED_GAUSS, &ceed_data->basis_q);
232*2b730f8bSJeremy L Thompson   CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_x, 2, Q, CEED_GAUSS, &ceed_data->basis_x);
233*2b730f8bSJeremy L Thompson   CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_x, 2, P, CEED_GAUSS_LOBATTO, &ceed_data->basis_xc);
23477841947SLeila Ghaffari 
23577841947SLeila Ghaffari   // -----------------------------------------------------------------------------
23677841947SLeila Ghaffari   // CEED Restrictions
23777841947SLeila Ghaffari   // -----------------------------------------------------------------------------
23877841947SLeila Ghaffari   // -- Create restriction
239*2b730f8bSJeremy L Thompson   PetscCall(GetRestrictionForDomain(ceed, dm, 0, 0, 0, Q, q_data_size_vol, &ceed_data->elem_restr_q, &ceed_data->elem_restr_x,
240*2b730f8bSJeremy L Thompson                                     &ceed_data->elem_restr_qd_i));
241a3ae0734SJed Brown 
242*2b730f8bSJeremy L Thompson   PetscCall(GetRestrictionForDomain(ceed, dm, 0, 0, 0, Q, jac_data_size_vol, NULL, NULL, &elem_restr_jd_i));
24377841947SLeila Ghaffari   // -- Create E vectors
24477841947SLeila Ghaffari   CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->q_ceed, NULL);
245*2b730f8bSJeremy L Thompson   CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->q_dot_ceed, NULL);
24677841947SLeila Ghaffari   CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->g_ceed, NULL);
24777841947SLeila Ghaffari 
24877841947SLeila Ghaffari   // -----------------------------------------------------------------------------
24977841947SLeila Ghaffari   // CEED QFunctions
25077841947SLeila Ghaffari   // -----------------------------------------------------------------------------
25177841947SLeila Ghaffari   // -- Create QFunction for quadrature data
252*2b730f8bSJeremy L Thompson   CeedQFunctionCreateInterior(ceed, 1, problem->setup_vol.qfunction, problem->setup_vol.qfunction_loc, &ceed_data->qf_setup_vol);
253841e4c73SJed Brown   if (problem->setup_vol.qfunction_context) {
254*2b730f8bSJeremy L Thompson     CeedQFunctionSetContext(ceed_data->qf_setup_vol, problem->setup_vol.qfunction_context);
255841e4c73SJed Brown     CeedQFunctionContextDestroy(&problem->setup_vol.qfunction_context);
256841e4c73SJed Brown   }
257*2b730f8bSJeremy L Thompson   CeedQFunctionAddInput(ceed_data->qf_setup_vol, "dx", num_comp_x * dim, CEED_EVAL_GRAD);
25877841947SLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_setup_vol, "weight", 1, CEED_EVAL_WEIGHT);
259*2b730f8bSJeremy L Thompson   CeedQFunctionAddOutput(ceed_data->qf_setup_vol, "qdata", q_data_size_vol, CEED_EVAL_NONE);
26077841947SLeila Ghaffari 
26177841947SLeila Ghaffari   // -- Create QFunction for ICs
262*2b730f8bSJeremy L Thompson   CeedQFunctionCreateInterior(ceed, 1, problem->ics.qfunction, problem->ics.qfunction_loc, &ceed_data->qf_ics);
263841e4c73SJed Brown   CeedQFunctionSetContext(ceed_data->qf_ics, problem->ics.qfunction_context);
264841e4c73SJed Brown   CeedQFunctionContextDestroy(&problem->ics.qfunction_context);
26577841947SLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_ics, "x", num_comp_x, CEED_EVAL_INTERP);
266*2b730f8bSJeremy L Thompson   CeedQFunctionAddInput(ceed_data->qf_ics, "qdata", q_data_size_vol, CEED_EVAL_NONE);
26777841947SLeila Ghaffari   CeedQFunctionAddOutput(ceed_data->qf_ics, "q0", num_comp_q, CEED_EVAL_NONE);
26877841947SLeila Ghaffari 
26977841947SLeila Ghaffari   // -- Create QFunction for RHS
27091e5af17SJed Brown   if (problem->apply_vol_rhs.qfunction) {
271*2b730f8bSJeremy L Thompson     CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_rhs.qfunction, problem->apply_vol_rhs.qfunction_loc, &ceed_data->qf_rhs_vol);
272*2b730f8bSJeremy L Thompson     CeedQFunctionSetContext(ceed_data->qf_rhs_vol, problem->apply_vol_rhs.qfunction_context);
273841e4c73SJed Brown     CeedQFunctionContextDestroy(&problem->apply_vol_rhs.qfunction_context);
27477841947SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "q", num_comp_q, CEED_EVAL_INTERP);
275*2b730f8bSJeremy L Thompson     CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "Grad_q", num_comp_q * dim, CEED_EVAL_GRAD);
276*2b730f8bSJeremy L Thompson     CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "qdata", q_data_size_vol, CEED_EVAL_NONE);
27777841947SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "x", num_comp_x, CEED_EVAL_INTERP);
278*2b730f8bSJeremy L Thompson     CeedQFunctionAddOutput(ceed_data->qf_rhs_vol, "v", num_comp_q, CEED_EVAL_INTERP);
279*2b730f8bSJeremy L Thompson     CeedQFunctionAddOutput(ceed_data->qf_rhs_vol, "Grad_v", num_comp_q * dim, CEED_EVAL_GRAD);
28077841947SLeila Ghaffari   }
28177841947SLeila Ghaffari 
28277841947SLeila Ghaffari   // -- Create QFunction for IFunction
28391e5af17SJed Brown   if (problem->apply_vol_ifunction.qfunction) {
284*2b730f8bSJeremy L Thompson     CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_ifunction.qfunction, problem->apply_vol_ifunction.qfunction_loc,
285*2b730f8bSJeremy L Thompson                                 &ceed_data->qf_ifunction_vol);
286*2b730f8bSJeremy L Thompson     CeedQFunctionSetContext(ceed_data->qf_ifunction_vol, problem->apply_vol_ifunction.qfunction_context);
287841e4c73SJed Brown     CeedQFunctionContextDestroy(&problem->apply_vol_ifunction.qfunction_context);
288*2b730f8bSJeremy L Thompson     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "q", num_comp_q, CEED_EVAL_INTERP);
289*2b730f8bSJeremy L Thompson     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "Grad_q", num_comp_q * dim, CEED_EVAL_GRAD);
290*2b730f8bSJeremy L Thompson     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "q dot", num_comp_q, CEED_EVAL_INTERP);
291*2b730f8bSJeremy L Thompson     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "qdata", q_data_size_vol, CEED_EVAL_NONE);
292*2b730f8bSJeremy L Thompson     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "x", num_comp_x, CEED_EVAL_INTERP);
293*2b730f8bSJeremy L Thompson     CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "v", num_comp_q, CEED_EVAL_INTERP);
294*2b730f8bSJeremy L Thompson     CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "Grad_v", num_comp_q * dim, CEED_EVAL_GRAD);
295*2b730f8bSJeremy L Thompson     CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "jac_data", jac_data_size_vol, CEED_EVAL_NONE);
29677841947SLeila Ghaffari   }
29777841947SLeila Ghaffari 
298e334ad8fSJed Brown   CeedQFunction qf_ijacobian_vol = NULL;
299e334ad8fSJed Brown   if (problem->apply_vol_ijacobian.qfunction) {
300*2b730f8bSJeremy L Thompson     CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_ijacobian.qfunction, problem->apply_vol_ijacobian.qfunction_loc, &qf_ijacobian_vol);
301*2b730f8bSJeremy L Thompson     CeedQFunctionSetContext(qf_ijacobian_vol, problem->apply_vol_ijacobian.qfunction_context);
302e334ad8fSJed Brown     CeedQFunctionContextDestroy(&problem->apply_vol_ijacobian.qfunction_context);
303*2b730f8bSJeremy L Thompson     CeedQFunctionAddInput(qf_ijacobian_vol, "dq", num_comp_q, CEED_EVAL_INTERP);
304*2b730f8bSJeremy L Thompson     CeedQFunctionAddInput(qf_ijacobian_vol, "Grad_dq", num_comp_q * dim, CEED_EVAL_GRAD);
305*2b730f8bSJeremy L Thompson     CeedQFunctionAddInput(qf_ijacobian_vol, "qdata", q_data_size_vol, CEED_EVAL_NONE);
306*2b730f8bSJeremy L Thompson     CeedQFunctionAddInput(qf_ijacobian_vol, "x", num_comp_x, CEED_EVAL_INTERP);
307*2b730f8bSJeremy L Thompson     CeedQFunctionAddInput(qf_ijacobian_vol, "jac_data", jac_data_size_vol, CEED_EVAL_NONE);
308*2b730f8bSJeremy L Thompson     CeedQFunctionAddOutput(qf_ijacobian_vol, "v", num_comp_q, CEED_EVAL_INTERP);
309*2b730f8bSJeremy L Thompson     CeedQFunctionAddOutput(qf_ijacobian_vol, "Grad_v", num_comp_q * dim, CEED_EVAL_GRAD);
310e334ad8fSJed Brown   }
311e334ad8fSJed Brown 
31277841947SLeila Ghaffari   // ---------------------------------------------------------------------------
31377841947SLeila Ghaffari   // Element coordinates
31477841947SLeila Ghaffari   // ---------------------------------------------------------------------------
31577841947SLeila Ghaffari   // -- Create CEED vector
316*2b730f8bSJeremy L Thompson   CeedElemRestrictionCreateVector(ceed_data->elem_restr_x, &ceed_data->x_coord, NULL);
31777841947SLeila Ghaffari 
31877841947SLeila Ghaffari   // -- Copy PETSc vector in CEED vector
31977841947SLeila Ghaffari   Vec                X_loc;
32077841947SLeila Ghaffari   const PetscScalar *X_loc_array;
3213796c488SJed Brown   {
3223796c488SJed Brown     DM cdm;
323*2b730f8bSJeremy L Thompson     PetscCall(DMGetCellCoordinateDM(dm, &cdm));
324*2b730f8bSJeremy L Thompson     if (cdm) {
325*2b730f8bSJeremy L Thompson       PetscCall(DMGetCellCoordinatesLocal(dm, &X_loc));
326*2b730f8bSJeremy L Thompson     } else {
327*2b730f8bSJeremy L Thompson       PetscCall(DMGetCoordinatesLocal(dm, &X_loc));
3283796c488SJed Brown     }
329*2b730f8bSJeremy L Thompson   }
330*2b730f8bSJeremy L Thompson   PetscCall(VecScale(X_loc, problem->dm_scale));
331*2b730f8bSJeremy L Thompson   PetscCall(VecGetArrayRead(X_loc, &X_loc_array));
332*2b730f8bSJeremy L Thompson   CeedVectorSetArray(ceed_data->x_coord, CEED_MEM_HOST, CEED_COPY_VALUES, (PetscScalar *)X_loc_array);
333*2b730f8bSJeremy L Thompson   PetscCall(VecRestoreArrayRead(X_loc, &X_loc_array));
33477841947SLeila Ghaffari 
33577841947SLeila Ghaffari   // -----------------------------------------------------------------------------
33677841947SLeila Ghaffari   // CEED vectors
33777841947SLeila Ghaffari   // -----------------------------------------------------------------------------
33877841947SLeila Ghaffari   // -- Create CEED vector for geometric data
33977841947SLeila Ghaffari   CeedInt  num_qpts_vol;
34077841947SLeila Ghaffari   PetscInt loc_num_elem_vol;
34177841947SLeila Ghaffari   CeedBasisGetNumQuadraturePoints(ceed_data->basis_q, &num_qpts_vol);
34277841947SLeila Ghaffari   CeedElemRestrictionGetNumElements(ceed_data->elem_restr_q, &loc_num_elem_vol);
343*2b730f8bSJeremy L Thompson   CeedVectorCreate(ceed, q_data_size_vol * loc_num_elem_vol * num_qpts_vol, &ceed_data->q_data);
34477841947SLeila Ghaffari 
345a3ae0734SJed Brown   CeedElemRestrictionCreateVector(elem_restr_jd_i, &jac_data, NULL);
34677841947SLeila Ghaffari   // -----------------------------------------------------------------------------
34777841947SLeila Ghaffari   // CEED Operators
34877841947SLeila Ghaffari   // -----------------------------------------------------------------------------
34977841947SLeila Ghaffari   // -- Create CEED operator for quadrature data
350*2b730f8bSJeremy L Thompson   CeedOperatorCreate(ceed, ceed_data->qf_setup_vol, NULL, NULL, &ceed_data->op_setup_vol);
351*2b730f8bSJeremy L Thompson   CeedOperatorSetField(ceed_data->op_setup_vol, "dx", ceed_data->elem_restr_x, ceed_data->basis_x, CEED_VECTOR_ACTIVE);
352*2b730f8bSJeremy L Thompson   CeedOperatorSetField(ceed_data->op_setup_vol, "weight", CEED_ELEMRESTRICTION_NONE, ceed_data->basis_x, CEED_VECTOR_NONE);
353*2b730f8bSJeremy L Thompson   CeedOperatorSetField(ceed_data->op_setup_vol, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE);
35477841947SLeila Ghaffari 
35577841947SLeila Ghaffari   // -- Create CEED operator for ICs
35677841947SLeila Ghaffari   CeedOperatorCreate(ceed, ceed_data->qf_ics, NULL, NULL, &ceed_data->op_ics);
357*2b730f8bSJeremy L Thompson   CeedOperatorSetField(ceed_data->op_ics, "x", ceed_data->elem_restr_x, ceed_data->basis_xc, CEED_VECTOR_ACTIVE);
358*2b730f8bSJeremy L Thompson   CeedOperatorSetField(ceed_data->op_ics, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, ceed_data->q_data);
359*2b730f8bSJeremy L Thompson   CeedOperatorSetField(ceed_data->op_ics, "q0", ceed_data->elem_restr_q, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE);
360*2b730f8bSJeremy L Thompson   CeedOperatorContextGetFieldLabel(ceed_data->op_ics, "evaluation time", &user->phys->ics_time_label);
36177841947SLeila Ghaffari 
36277841947SLeila Ghaffari   // Create CEED operator for RHS
36377841947SLeila Ghaffari   if (ceed_data->qf_rhs_vol) {
36477841947SLeila Ghaffari     CeedOperator op;
36577841947SLeila Ghaffari     CeedOperatorCreate(ceed, ceed_data->qf_rhs_vol, NULL, NULL, &op);
366*2b730f8bSJeremy L Thompson     CeedOperatorSetField(op, "q", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE);
367*2b730f8bSJeremy L Thompson     CeedOperatorSetField(op, "Grad_q", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE);
368*2b730f8bSJeremy L Thompson     CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, ceed_data->q_data);
369*2b730f8bSJeremy L Thompson     CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord);
370*2b730f8bSJeremy L Thompson     CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE);
371*2b730f8bSJeremy L Thompson     CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE);
37277841947SLeila Ghaffari     user->op_rhs_vol = op;
37377841947SLeila Ghaffari   }
37477841947SLeila Ghaffari 
37577841947SLeila Ghaffari   // -- CEED operator for IFunction
37677841947SLeila Ghaffari   if (ceed_data->qf_ifunction_vol) {
37777841947SLeila Ghaffari     CeedOperator op;
37877841947SLeila Ghaffari     CeedOperatorCreate(ceed, ceed_data->qf_ifunction_vol, NULL, NULL, &op);
379*2b730f8bSJeremy L Thompson     CeedOperatorSetField(op, "q", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE);
380*2b730f8bSJeremy L Thompson     CeedOperatorSetField(op, "Grad_q", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE);
381*2b730f8bSJeremy L Thompson     CeedOperatorSetField(op, "q dot", ceed_data->elem_restr_q, ceed_data->basis_q, user->q_dot_ceed);
382*2b730f8bSJeremy L Thompson     CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, ceed_data->q_data);
383*2b730f8bSJeremy L Thompson     CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord);
384*2b730f8bSJeremy L Thompson     CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE);
385*2b730f8bSJeremy L Thompson     CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE);
386*2b730f8bSJeremy L Thompson     CeedOperatorSetField(op, "jac_data", elem_restr_jd_i, CEED_BASIS_COLLOCATED, jac_data);
387a3ae0734SJed Brown 
38877841947SLeila Ghaffari     user->op_ifunction_vol = op;
38977841947SLeila Ghaffari   }
39077841947SLeila Ghaffari 
391e334ad8fSJed Brown   CeedOperator op_ijacobian_vol = NULL;
392e334ad8fSJed Brown   if (qf_ijacobian_vol) {
393e334ad8fSJed Brown     CeedOperator op;
394e334ad8fSJed Brown     CeedOperatorCreate(ceed, qf_ijacobian_vol, NULL, NULL, &op);
395*2b730f8bSJeremy L Thompson     CeedOperatorSetField(op, "dq", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE);
396*2b730f8bSJeremy L Thompson     CeedOperatorSetField(op, "Grad_dq", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE);
397*2b730f8bSJeremy L Thompson     CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, ceed_data->q_data);
398*2b730f8bSJeremy L Thompson     CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord);
399*2b730f8bSJeremy L Thompson     CeedOperatorSetField(op, "jac_data", elem_restr_jd_i, CEED_BASIS_COLLOCATED, jac_data);
400*2b730f8bSJeremy L Thompson     CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE);
401*2b730f8bSJeremy L Thompson     CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE);
402e334ad8fSJed Brown     op_ijacobian_vol = op;
403e334ad8fSJed Brown     CeedQFunctionDestroy(&qf_ijacobian_vol);
404e334ad8fSJed Brown   }
405e334ad8fSJed Brown 
40677841947SLeila Ghaffari   // *****************************************************************************
40777841947SLeila Ghaffari   // Set up CEED objects for the exterior domain (surface)
40877841947SLeila Ghaffari   // *****************************************************************************
409*2b730f8bSJeremy L Thompson   CeedInt       height = 1, dim_sur = dim - height, P_sur = app_ctx->degree + 1, Q_sur = P_sur + app_ctx->q_extra;
410*2b730f8bSJeremy L Thompson   const CeedInt q_data_size_sur = problem->q_data_size_sur, jac_data_size_sur = problem->jac_data_size_sur;
41177841947SLeila Ghaffari 
41277841947SLeila Ghaffari   // -----------------------------------------------------------------------------
41377841947SLeila Ghaffari   // CEED Bases
41477841947SLeila Ghaffari   // -----------------------------------------------------------------------------
415*2b730f8bSJeremy L Thompson   CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_q, P_sur, Q_sur, CEED_GAUSS, &ceed_data->basis_q_sur);
416*2b730f8bSJeremy L Thompson   CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_x, 2, Q_sur, CEED_GAUSS, &ceed_data->basis_x_sur);
417*2b730f8bSJeremy L Thompson   CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_x, 2, P_sur, CEED_GAUSS_LOBATTO, &ceed_data->basis_xc_sur);
41877841947SLeila Ghaffari 
41977841947SLeila Ghaffari   // -----------------------------------------------------------------------------
42077841947SLeila Ghaffari   // CEED QFunctions
42177841947SLeila Ghaffari   // -----------------------------------------------------------------------------
42277841947SLeila Ghaffari   // -- Create QFunction for quadrature data
423*2b730f8bSJeremy L Thompson   CeedQFunctionCreateInterior(ceed, 1, problem->setup_sur.qfunction, problem->setup_sur.qfunction_loc, &ceed_data->qf_setup_sur);
424841e4c73SJed Brown   if (problem->setup_sur.qfunction_context) {
425*2b730f8bSJeremy L Thompson     CeedQFunctionSetContext(ceed_data->qf_setup_sur, problem->setup_sur.qfunction_context);
426841e4c73SJed Brown     CeedQFunctionContextDestroy(&problem->setup_sur.qfunction_context);
427841e4c73SJed Brown   }
428*2b730f8bSJeremy L Thompson   CeedQFunctionAddInput(ceed_data->qf_setup_sur, "dx", num_comp_x * dim_sur, CEED_EVAL_GRAD);
42977841947SLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_setup_sur, "weight", 1, CEED_EVAL_WEIGHT);
430*2b730f8bSJeremy L Thompson   CeedQFunctionAddOutput(ceed_data->qf_setup_sur, "surface qdata", q_data_size_sur, CEED_EVAL_NONE);
43177841947SLeila Ghaffari 
432*2b730f8bSJeremy L Thompson   PetscCall(SetupBCQFunctions(ceed, dim_sur, num_comp_x, num_comp_q, q_data_size_sur, jac_data_size_sur, problem->apply_inflow,
433*2b730f8bSJeremy L Thompson                               problem->apply_inflow_jacobian, &ceed_data->qf_apply_inflow, &ceed_data->qf_apply_inflow_jacobian));
4342fe7aee7SLeila Ghaffari 
435*2b730f8bSJeremy L Thompson   PetscCall(SetupBCQFunctions(ceed, dim_sur, num_comp_x, num_comp_q, q_data_size_sur, jac_data_size_sur, problem->apply_outflow,
436*2b730f8bSJeremy L Thompson                               problem->apply_outflow_jacobian, &ceed_data->qf_apply_outflow, &ceed_data->qf_apply_outflow_jacobian));
43777841947SLeila Ghaffari 
438*2b730f8bSJeremy L Thompson   PetscCall(SetupBCQFunctions(ceed, dim_sur, num_comp_x, num_comp_q, q_data_size_sur, jac_data_size_sur, problem->apply_freestream,
439*2b730f8bSJeremy L Thompson                               problem->apply_freestream_jacobian, &ceed_data->qf_apply_freestream, &ceed_data->qf_apply_freestream_jacobian));
44077841947SLeila Ghaffari 
44177841947SLeila Ghaffari   // *****************************************************************************
44277841947SLeila Ghaffari   // CEED Operator Apply
44377841947SLeila Ghaffari   // *****************************************************************************
44477841947SLeila Ghaffari   // -- Apply CEED Operator for the geometric data
445*2b730f8bSJeremy L Thompson   CeedOperatorApply(ceed_data->op_setup_vol, ceed_data->x_coord, ceed_data->q_data, CEED_REQUEST_IMMEDIATE);
44677841947SLeila Ghaffari 
44777841947SLeila Ghaffari   // -- Create and apply CEED Composite Operator for the entire domain
44877841947SLeila Ghaffari   if (!user->phys->implicit) {  // RHS
449*2b730f8bSJeremy L Thompson     PetscCall(CreateOperatorForDomain(ceed, dm, bc, ceed_data, user->phys, user->op_rhs_vol, NULL, height, P_sur, Q_sur, q_data_size_sur, 0,
450*2b730f8bSJeremy L Thompson                                       &user->op_rhs, NULL));
45177841947SLeila Ghaffari   } else {  // IFunction
452*2b730f8bSJeremy L Thompson     PetscCall(CreateOperatorForDomain(ceed, dm, bc, ceed_data, user->phys, user->op_ifunction_vol, op_ijacobian_vol, height, P_sur, Q_sur,
453*2b730f8bSJeremy L Thompson                                       q_data_size_sur, jac_data_size_sur, &user->op_ifunction, op_ijacobian_vol ? &user->op_ijacobian : NULL));
454e334ad8fSJed Brown     if (user->op_ijacobian) {
455*2b730f8bSJeremy L Thompson       CeedOperatorContextGetFieldLabel(user->op_ijacobian, "ijacobian time shift", &user->phys->ijacobian_time_shift_label);
456e334ad8fSJed Brown     }
457dada6cc0SJames Wright     if (problem->use_dirichlet_ceed) {
458*2b730f8bSJeremy L Thompson       PetscCall(SetupStrongBC_Ceed(ceed, ceed_data, dm, user, app_ctx, problem, bc, Q_sur, q_data_size_sur));
459dada6cc0SJames Wright     }
46077841947SLeila Ghaffari   }
461a3ae0734SJed Brown   CeedElemRestrictionDestroy(&elem_restr_jd_i);
46222d320f5SLeila Ghaffari   CeedOperatorDestroy(&op_ijacobian_vol);
463a3ae0734SJed Brown   CeedVectorDestroy(&jac_data);
46477841947SLeila Ghaffari   PetscFunctionReturn(0);
46577841947SLeila Ghaffari }
466