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