1a515125bSLeila Ghaffari // Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at 2a515125bSLeila Ghaffari // the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights 3a515125bSLeila Ghaffari // reserved. See files LICENSE and NOTICE for details. 4a515125bSLeila Ghaffari // 5a515125bSLeila Ghaffari // This file is part of CEED, a collection of benchmarks, miniapps, software 6a515125bSLeila Ghaffari // libraries and APIs for efficient high-order finite element and spectral 7a515125bSLeila Ghaffari // element discretizations for exascale applications. For more information and 8a515125bSLeila Ghaffari // source code availability see http://github.com/ceed. 9a515125bSLeila Ghaffari // 10a515125bSLeila Ghaffari // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC, 11a515125bSLeila Ghaffari // a collaborative effort of two U.S. Department of Energy organizations (Office 12a515125bSLeila Ghaffari // of Science and the National Nuclear Security Administration) responsible for 13a515125bSLeila Ghaffari // the planning and preparation of a capable exascale ecosystem, including 14a515125bSLeila Ghaffari // software, applications, hardware, advanced system engineering and early 15a515125bSLeila Ghaffari // testbed platforms, in support of the nation's exascale computing imperative. 16a515125bSLeila Ghaffari 17a515125bSLeila Ghaffari /// @file 18a515125bSLeila Ghaffari /// Setup libCEED for Navier-Stokes example using PETSc 19a515125bSLeila Ghaffari 20a515125bSLeila Ghaffari #include "../navierstokes.h" 21a515125bSLeila Ghaffari 22a515125bSLeila Ghaffari // Utility function - essential BC dofs are encoded in closure indices as -(i+1). 23a515125bSLeila Ghaffari PetscInt Involute(PetscInt i) { 24a515125bSLeila Ghaffari return i >= 0 ? i : -(i+1); 25a515125bSLeila Ghaffari } 26a515125bSLeila Ghaffari 27a515125bSLeila Ghaffari // Utility function to create local CEED restriction 286b1ccf21SJeremy L Thompson PetscErrorCode CreateRestrictionFromPlex(Ceed ceed, DM dm, CeedInt height, 296b1ccf21SJeremy L Thompson DMLabel domain_label, CeedInt value, CeedElemRestriction *elem_restr) { 306b1ccf21SJeremy L Thompson PetscInt num_elem, elem_size, num_dof, num_comp, *elem_restr_offsets; 31a515125bSLeila Ghaffari PetscErrorCode ierr; 326b1ccf21SJeremy L Thompson 33a515125bSLeila Ghaffari PetscFunctionBeginUser; 346b1ccf21SJeremy L Thompson ierr = DMPlexGetLocalOffsets(dm, domain_label, value, height, 0, &num_elem, 356b1ccf21SJeremy L Thompson &elem_size, &num_comp, &num_dof, &elem_restr_offsets); 366b1ccf21SJeremy L Thompson CHKERRQ(ierr); 37a515125bSLeila Ghaffari 386b1ccf21SJeremy L Thompson CeedElemRestrictionCreate(ceed, num_elem, elem_size, num_comp, 396b1ccf21SJeremy L Thompson 1, num_dof, CEED_MEM_HOST, CEED_COPY_VALUES, 406b1ccf21SJeremy L Thompson elem_restr_offsets, elem_restr); 416b1ccf21SJeremy L Thompson ierr = PetscFree(elem_restr_offsets); CHKERRQ(ierr); 42a515125bSLeila Ghaffari 43a515125bSLeila Ghaffari PetscFunctionReturn(0); 44a515125bSLeila Ghaffari } 45a515125bSLeila Ghaffari 46a515125bSLeila Ghaffari // Utility function to get Ceed Restriction for each domain 47a515125bSLeila Ghaffari PetscErrorCode GetRestrictionForDomain(Ceed ceed, DM dm, CeedInt height, 48a515125bSLeila Ghaffari DMLabel domain_label, PetscInt value, 496b1ccf21SJeremy L Thompson CeedInt Q, CeedInt q_data_size, 50a515125bSLeila Ghaffari CeedElemRestriction *elem_restr_q, 51a515125bSLeila Ghaffari CeedElemRestriction *elem_restr_x, 52a515125bSLeila Ghaffari CeedElemRestriction *elem_restr_qd_i) { 53a515125bSLeila Ghaffari DM dm_coord; 54a515125bSLeila Ghaffari CeedInt dim, loc_num_elem; 55a515125bSLeila Ghaffari CeedInt Q_dim; 56a515125bSLeila Ghaffari PetscErrorCode ierr; 57a515125bSLeila Ghaffari PetscFunctionBeginUser; 58a515125bSLeila Ghaffari 59a515125bSLeila Ghaffari ierr = DMGetDimension(dm, &dim); CHKERRQ(ierr); 60a515125bSLeila Ghaffari dim -= height; 61a515125bSLeila Ghaffari Q_dim = CeedIntPow(Q, dim); 62a515125bSLeila Ghaffari ierr = DMGetCoordinateDM(dm, &dm_coord); CHKERRQ(ierr); 63a515125bSLeila Ghaffari ierr = DMPlexSetClosurePermutationTensor(dm_coord, PETSC_DETERMINE, NULL); 64a515125bSLeila Ghaffari CHKERRQ(ierr); 656b1ccf21SJeremy L Thompson ierr = CreateRestrictionFromPlex(ceed, dm, height, domain_label, value, 666b1ccf21SJeremy L Thompson elem_restr_q); 676b1ccf21SJeremy L Thompson CHKERRQ(ierr); 686b1ccf21SJeremy L Thompson ierr = CreateRestrictionFromPlex(ceed, dm_coord, height, domain_label, value, 696b1ccf21SJeremy L Thompson elem_restr_x); 706b1ccf21SJeremy L Thompson CHKERRQ(ierr); 71a515125bSLeila Ghaffari CeedElemRestrictionGetNumElements(*elem_restr_q, &loc_num_elem); 72a515125bSLeila Ghaffari CeedElemRestrictionCreateStrided(ceed, loc_num_elem, Q_dim, 73a515125bSLeila Ghaffari q_data_size, q_data_size*loc_num_elem*Q_dim, 74a515125bSLeila Ghaffari CEED_STRIDES_BACKEND, elem_restr_qd_i); 75a515125bSLeila Ghaffari PetscFunctionReturn(0); 76a515125bSLeila Ghaffari } 77a515125bSLeila Ghaffari 78a515125bSLeila Ghaffari // Utility function to create CEED Composite Operator for the entire domain 79a515125bSLeila Ghaffari PetscErrorCode CreateOperatorForDomain(Ceed ceed, DM dm, SimpleBC bc, 80a515125bSLeila Ghaffari CeedData ceed_data, Physics phys, 81a515125bSLeila Ghaffari CeedOperator op_apply_vol, CeedInt height, 82a515125bSLeila Ghaffari CeedInt P_sur, CeedInt Q_sur, CeedInt q_data_size_sur, 83a515125bSLeila Ghaffari CeedOperator *op_apply) { 84a515125bSLeila Ghaffari CeedInt dim, num_face; 85a515125bSLeila Ghaffari DMLabel domain_label; 86a515125bSLeila Ghaffari PetscErrorCode ierr; 87a515125bSLeila Ghaffari PetscFunctionBeginUser; 88a515125bSLeila Ghaffari 89a515125bSLeila Ghaffari // Create Composite Operaters 90a515125bSLeila Ghaffari CeedCompositeOperatorCreate(ceed, op_apply); 91a515125bSLeila Ghaffari 92a515125bSLeila Ghaffari // --Apply Sub-Operator for the volume 93a515125bSLeila Ghaffari CeedCompositeOperatorAddSub(*op_apply, op_apply_vol); 94a515125bSLeila Ghaffari 95a515125bSLeila Ghaffari // -- Create Sub-Operator for in/outflow BCs 96139613f2SLeila Ghaffari if (phys->has_neumann) { 97a515125bSLeila Ghaffari // --- Setup 98a515125bSLeila Ghaffari ierr = DMGetLabel(dm, "Face Sets", &domain_label); CHKERRQ(ierr); 99a515125bSLeila Ghaffari ierr = DMGetDimension(dm, &dim); CHKERRQ(ierr); 100a515125bSLeila Ghaffari if (dim == 2) num_face = 4; 101a515125bSLeila Ghaffari if (dim == 3) num_face = 6; 102a515125bSLeila Ghaffari 103a515125bSLeila Ghaffari // --- Get number of quadrature points for the boundaries 104a515125bSLeila Ghaffari CeedInt num_qpts_sur; 105a515125bSLeila Ghaffari CeedBasisGetNumQuadraturePoints(ceed_data->basis_q_sur, &num_qpts_sur); 106a515125bSLeila Ghaffari 107a515125bSLeila Ghaffari // --- Create Sub-Operator for each face 108a515125bSLeila Ghaffari for (CeedInt i=0; i<num_face; i++) { 109a515125bSLeila Ghaffari CeedVector q_data_sur; 110a515125bSLeila Ghaffari CeedOperator op_setup_sur, op_apply_sur; 111a515125bSLeila Ghaffari CeedElemRestriction elem_restr_x_sur, elem_restr_q_sur, 112a515125bSLeila Ghaffari elem_restr_qd_i_sur; 113a515125bSLeila Ghaffari 114a515125bSLeila Ghaffari // ---- CEED Restriction 1156b1ccf21SJeremy L Thompson ierr = GetRestrictionForDomain(ceed, dm, height, domain_label, i+1, 116a515125bSLeila Ghaffari Q_sur, q_data_size_sur, &elem_restr_q_sur, 117a515125bSLeila Ghaffari &elem_restr_x_sur, &elem_restr_qd_i_sur); 118a515125bSLeila Ghaffari CHKERRQ(ierr); 119a515125bSLeila Ghaffari 120a515125bSLeila Ghaffari // ---- CEED Vector 121a515125bSLeila Ghaffari PetscInt loc_num_elem_sur; 122a515125bSLeila Ghaffari CeedElemRestrictionGetNumElements(elem_restr_q_sur, &loc_num_elem_sur); 123a515125bSLeila Ghaffari CeedVectorCreate(ceed, q_data_size_sur*loc_num_elem_sur*num_qpts_sur, 124a515125bSLeila Ghaffari &q_data_sur); 125a515125bSLeila Ghaffari 126a515125bSLeila Ghaffari // ---- CEED Operator 127a515125bSLeila Ghaffari // ----- CEED Operator for Setup (geometric factors) 128a515125bSLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_setup_sur, NULL, NULL, &op_setup_sur); 129a515125bSLeila Ghaffari CeedOperatorSetField(op_setup_sur, "dx", elem_restr_x_sur, 130139613f2SLeila Ghaffari ceed_data->basis_x_sur, CEED_VECTOR_ACTIVE); 131a515125bSLeila Ghaffari CeedOperatorSetField(op_setup_sur, "weight", CEED_ELEMRESTRICTION_NONE, 132a515125bSLeila Ghaffari ceed_data->basis_x_sur, CEED_VECTOR_NONE); 133*3b1e209bSJeremy L Thompson CeedOperatorSetField(op_setup_sur, "surface qdata", elem_restr_qd_i_sur, 134a515125bSLeila Ghaffari CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); 135a515125bSLeila Ghaffari 136a515125bSLeila Ghaffari // ----- CEED Operator for Physics 137a515125bSLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_apply_sur, NULL, NULL, &op_apply_sur); 138a515125bSLeila Ghaffari CeedOperatorSetField(op_apply_sur, "q", elem_restr_q_sur, 139a515125bSLeila Ghaffari ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 140*3b1e209bSJeremy L Thompson CeedOperatorSetField(op_apply_sur, "surface qdata", elem_restr_qd_i_sur, 141a515125bSLeila Ghaffari CEED_BASIS_COLLOCATED, q_data_sur); 142a515125bSLeila Ghaffari CeedOperatorSetField(op_apply_sur, "x", elem_restr_x_sur, 143a515125bSLeila Ghaffari ceed_data->basis_x_sur, ceed_data->x_coord); 144a515125bSLeila Ghaffari CeedOperatorSetField(op_apply_sur, "v", elem_restr_q_sur, 145a515125bSLeila Ghaffari ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 146a515125bSLeila Ghaffari 147a515125bSLeila Ghaffari // ----- Apply CEED operator for Setup 148a515125bSLeila Ghaffari CeedOperatorApply(op_setup_sur, ceed_data->x_coord, q_data_sur, 149a515125bSLeila Ghaffari CEED_REQUEST_IMMEDIATE); 150a515125bSLeila Ghaffari 151a515125bSLeila Ghaffari // ----- Apply Sub-Operator for the Boundary 152a515125bSLeila Ghaffari CeedCompositeOperatorAddSub(*op_apply, op_apply_sur); 153a515125bSLeila Ghaffari 154a515125bSLeila Ghaffari // ----- Cleanup 155a515125bSLeila Ghaffari CeedVectorDestroy(&q_data_sur); 156a515125bSLeila Ghaffari CeedElemRestrictionDestroy(&elem_restr_q_sur); 157a515125bSLeila Ghaffari CeedElemRestrictionDestroy(&elem_restr_x_sur); 158a515125bSLeila Ghaffari CeedElemRestrictionDestroy(&elem_restr_qd_i_sur); 159a515125bSLeila Ghaffari CeedOperatorDestroy(&op_setup_sur); 160a515125bSLeila Ghaffari CeedOperatorDestroy(&op_apply_sur); 161a515125bSLeila Ghaffari } 162a515125bSLeila Ghaffari } 163a515125bSLeila Ghaffari 164a515125bSLeila Ghaffari PetscFunctionReturn(0); 165a515125bSLeila Ghaffari } 166a515125bSLeila Ghaffari 167a515125bSLeila Ghaffari PetscErrorCode SetupLibceed(Ceed ceed, CeedData ceed_data, DM dm, User user, 168a515125bSLeila Ghaffari AppCtx app_ctx, ProblemData *problem, SimpleBC bc) { 169a515125bSLeila Ghaffari PetscErrorCode ierr; 170a515125bSLeila Ghaffari PetscFunctionBeginUser; 171a515125bSLeila Ghaffari 172a515125bSLeila Ghaffari // ***************************************************************************** 173a515125bSLeila Ghaffari // Set up CEED objects for the interior domain (volume) 174a515125bSLeila Ghaffari // ***************************************************************************** 175a515125bSLeila Ghaffari const PetscInt num_comp_q = 5; 176a515125bSLeila Ghaffari const CeedInt dim = problem->dim, 177a515125bSLeila Ghaffari num_comp_x = problem->dim, 178a515125bSLeila Ghaffari q_data_size_vol = problem->q_data_size_vol, 179a515125bSLeila Ghaffari P = app_ctx->degree + 1, 180a515125bSLeila Ghaffari Q = P + app_ctx->q_extra; 181a515125bSLeila Ghaffari 182a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 183a515125bSLeila Ghaffari // CEED Bases 184a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 185a515125bSLeila Ghaffari CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_q, P, Q, CEED_GAUSS, 186a515125bSLeila Ghaffari &ceed_data->basis_q); 187a515125bSLeila Ghaffari CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_x, 2, Q, CEED_GAUSS, 188a515125bSLeila Ghaffari &ceed_data->basis_x); 189a515125bSLeila Ghaffari CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_x, 2, P, 190a515125bSLeila Ghaffari CEED_GAUSS_LOBATTO, &ceed_data->basis_xc); 191a515125bSLeila Ghaffari 192a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 193a515125bSLeila Ghaffari // CEED Restrictions 194a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 195a515125bSLeila Ghaffari // -- Create restriction 1966b1ccf21SJeremy L Thompson ierr = GetRestrictionForDomain(ceed, dm, 0, 0, 0, Q, q_data_size_vol, 1976b1ccf21SJeremy L Thompson &ceed_data->elem_restr_q, &ceed_data->elem_restr_x, 198a515125bSLeila Ghaffari &ceed_data->elem_restr_qd_i); CHKERRQ(ierr); 199a515125bSLeila Ghaffari // -- Create E vectors 200a515125bSLeila Ghaffari CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->q_ceed, NULL); 201a515125bSLeila Ghaffari CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->q_dot_ceed, 202a515125bSLeila Ghaffari NULL); 203a515125bSLeila Ghaffari CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->g_ceed, NULL); 204a515125bSLeila Ghaffari 205a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 206a515125bSLeila Ghaffari // CEED QFunctions 207a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 208a515125bSLeila Ghaffari // -- Create QFunction for quadrature data 209a515125bSLeila Ghaffari CeedQFunctionCreateInterior(ceed, 1, problem->setup_vol, problem->setup_vol_loc, 210a515125bSLeila Ghaffari &ceed_data->qf_setup_vol); 211a515125bSLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_setup_vol, "dx", num_comp_x*dim, 212a515125bSLeila Ghaffari CEED_EVAL_GRAD); 213a515125bSLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_setup_vol, "weight", 1, CEED_EVAL_WEIGHT); 214*3b1e209bSJeremy L Thompson CeedQFunctionAddOutput(ceed_data->qf_setup_vol, "qdata", q_data_size_vol, 215a515125bSLeila Ghaffari CEED_EVAL_NONE); 216a515125bSLeila Ghaffari 217a515125bSLeila Ghaffari // -- Create QFunction for ICs 218a515125bSLeila Ghaffari CeedQFunctionCreateInterior(ceed, 1, problem->ics, problem->ics_loc, 219a515125bSLeila Ghaffari &ceed_data->qf_ics); 220a515125bSLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_ics, "x", num_comp_x, CEED_EVAL_INTERP); 221a515125bSLeila Ghaffari CeedQFunctionAddOutput(ceed_data->qf_ics, "q0", num_comp_q, CEED_EVAL_NONE); 222a515125bSLeila Ghaffari 223a515125bSLeila Ghaffari // -- Create QFunction for RHS 224a515125bSLeila Ghaffari if (problem->apply_vol_rhs) { 225a515125bSLeila Ghaffari CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_rhs, 226a515125bSLeila Ghaffari problem->apply_vol_rhs_loc, &ceed_data->qf_rhs_vol); 227a515125bSLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "q", num_comp_q, CEED_EVAL_INTERP); 228a515125bSLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "dq", num_comp_q*dim, 229a515125bSLeila Ghaffari CEED_EVAL_GRAD); 230*3b1e209bSJeremy L Thompson CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "qdata", q_data_size_vol, 231a515125bSLeila Ghaffari CEED_EVAL_NONE); 232a515125bSLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "x", num_comp_x, CEED_EVAL_INTERP); 233a515125bSLeila Ghaffari CeedQFunctionAddOutput(ceed_data->qf_rhs_vol, "v", num_comp_q, 234a515125bSLeila Ghaffari CEED_EVAL_INTERP); 235a515125bSLeila Ghaffari CeedQFunctionAddOutput(ceed_data->qf_rhs_vol, "dv", num_comp_q*dim, 236a515125bSLeila Ghaffari CEED_EVAL_GRAD); 237a515125bSLeila Ghaffari } 238a515125bSLeila Ghaffari 239a515125bSLeila Ghaffari // -- Create QFunction for IFunction 240a515125bSLeila Ghaffari if (problem->apply_vol_ifunction) { 241a515125bSLeila Ghaffari CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_ifunction, 242a515125bSLeila Ghaffari problem->apply_vol_ifunction_loc, &ceed_data->qf_ifunction_vol); 243a515125bSLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "q", num_comp_q, 244a515125bSLeila Ghaffari CEED_EVAL_INTERP); 245a515125bSLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "dq", num_comp_q*dim, 246a515125bSLeila Ghaffari CEED_EVAL_GRAD); 247*3b1e209bSJeremy L Thompson CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "q dot", num_comp_q, 248a515125bSLeila Ghaffari CEED_EVAL_INTERP); 249*3b1e209bSJeremy L Thompson CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "qdata", q_data_size_vol, 250a515125bSLeila Ghaffari CEED_EVAL_NONE); 251a515125bSLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "x", num_comp_x, 252a515125bSLeila Ghaffari CEED_EVAL_INTERP); 253a515125bSLeila Ghaffari CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "v", num_comp_q, 254a515125bSLeila Ghaffari CEED_EVAL_INTERP); 255a515125bSLeila Ghaffari CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "dv", num_comp_q*dim, 256a515125bSLeila Ghaffari CEED_EVAL_GRAD); 257a515125bSLeila Ghaffari } 258a515125bSLeila Ghaffari 259a515125bSLeila Ghaffari // --------------------------------------------------------------------------- 260a515125bSLeila Ghaffari // Element coordinates 261a515125bSLeila Ghaffari // --------------------------------------------------------------------------- 262a515125bSLeila Ghaffari // -- Create CEED vector 263a515125bSLeila Ghaffari CeedElemRestrictionCreateVector(ceed_data->elem_restr_x, &ceed_data->x_coord, 264a515125bSLeila Ghaffari NULL); 265a515125bSLeila Ghaffari 266a515125bSLeila Ghaffari // -- Copy PETSc vector in CEED vector 267a515125bSLeila Ghaffari Vec X_loc; 268a515125bSLeila Ghaffari const PetscScalar *X_loc_array; 269a515125bSLeila Ghaffari ierr = DMGetCoordinatesLocal(dm, &X_loc); CHKERRQ(ierr); 270a515125bSLeila Ghaffari ierr = VecGetArrayRead(X_loc, &X_loc_array); CHKERRQ(ierr); 271a515125bSLeila Ghaffari CeedVectorSetArray(ceed_data->x_coord, CEED_MEM_HOST, CEED_COPY_VALUES, 272a515125bSLeila Ghaffari (PetscScalar *)X_loc_array); 273a515125bSLeila Ghaffari ierr = VecRestoreArrayRead(X_loc, &X_loc_array); CHKERRQ(ierr); 274a515125bSLeila Ghaffari 275a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 276a515125bSLeila Ghaffari // CEED vectors 277a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 278a515125bSLeila Ghaffari // -- Create CEED vector for geometric data 279a515125bSLeila Ghaffari CeedInt num_qpts_vol; 280a515125bSLeila Ghaffari PetscInt loc_num_elem_vol; 281a515125bSLeila Ghaffari CeedBasisGetNumQuadraturePoints(ceed_data->basis_q, &num_qpts_vol); 282a515125bSLeila Ghaffari CeedElemRestrictionGetNumElements(ceed_data->elem_restr_q, &loc_num_elem_vol); 283a515125bSLeila Ghaffari CeedVectorCreate(ceed, q_data_size_vol*loc_num_elem_vol*num_qpts_vol, 284a515125bSLeila Ghaffari &ceed_data->q_data); 285a515125bSLeila Ghaffari 286a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 287a515125bSLeila Ghaffari // CEED Operators 288a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 289a515125bSLeila Ghaffari // -- Create CEED operator for quadrature data 290a515125bSLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_setup_vol, NULL, NULL, 291a515125bSLeila Ghaffari &ceed_data->op_setup_vol); 292a515125bSLeila Ghaffari CeedOperatorSetField(ceed_data->op_setup_vol, "dx", ceed_data->elem_restr_x, 293a515125bSLeila Ghaffari ceed_data->basis_x, CEED_VECTOR_ACTIVE); 294a515125bSLeila Ghaffari CeedOperatorSetField(ceed_data->op_setup_vol, "weight", 295139613f2SLeila Ghaffari CEED_ELEMRESTRICTION_NONE, ceed_data->basis_x, CEED_VECTOR_NONE); 296*3b1e209bSJeremy L Thompson CeedOperatorSetField(ceed_data->op_setup_vol, "qdata", 297139613f2SLeila Ghaffari ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); 298a515125bSLeila Ghaffari 299a515125bSLeila Ghaffari // -- Create CEED operator for ICs 300a515125bSLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_ics, NULL, NULL, &ceed_data->op_ics); 301a515125bSLeila Ghaffari CeedOperatorSetField(ceed_data->op_ics, "x", ceed_data->elem_restr_x, 302a515125bSLeila Ghaffari ceed_data->basis_xc, CEED_VECTOR_ACTIVE); 303a515125bSLeila Ghaffari CeedOperatorSetField(ceed_data->op_ics, "q0", ceed_data->elem_restr_q, 304a515125bSLeila Ghaffari CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); 305a515125bSLeila Ghaffari 306a515125bSLeila Ghaffari // Create CEED operator for RHS 307a515125bSLeila Ghaffari if (ceed_data->qf_rhs_vol) { 308a515125bSLeila Ghaffari CeedOperator op; 309a515125bSLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_rhs_vol, NULL, NULL, &op); 310a515125bSLeila Ghaffari CeedOperatorSetField(op, "q", ceed_data->elem_restr_q, ceed_data->basis_q, 311a515125bSLeila Ghaffari CEED_VECTOR_ACTIVE); 312a515125bSLeila Ghaffari CeedOperatorSetField(op, "dq", ceed_data->elem_restr_q, ceed_data->basis_q, 313a515125bSLeila Ghaffari CEED_VECTOR_ACTIVE); 314*3b1e209bSJeremy L Thompson CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i, 315139613f2SLeila Ghaffari CEED_BASIS_COLLOCATED, ceed_data->q_data); 316a515125bSLeila Ghaffari CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x, 317a515125bSLeila Ghaffari ceed_data->x_coord); 318a515125bSLeila Ghaffari CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q, 319a515125bSLeila Ghaffari CEED_VECTOR_ACTIVE); 320a515125bSLeila Ghaffari CeedOperatorSetField(op, "dv", ceed_data->elem_restr_q, ceed_data->basis_q, 321a515125bSLeila Ghaffari CEED_VECTOR_ACTIVE); 322a515125bSLeila Ghaffari user->op_rhs_vol = op; 323a515125bSLeila Ghaffari } 324a515125bSLeila Ghaffari 325a515125bSLeila Ghaffari // -- CEED operator for IFunction 326a515125bSLeila Ghaffari if (ceed_data->qf_ifunction_vol) { 327a515125bSLeila Ghaffari CeedOperator op; 328a515125bSLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_ifunction_vol, NULL, NULL, &op); 329a515125bSLeila Ghaffari CeedOperatorSetField(op, "q", ceed_data->elem_restr_q, ceed_data->basis_q, 330a515125bSLeila Ghaffari CEED_VECTOR_ACTIVE); 331a515125bSLeila Ghaffari CeedOperatorSetField(op, "dq", ceed_data->elem_restr_q, ceed_data->basis_q, 332a515125bSLeila Ghaffari CEED_VECTOR_ACTIVE); 333*3b1e209bSJeremy L Thompson CeedOperatorSetField(op, "q dot", ceed_data->elem_restr_q, ceed_data->basis_q, 334a515125bSLeila Ghaffari user->q_dot_ceed); 335*3b1e209bSJeremy L Thompson CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i, 336139613f2SLeila Ghaffari CEED_BASIS_COLLOCATED, ceed_data->q_data); 337a515125bSLeila Ghaffari CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x, 338a515125bSLeila Ghaffari ceed_data->x_coord); 339a515125bSLeila Ghaffari CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q, 340a515125bSLeila Ghaffari CEED_VECTOR_ACTIVE); 341a515125bSLeila Ghaffari CeedOperatorSetField(op, "dv", ceed_data->elem_restr_q, ceed_data->basis_q, 342a515125bSLeila Ghaffari CEED_VECTOR_ACTIVE); 343a515125bSLeila Ghaffari user->op_ifunction_vol = op; 344a515125bSLeila Ghaffari } 345a515125bSLeila Ghaffari 346a515125bSLeila Ghaffari // ***************************************************************************** 347a515125bSLeila Ghaffari // Set up CEED objects for the exterior domain (surface) 348a515125bSLeila Ghaffari // ***************************************************************************** 349a515125bSLeila Ghaffari CeedInt height = 1, 350a515125bSLeila Ghaffari dim_sur = dim - height, 351a515125bSLeila Ghaffari P_sur = app_ctx->degree + 1, 352a515125bSLeila Ghaffari Q_sur = P_sur + app_ctx->q_extra; 353a515125bSLeila Ghaffari const CeedInt q_data_size_sur = problem->q_data_size_sur; 354a515125bSLeila Ghaffari 355a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 356a515125bSLeila Ghaffari // CEED Bases 357a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 358a515125bSLeila Ghaffari CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_q, P_sur, Q_sur, 359a515125bSLeila Ghaffari CEED_GAUSS, &ceed_data->basis_q_sur); 360a515125bSLeila Ghaffari CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_x, 2, Q_sur, CEED_GAUSS, 361a515125bSLeila Ghaffari &ceed_data->basis_x_sur); 362a515125bSLeila Ghaffari 363a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 364a515125bSLeila Ghaffari // CEED QFunctions 365a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 366a515125bSLeila Ghaffari // -- Create QFunction for quadrature data 367a515125bSLeila Ghaffari CeedQFunctionCreateInterior(ceed, 1, problem->setup_sur, problem->setup_sur_loc, 368a515125bSLeila Ghaffari &ceed_data->qf_setup_sur); 369a515125bSLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_setup_sur, "dx", num_comp_x*dim_sur, 370a515125bSLeila Ghaffari CEED_EVAL_GRAD); 371a515125bSLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_setup_sur, "weight", 1, CEED_EVAL_WEIGHT); 372*3b1e209bSJeremy L Thompson CeedQFunctionAddOutput(ceed_data->qf_setup_sur, "surface qdata", 373*3b1e209bSJeremy L Thompson q_data_size_sur, 374a515125bSLeila Ghaffari CEED_EVAL_NONE); 375a515125bSLeila Ghaffari 376a515125bSLeila Ghaffari // -- Creat QFunction for the physics on the boundaries 377a515125bSLeila Ghaffari if (problem->apply_sur) { 378a515125bSLeila Ghaffari CeedQFunctionCreateInterior(ceed, 1, problem->apply_sur, problem->apply_sur_loc, 379a515125bSLeila Ghaffari &ceed_data->qf_apply_sur); 380a515125bSLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_apply_sur, "q", num_comp_q, 381a515125bSLeila Ghaffari CEED_EVAL_INTERP); 382*3b1e209bSJeremy L Thompson CeedQFunctionAddInput(ceed_data->qf_apply_sur, "surface qdata", q_data_size_sur, 383a515125bSLeila Ghaffari CEED_EVAL_NONE); 384a515125bSLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_apply_sur, "x", num_comp_x, 385a515125bSLeila Ghaffari CEED_EVAL_INTERP); 386a515125bSLeila Ghaffari CeedQFunctionAddOutput(ceed_data->qf_apply_sur, "v", num_comp_q, 387a515125bSLeila Ghaffari CEED_EVAL_INTERP); 388a515125bSLeila Ghaffari } 389a515125bSLeila Ghaffari 390a515125bSLeila Ghaffari // ***************************************************************************** 391a515125bSLeila Ghaffari // CEED Operator Apply 392a515125bSLeila Ghaffari // ***************************************************************************** 393a515125bSLeila Ghaffari // -- Apply CEED Operator for the geometric data 394a515125bSLeila Ghaffari CeedOperatorApply(ceed_data->op_setup_vol, ceed_data->x_coord, 395a515125bSLeila Ghaffari ceed_data->q_data, CEED_REQUEST_IMMEDIATE); 396a515125bSLeila Ghaffari 397a515125bSLeila Ghaffari // -- Create and apply CEED Composite Operator for the entire domain 398a515125bSLeila Ghaffari if (!user->phys->implicit) { // RHS 399a515125bSLeila Ghaffari ierr = CreateOperatorForDomain(ceed, dm, bc, ceed_data, user->phys, 400a515125bSLeila Ghaffari user->op_rhs_vol, height, P_sur, Q_sur, 401a515125bSLeila Ghaffari q_data_size_sur, &user->op_rhs); CHKERRQ(ierr); 402a515125bSLeila Ghaffari } else { // IFunction 403a515125bSLeila Ghaffari ierr = CreateOperatorForDomain(ceed, dm, bc, ceed_data, user->phys, 404a515125bSLeila Ghaffari user->op_ifunction_vol, height, P_sur, Q_sur, 405a515125bSLeila Ghaffari q_data_size_sur, &user->op_ifunction); CHKERRQ(ierr); 406a515125bSLeila Ghaffari } 407a515125bSLeila Ghaffari 408a515125bSLeila Ghaffari PetscFunctionReturn(0); 409a515125bSLeila Ghaffari } 410