WarpX
CoarsenIO.H
Go to the documentation of this file.
1 #ifndef WARPX_COARSEN_IO_H_
2 #define WARPX_COARSEN_IO_H_
3 
4 #include "WarpX.H"
5 #include <AMReX_Math.H>
6 
7 namespace CoarsenIO{
8 
9  using namespace amrex;
10 
28  AMREX_GPU_DEVICE
29  AMREX_FORCE_INLINE
30  Real Interp ( Array4<Real const> const& arr_src,
31  GpuArray<int,3> const& sf,
32  GpuArray<int,3> const& sc,
33  GpuArray<int,3> const& cr,
34  const int i,
35  const int j,
36  const int k,
37  const int comp )
38  {
39  // Indices of destination array (coarse)
40  const int ic[3] = { i, j, k };
41 
42  // Number of points and starting indices of source array (fine)
43  int np[3], idx_min[3];
44 
45  // Compute number of points
46  for ( int l = 0; l < 3; ++l ) {
47  if ( cr[l] == 1 ) np[l] = 1+amrex::Math::abs(sf[l]-sc[l]); // no coarsening
48  else np[l] = 2-sf[l];
49  }
50 
51  // Compute starting indices of source array (fine)
52  for ( int l = 0; l < 3; ++l ) {
53  if ( cr[l] == 1 ) idx_min[l] = ic[l]-sc[l]*(1-sf[l]); // no coarsening
54  else idx_min[l] = ic[l]*cr[l]+static_cast<int>(cr[l]/2)*(1-sc[l])-(1-sf[l]);
55  }
56 
57  // Auxiliary integer variables
58  const int numx = np[0];
59  const int numy = np[1];
60  const int numz = np[2];
61  const int imin = idx_min[0];
62  const int jmin = idx_min[1];
63  const int kmin = idx_min[2];
64  int ii, jj, kk;
65  Real wx, wy, wz;
66 
67  // Interpolate over points computed above
68  Real c = 0.0_rt;
69  for (int kref = 0; kref < numz; ++kref) {
70  for (int jref = 0; jref < numy; ++jref) {
71  for (int iref = 0; iref < numx; ++iref) {
72  ii = imin+iref;
73  jj = jmin+jref;
74  kk = kmin+kref;
75  wx = 1.0_rt/static_cast<Real>(numx);
76  wy = 1.0_rt/static_cast<Real>(numy);
77  wz = 1.0_rt/static_cast<Real>(numz);
78  c += wx*wy*wz*arr_src(ii,jj,kk,comp);
79  }
80  }
81  }
82  return c;
83  }
84 
104  void Loop ( MultiFab& mf_dst,
105  const MultiFab& mf_src,
106  const int dcomp,
107  const int scomp,
108  const int ncomp,
109  const int ngrow,
110  const IntVect crse_ratio=IntVect(1) );
111 
131  void Coarsen ( MultiFab& mf_dst,
132  const MultiFab& mf_src,
133  const int dcomp,
134  const int scomp,
135  const int ncomp,
136  const int ngrow,
137  const IntVect crse_ratio=IntVect(1) );
138 }
139 
140 #endif // WARPX_COARSEN_IO_H_
imin
Definition: check_interp_points_and_weights.py:121
void Coarsen(MultiFab &mf_dst, const MultiFab &mf_src, const int dcomp, const int scomp, const int ncomp, const int ngrow, const IntVect crse_ratio=IntVect(1))
Stores in the coarsened MultiFab mf_dst the values obtained by interpolating the data contained in th...
Definition: CoarsenIO.cpp:73
Definition: CoarsenIO.H:7
ii
Definition: check_interp_points_and_weights.py:145
i
Definition: check_interp_points_and_weights.py:171
AMREX_GPU_DEVICE AMREX_FORCE_INLINE Real Interp(Array4< Real const > const &arr_src, GpuArray< int, 3 > const &sf, GpuArray< int, 3 > const &sc, GpuArray< int, 3 > const &cr, const int i, const int j, const int k, const int comp)
Interpolates the floating point data contained in the source Array4 arr_src, extracted from a fine Mu...
Definition: CoarsenIO.H:30
jj
Definition: check_interp_points_and_weights.py:157
cr
TODO Coarsening for IO: interpolation points and weights def coarsening_points_and_weights_for_IO( i...
Definition: check_interp_points_and_weights.py:98
Definition: PML.H:52
void Loop(MultiFab &mf_dst, const MultiFab &mf_src, const int dcomp, const int scomp, const int ncomp, const int ngrow, const IntVect crse_ratio=IntVect(1))
Loops over the boxes of the coarsened MultiFab mf_dst and fills them by interpolating the data contai...
Definition: CoarsenIO.cpp:6