1 // Copyright (c) 2017-2023, 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 8 /// @file 9 /// Structs and helper functions for training data-driven subgrid-stress models 10 /// See 'Invariant data-driven subgrid stress modeling in the strain-rate eigenframe for large eddy simulation' 2022 and 'S-frame discrepancy 11 /// correction models for data-informed Reynolds stress closure' 2022 12 13 #ifndef sgs_dd_training_h 14 #define sgs_dd_training_h 15 16 #include <ceed.h> 17 18 #include "differential_filter_enums.h" 19 #include "newtonian_state.h" 20 #include "newtonian_types.h" 21 #include "sgs_dd_utils.h" 22 #include "utils.h" 23 #include "utils_eigensolver_jacobi.h" 24 25 typedef struct SGS_DD_TrainingContext_ *SGS_DDTrainingContext; 26 struct SGS_DD_TrainingContext_ { 27 struct NewtonianIdealGasContext_ gas; 28 }; 29 30 // @brief Calculate Data-Driven SGS model training data at nodes 31 CEED_QFUNCTION_HELPER int ComputeSGS_DDAnisotropicTrainingDataNodal(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out, 32 StateVariable state_var) { 33 const CeedScalar(*q)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0]; 34 const CeedScalar(*velo_prod)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[1]; 35 const CeedScalar(*grad_velo)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[2]; 36 const CeedScalar(*A_ij_delta)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[3]; 37 const CeedScalar(*inv_multiplicity) = (const CeedScalar(*))in[4]; 38 CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; 39 40 const SGS_DDTrainingContext sgsdd_ctx = (SGS_DDTrainingContext)ctx; 41 const NewtonianIdealGasContext gas = &sgsdd_ctx->gas; 42 43 CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 44 const CeedScalar qi[5] = {q[0][i], q[1][i], q[2][i], q[3][i], q[4][i]}; 45 const CeedScalar grad_velo_aniso[3][3] = { 46 {grad_velo[0][0][i], grad_velo[0][1][i], grad_velo[0][2][i]}, 47 {grad_velo[1][0][i], grad_velo[1][1][i], grad_velo[1][2][i]}, 48 {grad_velo[2][0][i], grad_velo[2][1][i], grad_velo[2][2][i]} 49 }; 50 const CeedScalar km_A_ij[6] = {A_ij_delta[0][i], A_ij_delta[1][i], A_ij_delta[2][i], A_ij_delta[3][i], A_ij_delta[4][i], A_ij_delta[5][i]}; 51 const CeedScalar delta = A_ij_delta[6][i]; 52 const State s = StateFromQ(gas, qi, state_var); 53 CeedScalar inputs[6]; 54 CeedScalar eigenvectors[3][3], grad_velo_magnitude; // dummy variables, don't actually use them 55 56 ComputeSgsDDInputs(grad_velo_aniso, km_A_ij, delta, gas->mu / s.U.density, eigenvectors, inputs, &grad_velo_magnitude); 57 58 for (int j = 0; j < 6; j++) v[j][i] = inv_multiplicity[i] * inputs[j]; 59 60 v[0 + 6][i] = (velo_prod[DIFF_FILTER_VELOCITY_SQUARED_XX][i] - Square(s.Y.velocity[0])) * inv_multiplicity[i]; 61 v[1 + 6][i] = (velo_prod[DIFF_FILTER_VELOCITY_SQUARED_YY][i] - Square(s.Y.velocity[1])) * inv_multiplicity[i]; 62 v[2 + 6][i] = (velo_prod[DIFF_FILTER_VELOCITY_SQUARED_ZZ][i] - Square(s.Y.velocity[2])) * inv_multiplicity[i]; 63 v[3 + 6][i] = (velo_prod[DIFF_FILTER_VELOCITY_SQUARED_YZ][i] - s.Y.velocity[1] * s.Y.velocity[2]) * inv_multiplicity[i]; 64 v[4 + 6][i] = (velo_prod[DIFF_FILTER_VELOCITY_SQUARED_XZ][i] - s.Y.velocity[0] * s.Y.velocity[2]) * inv_multiplicity[i]; 65 v[5 + 6][i] = (velo_prod[DIFF_FILTER_VELOCITY_SQUARED_XY][i] - s.Y.velocity[0] * s.Y.velocity[1]) * inv_multiplicity[i]; 66 } 67 return 0; 68 } 69 70 CEED_QFUNCTION(ComputeSGS_DDAnisotropicTrainingDataNodal_Prim)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 71 return ComputeSGS_DDAnisotropicTrainingDataNodal(ctx, Q, in, out, STATEVAR_PRIMITIVE); 72 } 73 74 #endif // sgs_dd_training_h 75