Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 4 additions & 50 deletions src/engines/grpic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,8 @@ namespace ntt {
domain.mesh.metric,
xg_edge,
ds,
tags));
tags,
domain.mesh.flds_bc()));
Kokkos::parallel_for(
"MatchBoundaries",
CreateRangePolicy<M::Dim>(range_min, range_max),
Expand All @@ -657,7 +658,8 @@ namespace ntt {
domain.mesh.metric,
xg_edge,
ds,
tags));
tags,
domain.mesh.flds_bc()));
} else {
Kokkos::parallel_for(
"AbsorbCurrents",
Expand All @@ -672,54 +674,6 @@ namespace ntt {
}
}

// void AbsorbCurrentsIn(dir::direction_t<M::Dim> direction,
// domain_t& domain,
// BCTags tags) {
// /**
// * absorbing currents at the boundaries
// */
// // @TODO: also in MatchFieldsIn (need a better way)
// const auto ds_array = m_params.template get<boundaries_t<real_t>>(
// "grid.boundaries.match.ds");
// const auto dim = in::x1;
// real_t xg_min, xg_max, xg_edge;
// real_t ds;
// ds = ds_array[(short)dim].second;
// xg_max = m_metadomain.mesh().extent(dim).second;
// xg_min = xg_max - ds;
// xg_edge = xg_max;
//
// boundaries_t<real_t> box;
// boundaries_t<bool> incl_ghosts;
// for (unsigned short d { 0 }; d < M::Dim; ++d) {
// if (d == static_cast<unsigned short>(dim)) {
// box.push_back({ xg_min, xg_max });
// incl_ghosts.push_back({ false, true });
// } else {
// box.push_back(Range::All);
// incl_ghosts.push_back({ true, true });
// }
// }
// if (not domain.mesh.Intersects(box)) {
// return;
// }
// const auto intersect_range = domain.mesh.ExtentToRange(box, incl_ghosts);
// tuple_t<std::size_t, M::Dim> range_min { 0 };
// tuple_t<std::size_t, M::Dim> range_max { 0 };
//
// for (unsigned short d { 0 }; d < M::Dim; ++d) {
// range_min[d] = intersect_range[d].first;
// range_max[d] = intersect_range[d].second;
// }
// Kokkos::parallel_for(
// "AbsorbCurrentsGR",
// CreateRangePolicy<M::Dim>(range_min, range_max),
// kernel::bc::AbsorbCurrentsGR_kernel<M, 1>(domain.fields.cur0,
// domain.mesh.metric,
// xg_edge,
// ds));
// }

void HorizonFieldsIn(dir::direction_t<M::Dim> direction,
domain_t& domain,
BCTags tags,
Expand Down
55 changes: 26 additions & 29 deletions src/engines/srpic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,31 +492,20 @@ namespace ntt {
species.npart(),
(double)species.charge()),
HERE);
// clang-format off
Kokkos::parallel_for("CurrentsDeposit",
species.rangeActiveParticles(),
kernel::DepositCurrents_kernel<SimEngine::SRPIC, M>(
scatter_cur,
species.i1,
species.i2,
species.i3,
species.i1_prev,
species.i2_prev,
species.i3_prev,
species.dx1,
species.dx2,
species.dx3,
species.dx1_prev,
species.dx2_prev,
species.dx3_prev,
species.ux1,
species.ux2,
species.ux3,
species.phi,
species.weight,
species.tag,
species.i1, species.i2, species.i3,
species.i1_prev, species.i2_prev, species.i3_prev,
species.dx1, species.dx2, species.dx3,
species.dx1_prev, species.dx2_prev, species.dx3_prev,
species.ux1, species.ux2, species.ux3,
species.phi, species.weight, species.tag,
domain.mesh.metric,
(real_t)(species.charge()),
dt));
(real_t)(species.charge()), dt));
// clang-format on
}
Kokkos::Experimental::contribute(domain.fields.cur, scatter_cur);
}
Expand Down Expand Up @@ -685,6 +674,7 @@ namespace ntt {
traits::has_member<traits::pgen::match_fields_t, pgen_t>::value) {
auto match_fields = m_pgen.MatchFields(time);
call_match_fields<decltype(match_fields), in::x1>(domain.fields.em,
domain.mesh.flds_bc(),
match_fields,
domain.mesh.metric,
xg_edge,
Expand All @@ -696,6 +686,7 @@ namespace ntt {
traits::has_member<traits::pgen::match_fields_in_x1_t, pgen_t>::value) {
auto match_fields = m_pgen.MatchFieldsInX1(time);
call_match_fields<decltype(match_fields), in::x1>(domain.fields.em,
domain.mesh.flds_bc(),
match_fields,
domain.mesh.metric,
xg_edge,
Expand All @@ -710,6 +701,7 @@ namespace ntt {
traits::has_member<traits::pgen::match_fields_t, pgen_t>::value) {
auto match_fields = m_pgen.MatchFields(time);
call_match_fields<decltype(match_fields), in::x2>(domain.fields.em,
domain.mesh.flds_bc(),
match_fields,
domain.mesh.metric,
xg_edge,
Expand All @@ -721,6 +713,7 @@ namespace ntt {
traits::has_member<traits::pgen::match_fields_in_x2_t, pgen_t>::value) {
auto match_fields = m_pgen.MatchFieldsInX2(time);
call_match_fields<decltype(match_fields), in::x2>(domain.fields.em,
domain.mesh.flds_bc(),
match_fields,
domain.mesh.metric,
xg_edge,
Expand All @@ -738,6 +731,7 @@ namespace ntt {
traits::has_member<traits::pgen::match_fields_t, pgen_t>::value) {
auto match_fields = m_pgen.MatchFields(time);
call_match_fields<decltype(match_fields), in::x3>(domain.fields.em,
domain.mesh.flds_bc(),
match_fields,
domain.mesh.metric,
xg_edge,
Expand All @@ -749,6 +743,7 @@ namespace ntt {
traits::has_member<traits::pgen::match_fields_in_x3_t, pgen_t>::value) {
auto match_fields = m_pgen.MatchFieldsInX3(time);
call_match_fields<decltype(match_fields), in::x3>(domain.fields.em,
domain.mesh.flds_bc(),
match_fields,
domain.mesh.metric,
xg_edge,
Expand Down Expand Up @@ -1463,14 +1458,15 @@ namespace ntt {
}

template <class T, in O>
void call_match_fields(ndfield_t<M::Dim, 6>& fields,
const T& match_fields,
const M& metric,
real_t xg_edge,
real_t ds,
BCTags tags,
tuple_t<ncells_t, M::Dim>& range_min,
tuple_t<ncells_t, M::Dim>& range_max) {
void call_match_fields(ndfield_t<M::Dim, 6>& fields,
const boundaries_t<FldsBC>& boundaries,
const T& match_fields,
const M& metric,
real_t xg_edge,
real_t ds,
BCTags tags,
tuple_t<ncells_t, M::Dim>& range_min,
tuple_t<ncells_t, M::Dim>& range_max) {
Kokkos::parallel_for(
"MatchFields",
CreateRangePolicy<M::Dim>(range_min, range_max),
Expand All @@ -1479,7 +1475,8 @@ namespace ntt {
metric,
xg_edge,
ds,
tags));
tags,
boundaries));
}
};

Expand Down
60 changes: 41 additions & 19 deletions src/kernels/fields_bcs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace kernel::bc {
static_assert(M::is_metric, "M must be a metric class");
static_assert(static_cast<dim_t>(o) < static_cast<dim_t>(M::Dim),
"Invalid component index");
static constexpr auto D = M::Dim;
static constexpr idx_t i = static_cast<idx_t>(o) + 1u;
static constexpr bool defines_dx1 = traits::has_method<traits::dx1_t, I>::value;
static constexpr bool defines_dx2 = traits::has_method<traits::dx2_t, I>::value;
Expand All @@ -66,18 +67,30 @@ namespace kernel::bc {
const real_t dx_abs;
const BCTags tags;

MatchBoundaries_kernel(ndfield_t<M::Dim, 6> Fld,
const I& fset,
const M& metric,
real_t xg_edge,
real_t dx_abs,
BCTags tags)
ncells_t extent_2 { 0u };
bool is_axis_i2min { false }, is_axis_i2max { false };

MatchBoundaries_kernel(ndfield_t<M::Dim, 6> Fld,
const I& fset,
const M& metric,
real_t xg_edge,
real_t dx_abs,
BCTags tags,
const boundaries_t<FldsBC>& boundaries)
: Fld { Fld }
, fset { fset }
, metric { metric }
, xg_edge { xg_edge }
, dx_abs { dx_abs }
, tags { tags } {}
, tags { tags } {
if constexpr ((M::CoordType != Coord::Cart) &&
((D == Dim::_2D) || (D == Dim::_3D))) {
raise::ErrorIf(boundaries.size() < 2, "boundaries defined incorrectly", HERE);
is_axis_i2min = (boundaries[1].first == FldsBC::AXIS);
is_axis_i2max = (boundaries[1].second == FldsBC::AXIS);
extent_2 = static_cast<ncells_t>(Fld.extent(1));
}
}

Inline auto shape(const real_t& dx) const -> real_t {
return math::tanh(dx * FOUR / dx_abs);
Expand Down Expand Up @@ -281,14 +294,20 @@ namespace kernel::bc {
metric.template convert<Crd::Cd, Crd::Ph>({ i1_, i2_ }, x_Ph_00);

if constexpr (defines_ex3 and S == SimEngine::SRPIC) {
Fld(i1, i2, em::ex3) = s * Fld(i1, i2, em::ex3) +
(ONE - s) *
metric.template transform<3, Idx::T, Idx::U>(
{ i1_, i2_ },
fset.ex3(x_Ph_00));
Fld(i1, i2, em::ex3) = s * Fld(i1, i2, em::ex3);
if ((!is_axis_i2min or (i2 > N_GHOSTS)) and
(!is_axis_i2max or (i2 < extent_2 - N_GHOSTS))) {
Fld(i1, i2, em::ex3) += (ONE - s) *
metric.template transform<3, Idx::T, Idx::U>(
{ i1_, i2_ },
fset.ex3(x_Ph_00));
}
} else if constexpr (defines_dx3 and S == SimEngine::GRPIC) {
Fld(i1, i2, em::dx3) = s * Fld(i1, i2, em::dx3) +
(ONE - s) * fset.dx3(x_Ph_00);
Fld(i1, i2, em::dx3) = s * Fld(i1, i2, em::dx3);
if ((!is_axis_i2min or (i2 > N_GHOSTS)) and
(!is_axis_i2max or (i2 < extent_2 - N_GHOSTS))) {
Fld(i1, i2, em::dx3) += (ONE - s) * fset.dx3(x_Ph_00);
}
}
}
}
Expand Down Expand Up @@ -403,11 +422,14 @@ namespace kernel::bc {
coord_t<Dim::_3D> x_Ph_00H { ZERO };
metric.template convert<Crd::Cd, Crd::Ph>({ i1_, i2_, i3_ + HALF },
x_Ph_00H);
Fld(i1, i2, i3, em::ex3) =
s * Fld(i1, i2, i3, em::ex3) +
(ONE - s) * metric.template transform<3, Idx::T, Idx::U>(
{ i1_, i2_, i3_ + HALF },
fset.ex3(x_Ph_00H));
Fld(i1, i2, i3, em::ex3) = s * Fld(i1, i2, i3, em::ex3);
if ((!is_axis_i2min or (i2 > N_GHOSTS)) and
(!is_axis_i2max or (i2 < extent_2 - N_GHOSTS))) {
Fld(i1, i2, i3, em::ex3) +=
(ONE - s) * metric.template transform<3, Idx::T, Idx::U>(
{ i1_, i2_, i3_ + HALF },
fset.ex3(x_Ph_00H));
}
}
}
}
Expand Down
13 changes: 9 additions & 4 deletions src/kernels/tests/flds_bc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,13 @@ void testFldsBCs(const std::vector<std::size_t>& res) {
{ res[0] + 2 * N_GHOSTS, res[1] + N_GHOSTS, res[2] + N_GHOSTS });
}

const auto xg_edge = (real_t)(sx[0].second);
const auto dx_abs = (real_t)(res[0] / 10.0);

const auto xg_edge = (real_t)(sx[0].second);
const auto dx_abs = (real_t)(res[0] / 10.0);
boundaries_t<FldsBC> flds_bc {
{ FldsBC::PERIODIC, FldsBC::PERIODIC },
{ FldsBC::PERIODIC, FldsBC::PERIODIC },
{ FldsBC::PERIODIC, FldsBC::PERIODIC }
};
Kokkos::parallel_for(
"MatchBoundaries_kernel",
range,
Expand All @@ -101,7 +105,8 @@ void testFldsBCs(const std::vector<std::size_t>& res) {
metric,
xg_edge,
dx_abs,
BC::E | BC::B));
BC::E | BC::B,
flds_bc));

if constexpr (D == Dim::_1D) {
Kokkos::parallel_for(
Expand Down