xref: /honee/src/setuplibceed.c (revision 368c645f6b629b3130bfcb4463abc79d3cf84246)
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 
79*368c645fSJames Wright PetscErrorCode AddBCSubOperator(Ceed ceed, DM dm, CeedData ceed_data,
80*368c645fSJames Wright                                 DMLabel domain_label, PetscInt value,
81*368c645fSJames Wright                                 CeedInt height, CeedInt Q_sur,
82*368c645fSJames Wright                                 CeedInt q_data_size_sur, CeedInt jac_data_size_sur,
83*368c645fSJames Wright                                 CeedQFunction qf_apply_bc, CeedQFunction qf_apply_bc_jacobian,
84*368c645fSJames Wright                                 CeedOperator *op_apply, CeedOperator *op_apply_ijacobian) {
85*368c645fSJames Wright   CeedVector          q_data_sur, jac_data_sur;
86*368c645fSJames Wright   CeedOperator        op_setup_sur, op_apply_bc,
87*368c645fSJames Wright                       op_apply_bc_jacobian = NULL;
88*368c645fSJames Wright   CeedElemRestriction elem_restr_x_sur, elem_restr_q_sur, elem_restr_qd_i_sur,
89*368c645fSJames Wright                       elem_restr_jd_i_sur;
90*368c645fSJames Wright   CeedInt num_qpts_sur;
91*368c645fSJames Wright   PetscFunctionBeginUser;
92*368c645fSJames Wright 
93*368c645fSJames Wright   // --- Get number of quadrature points for the boundaries
94*368c645fSJames Wright   CeedBasisGetNumQuadraturePoints(ceed_data->basis_q_sur, &num_qpts_sur);
95*368c645fSJames Wright 
96*368c645fSJames Wright 
97*368c645fSJames Wright   // ---- CEED Restriction
98*368c645fSJames Wright   PetscCall(GetRestrictionForDomain(ceed, dm, height, domain_label, value, Q_sur,
99*368c645fSJames Wright                                     q_data_size_sur, &elem_restr_q_sur, &elem_restr_x_sur, &elem_restr_qd_i_sur));
100*368c645fSJames Wright   if (jac_data_size_sur > 0) {
101*368c645fSJames Wright     // State-dependent data will be passed from residual to Jacobian. This will be collocated.
102*368c645fSJames Wright     PetscCall(GetRestrictionForDomain(ceed, dm, height, domain_label, value, Q_sur,
103*368c645fSJames Wright                                       jac_data_size_sur, NULL, NULL, &elem_restr_jd_i_sur));
104*368c645fSJames Wright     CeedElemRestrictionCreateVector(elem_restr_jd_i_sur, &jac_data_sur, NULL);
105*368c645fSJames Wright   } else {
106*368c645fSJames Wright     elem_restr_jd_i_sur = NULL;
107*368c645fSJames Wright     jac_data_sur = NULL;
108*368c645fSJames Wright   }
109*368c645fSJames Wright 
110*368c645fSJames Wright   // ---- CEED Vector
111*368c645fSJames Wright   PetscInt loc_num_elem_sur;
112*368c645fSJames Wright   CeedElemRestrictionGetNumElements(elem_restr_q_sur, &loc_num_elem_sur);
113*368c645fSJames Wright   CeedVectorCreate(ceed, q_data_size_sur*loc_num_elem_sur*num_qpts_sur,
114*368c645fSJames Wright                    &q_data_sur);
115*368c645fSJames Wright 
116*368c645fSJames Wright   // ---- CEED Operator
117*368c645fSJames Wright   // ----- CEED Operator for Setup (geometric factors)
118*368c645fSJames Wright   CeedOperatorCreate(ceed, ceed_data->qf_setup_sur, NULL, NULL, &op_setup_sur);
119*368c645fSJames Wright   CeedOperatorSetField(op_setup_sur, "dx", elem_restr_x_sur,
120*368c645fSJames Wright                        ceed_data->basis_x_sur, CEED_VECTOR_ACTIVE);
121*368c645fSJames Wright   CeedOperatorSetField(op_setup_sur, "weight", CEED_ELEMRESTRICTION_NONE,
122*368c645fSJames Wright                        ceed_data->basis_x_sur, CEED_VECTOR_NONE);
123*368c645fSJames Wright   CeedOperatorSetField(op_setup_sur, "surface qdata", elem_restr_qd_i_sur,
124*368c645fSJames Wright                        CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE);
125*368c645fSJames Wright 
126*368c645fSJames Wright   // ----- CEED Operator for Physics
127*368c645fSJames Wright   CeedOperatorCreate(ceed, qf_apply_bc, NULL, NULL, &op_apply_bc);
128*368c645fSJames Wright   CeedOperatorSetField(op_apply_bc, "q", elem_restr_q_sur, ceed_data->basis_q_sur,
129*368c645fSJames Wright                        CEED_VECTOR_ACTIVE);
130*368c645fSJames Wright   CeedOperatorSetField(op_apply_bc, "Grad_q", elem_restr_q_sur,
131*368c645fSJames Wright                        ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
132*368c645fSJames Wright   CeedOperatorSetField(op_apply_bc, "surface qdata", elem_restr_qd_i_sur,
133*368c645fSJames Wright                        CEED_BASIS_COLLOCATED, q_data_sur);
134*368c645fSJames Wright   CeedOperatorSetField(op_apply_bc, "x", elem_restr_x_sur, ceed_data->basis_x_sur,
135*368c645fSJames Wright                        ceed_data->x_coord);
136*368c645fSJames Wright   CeedOperatorSetField(op_apply_bc, "v", elem_restr_q_sur, ceed_data->basis_q_sur,
137*368c645fSJames Wright                        CEED_VECTOR_ACTIVE);
138*368c645fSJames Wright   if (elem_restr_jd_i_sur)
139*368c645fSJames Wright     CeedOperatorSetField(op_apply_bc, "surface jacobian data",
140*368c645fSJames Wright                          elem_restr_jd_i_sur,
141*368c645fSJames Wright                          CEED_BASIS_COLLOCATED, jac_data_sur);
142*368c645fSJames Wright 
143*368c645fSJames Wright   if (qf_apply_bc_jacobian) {
144*368c645fSJames Wright     CeedOperatorCreate(ceed, qf_apply_bc_jacobian, NULL, NULL,
145*368c645fSJames Wright                        &op_apply_bc_jacobian);
146*368c645fSJames Wright     CeedOperatorSetField(op_apply_bc_jacobian, "dq", elem_restr_q_sur,
147*368c645fSJames Wright                          ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
148*368c645fSJames Wright     CeedOperatorSetField(op_apply_bc_jacobian, "Grad_dq", elem_restr_q_sur,
149*368c645fSJames Wright                          ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
150*368c645fSJames Wright     CeedOperatorSetField(op_apply_bc_jacobian, "surface qdata", elem_restr_qd_i_sur,
151*368c645fSJames Wright                          CEED_BASIS_COLLOCATED, q_data_sur);
152*368c645fSJames Wright     CeedOperatorSetField(op_apply_bc_jacobian, "x", elem_restr_x_sur,
153*368c645fSJames Wright                          ceed_data->basis_x_sur, ceed_data->x_coord);
154*368c645fSJames Wright     CeedOperatorSetField(op_apply_bc_jacobian, "surface jacobian data",
155*368c645fSJames Wright                          elem_restr_jd_i_sur, CEED_BASIS_COLLOCATED, jac_data_sur);
156*368c645fSJames Wright     CeedOperatorSetField(op_apply_bc_jacobian, "v", elem_restr_q_sur,
157*368c645fSJames Wright                          ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
158*368c645fSJames Wright   }
159*368c645fSJames Wright 
160*368c645fSJames Wright   // ----- Apply CEED operator for Setup
161*368c645fSJames Wright   CeedOperatorApply(op_setup_sur, ceed_data->x_coord, q_data_sur,
162*368c645fSJames Wright                     CEED_REQUEST_IMMEDIATE);
163*368c645fSJames Wright 
164*368c645fSJames Wright   // ----- Apply Sub-Operator for Physics
165*368c645fSJames Wright   CeedCompositeOperatorAddSub(*op_apply, op_apply_bc);
166*368c645fSJames Wright   if (op_apply_bc_jacobian)
167*368c645fSJames Wright     CeedCompositeOperatorAddSub(*op_apply_ijacobian, op_apply_bc_jacobian);
168*368c645fSJames Wright 
169*368c645fSJames Wright   // ----- Cleanup
170*368c645fSJames Wright   CeedVectorDestroy(&q_data_sur);
171*368c645fSJames Wright   CeedVectorDestroy(&jac_data_sur);
172*368c645fSJames Wright   CeedElemRestrictionDestroy(&elem_restr_q_sur);
173*368c645fSJames Wright   CeedElemRestrictionDestroy(&elem_restr_x_sur);
174*368c645fSJames Wright   CeedElemRestrictionDestroy(&elem_restr_qd_i_sur);
175*368c645fSJames Wright   CeedElemRestrictionDestroy(&elem_restr_jd_i_sur);
176*368c645fSJames Wright   CeedOperatorDestroy(&op_setup_sur);
177*368c645fSJames Wright   CeedOperatorDestroy(&op_apply_bc);
178*368c645fSJames Wright   CeedOperatorDestroy(&op_apply_bc_jacobian);
179*368c645fSJames Wright 
180*368c645fSJames Wright   PetscFunctionReturn(0);
181*368c645fSJames Wright }
182*368c645fSJames 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++) {
213*368c645fSJames Wright       PetscCall(AddBCSubOperator(ceed, dm, ceed_data, domain_label, bc->inflows[i],
214*368c645fSJames Wright                                  height, Q_sur, q_data_size_sur, jac_data_size_sur,
215*368c645fSJames Wright                                  ceed_data->qf_apply_inflow, ceed_data->qf_apply_inflow_jacobian,
216*368c645fSJames 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++) {
221*368c645fSJames Wright       PetscCall(AddBCSubOperator(ceed, dm, ceed_data, domain_label, bc->outflows[i],
222*368c645fSJames Wright                                  height, Q_sur, q_data_size_sur, jac_data_size_sur,
223*368c645fSJames Wright                                  ceed_data->qf_apply_outflow, ceed_data->qf_apply_outflow_jacobian,
224*368c645fSJames Wright                                  op_apply, op_apply_ijacobian));
225002797a3SLeila Ghaffari     }
226002797a3SLeila Ghaffari   }
22792ada588SJames Wright 
22892ada588SJames Wright   // ----- Get Context Labels for Operator
22992ada588SJames Wright   CeedOperatorContextGetFieldLabel(*op_apply, "solution time",
23092ada588SJames Wright                                    &phys->solution_time_label);
231bb8a0c61SJames Wright   CeedOperatorContextGetFieldLabel(*op_apply, "timestep size",
232bb8a0c61SJames Wright                                    &phys->timestep_size_label);
23392ada588SJames Wright 
234a515125bSLeila Ghaffari   PetscFunctionReturn(0);
235a515125bSLeila Ghaffari }
236a515125bSLeila Ghaffari 
237a515125bSLeila Ghaffari PetscErrorCode SetupLibceed(Ceed ceed, CeedData ceed_data, DM dm, User user,
238c848b8b7SJed Brown                             AppCtx app_ctx, ProblemData *problem, SimpleBC bc) {
239a515125bSLeila Ghaffari   PetscErrorCode ierr;
240a515125bSLeila Ghaffari   PetscFunctionBeginUser;
241a515125bSLeila Ghaffari 
242a515125bSLeila Ghaffari   // *****************************************************************************
243a515125bSLeila Ghaffari   // Set up CEED objects for the interior domain (volume)
244a515125bSLeila Ghaffari   // *****************************************************************************
245a515125bSLeila Ghaffari   const PetscInt num_comp_q      = 5;
246a515125bSLeila Ghaffari   const CeedInt  dim             = problem->dim,
247a515125bSLeila Ghaffari                  num_comp_x      = problem->dim,
248a515125bSLeila Ghaffari                  q_data_size_vol = problem->q_data_size_vol,
249f0b65372SJed Brown                  jac_data_size_vol = num_comp_q + 6 + 3,
250a515125bSLeila Ghaffari                  P               = app_ctx->degree + 1,
251a515125bSLeila Ghaffari                  Q               = P + app_ctx->q_extra;
252752f40e3SJed Brown   CeedElemRestriction elem_restr_jd_i;
253752f40e3SJed Brown   CeedVector jac_data;
254a515125bSLeila Ghaffari 
255a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
256a515125bSLeila Ghaffari   // CEED Bases
257a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
258a515125bSLeila Ghaffari   CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_q, P, Q, CEED_GAUSS,
259a515125bSLeila Ghaffari                                   &ceed_data->basis_q);
260a515125bSLeila Ghaffari   CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_x, 2, Q, CEED_GAUSS,
261a515125bSLeila Ghaffari                                   &ceed_data->basis_x);
262a515125bSLeila Ghaffari   CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_x, 2, P,
263a515125bSLeila Ghaffari                                   CEED_GAUSS_LOBATTO, &ceed_data->basis_xc);
264a515125bSLeila Ghaffari 
265a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
266a515125bSLeila Ghaffari   // CEED Restrictions
267a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
268a515125bSLeila Ghaffari   // -- Create restriction
2696b1ccf21SJeremy L Thompson   ierr = GetRestrictionForDomain(ceed, dm, 0, 0, 0, Q, q_data_size_vol,
2706b1ccf21SJeremy L Thompson                                  &ceed_data->elem_restr_q, &ceed_data->elem_restr_x,
271a515125bSLeila Ghaffari                                  &ceed_data->elem_restr_qd_i); CHKERRQ(ierr);
272752f40e3SJed Brown 
273752f40e3SJed Brown   ierr = GetRestrictionForDomain(ceed, dm, 0, 0, 0, Q, jac_data_size_vol,
274752f40e3SJed Brown                                  NULL, NULL,
275752f40e3SJed Brown                                  &elem_restr_jd_i); CHKERRQ(ierr);
276a515125bSLeila Ghaffari // -- Create E vectors
277a515125bSLeila Ghaffari   CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->q_ceed, NULL);
278a515125bSLeila Ghaffari   CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->q_dot_ceed,
279a515125bSLeila Ghaffari                                   NULL);
280a515125bSLeila Ghaffari   CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->g_ceed, NULL);
281a515125bSLeila Ghaffari 
282a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
283a515125bSLeila Ghaffari   // CEED QFunctions
284a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
285a515125bSLeila Ghaffari   // -- Create QFunction for quadrature data
2869785fe93SJed Brown   CeedQFunctionCreateInterior(ceed, 1, problem->setup_vol.qfunction,
2879785fe93SJed Brown                               problem->setup_vol.qfunction_loc,
288a515125bSLeila Ghaffari                               &ceed_data->qf_setup_vol);
28915a3537eSJed Brown   if (problem->setup_vol.qfunction_context) {
29015a3537eSJed Brown     CeedQFunctionSetContext(ceed_data->qf_setup_vol,
29115a3537eSJed Brown                             problem->setup_vol.qfunction_context);
29215a3537eSJed Brown     CeedQFunctionContextDestroy(&problem->setup_vol.qfunction_context);
29315a3537eSJed Brown   }
294a515125bSLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_setup_vol, "dx", num_comp_x*dim,
295a515125bSLeila Ghaffari                         CEED_EVAL_GRAD);
296a515125bSLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_setup_vol, "weight", 1, CEED_EVAL_WEIGHT);
2973b1e209bSJeremy L Thompson   CeedQFunctionAddOutput(ceed_data->qf_setup_vol, "qdata", q_data_size_vol,
298a515125bSLeila Ghaffari                          CEED_EVAL_NONE);
299a515125bSLeila Ghaffari 
300a515125bSLeila Ghaffari   // -- Create QFunction for ICs
3019785fe93SJed Brown   CeedQFunctionCreateInterior(ceed, 1, problem->ics.qfunction,
3029785fe93SJed Brown                               problem->ics.qfunction_loc,
303a515125bSLeila Ghaffari                               &ceed_data->qf_ics);
30415a3537eSJed Brown   CeedQFunctionSetContext(ceed_data->qf_ics, problem->ics.qfunction_context);
30515a3537eSJed Brown   CeedQFunctionContextDestroy(&problem->ics.qfunction_context);
306a515125bSLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_ics, "x", num_comp_x, CEED_EVAL_INTERP);
307a515125bSLeila Ghaffari   CeedQFunctionAddOutput(ceed_data->qf_ics, "q0", num_comp_q, CEED_EVAL_NONE);
308a515125bSLeila Ghaffari 
309a515125bSLeila Ghaffari   // -- Create QFunction for RHS
3109785fe93SJed Brown   if (problem->apply_vol_rhs.qfunction) {
3119785fe93SJed Brown     CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_rhs.qfunction,
3129785fe93SJed Brown                                 problem->apply_vol_rhs.qfunction_loc, &ceed_data->qf_rhs_vol);
31315a3537eSJed Brown     CeedQFunctionSetContext(ceed_data->qf_rhs_vol,
31415a3537eSJed Brown                             problem->apply_vol_rhs.qfunction_context);
31515a3537eSJed Brown     CeedQFunctionContextDestroy(&problem->apply_vol_rhs.qfunction_context);
316a515125bSLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "q", num_comp_q, CEED_EVAL_INTERP);
317752f40e3SJed Brown     CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "Grad_q", num_comp_q*dim,
318a515125bSLeila Ghaffari                           CEED_EVAL_GRAD);
3193b1e209bSJeremy L Thompson     CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "qdata", q_data_size_vol,
320a515125bSLeila Ghaffari                           CEED_EVAL_NONE);
321a515125bSLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "x", num_comp_x, CEED_EVAL_INTERP);
322a515125bSLeila Ghaffari     CeedQFunctionAddOutput(ceed_data->qf_rhs_vol, "v", num_comp_q,
323a515125bSLeila Ghaffari                            CEED_EVAL_INTERP);
324752f40e3SJed Brown     CeedQFunctionAddOutput(ceed_data->qf_rhs_vol, "Grad_v", num_comp_q*dim,
325a515125bSLeila Ghaffari                            CEED_EVAL_GRAD);
326a515125bSLeila Ghaffari   }
327a515125bSLeila Ghaffari 
328a515125bSLeila Ghaffari   // -- Create QFunction for IFunction
3299785fe93SJed Brown   if (problem->apply_vol_ifunction.qfunction) {
3309785fe93SJed Brown     CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_ifunction.qfunction,
3319785fe93SJed Brown                                 problem->apply_vol_ifunction.qfunction_loc, &ceed_data->qf_ifunction_vol);
33215a3537eSJed Brown     CeedQFunctionSetContext(ceed_data->qf_ifunction_vol,
33315a3537eSJed Brown                             problem->apply_vol_ifunction.qfunction_context);
33415a3537eSJed Brown     CeedQFunctionContextDestroy(&problem->apply_vol_ifunction.qfunction_context);
335a515125bSLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "q", num_comp_q,
336a515125bSLeila Ghaffari                           CEED_EVAL_INTERP);
337752f40e3SJed Brown     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "Grad_q", num_comp_q*dim,
338a515125bSLeila Ghaffari                           CEED_EVAL_GRAD);
3393b1e209bSJeremy L Thompson     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "q dot", num_comp_q,
340a515125bSLeila Ghaffari                           CEED_EVAL_INTERP);
3413b1e209bSJeremy L Thompson     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "qdata", q_data_size_vol,
342a515125bSLeila Ghaffari                           CEED_EVAL_NONE);
343a515125bSLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "x", num_comp_x,
344a515125bSLeila Ghaffari                           CEED_EVAL_INTERP);
345a515125bSLeila Ghaffari     CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "v", num_comp_q,
346a515125bSLeila Ghaffari                            CEED_EVAL_INTERP);
347752f40e3SJed Brown     CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "Grad_v", num_comp_q*dim,
348a515125bSLeila Ghaffari                            CEED_EVAL_GRAD);
349752f40e3SJed Brown     CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "jac_data",
350752f40e3SJed Brown                            jac_data_size_vol, CEED_EVAL_NONE);
351a515125bSLeila Ghaffari   }
352a515125bSLeila Ghaffari 
353f0b65372SJed Brown   CeedQFunction qf_ijacobian_vol = NULL;
354f0b65372SJed Brown   if (problem->apply_vol_ijacobian.qfunction) {
355f0b65372SJed Brown     CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_ijacobian.qfunction,
356f0b65372SJed Brown                                 problem->apply_vol_ijacobian.qfunction_loc, &qf_ijacobian_vol);
357f0b65372SJed Brown     CeedQFunctionSetContext(qf_ijacobian_vol,
358f0b65372SJed Brown                             problem->apply_vol_ijacobian.qfunction_context);
359f0b65372SJed Brown     CeedQFunctionContextDestroy(&problem->apply_vol_ijacobian.qfunction_context);
360f0b65372SJed Brown     CeedQFunctionAddInput(qf_ijacobian_vol, "dq", num_comp_q,
361f0b65372SJed Brown                           CEED_EVAL_INTERP);
362f0b65372SJed Brown     CeedQFunctionAddInput(qf_ijacobian_vol, "Grad_dq", num_comp_q*dim,
363f0b65372SJed Brown                           CEED_EVAL_GRAD);
364f0b65372SJed Brown     CeedQFunctionAddInput(qf_ijacobian_vol, "qdata", q_data_size_vol,
365f0b65372SJed Brown                           CEED_EVAL_NONE);
366f0b65372SJed Brown     CeedQFunctionAddInput(qf_ijacobian_vol, "x", num_comp_x,
367f0b65372SJed Brown                           CEED_EVAL_INTERP);
368f0b65372SJed Brown     CeedQFunctionAddInput(qf_ijacobian_vol, "jac_data",
369f0b65372SJed Brown                           jac_data_size_vol, CEED_EVAL_NONE);
370f0b65372SJed Brown     CeedQFunctionAddOutput(qf_ijacobian_vol, "v", num_comp_q,
371f0b65372SJed Brown                            CEED_EVAL_INTERP);
372f0b65372SJed Brown     CeedQFunctionAddOutput(qf_ijacobian_vol, "Grad_v", num_comp_q*dim,
373f0b65372SJed Brown                            CEED_EVAL_GRAD);
374f0b65372SJed Brown   }
375f0b65372SJed Brown 
376a515125bSLeila Ghaffari   // ---------------------------------------------------------------------------
377a515125bSLeila Ghaffari   // Element coordinates
378a515125bSLeila Ghaffari   // ---------------------------------------------------------------------------
379a515125bSLeila Ghaffari   // -- Create CEED vector
380a515125bSLeila Ghaffari   CeedElemRestrictionCreateVector(ceed_data->elem_restr_x, &ceed_data->x_coord,
381a515125bSLeila Ghaffari                                   NULL);
382a515125bSLeila Ghaffari 
383a515125bSLeila Ghaffari   // -- Copy PETSc vector in CEED vector
384a515125bSLeila Ghaffari   Vec               X_loc;
385a515125bSLeila Ghaffari   const PetscScalar *X_loc_array;
386cac8aa24SJed Brown   {
387cac8aa24SJed Brown     DM cdm;
388cac8aa24SJed Brown     ierr = DMGetCellCoordinateDM(dm, &cdm); CHKERRQ(ierr);
389cac8aa24SJed Brown     if (cdm) {ierr = DMGetCellCoordinatesLocal(dm, &X_loc); CHKERRQ(ierr);}
390cac8aa24SJed Brown     else {ierr = DMGetCoordinatesLocal(dm, &X_loc); CHKERRQ(ierr);}
391cac8aa24SJed Brown   }
39205a512bdSLeila Ghaffari   ierr = VecScale(X_loc, problem->dm_scale); CHKERRQ(ierr);
393a515125bSLeila Ghaffari   ierr = VecGetArrayRead(X_loc, &X_loc_array); CHKERRQ(ierr);
394a515125bSLeila Ghaffari   CeedVectorSetArray(ceed_data->x_coord, CEED_MEM_HOST, CEED_COPY_VALUES,
395a515125bSLeila Ghaffari                      (PetscScalar *)X_loc_array);
396a515125bSLeila Ghaffari   ierr = VecRestoreArrayRead(X_loc, &X_loc_array); CHKERRQ(ierr);
397a515125bSLeila Ghaffari 
398a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
399a515125bSLeila Ghaffari   // CEED vectors
400a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
401a515125bSLeila Ghaffari   // -- Create CEED vector for geometric data
402a515125bSLeila Ghaffari   CeedInt  num_qpts_vol;
403a515125bSLeila Ghaffari   PetscInt loc_num_elem_vol;
404a515125bSLeila Ghaffari   CeedBasisGetNumQuadraturePoints(ceed_data->basis_q, &num_qpts_vol);
405a515125bSLeila Ghaffari   CeedElemRestrictionGetNumElements(ceed_data->elem_restr_q, &loc_num_elem_vol);
406a515125bSLeila Ghaffari   CeedVectorCreate(ceed, q_data_size_vol*loc_num_elem_vol*num_qpts_vol,
407a515125bSLeila Ghaffari                    &ceed_data->q_data);
408a515125bSLeila Ghaffari 
409752f40e3SJed Brown   CeedElemRestrictionCreateVector(elem_restr_jd_i, &jac_data, NULL);
410a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
411a515125bSLeila Ghaffari   // CEED Operators
412a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
413a515125bSLeila Ghaffari   // -- Create CEED operator for quadrature data
414a515125bSLeila Ghaffari   CeedOperatorCreate(ceed, ceed_data->qf_setup_vol, NULL, NULL,
415a515125bSLeila Ghaffari                      &ceed_data->op_setup_vol);
416a515125bSLeila Ghaffari   CeedOperatorSetField(ceed_data->op_setup_vol, "dx", ceed_data->elem_restr_x,
417a515125bSLeila Ghaffari                        ceed_data->basis_x, CEED_VECTOR_ACTIVE);
418a515125bSLeila Ghaffari   CeedOperatorSetField(ceed_data->op_setup_vol, "weight",
419139613f2SLeila Ghaffari                        CEED_ELEMRESTRICTION_NONE, ceed_data->basis_x, CEED_VECTOR_NONE);
4203b1e209bSJeremy L Thompson   CeedOperatorSetField(ceed_data->op_setup_vol, "qdata",
421139613f2SLeila Ghaffari                        ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE);
422a515125bSLeila Ghaffari 
423a515125bSLeila Ghaffari   // -- Create CEED operator for ICs
424a515125bSLeila Ghaffari   CeedOperatorCreate(ceed, ceed_data->qf_ics, NULL, NULL, &ceed_data->op_ics);
425a515125bSLeila Ghaffari   CeedOperatorSetField(ceed_data->op_ics, "x", ceed_data->elem_restr_x,
426a515125bSLeila Ghaffari                        ceed_data->basis_xc, CEED_VECTOR_ACTIVE);
427a515125bSLeila Ghaffari   CeedOperatorSetField(ceed_data->op_ics, "q0", ceed_data->elem_restr_q,
428a515125bSLeila Ghaffari                        CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE);
42915a3537eSJed Brown   CeedOperatorContextGetFieldLabel(ceed_data->op_ics, "evaluation time",
43015a3537eSJed Brown                                    &user->phys->ics_time_label);
431a515125bSLeila Ghaffari 
432a515125bSLeila Ghaffari   // Create CEED operator for RHS
433a515125bSLeila Ghaffari   if (ceed_data->qf_rhs_vol) {
434a515125bSLeila Ghaffari     CeedOperator op;
435a515125bSLeila Ghaffari     CeedOperatorCreate(ceed, ceed_data->qf_rhs_vol, NULL, NULL, &op);
436a515125bSLeila Ghaffari     CeedOperatorSetField(op, "q", ceed_data->elem_restr_q, ceed_data->basis_q,
437a515125bSLeila Ghaffari                          CEED_VECTOR_ACTIVE);
438752f40e3SJed Brown     CeedOperatorSetField(op, "Grad_q", ceed_data->elem_restr_q, ceed_data->basis_q,
439a515125bSLeila Ghaffari                          CEED_VECTOR_ACTIVE);
4403b1e209bSJeremy L Thompson     CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i,
441139613f2SLeila Ghaffari                          CEED_BASIS_COLLOCATED, ceed_data->q_data);
442a515125bSLeila Ghaffari     CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x,
443a515125bSLeila Ghaffari                          ceed_data->x_coord);
444a515125bSLeila Ghaffari     CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q,
445a515125bSLeila Ghaffari                          CEED_VECTOR_ACTIVE);
446752f40e3SJed Brown     CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q,
447a515125bSLeila Ghaffari                          CEED_VECTOR_ACTIVE);
448a515125bSLeila Ghaffari     user->op_rhs_vol = op;
449a515125bSLeila Ghaffari   }
450a515125bSLeila Ghaffari 
451a515125bSLeila Ghaffari   // -- CEED operator for IFunction
452a515125bSLeila Ghaffari   if (ceed_data->qf_ifunction_vol) {
453a515125bSLeila Ghaffari     CeedOperator op;
454a515125bSLeila Ghaffari     CeedOperatorCreate(ceed, ceed_data->qf_ifunction_vol, NULL, NULL, &op);
455a515125bSLeila Ghaffari     CeedOperatorSetField(op, "q", ceed_data->elem_restr_q, ceed_data->basis_q,
456a515125bSLeila Ghaffari                          CEED_VECTOR_ACTIVE);
457752f40e3SJed Brown     CeedOperatorSetField(op, "Grad_q", ceed_data->elem_restr_q, ceed_data->basis_q,
458a515125bSLeila Ghaffari                          CEED_VECTOR_ACTIVE);
4593b1e209bSJeremy L Thompson     CeedOperatorSetField(op, "q dot", ceed_data->elem_restr_q, ceed_data->basis_q,
460a515125bSLeila Ghaffari                          user->q_dot_ceed);
4613b1e209bSJeremy L Thompson     CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i,
462139613f2SLeila Ghaffari                          CEED_BASIS_COLLOCATED, ceed_data->q_data);
463a515125bSLeila Ghaffari     CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x,
464a515125bSLeila Ghaffari                          ceed_data->x_coord);
465a515125bSLeila Ghaffari     CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q,
466a515125bSLeila Ghaffari                          CEED_VECTOR_ACTIVE);
467752f40e3SJed Brown     CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q,
468a515125bSLeila Ghaffari                          CEED_VECTOR_ACTIVE);
469752f40e3SJed Brown     CeedOperatorSetField(op, "jac_data", elem_restr_jd_i,
470752f40e3SJed Brown                          CEED_BASIS_COLLOCATED, jac_data);
471752f40e3SJed Brown 
472a515125bSLeila Ghaffari     user->op_ifunction_vol = op;
473a515125bSLeila Ghaffari   }
474a515125bSLeila Ghaffari 
475f0b65372SJed Brown   CeedOperator op_ijacobian_vol = NULL;
476f0b65372SJed Brown   if (qf_ijacobian_vol) {
477f0b65372SJed Brown     CeedOperator op;
478f0b65372SJed Brown     CeedOperatorCreate(ceed, qf_ijacobian_vol, NULL, NULL, &op);
479f0b65372SJed Brown     CeedOperatorSetField(op, "dq", ceed_data->elem_restr_q, ceed_data->basis_q,
480f0b65372SJed Brown                          CEED_VECTOR_ACTIVE);
481f0b65372SJed Brown     CeedOperatorSetField(op, "Grad_dq", ceed_data->elem_restr_q, ceed_data->basis_q,
482f0b65372SJed Brown                          CEED_VECTOR_ACTIVE);
483f0b65372SJed Brown     CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i,
484f0b65372SJed Brown                          CEED_BASIS_COLLOCATED, ceed_data->q_data);
485f0b65372SJed Brown     CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x,
486f0b65372SJed Brown                          ceed_data->x_coord);
487f0b65372SJed Brown     CeedOperatorSetField(op, "jac_data", elem_restr_jd_i,
488f0b65372SJed Brown                          CEED_BASIS_COLLOCATED, jac_data);
489f0b65372SJed Brown     CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q,
490f0b65372SJed Brown                          CEED_VECTOR_ACTIVE);
491f0b65372SJed Brown     CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q,
492f0b65372SJed Brown                          CEED_VECTOR_ACTIVE);
493f0b65372SJed Brown     op_ijacobian_vol = op;
494f0b65372SJed Brown     CeedQFunctionDestroy(&qf_ijacobian_vol);
495f0b65372SJed Brown   }
496f0b65372SJed Brown 
497a515125bSLeila Ghaffari   // *****************************************************************************
498a515125bSLeila Ghaffari   // Set up CEED objects for the exterior domain (surface)
499a515125bSLeila Ghaffari   // *****************************************************************************
500a515125bSLeila Ghaffari   CeedInt height  = 1,
501a515125bSLeila Ghaffari           dim_sur = dim - height,
502a515125bSLeila Ghaffari           P_sur   = app_ctx->degree + 1,
503a515125bSLeila Ghaffari           Q_sur   = P_sur + app_ctx->q_extra;
504f0b65372SJed Brown   const CeedInt q_data_size_sur = problem->q_data_size_sur,
505f0b65372SJed Brown                 jac_data_size_sur = problem->jac_data_size_sur;
506a515125bSLeila Ghaffari 
507a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
508a515125bSLeila Ghaffari   // CEED Bases
509a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
510a515125bSLeila Ghaffari   CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_q, P_sur, Q_sur,
511a515125bSLeila Ghaffari                                   CEED_GAUSS, &ceed_data->basis_q_sur);
512a515125bSLeila Ghaffari   CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_x, 2, Q_sur, CEED_GAUSS,
513a515125bSLeila Ghaffari                                   &ceed_data->basis_x_sur);
514da7e3aacSJames Wright   CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_x, 2, P_sur,
515da7e3aacSJames Wright                                   CEED_GAUSS_LOBATTO, &ceed_data->basis_xc_sur);
516a515125bSLeila Ghaffari 
517a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
518a515125bSLeila Ghaffari   // CEED QFunctions
519a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
520a515125bSLeila Ghaffari   // -- Create QFunction for quadrature data
5219785fe93SJed Brown   CeedQFunctionCreateInterior(ceed, 1, problem->setup_sur.qfunction,
5229785fe93SJed Brown                               problem->setup_sur.qfunction_loc,
523a515125bSLeila Ghaffari                               &ceed_data->qf_setup_sur);
52415a3537eSJed Brown   if (problem->setup_sur.qfunction_context) {
52515a3537eSJed Brown     CeedQFunctionSetContext(ceed_data->qf_setup_sur,
52615a3537eSJed Brown                             problem->setup_sur.qfunction_context);
52715a3537eSJed Brown     CeedQFunctionContextDestroy(&problem->setup_sur.qfunction_context);
52815a3537eSJed Brown   }
529a515125bSLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_setup_sur, "dx", num_comp_x*dim_sur,
530a515125bSLeila Ghaffari                         CEED_EVAL_GRAD);
531a515125bSLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_setup_sur, "weight", 1, CEED_EVAL_WEIGHT);
5323b1e209bSJeremy L Thompson   CeedQFunctionAddOutput(ceed_data->qf_setup_sur, "surface qdata",
533002797a3SLeila Ghaffari                          q_data_size_sur, CEED_EVAL_NONE);
534a515125bSLeila Ghaffari 
535002797a3SLeila Ghaffari   // -- Creat QFunction for inflow boundaries
5369785fe93SJed Brown   if (problem->apply_inflow.qfunction) {
5379785fe93SJed Brown     CeedQFunctionCreateInterior(ceed, 1, problem->apply_inflow.qfunction,
5389785fe93SJed Brown                                 problem->apply_inflow.qfunction_loc, &ceed_data->qf_apply_inflow);
53915a3537eSJed Brown     CeedQFunctionSetContext(ceed_data->qf_apply_inflow,
54015a3537eSJed Brown                             problem->apply_inflow.qfunction_context);
54115a3537eSJed Brown     CeedQFunctionContextDestroy(&problem->apply_inflow.qfunction_context);
542002797a3SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_apply_inflow, "q", num_comp_q,
543a515125bSLeila Ghaffari                           CEED_EVAL_INTERP);
544dd64951cSJames Wright     CeedQFunctionAddInput(ceed_data->qf_apply_inflow, "Grad_q", num_comp_q*(dim-1),
545dd64951cSJames Wright                           CEED_EVAL_GRAD);
546002797a3SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_apply_inflow, "surface qdata",
547002797a3SLeila Ghaffari                           q_data_size_sur, CEED_EVAL_NONE);
548002797a3SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_apply_inflow, "x", num_comp_x,
549a515125bSLeila Ghaffari                           CEED_EVAL_INTERP);
550002797a3SLeila Ghaffari     CeedQFunctionAddOutput(ceed_data->qf_apply_inflow, "v", num_comp_q,
551002797a3SLeila Ghaffari                            CEED_EVAL_INTERP);
55268ae065aSJames Wright     if (jac_data_size_sur)
55368ae065aSJames Wright       CeedQFunctionAddOutput(ceed_data->qf_apply_inflow, "surface jacobian data",
55468ae065aSJames Wright                              jac_data_size_sur,
55568ae065aSJames Wright                              CEED_EVAL_NONE);
556002797a3SLeila Ghaffari   }
557f0b65372SJed Brown   if (problem->apply_inflow_jacobian.qfunction) {
558f0b65372SJed Brown     CeedQFunctionCreateInterior(ceed, 1, problem->apply_inflow_jacobian.qfunction,
559f0b65372SJed Brown                                 problem->apply_inflow_jacobian.qfunction_loc,
560f0b65372SJed Brown                                 &ceed_data->qf_apply_inflow_jacobian);
561f0b65372SJed Brown     CeedQFunctionSetContext(ceed_data->qf_apply_inflow_jacobian,
562f0b65372SJed Brown                             problem->apply_inflow_jacobian.qfunction_context);
563f0b65372SJed Brown     CeedQFunctionContextDestroy(&problem->apply_inflow_jacobian.qfunction_context);
564f0b65372SJed Brown     CeedQFunctionAddInput(ceed_data->qf_apply_inflow_jacobian, "dq", num_comp_q,
565f0b65372SJed Brown                           CEED_EVAL_INTERP);
56668ae065aSJames Wright     CeedQFunctionAddInput(ceed_data->qf_apply_inflow_jacobian, "Grad_dq",
56768ae065aSJames Wright                           num_comp_q*dim_sur, CEED_EVAL_GRAD);
568f0b65372SJed Brown     CeedQFunctionAddInput(ceed_data->qf_apply_inflow_jacobian, "surface qdata",
569f0b65372SJed Brown                           q_data_size_sur, CEED_EVAL_NONE);
570f0b65372SJed Brown     CeedQFunctionAddInput(ceed_data->qf_apply_inflow_jacobian, "x", num_comp_x,
571f0b65372SJed Brown                           CEED_EVAL_INTERP);
57268ae065aSJames Wright     CeedQFunctionAddInput(ceed_data->qf_apply_inflow_jacobian,
57368ae065aSJames Wright                           "surface jacobian data",
57468ae065aSJames Wright                           jac_data_size_sur, CEED_EVAL_NONE);
575f0b65372SJed Brown     CeedQFunctionAddOutput(ceed_data->qf_apply_inflow_jacobian, "v", num_comp_q,
576f0b65372SJed Brown                            CEED_EVAL_INTERP);
577f0b65372SJed Brown   }
578002797a3SLeila Ghaffari 
579002797a3SLeila Ghaffari   // -- Creat QFunction for outflow boundaries
5809785fe93SJed Brown   if (problem->apply_outflow.qfunction) {
5819785fe93SJed Brown     CeedQFunctionCreateInterior(ceed, 1, problem->apply_outflow.qfunction,
5829785fe93SJed Brown                                 problem->apply_outflow.qfunction_loc, &ceed_data->qf_apply_outflow);
58315a3537eSJed Brown     CeedQFunctionSetContext(ceed_data->qf_apply_outflow,
58415a3537eSJed Brown                             problem->apply_outflow.qfunction_context);
58515a3537eSJed Brown     CeedQFunctionContextDestroy(&problem->apply_outflow.qfunction_context);
586002797a3SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_apply_outflow, "q", num_comp_q,
587002797a3SLeila Ghaffari                           CEED_EVAL_INTERP);
588dd64951cSJames Wright     CeedQFunctionAddInput(ceed_data->qf_apply_outflow, "Grad_q", num_comp_q*(dim-1),
589dd64951cSJames Wright                           CEED_EVAL_GRAD);
590002797a3SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_apply_outflow, "surface qdata",
591002797a3SLeila Ghaffari                           q_data_size_sur, CEED_EVAL_NONE);
592002797a3SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_apply_outflow, "x", num_comp_x,
593002797a3SLeila Ghaffari                           CEED_EVAL_INTERP);
594002797a3SLeila Ghaffari     CeedQFunctionAddOutput(ceed_data->qf_apply_outflow, "v", num_comp_q,
595a515125bSLeila Ghaffari                            CEED_EVAL_INTERP);
5962556a851SJed Brown     if (jac_data_size_sur)
597f0b65372SJed Brown       CeedQFunctionAddOutput(ceed_data->qf_apply_outflow, "surface jacobian data",
598f0b65372SJed Brown                              jac_data_size_sur,
599f0b65372SJed Brown                              CEED_EVAL_NONE);
600f0b65372SJed Brown   }
601f0b65372SJed Brown   if (problem->apply_outflow_jacobian.qfunction) {
602f0b65372SJed Brown     CeedQFunctionCreateInterior(ceed, 1, problem->apply_outflow_jacobian.qfunction,
603f0b65372SJed Brown                                 problem->apply_outflow_jacobian.qfunction_loc,
604f0b65372SJed Brown                                 &ceed_data->qf_apply_outflow_jacobian);
605f0b65372SJed Brown     CeedQFunctionSetContext(ceed_data->qf_apply_outflow_jacobian,
606f0b65372SJed Brown                             problem->apply_outflow_jacobian.qfunction_context);
607f0b65372SJed Brown     CeedQFunctionContextDestroy(&problem->apply_outflow_jacobian.qfunction_context);
608f0b65372SJed Brown     CeedQFunctionAddInput(ceed_data->qf_apply_outflow_jacobian, "dq", num_comp_q,
609f0b65372SJed Brown                           CEED_EVAL_INTERP);
61068ae065aSJames Wright     CeedQFunctionAddInput(ceed_data->qf_apply_outflow_jacobian, "Grad_dq",
61168ae065aSJames Wright                           num_comp_q*dim_sur, CEED_EVAL_GRAD);
612f0b65372SJed Brown     CeedQFunctionAddInput(ceed_data->qf_apply_outflow_jacobian, "surface qdata",
613f0b65372SJed Brown                           q_data_size_sur, CEED_EVAL_NONE);
614b01ba163SJames Wright     CeedQFunctionAddInput(ceed_data->qf_apply_outflow_jacobian, "x", num_comp_x,
615b01ba163SJames Wright                           CEED_EVAL_INTERP);
616f0b65372SJed Brown     CeedQFunctionAddInput(ceed_data->qf_apply_outflow_jacobian,
617f0b65372SJed Brown                           "surface jacobian data",
618f0b65372SJed Brown                           jac_data_size_sur, CEED_EVAL_NONE);
619f0b65372SJed Brown     CeedQFunctionAddOutput(ceed_data->qf_apply_outflow_jacobian, "v", num_comp_q,
620f0b65372SJed Brown                            CEED_EVAL_INTERP);
621a515125bSLeila Ghaffari   }
622a515125bSLeila Ghaffari 
623a515125bSLeila Ghaffari   // *****************************************************************************
624a515125bSLeila Ghaffari   // CEED Operator Apply
625a515125bSLeila Ghaffari   // *****************************************************************************
626a515125bSLeila Ghaffari   // -- Apply CEED Operator for the geometric data
627a515125bSLeila Ghaffari   CeedOperatorApply(ceed_data->op_setup_vol, ceed_data->x_coord,
628a515125bSLeila Ghaffari                     ceed_data->q_data, CEED_REQUEST_IMMEDIATE);
629a515125bSLeila Ghaffari 
630a515125bSLeila Ghaffari   // -- Create and apply CEED Composite Operator for the entire domain
631a515125bSLeila Ghaffari   if (!user->phys->implicit) { // RHS
632a515125bSLeila Ghaffari     ierr = CreateOperatorForDomain(ceed, dm, bc, ceed_data, user->phys,
633f0b65372SJed Brown                                    user->op_rhs_vol, NULL, height, P_sur, Q_sur,
634f0b65372SJed Brown                                    q_data_size_sur, 0,
635f0b65372SJed Brown                                    &user->op_rhs, NULL); CHKERRQ(ierr);
636a515125bSLeila Ghaffari   } else { // IFunction
637a515125bSLeila Ghaffari     ierr = CreateOperatorForDomain(ceed, dm, bc, ceed_data, user->phys,
638f0b65372SJed Brown                                    user->op_ifunction_vol, op_ijacobian_vol,
639f0b65372SJed Brown                                    height, P_sur, Q_sur,
640f0b65372SJed Brown                                    q_data_size_sur, jac_data_size_sur,
641f0b65372SJed Brown                                    &user->op_ifunction,
642f0b65372SJed Brown                                    op_ijacobian_vol ? &user->op_ijacobian : NULL); CHKERRQ(ierr);
643f0b65372SJed Brown     if (user->op_ijacobian) {
644f0b65372SJed Brown       CeedOperatorContextGetFieldLabel(user->op_ijacobian, "ijacobian time shift",
645f0b65372SJed Brown                                        &user->phys->ijacobian_time_shift_label);
646f0b65372SJed Brown     }
6476d0190e2SJames Wright     if (problem->use_dirichlet_ceed) {
6486d0190e2SJames Wright       PetscCall(SetupStrongBC_Ceed(ceed, ceed_data, dm, user, app_ctx, problem, bc,
6496d0190e2SJames Wright                                    Q_sur, q_data_size_sur));
6506d0190e2SJames Wright     }
651f0b65372SJed Brown 
652a515125bSLeila Ghaffari   }
653752f40e3SJed Brown   CeedElemRestrictionDestroy(&elem_restr_jd_i);
654e22e0f1cSLeila Ghaffari   CeedOperatorDestroy(&op_ijacobian_vol);
655752f40e3SJed Brown   CeedVectorDestroy(&jac_data);
656a515125bSLeila Ghaffari   PetscFunctionReturn(0);
657a515125bSLeila Ghaffari }
658