Skip to content

Commit

Permalink
Merge branch 'renaming_collisions' into 'main'
Browse files Browse the repository at this point in the history
Update naming conventions for collisions and VparMu geometry

See merge request gysela-developpers/gyselalibxx!629
  • Loading branch information
EmilyBourne committed Jul 31, 2024
1 parent 8a5521a commit c11a009
Show file tree
Hide file tree
Showing 13 changed files with 229 additions and 231 deletions.
2 changes: 2 additions & 0 deletions simulations/geometryVparMu/collisions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ target_link_libraries(test_collSpVparMu
gslx::io
gslx::quadrature
gslx::speciesinfo
gslx::utils

paraconf::paraconf
)

Expand Down
22 changes: 11 additions & 11 deletions simulations/geometryVparMu/collisions/test_collSpVparMu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ int main(int argc, char** argv)
IdxRangeSpVparMu const idxrange_spvparmu(idxrange_kinsp, idxrange_vpar, idxrange_mu);

// ---> Initialisation of the Maxwellian equilibrium distribution
DFieldSpVparMu allfequilibrium(idxrange_spvparmu);
DFieldMemSpVparMu allfequilibrium(idxrange_spvparmu);
MaxwellianEquilibrium const init_fequilibrium
= MaxwellianEquilibrium::init_from_input(idxrange_kinsp, conf_collision);
init_fequilibrium(allfequilibrium);

// ---> Initialisation of the distribution function as a pertubed Maxwellian
DFieldSpVparMu allfdistribu(idxrange_spvparmu);
DFieldMemSpVparMu allfdistribu(idxrange_spvparmu);
NoPerturbInitialization const init(allfequilibrium);
init(allfdistribu);

Expand All @@ -87,23 +87,23 @@ int main(int argc, char** argv)
double const B_norm = 1.0;

// TODO: Simplify the construction of coeff_intdmu and coeff_indmu as soon as the possibililty to define the quadrature coefficients directly on GPU is available
host_t<DFieldVpar> const coeff_intdvpar_host
= simpson_quadrature_coefficients_1d(allfdistribu.domain<GridVpar>());
host_t<DFieldMu> const coeff_intdmu_host
= simpson_quadrature_coefficients_1d(allfdistribu.domain<GridMu>());
host_t<DFieldMemVpar> const coeff_intdvpar_host
= simpson_quadrature_coefficients_1d(get_idx_range<GridVpar>(allfdistribu));
host_t<DFieldMemMu> const coeff_intdmu_host
= simpson_quadrature_coefficients_1d(get_idx_range<GridMu>(allfdistribu));
auto coeff_intdvpar = ddc::create_mirror_view_and_copy(
Kokkos::DefaultExecutionSpace(),
coeff_intdvpar_host.span_cview());
get_const_field(coeff_intdvpar_host));
auto coeff_intdmu = ddc::create_mirror_view_and_copy(
Kokkos::DefaultExecutionSpace(),
coeff_intdmu_host.span_cview());
get_const_field(coeff_intdmu_host));

CollisionInfo const collision_info(conf_collision);
CollisionSpVparMu<CollisionInfo, IdxRangeSpVparMu, GridVpar, GridMu, double> collision_operator(
collision_info,
idxrange_spvparmu,
coeff_intdmu.span_cview(),
coeff_intdvpar.span_cview(),
get_const_field(coeff_intdmu),
get_const_field(coeff_intdvpar),
B_norm);

// --------- TIME ITERATION ---------
Expand Down Expand Up @@ -131,7 +131,7 @@ int main(int argc, char** argv)

steady_clock::time_point const start = steady_clock::now();

auto allfdistribu_host = ddc::create_mirror_view_and_copy(allfdistribu.span_view());
auto allfdistribu_host = ddc::create_mirror_view_and_copy(get_field(allfdistribu));

