diff --git a/src/geometryXVx/rhs/collisions_intra.cpp b/src/geometryXVx/rhs/collisions_intra.cpp index 03b81b707..98f151c2d 100644 --- a/src/geometryXVx/rhs/collisions_intra.cpp +++ b/src/geometryXVx/rhs/collisions_intra.cpp @@ -13,12 +13,11 @@ CollisionsIntra::CollisionsIntra(IDomainSpXVx const& mesh, double nustar0) , m_fthresh(1.e-30) , m_nustar_profile_alloc(ddc::select(mesh)) , m_gridvx_ghosted( - ddc::DiscreteElement(0), - ddc::DiscreteVector(ddc::select(mesh).size() + 2)) + ddc::DiscreteElement(0), + ddc::DiscreteVector(ddc::select(mesh).size() + 2)) , m_gridvx_ghosted_staggered( - ddc::DiscreteElement(0), - ddc::DiscreteVector( - ddc::select(mesh).size() + 1)) + ddc::DiscreteElement(0), + ddc::DiscreteVector(ddc::select(mesh).size() + 1)) , m_mesh_ghosted(ddc::select(mesh), ddc::select(mesh), m_gridvx_ghosted) , m_mesh_ghosted_staggered( ddc::select(mesh), @@ -34,47 +33,44 @@ CollisionsIntra::CollisionsIntra(IDomainSpXVx const& mesh, double nustar0) throw std::invalid_argument("Collision operator should not be used with nustar0=0."); } - double const vx0 = ddc::coordinate(ddc::select(mesh).front()); - double const vx1 = ddc::coordinate(ddc::select(mesh).front() + 1); - double const vxN = ddc::coordinate(ddc::select(mesh).back()); - double const vxNm1 = ddc::coordinate(ddc::select(mesh).back() - 1); + CoordVx const vx0 = ddc::coordinate(ddc::select(mesh).front()); + CoordVx const vx1 = ddc::coordinate(ddc::select(mesh).front() + 1); + CoordVx const vxN = ddc::coordinate(ddc::select(mesh).back()); + CoordVx const vxNm1 = ddc::coordinate(ddc::select(mesh).back() - 1); int const ncells(ddc::select(mesh).size() - 1); if constexpr (uniform_edge_v) { double const step(ddc::step()); - ddc::init_discrete_space( - ghosted_vx_point_sampling:: - init(ddc::Coordinate(vx0 - step), - ddc::Coordinate(vxN + step), - ddc::DiscreteVector(ncells + 3))); + ddc::init_discrete_space( + GhostedVx:: + init(vx0 - step, vxN + step, ddc::DiscreteVector(ncells + 3))); } else { int const npoints(ncells + 3); - std::vector> breaks(npoints); - breaks[0] = ddc::Coordinate(vx0 - (vx1 - vx0)); - breaks[npoints - 1] = ddc::Coordinate(vxN + (vxN - vxNm1)); + std::vector breaks(npoints); + breaks[0] = vx0 - (vx1 - vx0); + breaks[npoints - 1] = vxN + (vxN - vxNm1); ddc::for_each(ddc::select(mesh), [&](IndexVx const ivx) { - breaks[ghosted_from_index(ivx).uid()] = ghosted_from_coord(ddc::coordinate(ivx)); + breaks[ghosted_from_index(ivx).uid()] = ddc::coordinate(ivx); }); - ddc::init_discrete_space(breaks); + ddc::init_discrete_space(breaks); } if constexpr (uniform_edge_v) { double const step(ddc::step()); - ddc::init_discrete_space( - ghosted_vx_staggered_point_sampling:: - init(ddc::Coordinate(vx0 - step / 2), - ddc::Coordinate(vxN + step / 2), - ddc::DiscreteVector(ncells + 2))); + ddc::init_discrete_space( + GhostedVxStaggered:: + init(vx0 - step / 2, + vxN + step / 2, + ddc::DiscreteVector(ncells + 2))); } else { int const npoints(ncells + 2); - std::vector> breaks(npoints); - breaks[0] = ddc::Coordinate(vx0 - (vx1 - vx0) / 2.); - breaks[npoints - 1] = ddc::Coordinate(vxN + (vxN - vxNm1) / 2.); + std::vector breaks(npoints); + breaks[0] = vx0 - (vx1 - vx0) / 2.; + breaks[npoints - 1] = vxN + (vxN - vxNm1) / 2.; IDomainVx const gridvx_less(ddc::select(mesh).remove_last(IVectVx(1))); ddc::for_each(gridvx_less, [&](IndexVx const ivx) { - breaks[ivx.uid() + 1] = CollisionsIntra::ghosted_staggered_from_coord( - CoordVx((ddc::coordinate(ivx) + ddc::coordinate(ivx + 1)) / 2.)); + breaks[ivx.uid() + 1] = CoordVx((ddc::coordinate(ivx) + ddc::coordinate(ivx + 1)) / 2.); }); - ddc::init_discrete_space(breaks); + ddc::init_discrete_space(breaks); } m_nustar_profile = m_nustar_profile_alloc.span_view(); @@ -82,20 +78,19 @@ CollisionsIntra::CollisionsIntra(IDomainSpXVx const& mesh, double nustar0) ddc::expose_to_pdi("collintra_nustar0", m_nustar0); } -ddc::DiscreteDomain const& CollisionsIntra:: - get_gridvx_ghosted() const +ddc::DiscreteDomain const& CollisionsIntra::get_gridvx_ghosted() const { return m_gridvx_ghosted; } -ddc::DiscreteDomain const& CollisionsIntra:: +ddc::DiscreteDomain const& CollisionsIntra:: get_gridvx_ghosted_staggered() const { return m_gridvx_ghosted_staggered; } -ddc::DiscreteDomain const& -CollisionsIntra::get_mesh_ghosted() const +ddc::DiscreteDomain const& CollisionsIntra:: + get_mesh_ghosted() const { return m_mesh_ghosted; } @@ -272,29 +267,28 @@ DSpanSpXVx CollisionsIntra::operator()(DSpanSpXVx allfdistribu, double dt) const // diffusion coefficient device_t> Dcoll_alloc(m_mesh_ghosted); auto Dcoll = Dcoll_alloc.span_view(); - compute_Dcoll(Dcoll, collfreq, density, temperature); + compute_Dcoll(Dcoll, collfreq, density, temperature); device_t> dvDcoll_alloc(m_mesh_ghosted); auto dvDcoll = dvDcoll_alloc.span_view(); - compute_dvDcoll(dvDcoll, collfreq, density, temperature); + compute_dvDcoll(dvDcoll, collfreq, density, temperature); device_t> Dcoll_staggered_alloc( m_mesh_ghosted_staggered); auto Dcoll_staggered = Dcoll_staggered_alloc.span_view(); - compute_Dcoll< - ghosted_vx_staggered_point_sampling>(Dcoll_staggered, collfreq, density, temperature); + compute_Dcoll(Dcoll_staggered, collfreq, density, temperature); // kernel maxwellian fluid moments DFieldSpX Vcoll_alloc(grid_sp_x); DFieldSpX Tcoll_alloc(grid_sp_x); auto Vcoll = Vcoll_alloc.span_view(); auto Tcoll = Tcoll_alloc.span_view(); - compute_Vcoll_Tcoll(Vcoll, Tcoll, allfdistribu, Dcoll, dvDcoll); + compute_Vcoll_Tcoll(Vcoll, Tcoll, allfdistribu, Dcoll, dvDcoll); // convection coefficient Nucoll device_t> Nucoll_alloc(m_mesh_ghosted); auto Nucoll = Nucoll_alloc.span_view(); - compute_Nucoll(Nucoll, Dcoll, Vcoll, Tcoll); + compute_Nucoll(Nucoll, Dcoll, Vcoll, Tcoll); // matrix coefficients DFieldSpXVx AA_alloc(allfdistribu.domain()); diff --git a/src/geometryXVx/rhs/collisions_intra.hpp b/src/geometryXVx/rhs/collisions_intra.hpp index 6375ef58c..6dc11ad31 100644 --- a/src/geometryXVx/rhs/collisions_intra.hpp +++ b/src/geometryXVx/rhs/collisions_intra.hpp @@ -37,21 +37,6 @@ */ class CollisionsIntra : public IRightHandSide { -public: - /** - * @brief A struct representing a tag to construct a mesh with ghosted points. - */ - struct GhostedVx - { - }; - - /** - * @brief A struct representing a tag to construct a mesh with ghosted and staggered points. - */ - struct GhostedVxStaggered - { - }; - private: static constexpr bool uniform_edge_v = ddc::is_uniform_sampling_v; @@ -59,81 +44,57 @@ class CollisionsIntra : public IRightHandSide /** * A conditional type representing either a uniform or a non-uniform ghosted vx mesh. */ - struct ghosted_vx_point_sampling + struct GhostedVx : std::conditional_t< uniform_edge_v, - ddc::UniformPointSampling, - ddc::NonUniformPointSampling> + ddc::UniformPointSampling, + ddc::NonUniformPointSampling> { }; /** * A conditional type representing either a uniform or a non-uniform ghosted staggered vx mesh. */ - struct ghosted_vx_staggered_point_sampling + struct GhostedVxStaggered : std::conditional_t< uniform_edge_v, - ddc::UniformPointSampling, - ddc::NonUniformPointSampling> + ddc::UniformPointSampling, + ddc::NonUniformPointSampling> { }; /** * A type representing a mesh for species, space and ghosted vx mesh. */ - using IDomainSpXVx_ghosted = ddc::DiscreteDomain; + using IDomainSpXVx_ghosted = ddc::DiscreteDomain; /** * A type representing a mesh for species, space and ghosted staggered vx mesh. */ - using IDomainSpXVx_ghosted_staggered - = ddc::DiscreteDomain; + using IDomainSpXVx_ghosted_staggered = ddc::DiscreteDomain; /** * A type representing a ghosted vx index. */ - using IndexVx_ghosted = ddc::DiscreteElement; + using IndexVx_ghosted = ddc::DiscreteElement; /** * A type representing a ghosted staggered vx index. */ - using IndexVx_ghosted_staggered = ddc::DiscreteElement; + using IndexVx_ghosted_staggered = ddc::DiscreteElement; /** * A type representing a species, space and ghosted vx index. */ - using IndexSpXVx_ghosted = ddc::DiscreteElement; + using IndexSpXVx_ghosted = ddc::DiscreteElement; /** * A type representing a species, space and ghosted staggered vx index. */ - using IndexSpXVx_ghosted_staggered - = ddc::DiscreteElement; + using IndexSpXVx_ghosted_staggered = ddc::DiscreteElement; private: - static ddc::Coordinate ghosted_from_coord(ddc::Coordinate const& coord) - { - return ddc::Coordinate(ddc::get(coord)); - } - static ddc::Coordinate coord_from_ghosted(ddc::Coordinate const& coord) - { - return ddc::Coordinate(ddc::get(coord)); - } - static ddc::Coordinate ghosted_staggered_from_coord( - ddc::Coordinate const& coord) - { - return ddc::Coordinate(ddc::get(coord)); - } - static ddc::Coordinate coord_from_ghosted_staggered( - ddc::Coordinate const& coord) - { - return ddc::Coordinate(ddc::get(coord)); - } - static IndexVx index_from_ghosted(ddc::DiscreteElement const& index_ghosted) - { - return IndexVx(index_ghosted.uid() - 1); - } KOKKOS_FUNCTION static IndexVx_ghosted ghosted_from_index(IndexVx const& index) { return IndexVx_ghosted(index.uid() + 1); @@ -150,8 +111,8 @@ class CollisionsIntra : public IRightHandSide DFieldSpX m_nustar_profile_alloc; DSpanSpX m_nustar_profile; - ddc::DiscreteDomain m_gridvx_ghosted; - ddc::DiscreteDomain m_gridvx_ghosted_staggered; + ddc::DiscreteDomain m_gridvx_ghosted; + ddc::DiscreteDomain m_gridvx_ghosted_staggered; IDomainSpXVx_ghosted m_mesh_ghosted; IDomainSpXVx_ghosted_staggered m_mesh_ghosted_staggered; @@ -194,22 +155,21 @@ class CollisionsIntra : public IRightHandSide * * @return The ghosted vx mesh. */ - ddc::DiscreteDomain const& get_gridvx_ghosted() const; + ddc::DiscreteDomain const& get_gridvx_ghosted() const; /** * @brief Get the ghosted and staggered vx mesh used for computing finite differences centered derivatives. * * @return The ghosted and staggered vx mesh. */ - ddc::DiscreteDomain const& get_gridvx_ghosted_staggered() - const; + ddc::DiscreteDomain const& get_gridvx_ghosted_staggered() const; /** * @brief Get a mesh containing the species, spatial and the ghosted vx mesh. * * @return The species, spatial, and ghosted vx mesh. */ - ddc::DiscreteDomain const& get_mesh_ghosted() const; + ddc::DiscreteDomain const& get_mesh_ghosted() const; /** * @brief Compute the right-hand-side of the collision operator linear system. diff --git a/tests/geometryXVx/collisions_intra_gridvx.cpp b/tests/geometryXVx/collisions_intra_gridvx.cpp index a80c3d439..3a9f77561 100644 --- a/tests/geometryXVx/collisions_intra_gridvx.cpp +++ b/tests/geometryXVx/collisions_intra_gridvx.cpp @@ -68,10 +68,10 @@ TEST(CollisionsIntraGridvx, CollisionsIntraGridvx) // collision operator double const nustar0(1.); CollisionsIntra collisions(mesh, nustar0); - ddc::DiscreteDomain gridvx_ghosted + ddc::DiscreteDomain gridvx_ghosted = collisions.get_gridvx_ghosted(); - ddc::DiscreteDomain - gridvx_ghosted_staggered = collisions.get_gridvx_ghosted_staggered(); + ddc::DiscreteDomain gridvx_ghosted_staggered + = collisions.get_gridvx_ghosted_staggered(); double const npoints(gridvx.size()); std::vector gridvx_ghosted_pred(npoints + 2); diff --git a/tests/geometryXVx/collisions_intra_maxwellian.cpp b/tests/geometryXVx/collisions_intra_maxwellian.cpp index b2332043d..26a68bc45 100644 --- a/tests/geometryXVx/collisions_intra_maxwellian.cpp +++ b/tests/geometryXVx/collisions_intra_maxwellian.cpp @@ -161,31 +161,22 @@ TEST(CollisionsIntraMaxwellian, CollisionsIntraMaxwellian) }); // diffusion coefficient - device_t>> + device_t>> Dcoll_f(collisions.get_mesh_ghosted()); auto Dcoll = Dcoll_f.span_view(); - compute_Dcoll< - CollisionsIntra:: - ghosted_vx_point_sampling>(Dcoll, collfreq, density_init, temperature_init); + compute_Dcoll(Dcoll, collfreq, density_init, temperature_init); - device_t>> + device_t>> dvDcoll_f(collisions.get_mesh_ghosted()); auto dvDcoll = dvDcoll_f.span_view(); - compute_dvDcoll< - CollisionsIntra:: - ghosted_vx_point_sampling>(dvDcoll, collfreq, density_init, temperature_init); + compute_dvDcoll(dvDcoll, collfreq, density_init, temperature_init); // kernel maxwellian fluid moments DFieldSpX Vcoll_f(ddc::get_domain(allfdistribu_host)); DFieldSpX Tcoll_f(ddc::get_domain(allfdistribu_host)); auto Vcoll = Vcoll_f.span_view(); auto Tcoll = Tcoll_f.span_view(); - compute_Vcoll_Tcoll< - CollisionsIntra::ghosted_vx_point_sampling>(Vcoll, Tcoll, allfdistribu, Dcoll, dvDcoll); + compute_Vcoll_Tcoll(Vcoll, Tcoll, allfdistribu, Dcoll, dvDcoll); host_t Vcoll_host(ddc::get_domain(allfdistribu_host)); host_t Tcoll_host(ddc::get_domain(allfdistribu_host)); @@ -302,16 +293,11 @@ TEST(CollisionsIntraMaxwellian, CollisionsIntraMaxwellian) // Vcoll and Tcoll calculation compute_collfreq(collfreq, nustar_profile, density_init, temperature_init); - compute_Dcoll< - CollisionsIntra:: - ghosted_vx_point_sampling>(Dcoll, collfreq, density_init, temperature_init); + compute_Dcoll(Dcoll, collfreq, density_init, temperature_init); - compute_dvDcoll< - CollisionsIntra:: - ghosted_vx_point_sampling>(dvDcoll, collfreq, density_init, temperature_init); + compute_dvDcoll(dvDcoll, collfreq, density_init, temperature_init); - compute_Vcoll_Tcoll< - CollisionsIntra::ghosted_vx_point_sampling>(Vcoll, Tcoll, allfdistribu, Dcoll, dvDcoll); + compute_Vcoll_Tcoll(Vcoll, Tcoll, allfdistribu, Dcoll, dvDcoll); moments(density_res.span_view(), allfdistribu_host.span_cview(), FluidMoments::s_density); moments(mean_velocity_res.span_view(),