xref: /honee/src/setuplibceed.c (revision dd64951c5150ec2eff9c2280926c45eced5070c5)
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) {
59a515125bSLeila Ghaffari     ierr = DMGetCoordinateDM(dm, &dm_coord); CHKERRQ(ierr);
60a515125bSLeila Ghaffari     ierr = DMPlexSetClosurePermutationTensor(dm_coord, PETSC_DETERMINE, NULL);
61a515125bSLeila Ghaffari     CHKERRQ(ierr);
626b1ccf21SJeremy L Thompson     ierr = CreateRestrictionFromPlex(ceed, dm_coord, height, domain_label, value,
636b1ccf21SJeremy L Thompson                                      elem_restr_x);
646b1ccf21SJeremy L Thompson     CHKERRQ(ierr);
65395c96d3SJed Brown   }
66395c96d3SJed Brown   if (elem_restr_qd_i) {
67395c96d3SJed Brown     CeedElemRestrictionGetNumElements(elem_restr_tmp, &loc_num_elem);
68a515125bSLeila Ghaffari     CeedElemRestrictionCreateStrided(ceed, loc_num_elem, Q_dim,
69a515125bSLeila Ghaffari                                      q_data_size, q_data_size*loc_num_elem*Q_dim,
70a515125bSLeila Ghaffari                                      CEED_STRIDES_BACKEND, elem_restr_qd_i);
71395c96d3SJed Brown   }
72395c96d3SJed Brown   if (!elem_restr_q) CeedElemRestrictionDestroy(&elem_restr_tmp);
73a515125bSLeila Ghaffari   PetscFunctionReturn(0);
74a515125bSLeila Ghaffari }
75a515125bSLeila Ghaffari 
76a515125bSLeila Ghaffari // Utility function to create CEED Composite Operator for the entire domain
77a515125bSLeila Ghaffari PetscErrorCode CreateOperatorForDomain(Ceed ceed, DM dm, SimpleBC bc,
78a515125bSLeila Ghaffari                                        CeedData ceed_data, Physics phys,
79f0b65372SJed Brown                                        CeedOperator op_apply_vol,
80f0b65372SJed Brown                                        CeedOperator op_apply_ijacobian_vol,
81f0b65372SJed Brown                                        CeedInt height,
82f0b65372SJed Brown                                        CeedInt P_sur, CeedInt Q_sur,
83f0b65372SJed Brown                                        CeedInt q_data_size_sur, CeedInt jac_data_size_sur,
84f0b65372SJed Brown                                        CeedOperator *op_apply, CeedOperator *op_apply_ijacobian) {
85002797a3SLeila Ghaffari   //CeedInt        dim;
86a515125bSLeila Ghaffari   DMLabel        domain_label;
87a515125bSLeila Ghaffari   PetscErrorCode ierr;
88a515125bSLeila Ghaffari   PetscFunctionBeginUser;
89a515125bSLeila Ghaffari 
90a515125bSLeila Ghaffari   // Create Composite Operaters
91a515125bSLeila Ghaffari   CeedCompositeOperatorCreate(ceed, op_apply);
92f0b65372SJed Brown   if (op_apply_ijacobian)
93f0b65372SJed Brown     CeedCompositeOperatorCreate(ceed, op_apply_ijacobian);
94a515125bSLeila Ghaffari 
95a515125bSLeila Ghaffari   // --Apply Sub-Operator for the volume
96a515125bSLeila Ghaffari   CeedCompositeOperatorAddSub(*op_apply, op_apply_vol);
97f0b65372SJed Brown   if (op_apply_ijacobian)
98f0b65372SJed Brown     CeedCompositeOperatorAddSub(*op_apply_ijacobian, op_apply_ijacobian_vol);
99a515125bSLeila Ghaffari 
100a515125bSLeila Ghaffari   // -- Create Sub-Operator for in/outflow BCs
101bb8a0c61SJames Wright   if (phys->has_neumann || 1) {
102a515125bSLeila Ghaffari     // --- Setup
103a515125bSLeila Ghaffari     ierr = DMGetLabel(dm, "Face Sets", &domain_label); CHKERRQ(ierr);
104002797a3SLeila Ghaffari     //ierr = DMGetDimension(dm, &dim); CHKERRQ(ierr);
105a515125bSLeila Ghaffari 
106a515125bSLeila Ghaffari     // --- Get number of quadrature points for the boundaries
107a515125bSLeila Ghaffari     CeedInt num_qpts_sur;
108a515125bSLeila Ghaffari     CeedBasisGetNumQuadraturePoints(ceed_data->basis_q_sur, &num_qpts_sur);
109a515125bSLeila Ghaffari 
110002797a3SLeila Ghaffari     // --- Create Sub-Operator for inflow boundaries
111002797a3SLeila Ghaffari     for (CeedInt i=0; i < bc->num_inflow; i++) {
112a515125bSLeila Ghaffari       CeedVector          q_data_sur;
113f0b65372SJed Brown       CeedOperator        op_setup_sur, op_apply_inflow,
114f0b65372SJed Brown                           op_apply_inflow_jacobian = NULL;
115002797a3SLeila Ghaffari       CeedElemRestriction elem_restr_x_sur, elem_restr_q_sur, elem_restr_qd_i_sur;
116a515125bSLeila Ghaffari 
117a515125bSLeila Ghaffari       // ---- CEED Restriction
118002797a3SLeila Ghaffari       ierr = GetRestrictionForDomain(ceed, dm, height, domain_label, bc->inflows[i],
119002797a3SLeila Ghaffari                                      Q_sur, q_data_size_sur, &elem_restr_q_sur, &elem_restr_x_sur,
120002797a3SLeila Ghaffari                                      &elem_restr_qd_i_sur);
121a515125bSLeila Ghaffari       CHKERRQ(ierr);
122a515125bSLeila Ghaffari 
123a515125bSLeila Ghaffari       // ---- CEED Vector
124a515125bSLeila Ghaffari       PetscInt loc_num_elem_sur;
125a515125bSLeila Ghaffari       CeedElemRestrictionGetNumElements(elem_restr_q_sur, &loc_num_elem_sur);
126a515125bSLeila Ghaffari       CeedVectorCreate(ceed, q_data_size_sur*loc_num_elem_sur*num_qpts_sur,
127a515125bSLeila Ghaffari                        &q_data_sur);
128a515125bSLeila Ghaffari 
129a515125bSLeila Ghaffari       // ---- CEED Operator
130a515125bSLeila Ghaffari       // ----- CEED Operator for Setup (geometric factors)
131a515125bSLeila Ghaffari       CeedOperatorCreate(ceed, ceed_data->qf_setup_sur, NULL, NULL, &op_setup_sur);
132a515125bSLeila Ghaffari       CeedOperatorSetField(op_setup_sur, "dx", elem_restr_x_sur,
133139613f2SLeila Ghaffari                            ceed_data->basis_x_sur, CEED_VECTOR_ACTIVE);
134a515125bSLeila Ghaffari       CeedOperatorSetField(op_setup_sur, "weight", CEED_ELEMRESTRICTION_NONE,
135a515125bSLeila Ghaffari                            ceed_data->basis_x_sur, CEED_VECTOR_NONE);
1363b1e209bSJeremy L Thompson       CeedOperatorSetField(op_setup_sur, "surface qdata", elem_restr_qd_i_sur,
137a515125bSLeila Ghaffari                            CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE);
138a515125bSLeila Ghaffari 
139a515125bSLeila Ghaffari       // ----- CEED Operator for Physics
140002797a3SLeila Ghaffari       CeedOperatorCreate(ceed, ceed_data->qf_apply_inflow, NULL, NULL,
141002797a3SLeila Ghaffari                          &op_apply_inflow);
142002797a3SLeila Ghaffari       CeedOperatorSetField(op_apply_inflow, "q", elem_restr_q_sur,
143a515125bSLeila Ghaffari                            ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
144*dd64951cSJames Wright       CeedOperatorSetField(op_apply_inflow, "Grad_q", elem_restr_q_sur,
145*dd64951cSJames Wright                            ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
146002797a3SLeila Ghaffari       CeedOperatorSetField(op_apply_inflow, "surface qdata", elem_restr_qd_i_sur,
147a515125bSLeila Ghaffari                            CEED_BASIS_COLLOCATED, q_data_sur);
148002797a3SLeila Ghaffari       CeedOperatorSetField(op_apply_inflow, "x", elem_restr_x_sur,
149a515125bSLeila Ghaffari                            ceed_data->basis_x_sur, ceed_data->x_coord);
150002797a3SLeila Ghaffari       CeedOperatorSetField(op_apply_inflow, "v", elem_restr_q_sur,
151a515125bSLeila Ghaffari                            ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
152a515125bSLeila Ghaffari 
153f0b65372SJed Brown       if (ceed_data->qf_apply_inflow_jacobian) {
154f0b65372SJed Brown         CeedOperatorCreate(ceed, ceed_data->qf_apply_inflow_jacobian, NULL, NULL,
155f0b65372SJed Brown                            &op_apply_inflow_jacobian);
156f0b65372SJed Brown         CeedOperatorSetField(op_apply_inflow_jacobian, "dq", elem_restr_q_sur,
157f0b65372SJed Brown                              ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
158f0b65372SJed Brown         CeedOperatorSetField(op_apply_inflow_jacobian, "surface qdata",
159f0b65372SJed Brown                              elem_restr_qd_i_sur,
160f0b65372SJed Brown                              CEED_BASIS_COLLOCATED, q_data_sur);
161f0b65372SJed Brown         CeedOperatorSetField(op_apply_inflow_jacobian, "x", elem_restr_x_sur,
162f0b65372SJed Brown                              ceed_data->basis_x_sur, ceed_data->x_coord);
163f0b65372SJed Brown         CeedOperatorSetField(op_apply_inflow_jacobian, "v", elem_restr_q_sur,
164f0b65372SJed Brown                              ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
165f0b65372SJed Brown       }
166f0b65372SJed Brown 
167a515125bSLeila Ghaffari       // ----- Apply CEED operator for Setup
168a515125bSLeila Ghaffari       CeedOperatorApply(op_setup_sur, ceed_data->x_coord, q_data_sur,
169a515125bSLeila Ghaffari                         CEED_REQUEST_IMMEDIATE);
170a515125bSLeila Ghaffari 
171002797a3SLeila Ghaffari       // ----- Apply Sub-Operator for Physics
172002797a3SLeila Ghaffari       CeedCompositeOperatorAddSub(*op_apply, op_apply_inflow);
173f0b65372SJed Brown       if (op_apply_ijacobian)
174f0b65372SJed Brown         CeedCompositeOperatorAddSub(*op_apply_ijacobian, op_apply_inflow_jacobian);
175a515125bSLeila Ghaffari 
176a515125bSLeila Ghaffari       // ----- Cleanup
177a515125bSLeila Ghaffari       CeedVectorDestroy(&q_data_sur);
178a515125bSLeila Ghaffari       CeedElemRestrictionDestroy(&elem_restr_q_sur);
179a515125bSLeila Ghaffari       CeedElemRestrictionDestroy(&elem_restr_x_sur);
180a515125bSLeila Ghaffari       CeedElemRestrictionDestroy(&elem_restr_qd_i_sur);
181a515125bSLeila Ghaffari       CeedOperatorDestroy(&op_setup_sur);
182002797a3SLeila Ghaffari       CeedOperatorDestroy(&op_apply_inflow);
183f0b65372SJed Brown       CeedOperatorDestroy(&op_apply_inflow_jacobian);
184a515125bSLeila Ghaffari     }
185a515125bSLeila Ghaffari 
186002797a3SLeila Ghaffari     // --- Create Sub-Operator for outflow boundaries
187002797a3SLeila Ghaffari     for (CeedInt i=0; i < bc->num_outflow; i++) {
188f0b65372SJed Brown       CeedVector          q_data_sur, jac_data_sur;
189f0b65372SJed Brown       CeedOperator        op_setup_sur, op_apply_outflow,
190f0b65372SJed Brown                           op_apply_outflow_jacobian = NULL;
191f0b65372SJed Brown       CeedElemRestriction elem_restr_x_sur, elem_restr_q_sur, elem_restr_qd_i_sur,
192f0b65372SJed Brown                           elem_restr_jd_i_sur;
193002797a3SLeila Ghaffari 
194002797a3SLeila Ghaffari       // ---- CEED Restriction
195002797a3SLeila Ghaffari       ierr = GetRestrictionForDomain(ceed, dm, height, domain_label, bc->outflows[i],
196002797a3SLeila Ghaffari                                      Q_sur, q_data_size_sur, &elem_restr_q_sur, &elem_restr_x_sur,
197002797a3SLeila Ghaffari                                      &elem_restr_qd_i_sur);
198002797a3SLeila Ghaffari       CHKERRQ(ierr);
1992556a851SJed Brown       if (jac_data_size_sur > 0) {
2002556a851SJed Brown         // State-dependent data will be passed from residual to Jacobian. This will be collocated.
201f0b65372SJed Brown         ierr = GetRestrictionForDomain(ceed, dm, height, domain_label, bc->outflows[i],
202f0b65372SJed Brown                                        Q_sur, jac_data_size_sur, NULL, NULL,
203f0b65372SJed Brown                                        &elem_restr_jd_i_sur);
204f0b65372SJed Brown         CHKERRQ(ierr);
2052556a851SJed Brown         CeedElemRestrictionCreateVector(elem_restr_jd_i_sur, &jac_data_sur, NULL);
2062556a851SJed Brown       } else {
2072556a851SJed Brown         elem_restr_jd_i_sur = NULL;
2082556a851SJed Brown         jac_data_sur = NULL;
2092556a851SJed Brown       }
210002797a3SLeila Ghaffari 
211002797a3SLeila Ghaffari       // ---- CEED Vector
212002797a3SLeila Ghaffari       PetscInt loc_num_elem_sur;
213002797a3SLeila Ghaffari       CeedElemRestrictionGetNumElements(elem_restr_q_sur, &loc_num_elem_sur);
214002797a3SLeila Ghaffari       CeedVectorCreate(ceed, q_data_size_sur*loc_num_elem_sur*num_qpts_sur,
215002797a3SLeila Ghaffari                        &q_data_sur);
216002797a3SLeila Ghaffari 
217002797a3SLeila Ghaffari       // ---- CEED Operator
218002797a3SLeila Ghaffari       // ----- CEED Operator for Setup (geometric factors)
219002797a3SLeila Ghaffari       CeedOperatorCreate(ceed, ceed_data->qf_setup_sur, NULL, NULL, &op_setup_sur);
220002797a3SLeila Ghaffari       CeedOperatorSetField(op_setup_sur, "dx", elem_restr_x_sur,
221002797a3SLeila Ghaffari                            ceed_data->basis_x_sur, CEED_VECTOR_ACTIVE);
222002797a3SLeila Ghaffari       CeedOperatorSetField(op_setup_sur, "weight", CEED_ELEMRESTRICTION_NONE,
223002797a3SLeila Ghaffari                            ceed_data->basis_x_sur, CEED_VECTOR_NONE);
224002797a3SLeila Ghaffari       CeedOperatorSetField(op_setup_sur, "surface qdata", elem_restr_qd_i_sur,
225002797a3SLeila Ghaffari                            CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE);
226002797a3SLeila Ghaffari 
227002797a3SLeila Ghaffari       // ----- CEED Operator for Physics
228002797a3SLeila Ghaffari       CeedOperatorCreate(ceed, ceed_data->qf_apply_outflow, NULL, NULL,
229002797a3SLeila Ghaffari                          &op_apply_outflow);
230002797a3SLeila Ghaffari       CeedOperatorSetField(op_apply_outflow, "q", elem_restr_q_sur,
231002797a3SLeila Ghaffari                            ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
232*dd64951cSJames Wright       CeedOperatorSetField(op_apply_outflow, "Grad_q", elem_restr_q_sur,
233*dd64951cSJames Wright                            ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
234002797a3SLeila Ghaffari       CeedOperatorSetField(op_apply_outflow, "surface qdata", elem_restr_qd_i_sur,
235002797a3SLeila Ghaffari                            CEED_BASIS_COLLOCATED, q_data_sur);
236002797a3SLeila Ghaffari       CeedOperatorSetField(op_apply_outflow, "x", elem_restr_x_sur,
237002797a3SLeila Ghaffari                            ceed_data->basis_x_sur, ceed_data->x_coord);
238002797a3SLeila Ghaffari       CeedOperatorSetField(op_apply_outflow, "v", elem_restr_q_sur,
239002797a3SLeila Ghaffari                            ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
2402556a851SJed Brown       if (elem_restr_jd_i_sur)
241f0b65372SJed Brown         CeedOperatorSetField(op_apply_outflow, "surface jacobian data",
242f0b65372SJed Brown                              elem_restr_jd_i_sur,
243f0b65372SJed Brown                              CEED_BASIS_COLLOCATED, jac_data_sur);
244f0b65372SJed Brown 
245f0b65372SJed Brown       if (ceed_data->qf_apply_outflow_jacobian) {
246f0b65372SJed Brown         CeedOperatorCreate(ceed, ceed_data->qf_apply_outflow_jacobian, NULL, NULL,
247f0b65372SJed Brown                            &op_apply_outflow_jacobian);
248f0b65372SJed Brown         CeedOperatorSetField(op_apply_outflow_jacobian, "dq", elem_restr_q_sur,
249f0b65372SJed Brown                              ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
250f0b65372SJed Brown         CeedOperatorSetField(op_apply_outflow_jacobian, "surface qdata",
251f0b65372SJed Brown                              elem_restr_qd_i_sur,
252f0b65372SJed Brown                              CEED_BASIS_COLLOCATED, q_data_sur);
253f0b65372SJed Brown         CeedOperatorSetField(op_apply_outflow_jacobian, "surface jacobian data",
254f0b65372SJed Brown                              elem_restr_jd_i_sur,
255f0b65372SJed Brown                              CEED_BASIS_COLLOCATED, jac_data_sur);
256f0b65372SJed Brown         CeedOperatorSetField(op_apply_outflow_jacobian, "v", elem_restr_q_sur,
257f0b65372SJed Brown                              ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
258f0b65372SJed Brown       }
259002797a3SLeila Ghaffari 
260002797a3SLeila Ghaffari       // ----- Apply CEED operator for Setup
261002797a3SLeila Ghaffari       CeedOperatorApply(op_setup_sur, ceed_data->x_coord, q_data_sur,
262002797a3SLeila Ghaffari                         CEED_REQUEST_IMMEDIATE);
263002797a3SLeila Ghaffari 
264002797a3SLeila Ghaffari       // ----- Apply Sub-Operator for Physics
265002797a3SLeila Ghaffari       CeedCompositeOperatorAddSub(*op_apply, op_apply_outflow);
266f0b65372SJed Brown       if (op_apply_ijacobian)
267f0b65372SJed Brown         CeedCompositeOperatorAddSub(*op_apply_ijacobian, op_apply_outflow_jacobian);
268002797a3SLeila Ghaffari 
269002797a3SLeila Ghaffari       // ----- Cleanup
270002797a3SLeila Ghaffari       CeedVectorDestroy(&q_data_sur);
271f0b65372SJed Brown       CeedVectorDestroy(&jac_data_sur);
272002797a3SLeila Ghaffari       CeedElemRestrictionDestroy(&elem_restr_q_sur);
273002797a3SLeila Ghaffari       CeedElemRestrictionDestroy(&elem_restr_x_sur);
274002797a3SLeila Ghaffari       CeedElemRestrictionDestroy(&elem_restr_qd_i_sur);
275f0b65372SJed Brown       CeedElemRestrictionDestroy(&elem_restr_jd_i_sur);
276002797a3SLeila Ghaffari       CeedOperatorDestroy(&op_setup_sur);
277002797a3SLeila Ghaffari       CeedOperatorDestroy(&op_apply_outflow);
278f0b65372SJed Brown       CeedOperatorDestroy(&op_apply_outflow_jacobian);
279002797a3SLeila Ghaffari     }
280002797a3SLeila Ghaffari   }
28192ada588SJames Wright 
28292ada588SJames Wright   // ----- Get Context Labels for Operator
28392ada588SJames Wright   CeedOperatorContextGetFieldLabel(*op_apply, "solution time",
28492ada588SJames Wright                                    &phys->solution_time_label);
285bb8a0c61SJames Wright   CeedOperatorContextGetFieldLabel(*op_apply, "timestep size",
286bb8a0c61SJames Wright                                    &phys->timestep_size_label);
28792ada588SJames Wright 
288a515125bSLeila Ghaffari   PetscFunctionReturn(0);
289a515125bSLeila Ghaffari }
290a515125bSLeila Ghaffari 
291a515125bSLeila Ghaffari PetscErrorCode SetupLibceed(Ceed ceed, CeedData ceed_data, DM dm, User user,
292c848b8b7SJed Brown                             AppCtx app_ctx, ProblemData *problem, SimpleBC bc) {
293a515125bSLeila Ghaffari   PetscErrorCode ierr;
294a515125bSLeila Ghaffari   PetscFunctionBeginUser;
295a515125bSLeila Ghaffari 
296a515125bSLeila Ghaffari   // *****************************************************************************
297a515125bSLeila Ghaffari   // Set up CEED objects for the interior domain (volume)
298a515125bSLeila Ghaffari   // *****************************************************************************
299a515125bSLeila Ghaffari   const PetscInt num_comp_q      = 5;
300a515125bSLeila Ghaffari   const CeedInt  dim             = problem->dim,
301a515125bSLeila Ghaffari                  num_comp_x      = problem->dim,
302a515125bSLeila Ghaffari                  q_data_size_vol = problem->q_data_size_vol,
303f0b65372SJed Brown                  jac_data_size_vol = num_comp_q + 6 + 3,
304a515125bSLeila Ghaffari                  P               = app_ctx->degree + 1,
305a515125bSLeila Ghaffari                  Q               = P + app_ctx->q_extra;
306752f40e3SJed Brown   CeedElemRestriction elem_restr_jd_i;
307752f40e3SJed Brown   CeedVector jac_data;
308a515125bSLeila Ghaffari 
309a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
310a515125bSLeila Ghaffari   // CEED Bases
311a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
312a515125bSLeila Ghaffari   CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_q, P, Q, CEED_GAUSS,
313a515125bSLeila Ghaffari                                   &ceed_data->basis_q);
314a515125bSLeila Ghaffari   CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_x, 2, Q, CEED_GAUSS,
315a515125bSLeila Ghaffari                                   &ceed_data->basis_x);
316a515125bSLeila Ghaffari   CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_x, 2, P,
317a515125bSLeila Ghaffari                                   CEED_GAUSS_LOBATTO, &ceed_data->basis_xc);
318a515125bSLeila Ghaffari 
319a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
320a515125bSLeila Ghaffari   // CEED Restrictions
321a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
322a515125bSLeila Ghaffari   // -- Create restriction
3236b1ccf21SJeremy L Thompson   ierr = GetRestrictionForDomain(ceed, dm, 0, 0, 0, Q, q_data_size_vol,
3246b1ccf21SJeremy L Thompson                                  &ceed_data->elem_restr_q, &ceed_data->elem_restr_x,
325a515125bSLeila Ghaffari                                  &ceed_data->elem_restr_qd_i); CHKERRQ(ierr);
326752f40e3SJed Brown 
327752f40e3SJed Brown   ierr = GetRestrictionForDomain(ceed, dm, 0, 0, 0, Q, jac_data_size_vol,
328752f40e3SJed Brown                                  NULL, NULL,
329752f40e3SJed Brown                                  &elem_restr_jd_i); CHKERRQ(ierr);
330a515125bSLeila Ghaffari // -- Create E vectors
331a515125bSLeila Ghaffari   CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->q_ceed, NULL);
332a515125bSLeila Ghaffari   CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->q_dot_ceed,
333a515125bSLeila Ghaffari                                   NULL);
334a515125bSLeila Ghaffari   CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->g_ceed, NULL);
335a515125bSLeila Ghaffari 
336a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
337a515125bSLeila Ghaffari   // CEED QFunctions
338a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
339a515125bSLeila Ghaffari   // -- Create QFunction for quadrature data
3409785fe93SJed Brown   CeedQFunctionCreateInterior(ceed, 1, problem->setup_vol.qfunction,
3419785fe93SJed Brown                               problem->setup_vol.qfunction_loc,
342a515125bSLeila Ghaffari                               &ceed_data->qf_setup_vol);
34315a3537eSJed Brown   if (problem->setup_vol.qfunction_context) {
34415a3537eSJed Brown     CeedQFunctionSetContext(ceed_data->qf_setup_vol,
34515a3537eSJed Brown                             problem->setup_vol.qfunction_context);
34615a3537eSJed Brown     CeedQFunctionContextDestroy(&problem->setup_vol.qfunction_context);
34715a3537eSJed Brown   }
348a515125bSLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_setup_vol, "dx", num_comp_x*dim,
349a515125bSLeila Ghaffari                         CEED_EVAL_GRAD);
350a515125bSLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_setup_vol, "weight", 1, CEED_EVAL_WEIGHT);
3513b1e209bSJeremy L Thompson   CeedQFunctionAddOutput(ceed_data->qf_setup_vol, "qdata", q_data_size_vol,
352a515125bSLeila Ghaffari                          CEED_EVAL_NONE);
353a515125bSLeila Ghaffari 
354a515125bSLeila Ghaffari   // -- Create QFunction for ICs
3559785fe93SJed Brown   CeedQFunctionCreateInterior(ceed, 1, problem->ics.qfunction,
3569785fe93SJed Brown                               problem->ics.qfunction_loc,
357a515125bSLeila Ghaffari                               &ceed_data->qf_ics);
35815a3537eSJed Brown   CeedQFunctionSetContext(ceed_data->qf_ics, problem->ics.qfunction_context);
35915a3537eSJed Brown   CeedQFunctionContextDestroy(&problem->ics.qfunction_context);
360a515125bSLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_ics, "x", num_comp_x, CEED_EVAL_INTERP);
361a515125bSLeila Ghaffari   CeedQFunctionAddOutput(ceed_data->qf_ics, "q0", num_comp_q, CEED_EVAL_NONE);
362a515125bSLeila Ghaffari 
363a515125bSLeila Ghaffari   // -- Create QFunction for RHS
3649785fe93SJed Brown   if (problem->apply_vol_rhs.qfunction) {
3659785fe93SJed Brown     CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_rhs.qfunction,
3669785fe93SJed Brown                                 problem->apply_vol_rhs.qfunction_loc, &ceed_data->qf_rhs_vol);
36715a3537eSJed Brown     CeedQFunctionSetContext(ceed_data->qf_rhs_vol,
36815a3537eSJed Brown                             problem->apply_vol_rhs.qfunction_context);
36915a3537eSJed Brown     CeedQFunctionContextDestroy(&problem->apply_vol_rhs.qfunction_context);
370a515125bSLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "q", num_comp_q, CEED_EVAL_INTERP);
371752f40e3SJed Brown     CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "Grad_q", num_comp_q*dim,
372a515125bSLeila Ghaffari                           CEED_EVAL_GRAD);
3733b1e209bSJeremy L Thompson     CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "qdata", q_data_size_vol,
374a515125bSLeila Ghaffari                           CEED_EVAL_NONE);
375a515125bSLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "x", num_comp_x, CEED_EVAL_INTERP);
376a515125bSLeila Ghaffari     CeedQFunctionAddOutput(ceed_data->qf_rhs_vol, "v", num_comp_q,
377a515125bSLeila Ghaffari                            CEED_EVAL_INTERP);
378752f40e3SJed Brown     CeedQFunctionAddOutput(ceed_data->qf_rhs_vol, "Grad_v", num_comp_q*dim,
379a515125bSLeila Ghaffari                            CEED_EVAL_GRAD);
380a515125bSLeila Ghaffari   }
381a515125bSLeila Ghaffari 
382a515125bSLeila Ghaffari   // -- Create QFunction for IFunction
3839785fe93SJed Brown   if (problem->apply_vol_ifunction.qfunction) {
3849785fe93SJed Brown     CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_ifunction.qfunction,
3859785fe93SJed Brown                                 problem->apply_vol_ifunction.qfunction_loc, &ceed_data->qf_ifunction_vol);
38615a3537eSJed Brown     CeedQFunctionSetContext(ceed_data->qf_ifunction_vol,
38715a3537eSJed Brown                             problem->apply_vol_ifunction.qfunction_context);
38815a3537eSJed Brown     CeedQFunctionContextDestroy(&problem->apply_vol_ifunction.qfunction_context);
389a515125bSLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "q", num_comp_q,
390a515125bSLeila Ghaffari                           CEED_EVAL_INTERP);
391752f40e3SJed Brown     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "Grad_q", num_comp_q*dim,
392a515125bSLeila Ghaffari                           CEED_EVAL_GRAD);
3933b1e209bSJeremy L Thompson     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "q dot", num_comp_q,
394a515125bSLeila Ghaffari                           CEED_EVAL_INTERP);
3953b1e209bSJeremy L Thompson     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "qdata", q_data_size_vol,
396a515125bSLeila Ghaffari                           CEED_EVAL_NONE);
397a515125bSLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "x", num_comp_x,
398a515125bSLeila Ghaffari                           CEED_EVAL_INTERP);
399a515125bSLeila Ghaffari     CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "v", num_comp_q,
400a515125bSLeila Ghaffari                            CEED_EVAL_INTERP);
401752f40e3SJed Brown     CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "Grad_v", num_comp_q*dim,
402a515125bSLeila Ghaffari                            CEED_EVAL_GRAD);
403752f40e3SJed Brown     CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "jac_data",
404752f40e3SJed Brown                            jac_data_size_vol, CEED_EVAL_NONE);
405a515125bSLeila Ghaffari   }
406a515125bSLeila Ghaffari 
407f0b65372SJed Brown   CeedQFunction qf_ijacobian_vol = NULL;
408f0b65372SJed Brown   if (problem->apply_vol_ijacobian.qfunction) {
409f0b65372SJed Brown     CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_ijacobian.qfunction,
410f0b65372SJed Brown                                 problem->apply_vol_ijacobian.qfunction_loc, &qf_ijacobian_vol);
411f0b65372SJed Brown     CeedQFunctionSetContext(qf_ijacobian_vol,
412f0b65372SJed Brown                             problem->apply_vol_ijacobian.qfunction_context);
413f0b65372SJed Brown     CeedQFunctionContextDestroy(&problem->apply_vol_ijacobian.qfunction_context);
414f0b65372SJed Brown     CeedQFunctionAddInput(qf_ijacobian_vol, "dq", num_comp_q,
415f0b65372SJed Brown                           CEED_EVAL_INTERP);
416f0b65372SJed Brown     CeedQFunctionAddInput(qf_ijacobian_vol, "Grad_dq", num_comp_q*dim,
417f0b65372SJed Brown                           CEED_EVAL_GRAD);
418f0b65372SJed Brown     CeedQFunctionAddInput(qf_ijacobian_vol, "qdata", q_data_size_vol,
419f0b65372SJed Brown                           CEED_EVAL_NONE);
420f0b65372SJed Brown     CeedQFunctionAddInput(qf_ijacobian_vol, "x", num_comp_x,
421f0b65372SJed Brown                           CEED_EVAL_INTERP);
422f0b65372SJed Brown     CeedQFunctionAddInput(qf_ijacobian_vol, "jac_data",
423f0b65372SJed Brown                           jac_data_size_vol, CEED_EVAL_NONE);
424f0b65372SJed Brown     CeedQFunctionAddOutput(qf_ijacobian_vol, "v", num_comp_q,
425f0b65372SJed Brown                            CEED_EVAL_INTERP);
426f0b65372SJed Brown     CeedQFunctionAddOutput(qf_ijacobian_vol, "Grad_v", num_comp_q*dim,
427f0b65372SJed Brown                            CEED_EVAL_GRAD);
428f0b65372SJed Brown   }
429f0b65372SJed Brown 
430a515125bSLeila Ghaffari   // ---------------------------------------------------------------------------
431a515125bSLeila Ghaffari   // Element coordinates
432a515125bSLeila Ghaffari   // ---------------------------------------------------------------------------
433a515125bSLeila Ghaffari   // -- Create CEED vector
434a515125bSLeila Ghaffari   CeedElemRestrictionCreateVector(ceed_data->elem_restr_x, &ceed_data->x_coord,
435a515125bSLeila Ghaffari                                   NULL);
436a515125bSLeila Ghaffari 
437a515125bSLeila Ghaffari   // -- Copy PETSc vector in CEED vector
438a515125bSLeila Ghaffari   Vec               X_loc;
439a515125bSLeila Ghaffari   const PetscScalar *X_loc_array;
440a515125bSLeila Ghaffari   ierr = DMGetCoordinatesLocal(dm, &X_loc); CHKERRQ(ierr);
44105a512bdSLeila Ghaffari   ierr = VecScale(X_loc, problem->dm_scale); CHKERRQ(ierr);
442a515125bSLeila Ghaffari   ierr = VecGetArrayRead(X_loc, &X_loc_array); CHKERRQ(ierr);
443a515125bSLeila Ghaffari   CeedVectorSetArray(ceed_data->x_coord, CEED_MEM_HOST, CEED_COPY_VALUES,
444a515125bSLeila Ghaffari                      (PetscScalar *)X_loc_array);
445a515125bSLeila Ghaffari   ierr = VecRestoreArrayRead(X_loc, &X_loc_array); CHKERRQ(ierr);
446a515125bSLeila Ghaffari 
447a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
448a515125bSLeila Ghaffari   // CEED vectors
449a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
450a515125bSLeila Ghaffari   // -- Create CEED vector for geometric data
451a515125bSLeila Ghaffari   CeedInt  num_qpts_vol;
452a515125bSLeila Ghaffari   PetscInt loc_num_elem_vol;
453a515125bSLeila Ghaffari   CeedBasisGetNumQuadraturePoints(ceed_data->basis_q, &num_qpts_vol);
454a515125bSLeila Ghaffari   CeedElemRestrictionGetNumElements(ceed_data->elem_restr_q, &loc_num_elem_vol);
455a515125bSLeila Ghaffari   CeedVectorCreate(ceed, q_data_size_vol*loc_num_elem_vol*num_qpts_vol,
456a515125bSLeila Ghaffari                    &ceed_data->q_data);
457a515125bSLeila Ghaffari 
458752f40e3SJed Brown   CeedElemRestrictionCreateVector(elem_restr_jd_i, &jac_data, NULL);
459a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
460a515125bSLeila Ghaffari   // CEED Operators
461a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
462a515125bSLeila Ghaffari   // -- Create CEED operator for quadrature data
463a515125bSLeila Ghaffari   CeedOperatorCreate(ceed, ceed_data->qf_setup_vol, NULL, NULL,
464a515125bSLeila Ghaffari                      &ceed_data->op_setup_vol);
465a515125bSLeila Ghaffari   CeedOperatorSetField(ceed_data->op_setup_vol, "dx", ceed_data->elem_restr_x,
466a515125bSLeila Ghaffari                        ceed_data->basis_x, CEED_VECTOR_ACTIVE);
467a515125bSLeila Ghaffari   CeedOperatorSetField(ceed_data->op_setup_vol, "weight",
468139613f2SLeila Ghaffari                        CEED_ELEMRESTRICTION_NONE, ceed_data->basis_x, CEED_VECTOR_NONE);
4693b1e209bSJeremy L Thompson   CeedOperatorSetField(ceed_data->op_setup_vol, "qdata",
470139613f2SLeila Ghaffari                        ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE);
471a515125bSLeila Ghaffari 
472a515125bSLeila Ghaffari   // -- Create CEED operator for ICs
473a515125bSLeila Ghaffari   CeedOperatorCreate(ceed, ceed_data->qf_ics, NULL, NULL, &ceed_data->op_ics);
474a515125bSLeila Ghaffari   CeedOperatorSetField(ceed_data->op_ics, "x", ceed_data->elem_restr_x,
475a515125bSLeila Ghaffari                        ceed_data->basis_xc, CEED_VECTOR_ACTIVE);
476a515125bSLeila Ghaffari   CeedOperatorSetField(ceed_data->op_ics, "q0", ceed_data->elem_restr_q,
477a515125bSLeila Ghaffari                        CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE);
47815a3537eSJed Brown   CeedOperatorContextGetFieldLabel(ceed_data->op_ics, "evaluation time",
47915a3537eSJed Brown                                    &user->phys->ics_time_label);
480a515125bSLeila Ghaffari 
481a515125bSLeila Ghaffari   // Create CEED operator for RHS
482a515125bSLeila Ghaffari   if (ceed_data->qf_rhs_vol) {
483a515125bSLeila Ghaffari     CeedOperator op;
484a515125bSLeila Ghaffari     CeedOperatorCreate(ceed, ceed_data->qf_rhs_vol, NULL, NULL, &op);
485a515125bSLeila Ghaffari     CeedOperatorSetField(op, "q", ceed_data->elem_restr_q, ceed_data->basis_q,
486a515125bSLeila Ghaffari                          CEED_VECTOR_ACTIVE);
487752f40e3SJed Brown     CeedOperatorSetField(op, "Grad_q", ceed_data->elem_restr_q, ceed_data->basis_q,
488a515125bSLeila Ghaffari                          CEED_VECTOR_ACTIVE);
4893b1e209bSJeremy L Thompson     CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i,
490139613f2SLeila Ghaffari                          CEED_BASIS_COLLOCATED, ceed_data->q_data);
491a515125bSLeila Ghaffari     CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x,
492a515125bSLeila Ghaffari                          ceed_data->x_coord);
493a515125bSLeila Ghaffari     CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q,
494a515125bSLeila Ghaffari                          CEED_VECTOR_ACTIVE);
495752f40e3SJed Brown     CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q,
496a515125bSLeila Ghaffari                          CEED_VECTOR_ACTIVE);
497a515125bSLeila Ghaffari     user->op_rhs_vol = op;
498a515125bSLeila Ghaffari   }
499a515125bSLeila Ghaffari 
500a515125bSLeila Ghaffari   // -- CEED operator for IFunction
501a515125bSLeila Ghaffari   if (ceed_data->qf_ifunction_vol) {
502a515125bSLeila Ghaffari     CeedOperator op;
503a515125bSLeila Ghaffari     CeedOperatorCreate(ceed, ceed_data->qf_ifunction_vol, NULL, NULL, &op);
504a515125bSLeila Ghaffari     CeedOperatorSetField(op, "q", ceed_data->elem_restr_q, ceed_data->basis_q,
505a515125bSLeila Ghaffari                          CEED_VECTOR_ACTIVE);
506752f40e3SJed Brown     CeedOperatorSetField(op, "Grad_q", ceed_data->elem_restr_q, ceed_data->basis_q,
507a515125bSLeila Ghaffari                          CEED_VECTOR_ACTIVE);
5083b1e209bSJeremy L Thompson     CeedOperatorSetField(op, "q dot", ceed_data->elem_restr_q, ceed_data->basis_q,
509a515125bSLeila Ghaffari                          user->q_dot_ceed);
5103b1e209bSJeremy L Thompson     CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i,
511139613f2SLeila Ghaffari                          CEED_BASIS_COLLOCATED, ceed_data->q_data);
512a515125bSLeila Ghaffari     CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x,
513a515125bSLeila Ghaffari                          ceed_data->x_coord);
514a515125bSLeila Ghaffari     CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q,
515a515125bSLeila Ghaffari                          CEED_VECTOR_ACTIVE);
516752f40e3SJed Brown     CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q,
517a515125bSLeila Ghaffari                          CEED_VECTOR_ACTIVE);
518752f40e3SJed Brown     CeedOperatorSetField(op, "jac_data", elem_restr_jd_i,
519752f40e3SJed Brown                          CEED_BASIS_COLLOCATED, jac_data);
520752f40e3SJed Brown 
521a515125bSLeila Ghaffari     user->op_ifunction_vol = op;
522a515125bSLeila Ghaffari   }
523a515125bSLeila Ghaffari 
524f0b65372SJed Brown   CeedOperator op_ijacobian_vol = NULL;
525f0b65372SJed Brown   if (qf_ijacobian_vol) {
526f0b65372SJed Brown     CeedOperator op;
527f0b65372SJed Brown     CeedOperatorCreate(ceed, qf_ijacobian_vol, NULL, NULL, &op);
528f0b65372SJed Brown     CeedOperatorSetField(op, "dq", ceed_data->elem_restr_q, ceed_data->basis_q,
529f0b65372SJed Brown                          CEED_VECTOR_ACTIVE);
530f0b65372SJed Brown     CeedOperatorSetField(op, "Grad_dq", ceed_data->elem_restr_q, ceed_data->basis_q,
531f0b65372SJed Brown                          CEED_VECTOR_ACTIVE);
532f0b65372SJed Brown     CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i,
533f0b65372SJed Brown                          CEED_BASIS_COLLOCATED, ceed_data->q_data);
534f0b65372SJed Brown     CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x,
535f0b65372SJed Brown                          ceed_data->x_coord);
536f0b65372SJed Brown     CeedOperatorSetField(op, "jac_data", elem_restr_jd_i,
537f0b65372SJed Brown                          CEED_BASIS_COLLOCATED, jac_data);
538f0b65372SJed Brown     CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q,
539f0b65372SJed Brown                          CEED_VECTOR_ACTIVE);
540f0b65372SJed Brown     CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q,
541f0b65372SJed Brown                          CEED_VECTOR_ACTIVE);
542f0b65372SJed Brown     op_ijacobian_vol = op;
543f0b65372SJed Brown     CeedQFunctionDestroy(&qf_ijacobian_vol);
544f0b65372SJed Brown   }
545f0b65372SJed Brown 
546a515125bSLeila Ghaffari   // *****************************************************************************
547a515125bSLeila Ghaffari   // Set up CEED objects for the exterior domain (surface)
548a515125bSLeila Ghaffari   // *****************************************************************************
549a515125bSLeila Ghaffari   CeedInt height  = 1,
550a515125bSLeila Ghaffari           dim_sur = dim - height,
551a515125bSLeila Ghaffari           P_sur   = app_ctx->degree + 1,
552a515125bSLeila Ghaffari           Q_sur   = P_sur + app_ctx->q_extra;
553f0b65372SJed Brown   const CeedInt q_data_size_sur = problem->q_data_size_sur,
554f0b65372SJed Brown                 jac_data_size_sur = problem->jac_data_size_sur;
555a515125bSLeila Ghaffari 
556a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
557a515125bSLeila Ghaffari   // CEED Bases
558a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
559a515125bSLeila Ghaffari   CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_q, P_sur, Q_sur,
560a515125bSLeila Ghaffari                                   CEED_GAUSS, &ceed_data->basis_q_sur);
561a515125bSLeila Ghaffari   CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_x, 2, Q_sur, CEED_GAUSS,
562a515125bSLeila Ghaffari                                   &ceed_data->basis_x_sur);
563a515125bSLeila Ghaffari 
564a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
565a515125bSLeila Ghaffari   // CEED QFunctions
566a515125bSLeila Ghaffari   // -----------------------------------------------------------------------------
567a515125bSLeila Ghaffari   // -- Create QFunction for quadrature data
5689785fe93SJed Brown   CeedQFunctionCreateInterior(ceed, 1, problem->setup_sur.qfunction,
5699785fe93SJed Brown                               problem->setup_sur.qfunction_loc,
570a515125bSLeila Ghaffari                               &ceed_data->qf_setup_sur);
57115a3537eSJed Brown   if (problem->setup_sur.qfunction_context) {
57215a3537eSJed Brown     CeedQFunctionSetContext(ceed_data->qf_setup_sur,
57315a3537eSJed Brown                             problem->setup_sur.qfunction_context);
57415a3537eSJed Brown     CeedQFunctionContextDestroy(&problem->setup_sur.qfunction_context);
57515a3537eSJed Brown   }
576a515125bSLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_setup_sur, "dx", num_comp_x*dim_sur,
577a515125bSLeila Ghaffari                         CEED_EVAL_GRAD);
578a515125bSLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_setup_sur, "weight", 1, CEED_EVAL_WEIGHT);
5793b1e209bSJeremy L Thompson   CeedQFunctionAddOutput(ceed_data->qf_setup_sur, "surface qdata",
580002797a3SLeila Ghaffari                          q_data_size_sur, CEED_EVAL_NONE);
581a515125bSLeila Ghaffari 
582002797a3SLeila Ghaffari   // -- Creat QFunction for inflow boundaries
5839785fe93SJed Brown   if (problem->apply_inflow.qfunction) {
5849785fe93SJed Brown     CeedQFunctionCreateInterior(ceed, 1, problem->apply_inflow.qfunction,
5859785fe93SJed Brown                                 problem->apply_inflow.qfunction_loc, &ceed_data->qf_apply_inflow);
58615a3537eSJed Brown     CeedQFunctionSetContext(ceed_data->qf_apply_inflow,
58715a3537eSJed Brown                             problem->apply_inflow.qfunction_context);
58815a3537eSJed Brown     CeedQFunctionContextDestroy(&problem->apply_inflow.qfunction_context);
589002797a3SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_apply_inflow, "q", num_comp_q,
590a515125bSLeila Ghaffari                           CEED_EVAL_INTERP);
591*dd64951cSJames Wright     CeedQFunctionAddInput(ceed_data->qf_apply_inflow, "Grad_q", num_comp_q*(dim-1),
592*dd64951cSJames Wright                           CEED_EVAL_GRAD);
593002797a3SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_apply_inflow, "surface qdata",
594002797a3SLeila Ghaffari                           q_data_size_sur, CEED_EVAL_NONE);
595002797a3SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_apply_inflow, "x", num_comp_x,
596a515125bSLeila Ghaffari                           CEED_EVAL_INTERP);
597002797a3SLeila Ghaffari     CeedQFunctionAddOutput(ceed_data->qf_apply_inflow, "v", num_comp_q,
598002797a3SLeila Ghaffari                            CEED_EVAL_INTERP);
599002797a3SLeila Ghaffari   }
600f0b65372SJed Brown   if (problem->apply_inflow_jacobian.qfunction) {
601f0b65372SJed Brown     CeedQFunctionCreateInterior(ceed, 1, problem->apply_inflow_jacobian.qfunction,
602f0b65372SJed Brown                                 problem->apply_inflow_jacobian.qfunction_loc,
603f0b65372SJed Brown                                 &ceed_data->qf_apply_inflow_jacobian);
604f0b65372SJed Brown     CeedQFunctionSetContext(ceed_data->qf_apply_inflow_jacobian,
605f0b65372SJed Brown                             problem->apply_inflow_jacobian.qfunction_context);
606f0b65372SJed Brown     CeedQFunctionContextDestroy(&problem->apply_inflow_jacobian.qfunction_context);
607f0b65372SJed Brown     CeedQFunctionAddInput(ceed_data->qf_apply_inflow_jacobian, "dq", num_comp_q,
608f0b65372SJed Brown                           CEED_EVAL_INTERP);
609f0b65372SJed Brown     CeedQFunctionAddInput(ceed_data->qf_apply_inflow_jacobian, "surface qdata",
610f0b65372SJed Brown                           q_data_size_sur, CEED_EVAL_NONE);
611f0b65372SJed Brown     CeedQFunctionAddInput(ceed_data->qf_apply_inflow_jacobian, "x", num_comp_x,
612f0b65372SJed Brown                           CEED_EVAL_INTERP);
613f0b65372SJed Brown     CeedQFunctionAddOutput(ceed_data->qf_apply_inflow_jacobian, "v", num_comp_q,
614f0b65372SJed Brown                            CEED_EVAL_INTERP);
615f0b65372SJed Brown   }
616002797a3SLeila Ghaffari 
617002797a3SLeila Ghaffari   // -- Creat QFunction for outflow boundaries
6189785fe93SJed Brown   if (problem->apply_outflow.qfunction) {
6199785fe93SJed Brown     CeedQFunctionCreateInterior(ceed, 1, problem->apply_outflow.qfunction,
6209785fe93SJed Brown                                 problem->apply_outflow.qfunction_loc, &ceed_data->qf_apply_outflow);
62115a3537eSJed Brown     CeedQFunctionSetContext(ceed_data->qf_apply_outflow,
62215a3537eSJed Brown                             problem->apply_outflow.qfunction_context);
62315a3537eSJed Brown     CeedQFunctionContextDestroy(&problem->apply_outflow.qfunction_context);
624002797a3SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_apply_outflow, "q", num_comp_q,
625002797a3SLeila Ghaffari                           CEED_EVAL_INTERP);
626*dd64951cSJames Wright     CeedQFunctionAddInput(ceed_data->qf_apply_outflow, "Grad_q", num_comp_q*(dim-1),
627*dd64951cSJames Wright                           CEED_EVAL_GRAD);
628002797a3SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_apply_outflow, "surface qdata",
629002797a3SLeila Ghaffari                           q_data_size_sur, CEED_EVAL_NONE);
630002797a3SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_apply_outflow, "x", num_comp_x,
631002797a3SLeila Ghaffari                           CEED_EVAL_INTERP);
632002797a3SLeila Ghaffari     CeedQFunctionAddOutput(ceed_data->qf_apply_outflow, "v", num_comp_q,
633a515125bSLeila Ghaffari                            CEED_EVAL_INTERP);
6342556a851SJed Brown     if (jac_data_size_sur)
635f0b65372SJed Brown       CeedQFunctionAddOutput(ceed_data->qf_apply_outflow, "surface jacobian data",
636f0b65372SJed Brown                              jac_data_size_sur,
637f0b65372SJed Brown                              CEED_EVAL_NONE);
638f0b65372SJed Brown   }
639f0b65372SJed Brown   if (problem->apply_outflow_jacobian.qfunction) {
640f0b65372SJed Brown     CeedQFunctionCreateInterior(ceed, 1, problem->apply_outflow_jacobian.qfunction,
641f0b65372SJed Brown                                 problem->apply_outflow_jacobian.qfunction_loc,
642f0b65372SJed Brown                                 &ceed_data->qf_apply_outflow_jacobian);
643f0b65372SJed Brown     CeedQFunctionSetContext(ceed_data->qf_apply_outflow_jacobian,
644f0b65372SJed Brown                             problem->apply_outflow_jacobian.qfunction_context);
645f0b65372SJed Brown     CeedQFunctionContextDestroy(&problem->apply_outflow_jacobian.qfunction_context);
646f0b65372SJed Brown     CeedQFunctionAddInput(ceed_data->qf_apply_outflow_jacobian, "dq", num_comp_q,
647f0b65372SJed Brown                           CEED_EVAL_INTERP);
648f0b65372SJed Brown     CeedQFunctionAddInput(ceed_data->qf_apply_outflow_jacobian, "surface qdata",
649f0b65372SJed Brown                           q_data_size_sur, CEED_EVAL_NONE);
650f0b65372SJed Brown     CeedQFunctionAddInput(ceed_data->qf_apply_outflow_jacobian,
651f0b65372SJed Brown                           "surface jacobian data",
652f0b65372SJed Brown                           jac_data_size_sur, CEED_EVAL_NONE);
653f0b65372SJed Brown     CeedQFunctionAddOutput(ceed_data->qf_apply_outflow_jacobian, "v", num_comp_q,
654f0b65372SJed Brown                            CEED_EVAL_INTERP);
655a515125bSLeila Ghaffari   }
656a515125bSLeila Ghaffari 
657a515125bSLeila Ghaffari   // *****************************************************************************
658a515125bSLeila Ghaffari   // CEED Operator Apply
659a515125bSLeila Ghaffari   // *****************************************************************************
660a515125bSLeila Ghaffari   // -- Apply CEED Operator for the geometric data
661a515125bSLeila Ghaffari   CeedOperatorApply(ceed_data->op_setup_vol, ceed_data->x_coord,
662a515125bSLeila Ghaffari                     ceed_data->q_data, CEED_REQUEST_IMMEDIATE);
663a515125bSLeila Ghaffari 
664a515125bSLeila Ghaffari   // -- Create and apply CEED Composite Operator for the entire domain
665a515125bSLeila Ghaffari   if (!user->phys->implicit) { // RHS
666a515125bSLeila Ghaffari     ierr = CreateOperatorForDomain(ceed, dm, bc, ceed_data, user->phys,
667f0b65372SJed Brown                                    user->op_rhs_vol, NULL, height, P_sur, Q_sur,
668f0b65372SJed Brown                                    q_data_size_sur, 0,
669f0b65372SJed Brown                                    &user->op_rhs, NULL); CHKERRQ(ierr);
670a515125bSLeila Ghaffari   } else { // IFunction
671a515125bSLeila Ghaffari     ierr = CreateOperatorForDomain(ceed, dm, bc, ceed_data, user->phys,
672f0b65372SJed Brown                                    user->op_ifunction_vol, op_ijacobian_vol,
673f0b65372SJed Brown                                    height, P_sur, Q_sur,
674f0b65372SJed Brown                                    q_data_size_sur, jac_data_size_sur,
675f0b65372SJed Brown                                    &user->op_ifunction,
676f0b65372SJed Brown                                    op_ijacobian_vol ? &user->op_ijacobian : NULL); CHKERRQ(ierr);
677f0b65372SJed Brown     if (user->op_ijacobian) {
678f0b65372SJed Brown       CeedOperatorContextGetFieldLabel(user->op_ijacobian, "ijacobian time shift",
679f0b65372SJed Brown                                        &user->phys->ijacobian_time_shift_label);
680f0b65372SJed Brown     }
681f0b65372SJed Brown 
682a515125bSLeila Ghaffari   }
683752f40e3SJed Brown   CeedElemRestrictionDestroy(&elem_restr_jd_i);
684e22e0f1cSLeila Ghaffari   CeedOperatorDestroy(&op_ijacobian_vol);
685752f40e3SJed Brown   CeedVectorDestroy(&jac_data);
686a515125bSLeila Ghaffari   PetscFunctionReturn(0);
687a515125bSLeila Ghaffari }
688