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