Gyselalib++
 
Loading...
Searching...
No Matches
bsl_advection_x.hpp
1// SPDX-License-Identifier: MIT
2#pragma once
3#include <ddc/ddc.hpp>
4
5#include "ddc_alias_inline_functions.hpp"
6#include "ddc_aliases.hpp"
7#include "iadvectionx.hpp"
8#include "iinterpolator.hpp"
9#include "species_info.hpp"
10
14template <class Geometry, class GridX>
15class BslAdvectionSpatial : public IAdvectionSpatial<Geometry, GridX>
16{
17 using GridV = typename Geometry::template velocity_dim_for<GridX>;
18 using IdxRangeFdistrib = typename Geometry::IdxRangeFdistribu;
19 using IdxX = Idx<GridX>;
20 using IdxV = Idx<GridV>;
21 using DimX = typename GridX::continuous_dimension_type;
22 using DimV = typename GridV::continuous_dimension_type;
23 using IdxRangeSpaceVelocity = ddc::cartesian_prod_t<
24 typename Geometry::IdxRangeSpatial,
25 typename Geometry::IdxRangeVelocity>;
26
27private:
28 using PreallocatableInterpolatorType = interpolator_on_idx_range_t<
30 GridX,
31 IdxRangeSpaceVelocity>;
32 using InterpolatorType
33 = interpolator_on_idx_range_t<IInterpolator, GridX, IdxRangeSpaceVelocity>;
34 PreallocatableInterpolatorType const& m_interpolator_x;
35
36public:
41 explicit BslAdvectionSpatial(PreallocatableInterpolatorType const& interpolator_x)
42 : m_interpolator_x(interpolator_x)
43 {
44 }
45
46 ~BslAdvectionSpatial() override = default;
47
54 Field<double, IdxRangeFdistrib> operator()(
55 Field<double, IdxRangeFdistrib> const allfdistribu,
56 double const dt) const override
57 {
58 using IdxRangeBatch = ddc::remove_dims_of_t<IdxRangeFdistrib, Species, GridX>;
59 using IdxBatch = typename IdxRangeBatch::discrete_element_type;
60
61 Kokkos::Profiling::pushRegion("BslAdvectionSpatial");
62 IdxRangeFdistrib const idx_range = get_idx_range(allfdistribu);
63 IdxRange<GridX> const x_idx_range = ddc::select<GridX>(idx_range);
64 IdxRange<GridV> const v_idx_range = ddc::select<GridV>(idx_range);
65 IdxRange<Species> const sp_idx_range = ddc::select<Species>(idx_range);
66
67 // pre-allocate some memory to prevent allocation later in loop
68 IdxRangeSpaceVelocity batched_feet_idx_range(idx_range);
69 FieldMem<Coord<DimX>, IdxRangeSpaceVelocity> feet_coords_alloc(batched_feet_idx_range);
70 Field<Coord<DimX>, IdxRangeSpaceVelocity> feet_coords(get_field(feet_coords_alloc));
71 std::unique_ptr<InterpolatorType> const interpolator_x_ptr = m_interpolator_x.preallocate();
72 InterpolatorType const& interpolator_x = *interpolator_x_ptr;
73
74 IdxRangeBatch batch_idx_range(idx_range);
75
76 for (IdxSp const isp : sp_idx_range) {
77 double const sqrt_me_on_mspecies = std::sqrt(mass(ielec()) / mass(isp));
78 ddc::parallel_for_each(
79 Kokkos::DefaultExecutionSpace(),
80 batch_idx_range,
81 KOKKOS_LAMBDA(IdxBatch const ib) {
82 // compute the displacement
83 IdxV const iv(ib);
84 Coord<DimV> const coord_iv = ddc::coordinate(iv);
85 double const dx = sqrt_me_on_mspecies * dt * coord_iv;
86
87 // compute the coordinates of the feet
88 for (IdxX const ix : x_idx_range) {
89 feet_coords(ix, ib) = Coord<DimX>(ddc::coordinate(ix) - dx);
90 }
91 });
92 interpolator_x(allfdistribu[isp], get_const_field(feet_coords));
93 }
94
95 Kokkos::Profiling::popRegion();
96 return allfdistribu;
97 }
98};
A class which computes the spatial advection along the dimension of interest GridX.
Definition bsl_advection_x.hpp:16
BslAdvectionSpatial(PreallocatableInterpolatorType const &interpolator_x)
Constructor
Definition bsl_advection_x.hpp:41
Field< double, IdxRangeFdistrib > operator()(Field< double, IdxRangeFdistrib > const allfdistribu, double const dt) const override
Advects fdistribu along GridX for a duration dt.
Definition bsl_advection_x.hpp:54
A class which provides an advection operator.
Definition iadvectionx.hpp:16
A class which provides access to an interpolating function which can be preallocated where useful.
Definition iinterpolator.hpp:134
Definition geometry.hpp:94