Gyselalib++
 
Loading...
Searching...
No Matches
species_info.hpp
1// SPDX-License-Identifier: MIT
2
3#pragma once
4
5#include <ddc/ddc.hpp>
6
7#include "ddc_alias_inline_functions.hpp"
8#include "ddc_aliases.hpp"
9#include "ddc_helper.hpp"
10
13{
14public:
17
18public:
20 template <class Grid1D, class MemorySpace>
21 class Impl
22 {
23 template <class ODDim, class OMemorySpace>
24 friend class Impl;
25
27 using discrete_element_type = Idx<Grid1D>;
28
30 using discrete_domain_type = IdxRange<Grid1D>;
32 using index_range_type = discrete_domain_type;
33
35 using discrete_vector_type = IdxStep<Grid1D>;
36
37 private:
38 // charge of the particles (kinetic + adiabatic)
39 DFieldMem<index_range_type, MemorySpace> m_charge;
40
41 // mass of the particles of all kinetic species
42 DFieldMem<index_range_type, MemorySpace> m_mass;
43
44 // workaround to access charges on the device
45 DConstField<index_range_type, MemorySpace> m_charge_view;
46
47 // workaround to access masses on the device
48 DConstField<index_range_type, MemorySpace> m_mass_view;
49
50 discrete_element_type m_ielec;
51
52 public:
55
60 template <class OMemorySpace>
61 explicit Impl(Impl<Grid1D, OMemorySpace> const& impl)
62 : m_charge(get_idx_range(impl.m_charge))
63 , m_mass(get_idx_range(impl.m_mass))
64 , m_ielec(impl.m_ielec)
65 {
66 m_charge_view = get_const_field(m_charge);
67 m_mass_view = get_const_field(m_mass);
68 ddc::parallel_deepcopy(m_charge, impl.m_charge);
69 ddc::parallel_deepcopy(m_mass, impl.m_mass);
70 }
71
77 Impl(DFieldMem<index_range_type, MemorySpace> charge,
78 DFieldMem<index_range_type, MemorySpace> mass)
79 : m_charge(std::move(charge))
80 , m_mass(std::move(mass))
81 {
82 m_charge_view = get_const_field(m_charge);
83 m_mass_view = get_const_field(m_mass);
84 assert(charge.size() >= 2);
85 bool electron_found = false;
86 for (discrete_element_type const isp : get_idx_range(m_charge)) {
87 if (m_charge(isp) == -1.) {
88 electron_found = true;
89 m_ielec = isp;
90 }
91 }
92 if (!electron_found) {
93 throw std::runtime_error("electron not found");
94 }
95 }
96
98 KOKKOS_FUNCTION discrete_element_type ielec() const
99 {
100 return m_ielec;
101 }
102
107 KOKKOS_FUNCTION double charge(discrete_element_type const isp) const
108 {
109 return m_charge_view(isp);
110 }
111
116 KOKKOS_FUNCTION double mass(discrete_element_type const isp) const
117 {
118 return m_mass_view(isp);
119 }
120
122 auto charges() const
123 {
124 return get_const_field(m_charge);
125 }
126
128 auto masses() const
129 {
130 return get_const_field(m_mass);
131 }
132 };
133};
134
135template <class Grid1D>
136inline constexpr bool is_species_information_v
137 = std::is_same_v<typename Grid1D::discrete_dimension_type, SpeciesInformation>;
138
139// Species dimension
141{
142};
143
145KOKKOS_INLINE_FUNCTION Idx<Species> ielec()
146{
147 return ddc::discrete_space<Species>().ielec();
148}
149
154KOKKOS_INLINE_FUNCTION double charge(Idx<Species> const isp)
155{
156 return ddc::discrete_space<Species>().charge(isp);
157}
158
163KOKKOS_INLINE_FUNCTION double mass(Idx<Species> const isp)
164{
165 return ddc::discrete_space<Species>().mass(isp);
166}
167
168using IdxSp = Idx<Species>;
169using IdxRangeSp = IdxRange<Species>;
170using IdxStepSp = IdxStep<Species>;
171
172template <class ElementType>
173using FieldMemSp = FieldMem<ElementType, IdxRangeSp>;
174using DFieldMemSp = FieldMemSp<double>;
175using IFieldMemSp = FieldMemSp<int>;
176
177template <class ElementType>
178using ConstFieldSp = ConstField<ElementType, IdxRangeSp>;
179using DConstFieldSp = ConstFieldSp<double>;
180
181template <class ElementType>
182using FieldSp = Field<ElementType, IdxRangeSp>;
183using DFieldSp = FieldSp<double>;
Impl object storing attributes in MemorySpace.
Definition species_info.hpp:22
auto charges() const
Definition species_info.hpp:122
Impl(DFieldMem< index_range_type, MemorySpace > charge, DFieldMem< index_range_type, MemorySpace > mass)
Main constructor taking all attributes.
Definition species_info.hpp:77
Impl(Impl< Grid1D, OMemorySpace > const &impl)
Conversion constructor between different memory spaces.
Definition species_info.hpp:61
auto masses() const
Definition species_info.hpp:128
KOKKOS_FUNCTION double charge(discrete_element_type const isp) const
Definition species_info.hpp:107
KOKKOS_FUNCTION double mass(discrete_element_type const isp) const
Definition species_info.hpp:116
KOKKOS_FUNCTION discrete_element_type ielec() const
Definition species_info.hpp:98
Species discrete dimension to access constant attributes related to species.
Definition species_info.hpp:13
Definition species_info.hpp:141