xref: /libCEED/examples/fluids/src/setuplibceed.c (revision 9eb9c072e5a82e606f91268335049ddfee1c572b)
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).
1477841947SLeila Ghaffari PetscInt Involute(PetscInt i) {
1577841947SLeila Ghaffari   return i >= 0 ? i : -(i+1);
1677841947SLeila Ghaffari }
1777841947SLeila Ghaffari 
1877841947SLeila Ghaffari // Utility function to create local CEED restriction
197ed3e4cdSJeremy L Thompson PetscErrorCode CreateRestrictionFromPlex(Ceed ceed, DM dm, CeedInt height,
207ed3e4cdSJeremy L Thompson     DMLabel domain_label, CeedInt value, CeedElemRestriction *elem_restr) {
217ed3e4cdSJeremy L Thompson   PetscInt num_elem, elem_size, num_dof, num_comp, *elem_restr_offsets;
2277841947SLeila Ghaffari   PetscErrorCode ierr;
237ed3e4cdSJeremy L Thompson 
2477841947SLeila Ghaffari   PetscFunctionBeginUser;
257ed3e4cdSJeremy L Thompson   ierr = DMPlexGetLocalOffsets(dm, domain_label, value, height, 0, &num_elem,
267ed3e4cdSJeremy L Thompson                                &elem_size, &num_comp, &num_dof, &elem_restr_offsets);
277ed3e4cdSJeremy L Thompson   CHKERRQ(ierr);
2877841947SLeila Ghaffari 
297ed3e4cdSJeremy L Thompson   CeedElemRestrictionCreate(ceed, num_elem, elem_size, num_comp,
307ed3e4cdSJeremy L Thompson                             1, num_dof, CEED_MEM_HOST, CEED_COPY_VALUES,
317ed3e4cdSJeremy L Thompson                             elem_restr_offsets, elem_restr);
327ed3e4cdSJeremy L Thompson   ierr = PetscFree(elem_restr_offsets); CHKERRQ(ierr);
3377841947SLeila Ghaffari 
3477841947SLeila Ghaffari   PetscFunctionReturn(0);
3577841947SLeila Ghaffari }
3677841947SLeila Ghaffari 
3777841947SLeila Ghaffari // Utility function to get Ceed Restriction for each domain
3877841947SLeila Ghaffari PetscErrorCode GetRestrictionForDomain(Ceed ceed, DM dm, CeedInt height,
3977841947SLeila Ghaffari                                        DMLabel domain_label, PetscInt value,
407ed3e4cdSJeremy L Thompson                                        CeedInt Q, CeedInt q_data_size,
4177841947SLeila Ghaffari                                        CeedElemRestriction *elem_restr_q,
4277841947SLeila Ghaffari                                        CeedElemRestriction *elem_restr_x,
4377841947SLeila Ghaffari                                        CeedElemRestriction *elem_restr_qd_i) {
4477841947SLeila Ghaffari   DM             dm_coord;
4577841947SLeila Ghaffari   CeedInt        dim, loc_num_elem;
4677841947SLeila Ghaffari   CeedInt        Q_dim;
472534dcc8SJed Brown   CeedElemRestriction elem_restr_tmp;
4877841947SLeila Ghaffari   PetscErrorCode ierr;
4977841947SLeila Ghaffari   PetscFunctionBeginUser;
5077841947SLeila Ghaffari 
5177841947SLeila Ghaffari   ierr = DMGetDimension(dm, &dim); CHKERRQ(ierr);
5277841947SLeila Ghaffari   dim -= height;
5377841947SLeila Ghaffari   Q_dim = CeedIntPow(Q, dim);
542534dcc8SJed Brown   ierr = CreateRestrictionFromPlex(ceed, dm, height, domain_label, value,
552534dcc8SJed Brown                                    &elem_restr_tmp);
562534dcc8SJed Brown   CHKERRQ(ierr);
572534dcc8SJed Brown   if (elem_restr_q) *elem_restr_q = elem_restr_tmp;
582534dcc8SJed Brown   if (elem_restr_x) {
593796c488SJed Brown     ierr = DMGetCellCoordinateDM(dm, &dm_coord); CHKERRQ(ierr);
603796c488SJed Brown     if (!dm_coord) {
6177841947SLeila Ghaffari       ierr = DMGetCoordinateDM(dm, &dm_coord); CHKERRQ(ierr);
623796c488SJed Brown     }
6377841947SLeila Ghaffari     ierr = DMPlexSetClosurePermutationTensor(dm_coord, PETSC_DETERMINE, NULL);
6477841947SLeila Ghaffari     CHKERRQ(ierr);
657ed3e4cdSJeremy L Thompson     ierr = CreateRestrictionFromPlex(ceed, dm_coord, height, domain_label, value,
667ed3e4cdSJeremy L Thompson                                      elem_restr_x);
677ed3e4cdSJeremy L Thompson     CHKERRQ(ierr);
682534dcc8SJed Brown   }
692534dcc8SJed Brown   if (elem_restr_qd_i) {
702534dcc8SJed Brown     CeedElemRestrictionGetNumElements(elem_restr_tmp, &loc_num_elem);
7177841947SLeila Ghaffari     CeedElemRestrictionCreateStrided(ceed, loc_num_elem, Q_dim,
7277841947SLeila Ghaffari                                      q_data_size, q_data_size*loc_num_elem*Q_dim,
7377841947SLeila Ghaffari                                      CEED_STRIDES_BACKEND, elem_restr_qd_i);
742534dcc8SJed Brown   }
752534dcc8SJed Brown   if (!elem_restr_q) CeedElemRestrictionDestroy(&elem_restr_tmp);
7677841947SLeila Ghaffari   PetscFunctionReturn(0);
7777841947SLeila Ghaffari }
7877841947SLeila Ghaffari 
79*9eb9c072SJames Wright PetscErrorCode AddBCSubOperator(Ceed ceed, DM dm, CeedData ceed_data,
80*9eb9c072SJames Wright                                 DMLabel domain_label, PetscInt value,
81*9eb9c072SJames Wright                                 CeedInt height, CeedInt Q_sur,
82*9eb9c072SJames Wright                                 CeedInt q_data_size_sur, CeedInt jac_data_size_sur,
83*9eb9c072SJames Wright                                 CeedQFunction qf_apply_bc, CeedQFunction qf_apply_bc_jacobian,
84*9eb9c072SJames Wright                                 CeedOperator *op_apply, CeedOperator *op_apply_ijacobian) {
85*9eb9c072SJames Wright   CeedVector          q_data_sur, jac_data_sur;
86*9eb9c072SJames Wright   CeedOperator        op_setup_sur, op_apply_bc,
87*9eb9c072SJames Wright                       op_apply_bc_jacobian = NULL;
88*9eb9c072SJames Wright   CeedElemRestriction elem_restr_x_sur, elem_restr_q_sur, elem_restr_qd_i_sur,
89*9eb9c072SJames Wright                       elem_restr_jd_i_sur;
90*9eb9c072SJames Wright   CeedInt num_qpts_sur;
91*9eb9c072SJames Wright   PetscFunctionBeginUser;
92*9eb9c072SJames Wright 
93*9eb9c072SJames Wright   // --- Get number of quadrature points for the boundaries
94*9eb9c072SJames Wright   CeedBasisGetNumQuadraturePoints(ceed_data->basis_q_sur, &num_qpts_sur);
95*9eb9c072SJames Wright 
96*9eb9c072SJames Wright 
97*9eb9c072SJames Wright   // ---- CEED Restriction
98*9eb9c072SJames Wright   PetscCall(GetRestrictionForDomain(ceed, dm, height, domain_label, value, Q_sur,
99*9eb9c072SJames Wright                                     q_data_size_sur, &elem_restr_q_sur, &elem_restr_x_sur, &elem_restr_qd_i_sur));
100*9eb9c072SJames Wright   if (jac_data_size_sur > 0) {
101*9eb9c072SJames Wright     // State-dependent data will be passed from residual to Jacobian. This will be collocated.
102*9eb9c072SJames Wright     PetscCall(GetRestrictionForDomain(ceed, dm, height, domain_label, value, Q_sur,
103*9eb9c072SJames Wright                                       jac_data_size_sur, NULL, NULL, &elem_restr_jd_i_sur));
104*9eb9c072SJames Wright     CeedElemRestrictionCreateVector(elem_restr_jd_i_sur, &jac_data_sur, NULL);
105*9eb9c072SJames Wright   } else {
106*9eb9c072SJames Wright     elem_restr_jd_i_sur = NULL;
107*9eb9c072SJames Wright     jac_data_sur = NULL;
108*9eb9c072SJames Wright   }
109*9eb9c072SJames Wright 
110*9eb9c072SJames Wright   // ---- CEED Vector
111*9eb9c072SJames Wright   PetscInt loc_num_elem_sur;
112*9eb9c072SJames Wright   CeedElemRestrictionGetNumElements(elem_restr_q_sur, &loc_num_elem_sur);
113*9eb9c072SJames Wright   CeedVectorCreate(ceed, q_data_size_sur*loc_num_elem_sur*num_qpts_sur,
114*9eb9c072SJames Wright                    &q_data_sur);
115*9eb9c072SJames Wright 
116*9eb9c072SJames Wright   // ---- CEED Operator
117*9eb9c072SJames Wright   // ----- CEED Operator for Setup (geometric factors)
118*9eb9c072SJames Wright   CeedOperatorCreate(ceed, ceed_data->qf_setup_sur, NULL, NULL, &op_setup_sur);
119*9eb9c072SJames Wright   CeedOperatorSetField(op_setup_sur, "dx", elem_restr_x_sur,
120*9eb9c072SJames Wright                        ceed_data->basis_x_sur, CEED_VECTOR_ACTIVE);
121*9eb9c072SJames Wright   CeedOperatorSetField(op_setup_sur, "weight", CEED_ELEMRESTRICTION_NONE,
122*9eb9c072SJames Wright                        ceed_data->basis_x_sur, CEED_VECTOR_NONE);
123*9eb9c072SJames Wright   CeedOperatorSetField(op_setup_sur, "surface qdata", elem_restr_qd_i_sur,
124*9eb9c072SJames Wright                        CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE);
125*9eb9c072SJames Wright 
126*9eb9c072SJames Wright   // ----- CEED Operator for Physics
127*9eb9c072SJames Wright   CeedOperatorCreate(ceed, qf_apply_bc, NULL, NULL, &op_apply_bc);
128*9eb9c072SJames Wright   CeedOperatorSetField(op_apply_bc, "q", elem_restr_q_sur, ceed_data->basis_q_sur,
129*9eb9c072SJames Wright                        CEED_VECTOR_ACTIVE);
130*9eb9c072SJames Wright   CeedOperatorSetField(op_apply_bc, "Grad_q", elem_restr_q_sur,
131*9eb9c072SJames Wright                        ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
132*9eb9c072SJames Wright   CeedOperatorSetField(op_apply_bc, "surface qdata", elem_restr_qd_i_sur,
133*9eb9c072SJames Wright                        CEED_BASIS_COLLOCATED, q_data_sur);
134*9eb9c072SJames Wright   CeedOperatorSetField(op_apply_bc, "x", elem_restr_x_sur, ceed_data->basis_x_sur,
135*9eb9c072SJames Wright                        ceed_data->x_coord);
136*9eb9c072SJames Wright   CeedOperatorSetField(op_apply_bc, "v", elem_restr_q_sur, ceed_data->basis_q_sur,
137*9eb9c072SJames Wright                        CEED_VECTOR_ACTIVE);
138*9eb9c072SJames Wright   if (elem_restr_jd_i_sur)
139*9eb9c072SJames Wright     CeedOperatorSetField(op_apply_bc, "surface jacobian data",
140*9eb9c072SJames Wright                          elem_restr_jd_i_sur,
141*9eb9c072SJames Wright                          CEED_BASIS_COLLOCATED, jac_data_sur);
142*9eb9c072SJames Wright 
143*9eb9c072SJames Wright   if (qf_apply_bc_jacobian) {
144*9eb9c072SJames Wright     CeedOperatorCreate(ceed, qf_apply_bc_jacobian, NULL, NULL,
145*9eb9c072SJames Wright                        &op_apply_bc_jacobian);
146*9eb9c072SJames Wright     CeedOperatorSetField(op_apply_bc_jacobian, "dq", elem_restr_q_sur,
147*9eb9c072SJames Wright                          ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
148*9eb9c072SJames Wright     CeedOperatorSetField(op_apply_bc_jacobian, "Grad_dq", elem_restr_q_sur,
149*9eb9c072SJames Wright                          ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
150*9eb9c072SJames Wright     CeedOperatorSetField(op_apply_bc_jacobian, "surface qdata", elem_restr_qd_i_sur,
151*9eb9c072SJames Wright                          CEED_BASIS_COLLOCATED, q_data_sur);
152*9eb9c072SJames Wright     CeedOperatorSetField(op_apply_bc_jacobian, "x", elem_restr_x_sur,
153*9eb9c072SJames Wright                          ceed_data->basis_x_sur, ceed_data->x_coord);
154*9eb9c072SJames Wright     CeedOperatorSetField(op_apply_bc_jacobian, "surface jacobian data",
155*9eb9c072SJames Wright                          elem_restr_jd_i_sur, CEED_BASIS_COLLOCATED, jac_data_sur);
156*9eb9c072SJames Wright     CeedOperatorSetField(op_apply_bc_jacobian, "v", elem_restr_q_sur,
157*9eb9c072SJames Wright                          ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
158*9eb9c072SJames Wright   }
159*9eb9c072SJames Wright 
160*9eb9c072SJames Wright   // ----- Apply CEED operator for Setup
161*9eb9c072SJames Wright   CeedOperatorApply(op_setup_sur, ceed_data->x_coord, q_data_sur,
162*9eb9c072SJames Wright                     CEED_REQUEST_IMMEDIATE);
163*9eb9c072SJames Wright 
164*9eb9c072SJames Wright   // ----- Apply Sub-Operator for Physics
165*9eb9c072SJames Wright   CeedCompositeOperatorAddSub(*op_apply, op_apply_bc);
166*9eb9c072SJames Wright   if (op_apply_bc_jacobian)
167*9eb9c072SJames Wright     CeedCompositeOperatorAddSub(*op_apply_ijacobian, op_apply_bc_jacobian);
168*9eb9c072SJames Wright 
169*9eb9c072SJames Wright   // ----- Cleanup
170*9eb9c072SJames Wright   CeedVectorDestroy(&q_data_sur);
171*9eb9c072SJames Wright   CeedVectorDestroy(&jac_data_sur);
172*9eb9c072SJames Wright   CeedElemRestrictionDestroy(&elem_restr_q_sur);
173*9eb9c072SJames Wright   CeedElemRestrictionDestroy(&elem_restr_x_sur);
174*9eb9c072SJames Wright   CeedElemRestrictionDestroy(&elem_restr_qd_i_sur);
175*9eb9c072SJames Wright   CeedElemRestrictionDestroy(&elem_restr_jd_i_sur);
176*9eb9c072SJames Wright   CeedOperatorDestroy(&op_setup_sur);
177*9eb9c072SJames Wright   CeedOperatorDestroy(&op_apply_bc);
178*9eb9c072SJames Wright   CeedOperatorDestroy(&op_apply_bc_jacobian);
179*9eb9c072SJames Wright 
180*9eb9c072SJames Wright   PetscFunctionReturn(0);
181*9eb9c072SJames Wright }
182*9eb9c072SJames Wright 
18377841947SLeila Ghaffari // Utility function to create CEED Composite Operator for the entire domain
18477841947SLeila Ghaffari PetscErrorCode CreateOperatorForDomain(Ceed ceed, DM dm, SimpleBC bc,
18577841947SLeila Ghaffari                                        CeedData ceed_data, Physics phys,
186e334ad8fSJed Brown                                        CeedOperator op_apply_vol,
187e334ad8fSJed Brown                                        CeedOperator op_apply_ijacobian_vol,
188e334ad8fSJed Brown                                        CeedInt height,
189e334ad8fSJed Brown                                        CeedInt P_sur, CeedInt Q_sur,
190e334ad8fSJed Brown                                        CeedInt q_data_size_sur, CeedInt jac_data_size_sur,
191e334ad8fSJed Brown                                        CeedOperator *op_apply, CeedOperator *op_apply_ijacobian) {
19277841947SLeila Ghaffari   DMLabel        domain_label;
19377841947SLeila Ghaffari   PetscErrorCode ierr;
19477841947SLeila Ghaffari   PetscFunctionBeginUser;
19577841947SLeila Ghaffari 
19677841947SLeila Ghaffari   // Create Composite Operaters
19777841947SLeila Ghaffari   CeedCompositeOperatorCreate(ceed, op_apply);
198e334ad8fSJed Brown   if (op_apply_ijacobian)
199e334ad8fSJed Brown     CeedCompositeOperatorCreate(ceed, op_apply_ijacobian);
20077841947SLeila Ghaffari 
20177841947SLeila Ghaffari   // --Apply Sub-Operator for the volume
20277841947SLeila Ghaffari   CeedCompositeOperatorAddSub(*op_apply, op_apply_vol);
203e334ad8fSJed Brown   if (op_apply_ijacobian)
204e334ad8fSJed Brown     CeedCompositeOperatorAddSub(*op_apply_ijacobian, op_apply_ijacobian_vol);
20577841947SLeila Ghaffari 
20677841947SLeila Ghaffari   // -- Create Sub-Operator for in/outflow BCs
20788626eedSJames Wright   if (phys->has_neumann || 1) {
20877841947SLeila Ghaffari     // --- Setup
20977841947SLeila Ghaffari     ierr = DMGetLabel(dm, "Face Sets", &domain_label); CHKERRQ(ierr);
21077841947SLeila Ghaffari 
2112fe7aee7SLeila Ghaffari     // --- Create Sub-Operator for inflow boundaries
2122fe7aee7SLeila Ghaffari     for (CeedInt i=0; i < bc->num_inflow; i++) {
213*9eb9c072SJames Wright       PetscCall(AddBCSubOperator(ceed, dm, ceed_data, domain_label, bc->inflows[i],
214*9eb9c072SJames Wright                                  height, Q_sur, q_data_size_sur, jac_data_size_sur,
215*9eb9c072SJames Wright                                  ceed_data->qf_apply_inflow, ceed_data->qf_apply_inflow_jacobian,
216*9eb9c072SJames Wright                                  op_apply, op_apply_ijacobian));
21777841947SLeila Ghaffari     }
21877841947SLeila Ghaffari 
2192fe7aee7SLeila Ghaffari     // --- Create Sub-Operator for outflow boundaries
2202fe7aee7SLeila Ghaffari     for (CeedInt i=0; i < bc->num_outflow; i++) {
221*9eb9c072SJames Wright       PetscCall(AddBCSubOperator(ceed, dm, ceed_data, domain_label, bc->outflows[i],
222*9eb9c072SJames Wright                                  height, Q_sur, q_data_size_sur, jac_data_size_sur,
223*9eb9c072SJames Wright                                  ceed_data->qf_apply_outflow, ceed_data->qf_apply_outflow_jacobian,
224*9eb9c072SJames Wright                                  op_apply, op_apply_ijacobian));
2252fe7aee7SLeila Ghaffari     }
2262fe7aee7SLeila Ghaffari   }
22711436a05SJames Wright 
22811436a05SJames Wright   // ----- Get Context Labels for Operator
22911436a05SJames Wright   CeedOperatorContextGetFieldLabel(*op_apply, "solution time",
23011436a05SJames Wright                                    &phys->solution_time_label);
23188626eedSJames Wright   CeedOperatorContextGetFieldLabel(*op_apply, "timestep size",
23288626eedSJames Wright                                    &phys->timestep_size_label);
23311436a05SJames Wright 
23477841947SLeila Ghaffari   PetscFunctionReturn(0);
23577841947SLeila Ghaffari }
23677841947SLeila Ghaffari 
23777841947SLeila Ghaffari PetscErrorCode SetupLibceed(Ceed ceed, CeedData ceed_data, DM dm, User user,
238c95f9967SJed Brown                             AppCtx app_ctx, ProblemData *problem, SimpleBC bc) {
23977841947SLeila Ghaffari   PetscErrorCode ierr;
24077841947SLeila Ghaffari   PetscFunctionBeginUser;
24177841947SLeila Ghaffari 
24277841947SLeila Ghaffari   // *****************************************************************************
24377841947SLeila Ghaffari   // Set up CEED objects for the interior domain (volume)
24477841947SLeila Ghaffari   // *****************************************************************************
24577841947SLeila Ghaffari   const PetscInt num_comp_q      = 5;
24677841947SLeila Ghaffari   const CeedInt  dim             = problem->dim,
24777841947SLeila Ghaffari                  num_comp_x      = problem->dim,
24877841947SLeila Ghaffari                  q_data_size_vol = problem->q_data_size_vol,
249e334ad8fSJed Brown                  jac_data_size_vol = num_comp_q + 6 + 3,
25077841947SLeila Ghaffari                  P               = app_ctx->degree + 1,
25177841947SLeila Ghaffari                  Q               = P + app_ctx->q_extra;
252a3ae0734SJed Brown   CeedElemRestriction elem_restr_jd_i;
253a3ae0734SJed Brown   CeedVector jac_data;
25477841947SLeila Ghaffari 
25577841947SLeila Ghaffari   // -----------------------------------------------------------------------------
25677841947SLeila Ghaffari   // CEED Bases
25777841947SLeila Ghaffari   // -----------------------------------------------------------------------------
25877841947SLeila Ghaffari   CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_q, P, Q, CEED_GAUSS,
25977841947SLeila Ghaffari                                   &ceed_data->basis_q);
26077841947SLeila Ghaffari   CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_x, 2, Q, CEED_GAUSS,
26177841947SLeila Ghaffari                                   &ceed_data->basis_x);
26277841947SLeila Ghaffari   CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_x, 2, P,
26377841947SLeila Ghaffari                                   CEED_GAUSS_LOBATTO, &ceed_data->basis_xc);
26477841947SLeila Ghaffari 
26577841947SLeila Ghaffari   // -----------------------------------------------------------------------------
26677841947SLeila Ghaffari   // CEED Restrictions
26777841947SLeila Ghaffari   // -----------------------------------------------------------------------------
26877841947SLeila Ghaffari   // -- Create restriction
2697ed3e4cdSJeremy L Thompson   ierr = GetRestrictionForDomain(ceed, dm, 0, 0, 0, Q, q_data_size_vol,
2707ed3e4cdSJeremy L Thompson                                  &ceed_data->elem_restr_q, &ceed_data->elem_restr_x,
27177841947SLeila Ghaffari                                  &ceed_data->elem_restr_qd_i); CHKERRQ(ierr);
272a3ae0734SJed Brown 
273a3ae0734SJed Brown   ierr = GetRestrictionForDomain(ceed, dm, 0, 0, 0, Q, jac_data_size_vol,
274a3ae0734SJed Brown                                  NULL, NULL,
275a3ae0734SJed Brown                                  &elem_restr_jd_i); CHKERRQ(ierr);
27677841947SLeila Ghaffari // -- Create E vectors
27777841947SLeila Ghaffari   CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->q_ceed, NULL);
27877841947SLeila Ghaffari   CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->q_dot_ceed,
27977841947SLeila Ghaffari                                   NULL);
28077841947SLeila Ghaffari   CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->g_ceed, NULL);
28177841947SLeila Ghaffari 
28277841947SLeila Ghaffari   // -----------------------------------------------------------------------------
28377841947SLeila Ghaffari   // CEED QFunctions
28477841947SLeila Ghaffari   // -----------------------------------------------------------------------------
28577841947SLeila Ghaffari   // -- Create QFunction for quadrature data
28691e5af17SJed Brown   CeedQFunctionCreateInterior(ceed, 1, problem->setup_vol.qfunction,
28791e5af17SJed Brown                               problem->setup_vol.qfunction_loc,
28877841947SLeila Ghaffari                               &ceed_data->qf_setup_vol);
289841e4c73SJed Brown   if (problem->setup_vol.qfunction_context) {
290841e4c73SJed Brown     CeedQFunctionSetContext(ceed_data->qf_setup_vol,
291841e4c73SJed Brown                             problem->setup_vol.qfunction_context);
292841e4c73SJed Brown     CeedQFunctionContextDestroy(&problem->setup_vol.qfunction_context);
293841e4c73SJed Brown   }
29477841947SLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_setup_vol, "dx", num_comp_x*dim,
29577841947SLeila Ghaffari                         CEED_EVAL_GRAD);
29677841947SLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_setup_vol, "weight", 1, CEED_EVAL_WEIGHT);
297a61c78d6SJeremy L Thompson   CeedQFunctionAddOutput(ceed_data->qf_setup_vol, "qdata", q_data_size_vol,
29877841947SLeila Ghaffari                          CEED_EVAL_NONE);
29977841947SLeila Ghaffari 
30077841947SLeila Ghaffari   // -- Create QFunction for ICs
30191e5af17SJed Brown   CeedQFunctionCreateInterior(ceed, 1, problem->ics.qfunction,
30291e5af17SJed Brown                               problem->ics.qfunction_loc,
30377841947SLeila Ghaffari                               &ceed_data->qf_ics);
304841e4c73SJed Brown   CeedQFunctionSetContext(ceed_data->qf_ics, problem->ics.qfunction_context);
305841e4c73SJed Brown   CeedQFunctionContextDestroy(&problem->ics.qfunction_context);
30677841947SLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_ics, "x", num_comp_x, CEED_EVAL_INTERP);
30777841947SLeila Ghaffari   CeedQFunctionAddOutput(ceed_data->qf_ics, "q0", num_comp_q, CEED_EVAL_NONE);
30877841947SLeila Ghaffari 
30977841947SLeila Ghaffari   // -- Create QFunction for RHS
31091e5af17SJed Brown   if (problem->apply_vol_rhs.qfunction) {
31191e5af17SJed Brown     CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_rhs.qfunction,
31291e5af17SJed Brown                                 problem->apply_vol_rhs.qfunction_loc, &ceed_data->qf_rhs_vol);
313841e4c73SJed Brown     CeedQFunctionSetContext(ceed_data->qf_rhs_vol,
314841e4c73SJed Brown                             problem->apply_vol_rhs.qfunction_context);
315841e4c73SJed Brown     CeedQFunctionContextDestroy(&problem->apply_vol_rhs.qfunction_context);
31677841947SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "q", num_comp_q, CEED_EVAL_INTERP);
317a3ae0734SJed Brown     CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "Grad_q", num_comp_q*dim,
31877841947SLeila Ghaffari                           CEED_EVAL_GRAD);
319a61c78d6SJeremy L Thompson     CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "qdata", q_data_size_vol,
32077841947SLeila Ghaffari                           CEED_EVAL_NONE);
32177841947SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "x", num_comp_x, CEED_EVAL_INTERP);
32277841947SLeila Ghaffari     CeedQFunctionAddOutput(ceed_data->qf_rhs_vol, "v", num_comp_q,
32377841947SLeila Ghaffari                            CEED_EVAL_INTERP);
324a3ae0734SJed Brown     CeedQFunctionAddOutput(ceed_data->qf_rhs_vol, "Grad_v", num_comp_q*dim,
32577841947SLeila Ghaffari                            CEED_EVAL_GRAD);
32677841947SLeila Ghaffari   }
32777841947SLeila Ghaffari 
32877841947SLeila Ghaffari   // -- Create QFunction for IFunction
32991e5af17SJed Brown   if (problem->apply_vol_ifunction.qfunction) {
33091e5af17SJed Brown     CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_ifunction.qfunction,
33191e5af17SJed Brown                                 problem->apply_vol_ifunction.qfunction_loc, &ceed_data->qf_ifunction_vol);
332841e4c73SJed Brown     CeedQFunctionSetContext(ceed_data->qf_ifunction_vol,
333841e4c73SJed Brown                             problem->apply_vol_ifunction.qfunction_context);
334841e4c73SJed Brown     CeedQFunctionContextDestroy(&problem->apply_vol_ifunction.qfunction_context);
33577841947SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "q", num_comp_q,
33677841947SLeila Ghaffari                           CEED_EVAL_INTERP);
337a3ae0734SJed Brown     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "Grad_q", num_comp_q*dim,
33877841947SLeila Ghaffari                           CEED_EVAL_GRAD);
339a61c78d6SJeremy L Thompson     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "q dot", num_comp_q,
34077841947SLeila Ghaffari                           CEED_EVAL_INTERP);
341a61c78d6SJeremy L Thompson     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "qdata", q_data_size_vol,
34277841947SLeila Ghaffari                           CEED_EVAL_NONE);
34377841947SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "x", num_comp_x,
34477841947SLeila Ghaffari                           CEED_EVAL_INTERP);
34577841947SLeila Ghaffari     CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "v", num_comp_q,
34677841947SLeila Ghaffari                            CEED_EVAL_INTERP);
347a3ae0734SJed Brown     CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "Grad_v", num_comp_q*dim,
34877841947SLeila Ghaffari                            CEED_EVAL_GRAD);
349a3ae0734SJed Brown     CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "jac_data",
350a3ae0734SJed Brown                            jac_data_size_vol, CEED_EVAL_NONE);
35177841947SLeila Ghaffari   }
35277841947SLeila Ghaffari 
353e334ad8fSJed Brown   CeedQFunction qf_ijacobian_vol = NULL;
354e334ad8fSJed Brown   if (problem->apply_vol_ijacobian.qfunction) {
355e334ad8fSJed Brown     CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_ijacobian.qfunction,
356e334ad8fSJed Brown                                 problem->apply_vol_ijacobian.qfunction_loc, &qf_ijacobian_vol);
357e334ad8fSJed Brown     CeedQFunctionSetContext(qf_ijacobian_vol,
358e334ad8fSJed Brown                             problem->apply_vol_ijacobian.qfunction_context);
359e334ad8fSJed Brown     CeedQFunctionContextDestroy(&problem->apply_vol_ijacobian.qfunction_context);
360e334ad8fSJed Brown     CeedQFunctionAddInput(qf_ijacobian_vol, "dq", num_comp_q,
361e334ad8fSJed Brown                           CEED_EVAL_INTERP);
362e334ad8fSJed Brown     CeedQFunctionAddInput(qf_ijacobian_vol, "Grad_dq", num_comp_q*dim,
363e334ad8fSJed Brown                           CEED_EVAL_GRAD);
364e334ad8fSJed Brown     CeedQFunctionAddInput(qf_ijacobian_vol, "qdata", q_data_size_vol,
365e334ad8fSJed Brown                           CEED_EVAL_NONE);
366e334ad8fSJed Brown     CeedQFunctionAddInput(qf_ijacobian_vol, "x", num_comp_x,
367e334ad8fSJed Brown                           CEED_EVAL_INTERP);
368e334ad8fSJed Brown     CeedQFunctionAddInput(qf_ijacobian_vol, "jac_data",
369e334ad8fSJed Brown                           jac_data_size_vol, CEED_EVAL_NONE);
370e334ad8fSJed Brown     CeedQFunctionAddOutput(qf_ijacobian_vol, "v", num_comp_q,
371e334ad8fSJed Brown                            CEED_EVAL_INTERP);
372e334ad8fSJed Brown     CeedQFunctionAddOutput(qf_ijacobian_vol, "Grad_v", num_comp_q*dim,
373e334ad8fSJed Brown                            CEED_EVAL_GRAD);
374e334ad8fSJed Brown   }
375e334ad8fSJed Brown 
37677841947SLeila Ghaffari   // ---------------------------------------------------------------------------
37777841947SLeila Ghaffari   // Element coordinates
37877841947SLeila Ghaffari   // ---------------------------------------------------------------------------
37977841947SLeila Ghaffari   // -- Create CEED vector
38077841947SLeila Ghaffari   CeedElemRestrictionCreateVector(ceed_data->elem_restr_x, &ceed_data->x_coord,
38177841947SLeila Ghaffari                                   NULL);
38277841947SLeila Ghaffari 
38377841947SLeila Ghaffari   // -- Copy PETSc vector in CEED vector
38477841947SLeila Ghaffari   Vec               X_loc;
38577841947SLeila Ghaffari   const PetscScalar *X_loc_array;
3863796c488SJed Brown   {
3873796c488SJed Brown     DM cdm;
3883796c488SJed Brown     ierr = DMGetCellCoordinateDM(dm, &cdm); CHKERRQ(ierr);
3893796c488SJed Brown     if (cdm) {ierr = DMGetCellCoordinatesLocal(dm, &X_loc); CHKERRQ(ierr);}
3903796c488SJed Brown     else {ierr = DMGetCoordinatesLocal(dm, &X_loc); CHKERRQ(ierr);}
3913796c488SJed Brown   }
3921864f1c2SLeila Ghaffari   ierr = VecScale(X_loc, problem->dm_scale); CHKERRQ(ierr);
39377841947SLeila Ghaffari   ierr = VecGetArrayRead(X_loc, &X_loc_array); CHKERRQ(ierr);
39477841947SLeila Ghaffari   CeedVectorSetArray(ceed_data->x_coord, CEED_MEM_HOST, CEED_COPY_VALUES,
39577841947SLeila Ghaffari                      (PetscScalar *)X_loc_array);
39677841947SLeila Ghaffari   ierr = VecRestoreArrayRead(X_loc, &X_loc_array); CHKERRQ(ierr);
39777841947SLeila Ghaffari 
39877841947SLeila Ghaffari   // -----------------------------------------------------------------------------
39977841947SLeila Ghaffari   // CEED vectors
40077841947SLeila Ghaffari   // -----------------------------------------------------------------------------
40177841947SLeila Ghaffari   // -- Create CEED vector for geometric data
40277841947SLeila Ghaffari   CeedInt  num_qpts_vol;
40377841947SLeila Ghaffari   PetscInt loc_num_elem_vol;
40477841947SLeila Ghaffari   CeedBasisGetNumQuadraturePoints(ceed_data->basis_q, &num_qpts_vol);
40577841947SLeila Ghaffari   CeedElemRestrictionGetNumElements(ceed_data->elem_restr_q, &loc_num_elem_vol);
40677841947SLeila Ghaffari   CeedVectorCreate(ceed, q_data_size_vol*loc_num_elem_vol*num_qpts_vol,
40777841947SLeila Ghaffari                    &ceed_data->q_data);
40877841947SLeila Ghaffari 
409a3ae0734SJed Brown   CeedElemRestrictionCreateVector(elem_restr_jd_i, &jac_data, NULL);
41077841947SLeila Ghaffari   // -----------------------------------------------------------------------------
41177841947SLeila Ghaffari   // CEED Operators
41277841947SLeila Ghaffari   // -----------------------------------------------------------------------------
41377841947SLeila Ghaffari   // -- Create CEED operator for quadrature data
41477841947SLeila Ghaffari   CeedOperatorCreate(ceed, ceed_data->qf_setup_vol, NULL, NULL,
41577841947SLeila Ghaffari                      &ceed_data->op_setup_vol);
41677841947SLeila Ghaffari   CeedOperatorSetField(ceed_data->op_setup_vol, "dx", ceed_data->elem_restr_x,
41777841947SLeila Ghaffari                        ceed_data->basis_x, CEED_VECTOR_ACTIVE);
41877841947SLeila Ghaffari   CeedOperatorSetField(ceed_data->op_setup_vol, "weight",
419e6225c47SLeila Ghaffari                        CEED_ELEMRESTRICTION_NONE, ceed_data->basis_x, CEED_VECTOR_NONE);
420a61c78d6SJeremy L Thompson   CeedOperatorSetField(ceed_data->op_setup_vol, "qdata",
421e6225c47SLeila Ghaffari                        ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE);
42277841947SLeila Ghaffari 
42377841947SLeila Ghaffari   // -- Create CEED operator for ICs
42477841947SLeila Ghaffari   CeedOperatorCreate(ceed, ceed_data->qf_ics, NULL, NULL, &ceed_data->op_ics);
42577841947SLeila Ghaffari   CeedOperatorSetField(ceed_data->op_ics, "x", ceed_data->elem_restr_x,
42677841947SLeila Ghaffari                        ceed_data->basis_xc, CEED_VECTOR_ACTIVE);
42777841947SLeila Ghaffari   CeedOperatorSetField(ceed_data->op_ics, "q0", ceed_data->elem_restr_q,
42877841947SLeila Ghaffari                        CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE);
429841e4c73SJed Brown   CeedOperatorContextGetFieldLabel(ceed_data->op_ics, "evaluation time",
430841e4c73SJed Brown                                    &user->phys->ics_time_label);
43177841947SLeila Ghaffari 
43277841947SLeila Ghaffari   // Create CEED operator for RHS
43377841947SLeila Ghaffari   if (ceed_data->qf_rhs_vol) {
43477841947SLeila Ghaffari     CeedOperator op;
43577841947SLeila Ghaffari     CeedOperatorCreate(ceed, ceed_data->qf_rhs_vol, NULL, NULL, &op);
43677841947SLeila Ghaffari     CeedOperatorSetField(op, "q", ceed_data->elem_restr_q, ceed_data->basis_q,
43777841947SLeila Ghaffari                          CEED_VECTOR_ACTIVE);
438a3ae0734SJed Brown     CeedOperatorSetField(op, "Grad_q", ceed_data->elem_restr_q, ceed_data->basis_q,
43977841947SLeila Ghaffari                          CEED_VECTOR_ACTIVE);
440a61c78d6SJeremy L Thompson     CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i,
441e6225c47SLeila Ghaffari                          CEED_BASIS_COLLOCATED, ceed_data->q_data);
44277841947SLeila Ghaffari     CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x,
44377841947SLeila Ghaffari                          ceed_data->x_coord);
44477841947SLeila Ghaffari     CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q,
44577841947SLeila Ghaffari                          CEED_VECTOR_ACTIVE);
446a3ae0734SJed Brown     CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q,
44777841947SLeila Ghaffari                          CEED_VECTOR_ACTIVE);
44877841947SLeila Ghaffari     user->op_rhs_vol = op;
44977841947SLeila Ghaffari   }
45077841947SLeila Ghaffari 
45177841947SLeila Ghaffari   // -- CEED operator for IFunction
45277841947SLeila Ghaffari   if (ceed_data->qf_ifunction_vol) {
45377841947SLeila Ghaffari     CeedOperator op;
45477841947SLeila Ghaffari     CeedOperatorCreate(ceed, ceed_data->qf_ifunction_vol, NULL, NULL, &op);
45577841947SLeila Ghaffari     CeedOperatorSetField(op, "q", ceed_data->elem_restr_q, ceed_data->basis_q,
45677841947SLeila Ghaffari                          CEED_VECTOR_ACTIVE);
457a3ae0734SJed Brown     CeedOperatorSetField(op, "Grad_q", ceed_data->elem_restr_q, ceed_data->basis_q,
45877841947SLeila Ghaffari                          CEED_VECTOR_ACTIVE);
459a61c78d6SJeremy L Thompson     CeedOperatorSetField(op, "q dot", ceed_data->elem_restr_q, ceed_data->basis_q,
46077841947SLeila Ghaffari                          user->q_dot_ceed);
461a61c78d6SJeremy L Thompson     CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i,
462e6225c47SLeila Ghaffari                          CEED_BASIS_COLLOCATED, ceed_data->q_data);
46377841947SLeila Ghaffari     CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x,
46477841947SLeila Ghaffari                          ceed_data->x_coord);
46577841947SLeila Ghaffari     CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q,
46677841947SLeila Ghaffari                          CEED_VECTOR_ACTIVE);
467a3ae0734SJed Brown     CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q,
46877841947SLeila Ghaffari                          CEED_VECTOR_ACTIVE);
469a3ae0734SJed Brown     CeedOperatorSetField(op, "jac_data", elem_restr_jd_i,
470a3ae0734SJed Brown                          CEED_BASIS_COLLOCATED, jac_data);
471a3ae0734SJed Brown 
47277841947SLeila Ghaffari     user->op_ifunction_vol = op;
47377841947SLeila Ghaffari   }
47477841947SLeila Ghaffari 
475e334ad8fSJed Brown   CeedOperator op_ijacobian_vol = NULL;
476e334ad8fSJed Brown   if (qf_ijacobian_vol) {
477e334ad8fSJed Brown     CeedOperator op;
478e334ad8fSJed Brown     CeedOperatorCreate(ceed, qf_ijacobian_vol, NULL, NULL, &op);
479e334ad8fSJed Brown     CeedOperatorSetField(op, "dq", ceed_data->elem_restr_q, ceed_data->basis_q,
480e334ad8fSJed Brown                          CEED_VECTOR_ACTIVE);
481e334ad8fSJed Brown     CeedOperatorSetField(op, "Grad_dq", ceed_data->elem_restr_q, ceed_data->basis_q,
482e334ad8fSJed Brown                          CEED_VECTOR_ACTIVE);
483e334ad8fSJed Brown     CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i,
484e334ad8fSJed Brown                          CEED_BASIS_COLLOCATED, ceed_data->q_data);
485e334ad8fSJed Brown     CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x,
486e334ad8fSJed Brown                          ceed_data->x_coord);
487e334ad8fSJed Brown     CeedOperatorSetField(op, "jac_data", elem_restr_jd_i,
488e334ad8fSJed Brown                          CEED_BASIS_COLLOCATED, jac_data);
489e334ad8fSJed Brown     CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q,
490e334ad8fSJed Brown                          CEED_VECTOR_ACTIVE);
491e334ad8fSJed Brown     CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q,
492e334ad8fSJed Brown                          CEED_VECTOR_ACTIVE);
493e334ad8fSJed Brown     op_ijacobian_vol = op;
494e334ad8fSJed Brown     CeedQFunctionDestroy(&qf_ijacobian_vol);
495e334ad8fSJed Brown   }
496e334ad8fSJed Brown 
49777841947SLeila Ghaffari   // *****************************************************************************
49877841947SLeila Ghaffari   // Set up CEED objects for the exterior domain (surface)
49977841947SLeila Ghaffari   // *****************************************************************************
50077841947SLeila Ghaffari   CeedInt height  = 1,
50177841947SLeila Ghaffari           dim_sur = dim - height,
50277841947SLeila Ghaffari           P_sur   = app_ctx->degree + 1,
50377841947SLeila Ghaffari           Q_sur   = P_sur + app_ctx->q_extra;
504e334ad8fSJed Brown   const CeedInt q_data_size_sur = problem->q_data_size_sur,
505e334ad8fSJed Brown                 jac_data_size_sur = problem->jac_data_size_sur;
50677841947SLeila Ghaffari 
50777841947SLeila Ghaffari   // -----------------------------------------------------------------------------
50877841947SLeila Ghaffari   // CEED Bases
50977841947SLeila Ghaffari   // -----------------------------------------------------------------------------
51077841947SLeila Ghaffari   CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_q, P_sur, Q_sur,
51177841947SLeila Ghaffari                                   CEED_GAUSS, &ceed_data->basis_q_sur);
51277841947SLeila Ghaffari   CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_x, 2, Q_sur, CEED_GAUSS,
51377841947SLeila Ghaffari                                   &ceed_data->basis_x_sur);
514959b8288SJames Wright   CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_x, 2, P_sur,
515959b8288SJames Wright                                   CEED_GAUSS_LOBATTO, &ceed_data->basis_xc_sur);
51677841947SLeila Ghaffari 
51777841947SLeila Ghaffari   // -----------------------------------------------------------------------------
51877841947SLeila Ghaffari   // CEED QFunctions
51977841947SLeila Ghaffari   // -----------------------------------------------------------------------------
52077841947SLeila Ghaffari   // -- Create QFunction for quadrature data
52191e5af17SJed Brown   CeedQFunctionCreateInterior(ceed, 1, problem->setup_sur.qfunction,
52291e5af17SJed Brown                               problem->setup_sur.qfunction_loc,
52377841947SLeila Ghaffari                               &ceed_data->qf_setup_sur);
524841e4c73SJed Brown   if (problem->setup_sur.qfunction_context) {
525841e4c73SJed Brown     CeedQFunctionSetContext(ceed_data->qf_setup_sur,
526841e4c73SJed Brown                             problem->setup_sur.qfunction_context);
527841e4c73SJed Brown     CeedQFunctionContextDestroy(&problem->setup_sur.qfunction_context);
528841e4c73SJed Brown   }
52977841947SLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_setup_sur, "dx", num_comp_x*dim_sur,
53077841947SLeila Ghaffari                         CEED_EVAL_GRAD);
53177841947SLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_setup_sur, "weight", 1, CEED_EVAL_WEIGHT);
532a61c78d6SJeremy L Thompson   CeedQFunctionAddOutput(ceed_data->qf_setup_sur, "surface qdata",
5332fe7aee7SLeila Ghaffari                          q_data_size_sur, CEED_EVAL_NONE);
53477841947SLeila Ghaffari 
5352fe7aee7SLeila Ghaffari   // -- Creat QFunction for inflow boundaries
53691e5af17SJed Brown   if (problem->apply_inflow.qfunction) {
53791e5af17SJed Brown     CeedQFunctionCreateInterior(ceed, 1, problem->apply_inflow.qfunction,
53891e5af17SJed Brown                                 problem->apply_inflow.qfunction_loc, &ceed_data->qf_apply_inflow);
539841e4c73SJed Brown     CeedQFunctionSetContext(ceed_data->qf_apply_inflow,
540841e4c73SJed Brown                             problem->apply_inflow.qfunction_context);
541841e4c73SJed Brown     CeedQFunctionContextDestroy(&problem->apply_inflow.qfunction_context);
5422fe7aee7SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_apply_inflow, "q", num_comp_q,
54377841947SLeila Ghaffari                           CEED_EVAL_INTERP);
544e8b03feeSJames Wright     CeedQFunctionAddInput(ceed_data->qf_apply_inflow, "Grad_q", num_comp_q*(dim-1),
545e8b03feeSJames Wright                           CEED_EVAL_GRAD);
5462fe7aee7SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_apply_inflow, "surface qdata",
5472fe7aee7SLeila Ghaffari                           q_data_size_sur, CEED_EVAL_NONE);
5482fe7aee7SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_apply_inflow, "x", num_comp_x,
54977841947SLeila Ghaffari                           CEED_EVAL_INTERP);
5502fe7aee7SLeila Ghaffari     CeedQFunctionAddOutput(ceed_data->qf_apply_inflow, "v", num_comp_q,
5512fe7aee7SLeila Ghaffari                            CEED_EVAL_INTERP);
552b55ac660SJames Wright     if (jac_data_size_sur)
553b55ac660SJames Wright       CeedQFunctionAddOutput(ceed_data->qf_apply_inflow, "surface jacobian data",
554b55ac660SJames Wright                              jac_data_size_sur,
555b55ac660SJames Wright                              CEED_EVAL_NONE);
5562fe7aee7SLeila Ghaffari   }
557e334ad8fSJed Brown   if (problem->apply_inflow_jacobian.qfunction) {
558e334ad8fSJed Brown     CeedQFunctionCreateInterior(ceed, 1, problem->apply_inflow_jacobian.qfunction,
559e334ad8fSJed Brown                                 problem->apply_inflow_jacobian.qfunction_loc,
560e334ad8fSJed Brown                                 &ceed_data->qf_apply_inflow_jacobian);
561e334ad8fSJed Brown     CeedQFunctionSetContext(ceed_data->qf_apply_inflow_jacobian,
562e334ad8fSJed Brown                             problem->apply_inflow_jacobian.qfunction_context);
563e334ad8fSJed Brown     CeedQFunctionContextDestroy(&problem->apply_inflow_jacobian.qfunction_context);
564e334ad8fSJed Brown     CeedQFunctionAddInput(ceed_data->qf_apply_inflow_jacobian, "dq", num_comp_q,
565e334ad8fSJed Brown                           CEED_EVAL_INTERP);
566b55ac660SJames Wright     CeedQFunctionAddInput(ceed_data->qf_apply_inflow_jacobian, "Grad_dq",
567b55ac660SJames Wright                           num_comp_q*dim_sur, CEED_EVAL_GRAD);
568e334ad8fSJed Brown     CeedQFunctionAddInput(ceed_data->qf_apply_inflow_jacobian, "surface qdata",
569e334ad8fSJed Brown                           q_data_size_sur, CEED_EVAL_NONE);
570e334ad8fSJed Brown     CeedQFunctionAddInput(ceed_data->qf_apply_inflow_jacobian, "x", num_comp_x,
571e334ad8fSJed Brown                           CEED_EVAL_INTERP);
572b55ac660SJames Wright     CeedQFunctionAddInput(ceed_data->qf_apply_inflow_jacobian,
573b55ac660SJames Wright                           "surface jacobian data",
574b55ac660SJames Wright                           jac_data_size_sur, CEED_EVAL_NONE);
575e334ad8fSJed Brown     CeedQFunctionAddOutput(ceed_data->qf_apply_inflow_jacobian, "v", num_comp_q,
576e334ad8fSJed Brown                            CEED_EVAL_INTERP);
577e334ad8fSJed Brown   }
5782fe7aee7SLeila Ghaffari 
5792fe7aee7SLeila Ghaffari   // -- Creat QFunction for outflow boundaries
58091e5af17SJed Brown   if (problem->apply_outflow.qfunction) {
58191e5af17SJed Brown     CeedQFunctionCreateInterior(ceed, 1, problem->apply_outflow.qfunction,
58291e5af17SJed Brown                                 problem->apply_outflow.qfunction_loc, &ceed_data->qf_apply_outflow);
583841e4c73SJed Brown     CeedQFunctionSetContext(ceed_data->qf_apply_outflow,
584841e4c73SJed Brown                             problem->apply_outflow.qfunction_context);
585841e4c73SJed Brown     CeedQFunctionContextDestroy(&problem->apply_outflow.qfunction_context);
5862fe7aee7SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_apply_outflow, "q", num_comp_q,
5872fe7aee7SLeila Ghaffari                           CEED_EVAL_INTERP);
588e8b03feeSJames Wright     CeedQFunctionAddInput(ceed_data->qf_apply_outflow, "Grad_q", num_comp_q*(dim-1),
589e8b03feeSJames Wright                           CEED_EVAL_GRAD);
5902fe7aee7SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_apply_outflow, "surface qdata",
5912fe7aee7SLeila Ghaffari                           q_data_size_sur, CEED_EVAL_NONE);
5922fe7aee7SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_apply_outflow, "x", num_comp_x,
5932fe7aee7SLeila Ghaffari                           CEED_EVAL_INTERP);
5942fe7aee7SLeila Ghaffari     CeedQFunctionAddOutput(ceed_data->qf_apply_outflow, "v", num_comp_q,
59577841947SLeila Ghaffari                            CEED_EVAL_INTERP);
59639c69132SJed Brown     if (jac_data_size_sur)
597e334ad8fSJed Brown       CeedQFunctionAddOutput(ceed_data->qf_apply_outflow, "surface jacobian data",
598e334ad8fSJed Brown                              jac_data_size_sur,
599e334ad8fSJed Brown                              CEED_EVAL_NONE);
600e334ad8fSJed Brown   }
601e334ad8fSJed Brown   if (problem->apply_outflow_jacobian.qfunction) {
602e334ad8fSJed Brown     CeedQFunctionCreateInterior(ceed, 1, problem->apply_outflow_jacobian.qfunction,
603e334ad8fSJed Brown                                 problem->apply_outflow_jacobian.qfunction_loc,
604e334ad8fSJed Brown                                 &ceed_data->qf_apply_outflow_jacobian);
605e334ad8fSJed Brown     CeedQFunctionSetContext(ceed_data->qf_apply_outflow_jacobian,
606e334ad8fSJed Brown                             problem->apply_outflow_jacobian.qfunction_context);
607e334ad8fSJed Brown     CeedQFunctionContextDestroy(&problem->apply_outflow_jacobian.qfunction_context);
608e334ad8fSJed Brown     CeedQFunctionAddInput(ceed_data->qf_apply_outflow_jacobian, "dq", num_comp_q,
609e334ad8fSJed Brown                           CEED_EVAL_INTERP);
610b55ac660SJames Wright     CeedQFunctionAddInput(ceed_data->qf_apply_outflow_jacobian, "Grad_dq",
611b55ac660SJames Wright                           num_comp_q*dim_sur, CEED_EVAL_GRAD);
612e334ad8fSJed Brown     CeedQFunctionAddInput(ceed_data->qf_apply_outflow_jacobian, "surface qdata",
613e334ad8fSJed Brown                           q_data_size_sur, CEED_EVAL_NONE);
6140ec2498eSJames Wright     CeedQFunctionAddInput(ceed_data->qf_apply_outflow_jacobian, "x", num_comp_x,
6150ec2498eSJames Wright                           CEED_EVAL_INTERP);
616e334ad8fSJed Brown     CeedQFunctionAddInput(ceed_data->qf_apply_outflow_jacobian,
617e334ad8fSJed Brown                           "surface jacobian data",
618e334ad8fSJed Brown                           jac_data_size_sur, CEED_EVAL_NONE);
619e334ad8fSJed Brown     CeedQFunctionAddOutput(ceed_data->qf_apply_outflow_jacobian, "v", num_comp_q,
620e334ad8fSJed Brown                            CEED_EVAL_INTERP);
62177841947SLeila Ghaffari   }
62277841947SLeila Ghaffari 
62377841947SLeila Ghaffari   // *****************************************************************************
62477841947SLeila Ghaffari   // CEED Operator Apply
62577841947SLeila Ghaffari   // *****************************************************************************
62677841947SLeila Ghaffari   // -- Apply CEED Operator for the geometric data
62777841947SLeila Ghaffari   CeedOperatorApply(ceed_data->op_setup_vol, ceed_data->x_coord,
62877841947SLeila Ghaffari                     ceed_data->q_data, CEED_REQUEST_IMMEDIATE);
62977841947SLeila Ghaffari 
63077841947SLeila Ghaffari   // -- Create and apply CEED Composite Operator for the entire domain
63177841947SLeila Ghaffari   if (!user->phys->implicit) { // RHS
63277841947SLeila Ghaffari     ierr = CreateOperatorForDomain(ceed, dm, bc, ceed_data, user->phys,
633e334ad8fSJed Brown                                    user->op_rhs_vol, NULL, height, P_sur, Q_sur,
634e334ad8fSJed Brown                                    q_data_size_sur, 0,
635e334ad8fSJed Brown                                    &user->op_rhs, NULL); CHKERRQ(ierr);
63677841947SLeila Ghaffari   } else { // IFunction
63777841947SLeila Ghaffari     ierr = CreateOperatorForDomain(ceed, dm, bc, ceed_data, user->phys,
638e334ad8fSJed Brown                                    user->op_ifunction_vol, op_ijacobian_vol,
639e334ad8fSJed Brown                                    height, P_sur, Q_sur,
640e334ad8fSJed Brown                                    q_data_size_sur, jac_data_size_sur,
641e334ad8fSJed Brown                                    &user->op_ifunction,
642e334ad8fSJed Brown                                    op_ijacobian_vol ? &user->op_ijacobian : NULL); CHKERRQ(ierr);
643e334ad8fSJed Brown     if (user->op_ijacobian) {
644e334ad8fSJed Brown       CeedOperatorContextGetFieldLabel(user->op_ijacobian, "ijacobian time shift",
645e334ad8fSJed Brown                                        &user->phys->ijacobian_time_shift_label);
646e334ad8fSJed Brown     }
647dada6cc0SJames Wright     if (problem->use_dirichlet_ceed) {
648dada6cc0SJames Wright       PetscCall(SetupStrongBC_Ceed(ceed, ceed_data, dm, user, app_ctx, problem, bc,
649dada6cc0SJames Wright                                    Q_sur, q_data_size_sur));
650dada6cc0SJames Wright     }
651e334ad8fSJed Brown 
65277841947SLeila Ghaffari   }
653a3ae0734SJed Brown   CeedElemRestrictionDestroy(&elem_restr_jd_i);
65422d320f5SLeila Ghaffari   CeedOperatorDestroy(&op_ijacobian_vol);
655a3ae0734SJed Brown   CeedVectorDestroy(&jac_data);
65677841947SLeila Ghaffari   PetscFunctionReturn(0);
65777841947SLeila Ghaffari }
658