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
12 changes: 4 additions & 8 deletions src/include/const_accessor_simple.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ struct ParticleProxySimple
{
using Particle = typename Mparticles::Particle;
using real_t = typename Mparticles::real_t;
using Patch = typename Mparticles::Patch;
using Real3 = Vec3<real_t>;

ParticleProxySimple(Particle& prt, const Mparticles& mprts)
Expand Down Expand Up @@ -212,11 +211,8 @@ struct ConstAccessorSimple

Patch operator[](int p) const { return {*this, p}; }
const Mparticles& mprts() const { return mprts_; }
uint size(int p) const { return mprts_[p].size(); }
typename Mparticles::Patch::iterator data(int p) const
{
return mprts_[p].begin();
}
uint size(int p) const { return mprts_.size(p); }
typename Mparticles::iterator data(int p) const { return mprts_.begin(p); }
const Grid_t& grid() const { return mprts_.grid(); }

private:
Expand All @@ -237,8 +233,8 @@ struct AccessorSimple
Patch operator[](int p) { return {*this, p}; }
const Mparticles& mprts() const { return mprts_; }
Mparticles& mprts() { return mprts_; }
uint size(int p) const { return mprts_[p].size(); }
typename Mparticles::Patch::iterator data(int p) { return mprts_[p].begin(); }
uint size(int p) const { return mprts_.size(p); }
typename Mparticles::iterator data(int p) { return mprts_.begin(p); }
const Grid_t& grid() const { return mprts_.grid(); }

private:
Expand Down
2 changes: 1 addition & 1 deletion src/include/injector_simple.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct InjectorSimple
new_prt.kind,
mprts_.uid_gen(),
new_prt.tag};
mprts_[p_].push_back(prt);
mprts_.push_back(p_, prt);
}

void reweight(const psc::particle::Inject& new_prt)
Expand Down
16 changes: 8 additions & 8 deletions src/include/particle_simple.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ public:
template <typename FUNC>
static void run(FUNC&& func)
{
func("x", [](Particle& prt) { return &prt.x[0]; });
func("y", [](Particle& prt) { return &prt.x[1]; });
func("z", [](Particle& prt) { return &prt.x[2]; });
func("ux", [](Particle& prt) { return &prt.u[0]; });
func("uy", [](Particle& prt) { return &prt.u[1]; });
func("uz", [](Particle& prt) { return &prt.u[2]; });
func("kind", [](Particle& prt) { return &prt.kind; });
func("qni_wni", [](Particle& prt) { return &prt.qni_wni; });
func("x", [](auto& prt) { return &prt.x[0]; });
func("y", [](auto& prt) { return &prt.x[1]; });
func("z", [](auto& prt) { return &prt.x[2]; });
func("ux", [](auto& prt) { return &prt.u[0]; });
func("uy", [](auto& prt) { return &prt.u[1]; });
func("uz", [](auto& prt) { return &prt.u[2]; });
func("kind", [](auto& prt) { return &prt.kind; });
func("qni_wni", [](auto& prt) { return &prt.qni_wni; });
}
};
111 changes: 40 additions & 71 deletions src/include/particles_simple.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ struct MparticlesStorage
using PatchBuffer = std::vector<Particle>;
using Buffers = std::vector<PatchBuffer>;
using Range = Span<Particle>;
using ConstRange = Span<const Particle>;
using iterator = typename Range::iterator;
using const_iterator = typename Range::const_iterator;

Expand Down Expand Up @@ -91,10 +92,22 @@ struct MparticlesStorage
}

Range operator[](int p) { return {bufs_[p].data(), bufs_[p].size()}; }

ConstRange operator[](int p) const
{
return {bufs_[p].data(), bufs_[p].size()};
}

Particle& at(int p, int n)
{
return bufs_[p][n];
} // FIXME, ugly and not great for effciency

const Particle& at(int p, int n) const
{
return bufs_[p][n];
} // FIXME, ugly and not great for effciency

void push_back(int p, const Particle& prt) { bufs_[p].push_back(prt); }

Buffers& bndBuffers() { return bufs_; }
Expand All @@ -119,65 +132,7 @@ struct MparticlesSimple : MparticlesBase
using BndBuffer = typename Storage::PatchBuffer;
using BndBuffers = typename Storage::Buffers;

