1*14712a6bSJames Wright // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors. 2*14712a6bSJames Wright // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 3*14712a6bSJames Wright // 4*14712a6bSJames Wright // SPDX-License-Identifier: BSD-2-Clause 5*14712a6bSJames Wright // 6*14712a6bSJames Wright // This file is part of CEED: http://github.com/ceed 7*14712a6bSJames Wright 8*14712a6bSJames Wright /// @file 9*14712a6bSJames Wright /// 10*14712a6bSJames Wright 11*14712a6bSJames Wright #ifndef taylorgreen_h 12*14712a6bSJames Wright #define taylorgreen_h 13*14712a6bSJames Wright 14*14712a6bSJames Wright #include <ceed.h> 15*14712a6bSJames Wright #include <math.h> 16*14712a6bSJames Wright 17*14712a6bSJames Wright #include "newtonian_state.h" 18*14712a6bSJames Wright #include "newtonian_types.h" 19*14712a6bSJames Wright #include "utils.h" 20*14712a6bSJames Wright 21*14712a6bSJames Wright // @brief Set initial condition for Taylor-Green Vortex problem 22*14712a6bSJames Wright CEED_QFUNCTION(ICsTaylorGreen)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 23*14712a6bSJames Wright const CeedScalar(*X)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0]; 24*14712a6bSJames Wright 25*14712a6bSJames Wright CeedScalar(*q0)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; 26*14712a6bSJames Wright 27*14712a6bSJames Wright const SetupContext context = (SetupContext)ctx; 28*14712a6bSJames Wright struct NewtonianIdealGasContext_ *gas = &context->gas; 29*14712a6bSJames Wright CeedScalar R = GasConstant(gas); 30*14712a6bSJames Wright StatePrimitive reference = context->reference; 31*14712a6bSJames Wright const CeedScalar V0 = sqrt(Dot3(reference.velocity, reference.velocity)); 32*14712a6bSJames Wright const CeedScalar density0 = reference.pressure / (reference.temperature * R); 33*14712a6bSJames Wright const CeedScalar x0[3] = {0.}; 34*14712a6bSJames Wright 35*14712a6bSJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 36*14712a6bSJames Wright CeedScalar x[] = {X[0][i], X[1][i], X[2][i]}; 37*14712a6bSJames Wright CeedScalar q[5] = {0}, Y[5]; 38*14712a6bSJames Wright ScaleN(x, 2 * M_PI / context->lx, 3); 39*14712a6bSJames Wright 40*14712a6bSJames Wright Y[0] = reference.pressure + (density0 * Square(V0) / 16) * (cos(2 * x[0]) + cos(2 * x[1])) * (cos(2 * x[2] + 2)); 41*14712a6bSJames Wright Y[1] = V0 * sin(x[0]) * cos(x[1]) * cos(x[2]); 42*14712a6bSJames Wright Y[2] = -V0 * cos(x[0]) * sin(x[1]) * cos(x[2]); 43*14712a6bSJames Wright Y[3] = 0; 44*14712a6bSJames Wright Y[4] = reference.temperature; 45*14712a6bSJames Wright 46*14712a6bSJames Wright State s = StateFromY(gas, Y, x0); 47*14712a6bSJames Wright switch (gas->state_var) { 48*14712a6bSJames Wright case STATEVAR_CONSERVATIVE: 49*14712a6bSJames Wright UnpackState_U(s.U, q); 50*14712a6bSJames Wright break; 51*14712a6bSJames Wright case STATEVAR_PRIMITIVE: 52*14712a6bSJames Wright UnpackState_Y(s.Y, q); 53*14712a6bSJames Wright break; 54*14712a6bSJames Wright } 55*14712a6bSJames Wright 56*14712a6bSJames Wright for (CeedInt j = 0; j < 5; j++) q0[j][i] = q[j]; 57*14712a6bSJames Wright } 58*14712a6bSJames Wright return 0; 59*14712a6bSJames Wright } 60*14712a6bSJames Wright 61*14712a6bSJames Wright #endif // taylorgreen_h 62