1ae2b091fSJames Wright // SPDX-FileCopyrightText: Copyright (c) 2017-2024, HONEE contributors. 2ae2b091fSJames Wright // SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause 33a8779fbSJames Wright 43a8779fbSJames Wright /// @file 53a8779fbSJames Wright /// Utility functions for setting up problems using the Newtonian Qfunction 63a8779fbSJames Wright 73a8779fbSJames Wright #include "../qfunctions/newtonian.h" 83a8779fbSJames Wright 9e419654dSJeremy L Thompson #include <ceed.h> 10e419654dSJeremy L Thompson #include <petscdm.h> 11e419654dSJeremy L Thompson 12149fb536SJames Wright #include <navierstokes.h> 136dd99bedSLeila Ghaffari 1448417fb7SJames Wright static PetscErrorCode UnitTests_Newtonian(Honee honee, NewtonianIdealGasContext gas); 15f0b65372SJed Brown 1665dee3d2SJames Wright // @brief Create CeedOperator for stabilized mass KSP for explicit timestepping 1765dee3d2SJames Wright // 1865dee3d2SJames Wright // Only used for SUPG stabilization 190c373b74SJames Wright PetscErrorCode CreateKSPMassOperator_NewtonianStabilized(Honee honee, CeedOperator *op_mass) { 200c373b74SJames Wright Ceed ceed = honee->ceed; 2165dee3d2SJames Wright CeedInt num_comp_q, q_data_size; 2265dee3d2SJames Wright CeedQFunction qf_mass; 2301e19bfaSJames Wright CeedElemRestriction elem_restr_q, elem_restr_qd; 2465dee3d2SJames Wright CeedBasis basis_q; 2565dee3d2SJames Wright CeedVector q_data; 26236a8ba6SJames Wright CeedQFunctionContext qfctx = NULL; 2765dee3d2SJames Wright PetscInt dim = 3; 2865dee3d2SJames Wright 2965dee3d2SJames Wright PetscFunctionBeginUser; 3065dee3d2SJames Wright { // Get restriction and basis from the RHS function 3165dee3d2SJames Wright CeedOperator *sub_ops; 3201e19bfaSJames Wright CeedOperatorField op_field; 3365dee3d2SJames Wright PetscInt sub_op_index = 0; // will be 0 for the volume op 3465dee3d2SJames Wright 350c373b74SJames Wright PetscCallCeed(ceed, CeedCompositeOperatorGetSubList(honee->op_rhs_ctx->op, &sub_ops)); 3601e19bfaSJames Wright PetscCallCeed(ceed, CeedOperatorGetFieldByName(sub_ops[sub_op_index], "q", &op_field)); 3701e19bfaSJames Wright PetscCallCeed(ceed, CeedOperatorFieldGetData(op_field, NULL, &elem_restr_q, &basis_q, NULL)); 3801e19bfaSJames Wright PetscCallCeed(ceed, CeedOperatorGetFieldByName(sub_ops[sub_op_index], "qdata", &op_field)); 3901e19bfaSJames Wright PetscCallCeed(ceed, CeedOperatorFieldGetData(op_field, NULL, &elem_restr_qd, NULL, &q_data)); 4065dee3d2SJames Wright 41236a8ba6SJames Wright PetscCallCeed(ceed, CeedOperatorGetContext(sub_ops[sub_op_index], &qfctx)); 4265dee3d2SJames Wright } 4365dee3d2SJames Wright 4465dee3d2SJames Wright PetscCallCeed(ceed, CeedElemRestrictionGetNumComponents(elem_restr_q, &num_comp_q)); 4501e19bfaSJames Wright PetscCallCeed(ceed, CeedElemRestrictionGetNumComponents(elem_restr_qd, &q_data_size)); 4665dee3d2SJames Wright 4765dee3d2SJames Wright PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, MassFunction_Newtonian_Conserv, MassFunction_Newtonian_Conserv_loc, &qf_mass)); 4865dee3d2SJames Wright 49236a8ba6SJames Wright PetscCallCeed(ceed, CeedQFunctionSetContext(qf_mass, qfctx)); 5065dee3d2SJames Wright PetscCallCeed(ceed, CeedQFunctionSetUserFlopsEstimate(qf_mass, 0)); 5165dee3d2SJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(qf_mass, "q_dot", 5, CEED_EVAL_INTERP)); 5265dee3d2SJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(qf_mass, "q", 5, CEED_EVAL_INTERP)); 5365dee3d2SJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(qf_mass, "qdata", q_data_size, CEED_EVAL_NONE)); 5465dee3d2SJames Wright PetscCallCeed(ceed, CeedQFunctionAddOutput(qf_mass, "v", 5, CEED_EVAL_INTERP)); 5565dee3d2SJames Wright PetscCallCeed(ceed, CeedQFunctionAddOutput(qf_mass, "Grad_v", 5 * dim, CEED_EVAL_GRAD)); 5665dee3d2SJames Wright 5765dee3d2SJames Wright PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_mass, NULL, NULL, op_mass)); 5871f2ed29SJames Wright PetscCallCeed(ceed, CeedOperatorSetName(*op_mass, "RHS Mass Operator, Newtonian Stabilized")); 5965dee3d2SJames Wright PetscCallCeed(ceed, CeedOperatorSetField(*op_mass, "q_dot", elem_restr_q, basis_q, CEED_VECTOR_ACTIVE)); 600c373b74SJames Wright PetscCallCeed(ceed, CeedOperatorSetField(*op_mass, "q", elem_restr_q, basis_q, honee->q_ceed)); 6101e19bfaSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(*op_mass, "qdata", elem_restr_qd, CEED_BASIS_NONE, q_data)); 6265dee3d2SJames Wright PetscCallCeed(ceed, CeedOperatorSetField(*op_mass, "v", elem_restr_q, basis_q, CEED_VECTOR_ACTIVE)); 6365dee3d2SJames Wright PetscCallCeed(ceed, CeedOperatorSetField(*op_mass, "Grad_v", elem_restr_q, basis_q, CEED_VECTOR_ACTIVE)); 6465dee3d2SJames Wright 65fff85bd3SJames Wright PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_q)); 6601e19bfaSJames Wright PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_qd)); 67fff85bd3SJames Wright PetscCallCeed(ceed, CeedVectorDestroy(&q_data)); 68fff85bd3SJames Wright PetscCallCeed(ceed, CeedBasisDestroy(&basis_q)); 69236a8ba6SJames Wright PetscCallCeed(ceed, CeedQFunctionContextDestroy(&qfctx)); 7065dee3d2SJames Wright PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_mass)); 7165dee3d2SJames Wright PetscFunctionReturn(PETSC_SUCCESS); 7265dee3d2SJames Wright } 734c07ec22SJames Wright 7436038bbcSJames Wright /** 7536038bbcSJames Wright @brief Create RHS CeedOperator for direct projection of divergence of diffusive flux 7636038bbcSJames Wright 770c373b74SJames Wright @param[in] honee `Honee` context 7836038bbcSJames Wright @param[in] diff_flux_proj `DivDiffFluxProjectionData` object 7936038bbcSJames Wright @param[out] op_rhs Operator to calculate the RHS of the L^2 projection 8036038bbcSJames Wright **/ 81e3663b90SJames Wright static PetscErrorCode DivDiffFluxProjectionCreateRHS_Direct_NS(Honee honee, DivDiffFluxProjectionData diff_flux_proj, CeedOperator *op_rhs) { 820c373b74SJames Wright Ceed ceed = honee->ceed; 8336038bbcSJames Wright NodalProjectionData projection = diff_flux_proj->projection; 8436038bbcSJames Wright CeedInt num_comp_q; 8536038bbcSJames Wright PetscInt dim, label_value = 0; 8636038bbcSJames Wright DMLabel domain_label = NULL; 87236a8ba6SJames Wright CeedQFunctionContext newtonian_qfctx = NULL; 8836038bbcSJames Wright 8936038bbcSJames Wright PetscFunctionBeginUser; 9036038bbcSJames Wright // -- Get Pre-requisite things 9136038bbcSJames Wright PetscCall(DMGetDimension(projection->dm, &dim)); 92e3663b90SJames Wright PetscCallCeed(ceed, CeedBasisGetNumComponents(honee->basis_q, &num_comp_q)); 9336038bbcSJames Wright 940880fbb6SJames Wright { // Get newtonian QF context 95b3b24828SJames Wright CeedOperator *sub_ops, main_op = honee->op_ifunction ? honee->op_ifunction : honee->op_rhs_ctx->op; 9636038bbcSJames Wright PetscInt sub_op_index = 0; // will be 0 for the volume op 9736038bbcSJames Wright 98b3b24828SJames Wright PetscCallCeed(ceed, CeedCompositeOperatorGetSubList(main_op, &sub_ops)); 99236a8ba6SJames Wright PetscCallCeed(ceed, CeedOperatorGetContext(sub_ops[sub_op_index], &newtonian_qfctx)); 10036038bbcSJames Wright } 10136038bbcSJames Wright PetscCallCeed(ceed, CeedCompositeOperatorCreate(ceed, op_rhs)); 10236038bbcSJames Wright { // Add the volume integral CeedOperator 10336038bbcSJames Wright CeedQFunction qf_rhs_volume; 10436038bbcSJames Wright CeedOperator op_rhs_volume; 10536038bbcSJames Wright CeedVector q_data; 1060880fbb6SJames Wright CeedElemRestriction elem_restr_qd, elem_restr_diff_flux_volume = NULL; 1070880fbb6SJames Wright CeedBasis basis_diff_flux = NULL; 10836038bbcSJames Wright CeedInt q_data_size; 10936038bbcSJames Wright 1100880fbb6SJames Wright PetscCall(DivDiffFluxProjectionGetOperatorFieldData(diff_flux_proj, &elem_restr_diff_flux_volume, &basis_diff_flux, NULL, NULL)); 111e3663b90SJames Wright PetscCall(QDataGet(ceed, projection->dm, domain_label, label_value, honee->elem_restr_x, honee->basis_x, honee->x_coord, &elem_restr_qd, &q_data, 112e3663b90SJames Wright &q_data_size)); 1130c373b74SJames Wright switch (honee->phys->state_var) { 11436038bbcSJames Wright case STATEVAR_PRIMITIVE: 11536038bbcSJames Wright PetscCallCeed(ceed, 11636038bbcSJames Wright CeedQFunctionCreateInterior(ceed, 1, DivDiffusiveFluxVolumeRHS_NS_Prim, DivDiffusiveFluxVolumeRHS_NS_Prim_loc, &qf_rhs_volume)); 11736038bbcSJames Wright break; 11836038bbcSJames Wright case STATEVAR_CONSERVATIVE: 11936038bbcSJames Wright PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, DivDiffusiveFluxVolumeRHS_NS_Conserv, DivDiffusiveFluxVolumeRHS_NS_Conserv_loc, 12036038bbcSJames Wright &qf_rhs_volume)); 12136038bbcSJames Wright break; 12236038bbcSJames Wright case STATEVAR_ENTROPY: 12336038bbcSJames Wright PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, DivDiffusiveFluxVolumeRHS_NS_Entropy, DivDiffusiveFluxVolumeRHS_NS_Entropy_loc, 12436038bbcSJames Wright &qf_rhs_volume)); 12536038bbcSJames Wright break; 12636038bbcSJames Wright } 12736038bbcSJames Wright 128236a8ba6SJames Wright PetscCallCeed(ceed, CeedQFunctionSetContext(qf_rhs_volume, newtonian_qfctx)); 12936038bbcSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(qf_rhs_volume, "q", num_comp_q, CEED_EVAL_INTERP)); 13036038bbcSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(qf_rhs_volume, "Grad_q", num_comp_q * dim, CEED_EVAL_GRAD)); 13136038bbcSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(qf_rhs_volume, "qdata", q_data_size, CEED_EVAL_NONE)); 13236038bbcSJames Wright PetscCallCeed(ceed, CeedQFunctionAddOutput(qf_rhs_volume, "diffusive flux RHS", projection->num_comp * dim, CEED_EVAL_GRAD)); 13336038bbcSJames Wright 13436038bbcSJames Wright PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_rhs_volume, NULL, NULL, &op_rhs_volume)); 135e3663b90SJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_rhs_volume, "q", honee->elem_restr_q, honee->basis_q, CEED_VECTOR_ACTIVE)); 136e3663b90SJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_rhs_volume, "Grad_q", honee->elem_restr_q, honee->basis_q, CEED_VECTOR_ACTIVE)); 13736038bbcSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_rhs_volume, "qdata", elem_restr_qd, CEED_BASIS_NONE, q_data)); 13836038bbcSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_rhs_volume, "diffusive flux RHS", elem_restr_diff_flux_volume, basis_diff_flux, CEED_VECTOR_ACTIVE)); 13936038bbcSJames Wright 14036038bbcSJames Wright PetscCallCeed(ceed, CeedCompositeOperatorAddSub(*op_rhs, op_rhs_volume)); 14136038bbcSJames Wright 14236038bbcSJames Wright PetscCallCeed(ceed, CeedVectorDestroy(&q_data)); 14336038bbcSJames Wright PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_qd)); 1440880fbb6SJames Wright PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_diff_flux_volume)); 1450880fbb6SJames Wright PetscCallCeed(ceed, CeedBasisDestroy(&basis_diff_flux)); 14636038bbcSJames Wright PetscCallCeed(ceed, CeedOperatorDestroy(&op_rhs_volume)); 14736038bbcSJames Wright PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_rhs_volume)); 14836038bbcSJames Wright } 14936038bbcSJames Wright 15036038bbcSJames Wright { // Add the boundary integral CeedOperator 15136038bbcSJames Wright CeedQFunction qf_rhs_boundary; 15236038bbcSJames Wright DMLabel face_sets_label; 15336038bbcSJames Wright PetscInt num_face_set_values, *face_set_values; 15436038bbcSJames Wright CeedInt q_data_size; 15536038bbcSJames Wright 15636038bbcSJames Wright // -- Build RHS operator 1570c373b74SJames Wright switch (honee->phys->state_var) { 15836038bbcSJames Wright case STATEVAR_PRIMITIVE: 15936038bbcSJames Wright PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, DivDiffusiveFluxBoundaryRHS_NS_Prim, DivDiffusiveFluxBoundaryRHS_NS_Prim_loc, 16036038bbcSJames Wright &qf_rhs_boundary)); 16136038bbcSJames Wright break; 16236038bbcSJames Wright case STATEVAR_CONSERVATIVE: 16336038bbcSJames Wright PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, DivDiffusiveFluxBoundaryRHS_NS_Conserv, DivDiffusiveFluxBoundaryRHS_NS_Conserv_loc, 16436038bbcSJames Wright &qf_rhs_boundary)); 16536038bbcSJames Wright break; 16636038bbcSJames Wright case STATEVAR_ENTROPY: 16736038bbcSJames Wright PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, DivDiffusiveFluxBoundaryRHS_NS_Entropy, DivDiffusiveFluxBoundaryRHS_NS_Entropy_loc, 16836038bbcSJames Wright &qf_rhs_boundary)); 16936038bbcSJames Wright break; 17036038bbcSJames Wright } 17136038bbcSJames Wright 1720c373b74SJames Wright PetscCall(QDataBoundaryGradientGetNumComponents(honee->dm, &q_data_size)); 173236a8ba6SJames Wright PetscCallCeed(ceed, CeedQFunctionSetContext(qf_rhs_boundary, newtonian_qfctx)); 17436038bbcSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(qf_rhs_boundary, "q", num_comp_q, CEED_EVAL_INTERP)); 17536038bbcSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(qf_rhs_boundary, "Grad_q", num_comp_q * dim, CEED_EVAL_GRAD)); 17636038bbcSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(qf_rhs_boundary, "qdata", q_data_size, CEED_EVAL_NONE)); 17736038bbcSJames Wright PetscCallCeed(ceed, CeedQFunctionAddOutput(qf_rhs_boundary, "diffusive flux RHS", projection->num_comp, CEED_EVAL_INTERP)); 17836038bbcSJames Wright 17936038bbcSJames Wright PetscCall(DMGetLabel(projection->dm, "Face Sets", &face_sets_label)); 18036038bbcSJames Wright PetscCall(DMLabelCreateGlobalValueArray(projection->dm, face_sets_label, &num_face_set_values, &face_set_values)); 18136038bbcSJames Wright for (PetscInt f = 0; f < num_face_set_values; f++) { 18236038bbcSJames Wright DMLabel face_orientation_label; 18336038bbcSJames Wright PetscInt num_orientations_values, *orientation_values; 18436038bbcSJames Wright 18536038bbcSJames Wright { 18636038bbcSJames Wright char *face_orientation_label_name; 18736038bbcSJames Wright 18836038bbcSJames Wright PetscCall(DMPlexCreateFaceLabel(projection->dm, face_set_values[f], &face_orientation_label_name)); 18936038bbcSJames Wright PetscCall(DMGetLabel(projection->dm, face_orientation_label_name, &face_orientation_label)); 19036038bbcSJames Wright PetscCall(PetscFree(face_orientation_label_name)); 19136038bbcSJames Wright } 19236038bbcSJames Wright PetscCall(DMLabelCreateGlobalValueArray(projection->dm, face_orientation_label, &num_orientations_values, &orientation_values)); 19336038bbcSJames Wright for (PetscInt o = 0; o < num_orientations_values; o++) { 19436038bbcSJames Wright CeedOperator op_rhs_boundary; 19536038bbcSJames Wright CeedBasis basis_q, basis_diff_flux_boundary; 19636038bbcSJames Wright CeedElemRestriction elem_restr_qdata, elem_restr_q, elem_restr_diff_flux_boundary; 19736038bbcSJames Wright CeedVector q_data; 19836038bbcSJames Wright CeedInt q_data_size; 19936038bbcSJames Wright PetscInt orientation = orientation_values[o], dm_field_q = 0, height_cell = 0, height_face = 1; 20036038bbcSJames Wright 2010c373b74SJames Wright PetscCall(DMPlexCeedElemRestrictionCreate(ceed, honee->dm, face_orientation_label, orientation, height_cell, dm_field_q, &elem_restr_q)); 2020c373b74SJames Wright PetscCall(DMPlexCeedBasisCellToFaceCreate(ceed, honee->dm, face_orientation_label, orientation, orientation, dm_field_q, &basis_q)); 20336038bbcSJames Wright PetscCall(DMPlexCeedElemRestrictionCreate(ceed, projection->dm, face_orientation_label, orientation, height_face, 0, 20436038bbcSJames Wright &elem_restr_diff_flux_boundary)); 2050880fbb6SJames Wright PetscCall(CreateBasisFromPlex(ceed, projection->dm, face_orientation_label, orientation, height_face, 0, &basis_diff_flux_boundary)); 206e3663b90SJames Wright PetscCall( 207e3663b90SJames Wright QDataBoundaryGradientGet(ceed, honee->dm, face_orientation_label, orientation, honee->x_coord, &elem_restr_qdata, &q_data, &q_data_size)); 20836038bbcSJames Wright 20936038bbcSJames Wright PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_rhs_boundary, NULL, NULL, &op_rhs_boundary)); 21036038bbcSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_rhs_boundary, "q", elem_restr_q, basis_q, CEED_VECTOR_ACTIVE)); 21136038bbcSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_rhs_boundary, "Grad_q", elem_restr_q, basis_q, CEED_VECTOR_ACTIVE)); 21236038bbcSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_rhs_boundary, "qdata", elem_restr_qdata, CEED_BASIS_NONE, q_data)); 21336038bbcSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(op_rhs_boundary, "diffusive flux RHS", elem_restr_diff_flux_boundary, basis_diff_flux_boundary, 21436038bbcSJames Wright CEED_VECTOR_ACTIVE)); 21536038bbcSJames Wright 21636038bbcSJames Wright PetscCallCeed(ceed, CeedCompositeOperatorAddSub(*op_rhs, op_rhs_boundary)); 21736038bbcSJames Wright 21836038bbcSJames Wright PetscCallCeed(ceed, CeedOperatorDestroy(&op_rhs_boundary)); 21936038bbcSJames Wright PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_qdata)); 22036038bbcSJames Wright PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_q)); 22136038bbcSJames Wright PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_diff_flux_boundary)); 22236038bbcSJames Wright PetscCallCeed(ceed, CeedBasisDestroy(&basis_q)); 22336038bbcSJames Wright PetscCallCeed(ceed, CeedBasisDestroy(&basis_diff_flux_boundary)); 22436038bbcSJames Wright PetscCallCeed(ceed, CeedVectorDestroy(&q_data)); 22536038bbcSJames Wright } 22636038bbcSJames Wright PetscCall(PetscFree(orientation_values)); 22736038bbcSJames Wright } 22836038bbcSJames Wright PetscCall(PetscFree(face_set_values)); 22936038bbcSJames Wright PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_rhs_boundary)); 23036038bbcSJames Wright } 23136038bbcSJames Wright 232236a8ba6SJames Wright PetscCallCeed(ceed, CeedQFunctionContextDestroy(&newtonian_qfctx)); 23336038bbcSJames Wright PetscFunctionReturn(PETSC_SUCCESS); 23436038bbcSJames Wright } 23536038bbcSJames Wright 23636038bbcSJames Wright /** 23736038bbcSJames Wright @brief Create RHS CeedOperator for indirect projection of divergence of diffusive flux 23836038bbcSJames Wright 2390c373b74SJames Wright @param[in] honee `Honee` context 24036038bbcSJames Wright @param[in] diff_flux_proj `DivDiffFluxProjectionData` object 24136038bbcSJames Wright @param[out] op_rhs Operator to calculate the RHS of the L^2 projection 24236038bbcSJames Wright **/ 243e3663b90SJames Wright static PetscErrorCode DivDiffFluxProjectionCreateRHS_Indirect_NS(Honee honee, DivDiffFluxProjectionData diff_flux_proj, CeedOperator *op_rhs) { 2440c373b74SJames Wright Ceed ceed = honee->ceed; 24536038bbcSJames Wright NodalProjectionData projection = diff_flux_proj->projection; 24636038bbcSJames Wright CeedBasis basis_diff_flux; 24736038bbcSJames Wright CeedElemRestriction elem_restr_diff_flux, elem_restr_qd; 24836038bbcSJames Wright CeedVector q_data; 24936038bbcSJames Wright CeedInt num_comp_q, q_data_size; 25036038bbcSJames Wright PetscInt dim; 25136038bbcSJames Wright PetscInt label_value = 0, height = 0, dm_field = 0; 25236038bbcSJames Wright DMLabel domain_label = NULL; 25336038bbcSJames Wright CeedQFunction qf_rhs; 254236a8ba6SJames Wright CeedQFunctionContext newtonian_qfctx = NULL; 25536038bbcSJames Wright 25636038bbcSJames Wright PetscFunctionBeginUser; 25736038bbcSJames Wright PetscCall(DMGetDimension(projection->dm, &dim)); 258e3663b90SJames Wright PetscCallCeed(ceed, CeedBasisGetNumComponents(honee->basis_q, &num_comp_q)); 25936038bbcSJames Wright 26040b78511SJames Wright { // Get newtonian QF context 261b3b24828SJames Wright CeedOperator *sub_ops, main_op = honee->op_ifunction ? honee->op_ifunction : honee->op_rhs_ctx->op; 26236038bbcSJames Wright PetscInt sub_op_index = 0; // will be 0 for the volume op 26336038bbcSJames Wright 264b3b24828SJames Wright PetscCallCeed(ceed, CeedCompositeOperatorGetSubList(main_op, &sub_ops)); 265236a8ba6SJames Wright PetscCallCeed(ceed, CeedOperatorGetContext(sub_ops[sub_op_index], &newtonian_qfctx)); 26636038bbcSJames Wright } 26736038bbcSJames Wright PetscCall(DMPlexCeedElemRestrictionCreate(ceed, projection->dm, domain_label, label_value, height, dm_field, &elem_restr_diff_flux)); 26836038bbcSJames Wright PetscCall(CreateBasisFromPlex(ceed, projection->dm, domain_label, label_value, height, dm_field, &basis_diff_flux)); 269e3663b90SJames Wright PetscCall(QDataGet(ceed, projection->dm, domain_label, label_value, honee->elem_restr_x, honee->basis_x, honee->x_coord, &elem_restr_qd, &q_data, 270e3663b90SJames Wright &q_data_size)); 27136038bbcSJames Wright 2720c373b74SJames Wright switch (honee->phys->state_var) { 27336038bbcSJames Wright case STATEVAR_PRIMITIVE: 27436038bbcSJames Wright PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, DiffusiveFluxRHS_NS_Prim, DiffusiveFluxRHS_NS_Prim_loc, &qf_rhs)); 27536038bbcSJames Wright break; 27636038bbcSJames Wright case STATEVAR_CONSERVATIVE: 27736038bbcSJames Wright PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, DiffusiveFluxRHS_NS_Conserv, DiffusiveFluxRHS_NS_Conserv_loc, &qf_rhs)); 27836038bbcSJames Wright break; 27936038bbcSJames Wright case STATEVAR_ENTROPY: 28036038bbcSJames Wright PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, DiffusiveFluxRHS_NS_Entropy, DiffusiveFluxRHS_NS_Entropy_loc, &qf_rhs)); 28136038bbcSJames Wright break; 28236038bbcSJames Wright } 28336038bbcSJames Wright 284236a8ba6SJames Wright PetscCallCeed(ceed, CeedQFunctionSetContext(qf_rhs, newtonian_qfctx)); 28536038bbcSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(qf_rhs, "q", num_comp_q, CEED_EVAL_INTERP)); 28636038bbcSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(qf_rhs, "Grad_q", num_comp_q * dim, CEED_EVAL_GRAD)); 28736038bbcSJames Wright PetscCallCeed(ceed, CeedQFunctionAddInput(qf_rhs, "qdata", q_data_size, CEED_EVAL_NONE)); 28836038bbcSJames Wright PetscCallCeed(ceed, CeedQFunctionAddOutput(qf_rhs, "F_diff RHS", projection->num_comp, CEED_EVAL_INTERP)); 28936038bbcSJames Wright 29036038bbcSJames Wright PetscCallCeed(ceed, CeedOperatorCreate(ceed, qf_rhs, NULL, NULL, op_rhs)); 291e3663b90SJames Wright PetscCallCeed(ceed, CeedOperatorSetField(*op_rhs, "q", honee->elem_restr_q, honee->basis_q, CEED_VECTOR_ACTIVE)); 292e3663b90SJames Wright PetscCallCeed(ceed, CeedOperatorSetField(*op_rhs, "Grad_q", honee->elem_restr_q, honee->basis_q, CEED_VECTOR_ACTIVE)); 29336038bbcSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(*op_rhs, "qdata", elem_restr_qd, CEED_BASIS_NONE, q_data)); 29436038bbcSJames Wright PetscCallCeed(ceed, CeedOperatorSetField(*op_rhs, "F_diff RHS", elem_restr_diff_flux, basis_diff_flux, CEED_VECTOR_ACTIVE)); 29536038bbcSJames Wright 29636038bbcSJames Wright PetscCallCeed(ceed, CeedQFunctionDestroy(&qf_rhs)); 297236a8ba6SJames Wright PetscCallCeed(ceed, CeedQFunctionContextDestroy(&newtonian_qfctx)); 29836038bbcSJames Wright PetscCallCeed(ceed, CeedBasisDestroy(&basis_diff_flux)); 29936038bbcSJames Wright PetscCallCeed(ceed, CeedVectorDestroy(&q_data)); 30036038bbcSJames Wright PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_qd)); 30136038bbcSJames Wright PetscCallCeed(ceed, CeedElemRestrictionDestroy(&elem_restr_diff_flux)); 30236038bbcSJames Wright PetscFunctionReturn(PETSC_SUCCESS); 30336038bbcSJames Wright } 30436038bbcSJames Wright 305991aef52SJames Wright PetscErrorCode NS_NEWTONIAN_IG(ProblemData problem, DM dm, void *ctx, SimpleBC bc) { 306b7f03f12SJed Brown SetupContext setup_context; 3070c373b74SJames Wright Honee honee = *(Honee *)ctx; 3080c373b74SJames Wright CeedInt degree = honee->app_ctx->degree; 3093a8779fbSJames Wright StabilizationType stab; 3103636f6a4SJames Wright StateVariable state_var; 3110c373b74SJames Wright MPI_Comm comm = honee->comm; 3120c373b74SJames Wright Ceed ceed = honee->ceed; 3133a8779fbSJames Wright PetscBool implicit; 3140d8cd818SJames Wright PetscBool unit_tests; 31515a3537eSJed Brown NewtonianIdealGasContext newtonian_ig_ctx; 316e07531f7SJames Wright CeedQFunctionContext newtonian_ig_qfctx; 3173a8779fbSJames Wright 31815a3537eSJed Brown PetscFunctionBeginUser; 3192b916ea7SJeremy L Thompson PetscCall(PetscCalloc1(1, &setup_context)); 3202b916ea7SJeremy L Thompson PetscCall(PetscCalloc1(1, &newtonian_ig_ctx)); 3213a8779fbSJames Wright 3223a8779fbSJames Wright // ------------------------------------------------------ 3233a8779fbSJames Wright // Setup Generic Newtonian IG Problem 3243a8779fbSJames Wright // ------------------------------------------------------ 32528160fc2SJames Wright problem->jac_data_size_vol = 14; 326b01ba163SJames Wright problem->jac_data_size_sur = 11; 32758ce1233SJames Wright problem->compute_exact_solution_error = PETSC_FALSE; 328cbe60e31SLeila Ghaffari problem->print_info = PRINT_NEWTONIAN; 3293a8779fbSJames Wright 3300c373b74SJames Wright PetscCall(DivDiffFluxProjectionCreate(honee, 4, &honee->diff_flux_proj)); 3310c373b74SJames Wright if (honee->diff_flux_proj) { 3320c373b74SJames Wright DivDiffFluxProjectionData diff_flux_proj = honee->diff_flux_proj; 33336038bbcSJames Wright NodalProjectionData projection = diff_flux_proj->projection; 33436038bbcSJames Wright 33536038bbcSJames Wright diff_flux_proj->CreateRHSOperator_Direct = DivDiffFluxProjectionCreateRHS_Direct_NS; 33636038bbcSJames Wright diff_flux_proj->CreateRHSOperator_Indirect = DivDiffFluxProjectionCreateRHS_Indirect_NS; 33736038bbcSJames Wright 3380c373b74SJames Wright switch (honee->diff_flux_proj->method) { 33936038bbcSJames Wright case DIV_DIFF_FLUX_PROJ_DIRECT: { 34036038bbcSJames Wright PetscSection section; 34136038bbcSJames Wright 34236038bbcSJames Wright PetscCall(DMGetLocalSection(projection->dm, §ion)); 34336038bbcSJames Wright PetscCall(PetscSectionSetFieldName(section, 0, "")); 34436038bbcSJames Wright PetscCall(PetscSectionSetComponentName(section, 0, 0, "DivDiffusiveFlux_MomentumX")); 34536038bbcSJames Wright PetscCall(PetscSectionSetComponentName(section, 0, 1, "DivDiffusiveFlux_MomentumY")); 34636038bbcSJames Wright PetscCall(PetscSectionSetComponentName(section, 0, 2, "DivDiffusiveFlux_MomentumZ")); 34736038bbcSJames Wright PetscCall(PetscSectionSetComponentName(section, 0, 3, "DivDiffusiveFlux_Energy")); 34836038bbcSJames Wright } break; 34936038bbcSJames Wright case DIV_DIFF_FLUX_PROJ_INDIRECT: { 35036038bbcSJames Wright PetscSection section; 35136038bbcSJames Wright 35236038bbcSJames Wright PetscCall(DMGetLocalSection(projection->dm, §ion)); 35336038bbcSJames Wright PetscCall(PetscSectionSetFieldName(section, 0, "")); 35436038bbcSJames Wright PetscCall(PetscSectionSetComponentName(section, 0, 0, "DiffusiveFlux_MomentumXX")); 35536038bbcSJames Wright PetscCall(PetscSectionSetComponentName(section, 0, 1, "DiffusiveFlux_MomentumXY")); 35636038bbcSJames Wright PetscCall(PetscSectionSetComponentName(section, 0, 2, "DiffusiveFlux_MomentumXZ")); 35736038bbcSJames Wright PetscCall(PetscSectionSetComponentName(section, 0, 3, "DiffusiveFlux_MomentumYX")); 35836038bbcSJames Wright PetscCall(PetscSectionSetComponentName(section, 0, 4, "DiffusiveFlux_MomentumYY")); 35936038bbcSJames Wright PetscCall(PetscSectionSetComponentName(section, 0, 5, "DiffusiveFlux_MomentumYZ")); 36036038bbcSJames Wright PetscCall(PetscSectionSetComponentName(section, 0, 6, "DiffusiveFlux_MomentumZX")); 36136038bbcSJames Wright PetscCall(PetscSectionSetComponentName(section, 0, 7, "DiffusiveFlux_MomentumZY")); 36236038bbcSJames Wright PetscCall(PetscSectionSetComponentName(section, 0, 8, "DiffusiveFlux_MomentumZZ")); 36336038bbcSJames Wright PetscCall(PetscSectionSetComponentName(section, 0, 9, "DiffusiveFlux_EnergyX")); 36436038bbcSJames Wright PetscCall(PetscSectionSetComponentName(section, 0, 10, "DiffusiveFlux_EnergyY")); 36536038bbcSJames Wright PetscCall(PetscSectionSetComponentName(section, 0, 11, "DiffusiveFlux_EnergyZ")); 36636038bbcSJames Wright } break; 36736038bbcSJames Wright case DIV_DIFF_FLUX_PROJ_NONE: 3680c373b74SJames Wright SETERRQ(PetscObjectComm((PetscObject)honee->dm), PETSC_ERR_ARG_WRONG, "Should not reach here with div_diff_flux_projection_method %s", 3690c373b74SJames Wright DivDiffFluxProjectionMethods[honee->app_ctx->divFdiffproj_method]); 37036038bbcSJames Wright break; 37136038bbcSJames Wright } 37236038bbcSJames Wright } 37336038bbcSJames Wright 3743a8779fbSJames Wright // ------------------------------------------------------ 375ea615d4cSJames Wright // Create the QFunction context 3763a8779fbSJames Wright // ------------------------------------------------------ 3773a8779fbSJames Wright CeedScalar cv = 717.; // J/(kg K) 3783a8779fbSJames Wright CeedScalar cp = 1004.; // J/(kg K) 379d9bb1cdbSJames Wright CeedScalar g[3] = {0, 0, 0}; // m/s^2 3803a8779fbSJames Wright CeedScalar lambda = -2. / 3.; // - 381bb8a0c61SJames Wright CeedScalar mu = 1.8e-5; // Pa s, dynamic viscosity 3823a8779fbSJames Wright CeedScalar k = 0.02638; // W/(m K) 3834351d27fSLeila Ghaffari CeedScalar c_tau = 0.5 / degree; // - 384bb8a0c61SJames Wright CeedScalar Ctau_t = 1.0; // - 385b5786772SLeila Ghaffari CeedScalar Cv_func[3] = {36, 60, 128}; 386c176988bSLeila Ghaffari CeedScalar Ctau_v = Cv_func[(CeedInt)Min(3, degree) - 1]; 3872a0eee6eSLeila Ghaffari CeedScalar Ctau_C = 0.25 / degree; 3882a0eee6eSLeila Ghaffari CeedScalar Ctau_M = 0.25 / degree; 3892a0eee6eSLeila Ghaffari CeedScalar Ctau_E = 0.125; 3903a8779fbSJames Wright PetscReal domain_min[3], domain_max[3], domain_size[3]; 3912b916ea7SJeremy L Thompson PetscCall(DMGetBoundingBox(dm, domain_min, domain_max)); 392493642f1SJames Wright for (PetscInt i = 0; i < 3; i++) domain_size[i] = domain_max[i] - domain_min[i]; 3933a8779fbSJames Wright 394b8fb7609SAdeleke O. Bankole StatePrimitive reference = {.pressure = 1.01e5, .velocity = {0}, .temperature = 288.15}; 395a213b8aaSJames Wright CeedScalar idl_decay_time = -1, idl_start = 0, idl_length = 0, idl_pressure = reference.pressure; 396e7754af5SKenneth E. Jansen PetscBool idl_enable = PETSC_FALSE; 397b8fb7609SAdeleke O. Bankole 3983a8779fbSJames Wright // ------------------------------------------------------ 3993a8779fbSJames Wright // Create the PETSc context 4003a8779fbSJames Wright // ------------------------------------------------------ 401bb8a0c61SJames Wright PetscScalar meter = 1; // 1 meter in scaled length units 402bb8a0c61SJames Wright PetscScalar kilogram = 1; // 1 kilogram in scaled mass units 403bb8a0c61SJames Wright PetscScalar second = 1; // 1 second in scaled time units 4043a8779fbSJames Wright PetscScalar Kelvin = 1; // 1 Kelvin in scaled temperature units 4053a8779fbSJames Wright PetscScalar W_per_m_K, Pascal, J_per_kg_K, m_per_squared_s; 4063a8779fbSJames Wright 4073a8779fbSJames Wright // ------------------------------------------------------ 4083a8779fbSJames Wright // Command line Options 4093a8779fbSJames Wright // ------------------------------------------------------ 410d9bb1cdbSJames Wright PetscBool given_option = PETSC_FALSE; 4112b916ea7SJeremy L Thompson PetscOptionsBegin(comm, NULL, "Options for Newtonian Ideal Gas based problem", NULL); 412cbe60e31SLeila Ghaffari // -- Conservative vs Primitive variables 4132b916ea7SJeremy L Thompson PetscCall(PetscOptionsEnum("-state_var", "State variables used", NULL, StateVariables, (PetscEnum)(state_var = STATEVAR_CONSERVATIVE), 4142b916ea7SJeremy L Thompson (PetscEnum *)&state_var, NULL)); 4153636f6a4SJames Wright 4163636f6a4SJames Wright switch (state_var) { 4173636f6a4SJames Wright case STATEVAR_CONSERVATIVE: 418e07531f7SJames Wright problem->ics.qf_func_ptr = ICsNewtonianIG_Conserv; 419e07531f7SJames Wright problem->ics.qf_loc = ICsNewtonianIG_Conserv_loc; 420e07531f7SJames Wright problem->apply_vol_rhs.qf_func_ptr = RHSFunction_Newtonian; 421e07531f7SJames Wright problem->apply_vol_rhs.qf_loc = RHSFunction_Newtonian_loc; 422e07531f7SJames Wright problem->apply_vol_ifunction.qf_func_ptr = IFunction_Newtonian_Conserv; 423e07531f7SJames Wright problem->apply_vol_ifunction.qf_loc = IFunction_Newtonian_Conserv_loc; 424e07531f7SJames Wright problem->apply_vol_ijacobian.qf_func_ptr = IJacobian_Newtonian_Conserv; 425e07531f7SJames Wright problem->apply_vol_ijacobian.qf_loc = IJacobian_Newtonian_Conserv_loc; 426e07531f7SJames Wright problem->apply_inflow.qf_func_ptr = BoundaryIntegral_Conserv; 427e07531f7SJames Wright problem->apply_inflow.qf_loc = BoundaryIntegral_Conserv_loc; 428e07531f7SJames Wright problem->apply_inflow_jacobian.qf_func_ptr = BoundaryIntegral_Jacobian_Conserv; 429e07531f7SJames Wright problem->apply_inflow_jacobian.qf_loc = BoundaryIntegral_Jacobian_Conserv_loc; 4303636f6a4SJames Wright break; 4313636f6a4SJames Wright case STATEVAR_PRIMITIVE: 432e07531f7SJames Wright problem->ics.qf_func_ptr = ICsNewtonianIG_Prim; 433e07531f7SJames Wright problem->ics.qf_loc = ICsNewtonianIG_Prim_loc; 434e07531f7SJames Wright problem->apply_vol_ifunction.qf_func_ptr = IFunction_Newtonian_Prim; 435e07531f7SJames Wright problem->apply_vol_ifunction.qf_loc = IFunction_Newtonian_Prim_loc; 436e07531f7SJames Wright problem->apply_vol_ijacobian.qf_func_ptr = IJacobian_Newtonian_Prim; 437e07531f7SJames Wright problem->apply_vol_ijacobian.qf_loc = IJacobian_Newtonian_Prim_loc; 438e07531f7SJames Wright problem->apply_inflow.qf_func_ptr = BoundaryIntegral_Prim; 439e07531f7SJames Wright problem->apply_inflow.qf_loc = BoundaryIntegral_Prim_loc; 440e07531f7SJames Wright problem->apply_inflow_jacobian.qf_func_ptr = BoundaryIntegral_Jacobian_Prim; 441e07531f7SJames Wright problem->apply_inflow_jacobian.qf_loc = BoundaryIntegral_Jacobian_Prim_loc; 4423636f6a4SJames Wright break; 443c62f7daeSJames Wright case STATEVAR_ENTROPY: 444e07531f7SJames Wright problem->ics.qf_func_ptr = ICsNewtonianIG_Entropy; 445e07531f7SJames Wright problem->ics.qf_loc = ICsNewtonianIG_Entropy_loc; 446e07531f7SJames Wright problem->apply_vol_ifunction.qf_func_ptr = IFunction_Newtonian_Entropy; 447e07531f7SJames Wright problem->apply_vol_ifunction.qf_loc = IFunction_Newtonian_Entropy_loc; 448e07531f7SJames Wright problem->apply_vol_ijacobian.qf_func_ptr = IJacobian_Newtonian_Entropy; 449e07531f7SJames Wright problem->apply_vol_ijacobian.qf_loc = IJacobian_Newtonian_Entropy_loc; 450e07531f7SJames Wright problem->apply_inflow.qf_func_ptr = BoundaryIntegral_Entropy; 451e07531f7SJames Wright problem->apply_inflow.qf_loc = BoundaryIntegral_Entropy_loc; 452e07531f7SJames Wright problem->apply_inflow_jacobian.qf_func_ptr = BoundaryIntegral_Jacobian_Entropy; 453e07531f7SJames Wright problem->apply_inflow_jacobian.qf_loc = BoundaryIntegral_Jacobian_Entropy_loc; 454c62f7daeSJames Wright break; 455cbe60e31SLeila Ghaffari } 4561485969bSJeremy L Thompson 4573a8779fbSJames Wright // -- Physics 4582b916ea7SJeremy L Thompson PetscCall(PetscOptionsScalar("-cv", "Heat capacity at constant volume", NULL, cv, &cv, NULL)); 4592b916ea7SJeremy L Thompson PetscCall(PetscOptionsScalar("-cp", "Heat capacity at constant pressure", NULL, cp, &cp, NULL)); 4602b916ea7SJeremy L Thompson PetscCall(PetscOptionsScalar("-lambda", "Stokes hypothesis second viscosity coefficient", NULL, lambda, &lambda, NULL)); 4612b916ea7SJeremy L Thompson PetscCall(PetscOptionsScalar("-mu", "Shear dynamic viscosity coefficient", NULL, mu, &mu, NULL)); 4622b916ea7SJeremy L Thompson PetscCall(PetscOptionsScalar("-k", "Thermal conductivity", NULL, k, &k, NULL)); 4633a8779fbSJames Wright 46466d54740SJames Wright PetscInt dim = 3; 465d9bb1cdbSJames Wright PetscCall(PetscOptionsDeprecated("-g", "-gravity", "libCEED 0.11.1", NULL)); 466d9bb1cdbSJames Wright PetscCall(PetscOptionsRealArray("-gravity", "Gravitational acceleration vector", NULL, g, &dim, &given_option)); 467d9bb1cdbSJames Wright if (given_option) PetscCheck(dim == 3, comm, PETSC_ERR_ARG_SIZ, "Gravity vector must be size 3, %" PetscInt_FMT " values given", dim); 468d9bb1cdbSJames Wright 4692b916ea7SJeremy L Thompson PetscCall(PetscOptionsEnum("-stab", "Stabilization method", NULL, StabilizationTypes, (PetscEnum)(stab = STAB_NONE), (PetscEnum *)&stab, NULL)); 4702b916ea7SJeremy L Thompson PetscCall(PetscOptionsScalar("-c_tau", "Stabilization constant", NULL, c_tau, &c_tau, NULL)); 4712b916ea7SJeremy L Thompson PetscCall(PetscOptionsScalar("-Ctau_t", "Stabilization time constant", NULL, Ctau_t, &Ctau_t, NULL)); 4722b916ea7SJeremy L Thompson PetscCall(PetscOptionsScalar("-Ctau_v", "Stabilization viscous constant", NULL, Ctau_v, &Ctau_v, NULL)); 4732b916ea7SJeremy L Thompson PetscCall(PetscOptionsScalar("-Ctau_C", "Stabilization continuity constant", NULL, Ctau_C, &Ctau_C, NULL)); 4742b916ea7SJeremy L Thompson PetscCall(PetscOptionsScalar("-Ctau_M", "Stabilization momentum constant", NULL, Ctau_M, &Ctau_M, NULL)); 4752b916ea7SJeremy L Thompson PetscCall(PetscOptionsScalar("-Ctau_E", "Stabilization energy constant", NULL, Ctau_E, &Ctau_E, NULL)); 4762b916ea7SJeremy L Thompson PetscCall(PetscOptionsBool("-implicit", "Use implicit (IFunction) formulation", NULL, implicit = PETSC_FALSE, &implicit, NULL)); 4772b916ea7SJeremy L Thompson PetscCall(PetscOptionsBool("-newtonian_unit_tests", "Run Newtonian unit tests", NULL, unit_tests = PETSC_FALSE, &unit_tests, NULL)); 4783a8779fbSJames Wright 479db95602eSJames Wright dim = 3; 480b8fb7609SAdeleke O. Bankole PetscCall(PetscOptionsScalar("-reference_pressure", "Reference/initial pressure", NULL, reference.pressure, &reference.pressure, NULL)); 481b8fb7609SAdeleke O. Bankole PetscCall(PetscOptionsScalarArray("-reference_velocity", "Reference/initial velocity", NULL, reference.velocity, &dim, NULL)); 482b8fb7609SAdeleke O. Bankole PetscCall(PetscOptionsScalar("-reference_temperature", "Reference/initial temperature", NULL, reference.temperature, &reference.temperature, NULL)); 483b8fb7609SAdeleke O. Bankole 4843a8779fbSJames Wright // -- Units 4852b916ea7SJeremy L Thompson PetscCall(PetscOptionsScalar("-units_meter", "1 meter in scaled length units", NULL, meter, &meter, NULL)); 4863a8779fbSJames Wright meter = fabs(meter); 4872b916ea7SJeremy L Thompson PetscCall(PetscOptionsScalar("-units_kilogram", "1 kilogram in scaled mass units", NULL, kilogram, &kilogram, NULL)); 4883a8779fbSJames Wright kilogram = fabs(kilogram); 4892b916ea7SJeremy L Thompson PetscCall(PetscOptionsScalar("-units_second", "1 second in scaled time units", NULL, second, &second, NULL)); 4903a8779fbSJames Wright second = fabs(second); 4912b916ea7SJeremy L Thompson PetscCall(PetscOptionsScalar("-units_Kelvin", "1 Kelvin in scaled temperature units", NULL, Kelvin, &Kelvin, NULL)); 4923a8779fbSJames Wright Kelvin = fabs(Kelvin); 4933a8779fbSJames Wright 4943a8779fbSJames Wright // -- Warnings 4955d28dccaSJames Wright PetscCheck(!(state_var == STATEVAR_PRIMITIVE && !implicit), comm, PETSC_ERR_SUP, 4965d28dccaSJames Wright "RHSFunction is not provided for primitive variables (use -state_var primitive only with -implicit)\n"); 497e7754af5SKenneth E. Jansen 498e7754af5SKenneth E. Jansen PetscCall(PetscOptionsScalar("-idl_decay_time", "Characteristic timescale of the pressure deviance decay. The timestep is good starting point", 499e7754af5SKenneth E. Jansen NULL, idl_decay_time, &idl_decay_time, &idl_enable)); 5009cbdf780SJames Wright PetscCheck(!(idl_enable && idl_decay_time == 0), comm, PETSC_ERR_SUP, "idl_decay_time may not be equal to zero."); 5019cbdf780SJames Wright if (idl_decay_time < 0) idl_enable = PETSC_FALSE; 50228160fc2SJames Wright if (idl_enable) problem->jac_data_size_vol++; 503e7754af5SKenneth E. Jansen PetscCall(PetscOptionsScalar("-idl_start", "Start of IDL in the x direction", NULL, idl_start, &idl_start, NULL)); 504e7754af5SKenneth E. Jansen PetscCall(PetscOptionsScalar("-idl_length", "Length of IDL in the positive x direction", NULL, idl_length, &idl_length, NULL)); 505a213b8aaSJames Wright idl_pressure = reference.pressure; 506a213b8aaSJames Wright PetscCall(PetscOptionsScalar("-idl_pressure", "Pressure IDL uses as reference (default is `-reference_pressure`)", NULL, idl_pressure, 507a213b8aaSJames Wright &idl_pressure, NULL)); 5081485969bSJeremy L Thompson PetscOptionsEnd(); 5093a8779fbSJames Wright 51065dee3d2SJames Wright if (stab == STAB_SUPG && !implicit) problem->create_mass_operator = CreateKSPMassOperator_NewtonianStabilized; 51165dee3d2SJames Wright 5123a8779fbSJames Wright // ------------------------------------------------------ 5133a8779fbSJames Wright // Set up the PETSc context 5143a8779fbSJames Wright // ------------------------------------------------------ 5153a8779fbSJames Wright // -- Define derived units 5163a8779fbSJames Wright Pascal = kilogram / (meter * PetscSqr(second)); 5173a8779fbSJames Wright J_per_kg_K = PetscSqr(meter) / (PetscSqr(second) * Kelvin); 5183a8779fbSJames Wright m_per_squared_s = meter / PetscSqr(second); 5193a8779fbSJames Wright W_per_m_K = kilogram * meter / (pow(second, 3) * Kelvin); 5203a8779fbSJames Wright 5210c373b74SJames Wright honee->units->meter = meter; 5220c373b74SJames Wright honee->units->kilogram = kilogram; 5230c373b74SJames Wright honee->units->second = second; 5240c373b74SJames Wright honee->units->Kelvin = Kelvin; 5250c373b74SJames Wright honee->units->Pascal = Pascal; 5260c373b74SJames Wright honee->units->J_per_kg_K = J_per_kg_K; 5270c373b74SJames Wright honee->units->m_per_squared_s = m_per_squared_s; 5280c373b74SJames Wright honee->units->W_per_m_K = W_per_m_K; 5293a8779fbSJames Wright 5303a8779fbSJames Wright // ------------------------------------------------------ 531ea615d4cSJames Wright // Set up the QFunction context 5323a8779fbSJames Wright // ------------------------------------------------------ 5333a8779fbSJames Wright // -- Scale variables to desired units 5343a8779fbSJames Wright cv *= J_per_kg_K; 5353a8779fbSJames Wright cp *= J_per_kg_K; 5363a8779fbSJames Wright mu *= Pascal * second; 5373a8779fbSJames Wright k *= W_per_m_K; 538493642f1SJames Wright for (PetscInt i = 0; i < 3; i++) domain_size[i] *= meter; 539493642f1SJames Wright for (PetscInt i = 0; i < 3; i++) g[i] *= m_per_squared_s; 540b8fb7609SAdeleke O. Bankole reference.pressure *= Pascal; 541b8fb7609SAdeleke O. Bankole for (PetscInt i = 0; i < 3; i++) reference.velocity[i] *= meter / second; 542b8fb7609SAdeleke O. Bankole reference.temperature *= Kelvin; 5433a8779fbSJames Wright 5443a8779fbSJames Wright // -- Solver Settings 5450c373b74SJames Wright honee->phys->implicit = implicit; 5460c373b74SJames Wright honee->phys->state_var = state_var; 5473a8779fbSJames Wright 5483a8779fbSJames Wright // -- QFunction Context 54915a3537eSJed Brown newtonian_ig_ctx->lambda = lambda; 55015a3537eSJed Brown newtonian_ig_ctx->mu = mu; 55115a3537eSJed Brown newtonian_ig_ctx->k = k; 55215a3537eSJed Brown newtonian_ig_ctx->cv = cv; 55315a3537eSJed Brown newtonian_ig_ctx->cp = cp; 55415a3537eSJed Brown newtonian_ig_ctx->c_tau = c_tau; 55515a3537eSJed Brown newtonian_ig_ctx->Ctau_t = Ctau_t; 55615a3537eSJed Brown newtonian_ig_ctx->Ctau_v = Ctau_v; 55715a3537eSJed Brown newtonian_ig_ctx->Ctau_C = Ctau_C; 55815a3537eSJed Brown newtonian_ig_ctx->Ctau_M = Ctau_M; 55915a3537eSJed Brown newtonian_ig_ctx->Ctau_E = Ctau_E; 56015a3537eSJed Brown newtonian_ig_ctx->stabilization = stab; 5618085925cSJames Wright newtonian_ig_ctx->is_implicit = implicit; 5623636f6a4SJames Wright newtonian_ig_ctx->state_var = state_var; 563e7754af5SKenneth E. Jansen newtonian_ig_ctx->idl_enable = idl_enable; 564e7754af5SKenneth E. Jansen newtonian_ig_ctx->idl_amplitude = 1 / (idl_decay_time * second); 565e7754af5SKenneth E. Jansen newtonian_ig_ctx->idl_start = idl_start * meter; 566e7754af5SKenneth E. Jansen newtonian_ig_ctx->idl_length = idl_length * meter; 567a213b8aaSJames Wright newtonian_ig_ctx->idl_pressure = idl_pressure; 5680c373b74SJames Wright newtonian_ig_ctx->divFdiff_method = honee->app_ctx->divFdiffproj_method; 5692b916ea7SJeremy L Thompson PetscCall(PetscArraycpy(newtonian_ig_ctx->g, g, 3)); 5703a8779fbSJames Wright 571b8fb7609SAdeleke O. Bankole // -- Setup Context 572b8fb7609SAdeleke O. Bankole setup_context->reference = reference; 573b8fb7609SAdeleke O. Bankole setup_context->gas = *newtonian_ig_ctx; 574b8fb7609SAdeleke O. Bankole setup_context->lx = domain_size[0]; 575b8fb7609SAdeleke O. Bankole setup_context->ly = domain_size[1]; 576b8fb7609SAdeleke O. Bankole setup_context->lz = domain_size[2]; 577b8fb7609SAdeleke O. Bankole setup_context->time = 0; 578b8fb7609SAdeleke O. Bankole 5790c373b74SJames Wright PetscCallCeed(ceed, CeedQFunctionContextCreate(honee->ceed, &problem->ics.qfctx)); 580e07531f7SJames Wright PetscCallCeed(ceed, CeedQFunctionContextSetData(problem->ics.qfctx, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*setup_context), setup_context)); 581e07531f7SJames Wright PetscCallCeed(ceed, CeedQFunctionContextSetDataDestroy(problem->ics.qfctx, CEED_MEM_HOST, FreeContextPetsc)); 582e07531f7SJames Wright PetscCallCeed( 583e07531f7SJames Wright ceed, CeedQFunctionContextRegisterDouble(problem->ics.qfctx, "evaluation time", offsetof(struct SetupContext_, time), 1, "Time of evaluation")); 58415a3537eSJed Brown 5850c373b74SJames Wright PetscCallCeed(ceed, CeedQFunctionContextCreate(honee->ceed, &newtonian_ig_qfctx)); 586e07531f7SJames Wright PetscCallCeed(ceed, CeedQFunctionContextSetData(newtonian_ig_qfctx, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(*newtonian_ig_ctx), newtonian_ig_ctx)); 587e07531f7SJames Wright PetscCallCeed(ceed, CeedQFunctionContextSetDataDestroy(newtonian_ig_qfctx, CEED_MEM_HOST, FreeContextPetsc)); 588e07531f7SJames Wright PetscCallCeed(ceed, CeedQFunctionContextRegisterDouble(newtonian_ig_qfctx, "timestep size", offsetof(struct NewtonianIdealGasContext_, dt), 1, 589b4c37c5cSJames Wright "Size of timestep, delta t")); 590e07531f7SJames Wright PetscCallCeed(ceed, CeedQFunctionContextRegisterDouble(newtonian_ig_qfctx, "ijacobian time shift", 591b4c37c5cSJames Wright offsetof(struct NewtonianIdealGasContext_, ijacobian_time_shift), 1, 592b4c37c5cSJames Wright "Shift for mass matrix in IJacobian")); 593e07531f7SJames Wright PetscCallCeed(ceed, CeedQFunctionContextRegisterDouble(newtonian_ig_qfctx, "solution time", offsetof(struct NewtonianIdealGasContext_, time), 1, 594b4c37c5cSJames Wright "Current solution time")); 595a8bca8acSJames Wright 596e07531f7SJames Wright problem->apply_vol_rhs.qfctx = newtonian_ig_qfctx; 597e07531f7SJames Wright PetscCallCeed(ceed, CeedQFunctionContextReferenceCopy(newtonian_ig_qfctx, &problem->apply_vol_ifunction.qfctx)); 598e07531f7SJames Wright PetscCallCeed(ceed, CeedQFunctionContextReferenceCopy(newtonian_ig_qfctx, &problem->apply_vol_ijacobian.qfctx)); 599e07531f7SJames Wright PetscCallCeed(ceed, CeedQFunctionContextReferenceCopy(newtonian_ig_qfctx, &problem->apply_inflow.qfctx)); 600e07531f7SJames Wright PetscCallCeed(ceed, CeedQFunctionContextReferenceCopy(newtonian_ig_qfctx, &problem->apply_inflow_jacobian.qfctx)); 601f0b65372SJed Brown 6025e79d562SJames Wright for (PetscCount b = 0; b < problem->num_bc_defs; b++) { 6035e79d562SJames Wright BCDefinition bc_def = problem->bc_defs[b]; 6045e79d562SJames Wright const char *name; 6055e79d562SJames Wright 6065e79d562SJames Wright PetscCall(BCDefinitionGetInfo(bc_def, &name, NULL, NULL)); 6075e79d562SJames Wright if (!strcmp(name, "slip")) { 6085e79d562SJames Wright PetscCall(SlipBCSetup(bc_def, problem, dm, ctx, newtonian_ig_qfctx)); 609d4e423e7SJames Wright } else if (!strcmp(name, "freestream")) { 610d4e423e7SJames Wright PetscCall(FreestreamBCSetup(bc_def, problem, dm, ctx, newtonian_ig_ctx, &reference)); 611*f978755dSJames Wright } else if (!strcmp(name, "outflow")) { 612*f978755dSJames Wright PetscCall(OutflowBCSetup(bc_def, problem, dm, ctx, newtonian_ig_ctx, &reference)); 6135e79d562SJames Wright } 6145e79d562SJames Wright } 6159ed3d70dSJames Wright 616f0b65372SJed Brown if (unit_tests) { 6170c373b74SJames Wright PetscCall(UnitTests_Newtonian(honee, newtonian_ig_ctx)); 618f0b65372SJed Brown } 619d949ddfcSJames Wright PetscFunctionReturn(PETSC_SUCCESS); 6203a8779fbSJames Wright } 6213a8779fbSJames Wright 6220c373b74SJames Wright PetscErrorCode PRINT_NEWTONIAN(Honee honee, ProblemData problem, AppCtx app_ctx) { 6230c373b74SJames Wright MPI_Comm comm = honee->comm; 6240c373b74SJames Wright Ceed ceed = honee->ceed; 62515a3537eSJed Brown NewtonianIdealGasContext newtonian_ctx; 62615a3537eSJed Brown 6273a8779fbSJames Wright PetscFunctionBeginUser; 628e07531f7SJames Wright PetscCallCeed(ceed, CeedQFunctionContextGetData(problem->apply_vol_rhs.qfctx, CEED_MEM_HOST, &newtonian_ctx)); 6292b916ea7SJeremy L Thompson PetscCall(PetscPrintf(comm, 63015a3537eSJed Brown " Problem:\n" 63115a3537eSJed Brown " Problem Name : %s\n" 63215a3537eSJed Brown " Stabilization : %s\n", 6332b916ea7SJeremy L Thompson app_ctx->problem_name, StabilizationTypes[newtonian_ctx->stabilization])); 634e07531f7SJames Wright PetscCallCeed(ceed, CeedQFunctionContextRestoreData(problem->apply_vol_rhs.qfctx, &newtonian_ctx)); 635d949ddfcSJames Wright PetscFunctionReturn(PETSC_SUCCESS); 6363a8779fbSJames Wright } 63748417fb7SJames Wright 63848417fb7SJames Wright static PetscErrorCode CheckQWithTolerance(const CeedScalar Q_s[5], const CeedScalar Q_a[5], const CeedScalar Q_b[5], const char *name, 63948417fb7SJames Wright PetscReal rtol_0, PetscReal rtol_u, PetscReal rtol_4) { 64048417fb7SJames Wright CeedScalar relative_error[5]; // relative error 64148417fb7SJames Wright CeedScalar divisor_threshold = 10 * CEED_EPSILON; 64248417fb7SJames Wright 64348417fb7SJames Wright PetscFunctionBeginUser; 64448417fb7SJames Wright relative_error[0] = (Q_a[0] - Q_b[0]) / (fabs(Q_s[0]) > divisor_threshold ? Q_s[0] : 1); 64548417fb7SJames Wright relative_error[4] = (Q_a[4] - Q_b[4]) / (fabs(Q_s[4]) > divisor_threshold ? Q_s[4] : 1); 64648417fb7SJames Wright 64748417fb7SJames Wright CeedScalar u_magnitude = sqrt(Square(Q_s[1]) + Square(Q_s[2]) + Square(Q_s[3])); 64848417fb7SJames Wright CeedScalar u_divisor = u_magnitude > divisor_threshold ? u_magnitude : 1; 64948417fb7SJames Wright for (int i = 1; i < 4; i++) { 65048417fb7SJames Wright relative_error[i] = (Q_a[i] - Q_b[i]) / u_divisor; 65148417fb7SJames Wright } 65248417fb7SJames Wright 65348417fb7SJames Wright if (fabs(relative_error[0]) >= rtol_0) { 65448417fb7SJames Wright printf("%s[0] error %g (expected %.10e, got %.10e)\n", name, relative_error[0], Q_s[0], Q_a[0]); 65548417fb7SJames Wright } 65648417fb7SJames Wright for (int i = 1; i < 4; i++) { 65748417fb7SJames Wright if (fabs(relative_error[i]) >= rtol_u) { 65848417fb7SJames Wright printf("%s[%d] error %g (expected %.10e, got %.10e)\n", name, i, relative_error[i], Q_s[i], Q_a[i]); 65948417fb7SJames Wright } 66048417fb7SJames Wright } 66148417fb7SJames Wright if (fabs(relative_error[4]) >= rtol_4) { 66248417fb7SJames Wright printf("%s[4] error %g (expected %.10e, got %.10e)\n", name, relative_error[4], Q_s[4], Q_a[4]); 66348417fb7SJames Wright } 66448417fb7SJames Wright PetscFunctionReturn(PETSC_SUCCESS); 66548417fb7SJames Wright } 66648417fb7SJames Wright 66748417fb7SJames Wright // @brief Verify `StateFromQ` by converting A0 -> B0 -> A0_test, where A0 should equal A0_test 66848417fb7SJames Wright static PetscErrorCode TestState(StateVariable state_var_A, StateVariable state_var_B, NewtonianIdealGasContext gas, const CeedScalar A0[5], 66948417fb7SJames Wright CeedScalar rtol_0, CeedScalar rtol_u, CeedScalar rtol_4) { 67048417fb7SJames Wright CeedScalar B0[5], A0_test[5]; 67148417fb7SJames Wright char buf[128]; 67248417fb7SJames Wright const char *const StateVariables_Initial[] = {"U", "Y", "V"}; 67348417fb7SJames Wright 67448417fb7SJames Wright PetscFunctionBeginUser; 67548417fb7SJames Wright const char *A_initial = StateVariables_Initial[state_var_A]; 67648417fb7SJames Wright const char *B_initial = StateVariables_Initial[state_var_B]; 67748417fb7SJames Wright 67848417fb7SJames Wright State state_A0 = StateFromQ(gas, A0, state_var_A); 67948417fb7SJames Wright StateToQ(gas, state_A0, B0, state_var_B); 68048417fb7SJames Wright State state_B0 = StateFromQ(gas, B0, state_var_B); 68148417fb7SJames Wright StateToQ(gas, state_B0, A0_test, state_var_A); 68248417fb7SJames Wright 68348417fb7SJames Wright snprintf(buf, sizeof buf, "%s->%s->%s: %s", A_initial, B_initial, A_initial, A_initial); 68448417fb7SJames Wright PetscCall(CheckQWithTolerance(A0, A0_test, A0, buf, rtol_0, rtol_u, rtol_4)); 68548417fb7SJames Wright PetscFunctionReturn(PETSC_SUCCESS); 68648417fb7SJames Wright } 68748417fb7SJames Wright 68848417fb7SJames Wright // @brief Verify `StateFromQ_fwd` via a finite difference approximation 68948417fb7SJames Wright static PetscErrorCode TestState_fwd(StateVariable state_var_A, StateVariable state_var_B, NewtonianIdealGasContext gas, const CeedScalar A0[5], 69048417fb7SJames Wright CeedScalar rtol_0, CeedScalar rtol_u, CeedScalar rtol_4) { 69148417fb7SJames Wright CeedScalar eps = 4e-7; // Finite difference step 69248417fb7SJames Wright char buf[128]; 69348417fb7SJames Wright const char *const StateVariables_Initial[] = {"U", "Y", "V"}; 69448417fb7SJames Wright 69548417fb7SJames Wright PetscFunctionBeginUser; 69648417fb7SJames Wright const char *A_initial = StateVariables_Initial[state_var_A]; 69748417fb7SJames Wright const char *B_initial = StateVariables_Initial[state_var_B]; 69848417fb7SJames Wright State state_0 = StateFromQ(gas, A0, state_var_A); 69948417fb7SJames Wright 70048417fb7SJames Wright for (int i = 0; i < 5; i++) { 70148417fb7SJames Wright CeedScalar dB[5] = {0.}, dB_fd[5] = {0.}; 70248417fb7SJames Wright { // Calculate dB using State functions 70348417fb7SJames Wright CeedScalar dA[5] = {0}; 70448417fb7SJames Wright 70548417fb7SJames Wright dA[i] = A0[i]; 70648417fb7SJames Wright State dstate_0 = StateFromQ_fwd(gas, state_0, dA, state_var_A); 70748417fb7SJames Wright StateToQ_fwd(gas, state_0, dstate_0, dB, state_var_B); 70848417fb7SJames Wright } 70948417fb7SJames Wright 71048417fb7SJames Wright { // Calculate dB_fd via finite difference approximation 71148417fb7SJames Wright CeedScalar A1[5], B0[5], B1[5]; 71248417fb7SJames Wright 71348417fb7SJames Wright for (int j = 0; j < 5; j++) A1[j] = (1 + eps * (i == j)) * A0[j]; 71448417fb7SJames Wright State state_1 = StateFromQ(gas, A1, state_var_A); 71548417fb7SJames Wright StateToQ(gas, state_0, B0, state_var_B); 71648417fb7SJames Wright StateToQ(gas, state_1, B1, state_var_B); 71748417fb7SJames Wright for (int j = 0; j < 5; j++) dB_fd[j] = (B1[j] - B0[j]) / eps; 71848417fb7SJames Wright } 71948417fb7SJames Wright 72048417fb7SJames Wright snprintf(buf, sizeof buf, "d%s->d%s: StateFrom%s_fwd i=%d: d%s", A_initial, B_initial, A_initial, i, B_initial); 72148417fb7SJames Wright PetscCall(CheckQWithTolerance(dB_fd, dB, dB_fd, buf, rtol_0, rtol_u, rtol_4)); 72248417fb7SJames Wright } 72348417fb7SJames Wright PetscFunctionReturn(PETSC_SUCCESS); 72448417fb7SJames Wright } 72548417fb7SJames Wright 72648417fb7SJames Wright // @brief Test the Newtonian State transformation functions, `StateFrom*` 72748417fb7SJames Wright static PetscErrorCode UnitTests_Newtonian(Honee honee, NewtonianIdealGasContext gas) { 72848417fb7SJames Wright Units units = honee->units; 72948417fb7SJames Wright const CeedScalar kg = units->kilogram, m = units->meter, sec = units->second, K = units->Kelvin; 73048417fb7SJames Wright CeedScalar rtol; 73148417fb7SJames Wright 73248417fb7SJames Wright PetscFunctionBeginUser; 73348417fb7SJames Wright const CeedScalar T = 200 * K; 73448417fb7SJames Wright const CeedScalar rho = 1.2 * kg / Cube(m); 73548417fb7SJames Wright const CeedScalar P = (HeatCapacityRatio(gas) - 1) * rho * gas->cv * T; 73648417fb7SJames Wright const CeedScalar u_base = 40 * m / sec; 73748417fb7SJames Wright const CeedScalar u[3] = {u_base, u_base * 1.1, u_base * 1.2}; 73848417fb7SJames Wright const CeedScalar e_kinetic = 0.5 * Dot3(u, u); 73948417fb7SJames Wright const CeedScalar e_internal = gas->cv * T; 74048417fb7SJames Wright const CeedScalar e_total = e_kinetic + e_internal; 74148417fb7SJames Wright const CeedScalar gamma = HeatCapacityRatio(gas); 74248417fb7SJames Wright const CeedScalar entropy = log(P) - gamma * log(rho); 74348417fb7SJames Wright const CeedScalar rho_div_p = rho / P; 74448417fb7SJames Wright const CeedScalar Y0[5] = {P, u[0], u[1], u[2], T}; 74548417fb7SJames Wright const CeedScalar U0[5] = {rho, rho * u[0], rho * u[1], rho * u[2], rho * e_total}; 74648417fb7SJames Wright const CeedScalar V0[5] = {(gamma - entropy) / (gamma - 1) - rho_div_p * (e_kinetic), rho_div_p * u[0], rho_div_p * u[1], rho_div_p * u[2], 74748417fb7SJames Wright -rho_div_p}; 74848417fb7SJames Wright 74948417fb7SJames Wright rtol = 20 * CEED_EPSILON; 75048417fb7SJames Wright PetscCall(TestState(STATEVAR_PRIMITIVE, STATEVAR_CONSERVATIVE, gas, Y0, rtol, rtol, rtol)); 75148417fb7SJames Wright PetscCall(TestState(STATEVAR_PRIMITIVE, STATEVAR_ENTROPY, gas, Y0, rtol, rtol, rtol)); 75248417fb7SJames Wright PetscCall(TestState(STATEVAR_CONSERVATIVE, STATEVAR_PRIMITIVE, gas, U0, rtol, rtol, rtol)); 75348417fb7SJames Wright PetscCall(TestState(STATEVAR_CONSERVATIVE, STATEVAR_ENTROPY, gas, U0, rtol, rtol, rtol)); 75448417fb7SJames Wright PetscCall(TestState(STATEVAR_ENTROPY, STATEVAR_CONSERVATIVE, gas, V0, rtol, rtol, rtol)); 75548417fb7SJames Wright PetscCall(TestState(STATEVAR_ENTROPY, STATEVAR_PRIMITIVE, gas, V0, rtol, rtol, rtol)); 75648417fb7SJames Wright 75748417fb7SJames Wright rtol = 5e-6; 75848417fb7SJames Wright PetscCall(TestState_fwd(STATEVAR_PRIMITIVE, STATEVAR_CONSERVATIVE, gas, Y0, rtol, rtol, rtol)); 75948417fb7SJames Wright PetscCall(TestState_fwd(STATEVAR_PRIMITIVE, STATEVAR_ENTROPY, gas, Y0, rtol, rtol, rtol)); 76048417fb7SJames Wright PetscCall(TestState_fwd(STATEVAR_CONSERVATIVE, STATEVAR_PRIMITIVE, gas, U0, rtol, rtol, rtol)); 76148417fb7SJames Wright PetscCall(TestState_fwd(STATEVAR_CONSERVATIVE, STATEVAR_ENTROPY, gas, U0, 10 * rtol, rtol, rtol)); 76248417fb7SJames Wright PetscCall(TestState_fwd(STATEVAR_ENTROPY, STATEVAR_CONSERVATIVE, gas, V0, 5 * rtol, rtol, rtol)); 76348417fb7SJames Wright PetscCall(TestState_fwd(STATEVAR_ENTROPY, STATEVAR_PRIMITIVE, gas, V0, 5 * rtol, 5 * rtol, 5 * rtol)); 76448417fb7SJames Wright PetscFunctionReturn(PETSC_SUCCESS); 76548417fb7SJames Wright } 766