1 // SPDX-FileCopyrightText: Copyright (c) 2017-2024, HONEE contributors. 2 // SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause 3 #include <ceed/types.h> 4 #ifndef CEED_RUNNING_JIT_PASS 5 #include <math.h> 6 #endif 7 8 #include "newtonian_state.h" 9 #include "newtonian_types.h" 10 #include "utils.h" 11 12 // @brief Set initial condition for Taylor-Green Vortex problem 13 CEED_QFUNCTION(ICsTaylorGreen)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 14 const CeedScalar(*X)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0]; 15 16 CeedScalar(*q0)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; 17 18 const SetupContext context = (SetupContext)ctx; 19 const NewtonianIdealGasContext gas = &context->gas; 20 CeedScalar R = GasConstant(gas); 21 StatePrimitive reference = context->reference; 22 const CeedScalar V0 = Norm3(reference.velocity); 23 const CeedScalar density0 = reference.pressure / (reference.temperature * R); 24 25 CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 26 CeedScalar x[] = {X[0][i], X[1][i], X[2][i]}; 27 CeedScalar q[5], Y[5]; 28 ScaleN(x, 2 * M_PI / context->lx, 3); 29 30 Y[0] = reference.pressure + (density0 * Square(V0) / 16) * (cos(2 * x[0]) + cos(2 * x[1])) * (cos(2 * x[2] + 2)); 31 Y[1] = V0 * sin(x[0]) * cos(x[1]) * cos(x[2]); 32 Y[2] = -V0 * cos(x[0]) * sin(x[1]) * cos(x[2]); 33 Y[3] = 0; 34 Y[4] = reference.temperature; 35 36 State s = StateFromY(gas, Y); 37 StateToQ(gas, s, q, gas->state_var); 38 for (CeedInt j = 0; j < 5; j++) q0[j][i] = q[j]; 39 } 40 return 0; 41 } 42