xref: /libCEED/examples/fluids/src/setuplibceed.c (revision 5b881d11bf2f67866ae4facae92d76dc7c086dc3)
13d8e8822SJeremy L Thompson // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
23d8e8822SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
377841947SLeila Ghaffari //
43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
577841947SLeila Ghaffari //
63d8e8822SJeremy L Thompson // This file is part of CEED:  http://github.com/ceed
777841947SLeila Ghaffari 
877841947SLeila Ghaffari /// @file
977841947SLeila Ghaffari /// Setup libCEED for Navier-Stokes example using PETSc
1077841947SLeila Ghaffari 
1177841947SLeila Ghaffari #include "../navierstokes.h"
1277841947SLeila Ghaffari 
1377841947SLeila Ghaffari // Utility function - essential BC dofs are encoded in closure indices as -(i+1).
1477841947SLeila Ghaffari PetscInt Involute(PetscInt i) {
1577841947SLeila Ghaffari   return i >= 0 ? i : -(i+1);
1677841947SLeila Ghaffari }
1777841947SLeila Ghaffari 
1877841947SLeila Ghaffari // Utility function to create local CEED restriction
197ed3e4cdSJeremy L Thompson PetscErrorCode CreateRestrictionFromPlex(Ceed ceed, DM dm, CeedInt height,
207ed3e4cdSJeremy L Thompson     DMLabel domain_label, CeedInt value, CeedElemRestriction *elem_restr) {
217ed3e4cdSJeremy L Thompson   PetscInt num_elem, elem_size, num_dof, num_comp, *elem_restr_offsets;
2277841947SLeila Ghaffari   PetscErrorCode ierr;
237ed3e4cdSJeremy L Thompson 
2477841947SLeila Ghaffari   PetscFunctionBeginUser;
257ed3e4cdSJeremy L Thompson   ierr = DMPlexGetLocalOffsets(dm, domain_label, value, height, 0, &num_elem,
267ed3e4cdSJeremy L Thompson                                &elem_size, &num_comp, &num_dof, &elem_restr_offsets);
277ed3e4cdSJeremy L Thompson   CHKERRQ(ierr);
2877841947SLeila Ghaffari 
297ed3e4cdSJeremy L Thompson   CeedElemRestrictionCreate(ceed, num_elem, elem_size, num_comp,
307ed3e4cdSJeremy L Thompson                             1, num_dof, CEED_MEM_HOST, CEED_COPY_VALUES,
317ed3e4cdSJeremy L Thompson                             elem_restr_offsets, elem_restr);
327ed3e4cdSJeremy L Thompson   ierr = PetscFree(elem_restr_offsets); CHKERRQ(ierr);
3377841947SLeila Ghaffari 
3477841947SLeila Ghaffari   PetscFunctionReturn(0);
3577841947SLeila Ghaffari }
3677841947SLeila Ghaffari 
3777841947SLeila Ghaffari // Utility function to get Ceed Restriction for each domain
3877841947SLeila Ghaffari PetscErrorCode GetRestrictionForDomain(Ceed ceed, DM dm, CeedInt height,
3977841947SLeila Ghaffari                                        DMLabel domain_label, PetscInt value,
407ed3e4cdSJeremy L Thompson                                        CeedInt Q, CeedInt q_data_size,
4177841947SLeila Ghaffari                                        CeedElemRestriction *elem_restr_q,
4277841947SLeila Ghaffari                                        CeedElemRestriction *elem_restr_x,
4377841947SLeila Ghaffari                                        CeedElemRestriction *elem_restr_qd_i) {
4477841947SLeila Ghaffari   DM             dm_coord;
4577841947SLeila Ghaffari   CeedInt        dim, loc_num_elem;
4677841947SLeila Ghaffari   CeedInt        Q_dim;
472534dcc8SJed Brown   CeedElemRestriction elem_restr_tmp;
4877841947SLeila Ghaffari   PetscErrorCode ierr;
4977841947SLeila Ghaffari   PetscFunctionBeginUser;
5077841947SLeila Ghaffari 
5177841947SLeila Ghaffari   ierr = DMGetDimension(dm, &dim); CHKERRQ(ierr);
5277841947SLeila Ghaffari   dim -= height;
5377841947SLeila Ghaffari   Q_dim = CeedIntPow(Q, dim);
542534dcc8SJed Brown   ierr = CreateRestrictionFromPlex(ceed, dm, height, domain_label, value,
552534dcc8SJed Brown                                    &elem_restr_tmp);
562534dcc8SJed Brown   CHKERRQ(ierr);
572534dcc8SJed Brown   if (elem_restr_q) *elem_restr_q = elem_restr_tmp;
582534dcc8SJed Brown   if (elem_restr_x) {
593796c488SJed Brown     ierr = DMGetCellCoordinateDM(dm, &dm_coord); CHKERRQ(ierr);
603796c488SJed Brown     if (!dm_coord) {
6177841947SLeila Ghaffari       ierr = DMGetCoordinateDM(dm, &dm_coord); CHKERRQ(ierr);
623796c488SJed Brown     }
6377841947SLeila Ghaffari     ierr = DMPlexSetClosurePermutationTensor(dm_coord, PETSC_DETERMINE, NULL);
6477841947SLeila Ghaffari     CHKERRQ(ierr);
657ed3e4cdSJeremy L Thompson     ierr = CreateRestrictionFromPlex(ceed, dm_coord, height, domain_label, value,
667ed3e4cdSJeremy L Thompson                                      elem_restr_x);
677ed3e4cdSJeremy L Thompson     CHKERRQ(ierr);
682534dcc8SJed Brown   }
692534dcc8SJed Brown   if (elem_restr_qd_i) {
702534dcc8SJed Brown     CeedElemRestrictionGetNumElements(elem_restr_tmp, &loc_num_elem);
7177841947SLeila Ghaffari     CeedElemRestrictionCreateStrided(ceed, loc_num_elem, Q_dim,
7277841947SLeila Ghaffari                                      q_data_size, q_data_size*loc_num_elem*Q_dim,
7377841947SLeila Ghaffari                                      CEED_STRIDES_BACKEND, elem_restr_qd_i);
742534dcc8SJed Brown   }
752534dcc8SJed Brown   if (!elem_restr_q) CeedElemRestrictionDestroy(&elem_restr_tmp);
7677841947SLeila Ghaffari   PetscFunctionReturn(0);
7777841947SLeila Ghaffari }
7877841947SLeila Ghaffari 
799eb9c072SJames Wright PetscErrorCode AddBCSubOperator(Ceed ceed, DM dm, CeedData ceed_data,
809eb9c072SJames Wright                                 DMLabel domain_label, PetscInt value,
819eb9c072SJames Wright                                 CeedInt height, CeedInt Q_sur,
829eb9c072SJames Wright                                 CeedInt q_data_size_sur, CeedInt jac_data_size_sur,
839eb9c072SJames Wright                                 CeedQFunction qf_apply_bc, CeedQFunction qf_apply_bc_jacobian,
849eb9c072SJames Wright                                 CeedOperator *op_apply, CeedOperator *op_apply_ijacobian) {
859eb9c072SJames Wright   CeedVector          q_data_sur, jac_data_sur;
869eb9c072SJames Wright   CeedOperator        op_setup_sur, op_apply_bc,
879eb9c072SJames Wright                       op_apply_bc_jacobian = NULL;
889eb9c072SJames Wright   CeedElemRestriction elem_restr_x_sur, elem_restr_q_sur, elem_restr_qd_i_sur,
899eb9c072SJames Wright                       elem_restr_jd_i_sur;
909eb9c072SJames Wright   CeedInt num_qpts_sur;
919eb9c072SJames Wright   PetscFunctionBeginUser;
929eb9c072SJames Wright 
939eb9c072SJames Wright   // --- Get number of quadrature points for the boundaries
949eb9c072SJames Wright   CeedBasisGetNumQuadraturePoints(ceed_data->basis_q_sur, &num_qpts_sur);
959eb9c072SJames Wright 
969eb9c072SJames Wright 
979eb9c072SJames Wright   // ---- CEED Restriction
989eb9c072SJames Wright   PetscCall(GetRestrictionForDomain(ceed, dm, height, domain_label, value, Q_sur,
999eb9c072SJames Wright                                     q_data_size_sur, &elem_restr_q_sur, &elem_restr_x_sur, &elem_restr_qd_i_sur));
1009eb9c072SJames Wright   if (jac_data_size_sur > 0) {
1019eb9c072SJames Wright     // State-dependent data will be passed from residual to Jacobian. This will be collocated.
1029eb9c072SJames Wright     PetscCall(GetRestrictionForDomain(ceed, dm, height, domain_label, value, Q_sur,
1039eb9c072SJames Wright                                       jac_data_size_sur, NULL, NULL, &elem_restr_jd_i_sur));
1049eb9c072SJames Wright     CeedElemRestrictionCreateVector(elem_restr_jd_i_sur, &jac_data_sur, NULL);
1059eb9c072SJames Wright   } else {
1069eb9c072SJames Wright     elem_restr_jd_i_sur = NULL;
1079eb9c072SJames Wright     jac_data_sur = NULL;
1089eb9c072SJames Wright   }
1099eb9c072SJames Wright 
1109eb9c072SJames Wright   // ---- CEED Vector
1119eb9c072SJames Wright   PetscInt loc_num_elem_sur;
1129eb9c072SJames Wright   CeedElemRestrictionGetNumElements(elem_restr_q_sur, &loc_num_elem_sur);
1139eb9c072SJames Wright   CeedVectorCreate(ceed, q_data_size_sur*loc_num_elem_sur*num_qpts_sur,
1149eb9c072SJames Wright                    &q_data_sur);
1159eb9c072SJames Wright 
1169eb9c072SJames Wright   // ---- CEED Operator
1179eb9c072SJames Wright   // ----- CEED Operator for Setup (geometric factors)
1189eb9c072SJames Wright   CeedOperatorCreate(ceed, ceed_data->qf_setup_sur, NULL, NULL, &op_setup_sur);
1199eb9c072SJames Wright   CeedOperatorSetField(op_setup_sur, "dx", elem_restr_x_sur,
1209eb9c072SJames Wright                        ceed_data->basis_x_sur, CEED_VECTOR_ACTIVE);
1219eb9c072SJames Wright   CeedOperatorSetField(op_setup_sur, "weight", CEED_ELEMRESTRICTION_NONE,
1229eb9c072SJames Wright                        ceed_data->basis_x_sur, CEED_VECTOR_NONE);
1239eb9c072SJames Wright   CeedOperatorSetField(op_setup_sur, "surface qdata", elem_restr_qd_i_sur,
1249eb9c072SJames Wright                        CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE);
1259eb9c072SJames Wright 
1269eb9c072SJames Wright   // ----- CEED Operator for Physics
1279eb9c072SJames Wright   CeedOperatorCreate(ceed, qf_apply_bc, NULL, NULL, &op_apply_bc);
1289eb9c072SJames Wright   CeedOperatorSetField(op_apply_bc, "q", elem_restr_q_sur, ceed_data->basis_q_sur,
1299eb9c072SJames Wright                        CEED_VECTOR_ACTIVE);
1309eb9c072SJames Wright   CeedOperatorSetField(op_apply_bc, "Grad_q", elem_restr_q_sur,
1319eb9c072SJames Wright                        ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
1329eb9c072SJames Wright   CeedOperatorSetField(op_apply_bc, "surface qdata", elem_restr_qd_i_sur,
1339eb9c072SJames Wright                        CEED_BASIS_COLLOCATED, q_data_sur);
1349eb9c072SJames Wright   CeedOperatorSetField(op_apply_bc, "x", elem_restr_x_sur, ceed_data->basis_x_sur,
1359eb9c072SJames Wright                        ceed_data->x_coord);
1369eb9c072SJames Wright   CeedOperatorSetField(op_apply_bc, "v", elem_restr_q_sur, ceed_data->basis_q_sur,
1379eb9c072SJames Wright                        CEED_VECTOR_ACTIVE);
1389eb9c072SJames Wright   if (elem_restr_jd_i_sur)
1399eb9c072SJames Wright     CeedOperatorSetField(op_apply_bc, "surface jacobian data",
1409eb9c072SJames Wright                          elem_restr_jd_i_sur,
1419eb9c072SJames Wright                          CEED_BASIS_COLLOCATED, jac_data_sur);
1429eb9c072SJames Wright 
1439eb9c072SJames Wright   if (qf_apply_bc_jacobian) {
1449eb9c072SJames Wright     CeedOperatorCreate(ceed, qf_apply_bc_jacobian, NULL, NULL,
1459eb9c072SJames Wright                        &op_apply_bc_jacobian);
1469eb9c072SJames Wright     CeedOperatorSetField(op_apply_bc_jacobian, "dq", elem_restr_q_sur,
1479eb9c072SJames Wright                          ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
1489eb9c072SJames Wright     CeedOperatorSetField(op_apply_bc_jacobian, "Grad_dq", elem_restr_q_sur,
1499eb9c072SJames Wright                          ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
1509eb9c072SJames Wright     CeedOperatorSetField(op_apply_bc_jacobian, "surface qdata", elem_restr_qd_i_sur,
1519eb9c072SJames Wright                          CEED_BASIS_COLLOCATED, q_data_sur);
1529eb9c072SJames Wright     CeedOperatorSetField(op_apply_bc_jacobian, "x", elem_restr_x_sur,
1539eb9c072SJames Wright                          ceed_data->basis_x_sur, ceed_data->x_coord);
1549eb9c072SJames Wright     CeedOperatorSetField(op_apply_bc_jacobian, "surface jacobian data",
1559eb9c072SJames Wright                          elem_restr_jd_i_sur, CEED_BASIS_COLLOCATED, jac_data_sur);
1569eb9c072SJames Wright     CeedOperatorSetField(op_apply_bc_jacobian, "v", elem_restr_q_sur,
1579eb9c072SJames Wright                          ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE);
1589eb9c072SJames Wright   }
1599eb9c072SJames Wright 
1609eb9c072SJames Wright   // ----- Apply CEED operator for Setup
1619eb9c072SJames Wright   CeedOperatorApply(op_setup_sur, ceed_data->x_coord, q_data_sur,
1629eb9c072SJames Wright                     CEED_REQUEST_IMMEDIATE);
1639eb9c072SJames Wright 
1649eb9c072SJames Wright   // ----- Apply Sub-Operator for Physics
1659eb9c072SJames Wright   CeedCompositeOperatorAddSub(*op_apply, op_apply_bc);
1669eb9c072SJames Wright   if (op_apply_bc_jacobian)
1679eb9c072SJames Wright     CeedCompositeOperatorAddSub(*op_apply_ijacobian, op_apply_bc_jacobian);
1689eb9c072SJames Wright 
1699eb9c072SJames Wright   // ----- Cleanup
1709eb9c072SJames Wright   CeedVectorDestroy(&q_data_sur);
1719eb9c072SJames Wright   CeedVectorDestroy(&jac_data_sur);
1729eb9c072SJames Wright   CeedElemRestrictionDestroy(&elem_restr_q_sur);
1739eb9c072SJames Wright   CeedElemRestrictionDestroy(&elem_restr_x_sur);
1749eb9c072SJames Wright   CeedElemRestrictionDestroy(&elem_restr_qd_i_sur);
1759eb9c072SJames Wright   CeedElemRestrictionDestroy(&elem_restr_jd_i_sur);
1769eb9c072SJames Wright   CeedOperatorDestroy(&op_setup_sur);
1779eb9c072SJames Wright   CeedOperatorDestroy(&op_apply_bc);
1789eb9c072SJames Wright   CeedOperatorDestroy(&op_apply_bc_jacobian);
1799eb9c072SJames Wright 
1809eb9c072SJames Wright   PetscFunctionReturn(0);
1819eb9c072SJames Wright }
1829eb9c072SJames Wright 
18377841947SLeila Ghaffari // Utility function to create CEED Composite Operator for the entire domain
18477841947SLeila Ghaffari PetscErrorCode CreateOperatorForDomain(Ceed ceed, DM dm, SimpleBC bc,
18577841947SLeila Ghaffari                                        CeedData ceed_data, Physics phys,
186e334ad8fSJed Brown                                        CeedOperator op_apply_vol,
187e334ad8fSJed Brown                                        CeedOperator op_apply_ijacobian_vol,
188e334ad8fSJed Brown                                        CeedInt height,
189e334ad8fSJed Brown                                        CeedInt P_sur, CeedInt Q_sur,
190e334ad8fSJed Brown                                        CeedInt q_data_size_sur, CeedInt jac_data_size_sur,
191e334ad8fSJed Brown                                        CeedOperator *op_apply, CeedOperator *op_apply_ijacobian) {
19277841947SLeila Ghaffari   DMLabel        domain_label;
19377841947SLeila Ghaffari   PetscErrorCode ierr;
19477841947SLeila Ghaffari   PetscFunctionBeginUser;
19577841947SLeila Ghaffari 
19677841947SLeila Ghaffari   // Create Composite Operaters
19777841947SLeila Ghaffari   CeedCompositeOperatorCreate(ceed, op_apply);
198e334ad8fSJed Brown   if (op_apply_ijacobian)
199e334ad8fSJed Brown     CeedCompositeOperatorCreate(ceed, op_apply_ijacobian);
20077841947SLeila Ghaffari 
20177841947SLeila Ghaffari   // --Apply Sub-Operator for the volume
20277841947SLeila Ghaffari   CeedCompositeOperatorAddSub(*op_apply, op_apply_vol);
203e334ad8fSJed Brown   if (op_apply_ijacobian)
204e334ad8fSJed Brown     CeedCompositeOperatorAddSub(*op_apply_ijacobian, op_apply_ijacobian_vol);
20577841947SLeila Ghaffari 
20677841947SLeila Ghaffari   // -- Create Sub-Operator for in/outflow BCs
20788626eedSJames Wright   if (phys->has_neumann || 1) {
20877841947SLeila Ghaffari     // --- Setup
20977841947SLeila Ghaffari     ierr = DMGetLabel(dm, "Face Sets", &domain_label); CHKERRQ(ierr);
21077841947SLeila Ghaffari 
2112fe7aee7SLeila Ghaffari     // --- Create Sub-Operator for inflow boundaries
2122fe7aee7SLeila Ghaffari     for (CeedInt i=0; i < bc->num_inflow; i++) {
2139eb9c072SJames Wright       PetscCall(AddBCSubOperator(ceed, dm, ceed_data, domain_label, bc->inflows[i],
2149eb9c072SJames Wright                                  height, Q_sur, q_data_size_sur, jac_data_size_sur,
2159eb9c072SJames Wright                                  ceed_data->qf_apply_inflow, ceed_data->qf_apply_inflow_jacobian,
2169eb9c072SJames Wright                                  op_apply, op_apply_ijacobian));
21777841947SLeila Ghaffari     }
21877841947SLeila Ghaffari 
2192fe7aee7SLeila Ghaffari     // --- Create Sub-Operator for outflow boundaries
2202fe7aee7SLeila Ghaffari     for (CeedInt i=0; i < bc->num_outflow; i++) {
2219eb9c072SJames Wright       PetscCall(AddBCSubOperator(ceed, dm, ceed_data, domain_label, bc->outflows[i],
2229eb9c072SJames Wright                                  height, Q_sur, q_data_size_sur, jac_data_size_sur,
2239eb9c072SJames Wright                                  ceed_data->qf_apply_outflow, ceed_data->qf_apply_outflow_jacobian,
2249eb9c072SJames Wright                                  op_apply, op_apply_ijacobian));
2252fe7aee7SLeila Ghaffari     }
2262fe7aee7SLeila Ghaffari   }
22711436a05SJames Wright 
22811436a05SJames Wright   // ----- Get Context Labels for Operator
22911436a05SJames Wright   CeedOperatorContextGetFieldLabel(*op_apply, "solution time",
23011436a05SJames Wright                                    &phys->solution_time_label);
23188626eedSJames Wright   CeedOperatorContextGetFieldLabel(*op_apply, "timestep size",
23288626eedSJames Wright                                    &phys->timestep_size_label);
23311436a05SJames Wright 
23477841947SLeila Ghaffari   PetscFunctionReturn(0);
23577841947SLeila Ghaffari }
23677841947SLeila Ghaffari 
237*5b881d11SJames Wright PetscErrorCode SetupBCQFunctions(Ceed ceed, PetscInt dim_sur,
238*5b881d11SJames Wright                                  PetscInt num_comp_x, PetscInt num_comp_q,
239*5b881d11SJames Wright                                  PetscInt q_data_size_sur, PetscInt jac_data_size_sur,
240*5b881d11SJames Wright                                  ProblemQFunctionSpec apply_bc, ProblemQFunctionSpec apply_bc_jacobian,
241*5b881d11SJames Wright                                  CeedQFunction *qf_apply_bc, CeedQFunction *qf_apply_bc_jacobian) {
242*5b881d11SJames Wright   PetscFunctionBeginUser;
243*5b881d11SJames Wright 
244*5b881d11SJames Wright   if (apply_bc.qfunction) {
245*5b881d11SJames Wright     // *INDENT-OFF*
246*5b881d11SJames Wright     CeedQFunctionCreateInterior(ceed, 1, apply_bc.qfunction, apply_bc.qfunction_loc, qf_apply_bc);
247*5b881d11SJames Wright     CeedQFunctionSetContext(*qf_apply_bc, apply_bc.qfunction_context);
248*5b881d11SJames Wright     CeedQFunctionContextDestroy(&apply_bc.qfunction_context);
249*5b881d11SJames Wright     CeedQFunctionAddInput(*qf_apply_bc, "q", num_comp_q, CEED_EVAL_INTERP);
250*5b881d11SJames Wright     CeedQFunctionAddInput(*qf_apply_bc, "Grad_q", num_comp_q*dim_sur, CEED_EVAL_GRAD);
251*5b881d11SJames Wright     CeedQFunctionAddInput(*qf_apply_bc, "surface qdata", q_data_size_sur, CEED_EVAL_NONE);
252*5b881d11SJames Wright     CeedQFunctionAddInput(*qf_apply_bc, "x", num_comp_x, CEED_EVAL_INTERP);
253*5b881d11SJames Wright     CeedQFunctionAddOutput(*qf_apply_bc, "v", num_comp_q, CEED_EVAL_INTERP);
254*5b881d11SJames Wright     // *INDENT-ON*
255*5b881d11SJames Wright     if (jac_data_size_sur)
256*5b881d11SJames Wright       CeedQFunctionAddOutput(*qf_apply_bc, "surface jacobian data", jac_data_size_sur,
257*5b881d11SJames Wright                              CEED_EVAL_NONE);
258*5b881d11SJames Wright   }
259*5b881d11SJames Wright   if (apply_bc_jacobian.qfunction) {
260*5b881d11SJames Wright     // *INDENT-OFF*
261*5b881d11SJames Wright     CeedQFunctionCreateInterior(ceed, 1, apply_bc_jacobian.qfunction,
262*5b881d11SJames Wright                                 apply_bc_jacobian.qfunction_loc, qf_apply_bc_jacobian);
263*5b881d11SJames Wright     CeedQFunctionSetContext(*qf_apply_bc_jacobian, apply_bc_jacobian.qfunction_context);
264*5b881d11SJames Wright     CeedQFunctionContextDestroy(&apply_bc_jacobian.qfunction_context);
265*5b881d11SJames Wright     CeedQFunctionAddInput(*qf_apply_bc_jacobian, "dq", num_comp_q, CEED_EVAL_INTERP);
266*5b881d11SJames Wright     CeedQFunctionAddInput(*qf_apply_bc_jacobian, "Grad_dq", num_comp_q*dim_sur, CEED_EVAL_GRAD);
267*5b881d11SJames Wright     CeedQFunctionAddInput(*qf_apply_bc_jacobian, "surface qdata", q_data_size_sur, CEED_EVAL_NONE);
268*5b881d11SJames Wright     CeedQFunctionAddInput(*qf_apply_bc_jacobian, "x", num_comp_x, CEED_EVAL_INTERP);
269*5b881d11SJames Wright     CeedQFunctionAddInput(*qf_apply_bc_jacobian, "surface jacobian data",
270*5b881d11SJames Wright                           jac_data_size_sur, CEED_EVAL_NONE);
271*5b881d11SJames Wright     CeedQFunctionAddOutput(*qf_apply_bc_jacobian, "v", num_comp_q, CEED_EVAL_INTERP);
272*5b881d11SJames Wright     // *INDENT-ON*
273*5b881d11SJames Wright   }
274*5b881d11SJames Wright   PetscFunctionReturn(0);
275*5b881d11SJames Wright }
276*5b881d11SJames Wright 
27777841947SLeila Ghaffari PetscErrorCode SetupLibceed(Ceed ceed, CeedData ceed_data, DM dm, User user,
278c95f9967SJed Brown                             AppCtx app_ctx, ProblemData *problem, SimpleBC bc) {
27977841947SLeila Ghaffari   PetscErrorCode ierr;
28077841947SLeila Ghaffari   PetscFunctionBeginUser;
28177841947SLeila Ghaffari 
28277841947SLeila Ghaffari   // *****************************************************************************
28377841947SLeila Ghaffari   // Set up CEED objects for the interior domain (volume)
28477841947SLeila Ghaffari   // *****************************************************************************
28577841947SLeila Ghaffari   const PetscInt num_comp_q      = 5;
28677841947SLeila Ghaffari   const CeedInt  dim             = problem->dim,
28777841947SLeila Ghaffari                  num_comp_x      = problem->dim,
28877841947SLeila Ghaffari                  q_data_size_vol = problem->q_data_size_vol,
289e334ad8fSJed Brown                  jac_data_size_vol = num_comp_q + 6 + 3,
29077841947SLeila Ghaffari                  P               = app_ctx->degree + 1,
29177841947SLeila Ghaffari                  Q               = P + app_ctx->q_extra;
292a3ae0734SJed Brown   CeedElemRestriction elem_restr_jd_i;
293a3ae0734SJed Brown   CeedVector jac_data;
29477841947SLeila Ghaffari 
29577841947SLeila Ghaffari   // -----------------------------------------------------------------------------
29677841947SLeila Ghaffari   // CEED Bases
29777841947SLeila Ghaffari   // -----------------------------------------------------------------------------
29877841947SLeila Ghaffari   CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_q, P, Q, CEED_GAUSS,
29977841947SLeila Ghaffari                                   &ceed_data->basis_q);
30077841947SLeila Ghaffari   CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_x, 2, Q, CEED_GAUSS,
30177841947SLeila Ghaffari                                   &ceed_data->basis_x);
30277841947SLeila Ghaffari   CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_x, 2, P,
30377841947SLeila Ghaffari                                   CEED_GAUSS_LOBATTO, &ceed_data->basis_xc);
30477841947SLeila Ghaffari 
30577841947SLeila Ghaffari   // -----------------------------------------------------------------------------
30677841947SLeila Ghaffari   // CEED Restrictions
30777841947SLeila Ghaffari   // -----------------------------------------------------------------------------
30877841947SLeila Ghaffari   // -- Create restriction
3097ed3e4cdSJeremy L Thompson   ierr = GetRestrictionForDomain(ceed, dm, 0, 0, 0, Q, q_data_size_vol,
3107ed3e4cdSJeremy L Thompson                                  &ceed_data->elem_restr_q, &ceed_data->elem_restr_x,
31177841947SLeila Ghaffari                                  &ceed_data->elem_restr_qd_i); CHKERRQ(ierr);
312a3ae0734SJed Brown 
313a3ae0734SJed Brown   ierr = GetRestrictionForDomain(ceed, dm, 0, 0, 0, Q, jac_data_size_vol,
314a3ae0734SJed Brown                                  NULL, NULL,
315a3ae0734SJed Brown                                  &elem_restr_jd_i); CHKERRQ(ierr);
31677841947SLeila Ghaffari // -- Create E vectors
31777841947SLeila Ghaffari   CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->q_ceed, NULL);
31877841947SLeila Ghaffari   CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->q_dot_ceed,
31977841947SLeila Ghaffari                                   NULL);
32077841947SLeila Ghaffari   CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->g_ceed, NULL);
32177841947SLeila Ghaffari 
32277841947SLeila Ghaffari   // -----------------------------------------------------------------------------
32377841947SLeila Ghaffari   // CEED QFunctions
32477841947SLeila Ghaffari   // -----------------------------------------------------------------------------
32577841947SLeila Ghaffari   // -- Create QFunction for quadrature data
32691e5af17SJed Brown   CeedQFunctionCreateInterior(ceed, 1, problem->setup_vol.qfunction,
32791e5af17SJed Brown                               problem->setup_vol.qfunction_loc,
32877841947SLeila Ghaffari                               &ceed_data->qf_setup_vol);
329841e4c73SJed Brown   if (problem->setup_vol.qfunction_context) {
330841e4c73SJed Brown     CeedQFunctionSetContext(ceed_data->qf_setup_vol,
331841e4c73SJed Brown                             problem->setup_vol.qfunction_context);
332841e4c73SJed Brown     CeedQFunctionContextDestroy(&problem->setup_vol.qfunction_context);
333841e4c73SJed Brown   }
33477841947SLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_setup_vol, "dx", num_comp_x*dim,
33577841947SLeila Ghaffari                         CEED_EVAL_GRAD);
33677841947SLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_setup_vol, "weight", 1, CEED_EVAL_WEIGHT);
337a61c78d6SJeremy L Thompson   CeedQFunctionAddOutput(ceed_data->qf_setup_vol, "qdata", q_data_size_vol,
33877841947SLeila Ghaffari                          CEED_EVAL_NONE);
33977841947SLeila Ghaffari 
34077841947SLeila Ghaffari   // -- Create QFunction for ICs
34191e5af17SJed Brown   CeedQFunctionCreateInterior(ceed, 1, problem->ics.qfunction,
34291e5af17SJed Brown                               problem->ics.qfunction_loc,
34377841947SLeila Ghaffari                               &ceed_data->qf_ics);
344841e4c73SJed Brown   CeedQFunctionSetContext(ceed_data->qf_ics, problem->ics.qfunction_context);
345841e4c73SJed Brown   CeedQFunctionContextDestroy(&problem->ics.qfunction_context);
34677841947SLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_ics, "x", num_comp_x, CEED_EVAL_INTERP);
34777841947SLeila Ghaffari   CeedQFunctionAddOutput(ceed_data->qf_ics, "q0", num_comp_q, CEED_EVAL_NONE);
34877841947SLeila Ghaffari 
34977841947SLeila Ghaffari   // -- Create QFunction for RHS
35091e5af17SJed Brown   if (problem->apply_vol_rhs.qfunction) {
35191e5af17SJed Brown     CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_rhs.qfunction,
35291e5af17SJed Brown                                 problem->apply_vol_rhs.qfunction_loc, &ceed_data->qf_rhs_vol);
353841e4c73SJed Brown     CeedQFunctionSetContext(ceed_data->qf_rhs_vol,
354841e4c73SJed Brown                             problem->apply_vol_rhs.qfunction_context);
355841e4c73SJed Brown     CeedQFunctionContextDestroy(&problem->apply_vol_rhs.qfunction_context);
35677841947SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "q", num_comp_q, CEED_EVAL_INTERP);
357a3ae0734SJed Brown     CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "Grad_q", num_comp_q*dim,
35877841947SLeila Ghaffari                           CEED_EVAL_GRAD);
359a61c78d6SJeremy L Thompson     CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "qdata", q_data_size_vol,
36077841947SLeila Ghaffari                           CEED_EVAL_NONE);
36177841947SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "x", num_comp_x, CEED_EVAL_INTERP);
36277841947SLeila Ghaffari     CeedQFunctionAddOutput(ceed_data->qf_rhs_vol, "v", num_comp_q,
36377841947SLeila Ghaffari                            CEED_EVAL_INTERP);
364a3ae0734SJed Brown     CeedQFunctionAddOutput(ceed_data->qf_rhs_vol, "Grad_v", num_comp_q*dim,
36577841947SLeila Ghaffari                            CEED_EVAL_GRAD);
36677841947SLeila Ghaffari   }
36777841947SLeila Ghaffari 
36877841947SLeila Ghaffari   // -- Create QFunction for IFunction
36991e5af17SJed Brown   if (problem->apply_vol_ifunction.qfunction) {
37091e5af17SJed Brown     CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_ifunction.qfunction,
37191e5af17SJed Brown                                 problem->apply_vol_ifunction.qfunction_loc, &ceed_data->qf_ifunction_vol);
372841e4c73SJed Brown     CeedQFunctionSetContext(ceed_data->qf_ifunction_vol,
373841e4c73SJed Brown                             problem->apply_vol_ifunction.qfunction_context);
374841e4c73SJed Brown     CeedQFunctionContextDestroy(&problem->apply_vol_ifunction.qfunction_context);
37577841947SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "q", num_comp_q,
37677841947SLeila Ghaffari                           CEED_EVAL_INTERP);
377a3ae0734SJed Brown     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "Grad_q", num_comp_q*dim,
37877841947SLeila Ghaffari                           CEED_EVAL_GRAD);
379a61c78d6SJeremy L Thompson     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "q dot", num_comp_q,
38077841947SLeila Ghaffari                           CEED_EVAL_INTERP);
381a61c78d6SJeremy L Thompson     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "qdata", q_data_size_vol,
38277841947SLeila Ghaffari                           CEED_EVAL_NONE);
38377841947SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "x", num_comp_x,
38477841947SLeila Ghaffari                           CEED_EVAL_INTERP);
38577841947SLeila Ghaffari     CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "v", num_comp_q,
38677841947SLeila Ghaffari                            CEED_EVAL_INTERP);
387a3ae0734SJed Brown     CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "Grad_v", num_comp_q*dim,
38877841947SLeila Ghaffari                            CEED_EVAL_GRAD);
389a3ae0734SJed Brown     CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "jac_data",
390a3ae0734SJed Brown                            jac_data_size_vol, CEED_EVAL_NONE);
39177841947SLeila Ghaffari   }
39277841947SLeila Ghaffari 
393e334ad8fSJed Brown   CeedQFunction qf_ijacobian_vol = NULL;
394e334ad8fSJed Brown   if (problem->apply_vol_ijacobian.qfunction) {
395e334ad8fSJed Brown     CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_ijacobian.qfunction,
396e334ad8fSJed Brown                                 problem->apply_vol_ijacobian.qfunction_loc, &qf_ijacobian_vol);
397e334ad8fSJed Brown     CeedQFunctionSetContext(qf_ijacobian_vol,
398e334ad8fSJed Brown                             problem->apply_vol_ijacobian.qfunction_context);
399e334ad8fSJed Brown     CeedQFunctionContextDestroy(&problem->apply_vol_ijacobian.qfunction_context);
400e334ad8fSJed Brown     CeedQFunctionAddInput(qf_ijacobian_vol, "dq", num_comp_q,
401e334ad8fSJed Brown                           CEED_EVAL_INTERP);
402e334ad8fSJed Brown     CeedQFunctionAddInput(qf_ijacobian_vol, "Grad_dq", num_comp_q*dim,
403e334ad8fSJed Brown                           CEED_EVAL_GRAD);
404e334ad8fSJed Brown     CeedQFunctionAddInput(qf_ijacobian_vol, "qdata", q_data_size_vol,
405e334ad8fSJed Brown                           CEED_EVAL_NONE);
406e334ad8fSJed Brown     CeedQFunctionAddInput(qf_ijacobian_vol, "x", num_comp_x,
407e334ad8fSJed Brown                           CEED_EVAL_INTERP);
408e334ad8fSJed Brown     CeedQFunctionAddInput(qf_ijacobian_vol, "jac_data",
409e334ad8fSJed Brown                           jac_data_size_vol, CEED_EVAL_NONE);
410e334ad8fSJed Brown     CeedQFunctionAddOutput(qf_ijacobian_vol, "v", num_comp_q,
411e334ad8fSJed Brown                            CEED_EVAL_INTERP);
412e334ad8fSJed Brown     CeedQFunctionAddOutput(qf_ijacobian_vol, "Grad_v", num_comp_q*dim,
413e334ad8fSJed Brown                            CEED_EVAL_GRAD);
414e334ad8fSJed Brown   }
415e334ad8fSJed Brown 
41677841947SLeila Ghaffari   // ---------------------------------------------------------------------------
41777841947SLeila Ghaffari   // Element coordinates
41877841947SLeila Ghaffari   // ---------------------------------------------------------------------------
41977841947SLeila Ghaffari   // -- Create CEED vector
42077841947SLeila Ghaffari   CeedElemRestrictionCreateVector(ceed_data->elem_restr_x, &ceed_data->x_coord,
42177841947SLeila Ghaffari                                   NULL);
42277841947SLeila Ghaffari 
42377841947SLeila Ghaffari   // -- Copy PETSc vector in CEED vector
42477841947SLeila Ghaffari   Vec               X_loc;
42577841947SLeila Ghaffari   const PetscScalar *X_loc_array;
4263796c488SJed Brown   {
4273796c488SJed Brown     DM cdm;
4283796c488SJed Brown     ierr = DMGetCellCoordinateDM(dm, &cdm); CHKERRQ(ierr);
4293796c488SJed Brown     if (cdm) {ierr = DMGetCellCoordinatesLocal(dm, &X_loc); CHKERRQ(ierr);}
4303796c488SJed Brown     else {ierr = DMGetCoordinatesLocal(dm, &X_loc); CHKERRQ(ierr);}
4313796c488SJed Brown   }
4321864f1c2SLeila Ghaffari   ierr = VecScale(X_loc, problem->dm_scale); CHKERRQ(ierr);
43377841947SLeila Ghaffari   ierr = VecGetArrayRead(X_loc, &X_loc_array); CHKERRQ(ierr);
43477841947SLeila Ghaffari   CeedVectorSetArray(ceed_data->x_coord, CEED_MEM_HOST, CEED_COPY_VALUES,
43577841947SLeila Ghaffari                      (PetscScalar *)X_loc_array);
43677841947SLeila Ghaffari   ierr = VecRestoreArrayRead(X_loc, &X_loc_array); CHKERRQ(ierr);
43777841947SLeila Ghaffari 
43877841947SLeila Ghaffari   // -----------------------------------------------------------------------------
43977841947SLeila Ghaffari   // CEED vectors
44077841947SLeila Ghaffari   // -----------------------------------------------------------------------------
44177841947SLeila Ghaffari   // -- Create CEED vector for geometric data
44277841947SLeila Ghaffari   CeedInt  num_qpts_vol;
44377841947SLeila Ghaffari   PetscInt loc_num_elem_vol;
44477841947SLeila Ghaffari   CeedBasisGetNumQuadraturePoints(ceed_data->basis_q, &num_qpts_vol);
44577841947SLeila Ghaffari   CeedElemRestrictionGetNumElements(ceed_data->elem_restr_q, &loc_num_elem_vol);
44677841947SLeila Ghaffari   CeedVectorCreate(ceed, q_data_size_vol*loc_num_elem_vol*num_qpts_vol,
44777841947SLeila Ghaffari                    &ceed_data->q_data);
44877841947SLeila Ghaffari 
449a3ae0734SJed Brown   CeedElemRestrictionCreateVector(elem_restr_jd_i, &jac_data, NULL);
45077841947SLeila Ghaffari   // -----------------------------------------------------------------------------
45177841947SLeila Ghaffari   // CEED Operators
45277841947SLeila Ghaffari   // -----------------------------------------------------------------------------
45377841947SLeila Ghaffari   // -- Create CEED operator for quadrature data
45477841947SLeila Ghaffari   CeedOperatorCreate(ceed, ceed_data->qf_setup_vol, NULL, NULL,
45577841947SLeila Ghaffari                      &ceed_data->op_setup_vol);
45677841947SLeila Ghaffari   CeedOperatorSetField(ceed_data->op_setup_vol, "dx", ceed_data->elem_restr_x,
45777841947SLeila Ghaffari                        ceed_data->basis_x, CEED_VECTOR_ACTIVE);
45877841947SLeila Ghaffari   CeedOperatorSetField(ceed_data->op_setup_vol, "weight",
459e6225c47SLeila Ghaffari                        CEED_ELEMRESTRICTION_NONE, ceed_data->basis_x, CEED_VECTOR_NONE);
460a61c78d6SJeremy L Thompson   CeedOperatorSetField(ceed_data->op_setup_vol, "qdata",
461e6225c47SLeila Ghaffari                        ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE);
46277841947SLeila Ghaffari 
46377841947SLeila Ghaffari   // -- Create CEED operator for ICs
46477841947SLeila Ghaffari   CeedOperatorCreate(ceed, ceed_data->qf_ics, NULL, NULL, &ceed_data->op_ics);
46577841947SLeila Ghaffari   CeedOperatorSetField(ceed_data->op_ics, "x", ceed_data->elem_restr_x,
46677841947SLeila Ghaffari                        ceed_data->basis_xc, CEED_VECTOR_ACTIVE);
46777841947SLeila Ghaffari   CeedOperatorSetField(ceed_data->op_ics, "q0", ceed_data->elem_restr_q,
46877841947SLeila Ghaffari                        CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE);
469841e4c73SJed Brown   CeedOperatorContextGetFieldLabel(ceed_data->op_ics, "evaluation time",
470841e4c73SJed Brown                                    &user->phys->ics_time_label);
47177841947SLeila Ghaffari 
47277841947SLeila Ghaffari   // Create CEED operator for RHS
47377841947SLeila Ghaffari   if (ceed_data->qf_rhs_vol) {
47477841947SLeila Ghaffari     CeedOperator op;
47577841947SLeila Ghaffari     CeedOperatorCreate(ceed, ceed_data->qf_rhs_vol, NULL, NULL, &op);
47677841947SLeila Ghaffari     CeedOperatorSetField(op, "q", ceed_data->elem_restr_q, ceed_data->basis_q,
47777841947SLeila Ghaffari                          CEED_VECTOR_ACTIVE);
478a3ae0734SJed Brown     CeedOperatorSetField(op, "Grad_q", ceed_data->elem_restr_q, ceed_data->basis_q,
47977841947SLeila Ghaffari                          CEED_VECTOR_ACTIVE);
480a61c78d6SJeremy L Thompson     CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i,
481e6225c47SLeila Ghaffari                          CEED_BASIS_COLLOCATED, ceed_data->q_data);
48277841947SLeila Ghaffari     CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x,
48377841947SLeila Ghaffari                          ceed_data->x_coord);
48477841947SLeila Ghaffari     CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q,
48577841947SLeila Ghaffari                          CEED_VECTOR_ACTIVE);
486a3ae0734SJed Brown     CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q,
48777841947SLeila Ghaffari                          CEED_VECTOR_ACTIVE);
48877841947SLeila Ghaffari     user->op_rhs_vol = op;
48977841947SLeila Ghaffari   }
49077841947SLeila Ghaffari 
49177841947SLeila Ghaffari   // -- CEED operator for IFunction
49277841947SLeila Ghaffari   if (ceed_data->qf_ifunction_vol) {
49377841947SLeila Ghaffari     CeedOperator op;
49477841947SLeila Ghaffari     CeedOperatorCreate(ceed, ceed_data->qf_ifunction_vol, NULL, NULL, &op);
49577841947SLeila Ghaffari     CeedOperatorSetField(op, "q", ceed_data->elem_restr_q, ceed_data->basis_q,
49677841947SLeila Ghaffari                          CEED_VECTOR_ACTIVE);
497a3ae0734SJed Brown     CeedOperatorSetField(op, "Grad_q", ceed_data->elem_restr_q, ceed_data->basis_q,
49877841947SLeila Ghaffari                          CEED_VECTOR_ACTIVE);
499a61c78d6SJeremy L Thompson     CeedOperatorSetField(op, "q dot", ceed_data->elem_restr_q, ceed_data->basis_q,
50077841947SLeila Ghaffari                          user->q_dot_ceed);
501a61c78d6SJeremy L Thompson     CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i,
502e6225c47SLeila Ghaffari                          CEED_BASIS_COLLOCATED, ceed_data->q_data);
50377841947SLeila Ghaffari     CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x,
50477841947SLeila Ghaffari                          ceed_data->x_coord);
50577841947SLeila Ghaffari     CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q,
50677841947SLeila Ghaffari                          CEED_VECTOR_ACTIVE);
507a3ae0734SJed Brown     CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q,
50877841947SLeila Ghaffari                          CEED_VECTOR_ACTIVE);
509a3ae0734SJed Brown     CeedOperatorSetField(op, "jac_data", elem_restr_jd_i,
510a3ae0734SJed Brown                          CEED_BASIS_COLLOCATED, jac_data);
511a3ae0734SJed Brown 
51277841947SLeila Ghaffari     user->op_ifunction_vol = op;
51377841947SLeila Ghaffari   }
51477841947SLeila Ghaffari 
515e334ad8fSJed Brown   CeedOperator op_ijacobian_vol = NULL;
516e334ad8fSJed Brown   if (qf_ijacobian_vol) {
517e334ad8fSJed Brown     CeedOperator op;
518e334ad8fSJed Brown     CeedOperatorCreate(ceed, qf_ijacobian_vol, NULL, NULL, &op);
519e334ad8fSJed Brown     CeedOperatorSetField(op, "dq", ceed_data->elem_restr_q, ceed_data->basis_q,
520e334ad8fSJed Brown                          CEED_VECTOR_ACTIVE);
521e334ad8fSJed Brown     CeedOperatorSetField(op, "Grad_dq", ceed_data->elem_restr_q, ceed_data->basis_q,
522e334ad8fSJed Brown                          CEED_VECTOR_ACTIVE);
523e334ad8fSJed Brown     CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i,
524e334ad8fSJed Brown                          CEED_BASIS_COLLOCATED, ceed_data->q_data);
525e334ad8fSJed Brown     CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x,
526e334ad8fSJed Brown                          ceed_data->x_coord);
527e334ad8fSJed Brown     CeedOperatorSetField(op, "jac_data", elem_restr_jd_i,
528e334ad8fSJed Brown                          CEED_BASIS_COLLOCATED, jac_data);
529e334ad8fSJed Brown     CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q,
530e334ad8fSJed Brown                          CEED_VECTOR_ACTIVE);
531e334ad8fSJed Brown     CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q,
532e334ad8fSJed Brown                          CEED_VECTOR_ACTIVE);
533e334ad8fSJed Brown     op_ijacobian_vol = op;
534e334ad8fSJed Brown     CeedQFunctionDestroy(&qf_ijacobian_vol);
535e334ad8fSJed Brown   }
536e334ad8fSJed Brown 
53777841947SLeila Ghaffari   // *****************************************************************************
53877841947SLeila Ghaffari   // Set up CEED objects for the exterior domain (surface)
53977841947SLeila Ghaffari   // *****************************************************************************
54077841947SLeila Ghaffari   CeedInt height  = 1,
54177841947SLeila Ghaffari           dim_sur = dim - height,
54277841947SLeila Ghaffari           P_sur   = app_ctx->degree + 1,
54377841947SLeila Ghaffari           Q_sur   = P_sur + app_ctx->q_extra;
544e334ad8fSJed Brown   const CeedInt q_data_size_sur = problem->q_data_size_sur,
545e334ad8fSJed Brown                 jac_data_size_sur = problem->jac_data_size_sur;
54677841947SLeila Ghaffari 
54777841947SLeila Ghaffari   // -----------------------------------------------------------------------------
54877841947SLeila Ghaffari   // CEED Bases
54977841947SLeila Ghaffari   // -----------------------------------------------------------------------------
55077841947SLeila Ghaffari   CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_q, P_sur, Q_sur,
55177841947SLeila Ghaffari                                   CEED_GAUSS, &ceed_data->basis_q_sur);
55277841947SLeila Ghaffari   CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_x, 2, Q_sur, CEED_GAUSS,
55377841947SLeila Ghaffari                                   &ceed_data->basis_x_sur);
554959b8288SJames Wright   CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_x, 2, P_sur,
555959b8288SJames Wright                                   CEED_GAUSS_LOBATTO, &ceed_data->basis_xc_sur);
55677841947SLeila Ghaffari 
55777841947SLeila Ghaffari   // -----------------------------------------------------------------------------
55877841947SLeila Ghaffari   // CEED QFunctions
55977841947SLeila Ghaffari   // -----------------------------------------------------------------------------
56077841947SLeila Ghaffari   // -- Create QFunction for quadrature data
56191e5af17SJed Brown   CeedQFunctionCreateInterior(ceed, 1, problem->setup_sur.qfunction,
56291e5af17SJed Brown                               problem->setup_sur.qfunction_loc,
56377841947SLeila Ghaffari                               &ceed_data->qf_setup_sur);
564841e4c73SJed Brown   if (problem->setup_sur.qfunction_context) {
565841e4c73SJed Brown     CeedQFunctionSetContext(ceed_data->qf_setup_sur,
566841e4c73SJed Brown                             problem->setup_sur.qfunction_context);
567841e4c73SJed Brown     CeedQFunctionContextDestroy(&problem->setup_sur.qfunction_context);
568841e4c73SJed Brown   }
56977841947SLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_setup_sur, "dx", num_comp_x*dim_sur,
57077841947SLeila Ghaffari                         CEED_EVAL_GRAD);
57177841947SLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_setup_sur, "weight", 1, CEED_EVAL_WEIGHT);
572a61c78d6SJeremy L Thompson   CeedQFunctionAddOutput(ceed_data->qf_setup_sur, "surface qdata",
5732fe7aee7SLeila Ghaffari                          q_data_size_sur, CEED_EVAL_NONE);
57477841947SLeila Ghaffari 
575*5b881d11SJames Wright   PetscCall(SetupBCQFunctions(ceed, dim_sur, num_comp_x, num_comp_q,
576*5b881d11SJames Wright                               q_data_size_sur, jac_data_size_sur,
577*5b881d11SJames Wright                               problem->apply_inflow, problem->apply_inflow_jacobian,
578*5b881d11SJames Wright                               &ceed_data->qf_apply_inflow, &ceed_data->qf_apply_inflow_jacobian));
5792fe7aee7SLeila Ghaffari 
580*5b881d11SJames Wright   // -- Create QFunction for outflow boundaries
581*5b881d11SJames Wright   PetscCall(SetupBCQFunctions(ceed, dim_sur, num_comp_x, num_comp_q,
582*5b881d11SJames Wright                               q_data_size_sur, jac_data_size_sur,
583*5b881d11SJames Wright                               problem->apply_outflow, problem->apply_outflow_jacobian,
584*5b881d11SJames Wright                               &ceed_data->qf_apply_outflow, &ceed_data->qf_apply_outflow_jacobian));
58577841947SLeila Ghaffari 
58677841947SLeila Ghaffari   // *****************************************************************************
58777841947SLeila Ghaffari   // CEED Operator Apply
58877841947SLeila Ghaffari   // *****************************************************************************
58977841947SLeila Ghaffari   // -- Apply CEED Operator for the geometric data
59077841947SLeila Ghaffari   CeedOperatorApply(ceed_data->op_setup_vol, ceed_data->x_coord,
59177841947SLeila Ghaffari                     ceed_data->q_data, CEED_REQUEST_IMMEDIATE);
59277841947SLeila Ghaffari 
59377841947SLeila Ghaffari   // -- Create and apply CEED Composite Operator for the entire domain
59477841947SLeila Ghaffari   if (!user->phys->implicit) { // RHS
59577841947SLeila Ghaffari     ierr = CreateOperatorForDomain(ceed, dm, bc, ceed_data, user->phys,
596e334ad8fSJed Brown                                    user->op_rhs_vol, NULL, height, P_sur, Q_sur,
597e334ad8fSJed Brown                                    q_data_size_sur, 0,
598e334ad8fSJed Brown                                    &user->op_rhs, NULL); CHKERRQ(ierr);
59977841947SLeila Ghaffari   } else { // IFunction
60077841947SLeila Ghaffari     ierr = CreateOperatorForDomain(ceed, dm, bc, ceed_data, user->phys,
601e334ad8fSJed Brown                                    user->op_ifunction_vol, op_ijacobian_vol,
602e334ad8fSJed Brown                                    height, P_sur, Q_sur,
603e334ad8fSJed Brown                                    q_data_size_sur, jac_data_size_sur,
604e334ad8fSJed Brown                                    &user->op_ifunction,
605e334ad8fSJed Brown                                    op_ijacobian_vol ? &user->op_ijacobian : NULL); CHKERRQ(ierr);
606e334ad8fSJed Brown     if (user->op_ijacobian) {
607e334ad8fSJed Brown       CeedOperatorContextGetFieldLabel(user->op_ijacobian, "ijacobian time shift",
608e334ad8fSJed Brown                                        &user->phys->ijacobian_time_shift_label);
609e334ad8fSJed Brown     }
610dada6cc0SJames Wright     if (problem->use_dirichlet_ceed) {
611dada6cc0SJames Wright       PetscCall(SetupStrongBC_Ceed(ceed, ceed_data, dm, user, app_ctx, problem, bc,
612dada6cc0SJames Wright                                    Q_sur, q_data_size_sur));
613dada6cc0SJames Wright     }
614e334ad8fSJed Brown 
61577841947SLeila Ghaffari   }
616a3ae0734SJed Brown   CeedElemRestrictionDestroy(&elem_restr_jd_i);
61722d320f5SLeila Ghaffari   CeedOperatorDestroy(&op_ijacobian_vol);
618a3ae0734SJed Brown   CeedVectorDestroy(&jac_data);
61977841947SLeila Ghaffari   PetscFunctionReturn(0);
62077841947SLeila Ghaffari }
621