Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix conduit for changes to particles #1010

Merged
merged 4 commits into from
Jun 16, 2020
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
69 changes: 41 additions & 28 deletions Src/Extern/Conduit/AMReX_Conduit_Blueprint_ParticlesI.H
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Template implementation of functions for Conduit Mesh Blueprint Support
// for AMReX Particle Containers
//
// This file is included in AMReX_Conduit_Blueprint.H when
// This file is included in AMReX_Conduit_Blueprint.H when
// when USE_PARTICLES = TRUE
//
///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -36,9 +36,9 @@ ParticleTileToBlueprint(const ParticleTile<NStructReal,

// knowing the above, we can zero copy the x,y,z positions + id, cpu
// and any user fields in the AOS

// get the first particle's struct
const auto &p_aos = ptile.GetArrayOfStructs()[0];
const auto &pstruct = ptile.GetArrayOfStructs();

// setup a blueprint description for the particle mesh
// create a coordinate set
Expand All @@ -64,18 +64,23 @@ ParticleTileToBlueprint(const ParticleTile<NStructReal,
// point locations from from aos
//----------------------------------//

n_coords["values/x"].set_external(const_cast<ParticleReal*>(&p_aos.pos(0)),
const char* pbuf = reinterpret_cast<const char*>(pstruct.data());

const ParticleReal* xp = reinterpret_cast<const ParticleReal*>(pbuf); pbuf += sizeof(ParticleReal);
n_coords["values/x"].set_external(xp,
num_particles,
0,
struct_size);
#if AMREX_SPACEDIM > 1
n_coords["values/y"].set_external(const_cast<ParticleReal*>(&p_aos.pos(1)),
const ParticleReal* yp = reinterpret_cast<const ParticleReal*>(pbuf); pbuf += sizeof(ParticleReal);
n_coords["values/y"].set_external(yp,
num_particles,
0,
struct_size);
#endif
#if AMREX_SPACEDIM > 2
n_coords["values/z"].set_external(const_cast<ParticleReal*>(&p_aos.pos(2)),
const ParticleReal* zp = reinterpret_cast<const ParticleReal*>(pbuf); pbuf += sizeof(ParticleReal);
n_coords["values/z"].set_external(zp,
num_particles,
0,
struct_size);
Expand All @@ -84,58 +89,66 @@ ParticleTileToBlueprint(const ParticleTile<NStructReal,
// fields
conduit::Node &n_fields = res["fields"];

// -----------------------------
// user defined, real aos fields
// -----------------------------

int vname_real_idx = 0;
// struct real fields, the first set are always the particle positions
// which we wrap above
for (int i = 0; i < NStructReal; i++)
{
const ParticleReal* val = reinterpret_cast<const ParticleReal*>(pbuf); pbuf += sizeof(ParticleReal);
conduit::Node &n_f = n_fields[real_comp_names[vname_real_idx]];
n_f["topology"] = topology_name;
n_f["association"] = "element";
n_f["values"].set_external(val,
num_particles,
0,
struct_size);

vname_real_idx++;
}

//----------------------------------//
// standard integer fields from aos
// (id, cpu)
//----------------------------------//

// id is the first int entry
const int* id = reinterpret_cast<const int*>(pbuf); pbuf += sizeof(int);
conduit::Node &n_f_id = n_fields[topology_name + "_id"];

n_f_id["topology"] = topology_name;
n_f_id["association"] = "element";
n_f_id["values"].set_external(const_cast<int*>(&p_aos.id()),
n_f_id["values"].set_external(id,
num_particles,
0,
struct_size);

// cpu is the second int entry
const int* cpu = reinterpret_cast<const int*>(pbuf); pbuf += sizeof(int);
conduit::Node &n_f_cpu = n_fields[topology_name + "_cpu"];

n_f_cpu["topology"] = topology_name;
n_f_cpu["association"] = "element";
n_f_cpu["values"].set_external(const_cast<int*>(&p_aos.cpu()),
num_particles,
0,
struct_size);

// -------------------------
// user defined aos fields
// -------------------------

int vname_real_idx = 0;
// struct real fields, the first set are always the particle positions
// which we wrap above
for (int i = 0; i < NStructReal; i++)
{
conduit::Node &n_f = n_fields[real_comp_names[vname_real_idx]];
n_f["topology"] = topology_name;
n_f["association"] = "element";
n_f["values"].set_external(const_cast<ParticleReal*>(&p_aos.rdata(i)),
n_f_cpu["values"].set_external(cpu,
num_particles,
0,
struct_size);

vname_real_idx++;
}
// --------------------------------
// user defined, integer aos fields
// --------------------------------

int vname_int_idx = 0;
for (int i = 0; i < NStructInt; i++)
{
const int* val = reinterpret_cast<const int*>(pbuf); pbuf += sizeof(int);
conduit::Node &n_f = n_fields[int_comp_names[vname_int_idx]];
n_f["topology"] = topology_name;
n_f["association"] = "element";
n_f["values"].set_external(const_cast<int*>(&p_aos.idata(i)),
n_f["values"].set_external(val,
num_particles,
0,
struct_size);
Expand Down
26 changes: 13 additions & 13 deletions Src/Particle/AMReX_ArrayOfStructs.H
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ public:
using RealType = typename ParticleType::RealType;

using ParticleVector = Gpu::DeviceVector<ParticleType>;

using Iterator = typename ParticleVector::iterator;
using ConstIterator = typename ParticleVector::const_iterator;

static constexpr int SizeInReal = sizeof(ParticleType) / sizeof(RealType);
ArrayOfStructs()

ArrayOfStructs()
: m_num_neighbor_particles(0) {}

const ParticleVector& operator() () const { return m_data; }
Expand Down Expand Up @@ -57,36 +57,36 @@ public:
int numTotalParticles () const { return m_data.size(); }

void setNumNeighbors (int num_neighbors)
{
{
auto nrp = numRealParticles();
m_num_neighbor_particles = num_neighbors;
resize(nrp + num_neighbors);
}

int getNumNeighbors () { return m_num_neighbor_particles; }

bool empty () const { return m_data.empty(); }
const RealType* data () const { return &(m_data[0].pos(0)); }

const RealType* data () const { return &(m_data[0].m_rdata.pos[0]); }
RealType* data () { return &(m_data[0].pos(0)); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might need an adjustment for the non-const case as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The non-const actually works as is, the issue is that the pos method of particle returns a reference in the non-const case, but a value in the const case. So when you try to take the address of a value, you get the rvalue compile errors.

Perhaps that version should return const RealType&, but we might need to be careful about possible performance implications.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, thanks for clarifying -- that helps me better understand the const changes as well.


const RealType* dataPtr () const { return data(); }
RealType* dataPtr () { return data(); }

std::pair<int,int> dataShape () const {
return std::make_pair(SizeInReal, static_cast<int>(m_data.size()));
}

void push_back (const ParticleType& p) { return m_data.push_back(p); }
void pop_back() {m_data.pop_back(); }
bool empty() {return m_data.empty(); }

const ParticleType& back() const {return m_data.back(); }
ParticleType & back() {return m_data.back(); }

const ParticleType& operator[] (int i) const { return m_data[i]; }
ParticleType & operator[] (int i) { return m_data[i]; }

void resize(size_t count) { m_data.resize(count); }

Iterator erase( ConstIterator first, ConstIterator second) { return m_data.erase(first, second); }
Expand All @@ -97,7 +97,7 @@ public:
typename ParticleVector::iterator begin () { return m_data.begin(); }
typename ParticleVector::const_iterator begin () const { return m_data.begin(); }
typename ParticleVector::const_iterator cbegin () const { return m_data.cbegin(); }

typename ParticleVector::iterator end () { return m_data.end(); }
typename ParticleVector::const_iterator end () const { return m_data.end(); }
typename ParticleVector::const_iterator cend () const { return m_data.cend(); }
Expand Down