XGCa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
species.hpp
Go to the documentation of this file.
1 #ifndef SPECIES_HPP
2 #define SPECIES_HPP
3 #include <Cabana_AoSoA.hpp>
4 #include <Cabana_DeepCopy.hpp>
5 #include <Kokkos_Core.hpp>
6 #include "NamelistReader.hpp"
7 #include "particles.hpp"
8 #include "space_settings.hpp"
9 #include "distribution.hpp"
10 #include "profile.hpp"
11 
12 #ifndef NO_FORTRAN
13 extern "C" void set_spall_num_and_ptr(int idx, int n_ptl, int n_vecs, VecParticles* ptl);
14 #else
15 inline void set_spall_num_and_ptr(int idx, int n_ptl, int n_vecs, VecParticles* ptl){}
16 #endif
17 
18 // Species class
19 template<class Device>
20 class Species{
21  public:
22 
23  int idx;
24  bool is_electron;
25  bool is_adiabatic;
27  double mass;
28  double charge;
29  double charge_eu;
30  double c_m;
31  double c2_2m;
32 
33  bool is_deltaf;
34 
35  int ncycles;
37 
38  int n_ptl;
39  Cabana::AoSoA<ParticleDataTypes,HostType,VEC_LEN> particles;
40  Cabana::AoSoA<PhaseDataTypes,HostType,VEC_LEN> phase0;
41  Cabana::AoSoA<ParticleDataTypes,HostType,VEC_LEN> backup_particles;
42  int n_backup_particles; // Number of particles stored in backup_particles (can't be deduced from its size due to buffer)
43 
45 
46  Eq::Profile<Device> eq_temp; // Equilibrium temperature
47  Eq::Profile<Device> eq_den; // Equilibrium density
48  Eq::Profile<Device> eq_flow; // Equilibrium flow
49 
50  Species(int idx_in, bool is_electron_in, bool is_adiabatic_in, bool is_gyrokinetic_in, double mass_in, double charge_in, double charge_eu_in, bool is_deltaf_in,
51  int ncycles_in);
52 
53  Species(NLReader::NamelistReader& nlr, int idx_in);
54 
55  // Default constructor
56  Species(){}
57 
58  // Electron or ion default constructor
59  Species(SpeciesType sp_type, int n_ptl)
60  : idx(sp_type==ELECTRON ? 0 : 1),
61  is_electron(sp_type==ELECTRON),
62  mass(is_electron ? 3.344e-30 : PROTON_MASS),
64  charge_eu(is_electron ? -1.0 : 1.0),
65  is_deltaf(true),
66  is_adiabatic(false),
68  ncycles(is_electron ? 70 : 1),
69  c_m(charge/mass),
70  c2_2m(0.5*charge*charge/mass),
71  n_ptl(n_ptl),
72  backup_particles("backup_particles", 0),
73  particles("particles", add_vec_buffer(n_ptl)),
75  eq_temp(1.0e3,-0.1),
76  eq_den(1.0e19,-0.1) {}
77 
78 
79  void resize_particles(int new_n_ptl){
80  n_ptl = new_n_ptl;
83  }
84 
85  /* If using CPU-only, then "device" particles are a shallow copy of host particles so that
86  * there is no unnecessary duplication. When "device" particles are resized, Cabana will keep the
87  * original allocation if there is a second reference (i.e. host particles).
88  * To resolve this, we free the host particles here so that there is no second reference
89  * */
90  void unassign(){
91 #ifndef USE_GPU
92  particles = Cabana::AoSoA<ParticleDataTypes,Device,VEC_LEN>();
93 #endif
94  }
95 };
96 
97 template<class Device>
98 class TmpSpecies{
99  public:
100 
101  TmpSpecies(int n_ptl_in);
103 
104  void resize(int n_ptl_in);
105 
106  // Particles
107  Cabana::AoSoA<ParticleDataTypes,Device,VEC_LEN> particles;
108  VecParticles* ptl; // Pointer to the particles
109 
110  // phase0 (for ions)
111  Cabana::AoSoA<PhaseDataTypes,Device,VEC_LEN> phase0;
112  VecPhase* ph0; // Pointer to phase0
113 };
114 
115 #include "species.tpp"
116 #endif
Cabana::AoSoA< PhaseDataTypes, HostType, VEC_LEN > phase0
For ion restoration.
Definition: species.hpp:40
Definition: globals.hpp:55
void unassign()
Definition: species.hpp:90
KOKKOS_INLINE_FUNCTION int divide_and_round_up(int a, int b)
Definition: globals.hpp:89
void set_spall_num_and_ptr(int idx, int n_ptl, int n_vecs, VecParticles *ptl)
Distribution< Device > f0
Species distribution in velocity space on local mesh nodes.
Definition: species.hpp:44
Cabana::AoSoA< ParticleDataTypes, HostType, VEC_LEN > backup_particles
Copy of particles to be restored for RK2.
Definition: species.hpp:41
bool is_electron
Whether this species is the electrons.
Definition: species.hpp:24
double c2_2m
c2/2m
Definition: species.hpp:31
double c_m
c/m
Definition: species.hpp:30
VecPhase * ph0
Definition: species.hpp:112
Eq::Profile< Device > eq_den
Definition: species.hpp:47
Definition: NamelistReader.hpp:163
int add_vec_buffer(int n_ptl)
Definition: particles.hpp:120
int idx
Index in all_species.
Definition: species.hpp:23
TmpSpecies()
Definition: species.hpp:102
Definition: particles.hpp:38
bool is_gyrokinetic
Whether the species is gyrokinetic or drift kinetic.
Definition: species.hpp:26
Definition: distribution.hpp:20
Definition: particles.hpp:55
int n_ptl
Number of particles.
Definition: species.hpp:38
const double UNIT_CHARGE
Charge of an electron (C)
Definition: globals.hpp:81
double charge_eu
Particle charge in eu.
Definition: species.hpp:29
void resize_particles(int new_n_ptl)
Definition: species.hpp:79
double mass
Particle mass.
Definition: species.hpp:27
void resize(int n_ptl_in)
Definition: species.tpp:140
double charge
Particle charge.
Definition: species.hpp:28
int ncycles_between_sorts
Number of subcycles between sorts.
Definition: species.hpp:36
Species(SpeciesType sp_type, int n_ptl)
Definition: species.hpp:59
bool is_deltaf
Whether this species is deltaf.
Definition: species.hpp:33
Cabana::AoSoA< ParticleDataTypes, Device, VEC_LEN > particles
Definition: species.hpp:107
bool is_adiabatic
Whether this species is adiabatic.
Definition: species.hpp:25
Cabana::AoSoA< PhaseDataTypes, Device, VEC_LEN > phase0
Definition: species.hpp:111
int n_backup_particles
Definition: species.hpp:42
Eq::Profile< Device > eq_flow
Definition: species.hpp:48
const double PROTON_MASS
Definition: globals.hpp:84
Definition: species.hpp:20
Eq::Profile< Device > eq_temp
Definition: species.hpp:46
Definition: species.hpp:98
VecParticles * ptl
Definition: species.hpp:108
Species()
Definition: species.hpp:56
int ncycles
Number of subcycles.
Definition: species.hpp:35
Definition: profile.hpp:65
SpeciesType
Definition: globals.hpp:54
Cabana::AoSoA< ParticleDataTypes, HostType, VEC_LEN > particles
Particles.
Definition: species.hpp:39