struct Patch
{
using iterator = typename Storage::iterator;
using const_iterator = typename Storage::const_iterator;

Patch(MparticlesSimple& mprts, int p) : mprts_(mprts), p_(p) {}

Patch(const Patch&) = delete;
Patch(Patch&&) = default;

Particle& operator[](int n) { return mprts_.storage_.at(p_, n); }
const Particle& operator[](int n) const
{
return mprts_.storage_.at(p_, n);
}

iterator begin() { return mprts_.storage_[p_].begin(); }
iterator end() { return mprts_.storage_[p_].end(); }
unsigned int size() const { return mprts_.storage_[p_].size(); }

void push_back(const Particle& new_prt)
{
// need to copy because we modify it
auto prt = new_prt;
checkInPatchMod(prt);
validCellIndex(prt);
mprts_.storage_.push_back(p_, prt);
}

void check() const
{
for (auto& prt : mprts_.storage_[p_]) {
mprts_.pi_.validCellIndex(prt.x());
}
}

// ParticleIndexer functionality
int cellPosition(real_t xi, int d) const
{
return mprts_.pi_.cellPosition(xi, d);
}
int validCellIndex(const Particle& prt) const
{
return mprts_.pi_.validCellIndex(prt.x);
}

void checkInPatchMod(Particle& prt) const
{
return mprts_.pi_.checkInPatchMod(prt.x);
}

const Grid_t& grid() const { return mprts_.grid(); }
const MparticlesSimple& mprts() const { return mprts_; }
int p() const { return p_; }

private:
MparticlesSimple& mprts_;
int p_;
};
using iterator = typename Storage::iterator;

explicit MparticlesSimple(const Grid_t& grid)
: MparticlesBase(grid),
Expand All @@ -197,11 +152,6 @@ struct MparticlesSimple : MparticlesBase
storage_.reset(grid);
}

Patch operator[](int p) const
{
return {const_cast<MparticlesSimple&>(*this), p};
} // FIXME, isn't actually const

