1727da7e7SJeremy L Thompson // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors. 2727da7e7SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 3a515125bSLeila Ghaffari // 4727da7e7SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause 5a515125bSLeila Ghaffari // 6727da7e7SJeremy L Thompson // This file is part of CEED: http://github.com/ceed 7a515125bSLeila Ghaffari 8a515125bSLeila Ghaffari /// @file 9a515125bSLeila Ghaffari /// Setup libCEED for Navier-Stokes example using PETSc 10a515125bSLeila Ghaffari 11a515125bSLeila Ghaffari #include "../navierstokes.h" 12a515125bSLeila Ghaffari 13a515125bSLeila Ghaffari // Utility function - essential BC dofs are encoded in closure indices as -(i+1). 14a515125bSLeila Ghaffari PetscInt Involute(PetscInt i) { 15a515125bSLeila Ghaffari return i >= 0 ? i : -(i+1); 16a515125bSLeila Ghaffari } 17a515125bSLeila Ghaffari 18a515125bSLeila Ghaffari // Utility function to create local CEED restriction 196b1ccf21SJeremy L Thompson PetscErrorCode CreateRestrictionFromPlex(Ceed ceed, DM dm, CeedInt height, 206b1ccf21SJeremy L Thompson DMLabel domain_label, CeedInt value, CeedElemRestriction *elem_restr) { 216b1ccf21SJeremy L Thompson PetscInt num_elem, elem_size, num_dof, num_comp, *elem_restr_offsets; 22a515125bSLeila Ghaffari PetscErrorCode ierr; 236b1ccf21SJeremy L Thompson 24a515125bSLeila Ghaffari PetscFunctionBeginUser; 256b1ccf21SJeremy L Thompson ierr = DMPlexGetLocalOffsets(dm, domain_label, value, height, 0, &num_elem, 266b1ccf21SJeremy L Thompson &elem_size, &num_comp, &num_dof, &elem_restr_offsets); 276b1ccf21SJeremy L Thompson CHKERRQ(ierr); 28a515125bSLeila Ghaffari 296b1ccf21SJeremy L Thompson CeedElemRestrictionCreate(ceed, num_elem, elem_size, num_comp, 306b1ccf21SJeremy L Thompson 1, num_dof, CEED_MEM_HOST, CEED_COPY_VALUES, 316b1ccf21SJeremy L Thompson elem_restr_offsets, elem_restr); 326b1ccf21SJeremy L Thompson ierr = PetscFree(elem_restr_offsets); CHKERRQ(ierr); 33a515125bSLeila Ghaffari 34a515125bSLeila Ghaffari PetscFunctionReturn(0); 35a515125bSLeila Ghaffari } 36a515125bSLeila Ghaffari 37a515125bSLeila Ghaffari // Utility function to get Ceed Restriction for each domain 38a515125bSLeila Ghaffari PetscErrorCode GetRestrictionForDomain(Ceed ceed, DM dm, CeedInt height, 39a515125bSLeila Ghaffari DMLabel domain_label, PetscInt value, 406b1ccf21SJeremy L Thompson CeedInt Q, CeedInt q_data_size, 41a515125bSLeila Ghaffari CeedElemRestriction *elem_restr_q, 42a515125bSLeila Ghaffari CeedElemRestriction *elem_restr_x, 43a515125bSLeila Ghaffari CeedElemRestriction *elem_restr_qd_i) { 44a515125bSLeila Ghaffari DM dm_coord; 45a515125bSLeila Ghaffari CeedInt dim, loc_num_elem; 46a515125bSLeila Ghaffari CeedInt Q_dim; 47395c96d3SJed Brown CeedElemRestriction elem_restr_tmp; 48a515125bSLeila Ghaffari PetscErrorCode ierr; 49a515125bSLeila Ghaffari PetscFunctionBeginUser; 50a515125bSLeila Ghaffari 51a515125bSLeila Ghaffari ierr = DMGetDimension(dm, &dim); CHKERRQ(ierr); 52a515125bSLeila Ghaffari dim -= height; 53a515125bSLeila Ghaffari Q_dim = CeedIntPow(Q, dim); 54395c96d3SJed Brown ierr = CreateRestrictionFromPlex(ceed, dm, height, domain_label, value, 55395c96d3SJed Brown &elem_restr_tmp); 56395c96d3SJed Brown CHKERRQ(ierr); 57395c96d3SJed Brown if (elem_restr_q) *elem_restr_q = elem_restr_tmp; 58395c96d3SJed Brown if (elem_restr_x) { 59*cac8aa24SJed Brown ierr = DMGetCellCoordinateDM(dm, &dm_coord); CHKERRQ(ierr); 60*cac8aa24SJed Brown if (!dm_coord) { 61a515125bSLeila Ghaffari ierr = DMGetCoordinateDM(dm, &dm_coord); CHKERRQ(ierr); 62*cac8aa24SJed Brown } 63a515125bSLeila Ghaffari ierr = DMPlexSetClosurePermutationTensor(dm_coord, PETSC_DETERMINE, NULL); 64a515125bSLeila Ghaffari CHKERRQ(ierr); 656b1ccf21SJeremy L Thompson ierr = CreateRestrictionFromPlex(ceed, dm_coord, height, domain_label, value, 666b1ccf21SJeremy L Thompson elem_restr_x); 676b1ccf21SJeremy L Thompson CHKERRQ(ierr); 68395c96d3SJed Brown } 69395c96d3SJed Brown if (elem_restr_qd_i) { 70395c96d3SJed Brown CeedElemRestrictionGetNumElements(elem_restr_tmp, &loc_num_elem); 71a515125bSLeila Ghaffari CeedElemRestrictionCreateStrided(ceed, loc_num_elem, Q_dim, 72a515125bSLeila Ghaffari q_data_size, q_data_size*loc_num_elem*Q_dim, 73a515125bSLeila Ghaffari CEED_STRIDES_BACKEND, elem_restr_qd_i); 74395c96d3SJed Brown } 75395c96d3SJed Brown if (!elem_restr_q) CeedElemRestrictionDestroy(&elem_restr_tmp); 76a515125bSLeila Ghaffari PetscFunctionReturn(0); 77a515125bSLeila Ghaffari } 78a515125bSLeila Ghaffari 79a515125bSLeila Ghaffari // Utility function to create CEED Composite Operator for the entire domain 80a515125bSLeila Ghaffari PetscErrorCode CreateOperatorForDomain(Ceed ceed, DM dm, SimpleBC bc, 81a515125bSLeila Ghaffari CeedData ceed_data, Physics phys, 82f0b65372SJed Brown CeedOperator op_apply_vol, 83f0b65372SJed Brown CeedOperator op_apply_ijacobian_vol, 84f0b65372SJed Brown CeedInt height, 85f0b65372SJed Brown CeedInt P_sur, CeedInt Q_sur, 86f0b65372SJed Brown CeedInt q_data_size_sur, CeedInt jac_data_size_sur, 87f0b65372SJed Brown CeedOperator *op_apply, CeedOperator *op_apply_ijacobian) { 88a515125bSLeila Ghaffari DMLabel domain_label; 89a515125bSLeila Ghaffari PetscErrorCode ierr; 90a515125bSLeila Ghaffari PetscFunctionBeginUser; 91a515125bSLeila Ghaffari 92a515125bSLeila Ghaffari // Create Composite Operaters 93a515125bSLeila Ghaffari CeedCompositeOperatorCreate(ceed, op_apply); 94f0b65372SJed Brown if (op_apply_ijacobian) 95f0b65372SJed Brown CeedCompositeOperatorCreate(ceed, op_apply_ijacobian); 96a515125bSLeila Ghaffari 97a515125bSLeila Ghaffari // --Apply Sub-Operator for the volume 98a515125bSLeila Ghaffari CeedCompositeOperatorAddSub(*op_apply, op_apply_vol); 99f0b65372SJed Brown if (op_apply_ijacobian) 100f0b65372SJed Brown CeedCompositeOperatorAddSub(*op_apply_ijacobian, op_apply_ijacobian_vol); 101a515125bSLeila Ghaffari 102a515125bSLeila Ghaffari // -- Create Sub-Operator for in/outflow BCs 103bb8a0c61SJames Wright if (phys->has_neumann || 1) { 104a515125bSLeila Ghaffari // --- Setup 105a515125bSLeila Ghaffari ierr = DMGetLabel(dm, "Face Sets", &domain_label); CHKERRQ(ierr); 106a515125bSLeila Ghaffari 107a515125bSLeila Ghaffari // --- Get number of quadrature points for the boundaries 108a515125bSLeila Ghaffari CeedInt num_qpts_sur; 109a515125bSLeila Ghaffari CeedBasisGetNumQuadraturePoints(ceed_data->basis_q_sur, &num_qpts_sur); 110a515125bSLeila Ghaffari 111002797a3SLeila Ghaffari // --- Create Sub-Operator for inflow boundaries 112002797a3SLeila Ghaffari for (CeedInt i=0; i < bc->num_inflow; i++) { 11368ae065aSJames Wright CeedVector q_data_sur, jac_data_sur; 114f0b65372SJed Brown CeedOperator op_setup_sur, op_apply_inflow, 115f0b65372SJed Brown op_apply_inflow_jacobian = NULL; 11668ae065aSJames Wright CeedElemRestriction elem_restr_x_sur, elem_restr_q_sur, elem_restr_qd_i_sur, 11768ae065aSJames Wright elem_restr_jd_i_sur; 118a515125bSLeila Ghaffari 119a515125bSLeila Ghaffari // ---- CEED Restriction 120002797a3SLeila Ghaffari ierr = GetRestrictionForDomain(ceed, dm, height, domain_label, bc->inflows[i], 121002797a3SLeila Ghaffari Q_sur, q_data_size_sur, &elem_restr_q_sur, &elem_restr_x_sur, 122002797a3SLeila Ghaffari &elem_restr_qd_i_sur); 123a515125bSLeila Ghaffari CHKERRQ(ierr); 12468ae065aSJames Wright if (jac_data_size_sur > 0) { 12568ae065aSJames Wright // State-dependent data will be passed from residual to Jacobian. This will be collocated. 12668ae065aSJames Wright ierr = GetRestrictionForDomain(ceed, dm, height, domain_label, bc->inflows[i], 12768ae065aSJames Wright Q_sur, jac_data_size_sur, NULL, NULL, 12868ae065aSJames Wright &elem_restr_jd_i_sur); 12968ae065aSJames Wright CHKERRQ(ierr); 13068ae065aSJames Wright CeedElemRestrictionCreateVector(elem_restr_jd_i_sur, &jac_data_sur, NULL); 13168ae065aSJames Wright } else { 13268ae065aSJames Wright elem_restr_jd_i_sur = NULL; 13368ae065aSJames Wright jac_data_sur = NULL; 13468ae065aSJames Wright } 135a515125bSLeila Ghaffari 136a515125bSLeila Ghaffari // ---- CEED Vector 137a515125bSLeila Ghaffari PetscInt loc_num_elem_sur; 138a515125bSLeila Ghaffari CeedElemRestrictionGetNumElements(elem_restr_q_sur, &loc_num_elem_sur); 139a515125bSLeila Ghaffari CeedVectorCreate(ceed, q_data_size_sur*loc_num_elem_sur*num_qpts_sur, 140a515125bSLeila Ghaffari &q_data_sur); 141a515125bSLeila Ghaffari 142a515125bSLeila Ghaffari // ---- CEED Operator 143a515125bSLeila Ghaffari // ----- CEED Operator for Setup (geometric factors) 144a515125bSLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_setup_sur, NULL, NULL, &op_setup_sur); 145a515125bSLeila Ghaffari CeedOperatorSetField(op_setup_sur, "dx", elem_restr_x_sur, 146139613f2SLeila Ghaffari ceed_data->basis_x_sur, CEED_VECTOR_ACTIVE); 147a515125bSLeila Ghaffari CeedOperatorSetField(op_setup_sur, "weight", CEED_ELEMRESTRICTION_NONE, 148a515125bSLeila Ghaffari ceed_data->basis_x_sur, CEED_VECTOR_NONE); 1493b1e209bSJeremy L Thompson CeedOperatorSetField(op_setup_sur, "surface qdata", elem_restr_qd_i_sur, 150a515125bSLeila Ghaffari CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); 151a515125bSLeila Ghaffari 152a515125bSLeila Ghaffari // ----- CEED Operator for Physics 153002797a3SLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_apply_inflow, NULL, NULL, 154002797a3SLeila Ghaffari &op_apply_inflow); 155002797a3SLeila Ghaffari CeedOperatorSetField(op_apply_inflow, "q", elem_restr_q_sur, 156a515125bSLeila Ghaffari ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 157dd64951cSJames Wright CeedOperatorSetField(op_apply_inflow, "Grad_q", elem_restr_q_sur, 158dd64951cSJames Wright ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 159002797a3SLeila Ghaffari CeedOperatorSetField(op_apply_inflow, "surface qdata", elem_restr_qd_i_sur, 160a515125bSLeila Ghaffari CEED_BASIS_COLLOCATED, q_data_sur); 161002797a3SLeila Ghaffari CeedOperatorSetField(op_apply_inflow, "x", elem_restr_x_sur, 162a515125bSLeila Ghaffari ceed_data->basis_x_sur, ceed_data->x_coord); 163002797a3SLeila Ghaffari CeedOperatorSetField(op_apply_inflow, "v", elem_restr_q_sur, 164a515125bSLeila Ghaffari ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 16568ae065aSJames Wright if (elem_restr_jd_i_sur) 16668ae065aSJames Wright CeedOperatorSetField(op_apply_inflow, "surface jacobian data", 16768ae065aSJames Wright elem_restr_jd_i_sur, 16868ae065aSJames Wright CEED_BASIS_COLLOCATED, jac_data_sur); 169a515125bSLeila Ghaffari 170f0b65372SJed Brown if (ceed_data->qf_apply_inflow_jacobian) { 171f0b65372SJed Brown CeedOperatorCreate(ceed, ceed_data->qf_apply_inflow_jacobian, NULL, NULL, 172f0b65372SJed Brown &op_apply_inflow_jacobian); 173f0b65372SJed Brown CeedOperatorSetField(op_apply_inflow_jacobian, "dq", elem_restr_q_sur, 174f0b65372SJed Brown ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 17568ae065aSJames Wright CeedOperatorSetField(op_apply_inflow_jacobian, "Grad_dq", elem_restr_q_sur, 17668ae065aSJames Wright ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 177f0b65372SJed Brown CeedOperatorSetField(op_apply_inflow_jacobian, "surface qdata", 178f0b65372SJed Brown elem_restr_qd_i_sur, 179f0b65372SJed Brown CEED_BASIS_COLLOCATED, q_data_sur); 180f0b65372SJed Brown CeedOperatorSetField(op_apply_inflow_jacobian, "x", elem_restr_x_sur, 181f0b65372SJed Brown ceed_data->basis_x_sur, ceed_data->x_coord); 18268ae065aSJames Wright CeedOperatorSetField(op_apply_inflow_jacobian, "surface jacobian data", 18368ae065aSJames Wright elem_restr_jd_i_sur, 18468ae065aSJames Wright CEED_BASIS_COLLOCATED, jac_data_sur); 185f0b65372SJed Brown CeedOperatorSetField(op_apply_inflow_jacobian, "v", elem_restr_q_sur, 186f0b65372SJed Brown ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 187f0b65372SJed Brown } 188f0b65372SJed Brown 189a515125bSLeila Ghaffari // ----- Apply CEED operator for Setup 190a515125bSLeila Ghaffari CeedOperatorApply(op_setup_sur, ceed_data->x_coord, q_data_sur, 191a515125bSLeila Ghaffari CEED_REQUEST_IMMEDIATE); 192a515125bSLeila Ghaffari 193002797a3SLeila Ghaffari // ----- Apply Sub-Operator for Physics 194002797a3SLeila Ghaffari CeedCompositeOperatorAddSub(*op_apply, op_apply_inflow); 195f0b65372SJed Brown if (op_apply_ijacobian) 196f0b65372SJed Brown CeedCompositeOperatorAddSub(*op_apply_ijacobian, op_apply_inflow_jacobian); 197a515125bSLeila Ghaffari 198a515125bSLeila Ghaffari // ----- Cleanup 199a515125bSLeila Ghaffari CeedVectorDestroy(&q_data_sur); 20068ae065aSJames Wright CeedVectorDestroy(&jac_data_sur); 201a515125bSLeila Ghaffari CeedElemRestrictionDestroy(&elem_restr_q_sur); 202a515125bSLeila Ghaffari CeedElemRestrictionDestroy(&elem_restr_x_sur); 203a515125bSLeila Ghaffari CeedElemRestrictionDestroy(&elem_restr_qd_i_sur); 20468ae065aSJames Wright CeedElemRestrictionDestroy(&elem_restr_jd_i_sur); 205a515125bSLeila Ghaffari CeedOperatorDestroy(&op_setup_sur); 206002797a3SLeila Ghaffari CeedOperatorDestroy(&op_apply_inflow); 207f0b65372SJed Brown CeedOperatorDestroy(&op_apply_inflow_jacobian); 208a515125bSLeila Ghaffari } 209a515125bSLeila Ghaffari 210002797a3SLeila Ghaffari // --- Create Sub-Operator for outflow boundaries 211002797a3SLeila Ghaffari for (CeedInt i=0; i < bc->num_outflow; i++) { 212f0b65372SJed Brown CeedVector q_data_sur, jac_data_sur; 213f0b65372SJed Brown CeedOperator op_setup_sur, op_apply_outflow, 214f0b65372SJed Brown op_apply_outflow_jacobian = NULL; 215f0b65372SJed Brown CeedElemRestriction elem_restr_x_sur, elem_restr_q_sur, elem_restr_qd_i_sur, 216f0b65372SJed Brown elem_restr_jd_i_sur; 217002797a3SLeila Ghaffari 218002797a3SLeila Ghaffari // ---- CEED Restriction 219002797a3SLeila Ghaffari ierr = GetRestrictionForDomain(ceed, dm, height, domain_label, bc->outflows[i], 220002797a3SLeila Ghaffari Q_sur, q_data_size_sur, &elem_restr_q_sur, &elem_restr_x_sur, 221002797a3SLeila Ghaffari &elem_restr_qd_i_sur); 222002797a3SLeila Ghaffari CHKERRQ(ierr); 2232556a851SJed Brown if (jac_data_size_sur > 0) { 2242556a851SJed Brown // State-dependent data will be passed from residual to Jacobian. This will be collocated. 225f0b65372SJed Brown ierr = GetRestrictionForDomain(ceed, dm, height, domain_label, bc->outflows[i], 226f0b65372SJed Brown Q_sur, jac_data_size_sur, NULL, NULL, 227f0b65372SJed Brown &elem_restr_jd_i_sur); 228f0b65372SJed Brown CHKERRQ(ierr); 2292556a851SJed Brown CeedElemRestrictionCreateVector(elem_restr_jd_i_sur, &jac_data_sur, NULL); 2302556a851SJed Brown } else { 2312556a851SJed Brown elem_restr_jd_i_sur = NULL; 2322556a851SJed Brown jac_data_sur = NULL; 2332556a851SJed Brown } 234002797a3SLeila Ghaffari 235002797a3SLeila Ghaffari // ---- CEED Vector 236002797a3SLeila Ghaffari PetscInt loc_num_elem_sur; 237002797a3SLeila Ghaffari CeedElemRestrictionGetNumElements(elem_restr_q_sur, &loc_num_elem_sur); 238002797a3SLeila Ghaffari CeedVectorCreate(ceed, q_data_size_sur*loc_num_elem_sur*num_qpts_sur, 239002797a3SLeila Ghaffari &q_data_sur); 240002797a3SLeila Ghaffari 241002797a3SLeila Ghaffari // ---- CEED Operator 242002797a3SLeila Ghaffari // ----- CEED Operator for Setup (geometric factors) 243002797a3SLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_setup_sur, NULL, NULL, &op_setup_sur); 244002797a3SLeila Ghaffari CeedOperatorSetField(op_setup_sur, "dx", elem_restr_x_sur, 245002797a3SLeila Ghaffari ceed_data->basis_x_sur, CEED_VECTOR_ACTIVE); 246002797a3SLeila Ghaffari CeedOperatorSetField(op_setup_sur, "weight", CEED_ELEMRESTRICTION_NONE, 247002797a3SLeila Ghaffari ceed_data->basis_x_sur, CEED_VECTOR_NONE); 248002797a3SLeila Ghaffari CeedOperatorSetField(op_setup_sur, "surface qdata", elem_restr_qd_i_sur, 249002797a3SLeila Ghaffari CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); 250002797a3SLeila Ghaffari 251002797a3SLeila Ghaffari // ----- CEED Operator for Physics 252002797a3SLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_apply_outflow, NULL, NULL, 253002797a3SLeila Ghaffari &op_apply_outflow); 254002797a3SLeila Ghaffari CeedOperatorSetField(op_apply_outflow, "q", elem_restr_q_sur, 255002797a3SLeila Ghaffari ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 256dd64951cSJames Wright CeedOperatorSetField(op_apply_outflow, "Grad_q", elem_restr_q_sur, 257dd64951cSJames Wright ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 258002797a3SLeila Ghaffari CeedOperatorSetField(op_apply_outflow, "surface qdata", elem_restr_qd_i_sur, 259002797a3SLeila Ghaffari CEED_BASIS_COLLOCATED, q_data_sur); 260002797a3SLeila Ghaffari CeedOperatorSetField(op_apply_outflow, "x", elem_restr_x_sur, 261002797a3SLeila Ghaffari ceed_data->basis_x_sur, ceed_data->x_coord); 262002797a3SLeila Ghaffari CeedOperatorSetField(op_apply_outflow, "v", elem_restr_q_sur, 263002797a3SLeila Ghaffari ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 2642556a851SJed Brown if (elem_restr_jd_i_sur) 265f0b65372SJed Brown CeedOperatorSetField(op_apply_outflow, "surface jacobian data", 266f0b65372SJed Brown elem_restr_jd_i_sur, 267f0b65372SJed Brown CEED_BASIS_COLLOCATED, jac_data_sur); 268f0b65372SJed Brown 269f0b65372SJed Brown if (ceed_data->qf_apply_outflow_jacobian) { 270f0b65372SJed Brown CeedOperatorCreate(ceed, ceed_data->qf_apply_outflow_jacobian, NULL, NULL, 271f0b65372SJed Brown &op_apply_outflow_jacobian); 272f0b65372SJed Brown CeedOperatorSetField(op_apply_outflow_jacobian, "dq", elem_restr_q_sur, 273f0b65372SJed Brown ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 274b01ba163SJames Wright CeedOperatorSetField(op_apply_outflow_jacobian, "Grad_dq", elem_restr_q_sur, 275b01ba163SJames Wright ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 276f0b65372SJed Brown CeedOperatorSetField(op_apply_outflow_jacobian, "surface qdata", 277f0b65372SJed Brown elem_restr_qd_i_sur, 278f0b65372SJed Brown CEED_BASIS_COLLOCATED, q_data_sur); 279b01ba163SJames Wright CeedOperatorSetField(op_apply_outflow_jacobian, "x", elem_restr_x_sur, 280b01ba163SJames Wright ceed_data->basis_x_sur, ceed_data->x_coord); 281f0b65372SJed Brown CeedOperatorSetField(op_apply_outflow_jacobian, "surface jacobian data", 282f0b65372SJed Brown elem_restr_jd_i_sur, 283f0b65372SJed Brown CEED_BASIS_COLLOCATED, jac_data_sur); 284f0b65372SJed Brown CeedOperatorSetField(op_apply_outflow_jacobian, "v", elem_restr_q_sur, 285f0b65372SJed Brown ceed_data->basis_q_sur, CEED_VECTOR_ACTIVE); 286f0b65372SJed Brown } 287002797a3SLeila Ghaffari 288002797a3SLeila Ghaffari // ----- Apply CEED operator for Setup 289002797a3SLeila Ghaffari CeedOperatorApply(op_setup_sur, ceed_data->x_coord, q_data_sur, 290002797a3SLeila Ghaffari CEED_REQUEST_IMMEDIATE); 291002797a3SLeila Ghaffari 292002797a3SLeila Ghaffari // ----- Apply Sub-Operator for Physics 293002797a3SLeila Ghaffari CeedCompositeOperatorAddSub(*op_apply, op_apply_outflow); 294f0b65372SJed Brown if (op_apply_ijacobian) 295f0b65372SJed Brown CeedCompositeOperatorAddSub(*op_apply_ijacobian, op_apply_outflow_jacobian); 296002797a3SLeila Ghaffari 297002797a3SLeila Ghaffari // ----- Cleanup 298002797a3SLeila Ghaffari CeedVectorDestroy(&q_data_sur); 299f0b65372SJed Brown CeedVectorDestroy(&jac_data_sur); 300002797a3SLeila Ghaffari CeedElemRestrictionDestroy(&elem_restr_q_sur); 301002797a3SLeila Ghaffari CeedElemRestrictionDestroy(&elem_restr_x_sur); 302002797a3SLeila Ghaffari CeedElemRestrictionDestroy(&elem_restr_qd_i_sur); 303f0b65372SJed Brown CeedElemRestrictionDestroy(&elem_restr_jd_i_sur); 304002797a3SLeila Ghaffari CeedOperatorDestroy(&op_setup_sur); 305002797a3SLeila Ghaffari CeedOperatorDestroy(&op_apply_outflow); 306f0b65372SJed Brown CeedOperatorDestroy(&op_apply_outflow_jacobian); 307002797a3SLeila Ghaffari } 308002797a3SLeila Ghaffari } 30992ada588SJames Wright 31092ada588SJames Wright // ----- Get Context Labels for Operator 31192ada588SJames Wright CeedOperatorContextGetFieldLabel(*op_apply, "solution time", 31292ada588SJames Wright &phys->solution_time_label); 313bb8a0c61SJames Wright CeedOperatorContextGetFieldLabel(*op_apply, "timestep size", 314bb8a0c61SJames Wright &phys->timestep_size_label); 31592ada588SJames Wright 316a515125bSLeila Ghaffari PetscFunctionReturn(0); 317a515125bSLeila Ghaffari } 318a515125bSLeila Ghaffari 319a515125bSLeila Ghaffari PetscErrorCode SetupLibceed(Ceed ceed, CeedData ceed_data, DM dm, User user, 320c848b8b7SJed Brown AppCtx app_ctx, ProblemData *problem, SimpleBC bc) { 321a515125bSLeila Ghaffari PetscErrorCode ierr; 322a515125bSLeila Ghaffari PetscFunctionBeginUser; 323a515125bSLeila Ghaffari 324a515125bSLeila Ghaffari // ***************************************************************************** 325a515125bSLeila Ghaffari // Set up CEED objects for the interior domain (volume) 326a515125bSLeila Ghaffari // ***************************************************************************** 327a515125bSLeila Ghaffari const PetscInt num_comp_q = 5; 328a515125bSLeila Ghaffari const CeedInt dim = problem->dim, 329a515125bSLeila Ghaffari num_comp_x = problem->dim, 330a515125bSLeila Ghaffari q_data_size_vol = problem->q_data_size_vol, 331f0b65372SJed Brown jac_data_size_vol = num_comp_q + 6 + 3, 332a515125bSLeila Ghaffari P = app_ctx->degree + 1, 333a515125bSLeila Ghaffari Q = P + app_ctx->q_extra; 334752f40e3SJed Brown CeedElemRestriction elem_restr_jd_i; 335752f40e3SJed Brown CeedVector jac_data; 336a515125bSLeila Ghaffari 337a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 338a515125bSLeila Ghaffari // CEED Bases 339a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 340a515125bSLeila Ghaffari CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_q, P, Q, CEED_GAUSS, 341a515125bSLeila Ghaffari &ceed_data->basis_q); 342a515125bSLeila Ghaffari CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_x, 2, Q, CEED_GAUSS, 343a515125bSLeila Ghaffari &ceed_data->basis_x); 344a515125bSLeila Ghaffari CeedBasisCreateTensorH1Lagrange(ceed, dim, num_comp_x, 2, P, 345a515125bSLeila Ghaffari CEED_GAUSS_LOBATTO, &ceed_data->basis_xc); 346a515125bSLeila Ghaffari 347a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 348a515125bSLeila Ghaffari // CEED Restrictions 349a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 350a515125bSLeila Ghaffari // -- Create restriction 3516b1ccf21SJeremy L Thompson ierr = GetRestrictionForDomain(ceed, dm, 0, 0, 0, Q, q_data_size_vol, 3526b1ccf21SJeremy L Thompson &ceed_data->elem_restr_q, &ceed_data->elem_restr_x, 353a515125bSLeila Ghaffari &ceed_data->elem_restr_qd_i); CHKERRQ(ierr); 354752f40e3SJed Brown 355752f40e3SJed Brown ierr = GetRestrictionForDomain(ceed, dm, 0, 0, 0, Q, jac_data_size_vol, 356752f40e3SJed Brown NULL, NULL, 357752f40e3SJed Brown &elem_restr_jd_i); CHKERRQ(ierr); 358a515125bSLeila Ghaffari // -- Create E vectors 359a515125bSLeila Ghaffari CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->q_ceed, NULL); 360a515125bSLeila Ghaffari CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->q_dot_ceed, 361a515125bSLeila Ghaffari NULL); 362a515125bSLeila Ghaffari CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &user->g_ceed, NULL); 363a515125bSLeila Ghaffari 364a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 365a515125bSLeila Ghaffari // CEED QFunctions 366a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 367a515125bSLeila Ghaffari // -- Create QFunction for quadrature data 3689785fe93SJed Brown CeedQFunctionCreateInterior(ceed, 1, problem->setup_vol.qfunction, 3699785fe93SJed Brown problem->setup_vol.qfunction_loc, 370a515125bSLeila Ghaffari &ceed_data->qf_setup_vol); 37115a3537eSJed Brown if (problem->setup_vol.qfunction_context) { 37215a3537eSJed Brown CeedQFunctionSetContext(ceed_data->qf_setup_vol, 37315a3537eSJed Brown problem->setup_vol.qfunction_context); 37415a3537eSJed Brown CeedQFunctionContextDestroy(&problem->setup_vol.qfunction_context); 37515a3537eSJed Brown } 376a515125bSLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_setup_vol, "dx", num_comp_x*dim, 377a515125bSLeila Ghaffari CEED_EVAL_GRAD); 378a515125bSLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_setup_vol, "weight", 1, CEED_EVAL_WEIGHT); 3793b1e209bSJeremy L Thompson CeedQFunctionAddOutput(ceed_data->qf_setup_vol, "qdata", q_data_size_vol, 380a515125bSLeila Ghaffari CEED_EVAL_NONE); 381a515125bSLeila Ghaffari 382a515125bSLeila Ghaffari // -- Create QFunction for ICs 3839785fe93SJed Brown CeedQFunctionCreateInterior(ceed, 1, problem->ics.qfunction, 3849785fe93SJed Brown problem->ics.qfunction_loc, 385a515125bSLeila Ghaffari &ceed_data->qf_ics); 38615a3537eSJed Brown CeedQFunctionSetContext(ceed_data->qf_ics, problem->ics.qfunction_context); 38715a3537eSJed Brown CeedQFunctionContextDestroy(&problem->ics.qfunction_context); 388a515125bSLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_ics, "x", num_comp_x, CEED_EVAL_INTERP); 389a515125bSLeila Ghaffari CeedQFunctionAddOutput(ceed_data->qf_ics, "q0", num_comp_q, CEED_EVAL_NONE); 390a515125bSLeila Ghaffari 391a515125bSLeila Ghaffari // -- Create QFunction for RHS 3929785fe93SJed Brown if (problem->apply_vol_rhs.qfunction) { 3939785fe93SJed Brown CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_rhs.qfunction, 3949785fe93SJed Brown problem->apply_vol_rhs.qfunction_loc, &ceed_data->qf_rhs_vol); 39515a3537eSJed Brown CeedQFunctionSetContext(ceed_data->qf_rhs_vol, 39615a3537eSJed Brown problem->apply_vol_rhs.qfunction_context); 39715a3537eSJed Brown CeedQFunctionContextDestroy(&problem->apply_vol_rhs.qfunction_context); 398a515125bSLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "q", num_comp_q, CEED_EVAL_INTERP); 399752f40e3SJed Brown CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "Grad_q", num_comp_q*dim, 400a515125bSLeila Ghaffari CEED_EVAL_GRAD); 4013b1e209bSJeremy L Thompson CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "qdata", q_data_size_vol, 402a515125bSLeila Ghaffari CEED_EVAL_NONE); 403a515125bSLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_rhs_vol, "x", num_comp_x, CEED_EVAL_INTERP); 404a515125bSLeila Ghaffari CeedQFunctionAddOutput(ceed_data->qf_rhs_vol, "v", num_comp_q, 405a515125bSLeila Ghaffari CEED_EVAL_INTERP); 406752f40e3SJed Brown CeedQFunctionAddOutput(ceed_data->qf_rhs_vol, "Grad_v", num_comp_q*dim, 407a515125bSLeila Ghaffari CEED_EVAL_GRAD); 408a515125bSLeila Ghaffari } 409a515125bSLeila Ghaffari 410a515125bSLeila Ghaffari // -- Create QFunction for IFunction 4119785fe93SJed Brown if (problem->apply_vol_ifunction.qfunction) { 4129785fe93SJed Brown CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_ifunction.qfunction, 4139785fe93SJed Brown problem->apply_vol_ifunction.qfunction_loc, &ceed_data->qf_ifunction_vol); 41415a3537eSJed Brown CeedQFunctionSetContext(ceed_data->qf_ifunction_vol, 41515a3537eSJed Brown problem->apply_vol_ifunction.qfunction_context); 41615a3537eSJed Brown CeedQFunctionContextDestroy(&problem->apply_vol_ifunction.qfunction_context); 417a515125bSLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "q", num_comp_q, 418a515125bSLeila Ghaffari CEED_EVAL_INTERP); 419752f40e3SJed Brown CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "Grad_q", num_comp_q*dim, 420a515125bSLeila Ghaffari CEED_EVAL_GRAD); 4213b1e209bSJeremy L Thompson CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "q dot", num_comp_q, 422a515125bSLeila Ghaffari CEED_EVAL_INTERP); 4233b1e209bSJeremy L Thompson CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "qdata", q_data_size_vol, 424a515125bSLeila Ghaffari CEED_EVAL_NONE); 425a515125bSLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_ifunction_vol, "x", num_comp_x, 426a515125bSLeila Ghaffari CEED_EVAL_INTERP); 427a515125bSLeila Ghaffari CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "v", num_comp_q, 428a515125bSLeila Ghaffari CEED_EVAL_INTERP); 429752f40e3SJed Brown CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "Grad_v", num_comp_q*dim, 430a515125bSLeila Ghaffari CEED_EVAL_GRAD); 431752f40e3SJed Brown CeedQFunctionAddOutput(ceed_data->qf_ifunction_vol, "jac_data", 432752f40e3SJed Brown jac_data_size_vol, CEED_EVAL_NONE); 433a515125bSLeila Ghaffari } 434a515125bSLeila Ghaffari 435f0b65372SJed Brown CeedQFunction qf_ijacobian_vol = NULL; 436f0b65372SJed Brown if (problem->apply_vol_ijacobian.qfunction) { 437f0b65372SJed Brown CeedQFunctionCreateInterior(ceed, 1, problem->apply_vol_ijacobian.qfunction, 438f0b65372SJed Brown problem->apply_vol_ijacobian.qfunction_loc, &qf_ijacobian_vol); 439f0b65372SJed Brown CeedQFunctionSetContext(qf_ijacobian_vol, 440f0b65372SJed Brown problem->apply_vol_ijacobian.qfunction_context); 441f0b65372SJed Brown CeedQFunctionContextDestroy(&problem->apply_vol_ijacobian.qfunction_context); 442f0b65372SJed Brown CeedQFunctionAddInput(qf_ijacobian_vol, "dq", num_comp_q, 443f0b65372SJed Brown CEED_EVAL_INTERP); 444f0b65372SJed Brown CeedQFunctionAddInput(qf_ijacobian_vol, "Grad_dq", num_comp_q*dim, 445f0b65372SJed Brown CEED_EVAL_GRAD); 446f0b65372SJed Brown CeedQFunctionAddInput(qf_ijacobian_vol, "qdata", q_data_size_vol, 447f0b65372SJed Brown CEED_EVAL_NONE); 448f0b65372SJed Brown CeedQFunctionAddInput(qf_ijacobian_vol, "x", num_comp_x, 449f0b65372SJed Brown CEED_EVAL_INTERP); 450f0b65372SJed Brown CeedQFunctionAddInput(qf_ijacobian_vol, "jac_data", 451f0b65372SJed Brown jac_data_size_vol, CEED_EVAL_NONE); 452f0b65372SJed Brown CeedQFunctionAddOutput(qf_ijacobian_vol, "v", num_comp_q, 453f0b65372SJed Brown CEED_EVAL_INTERP); 454f0b65372SJed Brown CeedQFunctionAddOutput(qf_ijacobian_vol, "Grad_v", num_comp_q*dim, 455f0b65372SJed Brown CEED_EVAL_GRAD); 456f0b65372SJed Brown } 457f0b65372SJed Brown 458a515125bSLeila Ghaffari // --------------------------------------------------------------------------- 459a515125bSLeila Ghaffari // Element coordinates 460a515125bSLeila Ghaffari // --------------------------------------------------------------------------- 461a515125bSLeila Ghaffari // -- Create CEED vector 462a515125bSLeila Ghaffari CeedElemRestrictionCreateVector(ceed_data->elem_restr_x, &ceed_data->x_coord, 463a515125bSLeila Ghaffari NULL); 464a515125bSLeila Ghaffari 465a515125bSLeila Ghaffari // -- Copy PETSc vector in CEED vector 466a515125bSLeila Ghaffari Vec X_loc; 467a515125bSLeila Ghaffari const PetscScalar *X_loc_array; 468*cac8aa24SJed Brown { 469*cac8aa24SJed Brown DM cdm; 470*cac8aa24SJed Brown ierr = DMGetCellCoordinateDM(dm, &cdm); CHKERRQ(ierr); 471*cac8aa24SJed Brown if (cdm) {ierr = DMGetCellCoordinatesLocal(dm, &X_loc); CHKERRQ(ierr);} 472*cac8aa24SJed Brown else {ierr = DMGetCoordinatesLocal(dm, &X_loc); CHKERRQ(ierr);} 473*cac8aa24SJed Brown } 47405a512bdSLeila Ghaffari ierr = VecScale(X_loc, problem->dm_scale); CHKERRQ(ierr); 475a515125bSLeila Ghaffari ierr = VecGetArrayRead(X_loc, &X_loc_array); CHKERRQ(ierr); 476a515125bSLeila Ghaffari CeedVectorSetArray(ceed_data->x_coord, CEED_MEM_HOST, CEED_COPY_VALUES, 477a515125bSLeila Ghaffari (PetscScalar *)X_loc_array); 478a515125bSLeila Ghaffari ierr = VecRestoreArrayRead(X_loc, &X_loc_array); CHKERRQ(ierr); 479a515125bSLeila Ghaffari 480a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 481a515125bSLeila Ghaffari // CEED vectors 482a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 483a515125bSLeila Ghaffari // -- Create CEED vector for geometric data 484a515125bSLeila Ghaffari CeedInt num_qpts_vol; 485a515125bSLeila Ghaffari PetscInt loc_num_elem_vol; 486a515125bSLeila Ghaffari CeedBasisGetNumQuadraturePoints(ceed_data->basis_q, &num_qpts_vol); 487a515125bSLeila Ghaffari CeedElemRestrictionGetNumElements(ceed_data->elem_restr_q, &loc_num_elem_vol); 488a515125bSLeila Ghaffari CeedVectorCreate(ceed, q_data_size_vol*loc_num_elem_vol*num_qpts_vol, 489a515125bSLeila Ghaffari &ceed_data->q_data); 490a515125bSLeila Ghaffari 491752f40e3SJed Brown CeedElemRestrictionCreateVector(elem_restr_jd_i, &jac_data, NULL); 492a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 493a515125bSLeila Ghaffari // CEED Operators 494a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 495a515125bSLeila Ghaffari // -- Create CEED operator for quadrature data 496a515125bSLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_setup_vol, NULL, NULL, 497a515125bSLeila Ghaffari &ceed_data->op_setup_vol); 498a515125bSLeila Ghaffari CeedOperatorSetField(ceed_data->op_setup_vol, "dx", ceed_data->elem_restr_x, 499a515125bSLeila Ghaffari ceed_data->basis_x, CEED_VECTOR_ACTIVE); 500a515125bSLeila Ghaffari CeedOperatorSetField(ceed_data->op_setup_vol, "weight", 501139613f2SLeila Ghaffari CEED_ELEMRESTRICTION_NONE, ceed_data->basis_x, CEED_VECTOR_NONE); 5023b1e209bSJeremy L Thompson CeedOperatorSetField(ceed_data->op_setup_vol, "qdata", 503139613f2SLeila Ghaffari ceed_data->elem_restr_qd_i, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); 504a515125bSLeila Ghaffari 505a515125bSLeila Ghaffari // -- Create CEED operator for ICs 506a515125bSLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_ics, NULL, NULL, &ceed_data->op_ics); 507a515125bSLeila Ghaffari CeedOperatorSetField(ceed_data->op_ics, "x", ceed_data->elem_restr_x, 508a515125bSLeila Ghaffari ceed_data->basis_xc, CEED_VECTOR_ACTIVE); 509a515125bSLeila Ghaffari CeedOperatorSetField(ceed_data->op_ics, "q0", ceed_data->elem_restr_q, 510a515125bSLeila Ghaffari CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); 51115a3537eSJed Brown CeedOperatorContextGetFieldLabel(ceed_data->op_ics, "evaluation time", 51215a3537eSJed Brown &user->phys->ics_time_label); 513a515125bSLeila Ghaffari 514a515125bSLeila Ghaffari // Create CEED operator for RHS 515a515125bSLeila Ghaffari if (ceed_data->qf_rhs_vol) { 516a515125bSLeila Ghaffari CeedOperator op; 517a515125bSLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_rhs_vol, NULL, NULL, &op); 518a515125bSLeila Ghaffari CeedOperatorSetField(op, "q", ceed_data->elem_restr_q, ceed_data->basis_q, 519a515125bSLeila Ghaffari CEED_VECTOR_ACTIVE); 520752f40e3SJed Brown CeedOperatorSetField(op, "Grad_q", ceed_data->elem_restr_q, ceed_data->basis_q, 521a515125bSLeila Ghaffari CEED_VECTOR_ACTIVE); 5223b1e209bSJeremy L Thompson CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i, 523139613f2SLeila Ghaffari CEED_BASIS_COLLOCATED, ceed_data->q_data); 524a515125bSLeila Ghaffari CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x, 525a515125bSLeila Ghaffari ceed_data->x_coord); 526a515125bSLeila Ghaffari CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q, 527a515125bSLeila Ghaffari CEED_VECTOR_ACTIVE); 528752f40e3SJed Brown CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q, 529a515125bSLeila Ghaffari CEED_VECTOR_ACTIVE); 530a515125bSLeila Ghaffari user->op_rhs_vol = op; 531a515125bSLeila Ghaffari } 532a515125bSLeila Ghaffari 533a515125bSLeila Ghaffari // -- CEED operator for IFunction 534a515125bSLeila Ghaffari if (ceed_data->qf_ifunction_vol) { 535a515125bSLeila Ghaffari CeedOperator op; 536a515125bSLeila Ghaffari CeedOperatorCreate(ceed, ceed_data->qf_ifunction_vol, NULL, NULL, &op); 537a515125bSLeila Ghaffari CeedOperatorSetField(op, "q", ceed_data->elem_restr_q, ceed_data->basis_q, 538a515125bSLeila Ghaffari CEED_VECTOR_ACTIVE); 539752f40e3SJed Brown CeedOperatorSetField(op, "Grad_q", ceed_data->elem_restr_q, ceed_data->basis_q, 540a515125bSLeila Ghaffari CEED_VECTOR_ACTIVE); 5413b1e209bSJeremy L Thompson CeedOperatorSetField(op, "q dot", ceed_data->elem_restr_q, ceed_data->basis_q, 542a515125bSLeila Ghaffari user->q_dot_ceed); 5433b1e209bSJeremy L Thompson CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i, 544139613f2SLeila Ghaffari CEED_BASIS_COLLOCATED, ceed_data->q_data); 545a515125bSLeila Ghaffari CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x, 546a515125bSLeila Ghaffari ceed_data->x_coord); 547a515125bSLeila Ghaffari CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q, 548a515125bSLeila Ghaffari CEED_VECTOR_ACTIVE); 549752f40e3SJed Brown CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q, 550a515125bSLeila Ghaffari CEED_VECTOR_ACTIVE); 551752f40e3SJed Brown CeedOperatorSetField(op, "jac_data", elem_restr_jd_i, 552752f40e3SJed Brown CEED_BASIS_COLLOCATED, jac_data); 553752f40e3SJed Brown 554a515125bSLeila Ghaffari user->op_ifunction_vol = op; 555a515125bSLeila Ghaffari } 556a515125bSLeila Ghaffari 557f0b65372SJed Brown CeedOperator op_ijacobian_vol = NULL; 558f0b65372SJed Brown if (qf_ijacobian_vol) { 559f0b65372SJed Brown CeedOperator op; 560f0b65372SJed Brown CeedOperatorCreate(ceed, qf_ijacobian_vol, NULL, NULL, &op); 561f0b65372SJed Brown CeedOperatorSetField(op, "dq", ceed_data->elem_restr_q, ceed_data->basis_q, 562f0b65372SJed Brown CEED_VECTOR_ACTIVE); 563f0b65372SJed Brown CeedOperatorSetField(op, "Grad_dq", ceed_data->elem_restr_q, ceed_data->basis_q, 564f0b65372SJed Brown CEED_VECTOR_ACTIVE); 565f0b65372SJed Brown CeedOperatorSetField(op, "qdata", ceed_data->elem_restr_qd_i, 566f0b65372SJed Brown CEED_BASIS_COLLOCATED, ceed_data->q_data); 567f0b65372SJed Brown CeedOperatorSetField(op, "x", ceed_data->elem_restr_x, ceed_data->basis_x, 568f0b65372SJed Brown ceed_data->x_coord); 569f0b65372SJed Brown CeedOperatorSetField(op, "jac_data", elem_restr_jd_i, 570f0b65372SJed Brown CEED_BASIS_COLLOCATED, jac_data); 571f0b65372SJed Brown CeedOperatorSetField(op, "v", ceed_data->elem_restr_q, ceed_data->basis_q, 572f0b65372SJed Brown CEED_VECTOR_ACTIVE); 573f0b65372SJed Brown CeedOperatorSetField(op, "Grad_v", ceed_data->elem_restr_q, ceed_data->basis_q, 574f0b65372SJed Brown CEED_VECTOR_ACTIVE); 575f0b65372SJed Brown op_ijacobian_vol = op; 576f0b65372SJed Brown CeedQFunctionDestroy(&qf_ijacobian_vol); 577f0b65372SJed Brown } 578f0b65372SJed Brown 579a515125bSLeila Ghaffari // ***************************************************************************** 580a515125bSLeila Ghaffari // Set up CEED objects for the exterior domain (surface) 581a515125bSLeila Ghaffari // ***************************************************************************** 582a515125bSLeila Ghaffari CeedInt height = 1, 583a515125bSLeila Ghaffari dim_sur = dim - height, 584a515125bSLeila Ghaffari P_sur = app_ctx->degree + 1, 585a515125bSLeila Ghaffari Q_sur = P_sur + app_ctx->q_extra; 586f0b65372SJed Brown const CeedInt q_data_size_sur = problem->q_data_size_sur, 587f0b65372SJed Brown jac_data_size_sur = problem->jac_data_size_sur; 588a515125bSLeila Ghaffari 589a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 590a515125bSLeila Ghaffari // CEED Bases 591a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 592a515125bSLeila Ghaffari CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_q, P_sur, Q_sur, 593a515125bSLeila Ghaffari CEED_GAUSS, &ceed_data->basis_q_sur); 594a515125bSLeila Ghaffari CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_x, 2, Q_sur, CEED_GAUSS, 595a515125bSLeila Ghaffari &ceed_data->basis_x_sur); 596da7e3aacSJames Wright CeedBasisCreateTensorH1Lagrange(ceed, dim_sur, num_comp_x, 2, P_sur, 597da7e3aacSJames Wright CEED_GAUSS_LOBATTO, &ceed_data->basis_xc_sur); 598a515125bSLeila Ghaffari 599a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 600a515125bSLeila Ghaffari // CEED QFunctions 601a515125bSLeila Ghaffari // ----------------------------------------------------------------------------- 602a515125bSLeila Ghaffari // -- Create QFunction for quadrature data 6039785fe93SJed Brown CeedQFunctionCreateInterior(ceed, 1, problem->setup_sur.qfunction, 6049785fe93SJed Brown problem->setup_sur.qfunction_loc, 605a515125bSLeila Ghaffari &ceed_data->qf_setup_sur); 60615a3537eSJed Brown if (problem->setup_sur.qfunction_context) { 60715a3537eSJed Brown CeedQFunctionSetContext(ceed_data->qf_setup_sur, 60815a3537eSJed Brown problem->setup_sur.qfunction_context); 60915a3537eSJed Brown CeedQFunctionContextDestroy(&problem->setup_sur.qfunction_context); 61015a3537eSJed Brown } 611a515125bSLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_setup_sur, "dx", num_comp_x*dim_sur, 612a515125bSLeila Ghaffari CEED_EVAL_GRAD); 613a515125bSLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_setup_sur, "weight", 1, CEED_EVAL_WEIGHT); 6143b1e209bSJeremy L Thompson CeedQFunctionAddOutput(ceed_data->qf_setup_sur, "surface qdata", 615002797a3SLeila Ghaffari q_data_size_sur, CEED_EVAL_NONE); 616a515125bSLeila Ghaffari 617002797a3SLeila Ghaffari // -- Creat QFunction for inflow boundaries 6189785fe93SJed Brown if (problem->apply_inflow.qfunction) { 6199785fe93SJed Brown CeedQFunctionCreateInterior(ceed, 1, problem->apply_inflow.qfunction, 6209785fe93SJed Brown problem->apply_inflow.qfunction_loc, &ceed_data->qf_apply_inflow); 62115a3537eSJed Brown CeedQFunctionSetContext(ceed_data->qf_apply_inflow, 62215a3537eSJed Brown problem->apply_inflow.qfunction_context); 62315a3537eSJed Brown CeedQFunctionContextDestroy(&problem->apply_inflow.qfunction_context); 624002797a3SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_apply_inflow, "q", num_comp_q, 625a515125bSLeila Ghaffari CEED_EVAL_INTERP); 626dd64951cSJames Wright CeedQFunctionAddInput(ceed_data->qf_apply_inflow, "Grad_q", num_comp_q*(dim-1), 627dd64951cSJames Wright CEED_EVAL_GRAD); 628002797a3SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_apply_inflow, "surface qdata", 629002797a3SLeila Ghaffari q_data_size_sur, CEED_EVAL_NONE); 630002797a3SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_apply_inflow, "x", num_comp_x, 631a515125bSLeila Ghaffari CEED_EVAL_INTERP); 632002797a3SLeila Ghaffari CeedQFunctionAddOutput(ceed_data->qf_apply_inflow, "v", num_comp_q, 633002797a3SLeila Ghaffari CEED_EVAL_INTERP); 63468ae065aSJames Wright if (jac_data_size_sur) 63568ae065aSJames Wright CeedQFunctionAddOutput(ceed_data->qf_apply_inflow, "surface jacobian data", 63668ae065aSJames Wright jac_data_size_sur, 63768ae065aSJames Wright CEED_EVAL_NONE); 638002797a3SLeila Ghaffari } 639f0b65372SJed Brown if (problem->apply_inflow_jacobian.qfunction) { 640f0b65372SJed Brown CeedQFunctionCreateInterior(ceed, 1, problem->apply_inflow_jacobian.qfunction, 641f0b65372SJed Brown problem->apply_inflow_jacobian.qfunction_loc, 642f0b65372SJed Brown &ceed_data->qf_apply_inflow_jacobian); 643f0b65372SJed Brown CeedQFunctionSetContext(ceed_data->qf_apply_inflow_jacobian, 644f0b65372SJed Brown problem->apply_inflow_jacobian.qfunction_context); 645f0b65372SJed Brown CeedQFunctionContextDestroy(&problem->apply_inflow_jacobian.qfunction_context); 646f0b65372SJed Brown CeedQFunctionAddInput(ceed_data->qf_apply_inflow_jacobian, "dq", num_comp_q, 647f0b65372SJed Brown CEED_EVAL_INTERP); 64868ae065aSJames Wright CeedQFunctionAddInput(ceed_data->qf_apply_inflow_jacobian, "Grad_dq", 64968ae065aSJames Wright num_comp_q*dim_sur, CEED_EVAL_GRAD); 650f0b65372SJed Brown CeedQFunctionAddInput(ceed_data->qf_apply_inflow_jacobian, "surface qdata", 651f0b65372SJed Brown q_data_size_sur, CEED_EVAL_NONE); 652f0b65372SJed Brown CeedQFunctionAddInput(ceed_data->qf_apply_inflow_jacobian, "x", num_comp_x, 653f0b65372SJed Brown CEED_EVAL_INTERP); 65468ae065aSJames Wright CeedQFunctionAddInput(ceed_data->qf_apply_inflow_jacobian, 65568ae065aSJames Wright "surface jacobian data", 65668ae065aSJames Wright jac_data_size_sur, CEED_EVAL_NONE); 657f0b65372SJed Brown CeedQFunctionAddOutput(ceed_data->qf_apply_inflow_jacobian, "v", num_comp_q, 658f0b65372SJed Brown CEED_EVAL_INTERP); 659f0b65372SJed Brown } 660002797a3SLeila Ghaffari 661002797a3SLeila Ghaffari // -- Creat QFunction for outflow boundaries 6629785fe93SJed Brown if (problem->apply_outflow.qfunction) { 6639785fe93SJed Brown CeedQFunctionCreateInterior(ceed, 1, problem->apply_outflow.qfunction, 6649785fe93SJed Brown problem->apply_outflow.qfunction_loc, &ceed_data->qf_apply_outflow); 66515a3537eSJed Brown CeedQFunctionSetContext(ceed_data->qf_apply_outflow, 66615a3537eSJed Brown problem->apply_outflow.qfunction_context); 66715a3537eSJed Brown CeedQFunctionContextDestroy(&problem->apply_outflow.qfunction_context); 668002797a3SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_apply_outflow, "q", num_comp_q, 669002797a3SLeila Ghaffari CEED_EVAL_INTERP); 670dd64951cSJames Wright CeedQFunctionAddInput(ceed_data->qf_apply_outflow, "Grad_q", num_comp_q*(dim-1), 671dd64951cSJames Wright CEED_EVAL_GRAD); 672002797a3SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_apply_outflow, "surface qdata", 673002797a3SLeila Ghaffari q_data_size_sur, CEED_EVAL_NONE); 674002797a3SLeila Ghaffari CeedQFunctionAddInput(ceed_data->qf_apply_outflow, "x", num_comp_x, 675002797a3SLeila Ghaffari CEED_EVAL_INTERP); 676002797a3SLeila Ghaffari CeedQFunctionAddOutput(ceed_data->qf_apply_outflow, "v", num_comp_q, 677a515125bSLeila Ghaffari CEED_EVAL_INTERP); 6782556a851SJed Brown if (jac_data_size_sur) 679f0b65372SJed Brown CeedQFunctionAddOutput(ceed_data->qf_apply_outflow, "surface jacobian data", 680f0b65372SJed Brown jac_data_size_sur, 681f0b65372SJed Brown CEED_EVAL_NONE); 682f0b65372SJed Brown } 683f0b65372SJed Brown if (problem->apply_outflow_jacobian.qfunction) { 684f0b65372SJed Brown CeedQFunctionCreateInterior(ceed, 1, problem->apply_outflow_jacobian.qfunction, 685f0b65372SJed Brown problem->apply_outflow_jacobian.qfunction_loc, 686f0b65372SJed Brown &ceed_data->qf_apply_outflow_jacobian); 687f0b65372SJed Brown CeedQFunctionSetContext(ceed_data->qf_apply_outflow_jacobian, 688f0b65372SJed Brown problem->apply_outflow_jacobian.qfunction_context); 689f0b65372SJed Brown CeedQFunctionContextDestroy(&problem->apply_outflow_jacobian.qfunction_context); 690f0b65372SJed Brown CeedQFunctionAddInput(ceed_data->qf_apply_outflow_jacobian, "dq", num_comp_q, 691f0b65372SJed Brown CEED_EVAL_INTERP); 69268ae065aSJames Wright CeedQFunctionAddInput(ceed_data->qf_apply_outflow_jacobian, "Grad_dq", 69368ae065aSJames Wright num_comp_q*dim_sur, CEED_EVAL_GRAD); 694f0b65372SJed Brown CeedQFunctionAddInput(ceed_data->qf_apply_outflow_jacobian, "surface qdata", 695f0b65372SJed Brown q_data_size_sur, CEED_EVAL_NONE); 696b01ba163SJames Wright CeedQFunctionAddInput(ceed_data->qf_apply_outflow_jacobian, "x", num_comp_x, 697b01ba163SJames Wright CEED_EVAL_INTERP); 698f0b65372SJed Brown CeedQFunctionAddInput(ceed_data->qf_apply_outflow_jacobian, 699f0b65372SJed Brown "surface jacobian data", 700f0b65372SJed Brown jac_data_size_sur, CEED_EVAL_NONE); 701f0b65372SJed Brown CeedQFunctionAddOutput(ceed_data->qf_apply_outflow_jacobian, "v", num_comp_q, 702f0b65372SJed Brown CEED_EVAL_INTERP); 703a515125bSLeila Ghaffari } 704a515125bSLeila Ghaffari 705a515125bSLeila Ghaffari // ***************************************************************************** 706a515125bSLeila Ghaffari // CEED Operator Apply 707a515125bSLeila Ghaffari // ***************************************************************************** 708a515125bSLeila Ghaffari // -- Apply CEED Operator for the geometric data 709a515125bSLeila Ghaffari CeedOperatorApply(ceed_data->op_setup_vol, ceed_data->x_coord, 710a515125bSLeila Ghaffari ceed_data->q_data, CEED_REQUEST_IMMEDIATE); 711a515125bSLeila Ghaffari 712a515125bSLeila Ghaffari // -- Create and apply CEED Composite Operator for the entire domain 713a515125bSLeila Ghaffari if (!user->phys->implicit) { // RHS 714a515125bSLeila Ghaffari ierr = CreateOperatorForDomain(ceed, dm, bc, ceed_data, user->phys, 715f0b65372SJed Brown user->op_rhs_vol, NULL, height, P_sur, Q_sur, 716f0b65372SJed Brown q_data_size_sur, 0, 717f0b65372SJed Brown &user->op_rhs, NULL); CHKERRQ(ierr); 718a515125bSLeila Ghaffari } else { // IFunction 719a515125bSLeila Ghaffari ierr = CreateOperatorForDomain(ceed, dm, bc, ceed_data, user->phys, 720f0b65372SJed Brown user->op_ifunction_vol, op_ijacobian_vol, 721f0b65372SJed Brown height, P_sur, Q_sur, 722f0b65372SJed Brown q_data_size_sur, jac_data_size_sur, 723f0b65372SJed Brown &user->op_ifunction, 724f0b65372SJed Brown op_ijacobian_vol ? &user->op_ijacobian : NULL); CHKERRQ(ierr); 725f0b65372SJed Brown if (user->op_ijacobian) { 726f0b65372SJed Brown CeedOperatorContextGetFieldLabel(user->op_ijacobian, "ijacobian time shift", 727f0b65372SJed Brown &user->phys->ijacobian_time_shift_label); 728f0b65372SJed Brown } 7296d0190e2SJames Wright if (problem->use_dirichlet_ceed) { 7306d0190e2SJames Wright PetscCall(SetupStrongBC_Ceed(ceed, ceed_data, dm, user, app_ctx, problem, bc, 7316d0190e2SJames Wright Q_sur, q_data_size_sur)); 7326d0190e2SJames Wright } 733f0b65372SJed Brown 734a515125bSLeila Ghaffari } 735752f40e3SJed Brown CeedElemRestrictionDestroy(&elem_restr_jd_i); 736e22e0f1cSLeila Ghaffari CeedOperatorDestroy(&op_ijacobian_vol); 737752f40e3SJed Brown CeedVectorDestroy(&jac_data); 738a515125bSLeila Ghaffari PetscFunctionReturn(0); 739a515125bSLeila Ghaffari } 740