xref: /libCEED/examples/fluids/qfunctions/taylorgreen.h (revision 5aed82e4fa97acf4ba24a7f10a35f5303a6798e0)
1*5aed82e4SJeremy L Thompson // Copyright (c) 2017-2024, Lawrence Livermore National Security, LLC and other CEED contributors.
214712a6bSJames Wright // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
314712a6bSJames Wright //
414712a6bSJames Wright // SPDX-License-Identifier: BSD-2-Clause
514712a6bSJames Wright //
614712a6bSJames Wright // This file is part of CEED:  http://github.com/ceed
714712a6bSJames Wright 
814712a6bSJames Wright /// @file
914712a6bSJames Wright ///
1014712a6bSJames Wright 
1114712a6bSJames Wright #ifndef taylorgreen_h
1214712a6bSJames Wright #define taylorgreen_h
1314712a6bSJames Wright 
1414712a6bSJames Wright #include <ceed.h>
1514712a6bSJames Wright #include <math.h>
1614712a6bSJames Wright 
1714712a6bSJames Wright #include "newtonian_state.h"
1814712a6bSJames Wright #include "newtonian_types.h"
1914712a6bSJames Wright #include "utils.h"
2014712a6bSJames Wright 
2114712a6bSJames Wright // @brief Set initial condition for Taylor-Green Vortex problem
2214712a6bSJames Wright CEED_QFUNCTION(ICsTaylorGreen)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) {
2314712a6bSJames Wright   const CeedScalar(*X)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0];
2414712a6bSJames Wright 
2514712a6bSJames Wright   CeedScalar(*q0)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
2614712a6bSJames Wright 
2714712a6bSJames Wright   const SetupContext                context   = (SetupContext)ctx;
2814712a6bSJames Wright   struct NewtonianIdealGasContext_ *gas       = &context->gas;
2914712a6bSJames Wright   CeedScalar                        R         = GasConstant(gas);
3014712a6bSJames Wright   StatePrimitive                    reference = context->reference;
3114712a6bSJames Wright   const CeedScalar                  V0        = sqrt(Dot3(reference.velocity, reference.velocity));
3214712a6bSJames Wright   const CeedScalar                  density0  = reference.pressure / (reference.temperature * R);
3314712a6bSJames Wright 
3414712a6bSJames Wright   CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) {
3514712a6bSJames Wright     CeedScalar x[]  = {X[0][i], X[1][i], X[2][i]};
3614712a6bSJames Wright     CeedScalar q[5] = {0}, Y[5];
3714712a6bSJames Wright     ScaleN(x, 2 * M_PI / context->lx, 3);
3814712a6bSJames Wright 
3914712a6bSJames Wright     Y[0] = reference.pressure + (density0 * Square(V0) / 16) * (cos(2 * x[0]) + cos(2 * x[1])) * (cos(2 * x[2] + 2));
4014712a6bSJames Wright     Y[1] = V0 * sin(x[0]) * cos(x[1]) * cos(x[2]);
4114712a6bSJames Wright     Y[2] = -V0 * cos(x[0]) * sin(x[1]) * cos(x[2]);
4214712a6bSJames Wright     Y[3] = 0;
4314712a6bSJames Wright     Y[4] = reference.temperature;
4414712a6bSJames Wright 
453bd61617SKenneth E. Jansen     State s = StateFromY(gas, Y);
4614712a6bSJames Wright     switch (gas->state_var) {
4714712a6bSJames Wright       case STATEVAR_CONSERVATIVE:
4814712a6bSJames Wright         UnpackState_U(s.U, q);
4914712a6bSJames Wright         break;
5014712a6bSJames Wright       case STATEVAR_PRIMITIVE:
5114712a6bSJames Wright         UnpackState_Y(s.Y, q);
5214712a6bSJames Wright         break;
5314712a6bSJames Wright     }
5414712a6bSJames Wright 
5514712a6bSJames Wright     for (CeedInt j = 0; j < 5; j++) q0[j][i] = q[j];
5614712a6bSJames Wright   }
5714712a6bSJames Wright   return 0;
5814712a6bSJames Wright }
5914712a6bSJames Wright 
6014712a6bSJames Wright #endif  // taylorgreen_h
61