Skip to content

Commit 606ad54

Browse files
committed
move linear interpolation to ablastr
1 parent cfd9d1d commit 606ad54

File tree

3 files changed

+44
-39
lines changed

3 files changed

+44
-39
lines changed

Source/Initialization/WarpXInitData.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include "Initialization/ExternalField.H"
3030
#include "Initialization/DivCleaner/ProjectionDivCleaner.H"
3131
#include "Particles/MultiParticleContainer.H"
32-
#include "Utils/Algorithms/LinearInterpolation.H"
3332
#include "Utils/Logo/GetLogo.H"
3433
#include "Utils/Parser/ParserUtils.H"
3534
#include "Utils/TextMsg.H"
@@ -40,6 +39,7 @@
4039
#include "Python/callbacks.H"
4140

4241
#include <ablastr/fields/MultiFabRegister.H>
42+
#include <ablastr/math/LinearInterpolation.H>
4343
#include <ablastr/parallelization/MPIInitHelpers.H>
4444
#include <ablastr/utils/Communication.H>
4545
#include <ablastr/utils/UsedInputsFile.H>
@@ -1698,7 +1698,7 @@ WarpX::ReadExternalFieldFromFile (
16981698
f01 = fc_array(0, iz , ir+1),
16991699
f10 = fc_array(0, iz+1, ir ),
17001700
f11 = fc_array(0, iz+1, ir+1);
1701-
mffab(i,j,k) = static_cast<amrex::Real>(utils::algorithms::bilinear_interp<double>
1701+
mffab(i,j,k) = static_cast<amrex::Real>(ablastr::math::bilinear_interp<double>
17021702
(xx0, xx0+file_dr, xx1, xx1+file_dz,
17031703
f00, f01, f10, f11,
17041704
x0, x1));
@@ -1713,7 +1713,7 @@ WarpX::ReadExternalFieldFromFile (
17131713
f101 = fc_array(iz+1, iy , ix+1),
17141714
f110 = fc_array(iz , iy+1, ix+1),
17151715
f111 = fc_array(iz+1, iy+1, ix+1);
1716-
mffab(i,j,k) = static_cast<amrex::Real>(utils::algorithms::trilinear_interp<double>
1716+
mffab(i,j,k) = static_cast<amrex::Real>(ablastr::math::trilinear_interp<double>
17171717
(xx0, xx0+file_dx, xx1, xx1+file_dy, xx2, xx2+file_dz,
17181718
f000, f001, f010, f011, f100, f101, f110, f111,
17191719
x0, x1, x2));

Source/Laser/LaserProfilesImpl/LaserProfileFromFile.cpp

+30-28
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
*/
77
#include "Laser/LaserProfiles.H"
88

9-
#include "Utils/Algorithms/LinearInterpolation.H"
109
#include "Utils/Parser/ParserUtils.H"
1110
#include "Utils/TextMsg.H"
1211
#include "Utils/WarpX_Complex.H"
1312
#include "Utils/WarpXConst.H"
1413

14+
#include <ablastr/math/LinearInterpolation.H>
1515
#include <ablastr/warn_manager/WarnManager.H>
1616

1717
#include <AMReX.H>
@@ -489,7 +489,7 @@ WarpXLaserProfiles::FromFileLaserProfile::internal_fill_amplitude_uniform_cartes
489489
(i_interp-tmp_idx_first_time)*tmp_nx*tmp_ny+
490490
j_interp*tmp_nx + k_interp;
491491
};
492-
const Complex val = utils::algorithms::trilinear_interp(
492+
const Complex val = ablastr::math::trilinear_interp(
493493
t_left, t_right,
494494
x_0, x_1,
495495
y_0, y_1,
@@ -574,33 +574,35 @@ WarpXLaserProfiles::FromFileLaserProfile::internal_fill_amplitude_uniform_cylind
574574
Complex fact = Complex{costheta, sintheta};
575575

576576
// azimuthal mode 0
577-
val += utils::algorithms::bilinear_interp(
578-
t_left, t_right,
579-
r_0, r_1,
580-
p_E_lasy_data[idx(0, idx_t_left, idx_r_left)],
581-
p_E_lasy_data[idx(0, idx_t_left, idx_r_right)],
582-
p_E_lasy_data[idx(0, idx_t_right, idx_r_left)],
583-
p_E_lasy_data[idx(0, idx_t_right, idx_r_right)],
584-
t, Rp_i);
577+
val +=
578+
ablastr::math::bilinear_interp(
579+
t_left, t_right,
580+
r_0, r_1,
581+
p_E_lasy_data[idx(0, idx_t_left, idx_r_left)],
582+
p_E_lasy_data[idx(0, idx_t_left, idx_r_right)],
583+
p_E_lasy_data[idx(0, idx_t_right, idx_r_left)],
584+
p_E_lasy_data[idx(0, idx_t_right, idx_r_right)],
585+
t, Rp_i);
585586

586587
// higher modes
587588
for (int m=1 ; m <= tmp_n_rz_azimuthal_components/2; m++) {
588-
val += utils::algorithms::bilinear_interp(
589-
t_left, t_right,
590-
r_0, r_1,
591-
p_E_lasy_data[idx(2*m-1, idx_t_left, idx_r_left)],
592-
p_E_lasy_data[idx(2*m-1, idx_t_left, idx_r_right)],
593-
p_E_lasy_data[idx(2*m-1, idx_t_right, idx_r_left)],
594-
p_E_lasy_data[idx(2*m-1, idx_t_right, idx_r_right)],
595-
t, Rp_i)*(fact.real()) +
596-
utils::algorithms::bilinear_interp(
597-
t_left, t_right,
598-
r_0, r_1,
599-
p_E_lasy_data[idx(2*m, idx_t_left, idx_r_left)],
600-
p_E_lasy_data[idx(2*m, idx_t_left, idx_r_right)],
601-
p_E_lasy_data[idx(2*m, idx_t_right, idx_r_left)],
602-
p_E_lasy_data[idx(2*m, idx_t_right, idx_r_right)],
603-
t, Rp_i)*(fact.imag()) ;
589+
val +=
590+
ablastr::math::bilinear_interp(
591+
t_left, t_right,
592+
r_0, r_1,
593+
p_E_lasy_data[idx(2*m-1, idx_t_left, idx_r_left)],
594+
p_E_lasy_data[idx(2*m-1, idx_t_left, idx_r_right)],
595+
p_E_lasy_data[idx(2*m-1, idx_t_right, idx_r_left)],
596+
p_E_lasy_data[idx(2*m-1, idx_t_right, idx_r_right)],
597+
t, Rp_i)*(fact.real()) +
598+
ablastr::math::bilinear_interp(
599+
t_left, t_right,
600+
r_0, r_1,
601+
p_E_lasy_data[idx(2*m, idx_t_left, idx_r_left)],
602+
p_E_lasy_data[idx(2*m, idx_t_left, idx_r_right)],
603+
p_E_lasy_data[idx(2*m, idx_t_right, idx_r_left)],
604+
p_E_lasy_data[idx(2*m, idx_t_right, idx_r_right)],
605+
t, Rp_i)*(fact.imag()) ;
604606
fact = fact*Complex{costheta, sintheta};
605607
}
606608
amplitude[i] = (val*exp_omega_t).real();
@@ -683,7 +685,7 @@ WarpXLaserProfiles::FromFileLaserProfile::internal_fill_amplitude_uniform_binary
683685
(i_interp-tmp_idx_first_time)*tmp_nx*tmp_ny+
684686
j_interp*tmp_ny + k_interp;
685687
};
686-
amplitude[i] = utils::algorithms::trilinear_interp(
688+
amplitude[i] = ablastr::math::trilinear_interp(
687689
t_left, t_right,
688690
x_0, x_1,
689691
y_0, y_1,
@@ -702,7 +704,7 @@ WarpXLaserProfiles::FromFileLaserProfile::internal_fill_amplitude_uniform_binary
702704
const auto idx = [=](int i_interp, int j_interp){
703705
return (i_interp-tmp_idx_first_time) * tmp_nx + j_interp;
704706
};
705-
amplitude[i] = utils::algorithms::bilinear_interp(
707+
amplitude[i] = ablastr::math::bilinear_interp(
706708
t_left, t_right,
707709
x_0, x_1,
708710
p_E_binary_data[idx(idx_t_left, idx_x_left)],

Source/Utils/Algorithms/LinearInterpolation.H Source/ablastr/math/LinearInterpolation.H

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1-
/* Copyright 2022 Luca Fedeli
1+
/* Copyright 2022-2025 Luca Fedeli
22
*
33
* This file is part of WarpX.
44
*
55
* License: BSD-3-Clause-LBNL
66
*/
77

8-
#ifndef WARPX_UTILS_ALGORITHMS_LINEAR_INTERPOLATION_H_
9-
#define WARPX_UTILS_ALGORITHMS_LINEAR_INTERPOLATION_H_
8+
#ifndef ABLASTR_MATH_LINEAR_INTERPOLATION_H_
9+
#define ABLASTR_MATH_LINEAR_INTERPOLATION_H_
1010

1111
#include <AMReX_Extension.H>
1212
#include <AMReX_GpuQualifiers.H>
1313

14-
namespace utils::algorithms
14+
namespace ablastr::math
1515
{
1616
/** \brief Performs a linear interpolation
1717
*
1818
* Performs a linear interpolation at x given the 2 points
1919
* (x0, f0) and (x1, f1)
2020
*/
21-
template<typename TCoord, typename TVal> AMREX_GPU_DEVICE AMREX_FORCE_INLINE
21+
template<typename TCoord, typename TVal>
22+
AMREX_GPU_DEVICE AMREX_FORCE_INLINE
2223
constexpr auto linear_interp(
2324
TCoord x0, TCoord x1,
2425
TVal f0, TVal f1,
@@ -32,7 +33,8 @@ namespace utils::algorithms
3233
* Performs a bilinear interpolation at (x,y) given the 4 points
3334
* (x0, y0, f00), (x0, y1, f01), (x1, y0, f10), (x1, y1, f11).
3435
*/
35-
template<typename TCoord, typename TVal> AMREX_GPU_DEVICE AMREX_FORCE_INLINE
36+
template<typename TCoord, typename TVal>
37+
AMREX_GPU_DEVICE AMREX_FORCE_INLINE
3638
constexpr auto bilinear_interp(
3739
TCoord x0, TCoord x1, TCoord y0, TCoord y1,
3840
TVal f00, TVal f01, TVal f10, TVal f11,
@@ -49,7 +51,8 @@ namespace utils::algorithms
4951
* (x0, y0, z0, f000), (x0, y0, z1, f001), (x0, y1, z0, f010), (x0, y1, z1, f011),
5052
* (x1, y0, z0, f100), (x1, y0, z1, f101), (x1, y1, z0, f110), (x1, y1, z1, f111)
5153
*/
52-
template<typename TCoord, typename TVal> AMREX_GPU_DEVICE AMREX_FORCE_INLINE
54+
template<typename TCoord, typename TVal>
55+
AMREX_GPU_DEVICE AMREX_FORCE_INLINE
5356
constexpr auto trilinear_interp(
5457
TCoord x0, TCoord x1, TCoord y0, TCoord y1, TCoord z0, TCoord z1,
5558
TVal f000, TVal f001, TVal f010, TVal f011, TVal f100, TVal f101, TVal f110, TVal f111,
@@ -63,4 +66,4 @@ namespace utils::algorithms
6366
}
6467
}
6568

66-
#endif //WARPX_UTILS_ALGORITHMS_LINEAR_INTERPOLATION_H_
69+
#endif //ABLASTR_MATH_LINEAR_INTERPOLATION_H_

0 commit comments

Comments
 (0)