1*2a28a40bSJames Wright // SPDX-FileCopyrightText: Copyright (c) 2017-2024, HONEE contributors. 2*2a28a40bSJames Wright // SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause 3*2a28a40bSJames Wright 4*2a28a40bSJames Wright #include <ceed/types.h> 5*2a28a40bSJames Wright #include "utils.h" 6*2a28a40bSJames Wright 7*2a28a40bSJames Wright /** 8*2a28a40bSJames Wright @brief Calculate CFL for 3D spatial dimensions 9*2a28a40bSJames Wright 10*2a28a40bSJames Wright Defined as 11*2a28a40bSJames Wright @f[ 12*2a28a40bSJames Wright \mathrm{CFL} = \Delta t \sqrt{\overline{g}_{jk} u_j u_k} 13*2a28a40bSJames Wright @f] 14*2a28a40bSJames Wright 15*2a28a40bSJames Wright where \f$ \Delta t \f$ is the `timestep`, \f$ \overline{g}_{jk} \f$ is the element metric tensor `gij`, and \f$ u_j \f$ is the `velocity`. 16*2a28a40bSJames Wright For best results, `gij` should be scaled to account for the reference element domain (often [-1,1] for Gaussian quadrature). 17*2a28a40bSJames Wright 18*2a28a40bSJames Wright @param[in] velocity Velocity 19*2a28a40bSJames Wright @param[in] timestep Timestep 20*2a28a40bSJames Wright @param[in] gij Element metric tensor (should be scaled) 21*2a28a40bSJames Wright @return The CFL value for the element 22*2a28a40bSJames Wright **/ 23*2a28a40bSJames Wright CEED_QFUNCTION_HELPER CeedScalar CalculateCFL_3D(const CeedScalar velocity[3], CeedScalar timestep, const CeedScalar gij[3][3]) { 24*2a28a40bSJames Wright CeedScalar gij_uj[3] = {0.}; 25*2a28a40bSJames Wright 26*2a28a40bSJames Wright MatVec3(gij, velocity, CEED_NOTRANSPOSE, gij_uj); 27*2a28a40bSJames Wright return sqrt(Dot3(velocity, gij_uj)) * timestep; 28*2a28a40bSJames Wright } 29*2a28a40bSJames Wright 30*2a28a40bSJames Wright /** 31*2a28a40bSJames Wright @brief Calculate CFL for 2D spatial dimensions 32*2a28a40bSJames Wright 33*2a28a40bSJames Wright Defined as 34*2a28a40bSJames Wright @f[ 35*2a28a40bSJames Wright \mathrm{CFL} = \Delta t \sqrt{\overline{g}_{jk} u_j u_k} 36*2a28a40bSJames Wright @f] 37*2a28a40bSJames Wright 38*2a28a40bSJames Wright where \f$ \Delta t \f$ is the `timestep`, \f$ \overline{g}_{jk} \f$ is the element metric tensor `gij`, and \f$ u_j \f$ is the `velocity`. 39*2a28a40bSJames Wright For best results, `gij` should be scaled to account for the reference element domain (often [-1,1] for Gaussian quadrature). 40*2a28a40bSJames Wright 41*2a28a40bSJames Wright @param[in] velocity Advection velocity 42*2a28a40bSJames Wright @param[in] timestep Timestep 43*2a28a40bSJames Wright @param[in] gij Element metric tensor (should be scaled) 44*2a28a40bSJames Wright @return The CFL value for the element 45*2a28a40bSJames Wright **/ 46*2a28a40bSJames Wright CEED_QFUNCTION_HELPER CeedScalar CalculateCFL_2D(const CeedScalar velocity[2], CeedScalar timestep, const CeedScalar gij[2][2]) { 47*2a28a40bSJames Wright CeedScalar gij_uj[2] = {0.}; 48*2a28a40bSJames Wright 49*2a28a40bSJames Wright MatVec2(gij, velocity, CEED_NOTRANSPOSE, gij_uj); 50*2a28a40bSJames Wright return sqrt(Dot2(velocity, gij_uj)) * timestep; 51*2a28a40bSJames Wright } 52