Skip to content

Commit

Permalink
Merge branch 'renaming_species_cleaning' into 'main'
Browse files Browse the repository at this point in the history
Stop mixing device/host conventions for species

See merge request gysela-developpers/gyselalibxx!639
  • Loading branch information
EmilyBourne committed Aug 2, 2024
1 parent f965f0b commit 584621c
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 47 deletions.
6 changes: 3 additions & 3 deletions simulations/geometry5D/testcollisions/testcollisions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ int main(int argc, char** argv)
ddc::parallel_deepcopy(field_grid_mu, DConstFieldMu(grid_mu.data(), dom_mu));
auto field_grid_mu_host = ddc::create_mirror_view_and_copy(get_field(field_grid_mu));
FieldMemSp<int> field_species(dom_kinsp);
ddc::parallel_deepcopy(field_species, ConstFieldSp<int>(species.data(), dom_kinsp));
ddc::parallel_deepcopy(field_species, host_t<ConstFieldSp<int>>(species.data(), dom_kinsp));
auto field_species_host = ddc::create_mirror_view_and_copy(get_field(field_species));
DFieldMemSp field_charges(dom_kinsp);
ddc::parallel_deepcopy(field_charges, DConstFieldSp(charges.data(), dom_kinsp));
ddc::parallel_deepcopy(field_charges, host_t<DConstFieldSp>(charges.data(), dom_kinsp));
auto field_charges_host = ddc::create_mirror_view_and_copy(get_field(field_charges));
DFieldMemSp field_masses(dom_kinsp);
ddc::parallel_deepcopy(field_masses, DConstFieldSp(masses.data(), dom_kinsp));
ddc::parallel_deepcopy(field_masses, host_t<DConstFieldSp>(masses.data(), dom_kinsp));
auto field_masses_host = ddc::create_mirror_view_and_copy(get_field(field_masses));

// Algorithm Info
Expand Down
2 changes: 0 additions & 2 deletions src/collisions/CollisionSpVparMu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ class CollisionSpVparMu /* : public IRightHandSide */
using IdxRangeMu = IdxRange<GridMu>;
/// Type alias for the index range of the velocity parallel to the magnetic field.
using IdxRangeVpar = IdxRange<GridVpar>;
/// Type alias for a field on a grid of species
using DFieldMemSp = FieldMem<double, IdxRangeSp>;
/// Type alias for a field on a grid of radial values
using DFieldMemR = FieldMem<double, IdxRangeR>;
/// Type alias for a field on a grid of magnetic moments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

SingleModePerturbInitialization::SingleModePerturbInitialization(
DConstFieldSpVx fequilibrium,
host_t<IFieldSp> init_perturb_mode,
host_t<IFieldMemSp> init_perturb_mode,
host_t<DFieldMemSp> init_perturb_amplitude)
: m_fequilibrium(fequilibrium)
, m_init_perturb_mode(std::move(init_perturb_mode))
Expand Down Expand Up @@ -55,7 +55,7 @@ SingleModePerturbInitialization SingleModePerturbInitialization::init_from_input
IdxRangeSp dom_kinsp,
PC_tree_t const& yaml_input_file)
{
host_t<IFieldSp> init_perturb_mode(dom_kinsp);
host_t<IFieldMemSp> init_perturb_mode(dom_kinsp);
host_t<DFieldMemSp> init_perturb_amplitude(dom_kinsp);

for (IdxSp const isp : dom_kinsp) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SingleModePerturbInitialization : public IInitialization
{
DConstFieldSpVx m_fequilibrium;

host_t<IFieldSp> m_init_perturb_mode;
host_t<IFieldMemSp> m_init_perturb_mode;

host_t<DFieldMemSp> m_init_perturb_amplitude;

Expand All @@ -46,7 +46,7 @@ class SingleModePerturbInitialization : public IInitialization
*/
SingleModePerturbInitialization(
DConstFieldSpVx fequilibrium,
host_t<IFieldSp> init_perturb_mode,
host_t<IFieldMemSp> init_perturb_mode,
host_t<DFieldMemSp> init_perturb_amplitude);

~SingleModePerturbInitialization() override = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

SingleModePerturbInitialization::SingleModePerturbInitialization(
DConstFieldSpVxVy fequilibrium,
host_t<IFieldSp> init_perturb_mode,
host_t<IFieldMemSp> init_perturb_mode,
host_t<DFieldMemSp> init_perturb_amplitude)
: m_fequilibrium(fequilibrium)
, m_init_perturb_mode(std::move(init_perturb_mode))
Expand Down Expand Up @@ -58,7 +58,7 @@ SingleModePerturbInitialization SingleModePerturbInitialization::init_from_input
IdxRangeSp dom_kinsp,
PC_tree_t const& yaml_input_file)
{
host_t<IFieldSp> init_perturb_mode(dom_kinsp);
host_t<IFieldMemSp> init_perturb_mode(dom_kinsp);
host_t<DFieldMemSp> init_perturb_amplitude(dom_kinsp);

for (IdxSp const isp : dom_kinsp) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SingleModePerturbInitialization : public IInitialization
{
DConstFieldSpVxVy m_fequilibrium;

host_t<IFieldSp> m_init_perturb_mode;
host_t<IFieldMemSp> m_init_perturb_mode;

host_t<DFieldMemSp> m_init_perturb_amplitude;

Expand All @@ -40,7 +40,7 @@ class SingleModePerturbInitialization : public IInitialization
*/
SingleModePerturbInitialization(
DConstFieldSpVxVy fequilibrium,
host_t<IFieldSp> init_perturb_mode,
host_t<IFieldMemSp> init_perturb_mode,
host_t<DFieldMemSp> init_perturb_amplitude);

~SingleModePerturbInitialization() override = default;
Expand All @@ -64,4 +64,4 @@ class SingleModePerturbInitialization : public IInitialization
DConstFieldSpVxVy allfequilibrium,
IdxRangeSp dom_kinsp,
PC_tree_t const& yaml_input_file);
};
};
43 changes: 21 additions & 22 deletions src/speciesinfo/species_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

