12a28a40bSJames Wright // SPDX-FileCopyrightText: Copyright (c) 2017-2024, HONEE contributors. 22a28a40bSJames Wright // SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause 32a28a40bSJames Wright 42a28a40bSJames Wright #include <ceed/types.h> 52a28a40bSJames Wright #include "utils.h" 62a28a40bSJames Wright 72a28a40bSJames Wright /** 82a28a40bSJames Wright @brief Calculate CFL for 3D spatial dimensions 92a28a40bSJames Wright 102a28a40bSJames Wright Defined as 112a28a40bSJames Wright @f[ 122a28a40bSJames Wright \mathrm{CFL} = \Delta t \sqrt{\overline{g}_{jk} u_j u_k} 132a28a40bSJames Wright @f] 142a28a40bSJames Wright 152a28a40bSJames 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`. 162a28a40bSJames Wright For best results, `gij` should be scaled to account for the reference element domain (often [-1,1] for Gaussian quadrature). 172a28a40bSJames Wright 182a28a40bSJames Wright @param[in] velocity Velocity 192a28a40bSJames Wright @param[in] timestep Timestep 202a28a40bSJames Wright @param[in] gij Element metric tensor (should be scaled) 212a28a40bSJames Wright @return The CFL value for the element 222a28a40bSJames Wright **/ 232a28a40bSJames Wright CEED_QFUNCTION_HELPER CeedScalar CalculateCFL_3D(const CeedScalar velocity[3], CeedScalar timestep, const CeedScalar gij[3][3]) { 242a28a40bSJames Wright CeedScalar gij_uj[3] = {0.}; 252a28a40bSJames Wright 262a28a40bSJames Wright MatVec3(gij, velocity, CEED_NOTRANSPOSE, gij_uj); 272a28a40bSJames Wright return sqrt(Dot3(velocity, gij_uj)) * timestep; 282a28a40bSJames Wright } 292a28a40bSJames Wright 302a28a40bSJames Wright /** 312a28a40bSJames Wright @brief Calculate CFL for 2D spatial dimensions 322a28a40bSJames Wright 332a28a40bSJames Wright Defined as 342a28a40bSJames Wright @f[ 352a28a40bSJames Wright \mathrm{CFL} = \Delta t \sqrt{\overline{g}_{jk} u_j u_k} 362a28a40bSJames Wright @f] 372a28a40bSJames Wright 382a28a40bSJames 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`. 392a28a40bSJames Wright For best results, `gij` should be scaled to account for the reference element domain (often [-1,1] for Gaussian quadrature). 402a28a40bSJames Wright 412a28a40bSJames Wright @param[in] velocity Advection velocity 422a28a40bSJames Wright @param[in] timestep Timestep 432a28a40bSJames Wright @param[in] gij Element metric tensor (should be scaled) 442a28a40bSJames Wright @return The CFL value for the element 452a28a40bSJames Wright **/ 462a28a40bSJames Wright CEED_QFUNCTION_HELPER CeedScalar CalculateCFL_2D(const CeedScalar velocity[2], CeedScalar timestep, const CeedScalar gij[2][2]) { 472a28a40bSJames Wright CeedScalar gij_uj[2] = {0.}; 482a28a40bSJames Wright 492a28a40bSJames Wright MatVec2(gij, velocity, CEED_NOTRANSPOSE, gij_uj); 502a28a40bSJames Wright return sqrt(Dot2(velocity, gij_uj)) * timestep; 512a28a40bSJames Wright } 52*b30619f6SJames Wright 53*b30619f6SJames Wright /** 54*b30619f6SJames Wright @brief Calculate Peclet number for 3D spatial dimensions 55*b30619f6SJames Wright 56*b30619f6SJames Wright Defined as 57*b30619f6SJames Wright @f[ 58*b30619f6SJames Wright \mathrm{Pe} = \frac{\sqrt{\overline{g}_{jk} u_j u_k}}{\kappa} 59*b30619f6SJames Wright @f] 60*b30619f6SJames Wright 61*b30619f6SJames Wright where \f$ \kappa \f$ is the `diffusion_coeff`, \f$ \overline{g}_{jk} \f$ is the element metric tensor `gij`, and \f$ u_j \f$ is the `velocity`. 62*b30619f6SJames Wright For best results, `gij` should be scaled to account for the reference element domain (often [-1,1] for Gaussian quadrature). 63*b30619f6SJames Wright 64*b30619f6SJames Wright @param[in] velocity Advection velocity 65*b30619f6SJames Wright @param[in] diffusion_coeff Diffusion coefficient 66*b30619f6SJames Wright @param[in] gij Element metric tensor (should be scaled) 67*b30619f6SJames Wright @return The Peclet value for the element 68*b30619f6SJames Wright **/ 69*b30619f6SJames Wright CEED_QFUNCTION_HELPER CeedScalar CalculatePe_3D(const CeedScalar velocity[3], CeedScalar diffusion_coeff, const CeedScalar gij[3][3]) { 70*b30619f6SJames Wright CeedScalar gij_uj[3] = {0.}, gij_inv_mat[3][3] = {{0.}}; 71*b30619f6SJames Wright 72*b30619f6SJames Wright MatInv3(gij, gij_inv_mat, NULL); 73*b30619f6SJames Wright MatVec3(gij_inv_mat, velocity, CEED_NOTRANSPOSE, gij_uj); 74*b30619f6SJames Wright return sqrt(Dot3(velocity, gij_uj)) / diffusion_coeff; 75*b30619f6SJames Wright } 76*b30619f6SJames Wright 77*b30619f6SJames Wright /** 78*b30619f6SJames Wright @brief Calculate Peclet number for 2D spatial dimensions 79*b30619f6SJames Wright 80*b30619f6SJames Wright Defined as 81*b30619f6SJames Wright @f[ 82*b30619f6SJames Wright \mathrm{Pe} = \frac{\sqrt{\overline{g}_{jk} u_j u_k}}{\kappa} 83*b30619f6SJames Wright @f] 84*b30619f6SJames Wright 85*b30619f6SJames Wright where \f$ \kappa \f$ is the `diffusion_coeff`, \f$ \overline{g}_{jk} \f$ is the element metric tensor `gij`, and \f$ u_j \f$ is the `velocity`. 86*b30619f6SJames Wright For best results, `gij` should be scaled to account for the reference element domain (often [-1,1] for Gaussian quadrature). 87*b30619f6SJames Wright 88*b30619f6SJames Wright @param[in] velocity Advection velocity 89*b30619f6SJames Wright @param[in] diffusion_coeff Diffusion coefficient 90*b30619f6SJames Wright @param[in] gij Element metric tensor (should be scaled) 91*b30619f6SJames Wright @return The Peclet value for the element 92*b30619f6SJames Wright **/ 93*b30619f6SJames Wright CEED_QFUNCTION_HELPER CeedScalar CalculatePe_2D(const CeedScalar velocity[2], CeedScalar diffusion_coeff, const CeedScalar gij[2][2]) { 94*b30619f6SJames Wright CeedScalar gij_uj[2] = {0.}, gij_inv_mat[2][2] = {{0.}}; 95*b30619f6SJames Wright 96*b30619f6SJames Wright MatInv2(gij, gij_inv_mat, NULL); 97*b30619f6SJames Wright MatVec2(gij_inv_mat, velocity, CEED_NOTRANSPOSE, gij_uj); 98*b30619f6SJames Wright return sqrt(Dot2(velocity, gij_uj)) / diffusion_coeff; 99*b30619f6SJames Wright } 100