xref: /honee/src/setuplibceed.c (revision 2b916ea7fa53b5c2584160b9274b1b14ca18ff4f)
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).
14*2b916ea7SJeremy L Thompson PetscInt Involute(PetscInt i) { return i >= 0 ? i : -(i + 1); }
15a515125bSLeila Ghaffari 
16a515125bSLeila Ghaffari // Utility function to create local CEED restriction
17*2b916ea7SJeremy L Thompson PetscErrorCode CreateRestrictionFromPlex(Ceed ceed, DM dm, CeedInt height, DMLabel domain_label, CeedInt value, CeedElemRestriction *elem_restr) {
186b1ccf21SJeremy L Thompson   PetscInt num_elem, elem_size, num_dof, num_comp, *elem_restr_offsets;
196b1ccf21SJeremy L Thompson 
20a515125bSLeila Ghaffari   PetscFunctionBeginUser;
21*2b916ea7SJeremy L Thompson   PetscCall(DMPlexGetLocalOffsets(dm, domain_label, value, height, 0, &num_elem, &elem_size, &num_comp, &num_dof, &elem_restr_offsets));
22a515125bSLeila Ghaffari 
23*2b916ea7SJeremy 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*2b916ea7SJeremy L Thompson   PetscCall(PetscFree(elem_restr_offsets));
25a515125bSLeila Ghaffari 
26a515125bSLeila Ghaffari   PetscFunctionReturn(0);
27a515125bSLeila Ghaffari }
28a515125bSLeila Ghaffari 
29a515125bSLeila Ghaffari // Utility function to get Ceed Restriction for each domain
30*2b916ea7SJeremy L Thompson PetscErrorCode GetRestrictionForDomain(Ceed ceed, DM dm, CeedInt height, DMLabel domain_label, PetscInt value, CeedInt Q, CeedInt q_data_size,
31*2b916ea7SJeremy L Thompson                                        CeedElemRestriction *elem_restr_q, CeedElemRestriction *elem_restr_x, CeedElemRestriction *elem_restr_qd_i) {
32a515125bSLeila Ghaffari   DM                  dm_coord;
33a515125bSLeila Ghaffari   CeedInt             dim, loc_num_elem;
34a515125bSLeila Ghaffari   CeedInt             Q_dim;
35395c96d3SJed Brown   CeedElemRestriction elem_restr_tmp;
36a515125bSLeila Ghaffari   PetscFunctionBeginUser;
37a515125bSLeila Ghaffari 
38*2b916ea7SJeremy L Thompson   PetscCall(DMGetDimension(dm, &dim));
39a515125bSLeila Ghaffari   dim -= height;
40a515125bSLeila Ghaffari   Q_dim = CeedIntPow(Q, dim);
41*2b916ea7SJeremy L Thompson   PetscCall(CreateRestrictionFromPlex(ceed, dm, height, domain_label, value, &elem_restr_tmp));
42395c96d3SJed Brown   if (elem_restr_q) *elem_restr_q = elem_restr_tmp;
43395c96d3SJed Brown   if (elem_restr_x) {
44*2b916ea7SJeremy L Thompson     PetscCall(DMGetCellCoordinateDM(dm, &dm_coord));
45cac8aa24SJed Brown     if (!dm_coord) {
46*2b916ea7SJeremy L Thompson       PetscCall(DMGetCoordinateDM(dm, &dm_coord));
47cac8aa24SJed Brown     }
48*2b916ea7SJeremy L Thompson     PetscCall(DMPlexSetClosurePermutationTensor(dm_coord, PETSC_DETERMINE, NULL));
49*2b916ea7SJeremy L Thompson     PetscCall(CreateRestrictionFromPlex(ceed, dm_coord, height, domain_label, value, elem_restr_x));
50395c96d3SJed Brown   }
51395c96d3SJed Brown   if (elem_restr_qd_i) {
52395c96d3SJed Brown     CeedElemRestrictionGetNumElements(elem_restr_tmp, &loc_num_elem);
53*2b916ea7SJeremy L Thompson     CeedElemRestrictionCreateStrided(ceed, loc_num_elem, Q_dim, q_data_size, q_data_size * loc_num_elem * Q_dim, CEED_STRIDES_BACKEND,
54*2b916ea7SJeremy L Thompson                                      elem_restr_qd_i);
55395c96d3SJed Brown   }
56395c96d3SJed Brown   if (!elem_restr_q) CeedElemRestrictionDestroy(&elem_restr_tmp);
57a515125bSLeila Ghaffari   PetscFunctionReturn(0);
58a515125bSLeila Ghaffari }
59a515125bSLeila Ghaffari 
60*2b916ea7SJeremy L Thompson PetscErrorCode AddBCSubOperator(Ceed ceed, DM dm, CeedData ceed_data, DMLabel domain_label, PetscInt value, CeedInt height, CeedInt Q_sur,
61*2b916ea7SJeremy L Thompson                                 CeedInt q_data_size_sur, CeedInt jac_data_size_sur, CeedQFunction qf_apply_bc, CeedQFunction qf_apply_bc_jacobian,
62368c645fSJames Wright                                 CeedOperator *op_apply, CeedOperator *op_apply_ijacobian) {
63368c645fSJames Wright   CeedVector          q_data_sur, jac_data_sur;
64*2b916ea7SJeremy L Thompson   CeedOperator        op_setup_sur, op_apply_bc, op_apply_bc_jacobian = NULL;
65*2b916ea7SJeremy L Thompson   CeedElemRestriction elem_restr_x_sur, elem_restr_q_sur, elem_restr_qd_i_sur, elem_restr_jd_i_sur;
66368c645fSJames Wright   CeedInt             num_qpts_sur;
67368c645fSJames Wright   PetscFunctionBeginUser;
68368c645fSJames Wright 
69368c645fSJames Wright   // --- Get number of quadrature points for the boundaries
70368c645fSJames Wright   CeedBasisGetNumQuadraturePoints(ceed_data->basis_q_sur, &num_qpts_sur);
71368c645fSJames Wright 
72368c645fSJames Wright   // ---- CEED Restriction
73*2b916ea7SJeremy 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*2b916ea7SJeremy L Thompson                                     &elem_restr_qd_i_sur));
75368c645fSJames Wright   if (jac_data_size_sur > 0) {
76368c645fSJames Wright     // State-dependent data will be passed from residual to Jacobian. This will be collocated.
77*2b916ea7SJeremy L Thompson     PetscCall(GetRestrictionForDomain(ceed, dm, height, domain_label, value, Q_sur, jac_data_size_sur, NULL, NULL, &elem_restr_jd_i_sur));
78368c645fSJames Wright     CeedElemRestrictionCreateVector(elem_restr_jd_i_sur, &jac_data_sur, NULL);
79368c645fSJames Wright   } else {
80368c645fSJames Wright     elem_restr_jd_i_sur = NULL;
81368c645fSJames Wright     jac_data_sur        = NULL;
82368c645fSJames Wright   }
83368c645fSJames Wright 
84368c645fSJames Wright   // ---- CEED Vector
85368c645fSJames Wright   PetscInt loc_num_elem_sur;
86368c645fSJames Wright   CeedElemRestrictionGetNumElements(elem_restr_q_sur, &loc_num_elem_sur);
87*2b916ea7SJeremy L Thompson   CeedVectorCreate(ceed, q_data_size_sur * loc_num_elem_sur * num_qpts_sur, &q_data_sur);
88368c645fSJames Wright 
89368c645fSJames Wright   // ---- CEED Operator
90368c645fSJames Wright   // ----- CEED Operator for Setup (geometric factors)
91368c645fSJames Wright   CeedOperatorCreate(ceed, ceed_data->qf_setup_sur, NULL, NULL, &op_setup_sur);
92*2b916ea7SJeremy L Thompson   CeedOperatorSetField(op_setup_sur, "dx", elem_restr_x_sur, ceed_data->basis_x_sur, CEED_VECTOR_ACTIVE);
93*2b916ea7SJeremy L Thompson   CeedOperatorSetField(op_setup_sur, "weight", CEED_ELEMRESTRICTION_NONE, ceed_data->basis_x_sur, CEED_VECTOR_NONE);
94*2b916ea7SJeremy L Thompson   CeedOperatorSetField(op_setup_sur, "surface qdata", elem_restr_qd_i_sur, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE);
95368c645fSJames Wright 
96368c645fSJames Wright   // ----- CEED Operator for Physics
97368c645fSJames Wright   CeedOperatorCreate(ceed, qf_apply_bc, NULL, NULL, &op_apply_bc);
98*2b916ea7SJeremy L Thompson   CeedOperatorSetField(op_apply_bc, "q", elem_restr_q_sur, ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
99*2b916ea7SJeremy L Thompson   CeedOperatorSetField(op_apply_bc, "Grad_q", elem_restr_q_sur, ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
100*2b916ea7SJeremy L Thompson   CeedOperatorSetField(op_apply_bc, "surface qdata", elem_restr_qd_i_sur, CEED_BASIS_COLLOCATED, q_data_sur);
101*2b916ea7SJeremy L Thompson   CeedOperatorSetField(op_apply_bc, "x", elem_restr_x_sur, ceed_data->basis_x_sur, ceed_data->x_coord);
102*2b916ea7SJeremy L Thompson   CeedOperatorSetField(op_apply_bc, "v", elem_restr_q_sur, ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
103*2b916ea7SJeremy 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);
104368c645fSJames Wright 
105368c645fSJames Wright   if (qf_apply_bc_jacobian) {
106*2b916ea7SJeremy L Thompson     CeedOperatorCreate(ceed, qf_apply_bc_jacobian, NULL, NULL, &op_apply_bc_jacobian);
107*2b916ea7SJeremy L Thompson     CeedOperatorSetField(op_apply_bc_jacobian, "dq", elem_restr_q_sur, ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
108*2b916ea7SJeremy L Thompson     CeedOperatorSetField(op_apply_bc_jacobian, "Grad_dq", elem_restr_q_sur, ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
109*2b916ea7SJeremy L Thompson     CeedOperatorSetField(op_apply_bc_jacobian, "surface qdata", elem_restr_qd_i_sur, CEED_BASIS_COLLOCATED, q_data_sur);
110*2b916ea7SJeremy L Thompson     CeedOperatorSetField(op_apply_bc_jacobian, "x", elem_restr_x_sur, ceed_data->basis_x_sur, ceed_data->x_coord);
111*2b916ea7SJeremy L Thompson     CeedOperatorSetField(op_apply_bc_jacobian, "surface jacobian data", elem_restr_jd_i_sur, CEED_BASIS_COLLOCATED, jac_data_sur);
112*2b916ea7SJeremy L Thompson     CeedOperatorSetField(op_apply_bc_jacobian, "v", elem_restr_q_sur, ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
113368c645fSJames Wright   }
114368c645fSJames Wright 
115368c645fSJames Wright   // ----- Apply CEED operator for Setup
116*2b916ea7SJeremy L Thompson   CeedOperatorApply(op_setup_sur, ceed_data->x_coord, q_data_sur, CEED_REQUEST_IMMEDIATE);
117368c645fSJames Wright 
118368c645fSJames Wright   // ----- Apply Sub-Operator for Physics
119368c645fSJames Wright   CeedCompositeOperatorAddSub(*op_apply, op_apply_bc);
120*2b916ea7SJeremy L Thompson   if (op_apply_bc_jacobian) CeedCompositeOperatorAddSub(*op_apply_ijacobian, op_apply_bc_jacobian);
121368c645fSJames Wright 
122368c645fSJames Wright   // ----- Cleanup
123368c645fSJames Wright   CeedVectorDestroy(&q_data_sur);
124368c645fSJames Wright   CeedVectorDestroy(&jac_data_sur);
125368c645fSJames Wright   CeedElemRestrictionDestroy(&elem_restr_q_sur);
126368c645fSJames Wright   CeedElemRestrictionDestroy(&elem_restr_x_sur);
127368c645fSJames Wright   CeedElemRestrictionDestroy(&elem_restr_qd_i_sur);
128368c645fSJames Wright   CeedElemRestrictionDestroy(&elem_restr_jd_i_sur);
129368c645fSJames Wright   CeedOperatorDestroy(&op_setup_sur);
130368c645fSJames Wright   CeedOperatorDestroy(&op_apply_bc);
131368c645fSJames Wright   CeedOperatorDestroy(&op_apply_bc_jacobian);
132368c645fSJames Wright 
133368c645fSJames Wright   PetscFunctionReturn(0);
134368c645fSJames Wright }
135368c645fSJames Wright 
136a515125bSLeila Ghaffari // Utility function to create CEED Composite Operator for the entire domain
137*2b916ea7SJeremy L Thompson PetscErrorCode CreateOperatorForDomain(Ceed ceed, DM dm, SimpleBC bc, CeedData ceed_data, Physics phys, CeedOperator op_apply_vol,
138*2b916ea7SJeremy L Thompson                                        CeedOperator op_apply_ijacobian_vol, CeedInt height, CeedInt P_sur, CeedInt Q_sur, CeedInt q_data_size_sur,
139*2b916ea7SJeremy L Thompson                                        CeedInt jac_data_size_sur, CeedOperator *op_apply, CeedOperator *op_apply_ijacobian) {
140a515125bSLeila Ghaffari   DMLabel domain_label;
141a515125bSLeila Ghaffari   PetscFunctionBeginUser;
142a515125bSLeila Ghaffari 
143a515125bSLeila Ghaffari   // Create Composite Operaters
144a515125bSLeila Ghaffari   CeedCompositeOperatorCreate(ceed, op_apply);
145*2b916ea7SJeremy L Thompson   if (op_apply_ijacobian) CeedCompositeOperatorCreate(ceed, op_apply_ijacobian);
146a515125bSLeila Ghaffari 
147a515125bSLeila Ghaffari   // --Apply Sub-Operator for the volume
148a515125bSLeila Ghaffari   CeedCompositeOperatorAddSub(*op_apply, op_apply_vol);
149*2b916ea7SJeremy L Thompson   if (op_apply_ijacobian) CeedCompositeOperatorAddSub(*op_apply_ijacobian, op_apply_ijacobian_vol);
150a515125bSLeila Ghaffari 
151a515125bSLeila Ghaffari   // -- Create Sub-Operator for in/outflow BCs
152bb8a0c61SJames Wright   if (phys->has_neumann || 1) {
153a515125bSLeila Ghaffari     // --- Setup
154*2b916ea7SJeremy L Thompson     PetscCall(DMGetLabel(dm, "Face Sets", &domain_label));
155a515125bSLeila Ghaffari 
156002797a3SLeila Ghaffari     // --- Create Sub-Operator for inflow boundaries
157002797a3SLeila Ghaffari     for (CeedInt i = 0; i < bc->num_inflow; i++) {
158*2b916ea7SJeremy 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*2b916ea7SJeremy L Thompson                                  ceed_data->qf_apply_inflow, ceed_data->qf_apply_inflow_jacobian, op_apply, op_apply_ijacobian));
160a515125bSLeila Ghaffari     }
161a515125bSLeila Ghaffari 
162002797a3SLeila Ghaffari     // --- Create Sub-Operator for outflow boundaries
163002797a3SLeila Ghaffari     for (CeedInt i = 0; i < bc->num_outflow; i++) {
164*2b916ea7SJeremy 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*2b916ea7SJeremy L Thompson                                  ceed_data->qf_apply_outflow, ceed_data->qf_apply_outflow_jacobian, op_apply, op_apply_ijacobian));
1662556a851SJed Brown     }
167002797a3SLeila Ghaffari 
168df55ba5fSJames Wright     // --- Create Sub-Operator for freestream boundaries
169df55ba5fSJames Wright     for (CeedInt i = 0; i < bc->num_freestream; i++) {
170*2b916ea7SJeremy 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*2b916ea7SJeremy L Thompson                                  ceed_data->qf_apply_freestream, ceed_data->qf_apply_freestream_jacobian, op_apply, op_apply_ijacobian));
172002797a3SLeila Ghaffari     }
173002797a3SLeila Ghaffari   }
17492ada588SJames Wright 
17592ada588SJames Wright   // ----- Get Context Labels for Operator
176*2b916ea7SJeremy L Thompson   CeedOperatorContextGetFieldLabel(*op_apply, "solution time", &phys->solution_time_label);
177*2b916ea7SJeremy L Thompson   CeedOperatorContextGetFieldLabel(*op_apply, "timestep size", &phys->timestep_size_label);
17892ada588SJames Wright 
179a515125bSLeila Ghaffari   PetscFunctionReturn(0);
180a515125bSLeila Ghaffari }
181a515125bSLeila Ghaffari 
182*2b916ea7SJeremy L Thompson PetscErrorCode SetupBCQFunctions(Ceed ceed, PetscInt dim_sur, PetscInt num_comp_x, PetscInt num_comp_q, PetscInt q_data_size_sur,
183*2b916ea7SJeremy L Thompson                                  PetscInt jac_data_size_sur, ProblemQFunctionSpec apply_bc, ProblemQFunctionSpec apply_bc_jacobian,
18425988f00SJames Wright                                  CeedQFunction *qf_apply_bc, CeedQFunction *qf_apply_bc_jacobian) {
18525988f00SJames Wright   PetscFunctionBeginUser;
18625988f00SJames Wright 
18725988f00SJames Wright   if (apply_bc.qfunction) {
18825988f00SJames Wright     // *INDENT-OFF*
18925988f00SJames Wright     CeedQFunctionCreateInterior(ceed, 1, apply_bc.qfunction, apply_bc.qfunction_loc, qf_apply_bc);
19025988f00SJames Wright     CeedQFunctionSetContext(*qf_apply_bc, apply_bc.qfunction_context);
19125988f00SJames Wright     CeedQFunctionContextDestroy(&apply_bc.qfunction_context);
19225988f00SJames Wright     CeedQFunctionAddInput(*qf_apply_bc, "q", num_comp_q, CEED_EVAL_INTERP);
19325988f00SJames Wright     CeedQFunctionAddInput(*qf_apply_bc, "Grad_q", num_comp_q * dim_sur, CEED_EVAL_GRAD);
19425988f00SJames Wright     CeedQFunctionAddInput(*qf_apply_bc, "surface qdata", q_data_size_sur, CEED_EVAL_NONE);
19525988f00SJames Wright     CeedQFunctionAddInput(*qf_apply_bc, "x", num_comp_x, CEED_EVAL_INTERP);
19625988f00SJames Wright     CeedQFunctionAddOutput(*qf_apply_bc, "v", num_comp_q, CEED_EVAL_INTERP);
19725988f00SJames Wright     // *INDENT-ON*
198*2b916ea7SJeremy L Thompson     if (jac_data_size_sur) CeedQFunctionAddOutput(*qf_apply_bc, "surface jacobian data", jac_data_size_sur, CEED_EVAL_NONE);
19925988f00SJames Wright   }
20025988f00SJames Wright   if (apply_bc_jacobian.qfunction) {
20125988f00SJames Wright     // *INDENT-OFF*
202*2b916ea7SJeremy L Thompson     CeedQFunctionCreateInterior(ceed, 1, apply_bc_jacobian.qfunction, apply_bc_jacobian.qfunction_loc, qf_apply_bc_jacobian);
20325988f00SJames Wright     CeedQFunctionSetContext(*qf_apply_bc_jacobian, apply_bc_jacobian.qfunction_context);
20425988f00SJames Wright     CeedQFunctionContextDestroy(&apply_bc_jacobian.qfunction_context);
20525988f00SJames Wright     CeedQFunctionAddInput(*qf_apply_bc_jacobian, "dq", num_comp_q, CEED_EVAL_INTERP);
20625988f00SJames Wright     CeedQFunctionAddInput(*qf_apply_bc_jacobian, "Grad_dq", num_comp_q * dim_sur, CEED_EVAL_GRAD);
20725988f00SJames Wright     CeedQFunctionAddInput(*qf_apply_bc_jacobian, "surface qdata", q_data_size_sur, CEED_EVAL_NONE);
20825988f00SJames Wright     CeedQFunctionAddInput(*qf_apply_bc_jacobian, "x", num_comp_x, CEED_EVAL_INTERP);
209*2b916ea7SJeremy L Thompson     CeedQFunctionAddInput(*qf_apply_bc_jacobian, "surface jacobian data", jac_data_size_sur, CEED_EVAL_NONE);
21025988f00SJames Wright     CeedQFunctionAddOutput(*qf_apply_bc_jacobian, "v", num_comp_q, CEED_EVAL_INTERP);
21125988f00SJames Wright     // *INDENT-ON*
21225988f00SJames Wright   }
21325988f00SJames Wright   PetscFunctionReturn(0);
21425988f00SJames Wright }
21525988f00SJames Wright 
216*2b916ea7SJeremy L Thompson PetscErrorCode SetupLibceed(Ceed ceed, CeedData ceed_data, DM dm, User user, AppCtx app_ctx, ProblemData *problem, SimpleBC bc) {
217a515125bSLeila Ghaffari   PetscFunctionBeginUser;
218a515125bSLeila Ghaffari 
219a515125bSLeila Ghaffari   // *****************************************************************************
220a515125bSLeila Ghaffari   // Set up CEED objects for the interior domain (volume)
221a515125bSLeila Ghaffari   // *****************************************************************************
222a515125bSLeila Ghaffari   const PetscInt num_comp_q = 5;
223*2b916ea7SJeremy 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*2b916ea7SJeremy L Thompson                 P = app_ctx->degree + 1, Q = P + app_ctx->q_extra;
225752f40e3SJed Brown   CeedElemRestriction elem_restr_jd_i;
226752f40e3SJed Brown   CeedVector          jac_data;
227a515125bSLeila Ghaffari 
228a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
229a515125bSLeila Ghaffari   // CEED Bases
230a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
231*2b916ea7SJeremy L Thompson   CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_q, P, Q, CEED_GAUSS, &ceed_data->basis_q);
232*2b916ea7SJeremy L Thompson   CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_x, 2, Q, CEED_GAUSS, &ceed_data->basis_x);
233*2b916ea7SJeremy L Thompson   CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_x, 2, P, CEED_GAUSS_LOBATTO, &ceed_data->basis_xc);
234a515125bSLeila Ghaffari 
235a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
236a515125bSLeila Ghaffari   // CEED Restrictions
237a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
238a515125bSLeila Ghaffari   // -- Create restriction
239*2b916ea7SJeremy 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*2b916ea7SJeremy L Thompson                                     &ceed_data->elem_restr_qd_i));
241752f40e3SJed Brown 
242*2b916ea7SJeremy L Thompson   PetscCall(GetRestrictionForDomain(ceed, dm, 0, 0, 0, Q, jac_data_size_vol, NULL, NULL, &elem_restr_jd_i));
243a515125bSLeila Ghaffari   // -- Create E vectors
244a515125bSLeila Ghaffari   CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->q_ceed, NULL);
245*2b916ea7SJeremy L Thompson   CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->q_dot_ceed, NULL);
246a515125bSLeila Ghaffari   CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->g_ceed, NULL);
247a515125bSLeila Ghaffari 
248a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
249a515125bSLeila Ghaffari   // CEED QFunctions
250a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
251a515125bSLeila Ghaffari   // -- Create QFunction for quadrature data
252*2b916ea7SJeremy L Thompson   CeedQFunctionCreateInterior(ceed, 1, problem->setup_vol.qfunction, problem->setup_vol.qfunction_loc, &ceed_data->qf_setup_vol);
25315a3537eSJed Brown   if (problem->setup_vol.qfunction_context) {
254*2b916ea7SJeremy L Thompson     CeedQFunctionSetContext(ceed_data->qf_setup_vol, problem->setup_vol.qfunction_context);
25515a3537eSJed Brown     CeedQFunctionContextDestroy(&problem->setup_vol.qfunction_context);
25615a3537eSJed Brown   }
257*2b916ea7SJeremy L Thompson   CeedQFunctionAddInput(ceed_data->qf_setup_vol, "dx", num_comp_x * dim, CEED_EVAL_GRAD);
258a515125bSLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_setup_vol, "weight", 1, CEED_EVAL_WEIGHT);
259*2b916ea7SJeremy L Thompson   CeedQFunctionAddOutput(ceed_data->qf_setup_vol, "qdata", q_data_size_vol, CEED_EVAL_NONE);
260a515125bSLeila Ghaffari 
261a515125bSLeila Ghaffari   // -- Create QFunction for ICs
262*2b916ea7SJeremy L Thompson   CeedQFunctionCreateInterior(ceed, 1, problem->ics.qfunction, problem->ics.qfunction_loc, &ceed_data->qf_ics);
26315a3537eSJed Brown   CeedQFunctionSetContext(ceed_data->qf_ics, problem->ics.qfunction_context);
26415a3537eSJed Brown   CeedQFunctionContextDestroy(&problem->ics.qfunction_context);
265a515125bSLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_ics, "x", num_comp_x, CEED_EVAL_INTERP);
266*2b916ea7SJeremy L Thompson   CeedQFunctionAddInput(ceed_data->qf_ics, "qdata", q_data_size_vol, CEED_EVAL_NONE);
267a515125bSLeila Ghaffari   CeedQFunctionAddOutput(ceed_data->qf_ics, "q0", num_comp_q, CEED_EVAL_NONE);
268a515125bSLeila Ghaffari 
269a515125bSLeila Ghaffari   // -- Create QFunction for RHS
2709785fe93SJed Brown   if (problem->apply_vol_rhs.qfunction) {
271*2b916ea7SJeremy L Thompson     CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_rhs.qfunction, problem->apply_vol_rhs.qfunction_loc, &ceed_data->qf_rhs_vol);
272*2b916ea7SJeremy L Thompson     CeedQFunctionSetContext(ceed_data->qf_rhs_vol, problem->apply_vol_rhs.qfunction_context);
27315a3537eSJed Brown     CeedQFunctionContextDestroy(&problem->apply_vol_rhs.qfunction_context);
274a515125bSLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "q", num_comp_q, CEED_EVAL_INTERP);
275*2b916ea7SJeremy L Thompson     CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "Grad_q", num_comp_q * dim, CEED_EVAL_GRAD);
276*2b916ea7SJeremy L Thompson     CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "qdata", q_data_size_vol, CEED_EVAL_NONE);
277a515125bSLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "x", num_comp_x, CEED_EVAL_INTERP);
278*2b916ea7SJeremy L Thompson     CeedQFunctionAddOutput(ceed_data->qf_rhs_vol, "v", num_comp_q, CEED_EVAL_INTERP);
279*2b916ea7SJeremy L Thompson     CeedQFunctionAddOutput(ceed_data->qf_rhs_vol, "Grad_v", num_comp_q * dim, CEED_EVAL_GRAD);
280a515125bSLeila Ghaffari   }
281a515125bSLeila Ghaffari 
282a515125bSLeila Ghaffari   // -- Create QFunction for IFunction
2839785fe93SJed Brown   if (problem->apply_vol_ifunction.qfunction) {
284*2b916ea7SJeremy L Thompson     CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_ifunction.qfunction, problem->apply_vol_ifunction.qfunction_loc,
285*2b916ea7SJeremy L Thompson                                 &ceed_data->qf_ifunction_vol);
286*2b916ea7SJeremy L Thompson     CeedQFunctionSetContext(ceed_data->qf_ifunction_vol, problem->apply_vol_ifunction.qfunction_context);
28715a3537eSJed Brown     CeedQFunctionContextDestroy(&problem->apply_vol_ifunction.qfunction_context);
288*2b916ea7SJeremy L Thompson     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "q", num_comp_q, CEED_EVAL_INTERP);
289*2b916ea7SJeremy L Thompson     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "Grad_q", num_comp_q * dim, CEED_EVAL_GRAD);
290*2b916ea7SJeremy L Thompson     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "q dot", num_comp_q, CEED_EVAL_INTERP);
291*2b916ea7SJeremy L Thompson     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "qdata", q_data_size_vol, CEED_EVAL_NONE);
292*2b916ea7SJeremy L Thompson     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "x", num_comp_x, CEED_EVAL_INTERP);
293*2b916ea7SJeremy L Thompson     CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "v", num_comp_q, CEED_EVAL_INTERP);
294*2b916ea7SJeremy L Thompson     CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "Grad_v", num_comp_q * dim, CEED_EVAL_GRAD);
295*2b916ea7SJeremy L Thompson     CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "jac_data", jac_data_size_vol, CEED_EVAL_NONE);
296a515125bSLeila Ghaffari   }
297a515125bSLeila Ghaffari 
298f0b65372SJed Brown   CeedQFunction qf_ijacobian_vol = NULL;
299f0b65372SJed Brown   if (problem->apply_vol_ijacobian.qfunction) {
300*2b916ea7SJeremy L Thompson     CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_ijacobian.qfunction, problem->apply_vol_ijacobian.qfunction_loc, &qf_ijacobian_vol);
301*2b916ea7SJeremy L Thompson     CeedQFunctionSetContext(qf_ijacobian_vol, problem->apply_vol_ijacobian.qfunction_context);
302f0b65372SJed Brown     CeedQFunctionContextDestroy(&problem->apply_vol_ijacobian.qfunction_context);
303*2b916ea7SJeremy L Thompson     CeedQFunctionAddInput(qf_ijacobian_vol, "dq", num_comp_q, CEED_EVAL_INTERP);
304*2b916ea7SJeremy L Thompson     CeedQFunctionAddInput(qf_ijacobian_vol, "Grad_dq", num_comp_q * dim, CEED_EVAL_GRAD);
305*2b916ea7SJeremy L Thompson     CeedQFunctionAddInput(qf_ijacobian_vol, "qdata", q_data_size_vol, CEED_EVAL_NONE);
306*2b916ea7SJeremy L Thompson     CeedQFunctionAddInput(qf_ijacobian_vol, "x", num_comp_x, CEED_EVAL_INTERP);
307*2b916ea7SJeremy L Thompson     CeedQFunctionAddInput(qf_ijacobian_vol, "jac_data", jac_data_size_vol, CEED_EVAL_NONE);
308*2b916ea7SJeremy L Thompson     CeedQFunctionAddOutput(qf_ijacobian_vol, "v", num_comp_q, CEED_EVAL_INTERP);
309*2b916ea7SJeremy L Thompson     CeedQFunctionAddOutput(qf_ijacobian_vol, "Grad_v", num_comp_q * dim, CEED_EVAL_GRAD);
310f0b65372SJed Brown   }
311f0b65372SJed Brown 
312a515125bSLeila Ghaffari   // ---------------------------------------------------------------------------
313a515125bSLeila Ghaffari   // Element coordinates
314a515125bSLeila Ghaffari   // ---------------------------------------------------------------------------
315a515125bSLeila Ghaffari   // -- Create CEED vector
316*2b916ea7SJeremy L Thompson   CeedElemRestrictionCreateVector(ceed_data->elem_restr_x, &ceed_data->x_coord, NULL);
317a515125bSLeila Ghaffari 
318a515125bSLeila Ghaffari   // -- Copy PETSc vector in CEED vector
319a515125bSLeila Ghaffari   Vec                X_loc;
320a515125bSLeila Ghaffari   const PetscScalar *X_loc_array;
321cac8aa24SJed Brown   {
322cac8aa24SJed Brown     DM cdm;
323*2b916ea7SJeremy L Thompson     PetscCall(DMGetCellCoordinateDM(dm, &cdm));
324*2b916ea7SJeremy L Thompson     if (cdm) {
325*2b916ea7SJeremy L Thompson       PetscCall(DMGetCellCoordinatesLocal(dm, &X_loc));
326*2b916ea7SJeremy L Thompson     } else {
327*2b916ea7SJeremy L Thompson       PetscCall(DMGetCoordinatesLocal(dm, &X_loc));
328cac8aa24SJed Brown     }
329*2b916ea7SJeremy L Thompson   }
330*2b916ea7SJeremy L Thompson   PetscCall(VecScale(X_loc, problem->dm_scale));
331*2b916ea7SJeremy L Thompson   PetscCall(VecGetArrayRead(X_loc, &X_loc_array));
332*2b916ea7SJeremy L Thompson   CeedVectorSetArray(ceed_data->x_coord, CEED_MEM_HOST, CEED_COPY_VALUES, (PetscScalar *)X_loc_array);
333*2b916ea7SJeremy L Thompson   PetscCall(VecRestoreArrayRead(X_loc, &X_loc_array));
334a515125bSLeila Ghaffari 
335a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
336a515125bSLeila Ghaffari   // CEED vectors
337a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
338a515125bSLeila Ghaffari   // -- Create CEED vector for geometric data
339a515125bSLeila Ghaffari   CeedInt  num_qpts_vol;
340a515125bSLeila Ghaffari   PetscInt loc_num_elem_vol;
341a515125bSLeila Ghaffari   CeedBasisGetNumQuadraturePoints(ceed_data->basis_q, &num_qpts_vol);
342a515125bSLeila Ghaffari   CeedElemRestrictionGetNumElements(ceed_data->elem_restr_q, &loc_num_elem_vol);
343*2b916ea7SJeremy L Thompson   CeedVectorCreate(ceed, q_data_size_vol * loc_num_elem_vol * num_qpts_vol, &ceed_data->q_data);
344a515125bSLeila Ghaffari 
345752f40e3SJed Brown   CeedElemRestrictionCreateVector(elem_restr_jd_i, &jac_data, NULL);
346a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
347a515125bSLeila Ghaffari   // CEED Operators
348a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
349a515125bSLeila Ghaffari   // -- Create CEED operator for quadrature data
350*2b916ea7SJeremy L Thompson   CeedOperatorCreate(ceed, ceed_data->qf_setup_vol, NULL, NULL, &ceed_data->op_setup_vol);
351*2b916ea7SJeremy L Thompson   CeedOperatorSetField(ceed_data->op_setup_vol, "dx", ceed_data->elem_restr_x, ceed_data->basis_x, CEED_VECTOR_ACTIVE);
352*2b916ea7SJeremy L Thompson   CeedOperatorSetField(ceed_data->op_setup_vol, "weight", CEED_ELEMRESTRICTION_NONE, ceed_data->basis_x, CEED_VECTOR_NONE);
353*2b916ea7SJeremy L Thompson   CeedOperatorSetField(ceed_data->op_setup_vol, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE);
354a515125bSLeila Ghaffari 
355a515125bSLeila Ghaffari   // -- Create CEED operator for ICs
356a515125bSLeila Ghaffari   CeedOperatorCreate(ceed, ceed_data->qf_ics, NULL, NULL, &ceed_data->op_ics);
357*2b916ea7SJeremy L Thompson   CeedOperatorSetField(ceed_data->op_ics, "x", ceed_data->elem_restr_x, ceed_data->basis_xc, CEED_VECTOR_ACTIVE);
358*2b916ea7SJeremy L Thompson   CeedOperatorSetField(ceed_data->op_ics, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, ceed_data->q_data);
359*2b916ea7SJeremy L Thompson   CeedOperatorSetField(ceed_data->op_ics, "q0", ceed_data->elem_restr_q, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE);
360*2b916ea7SJeremy L Thompson   CeedOperatorContextGetFieldLabel(ceed_data->op_ics, "evaluation time", &user->phys->ics_time_label);
361a515125bSLeila Ghaffari 
362a515125bSLeila Ghaffari   // Create CEED operator for RHS
363a515125bSLeila Ghaffari   if (ceed_data->qf_rhs_vol) {
364a515125bSLeila Ghaffari     CeedOperator op;
365a515125bSLeila Ghaffari     CeedOperatorCreate(ceed, ceed_data->qf_rhs_vol, NULL, NULL, &op);
366*2b916ea7SJeremy L Thompson     CeedOperatorSetField(op, "q", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE);
367*2b916ea7SJeremy L Thompson     CeedOperatorSetField(op, "Grad_q", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE);
368*2b916ea7SJeremy L Thompson     CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, ceed_data->q_data);
369*2b916ea7SJeremy L Thompson     CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord);
370*2b916ea7SJeremy L Thompson     CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE);
371*2b916ea7SJeremy L Thompson     CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE);
372a515125bSLeila Ghaffari     user->op_rhs_vol = op;
373a515125bSLeila Ghaffari   }
374a515125bSLeila Ghaffari 
375a515125bSLeila Ghaffari   // -- CEED operator for IFunction
376a515125bSLeila Ghaffari   if (ceed_data->qf_ifunction_vol) {
377a515125bSLeila Ghaffari     CeedOperator op;
378a515125bSLeila Ghaffari     CeedOperatorCreate(ceed, ceed_data->qf_ifunction_vol, NULL, NULL, &op);
379*2b916ea7SJeremy L Thompson     CeedOperatorSetField(op, "q", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE);
380*2b916ea7SJeremy L Thompson     CeedOperatorSetField(op, "Grad_q", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE);
381*2b916ea7SJeremy L Thompson     CeedOperatorSetField(op, "q dot", ceed_data->elem_restr_q, ceed_data->basis_q, user->q_dot_ceed);
382*2b916ea7SJeremy L Thompson     CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, ceed_data->q_data);
383*2b916ea7SJeremy L Thompson     CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord);
384*2b916ea7SJeremy L Thompson     CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE);
385*2b916ea7SJeremy L Thompson     CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE);
386*2b916ea7SJeremy L Thompson     CeedOperatorSetField(op, "jac_data", elem_restr_jd_i, CEED_BASIS_COLLOCATED, jac_data);
387752f40e3SJed Brown 
388a515125bSLeila Ghaffari     user->op_ifunction_vol = op;
389a515125bSLeila Ghaffari   }
390a515125bSLeila Ghaffari 
391f0b65372SJed Brown   CeedOperator op_ijacobian_vol = NULL;
392f0b65372SJed Brown   if (qf_ijacobian_vol) {
393f0b65372SJed Brown     CeedOperator op;
394f0b65372SJed Brown     CeedOperatorCreate(ceed, qf_ijacobian_vol, NULL, NULL, &op);
395*2b916ea7SJeremy L Thompson     CeedOperatorSetField(op, "dq", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE);
396*2b916ea7SJeremy L Thompson     CeedOperatorSetField(op, "Grad_dq", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE);
397*2b916ea7SJeremy L Thompson     CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, ceed_data->q_data);
398*2b916ea7SJeremy L Thompson     CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x, ceed_data->x_coord);
399*2b916ea7SJeremy L Thompson     CeedOperatorSetField(op, "jac_data", elem_restr_jd_i, CEED_BASIS_COLLOCATED, jac_data);
400*2b916ea7SJeremy L Thompson     CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE);
401*2b916ea7SJeremy L Thompson     CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q, CEED_VECTOR_ACTIVE);
402f0b65372SJed Brown     op_ijacobian_vol = op;
403f0b65372SJed Brown     CeedQFunctionDestroy(&qf_ijacobian_vol);
404f0b65372SJed Brown   }
405f0b65372SJed Brown 
406a515125bSLeila Ghaffari   // *****************************************************************************
407a515125bSLeila Ghaffari   // Set up CEED objects for the exterior domain (surface)
408a515125bSLeila Ghaffari   // *****************************************************************************
409*2b916ea7SJeremy L Thompson   CeedInt       height = 1, dim_sur = dim - height, P_sur = app_ctx->degree + 1, Q_sur = P_sur + app_ctx->q_extra;
410*2b916ea7SJeremy L Thompson   const CeedInt q_data_size_sur = problem->q_data_size_sur, jac_data_size_sur = problem->jac_data_size_sur;
411a515125bSLeila Ghaffari 
412a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
413a515125bSLeila Ghaffari   // CEED Bases
414a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
415*2b916ea7SJeremy L Thompson   CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_q, P_sur, Q_sur, CEED_GAUSS, &ceed_data->basis_q_sur);
416*2b916ea7SJeremy L Thompson   CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_x, 2, Q_sur, CEED_GAUSS, &ceed_data->basis_x_sur);
417*2b916ea7SJeremy L Thompson   CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_x, 2, P_sur, CEED_GAUSS_LOBATTO, &ceed_data->basis_xc_sur);
418a515125bSLeila Ghaffari 
419a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
420a515125bSLeila Ghaffari   // CEED QFunctions
421a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
422a515125bSLeila Ghaffari   // -- Create QFunction for quadrature data
423*2b916ea7SJeremy L Thompson   CeedQFunctionCreateInterior(ceed, 1, problem->setup_sur.qfunction, problem->setup_sur.qfunction_loc, &ceed_data->qf_setup_sur);
42415a3537eSJed Brown   if (problem->setup_sur.qfunction_context) {
425*2b916ea7SJeremy L Thompson     CeedQFunctionSetContext(ceed_data->qf_setup_sur, problem->setup_sur.qfunction_context);
42615a3537eSJed Brown     CeedQFunctionContextDestroy(&problem->setup_sur.qfunction_context);
42715a3537eSJed Brown   }
428*2b916ea7SJeremy L Thompson   CeedQFunctionAddInput(ceed_data->qf_setup_sur, "dx", num_comp_x * dim_sur, CEED_EVAL_GRAD);
429a515125bSLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_setup_sur, "weight", 1, CEED_EVAL_WEIGHT);
430*2b916ea7SJeremy L Thompson   CeedQFunctionAddOutput(ceed_data->qf_setup_sur, "surface qdata", q_data_size_sur, CEED_EVAL_NONE);
431a515125bSLeila Ghaffari 
432*2b916ea7SJeremy 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*2b916ea7SJeremy L Thompson                               problem->apply_inflow_jacobian, &ceed_data->qf_apply_inflow, &ceed_data->qf_apply_inflow_jacobian));
434002797a3SLeila Ghaffari 
435*2b916ea7SJeremy 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*2b916ea7SJeremy L Thompson                               problem->apply_outflow_jacobian, &ceed_data->qf_apply_outflow, &ceed_data->qf_apply_outflow_jacobian));
437a515125bSLeila Ghaffari 
438*2b916ea7SJeremy 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*2b916ea7SJeremy L Thompson                               problem->apply_freestream_jacobian, &ceed_data->qf_apply_freestream, &ceed_data->qf_apply_freestream_jacobian));
440a515125bSLeila Ghaffari 
441a515125bSLeila Ghaffari   // *****************************************************************************
442a515125bSLeila Ghaffari   // CEED Operator Apply
443a515125bSLeila Ghaffari   // *****************************************************************************
444a515125bSLeila Ghaffari   // -- Apply CEED Operator for the geometric data
445*2b916ea7SJeremy L Thompson   CeedOperatorApply(ceed_data->op_setup_vol, ceed_data->x_coord, ceed_data->q_data, CEED_REQUEST_IMMEDIATE);
446a515125bSLeila Ghaffari 
447a515125bSLeila Ghaffari   // -- Create and apply CEED Composite Operator for the entire domain
448a515125bSLeila Ghaffari   if (!user->phys->implicit) {  // RHS
449*2b916ea7SJeremy 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*2b916ea7SJeremy L Thompson                                       &user->op_rhs, NULL));
451a515125bSLeila Ghaffari   } else {  // IFunction
452*2b916ea7SJeremy L Thompson     PetscCall(CreateOperatorForDomain(ceed, dm, bc, ceed_data, user->phys, user->op_ifunction_vol, op_ijacobian_vol, height, P_sur, Q_sur,
453*2b916ea7SJeremy L Thompson                                       q_data_size_sur, jac_data_size_sur, &user->op_ifunction, op_ijacobian_vol ? &user->op_ijacobian : NULL));
454f0b65372SJed Brown     if (user->op_ijacobian) {
455*2b916ea7SJeremy L Thompson       CeedOperatorContextGetFieldLabel(user->op_ijacobian, "ijacobian time shift", &user->phys->ijacobian_time_shift_label);
456f0b65372SJed Brown     }
4576d0190e2SJames Wright     if (problem->use_dirichlet_ceed) {
458*2b916ea7SJeremy L Thompson       PetscCall(SetupStrongBC_Ceed(ceed, ceed_data, dm, user, app_ctx, problem, bc, Q_sur, q_data_size_sur));
4596d0190e2SJames Wright     }
460a515125bSLeila Ghaffari   }
461752f40e3SJed Brown   CeedElemRestrictionDestroy(&elem_restr_jd_i);
462e22e0f1cSLeila Ghaffari   CeedOperatorDestroy(&op_ijacobian_vol);
463752f40e3SJed Brown   CeedVectorDestroy(&jac_data);
464a515125bSLeila Ghaffari   PetscFunctionReturn(0);
465a515125bSLeila Ghaffari }
466