ARTEMIS
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 #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 
21 #include <map>
22 #include <string>
23 #include <vector>
24 
25 using NameMap = std::map<std::string, int>;
27 
29 {
30  std::vector<std::string> common_names;
33 
34  int size () const noexcept { return common_names.size(); }
35 };
36 
37 PolicyVec getPolicies (const NameMap& names) noexcept;
38 
39 SmartCopyTag getSmartCopyTag (const NameMap& src, const NameMap& dst) noexcept;
40 
50 template <typename PTile>
51 void setNewParticleIDs (PTile& ptile, int old_size, int num_added)
52 {
53  amrex::Long pid;
54 #ifdef AMREX_USE_OMP
55 #pragma omp critical (ionization_nextid)
56 #endif
57  {
58  pid = PTile::ParticleType::NextID();
59  PTile::ParticleType::NextID(pid + num_added);
60  }
61 
62  const int cpuid = amrex::ParallelDescriptor::MyProc();
63  auto pp = ptile.GetArrayOfStructs()().data() + old_size;
64  amrex::ParallelFor(num_added, [=] AMREX_GPU_DEVICE (int ip) noexcept
65  {
66  auto& p = pp[ip];
67  p.id() = pid+ip;
68  p.cpu() = cpuid;
69  });
70 }
71 
72 #endif //SMART_UTILS_H_
#define AMREX_GPU_DEVICE
amrex::ParmParse pp
std::map< std::string, int > NameMap
Definition: SmartUtils.H:25
PolicyVec getPolicies(const NameMap &names) noexcept
Definition: SmartUtils.cpp:16
SmartCopyTag getSmartCopyTag(const NameMap &src, const NameMap &dst) noexcept
Definition: SmartUtils.cpp:34
void setNewParticleIDs(PTile &ptile, int old_size, int num_added)
Sets the ids of newly created particles to the next values.
Definition: SmartUtils.H:51
list data
open text file and read data #####
Definition: Excitation_Flag_Generator.py:24
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)
names
Definition: plot_results.py:42
Definition: SmartUtils.H:29
amrex::Gpu::DeviceVector< int > dst_comps
Definition: SmartUtils.H:32
int size() const noexcept
Definition: SmartUtils.H:34
amrex::Gpu::DeviceVector< int > src_comps
Definition: SmartUtils.H:31
std::vector< std::string > common_names
Definition: SmartUtils.H:30