| 228 | } |
| 229 | |
| 230 | Real |
| 231 | Castro::locSquaredSum (const std::string& name, |
| 232 | Real time, |
| 233 | int idir, |
| 234 | bool local) |
| 235 | { |
| 236 | BL_PROFILE("Castro::locSquaredSum()"); |
| 237 | |
| 238 | auto mf = derive(name, time, 0); |
| 239 | |
| 240 | BL_ASSERT(mf); |
| 241 | |
| 242 | bool mask_available = level < parent->finestLevel(); |
| 243 | |
| 244 | MultiFab tmp_mf; |
| 245 | const MultiFab& mask_mf = mask_available ? getLevel(level+1).build_fine_mask() : tmp_mf; |
| 246 | |
| 247 | ReduceOps<ReduceOpSum> reduce_op; |
| 248 | ReduceData<Real> reduce_data(reduce_op); |
| 249 | using ReduceTuple = typename decltype(reduce_data)::Type; |
| 250 | |
| 251 | auto dx = geom.CellSizeArray(); |
| 252 | auto problo = geom.ProbLoArray(); |
| 253 | |
| 254 | #ifdef AMREX_USE_OMP |
| 255 | #pragma omp parallel |
| 256 | #endif |
| 257 | for (MFIter mfi(*mf, TilingIfNotGPU()); mfi.isValid(); ++mfi) |
| 258 | { |
| 259 | auto const& fab = (*mf).array(mfi); |
| 260 | auto const& mask = mask_available ? mask_mf.array(mfi) : Array4<Real>{}; |
| 261 | |
| 262 | const Box& box = mfi.tilebox(); |
| 263 | |
| 264 | reduce_op.eval(box, reduce_data, |
| 265 | [=] AMREX_GPU_HOST_DEVICE (int i, int j, int k) -> ReduceTuple |
| 266 | { |
| 267 | Real maskFactor = mask_available ? mask(i,j,k) : 1.0_rt; |
| 268 | |
| 269 | Real loc[3]; |
| 270 | |
| 271 | loc[0] = problo[0] + (0.5_rt + i) * dx[0]; |
| 272 | |
| 273 | #if AMREX_SPACEDIM >= 2 |
| 274 | loc[1] = problo[1] + (0.5_rt + j) * dx[1]; |
| 275 | #else |
| 276 | loc[1] = 0.0_rt; |
| 277 | #endif |
| 278 | |
| 279 | #if AMREX_SPACEDIM == 3 |
| 280 | loc[2] = problo[2] + (0.5_rt + k) * dx[2]; |
| 281 | #else |
| 282 | loc[2] = 0.0_rt; |
| 283 | #endif |
| 284 | |
| 285 | Real ds; |
| 286 | |
| 287 | if (idir == 0) { // sum(mass * x^2) |
no test coverage detected