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