From 2a56e2b7eae582abc1b7e2eecd83af7a72610f9b Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Tue, 25 Feb 2020 16:53:03 -0800 Subject: FDTD: Real Literals and Formatting (#736) Clean up `amrex::Real` literals (aka "numbers"). This avoids calculating a line in double precision and casting it down to `Real` on assignment. Also fixes some formatting issues. (Commit credited to Remi.) Co-authored-by: Axel Huebl Co-authored-by: Remi Lehe --- .../CylindricalYeeAlgorithm.H | 31 +++++++++++++--------- 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CylindricalYeeAlgorithm.H') diff --git a/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CylindricalYeeAlgorithm.H b/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CylindricalYeeAlgorithm.H index ab32c8bcb..cdc693a78 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CylindricalYeeAlgorithm.H +++ b/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CylindricalYeeAlgorithm.H @@ -12,6 +12,8 @@ #include #include +#include + /** * This struct contains only static functions to initialize the stencil coefficients * and to compute finite-difference derivatives for the Cartesian Yee algorithm. @@ -23,11 +25,12 @@ struct CylindricalYeeAlgorithm { amrex::Gpu::ManagedVector& stencil_coefs_r, amrex::Gpu::ManagedVector& stencil_coefs_z ) { + using namespace amrex; // Store the inverse cell size along each direction in the coefficients stencil_coefs_r.resize(1); - stencil_coefs_r[0] = 1./cell_size[0]; // 1./dr + stencil_coefs_r[0] = 1._rt/cell_size[0]; // 1./dr stencil_coefs_z.resize(1); - stencil_coefs_z[0] = 1./cell_size[2]; // 1./dz + stencil_coefs_z[0] = 1._rt/cell_size[2]; // 1./dz } /** Applies the differential operator `1/r * d(rF)/dr`, @@ -41,8 +44,9 @@ struct CylindricalYeeAlgorithm { amrex::Real const * const coefs_r, int const n_coefs_r, int const i, int const j, int const k, int const comp ) { - amrex::Real const inv_dr = coefs_r[0]; - return 1./r * inv_dr*( (r+0.5*dr)*F(i+1,j,k,comp) - (r-0.5*dr)*F(i,j,k,comp) ); + using namespace amrex; + Real const inv_dr = coefs_r[0]; + return 1._rt/r * inv_dr*( (r+0.5_rt*dr)*F(i+1,j,k,comp) - (r-0.5_rt*dr)*F(i,j,k,comp) ); }; /** Applies the differential operator `1/r * d(rF)/dr`, @@ -56,36 +60,39 @@ struct CylindricalYeeAlgorithm { amrex::Real const * const coefs_r, int const n_coefs_r, int const i, int const j, int const k, int const comp ) { - amrex::Real const inv_dr = coefs_r[0]; - return 1./r * inv_dr*( (r+0.5*dr)*F(i,j,k,comp) - (r-0.5*dr)*F(i-1,j,k,comp) ); + using namespace amrex; + Real const inv_dr = coefs_r[0]; + return 1._rt/r * inv_dr*( (r+0.5_rt*dr)*F(i,j,k,comp) - (r-0.5_rt*dr)*F(i-1,j,k,comp) ); }; /** - /* Perform derivative along r on a cell-centered grid, from a nodal field `F`*/ + * Perform derivative along r on a cell-centered grid, from a nodal field `F` */ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static amrex::Real UpwardDr ( amrex::Array4 const& F, amrex::Real const * const coefs_r, int const n_coefs_r, int const i, int const j, int const k, int const comp ) { - amrex::Real const inv_dr = coefs_r[0]; + using namespace amrex; + Real const inv_dr = coefs_r[0]; return inv_dr*( F(i+1,j,k,comp) - F(i,j,k,comp) ); }; /** - /* Perform derivative along r on a nodal grid, from a cell-centered field `F`*/ + * Perform derivative along r on a nodal grid, from a cell-centered field `F` */ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static amrex::Real DownwardDr ( amrex::Array4 const& F, amrex::Real const * const coefs_r, int const n_coefs_r, int const i, int const j, int const k, int const comp ) { - amrex::Real const inv_dr = coefs_r[0]; + using namespace amrex; + Real const inv_dr = coefs_r[0]; return inv_dr*( F(i,j,k,comp) - F(i-1,j,k,comp) ); }; /** - /* Perform derivative along z on a cell-centered grid, from a nodal field `F`*/ + * Perform derivative along z on a cell-centered grid, from a nodal field `F` */ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static amrex::Real UpwardDz ( amrex::Array4 const& F, @@ -97,7 +104,7 @@ struct CylindricalYeeAlgorithm { }; /** - /* Perform derivative along z on a nodal grid, from a cell-centered field `F`*/ + * Perform derivative along z on a nodal grid, from a cell-centered field `F` */ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE static amrex::Real DownwardDz ( amrex::Array4 const& F, -- cgit v1.2.3