From 324115542740ca838d645b1f1d01cb50bd17e584 Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Wed, 22 Jul 2020 17:29:51 -0700 Subject: Cleaner calculation of the simulation timestep (#1031) * Cleaner calculation of the simulation timestep * Fix compilation errors * Remove specification of CKC solver in PSATD test * Correct calculation of dt * Fix compilation error * Cleaner calculation of the simulation timestep * Fix compilation errors * Remove specification of CKC solver in PSATD test * Correct calculation of dt * Fix compilation error * Cleanup for cylindrical * Change input of automated tests to preserve previous results * Fix import statement for cylindrical * Preserve dt for PML test * Move function documentation to WarpX.H * Update CMakeList * Update CFL in some tests * Apply suggestions from code review Co-authored-by: Axel Huebl * Fix compilation errors * Revert "Fix compilation errors" This reverts commit 56ef67f228269b266876629f49789d3afdbbc00b. * Fix compilation error * Add cmath headers Add directly used header files. * Fix Include Order Co-authored-by: Axel Huebl --- .../FiniteDifferenceAlgorithms/CartesianCKCAlgorithm.H | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CartesianCKCAlgorithm.H') diff --git a/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CartesianCKCAlgorithm.H b/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CartesianCKCAlgorithm.H index 9c52327e3..bb480364a 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CartesianCKCAlgorithm.H +++ b/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CartesianCKCAlgorithm.H @@ -8,6 +8,8 @@ #ifndef WARPX_FINITE_DIFFERENCE_ALGORITHM_CARTESIAN_CKC_H_ #define WARPX_FINITE_DIFFERENCE_ALGORITHM_CARTESIAN_CKC_H_ +#include "Utils/WarpXConst.H" + #include #include #include @@ -15,6 +17,7 @@ #include #include + /** * This struct contains only static functions to initialize the stencil coefficients * and to compute finite-difference derivatives for the Cartesian CKC algorithm. @@ -90,6 +93,20 @@ struct CartesianCKCAlgorithm { stencil_coefs_z[4] = gammaz*inv_dz; } + /** + * Compute the maximum timestep, for which the scheme remains stable + * (Courant-Friedrichs-Levy limit) */ + static amrex::Real ComputeMaxDt ( amrex::Real const * const dx ) { +#if (defined WARPX_DIM_XZ) + // - In Cartesian 2D geometry: determined by the minimum cell size in all direction + amrex::Real const delta_t = std::min( dx[0], dx[1] )/PhysConst::c; +#else + // - In Cartesian 3D geometry: determined by the minimum cell size in all direction + amrex::Real const delta_t = std::min( dx[0], std::min( dx[1], dx[2] ) ) / PhysConst::c; +#endif + return delta_t; + } + /** * Perform derivative along x on a cell-centered grid, from a nodal field `F` */ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -- cgit v1.2.3