xref: /libCEED/examples/fluids/src/setuplibceed.c (revision e334ad8fca0b75b5d678f79cfd10f4127eb21e08)
13d8e8822SJeremy L Thompson // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
23d8e8822SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
377841947SLeila Ghaffari //
43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
577841947SLeila Ghaffari //
63d8e8822SJeremy L Thompson // This file is part of CEED:  http://github.com/ceed
777841947SLeila Ghaffari 
877841947SLeila Ghaffari /// @file
977841947SLeila Ghaffari /// Setup libCEED for Navier-Stokes example using PETSc
1077841947SLeila Ghaffari 
1177841947SLeila Ghaffari #include "../navierstokes.h"
1277841947SLeila Ghaffari 
1377841947SLeila Ghaffari // Utility function - essential BC dofs are encoded in closure indices as -(i+1).
1477841947SLeila Ghaffari PetscInt Involute(PetscInt i) {
1577841947SLeila Ghaffari   return i >= 0 ? i : -(i+1);
1677841947SLeila Ghaffari }
1777841947SLeila Ghaffari 
1877841947SLeila Ghaffari // Utility function to create local CEED restriction
197ed3e4cdSJeremy L Thompson PetscErrorCode CreateRestrictionFromPlex(Ceed ceed, DM dm, CeedInt height,
207ed3e4cdSJeremy L Thompson     DMLabel domain_label, CeedInt value, CeedElemRestriction *elem_restr) {
217ed3e4cdSJeremy L Thompson   PetscInt num_elem, elem_size, num_dof, num_comp, *elem_restr_offsets;
2277841947SLeila Ghaffari   PetscErrorCode ierr;
237ed3e4cdSJeremy L Thompson 
2477841947SLeila Ghaffari   PetscFunctionBeginUser;
257ed3e4cdSJeremy L Thompson   ierr = DMPlexGetLocalOffsets(dm, domain_label, value, height, 0, &num_elem,
267ed3e4cdSJeremy L Thompson                                &elem_size, &num_comp, &num_dof, &elem_restr_offsets);
277ed3e4cdSJeremy L Thompson   CHKERRQ(ierr);
2877841947SLeila Ghaffari 
297ed3e4cdSJeremy L Thompson   CeedElemRestrictionCreate(ceed, num_elem, elem_size, num_comp,
307ed3e4cdSJeremy L Thompson                             1, num_dof, CEED_MEM_HOST, CEED_COPY_VALUES,
317ed3e4cdSJeremy L Thompson                             elem_restr_offsets, elem_restr);
327ed3e4cdSJeremy L Thompson   ierr = PetscFree(elem_restr_offsets); CHKERRQ(ierr);
3377841947SLeila Ghaffari 
3477841947SLeila Ghaffari   PetscFunctionReturn(0);
3577841947SLeila Ghaffari }
3677841947SLeila Ghaffari 
3777841947SLeila Ghaffari // Utility function to get Ceed Restriction for each domain
3877841947SLeila Ghaffari PetscErrorCode GetRestrictionForDomain(Ceed ceed, DM dm, CeedInt height,
3977841947SLeila Ghaffari                                        DMLabel domain_label, PetscInt value,
407ed3e4cdSJeremy L Thompson                                        CeedInt Q, CeedInt q_data_size,
4177841947SLeila Ghaffari                                        CeedElemRestriction *elem_restr_q,
4277841947SLeila Ghaffari                                        CeedElemRestriction *elem_restr_x,
4377841947SLeila Ghaffari                                        CeedElemRestriction *elem_restr_qd_i) {
4477841947SLeila Ghaffari   DM             dm_coord;
4577841947SLeila Ghaffari   CeedInt        dim, loc_num_elem;
4677841947SLeila Ghaffari   CeedInt        Q_dim;
472534dcc8SJed Brown   CeedElemRestriction elem_restr_tmp;
4877841947SLeila Ghaffari   PetscErrorCode ierr;
4977841947SLeila Ghaffari   PetscFunctionBeginUser;
5077841947SLeila Ghaffari 
5177841947SLeila Ghaffari   ierr = DMGetDimension(dm, &dim); CHKERRQ(ierr);
5277841947SLeila Ghaffari   dim -= height;
5377841947SLeila Ghaffari   Q_dim = CeedIntPow(Q, dim);
542534dcc8SJed Brown   ierr = CreateRestrictionFromPlex(ceed, dm, height, domain_label, value,
552534dcc8SJed Brown                                    &elem_restr_tmp);
562534dcc8SJed Brown   CHKERRQ(ierr);
572534dcc8SJed Brown   if (elem_restr_q) *elem_restr_q = elem_restr_tmp;
582534dcc8SJed Brown   if (elem_restr_x) {
5977841947SLeila Ghaffari     ierr = DMGetCoordinateDM(dm, &dm_coord); CHKERRQ(ierr);
6077841947SLeila Ghaffari     ierr = DMPlexSetClosurePermutationTensor(dm_coord, PETSC_DETERMINE, NULL);
6177841947SLeila Ghaffari     CHKERRQ(ierr);
627ed3e4cdSJeremy L Thompson     ierr = CreateRestrictionFromPlex(ceed, dm_coord, height, domain_label, value,
637ed3e4cdSJeremy L Thompson                                      elem_restr_x);
647ed3e4cdSJeremy L Thompson     CHKERRQ(ierr);
652534dcc8SJed Brown   }
662534dcc8SJed Brown   if (elem_restr_qd_i) {
672534dcc8SJed Brown     CeedElemRestrictionGetNumElements(elem_restr_tmp, &loc_num_elem);
6877841947SLeila Ghaffari     CeedElemRestrictionCreateStrided(ceed, loc_num_elem, Q_dim,
6977841947SLeila Ghaffari                                      q_data_size, q_data_size*loc_num_elem*Q_dim,
7077841947SLeila Ghaffari                                      CEED_STRIDES_BACKEND, elem_restr_qd_i);
712534dcc8SJed Brown   }
722534dcc8SJed Brown   if (!elem_restr_q) CeedElemRestrictionDestroy(&elem_restr_tmp);
7377841947SLeila Ghaffari   PetscFunctionReturn(0);
7477841947SLeila Ghaffari }
7577841947SLeila Ghaffari 
7677841947SLeila Ghaffari // Utility function to create CEED Composite Operator for the entire domain
7777841947SLeila Ghaffari PetscErrorCode CreateOperatorForDomain(Ceed ceed, DM dm, SimpleBC bc,
7877841947SLeila Ghaffari                                        CeedData ceed_data, Physics phys,
79*e334ad8fSJed Brown                                        CeedOperator op_apply_vol,
80*e334ad8fSJed Brown                                        CeedOperator op_apply_ijacobian_vol,
81*e334ad8fSJed Brown                                        CeedInt height,
82*e334ad8fSJed Brown                                        CeedInt P_sur, CeedInt Q_sur,
83*e334ad8fSJed Brown                                        CeedInt q_data_size_sur, CeedInt jac_data_size_sur,
84*e334ad8fSJed Brown                                        CeedOperator *op_apply, CeedOperator *op_apply_ijacobian) {
852fe7aee7SLeila Ghaffari   //CeedInt        dim;
8677841947SLeila Ghaffari   DMLabel        domain_label;
8777841947SLeila Ghaffari   PetscErrorCode ierr;
8877841947SLeila Ghaffari   PetscFunctionBeginUser;
8977841947SLeila Ghaffari 
9077841947SLeila Ghaffari   // Create Composite Operaters
9177841947SLeila Ghaffari   CeedCompositeOperatorCreate(ceed, op_apply);
92*e334ad8fSJed Brown   if (op_apply_ijacobian)
93*e334ad8fSJed Brown     CeedCompositeOperatorCreate(ceed, op_apply_ijacobian);
9477841947SLeila Ghaffari 
9577841947SLeila Ghaffari   // --Apply Sub-Operator for the volume
9677841947SLeila Ghaffari   CeedCompositeOperatorAddSub(*op_apply, op_apply_vol);
97*e334ad8fSJed Brown   if (op_apply_ijacobian)
98*e334ad8fSJed Brown     CeedCompositeOperatorAddSub(*op_apply_ijacobian, op_apply_ijacobian_vol);
9977841947SLeila Ghaffari 
10077841947SLeila Ghaffari   // -- Create Sub-Operator for in/outflow BCs
10188626eedSJames Wright   if (phys->has_neumann || 1) {
10277841947SLeila Ghaffari     // --- Setup
10377841947SLeila Ghaffari     ierr = DMGetLabel(dm, "Face Sets", &domain_label); CHKERRQ(ierr);
1042fe7aee7SLeila Ghaffari     //ierr = DMGetDimension(dm, &dim); CHKERRQ(ierr);
10577841947SLeila Ghaffari 
10677841947SLeila Ghaffari     // --- Get number of quadrature points for the boundaries
10777841947SLeila Ghaffari     CeedInt num_qpts_sur;
10877841947SLeila Ghaffari     CeedBasisGetNumQuadraturePoints(ceed_data->basis_q_sur, &num_qpts_sur);
10977841947SLeila Ghaffari 
1102fe7aee7SLeila Ghaffari     // --- Create Sub-Operator for inflow boundaries
1112fe7aee7SLeila Ghaffari     for (CeedInt i=0; i < bc->num_inflow; i++) {
11277841947SLeila Ghaffari       CeedVector          q_data_sur;
113*e334ad8fSJed Brown       CeedOperator        op_setup_sur, op_apply_inflow,
114*e334ad8fSJed Brown                           op_apply_inflow_jacobian = NULL;
1152fe7aee7SLeila Ghaffari       CeedElemRestriction elem_restr_x_sur, elem_restr_q_sur, elem_restr_qd_i_sur;
11677841947SLeila Ghaffari 
11777841947SLeila Ghaffari       // ---- CEED Restriction
1182fe7aee7SLeila Ghaffari       ierr = GetRestrictionForDomain(ceed, dm, height, domain_label, bc->inflows[i],
1192fe7aee7SLeila Ghaffari                                      Q_sur, q_data_size_sur, &elem_restr_q_sur, &elem_restr_x_sur,
1202fe7aee7SLeila Ghaffari                                      &elem_restr_qd_i_sur);
12177841947SLeila Ghaffari       CHKERRQ(ierr);
12277841947SLeila Ghaffari 
12377841947SLeila Ghaffari       // ---- CEED Vector
12477841947SLeila Ghaffari       PetscInt loc_num_elem_sur;
12577841947SLeila Ghaffari       CeedElemRestrictionGetNumElements(elem_restr_q_sur, &loc_num_elem_sur);
12677841947SLeila Ghaffari       CeedVectorCreate(ceed, q_data_size_sur*loc_num_elem_sur*num_qpts_sur,
12777841947SLeila Ghaffari                        &q_data_sur);
12877841947SLeila Ghaffari 
12977841947SLeila Ghaffari       // ---- CEED Operator
13077841947SLeila Ghaffari       // ----- CEED Operator for Setup (geometric factors)
13177841947SLeila Ghaffari       CeedOperatorCreate(ceed, ceed_data->qf_setup_sur, NULL, NULL, &op_setup_sur);
13277841947SLeila Ghaffari       CeedOperatorSetField(op_setup_sur, "dx", elem_restr_x_sur,
133e6225c47SLeila Ghaffari                            ceed_data->basis_x_sur, CEED_VECTOR_ACTIVE);
13477841947SLeila Ghaffari       CeedOperatorSetField(op_setup_sur, "weight", CEED_ELEMRESTRICTION_NONE,
13577841947SLeila Ghaffari                            ceed_data->basis_x_sur, CEED_VECTOR_NONE);
136a61c78d6SJeremy L Thompson       CeedOperatorSetField(op_setup_sur, "surface qdata", elem_restr_qd_i_sur,
13777841947SLeila Ghaffari                            CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE);
13877841947SLeila Ghaffari 
13977841947SLeila Ghaffari       // ----- CEED Operator for Physics
1402fe7aee7SLeila Ghaffari       CeedOperatorCreate(ceed, ceed_data->qf_apply_inflow, NULL, NULL,
1412fe7aee7SLeila Ghaffari                          &op_apply_inflow);
1422fe7aee7SLeila Ghaffari       CeedOperatorSetField(op_apply_inflow, "q", elem_restr_q_sur,
14377841947SLeila Ghaffari                            ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
1442fe7aee7SLeila Ghaffari       CeedOperatorSetField(op_apply_inflow, "surface qdata", elem_restr_qd_i_sur,
14577841947SLeila Ghaffari                            CEED_BASIS_COLLOCATED, q_data_sur);
1462fe7aee7SLeila Ghaffari       CeedOperatorSetField(op_apply_inflow, "x", elem_restr_x_sur,
14777841947SLeila Ghaffari                            ceed_data->basis_x_sur, ceed_data->x_coord);
1482fe7aee7SLeila Ghaffari       CeedOperatorSetField(op_apply_inflow, "v", elem_restr_q_sur,
14977841947SLeila Ghaffari                            ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
15077841947SLeila Ghaffari 
151*e334ad8fSJed Brown       if (ceed_data->qf_apply_inflow_jacobian) {
152*e334ad8fSJed Brown         CeedOperatorCreate(ceed, ceed_data->qf_apply_inflow_jacobian, NULL, NULL,
153*e334ad8fSJed Brown                            &op_apply_inflow_jacobian);
154*e334ad8fSJed Brown         CeedOperatorSetField(op_apply_inflow_jacobian, "dq", elem_restr_q_sur,
155*e334ad8fSJed Brown                              ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
156*e334ad8fSJed Brown         CeedOperatorSetField(op_apply_inflow_jacobian, "surface qdata",
157*e334ad8fSJed Brown                              elem_restr_qd_i_sur,
158*e334ad8fSJed Brown                              CEED_BASIS_COLLOCATED, q_data_sur);
159*e334ad8fSJed Brown         CeedOperatorSetField(op_apply_inflow_jacobian, "x", elem_restr_x_sur,
160*e334ad8fSJed Brown                              ceed_data->basis_x_sur, ceed_data->x_coord);
161*e334ad8fSJed Brown         CeedOperatorSetField(op_apply_inflow_jacobian, "v", elem_restr_q_sur,
162*e334ad8fSJed Brown                              ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
163*e334ad8fSJed Brown       }
164*e334ad8fSJed Brown 
16577841947SLeila Ghaffari       // ----- Apply CEED operator for Setup
16677841947SLeila Ghaffari       CeedOperatorApply(op_setup_sur, ceed_data->x_coord, q_data_sur,
16777841947SLeila Ghaffari                         CEED_REQUEST_IMMEDIATE);
16877841947SLeila Ghaffari 
1692fe7aee7SLeila Ghaffari       // ----- Apply Sub-Operator for Physics
1702fe7aee7SLeila Ghaffari       CeedCompositeOperatorAddSub(*op_apply, op_apply_inflow);
171*e334ad8fSJed Brown       if (op_apply_ijacobian)
172*e334ad8fSJed Brown         CeedCompositeOperatorAddSub(*op_apply_ijacobian, op_apply_inflow_jacobian);
17377841947SLeila Ghaffari 
17477841947SLeila Ghaffari       // ----- Cleanup
17577841947SLeila Ghaffari       CeedVectorDestroy(&q_data_sur);
17677841947SLeila Ghaffari       CeedElemRestrictionDestroy(&elem_restr_q_sur);
17777841947SLeila Ghaffari       CeedElemRestrictionDestroy(&elem_restr_x_sur);
17877841947SLeila Ghaffari       CeedElemRestrictionDestroy(&elem_restr_qd_i_sur);
17977841947SLeila Ghaffari       CeedOperatorDestroy(&op_setup_sur);
1802fe7aee7SLeila Ghaffari       CeedOperatorDestroy(&op_apply_inflow);
181*e334ad8fSJed Brown       CeedOperatorDestroy(&op_apply_inflow_jacobian);
18277841947SLeila Ghaffari     }
18377841947SLeila Ghaffari 
1842fe7aee7SLeila Ghaffari     // --- Create Sub-Operator for outflow boundaries
1852fe7aee7SLeila Ghaffari     for (CeedInt i=0; i < bc->num_outflow; i++) {
186*e334ad8fSJed Brown       CeedVector          q_data_sur, jac_data_sur;
187*e334ad8fSJed Brown       CeedOperator        op_setup_sur, op_apply_outflow,
188*e334ad8fSJed Brown                           op_apply_outflow_jacobian = NULL;
189*e334ad8fSJed Brown       CeedElemRestriction elem_restr_x_sur, elem_restr_q_sur, elem_restr_qd_i_sur,
190*e334ad8fSJed Brown                           elem_restr_jd_i_sur;
1912fe7aee7SLeila Ghaffari 
1922fe7aee7SLeila Ghaffari       // ---- CEED Restriction
1932fe7aee7SLeila Ghaffari       ierr = GetRestrictionForDomain(ceed, dm, height, domain_label, bc->outflows[i],
1942fe7aee7SLeila Ghaffari                                      Q_sur, q_data_size_sur, &elem_restr_q_sur, &elem_restr_x_sur,
1952fe7aee7SLeila Ghaffari                                      &elem_restr_qd_i_sur);
1962fe7aee7SLeila Ghaffari       CHKERRQ(ierr);
197*e334ad8fSJed Brown       ierr = GetRestrictionForDomain(ceed, dm, height, domain_label, bc->outflows[i],
198*e334ad8fSJed Brown                                      Q_sur, jac_data_size_sur, NULL, NULL,
199*e334ad8fSJed Brown                                      &elem_restr_jd_i_sur);
200*e334ad8fSJed Brown       CHKERRQ(ierr);
2012fe7aee7SLeila Ghaffari 
2022fe7aee7SLeila Ghaffari       // ---- CEED Vector
2032fe7aee7SLeila Ghaffari       PetscInt loc_num_elem_sur;
2042fe7aee7SLeila Ghaffari       CeedElemRestrictionGetNumElements(elem_restr_q_sur, &loc_num_elem_sur);
2052fe7aee7SLeila Ghaffari       CeedVectorCreate(ceed, q_data_size_sur*loc_num_elem_sur*num_qpts_sur,
2062fe7aee7SLeila Ghaffari                        &q_data_sur);
2072fe7aee7SLeila Ghaffari 
208*e334ad8fSJed Brown       CeedElemRestrictionCreateVector(elem_restr_jd_i_sur, &jac_data_sur, NULL);
209*e334ad8fSJed Brown 
2102fe7aee7SLeila Ghaffari       // ---- CEED Operator
2112fe7aee7SLeila Ghaffari       // ----- CEED Operator for Setup (geometric factors)
2122fe7aee7SLeila Ghaffari       CeedOperatorCreate(ceed, ceed_data->qf_setup_sur, NULL, NULL, &op_setup_sur);
2132fe7aee7SLeila Ghaffari       CeedOperatorSetField(op_setup_sur, "dx", elem_restr_x_sur,
2142fe7aee7SLeila Ghaffari                            ceed_data->basis_x_sur, CEED_VECTOR_ACTIVE);
2152fe7aee7SLeila Ghaffari       CeedOperatorSetField(op_setup_sur, "weight", CEED_ELEMRESTRICTION_NONE,
2162fe7aee7SLeila Ghaffari                            ceed_data->basis_x_sur, CEED_VECTOR_NONE);
2172fe7aee7SLeila Ghaffari       CeedOperatorSetField(op_setup_sur, "surface qdata", elem_restr_qd_i_sur,
2182fe7aee7SLeila Ghaffari                            CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE);
2192fe7aee7SLeila Ghaffari 
2202fe7aee7SLeila Ghaffari       // ----- CEED Operator for Physics
2212fe7aee7SLeila Ghaffari       CeedOperatorCreate(ceed, ceed_data->qf_apply_outflow, NULL, NULL,
2222fe7aee7SLeila Ghaffari                          &op_apply_outflow);
2232fe7aee7SLeila Ghaffari       CeedOperatorSetField(op_apply_outflow, "q", elem_restr_q_sur,
2242fe7aee7SLeila Ghaffari                            ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
2252fe7aee7SLeila Ghaffari       CeedOperatorSetField(op_apply_outflow, "surface qdata", elem_restr_qd_i_sur,
2262fe7aee7SLeila Ghaffari                            CEED_BASIS_COLLOCATED, q_data_sur);
2272fe7aee7SLeila Ghaffari       CeedOperatorSetField(op_apply_outflow, "x", elem_restr_x_sur,
2282fe7aee7SLeila Ghaffari                            ceed_data->basis_x_sur, ceed_data->x_coord);
2292fe7aee7SLeila Ghaffari       CeedOperatorSetField(op_apply_outflow, "v", elem_restr_q_sur,
2302fe7aee7SLeila Ghaffari                            ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
231*e334ad8fSJed Brown       CeedOperatorSetField(op_apply_outflow, "surface jacobian data",
232*e334ad8fSJed Brown                            elem_restr_jd_i_sur,
233*e334ad8fSJed Brown                            CEED_BASIS_COLLOCATED, jac_data_sur);
234*e334ad8fSJed Brown 
235*e334ad8fSJed Brown       if (ceed_data->qf_apply_outflow_jacobian) {
236*e334ad8fSJed Brown         CeedOperatorCreate(ceed, ceed_data->qf_apply_outflow_jacobian, NULL, NULL,
237*e334ad8fSJed Brown                            &op_apply_outflow_jacobian);
238*e334ad8fSJed Brown         CeedOperatorSetField(op_apply_outflow_jacobian, "dq", elem_restr_q_sur,
239*e334ad8fSJed Brown                              ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
240*e334ad8fSJed Brown         CeedOperatorSetField(op_apply_outflow_jacobian, "surface qdata",
241*e334ad8fSJed Brown                              elem_restr_qd_i_sur,
242*e334ad8fSJed Brown                              CEED_BASIS_COLLOCATED, q_data_sur);
243*e334ad8fSJed Brown         CeedOperatorSetField(op_apply_outflow_jacobian, "surface jacobian data",
244*e334ad8fSJed Brown                              elem_restr_jd_i_sur,
245*e334ad8fSJed Brown                              CEED_BASIS_COLLOCATED, jac_data_sur);
246*e334ad8fSJed Brown         CeedOperatorSetField(op_apply_outflow_jacobian, "v", elem_restr_q_sur,
247*e334ad8fSJed Brown                              ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
248*e334ad8fSJed Brown       }
2492fe7aee7SLeila Ghaffari 
2502fe7aee7SLeila Ghaffari       // ----- Apply CEED operator for Setup
2512fe7aee7SLeila Ghaffari       CeedOperatorApply(op_setup_sur, ceed_data->x_coord, q_data_sur,
2522fe7aee7SLeila Ghaffari                         CEED_REQUEST_IMMEDIATE);
2532fe7aee7SLeila Ghaffari 
2542fe7aee7SLeila Ghaffari       // ----- Apply Sub-Operator for Physics
2552fe7aee7SLeila Ghaffari       CeedCompositeOperatorAddSub(*op_apply, op_apply_outflow);
256*e334ad8fSJed Brown       if (op_apply_ijacobian)
257*e334ad8fSJed Brown         CeedCompositeOperatorAddSub(*op_apply_ijacobian, op_apply_outflow_jacobian);
2582fe7aee7SLeila Ghaffari 
2592fe7aee7SLeila Ghaffari       // ----- Cleanup
2602fe7aee7SLeila Ghaffari       CeedVectorDestroy(&q_data_sur);
261*e334ad8fSJed Brown       CeedVectorDestroy(&jac_data_sur);
2622fe7aee7SLeila Ghaffari       CeedElemRestrictionDestroy(&elem_restr_q_sur);
2632fe7aee7SLeila Ghaffari       CeedElemRestrictionDestroy(&elem_restr_x_sur);
2642fe7aee7SLeila Ghaffari       CeedElemRestrictionDestroy(&elem_restr_qd_i_sur);
265*e334ad8fSJed Brown       CeedElemRestrictionDestroy(&elem_restr_jd_i_sur);
2662fe7aee7SLeila Ghaffari       CeedOperatorDestroy(&op_setup_sur);
2672fe7aee7SLeila Ghaffari       CeedOperatorDestroy(&op_apply_outflow);
268*e334ad8fSJed Brown       CeedOperatorDestroy(&op_apply_outflow_jacobian);
2692fe7aee7SLeila Ghaffari     }
2702fe7aee7SLeila Ghaffari   }
27111436a05SJames Wright 
27211436a05SJames Wright   // ----- Get Context Labels for Operator
27311436a05SJames Wright   CeedOperatorContextGetFieldLabel(*op_apply, "solution time",
27411436a05SJames Wright                                    &phys->solution_time_label);
27588626eedSJames Wright   CeedOperatorContextGetFieldLabel(*op_apply, "timestep size",
27688626eedSJames Wright                                    &phys->timestep_size_label);
27711436a05SJames Wright 
27877841947SLeila Ghaffari   PetscFunctionReturn(0);
27977841947SLeila Ghaffari }
28077841947SLeila Ghaffari 
28177841947SLeila Ghaffari PetscErrorCode SetupLibceed(Ceed ceed, CeedData ceed_data, DM dm, User user,
282c95f9967SJed Brown                             AppCtx app_ctx, ProblemData *problem, SimpleBC bc) {
28377841947SLeila Ghaffari   PetscErrorCode ierr;
28477841947SLeila Ghaffari   PetscFunctionBeginUser;
28577841947SLeila Ghaffari 
28677841947SLeila Ghaffari   // *****************************************************************************
28777841947SLeila Ghaffari   // Set up CEED objects for the interior domain (volume)
28877841947SLeila Ghaffari   // *****************************************************************************
28977841947SLeila Ghaffari   const PetscInt num_comp_q      = 5;
29077841947SLeila Ghaffari   const CeedInt  dim             = problem->dim,
29177841947SLeila Ghaffari                  num_comp_x      = problem->dim,
29277841947SLeila Ghaffari                  q_data_size_vol = problem->q_data_size_vol,
293*e334ad8fSJed Brown                  jac_data_size_vol = num_comp_q + 6 + 3,
29477841947SLeila Ghaffari                  P               = app_ctx->degree + 1,
29577841947SLeila Ghaffari                  Q               = P + app_ctx->q_extra;
296a3ae0734SJed Brown   CeedElemRestriction elem_restr_jd_i;
297a3ae0734SJed Brown   CeedVector jac_data;
29877841947SLeila Ghaffari 
29977841947SLeila Ghaffari   // -----------------------------------------------------------------------------
30077841947SLeila Ghaffari   // CEED Bases
30177841947SLeila Ghaffari   // -----------------------------------------------------------------------------
30277841947SLeila Ghaffari   CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_q, P, Q, CEED_GAUSS,
30377841947SLeila Ghaffari                                   &ceed_data->basis_q);
30477841947SLeila Ghaffari   CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_x, 2, Q, CEED_GAUSS,
30577841947SLeila Ghaffari                                   &ceed_data->basis_x);
30677841947SLeila Ghaffari   CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_x, 2, P,
30777841947SLeila Ghaffari                                   CEED_GAUSS_LOBATTO, &ceed_data->basis_xc);
30877841947SLeila Ghaffari 
30977841947SLeila Ghaffari   // -----------------------------------------------------------------------------
31077841947SLeila Ghaffari   // CEED Restrictions
31177841947SLeila Ghaffari   // -----------------------------------------------------------------------------
31277841947SLeila Ghaffari   // -- Create restriction
3137ed3e4cdSJeremy L Thompson   ierr = GetRestrictionForDomain(ceed, dm, 0, 0, 0, Q, q_data_size_vol,
3147ed3e4cdSJeremy L Thompson                                  &ceed_data->elem_restr_q, &ceed_data->elem_restr_x,
31577841947SLeila Ghaffari                                  &ceed_data->elem_restr_qd_i); CHKERRQ(ierr);
316a3ae0734SJed Brown 
317a3ae0734SJed Brown   ierr = GetRestrictionForDomain(ceed, dm, 0, 0, 0, Q, jac_data_size_vol,
318a3ae0734SJed Brown                                  NULL, NULL,
319a3ae0734SJed Brown                                  &elem_restr_jd_i); CHKERRQ(ierr);
32077841947SLeila Ghaffari // -- Create E vectors
32177841947SLeila Ghaffari   CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->q_ceed, NULL);
32277841947SLeila Ghaffari   CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->q_dot_ceed,
32377841947SLeila Ghaffari                                   NULL);
32477841947SLeila Ghaffari   CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->g_ceed, NULL);
32577841947SLeila Ghaffari 
32677841947SLeila Ghaffari   // -----------------------------------------------------------------------------
32777841947SLeila Ghaffari   // CEED QFunctions
32877841947SLeila Ghaffari   // -----------------------------------------------------------------------------
32977841947SLeila Ghaffari   // -- Create QFunction for quadrature data
33091e5af17SJed Brown   CeedQFunctionCreateInterior(ceed, 1, problem->setup_vol.qfunction,
33191e5af17SJed Brown                               problem->setup_vol.qfunction_loc,
33277841947SLeila Ghaffari                               &ceed_data->qf_setup_vol);
333841e4c73SJed Brown   if (problem->setup_vol.qfunction_context) {
334841e4c73SJed Brown     CeedQFunctionSetContext(ceed_data->qf_setup_vol,
335841e4c73SJed Brown                             problem->setup_vol.qfunction_context);
336841e4c73SJed Brown     CeedQFunctionContextDestroy(&problem->setup_vol.qfunction_context);
337841e4c73SJed Brown   }
33877841947SLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_setup_vol, "dx", num_comp_x*dim,
33977841947SLeila Ghaffari                         CEED_EVAL_GRAD);
34077841947SLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_setup_vol, "weight", 1, CEED_EVAL_WEIGHT);
341a61c78d6SJeremy L Thompson   CeedQFunctionAddOutput(ceed_data->qf_setup_vol, "qdata", q_data_size_vol,
34277841947SLeila Ghaffari                          CEED_EVAL_NONE);
34377841947SLeila Ghaffari 
34477841947SLeila Ghaffari   // -- Create QFunction for ICs
34591e5af17SJed Brown   CeedQFunctionCreateInterior(ceed, 1, problem->ics.qfunction,
34691e5af17SJed Brown                               problem->ics.qfunction_loc,
34777841947SLeila Ghaffari                               &ceed_data->qf_ics);
348841e4c73SJed Brown   CeedQFunctionSetContext(ceed_data->qf_ics, problem->ics.qfunction_context);
349841e4c73SJed Brown   CeedQFunctionContextDestroy(&problem->ics.qfunction_context);
35077841947SLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_ics, "x", num_comp_x, CEED_EVAL_INTERP);
35177841947SLeila Ghaffari   CeedQFunctionAddOutput(ceed_data->qf_ics, "q0", num_comp_q, CEED_EVAL_NONE);
35277841947SLeila Ghaffari 
35377841947SLeila Ghaffari   // -- Create QFunction for RHS
35491e5af17SJed Brown   if (problem->apply_vol_rhs.qfunction) {
35591e5af17SJed Brown     CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_rhs.qfunction,
35691e5af17SJed Brown                                 problem->apply_vol_rhs.qfunction_loc, &ceed_data->qf_rhs_vol);
357841e4c73SJed Brown     CeedQFunctionSetContext(ceed_data->qf_rhs_vol,
358841e4c73SJed Brown                             problem->apply_vol_rhs.qfunction_context);
359841e4c73SJed Brown     CeedQFunctionContextDestroy(&problem->apply_vol_rhs.qfunction_context);
36077841947SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "q", num_comp_q, CEED_EVAL_INTERP);
361a3ae0734SJed Brown     CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "Grad_q", num_comp_q*dim,
36277841947SLeila Ghaffari                           CEED_EVAL_GRAD);
363a61c78d6SJeremy L Thompson     CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "qdata", q_data_size_vol,
36477841947SLeila Ghaffari                           CEED_EVAL_NONE);
36577841947SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "x", num_comp_x, CEED_EVAL_INTERP);
36677841947SLeila Ghaffari     CeedQFunctionAddOutput(ceed_data->qf_rhs_vol, "v", num_comp_q,
36777841947SLeila Ghaffari                            CEED_EVAL_INTERP);
368a3ae0734SJed Brown     CeedQFunctionAddOutput(ceed_data->qf_rhs_vol, "Grad_v", num_comp_q*dim,
36977841947SLeila Ghaffari                            CEED_EVAL_GRAD);
37077841947SLeila Ghaffari   }
37177841947SLeila Ghaffari 
37277841947SLeila Ghaffari   // -- Create QFunction for IFunction
37391e5af17SJed Brown   if (problem->apply_vol_ifunction.qfunction) {
37491e5af17SJed Brown     CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_ifunction.qfunction,
37591e5af17SJed Brown                                 problem->apply_vol_ifunction.qfunction_loc, &ceed_data->qf_ifunction_vol);
376841e4c73SJed Brown     CeedQFunctionSetContext(ceed_data->qf_ifunction_vol,
377841e4c73SJed Brown                             problem->apply_vol_ifunction.qfunction_context);
378841e4c73SJed Brown     CeedQFunctionContextDestroy(&problem->apply_vol_ifunction.qfunction_context);
37977841947SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "q", num_comp_q,
38077841947SLeila Ghaffari                           CEED_EVAL_INTERP);
381a3ae0734SJed Brown     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "Grad_q", num_comp_q*dim,
38277841947SLeila Ghaffari                           CEED_EVAL_GRAD);
383a61c78d6SJeremy L Thompson     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "q dot", num_comp_q,
38477841947SLeila Ghaffari                           CEED_EVAL_INTERP);
385a61c78d6SJeremy L Thompson     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "qdata", q_data_size_vol,
38677841947SLeila Ghaffari                           CEED_EVAL_NONE);
38777841947SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "x", num_comp_x,
38877841947SLeila Ghaffari                           CEED_EVAL_INTERP);
38977841947SLeila Ghaffari     CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "v", num_comp_q,
39077841947SLeila Ghaffari                            CEED_EVAL_INTERP);
391a3ae0734SJed Brown     CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "Grad_v", num_comp_q*dim,
39277841947SLeila Ghaffari                            CEED_EVAL_GRAD);
393a3ae0734SJed Brown     CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "jac_data",
394a3ae0734SJed Brown                            jac_data_size_vol, CEED_EVAL_NONE);
39577841947SLeila Ghaffari   }
39677841947SLeila Ghaffari 
397*e334ad8fSJed Brown   CeedQFunction qf_ijacobian_vol = NULL;
398*e334ad8fSJed Brown   if (problem->apply_vol_ijacobian.qfunction) {
399*e334ad8fSJed Brown     CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_ijacobian.qfunction,
400*e334ad8fSJed Brown                                 problem->apply_vol_ijacobian.qfunction_loc, &qf_ijacobian_vol);
401*e334ad8fSJed Brown     CeedQFunctionSetContext(qf_ijacobian_vol,
402*e334ad8fSJed Brown                             problem->apply_vol_ijacobian.qfunction_context);
403*e334ad8fSJed Brown     CeedQFunctionContextDestroy(&problem->apply_vol_ijacobian.qfunction_context);
404*e334ad8fSJed Brown     CeedQFunctionAddInput(qf_ijacobian_vol, "dq", num_comp_q,
405*e334ad8fSJed Brown                           CEED_EVAL_INTERP);
406*e334ad8fSJed Brown     CeedQFunctionAddInput(qf_ijacobian_vol, "Grad_dq", num_comp_q*dim,
407*e334ad8fSJed Brown                           CEED_EVAL_GRAD);
408*e334ad8fSJed Brown     CeedQFunctionAddInput(qf_ijacobian_vol, "qdata", q_data_size_vol,
409*e334ad8fSJed Brown                           CEED_EVAL_NONE);
410*e334ad8fSJed Brown     CeedQFunctionAddInput(qf_ijacobian_vol, "x", num_comp_x,
411*e334ad8fSJed Brown                           CEED_EVAL_INTERP);
412*e334ad8fSJed Brown     CeedQFunctionAddInput(qf_ijacobian_vol, "jac_data",
413*e334ad8fSJed Brown                           jac_data_size_vol, CEED_EVAL_NONE);
414*e334ad8fSJed Brown     CeedQFunctionAddOutput(qf_ijacobian_vol, "v", num_comp_q,
415*e334ad8fSJed Brown                            CEED_EVAL_INTERP);
416*e334ad8fSJed Brown     CeedQFunctionAddOutput(qf_ijacobian_vol, "Grad_v", num_comp_q*dim,
417*e334ad8fSJed Brown                            CEED_EVAL_GRAD);
418*e334ad8fSJed Brown   }
419*e334ad8fSJed Brown 
42077841947SLeila Ghaffari   // ---------------------------------------------------------------------------
42177841947SLeila Ghaffari   // Element coordinates
42277841947SLeila Ghaffari   // ---------------------------------------------------------------------------
42377841947SLeila Ghaffari   // -- Create CEED vector
42477841947SLeila Ghaffari   CeedElemRestrictionCreateVector(ceed_data->elem_restr_x, &ceed_data->x_coord,
42577841947SLeila Ghaffari                                   NULL);
42677841947SLeila Ghaffari 
42777841947SLeila Ghaffari   // -- Copy PETSc vector in CEED vector
42877841947SLeila Ghaffari   Vec               X_loc;
42977841947SLeila Ghaffari   const PetscScalar *X_loc_array;
43077841947SLeila Ghaffari   ierr = DMGetCoordinatesLocal(dm, &X_loc); CHKERRQ(ierr);
4311864f1c2SLeila Ghaffari   ierr = VecScale(X_loc, problem->dm_scale); CHKERRQ(ierr);
43277841947SLeila Ghaffari   ierr = VecGetArrayRead(X_loc, &X_loc_array); CHKERRQ(ierr);
43377841947SLeila Ghaffari   CeedVectorSetArray(ceed_data->x_coord, CEED_MEM_HOST, CEED_COPY_VALUES,
43477841947SLeila Ghaffari                      (PetscScalar *)X_loc_array);
43577841947SLeila Ghaffari   ierr = VecRestoreArrayRead(X_loc, &X_loc_array); CHKERRQ(ierr);
43677841947SLeila Ghaffari 
43777841947SLeila Ghaffari   // -----------------------------------------------------------------------------
43877841947SLeila Ghaffari   // CEED vectors
43977841947SLeila Ghaffari   // -----------------------------------------------------------------------------
44077841947SLeila Ghaffari   // -- Create CEED vector for geometric data
44177841947SLeila Ghaffari   CeedInt  num_qpts_vol;
44277841947SLeila Ghaffari   PetscInt loc_num_elem_vol;
44377841947SLeila Ghaffari   CeedBasisGetNumQuadraturePoints(ceed_data->basis_q, &num_qpts_vol);
44477841947SLeila Ghaffari   CeedElemRestrictionGetNumElements(ceed_data->elem_restr_q, &loc_num_elem_vol);
44577841947SLeila Ghaffari   CeedVectorCreate(ceed, q_data_size_vol*loc_num_elem_vol*num_qpts_vol,
44677841947SLeila Ghaffari                    &ceed_data->q_data);
44777841947SLeila Ghaffari 
448a3ae0734SJed Brown   CeedElemRestrictionCreateVector(elem_restr_jd_i, &jac_data, NULL);
44977841947SLeila Ghaffari   // -----------------------------------------------------------------------------
45077841947SLeila Ghaffari   // CEED Operators
45177841947SLeila Ghaffari   // -----------------------------------------------------------------------------
45277841947SLeila Ghaffari   // -- Create CEED operator for quadrature data
45377841947SLeila Ghaffari   CeedOperatorCreate(ceed, ceed_data->qf_setup_vol, NULL, NULL,
45477841947SLeila Ghaffari                      &ceed_data->op_setup_vol);
45577841947SLeila Ghaffari   CeedOperatorSetField(ceed_data->op_setup_vol, "dx", ceed_data->elem_restr_x,
45677841947SLeila Ghaffari                        ceed_data->basis_x, CEED_VECTOR_ACTIVE);
45777841947SLeila Ghaffari   CeedOperatorSetField(ceed_data->op_setup_vol, "weight",
458e6225c47SLeila Ghaffari                        CEED_ELEMRESTRICTION_NONE, ceed_data->basis_x, CEED_VECTOR_NONE);
459a61c78d6SJeremy L Thompson   CeedOperatorSetField(ceed_data->op_setup_vol, "qdata",
460e6225c47SLeila Ghaffari                        ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE);
46177841947SLeila Ghaffari 
46277841947SLeila Ghaffari   // -- Create CEED operator for ICs
46377841947SLeila Ghaffari   CeedOperatorCreate(ceed, ceed_data->qf_ics, NULL, NULL, &ceed_data->op_ics);
46477841947SLeila Ghaffari   CeedOperatorSetField(ceed_data->op_ics, "x", ceed_data->elem_restr_x,
46577841947SLeila Ghaffari                        ceed_data->basis_xc, CEED_VECTOR_ACTIVE);
46677841947SLeila Ghaffari   CeedOperatorSetField(ceed_data->op_ics, "q0", ceed_data->elem_restr_q,
46777841947SLeila Ghaffari                        CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE);
468841e4c73SJed Brown   CeedOperatorContextGetFieldLabel(ceed_data->op_ics, "evaluation time",
469841e4c73SJed Brown                                    &user->phys->ics_time_label);
47077841947SLeila Ghaffari 
47177841947SLeila Ghaffari   // Create CEED operator for RHS
47277841947SLeila Ghaffari   if (ceed_data->qf_rhs_vol) {
47377841947SLeila Ghaffari     CeedOperator op;
47477841947SLeila Ghaffari     CeedOperatorCreate(ceed, ceed_data->qf_rhs_vol, NULL, NULL, &op);
47577841947SLeila Ghaffari     CeedOperatorSetField(op, "q", ceed_data->elem_restr_q, ceed_data->basis_q,
47677841947SLeila Ghaffari                          CEED_VECTOR_ACTIVE);
477a3ae0734SJed Brown     CeedOperatorSetField(op, "Grad_q", ceed_data->elem_restr_q, ceed_data->basis_q,
47877841947SLeila Ghaffari                          CEED_VECTOR_ACTIVE);
479a61c78d6SJeremy L Thompson     CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i,
480e6225c47SLeila Ghaffari                          CEED_BASIS_COLLOCATED, ceed_data->q_data);
48177841947SLeila Ghaffari     CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x,
48277841947SLeila Ghaffari                          ceed_data->x_coord);
48377841947SLeila Ghaffari     CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q,
48477841947SLeila Ghaffari                          CEED_VECTOR_ACTIVE);
485a3ae0734SJed Brown     CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q,
48677841947SLeila Ghaffari                          CEED_VECTOR_ACTIVE);
48777841947SLeila Ghaffari     user->op_rhs_vol = op;
48877841947SLeila Ghaffari   }
48977841947SLeila Ghaffari 
49077841947SLeila Ghaffari   // -- CEED operator for IFunction
49177841947SLeila Ghaffari   if (ceed_data->qf_ifunction_vol) {
49277841947SLeila Ghaffari     CeedOperator op;
49377841947SLeila Ghaffari     CeedOperatorCreate(ceed, ceed_data->qf_ifunction_vol, NULL, NULL, &op);
49477841947SLeila Ghaffari     CeedOperatorSetField(op, "q", ceed_data->elem_restr_q, ceed_data->basis_q,
49577841947SLeila Ghaffari                          CEED_VECTOR_ACTIVE);
496a3ae0734SJed Brown     CeedOperatorSetField(op, "Grad_q", ceed_data->elem_restr_q, ceed_data->basis_q,
49777841947SLeila Ghaffari                          CEED_VECTOR_ACTIVE);
498a61c78d6SJeremy L Thompson     CeedOperatorSetField(op, "q dot", ceed_data->elem_restr_q, ceed_data->basis_q,
49977841947SLeila Ghaffari                          user->q_dot_ceed);
500a61c78d6SJeremy L Thompson     CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i,
501e6225c47SLeila Ghaffari                          CEED_BASIS_COLLOCATED, ceed_data->q_data);
50277841947SLeila Ghaffari     CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x,
50377841947SLeila Ghaffari                          ceed_data->x_coord);
50477841947SLeila Ghaffari     CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q,
50577841947SLeila Ghaffari                          CEED_VECTOR_ACTIVE);
506a3ae0734SJed Brown     CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q,
50777841947SLeila Ghaffari                          CEED_VECTOR_ACTIVE);
508a3ae0734SJed Brown     CeedOperatorSetField(op, "jac_data", elem_restr_jd_i,
509a3ae0734SJed Brown                          CEED_BASIS_COLLOCATED, jac_data);
510a3ae0734SJed Brown 
51177841947SLeila Ghaffari     user->op_ifunction_vol = op;
51277841947SLeila Ghaffari   }
51377841947SLeila Ghaffari 
514*e334ad8fSJed Brown   CeedOperator op_ijacobian_vol = NULL;
515*e334ad8fSJed Brown   if (qf_ijacobian_vol) {
516*e334ad8fSJed Brown     CeedOperator op;
517*e334ad8fSJed Brown     CeedOperatorCreate(ceed, qf_ijacobian_vol, NULL, NULL, &op);
518*e334ad8fSJed Brown     CeedOperatorSetField(op, "dq", ceed_data->elem_restr_q, ceed_data->basis_q,
519*e334ad8fSJed Brown                          CEED_VECTOR_ACTIVE);
520*e334ad8fSJed Brown     CeedOperatorSetField(op, "Grad_dq", ceed_data->elem_restr_q, ceed_data->basis_q,
521*e334ad8fSJed Brown                          CEED_VECTOR_ACTIVE);
522*e334ad8fSJed Brown     CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i,
523*e334ad8fSJed Brown                          CEED_BASIS_COLLOCATED, ceed_data->q_data);
524*e334ad8fSJed Brown     CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x,
525*e334ad8fSJed Brown                          ceed_data->x_coord);
526*e334ad8fSJed Brown     CeedOperatorSetField(op, "jac_data", elem_restr_jd_i,
527*e334ad8fSJed Brown                          CEED_BASIS_COLLOCATED, jac_data);
528*e334ad8fSJed Brown     CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q,
529*e334ad8fSJed Brown                          CEED_VECTOR_ACTIVE);
530*e334ad8fSJed Brown     CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q,
531*e334ad8fSJed Brown                          CEED_VECTOR_ACTIVE);
532*e334ad8fSJed Brown     op_ijacobian_vol = op;
533*e334ad8fSJed Brown     CeedQFunctionDestroy(&qf_ijacobian_vol);
534*e334ad8fSJed Brown   }
535*e334ad8fSJed Brown 
53677841947SLeila Ghaffari   // *****************************************************************************
53777841947SLeila Ghaffari   // Set up CEED objects for the exterior domain (surface)
53877841947SLeila Ghaffari   // *****************************************************************************
53977841947SLeila Ghaffari   CeedInt height  = 1,
54077841947SLeila Ghaffari           dim_sur = dim - height,
54177841947SLeila Ghaffari           P_sur   = app_ctx->degree + 1,
54277841947SLeila Ghaffari           Q_sur   = P_sur + app_ctx->q_extra;
543*e334ad8fSJed Brown   const CeedInt q_data_size_sur = problem->q_data_size_sur,
544*e334ad8fSJed Brown                 jac_data_size_sur = problem->jac_data_size_sur;
54577841947SLeila Ghaffari 
54677841947SLeila Ghaffari   // -----------------------------------------------------------------------------
54777841947SLeila Ghaffari   // CEED Bases
54877841947SLeila Ghaffari   // -----------------------------------------------------------------------------
54977841947SLeila Ghaffari   CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_q, P_sur, Q_sur,
55077841947SLeila Ghaffari                                   CEED_GAUSS, &ceed_data->basis_q_sur);
55177841947SLeila Ghaffari   CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_x, 2, Q_sur, CEED_GAUSS,
55277841947SLeila Ghaffari                                   &ceed_data->basis_x_sur);
55377841947SLeila Ghaffari 
55477841947SLeila Ghaffari   // -----------------------------------------------------------------------------
55577841947SLeila Ghaffari   // CEED QFunctions
55677841947SLeila Ghaffari   // -----------------------------------------------------------------------------
55777841947SLeila Ghaffari   // -- Create QFunction for quadrature data
55891e5af17SJed Brown   CeedQFunctionCreateInterior(ceed, 1, problem->setup_sur.qfunction,
55991e5af17SJed Brown                               problem->setup_sur.qfunction_loc,
56077841947SLeila Ghaffari                               &ceed_data->qf_setup_sur);
561841e4c73SJed Brown   if (problem->setup_sur.qfunction_context) {
562841e4c73SJed Brown     CeedQFunctionSetContext(ceed_data->qf_setup_sur,
563841e4c73SJed Brown                             problem->setup_sur.qfunction_context);
564841e4c73SJed Brown     CeedQFunctionContextDestroy(&problem->setup_sur.qfunction_context);
565841e4c73SJed Brown   }
56677841947SLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_setup_sur, "dx", num_comp_x*dim_sur,
56777841947SLeila Ghaffari                         CEED_EVAL_GRAD);
56877841947SLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_setup_sur, "weight", 1, CEED_EVAL_WEIGHT);
569a61c78d6SJeremy L Thompson   CeedQFunctionAddOutput(ceed_data->qf_setup_sur, "surface qdata",
5702fe7aee7SLeila Ghaffari                          q_data_size_sur, CEED_EVAL_NONE);
57177841947SLeila Ghaffari 
5722fe7aee7SLeila Ghaffari   // -- Creat QFunction for inflow boundaries
57391e5af17SJed Brown   if (problem->apply_inflow.qfunction) {
57491e5af17SJed Brown     CeedQFunctionCreateInterior(ceed, 1, problem->apply_inflow.qfunction,
57591e5af17SJed Brown                                 problem->apply_inflow.qfunction_loc, &ceed_data->qf_apply_inflow);
576841e4c73SJed Brown     CeedQFunctionSetContext(ceed_data->qf_apply_inflow,
577841e4c73SJed Brown                             problem->apply_inflow.qfunction_context);
578841e4c73SJed Brown     CeedQFunctionContextDestroy(&problem->apply_inflow.qfunction_context);
5792fe7aee7SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_apply_inflow, "q", num_comp_q,
58077841947SLeila Ghaffari                           CEED_EVAL_INTERP);
5812fe7aee7SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_apply_inflow, "surface qdata",
5822fe7aee7SLeila Ghaffari                           q_data_size_sur, CEED_EVAL_NONE);
5832fe7aee7SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_apply_inflow, "x", num_comp_x,
58477841947SLeila Ghaffari                           CEED_EVAL_INTERP);
5852fe7aee7SLeila Ghaffari     CeedQFunctionAddOutput(ceed_data->qf_apply_inflow, "v", num_comp_q,
5862fe7aee7SLeila Ghaffari                            CEED_EVAL_INTERP);
5872fe7aee7SLeila Ghaffari   }
588*e334ad8fSJed Brown   if (problem->apply_inflow_jacobian.qfunction) {
589*e334ad8fSJed Brown     CeedQFunctionCreateInterior(ceed, 1, problem->apply_inflow_jacobian.qfunction,
590*e334ad8fSJed Brown                                 problem->apply_inflow_jacobian.qfunction_loc,
591*e334ad8fSJed Brown                                 &ceed_data->qf_apply_inflow_jacobian);
592*e334ad8fSJed Brown     CeedQFunctionSetContext(ceed_data->qf_apply_inflow_jacobian,
593*e334ad8fSJed Brown                             problem->apply_inflow_jacobian.qfunction_context);
594*e334ad8fSJed Brown     CeedQFunctionContextDestroy(&problem->apply_inflow_jacobian.qfunction_context);
595*e334ad8fSJed Brown     CeedQFunctionAddInput(ceed_data->qf_apply_inflow_jacobian, "dq", num_comp_q,
596*e334ad8fSJed Brown                           CEED_EVAL_INTERP);
597*e334ad8fSJed Brown     CeedQFunctionAddInput(ceed_data->qf_apply_inflow_jacobian, "surface qdata",
598*e334ad8fSJed Brown                           q_data_size_sur, CEED_EVAL_NONE);
599*e334ad8fSJed Brown     CeedQFunctionAddInput(ceed_data->qf_apply_inflow_jacobian, "x", num_comp_x,
600*e334ad8fSJed Brown                           CEED_EVAL_INTERP);
601*e334ad8fSJed Brown     CeedQFunctionAddOutput(ceed_data->qf_apply_inflow_jacobian, "v", num_comp_q,
602*e334ad8fSJed Brown                            CEED_EVAL_INTERP);
603*e334ad8fSJed Brown   }
6042fe7aee7SLeila Ghaffari 
6052fe7aee7SLeila Ghaffari   // -- Creat QFunction for outflow boundaries
60691e5af17SJed Brown   if (problem->apply_outflow.qfunction) {
60791e5af17SJed Brown     CeedQFunctionCreateInterior(ceed, 1, problem->apply_outflow.qfunction,
60891e5af17SJed Brown                                 problem->apply_outflow.qfunction_loc, &ceed_data->qf_apply_outflow);
609841e4c73SJed Brown     CeedQFunctionSetContext(ceed_data->qf_apply_outflow,
610841e4c73SJed Brown                             problem->apply_outflow.qfunction_context);
611841e4c73SJed Brown     CeedQFunctionContextDestroy(&problem->apply_outflow.qfunction_context);
6122fe7aee7SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_apply_outflow, "q", num_comp_q,
6132fe7aee7SLeila Ghaffari                           CEED_EVAL_INTERP);
6142fe7aee7SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_apply_outflow, "surface qdata",
6152fe7aee7SLeila Ghaffari                           q_data_size_sur, CEED_EVAL_NONE);
6162fe7aee7SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_apply_outflow, "x", num_comp_x,
6172fe7aee7SLeila Ghaffari                           CEED_EVAL_INTERP);
6182fe7aee7SLeila Ghaffari     CeedQFunctionAddOutput(ceed_data->qf_apply_outflow, "v", num_comp_q,
61977841947SLeila Ghaffari                            CEED_EVAL_INTERP);
620*e334ad8fSJed Brown     CeedQFunctionAddOutput(ceed_data->qf_apply_outflow, "surface jacobian data",
621*e334ad8fSJed Brown                            jac_data_size_sur,
622*e334ad8fSJed Brown                            CEED_EVAL_NONE);
623*e334ad8fSJed Brown   }
624*e334ad8fSJed Brown   if (problem->apply_outflow_jacobian.qfunction) {
625*e334ad8fSJed Brown     CeedQFunctionCreateInterior(ceed, 1, problem->apply_outflow_jacobian.qfunction,
626*e334ad8fSJed Brown                                 problem->apply_outflow_jacobian.qfunction_loc,
627*e334ad8fSJed Brown                                 &ceed_data->qf_apply_outflow_jacobian);
628*e334ad8fSJed Brown     CeedQFunctionSetContext(ceed_data->qf_apply_outflow_jacobian,
629*e334ad8fSJed Brown                             problem->apply_outflow_jacobian.qfunction_context);
630*e334ad8fSJed Brown     CeedQFunctionContextDestroy(&problem->apply_outflow_jacobian.qfunction_context);
631*e334ad8fSJed Brown     CeedQFunctionAddInput(ceed_data->qf_apply_outflow_jacobian, "dq", num_comp_q,
632*e334ad8fSJed Brown                           CEED_EVAL_INTERP);
633*e334ad8fSJed Brown     CeedQFunctionAddInput(ceed_data->qf_apply_outflow_jacobian, "surface qdata",
634*e334ad8fSJed Brown                           q_data_size_sur, CEED_EVAL_NONE);
635*e334ad8fSJed Brown     CeedQFunctionAddInput(ceed_data->qf_apply_outflow_jacobian,
636*e334ad8fSJed Brown                           "surface jacobian data",
637*e334ad8fSJed Brown                           jac_data_size_sur, CEED_EVAL_NONE);
638*e334ad8fSJed Brown     CeedQFunctionAddOutput(ceed_data->qf_apply_outflow_jacobian, "v", num_comp_q,
639*e334ad8fSJed Brown                            CEED_EVAL_INTERP);
64077841947SLeila Ghaffari   }
64177841947SLeila Ghaffari 
64277841947SLeila Ghaffari   // *****************************************************************************
64377841947SLeila Ghaffari   // CEED Operator Apply
64477841947SLeila Ghaffari   // *****************************************************************************
64577841947SLeila Ghaffari   // -- Apply CEED Operator for the geometric data
64677841947SLeila Ghaffari   CeedOperatorApply(ceed_data->op_setup_vol, ceed_data->x_coord,
64777841947SLeila Ghaffari                     ceed_data->q_data, CEED_REQUEST_IMMEDIATE);
64877841947SLeila Ghaffari 
64977841947SLeila Ghaffari   // -- Create and apply CEED Composite Operator for the entire domain
65077841947SLeila Ghaffari   if (!user->phys->implicit) { // RHS
65177841947SLeila Ghaffari     ierr = CreateOperatorForDomain(ceed, dm, bc, ceed_data, user->phys,
652*e334ad8fSJed Brown                                    user->op_rhs_vol, NULL, height, P_sur, Q_sur,
653*e334ad8fSJed Brown                                    q_data_size_sur, 0,
654*e334ad8fSJed Brown                                    &user->op_rhs, NULL); CHKERRQ(ierr);
65577841947SLeila Ghaffari   } else { // IFunction
65677841947SLeila Ghaffari     ierr = CreateOperatorForDomain(ceed, dm, bc, ceed_data, user->phys,
657*e334ad8fSJed Brown                                    user->op_ifunction_vol, op_ijacobian_vol,
658*e334ad8fSJed Brown                                    height, P_sur, Q_sur,
659*e334ad8fSJed Brown                                    q_data_size_sur, jac_data_size_sur,
660*e334ad8fSJed Brown                                    &user->op_ifunction,
661*e334ad8fSJed Brown                                    op_ijacobian_vol ? &user->op_ijacobian : NULL); CHKERRQ(ierr);
662*e334ad8fSJed Brown     if (user->op_ijacobian) {
663*e334ad8fSJed Brown       CeedOperatorContextGetFieldLabel(user->op_ijacobian, "ijacobian time shift",
664*e334ad8fSJed Brown                                        &user->phys->ijacobian_time_shift_label);
665*e334ad8fSJed Brown     }
666*e334ad8fSJed Brown 
66777841947SLeila Ghaffari   }
668a3ae0734SJed Brown   CeedElemRestrictionDestroy(&elem_restr_jd_i);
669a3ae0734SJed Brown   CeedVectorDestroy(&jac_data);
67077841947SLeila Ghaffari   PetscFunctionReturn(0);
67177841947SLeila Ghaffari }
672