WarpX
SmartCreate.H
Go to the documentation of this file.
1 /* Copyright 2019-2020 Luca Fedeli, Neil Zaim
2  *
3  * This file is part of WarpX.
4  *
5  * License: BSD-3-Clause-LBNL
6  */
7 
8 #ifndef SMART_CREATE_H_
9 #define SMART_CREATE_H_
10 
11 #include "DefaultInitialization.H"
12 
13 #include <AMReX.H>
14 #include <AMReX_AmrCore.H>
15 #include <AMReX_GpuContainers.H>
17 
33 {
36  const int m_weight_index = 0;
37 
38  template <typename PartData>
41  PartData& prt, const int i_prt,
42  amrex::RandomEngine const& engine,
43  const amrex::Real x = 0.0,
44  const amrex::Real y = 0.0,
45  const amrex::Real z = 0.0,
46  const int cpu = 0,
47  const int id = 0) const noexcept
48  {
49 #if defined(WARPX_DIM_3D)
50  prt.m_aos[i_prt].pos(0) = x;
51  prt.m_aos[i_prt].pos(1) = y;
52  prt.m_aos[i_prt].pos(2) = z;
53 #elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
54  prt.m_aos[i_prt].pos(0) = x;
55  prt.m_aos[i_prt].pos(1) = z;
57 #else
58  prt.m_aos[i_prt].pos(0) = z;
60 #endif
61 
62  prt.m_aos[i_prt].cpu() = cpu;
63  prt.m_aos[i_prt].id() = id;
64 
65  // initialize the real components
66  for (int j = 0; j < PartData::NAR; ++j) {
67  prt.m_rdata[j][i_prt] = initializeRealValue(m_policy_real[j], engine);
68  }
69  for (int j = 0; j < prt.m_num_runtime_real; ++j) {
70  prt.m_runtime_rdata[j][i_prt] = initializeRealValue(m_policy_real[j+PartData::NAR], engine);
71  }
72 
73  // initialize the int components
74  for (int j = 0; j < PartData::NAI; ++j) {
75  prt.m_idata[j][i_prt] = initializeIntValue(m_policy_int[j]);
76  }
77  for (int j = 0; j < prt.m_num_runtime_int; ++j) {
78  prt.m_runtime_idata[j][i_prt] = initializeIntValue(m_policy_int[j+PartData::NAI]);
79  }
80  }
81 };
82 
91 {
94  bool m_defined{false};
95 
96 public:
97  template <class PartTileData>
98  SmartCreateFactory (const PartTileData& part) noexcept:
99  m_policy_real{getPolicies(part.getParticleComps())},
100  m_policy_int{getPolicies(part.getParticleiComps())},
101  m_defined{true}
102  {}
103 
104  [[nodiscard]] SmartCreate getSmartCreate () const noexcept
105  {
109  }
110 
111  [[nodiscard]] bool isDefined () const noexcept { return m_defined; }
112 };
113 
114 #endif //SMART_CREATE_H_
#define AMREX_ASSERT(EX)
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int initializeIntValue(const InitializationPolicy policy) noexcept
Definition: DefaultInitialization.H:78
InitializationPolicy
This set of initialization policies describes what happens when we need to create a new particle due ...
Definition: DefaultInitialization.H:39
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal initializeRealValue(const InitializationPolicy policy, amrex::RandomEngine const &engine) noexcept
Definition: DefaultInitialization.H:62
PolicyVec getPolicies(const NameMap &names) noexcept
Definition: SmartUtils.cpp:16
A factory for creating SmartCreate functors.
Definition: SmartCreate.H:91
PolicyVec m_policy_real
Definition: SmartCreate.H:92
SmartCreateFactory(const PartTileData &part) noexcept
Definition: SmartCreate.H:98
bool isDefined() const noexcept
Definition: SmartCreate.H:111
SmartCreate getSmartCreate() const noexcept
Definition: SmartCreate.H:104
bool m_defined
Definition: SmartCreate.H:94
PolicyVec m_policy_int
Definition: SmartCreate.H:93
T * dataPtr() noexcept
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void ignore_unused(const Ts &...)
This is a functor for performing a "smart create" that works in both host and device code.
Definition: SmartCreate.H:33
const int m_weight_index
Definition: SmartCreate.H:36
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void operator()(PartData &prt, const int i_prt, amrex::RandomEngine const &engine, const amrex::Real x=0.0, const amrex::Real y=0.0, const amrex::Real z=0.0, const int cpu=0, const int id=0) const noexcept
Definition: SmartCreate.H:40
const InitializationPolicy * m_policy_int
Definition: SmartCreate.H:35
const InitializationPolicy * m_policy_real
Definition: SmartCreate.H:34