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 SMART_UTILS_H_
10 #define SMART_UTILS_H_
11 
12 #include "DefaultInitialization.H"
13 
14 using NameMap = std::map<std::string, int>;
15 using PolicyVec = amrex::Gpu::DeviceVector<InitializationPolicy>;
16 
18 {
19  std::vector<std::string> common_names;
20  amrex::Gpu::DeviceVector<int> src_comps;
21  amrex::Gpu::DeviceVector<int> dst_comps;
22 
23  int size () const noexcept { return common_names.size(); }
24 };
25 
26 PolicyVec getPolicies (const NameMap& names) noexcept;
27 
28 SmartCopyTag getSmartCopyTag (const NameMap& src, const NameMap& dst) noexcept;
29 
39 template <typename PTile>
40 void setNewParticleIDs (PTile& ptile, int old_size, int num_added)
41 {
42  amrex::Long pid;
43 #ifdef _OPENMP
44 #pragma omp critical (ionization_nextid)
45 #endif
46  {
47  pid = PTile::ParticleType::NextID();
48  PTile::ParticleType::NextID(pid + num_added);
49  }
50 
51  const int cpuid = amrex::ParallelDescriptor::MyProc();
52  auto pp = ptile.GetArrayOfStructs()().data() + old_size;
53  amrex::ParallelFor(num_added, [=] AMREX_GPU_DEVICE (int ip) noexcept
54  {
55  auto& p = pp[ip];
56  p.id() = pid+ip;
57  p.cpu() = cpuid;
58  });
59 }
60 
61 #endif //SMART_UTILS_H_
data
Definition: run_alltests_1node.py:320
int size() const noexcept
Definition: SmartUtils.H:23
void setNewParticleIDs(PTile &ptile, int old_size, int num_added)
Sets the ids of newly created particles to the next values.
Definition: SmartUtils.H:40
amrex::Gpu::DeviceVector< InitializationPolicy > PolicyVec
Definition: SmartUtils.H:15
Definition: SmartUtils.H:17
PolicyVec getPolicies(const NameMap &names) noexcept
Definition: SmartUtils.cpp:10
names
Definition: plot_results.py:41
amrex::Gpu::DeviceVector< int > dst_comps
Definition: SmartUtils.H:21
std::vector< std::string > common_names
Definition: SmartUtils.H:19
SmartCopyTag getSmartCopyTag(const NameMap &src, const NameMap &dst) noexcept
Definition: SmartUtils.cpp:21
amrex::Gpu::DeviceVector< int > src_comps
Definition: SmartUtils.H:20
std::map< std::string, int > NameMap
Definition: SmartUtils.H:14