void reserve_all(const std::vector<uint>& n_prts_by_patch)
{
storage_.reserve_all(n_prts_by_patch);
Expand All @@ -219,6 +169,22 @@ struct MparticlesSimple : MparticlesBase

const ParticleIndexer<real_t>& particleIndexer() const { return pi_; }

int cellPosition(int p, int n, int d) const
{
return pi_.cellPosition(this->at(p, n).x[d], d);
}

int validCellIndex(const Real3& x) const { return pi_.validCellIndex(x); }

void push_back(int p, const Particle& new_prt)
{
// need to copy because we modify it
auto prt = new_prt;
pi_.checkInPatchMod(prt.x);
validCellIndex(prt.x);
storage_.push_back(p, prt);
}

InjectorSimple<MparticlesSimple> injector() { return {*this}; }
ConstAccessor accessor() const
{
Expand All @@ -228,13 +194,6 @@ struct MparticlesSimple : MparticlesBase

BndBuffers& bndBuffers() { return storage_.bndBuffers(); }

void check() const
{
for (int p = 0; p < n_patches(); p++) {
(*this)[p].check();
}
}

void dump(const std::string& filename)
{
FILE* file = fopen(filename.c_str(), "w");
Expand All @@ -254,6 +213,16 @@ struct MparticlesSimple : MparticlesBase
fclose(file);
}

Particle& at(int p, int n) { return storage_.at(p, n); }

const Particle& at(int p, int n) const { return storage_.at(p, n); }

iterator begin(int p) { return storage_[p].begin(); }

iterator end(int p) { return storage_[p].end(); }

unsigned int size(int p) const { return storage_[p].size(); }

real_t prt_q(const Particle& prt) const { return grid().kinds[prt.kind].q; }

real_t prt_m(const Particle& prt) const { return grid().kinds[prt.kind].m; }
Expand Down
16 changes: 8 additions & 8 deletions src/include/particles_simple.inl
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ public:
template <typename FUNC>
void operator()(const std::string& name, FUNC&& func)
{
using Ret = typename std::remove_pointer<decltype(func(mprts_[0][0]))>::type;
using Ret = typename std::remove_const_t<
typename std::remove_pointer_t<decltype(func(mprts_.at(0, 0)))>>;
std::vector<Ret> vec(mprts_.size());
auto it = vec.begin();
for (int p = 0; p < mprts_.n_patches(); p++) {
auto prts = mprts_[p];
for (int n = 0; n < prts.size(); n++) {
*it++ = *func(prts[n]);
for (int n = 0; n < mprts_.size(p); n++) {
*it++ = *func(mprts_.at(p, n));
}
}

Expand All @@ -83,15 +83,15 @@ public:
template <typename FUNC>
void operator()(const std::string& name, FUNC&& func)
{
using Ret = typename std::remove_pointer<decltype(func(mprts_[0][0]))>::type;
using Ret =
typename std::remove_pointer<decltype(func(mprts_.at(0, 0)))>::type;
std::vector<Ret> vec(mprts_.size());
reader_.get<VariableByParticle>(name, vec, mprts_.grid(),
kg::io::Mode::Blocking);
auto it = vec.begin();
for (int p = 0; p < mprts_.n_patches(); p++) {
auto prts = mprts_[p];
for (int n = 0; n < prts.size(); n++) {
*func(prts[n]) = *it++;
for (int n = 0; n < mprts_.size(p); n++) {
*func(mprts_.at(p, n)) = *it++;
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/libpsc/mparticles.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ void psc_mparticles_check(MparticlesBase& mprts_base)

for (int p = 0; p < grid.n_patches(); p++) {
auto& patch = grid.patches[p];
auto&& prts = mprts[p];

double xb[3], xe[3];

Expand All @@ -61,12 +60,13 @@ void psc_mparticles_check(MparticlesBase& mprts_base)
xe[d] = patch.xb[d] + grid.ldims[d] * grid.domain.dx[d];
}

for (auto prt : prts) {
if (prt.x[0] < 0.f || prt.x[0] >= xe[0] - xb[0] || // FIXME xz only!
prt.x[2] < 0.f || prt.x[2] >= xe[2] - xb[2]) {
for (auto prt_iter = mprts.begin(p); prt_iter != mprts.end(p); prt_iter++) {
if (prt_iter->x[0] < 0.f ||
prt_iter->x[0] >= xe[0] - xb[0] || // FIXME xz only!
prt_iter->x[2] < 0.f || prt_iter->x[2] >= xe[2] - xb[2]) {
if (fail_cnt++ < 10) {
mprintf("FAIL: xi %g [%g:%g]\n", prt.x[0], 0., xe[0] - xb[0]);
mprintf(" zi %g [%g:%g]\n", prt.x[2], 0., xe[2] - xb[2]);
mprintf("FAIL: xi %g [%g:%g]\n", prt_iter->x[0], 0., xe[0] - xb[0]);
mprintf(" zi %g [%g:%g]\n", prt_iter->x[2], 0., xe[2] - xb[2]);
}
}
}
Expand Down
18 changes: 7 additions & 11 deletions src/libpsc/psc_balance/psc_balance_impl.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -608,9 +608,8 @@ public:

for (int pi = 0; pi < recv->nr_patches; pi++) {
int p = recv->pi_to_patch[pi];
auto&& prts_new = mp_new[p];
int nn = prts_new.size() * (sizeof(Particle) / sizeof(real_t));
MPI_Irecv(&*prts_new.begin(), nn, mpi_dtype, recv->rank, pi, comm_,
int nn = mp_new.size(p) * (sizeof(Particle) / sizeof(real_t));
MPI_Irecv(&*mp_new.begin(p), nn, mpi_dtype, recv->rank, pi, comm_,
&recv_reqs[nr_recv_reqs++]);
}
}
Expand All @@ -629,10 +628,9 @@ public:

for (int pi = 0; pi < send->nr_patches; pi++) {
int p = send->pi_to_patch[pi];
auto&& prts_old = mp_old[p];
int nn = prts_old.size() * (sizeof(Particle) / sizeof(real_t));
int nn = mp_old.size(p) * (sizeof(Particle) / sizeof(real_t));
// mprintf("A send -> %d tag %d (patch %d)\n", send->rank, pi, p);
MPI_Isend(&*prts_old.begin(), nn, mpi_dtype, send->rank, pi, comm_,
MPI_Isend(&*mp_old.begin(p), nn, mpi_dtype, send->rank, pi, comm_,
&send_reqs[nr_send_reqs++]);
}
}
Expand All @@ -646,12 +644,10 @@ public:
continue;
}

auto&& prts_old = mp_old[recv_info_[p].patch];
auto&& prts_new = mp_new[p];
assert(prts_old.size() == prts_new.size());
assert(mp_old.size(recv_info_[p].patch) == mp_new.size(p));
#if 1
for (int n = 0; n < prts_new.size(); n++) {
prts_new[n] = prts_old[n];
for (int n = 0; n < mp_new.size(p); n++) {
mp_new.at(p, n) = mp_old.at(recv_info_[p].patch, n);
}
#else
// FIXME, this needs at least a proper interface -- if not separately
Expand Down
Loading