int iter = 0;
for (; iter < nbiter + 1; ++iter) {
Expand Down
196 changes: 99 additions & 97 deletions src/collisions/CollisionSpVparMu.hpp

Large diffs are not rendered by default.

46 changes: 23 additions & 23 deletions src/collisions/collisioninfo_radial.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: MIT

#pragma once

#include <paraconf.h>

#include "ddc_aliases.hpp"
#include "paraconfpp.hpp"
#include "species_info.hpp"

Expand All @@ -12,17 +12,17 @@ template <class GridR>
class CollisionInfoRadial
{
private:
using DDomR = ddc::DiscreteDomain<GridR>;
using IdxRangeR = IdxRange<GridR>;

public:
/// Type alias for a field on a grid of radial values
using DFieldR = device_t<ddc::Chunk<double, DDomR>>;
using DFieldMemR = FieldMem<double, IdxRangeR>;
/// Type alias for a span of a field defined on a grid of radial values
using DSpanR = device_t<ddc::ChunkSpan<double, DDomR>>;
using DFieldR = Field<double, IdxRangeR>;
/// Type alias for a span of a field defined on a grid of radial values
using DViewR = device_t<ddc::ChunkSpan<double const, DDomR>>;
using DConstFieldR = Field<double const, IdxRangeR>;
/// radial_chunk_type used to treat the 0D case for radial profile
using radial_chunk_type = DViewR;
using radial_chunk_type = DConstFieldR;

private:
/// value of nustar0_rpeak read in the YAML input file
Expand All @@ -36,11 +36,11 @@ class CollisionInfoRadial
// but that will be deleted as soon as no more required
double const m_rpeak;
double const m_q_rpeak;
DViewR m_rg;
DViewR m_safety_factor;
DConstFieldR m_rg;
DConstFieldR m_safety_factor;

/// radial profile of nustar0
DFieldR m_nustar0_r;
DFieldMemR m_nustar0_r;

public:
/**
Expand All @@ -54,15 +54,15 @@ class CollisionInfoRadial
{
double const rpeak = m_rpeak;
double const q_rpeak = m_q_rpeak;
DViewR radial_profile = m_rg.span_cview();
DViewR safety_factor = m_safety_factor.span_cview();
DConstFieldR radial_profile = get_const_field(m_rg);
DConstFieldR safety_factor = get_const_field(m_safety_factor);
double const nustar0_rpeak = m_nustar0_rpeak;

DSpanR nustar0_r = m_nustar0_r.span_view();
DFieldR nustar0_r = get_field(m_nustar0_r);
ddc::parallel_for_each(
Kokkos::DefaultExecutionSpace(),
radial_profile.domain(),
KOKKOS_LAMBDA(ddc::DiscreteElement<GridR> idx) {
get_idx_range(radial_profile),
KOKKOS_LAMBDA(Idx<GridR> idx) {
double rpeak_on_r = rpeak / radial_profile(idx);
double q_on_qrpeak = safety_factor(idx) / q_rpeak;
nustar0_r(idx)
Expand All @@ -83,8 +83,8 @@ class CollisionInfoRadial
PC_tree_t const& yaml_input_file,
double const rpeak,
double const q_rpeak,
DViewR radial_profile,
DViewR safety_factor)
DConstFieldR radial_profile,
DConstFieldR safety_factor)
: m_nustar0_rpeak {PCpp_double(yaml_input_file, ".CollisionsInfo.nustar0_rpeak")}
, m_collisions_interspecies {PCpp_bool(
yaml_input_file,
Expand All @@ -93,7 +93,7 @@ class CollisionInfoRadial
, m_q_rpeak(q_rpeak)
, m_rg(radial_profile)
, m_safety_factor(safety_factor)
, m_nustar0_r(radial_profile.domain())
, m_nustar0_r(get_idx_range(radial_profile))
{
compute_nustar0_r();
};
Expand All @@ -113,15 +113,15 @@ class CollisionInfoRadial
std::int8_t const collisions_interspecies,
double const rpeak,
double const q_rpeak,
DViewR radial_profile,
DViewR safety_factor)
DConstFieldR radial_profile,
DConstFieldR safety_factor)
: m_nustar0_rpeak(nustar0_rpeak)
, m_collisions_interspecies(collisions_interspecies)
, m_rpeak(rpeak)
, m_q_rpeak(q_rpeak)
, m_rg(radial_profile)
, m_safety_factor(safety_factor)
, m_nustar0_r(radial_profile.domain())
, m_nustar0_r(get_idx_range(radial_profile))
{
compute_nustar0_r();
};
Expand All @@ -141,7 +141,7 @@ class CollisionInfoRadial
* @brief A method for accessing the radial profile variable of the class.
* @return A view containing the radial profile of the grid.
*/
DViewR rg() const
DConstFieldR rg() const
{
return m_rg;
}
Expand All @@ -150,7 +150,7 @@ class CollisionInfoRadial
* @brief A method for accessing the safety factor variable of the class.
* @return A view containing the radial profile of the safety_factor.
*/
DViewR safety_factor() const
DConstFieldR safety_factor() const
{
return m_safety_factor;
}
Expand All @@ -159,7 +159,7 @@ class CollisionInfoRadial
* @brief A method for accessing nustar0_r (the radial profile of nustar0) variable of the class.
* @return A view containing the radial profile of nustar0.
*/
DViewR nustar0() const
DConstFieldR nustar0() const
{
return m_nustar0_r;
}
Expand Down
59 changes: 26 additions & 33 deletions src/collisions/collisions_dimensions.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include "ddc_aliases.hpp"

/**
* @brief A namespace to collect classes which are necessary to create Chunks with the
Expand Down Expand Up @@ -31,23 +32,23 @@ inline constexpr bool is_spoofed_dim_v = std::is_base_of_v<InternalSpoofGrid, Gr

/**
* Class to get the type of the radial dimension from a field containing a radial profile.
* @tparam Field The type of the field containing the radial profile.
* @tparam FieldMem The type of the field containing the radial profile.
*/
template <class Field>
template <class FieldMem>
struct ExtractRDim
{
static_assert(!std::is_same_v<Field, Field>, "Unrecognised radial profile type");
static_assert(!std::is_same_v<FieldMem, FieldMem>, "Unrecognised radial profile type");
};

/**
* Class to get the type of the poloidal dimension from a field containing a profile on the poloidal plane.
* @tparam Field The type of the field containing the profile on the poloidal plane.
* @tparam FieldMem The type of the field containing the profile on the poloidal plane.
* @tparam GridR The tag for the discrete radial dimension.
*/
template <class Field, class GridR>
template <class FieldMem, class GridR>
struct ExtractThetaDim
{
static_assert(!std::is_same_v<Field, Field>, "Unrecognised poloidal profile type");
static_assert(!std::is_same_v<FieldMem, FieldMem>, "Unrecognised poloidal profile type");
};

/**
Expand All @@ -59,12 +60,11 @@ struct ExtractThetaDim
* @param idx_range The multi-D index range.
* @returns The index range for the specific grid.
*/
template <class Grid, class FDistribDomain>
inline ddc::DiscreteDomain<Grid> get_1d_idx_range(FDistribDomain idx_range)
template <class Grid, class FDistribIdxRange>
inline IdxRange<Grid> get_1d_idx_range(FDistribIdxRange idx_range)
{
if constexpr (is_spoofed_dim_v<Grid>) {
return ddc::DiscreteDomain<
Grid>(ddc::DiscreteElement<Grid> {0}, ddc::DiscreteVector<Grid> {1});
return IdxRange<Grid>(Idx<Grid> {0}, IdxStep<Grid> {1});
} else {
return ddc::select<Grid>(idx_range);
}
Expand All @@ -77,10 +77,10 @@ inline ddc::DiscreteDomain<Grid> get_1d_idx_range(FDistribDomain idx_range)
* @param idx_range The multi-D index range.
* @returns The index range for the specific grid.
*/
template <class... Grid, class FDistribDomain>
inline ddc::DiscreteDomain<Grid...> get_idx_range(FDistribDomain idx_range)
template <class... Grid, class FDistribIdxRange>
inline IdxRange<Grid...> get_idx_range(FDistribIdxRange idx_range)
{
return ddc::DiscreteDomain<Grid...>(get_1d_idx_range<Grid>(idx_range)...);
return IdxRange<Grid...>(get_1d_idx_range<Grid>(idx_range)...);
}

/// If radial profile is stored in a double then the grid tag must be spoofed.
Expand All @@ -92,18 +92,15 @@ struct ExtractRDim<double>

/// If radial profile is stored in a 1D chunk then the grid tag is extracted.
template <class GridR, class Layout>
struct ExtractRDim<ddc::ChunkView<
double,
ddc::DiscreteDomain<GridR>,
Layout,
Kokkos::DefaultExecutionSpace::memory_space>>
struct ExtractRDim<
ConstField<double, IdxRange<GridR>, Layout, Kokkos::DefaultExecutionSpace::memory_space>>
{
using type = GridR;
};

/// If radial profile is stored in a chunk then information about why the chunk has the wrong type is provided
template <class ElementType, class Domain, class Layout, class MemSpace>
struct ExtractRDim<ddc::ChunkSpan<ElementType, Domain, Layout, MemSpace>>
template <class ElementType, class IdxRange, class Layout, class MemSpace>
struct ExtractRDim<Field<ElementType, IdxRange, Layout, MemSpace>>
{
static_assert(
std::is_same_v<ElementType, const double>,
Expand All @@ -113,7 +110,7 @@ struct ExtractRDim<ddc::ChunkSpan<ElementType, Domain, Layout, MemSpace>>
std::is_same_v<MemSpace, Kokkos::DefaultExecutionSpace::memory_space>,
"The radial profile should be provided on the GPU");
static_assert(
(ddcHelper::type_seq_length_v<ddc::to_type_seq_t<Domain>>) > 1,
(ddcHelper::type_seq_length_v<ddc::to_type_seq_t<IdxRange>>) > 1,
"The radial profile should not be defined on more than 1 dimensions.");
};

Expand All @@ -127,11 +124,7 @@ struct ExtractThetaDim<double, InternalSpoofGridR>
/// If the profile on the poloidal plane is stored in a chunk on radial values then the grid tag must be spoofed.
template <class GridR, class Layout>
struct ExtractThetaDim<
ddc::ChunkView<
double,
ddc::DiscreteDomain<GridR>,
Layout,
Kokkos::DefaultExecutionSpace::memory_space>,
ConstField<double, IdxRange<GridR>, Layout, Kokkos::DefaultExecutionSpace::memory_space>,
GridR>
{
using type = InternalSpoofGridTheta;
Expand All @@ -140,9 +133,9 @@ struct ExtractThetaDim<
/// If the profile on the poloidal plane is stored in a chunk on poloidal values then the grid tag is extracted.
template <class GridR, class GridTheta, class Layout>
struct ExtractThetaDim<
ddc::ChunkView<
ConstField<
double,
ddc::DiscreteDomain<GridTheta>,
IdxRange<GridTheta>,
Layout,
Kokkos::DefaultExecutionSpace::memory_space>,
GridR>
Expand All @@ -153,9 +146,9 @@ struct ExtractThetaDim<
/// If the profile on the poloidal plane is stored in a 2D chunk then the grid tag is extracted.
template <class GridR, class GridTheta, class Layout>
struct ExtractThetaDim<
ddc::ChunkView<
ConstField<
double,
ddc::DiscreteDomain<GridTheta, GridR>,
IdxRange<GridTheta, GridR>,
Layout,
Kokkos::DefaultExecutionSpace::memory_space>,
GridR>
Expand All @@ -164,8 +157,8 @@ struct ExtractThetaDim<
};

/// If poloidal profile is stored in a chunk then information about why the chunk has the wrong type is provided
template <class GridR, class ElementType, class Domain, class Layout, class MemSpace>
struct ExtractThetaDim<ddc::ChunkSpan<ElementType, Domain, Layout, MemSpace>, GridR>
template <class GridR, class ElementType, class IdxRange, class Layout, class MemSpace>
struct ExtractThetaDim<Field<ElementType, IdxRange, Layout, MemSpace>, GridR>
{
static_assert(
std::is_same_v<ElementType, const double>,
Expand All @@ -175,7 +168,7 @@ struct ExtractThetaDim<ddc::ChunkSpan<ElementType, Domain, Layout, MemSpace>, Gr
std::is_same_v<MemSpace, Kokkos::DefaultExecutionSpace::memory_space>,
"The poloidal profile should be provided on the GPU");
static_assert(
(ddcHelper::type_seq_length_v<ddc::to_type_seq_t<Domain>>) > 2,
(ddcHelper::type_seq_length_v<ddc::to_type_seq_t<IdxRange>>) > 2,
"The poloidal profile should not be defined on more than 2 dimensions.");
};

Expand Down
12 changes: 6 additions & 6 deletions src/collisions/koliop_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ static inline constexpr std::size_t index_max = 2 * (Npolmax - 1);
static inline constexpr std::int64_t pSpecies_id = 0;
static inline constexpr std::int64_t mu_id
= 0; // [TODO] Same than for pSpecies_id: must be deleted from the list of input
static inline constexpr std::size_t the_local_domain_r_offset = 0;
static inline constexpr std::size_t the_local_domain_theta_offset = 0;
static inline constexpr std::size_t the_local_idx_range_r_offset = 0;
static inline constexpr std::size_t the_local_idx_range_theta_offset = 0;
static inline constexpr double R0 = 1.0; //[TODO] Attention this should not be fixed.
static inline constexpr std::int8_t SOL = false;
static inline constexpr std::int8_t LIM = false;
Expand Down Expand Up @@ -65,10 +65,10 @@ ::koliop_Operator DoOperatorInitialization(
the_theta_extent,
the_phi_extent,
the_species_extent,
the_r_extent, // NOTE: No MPI domain decomposition.
the_theta_extent, // NOTE: No MPI domain decomposition.
the_local_domain_r_offset,
the_local_domain_theta_offset,
the_r_extent, // NOTE: No MPI index range decomposition.
the_theta_extent, // NOTE: No MPI index range decomposition.
the_local_idx_range_r_offset,
the_local_idx_range_theta_offset,
R0,
collision_interspecies,
SOL,
Expand Down
Loading

0 comments on commit c11a009

Please sign in to comment.