xref: /honee/src/setuplibceed.c (revision df55ba5f67e466f2a56c81154f745529fc796b2e)
1727da7e7SJeremy L Thompson // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
2727da7e7SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3a515125bSLeila Ghaffari //
4727da7e7SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
5a515125bSLeila Ghaffari //
6727da7e7SJeremy L Thompson // This file is part of CEED:  http://github.com/ceed
7a515125bSLeila Ghaffari 
8a515125bSLeila Ghaffari /// @file
9a515125bSLeila Ghaffari /// Setup libCEED for Navier-Stokes example using PETSc
10a515125bSLeila Ghaffari 
11a515125bSLeila Ghaffari #include "../navierstokes.h"
12a515125bSLeila Ghaffari 
13a515125bSLeila Ghaffari // Utility function - essential BC dofs are encoded in closure indices as -(i+1).
14a515125bSLeila Ghaffari PetscInt Involute(PetscInt i) {
15a515125bSLeila Ghaffari   return i >= 0 ? i : -(i+1);
16a515125bSLeila Ghaffari }
17a515125bSLeila Ghaffari 
18a515125bSLeila Ghaffari // Utility function to create local CEED restriction
196b1ccf21SJeremy L Thompson PetscErrorCode CreateRestrictionFromPlex(Ceed ceed, DM dm, CeedInt height,
206b1ccf21SJeremy L Thompson     DMLabel domain_label, CeedInt value, CeedElemRestriction *elem_restr) {
216b1ccf21SJeremy L Thompson   PetscInt num_elem, elem_size, num_dof, num_comp, *elem_restr_offsets;
22a515125bSLeila Ghaffari   PetscErrorCode ierr;
236b1ccf21SJeremy L Thompson 
24a515125bSLeila Ghaffari   PetscFunctionBeginUser;
256b1ccf21SJeremy L Thompson   ierr = DMPlexGetLocalOffsets(dm, domain_label, value, height, 0, &num_elem,
266b1ccf21SJeremy L Thompson                                &elem_size, &num_comp, &num_dof, &elem_restr_offsets);
276b1ccf21SJeremy L Thompson   CHKERRQ(ierr);
28a515125bSLeila Ghaffari 
296b1ccf21SJeremy L Thompson   CeedElemRestrictionCreate(ceed, num_elem, elem_size, num_comp,
306b1ccf21SJeremy L Thompson                             1, num_dof, CEED_MEM_HOST, CEED_COPY_VALUES,
316b1ccf21SJeremy L Thompson                             elem_restr_offsets, elem_restr);
326b1ccf21SJeremy L Thompson   ierr = PetscFree(elem_restr_offsets); CHKERRQ(ierr);
33a515125bSLeila Ghaffari 
34a515125bSLeila Ghaffari   PetscFunctionReturn(0);
35a515125bSLeila Ghaffari }
36a515125bSLeila Ghaffari 
37a515125bSLeila Ghaffari // Utility function to get Ceed Restriction for each domain
38a515125bSLeila Ghaffari PetscErrorCode GetRestrictionForDomain(Ceed ceed, DM dm, CeedInt height,
39a515125bSLeila Ghaffari                                        DMLabel domain_label, PetscInt value,
406b1ccf21SJeremy L Thompson                                        CeedInt Q, CeedInt q_data_size,
41a515125bSLeila Ghaffari                                        CeedElemRestriction *elem_restr_q,
42a515125bSLeila Ghaffari                                        CeedElemRestriction *elem_restr_x,
43a515125bSLeila Ghaffari                                        CeedElemRestriction *elem_restr_qd_i) {
44a515125bSLeila Ghaffari   DM             dm_coord;
45a515125bSLeila Ghaffari   CeedInt        dim, loc_num_elem;
46a515125bSLeila Ghaffari   CeedInt        Q_dim;
47395c96d3SJed Brown   CeedElemRestriction elem_restr_tmp;
48a515125bSLeila Ghaffari   PetscErrorCode ierr;
49a515125bSLeila Ghaffari   PetscFunctionBeginUser;
50a515125bSLeila Ghaffari 
51a515125bSLeila Ghaffari   ierr = DMGetDimension(dm, &dim); CHKERRQ(ierr);
52a515125bSLeila Ghaffari   dim -= height;
53a515125bSLeila Ghaffari   Q_dim = CeedIntPow(Q, dim);
54395c96d3SJed Brown   ierr = CreateRestrictionFromPlex(ceed, dm, height, domain_label, value,
55395c96d3SJed Brown                                    &elem_restr_tmp);
56395c96d3SJed Brown   CHKERRQ(ierr);
57395c96d3SJed Brown   if (elem_restr_q) *elem_restr_q = elem_restr_tmp;
58395c96d3SJed Brown   if (elem_restr_x) {
59cac8aa24SJed Brown     ierr = DMGetCellCoordinateDM(dm, &dm_coord); CHKERRQ(ierr);
60cac8aa24SJed Brown     if (!dm_coord) {
61a515125bSLeila Ghaffari       ierr = DMGetCoordinateDM(dm, &dm_coord); CHKERRQ(ierr);
62cac8aa24SJed Brown     }
63a515125bSLeila Ghaffari     ierr = DMPlexSetClosurePermutationTensor(dm_coord, PETSC_DETERMINE, NULL);
64a515125bSLeila Ghaffari     CHKERRQ(ierr);
656b1ccf21SJeremy L Thompson     ierr = CreateRestrictionFromPlex(ceed, dm_coord, height, domain_label, value,
666b1ccf21SJeremy L Thompson                                      elem_restr_x);
676b1ccf21SJeremy L Thompson     CHKERRQ(ierr);
68395c96d3SJed Brown   }
69395c96d3SJed Brown   if (elem_restr_qd_i) {
70395c96d3SJed Brown     CeedElemRestrictionGetNumElements(elem_restr_tmp, &loc_num_elem);
71a515125bSLeila Ghaffari     CeedElemRestrictionCreateStrided(ceed, loc_num_elem, Q_dim,
72a515125bSLeila Ghaffari                                      q_data_size, q_data_size*loc_num_elem*Q_dim,
73a515125bSLeila Ghaffari                                      CEED_STRIDES_BACKEND, elem_restr_qd_i);
74395c96d3SJed Brown   }
75395c96d3SJed Brown   if (!elem_restr_q) CeedElemRestrictionDestroy(&elem_restr_tmp);
76a515125bSLeila Ghaffari   PetscFunctionReturn(0);
77a515125bSLeila Ghaffari }
78a515125bSLeila Ghaffari 
79368c645fSJames Wright PetscErrorCode AddBCSubOperator(Ceed ceed, DM dm, CeedData ceed_data,
80368c645fSJames Wright                                 DMLabel domain_label, PetscInt value,
81368c645fSJames Wright                                 CeedInt height, CeedInt Q_sur,
82368c645fSJames Wright                                 CeedInt q_data_size_sur, CeedInt jac_data_size_sur,
83368c645fSJames Wright                                 CeedQFunction qf_apply_bc, CeedQFunction qf_apply_bc_jacobian,
84368c645fSJames Wright                                 CeedOperator *op_apply, CeedOperator *op_apply_ijacobian) {
85368c645fSJames Wright   CeedVector          q_data_sur, jac_data_sur;
86368c645fSJames Wright   CeedOperator        op_setup_sur, op_apply_bc,
87368c645fSJames Wright                       op_apply_bc_jacobian = NULL;
88368c645fSJames Wright   CeedElemRestriction elem_restr_x_sur, elem_restr_q_sur, elem_restr_qd_i_sur,
89368c645fSJames Wright                       elem_restr_jd_i_sur;
90368c645fSJames Wright   CeedInt num_qpts_sur;
91368c645fSJames Wright   PetscFunctionBeginUser;
92368c645fSJames Wright 
93368c645fSJames Wright   // --- Get number of quadrature points for the boundaries
94368c645fSJames Wright   CeedBasisGetNumQuadraturePoints(ceed_data->basis_q_sur, &num_qpts_sur);
95368c645fSJames Wright 
96368c645fSJames Wright 
97368c645fSJames Wright   // ---- CEED Restriction
98368c645fSJames Wright   PetscCall(GetRestrictionForDomain(ceed, dm, height, domain_label, value, Q_sur,
99368c645fSJames Wright                                     q_data_size_sur, &elem_restr_q_sur, &elem_restr_x_sur, &elem_restr_qd_i_sur));
100368c645fSJames Wright   if (jac_data_size_sur > 0) {
101368c645fSJames Wright     // State-dependent data will be passed from residual to Jacobian. This will be collocated.
102368c645fSJames Wright     PetscCall(GetRestrictionForDomain(ceed, dm, height, domain_label, value, Q_sur,
103368c645fSJames Wright                                       jac_data_size_sur, NULL, NULL, &elem_restr_jd_i_sur));
104368c645fSJames Wright     CeedElemRestrictionCreateVector(elem_restr_jd_i_sur, &jac_data_sur, NULL);
105368c645fSJames Wright   } else {
106368c645fSJames Wright     elem_restr_jd_i_sur = NULL;
107368c645fSJames Wright     jac_data_sur = NULL;
108368c645fSJames Wright   }
109368c645fSJames Wright 
110368c645fSJames Wright   // ---- CEED Vector
111368c645fSJames Wright   PetscInt loc_num_elem_sur;
112368c645fSJames Wright   CeedElemRestrictionGetNumElements(elem_restr_q_sur, &loc_num_elem_sur);
113368c645fSJames Wright   CeedVectorCreate(ceed, q_data_size_sur*loc_num_elem_sur*num_qpts_sur,
114368c645fSJames Wright                    &q_data_sur);
115368c645fSJames Wright 
116368c645fSJames Wright   // ---- CEED Operator
117368c645fSJames Wright   // ----- CEED Operator for Setup (geometric factors)
118368c645fSJames Wright   CeedOperatorCreate(ceed, ceed_data->qf_setup_sur, NULL, NULL, &op_setup_sur);
119368c645fSJames Wright   CeedOperatorSetField(op_setup_sur, "dx", elem_restr_x_sur,
120368c645fSJames Wright                        ceed_data->basis_x_sur, CEED_VECTOR_ACTIVE);
121368c645fSJames Wright   CeedOperatorSetField(op_setup_sur, "weight", CEED_ELEMRESTRICTION_NONE,
122368c645fSJames Wright                        ceed_data->basis_x_sur, CEED_VECTOR_NONE);
123368c645fSJames Wright   CeedOperatorSetField(op_setup_sur, "surface qdata", elem_restr_qd_i_sur,
124368c645fSJames Wright                        CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE);
125368c645fSJames Wright 
126368c645fSJames Wright   // ----- CEED Operator for Physics
127368c645fSJames Wright   CeedOperatorCreate(ceed, qf_apply_bc, NULL, NULL, &op_apply_bc);
128368c645fSJames Wright   CeedOperatorSetField(op_apply_bc, "q", elem_restr_q_sur, ceed_data->basis_q_sur,
129368c645fSJames Wright                        CEED_VECTOR_ACTIVE);
130368c645fSJames Wright   CeedOperatorSetField(op_apply_bc, "Grad_q", elem_restr_q_sur,
131368c645fSJames Wright                        ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
132368c645fSJames Wright   CeedOperatorSetField(op_apply_bc, "surface qdata", elem_restr_qd_i_sur,
133368c645fSJames Wright                        CEED_BASIS_COLLOCATED, q_data_sur);
134368c645fSJames Wright   CeedOperatorSetField(op_apply_bc, "x", elem_restr_x_sur, ceed_data->basis_x_sur,
135368c645fSJames Wright                        ceed_data->x_coord);
136368c645fSJames Wright   CeedOperatorSetField(op_apply_bc, "v", elem_restr_q_sur, ceed_data->basis_q_sur,
137368c645fSJames Wright                        CEED_VECTOR_ACTIVE);
138368c645fSJames Wright   if (elem_restr_jd_i_sur)
139368c645fSJames Wright     CeedOperatorSetField(op_apply_bc, "surface jacobian data",
140368c645fSJames Wright                          elem_restr_jd_i_sur,
141368c645fSJames Wright                          CEED_BASIS_COLLOCATED, jac_data_sur);
142368c645fSJames Wright 
143368c645fSJames Wright   if (qf_apply_bc_jacobian) {
144368c645fSJames Wright     CeedOperatorCreate(ceed, qf_apply_bc_jacobian, NULL, NULL,
145368c645fSJames Wright                        &op_apply_bc_jacobian);
146368c645fSJames Wright     CeedOperatorSetField(op_apply_bc_jacobian, "dq", elem_restr_q_sur,
147368c645fSJames Wright                          ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
148368c645fSJames Wright     CeedOperatorSetField(op_apply_bc_jacobian, "Grad_dq", elem_restr_q_sur,
149368c645fSJames Wright                          ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
150368c645fSJames Wright     CeedOperatorSetField(op_apply_bc_jacobian, "surface qdata", elem_restr_qd_i_sur,
151368c645fSJames Wright                          CEED_BASIS_COLLOCATED, q_data_sur);
152368c645fSJames Wright     CeedOperatorSetField(op_apply_bc_jacobian, "x", elem_restr_x_sur,
153368c645fSJames Wright                          ceed_data->basis_x_sur, ceed_data->x_coord);
154368c645fSJames Wright     CeedOperatorSetField(op_apply_bc_jacobian, "surface jacobian data",
155368c645fSJames Wright                          elem_restr_jd_i_sur, CEED_BASIS_COLLOCATED, jac_data_sur);
156368c645fSJames Wright     CeedOperatorSetField(op_apply_bc_jacobian, "v", elem_restr_q_sur,
157368c645fSJames Wright                          ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
158368c645fSJames Wright   }
159368c645fSJames Wright 
160368c645fSJames Wright   // ----- Apply CEED operator for Setup
161368c645fSJames Wright   CeedOperatorApply(op_setup_sur, ceed_data->x_coord, q_data_sur,
162368c645fSJames Wright                     CEED_REQUEST_IMMEDIATE);
163368c645fSJames Wright 
164368c645fSJames Wright   // ----- Apply Sub-Operator for Physics
165368c645fSJames Wright   CeedCompositeOperatorAddSub(*op_apply, op_apply_bc);
166368c645fSJames Wright   if (op_apply_bc_jacobian)
167368c645fSJames Wright     CeedCompositeOperatorAddSub(*op_apply_ijacobian, op_apply_bc_jacobian);
168368c645fSJames Wright 
169368c645fSJames Wright   // ----- Cleanup
170368c645fSJames Wright   CeedVectorDestroy(&q_data_sur);
171368c645fSJames Wright   CeedVectorDestroy(&jac_data_sur);
172368c645fSJames Wright   CeedElemRestrictionDestroy(&elem_restr_q_sur);
173368c645fSJames Wright   CeedElemRestrictionDestroy(&elem_restr_x_sur);
174368c645fSJames Wright   CeedElemRestrictionDestroy(&elem_restr_qd_i_sur);
175368c645fSJames Wright   CeedElemRestrictionDestroy(&elem_restr_jd_i_sur);
176368c645fSJames Wright   CeedOperatorDestroy(&op_setup_sur);
177368c645fSJames Wright   CeedOperatorDestroy(&op_apply_bc);
178368c645fSJames Wright   CeedOperatorDestroy(&op_apply_bc_jacobian);
179368c645fSJames Wright 
180368c645fSJames Wright   PetscFunctionReturn(0);
181368c645fSJames Wright }
182368c645fSJames Wright 
183a515125bSLeila Ghaffari // Utility function to create CEED Composite Operator for the entire domain
184a515125bSLeila Ghaffari PetscErrorCode CreateOperatorForDomain(Ceed ceed, DM dm, SimpleBC bc,
185a515125bSLeila Ghaffari                                        CeedData ceed_data, Physics phys,
186f0b65372SJed Brown                                        CeedOperator op_apply_vol,
187f0b65372SJed Brown                                        CeedOperator op_apply_ijacobian_vol,
188f0b65372SJed Brown                                        CeedInt height,
189f0b65372SJed Brown                                        CeedInt P_sur, CeedInt Q_sur,
190f0b65372SJed Brown                                        CeedInt q_data_size_sur, CeedInt jac_data_size_sur,
191f0b65372SJed Brown                                        CeedOperator *op_apply, CeedOperator *op_apply_ijacobian) {
192a515125bSLeila Ghaffari   DMLabel        domain_label;
193a515125bSLeila Ghaffari   PetscErrorCode ierr;
194a515125bSLeila Ghaffari   PetscFunctionBeginUser;
195a515125bSLeila Ghaffari 
196a515125bSLeila Ghaffari   // Create Composite Operaters
197a515125bSLeila Ghaffari   CeedCompositeOperatorCreate(ceed, op_apply);
198f0b65372SJed Brown   if (op_apply_ijacobian)
199f0b65372SJed Brown     CeedCompositeOperatorCreate(ceed, op_apply_ijacobian);
200a515125bSLeila Ghaffari 
201a515125bSLeila Ghaffari   // --Apply Sub-Operator for the volume
202a515125bSLeila Ghaffari   CeedCompositeOperatorAddSub(*op_apply, op_apply_vol);
203f0b65372SJed Brown   if (op_apply_ijacobian)
204f0b65372SJed Brown     CeedCompositeOperatorAddSub(*op_apply_ijacobian, op_apply_ijacobian_vol);
205a515125bSLeila Ghaffari 
206a515125bSLeila Ghaffari   // -- Create Sub-Operator for in/outflow BCs
207bb8a0c61SJames Wright   if (phys->has_neumann || 1) {
208a515125bSLeila Ghaffari     // --- Setup
209a515125bSLeila Ghaffari     ierr = DMGetLabel(dm, "Face Sets", &domain_label); CHKERRQ(ierr);
210a515125bSLeila Ghaffari 
211002797a3SLeila Ghaffari     // --- Create Sub-Operator for inflow boundaries
212002797a3SLeila Ghaffari     for (CeedInt i=0; i < bc->num_inflow; i++) {
213368c645fSJames Wright       PetscCall(AddBCSubOperator(ceed, dm, ceed_data, domain_label, bc->inflows[i],
214368c645fSJames Wright                                  height, Q_sur, q_data_size_sur, jac_data_size_sur,
215368c645fSJames Wright                                  ceed_data->qf_apply_inflow, ceed_data->qf_apply_inflow_jacobian,
216368c645fSJames Wright                                  op_apply, op_apply_ijacobian));
217a515125bSLeila Ghaffari     }
218a515125bSLeila Ghaffari 
219002797a3SLeila Ghaffari     // --- Create Sub-Operator for outflow boundaries
220002797a3SLeila Ghaffari     for (CeedInt i=0; i < bc->num_outflow; i++) {
221368c645fSJames Wright       PetscCall(AddBCSubOperator(ceed, dm, ceed_data, domain_label, bc->outflows[i],
222368c645fSJames Wright                                  height, Q_sur, q_data_size_sur, jac_data_size_sur,
223368c645fSJames Wright                                  ceed_data->qf_apply_outflow, ceed_data->qf_apply_outflow_jacobian,
224368c645fSJames Wright                                  op_apply, op_apply_ijacobian));
225002797a3SLeila Ghaffari     }
226*df55ba5fSJames Wright 
227*df55ba5fSJames Wright     // --- Create Sub-Operator for freestream boundaries
228*df55ba5fSJames Wright     for (CeedInt i=0; i < bc->num_freestream; i++) {
229*df55ba5fSJames Wright       PetscCall(AddBCSubOperator(ceed, dm, ceed_data, domain_label,
230*df55ba5fSJames Wright                                  bc->freestreams[i], height, Q_sur, q_data_size_sur, jac_data_size_sur,
231*df55ba5fSJames Wright                                  ceed_data->qf_apply_freestream, ceed_data->qf_apply_freestream_jacobian,
232*df55ba5fSJames Wright                                  op_apply, op_apply_ijacobian));
233*df55ba5fSJames Wright     }
234002797a3SLeila Ghaffari   }
23592ada588SJames Wright 
23692ada588SJames Wright   // ----- Get Context Labels for Operator
23792ada588SJames Wright   CeedOperatorContextGetFieldLabel(*op_apply, "solution time",
23892ada588SJames Wright                                    &phys->solution_time_label);
239bb8a0c61SJames Wright   CeedOperatorContextGetFieldLabel(*op_apply, "timestep size",
240bb8a0c61SJames Wright                                    &phys->timestep_size_label);
24192ada588SJames Wright 
242a515125bSLeila Ghaffari   PetscFunctionReturn(0);
243a515125bSLeila Ghaffari }
244a515125bSLeila Ghaffari 
24525988f00SJames Wright PetscErrorCode SetupBCQFunctions(Ceed ceed, PetscInt dim_sur,
24625988f00SJames Wright                                  PetscInt num_comp_x, PetscInt num_comp_q,
24725988f00SJames Wright                                  PetscInt q_data_size_sur, PetscInt jac_data_size_sur,
24825988f00SJames Wright                                  ProblemQFunctionSpec apply_bc, ProblemQFunctionSpec apply_bc_jacobian,
24925988f00SJames Wright                                  CeedQFunction *qf_apply_bc, CeedQFunction *qf_apply_bc_jacobian) {
25025988f00SJames Wright   PetscFunctionBeginUser;
25125988f00SJames Wright 
25225988f00SJames Wright   if (apply_bc.qfunction) {
25325988f00SJames Wright     // *INDENT-OFF*
25425988f00SJames Wright     CeedQFunctionCreateInterior(ceed, 1, apply_bc.qfunction, apply_bc.qfunction_loc, qf_apply_bc);
25525988f00SJames Wright     CeedQFunctionSetContext(*qf_apply_bc, apply_bc.qfunction_context);
25625988f00SJames Wright     CeedQFunctionContextDestroy(&apply_bc.qfunction_context);
25725988f00SJames Wright     CeedQFunctionAddInput(*qf_apply_bc, "q", num_comp_q, CEED_EVAL_INTERP);
25825988f00SJames Wright     CeedQFunctionAddInput(*qf_apply_bc, "Grad_q", num_comp_q*dim_sur, CEED_EVAL_GRAD);
25925988f00SJames Wright     CeedQFunctionAddInput(*qf_apply_bc, "surface qdata", q_data_size_sur, CEED_EVAL_NONE);
26025988f00SJames Wright     CeedQFunctionAddInput(*qf_apply_bc, "x", num_comp_x, CEED_EVAL_INTERP);
26125988f00SJames Wright     CeedQFunctionAddOutput(*qf_apply_bc, "v", num_comp_q, CEED_EVAL_INTERP);
26225988f00SJames Wright     // *INDENT-ON*
26325988f00SJames Wright     if (jac_data_size_sur)
26425988f00SJames Wright       CeedQFunctionAddOutput(*qf_apply_bc, "surface jacobian data", jac_data_size_sur,
26525988f00SJames Wright                              CEED_EVAL_NONE);
26625988f00SJames Wright   }
26725988f00SJames Wright   if (apply_bc_jacobian.qfunction) {
26825988f00SJames Wright     // *INDENT-OFF*
26925988f00SJames Wright     CeedQFunctionCreateInterior(ceed, 1, apply_bc_jacobian.qfunction,
27025988f00SJames Wright                                 apply_bc_jacobian.qfunction_loc, qf_apply_bc_jacobian);
27125988f00SJames Wright     CeedQFunctionSetContext(*qf_apply_bc_jacobian, apply_bc_jacobian.qfunction_context);
27225988f00SJames Wright     CeedQFunctionContextDestroy(&apply_bc_jacobian.qfunction_context);
27325988f00SJames Wright     CeedQFunctionAddInput(*qf_apply_bc_jacobian, "dq", num_comp_q, CEED_EVAL_INTERP);
27425988f00SJames Wright     CeedQFunctionAddInput(*qf_apply_bc_jacobian, "Grad_dq", num_comp_q*dim_sur, CEED_EVAL_GRAD);
27525988f00SJames Wright     CeedQFunctionAddInput(*qf_apply_bc_jacobian, "surface qdata", q_data_size_sur, CEED_EVAL_NONE);
27625988f00SJames Wright     CeedQFunctionAddInput(*qf_apply_bc_jacobian, "x", num_comp_x, CEED_EVAL_INTERP);
27725988f00SJames Wright     CeedQFunctionAddInput(*qf_apply_bc_jacobian, "surface jacobian data",
27825988f00SJames Wright                           jac_data_size_sur, CEED_EVAL_NONE);
27925988f00SJames Wright     CeedQFunctionAddOutput(*qf_apply_bc_jacobian, "v", num_comp_q, CEED_EVAL_INTERP);
28025988f00SJames Wright     // *INDENT-ON*
28125988f00SJames Wright   }
28225988f00SJames Wright   PetscFunctionReturn(0);
28325988f00SJames Wright }
28425988f00SJames Wright 
285a515125bSLeila Ghaffari PetscErrorCode SetupLibceed(Ceed ceed, CeedData ceed_data, DM dm, User user,
286c848b8b7SJed Brown                             AppCtx app_ctx, ProblemData *problem, SimpleBC bc) {
287a515125bSLeila Ghaffari   PetscErrorCode ierr;
288a515125bSLeila Ghaffari   PetscFunctionBeginUser;
289a515125bSLeila Ghaffari 
290a515125bSLeila Ghaffari   // *****************************************************************************
291a515125bSLeila Ghaffari   // Set up CEED objects for the interior domain (volume)
292a515125bSLeila Ghaffari   // *****************************************************************************
293a515125bSLeila Ghaffari   const PetscInt num_comp_q      = 5;
294a515125bSLeila Ghaffari   const CeedInt  dim             = problem->dim,
295a515125bSLeila Ghaffari                  num_comp_x      = problem->dim,
296a515125bSLeila Ghaffari                  q_data_size_vol = problem->q_data_size_vol,
297f0b65372SJed Brown                  jac_data_size_vol = num_comp_q + 6 + 3,
298a515125bSLeila Ghaffari                  P               = app_ctx->degree + 1,
299a515125bSLeila Ghaffari                  Q               = P + app_ctx->q_extra;
300752f40e3SJed Brown   CeedElemRestriction elem_restr_jd_i;
301752f40e3SJed Brown   CeedVector jac_data;
302a515125bSLeila Ghaffari 
303a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
304a515125bSLeila Ghaffari   // CEED Bases
305a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
306a515125bSLeila Ghaffari   CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_q, P, Q, CEED_GAUSS,
307a515125bSLeila Ghaffari                                   &ceed_data->basis_q);
308a515125bSLeila Ghaffari   CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_x, 2, Q, CEED_GAUSS,
309a515125bSLeila Ghaffari                                   &ceed_data->basis_x);
310a515125bSLeila Ghaffari   CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_x, 2, P,
311a515125bSLeila Ghaffari                                   CEED_GAUSS_LOBATTO, &ceed_data->basis_xc);
312a515125bSLeila Ghaffari 
313a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
314a515125bSLeila Ghaffari   // CEED Restrictions
315a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
316a515125bSLeila Ghaffari   // -- Create restriction
3176b1ccf21SJeremy L Thompson   ierr = GetRestrictionForDomain(ceed, dm, 0, 0, 0, Q, q_data_size_vol,
3186b1ccf21SJeremy L Thompson                                  &ceed_data->elem_restr_q, &ceed_data->elem_restr_x,
319a515125bSLeila Ghaffari                                  &ceed_data->elem_restr_qd_i); CHKERRQ(ierr);
320752f40e3SJed Brown 
321752f40e3SJed Brown   ierr = GetRestrictionForDomain(ceed, dm, 0, 0, 0, Q, jac_data_size_vol,
322752f40e3SJed Brown                                  NULL, NULL,
323752f40e3SJed Brown                                  &elem_restr_jd_i); CHKERRQ(ierr);
324a515125bSLeila Ghaffari // -- Create E vectors
325a515125bSLeila Ghaffari   CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->q_ceed, NULL);
326a515125bSLeila Ghaffari   CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->q_dot_ceed,
327a515125bSLeila Ghaffari                                   NULL);
328a515125bSLeila Ghaffari   CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->g_ceed, NULL);
329a515125bSLeila Ghaffari 
330a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
331a515125bSLeila Ghaffari   // CEED QFunctions
332a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
333a515125bSLeila Ghaffari   // -- Create QFunction for quadrature data
3349785fe93SJed Brown   CeedQFunctionCreateInterior(ceed, 1, problem->setup_vol.qfunction,
3359785fe93SJed Brown                               problem->setup_vol.qfunction_loc,
336a515125bSLeila Ghaffari                               &ceed_data->qf_setup_vol);
33715a3537eSJed Brown   if (problem->setup_vol.qfunction_context) {
33815a3537eSJed Brown     CeedQFunctionSetContext(ceed_data->qf_setup_vol,
33915a3537eSJed Brown                             problem->setup_vol.qfunction_context);
34015a3537eSJed Brown     CeedQFunctionContextDestroy(&problem->setup_vol.qfunction_context);
34115a3537eSJed Brown   }
342a515125bSLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_setup_vol, "dx", num_comp_x*dim,
343a515125bSLeila Ghaffari                         CEED_EVAL_GRAD);
344a515125bSLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_setup_vol, "weight", 1, CEED_EVAL_WEIGHT);
3453b1e209bSJeremy L Thompson   CeedQFunctionAddOutput(ceed_data->qf_setup_vol, "qdata", q_data_size_vol,
346a515125bSLeila Ghaffari                          CEED_EVAL_NONE);
347a515125bSLeila Ghaffari 
348a515125bSLeila Ghaffari   // -- Create QFunction for ICs
3499785fe93SJed Brown   CeedQFunctionCreateInterior(ceed, 1, problem->ics.qfunction,
3509785fe93SJed Brown                               problem->ics.qfunction_loc,
351a515125bSLeila Ghaffari                               &ceed_data->qf_ics);
35215a3537eSJed Brown   CeedQFunctionSetContext(ceed_data->qf_ics, problem->ics.qfunction_context);
35315a3537eSJed Brown   CeedQFunctionContextDestroy(&problem->ics.qfunction_context);
354a515125bSLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_ics, "x", num_comp_x, CEED_EVAL_INTERP);
355a515125bSLeila Ghaffari   CeedQFunctionAddOutput(ceed_data->qf_ics, "q0", num_comp_q, CEED_EVAL_NONE);
356a515125bSLeila Ghaffari 
357a515125bSLeila Ghaffari   // -- Create QFunction for RHS
3589785fe93SJed Brown   if (problem->apply_vol_rhs.qfunction) {
3599785fe93SJed Brown     CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_rhs.qfunction,
3609785fe93SJed Brown                                 problem->apply_vol_rhs.qfunction_loc, &ceed_data->qf_rhs_vol);
36115a3537eSJed Brown     CeedQFunctionSetContext(ceed_data->qf_rhs_vol,
36215a3537eSJed Brown                             problem->apply_vol_rhs.qfunction_context);
36315a3537eSJed Brown     CeedQFunctionContextDestroy(&problem->apply_vol_rhs.qfunction_context);
364a515125bSLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "q", num_comp_q, CEED_EVAL_INTERP);
365752f40e3SJed Brown     CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "Grad_q", num_comp_q*dim,
366a515125bSLeila Ghaffari                           CEED_EVAL_GRAD);
3673b1e209bSJeremy L Thompson     CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "qdata", q_data_size_vol,
368a515125bSLeila Ghaffari                           CEED_EVAL_NONE);
369a515125bSLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "x", num_comp_x, CEED_EVAL_INTERP);
370a515125bSLeila Ghaffari     CeedQFunctionAddOutput(ceed_data->qf_rhs_vol, "v", num_comp_q,
371a515125bSLeila Ghaffari                            CEED_EVAL_INTERP);
372752f40e3SJed Brown     CeedQFunctionAddOutput(ceed_data->qf_rhs_vol, "Grad_v", num_comp_q*dim,
373a515125bSLeila Ghaffari                            CEED_EVAL_GRAD);
374a515125bSLeila Ghaffari   }
375a515125bSLeila Ghaffari 
376a515125bSLeila Ghaffari   // -- Create QFunction for IFunction
3779785fe93SJed Brown   if (problem->apply_vol_ifunction.qfunction) {
3789785fe93SJed Brown     CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_ifunction.qfunction,
3799785fe93SJed Brown                                 problem->apply_vol_ifunction.qfunction_loc, &ceed_data->qf_ifunction_vol);
38015a3537eSJed Brown     CeedQFunctionSetContext(ceed_data->qf_ifunction_vol,
38115a3537eSJed Brown                             problem->apply_vol_ifunction.qfunction_context);
38215a3537eSJed Brown     CeedQFunctionContextDestroy(&problem->apply_vol_ifunction.qfunction_context);
383a515125bSLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "q", num_comp_q,
384a515125bSLeila Ghaffari                           CEED_EVAL_INTERP);
385752f40e3SJed Brown     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "Grad_q", num_comp_q*dim,
386a515125bSLeila Ghaffari                           CEED_EVAL_GRAD);
3873b1e209bSJeremy L Thompson     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "q dot", num_comp_q,
388a515125bSLeila Ghaffari                           CEED_EVAL_INTERP);
3893b1e209bSJeremy L Thompson     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "qdata", q_data_size_vol,
390a515125bSLeila Ghaffari                           CEED_EVAL_NONE);
391a515125bSLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "x", num_comp_x,
392a515125bSLeila Ghaffari                           CEED_EVAL_INTERP);
393a515125bSLeila Ghaffari     CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "v", num_comp_q,
394a515125bSLeila Ghaffari                            CEED_EVAL_INTERP);
395752f40e3SJed Brown     CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "Grad_v", num_comp_q*dim,
396a515125bSLeila Ghaffari                            CEED_EVAL_GRAD);
397752f40e3SJed Brown     CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "jac_data",
398752f40e3SJed Brown                            jac_data_size_vol, CEED_EVAL_NONE);
399a515125bSLeila Ghaffari   }
400a515125bSLeila Ghaffari 
401f0b65372SJed Brown   CeedQFunction qf_ijacobian_vol = NULL;
402f0b65372SJed Brown   if (problem->apply_vol_ijacobian.qfunction) {
403f0b65372SJed Brown     CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_ijacobian.qfunction,
404f0b65372SJed Brown                                 problem->apply_vol_ijacobian.qfunction_loc, &qf_ijacobian_vol);
405f0b65372SJed Brown     CeedQFunctionSetContext(qf_ijacobian_vol,
406f0b65372SJed Brown                             problem->apply_vol_ijacobian.qfunction_context);
407f0b65372SJed Brown     CeedQFunctionContextDestroy(&problem->apply_vol_ijacobian.qfunction_context);
408f0b65372SJed Brown     CeedQFunctionAddInput(qf_ijacobian_vol, "dq", num_comp_q,
409f0b65372SJed Brown                           CEED_EVAL_INTERP);
410f0b65372SJed Brown     CeedQFunctionAddInput(qf_ijacobian_vol, "Grad_dq", num_comp_q*dim,
411f0b65372SJed Brown                           CEED_EVAL_GRAD);
412f0b65372SJed Brown     CeedQFunctionAddInput(qf_ijacobian_vol, "qdata", q_data_size_vol,
413f0b65372SJed Brown                           CEED_EVAL_NONE);
414f0b65372SJed Brown     CeedQFunctionAddInput(qf_ijacobian_vol, "x", num_comp_x,
415f0b65372SJed Brown                           CEED_EVAL_INTERP);
416f0b65372SJed Brown     CeedQFunctionAddInput(qf_ijacobian_vol, "jac_data",
417f0b65372SJed Brown                           jac_data_size_vol, CEED_EVAL_NONE);
418f0b65372SJed Brown     CeedQFunctionAddOutput(qf_ijacobian_vol, "v", num_comp_q,
419f0b65372SJed Brown                            CEED_EVAL_INTERP);
420f0b65372SJed Brown     CeedQFunctionAddOutput(qf_ijacobian_vol, "Grad_v", num_comp_q*dim,
421f0b65372SJed Brown                            CEED_EVAL_GRAD);
422f0b65372SJed Brown   }
423f0b65372SJed Brown 
424a515125bSLeila Ghaffari   // ---------------------------------------------------------------------------
425a515125bSLeila Ghaffari   // Element coordinates
426a515125bSLeila Ghaffari   // ---------------------------------------------------------------------------
427a515125bSLeila Ghaffari   // -- Create CEED vector
428a515125bSLeila Ghaffari   CeedElemRestrictionCreateVector(ceed_data->elem_restr_x, &ceed_data->x_coord,
429a515125bSLeila Ghaffari                                   NULL);
430a515125bSLeila Ghaffari 
431a515125bSLeila Ghaffari   // -- Copy PETSc vector in CEED vector
432a515125bSLeila Ghaffari   Vec               X_loc;
433a515125bSLeila Ghaffari   const PetscScalar *X_loc_array;
434cac8aa24SJed Brown   {
435cac8aa24SJed Brown     DM cdm;
436cac8aa24SJed Brown     ierr = DMGetCellCoordinateDM(dm, &cdm); CHKERRQ(ierr);
437cac8aa24SJed Brown     if (cdm) {ierr = DMGetCellCoordinatesLocal(dm, &X_loc); CHKERRQ(ierr);}
438cac8aa24SJed Brown     else {ierr = DMGetCoordinatesLocal(dm, &X_loc); CHKERRQ(ierr);}
439cac8aa24SJed Brown   }
44005a512bdSLeila Ghaffari   ierr = VecScale(X_loc, problem->dm_scale); CHKERRQ(ierr);
441a515125bSLeila Ghaffari   ierr = VecGetArrayRead(X_loc, &X_loc_array); CHKERRQ(ierr);
442a515125bSLeila Ghaffari   CeedVectorSetArray(ceed_data->x_coord, CEED_MEM_HOST, CEED_COPY_VALUES,
443a515125bSLeila Ghaffari                      (PetscScalar *)X_loc_array);
444a515125bSLeila Ghaffari   ierr = VecRestoreArrayRead(X_loc, &X_loc_array); CHKERRQ(ierr);
445a515125bSLeila Ghaffari 
446a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
447a515125bSLeila Ghaffari   // CEED vectors
448a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
449a515125bSLeila Ghaffari   // -- Create CEED vector for geometric data
450a515125bSLeila Ghaffari   CeedInt  num_qpts_vol;
451a515125bSLeila Ghaffari   PetscInt loc_num_elem_vol;
452a515125bSLeila Ghaffari   CeedBasisGetNumQuadraturePoints(ceed_data->basis_q, &num_qpts_vol);
453a515125bSLeila Ghaffari   CeedElemRestrictionGetNumElements(ceed_data->elem_restr_q, &loc_num_elem_vol);
454a515125bSLeila Ghaffari   CeedVectorCreate(ceed, q_data_size_vol*loc_num_elem_vol*num_qpts_vol,
455a515125bSLeila Ghaffari                    &ceed_data->q_data);
456a515125bSLeila Ghaffari 
457752f40e3SJed Brown   CeedElemRestrictionCreateVector(elem_restr_jd_i, &jac_data, NULL);
458a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
459a515125bSLeila Ghaffari   // CEED Operators
460a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
461a515125bSLeila Ghaffari   // -- Create CEED operator for quadrature data
462a515125bSLeila Ghaffari   CeedOperatorCreate(ceed, ceed_data->qf_setup_vol, NULL, NULL,
463a515125bSLeila Ghaffari                      &ceed_data->op_setup_vol);
464a515125bSLeila Ghaffari   CeedOperatorSetField(ceed_data->op_setup_vol, "dx", ceed_data->elem_restr_x,
465a515125bSLeila Ghaffari                        ceed_data->basis_x, CEED_VECTOR_ACTIVE);
466a515125bSLeila Ghaffari   CeedOperatorSetField(ceed_data->op_setup_vol, "weight",
467139613f2SLeila Ghaffari                        CEED_ELEMRESTRICTION_NONE, ceed_data->basis_x, CEED_VECTOR_NONE);
4683b1e209bSJeremy L Thompson   CeedOperatorSetField(ceed_data->op_setup_vol, "qdata",
469139613f2SLeila Ghaffari                        ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE);
470a515125bSLeila Ghaffari 
471a515125bSLeila Ghaffari   // -- Create CEED operator for ICs
472a515125bSLeila Ghaffari   CeedOperatorCreate(ceed, ceed_data->qf_ics, NULL, NULL, &ceed_data->op_ics);
473a515125bSLeila Ghaffari   CeedOperatorSetField(ceed_data->op_ics, "x", ceed_data->elem_restr_x,
474a515125bSLeila Ghaffari                        ceed_data->basis_xc, CEED_VECTOR_ACTIVE);
475a515125bSLeila Ghaffari   CeedOperatorSetField(ceed_data->op_ics, "q0", ceed_data->elem_restr_q,
476a515125bSLeila Ghaffari                        CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE);
47715a3537eSJed Brown   CeedOperatorContextGetFieldLabel(ceed_data->op_ics, "evaluation time",
47815a3537eSJed Brown                                    &user->phys->ics_time_label);
479a515125bSLeila Ghaffari 
480a515125bSLeila Ghaffari   // Create CEED operator for RHS
481a515125bSLeila Ghaffari   if (ceed_data->qf_rhs_vol) {
482a515125bSLeila Ghaffari     CeedOperator op;
483a515125bSLeila Ghaffari     CeedOperatorCreate(ceed, ceed_data->qf_rhs_vol, NULL, NULL, &op);
484a515125bSLeila Ghaffari     CeedOperatorSetField(op, "q", ceed_data->elem_restr_q, ceed_data->basis_q,
485a515125bSLeila Ghaffari                          CEED_VECTOR_ACTIVE);
486752f40e3SJed Brown     CeedOperatorSetField(op, "Grad_q", ceed_data->elem_restr_q, ceed_data->basis_q,
487a515125bSLeila Ghaffari                          CEED_VECTOR_ACTIVE);
4883b1e209bSJeremy L Thompson     CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i,
489139613f2SLeila Ghaffari                          CEED_BASIS_COLLOCATED, ceed_data->q_data);
490a515125bSLeila Ghaffari     CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x,
491a515125bSLeila Ghaffari                          ceed_data->x_coord);
492a515125bSLeila Ghaffari     CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q,
493a515125bSLeila Ghaffari                          CEED_VECTOR_ACTIVE);
494752f40e3SJed Brown     CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q,
495a515125bSLeila Ghaffari                          CEED_VECTOR_ACTIVE);
496a515125bSLeila Ghaffari     user->op_rhs_vol = op;
497a515125bSLeila Ghaffari   }
498a515125bSLeila Ghaffari 
499a515125bSLeila Ghaffari   // -- CEED operator for IFunction
500a515125bSLeila Ghaffari   if (ceed_data->qf_ifunction_vol) {
501a515125bSLeila Ghaffari     CeedOperator op;
502a515125bSLeila Ghaffari     CeedOperatorCreate(ceed, ceed_data->qf_ifunction_vol, NULL, NULL, &op);
503a515125bSLeila Ghaffari     CeedOperatorSetField(op, "q", ceed_data->elem_restr_q, ceed_data->basis_q,
504a515125bSLeila Ghaffari                          CEED_VECTOR_ACTIVE);
505752f40e3SJed Brown     CeedOperatorSetField(op, "Grad_q", ceed_data->elem_restr_q, ceed_data->basis_q,
506a515125bSLeila Ghaffari                          CEED_VECTOR_ACTIVE);
5073b1e209bSJeremy L Thompson     CeedOperatorSetField(op, "q dot", ceed_data->elem_restr_q, ceed_data->basis_q,
508a515125bSLeila Ghaffari                          user->q_dot_ceed);
5093b1e209bSJeremy L Thompson     CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i,
510139613f2SLeila Ghaffari                          CEED_BASIS_COLLOCATED, ceed_data->q_data);
511a515125bSLeila Ghaffari     CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x,
512a515125bSLeila Ghaffari                          ceed_data->x_coord);
513a515125bSLeila Ghaffari     CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q,
514a515125bSLeila Ghaffari                          CEED_VECTOR_ACTIVE);
515752f40e3SJed Brown     CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q,
516a515125bSLeila Ghaffari                          CEED_VECTOR_ACTIVE);
517752f40e3SJed Brown     CeedOperatorSetField(op, "jac_data", elem_restr_jd_i,
518752f40e3SJed Brown                          CEED_BASIS_COLLOCATED, jac_data);
519752f40e3SJed Brown 
520a515125bSLeila Ghaffari     user->op_ifunction_vol = op;
521a515125bSLeila Ghaffari   }
522a515125bSLeila Ghaffari 
523f0b65372SJed Brown   CeedOperator op_ijacobian_vol = NULL;
524f0b65372SJed Brown   if (qf_ijacobian_vol) {
525f0b65372SJed Brown     CeedOperator op;
526f0b65372SJed Brown     CeedOperatorCreate(ceed, qf_ijacobian_vol, NULL, NULL, &op);
527f0b65372SJed Brown     CeedOperatorSetField(op, "dq", ceed_data->elem_restr_q, ceed_data->basis_q,
528f0b65372SJed Brown                          CEED_VECTOR_ACTIVE);
529f0b65372SJed Brown     CeedOperatorSetField(op, "Grad_dq", ceed_data->elem_restr_q, ceed_data->basis_q,
530f0b65372SJed Brown                          CEED_VECTOR_ACTIVE);
531f0b65372SJed Brown     CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i,
532f0b65372SJed Brown                          CEED_BASIS_COLLOCATED, ceed_data->q_data);
533f0b65372SJed Brown     CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x,
534f0b65372SJed Brown                          ceed_data->x_coord);
535f0b65372SJed Brown     CeedOperatorSetField(op, "jac_data", elem_restr_jd_i,
536f0b65372SJed Brown                          CEED_BASIS_COLLOCATED, jac_data);
537f0b65372SJed Brown     CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q,
538f0b65372SJed Brown                          CEED_VECTOR_ACTIVE);
539f0b65372SJed Brown     CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q,
540f0b65372SJed Brown                          CEED_VECTOR_ACTIVE);
541f0b65372SJed Brown     op_ijacobian_vol = op;
542f0b65372SJed Brown     CeedQFunctionDestroy(&qf_ijacobian_vol);
543f0b65372SJed Brown   }
544f0b65372SJed Brown 
545a515125bSLeila Ghaffari   // *****************************************************************************
546a515125bSLeila Ghaffari   // Set up CEED objects for the exterior domain (surface)
547a515125bSLeila Ghaffari   // *****************************************************************************
548a515125bSLeila Ghaffari   CeedInt height  = 1,
549a515125bSLeila Ghaffari           dim_sur = dim - height,
550a515125bSLeila Ghaffari           P_sur   = app_ctx->degree + 1,
551a515125bSLeila Ghaffari           Q_sur   = P_sur + app_ctx->q_extra;
552f0b65372SJed Brown   const CeedInt q_data_size_sur = problem->q_data_size_sur,
553f0b65372SJed Brown                 jac_data_size_sur = problem->jac_data_size_sur;
554a515125bSLeila Ghaffari 
555a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
556a515125bSLeila Ghaffari   // CEED Bases
557a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
558a515125bSLeila Ghaffari   CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_q, P_sur, Q_sur,
559a515125bSLeila Ghaffari                                   CEED_GAUSS, &ceed_data->basis_q_sur);
560a515125bSLeila Ghaffari   CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_x, 2, Q_sur, CEED_GAUSS,
561a515125bSLeila Ghaffari                                   &ceed_data->basis_x_sur);
562da7e3aacSJames Wright   CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_x, 2, P_sur,
563da7e3aacSJames Wright                                   CEED_GAUSS_LOBATTO, &ceed_data->basis_xc_sur);
564a515125bSLeila Ghaffari 
565a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
566a515125bSLeila Ghaffari   // CEED QFunctions
567a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
568a515125bSLeila Ghaffari   // -- Create QFunction for quadrature data
5699785fe93SJed Brown   CeedQFunctionCreateInterior(ceed, 1, problem->setup_sur.qfunction,
5709785fe93SJed Brown                               problem->setup_sur.qfunction_loc,
571a515125bSLeila Ghaffari                               &ceed_data->qf_setup_sur);
57215a3537eSJed Brown   if (problem->setup_sur.qfunction_context) {
57315a3537eSJed Brown     CeedQFunctionSetContext(ceed_data->qf_setup_sur,
57415a3537eSJed Brown                             problem->setup_sur.qfunction_context);
57515a3537eSJed Brown     CeedQFunctionContextDestroy(&problem->setup_sur.qfunction_context);
57615a3537eSJed Brown   }
577a515125bSLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_setup_sur, "dx", num_comp_x*dim_sur,
578a515125bSLeila Ghaffari                         CEED_EVAL_GRAD);
579a515125bSLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_setup_sur, "weight", 1, CEED_EVAL_WEIGHT);
5803b1e209bSJeremy L Thompson   CeedQFunctionAddOutput(ceed_data->qf_setup_sur, "surface qdata",
581002797a3SLeila Ghaffari                          q_data_size_sur, CEED_EVAL_NONE);
582a515125bSLeila Ghaffari 
58325988f00SJames Wright   PetscCall(SetupBCQFunctions(ceed, dim_sur, num_comp_x, num_comp_q,
58425988f00SJames Wright                               q_data_size_sur, jac_data_size_sur,
58525988f00SJames Wright                               problem->apply_inflow, problem->apply_inflow_jacobian,
58625988f00SJames Wright                               &ceed_data->qf_apply_inflow, &ceed_data->qf_apply_inflow_jacobian));
587002797a3SLeila Ghaffari 
58825988f00SJames Wright   PetscCall(SetupBCQFunctions(ceed, dim_sur, num_comp_x, num_comp_q,
58925988f00SJames Wright                               q_data_size_sur, jac_data_size_sur,
59025988f00SJames Wright                               problem->apply_outflow, problem->apply_outflow_jacobian,
59125988f00SJames Wright                               &ceed_data->qf_apply_outflow, &ceed_data->qf_apply_outflow_jacobian));
592a515125bSLeila Ghaffari 
593*df55ba5fSJames Wright   PetscCall(SetupBCQFunctions(ceed, dim_sur, num_comp_x, num_comp_q,
594*df55ba5fSJames Wright                               q_data_size_sur, jac_data_size_sur,
595*df55ba5fSJames Wright                               problem->apply_freestream, problem->apply_freestream_jacobian,
596*df55ba5fSJames Wright                               &ceed_data->qf_apply_freestream, &ceed_data->qf_apply_freestream_jacobian));
597*df55ba5fSJames Wright 
598a515125bSLeila Ghaffari   // *****************************************************************************
599a515125bSLeila Ghaffari   // CEED Operator Apply
600a515125bSLeila Ghaffari   // *****************************************************************************
601a515125bSLeila Ghaffari   // -- Apply CEED Operator for the geometric data
602a515125bSLeila Ghaffari   CeedOperatorApply(ceed_data->op_setup_vol, ceed_data->x_coord,
603a515125bSLeila Ghaffari                     ceed_data->q_data, CEED_REQUEST_IMMEDIATE);
604a515125bSLeila Ghaffari 
605a515125bSLeila Ghaffari   // -- Create and apply CEED Composite Operator for the entire domain
606a515125bSLeila Ghaffari   if (!user->phys->implicit) { // RHS
607a515125bSLeila Ghaffari     ierr = CreateOperatorForDomain(ceed, dm, bc, ceed_data, user->phys,
608f0b65372SJed Brown                                    user->op_rhs_vol, NULL, height, P_sur, Q_sur,
609f0b65372SJed Brown                                    q_data_size_sur, 0,
610f0b65372SJed Brown                                    &user->op_rhs, NULL); CHKERRQ(ierr);
611a515125bSLeila Ghaffari   } else { // IFunction
612a515125bSLeila Ghaffari     ierr = CreateOperatorForDomain(ceed, dm, bc, ceed_data, user->phys,
613f0b65372SJed Brown                                    user->op_ifunction_vol, op_ijacobian_vol,
614f0b65372SJed Brown                                    height, P_sur, Q_sur,
615f0b65372SJed Brown                                    q_data_size_sur, jac_data_size_sur,
616f0b65372SJed Brown                                    &user->op_ifunction,
617f0b65372SJed Brown                                    op_ijacobian_vol ? &user->op_ijacobian : NULL); CHKERRQ(ierr);
618f0b65372SJed Brown     if (user->op_ijacobian) {
619f0b65372SJed Brown       CeedOperatorContextGetFieldLabel(user->op_ijacobian, "ijacobian time shift",
620f0b65372SJed Brown                                        &user->phys->ijacobian_time_shift_label);
621f0b65372SJed Brown     }
6226d0190e2SJames Wright     if (problem->use_dirichlet_ceed) {
6236d0190e2SJames Wright       PetscCall(SetupStrongBC_Ceed(ceed, ceed_data, dm, user, app_ctx, problem, bc,
6246d0190e2SJames Wright                                    Q_sur, q_data_size_sur));
6256d0190e2SJames Wright     }
626f0b65372SJed Brown 
627a515125bSLeila Ghaffari   }
628752f40e3SJed Brown   CeedElemRestrictionDestroy(&elem_restr_jd_i);
629e22e0f1cSLeila Ghaffari   CeedOperatorDestroy(&op_ijacobian_vol);
630752f40e3SJed Brown   CeedVectorDestroy(&jac_data);
631a515125bSLeila Ghaffari   PetscFunctionReturn(0);
632a515125bSLeila Ghaffari }
633