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) { 5977841947SLeila Ghaffari ierr = DMGetCoordinateDM(dm, &dm_coord); CHKERRQ(ierr); 6077841947SLeila Ghaffari ierr = DMPlexSetClosurePermutationTensor(dm_coord, PETSC_DETERMINE, NULL); 6177841947SLeila Ghaffari CHKERRQ(ierr); 627ed3e4cdSJeremy L Thompson ierr = CreateRestrictionFromPlex(ceed, dm_coord, height, domain_label, value, 637ed3e4cdSJeremy L Thompson elem_restr_x); 647ed3e4cdSJeremy L Thompson CHKERRQ(ierr); 652534dcc8SJed Brown } 662534dcc8SJed Brown if (elem_restr_qd_i) { 672534dcc8SJed Brown CeedElemRestrictionGetNumElements(elem_restr_tmp, &loc_num_elem); 6877841947SLeila Ghaffari CeedElemRestrictionCreateStrided(ceed, loc_num_elem, Q_dim, 6977841947SLeila Ghaffari q_data_size, q_data_size*loc_num_elem*Q_dim, 7077841947SLeila Ghaffari CEED_STRIDES_BACKEND, elem_restr_qd_i); 712534dcc8SJed Brown } 722534dcc8SJed Brown if (!elem_restr_q) CeedElemRestrictionDestroy(&elem_restr_tmp); 7377841947SLeila Ghaffari PetscFunctionReturn(0); 7477841947SLeila Ghaffari } 7577841947SLeila Ghaffari 7677841947SLeila Ghaffari // Utility function to create CEED Composite Operator for the entire domain 7777841947SLeila Ghaffari PetscErrorCode CreateOperatorForDomain(Ceed ceed, DM dm, SimpleBC bc, 7877841947SLeila Ghaffari CeedData ceed_data, Physics phys, 79e334ad8fSJed Brown CeedOperator op_apply_vol, 80e334ad8fSJed Brown CeedOperator op_apply_ijacobian_vol, 81e334ad8fSJed Brown CeedInt height, 82e334ad8fSJed Brown CeedInt P_sur, CeedInt Q_sur, 83e334ad8fSJed Brown CeedInt q_data_size_sur, CeedInt jac_data_size_sur, 84e334ad8fSJed Brown CeedOperator *op_apply, CeedOperator *op_apply_ijacobian) { 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); 91e334ad8fSJed Brown if (op_apply_ijacobian) 92e334ad8fSJed Brown CeedCompositeOperatorCreate(ceed, op_apply_ijacobian); 9377841947SLeila Ghaffari 9477841947SLeila Ghaffari // --Apply Sub-Operator for the volume 9577841947SLeila Ghaffari CeedCompositeOperatorAddSub(*op_apply, op_apply_vol); 96e334ad8fSJed Brown if (op_apply_ijacobian) 97e334ad8fSJed Brown CeedCompositeOperatorAddSub(*op_apply_ijacobian, op_apply_ijacobian_vol); 9877841947SLeila Ghaffari 9977841947SLeila Ghaffari // -- Create Sub-Operator for in/outflow BCs 10088626eedSJames Wright if (phys->has_neumann || 1) { 10177841947SLeila Ghaffari // --- Setup 10277841947SLeila Ghaffari ierr = DMGetLabel(dm, "Face Sets", &domain_label); CHKERRQ(ierr); 10377841947SLeila Ghaffari 10477841947SLeila Ghaffari // --- Get number of quadrature points for the boundaries 10577841947SLeila Ghaffari CeedInt num_qpts_sur; 10677841947SLeila Ghaffari CeedBasisGetNumQuadraturePoints(ceed_data->basis_q_sur, &num_qpts_sur); 10777841947SLeila Ghaffari 1082fe7aee7SLeila Ghaffari // --- Create Sub-Operator for inflow boundaries 1092fe7aee7SLeila Ghaffari for (CeedInt i=0; i < bc->num_inflow; i++) { 110b55ac660SJames Wright CeedVector q_data_sur, jac_data_sur; 111e334ad8fSJed Brown CeedOperator op_setup_sur, op_apply_inflow, 112e334ad8fSJed Brown op_apply_inflow_jacobian = NULL; 113b55ac660SJames Wright CeedElemRestriction elem_restr_x_sur, elem_restr_q_sur, elem_restr_qd_i_sur, 114b55ac660SJames Wright elem_restr_jd_i_sur; 11577841947SLeila Ghaffari 11677841947SLeila Ghaffari // ---- CEED Restriction 1172fe7aee7SLeila Ghaffari ierr = GetRestrictionForDomain(ceed, dm, height, domain_label, bc->inflows[i], 1182fe7aee7SLeila Ghaffari Q_sur, q_data_size_sur, &elem_restr_q_sur, &elem_restr_x_sur, 1192fe7aee7SLeila Ghaffari &elem_restr_qd_i_sur); 12077841947SLeila Ghaffari CHKERRQ(ierr); 121b55ac660SJames Wright if (jac_data_size_sur > 0) { 122b55ac660SJames Wright // State-dependent data will be passed from residual to Jacobian. This will be collocated. 123b55ac660SJames Wright ierr = GetRestrictionForDomain(ceed, dm, height, domain_label, bc->inflows[i], 124b55ac660SJames Wright Q_sur, jac_data_size_sur, NULL, NULL, 125b55ac660SJames Wright &elem_restr_jd_i_sur); 126b55ac660SJames Wright CHKERRQ(ierr); 127b55ac660SJames Wright CeedElemRestrictionCreateVector(elem_restr_jd_i_sur, &jac_data_sur, NULL); 128b55ac660SJames Wright } else { 129b55ac660SJames Wright elem_restr_jd_i_sur = NULL; 130b55ac660SJames Wright jac_data_sur = NULL; 131b55ac660SJames Wright } 13277841947SLeila Ghaffari 13377841947SLeila Ghaffari // ---- CEED Vector 13477841947SLeila Ghaffari PetscInt loc_num_elem_sur; 13577841947SLeila Ghaffari CeedElemRestrictionGetNumElements(elem_restr_q_sur, &loc_num_elem_sur); 13677841947SLeila Ghaffari CeedVectorCreate(ceed, q_data_size_sur*loc_num_elem_sur*num_qpts_sur, 13777841947SLeila Ghaffari &q_data_sur); 13877841947SLeila Ghaffari 13977841947SLeila Ghaffari // ---- CEED Operator 14077841947SLeila Ghaffari // ----- CEED Operator for Setup (geometric factors) 14177841947SLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_setup_sur, NULL, NULL, &op_setup_sur); 14277841947SLeila Ghaffari CeedOperatorSetField(op_setup_sur, "dx", elem_restr_x_sur, 143e6225c47SLeila Ghaffari ceed_data->basis_x_sur, CEED_VECTOR_ACTIVE); 14477841947SLeila Ghaffari CeedOperatorSetField(op_setup_sur, "weight", CEED_ELEMRESTRICTION_NONE, 14577841947SLeila Ghaffari ceed_data->basis_x_sur, CEED_VECTOR_NONE); 146a61c78d6SJeremy L Thompson CeedOperatorSetField(op_setup_sur, "surface qdata", elem_restr_qd_i_sur, 14777841947SLeila Ghaffari CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); 14877841947SLeila Ghaffari 14977841947SLeila Ghaffari // ----- CEED Operator for Physics 1502fe7aee7SLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_apply_inflow, NULL, NULL, 1512fe7aee7SLeila Ghaffari &op_apply_inflow); 1522fe7aee7SLeila Ghaffari CeedOperatorSetField(op_apply_inflow, "q", elem_restr_q_sur, 15377841947SLeila Ghaffari ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 154e8b03feeSJames Wright CeedOperatorSetField(op_apply_inflow, "Grad_q", elem_restr_q_sur, 155e8b03feeSJames Wright ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 1562fe7aee7SLeila Ghaffari CeedOperatorSetField(op_apply_inflow, "surface qdata", elem_restr_qd_i_sur, 15777841947SLeila Ghaffari CEED_BASIS_COLLOCATED, q_data_sur); 1582fe7aee7SLeila Ghaffari CeedOperatorSetField(op_apply_inflow, "x", elem_restr_x_sur, 15977841947SLeila Ghaffari ceed_data->basis_x_sur, ceed_data->x_coord); 1602fe7aee7SLeila Ghaffari CeedOperatorSetField(op_apply_inflow, "v", elem_restr_q_sur, 16177841947SLeila Ghaffari ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 162b55ac660SJames Wright if (elem_restr_jd_i_sur) 163b55ac660SJames Wright CeedOperatorSetField(op_apply_inflow, "surface jacobian data", 164b55ac660SJames Wright elem_restr_jd_i_sur, 165b55ac660SJames Wright CEED_BASIS_COLLOCATED, jac_data_sur); 16677841947SLeila Ghaffari 167e334ad8fSJed Brown if (ceed_data->qf_apply_inflow_jacobian) { 168e334ad8fSJed Brown CeedOperatorCreate(ceed, ceed_data->qf_apply_inflow_jacobian, NULL, NULL, 169e334ad8fSJed Brown &op_apply_inflow_jacobian); 170e334ad8fSJed Brown CeedOperatorSetField(op_apply_inflow_jacobian, "dq", elem_restr_q_sur, 171e334ad8fSJed Brown ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 172b55ac660SJames Wright CeedOperatorSetField(op_apply_inflow_jacobian, "Grad_dq", elem_restr_q_sur, 173b55ac660SJames Wright ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 174e334ad8fSJed Brown CeedOperatorSetField(op_apply_inflow_jacobian, "surface qdata", 175e334ad8fSJed Brown elem_restr_qd_i_sur, 176e334ad8fSJed Brown CEED_BASIS_COLLOCATED, q_data_sur); 177e334ad8fSJed Brown CeedOperatorSetField(op_apply_inflow_jacobian, "x", elem_restr_x_sur, 178e334ad8fSJed Brown ceed_data->basis_x_sur, ceed_data->x_coord); 179b55ac660SJames Wright CeedOperatorSetField(op_apply_inflow_jacobian, "surface jacobian data", 180b55ac660SJames Wright elem_restr_jd_i_sur, 181b55ac660SJames Wright CEED_BASIS_COLLOCATED, jac_data_sur); 182e334ad8fSJed Brown CeedOperatorSetField(op_apply_inflow_jacobian, "v", elem_restr_q_sur, 183e334ad8fSJed Brown ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 184e334ad8fSJed Brown } 185e334ad8fSJed Brown 18677841947SLeila Ghaffari // ----- Apply CEED operator for Setup 18777841947SLeila Ghaffari CeedOperatorApply(op_setup_sur, ceed_data->x_coord, q_data_sur, 18877841947SLeila Ghaffari CEED_REQUEST_IMMEDIATE); 18977841947SLeila Ghaffari 1902fe7aee7SLeila Ghaffari // ----- Apply Sub-Operator for Physics 1912fe7aee7SLeila Ghaffari CeedCompositeOperatorAddSub(*op_apply, op_apply_inflow); 192e334ad8fSJed Brown if (op_apply_ijacobian) 193e334ad8fSJed Brown CeedCompositeOperatorAddSub(*op_apply_ijacobian, op_apply_inflow_jacobian); 19477841947SLeila Ghaffari 19577841947SLeila Ghaffari // ----- Cleanup 19677841947SLeila Ghaffari CeedVectorDestroy(&q_data_sur); 197b55ac660SJames Wright CeedVectorDestroy(&jac_data_sur); 19877841947SLeila Ghaffari CeedElemRestrictionDestroy(&elem_restr_q_sur); 19977841947SLeila Ghaffari CeedElemRestrictionDestroy(&elem_restr_x_sur); 20077841947SLeila Ghaffari CeedElemRestrictionDestroy(&elem_restr_qd_i_sur); 201b55ac660SJames Wright CeedElemRestrictionDestroy(&elem_restr_jd_i_sur); 20277841947SLeila Ghaffari CeedOperatorDestroy(&op_setup_sur); 2032fe7aee7SLeila Ghaffari CeedOperatorDestroy(&op_apply_inflow); 204e334ad8fSJed Brown CeedOperatorDestroy(&op_apply_inflow_jacobian); 20577841947SLeila Ghaffari } 20677841947SLeila Ghaffari 2072fe7aee7SLeila Ghaffari // --- Create Sub-Operator for outflow boundaries 2082fe7aee7SLeila Ghaffari for (CeedInt i=0; i < bc->num_outflow; i++) { 209e334ad8fSJed Brown CeedVector q_data_sur, jac_data_sur; 210e334ad8fSJed Brown CeedOperator op_setup_sur, op_apply_outflow, 211e334ad8fSJed Brown op_apply_outflow_jacobian = NULL; 212e334ad8fSJed Brown CeedElemRestriction elem_restr_x_sur, elem_restr_q_sur, elem_restr_qd_i_sur, 213e334ad8fSJed Brown elem_restr_jd_i_sur; 2142fe7aee7SLeila Ghaffari 2152fe7aee7SLeila Ghaffari // ---- CEED Restriction 2162fe7aee7SLeila Ghaffari ierr = GetRestrictionForDomain(ceed, dm, height, domain_label, bc->outflows[i], 2172fe7aee7SLeila Ghaffari Q_sur, q_data_size_sur, &elem_restr_q_sur, &elem_restr_x_sur, 2182fe7aee7SLeila Ghaffari &elem_restr_qd_i_sur); 2192fe7aee7SLeila Ghaffari CHKERRQ(ierr); 22039c69132SJed Brown if (jac_data_size_sur > 0) { 22139c69132SJed Brown // State-dependent data will be passed from residual to Jacobian. This will be collocated. 222e334ad8fSJed Brown ierr = GetRestrictionForDomain(ceed, dm, height, domain_label, bc->outflows[i], 223e334ad8fSJed Brown Q_sur, jac_data_size_sur, NULL, NULL, 224e334ad8fSJed Brown &elem_restr_jd_i_sur); 225e334ad8fSJed Brown CHKERRQ(ierr); 22639c69132SJed Brown CeedElemRestrictionCreateVector(elem_restr_jd_i_sur, &jac_data_sur, NULL); 22739c69132SJed Brown } else { 22839c69132SJed Brown elem_restr_jd_i_sur = NULL; 22939c69132SJed Brown jac_data_sur = NULL; 23039c69132SJed Brown } 2312fe7aee7SLeila Ghaffari 2322fe7aee7SLeila Ghaffari // ---- CEED Vector 2332fe7aee7SLeila Ghaffari PetscInt loc_num_elem_sur; 2342fe7aee7SLeila Ghaffari CeedElemRestrictionGetNumElements(elem_restr_q_sur, &loc_num_elem_sur); 2352fe7aee7SLeila Ghaffari CeedVectorCreate(ceed, q_data_size_sur*loc_num_elem_sur*num_qpts_sur, 2362fe7aee7SLeila Ghaffari &q_data_sur); 2372fe7aee7SLeila Ghaffari 2382fe7aee7SLeila Ghaffari // ---- CEED Operator 2392fe7aee7SLeila Ghaffari // ----- CEED Operator for Setup (geometric factors) 2402fe7aee7SLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_setup_sur, NULL, NULL, &op_setup_sur); 2412fe7aee7SLeila Ghaffari CeedOperatorSetField(op_setup_sur, "dx", elem_restr_x_sur, 2422fe7aee7SLeila Ghaffari ceed_data->basis_x_sur, CEED_VECTOR_ACTIVE); 2432fe7aee7SLeila Ghaffari CeedOperatorSetField(op_setup_sur, "weight", CEED_ELEMRESTRICTION_NONE, 2442fe7aee7SLeila Ghaffari ceed_data->basis_x_sur, CEED_VECTOR_NONE); 2452fe7aee7SLeila Ghaffari CeedOperatorSetField(op_setup_sur, "surface qdata", elem_restr_qd_i_sur, 2462fe7aee7SLeila Ghaffari CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); 2472fe7aee7SLeila Ghaffari 2482fe7aee7SLeila Ghaffari // ----- CEED Operator for Physics 2492fe7aee7SLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_apply_outflow, NULL, NULL, 2502fe7aee7SLeila Ghaffari &op_apply_outflow); 2512fe7aee7SLeila Ghaffari CeedOperatorSetField(op_apply_outflow, "q", elem_restr_q_sur, 2522fe7aee7SLeila Ghaffari ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 253e8b03feeSJames Wright CeedOperatorSetField(op_apply_outflow, "Grad_q", elem_restr_q_sur, 254e8b03feeSJames Wright ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 2552fe7aee7SLeila Ghaffari CeedOperatorSetField(op_apply_outflow, "surface qdata", elem_restr_qd_i_sur, 2562fe7aee7SLeila Ghaffari CEED_BASIS_COLLOCATED, q_data_sur); 2572fe7aee7SLeila Ghaffari CeedOperatorSetField(op_apply_outflow, "x", elem_restr_x_sur, 2582fe7aee7SLeila Ghaffari ceed_data->basis_x_sur, ceed_data->x_coord); 2592fe7aee7SLeila Ghaffari CeedOperatorSetField(op_apply_outflow, "v", elem_restr_q_sur, 2602fe7aee7SLeila Ghaffari ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 26139c69132SJed Brown if (elem_restr_jd_i_sur) 262e334ad8fSJed Brown CeedOperatorSetField(op_apply_outflow, "surface jacobian data", 263e334ad8fSJed Brown elem_restr_jd_i_sur, 264e334ad8fSJed Brown CEED_BASIS_COLLOCATED, jac_data_sur); 265e334ad8fSJed Brown 266e334ad8fSJed Brown if (ceed_data->qf_apply_outflow_jacobian) { 267e334ad8fSJed Brown CeedOperatorCreate(ceed, ceed_data->qf_apply_outflow_jacobian, NULL, NULL, 268e334ad8fSJed Brown &op_apply_outflow_jacobian); 269e334ad8fSJed Brown CeedOperatorSetField(op_apply_outflow_jacobian, "dq", elem_restr_q_sur, 270e334ad8fSJed Brown ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 2710ec2498eSJames Wright CeedOperatorSetField(op_apply_outflow_jacobian, "Grad_dq", elem_restr_q_sur, 2720ec2498eSJames Wright ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 273e334ad8fSJed Brown CeedOperatorSetField(op_apply_outflow_jacobian, "surface qdata", 274e334ad8fSJed Brown elem_restr_qd_i_sur, 275e334ad8fSJed Brown CEED_BASIS_COLLOCATED, q_data_sur); 2760ec2498eSJames Wright CeedOperatorSetField(op_apply_outflow_jacobian, "x", elem_restr_x_sur, 2770ec2498eSJames Wright ceed_data->basis_x_sur, ceed_data->x_coord); 278e334ad8fSJed Brown CeedOperatorSetField(op_apply_outflow_jacobian, "surface jacobian data", 279e334ad8fSJed Brown elem_restr_jd_i_sur, 280e334ad8fSJed Brown CEED_BASIS_COLLOCATED, jac_data_sur); 281e334ad8fSJed Brown CeedOperatorSetField(op_apply_outflow_jacobian, "v", elem_restr_q_sur, 282e334ad8fSJed Brown ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 283e334ad8fSJed Brown } 2842fe7aee7SLeila Ghaffari 2852fe7aee7SLeila Ghaffari // ----- Apply CEED operator for Setup 2862fe7aee7SLeila Ghaffari CeedOperatorApply(op_setup_sur, ceed_data->x_coord, q_data_sur, 2872fe7aee7SLeila Ghaffari CEED_REQUEST_IMMEDIATE); 2882fe7aee7SLeila Ghaffari 2892fe7aee7SLeila Ghaffari // ----- Apply Sub-Operator for Physics 2902fe7aee7SLeila Ghaffari CeedCompositeOperatorAddSub(*op_apply, op_apply_outflow); 291e334ad8fSJed Brown if (op_apply_ijacobian) 292e334ad8fSJed Brown CeedCompositeOperatorAddSub(*op_apply_ijacobian, op_apply_outflow_jacobian); 2932fe7aee7SLeila Ghaffari 2942fe7aee7SLeila Ghaffari // ----- Cleanup 2952fe7aee7SLeila Ghaffari CeedVectorDestroy(&q_data_sur); 296e334ad8fSJed Brown CeedVectorDestroy(&jac_data_sur); 2972fe7aee7SLeila Ghaffari CeedElemRestrictionDestroy(&elem_restr_q_sur); 2982fe7aee7SLeila Ghaffari CeedElemRestrictionDestroy(&elem_restr_x_sur); 2992fe7aee7SLeila Ghaffari CeedElemRestrictionDestroy(&elem_restr_qd_i_sur); 300e334ad8fSJed Brown CeedElemRestrictionDestroy(&elem_restr_jd_i_sur); 3012fe7aee7SLeila Ghaffari CeedOperatorDestroy(&op_setup_sur); 3022fe7aee7SLeila Ghaffari CeedOperatorDestroy(&op_apply_outflow); 303e334ad8fSJed Brown CeedOperatorDestroy(&op_apply_outflow_jacobian); 3042fe7aee7SLeila Ghaffari } 3052fe7aee7SLeila Ghaffari } 30611436a05SJames Wright 30711436a05SJames Wright // ----- Get Context Labels for Operator 30811436a05SJames Wright CeedOperatorContextGetFieldLabel(*op_apply, "solution time", 30911436a05SJames Wright &phys->solution_time_label); 31088626eedSJames Wright CeedOperatorContextGetFieldLabel(*op_apply, "timestep size", 31188626eedSJames Wright &phys->timestep_size_label); 31211436a05SJames Wright 31377841947SLeila Ghaffari PetscFunctionReturn(0); 31477841947SLeila Ghaffari } 31577841947SLeila Ghaffari 31677841947SLeila Ghaffari PetscErrorCode SetupLibceed(Ceed ceed, CeedData ceed_data, DM dm, User user, 317c95f9967SJed Brown AppCtx app_ctx, ProblemData *problem, SimpleBC bc) { 31877841947SLeila Ghaffari PetscErrorCode ierr; 31977841947SLeila Ghaffari PetscFunctionBeginUser; 32077841947SLeila Ghaffari 32177841947SLeila Ghaffari // ***************************************************************************** 32277841947SLeila Ghaffari // Set up CEED objects for the interior domain (volume) 32377841947SLeila Ghaffari // ***************************************************************************** 32477841947SLeila Ghaffari const PetscInt num_comp_q = 5; 32577841947SLeila Ghaffari const CeedInt dim = problem->dim, 32677841947SLeila Ghaffari num_comp_x = problem->dim, 32777841947SLeila Ghaffari q_data_size_vol = problem->q_data_size_vol, 328e334ad8fSJed Brown jac_data_size_vol = num_comp_q + 6 + 3, 32977841947SLeila Ghaffari P = app_ctx->degree + 1, 33077841947SLeila Ghaffari Q = P + app_ctx->q_extra; 331a3ae0734SJed Brown CeedElemRestriction elem_restr_jd_i; 332a3ae0734SJed Brown CeedVector jac_data; 33377841947SLeila Ghaffari 33477841947SLeila Ghaffari // ----------------------------------------------------------------------------- 33577841947SLeila Ghaffari // CEED Bases 33677841947SLeila Ghaffari // ----------------------------------------------------------------------------- 33777841947SLeila Ghaffari CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_q, P, Q, CEED_GAUSS, 33877841947SLeila Ghaffari &ceed_data->basis_q); 33977841947SLeila Ghaffari CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_x, 2, Q, CEED_GAUSS, 34077841947SLeila Ghaffari &ceed_data->basis_x); 34177841947SLeila Ghaffari CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_x, 2, P, 34277841947SLeila Ghaffari CEED_GAUSS_LOBATTO, &ceed_data->basis_xc); 34377841947SLeila Ghaffari 34477841947SLeila Ghaffari // ----------------------------------------------------------------------------- 34577841947SLeila Ghaffari // CEED Restrictions 34677841947SLeila Ghaffari // ----------------------------------------------------------------------------- 34777841947SLeila Ghaffari // -- Create restriction 3487ed3e4cdSJeremy L Thompson ierr = GetRestrictionForDomain(ceed, dm, 0, 0, 0, Q, q_data_size_vol, 3497ed3e4cdSJeremy L Thompson &ceed_data->elem_restr_q, &ceed_data->elem_restr_x, 35077841947SLeila Ghaffari &ceed_data->elem_restr_qd_i); CHKERRQ(ierr); 351a3ae0734SJed Brown 352a3ae0734SJed Brown ierr = GetRestrictionForDomain(ceed, dm, 0, 0, 0, Q, jac_data_size_vol, 353a3ae0734SJed Brown NULL, NULL, 354a3ae0734SJed Brown &elem_restr_jd_i); CHKERRQ(ierr); 35577841947SLeila Ghaffari // -- Create E vectors 35677841947SLeila Ghaffari CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->q_ceed, NULL); 35777841947SLeila Ghaffari CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->q_dot_ceed, 35877841947SLeila Ghaffari NULL); 35977841947SLeila Ghaffari CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->g_ceed, NULL); 36077841947SLeila Ghaffari 36177841947SLeila Ghaffari // ----------------------------------------------------------------------------- 36277841947SLeila Ghaffari // CEED QFunctions 36377841947SLeila Ghaffari // ----------------------------------------------------------------------------- 36477841947SLeila Ghaffari // -- Create QFunction for quadrature data 36591e5af17SJed Brown CeedQFunctionCreateInterior(ceed, 1, problem->setup_vol.qfunction, 36691e5af17SJed Brown problem->setup_vol.qfunction_loc, 36777841947SLeila Ghaffari &ceed_data->qf_setup_vol); 368841e4c73SJed Brown if (problem->setup_vol.qfunction_context) { 369841e4c73SJed Brown CeedQFunctionSetContext(ceed_data->qf_setup_vol, 370841e4c73SJed Brown problem->setup_vol.qfunction_context); 371841e4c73SJed Brown CeedQFunctionContextDestroy(&problem->setup_vol.qfunction_context); 372841e4c73SJed Brown } 37377841947SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_setup_vol, "dx", num_comp_x*dim, 37477841947SLeila Ghaffari CEED_EVAL_GRAD); 37577841947SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_setup_vol, "weight", 1, CEED_EVAL_WEIGHT); 376a61c78d6SJeremy L Thompson CeedQFunctionAddOutput(ceed_data->qf_setup_vol, "qdata", q_data_size_vol, 37777841947SLeila Ghaffari CEED_EVAL_NONE); 37877841947SLeila Ghaffari 37977841947SLeila Ghaffari // -- Create QFunction for ICs 38091e5af17SJed Brown CeedQFunctionCreateInterior(ceed, 1, problem->ics.qfunction, 38191e5af17SJed Brown problem->ics.qfunction_loc, 38277841947SLeila Ghaffari &ceed_data->qf_ics); 383841e4c73SJed Brown CeedQFunctionSetContext(ceed_data->qf_ics, problem->ics.qfunction_context); 384841e4c73SJed Brown CeedQFunctionContextDestroy(&problem->ics.qfunction_context); 38577841947SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_ics, "x", num_comp_x, CEED_EVAL_INTERP); 38677841947SLeila Ghaffari CeedQFunctionAddOutput(ceed_data->qf_ics, "q0", num_comp_q, CEED_EVAL_NONE); 38777841947SLeila Ghaffari 38877841947SLeila Ghaffari // -- Create QFunction for RHS 38991e5af17SJed Brown if (problem->apply_vol_rhs.qfunction) { 39091e5af17SJed Brown CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_rhs.qfunction, 39191e5af17SJed Brown problem->apply_vol_rhs.qfunction_loc, &ceed_data->qf_rhs_vol); 392841e4c73SJed Brown CeedQFunctionSetContext(ceed_data->qf_rhs_vol, 393841e4c73SJed Brown problem->apply_vol_rhs.qfunction_context); 394841e4c73SJed Brown CeedQFunctionContextDestroy(&problem->apply_vol_rhs.qfunction_context); 39577841947SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "q", num_comp_q, CEED_EVAL_INTERP); 396a3ae0734SJed Brown CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "Grad_q", num_comp_q*dim, 39777841947SLeila Ghaffari CEED_EVAL_GRAD); 398a61c78d6SJeremy L Thompson CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "qdata", q_data_size_vol, 39977841947SLeila Ghaffari CEED_EVAL_NONE); 40077841947SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "x", num_comp_x, CEED_EVAL_INTERP); 40177841947SLeila Ghaffari CeedQFunctionAddOutput(ceed_data->qf_rhs_vol, "v", num_comp_q, 40277841947SLeila Ghaffari CEED_EVAL_INTERP); 403a3ae0734SJed Brown CeedQFunctionAddOutput(ceed_data->qf_rhs_vol, "Grad_v", num_comp_q*dim, 40477841947SLeila Ghaffari CEED_EVAL_GRAD); 40577841947SLeila Ghaffari } 40677841947SLeila Ghaffari 40777841947SLeila Ghaffari // -- Create QFunction for IFunction 40891e5af17SJed Brown if (problem->apply_vol_ifunction.qfunction) { 40991e5af17SJed Brown CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_ifunction.qfunction, 41091e5af17SJed Brown problem->apply_vol_ifunction.qfunction_loc, &ceed_data->qf_ifunction_vol); 411841e4c73SJed Brown CeedQFunctionSetContext(ceed_data->qf_ifunction_vol, 412841e4c73SJed Brown problem->apply_vol_ifunction.qfunction_context); 413841e4c73SJed Brown CeedQFunctionContextDestroy(&problem->apply_vol_ifunction.qfunction_context); 41477841947SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "q", num_comp_q, 41577841947SLeila Ghaffari CEED_EVAL_INTERP); 416a3ae0734SJed Brown CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "Grad_q", num_comp_q*dim, 41777841947SLeila Ghaffari CEED_EVAL_GRAD); 418a61c78d6SJeremy L Thompson CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "q dot", num_comp_q, 41977841947SLeila Ghaffari CEED_EVAL_INTERP); 420a61c78d6SJeremy L Thompson CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "qdata", q_data_size_vol, 42177841947SLeila Ghaffari CEED_EVAL_NONE); 42277841947SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "x", num_comp_x, 42377841947SLeila Ghaffari CEED_EVAL_INTERP); 42477841947SLeila Ghaffari CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "v", num_comp_q, 42577841947SLeila Ghaffari CEED_EVAL_INTERP); 426a3ae0734SJed Brown CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "Grad_v", num_comp_q*dim, 42777841947SLeila Ghaffari CEED_EVAL_GRAD); 428a3ae0734SJed Brown CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "jac_data", 429a3ae0734SJed Brown jac_data_size_vol, CEED_EVAL_NONE); 43077841947SLeila Ghaffari } 43177841947SLeila Ghaffari 432e334ad8fSJed Brown CeedQFunction qf_ijacobian_vol = NULL; 433e334ad8fSJed Brown if (problem->apply_vol_ijacobian.qfunction) { 434e334ad8fSJed Brown CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_ijacobian.qfunction, 435e334ad8fSJed Brown problem->apply_vol_ijacobian.qfunction_loc, &qf_ijacobian_vol); 436e334ad8fSJed Brown CeedQFunctionSetContext(qf_ijacobian_vol, 437e334ad8fSJed Brown problem->apply_vol_ijacobian.qfunction_context); 438e334ad8fSJed Brown CeedQFunctionContextDestroy(&problem->apply_vol_ijacobian.qfunction_context); 439e334ad8fSJed Brown CeedQFunctionAddInput(qf_ijacobian_vol, "dq", num_comp_q, 440e334ad8fSJed Brown CEED_EVAL_INTERP); 441e334ad8fSJed Brown CeedQFunctionAddInput(qf_ijacobian_vol, "Grad_dq", num_comp_q*dim, 442e334ad8fSJed Brown CEED_EVAL_GRAD); 443e334ad8fSJed Brown CeedQFunctionAddInput(qf_ijacobian_vol, "qdata", q_data_size_vol, 444e334ad8fSJed Brown CEED_EVAL_NONE); 445e334ad8fSJed Brown CeedQFunctionAddInput(qf_ijacobian_vol, "x", num_comp_x, 446e334ad8fSJed Brown CEED_EVAL_INTERP); 447e334ad8fSJed Brown CeedQFunctionAddInput(qf_ijacobian_vol, "jac_data", 448e334ad8fSJed Brown jac_data_size_vol, CEED_EVAL_NONE); 449e334ad8fSJed Brown CeedQFunctionAddOutput(qf_ijacobian_vol, "v", num_comp_q, 450e334ad8fSJed Brown CEED_EVAL_INTERP); 451e334ad8fSJed Brown CeedQFunctionAddOutput(qf_ijacobian_vol, "Grad_v", num_comp_q*dim, 452e334ad8fSJed Brown CEED_EVAL_GRAD); 453e334ad8fSJed Brown } 454e334ad8fSJed Brown 45577841947SLeila Ghaffari // --------------------------------------------------------------------------- 45677841947SLeila Ghaffari // Element coordinates 45777841947SLeila Ghaffari // --------------------------------------------------------------------------- 45877841947SLeila Ghaffari // -- Create CEED vector 45977841947SLeila Ghaffari CeedElemRestrictionCreateVector(ceed_data->elem_restr_x, &ceed_data->x_coord, 46077841947SLeila Ghaffari NULL); 46177841947SLeila Ghaffari 46277841947SLeila Ghaffari // -- Copy PETSc vector in CEED vector 46377841947SLeila Ghaffari Vec X_loc; 46477841947SLeila Ghaffari const PetscScalar *X_loc_array; 46577841947SLeila Ghaffari ierr = DMGetCoordinatesLocal(dm, &X_loc); CHKERRQ(ierr); 4661864f1c2SLeila Ghaffari ierr = VecScale(X_loc, problem->dm_scale); CHKERRQ(ierr); 46777841947SLeila Ghaffari ierr = VecGetArrayRead(X_loc, &X_loc_array); CHKERRQ(ierr); 46877841947SLeila Ghaffari CeedVectorSetArray(ceed_data->x_coord, CEED_MEM_HOST, CEED_COPY_VALUES, 46977841947SLeila Ghaffari (PetscScalar *)X_loc_array); 47077841947SLeila Ghaffari ierr = VecRestoreArrayRead(X_loc, &X_loc_array); CHKERRQ(ierr); 47177841947SLeila Ghaffari 47277841947SLeila Ghaffari // ----------------------------------------------------------------------------- 47377841947SLeila Ghaffari // CEED vectors 47477841947SLeila Ghaffari // ----------------------------------------------------------------------------- 47577841947SLeila Ghaffari // -- Create CEED vector for geometric data 47677841947SLeila Ghaffari CeedInt num_qpts_vol; 47777841947SLeila Ghaffari PetscInt loc_num_elem_vol; 47877841947SLeila Ghaffari CeedBasisGetNumQuadraturePoints(ceed_data->basis_q, &num_qpts_vol); 47977841947SLeila Ghaffari CeedElemRestrictionGetNumElements(ceed_data->elem_restr_q, &loc_num_elem_vol); 48077841947SLeila Ghaffari CeedVectorCreate(ceed, q_data_size_vol*loc_num_elem_vol*num_qpts_vol, 48177841947SLeila Ghaffari &ceed_data->q_data); 48277841947SLeila Ghaffari 483a3ae0734SJed Brown CeedElemRestrictionCreateVector(elem_restr_jd_i, &jac_data, NULL); 48477841947SLeila Ghaffari // ----------------------------------------------------------------------------- 48577841947SLeila Ghaffari // CEED Operators 48677841947SLeila Ghaffari // ----------------------------------------------------------------------------- 48777841947SLeila Ghaffari // -- Create CEED operator for quadrature data 48877841947SLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_setup_vol, NULL, NULL, 48977841947SLeila Ghaffari &ceed_data->op_setup_vol); 49077841947SLeila Ghaffari CeedOperatorSetField(ceed_data->op_setup_vol, "dx", ceed_data->elem_restr_x, 49177841947SLeila Ghaffari ceed_data->basis_x, CEED_VECTOR_ACTIVE); 49277841947SLeila Ghaffari CeedOperatorSetField(ceed_data->op_setup_vol, "weight", 493e6225c47SLeila Ghaffari CEED_ELEMRESTRICTION_NONE, ceed_data->basis_x, CEED_VECTOR_NONE); 494a61c78d6SJeremy L Thompson CeedOperatorSetField(ceed_data->op_setup_vol, "qdata", 495e6225c47SLeila Ghaffari ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); 49677841947SLeila Ghaffari 49777841947SLeila Ghaffari // -- Create CEED operator for ICs 49877841947SLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_ics, NULL, NULL, &ceed_data->op_ics); 49977841947SLeila Ghaffari CeedOperatorSetField(ceed_data->op_ics, "x", ceed_data->elem_restr_x, 50077841947SLeila Ghaffari ceed_data->basis_xc, CEED_VECTOR_ACTIVE); 50177841947SLeila Ghaffari CeedOperatorSetField(ceed_data->op_ics, "q0", ceed_data->elem_restr_q, 50277841947SLeila Ghaffari CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); 503841e4c73SJed Brown CeedOperatorContextGetFieldLabel(ceed_data->op_ics, "evaluation time", 504841e4c73SJed Brown &user->phys->ics_time_label); 50577841947SLeila Ghaffari 50677841947SLeila Ghaffari // Create CEED operator for RHS 50777841947SLeila Ghaffari if (ceed_data->qf_rhs_vol) { 50877841947SLeila Ghaffari CeedOperator op; 50977841947SLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_rhs_vol, NULL, NULL, &op); 51077841947SLeila Ghaffari CeedOperatorSetField(op, "q", ceed_data->elem_restr_q, ceed_data->basis_q, 51177841947SLeila Ghaffari CEED_VECTOR_ACTIVE); 512a3ae0734SJed Brown CeedOperatorSetField(op, "Grad_q", ceed_data->elem_restr_q, ceed_data->basis_q, 51377841947SLeila Ghaffari CEED_VECTOR_ACTIVE); 514a61c78d6SJeremy L Thompson CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i, 515e6225c47SLeila Ghaffari CEED_BASIS_COLLOCATED, ceed_data->q_data); 51677841947SLeila Ghaffari CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x, 51777841947SLeila Ghaffari ceed_data->x_coord); 51877841947SLeila Ghaffari CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q, 51977841947SLeila Ghaffari CEED_VECTOR_ACTIVE); 520a3ae0734SJed Brown CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q, 52177841947SLeila Ghaffari CEED_VECTOR_ACTIVE); 52277841947SLeila Ghaffari user->op_rhs_vol = op; 52377841947SLeila Ghaffari } 52477841947SLeila Ghaffari 52577841947SLeila Ghaffari // -- CEED operator for IFunction 52677841947SLeila Ghaffari if (ceed_data->qf_ifunction_vol) { 52777841947SLeila Ghaffari CeedOperator op; 52877841947SLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_ifunction_vol, NULL, NULL, &op); 52977841947SLeila Ghaffari CeedOperatorSetField(op, "q", ceed_data->elem_restr_q, ceed_data->basis_q, 53077841947SLeila Ghaffari CEED_VECTOR_ACTIVE); 531a3ae0734SJed Brown CeedOperatorSetField(op, "Grad_q", ceed_data->elem_restr_q, ceed_data->basis_q, 53277841947SLeila Ghaffari CEED_VECTOR_ACTIVE); 533a61c78d6SJeremy L Thompson CeedOperatorSetField(op, "q dot", ceed_data->elem_restr_q, ceed_data->basis_q, 53477841947SLeila Ghaffari user->q_dot_ceed); 535a61c78d6SJeremy L Thompson CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i, 536e6225c47SLeila Ghaffari CEED_BASIS_COLLOCATED, ceed_data->q_data); 53777841947SLeila Ghaffari CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x, 53877841947SLeila Ghaffari ceed_data->x_coord); 53977841947SLeila Ghaffari CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q, 54077841947SLeila Ghaffari CEED_VECTOR_ACTIVE); 541a3ae0734SJed Brown CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q, 54277841947SLeila Ghaffari CEED_VECTOR_ACTIVE); 543a3ae0734SJed Brown CeedOperatorSetField(op, "jac_data", elem_restr_jd_i, 544a3ae0734SJed Brown CEED_BASIS_COLLOCATED, jac_data); 545a3ae0734SJed Brown 54677841947SLeila Ghaffari user->op_ifunction_vol = op; 54777841947SLeila Ghaffari } 54877841947SLeila Ghaffari 549e334ad8fSJed Brown CeedOperator op_ijacobian_vol = NULL; 550e334ad8fSJed Brown if (qf_ijacobian_vol) { 551e334ad8fSJed Brown CeedOperator op; 552e334ad8fSJed Brown CeedOperatorCreate(ceed, qf_ijacobian_vol, NULL, NULL, &op); 553e334ad8fSJed Brown CeedOperatorSetField(op, "dq", ceed_data->elem_restr_q, ceed_data->basis_q, 554e334ad8fSJed Brown CEED_VECTOR_ACTIVE); 555e334ad8fSJed Brown CeedOperatorSetField(op, "Grad_dq", ceed_data->elem_restr_q, ceed_data->basis_q, 556e334ad8fSJed Brown CEED_VECTOR_ACTIVE); 557e334ad8fSJed Brown CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i, 558e334ad8fSJed Brown CEED_BASIS_COLLOCATED, ceed_data->q_data); 559e334ad8fSJed Brown CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x, 560e334ad8fSJed Brown ceed_data->x_coord); 561e334ad8fSJed Brown CeedOperatorSetField(op, "jac_data", elem_restr_jd_i, 562e334ad8fSJed Brown CEED_BASIS_COLLOCATED, jac_data); 563e334ad8fSJed Brown CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q, 564e334ad8fSJed Brown CEED_VECTOR_ACTIVE); 565e334ad8fSJed Brown CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q, 566e334ad8fSJed Brown CEED_VECTOR_ACTIVE); 567e334ad8fSJed Brown op_ijacobian_vol = op; 568e334ad8fSJed Brown CeedQFunctionDestroy(&qf_ijacobian_vol); 569e334ad8fSJed Brown } 570e334ad8fSJed Brown 57177841947SLeila Ghaffari // ***************************************************************************** 57277841947SLeila Ghaffari // Set up CEED objects for the exterior domain (surface) 57377841947SLeila Ghaffari // ***************************************************************************** 57477841947SLeila Ghaffari CeedInt height = 1, 57577841947SLeila Ghaffari dim_sur = dim - height, 57677841947SLeila Ghaffari P_sur = app_ctx->degree + 1, 57777841947SLeila Ghaffari Q_sur = P_sur + app_ctx->q_extra; 578e334ad8fSJed Brown const CeedInt q_data_size_sur = problem->q_data_size_sur, 579e334ad8fSJed Brown jac_data_size_sur = problem->jac_data_size_sur; 58077841947SLeila Ghaffari 58177841947SLeila Ghaffari // ----------------------------------------------------------------------------- 58277841947SLeila Ghaffari // CEED Bases 58377841947SLeila Ghaffari // ----------------------------------------------------------------------------- 58477841947SLeila Ghaffari CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_q, P_sur, Q_sur, 58577841947SLeila Ghaffari CEED_GAUSS, &ceed_data->basis_q_sur); 58677841947SLeila Ghaffari CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_x, 2, Q_sur, CEED_GAUSS, 58777841947SLeila Ghaffari &ceed_data->basis_x_sur); 588*959b8288SJames Wright CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_x, 2, P_sur, 589*959b8288SJames Wright CEED_GAUSS_LOBATTO, &ceed_data->basis_xc_sur); 59077841947SLeila Ghaffari 59177841947SLeila Ghaffari // ----------------------------------------------------------------------------- 59277841947SLeila Ghaffari // CEED QFunctions 59377841947SLeila Ghaffari // ----------------------------------------------------------------------------- 59477841947SLeila Ghaffari // -- Create QFunction for quadrature data 59591e5af17SJed Brown CeedQFunctionCreateInterior(ceed, 1, problem->setup_sur.qfunction, 59691e5af17SJed Brown problem->setup_sur.qfunction_loc, 59777841947SLeila Ghaffari &ceed_data->qf_setup_sur); 598841e4c73SJed Brown if (problem->setup_sur.qfunction_context) { 599841e4c73SJed Brown CeedQFunctionSetContext(ceed_data->qf_setup_sur, 600841e4c73SJed Brown problem->setup_sur.qfunction_context); 601841e4c73SJed Brown CeedQFunctionContextDestroy(&problem->setup_sur.qfunction_context); 602841e4c73SJed Brown } 60377841947SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_setup_sur, "dx", num_comp_x*dim_sur, 60477841947SLeila Ghaffari CEED_EVAL_GRAD); 60577841947SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_setup_sur, "weight", 1, CEED_EVAL_WEIGHT); 606a61c78d6SJeremy L Thompson CeedQFunctionAddOutput(ceed_data->qf_setup_sur, "surface qdata", 6072fe7aee7SLeila Ghaffari q_data_size_sur, CEED_EVAL_NONE); 60877841947SLeila Ghaffari 6092fe7aee7SLeila Ghaffari // -- Creat QFunction for inflow boundaries 61091e5af17SJed Brown if (problem->apply_inflow.qfunction) { 61191e5af17SJed Brown CeedQFunctionCreateInterior(ceed, 1, problem->apply_inflow.qfunction, 61291e5af17SJed Brown problem->apply_inflow.qfunction_loc, &ceed_data->qf_apply_inflow); 613841e4c73SJed Brown CeedQFunctionSetContext(ceed_data->qf_apply_inflow, 614841e4c73SJed Brown problem->apply_inflow.qfunction_context); 615841e4c73SJed Brown CeedQFunctionContextDestroy(&problem->apply_inflow.qfunction_context); 6162fe7aee7SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_apply_inflow, "q", num_comp_q, 61777841947SLeila Ghaffari CEED_EVAL_INTERP); 618e8b03feeSJames Wright CeedQFunctionAddInput(ceed_data->qf_apply_inflow, "Grad_q", num_comp_q*(dim-1), 619e8b03feeSJames Wright CEED_EVAL_GRAD); 6202fe7aee7SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_apply_inflow, "surface qdata", 6212fe7aee7SLeila Ghaffari q_data_size_sur, CEED_EVAL_NONE); 6222fe7aee7SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_apply_inflow, "x", num_comp_x, 62377841947SLeila Ghaffari CEED_EVAL_INTERP); 6242fe7aee7SLeila Ghaffari CeedQFunctionAddOutput(ceed_data->qf_apply_inflow, "v", num_comp_q, 6252fe7aee7SLeila Ghaffari CEED_EVAL_INTERP); 626b55ac660SJames Wright if (jac_data_size_sur) 627b55ac660SJames Wright CeedQFunctionAddOutput(ceed_data->qf_apply_inflow, "surface jacobian data", 628b55ac660SJames Wright jac_data_size_sur, 629b55ac660SJames Wright CEED_EVAL_NONE); 6302fe7aee7SLeila Ghaffari } 631e334ad8fSJed Brown if (problem->apply_inflow_jacobian.qfunction) { 632e334ad8fSJed Brown CeedQFunctionCreateInterior(ceed, 1, problem->apply_inflow_jacobian.qfunction, 633e334ad8fSJed Brown problem->apply_inflow_jacobian.qfunction_loc, 634e334ad8fSJed Brown &ceed_data->qf_apply_inflow_jacobian); 635e334ad8fSJed Brown CeedQFunctionSetContext(ceed_data->qf_apply_inflow_jacobian, 636e334ad8fSJed Brown problem->apply_inflow_jacobian.qfunction_context); 637e334ad8fSJed Brown CeedQFunctionContextDestroy(&problem->apply_inflow_jacobian.qfunction_context); 638e334ad8fSJed Brown CeedQFunctionAddInput(ceed_data->qf_apply_inflow_jacobian, "dq", num_comp_q, 639e334ad8fSJed Brown CEED_EVAL_INTERP); 640b55ac660SJames Wright CeedQFunctionAddInput(ceed_data->qf_apply_inflow_jacobian, "Grad_dq", 641b55ac660SJames Wright num_comp_q*dim_sur, CEED_EVAL_GRAD); 642e334ad8fSJed Brown CeedQFunctionAddInput(ceed_data->qf_apply_inflow_jacobian, "surface qdata", 643e334ad8fSJed Brown q_data_size_sur, CEED_EVAL_NONE); 644e334ad8fSJed Brown CeedQFunctionAddInput(ceed_data->qf_apply_inflow_jacobian, "x", num_comp_x, 645e334ad8fSJed Brown CEED_EVAL_INTERP); 646b55ac660SJames Wright CeedQFunctionAddInput(ceed_data->qf_apply_inflow_jacobian, 647b55ac660SJames Wright "surface jacobian data", 648b55ac660SJames Wright jac_data_size_sur, CEED_EVAL_NONE); 649e334ad8fSJed Brown CeedQFunctionAddOutput(ceed_data->qf_apply_inflow_jacobian, "v", num_comp_q, 650e334ad8fSJed Brown CEED_EVAL_INTERP); 651e334ad8fSJed Brown } 6522fe7aee7SLeila Ghaffari 6532fe7aee7SLeila Ghaffari // -- Creat QFunction for outflow boundaries 65491e5af17SJed Brown if (problem->apply_outflow.qfunction) { 65591e5af17SJed Brown CeedQFunctionCreateInterior(ceed, 1, problem->apply_outflow.qfunction, 65691e5af17SJed Brown problem->apply_outflow.qfunction_loc, &ceed_data->qf_apply_outflow); 657841e4c73SJed Brown CeedQFunctionSetContext(ceed_data->qf_apply_outflow, 658841e4c73SJed Brown problem->apply_outflow.qfunction_context); 659841e4c73SJed Brown CeedQFunctionContextDestroy(&problem->apply_outflow.qfunction_context); 6602fe7aee7SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_apply_outflow, "q", num_comp_q, 6612fe7aee7SLeila Ghaffari CEED_EVAL_INTERP); 662e8b03feeSJames Wright CeedQFunctionAddInput(ceed_data->qf_apply_outflow, "Grad_q", num_comp_q*(dim-1), 663e8b03feeSJames Wright CEED_EVAL_GRAD); 6642fe7aee7SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_apply_outflow, "surface qdata", 6652fe7aee7SLeila Ghaffari q_data_size_sur, CEED_EVAL_NONE); 6662fe7aee7SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_apply_outflow, "x", num_comp_x, 6672fe7aee7SLeila Ghaffari CEED_EVAL_INTERP); 6682fe7aee7SLeila Ghaffari CeedQFunctionAddOutput(ceed_data->qf_apply_outflow, "v", num_comp_q, 66977841947SLeila Ghaffari CEED_EVAL_INTERP); 67039c69132SJed Brown if (jac_data_size_sur) 671e334ad8fSJed Brown CeedQFunctionAddOutput(ceed_data->qf_apply_outflow, "surface jacobian data", 672e334ad8fSJed Brown jac_data_size_sur, 673e334ad8fSJed Brown CEED_EVAL_NONE); 674e334ad8fSJed Brown } 675e334ad8fSJed Brown if (problem->apply_outflow_jacobian.qfunction) { 676e334ad8fSJed Brown CeedQFunctionCreateInterior(ceed, 1, problem->apply_outflow_jacobian.qfunction, 677e334ad8fSJed Brown problem->apply_outflow_jacobian.qfunction_loc, 678e334ad8fSJed Brown &ceed_data->qf_apply_outflow_jacobian); 679e334ad8fSJed Brown CeedQFunctionSetContext(ceed_data->qf_apply_outflow_jacobian, 680e334ad8fSJed Brown problem->apply_outflow_jacobian.qfunction_context); 681e334ad8fSJed Brown CeedQFunctionContextDestroy(&problem->apply_outflow_jacobian.qfunction_context); 682e334ad8fSJed Brown CeedQFunctionAddInput(ceed_data->qf_apply_outflow_jacobian, "dq", num_comp_q, 683e334ad8fSJed Brown CEED_EVAL_INTERP); 684b55ac660SJames Wright CeedQFunctionAddInput(ceed_data->qf_apply_outflow_jacobian, "Grad_dq", 685b55ac660SJames Wright num_comp_q*dim_sur, CEED_EVAL_GRAD); 686e334ad8fSJed Brown CeedQFunctionAddInput(ceed_data->qf_apply_outflow_jacobian, "surface qdata", 687e334ad8fSJed Brown q_data_size_sur, CEED_EVAL_NONE); 6880ec2498eSJames Wright CeedQFunctionAddInput(ceed_data->qf_apply_outflow_jacobian, "x", num_comp_x, 6890ec2498eSJames Wright CEED_EVAL_INTERP); 690e334ad8fSJed Brown CeedQFunctionAddInput(ceed_data->qf_apply_outflow_jacobian, 691e334ad8fSJed Brown "surface jacobian data", 692e334ad8fSJed Brown jac_data_size_sur, CEED_EVAL_NONE); 693e334ad8fSJed Brown CeedQFunctionAddOutput(ceed_data->qf_apply_outflow_jacobian, "v", num_comp_q, 694e334ad8fSJed Brown CEED_EVAL_INTERP); 69577841947SLeila Ghaffari } 69677841947SLeila Ghaffari 69777841947SLeila Ghaffari // ***************************************************************************** 69877841947SLeila Ghaffari // CEED Operator Apply 69977841947SLeila Ghaffari // ***************************************************************************** 70077841947SLeila Ghaffari // -- Apply CEED Operator for the geometric data 70177841947SLeila Ghaffari CeedOperatorApply(ceed_data->op_setup_vol, ceed_data->x_coord, 70277841947SLeila Ghaffari ceed_data->q_data, CEED_REQUEST_IMMEDIATE); 70377841947SLeila Ghaffari 70477841947SLeila Ghaffari // -- Create and apply CEED Composite Operator for the entire domain 70577841947SLeila Ghaffari if (!user->phys->implicit) { // RHS 70677841947SLeila Ghaffari ierr = CreateOperatorForDomain(ceed, dm, bc, ceed_data, user->phys, 707e334ad8fSJed Brown user->op_rhs_vol, NULL, height, P_sur, Q_sur, 708e334ad8fSJed Brown q_data_size_sur, 0, 709e334ad8fSJed Brown &user->op_rhs, NULL); CHKERRQ(ierr); 71077841947SLeila Ghaffari } else { // IFunction 71177841947SLeila Ghaffari ierr = CreateOperatorForDomain(ceed, dm, bc, ceed_data, user->phys, 712e334ad8fSJed Brown user->op_ifunction_vol, op_ijacobian_vol, 713e334ad8fSJed Brown height, P_sur, Q_sur, 714e334ad8fSJed Brown q_data_size_sur, jac_data_size_sur, 715e334ad8fSJed Brown &user->op_ifunction, 716e334ad8fSJed Brown op_ijacobian_vol ? &user->op_ijacobian : NULL); CHKERRQ(ierr); 717e334ad8fSJed Brown if (user->op_ijacobian) { 718e334ad8fSJed Brown CeedOperatorContextGetFieldLabel(user->op_ijacobian, "ijacobian time shift", 719e334ad8fSJed Brown &user->phys->ijacobian_time_shift_label); 720e334ad8fSJed Brown } 721dada6cc0SJames Wright if (problem->use_dirichlet_ceed) { 722dada6cc0SJames Wright PetscCall(SetupStrongBC_Ceed(ceed, ceed_data, dm, user, app_ctx, problem, bc, 723dada6cc0SJames Wright Q_sur, q_data_size_sur)); 724dada6cc0SJames Wright } 725e334ad8fSJed Brown 72677841947SLeila Ghaffari } 727a3ae0734SJed Brown CeedElemRestrictionDestroy(&elem_restr_jd_i); 72822d320f5SLeila Ghaffari CeedOperatorDestroy(&op_ijacobian_vol); 729a3ae0734SJed Brown CeedVectorDestroy(&jac_data); 73077841947SLeila Ghaffari PetscFunctionReturn(0); 73177841947SLeila Ghaffari } 732