// Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors. // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. // // SPDX-License-Identifier: BSD-2-Clause // // This file is part of CEED: http://github.com/ceed /// @file /// Operator for Navier-Stokes example using PETSc #ifndef blasius_h #define blasius_h #include #include "newtonian_state.h" #include "newtonian_types.h" #include "utils.h" #define BLASIUS_MAX_N_CHEBYSHEV 50 typedef struct BlasiusContext_ *BlasiusContext; struct BlasiusContext_ { bool implicit; // !< Using implicit timesteping or not bool weakT; // !< flag to set Temperature weakly at inflow CeedScalar delta0; // !< Boundary layer height at inflow CeedScalar U_inf; // !< Velocity at boundary layer edge CeedScalar T_inf; // !< Temperature at boundary layer edge CeedScalar T_wall; // !< Temperature at the wall CeedScalar P0; // !< Pressure at outflow CeedScalar x_inflow; // !< Location of inflow in x CeedScalar n_cheb; // !< Number of Chebyshev terms CeedScalar *X; // !< Chebyshev polynomial coordinate vector (CPU only) CeedScalar eta_max; // !< Maximum eta in the domain CeedScalar Tf_cheb[BLASIUS_MAX_N_CHEBYSHEV]; // !< Chebyshev coefficient for f CeedScalar Th_cheb[BLASIUS_MAX_N_CHEBYSHEV-1]; // !< Chebyshev coefficient for h struct NewtonianIdealGasContext_ newtonian_ctx; }; // ***************************************************************************** // This helper function evaluates Chebyshev polynomials with a set of // coefficients with all their derivatives represented as a recurrence table. // ***************************************************************************** CEED_QFUNCTION_HELPER void ChebyshevEval(int N, const double *Tf, double x, double eta_max, double *f) { double dX_deta = 2 / eta_max; double table[4][3] = { // Chebyshev polynomials T_0, T_1, T_2 of the first kind in (-1,1) {1, x, 2*x *x - 1}, {0, 1, 4*x}, {0, 0, 4}, {0, 0, 0} }; for (int i=0; i<4; i++) { // i-th derivative of f f[i] = table[i][0] * Tf[0] + table[i][1] * Tf[1] + table[i][2] * Tf[2]; } for (int i=3; in_cheb; CeedScalar mu = blasius->newtonian_ctx.mu; CeedScalar nu = mu / rho_infty; CeedScalar eta = x[1]*sqrt(blasius->U_inf/(nu*(x0+x[0]-x_inflow))); CeedScalar X = 2 * (eta / blasius->eta_max) - 1.; CeedScalar U_inf = blasius->U_inf; CeedScalar Rd = GasConstant(&blasius->newtonian_ctx); CeedScalar f[4], h[4]; ChebyshevEval(N, blasius->Tf_cheb, X, blasius->eta_max, f); ChebyshevEval(N-1, blasius->Th_cheb, X, blasius->eta_max, h); *t12 = mu*U_inf*f[2]*sqrt(U_inf/(nu*(x0+x[0]-x_inflow))); CeedScalar Y[5]; Y[1] = U_inf * f[1]; Y[2] = 0.5*sqrt(nu*U_inf/(x0+x[0]-x_inflow))*(eta*f[1] - f[0]); Y[3] = 0.; Y[4] = blasius->T_inf * h[0]; Y[0] = rho_infty / h[0] * Rd * Y[4]; return StateFromY(&blasius->newtonian_ctx, Y, x); } // ***************************************************************************** // This QFunction sets a Blasius boundary layer for the initial condition // ***************************************************************************** CEED_QFUNCTION(ICsBlasius)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { // Inputs const CeedScalar (*X)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0]; // Outputs CeedScalar (*q0)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; const BlasiusContext context = (BlasiusContext)ctx; const CeedScalar cv = context->newtonian_ctx.cv; const CeedScalar mu = context->newtonian_ctx.mu; const CeedScalar T_inf = context->T_inf; const CeedScalar P0 = context->P0; const CeedScalar delta0 = context->delta0; const CeedScalar U_inf = context->U_inf; const CeedScalar x_inflow = context->x_inflow; const CeedScalar gamma = HeatCapacityRatio(&context->newtonian_ctx); const CeedScalar e_internal = cv * T_inf; const CeedScalar rho = P0 / ((gamma - 1) * e_internal); const CeedScalar x0 = U_inf*rho / (mu*25/(delta0*delta0)); CeedScalar t12; // Quadrature Point Loop CeedPragmaSIMD for (CeedInt i=0; iimplicit; NewtonianIdealGasContext gas = &context->newtonian_ctx; const CeedScalar mu = context->newtonian_ctx.mu; const CeedScalar Rd = GasConstant(&context->newtonian_ctx); const CeedScalar T_inf = context->T_inf; const CeedScalar P0 = context->P0; const CeedScalar delta0 = context->delta0; const CeedScalar U_inf = context->U_inf; const CeedScalar x_inflow = context->x_inflow; const bool weakT = context->weakT; const CeedScalar rho_0 = P0 / (Rd * T_inf); const CeedScalar x0 = U_inf*rho_0 / (mu*25/ Square(delta0)); CeedPragmaSIMD // Quadrature Point Loop for (CeedInt i=0; inewtonian_ctx, s, Flux_inviscid); const CeedScalar stress[3][3] = {{0, t12, 0}, {t12, 0, 0}, {0, 0, 0}}; const CeedScalar Fe[3] = {0}; // TODO: viscous energy flux needs grad temperature CeedScalar Flux[5]; FluxTotal_Boundary(Flux_inviscid, stress, Fe, norm, Flux); for (CeedInt j=0; j<5; j++) v[j][i] = -wdetJb * Flux[j]; } // End Quadrature Point Loop return 0; } // ***************************************************************************** CEED_QFUNCTION(Blasius_Inflow_Jacobian)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { // *INDENT-OFF* // Inputs const CeedScalar (*dq)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0], (*q_data_sur)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[2], (*X)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[3]; // Outputs CeedScalar (*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; // *INDENT-ON* const BlasiusContext context = (BlasiusContext)ctx; const bool implicit = context->implicit; const CeedScalar mu = context->newtonian_ctx.mu; const CeedScalar cv = context->newtonian_ctx.cv; const CeedScalar Rd = GasConstant(&context->newtonian_ctx); const CeedScalar gamma = HeatCapacityRatio(&context->newtonian_ctx); const CeedScalar T_inf = context->T_inf; const CeedScalar P0 = context->P0; const CeedScalar delta0 = context->delta0; const CeedScalar U_inf = context->U_inf; const bool weakT = context->weakT; const CeedScalar rho_0 = P0 / (Rd * T_inf); const CeedScalar x0 = U_inf*rho_0 / (mu*25/ (delta0*delta0)); CeedPragmaSIMD // Quadrature Point Loop for (CeedInt i=0; i