Gyselalib++
 
Loading...
Searching...
No Matches
bsl_advection_vx.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 "ddc_helper.hpp"
8#include "iadvectionvx.hpp"
9#include "iinterpolator.hpp"
10#include "species_info.hpp"
11
15template <class Geometry, class GridV>
16class BslAdvectionVelocity : public IAdvectionVelocity<Geometry, GridV>
17{
18 using IdxRangeFdistribu = typename Geometry::IdxRangeFdistribu;
19 using IdxRangeSpatial = typename Geometry::IdxRangeSpatial;
20 using IdxSpatial = typename IdxRangeSpatial::discrete_element_type;
21 using IdxV = Idx<GridV>;
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 GridV,
31 IdxRangeSpaceVelocity>;
32 using InterpolatorType
33 = interpolator_on_idx_range_t<IInterpolator, GridV, IdxRangeSpaceVelocity>;
34 PreallocatableInterpolatorType const& m_interpolator_v;
35
36public:
41 explicit BslAdvectionVelocity(PreallocatableInterpolatorType const& interpolator_v)
42 : m_interpolator_v(interpolator_v)
43 {
44 }
45
46 ~BslAdvectionVelocity() override = default;
47
55 Field<double, IdxRangeFdistribu> operator()(
56 Field<double, IdxRangeFdistribu> const allfdistribu,
57 Field<const double, IdxRangeSpatial> const electric_field,
58 double const dt) const override
59 {
60 using IdxRangeBatch = ddc::remove_dims_of_t<IdxRangeFdistribu, Species, GridV>;
61 using IdxBatch = typename IdxRangeBatch::discrete_element_type;
62
63
64 Kokkos::Profiling::pushRegion("BslAdvectionVelocity");
65 IdxRangeFdistribu const idx_range = get_idx_range(allfdistribu);
66 IdxRange<GridV> const idx_range_v = ddc::select<GridV>(idx_range);
67 IdxRange<Species> const idx_range_sp = ddc::select<Species>(idx_range);
68
69 FieldMem<double, typename InterpolatorType::batched_derivs_idx_range_type> derivs_min(
70 m_interpolator_v.batched_derivs_idx_range_xmin(
71 ddc::remove_dims_of<Species>(idx_range)));
72 FieldMem<double, typename InterpolatorType::batched_derivs_idx_range_type> derivs_max(
73 m_interpolator_v.batched_derivs_idx_range_xmax(
74 ddc::remove_dims_of<Species>(idx_range)));
75 ddc::parallel_fill(derivs_min, 0.);
76 ddc::parallel_fill(derivs_max, 0.);
77
78 // pre-allocate some memory to prevent allocation later in loop
79 IdxRangeSpaceVelocity batched_feet_idx_range(idx_range);
80 FieldMem<Coord<DimV>, IdxRangeSpaceVelocity> feet_coords_alloc(batched_feet_idx_range);
81 Field<Coord<DimV>, IdxRangeSpaceVelocity> feet_coords(get_field(feet_coords_alloc));
82 std::unique_ptr<InterpolatorType> const interpolator_v_ptr = m_interpolator_v.preallocate();
83 InterpolatorType const& interpolator_v = *interpolator_v_ptr;
84
85 IdxRangeSpatial const idx_range_spatial(get_idx_range(allfdistribu));
86
87 IdxRangeBatch batch_idx_range(idx_range);
88
89 ddc::for_each(idx_range_sp, [&](IdxSp const isp) {
90 double const charge_proxy
91 = charge(isp); // TODO: consider proper way to access charge from device
92 double const sqrt_me_on_mspecies = std::sqrt(mass(ielec()) / mass(isp));
93 ddc::parallel_for_each(
94 Kokkos::DefaultExecutionSpace(),
95 batch_idx_range,
96 KOKKOS_LAMBDA(IdxBatch const ib) {
97 IdxSpatial const ix(ib);
98 // compute the displacement
99 double const dvx
100 = charge_proxy * sqrt_me_on_mspecies * dt * electric_field(ix);
101
102 // compute the coordinates of the feet
103 for (IdxV const iv : idx_range_v) {
104 feet_coords(iv, ib) = Coord<DimV>(ddc::coordinate(iv) - dvx);
105 }
106 });
107 interpolator_v(
108 allfdistribu[isp],
109 get_const_field(feet_coords),
110 get_const_field(derivs_min),
111 get_const_field(derivs_max));
112 });
113
114 Kokkos::Profiling::popRegion();
115 return allfdistribu;
116 }
117};
A class which computes the velocity advection along the dimension of interest GridV.
Definition bsl_advection_vx.hpp:17
BslAdvectionVelocity(PreallocatableInterpolatorType const &interpolator_v)
Constructor.
Definition bsl_advection_vx.hpp:41
Field< double, IdxRangeFdistribu > operator()(Field< double, IdxRangeFdistribu > const allfdistribu, Field< const double, IdxRangeSpatial > const electric_field, double const dt) const override
Advects fdistribu along GridV for a duration dt.
Definition bsl_advection_vx.hpp:55
A class which provides an advection operator.
Definition iadvectionvx.hpp:17
A class which provides access to an interpolating function which can be preallocated where useful.
Definition iinterpolator.hpp:134