WarpX
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 
12 #include "DefaultInitialization.H"
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 
26 using 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 
38 PolicyVec getPolicies (const NameMap& names) noexcept;
39 
40 SmartCopyTag getSmartCopyTag (const NameMap& src, const NameMap& dst) noexcept;
41 
51 template <typename PTile>
52 void 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
std::map< std::string, int > NameMap
Definition: SmartUtils.H:26
PolicyVec getPolicies(const NameMap &names) noexcept
Definition: SmartUtils.cpp:16
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(const NameMap &src, const NameMap &dst) noexcept
Definition: SmartUtils.cpp:34
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE std::uint64_t SetParticleIDandCPU(Long id, int cpu) noexcept
std::enable_if_t< std::is_integral_v< T > > ParallelFor(TypeList< CTOs... >, std::array< int, sizeof...(CTOs)> const &runtime_options, T N, F &&f)
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