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