#include <ddc/ddc.hpp>

#include <ddc_helper.hpp>
#include "ddc_aliases.hpp"
#include "ddc_helper.hpp"

/// @brief Species discrete dimension to access constant attributes related to species.
class SpeciesInformation
Expand All @@ -22,28 +23,27 @@ class SpeciesInformation
friend class Impl;

/// alias of the discrete element of this discrete dimension
using discrete_element_type = ddc::DiscreteElement<Grid1D>;
using discrete_element_type = Idx<Grid1D>;

/// alias of the discrete domain of this discrete dimension
using discrete_domain_type = ddc::DiscreteDomain<Grid1D>;
using discrete_domain_type = IdxRange<Grid1D>;

/// alias of the discrete vector of this discrete dimension
using discrete_vector_type = ddc::DiscreteVector<Grid1D>;
using discrete_vector_type = IdxStep<Grid1D>;

private:
// charge of the particles (kinetic + adiabatic)
ddc::Chunk<double, discrete_domain_type, ddc::KokkosAllocator<double, MemorySpace>>
m_charge;
FieldMem<double, discrete_domain_type, ddc::KokkosAllocator<double, MemorySpace>> m_charge;

// mass of the particles of all kinetic species
ddc::Chunk<double, discrete_domain_type, ddc::KokkosAllocator<double, MemorySpace>> m_mass;
FieldMem<double, discrete_domain_type, ddc::KokkosAllocator<double, MemorySpace>> m_mass;

// workaround to access charges on the device
ddc::ChunkView<double, discrete_domain_type, std::experimental::layout_right, MemorySpace>
ConstField<double, discrete_domain_type, std::experimental::layout_right, MemorySpace>
m_charge_view;

// workaround to access masses on the device
ddc::ChunkView<double, discrete_domain_type, std::experimental::layout_right, MemorySpace>
ConstField<double, discrete_domain_type, std::experimental::layout_right, MemorySpace>
m_mass_view;

discrete_element_type m_ielec;
Expand Down Expand Up @@ -73,10 +73,9 @@ class SpeciesInformation
* @param[in] charge array storing both kinetic and adiabatic charges
* @param[in] mass array storing both kinetic and adiabatic masses
*/
Impl(ddc::Chunk<double, discrete_domain_type, ddc::KokkosAllocator<double, MemorySpace>>
Impl(FieldMem<double, discrete_domain_type, ddc::KokkosAllocator<double, MemorySpace>>
charge,
ddc::Chunk<double, discrete_domain_type, ddc::KokkosAllocator<double, MemorySpace>>
mass)
FieldMem<double, discrete_domain_type, ddc::KokkosAllocator<double, MemorySpace>> mass)
: m_charge(std::move(charge))
, m_mass(std::move(mass))
{
Expand Down Expand Up @@ -143,7 +142,7 @@ struct Species : SpeciesInformation
};

