1*052409adSJames Wright // Copyright (c) 2017-2023, Lawrence Livermore National Security, LLC and other CEED contributors. 2*052409adSJames Wright // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 3*052409adSJames Wright // 4*052409adSJames Wright // SPDX-License-Identifier: BSD-2-Clause 5*052409adSJames Wright // 6*052409adSJames Wright // This file is part of CEED: http://github.com/ceed 7*052409adSJames Wright 8*052409adSJames Wright /// @file 9*052409adSJames Wright /// Element anisotropy tensor, as defined in 'Invariant data-driven subgrid stress modeling in the strain-rate eigenframe for large eddy simulation' 10*052409adSJames Wright /// Prakash et al. 2022 11*052409adSJames Wright 12*052409adSJames Wright #ifndef grid_anisotropy_tensor_h 13*052409adSJames Wright #define grid_anisotropy_tensor_h 14*052409adSJames Wright 15*052409adSJames Wright #include <ceed.h> 16*052409adSJames Wright 17*052409adSJames Wright #include "utils.h" 18*052409adSJames Wright #include "utils_eigensolver_jacobi.h" 19*052409adSJames Wright 20*052409adSJames Wright // @brief Get Anisotropy tensor from xi_{i,j} 21*052409adSJames Wright // @details A_ij = \Delta_{ij} / ||\Delta_ij||, \Delta_ij = (xi_{i,j})^(-1/2) 22*052409adSJames Wright CEED_QFUNCTION_HELPER void AnisotropyTensor(const CeedScalar km_g_ij[6], CeedScalar A_ij[3][3], CeedScalar *delta, const CeedInt n_sweeps) { 23*052409adSJames Wright CeedScalar evals[3], evecs[3][3], evals_evecs[3][3] = {{0.}}, g_ij[3][3]; 24*052409adSJames Wright CeedInt work_vector[2]; 25*052409adSJames Wright 26*052409adSJames Wright // Invert square root of metric tensor to get \Delta_ij 27*052409adSJames Wright KMUnpack(km_g_ij, g_ij); 28*052409adSJames Wright Diagonalize3(g_ij, evals, evecs, work_vector, SORT_DECREASING_EVALS, true, n_sweeps); 29*052409adSJames Wright for (int i = 0; i < 3; i++) evals[i] = 1 / sqrt(evals[i]); 30*052409adSJames Wright MatDiag3(evecs, evals, CEED_NOTRANSPOSE, evals_evecs); 31*052409adSJames Wright MatMat3(evecs, evals_evecs, CEED_TRANSPOSE, CEED_NOTRANSPOSE, A_ij); // A_ij = E^T D E 32*052409adSJames Wright 33*052409adSJames Wright // Scale by delta to get anisotropy tensor 34*052409adSJames Wright *delta = sqrt(Dot3(evals, evals)); 35*052409adSJames Wright ScaleN((CeedScalar *)A_ij, 1 / *delta, 9); 36*052409adSJames Wright // NOTE Need 2 factor to get physical element size (rather than projected onto [-1,1]^dim) 37*052409adSJames Wright // Should attempt to auto-determine this from the quadrature point coordinates in reference space 38*052409adSJames Wright *delta *= 2; 39*052409adSJames Wright } 40*052409adSJames Wright 41*052409adSJames Wright // @brief RHS for L^2 projection of anisotropic tensor and it's Frobenius norm 42*052409adSJames Wright CEED_QFUNCTION(AnisotropyTensorProjection)(void *ctx, CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 43*052409adSJames Wright const CeedScalar(*q_data)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[0]; 44*052409adSJames Wright CeedScalar(*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0]; 45*052409adSJames Wright 46*052409adSJames Wright CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 47*052409adSJames Wright const CeedScalar wdetJ = q_data[0][i]; 48*052409adSJames Wright const CeedScalar dXdx[3][3] = { 49*052409adSJames Wright {q_data[1][i], q_data[2][i], q_data[3][i]}, 50*052409adSJames Wright {q_data[4][i], q_data[5][i], q_data[6][i]}, 51*052409adSJames Wright {q_data[7][i], q_data[8][i], q_data[9][i]} 52*052409adSJames Wright }; 53*052409adSJames Wright 54*052409adSJames Wright CeedScalar km_g_ij[6] = {0.}, A_ij[3][3] = {{0.}}, km_A_ij[6], delta; 55*052409adSJames Wright KMMetricTensor(dXdx, km_g_ij); 56*052409adSJames Wright AnisotropyTensor(km_g_ij, A_ij, &delta, 15); 57*052409adSJames Wright KMPack(A_ij, km_A_ij); 58*052409adSJames Wright 59*052409adSJames Wright for (CeedInt j = 0; j < 6; j++) v[j][i] = wdetJ * km_A_ij[j]; 60*052409adSJames Wright v[6][i] = wdetJ * delta; 61*052409adSJames Wright } 62*052409adSJames Wright return 0; 63*052409adSJames Wright } 64*052409adSJames Wright 65*052409adSJames Wright #endif /* ifndef grid_anisotropy_tensor_h */ 66