WarpX
Loading...
Searching...
No Matches
SmartUtils.H
Go to the documentation of this file.
1/* Copyright 2019-2020 Andrew Myers, Axel Huebl,
2 * Maxence Thevenet
3 *
4 * This file is part of WarpX.
5 *
6 * License: BSD-3-Clause-LBNL
7 */
8
9#ifndef WARPX_SMART_UTILS_H_
10#define WARPX_SMART_UTILS_H_
11
13
14#include <AMReX_Config.H>
15#include <AMReX_GpuContainers.H>
16#include <AMReX_GpuLaunch.H>
17#include <AMReX_GpuQualifiers.H>
18#include <AMReX_INT.H>
20#include <AMReX_Particle.H>
21
22#include <map>
23#include <string>
24#include <vector>
25
26using NameMap = std::map<std::string, int>;
28
30{
31 std::vector<std::string> common_names;
34
35 [[nodiscard]] int size () const noexcept { return static_cast<int>(common_names.size()); }
36};
37
38PolicyVec getPolicies (std::vector<std::string> const & names) noexcept;
39
40SmartCopyTag getSmartCopyTag (std::vector<std::string> const & src, std::vector<std::string> const & dst) noexcept;
41
51template <typename PTile>
52void setNewParticleIDs (PTile& ptile, amrex::Long old_size, amrex::Long num_added)
53{
54 amrex::Long pid;
55#ifdef AMREX_USE_OMP
56#pragma omp critical (ionization_nextid)
57#endif
58 {
59 pid = PTile::ParticleType::NextID();
60 PTile::ParticleType::NextID(pid + num_added);
61 }
62
63 const int cpuid = amrex::ParallelDescriptor::MyProc();
64 auto ptd = ptile.getParticleTileData();
65 amrex::ParallelFor(num_added, [=] AMREX_GPU_DEVICE (int ip) noexcept
66 {
67 auto const lip = static_cast<amrex::Long>(ip);
68 auto const new_id = lip + old_size;
69 ptd.m_idcpu[new_id] = amrex::SetParticleIDandCPU(pid+lip, cpuid);
70 });
71}
72
73#endif //WARPX_SMART_UTILS_H_
#define AMREX_GPU_DEVICE
PolicyVec getPolicies(std::vector< std::string > const &names) noexcept
Definition SmartUtils.cpp:16
std::map< std::string, int > NameMap
Definition SmartUtils.H:26
amrex::Gpu::DeviceVector< InitializationPolicy > PolicyVec
Definition SmartUtils.H:27
void setNewParticleIDs(PTile &ptile, amrex::Long old_size, amrex::Long num_added)
Sets the ids of newly created particles to the next values.
Definition SmartUtils.H:52
SmartCopyTag getSmartCopyTag(std::vector< std::string > const &src, std::vector< std::string > const &dst) noexcept
Definition SmartUtils.cpp:37
PODVector< T, ArenaAllocator< T > > DeviceVector
std::enable_if_t< std::is_integral_v< T > > ParallelFor(TypeList< CTOs... > ctos, std::array< int, sizeof...(CTOs)> const &runtime_options, T N, F &&f)
__host__ __device__ std::uint64_t SetParticleIDandCPU(Long id, int cpu) noexcept
Definition SmartUtils.H:30
amrex::Gpu::DeviceVector< int > dst_comps
Definition SmartUtils.H:33
int size() const noexcept
Definition SmartUtils.H:35
amrex::Gpu::DeviceVector< int > src_comps
Definition SmartUtils.H:32
std::vector< std::string > common_names
Definition SmartUtils.H:31