ARTEMIS
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  for (int j = 0; j < prt.m_num_runtime_real; ++j)
69  prt.m_runtime_rdata[j][i_prt] = initializeRealValue(m_policy_real[j+PartData::NAR], engine);
70 
71  // initialize the int components
72  for (int j = 0; j < PartData::NAI; ++j)
73  prt.m_idata[j][i_prt] = initializeIntValue(m_policy_int[j]);
74  for (int j = 0; j < prt.m_num_runtime_int; ++j)
75  prt.m_runtime_idata[j][i_prt] = initializeIntValue(m_policy_int[j+PartData::NAI]);
76  }
77 };
78 
87 {
90  bool m_defined;
91 
92 public:
93  template <class PartTileData>
94  SmartCreateFactory (const PartTileData& part) noexcept
95  : m_defined(false)
96  {
97  m_policy_real = getPolicies(part.getParticleComps());
98  m_policy_int = getPolicies(part.getParticleiComps());
99  m_defined = true;
100  }
101 
102  SmartCreate getSmartCreate () const noexcept
103  {
107  }
108 
109  bool isDefined () const noexcept { return m_defined; }
110 };
111 
112 #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:72
InitializationPolicy
This set of initialization policies describes what happens when we need to create a new particle due ...
Definition: DefaultInitialization.H:33
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal initializeRealValue(const InitializationPolicy policy, amrex::RandomEngine const &engine) noexcept
Definition: DefaultInitialization.H:56
PolicyVec getPolicies(const NameMap &names) noexcept
Definition: SmartUtils.cpp:16
A factory for creating SmartCreate functors.
Definition: SmartCreate.H:87
PolicyVec m_policy_real
Definition: SmartCreate.H:88
SmartCreateFactory(const PartTileData &part) noexcept
Definition: SmartCreate.H:94
bool isDefined() const noexcept
Definition: SmartCreate.H:109
SmartCreate getSmartCreate() const noexcept
Definition: SmartCreate.H:102
bool m_defined
Definition: SmartCreate.H:90
PolicyVec m_policy_int
Definition: SmartCreate.H:89
T * dataPtr() noexcept
def y
Definition: Excitation_Flag_Generator.py:76
def x
Formats datastring to remove "+" at the end of the string #####.
Definition: Excitation_Flag_Generator.py:75
def z
Definition: Excitation_Flag_Generator.py:77
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