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