18ecc9db9SJames Wright // Copyright (c) 2017-2023, Lawrence Livermore National Security, LLC and other CEED contributors. 28ecc9db9SJames Wright // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 38ecc9db9SJames Wright // 48ecc9db9SJames Wright // SPDX-License-Identifier: BSD-2-Clause 58ecc9db9SJames Wright // 68ecc9db9SJames Wright // This file is part of CEED: http://github.com/ceed 78ecc9db9SJames Wright 88ecc9db9SJames Wright /// @file 98ecc9db9SJames Wright /// Structs and helper functions for training data-driven subgrid-stress models 108ecc9db9SJames Wright /// See 'Invariant data-driven subgrid stress modeling in the strain-rate eigenframe for large eddy simulation' 2022 and 'S-frame discrepancy 118ecc9db9SJames Wright /// correction models for data-informed Reynolds stress closure' 2022 128ecc9db9SJames Wright 138ecc9db9SJames Wright #ifndef sgs_dd_training_h 148ecc9db9SJames Wright #define sgs_dd_training_h 158ecc9db9SJames Wright 168ecc9db9SJames Wright #include <ceed.h> 178ecc9db9SJames Wright 188ecc9db9SJames Wright #include "differential_filter_enums.h" 198ecc9db9SJames Wright #include "newtonian_state.h" 208ecc9db9SJames Wright #include "newtonian_types.h" 218ecc9db9SJames Wright #include "sgs_dd_utils.h" 228ecc9db9SJames Wright #include "utils.h" 238ecc9db9SJames Wright #include "utils_eigensolver_jacobi.h" 248ecc9db9SJames Wright 258ecc9db9SJames Wright typedef struct SGS_DD_TrainingContext_ *SGS_DDTrainingContext; 268ecc9db9SJames Wright struct SGS_DD_TrainingContext_ { 278ecc9db9SJames Wright struct NewtonianIdealGasContext_ gas; 288ecc9db9SJames Wright }; 298ecc9db9SJames Wright 308ecc9db9SJames Wright // @brief Calculate Data-Driven SGS model training data at nodes 318ecc9db9SJames Wright CEED_QFUNCTION_HELPER int ComputeSGS_DDAnisotropicTrainingDataNodal(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out, 328ecc9db9SJames Wright StateVariable state_var) { 338ecc9db9SJames Wright const CeedScalar(*q)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0]; 348ecc9db9SJames Wright const CeedScalar(*velo_prod)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[1]; 358ecc9db9SJames Wright const CeedScalar(*grad_velo)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[2]; 368ecc9db9SJames Wright const CeedScalar(*A_ij_delta)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[3]; 378ecc9db9SJames Wright const CeedScalar(*inv_multiplicity) = (const CeedScalar(*))in[4]; 388ecc9db9SJames Wright CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; 398ecc9db9SJames Wright 408ecc9db9SJames Wright const SGS_DDTrainingContext sgsdd_ctx = (SGS_DDTrainingContext)ctx; 418ecc9db9SJames Wright const NewtonianIdealGasContext gas = &sgsdd_ctx->gas; 428ecc9db9SJames Wright 438ecc9db9SJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 448ecc9db9SJames Wright const CeedScalar qi[5] = {q[0][i], q[1][i], q[2][i], q[3][i], q[4][i]}; 458ecc9db9SJames Wright const CeedScalar grad_velo_aniso[3][3] = { 468ecc9db9SJames Wright {grad_velo[0][0][i], grad_velo[0][1][i], grad_velo[0][2][i]}, 478ecc9db9SJames Wright {grad_velo[1][0][i], grad_velo[1][1][i], grad_velo[1][2][i]}, 488ecc9db9SJames Wright {grad_velo[2][0][i], grad_velo[2][1][i], grad_velo[2][2][i]} 498ecc9db9SJames Wright }; 508ecc9db9SJames Wright 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]}; 518ecc9db9SJames Wright const CeedScalar delta = A_ij_delta[6][i]; 528ecc9db9SJames Wright const State s = StateFromQ(gas, qi, state_var); 538ecc9db9SJames Wright CeedScalar inputs[6]; 548ecc9db9SJames Wright CeedScalar eigenvectors[3][3], grad_velo_magnitude; // dummy variables, don't actually use them 558ecc9db9SJames Wright 56*ad494f68SJames Wright ComputeSgsDDInputs(grad_velo_aniso, km_A_ij, delta, gas->mu / s.U.density, eigenvectors, inputs, &grad_velo_magnitude); 578ecc9db9SJames Wright 588ecc9db9SJames Wright for (int j = 0; j < 6; j++) v[j][i] = inv_multiplicity[i] * inputs[j]; 598ecc9db9SJames Wright 608ecc9db9SJames Wright v[0 + 6][i] = (velo_prod[DIFF_FILTER_VELOCITY_SQUARED_XX][i] - Square(s.Y.velocity[0])) * inv_multiplicity[i]; 618ecc9db9SJames Wright v[1 + 6][i] = (velo_prod[DIFF_FILTER_VELOCITY_SQUARED_YY][i] - Square(s.Y.velocity[1])) * inv_multiplicity[i]; 628ecc9db9SJames Wright v[2 + 6][i] = (velo_prod[DIFF_FILTER_VELOCITY_SQUARED_ZZ][i] - Square(s.Y.velocity[2])) * inv_multiplicity[i]; 638ecc9db9SJames Wright v[3 + 6][i] = (velo_prod[DIFF_FILTER_VELOCITY_SQUARED_YZ][i] - s.Y.velocity[1] * s.Y.velocity[2]) * inv_multiplicity[i]; 648ecc9db9SJames Wright v[4 + 6][i] = (velo_prod[DIFF_FILTER_VELOCITY_SQUARED_XZ][i] - s.Y.velocity[0] * s.Y.velocity[2]) * inv_multiplicity[i]; 658ecc9db9SJames Wright v[5 + 6][i] = (velo_prod[DIFF_FILTER_VELOCITY_SQUARED_XY][i] - s.Y.velocity[0] * s.Y.velocity[1]) * inv_multiplicity[i]; 668ecc9db9SJames Wright } 678ecc9db9SJames Wright return 0; 688ecc9db9SJames Wright } 698ecc9db9SJames Wright 708ecc9db9SJames Wright CEED_QFUNCTION(ComputeSGS_DDAnisotropicTrainingDataNodal_Prim)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 718ecc9db9SJames Wright return ComputeSGS_DDAnisotropicTrainingDataNodal(ctx, Q, in, out, STATEVAR_PRIMITIVE); 728ecc9db9SJames Wright } 738ecc9db9SJames Wright 748ecc9db9SJames Wright #endif // sgs_dd_training_h 75