177841947SLeila Ghaffari // Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at 277841947SLeila Ghaffari // the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights 377841947SLeila Ghaffari // reserved. See files LICENSE and NOTICE for details. 477841947SLeila Ghaffari // 577841947SLeila Ghaffari // This file is part of CEED, a collection of benchmarks, miniapps, software 677841947SLeila Ghaffari // libraries and APIs for efficient high-order finite element and spectral 777841947SLeila Ghaffari // element discretizations for exascale applications. For more information and 877841947SLeila Ghaffari // source code availability see http://github.com/ceed. 977841947SLeila Ghaffari // 1077841947SLeila Ghaffari // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC, 1177841947SLeila Ghaffari // a collaborative effort of two U.S. Department of Energy organizations (Office 1277841947SLeila Ghaffari // of Science and the National Nuclear Security Administration) responsible for 1377841947SLeila Ghaffari // the planning and preparation of a capable exascale ecosystem, including 1477841947SLeila Ghaffari // software, applications, hardware, advanced system engineering and early 1577841947SLeila Ghaffari // testbed platforms, in support of the nation's exascale computing imperative. 1677841947SLeila Ghaffari 1777841947SLeila Ghaffari /// @file 1877841947SLeila Ghaffari /// Setup libCEED for Navier-Stokes example using PETSc 1977841947SLeila Ghaffari 2077841947SLeila Ghaffari #include "../navierstokes.h" 2177841947SLeila Ghaffari 2277841947SLeila Ghaffari // Utility function - essential BC dofs are encoded in closure indices as -(i+1). 2377841947SLeila Ghaffari PetscInt Involute(PetscInt i) { 2477841947SLeila Ghaffari return i >= 0 ? i : -(i+1); 2577841947SLeila Ghaffari } 2677841947SLeila Ghaffari 2777841947SLeila Ghaffari // Utility function to create local CEED restriction 287ed3e4cdSJeremy L Thompson PetscErrorCode CreateRestrictionFromPlex(Ceed ceed, DM dm, CeedInt height, 297ed3e4cdSJeremy L Thompson DMLabel domain_label, CeedInt value, CeedElemRestriction *elem_restr) { 307ed3e4cdSJeremy L Thompson PetscInt num_elem, elem_size, num_dof, num_comp, *elem_restr_offsets; 3177841947SLeila Ghaffari PetscErrorCode ierr; 327ed3e4cdSJeremy L Thompson 3377841947SLeila Ghaffari PetscFunctionBeginUser; 347ed3e4cdSJeremy L Thompson ierr = DMPlexGetLocalOffsets(dm, domain_label, value, height, 0, &num_elem, 357ed3e4cdSJeremy L Thompson &elem_size, &num_comp, &num_dof, &elem_restr_offsets); 367ed3e4cdSJeremy L Thompson CHKERRQ(ierr); 3777841947SLeila Ghaffari 387ed3e4cdSJeremy L Thompson CeedElemRestrictionCreate(ceed, num_elem, elem_size, num_comp, 397ed3e4cdSJeremy L Thompson 1, num_dof, CEED_MEM_HOST, CEED_COPY_VALUES, 407ed3e4cdSJeremy L Thompson elem_restr_offsets, elem_restr); 417ed3e4cdSJeremy L Thompson ierr = PetscFree(elem_restr_offsets); CHKERRQ(ierr); 4277841947SLeila Ghaffari 4377841947SLeila Ghaffari PetscFunctionReturn(0); 4477841947SLeila Ghaffari } 4577841947SLeila Ghaffari 4677841947SLeila Ghaffari // Utility function to get Ceed Restriction for each domain 4777841947SLeila Ghaffari PetscErrorCode GetRestrictionForDomain(Ceed ceed, DM dm, CeedInt height, 4877841947SLeila Ghaffari DMLabel domain_label, PetscInt value, 497ed3e4cdSJeremy L Thompson CeedInt Q, CeedInt q_data_size, 5077841947SLeila Ghaffari CeedElemRestriction *elem_restr_q, 5177841947SLeila Ghaffari CeedElemRestriction *elem_restr_x, 5277841947SLeila Ghaffari CeedElemRestriction *elem_restr_qd_i) { 5377841947SLeila Ghaffari DM dm_coord; 5477841947SLeila Ghaffari CeedInt dim, loc_num_elem; 5577841947SLeila Ghaffari CeedInt Q_dim; 5677841947SLeila Ghaffari PetscErrorCode ierr; 5777841947SLeila Ghaffari PetscFunctionBeginUser; 5877841947SLeila Ghaffari 5977841947SLeila Ghaffari ierr = DMGetDimension(dm, &dim); CHKERRQ(ierr); 6077841947SLeila Ghaffari dim -= height; 6177841947SLeila Ghaffari Q_dim = CeedIntPow(Q, dim); 6277841947SLeila Ghaffari ierr = DMGetCoordinateDM(dm, &dm_coord); CHKERRQ(ierr); 6377841947SLeila Ghaffari ierr = DMPlexSetClosurePermutationTensor(dm_coord, PETSC_DETERMINE, NULL); 6477841947SLeila Ghaffari CHKERRQ(ierr); 657ed3e4cdSJeremy L Thompson ierr = CreateRestrictionFromPlex(ceed, dm, height, domain_label, value, 667ed3e4cdSJeremy L Thompson elem_restr_q); 677ed3e4cdSJeremy L Thompson CHKERRQ(ierr); 687ed3e4cdSJeremy L Thompson ierr = CreateRestrictionFromPlex(ceed, dm_coord, height, domain_label, value, 697ed3e4cdSJeremy L Thompson elem_restr_x); 707ed3e4cdSJeremy L Thompson CHKERRQ(ierr); 7177841947SLeila Ghaffari CeedElemRestrictionGetNumElements(*elem_restr_q, &loc_num_elem); 7277841947SLeila Ghaffari CeedElemRestrictionCreateStrided(ceed, loc_num_elem, Q_dim, 7377841947SLeila Ghaffari q_data_size, q_data_size*loc_num_elem*Q_dim, 7477841947SLeila Ghaffari CEED_STRIDES_BACKEND, elem_restr_qd_i); 7577841947SLeila Ghaffari PetscFunctionReturn(0); 7677841947SLeila Ghaffari } 7777841947SLeila Ghaffari 7877841947SLeila Ghaffari // Utility function to create CEED Composite Operator for the entire domain 7977841947SLeila Ghaffari PetscErrorCode CreateOperatorForDomain(Ceed ceed, DM dm, SimpleBC bc, 8077841947SLeila Ghaffari CeedData ceed_data, Physics phys, 8177841947SLeila Ghaffari CeedOperator op_apply_vol, CeedInt height, 8277841947SLeila Ghaffari CeedInt P_sur, CeedInt Q_sur, CeedInt q_data_size_sur, 8377841947SLeila Ghaffari CeedOperator *op_apply) { 8477841947SLeila Ghaffari CeedInt dim, num_face; 8577841947SLeila Ghaffari DMLabel domain_label; 8677841947SLeila Ghaffari PetscErrorCode ierr; 8777841947SLeila Ghaffari PetscFunctionBeginUser; 8877841947SLeila Ghaffari 8977841947SLeila Ghaffari // Create Composite Operaters 9077841947SLeila Ghaffari CeedCompositeOperatorCreate(ceed, op_apply); 9177841947SLeila Ghaffari 9277841947SLeila Ghaffari // --Apply Sub-Operator for the volume 9377841947SLeila Ghaffari CeedCompositeOperatorAddSub(*op_apply, op_apply_vol); 9477841947SLeila Ghaffari 9577841947SLeila Ghaffari // -- Create Sub-Operator for in/outflow BCs 96e6225c47SLeila Ghaffari if (phys->has_neumann) { 9777841947SLeila Ghaffari // --- Setup 9877841947SLeila Ghaffari ierr = DMGetLabel(dm, "Face Sets", &domain_label); CHKERRQ(ierr); 9977841947SLeila Ghaffari ierr = DMGetDimension(dm, &dim); CHKERRQ(ierr); 10077841947SLeila Ghaffari if (dim == 2) num_face = 4; 10177841947SLeila Ghaffari if (dim == 3) num_face = 6; 10277841947SLeila Ghaffari 10377841947SLeila Ghaffari // --- Get number of quadrature points for the boundaries 10477841947SLeila Ghaffari CeedInt num_qpts_sur; 10577841947SLeila Ghaffari CeedBasisGetNumQuadraturePoints(ceed_data->basis_q_sur, &num_qpts_sur); 10677841947SLeila Ghaffari 10777841947SLeila Ghaffari // --- Create Sub-Operator for each face 10877841947SLeila Ghaffari for (CeedInt i=0; i<num_face; i++) { 10977841947SLeila Ghaffari CeedVector q_data_sur; 11077841947SLeila Ghaffari CeedOperator op_setup_sur, op_apply_sur; 11177841947SLeila Ghaffari CeedElemRestriction elem_restr_x_sur, elem_restr_q_sur, 11277841947SLeila Ghaffari elem_restr_qd_i_sur; 11377841947SLeila Ghaffari 11477841947SLeila Ghaffari // ---- CEED Restriction 1157ed3e4cdSJeremy L Thompson ierr = GetRestrictionForDomain(ceed, dm, height, domain_label, i+1, 11677841947SLeila Ghaffari Q_sur, q_data_size_sur, &elem_restr_q_sur, 11777841947SLeila Ghaffari &elem_restr_x_sur, &elem_restr_qd_i_sur); 11877841947SLeila Ghaffari CHKERRQ(ierr); 11977841947SLeila Ghaffari 12077841947SLeila Ghaffari // ---- CEED Vector 12177841947SLeila Ghaffari PetscInt loc_num_elem_sur; 12277841947SLeila Ghaffari CeedElemRestrictionGetNumElements(elem_restr_q_sur, &loc_num_elem_sur); 12377841947SLeila Ghaffari CeedVectorCreate(ceed, q_data_size_sur*loc_num_elem_sur*num_qpts_sur, 12477841947SLeila Ghaffari &q_data_sur); 12577841947SLeila Ghaffari 12677841947SLeila Ghaffari // ---- CEED Operator 12777841947SLeila Ghaffari // ----- CEED Operator for Setup (geometric factors) 12877841947SLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_setup_sur, NULL, NULL, &op_setup_sur); 12977841947SLeila Ghaffari CeedOperatorSetField(op_setup_sur, "dx", elem_restr_x_sur, 130e6225c47SLeila Ghaffari ceed_data->basis_x_sur, CEED_VECTOR_ACTIVE); 13177841947SLeila Ghaffari CeedOperatorSetField(op_setup_sur, "weight", CEED_ELEMRESTRICTION_NONE, 13277841947SLeila Ghaffari ceed_data->basis_x_sur, CEED_VECTOR_NONE); 133a61c78d6SJeremy L Thompson CeedOperatorSetField(op_setup_sur, "surface qdata", elem_restr_qd_i_sur, 13477841947SLeila Ghaffari CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); 13577841947SLeila Ghaffari 13677841947SLeila Ghaffari // ----- CEED Operator for Physics 13777841947SLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_apply_sur, NULL, NULL, &op_apply_sur); 13877841947SLeila Ghaffari CeedOperatorSetField(op_apply_sur, "q", elem_restr_q_sur, 13977841947SLeila Ghaffari ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 140a61c78d6SJeremy L Thompson CeedOperatorSetField(op_apply_sur, "surface qdata", elem_restr_qd_i_sur, 14177841947SLeila Ghaffari CEED_BASIS_COLLOCATED, q_data_sur); 14277841947SLeila Ghaffari CeedOperatorSetField(op_apply_sur, "x", elem_restr_x_sur, 14377841947SLeila Ghaffari ceed_data->basis_x_sur, ceed_data->x_coord); 14477841947SLeila Ghaffari CeedOperatorSetField(op_apply_sur, "v", elem_restr_q_sur, 14577841947SLeila Ghaffari ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 14677841947SLeila Ghaffari 14777841947SLeila Ghaffari // ----- Apply CEED operator for Setup 14877841947SLeila Ghaffari CeedOperatorApply(op_setup_sur, ceed_data->x_coord, q_data_sur, 14977841947SLeila Ghaffari CEED_REQUEST_IMMEDIATE); 15077841947SLeila Ghaffari 15177841947SLeila Ghaffari // ----- Apply Sub-Operator for the Boundary 15277841947SLeila Ghaffari CeedCompositeOperatorAddSub(*op_apply, op_apply_sur); 15377841947SLeila Ghaffari 15477841947SLeila Ghaffari // ----- Cleanup 15577841947SLeila Ghaffari CeedVectorDestroy(&q_data_sur); 15677841947SLeila Ghaffari CeedElemRestrictionDestroy(&elem_restr_q_sur); 15777841947SLeila Ghaffari CeedElemRestrictionDestroy(&elem_restr_x_sur); 15877841947SLeila Ghaffari CeedElemRestrictionDestroy(&elem_restr_qd_i_sur); 15977841947SLeila Ghaffari CeedOperatorDestroy(&op_setup_sur); 16077841947SLeila Ghaffari CeedOperatorDestroy(&op_apply_sur); 16177841947SLeila Ghaffari } 16277841947SLeila Ghaffari } 16377841947SLeila Ghaffari 16477841947SLeila Ghaffari PetscFunctionReturn(0); 16577841947SLeila Ghaffari } 16677841947SLeila Ghaffari 16777841947SLeila Ghaffari PetscErrorCode SetupLibceed(Ceed ceed, CeedData ceed_data, DM dm, User user, 16877841947SLeila Ghaffari AppCtx app_ctx, ProblemData *problem, SimpleBC bc) { 16977841947SLeila Ghaffari PetscErrorCode ierr; 17077841947SLeila Ghaffari PetscFunctionBeginUser; 17177841947SLeila Ghaffari 17277841947SLeila Ghaffari // ***************************************************************************** 17377841947SLeila Ghaffari // Set up CEED objects for the interior domain (volume) 17477841947SLeila Ghaffari // ***************************************************************************** 17577841947SLeila Ghaffari const PetscInt num_comp_q = 5; 17677841947SLeila Ghaffari const CeedInt dim = problem->dim, 17777841947SLeila Ghaffari num_comp_x = problem->dim, 17877841947SLeila Ghaffari q_data_size_vol = problem->q_data_size_vol, 17977841947SLeila Ghaffari P = app_ctx->degree + 1, 18077841947SLeila Ghaffari Q = P + app_ctx->q_extra; 18177841947SLeila Ghaffari 18277841947SLeila Ghaffari // ----------------------------------------------------------------------------- 18377841947SLeila Ghaffari // CEED Bases 18477841947SLeila Ghaffari // ----------------------------------------------------------------------------- 18577841947SLeila Ghaffari CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_q, P, Q, CEED_GAUSS, 18677841947SLeila Ghaffari &ceed_data->basis_q); 18777841947SLeila Ghaffari CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_x, 2, Q, CEED_GAUSS, 18877841947SLeila Ghaffari &ceed_data->basis_x); 18977841947SLeila Ghaffari CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_x, 2, P, 19077841947SLeila Ghaffari CEED_GAUSS_LOBATTO, &ceed_data->basis_xc); 19177841947SLeila Ghaffari 19277841947SLeila Ghaffari // ----------------------------------------------------------------------------- 19377841947SLeila Ghaffari // CEED Restrictions 19477841947SLeila Ghaffari // ----------------------------------------------------------------------------- 19577841947SLeila Ghaffari // -- Create restriction 1967ed3e4cdSJeremy L Thompson ierr = GetRestrictionForDomain(ceed, dm, 0, 0, 0, Q, q_data_size_vol, 1977ed3e4cdSJeremy L Thompson &ceed_data->elem_restr_q, &ceed_data->elem_restr_x, 19877841947SLeila Ghaffari &ceed_data->elem_restr_qd_i); CHKERRQ(ierr); 19977841947SLeila Ghaffari // -- Create E vectors 20077841947SLeila Ghaffari CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->q_ceed, NULL); 20177841947SLeila Ghaffari CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->q_dot_ceed, 20277841947SLeila Ghaffari NULL); 20377841947SLeila Ghaffari CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->g_ceed, NULL); 20477841947SLeila Ghaffari 20577841947SLeila Ghaffari // ----------------------------------------------------------------------------- 20677841947SLeila Ghaffari // CEED QFunctions 20777841947SLeila Ghaffari // ----------------------------------------------------------------------------- 20877841947SLeila Ghaffari // -- Create QFunction for quadrature data 20977841947SLeila Ghaffari CeedQFunctionCreateInterior(ceed, 1, problem->setup_vol, problem->setup_vol_loc, 21077841947SLeila Ghaffari &ceed_data->qf_setup_vol); 21177841947SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_setup_vol, "dx", num_comp_x*dim, 21277841947SLeila Ghaffari CEED_EVAL_GRAD); 21377841947SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_setup_vol, "weight", 1, CEED_EVAL_WEIGHT); 214a61c78d6SJeremy L Thompson CeedQFunctionAddOutput(ceed_data->qf_setup_vol, "qdata", q_data_size_vol, 21577841947SLeila Ghaffari CEED_EVAL_NONE); 21677841947SLeila Ghaffari 21777841947SLeila Ghaffari // -- Create QFunction for ICs 21877841947SLeila Ghaffari CeedQFunctionCreateInterior(ceed, 1, problem->ics, problem->ics_loc, 21977841947SLeila Ghaffari &ceed_data->qf_ics); 22077841947SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_ics, "x", num_comp_x, CEED_EVAL_INTERP); 22177841947SLeila Ghaffari CeedQFunctionAddOutput(ceed_data->qf_ics, "q0", num_comp_q, CEED_EVAL_NONE); 22277841947SLeila Ghaffari 22377841947SLeila Ghaffari // -- Create QFunction for RHS 22477841947SLeila Ghaffari if (problem->apply_vol_rhs) { 22577841947SLeila Ghaffari CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_rhs, 22677841947SLeila Ghaffari problem->apply_vol_rhs_loc, &ceed_data->qf_rhs_vol); 22777841947SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "q", num_comp_q, CEED_EVAL_INTERP); 22877841947SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "dq", num_comp_q*dim, 22977841947SLeila Ghaffari CEED_EVAL_GRAD); 230a61c78d6SJeremy L Thompson CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "qdata", q_data_size_vol, 23177841947SLeila Ghaffari CEED_EVAL_NONE); 23277841947SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "x", num_comp_x, CEED_EVAL_INTERP); 23377841947SLeila Ghaffari CeedQFunctionAddOutput(ceed_data->qf_rhs_vol, "v", num_comp_q, 23477841947SLeila Ghaffari CEED_EVAL_INTERP); 23577841947SLeila Ghaffari CeedQFunctionAddOutput(ceed_data->qf_rhs_vol, "dv", num_comp_q*dim, 23677841947SLeila Ghaffari CEED_EVAL_GRAD); 23777841947SLeila Ghaffari } 23877841947SLeila Ghaffari 23977841947SLeila Ghaffari // -- Create QFunction for IFunction 24077841947SLeila Ghaffari if (problem->apply_vol_ifunction) { 24177841947SLeila Ghaffari CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_ifunction, 24277841947SLeila Ghaffari problem->apply_vol_ifunction_loc, &ceed_data->qf_ifunction_vol); 24377841947SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "q", num_comp_q, 24477841947SLeila Ghaffari CEED_EVAL_INTERP); 24577841947SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "dq", num_comp_q*dim, 24677841947SLeila Ghaffari CEED_EVAL_GRAD); 247a61c78d6SJeremy L Thompson CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "q dot", num_comp_q, 24877841947SLeila Ghaffari CEED_EVAL_INTERP); 249a61c78d6SJeremy L Thompson CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "qdata", q_data_size_vol, 25077841947SLeila Ghaffari CEED_EVAL_NONE); 25177841947SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "x", num_comp_x, 25277841947SLeila Ghaffari CEED_EVAL_INTERP); 25377841947SLeila Ghaffari CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "v", num_comp_q, 25477841947SLeila Ghaffari CEED_EVAL_INTERP); 25577841947SLeila Ghaffari CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "dv", num_comp_q*dim, 25677841947SLeila Ghaffari CEED_EVAL_GRAD); 25777841947SLeila Ghaffari } 25877841947SLeila Ghaffari 25977841947SLeila Ghaffari // --------------------------------------------------------------------------- 26077841947SLeila Ghaffari // Element coordinates 26177841947SLeila Ghaffari // --------------------------------------------------------------------------- 26277841947SLeila Ghaffari // -- Create CEED vector 26377841947SLeila Ghaffari CeedElemRestrictionCreateVector(ceed_data->elem_restr_x, &ceed_data->x_coord, 26477841947SLeila Ghaffari NULL); 26577841947SLeila Ghaffari 26677841947SLeila Ghaffari // -- Copy PETSc vector in CEED vector 26777841947SLeila Ghaffari Vec X_loc; 26877841947SLeila Ghaffari const PetscScalar *X_loc_array; 26977841947SLeila Ghaffari ierr = DMGetCoordinatesLocal(dm, &X_loc); CHKERRQ(ierr); 270*1864f1c2SLeila Ghaffari ierr = VecScale(X_loc, problem->dm_scale); CHKERRQ(ierr); 27177841947SLeila Ghaffari ierr = VecGetArrayRead(X_loc, &X_loc_array); CHKERRQ(ierr); 27277841947SLeila Ghaffari CeedVectorSetArray(ceed_data->x_coord, CEED_MEM_HOST, CEED_COPY_VALUES, 27377841947SLeila Ghaffari (PetscScalar *)X_loc_array); 27477841947SLeila Ghaffari ierr = VecRestoreArrayRead(X_loc, &X_loc_array); CHKERRQ(ierr); 27577841947SLeila Ghaffari 27677841947SLeila Ghaffari // ----------------------------------------------------------------------------- 27777841947SLeila Ghaffari // CEED vectors 27877841947SLeila Ghaffari // ----------------------------------------------------------------------------- 27977841947SLeila Ghaffari // -- Create CEED vector for geometric data 28077841947SLeila Ghaffari CeedInt num_qpts_vol; 28177841947SLeila Ghaffari PetscInt loc_num_elem_vol; 28277841947SLeila Ghaffari CeedBasisGetNumQuadraturePoints(ceed_data->basis_q, &num_qpts_vol); 28377841947SLeila Ghaffari CeedElemRestrictionGetNumElements(ceed_data->elem_restr_q, &loc_num_elem_vol); 28477841947SLeila Ghaffari CeedVectorCreate(ceed, q_data_size_vol*loc_num_elem_vol*num_qpts_vol, 28577841947SLeila Ghaffari &ceed_data->q_data); 28677841947SLeila Ghaffari 28777841947SLeila Ghaffari // ----------------------------------------------------------------------------- 28877841947SLeila Ghaffari // CEED Operators 28977841947SLeila Ghaffari // ----------------------------------------------------------------------------- 29077841947SLeila Ghaffari // -- Create CEED operator for quadrature data 29177841947SLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_setup_vol, NULL, NULL, 29277841947SLeila Ghaffari &ceed_data->op_setup_vol); 29377841947SLeila Ghaffari CeedOperatorSetField(ceed_data->op_setup_vol, "dx", ceed_data->elem_restr_x, 29477841947SLeila Ghaffari ceed_data->basis_x, CEED_VECTOR_ACTIVE); 29577841947SLeila Ghaffari CeedOperatorSetField(ceed_data->op_setup_vol, "weight", 296e6225c47SLeila Ghaffari CEED_ELEMRESTRICTION_NONE, ceed_data->basis_x, CEED_VECTOR_NONE); 297a61c78d6SJeremy L Thompson CeedOperatorSetField(ceed_data->op_setup_vol, "qdata", 298e6225c47SLeila Ghaffari ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); 29977841947SLeila Ghaffari 30077841947SLeila Ghaffari // -- Create CEED operator for ICs 30177841947SLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_ics, NULL, NULL, &ceed_data->op_ics); 30277841947SLeila Ghaffari CeedOperatorSetField(ceed_data->op_ics, "x", ceed_data->elem_restr_x, 30377841947SLeila Ghaffari ceed_data->basis_xc, CEED_VECTOR_ACTIVE); 30477841947SLeila Ghaffari CeedOperatorSetField(ceed_data->op_ics, "q0", ceed_data->elem_restr_q, 30577841947SLeila Ghaffari CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); 30677841947SLeila Ghaffari 30777841947SLeila Ghaffari // Create CEED operator for RHS 30877841947SLeila Ghaffari if (ceed_data->qf_rhs_vol) { 30977841947SLeila Ghaffari CeedOperator op; 31077841947SLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_rhs_vol, NULL, NULL, &op); 31177841947SLeila Ghaffari CeedOperatorSetField(op, "q", ceed_data->elem_restr_q, ceed_data->basis_q, 31277841947SLeila Ghaffari CEED_VECTOR_ACTIVE); 31377841947SLeila Ghaffari CeedOperatorSetField(op, "dq", ceed_data->elem_restr_q, ceed_data->basis_q, 31477841947SLeila Ghaffari CEED_VECTOR_ACTIVE); 315a61c78d6SJeremy L Thompson CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i, 316e6225c47SLeila Ghaffari CEED_BASIS_COLLOCATED, ceed_data->q_data); 31777841947SLeila Ghaffari CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x, 31877841947SLeila Ghaffari ceed_data->x_coord); 31977841947SLeila Ghaffari CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q, 32077841947SLeila Ghaffari CEED_VECTOR_ACTIVE); 32177841947SLeila Ghaffari CeedOperatorSetField(op, "dv", ceed_data->elem_restr_q, ceed_data->basis_q, 32277841947SLeila Ghaffari CEED_VECTOR_ACTIVE); 32377841947SLeila Ghaffari user->op_rhs_vol = op; 32477841947SLeila Ghaffari } 32577841947SLeila Ghaffari 32677841947SLeila Ghaffari // -- CEED operator for IFunction 32777841947SLeila Ghaffari if (ceed_data->qf_ifunction_vol) { 32877841947SLeila Ghaffari CeedOperator op; 32977841947SLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_ifunction_vol, NULL, NULL, &op); 33077841947SLeila Ghaffari CeedOperatorSetField(op, "q", ceed_data->elem_restr_q, ceed_data->basis_q, 33177841947SLeila Ghaffari CEED_VECTOR_ACTIVE); 33277841947SLeila Ghaffari CeedOperatorSetField(op, "dq", ceed_data->elem_restr_q, ceed_data->basis_q, 33377841947SLeila Ghaffari CEED_VECTOR_ACTIVE); 334a61c78d6SJeremy L Thompson CeedOperatorSetField(op, "q dot", ceed_data->elem_restr_q, ceed_data->basis_q, 33577841947SLeila Ghaffari user->q_dot_ceed); 336a61c78d6SJeremy L Thompson CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i, 337e6225c47SLeila Ghaffari CEED_BASIS_COLLOCATED, ceed_data->q_data); 33877841947SLeila Ghaffari CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x, 33977841947SLeila Ghaffari ceed_data->x_coord); 34077841947SLeila Ghaffari CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q, 34177841947SLeila Ghaffari CEED_VECTOR_ACTIVE); 34277841947SLeila Ghaffari CeedOperatorSetField(op, "dv", ceed_data->elem_restr_q, ceed_data->basis_q, 34377841947SLeila Ghaffari CEED_VECTOR_ACTIVE); 34477841947SLeila Ghaffari user->op_ifunction_vol = op; 34577841947SLeila Ghaffari } 34677841947SLeila Ghaffari 34777841947SLeila Ghaffari // ***************************************************************************** 34877841947SLeila Ghaffari // Set up CEED objects for the exterior domain (surface) 34977841947SLeila Ghaffari // ***************************************************************************** 35077841947SLeila Ghaffari CeedInt height = 1, 35177841947SLeila Ghaffari dim_sur = dim - height, 35277841947SLeila Ghaffari P_sur = app_ctx->degree + 1, 35377841947SLeila Ghaffari Q_sur = P_sur + app_ctx->q_extra; 35477841947SLeila Ghaffari const CeedInt q_data_size_sur = problem->q_data_size_sur; 35577841947SLeila Ghaffari 35677841947SLeila Ghaffari // ----------------------------------------------------------------------------- 35777841947SLeila Ghaffari // CEED Bases 35877841947SLeila Ghaffari // ----------------------------------------------------------------------------- 35977841947SLeila Ghaffari CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_q, P_sur, Q_sur, 36077841947SLeila Ghaffari CEED_GAUSS, &ceed_data->basis_q_sur); 36177841947SLeila Ghaffari CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_x, 2, Q_sur, CEED_GAUSS, 36277841947SLeila Ghaffari &ceed_data->basis_x_sur); 36377841947SLeila Ghaffari 36477841947SLeila Ghaffari // ----------------------------------------------------------------------------- 36577841947SLeila Ghaffari // CEED QFunctions 36677841947SLeila Ghaffari // ----------------------------------------------------------------------------- 36777841947SLeila Ghaffari // -- Create QFunction for quadrature data 36877841947SLeila Ghaffari CeedQFunctionCreateInterior(ceed, 1, problem->setup_sur, problem->setup_sur_loc, 36977841947SLeila Ghaffari &ceed_data->qf_setup_sur); 37077841947SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_setup_sur, "dx", num_comp_x*dim_sur, 37177841947SLeila Ghaffari CEED_EVAL_GRAD); 37277841947SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_setup_sur, "weight", 1, CEED_EVAL_WEIGHT); 373a61c78d6SJeremy L Thompson CeedQFunctionAddOutput(ceed_data->qf_setup_sur, "surface qdata", 374a61c78d6SJeremy L Thompson q_data_size_sur, 37577841947SLeila Ghaffari CEED_EVAL_NONE); 37677841947SLeila Ghaffari 37777841947SLeila Ghaffari // -- Creat QFunction for the physics on the boundaries 37877841947SLeila Ghaffari if (problem->apply_sur) { 37977841947SLeila Ghaffari CeedQFunctionCreateInterior(ceed, 1, problem->apply_sur, problem->apply_sur_loc, 38077841947SLeila Ghaffari &ceed_data->qf_apply_sur); 38177841947SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_apply_sur, "q", num_comp_q, 38277841947SLeila Ghaffari CEED_EVAL_INTERP); 383a61c78d6SJeremy L Thompson CeedQFunctionAddInput(ceed_data->qf_apply_sur, "surface qdata", q_data_size_sur, 38477841947SLeila Ghaffari CEED_EVAL_NONE); 38577841947SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_apply_sur, "x", num_comp_x, 38677841947SLeila Ghaffari CEED_EVAL_INTERP); 38777841947SLeila Ghaffari CeedQFunctionAddOutput(ceed_data->qf_apply_sur, "v", num_comp_q, 38877841947SLeila Ghaffari CEED_EVAL_INTERP); 38977841947SLeila Ghaffari } 39077841947SLeila Ghaffari 39177841947SLeila Ghaffari // ***************************************************************************** 39277841947SLeila Ghaffari // CEED Operator Apply 39377841947SLeila Ghaffari // ***************************************************************************** 39477841947SLeila Ghaffari // -- Apply CEED Operator for the geometric data 39577841947SLeila Ghaffari CeedOperatorApply(ceed_data->op_setup_vol, ceed_data->x_coord, 39677841947SLeila Ghaffari ceed_data->q_data, CEED_REQUEST_IMMEDIATE); 39777841947SLeila Ghaffari 39877841947SLeila Ghaffari // -- Create and apply CEED Composite Operator for the entire domain 39977841947SLeila Ghaffari if (!user->phys->implicit) { // RHS 40077841947SLeila Ghaffari ierr = CreateOperatorForDomain(ceed, dm, bc, ceed_data, user->phys, 40177841947SLeila Ghaffari user->op_rhs_vol, height, P_sur, Q_sur, 40277841947SLeila Ghaffari q_data_size_sur, &user->op_rhs); CHKERRQ(ierr); 40377841947SLeila Ghaffari } else { // IFunction 40477841947SLeila Ghaffari ierr = CreateOperatorForDomain(ceed, dm, bc, ceed_data, user->phys, 40577841947SLeila Ghaffari user->op_ifunction_vol, height, P_sur, Q_sur, 40677841947SLeila Ghaffari q_data_size_sur, &user->op_ifunction); CHKERRQ(ierr); 40777841947SLeila Ghaffari } 40877841947SLeila Ghaffari 40977841947SLeila Ghaffari PetscFunctionReturn(0); 41077841947SLeila Ghaffari } 411