/// @return the discrete element representing the electron species
KOKKOS_INLINE_FUNCTION ddc::DiscreteElement<Species> ielec()
KOKKOS_INLINE_FUNCTION Idx<Species> ielec()
{
return ddc::discrete_space<Species>().ielec();
}
Expand All @@ -152,7 +151,7 @@ KOKKOS_INLINE_FUNCTION ddc::DiscreteElement<Species> ielec()
* @param[in] isp a discrete element of either a kinetic or adiabatic species
* @return the charge associated to the discrete element
*/
KOKKOS_INLINE_FUNCTION double charge(ddc::DiscreteElement<Species> const isp)
KOKKOS_INLINE_FUNCTION double charge(Idx<Species> const isp)
{
return ddc::discrete_space<Species>().charge(isp);
}
Expand All @@ -161,24 +160,24 @@ KOKKOS_INLINE_FUNCTION double charge(ddc::DiscreteElement<Species> const isp)
* @param[in] isp a discrete element of either a kinetic or adiabatic species
* @return the mass associated to the discrete element
*/
KOKKOS_INLINE_FUNCTION double mass(ddc::DiscreteElement<Species> const isp)
KOKKOS_INLINE_FUNCTION double mass(Idx<Species> const isp)
{
return ddc::discrete_space<Species>().mass(isp);
}

using IdxSp = ddc::DiscreteElement<Species>;
using IdxRangeSp = ddc::DiscreteDomain<Species>; // --> Should be DomSp
using IdxStepSp = ddc::DiscreteVector<Species>; // --> Should be VectSp or VecSp
using IdxSp = Idx<Species>;
using IdxRangeSp = IdxRange<Species>;
using IdxStepSp = IdxStep<Species>;

template <class ElementType>
using FieldMemSp = ddc::Chunk<ElementType, IdxRangeSp>;
using FieldMemSp = FieldMem<ElementType, IdxRangeSp>;
using DFieldMemSp = FieldMemSp<double>;
using IFieldSp = device_t<ddc::Chunk<int, IdxRangeSp>>;
using IFieldMemSp = FieldMemSp<int>;

template <class ElementType>
using ConstFieldSp = ddc::ChunkView<ElementType const, IdxRangeSp>;
using ConstFieldSp = ConstField<ElementType, IdxRangeSp>;
using DConstFieldSp = ConstFieldSp<double>;

template <class ElementType>
using FieldSp = device_t<ddc::ChunkSpan<ElementType, IdxRangeSp>>;
using FieldSp = Field<ElementType, IdxRangeSp>;
using DFieldSp = FieldSp<double>;
4 changes: 0 additions & 4 deletions tests/advection/spatial_advection_1d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ using IdxStepSp = IdxStep<Species>;
using IdxRangeSpXVx = IdxRange<Species, GridX, GridVx>;
using IdxSpXVx = Idx<Species, GridX, GridVx>;

// Chunks, Spans and Views
template <class ElementType>
using FieldMemSp = FieldMem<ElementType, IdxRangeSp>;
using DFieldMemSp = DFieldMemSp;

template <class ElementType>
using FieldMemSpXVx = FieldMem<ElementType, IdxRangeSpXVx>;
Expand Down
4 changes: 0 additions & 4 deletions tests/advection/velocity_advection_1d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ using IdxRangeSpXVx = IdxRange<Species, GridX, GridVx>;
using IdxSpXVx = Idx<Species, GridX, GridVx>;

// Chunks, Spans and Views
template <class ElementType>
using FieldMemSp = FieldMem<ElementType, IdxRangeSp>;
using DFieldMemSp = DFieldMemSp;

template <class ElementType>
using FieldMemSpXVx = FieldMem<ElementType, IdxRangeSpXVx>;
using DFieldMemSpXVx = FieldMemSpXVx<double>;
Expand Down
2 changes: 1 addition & 1 deletion tests/geometryXVx/geometryMX/kineticfluidcoupling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ static void TestKineticFluidCoupling()
std::move(kinsp_velocity_eq));
init_fequilibrium(allfequilibrium);

host_t<IFieldSp> init_perturb_mode(dom_kinsp);
host_t<IFieldMemSp> init_perturb_mode(dom_kinsp);
host_t<DFieldMemSp> init_perturb_amplitude(dom_kinsp);
ddc::parallel_fill(init_perturb_mode, 1);
ddc::parallel_fill(init_perturb_amplitude, 0.0);
Expand Down
4 changes: 2 additions & 2 deletions tests/species_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ TEST(SpeciesInfo, Ielec)
IdxSp my_iion = dom_sp.front();
IdxSp my_ielec = dom_sp.back();

DFieldMemSp charges(dom_sp);
DFieldMemSp masses(dom_sp);
host_t<DFieldMemSp> charges(dom_sp);
host_t<DFieldMemSp> masses(dom_sp);
charges(my_ielec) = -1.;
charges(my_iion) = 1.;
ddc::parallel_fill(masses, 1.);
Expand Down

0 comments on commit 584621c

Please sign in to comment.