6#include "collisions_dimensions.hpp"
7#include "ddc_alias_inline_functions.hpp"
8#include "ddc_aliases.hpp"
9#include "ddc_helper.hpp"
10#include "koliop_interface.hpp"
11#include "species_info.hpp"
18 class IdxRangeFDistrib,
21 class InputDFieldThetaR>
25 using InputDFieldR =
typename CollInfo::radial_chunk_type;
26 using fdistrib_grids = ddc::to_type_seq_t<IdxRangeFDistrib>;
30 using InputThetaRTags =
32 using InputSpThetaRVparTags = ddc::type_seq_merge_t<
33 ddc::detail::TypeSeq<Species>,
34 ddc::type_seq_merge_t<InputThetaRTags, ddc::detail::TypeSeq<GridVpar>>>;
35 using InputIdxRangeSpThetaRVpar
36 = ddc::detail::convert_type_seq_to_discrete_domain_t<InputSpThetaRVparTags>;
39 static_assert(ddc::is_discrete_domain_v<IdxRangeFDistrib>);
40 static_assert(IdxRangeFDistrib::rank() >= 3 && IdxRangeFDistrib::rank() <= 6);
41 static_assert((std::is_same_v<InputDFieldR, double>) || ddc::is_borrowed_chunk_v<InputDFieldR>);
43 (std::is_same_v<InputDFieldThetaR, double>)
44 || (ddc::is_borrowed_chunk_v<InputDFieldThetaR>));
47 ddc::in_tags_v<Species, fdistrib_grids>,
48 "The distribution function must be defined over the species");
50 ddc::in_tags_v<GridVpar, fdistrib_grids>,
51 "The distribution function must be defined over the Vpar direction");
53 ddc::in_tags_v<GridMu, fdistrib_grids>,
54 "The distribution function must be defined over the Mu direction");
57 ddc::is_uniform_point_sampling_v<GridVpar>,
58 "The grid must be uniform in the vpar direction.");
60 ddc::is_uniform_point_sampling_v<GridMu>,
61 "The grid must be uniform in the mu direction.");
64 ddc::type_seq_rank_v<Species, fdistrib_grids> == 0,
65 "Species should be the first index in the distribution function index set");
67 collisions_dimensions::
68 order_of_last_grids<fdistrib_grids, GridTheta, GridR, GridVpar, GridMu>(),
69 "Misordered inex set for the distribution function. Koliop expects (Sp, Phi, Theta, R, "
111 Kokkos::DefaultExecutionSpace::
116 Kokkos::DefaultExecutionSpace::
129 void deepcopy_radial_profile(
DFieldR dst, InputDFieldR src)
131 if constexpr (collisions_dimensions::is_spoofed_dim_v<GridR>) {
133 ddc::parallel_fill(Kokkos::DefaultExecutionSpace(), dst, src);
136 ddc::parallel_deepcopy(dst, src);
151 if constexpr ((collisions_dimensions::is_spoofed_dim_v<GridR>)&&(
152 collisions_dimensions::is_spoofed_dim_v<GridTheta>)) {
154 ddc::parallel_fill(Kokkos::DefaultExecutionSpace(), dst, src);
155 }
else if constexpr ((!collisions_dimensions::is_spoofed_dim_v<GridR>)&&(
156 !collisions_dimensions::is_spoofed_dim_v<GridTheta>)) {
158 ddc::parallel_deepcopy(dst, src);
160 using NonSpoofDim = std::
161 conditional_t<collisions_dimensions::is_spoofed_dim_v<GridR>,
GridTheta,
GridR>;
162 ddc::parallel_for_each(
163 Kokkos::DefaultExecutionSpace(),
165 KOKKOS_LAMBDA(Idx<GridTheta, GridR> idx) {
166 dst(idx) = src(ddc::select<NonSpoofDim>(idx));
181 if constexpr (std::is_same_v<DFieldSpThetaRVpar, InputDFieldSpThetaRVpar>) {
182 ddc::parallel_deepcopy(dst, src);
184 using InputIdxSpThetaRVpar =
typename InputIdxRangeSpThetaRVpar::discrete_element_type;
185 ddc::parallel_for_each(
186 Kokkos::DefaultExecutionSpace(),
189 InputIdxSpThetaRVpar src_idx(idx);
190 dst(idx) = src(src_idx);
214 CollInfo
const& collision_info,
215 IdxRangeFDistrib idxrange_fdistrib,
218 InputDFieldThetaR B_norm,
228 ,
m_mug {
"m_mug", ddc::select<
GridMu>(idxrange_fdistrib)}
232 if (idxrange_vpar.size() % 2 != 0) {
233 throw std::runtime_error(
"The number of points in the vpar direction must be a "
234 "multiple of 2. This ensures that there is no grid point at "
235 "vpar=0 (this would cause division by 0).");
237 IdxRangeSp idxrange_sp(idxrange_fdistrib);
239 host_t<DConstFieldSp> hat_As_host
240 = ddc::host_discrete_space<Species>().masses()[idxrange_sp];
241 ddc::parallel_deepcopy(get_field(
m_hat_As), hat_As_host);
243 host_t<DConstFieldSp> hat_Zs_host
244 = ddc::host_discrete_space<Species>().charges()[idxrange_sp];
245 ddc::parallel_deepcopy(get_field(
m_hat_Zs), hat_Zs_host);
248 deepcopy_radial_profile(get_field(
m_coeff_AD), collision_info.coeff_AD());
254 ddc::parallel_fill(get_field(
m_mask_LIM), 0.0);
257 ddcHelper::dump_coordinates(Kokkos::DefaultExecutionSpace(), get_field(
m_mug));
258 ddcHelper::dump_coordinates(Kokkos::DefaultExecutionSpace(), get_field(
m_vparg));
263 std::size_t
const n_mu = ddc::select<GridMu>(idxrange_fdistrib).size();
264 std::size_t
const n_vpar = idxrange_vpar.size();
266 std::size_t
const n_theta = get_idx_range<GridTheta>(
m_B_norm).size();
267 std::size_t
const n_sp = idxrange_sp.size();
268 std::size_t
const n_batch
269 = idxrange_fdistrib.size() / (n_mu * n_vpar * n_r * n_theta * n_sp);
278 collision_info.collisions_interspecies(),
284 coeff_intdmu.data_handle(),
285 coeff_intdvpar.data_handle(),
309 if (::koliop_Collision(
312 all_f_distribution.data_handle())
313 != KOLIOP_STATUS_SUCCESS) {
320 != KOLIOP_STATUS_SUCCESS) {
A class which computes the collision operator in (vpar,mu)
Definition CollisionSpVparMu.hpp:23
DConstField< InputIdxRangeSpThetaRVpar > InputDFieldSpThetaRVpar
Type alias for a field on a grid of (species, theta, r, vpar) or a subset.
Definition CollisionSpVparMu.hpp:74
void deepcopy_poloidal_plane(DFieldThetaR dst, InputDFieldThetaR src)
Copy the information in src (received as an input to the class) into a 2D field defined over (r,...
Definition CollisionSpVparMu.hpp:149
Idx< Species, GridTheta, GridR, GridVpar > IdxSpThetaRVpar
Type alias for the index containing (species, theta, r, vpar)
Definition CollisionSpVparMu.hpp:90
DFieldMemThetaR m_mask_LIM
Limiter mask in (r,theta)
Definition CollisionSpVparMu.hpp:344
DFieldMemMu m_mug
grid in mu direction
Definition CollisionSpVparMu.hpp:352
DFieldMemVpar m_vparg
grid in vpar direction
Definition CollisionSpVparMu.hpp:354
IdxRange< Species, GridTheta, GridR, GridVpar > IdxRangeSpThetaRVpar
Type alias for the index range containing (species, theta, r, vpar)
Definition CollisionSpVparMu.hpp:81
DFieldMem< IdxRangeMu > DFieldMemMu
Type alias for a field memory block on a grid of magnetic moments.
Definition CollisionSpVparMu.hpp:95
DFieldMemSp m_hat_As
Normalized masses for all species.
Definition CollisionSpVparMu.hpp:335
DFieldMem< IdxRangeR > DFieldMemR
Type alias for a field memory block on a grid of radial values.
Definition CollisionSpVparMu.hpp:93
DFieldMemR m_mask_buffer_r
Mask used to avoid to apply collision in certain region.
Definition CollisionSpVparMu.hpp:342
DFieldMemR m_coeff_AD
Radial AD coefficients.
Definition CollisionSpVparMu.hpp:339
koliop_interface::MDL< double[6][6]> m_comb_mat
Combinatory (6x6) matrix computed only one times at initialisation. Rk: 6 = 2*(Npolmax-1) + 1 + 1.
Definition CollisionSpVparMu.hpp:333
void operator()(FDistribField all_f_distribution, double deltat_coll) const
Apply the collision operator to the distribution functions of all species on all species.
Definition CollisionSpVparMu.hpp:307
void deepcopy_Bstar(DFieldSpThetaRVpar dst, InputDFieldSpThetaRVpar src)
Copy the information in src (received as an input to the class) into a 4D field defined over (species...
Definition CollisionSpVparMu.hpp:179
DConstField< IdxRangeMu, Kokkos::DefaultExecutionSpace::memory_space > DConstFieldMu
Type alias for a constant field on GPU defined on a grid of magnetic moments.
Definition CollisionSpVparMu.hpp:112
DField< IdxRangeSpThetaRVpar > DFieldSpThetaRVpar
Type alias for a field on a grid of species, poloidal plane and parallel velocities.
Definition CollisionSpVparMu.hpp:107
IdxRange< GridR > IdxRangeR
Type alias for the index range of the radial points.
Definition CollisionSpVparMu.hpp:77
::koliop_Operator m_operator_handle
Opaque type representing the operator (due to the C interface)
Definition CollisionSpVparMu.hpp:329
Idx< GridTheta, GridR > IdxThetaR
Type alias for the index of the poloidal plane.
Definition CollisionSpVparMu.hpp:88
IdxRange< GridVpar > IdxRangeVpar
Type alias for the index range of the velocity parallel to the magnetic field.
Definition CollisionSpVparMu.hpp:85
IdxRange< GridTheta, GridR > IdxRangeThetaR
Type alias for the index range of the poloidal plane.
Definition CollisionSpVparMu.hpp:79
DField< IdxRangeFDistrib > FDistribField
Type alias for the distribution function stored on GPU.
Definition CollisionSpVparMu.hpp:120
DFieldMemThetaR m_B_norm
B norm in (r,theta)
Definition CollisionSpVparMu.hpp:347
DFieldMemSp m_hat_Zs
Normalized charges for all species.
Definition CollisionSpVparMu.hpp:337
CollisionSpVparMu(CollInfo const &collision_info, IdxRangeFDistrib idxrange_fdistrib, DConstFieldMu coeff_intdmu, DConstFieldVpar coeff_intdvpar, InputDFieldThetaR B_norm, InputDFieldSpThetaRVpar Bstar_s)
Create instance of CollisionSpVparMu class.
Definition CollisionSpVparMu.hpp:213
DFieldMem< IdxRangeSpThetaRVpar > DFieldMemSpThetaRVpar
Type alias for a field memory block on a grid of species, poloidal plane and parallel velocities.
Definition CollisionSpVparMu.hpp:101
DFieldMemSpThetaRVpar m_Bstar_s
Bstar(species,r,theta,vpar)
Definition CollisionSpVparMu.hpp:350
DField< IdxRangeThetaR > DFieldThetaR
Type alias for a field defined on a grid on a poloidal plane.
Definition CollisionSpVparMu.hpp:105
DFieldMem< IdxRangeThetaR > DFieldMemThetaR
Type alias for a field memory block on a grid on a poloidal plane.
Definition CollisionSpVparMu.hpp:99
IdxRange< GridMu > IdxRangeMu
Type alias for the index range of the magnetic moment.
Definition CollisionSpVparMu.hpp:83
DFieldMem< IdxRangeVpar > DFieldMemVpar
Type alias for a field memory block on a grid of parallel velocities.
Definition CollisionSpVparMu.hpp:97
DConstField< IdxRangeVpar, Kokkos::DefaultExecutionSpace::memory_space > DConstFieldVpar
Type alias for a constant field on GPU defined on a grid of parallel velocities.
Definition CollisionSpVparMu.hpp:117
DField< IdxRangeR > DFieldR
Type alias for a field defined on a grid of radial values.
Definition CollisionSpVparMu.hpp:103
A namespace to collect classes which are necessary to create Fields with the correct number of dimens...
Definition collisions_dimensions.hpp:10
void DoOperatorDeinitialization(::koliop_Operator the_operator_handle)
Destructor for koliop.
::koliop_Operator DoOperatorInitialization(std::size_t the_mu_extent, std::size_t the_vpar_extent, std::size_t the_r_extent, std::size_t the_theta_extent, std::size_t the_phi_extent, std::size_t the_species_extent, std::int8_t collision_interspecies, std::int64_t ir_SOL_separatrix, const double *hat_As, const double *hat_Zs, const double *mug, const double *vparg, const double *coeff_intdmu, const double *coeff_intdvpar, const double *coeff_AD_r, const double *mask_buffer_r, const double *mask_LIM, const double *B_norm, const double *Bstar_s)
Initialise the collision operator defined in koliop.
Kokkos::View< Extent, Kokkos::LayoutLeft, Kokkos::DefaultExecutionSpace::memory_space, Kokkos::MemoryTraits< Kokkos::Restrict > > MDL
MDL is a helper type which avoids repetition of a lengthy type name.
Definition koliop_interface.hpp:27
Definition geometry.hpp:78
Definition geometry.hpp:116
Definition geometry.hpp:119
Definition geometry.hpp:75
Definition species_info.hpp:141