xref: /honee/qfunctions/taylorgreen.h (revision 3e17a7a1849b799c24669fa5a24aea7b05055bba)
1ae2b091fSJames Wright // SPDX-FileCopyrightText: Copyright (c) 2017-2024, HONEE contributors.
2ae2b091fSJames Wright // SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause
3*3e17a7a1SJames Wright #include <ceed/types.h>
4*3e17a7a1SJames Wright #ifndef CEED_RUNNING_JIT_PASS
5692bc0d9SJames Wright #include <math.h>
6*3e17a7a1SJames Wright #endif
7692bc0d9SJames Wright 
8692bc0d9SJames Wright #include "newtonian_state.h"
9692bc0d9SJames Wright #include "newtonian_types.h"
10692bc0d9SJames Wright #include "utils.h"
11692bc0d9SJames Wright 
12692bc0d9SJames Wright // @brief Set initial condition for Taylor-Green Vortex problem
13692bc0d9SJames Wright CEED_QFUNCTION(ICsTaylorGreen)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
14692bc0d9SJames Wright   const CeedScalar(*X)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0];
15692bc0d9SJames Wright 
16692bc0d9SJames Wright   CeedScalar(*q0)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
17692bc0d9SJames Wright 
18692bc0d9SJames Wright   const SetupContext             context   = (SetupContext)ctx;
199b103f75SJames Wright   const NewtonianIdealGasContext gas       = &context->gas;
20692bc0d9SJames Wright   CeedScalar                     R         = GasConstant(gas);
21692bc0d9SJames Wright   StatePrimitive                 reference = context->reference;
2264667825SJames Wright   const CeedScalar               V0        = Norm3(reference.velocity);
23692bc0d9SJames Wright   const CeedScalar               density0  = reference.pressure / (reference.temperature * R);
24692bc0d9SJames Wright 
25692bc0d9SJames Wright   CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
26692bc0d9SJames Wright     CeedScalar x[] = {X[0][i], X[1][i], X[2][i]};
27a541e550SJames Wright     CeedScalar q[5], Y[5];
28692bc0d9SJames Wright     ScaleN(x, 2 * M_PI / context->lx, 3);
29692bc0d9SJames Wright 
30692bc0d9SJames Wright     Y[0] = reference.pressure + (density0 * Square(V0) / 16) * (cos(2 * x[0]) + cos(2 * x[1])) * (cos(2 * x[2] + 2));
31692bc0d9SJames Wright     Y[1] = V0 * sin(x[0]) * cos(x[1]) * cos(x[2]);
32692bc0d9SJames Wright     Y[2] = -V0 * cos(x[0]) * sin(x[1]) * cos(x[2]);
33692bc0d9SJames Wright     Y[3] = 0;
34692bc0d9SJames Wright     Y[4] = reference.temperature;
35692bc0d9SJames Wright 
36edcfef1bSKenneth E. Jansen     State s = StateFromY(gas, Y);
379b103f75SJames Wright     StateToQ(gas, s, q, gas->state_var);
38692bc0d9SJames Wright     for (CeedInt j = 0; j < 5; j++) q0[j][i] = q[j];
39692bc0d9SJames Wright   }
40692bc0d9SJames Wright   return 0;
41692bc0d9SJames Wright }
42