WarpX
Toggle main menu visibility
Loading...
Searching...
No Matches
Source
Particles
ParticleCreation
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 WARPX_SMART_UTILS_H_
10
#define WARPX_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
>
19
#include <
AMReX_ParallelDescriptor.H
>
20
#include <
AMReX_Particle.H
>
21
22
#include <map>
23
#include <string>
24
#include <vector>
25
26
using
NameMap
= std::map<std::string, int>;
27
using
PolicyVec
=
amrex::Gpu::DeviceVector<InitializationPolicy>
;
28
29
struct
SmartCopyTag
30
{
31
std::vector<std::string>
common_names
;
32
amrex::Gpu::DeviceVector<int>
src_comps
;
33
amrex::Gpu::DeviceVector<int>
dst_comps
;
34
35
[[nodiscard]]
int
size
() const noexcept {
return
static_cast<
int
>
(
common_names
.size()); }
36
};
37
38
PolicyVec
getPolicies
(std::vector<std::string>
const
& names)
noexcept
;
39
40
SmartCopyTag
getSmartCopyTag
(std::vector<std::string>
const
& src, std::vector<std::string>
const
& dst)
noexcept
;
41
51
template
<
typename
PTile>
52
void
setNewParticleIDs
(PTile& ptile,
amrex::Long
old_size,
amrex::Long
num_added)
53
{
54
amrex::Long
pid;
55
#ifdef AMREX_USE_OMP
56
#pragma omp critical (ionization_nextid)
57
#endif
58
{
59
pid = PTile::ParticleType::NextID();
60
PTile::ParticleType::NextID(pid + num_added);
61
}
62
63
const
int
cpuid =
amrex::ParallelDescriptor::MyProc
();
64
auto
ptd = ptile.getParticleTileData();
65
amrex::ParallelFor
(num_added, [=]
AMREX_GPU_DEVICE
(
int
ip)
noexcept
66
{
67
auto
const
lip =
static_cast<
amrex::Long
>
(ip);
68
auto
const
new_id = lip + old_size;
69
ptd.m_idcpu[new_id] =
amrex::SetParticleIDandCPU
(pid+lip, cpuid);
70
});
71
}
72
73
#endif
//WARPX_SMART_UTILS_H_
AMReX_GpuContainers.H
AMReX_GpuLaunch.H
AMReX_GpuQualifiers.H
AMREX_GPU_DEVICE
#define AMREX_GPU_DEVICE
AMReX_INT.H
AMReX_ParallelDescriptor.H
AMReX_Particle.H
DefaultInitialization.H
getPolicies
PolicyVec getPolicies(std::vector< std::string > const &names) noexcept
Definition
SmartUtils.cpp:16
NameMap
std::map< std::string, int > NameMap
Definition
SmartUtils.H:26
PolicyVec
amrex::Gpu::DeviceVector< InitializationPolicy > PolicyVec
Definition
SmartUtils.H:27
setNewParticleIDs
void setNewParticleIDs(PTile &ptile, amrex::Long old_size, amrex::Long num_added)
Sets the ids of newly created particles to the next values.
Definition
SmartUtils.H:52
getSmartCopyTag
SmartCopyTag getSmartCopyTag(std::vector< std::string > const &src, std::vector< std::string > const &dst) noexcept
Definition
SmartUtils.cpp:37
amrex::Long
amrex_long Long
amrex::Gpu::DeviceVector
PODVector< T, ArenaAllocator< T > > DeviceVector
amrex::ParallelDescriptor::MyProc
int MyProc() noexcept
amrex::ParallelFor
void ParallelFor(TypeList< CTOs... > ctos, std::array< int, sizeof...(CTOs)> const &runtime_options, T N, F &&f)
amrex::SetParticleIDandCPU
__host__ __device__ std::uint64_t SetParticleIDandCPU(Long id, int cpu) noexcept
SmartCopyTag
Definition
SmartUtils.H:30
SmartCopyTag::dst_comps
amrex::Gpu::DeviceVector< int > dst_comps
Definition
SmartUtils.H:33
SmartCopyTag::size
int size() const noexcept
Definition
SmartUtils.H:35
SmartCopyTag::src_comps
amrex::Gpu::DeviceVector< int > src_comps
Definition
SmartUtils.H:32
SmartCopyTag::common_names
std::vector< std::string > common_names
Definition
SmartUtils.H:31
Generated by
1.17.0