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