xref: /libCEED/examples/fluids/src/setuplibceed.c (revision f4ca79c23e4a2a7ed05a55bf6f356bad2d03ca2a)
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     }
226*f4ca79c2SJames Wright 
227*f4ca79c2SJames Wright     // --- Create Sub-Operator for freestream boundaries
228*f4ca79c2SJames Wright     for (CeedInt i=0; i < bc->num_freestream; i++) {
229*f4ca79c2SJames Wright       PetscCall(AddBCSubOperator(ceed, dm, ceed_data, domain_label,
230*f4ca79c2SJames Wright                                  bc->freestreams[i], height, Q_sur, q_data_size_sur, jac_data_size_sur,
231*f4ca79c2SJames Wright                                  ceed_data->qf_apply_freestream, ceed_data->qf_apply_freestream_jacobian,
232*f4ca79c2SJames Wright                                  op_apply, op_apply_ijacobian));
233*f4ca79c2SJames Wright     }
2342fe7aee7SLeila Ghaffari   }
23511436a05SJames Wright 
23611436a05SJames Wright   // ----- Get Context Labels for Operator
23711436a05SJames Wright   CeedOperatorContextGetFieldLabel(*op_apply, "solution time",
23811436a05SJames Wright                                    &phys->solution_time_label);
23988626eedSJames Wright   CeedOperatorContextGetFieldLabel(*op_apply, "timestep size",
24088626eedSJames Wright                                    &phys->timestep_size_label);
24111436a05SJames Wright 
24277841947SLeila Ghaffari   PetscFunctionReturn(0);
24377841947SLeila Ghaffari }
24477841947SLeila Ghaffari 
2455b881d11SJames Wright PetscErrorCode SetupBCQFunctions(Ceed ceed, PetscInt dim_sur,
2465b881d11SJames Wright                                  PetscInt num_comp_x, PetscInt num_comp_q,
2475b881d11SJames Wright                                  PetscInt q_data_size_sur, PetscInt jac_data_size_sur,
2485b881d11SJames Wright                                  ProblemQFunctionSpec apply_bc, ProblemQFunctionSpec apply_bc_jacobian,
2495b881d11SJames Wright                                  CeedQFunction *qf_apply_bc, CeedQFunction *qf_apply_bc_jacobian) {
2505b881d11SJames Wright   PetscFunctionBeginUser;
2515b881d11SJames Wright 
2525b881d11SJames Wright   if (apply_bc.qfunction) {
2535b881d11SJames Wright     // *INDENT-OFF*
2545b881d11SJames Wright     CeedQFunctionCreateInterior(ceed, 1, apply_bc.qfunction, apply_bc.qfunction_loc, qf_apply_bc);
2555b881d11SJames Wright     CeedQFunctionSetContext(*qf_apply_bc, apply_bc.qfunction_context);
2565b881d11SJames Wright     CeedQFunctionContextDestroy(&apply_bc.qfunction_context);
2575b881d11SJames Wright     CeedQFunctionAddInput(*qf_apply_bc, "q", num_comp_q, CEED_EVAL_INTERP);
2585b881d11SJames Wright     CeedQFunctionAddInput(*qf_apply_bc, "Grad_q", num_comp_q*dim_sur, CEED_EVAL_GRAD);
2595b881d11SJames Wright     CeedQFunctionAddInput(*qf_apply_bc, "surface qdata", q_data_size_sur, CEED_EVAL_NONE);
2605b881d11SJames Wright     CeedQFunctionAddInput(*qf_apply_bc, "x", num_comp_x, CEED_EVAL_INTERP);
2615b881d11SJames Wright     CeedQFunctionAddOutput(*qf_apply_bc, "v", num_comp_q, CEED_EVAL_INTERP);
2625b881d11SJames Wright     // *INDENT-ON*
2635b881d11SJames Wright     if (jac_data_size_sur)
2645b881d11SJames Wright       CeedQFunctionAddOutput(*qf_apply_bc, "surface jacobian data", jac_data_size_sur,
2655b881d11SJames Wright                              CEED_EVAL_NONE);
2665b881d11SJames Wright   }
2675b881d11SJames Wright   if (apply_bc_jacobian.qfunction) {
2685b881d11SJames Wright     // *INDENT-OFF*
2695b881d11SJames Wright     CeedQFunctionCreateInterior(ceed, 1, apply_bc_jacobian.qfunction,
2705b881d11SJames Wright                                 apply_bc_jacobian.qfunction_loc, qf_apply_bc_jacobian);
2715b881d11SJames Wright     CeedQFunctionSetContext(*qf_apply_bc_jacobian, apply_bc_jacobian.qfunction_context);
2725b881d11SJames Wright     CeedQFunctionContextDestroy(&apply_bc_jacobian.qfunction_context);
2735b881d11SJames Wright     CeedQFunctionAddInput(*qf_apply_bc_jacobian, "dq", num_comp_q, CEED_EVAL_INTERP);
2745b881d11SJames Wright     CeedQFunctionAddInput(*qf_apply_bc_jacobian, "Grad_dq", num_comp_q*dim_sur, CEED_EVAL_GRAD);
2755b881d11SJames Wright     CeedQFunctionAddInput(*qf_apply_bc_jacobian, "surface qdata", q_data_size_sur, CEED_EVAL_NONE);
2765b881d11SJames Wright     CeedQFunctionAddInput(*qf_apply_bc_jacobian, "x", num_comp_x, CEED_EVAL_INTERP);
2775b881d11SJames Wright     CeedQFunctionAddInput(*qf_apply_bc_jacobian, "surface jacobian data",
2785b881d11SJames Wright                           jac_data_size_sur, CEED_EVAL_NONE);
2795b881d11SJames Wright     CeedQFunctionAddOutput(*qf_apply_bc_jacobian, "v", num_comp_q, CEED_EVAL_INTERP);
2805b881d11SJames Wright     // *INDENT-ON*
2815b881d11SJames Wright   }
2825b881d11SJames Wright   PetscFunctionReturn(0);
2835b881d11SJames Wright }
2845b881d11SJames Wright 
28577841947SLeila Ghaffari PetscErrorCode SetupLibceed(Ceed ceed, CeedData ceed_data, DM dm, User user,
286c95f9967SJed Brown                             AppCtx app_ctx, ProblemData *problem, SimpleBC bc) {
28777841947SLeila Ghaffari   PetscErrorCode ierr;
28877841947SLeila Ghaffari   PetscFunctionBeginUser;
28977841947SLeila Ghaffari 
29077841947SLeila Ghaffari   // *****************************************************************************
29177841947SLeila Ghaffari   // Set up CEED objects for the interior domain (volume)
29277841947SLeila Ghaffari   // *****************************************************************************
29377841947SLeila Ghaffari   const PetscInt num_comp_q      = 5;
29477841947SLeila Ghaffari   const CeedInt  dim             = problem->dim,
29577841947SLeila Ghaffari                  num_comp_x      = problem->dim,
29677841947SLeila Ghaffari                  q_data_size_vol = problem->q_data_size_vol,
297e334ad8fSJed Brown                  jac_data_size_vol = num_comp_q + 6 + 3,
29877841947SLeila Ghaffari                  P               = app_ctx->degree + 1,
29977841947SLeila Ghaffari                  Q               = P + app_ctx->q_extra;
300a3ae0734SJed Brown   CeedElemRestriction elem_restr_jd_i;
301a3ae0734SJed Brown   CeedVector jac_data;
30277841947SLeila Ghaffari 
30377841947SLeila Ghaffari   // -----------------------------------------------------------------------------
30477841947SLeila Ghaffari   // CEED Bases
30577841947SLeila Ghaffari   // -----------------------------------------------------------------------------
30677841947SLeila Ghaffari   CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_q, P, Q, CEED_GAUSS,
30777841947SLeila Ghaffari                                   &ceed_data->basis_q);
30877841947SLeila Ghaffari   CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_x, 2, Q, CEED_GAUSS,
30977841947SLeila Ghaffari                                   &ceed_data->basis_x);
31077841947SLeila Ghaffari   CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_x, 2, P,
31177841947SLeila Ghaffari                                   CEED_GAUSS_LOBATTO, &ceed_data->basis_xc);
31277841947SLeila Ghaffari 
31377841947SLeila Ghaffari   // -----------------------------------------------------------------------------
31477841947SLeila Ghaffari   // CEED Restrictions
31577841947SLeila Ghaffari   // -----------------------------------------------------------------------------
31677841947SLeila Ghaffari   // -- Create restriction
3177ed3e4cdSJeremy L Thompson   ierr = GetRestrictionForDomain(ceed, dm, 0, 0, 0, Q, q_data_size_vol,
3187ed3e4cdSJeremy L Thompson                                  &ceed_data->elem_restr_q, &ceed_data->elem_restr_x,
31977841947SLeila Ghaffari                                  &ceed_data->elem_restr_qd_i); CHKERRQ(ierr);
320a3ae0734SJed Brown 
321a3ae0734SJed Brown   ierr = GetRestrictionForDomain(ceed, dm, 0, 0, 0, Q, jac_data_size_vol,
322a3ae0734SJed Brown                                  NULL, NULL,
323a3ae0734SJed Brown                                  &elem_restr_jd_i); CHKERRQ(ierr);
32477841947SLeila Ghaffari // -- Create E vectors
32577841947SLeila Ghaffari   CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->q_ceed, NULL);
32677841947SLeila Ghaffari   CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->q_dot_ceed,
32777841947SLeila Ghaffari                                   NULL);
32877841947SLeila Ghaffari   CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->g_ceed, NULL);
32977841947SLeila Ghaffari 
33077841947SLeila Ghaffari   // -----------------------------------------------------------------------------
33177841947SLeila Ghaffari   // CEED QFunctions
33277841947SLeila Ghaffari   // -----------------------------------------------------------------------------
33377841947SLeila Ghaffari   // -- Create QFunction for quadrature data
33491e5af17SJed Brown   CeedQFunctionCreateInterior(ceed, 1, problem->setup_vol.qfunction,
33591e5af17SJed Brown                               problem->setup_vol.qfunction_loc,
33677841947SLeila Ghaffari                               &ceed_data->qf_setup_vol);
337841e4c73SJed Brown   if (problem->setup_vol.qfunction_context) {
338841e4c73SJed Brown     CeedQFunctionSetContext(ceed_data->qf_setup_vol,
339841e4c73SJed Brown                             problem->setup_vol.qfunction_context);
340841e4c73SJed Brown     CeedQFunctionContextDestroy(&problem->setup_vol.qfunction_context);
341841e4c73SJed Brown   }
34277841947SLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_setup_vol, "dx", num_comp_x*dim,
34377841947SLeila Ghaffari                         CEED_EVAL_GRAD);
34477841947SLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_setup_vol, "weight", 1, CEED_EVAL_WEIGHT);
345a61c78d6SJeremy L Thompson   CeedQFunctionAddOutput(ceed_data->qf_setup_vol, "qdata", q_data_size_vol,
34677841947SLeila Ghaffari                          CEED_EVAL_NONE);
34777841947SLeila Ghaffari 
34877841947SLeila Ghaffari   // -- Create QFunction for ICs
34991e5af17SJed Brown   CeedQFunctionCreateInterior(ceed, 1, problem->ics.qfunction,
35091e5af17SJed Brown                               problem->ics.qfunction_loc,
35177841947SLeila Ghaffari                               &ceed_data->qf_ics);
352841e4c73SJed Brown   CeedQFunctionSetContext(ceed_data->qf_ics, problem->ics.qfunction_context);
353841e4c73SJed Brown   CeedQFunctionContextDestroy(&problem->ics.qfunction_context);
35477841947SLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_ics, "x", num_comp_x, CEED_EVAL_INTERP);
35577841947SLeila Ghaffari   CeedQFunctionAddOutput(ceed_data->qf_ics, "q0", num_comp_q, CEED_EVAL_NONE);
35677841947SLeila Ghaffari 
35777841947SLeila Ghaffari   // -- Create QFunction for RHS
35891e5af17SJed Brown   if (problem->apply_vol_rhs.qfunction) {
35991e5af17SJed Brown     CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_rhs.qfunction,
36091e5af17SJed Brown                                 problem->apply_vol_rhs.qfunction_loc, &ceed_data->qf_rhs_vol);
361841e4c73SJed Brown     CeedQFunctionSetContext(ceed_data->qf_rhs_vol,
362841e4c73SJed Brown                             problem->apply_vol_rhs.qfunction_context);
363841e4c73SJed Brown     CeedQFunctionContextDestroy(&problem->apply_vol_rhs.qfunction_context);
36477841947SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "q", num_comp_q, CEED_EVAL_INTERP);
365a3ae0734SJed Brown     CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "Grad_q", num_comp_q*dim,
36677841947SLeila Ghaffari                           CEED_EVAL_GRAD);
367a61c78d6SJeremy L Thompson     CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "qdata", q_data_size_vol,
36877841947SLeila Ghaffari                           CEED_EVAL_NONE);
36977841947SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "x", num_comp_x, CEED_EVAL_INTERP);
37077841947SLeila Ghaffari     CeedQFunctionAddOutput(ceed_data->qf_rhs_vol, "v", num_comp_q,
37177841947SLeila Ghaffari                            CEED_EVAL_INTERP);
372a3ae0734SJed Brown     CeedQFunctionAddOutput(ceed_data->qf_rhs_vol, "Grad_v", num_comp_q*dim,
37377841947SLeila Ghaffari                            CEED_EVAL_GRAD);
37477841947SLeila Ghaffari   }
37577841947SLeila Ghaffari 
37677841947SLeila Ghaffari   // -- Create QFunction for IFunction
37791e5af17SJed Brown   if (problem->apply_vol_ifunction.qfunction) {
37891e5af17SJed Brown     CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_ifunction.qfunction,
37991e5af17SJed Brown                                 problem->apply_vol_ifunction.qfunction_loc, &ceed_data->qf_ifunction_vol);
380841e4c73SJed Brown     CeedQFunctionSetContext(ceed_data->qf_ifunction_vol,
381841e4c73SJed Brown                             problem->apply_vol_ifunction.qfunction_context);
382841e4c73SJed Brown     CeedQFunctionContextDestroy(&problem->apply_vol_ifunction.qfunction_context);
38377841947SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "q", num_comp_q,
38477841947SLeila Ghaffari                           CEED_EVAL_INTERP);
385a3ae0734SJed Brown     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "Grad_q", num_comp_q*dim,
38677841947SLeila Ghaffari                           CEED_EVAL_GRAD);
387a61c78d6SJeremy L Thompson     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "q dot", num_comp_q,
38877841947SLeila Ghaffari                           CEED_EVAL_INTERP);
389a61c78d6SJeremy L Thompson     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "qdata", q_data_size_vol,
39077841947SLeila Ghaffari                           CEED_EVAL_NONE);
39177841947SLeila Ghaffari     CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "x", num_comp_x,
39277841947SLeila Ghaffari                           CEED_EVAL_INTERP);
39377841947SLeila Ghaffari     CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "v", num_comp_q,
39477841947SLeila Ghaffari                            CEED_EVAL_INTERP);
395a3ae0734SJed Brown     CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "Grad_v", num_comp_q*dim,
39677841947SLeila Ghaffari                            CEED_EVAL_GRAD);
397a3ae0734SJed Brown     CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "jac_data",
398a3ae0734SJed Brown                            jac_data_size_vol, CEED_EVAL_NONE);
39977841947SLeila Ghaffari   }
40077841947SLeila Ghaffari 
401e334ad8fSJed Brown   CeedQFunction qf_ijacobian_vol = NULL;
402e334ad8fSJed Brown   if (problem->apply_vol_ijacobian.qfunction) {
403e334ad8fSJed Brown     CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_ijacobian.qfunction,
404e334ad8fSJed Brown                                 problem->apply_vol_ijacobian.qfunction_loc, &qf_ijacobian_vol);
405e334ad8fSJed Brown     CeedQFunctionSetContext(qf_ijacobian_vol,
406e334ad8fSJed Brown                             problem->apply_vol_ijacobian.qfunction_context);
407e334ad8fSJed Brown     CeedQFunctionContextDestroy(&problem->apply_vol_ijacobian.qfunction_context);
408e334ad8fSJed Brown     CeedQFunctionAddInput(qf_ijacobian_vol, "dq", num_comp_q,
409e334ad8fSJed Brown                           CEED_EVAL_INTERP);
410e334ad8fSJed Brown     CeedQFunctionAddInput(qf_ijacobian_vol, "Grad_dq", num_comp_q*dim,
411e334ad8fSJed Brown                           CEED_EVAL_GRAD);
412e334ad8fSJed Brown     CeedQFunctionAddInput(qf_ijacobian_vol, "qdata", q_data_size_vol,
413e334ad8fSJed Brown                           CEED_EVAL_NONE);
414e334ad8fSJed Brown     CeedQFunctionAddInput(qf_ijacobian_vol, "x", num_comp_x,
415e334ad8fSJed Brown                           CEED_EVAL_INTERP);
416e334ad8fSJed Brown     CeedQFunctionAddInput(qf_ijacobian_vol, "jac_data",
417e334ad8fSJed Brown                           jac_data_size_vol, CEED_EVAL_NONE);
418e334ad8fSJed Brown     CeedQFunctionAddOutput(qf_ijacobian_vol, "v", num_comp_q,
419e334ad8fSJed Brown                            CEED_EVAL_INTERP);
420e334ad8fSJed Brown     CeedQFunctionAddOutput(qf_ijacobian_vol, "Grad_v", num_comp_q*dim,
421e334ad8fSJed Brown                            CEED_EVAL_GRAD);
422e334ad8fSJed Brown   }
423e334ad8fSJed Brown 
42477841947SLeila Ghaffari   // ---------------------------------------------------------------------------
42577841947SLeila Ghaffari   // Element coordinates
42677841947SLeila Ghaffari   // ---------------------------------------------------------------------------
42777841947SLeila Ghaffari   // -- Create CEED vector
42877841947SLeila Ghaffari   CeedElemRestrictionCreateVector(ceed_data->elem_restr_x, &ceed_data->x_coord,
42977841947SLeila Ghaffari                                   NULL);
43077841947SLeila Ghaffari 
43177841947SLeila Ghaffari   // -- Copy PETSc vector in CEED vector
43277841947SLeila Ghaffari   Vec               X_loc;
43377841947SLeila Ghaffari   const PetscScalar *X_loc_array;
4343796c488SJed Brown   {
4353796c488SJed Brown     DM cdm;
4363796c488SJed Brown     ierr = DMGetCellCoordinateDM(dm, &cdm); CHKERRQ(ierr);
4373796c488SJed Brown     if (cdm) {ierr = DMGetCellCoordinatesLocal(dm, &X_loc); CHKERRQ(ierr);}
4383796c488SJed Brown     else {ierr = DMGetCoordinatesLocal(dm, &X_loc); CHKERRQ(ierr);}
4393796c488SJed Brown   }
4401864f1c2SLeila Ghaffari   ierr = VecScale(X_loc, problem->dm_scale); CHKERRQ(ierr);
44177841947SLeila Ghaffari   ierr = VecGetArrayRead(X_loc, &X_loc_array); CHKERRQ(ierr);
44277841947SLeila Ghaffari   CeedVectorSetArray(ceed_data->x_coord, CEED_MEM_HOST, CEED_COPY_VALUES,
44377841947SLeila Ghaffari                      (PetscScalar *)X_loc_array);
44477841947SLeila Ghaffari   ierr = VecRestoreArrayRead(X_loc, &X_loc_array); CHKERRQ(ierr);
44577841947SLeila Ghaffari 
44677841947SLeila Ghaffari   // -----------------------------------------------------------------------------
44777841947SLeila Ghaffari   // CEED vectors
44877841947SLeila Ghaffari   // -----------------------------------------------------------------------------
44977841947SLeila Ghaffari   // -- Create CEED vector for geometric data
45077841947SLeila Ghaffari   CeedInt  num_qpts_vol;
45177841947SLeila Ghaffari   PetscInt loc_num_elem_vol;
45277841947SLeila Ghaffari   CeedBasisGetNumQuadraturePoints(ceed_data->basis_q, &num_qpts_vol);
45377841947SLeila Ghaffari   CeedElemRestrictionGetNumElements(ceed_data->elem_restr_q, &loc_num_elem_vol);
45477841947SLeila Ghaffari   CeedVectorCreate(ceed, q_data_size_vol*loc_num_elem_vol*num_qpts_vol,
45577841947SLeila Ghaffari                    &ceed_data->q_data);
45677841947SLeila Ghaffari 
457a3ae0734SJed Brown   CeedElemRestrictionCreateVector(elem_restr_jd_i, &jac_data, NULL);
45877841947SLeila Ghaffari   // -----------------------------------------------------------------------------
45977841947SLeila Ghaffari   // CEED Operators
46077841947SLeila Ghaffari   // -----------------------------------------------------------------------------
46177841947SLeila Ghaffari   // -- Create CEED operator for quadrature data
46277841947SLeila Ghaffari   CeedOperatorCreate(ceed, ceed_data->qf_setup_vol, NULL, NULL,
46377841947SLeila Ghaffari                      &ceed_data->op_setup_vol);
46477841947SLeila Ghaffari   CeedOperatorSetField(ceed_data->op_setup_vol, "dx", ceed_data->elem_restr_x,
46577841947SLeila Ghaffari                        ceed_data->basis_x, CEED_VECTOR_ACTIVE);
46677841947SLeila Ghaffari   CeedOperatorSetField(ceed_data->op_setup_vol, "weight",
467e6225c47SLeila Ghaffari                        CEED_ELEMRESTRICTION_NONE, ceed_data->basis_x, CEED_VECTOR_NONE);
468a61c78d6SJeremy L Thompson   CeedOperatorSetField(ceed_data->op_setup_vol, "qdata",
469e6225c47SLeila Ghaffari                        ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE);
47077841947SLeila Ghaffari 
47177841947SLeila Ghaffari   // -- Create CEED operator for ICs
47277841947SLeila Ghaffari   CeedOperatorCreate(ceed, ceed_data->qf_ics, NULL, NULL, &ceed_data->op_ics);
47377841947SLeila Ghaffari   CeedOperatorSetField(ceed_data->op_ics, "x", ceed_data->elem_restr_x,
47477841947SLeila Ghaffari                        ceed_data->basis_xc, CEED_VECTOR_ACTIVE);
47577841947SLeila Ghaffari   CeedOperatorSetField(ceed_data->op_ics, "q0", ceed_data->elem_restr_q,
47677841947SLeila Ghaffari                        CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE);
477841e4c73SJed Brown   CeedOperatorContextGetFieldLabel(ceed_data->op_ics, "evaluation time",
478841e4c73SJed Brown                                    &user->phys->ics_time_label);
47977841947SLeila Ghaffari 
48077841947SLeila Ghaffari   // Create CEED operator for RHS
48177841947SLeila Ghaffari   if (ceed_data->qf_rhs_vol) {
48277841947SLeila Ghaffari     CeedOperator op;
48377841947SLeila Ghaffari     CeedOperatorCreate(ceed, ceed_data->qf_rhs_vol, NULL, NULL, &op);
48477841947SLeila Ghaffari     CeedOperatorSetField(op, "q", ceed_data->elem_restr_q, ceed_data->basis_q,
48577841947SLeila Ghaffari                          CEED_VECTOR_ACTIVE);
486a3ae0734SJed Brown     CeedOperatorSetField(op, "Grad_q", ceed_data->elem_restr_q, ceed_data->basis_q,
48777841947SLeila Ghaffari                          CEED_VECTOR_ACTIVE);
488a61c78d6SJeremy L Thompson     CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i,
489e6225c47SLeila Ghaffari                          CEED_BASIS_COLLOCATED, ceed_data->q_data);
49077841947SLeila Ghaffari     CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x,
49177841947SLeila Ghaffari                          ceed_data->x_coord);
49277841947SLeila Ghaffari     CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q,
49377841947SLeila Ghaffari                          CEED_VECTOR_ACTIVE);
494a3ae0734SJed Brown     CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q,
49577841947SLeila Ghaffari                          CEED_VECTOR_ACTIVE);
49677841947SLeila Ghaffari     user->op_rhs_vol = op;
49777841947SLeila Ghaffari   }
49877841947SLeila Ghaffari 
49977841947SLeila Ghaffari   // -- CEED operator for IFunction
50077841947SLeila Ghaffari   if (ceed_data->qf_ifunction_vol) {
50177841947SLeila Ghaffari     CeedOperator op;
50277841947SLeila Ghaffari     CeedOperatorCreate(ceed, ceed_data->qf_ifunction_vol, NULL, NULL, &op);
50377841947SLeila Ghaffari     CeedOperatorSetField(op, "q", ceed_data->elem_restr_q, ceed_data->basis_q,
50477841947SLeila Ghaffari                          CEED_VECTOR_ACTIVE);
505a3ae0734SJed Brown     CeedOperatorSetField(op, "Grad_q", ceed_data->elem_restr_q, ceed_data->basis_q,
50677841947SLeila Ghaffari                          CEED_VECTOR_ACTIVE);
507a61c78d6SJeremy L Thompson     CeedOperatorSetField(op, "q dot", ceed_data->elem_restr_q, ceed_data->basis_q,
50877841947SLeila Ghaffari                          user->q_dot_ceed);
509a61c78d6SJeremy L Thompson     CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i,
510e6225c47SLeila Ghaffari                          CEED_BASIS_COLLOCATED, ceed_data->q_data);
51177841947SLeila Ghaffari     CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x,
51277841947SLeila Ghaffari                          ceed_data->x_coord);
51377841947SLeila Ghaffari     CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q,
51477841947SLeila Ghaffari                          CEED_VECTOR_ACTIVE);
515a3ae0734SJed Brown     CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q,
51677841947SLeila Ghaffari                          CEED_VECTOR_ACTIVE);
517a3ae0734SJed Brown     CeedOperatorSetField(op, "jac_data", elem_restr_jd_i,
518a3ae0734SJed Brown                          CEED_BASIS_COLLOCATED, jac_data);
519a3ae0734SJed Brown 
52077841947SLeila Ghaffari     user->op_ifunction_vol = op;
52177841947SLeila Ghaffari   }
52277841947SLeila Ghaffari 
523e334ad8fSJed Brown   CeedOperator op_ijacobian_vol = NULL;
524e334ad8fSJed Brown   if (qf_ijacobian_vol) {
525e334ad8fSJed Brown     CeedOperator op;
526e334ad8fSJed Brown     CeedOperatorCreate(ceed, qf_ijacobian_vol, NULL, NULL, &op);
527e334ad8fSJed Brown     CeedOperatorSetField(op, "dq", ceed_data->elem_restr_q, ceed_data->basis_q,
528e334ad8fSJed Brown                          CEED_VECTOR_ACTIVE);
529e334ad8fSJed Brown     CeedOperatorSetField(op, "Grad_dq", ceed_data->elem_restr_q, ceed_data->basis_q,
530e334ad8fSJed Brown                          CEED_VECTOR_ACTIVE);
531e334ad8fSJed Brown     CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i,
532e334ad8fSJed Brown                          CEED_BASIS_COLLOCATED, ceed_data->q_data);
533e334ad8fSJed Brown     CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x,
534e334ad8fSJed Brown                          ceed_data->x_coord);
535e334ad8fSJed Brown     CeedOperatorSetField(op, "jac_data", elem_restr_jd_i,
536e334ad8fSJed Brown                          CEED_BASIS_COLLOCATED, jac_data);
537e334ad8fSJed Brown     CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q,
538e334ad8fSJed Brown                          CEED_VECTOR_ACTIVE);
539e334ad8fSJed Brown     CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q,
540e334ad8fSJed Brown                          CEED_VECTOR_ACTIVE);
541e334ad8fSJed Brown     op_ijacobian_vol = op;
542e334ad8fSJed Brown     CeedQFunctionDestroy(&qf_ijacobian_vol);
543e334ad8fSJed Brown   }
544e334ad8fSJed Brown 
54577841947SLeila Ghaffari   // *****************************************************************************
54677841947SLeila Ghaffari   // Set up CEED objects for the exterior domain (surface)
54777841947SLeila Ghaffari   // *****************************************************************************
54877841947SLeila Ghaffari   CeedInt height  = 1,
54977841947SLeila Ghaffari           dim_sur = dim - height,
55077841947SLeila Ghaffari           P_sur   = app_ctx->degree + 1,
55177841947SLeila Ghaffari           Q_sur   = P_sur + app_ctx->q_extra;
552e334ad8fSJed Brown   const CeedInt q_data_size_sur = problem->q_data_size_sur,
553e334ad8fSJed Brown                 jac_data_size_sur = problem->jac_data_size_sur;
55477841947SLeila Ghaffari 
55577841947SLeila Ghaffari   // -----------------------------------------------------------------------------
55677841947SLeila Ghaffari   // CEED Bases
55777841947SLeila Ghaffari   // -----------------------------------------------------------------------------
55877841947SLeila Ghaffari   CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_q, P_sur, Q_sur,
55977841947SLeila Ghaffari                                   CEED_GAUSS, &ceed_data->basis_q_sur);
56077841947SLeila Ghaffari   CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_x, 2, Q_sur, CEED_GAUSS,
56177841947SLeila Ghaffari                                   &ceed_data->basis_x_sur);
562959b8288SJames Wright   CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_x, 2, P_sur,
563959b8288SJames Wright                                   CEED_GAUSS_LOBATTO, &ceed_data->basis_xc_sur);
56477841947SLeila Ghaffari 
56577841947SLeila Ghaffari   // -----------------------------------------------------------------------------
56677841947SLeila Ghaffari   // CEED QFunctions
56777841947SLeila Ghaffari   // -----------------------------------------------------------------------------
56877841947SLeila Ghaffari   // -- Create QFunction for quadrature data
56991e5af17SJed Brown   CeedQFunctionCreateInterior(ceed, 1, problem->setup_sur.qfunction,
57091e5af17SJed Brown                               problem->setup_sur.qfunction_loc,
57177841947SLeila Ghaffari                               &ceed_data->qf_setup_sur);
572841e4c73SJed Brown   if (problem->setup_sur.qfunction_context) {
573841e4c73SJed Brown     CeedQFunctionSetContext(ceed_data->qf_setup_sur,
574841e4c73SJed Brown                             problem->setup_sur.qfunction_context);
575841e4c73SJed Brown     CeedQFunctionContextDestroy(&problem->setup_sur.qfunction_context);
576841e4c73SJed Brown   }
57777841947SLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_setup_sur, "dx", num_comp_x*dim_sur,
57877841947SLeila Ghaffari                         CEED_EVAL_GRAD);
57977841947SLeila Ghaffari   CeedQFunctionAddInput(ceed_data->qf_setup_sur, "weight", 1, CEED_EVAL_WEIGHT);
580a61c78d6SJeremy L Thompson   CeedQFunctionAddOutput(ceed_data->qf_setup_sur, "surface qdata",
5812fe7aee7SLeila Ghaffari                          q_data_size_sur, CEED_EVAL_NONE);
58277841947SLeila Ghaffari 
5835b881d11SJames Wright   PetscCall(SetupBCQFunctions(ceed, dim_sur, num_comp_x, num_comp_q,
5845b881d11SJames Wright                               q_data_size_sur, jac_data_size_sur,
5855b881d11SJames Wright                               problem->apply_inflow, problem->apply_inflow_jacobian,
5865b881d11SJames Wright                               &ceed_data->qf_apply_inflow, &ceed_data->qf_apply_inflow_jacobian));
5872fe7aee7SLeila Ghaffari 
5885b881d11SJames Wright   PetscCall(SetupBCQFunctions(ceed, dim_sur, num_comp_x, num_comp_q,
5895b881d11SJames Wright                               q_data_size_sur, jac_data_size_sur,
5905b881d11SJames Wright                               problem->apply_outflow, problem->apply_outflow_jacobian,
5915b881d11SJames Wright                               &ceed_data->qf_apply_outflow, &ceed_data->qf_apply_outflow_jacobian));
59277841947SLeila Ghaffari 
593*f4ca79c2SJames Wright   PetscCall(SetupBCQFunctions(ceed, dim_sur, num_comp_x, num_comp_q,
594*f4ca79c2SJames Wright                               q_data_size_sur, jac_data_size_sur,
595*f4ca79c2SJames Wright                               problem->apply_freestream, problem->apply_freestream_jacobian,
596*f4ca79c2SJames Wright                               &ceed_data->qf_apply_freestream, &ceed_data->qf_apply_freestream_jacobian));
597*f4ca79c2SJames Wright 
59877841947SLeila Ghaffari   // *****************************************************************************
59977841947SLeila Ghaffari   // CEED Operator Apply
60077841947SLeila Ghaffari   // *****************************************************************************
60177841947SLeila Ghaffari   // -- Apply CEED Operator for the geometric data
60277841947SLeila Ghaffari   CeedOperatorApply(ceed_data->op_setup_vol, ceed_data->x_coord,
60377841947SLeila Ghaffari                     ceed_data->q_data, CEED_REQUEST_IMMEDIATE);
60477841947SLeila Ghaffari 
60577841947SLeila Ghaffari   // -- Create and apply CEED Composite Operator for the entire domain
60677841947SLeila Ghaffari   if (!user->phys->implicit) { // RHS
60777841947SLeila Ghaffari     ierr = CreateOperatorForDomain(ceed, dm, bc, ceed_data, user->phys,
608e334ad8fSJed Brown                                    user->op_rhs_vol, NULL, height, P_sur, Q_sur,
609e334ad8fSJed Brown                                    q_data_size_sur, 0,
610e334ad8fSJed Brown                                    &user->op_rhs, NULL); CHKERRQ(ierr);
61177841947SLeila Ghaffari   } else { // IFunction
61277841947SLeila Ghaffari     ierr = CreateOperatorForDomain(ceed, dm, bc, ceed_data, user->phys,
613e334ad8fSJed Brown                                    user->op_ifunction_vol, op_ijacobian_vol,
614e334ad8fSJed Brown                                    height, P_sur, Q_sur,
615e334ad8fSJed Brown                                    q_data_size_sur, jac_data_size_sur,
616e334ad8fSJed Brown                                    &user->op_ifunction,
617e334ad8fSJed Brown                                    op_ijacobian_vol ? &user->op_ijacobian : NULL); CHKERRQ(ierr);
618e334ad8fSJed Brown     if (user->op_ijacobian) {
619e334ad8fSJed Brown       CeedOperatorContextGetFieldLabel(user->op_ijacobian, "ijacobian time shift",
620e334ad8fSJed Brown                                        &user->phys->ijacobian_time_shift_label);
621e334ad8fSJed Brown     }
622dada6cc0SJames Wright     if (problem->use_dirichlet_ceed) {
623dada6cc0SJames Wright       PetscCall(SetupStrongBC_Ceed(ceed, ceed_data, dm, user, app_ctx, problem, bc,
624dada6cc0SJames Wright                                    Q_sur, q_data_size_sur));
625dada6cc0SJames Wright     }
626e334ad8fSJed Brown 
62777841947SLeila Ghaffari   }
628a3ae0734SJed Brown   CeedElemRestrictionDestroy(&elem_restr_jd_i);
62922d320f5SLeila Ghaffari   CeedOperatorDestroy(&op_ijacobian_vol);
630a3ae0734SJed Brown   CeedVectorDestroy(&jac_data);
63177841947SLeila Ghaffari   PetscFunctionReturn(0);
63277841947SLeila Ghaffari }
633