Skip to content
Draft
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
20 changes: 15 additions & 5 deletions src/archetypes/spatial_dist.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ namespace arch {
struct Uniform : public SpatialDistribution<S, M> {
Uniform(const M& metric) : SpatialDistribution<S, M> { metric } {}

Inline auto operator()(const coord_t<M::Dim>&) const -> real_t {
return ONE;
Inline auto operator()(const coord_t<M::Dim>&,
real_t& nppc_distribution,
real_t& weight_distribution) const {
nppc_distribution = ONE;
weight_distribution = ONE;
// return nppc_distribution;
}
};

Expand All @@ -65,7 +69,9 @@ namespace arch {
, target_density { target_density }
, target_max_density { target_max_density } {}

Inline auto operator()(const coord_t<M::Dim>& x_Ph) const -> real_t {
Inline auto operator()(const coord_t<M::Dim>& x_Ph,
real_t& nppc_distribution,
real_t& weight_distribution) const {
coord_t<M::Dim> x_Cd { ZERO };
metric.template convert<Crd::Ph, Crd::Cd>(x_Ph, x_Cd);
real_t dens { ZERO };
Expand All @@ -85,9 +91,13 @@ namespace arch {
}
const auto target = target_density(x_Ph);
if (0.9 * target > dens) {
return (target - dens) / target_max_density;
nppc_distribution = (target - dens) / target_max_density;
weight_distribution = ONE;
// return nppc_distribution;
} else {
return ZERO;
nppc_distribution = ZERO;
weight_distribution = ONE;
// return nppc_distribution;
}
}
};
Expand Down
30 changes: 18 additions & 12 deletions src/kernels/injectors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,9 @@ namespace kernel {
coord_t<Dim::_1D> x_Cd { i1_ + HALF };
coord_t<Dim::_1D> x_Ph { ZERO };
metric.template convert<Crd::Cd, Crd::Ph>(x_Cd, x_Ph);
const auto ppc = static_cast<npart_t>(ppc0 * spatial_dist(x_Ph));
auto ppc_dist { ZERO }, weight_dist { ONE };
spatial_dist(x_Ph, ppc_dist, weight_dist);
const auto ppc = static_cast<npart_t>(ppc0 * ppc_dist);
if (ppc == 0) {
return;
}
Expand Down Expand Up @@ -704,10 +706,10 @@ namespace kernel {
tags_1(index + offset1) = ParticleTag::alive;
tags_2(index + offset2) = ParticleTag::alive;
if (M::CoordType == Coord::Cart) {
weights_1(index + offset1) = ONE;
weights_2(index + offset2) = ONE;
weights_1(index + offset1) = ONE * weight_dist;
weights_2(index + offset2) = ONE * weight_dist;
} else {
const auto wei = metric.sqrt_det_h({ i1_ + HALF }) * inv_V0;
const auto wei = metric.sqrt_det_h({ i1_ + HALF }) * inv_V0 * weight_dist;
weights_1(index + offset1) = wei;
weights_2(index + offset2) = wei;
}
Expand All @@ -731,7 +733,9 @@ namespace kernel {
x_Cd_[2] = ZERO;
}
metric.template convert<Crd::Cd, Crd::Ph>(x_Cd, x_Ph);
const auto ppc = static_cast<npart_t>(ppc0 * spatial_dist(x_Ph));
auto ppc_dist { ZERO }, weight_dist { ONE };
spatial_dist(x_Ph, ppc_dist, weight_dist);
const auto ppc = static_cast<npart_t>(ppc0 * ppc_dist);
if (ppc == 0) {
return;
}
Expand Down Expand Up @@ -774,10 +778,10 @@ namespace kernel {
tags_1(index + offset1) = ParticleTag::alive;
tags_2(index + offset2) = ParticleTag::alive;
if (M::CoordType == Coord::Cart) {
weights_1(index + offset1) = ONE;
weights_2(index + offset2) = ONE;
weights_1(index + offset1) = ONE * weight_dist;
weights_2(index + offset2) = ONE * weight_dist;
} else {
const auto wei = metric.sqrt_det_h({ i1_ + HALF, i2_ + HALF }) * inv_V0;
const auto wei = metric.sqrt_det_h({ i1_ + HALF, i2_ + HALF }) * inv_V0 * weight_dist;
weights_1(index + offset1) = wei;
weights_2(index + offset2) = wei;
}
Expand All @@ -798,7 +802,9 @@ namespace kernel {
coord_t<Dim::_3D> x_Cd { i1_ + HALF, i2_ + HALF, i3_ + HALF };
coord_t<Dim::_3D> x_Ph { ZERO };
metric.template convert<Crd::Cd, Crd::Ph>(x_Cd, x_Ph);
const auto ppc = static_cast<npart_t>(ppc0 * spatial_dist(x_Ph));
auto ppc_dist { ZERO }, weight_dist { ONE };
spatial_dist(x_Ph, ppc_dist, weight_dist);
const auto ppc = static_cast<npart_t>(ppc0 * ppc_dist);
if (ppc == 0) {
return;
}
Expand Down Expand Up @@ -847,12 +853,12 @@ namespace kernel {
tags_1(index + offset1) = ParticleTag::alive;
tags_2(index + offset2) = ParticleTag::alive;
if (M::CoordType == Coord::Cart) {
weights_1(index + offset1) = ONE;
weights_2(index + offset2) = ONE;
weights_1(index + offset1) = ONE * weight_dist;
weights_2(index + offset2) = ONE * weight_dist;
} else {
const auto wei = metric.sqrt_det_h(
{ i1_ + HALF, i2_ + HALF, i3_ + HALF }) *
inv_V0;
inv_V0 * weight_dist;
weights_1(index + offset1) = wei;
weights_2(index + offset2) = wei;
}
Expand Down