13d8e8822SJeremy L Thompson // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors. 23d8e8822SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 377841947SLeila Ghaffari // 43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause 577841947SLeila Ghaffari // 63d8e8822SJeremy L Thompson // This file is part of CEED: http://github.com/ceed 777841947SLeila Ghaffari 877841947SLeila Ghaffari /// @file 977841947SLeila Ghaffari /// Advection initial condition and operator for Navier-Stokes example using PETSc 1077841947SLeila Ghaffari 1177841947SLeila Ghaffari #ifndef advection_h 1277841947SLeila Ghaffari #define advection_h 1377841947SLeila Ghaffari 14ba6664aeSJames Wright #include <ceed.h> 15c9c2c079SJeremy L Thompson #include <math.h> 1677841947SLeila Ghaffari 1730e1b2c7SJames Wright #include "advection_generic.h" 18c44b1c7dSJames Wright #include "advection_types.h" 198f4d89c8SJames Wright #include "newtonian_state.h" 208f4d89c8SJames Wright #include "newtonian_types.h" 21c44b1c7dSJames Wright #include "stabilization_types.h" 228756a6ccSJames Wright #include "utils.h" 238756a6ccSJames Wright 2477841947SLeila Ghaffari // ***************************************************************************** 2577841947SLeila Ghaffari // This QFunction sets the initial conditions for 3D advection 2677841947SLeila Ghaffari // ***************************************************************************** 272b730f8bSJeremy L Thompson CEED_QFUNCTION(ICsAdvection)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 2877841947SLeila Ghaffari const CeedScalar(*X)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0]; 2977841947SLeila Ghaffari CeedScalar(*q0)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; 3077841947SLeila Ghaffari 3146603fc5SJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 3277841947SLeila Ghaffari const CeedScalar x[] = {X[0][i], X[1][i], X[2][i]}; 33e6225c47SLeila Ghaffari CeedScalar q[5] = {0.}; 3477841947SLeila Ghaffari 3530e1b2c7SJames Wright Exact_AdvectionGeneric(3, 0., x, 5, q, ctx); 3677841947SLeila Ghaffari for (CeedInt j = 0; j < 5; j++) q0[j][i] = q[j]; 3730e1b2c7SJames Wright } 3877841947SLeila Ghaffari return 0; 3977841947SLeila Ghaffari } 4077841947SLeila Ghaffari 4177841947SLeila Ghaffari // ***************************************************************************** 4277841947SLeila Ghaffari // This QFunction implements the following formulation of the advection equation 4377841947SLeila Ghaffari // 4477841947SLeila Ghaffari // This is 3D advection given in two formulations based upon the weak form. 4577841947SLeila Ghaffari // 4677841947SLeila Ghaffari // State Variables: q = ( rho, U1, U2, U3, E ) 4777841947SLeila Ghaffari // rho - Mass Density 4877841947SLeila Ghaffari // Ui - Momentum Density , Ui = rho ui 4977841947SLeila Ghaffari // E - Total Energy Density 5077841947SLeila Ghaffari // 5177841947SLeila Ghaffari // Advection Equation: 5277841947SLeila Ghaffari // dE/dt + div( E u ) = 0 5377841947SLeila Ghaffari // ***************************************************************************** 542b730f8bSJeremy L Thompson CEED_QFUNCTION(Advection)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 55*b28affb2SJames Wright RHSFunction_AdvectionGeneric(ctx, Q, in, out, 3); 5677841947SLeila Ghaffari return 0; 5777841947SLeila Ghaffari } 5877841947SLeila Ghaffari 592b730f8bSJeremy L Thompson CEED_QFUNCTION(IFunction_Advection)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 60372d1924SJames Wright IFunction_AdvectionGeneric(ctx, Q, in, out, 3); 6177841947SLeila Ghaffari return 0; 6277841947SLeila Ghaffari } 6377841947SLeila Ghaffari 6477841947SLeila Ghaffari // ***************************************************************************** 6577841947SLeila Ghaffari // This QFunction implements consistent outflow and inflow BCs 6677841947SLeila Ghaffari // for 3D advection 6777841947SLeila Ghaffari // 6877841947SLeila Ghaffari // Inflow and outflow faces are determined based on sign(dot(wind, normal)): 6977841947SLeila Ghaffari // sign(dot(wind, normal)) > 0 : outflow BCs 7077841947SLeila Ghaffari // sign(dot(wind, normal)) < 0 : inflow BCs 7177841947SLeila Ghaffari // 7277841947SLeila Ghaffari // Outflow BCs: 73ea61e9acSJeremy L Thompson // The validity of the weak form of the governing equations is extended to the outflow and the current values of E are applied. 7477841947SLeila Ghaffari // 7577841947SLeila Ghaffari // Inflow BCs: 7677841947SLeila Ghaffari // A prescribed Total Energy (E_wind) is applied weakly. 7777841947SLeila Ghaffari // ***************************************************************************** 782b730f8bSJeremy L Thompson CEED_QFUNCTION(Advection_InOutFlow)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 7977841947SLeila Ghaffari // Inputs 8046603fc5SJames Wright const CeedScalar(*q)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0]; 81f3e15844SJames Wright const CeedScalar(*q_data_sur) = in[2]; 8246603fc5SJames Wright 8377841947SLeila Ghaffari // Outputs 8477841947SLeila Ghaffari CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; 8577841947SLeila Ghaffari AdvectionContext context = (AdvectionContext)ctx; 8677841947SLeila Ghaffari const CeedScalar E_wind = context->E_wind; 8777841947SLeila Ghaffari const CeedScalar strong_form = context->strong_form; 88f3e15844SJames Wright const bool is_implicit = context->implicit; 8977841947SLeila Ghaffari 9077841947SLeila Ghaffari // Quadrature Point Loop 9146603fc5SJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 9277841947SLeila Ghaffari // Setup 9377841947SLeila Ghaffari // -- Interp in 9477841947SLeila Ghaffari const CeedScalar rho = q[0][i]; 952b730f8bSJeremy L Thompson const CeedScalar u[3] = {q[1][i] / rho, q[2][i] / rho, q[3][i] / rho}; 9677841947SLeila Ghaffari const CeedScalar E = q[4][i]; 9777841947SLeila Ghaffari 98f3e15844SJames Wright CeedScalar wdetJb, norm[3]; 99f3e15844SJames Wright QdataBoundaryUnpack_3D(Q, i, q_data_sur, &wdetJb, NULL, norm); 100f3e15844SJames Wright wdetJb *= is_implicit ? -1. : 1.; 10177841947SLeila Ghaffari 10277841947SLeila Ghaffari // Normal velocity 10377841947SLeila Ghaffari const CeedScalar u_normal = norm[0] * u[0] + norm[1] * u[1] + norm[2] * u[2]; 10477841947SLeila Ghaffari 10577841947SLeila Ghaffari // No Change in density or momentum 10677841947SLeila Ghaffari for (CeedInt j = 0; j < 4; j++) { 10777841947SLeila Ghaffari v[j][i] = 0; 10877841947SLeila Ghaffari } 10977841947SLeila Ghaffari // Implementing in/outflow BCs 11077841947SLeila Ghaffari if (u_normal > 0) { // outflow 11177841947SLeila Ghaffari v[4][i] = -(1 - strong_form) * wdetJb * E * u_normal; 11277841947SLeila Ghaffari } else { // inflow 11377841947SLeila Ghaffari v[4][i] = -(1 - strong_form) * wdetJb * E_wind * u_normal; 11477841947SLeila Ghaffari } 11577841947SLeila Ghaffari } // End Quadrature Point Loop 11677841947SLeila Ghaffari return 0; 11777841947SLeila Ghaffari } 11877841947SLeila Ghaffari // ***************************************************************************** 11977841947SLeila Ghaffari 12077841947SLeila Ghaffari #endif // advection_h 121