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