1ae2b091fSJames Wright // SPDX-FileCopyrightText: Copyright (c) 2017-2024, HONEE contributors.
2ae2b091fSJames Wright // SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause
33e17a7a1SJames Wright #include <ceed/types.h>
43e17a7a1SJames Wright #ifndef CEED_RUNNING_JIT_PASS
5692bc0d9SJames Wright #include <math.h>
63e17a7a1SJames Wright #endif
7692bc0d9SJames Wright
8692bc0d9SJames Wright #include "newtonian_state.h"
9692bc0d9SJames Wright #include "newtonian_types.h"
10692bc0d9SJames Wright #include "utils.h"
11692bc0d9SJames Wright
12d9f57b1cSJames Wright typedef struct TaylorGreenContext_ *TaylorGreenContext;
13d9f57b1cSJames Wright struct TaylorGreenContext_ {
14d9f57b1cSJames Wright StatePrimitive reference;
15*cde3d787SJames Wright struct NewtonianIdealGasContext_ newt_ctx;
16d9f57b1cSJames Wright CeedScalar lx;
17d9f57b1cSJames Wright CeedScalar ly;
18d9f57b1cSJames Wright CeedScalar lz;
19d9f57b1cSJames Wright CeedScalar u[3];
20d9f57b1cSJames Wright };
21d9f57b1cSJames Wright
22692bc0d9SJames Wright // @brief Set initial condition for Taylor-Green Vortex problem
ICsTaylorGreen(void * ctx,CeedInt Q,const CeedScalar * const * in,CeedScalar * const * out)23692bc0d9SJames Wright CEED_QFUNCTION(ICsTaylorGreen)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
24692bc0d9SJames Wright const CeedScalar(*X)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0];
25692bc0d9SJames Wright
26692bc0d9SJames Wright CeedScalar(*q0)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
27692bc0d9SJames Wright
28d9f57b1cSJames Wright const TaylorGreenContext context = (TaylorGreenContext)ctx;
29*cde3d787SJames Wright const NewtonianIGProperties gas = context->newt_ctx.gas;
30692bc0d9SJames Wright CeedScalar R = GasConstant(gas);
31692bc0d9SJames Wright StatePrimitive reference = context->reference;
3264667825SJames Wright const CeedScalar V0 = Norm3(reference.velocity);
33692bc0d9SJames Wright const CeedScalar density0 = reference.pressure / (reference.temperature * R);
34692bc0d9SJames Wright
35692bc0d9SJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
36692bc0d9SJames Wright CeedScalar x[] = {X[0][i], X[1][i], X[2][i]};
37a541e550SJames Wright CeedScalar q[5], Y[5];
38692bc0d9SJames Wright ScaleN(x, 2 * M_PI / context->lx, 3);
39692bc0d9SJames Wright
40692bc0d9SJames Wright Y[0] = reference.pressure + (density0 * Square(V0) / 16) * (cos(2 * x[0]) + cos(2 * x[1])) * (cos(2 * x[2] + 2));
41d9f57b1cSJames Wright Y[1] = context->u[0] + V0 * sin(x[0]) * cos(x[1]) * cos(x[2]);
42d9f57b1cSJames Wright Y[2] = context->u[1] - V0 * cos(x[0]) * sin(x[1]) * cos(x[2]);
43d9f57b1cSJames Wright Y[3] = context->u[2];
44692bc0d9SJames Wright Y[4] = reference.temperature;
45692bc0d9SJames Wright
46edcfef1bSKenneth E. Jansen State s = StateFromY(gas, Y);
47*cde3d787SJames Wright StateToQ(gas, s, q, context->newt_ctx.state_var);
48692bc0d9SJames Wright for (CeedInt j = 0; j < 5; j++) q0[j][i] = q[j];
49692bc0d9SJames Wright }
50692bc0d9SJames Wright return 0;
51692bc0d9SJames Wright }
52