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) { 59*3796c488SJed Brown ierr = DMGetCellCoordinateDM(dm, &dm_coord); CHKERRQ(ierr); 60*3796c488SJed Brown if (!dm_coord) { 6177841947SLeila Ghaffari ierr = DMGetCoordinateDM(dm, &dm_coord); CHKERRQ(ierr); 62*3796c488SJed 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 7977841947SLeila Ghaffari // Utility function to create CEED Composite Operator for the entire domain 8077841947SLeila Ghaffari PetscErrorCode CreateOperatorForDomain(Ceed ceed, DM dm, SimpleBC bc, 8177841947SLeila Ghaffari CeedData ceed_data, Physics phys, 82e334ad8fSJed Brown CeedOperator op_apply_vol, 83e334ad8fSJed Brown CeedOperator op_apply_ijacobian_vol, 84e334ad8fSJed Brown CeedInt height, 85e334ad8fSJed Brown CeedInt P_sur, CeedInt Q_sur, 86e334ad8fSJed Brown CeedInt q_data_size_sur, CeedInt jac_data_size_sur, 87e334ad8fSJed Brown CeedOperator *op_apply, CeedOperator *op_apply_ijacobian) { 8877841947SLeila Ghaffari DMLabel domain_label; 8977841947SLeila Ghaffari PetscErrorCode ierr; 9077841947SLeila Ghaffari PetscFunctionBeginUser; 9177841947SLeila Ghaffari 9277841947SLeila Ghaffari // Create Composite Operaters 9377841947SLeila Ghaffari CeedCompositeOperatorCreate(ceed, op_apply); 94e334ad8fSJed Brown if (op_apply_ijacobian) 95e334ad8fSJed Brown CeedCompositeOperatorCreate(ceed, op_apply_ijacobian); 9677841947SLeila Ghaffari 9777841947SLeila Ghaffari // --Apply Sub-Operator for the volume 9877841947SLeila Ghaffari CeedCompositeOperatorAddSub(*op_apply, op_apply_vol); 99e334ad8fSJed Brown if (op_apply_ijacobian) 100e334ad8fSJed Brown CeedCompositeOperatorAddSub(*op_apply_ijacobian, op_apply_ijacobian_vol); 10177841947SLeila Ghaffari 10277841947SLeila Ghaffari // -- Create Sub-Operator for in/outflow BCs 10388626eedSJames Wright if (phys->has_neumann || 1) { 10477841947SLeila Ghaffari // --- Setup 10577841947SLeila Ghaffari ierr = DMGetLabel(dm, "Face Sets", &domain_label); CHKERRQ(ierr); 10677841947SLeila Ghaffari 10777841947SLeila Ghaffari // --- Get number of quadrature points for the boundaries 10877841947SLeila Ghaffari CeedInt num_qpts_sur; 10977841947SLeila Ghaffari CeedBasisGetNumQuadraturePoints(ceed_data->basis_q_sur, &num_qpts_sur); 11077841947SLeila Ghaffari 1112fe7aee7SLeila Ghaffari // --- Create Sub-Operator for inflow boundaries 1122fe7aee7SLeila Ghaffari for (CeedInt i=0; i < bc->num_inflow; i++) { 113b55ac660SJames Wright CeedVector q_data_sur, jac_data_sur; 114e334ad8fSJed Brown CeedOperator op_setup_sur, op_apply_inflow, 115e334ad8fSJed Brown op_apply_inflow_jacobian = NULL; 116b55ac660SJames Wright CeedElemRestriction elem_restr_x_sur, elem_restr_q_sur, elem_restr_qd_i_sur, 117b55ac660SJames Wright elem_restr_jd_i_sur; 11877841947SLeila Ghaffari 11977841947SLeila Ghaffari // ---- CEED Restriction 1202fe7aee7SLeila Ghaffari ierr = GetRestrictionForDomain(ceed, dm, height, domain_label, bc->inflows[i], 1212fe7aee7SLeila Ghaffari Q_sur, q_data_size_sur, &elem_restr_q_sur, &elem_restr_x_sur, 1222fe7aee7SLeila Ghaffari &elem_restr_qd_i_sur); 12377841947SLeila Ghaffari CHKERRQ(ierr); 124b55ac660SJames Wright if (jac_data_size_sur > 0) { 125b55ac660SJames Wright // State-dependent data will be passed from residual to Jacobian. This will be collocated. 126b55ac660SJames Wright ierr = GetRestrictionForDomain(ceed, dm, height, domain_label, bc->inflows[i], 127b55ac660SJames Wright Q_sur, jac_data_size_sur, NULL, NULL, 128b55ac660SJames Wright &elem_restr_jd_i_sur); 129b55ac660SJames Wright CHKERRQ(ierr); 130b55ac660SJames Wright CeedElemRestrictionCreateVector(elem_restr_jd_i_sur, &jac_data_sur, NULL); 131b55ac660SJames Wright } else { 132b55ac660SJames Wright elem_restr_jd_i_sur = NULL; 133b55ac660SJames Wright jac_data_sur = NULL; 134b55ac660SJames Wright } 13577841947SLeila Ghaffari 13677841947SLeila Ghaffari // ---- CEED Vector 13777841947SLeila Ghaffari PetscInt loc_num_elem_sur; 13877841947SLeila Ghaffari CeedElemRestrictionGetNumElements(elem_restr_q_sur, &loc_num_elem_sur); 13977841947SLeila Ghaffari CeedVectorCreate(ceed, q_data_size_sur*loc_num_elem_sur*num_qpts_sur, 14077841947SLeila Ghaffari &q_data_sur); 14177841947SLeila Ghaffari 14277841947SLeila Ghaffari // ---- CEED Operator 14377841947SLeila Ghaffari // ----- CEED Operator for Setup (geometric factors) 14477841947SLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_setup_sur, NULL, NULL, &op_setup_sur); 14577841947SLeila Ghaffari CeedOperatorSetField(op_setup_sur, "dx", elem_restr_x_sur, 146e6225c47SLeila Ghaffari ceed_data->basis_x_sur, CEED_VECTOR_ACTIVE); 14777841947SLeila Ghaffari CeedOperatorSetField(op_setup_sur, "weight", CEED_ELEMRESTRICTION_NONE, 14877841947SLeila Ghaffari ceed_data->basis_x_sur, CEED_VECTOR_NONE); 149a61c78d6SJeremy L Thompson CeedOperatorSetField(op_setup_sur, "surface qdata", elem_restr_qd_i_sur, 15077841947SLeila Ghaffari CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); 15177841947SLeila Ghaffari 15277841947SLeila Ghaffari // ----- CEED Operator for Physics 1532fe7aee7SLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_apply_inflow, NULL, NULL, 1542fe7aee7SLeila Ghaffari &op_apply_inflow); 1552fe7aee7SLeila Ghaffari CeedOperatorSetField(op_apply_inflow, "q", elem_restr_q_sur, 15677841947SLeila Ghaffari ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 157e8b03feeSJames Wright CeedOperatorSetField(op_apply_inflow, "Grad_q", elem_restr_q_sur, 158e8b03feeSJames Wright ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 1592fe7aee7SLeila Ghaffari CeedOperatorSetField(op_apply_inflow, "surface qdata", elem_restr_qd_i_sur, 16077841947SLeila Ghaffari CEED_BASIS_COLLOCATED, q_data_sur); 1612fe7aee7SLeila Ghaffari CeedOperatorSetField(op_apply_inflow, "x", elem_restr_x_sur, 16277841947SLeila Ghaffari ceed_data->basis_x_sur, ceed_data->x_coord); 1632fe7aee7SLeila Ghaffari CeedOperatorSetField(op_apply_inflow, "v", elem_restr_q_sur, 16477841947SLeila Ghaffari ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 165b55ac660SJames Wright if (elem_restr_jd_i_sur) 166b55ac660SJames Wright CeedOperatorSetField(op_apply_inflow, "surface jacobian data", 167b55ac660SJames Wright elem_restr_jd_i_sur, 168b55ac660SJames Wright CEED_BASIS_COLLOCATED, jac_data_sur); 16977841947SLeila Ghaffari 170e334ad8fSJed Brown if (ceed_data->qf_apply_inflow_jacobian) { 171e334ad8fSJed Brown CeedOperatorCreate(ceed, ceed_data->qf_apply_inflow_jacobian, NULL, NULL, 172e334ad8fSJed Brown &op_apply_inflow_jacobian); 173e334ad8fSJed Brown CeedOperatorSetField(op_apply_inflow_jacobian, "dq", elem_restr_q_sur, 174e334ad8fSJed Brown ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 175b55ac660SJames Wright CeedOperatorSetField(op_apply_inflow_jacobian, "Grad_dq", elem_restr_q_sur, 176b55ac660SJames Wright ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 177e334ad8fSJed Brown CeedOperatorSetField(op_apply_inflow_jacobian, "surface qdata", 178e334ad8fSJed Brown elem_restr_qd_i_sur, 179e334ad8fSJed Brown CEED_BASIS_COLLOCATED, q_data_sur); 180e334ad8fSJed Brown CeedOperatorSetField(op_apply_inflow_jacobian, "x", elem_restr_x_sur, 181e334ad8fSJed Brown ceed_data->basis_x_sur, ceed_data->x_coord); 182b55ac660SJames Wright CeedOperatorSetField(op_apply_inflow_jacobian, "surface jacobian data", 183b55ac660SJames Wright elem_restr_jd_i_sur, 184b55ac660SJames Wright CEED_BASIS_COLLOCATED, jac_data_sur); 185e334ad8fSJed Brown CeedOperatorSetField(op_apply_inflow_jacobian, "v", elem_restr_q_sur, 186e334ad8fSJed Brown ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 187e334ad8fSJed Brown } 188e334ad8fSJed Brown 18977841947SLeila Ghaffari // ----- Apply CEED operator for Setup 19077841947SLeila Ghaffari CeedOperatorApply(op_setup_sur, ceed_data->x_coord, q_data_sur, 19177841947SLeila Ghaffari CEED_REQUEST_IMMEDIATE); 19277841947SLeila Ghaffari 1932fe7aee7SLeila Ghaffari // ----- Apply Sub-Operator for Physics 1942fe7aee7SLeila Ghaffari CeedCompositeOperatorAddSub(*op_apply, op_apply_inflow); 195e334ad8fSJed Brown if (op_apply_ijacobian) 196e334ad8fSJed Brown CeedCompositeOperatorAddSub(*op_apply_ijacobian, op_apply_inflow_jacobian); 19777841947SLeila Ghaffari 19877841947SLeila Ghaffari // ----- Cleanup 19977841947SLeila Ghaffari CeedVectorDestroy(&q_data_sur); 200b55ac660SJames Wright CeedVectorDestroy(&jac_data_sur); 20177841947SLeila Ghaffari CeedElemRestrictionDestroy(&elem_restr_q_sur); 20277841947SLeila Ghaffari CeedElemRestrictionDestroy(&elem_restr_x_sur); 20377841947SLeila Ghaffari CeedElemRestrictionDestroy(&elem_restr_qd_i_sur); 204b55ac660SJames Wright CeedElemRestrictionDestroy(&elem_restr_jd_i_sur); 20577841947SLeila Ghaffari CeedOperatorDestroy(&op_setup_sur); 2062fe7aee7SLeila Ghaffari CeedOperatorDestroy(&op_apply_inflow); 207e334ad8fSJed Brown CeedOperatorDestroy(&op_apply_inflow_jacobian); 20877841947SLeila Ghaffari } 20977841947SLeila Ghaffari 2102fe7aee7SLeila Ghaffari // --- Create Sub-Operator for outflow boundaries 2112fe7aee7SLeila Ghaffari for (CeedInt i=0; i < bc->num_outflow; i++) { 212e334ad8fSJed Brown CeedVector q_data_sur, jac_data_sur; 213e334ad8fSJed Brown CeedOperator op_setup_sur, op_apply_outflow, 214e334ad8fSJed Brown op_apply_outflow_jacobian = NULL; 215e334ad8fSJed Brown CeedElemRestriction elem_restr_x_sur, elem_restr_q_sur, elem_restr_qd_i_sur, 216e334ad8fSJed Brown elem_restr_jd_i_sur; 2172fe7aee7SLeila Ghaffari 2182fe7aee7SLeila Ghaffari // ---- CEED Restriction 2192fe7aee7SLeila Ghaffari ierr = GetRestrictionForDomain(ceed, dm, height, domain_label, bc->outflows[i], 2202fe7aee7SLeila Ghaffari Q_sur, q_data_size_sur, &elem_restr_q_sur, &elem_restr_x_sur, 2212fe7aee7SLeila Ghaffari &elem_restr_qd_i_sur); 2222fe7aee7SLeila Ghaffari CHKERRQ(ierr); 22339c69132SJed Brown if (jac_data_size_sur > 0) { 22439c69132SJed Brown // State-dependent data will be passed from residual to Jacobian. This will be collocated. 225e334ad8fSJed Brown ierr = GetRestrictionForDomain(ceed, dm, height, domain_label, bc->outflows[i], 226e334ad8fSJed Brown Q_sur, jac_data_size_sur, NULL, NULL, 227e334ad8fSJed Brown &elem_restr_jd_i_sur); 228e334ad8fSJed Brown CHKERRQ(ierr); 22939c69132SJed Brown CeedElemRestrictionCreateVector(elem_restr_jd_i_sur, &jac_data_sur, NULL); 23039c69132SJed Brown } else { 23139c69132SJed Brown elem_restr_jd_i_sur = NULL; 23239c69132SJed Brown jac_data_sur = NULL; 23339c69132SJed Brown } 2342fe7aee7SLeila Ghaffari 2352fe7aee7SLeila Ghaffari // ---- CEED Vector 2362fe7aee7SLeila Ghaffari PetscInt loc_num_elem_sur; 2372fe7aee7SLeila Ghaffari CeedElemRestrictionGetNumElements(elem_restr_q_sur, &loc_num_elem_sur); 2382fe7aee7SLeila Ghaffari CeedVectorCreate(ceed, q_data_size_sur*loc_num_elem_sur*num_qpts_sur, 2392fe7aee7SLeila Ghaffari &q_data_sur); 2402fe7aee7SLeila Ghaffari 2412fe7aee7SLeila Ghaffari // ---- CEED Operator 2422fe7aee7SLeila Ghaffari // ----- CEED Operator for Setup (geometric factors) 2432fe7aee7SLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_setup_sur, NULL, NULL, &op_setup_sur); 2442fe7aee7SLeila Ghaffari CeedOperatorSetField(op_setup_sur, "dx", elem_restr_x_sur, 2452fe7aee7SLeila Ghaffari ceed_data->basis_x_sur, CEED_VECTOR_ACTIVE); 2462fe7aee7SLeila Ghaffari CeedOperatorSetField(op_setup_sur, "weight", CEED_ELEMRESTRICTION_NONE, 2472fe7aee7SLeila Ghaffari ceed_data->basis_x_sur, CEED_VECTOR_NONE); 2482fe7aee7SLeila Ghaffari CeedOperatorSetField(op_setup_sur, "surface qdata", elem_restr_qd_i_sur, 2492fe7aee7SLeila Ghaffari CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); 2502fe7aee7SLeila Ghaffari 2512fe7aee7SLeila Ghaffari // ----- CEED Operator for Physics 2522fe7aee7SLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_apply_outflow, NULL, NULL, 2532fe7aee7SLeila Ghaffari &op_apply_outflow); 2542fe7aee7SLeila Ghaffari CeedOperatorSetField(op_apply_outflow, "q", elem_restr_q_sur, 2552fe7aee7SLeila Ghaffari ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 256e8b03feeSJames Wright CeedOperatorSetField(op_apply_outflow, "Grad_q", elem_restr_q_sur, 257e8b03feeSJames Wright ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 2582fe7aee7SLeila Ghaffari CeedOperatorSetField(op_apply_outflow, "surface qdata", elem_restr_qd_i_sur, 2592fe7aee7SLeila Ghaffari CEED_BASIS_COLLOCATED, q_data_sur); 2602fe7aee7SLeila Ghaffari CeedOperatorSetField(op_apply_outflow, "x", elem_restr_x_sur, 2612fe7aee7SLeila Ghaffari ceed_data->basis_x_sur, ceed_data->x_coord); 2622fe7aee7SLeila Ghaffari CeedOperatorSetField(op_apply_outflow, "v", elem_restr_q_sur, 2632fe7aee7SLeila Ghaffari ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 26439c69132SJed Brown if (elem_restr_jd_i_sur) 265e334ad8fSJed Brown CeedOperatorSetField(op_apply_outflow, "surface jacobian data", 266e334ad8fSJed Brown elem_restr_jd_i_sur, 267e334ad8fSJed Brown CEED_BASIS_COLLOCATED, jac_data_sur); 268e334ad8fSJed Brown 269e334ad8fSJed Brown if (ceed_data->qf_apply_outflow_jacobian) { 270e334ad8fSJed Brown CeedOperatorCreate(ceed, ceed_data->qf_apply_outflow_jacobian, NULL, NULL, 271e334ad8fSJed Brown &op_apply_outflow_jacobian); 272e334ad8fSJed Brown CeedOperatorSetField(op_apply_outflow_jacobian, "dq", elem_restr_q_sur, 273e334ad8fSJed Brown ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 2740ec2498eSJames Wright CeedOperatorSetField(op_apply_outflow_jacobian, "Grad_dq", elem_restr_q_sur, 2750ec2498eSJames Wright ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 276e334ad8fSJed Brown CeedOperatorSetField(op_apply_outflow_jacobian, "surface qdata", 277e334ad8fSJed Brown elem_restr_qd_i_sur, 278e334ad8fSJed Brown CEED_BASIS_COLLOCATED, q_data_sur); 2790ec2498eSJames Wright CeedOperatorSetField(op_apply_outflow_jacobian, "x", elem_restr_x_sur, 2800ec2498eSJames Wright ceed_data->basis_x_sur, ceed_data->x_coord); 281e334ad8fSJed Brown CeedOperatorSetField(op_apply_outflow_jacobian, "surface jacobian data", 282e334ad8fSJed Brown elem_restr_jd_i_sur, 283e334ad8fSJed Brown CEED_BASIS_COLLOCATED, jac_data_sur); 284e334ad8fSJed Brown CeedOperatorSetField(op_apply_outflow_jacobian, "v", elem_restr_q_sur, 285e334ad8fSJed Brown ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 286e334ad8fSJed Brown } 2872fe7aee7SLeila Ghaffari 2882fe7aee7SLeila Ghaffari // ----- Apply CEED operator for Setup 2892fe7aee7SLeila Ghaffari CeedOperatorApply(op_setup_sur, ceed_data->x_coord, q_data_sur, 2902fe7aee7SLeila Ghaffari CEED_REQUEST_IMMEDIATE); 2912fe7aee7SLeila Ghaffari 2922fe7aee7SLeila Ghaffari // ----- Apply Sub-Operator for Physics 2932fe7aee7SLeila Ghaffari CeedCompositeOperatorAddSub(*op_apply, op_apply_outflow); 294e334ad8fSJed Brown if (op_apply_ijacobian) 295e334ad8fSJed Brown CeedCompositeOperatorAddSub(*op_apply_ijacobian, op_apply_outflow_jacobian); 2962fe7aee7SLeila Ghaffari 2972fe7aee7SLeila Ghaffari // ----- Cleanup 2982fe7aee7SLeila Ghaffari CeedVectorDestroy(&q_data_sur); 299e334ad8fSJed Brown CeedVectorDestroy(&jac_data_sur); 3002fe7aee7SLeila Ghaffari CeedElemRestrictionDestroy(&elem_restr_q_sur); 3012fe7aee7SLeila Ghaffari CeedElemRestrictionDestroy(&elem_restr_x_sur); 3022fe7aee7SLeila Ghaffari CeedElemRestrictionDestroy(&elem_restr_qd_i_sur); 303e334ad8fSJed Brown CeedElemRestrictionDestroy(&elem_restr_jd_i_sur); 3042fe7aee7SLeila Ghaffari CeedOperatorDestroy(&op_setup_sur); 3052fe7aee7SLeila Ghaffari CeedOperatorDestroy(&op_apply_outflow); 306e334ad8fSJed Brown CeedOperatorDestroy(&op_apply_outflow_jacobian); 3072fe7aee7SLeila Ghaffari } 3082fe7aee7SLeila Ghaffari } 30911436a05SJames Wright 31011436a05SJames Wright // ----- Get Context Labels for Operator 31111436a05SJames Wright CeedOperatorContextGetFieldLabel(*op_apply, "solution time", 31211436a05SJames Wright &phys->solution_time_label); 31388626eedSJames Wright CeedOperatorContextGetFieldLabel(*op_apply, "timestep size", 31488626eedSJames Wright &phys->timestep_size_label); 31511436a05SJames Wright 31677841947SLeila Ghaffari PetscFunctionReturn(0); 31777841947SLeila Ghaffari } 31877841947SLeila Ghaffari 31977841947SLeila Ghaffari PetscErrorCode SetupLibceed(Ceed ceed, CeedData ceed_data, DM dm, User user, 320c95f9967SJed Brown AppCtx app_ctx, ProblemData *problem, SimpleBC bc) { 32177841947SLeila Ghaffari PetscErrorCode ierr; 32277841947SLeila Ghaffari PetscFunctionBeginUser; 32377841947SLeila Ghaffari 32477841947SLeila Ghaffari // ***************************************************************************** 32577841947SLeila Ghaffari // Set up CEED objects for the interior domain (volume) 32677841947SLeila Ghaffari // ***************************************************************************** 32777841947SLeila Ghaffari const PetscInt num_comp_q = 5; 32877841947SLeila Ghaffari const CeedInt dim = problem->dim, 32977841947SLeila Ghaffari num_comp_x = problem->dim, 33077841947SLeila Ghaffari q_data_size_vol = problem->q_data_size_vol, 331e334ad8fSJed Brown jac_data_size_vol = num_comp_q + 6 + 3, 33277841947SLeila Ghaffari P = app_ctx->degree + 1, 33377841947SLeila Ghaffari Q = P + app_ctx->q_extra; 334a3ae0734SJed Brown CeedElemRestriction elem_restr_jd_i; 335a3ae0734SJed Brown CeedVector jac_data; 33677841947SLeila Ghaffari 33777841947SLeila Ghaffari // ----------------------------------------------------------------------------- 33877841947SLeila Ghaffari // CEED Bases 33977841947SLeila Ghaffari // ----------------------------------------------------------------------------- 34077841947SLeila Ghaffari CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_q, P, Q, CEED_GAUSS, 34177841947SLeila Ghaffari &ceed_data->basis_q); 34277841947SLeila Ghaffari CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_x, 2, Q, CEED_GAUSS, 34377841947SLeila Ghaffari &ceed_data->basis_x); 34477841947SLeila Ghaffari CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_x, 2, P, 34577841947SLeila Ghaffari CEED_GAUSS_LOBATTO, &ceed_data->basis_xc); 34677841947SLeila Ghaffari 34777841947SLeila Ghaffari // ----------------------------------------------------------------------------- 34877841947SLeila Ghaffari // CEED Restrictions 34977841947SLeila Ghaffari // ----------------------------------------------------------------------------- 35077841947SLeila Ghaffari // -- Create restriction 3517ed3e4cdSJeremy L Thompson ierr = GetRestrictionForDomain(ceed, dm, 0, 0, 0, Q, q_data_size_vol, 3527ed3e4cdSJeremy L Thompson &ceed_data->elem_restr_q, &ceed_data->elem_restr_x, 35377841947SLeila Ghaffari &ceed_data->elem_restr_qd_i); CHKERRQ(ierr); 354a3ae0734SJed Brown 355a3ae0734SJed Brown ierr = GetRestrictionForDomain(ceed, dm, 0, 0, 0, Q, jac_data_size_vol, 356a3ae0734SJed Brown NULL, NULL, 357a3ae0734SJed Brown &elem_restr_jd_i); CHKERRQ(ierr); 35877841947SLeila Ghaffari // -- Create E vectors 35977841947SLeila Ghaffari CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->q_ceed, NULL); 36077841947SLeila Ghaffari CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->q_dot_ceed, 36177841947SLeila Ghaffari NULL); 36277841947SLeila Ghaffari CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->g_ceed, NULL); 36377841947SLeila Ghaffari 36477841947SLeila Ghaffari // ----------------------------------------------------------------------------- 36577841947SLeila Ghaffari // CEED QFunctions 36677841947SLeila Ghaffari // ----------------------------------------------------------------------------- 36777841947SLeila Ghaffari // -- Create QFunction for quadrature data 36891e5af17SJed Brown CeedQFunctionCreateInterior(ceed, 1, problem->setup_vol.qfunction, 36991e5af17SJed Brown problem->setup_vol.qfunction_loc, 37077841947SLeila Ghaffari &ceed_data->qf_setup_vol); 371841e4c73SJed Brown if (problem->setup_vol.qfunction_context) { 372841e4c73SJed Brown CeedQFunctionSetContext(ceed_data->qf_setup_vol, 373841e4c73SJed Brown problem->setup_vol.qfunction_context); 374841e4c73SJed Brown CeedQFunctionContextDestroy(&problem->setup_vol.qfunction_context); 375841e4c73SJed Brown } 37677841947SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_setup_vol, "dx", num_comp_x*dim, 37777841947SLeila Ghaffari CEED_EVAL_GRAD); 37877841947SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_setup_vol, "weight", 1, CEED_EVAL_WEIGHT); 379a61c78d6SJeremy L Thompson CeedQFunctionAddOutput(ceed_data->qf_setup_vol, "qdata", q_data_size_vol, 38077841947SLeila Ghaffari CEED_EVAL_NONE); 38177841947SLeila Ghaffari 38277841947SLeila Ghaffari // -- Create QFunction for ICs 38391e5af17SJed Brown CeedQFunctionCreateInterior(ceed, 1, problem->ics.qfunction, 38491e5af17SJed Brown problem->ics.qfunction_loc, 38577841947SLeila Ghaffari &ceed_data->qf_ics); 386841e4c73SJed Brown CeedQFunctionSetContext(ceed_data->qf_ics, problem->ics.qfunction_context); 387841e4c73SJed Brown CeedQFunctionContextDestroy(&problem->ics.qfunction_context); 38877841947SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_ics, "x", num_comp_x, CEED_EVAL_INTERP); 38977841947SLeila Ghaffari CeedQFunctionAddOutput(ceed_data->qf_ics, "q0", num_comp_q, CEED_EVAL_NONE); 39077841947SLeila Ghaffari 39177841947SLeila Ghaffari // -- Create QFunction for RHS 39291e5af17SJed Brown if (problem->apply_vol_rhs.qfunction) { 39391e5af17SJed Brown CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_rhs.qfunction, 39491e5af17SJed Brown problem->apply_vol_rhs.qfunction_loc, &ceed_data->qf_rhs_vol); 395841e4c73SJed Brown CeedQFunctionSetContext(ceed_data->qf_rhs_vol, 396841e4c73SJed Brown problem->apply_vol_rhs.qfunction_context); 397841e4c73SJed Brown CeedQFunctionContextDestroy(&problem->apply_vol_rhs.qfunction_context); 39877841947SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "q", num_comp_q, CEED_EVAL_INTERP); 399a3ae0734SJed Brown CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "Grad_q", num_comp_q*dim, 40077841947SLeila Ghaffari CEED_EVAL_GRAD); 401a61c78d6SJeremy L Thompson CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "qdata", q_data_size_vol, 40277841947SLeila Ghaffari CEED_EVAL_NONE); 40377841947SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "x", num_comp_x, CEED_EVAL_INTERP); 40477841947SLeila Ghaffari CeedQFunctionAddOutput(ceed_data->qf_rhs_vol, "v", num_comp_q, 40577841947SLeila Ghaffari CEED_EVAL_INTERP); 406a3ae0734SJed Brown CeedQFunctionAddOutput(ceed_data->qf_rhs_vol, "Grad_v", num_comp_q*dim, 40777841947SLeila Ghaffari CEED_EVAL_GRAD); 40877841947SLeila Ghaffari } 40977841947SLeila Ghaffari 41077841947SLeila Ghaffari // -- Create QFunction for IFunction 41191e5af17SJed Brown if (problem->apply_vol_ifunction.qfunction) { 41291e5af17SJed Brown CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_ifunction.qfunction, 41391e5af17SJed Brown problem->apply_vol_ifunction.qfunction_loc, &ceed_data->qf_ifunction_vol); 414841e4c73SJed Brown CeedQFunctionSetContext(ceed_data->qf_ifunction_vol, 415841e4c73SJed Brown problem->apply_vol_ifunction.qfunction_context); 416841e4c73SJed Brown CeedQFunctionContextDestroy(&problem->apply_vol_ifunction.qfunction_context); 41777841947SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "q", num_comp_q, 41877841947SLeila Ghaffari CEED_EVAL_INTERP); 419a3ae0734SJed Brown CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "Grad_q", num_comp_q*dim, 42077841947SLeila Ghaffari CEED_EVAL_GRAD); 421a61c78d6SJeremy L Thompson CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "q dot", num_comp_q, 42277841947SLeila Ghaffari CEED_EVAL_INTERP); 423a61c78d6SJeremy L Thompson CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "qdata", q_data_size_vol, 42477841947SLeila Ghaffari CEED_EVAL_NONE); 42577841947SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "x", num_comp_x, 42677841947SLeila Ghaffari CEED_EVAL_INTERP); 42777841947SLeila Ghaffari CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "v", num_comp_q, 42877841947SLeila Ghaffari CEED_EVAL_INTERP); 429a3ae0734SJed Brown CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "Grad_v", num_comp_q*dim, 43077841947SLeila Ghaffari CEED_EVAL_GRAD); 431a3ae0734SJed Brown CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "jac_data", 432a3ae0734SJed Brown jac_data_size_vol, CEED_EVAL_NONE); 43377841947SLeila Ghaffari } 43477841947SLeila Ghaffari 435e334ad8fSJed Brown CeedQFunction qf_ijacobian_vol = NULL; 436e334ad8fSJed Brown if (problem->apply_vol_ijacobian.qfunction) { 437e334ad8fSJed Brown CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_ijacobian.qfunction, 438e334ad8fSJed Brown problem->apply_vol_ijacobian.qfunction_loc, &qf_ijacobian_vol); 439e334ad8fSJed Brown CeedQFunctionSetContext(qf_ijacobian_vol, 440e334ad8fSJed Brown problem->apply_vol_ijacobian.qfunction_context); 441e334ad8fSJed Brown CeedQFunctionContextDestroy(&problem->apply_vol_ijacobian.qfunction_context); 442e334ad8fSJed Brown CeedQFunctionAddInput(qf_ijacobian_vol, "dq", num_comp_q, 443e334ad8fSJed Brown CEED_EVAL_INTERP); 444e334ad8fSJed Brown CeedQFunctionAddInput(qf_ijacobian_vol, "Grad_dq", num_comp_q*dim, 445e334ad8fSJed Brown CEED_EVAL_GRAD); 446e334ad8fSJed Brown CeedQFunctionAddInput(qf_ijacobian_vol, "qdata", q_data_size_vol, 447e334ad8fSJed Brown CEED_EVAL_NONE); 448e334ad8fSJed Brown CeedQFunctionAddInput(qf_ijacobian_vol, "x", num_comp_x, 449e334ad8fSJed Brown CEED_EVAL_INTERP); 450e334ad8fSJed Brown CeedQFunctionAddInput(qf_ijacobian_vol, "jac_data", 451e334ad8fSJed Brown jac_data_size_vol, CEED_EVAL_NONE); 452e334ad8fSJed Brown CeedQFunctionAddOutput(qf_ijacobian_vol, "v", num_comp_q, 453e334ad8fSJed Brown CEED_EVAL_INTERP); 454e334ad8fSJed Brown CeedQFunctionAddOutput(qf_ijacobian_vol, "Grad_v", num_comp_q*dim, 455e334ad8fSJed Brown CEED_EVAL_GRAD); 456e334ad8fSJed Brown } 457e334ad8fSJed Brown 45877841947SLeila Ghaffari // --------------------------------------------------------------------------- 45977841947SLeila Ghaffari // Element coordinates 46077841947SLeila Ghaffari // --------------------------------------------------------------------------- 46177841947SLeila Ghaffari // -- Create CEED vector 46277841947SLeila Ghaffari CeedElemRestrictionCreateVector(ceed_data->elem_restr_x, &ceed_data->x_coord, 46377841947SLeila Ghaffari NULL); 46477841947SLeila Ghaffari 46577841947SLeila Ghaffari // -- Copy PETSc vector in CEED vector 46677841947SLeila Ghaffari Vec X_loc; 46777841947SLeila Ghaffari const PetscScalar *X_loc_array; 468*3796c488SJed Brown { 469*3796c488SJed Brown DM cdm; 470*3796c488SJed Brown ierr = DMGetCellCoordinateDM(dm, &cdm); CHKERRQ(ierr); 471*3796c488SJed Brown if (cdm) {ierr = DMGetCellCoordinatesLocal(dm, &X_loc); CHKERRQ(ierr);} 472*3796c488SJed Brown else {ierr = DMGetCoordinatesLocal(dm, &X_loc); CHKERRQ(ierr);} 473*3796c488SJed Brown } 4741864f1c2SLeila Ghaffari ierr = VecScale(X_loc, problem->dm_scale); CHKERRQ(ierr); 47577841947SLeila Ghaffari ierr = VecGetArrayRead(X_loc, &X_loc_array); CHKERRQ(ierr); 47677841947SLeila Ghaffari CeedVectorSetArray(ceed_data->x_coord, CEED_MEM_HOST, CEED_COPY_VALUES, 47777841947SLeila Ghaffari (PetscScalar *)X_loc_array); 47877841947SLeila Ghaffari ierr = VecRestoreArrayRead(X_loc, &X_loc_array); CHKERRQ(ierr); 47977841947SLeila Ghaffari 48077841947SLeila Ghaffari // ----------------------------------------------------------------------------- 48177841947SLeila Ghaffari // CEED vectors 48277841947SLeila Ghaffari // ----------------------------------------------------------------------------- 48377841947SLeila Ghaffari // -- Create CEED vector for geometric data 48477841947SLeila Ghaffari CeedInt num_qpts_vol; 48577841947SLeila Ghaffari PetscInt loc_num_elem_vol; 48677841947SLeila Ghaffari CeedBasisGetNumQuadraturePoints(ceed_data->basis_q, &num_qpts_vol); 48777841947SLeila Ghaffari CeedElemRestrictionGetNumElements(ceed_data->elem_restr_q, &loc_num_elem_vol); 48877841947SLeila Ghaffari CeedVectorCreate(ceed, q_data_size_vol*loc_num_elem_vol*num_qpts_vol, 48977841947SLeila Ghaffari &ceed_data->q_data); 49077841947SLeila Ghaffari 491a3ae0734SJed Brown CeedElemRestrictionCreateVector(elem_restr_jd_i, &jac_data, NULL); 49277841947SLeila Ghaffari // ----------------------------------------------------------------------------- 49377841947SLeila Ghaffari // CEED Operators 49477841947SLeila Ghaffari // ----------------------------------------------------------------------------- 49577841947SLeila Ghaffari // -- Create CEED operator for quadrature data 49677841947SLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_setup_vol, NULL, NULL, 49777841947SLeila Ghaffari &ceed_data->op_setup_vol); 49877841947SLeila Ghaffari CeedOperatorSetField(ceed_data->op_setup_vol, "dx", ceed_data->elem_restr_x, 49977841947SLeila Ghaffari ceed_data->basis_x, CEED_VECTOR_ACTIVE); 50077841947SLeila Ghaffari CeedOperatorSetField(ceed_data->op_setup_vol, "weight", 501e6225c47SLeila Ghaffari CEED_ELEMRESTRICTION_NONE, ceed_data->basis_x, CEED_VECTOR_NONE); 502a61c78d6SJeremy L Thompson CeedOperatorSetField(ceed_data->op_setup_vol, "qdata", 503e6225c47SLeila Ghaffari ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); 50477841947SLeila Ghaffari 50577841947SLeila Ghaffari // -- Create CEED operator for ICs 50677841947SLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_ics, NULL, NULL, &ceed_data->op_ics); 50777841947SLeila Ghaffari CeedOperatorSetField(ceed_data->op_ics, "x", ceed_data->elem_restr_x, 50877841947SLeila Ghaffari ceed_data->basis_xc, CEED_VECTOR_ACTIVE); 50977841947SLeila Ghaffari CeedOperatorSetField(ceed_data->op_ics, "q0", ceed_data->elem_restr_q, 51077841947SLeila Ghaffari CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); 511841e4c73SJed Brown CeedOperatorContextGetFieldLabel(ceed_data->op_ics, "evaluation time", 512841e4c73SJed Brown &user->phys->ics_time_label); 51377841947SLeila Ghaffari 51477841947SLeila Ghaffari // Create CEED operator for RHS 51577841947SLeila Ghaffari if (ceed_data->qf_rhs_vol) { 51677841947SLeila Ghaffari CeedOperator op; 51777841947SLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_rhs_vol, NULL, NULL, &op); 51877841947SLeila Ghaffari CeedOperatorSetField(op, "q", ceed_data->elem_restr_q, ceed_data->basis_q, 51977841947SLeila Ghaffari CEED_VECTOR_ACTIVE); 520a3ae0734SJed Brown CeedOperatorSetField(op, "Grad_q", ceed_data->elem_restr_q, ceed_data->basis_q, 52177841947SLeila Ghaffari CEED_VECTOR_ACTIVE); 522a61c78d6SJeremy L Thompson CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i, 523e6225c47SLeila Ghaffari CEED_BASIS_COLLOCATED, ceed_data->q_data); 52477841947SLeila Ghaffari CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x, 52577841947SLeila Ghaffari ceed_data->x_coord); 52677841947SLeila Ghaffari CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q, 52777841947SLeila Ghaffari CEED_VECTOR_ACTIVE); 528a3ae0734SJed Brown CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q, 52977841947SLeila Ghaffari CEED_VECTOR_ACTIVE); 53077841947SLeila Ghaffari user->op_rhs_vol = op; 53177841947SLeila Ghaffari } 53277841947SLeila Ghaffari 53377841947SLeila Ghaffari // -- CEED operator for IFunction 53477841947SLeila Ghaffari if (ceed_data->qf_ifunction_vol) { 53577841947SLeila Ghaffari CeedOperator op; 53677841947SLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_ifunction_vol, NULL, NULL, &op); 53777841947SLeila Ghaffari CeedOperatorSetField(op, "q", ceed_data->elem_restr_q, ceed_data->basis_q, 53877841947SLeila Ghaffari CEED_VECTOR_ACTIVE); 539a3ae0734SJed Brown CeedOperatorSetField(op, "Grad_q", ceed_data->elem_restr_q, ceed_data->basis_q, 54077841947SLeila Ghaffari CEED_VECTOR_ACTIVE); 541a61c78d6SJeremy L Thompson CeedOperatorSetField(op, "q dot", ceed_data->elem_restr_q, ceed_data->basis_q, 54277841947SLeila Ghaffari user->q_dot_ceed); 543a61c78d6SJeremy L Thompson CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i, 544e6225c47SLeila Ghaffari CEED_BASIS_COLLOCATED, ceed_data->q_data); 54577841947SLeila Ghaffari CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x, 54677841947SLeila Ghaffari ceed_data->x_coord); 54777841947SLeila Ghaffari CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q, 54877841947SLeila Ghaffari CEED_VECTOR_ACTIVE); 549a3ae0734SJed Brown CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q, 55077841947SLeila Ghaffari CEED_VECTOR_ACTIVE); 551a3ae0734SJed Brown CeedOperatorSetField(op, "jac_data", elem_restr_jd_i, 552a3ae0734SJed Brown CEED_BASIS_COLLOCATED, jac_data); 553a3ae0734SJed Brown 55477841947SLeila Ghaffari user->op_ifunction_vol = op; 55577841947SLeila Ghaffari } 55677841947SLeila Ghaffari 557e334ad8fSJed Brown CeedOperator op_ijacobian_vol = NULL; 558e334ad8fSJed Brown if (qf_ijacobian_vol) { 559e334ad8fSJed Brown CeedOperator op; 560e334ad8fSJed Brown CeedOperatorCreate(ceed, qf_ijacobian_vol, NULL, NULL, &op); 561e334ad8fSJed Brown CeedOperatorSetField(op, "dq", ceed_data->elem_restr_q, ceed_data->basis_q, 562e334ad8fSJed Brown CEED_VECTOR_ACTIVE); 563e334ad8fSJed Brown CeedOperatorSetField(op, "Grad_dq", ceed_data->elem_restr_q, ceed_data->basis_q, 564e334ad8fSJed Brown CEED_VECTOR_ACTIVE); 565e334ad8fSJed Brown CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i, 566e334ad8fSJed Brown CEED_BASIS_COLLOCATED, ceed_data->q_data); 567e334ad8fSJed Brown CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x, 568e334ad8fSJed Brown ceed_data->x_coord); 569e334ad8fSJed Brown CeedOperatorSetField(op, "jac_data", elem_restr_jd_i, 570e334ad8fSJed Brown CEED_BASIS_COLLOCATED, jac_data); 571e334ad8fSJed Brown CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q, 572e334ad8fSJed Brown CEED_VECTOR_ACTIVE); 573e334ad8fSJed Brown CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q, 574e334ad8fSJed Brown CEED_VECTOR_ACTIVE); 575e334ad8fSJed Brown op_ijacobian_vol = op; 576e334ad8fSJed Brown CeedQFunctionDestroy(&qf_ijacobian_vol); 577e334ad8fSJed Brown } 578e334ad8fSJed Brown 57977841947SLeila Ghaffari // ***************************************************************************** 58077841947SLeila Ghaffari // Set up CEED objects for the exterior domain (surface) 58177841947SLeila Ghaffari // ***************************************************************************** 58277841947SLeila Ghaffari CeedInt height = 1, 58377841947SLeila Ghaffari dim_sur = dim - height, 58477841947SLeila Ghaffari P_sur = app_ctx->degree + 1, 58577841947SLeila Ghaffari Q_sur = P_sur + app_ctx->q_extra; 586e334ad8fSJed Brown const CeedInt q_data_size_sur = problem->q_data_size_sur, 587e334ad8fSJed Brown jac_data_size_sur = problem->jac_data_size_sur; 58877841947SLeila Ghaffari 58977841947SLeila Ghaffari // ----------------------------------------------------------------------------- 59077841947SLeila Ghaffari // CEED Bases 59177841947SLeila Ghaffari // ----------------------------------------------------------------------------- 59277841947SLeila Ghaffari CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_q, P_sur, Q_sur, 59377841947SLeila Ghaffari CEED_GAUSS, &ceed_data->basis_q_sur); 59477841947SLeila Ghaffari CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_x, 2, Q_sur, CEED_GAUSS, 59577841947SLeila Ghaffari &ceed_data->basis_x_sur); 596959b8288SJames Wright CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_x, 2, P_sur, 597959b8288SJames Wright CEED_GAUSS_LOBATTO, &ceed_data->basis_xc_sur); 59877841947SLeila Ghaffari 59977841947SLeila Ghaffari // ----------------------------------------------------------------------------- 60077841947SLeila Ghaffari // CEED QFunctions 60177841947SLeila Ghaffari // ----------------------------------------------------------------------------- 60277841947SLeila Ghaffari // -- Create QFunction for quadrature data 60391e5af17SJed Brown CeedQFunctionCreateInterior(ceed, 1, problem->setup_sur.qfunction, 60491e5af17SJed Brown problem->setup_sur.qfunction_loc, 60577841947SLeila Ghaffari &ceed_data->qf_setup_sur); 606841e4c73SJed Brown if (problem->setup_sur.qfunction_context) { 607841e4c73SJed Brown CeedQFunctionSetContext(ceed_data->qf_setup_sur, 608841e4c73SJed Brown problem->setup_sur.qfunction_context); 609841e4c73SJed Brown CeedQFunctionContextDestroy(&problem->setup_sur.qfunction_context); 610841e4c73SJed Brown } 61177841947SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_setup_sur, "dx", num_comp_x*dim_sur, 61277841947SLeila Ghaffari CEED_EVAL_GRAD); 61377841947SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_setup_sur, "weight", 1, CEED_EVAL_WEIGHT); 614a61c78d6SJeremy L Thompson CeedQFunctionAddOutput(ceed_data->qf_setup_sur, "surface qdata", 6152fe7aee7SLeila Ghaffari q_data_size_sur, CEED_EVAL_NONE); 61677841947SLeila Ghaffari 6172fe7aee7SLeila Ghaffari // -- Creat QFunction for inflow boundaries 61891e5af17SJed Brown if (problem->apply_inflow.qfunction) { 61991e5af17SJed Brown CeedQFunctionCreateInterior(ceed, 1, problem->apply_inflow.qfunction, 62091e5af17SJed Brown problem->apply_inflow.qfunction_loc, &ceed_data->qf_apply_inflow); 621841e4c73SJed Brown CeedQFunctionSetContext(ceed_data->qf_apply_inflow, 622841e4c73SJed Brown problem->apply_inflow.qfunction_context); 623841e4c73SJed Brown CeedQFunctionContextDestroy(&problem->apply_inflow.qfunction_context); 6242fe7aee7SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_apply_inflow, "q", num_comp_q, 62577841947SLeila Ghaffari CEED_EVAL_INTERP); 626e8b03feeSJames Wright CeedQFunctionAddInput(ceed_data->qf_apply_inflow, "Grad_q", num_comp_q*(dim-1), 627e8b03feeSJames Wright CEED_EVAL_GRAD); 6282fe7aee7SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_apply_inflow, "surface qdata", 6292fe7aee7SLeila Ghaffari q_data_size_sur, CEED_EVAL_NONE); 6302fe7aee7SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_apply_inflow, "x", num_comp_x, 63177841947SLeila Ghaffari CEED_EVAL_INTERP); 6322fe7aee7SLeila Ghaffari CeedQFunctionAddOutput(ceed_data->qf_apply_inflow, "v", num_comp_q, 6332fe7aee7SLeila Ghaffari CEED_EVAL_INTERP); 634b55ac660SJames Wright if (jac_data_size_sur) 635b55ac660SJames Wright CeedQFunctionAddOutput(ceed_data->qf_apply_inflow, "surface jacobian data", 636b55ac660SJames Wright jac_data_size_sur, 637b55ac660SJames Wright CEED_EVAL_NONE); 6382fe7aee7SLeila Ghaffari } 639e334ad8fSJed Brown if (problem->apply_inflow_jacobian.qfunction) { 640e334ad8fSJed Brown CeedQFunctionCreateInterior(ceed, 1, problem->apply_inflow_jacobian.qfunction, 641e334ad8fSJed Brown problem->apply_inflow_jacobian.qfunction_loc, 642e334ad8fSJed Brown &ceed_data->qf_apply_inflow_jacobian); 643e334ad8fSJed Brown CeedQFunctionSetContext(ceed_data->qf_apply_inflow_jacobian, 644e334ad8fSJed Brown problem->apply_inflow_jacobian.qfunction_context); 645e334ad8fSJed Brown CeedQFunctionContextDestroy(&problem->apply_inflow_jacobian.qfunction_context); 646e334ad8fSJed Brown CeedQFunctionAddInput(ceed_data->qf_apply_inflow_jacobian, "dq", num_comp_q, 647e334ad8fSJed Brown CEED_EVAL_INTERP); 648b55ac660SJames Wright CeedQFunctionAddInput(ceed_data->qf_apply_inflow_jacobian, "Grad_dq", 649b55ac660SJames Wright num_comp_q*dim_sur, CEED_EVAL_GRAD); 650e334ad8fSJed Brown CeedQFunctionAddInput(ceed_data->qf_apply_inflow_jacobian, "surface qdata", 651e334ad8fSJed Brown q_data_size_sur, CEED_EVAL_NONE); 652e334ad8fSJed Brown CeedQFunctionAddInput(ceed_data->qf_apply_inflow_jacobian, "x", num_comp_x, 653e334ad8fSJed Brown CEED_EVAL_INTERP); 654b55ac660SJames Wright CeedQFunctionAddInput(ceed_data->qf_apply_inflow_jacobian, 655b55ac660SJames Wright "surface jacobian data", 656b55ac660SJames Wright jac_data_size_sur, CEED_EVAL_NONE); 657e334ad8fSJed Brown CeedQFunctionAddOutput(ceed_data->qf_apply_inflow_jacobian, "v", num_comp_q, 658e334ad8fSJed Brown CEED_EVAL_INTERP); 659e334ad8fSJed Brown } 6602fe7aee7SLeila Ghaffari 6612fe7aee7SLeila Ghaffari // -- Creat QFunction for outflow boundaries 66291e5af17SJed Brown if (problem->apply_outflow.qfunction) { 66391e5af17SJed Brown CeedQFunctionCreateInterior(ceed, 1, problem->apply_outflow.qfunction, 66491e5af17SJed Brown problem->apply_outflow.qfunction_loc, &ceed_data->qf_apply_outflow); 665841e4c73SJed Brown CeedQFunctionSetContext(ceed_data->qf_apply_outflow, 666841e4c73SJed Brown problem->apply_outflow.qfunction_context); 667841e4c73SJed Brown CeedQFunctionContextDestroy(&problem->apply_outflow.qfunction_context); 6682fe7aee7SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_apply_outflow, "q", num_comp_q, 6692fe7aee7SLeila Ghaffari CEED_EVAL_INTERP); 670e8b03feeSJames Wright CeedQFunctionAddInput(ceed_data->qf_apply_outflow, "Grad_q", num_comp_q*(dim-1), 671e8b03feeSJames Wright CEED_EVAL_GRAD); 6722fe7aee7SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_apply_outflow, "surface qdata", 6732fe7aee7SLeila Ghaffari q_data_size_sur, CEED_EVAL_NONE); 6742fe7aee7SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_apply_outflow, "x", num_comp_x, 6752fe7aee7SLeila Ghaffari CEED_EVAL_INTERP); 6762fe7aee7SLeila Ghaffari CeedQFunctionAddOutput(ceed_data->qf_apply_outflow, "v", num_comp_q, 67777841947SLeila Ghaffari CEED_EVAL_INTERP); 67839c69132SJed Brown if (jac_data_size_sur) 679e334ad8fSJed Brown CeedQFunctionAddOutput(ceed_data->qf_apply_outflow, "surface jacobian data", 680e334ad8fSJed Brown jac_data_size_sur, 681e334ad8fSJed Brown CEED_EVAL_NONE); 682e334ad8fSJed Brown } 683e334ad8fSJed Brown if (problem->apply_outflow_jacobian.qfunction) { 684e334ad8fSJed Brown CeedQFunctionCreateInterior(ceed, 1, problem->apply_outflow_jacobian.qfunction, 685e334ad8fSJed Brown problem->apply_outflow_jacobian.qfunction_loc, 686e334ad8fSJed Brown &ceed_data->qf_apply_outflow_jacobian); 687e334ad8fSJed Brown CeedQFunctionSetContext(ceed_data->qf_apply_outflow_jacobian, 688e334ad8fSJed Brown problem->apply_outflow_jacobian.qfunction_context); 689e334ad8fSJed Brown CeedQFunctionContextDestroy(&problem->apply_outflow_jacobian.qfunction_context); 690e334ad8fSJed Brown CeedQFunctionAddInput(ceed_data->qf_apply_outflow_jacobian, "dq", num_comp_q, 691e334ad8fSJed Brown CEED_EVAL_INTERP); 692b55ac660SJames Wright CeedQFunctionAddInput(ceed_data->qf_apply_outflow_jacobian, "Grad_dq", 693b55ac660SJames Wright num_comp_q*dim_sur, CEED_EVAL_GRAD); 694e334ad8fSJed Brown CeedQFunctionAddInput(ceed_data->qf_apply_outflow_jacobian, "surface qdata", 695e334ad8fSJed Brown q_data_size_sur, CEED_EVAL_NONE); 6960ec2498eSJames Wright CeedQFunctionAddInput(ceed_data->qf_apply_outflow_jacobian, "x", num_comp_x, 6970ec2498eSJames Wright CEED_EVAL_INTERP); 698e334ad8fSJed Brown CeedQFunctionAddInput(ceed_data->qf_apply_outflow_jacobian, 699e334ad8fSJed Brown "surface jacobian data", 700e334ad8fSJed Brown jac_data_size_sur, CEED_EVAL_NONE); 701e334ad8fSJed Brown CeedQFunctionAddOutput(ceed_data->qf_apply_outflow_jacobian, "v", num_comp_q, 702e334ad8fSJed Brown CEED_EVAL_INTERP); 70377841947SLeila Ghaffari } 70477841947SLeila Ghaffari 70577841947SLeila Ghaffari // ***************************************************************************** 70677841947SLeila Ghaffari // CEED Operator Apply 70777841947SLeila Ghaffari // ***************************************************************************** 70877841947SLeila Ghaffari // -- Apply CEED Operator for the geometric data 70977841947SLeila Ghaffari CeedOperatorApply(ceed_data->op_setup_vol, ceed_data->x_coord, 71077841947SLeila Ghaffari ceed_data->q_data, CEED_REQUEST_IMMEDIATE); 71177841947SLeila Ghaffari 71277841947SLeila Ghaffari // -- Create and apply CEED Composite Operator for the entire domain 71377841947SLeila Ghaffari if (!user->phys->implicit) { // RHS 71477841947SLeila Ghaffari ierr = CreateOperatorForDomain(ceed, dm, bc, ceed_data, user->phys, 715e334ad8fSJed Brown user->op_rhs_vol, NULL, height, P_sur, Q_sur, 716e334ad8fSJed Brown q_data_size_sur, 0, 717e334ad8fSJed Brown &user->op_rhs, NULL); CHKERRQ(ierr); 71877841947SLeila Ghaffari } else { // IFunction 71977841947SLeila Ghaffari ierr = CreateOperatorForDomain(ceed, dm, bc, ceed_data, user->phys, 720e334ad8fSJed Brown user->op_ifunction_vol, op_ijacobian_vol, 721e334ad8fSJed Brown height, P_sur, Q_sur, 722e334ad8fSJed Brown q_data_size_sur, jac_data_size_sur, 723e334ad8fSJed Brown &user->op_ifunction, 724e334ad8fSJed Brown op_ijacobian_vol ? &user->op_ijacobian : NULL); CHKERRQ(ierr); 725e334ad8fSJed Brown if (user->op_ijacobian) { 726e334ad8fSJed Brown CeedOperatorContextGetFieldLabel(user->op_ijacobian, "ijacobian time shift", 727e334ad8fSJed Brown &user->phys->ijacobian_time_shift_label); 728e334ad8fSJed Brown } 729dada6cc0SJames Wright if (problem->use_dirichlet_ceed) { 730dada6cc0SJames Wright PetscCall(SetupStrongBC_Ceed(ceed, ceed_data, dm, user, app_ctx, problem, bc, 731dada6cc0SJames Wright Q_sur, q_data_size_sur)); 732dada6cc0SJames Wright } 733e334ad8fSJed Brown 73477841947SLeila Ghaffari } 735a3ae0734SJed Brown CeedElemRestrictionDestroy(&elem_restr_jd_i); 73622d320f5SLeila Ghaffari CeedOperatorDestroy(&op_ijacobian_vol); 737a3ae0734SJed Brown CeedVectorDestroy(&jac_data); 73877841947SLeila Ghaffari PetscFunctionReturn(0); 73977841947SLeila Ghaffari } 740