1692bc0d9SJames Wright // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors. 2692bc0d9SJames Wright // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 3692bc0d9SJames Wright // 4692bc0d9SJames Wright // SPDX-License-Identifier: BSD-2-Clause 5692bc0d9SJames Wright // 6692bc0d9SJames Wright // This file is part of CEED: http://github.com/ceed 7692bc0d9SJames Wright 8692bc0d9SJames Wright /// @file 9692bc0d9SJames Wright /// 10692bc0d9SJames Wright 11692bc0d9SJames Wright #ifndef taylorgreen_h 12692bc0d9SJames Wright #define taylorgreen_h 13692bc0d9SJames Wright 14692bc0d9SJames Wright #include <ceed.h> 15692bc0d9SJames Wright #include <math.h> 16692bc0d9SJames Wright 17692bc0d9SJames Wright #include "newtonian_state.h" 18692bc0d9SJames Wright #include "newtonian_types.h" 19692bc0d9SJames Wright #include "utils.h" 20692bc0d9SJames Wright 21692bc0d9SJames Wright // @brief Set initial condition for Taylor-Green Vortex problem 22692bc0d9SJames Wright CEED_QFUNCTION(ICsTaylorGreen)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 23692bc0d9SJames Wright const CeedScalar(*X)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0]; 24692bc0d9SJames Wright 25692bc0d9SJames Wright CeedScalar(*q0)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; 26692bc0d9SJames Wright 27692bc0d9SJames Wright const SetupContext context = (SetupContext)ctx; 28692bc0d9SJames Wright struct NewtonianIdealGasContext_ *gas = &context->gas; 29692bc0d9SJames Wright CeedScalar R = GasConstant(gas); 30692bc0d9SJames Wright StatePrimitive reference = context->reference; 31692bc0d9SJames Wright const CeedScalar V0 = sqrt(Dot3(reference.velocity, reference.velocity)); 32692bc0d9SJames Wright const CeedScalar density0 = reference.pressure / (reference.temperature * R); 33692bc0d9SJames Wright 34692bc0d9SJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 35692bc0d9SJames Wright CeedScalar x[] = {X[0][i], X[1][i], X[2][i]}; 36692bc0d9SJames Wright CeedScalar q[5] = {0}, Y[5]; 37692bc0d9SJames Wright ScaleN(x, 2 * M_PI / context->lx, 3); 38692bc0d9SJames Wright 39692bc0d9SJames Wright Y[0] = reference.pressure + (density0 * Square(V0) / 16) * (cos(2 * x[0]) + cos(2 * x[1])) * (cos(2 * x[2] + 2)); 40692bc0d9SJames Wright Y[1] = V0 * sin(x[0]) * cos(x[1]) * cos(x[2]); 41692bc0d9SJames Wright Y[2] = -V0 * cos(x[0]) * sin(x[1]) * cos(x[2]); 42692bc0d9SJames Wright Y[3] = 0; 43692bc0d9SJames Wright Y[4] = reference.temperature; 44692bc0d9SJames Wright 45*edcfef1bSKenneth E. Jansen State s = StateFromY(gas, Y); 46692bc0d9SJames Wright switch (gas->state_var) { 47692bc0d9SJames Wright case STATEVAR_CONSERVATIVE: 48692bc0d9SJames Wright UnpackState_U(s.U, q); 49692bc0d9SJames Wright break; 50692bc0d9SJames Wright case STATEVAR_PRIMITIVE: 51692bc0d9SJames Wright UnpackState_Y(s.Y, q); 52692bc0d9SJames Wright break; 53692bc0d9SJames Wright } 54692bc0d9SJames Wright 55692bc0d9SJames Wright for (CeedInt j = 0; j < 5; j++) q0[j][i] = q[j]; 56692bc0d9SJames Wright } 57692bc0d9SJames Wright return 0; 58692bc0d9SJames Wright } 59692bc0d9SJames Wright 60692bc0d9SJames Wright #endif // taylorgreen_h 61