MCPcopy Create free account
hub / github.com/AMReX-Codes/amrex / InitParticles

Method InitParticles

Tests/Particles/AsyncIO/main.cpp:64–182  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62 {}
63
64 void InitParticles (const amrex::IntVect& a_num_particles_per_cell)
65 {
66 BL_PROFILE("InitParticles");
67
68 const int lev = 0; // only add particles on level 0
69 const Real* dx = Geom(lev).CellSize();
70 const Real* plo = Geom(lev).ProbLo();
71
72 const int num_ppc = AMREX_D_TERM( a_num_particles_per_cell[0],
73 *a_num_particles_per_cell[1],
74 *a_num_particles_per_cell[2]);
75
76 for(MFIter mfi = MakeMFIter(lev); mfi.isValid(); ++mfi)
77 {
78 const Box& tile_box = mfi.tilebox();
79
80 Gpu::HostVector<ParticleType> host_particles;
81 std::array<Gpu::HostVector<ParticleReal>, NAR> host_real;
82 std::array<Gpu::HostVector<int>, NAI> host_int;
83
84 std::vector<Gpu::HostVector<ParticleReal> > host_runtime_real(NumRuntimeRealComps());
85 std::vector<Gpu::HostVector<int> > host_runtime_int(NumRuntimeIntComps());
86
87 for (IntVect iv = tile_box.smallEnd(); iv <= tile_box.bigEnd(); tile_box.next(iv))
88 {
89 for (int i_part=0; i_part<num_ppc;i_part++) {
90 Real r[3];
91 get_position_unit_cell(r, a_num_particles_per_cell, i_part);
92
93 ParticleType p;
94 p.id() = ParticleType::NextID();
95 p.cpu() = ParallelDescriptor::MyProc();
96 p.pos(0) = static_cast<ParticleReal> (plo[0] + (iv[0] + r[0])*dx[0]);
97#if AMREX_SPACEDIM > 1
98 p.pos(1) = static_cast<ParticleReal> (plo[1] + (iv[1] + r[1])*dx[1]);
99#endif
100#if AMREX_SPACEDIM > 2
101 p.pos(2) = static_cast<ParticleReal> (plo[2] + (iv[2] + r[2])*dx[2]);
102#endif
103
104 if constexpr (NSR > 0) {
105 for (int i = 0; i < NSR; ++i) {
106 p.rdata(i) = ParticleReal(p.id());
107 }
108 }
109 if constexpr (NSI > 0) {
110 for (int i = 0; i < NSI; ++i) {
111 p.idata(i) = p.id();
112 }
113 }
114
115 host_particles.push_back(p);
116
117 if constexpr (NAR > 0) {
118 for (int i = 0; i < NAR; ++i) {
119 host_real[i].push_back(ParticleReal(p.id()));
120 }
121 }

Callers 1

test_async_ioFunction · 0.45

Calls 15

copyAsyncFunction · 0.85
streamSynchronizeFunction · 0.85
tileboxMethod · 0.80
LocalTileIndexMethod · 0.80
GetArrayOfStructsMethod · 0.80
GetStructOfArraysMethod · 0.80
GetRealDataMethod · 0.80
GetIntDataMethod · 0.80
get_position_unit_cellFunction · 0.70
AMREX_D_TERMFunction · 0.50
MyProcFunction · 0.50
CellSizeMethod · 0.45

Tested by 1

test_async_ioFunction · 0.36