From 03407b05a39ffbc33399abb236d4dfc3da85ab0f Mon Sep 17 00:00:00 2001 From: atmyers Date: Thu, 11 Jun 2020 17:31:14 -0700 Subject: [PATCH 1/4] fix conduit for changes to particles --- .../Conduit/AMReX_Conduit_Blueprint_ParticlesI.H | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Src/Extern/Conduit/AMReX_Conduit_Blueprint_ParticlesI.H b/Src/Extern/Conduit/AMReX_Conduit_Blueprint_ParticlesI.H index 6dc31c4eb97..1c47f143df0 100644 --- a/Src/Extern/Conduit/AMReX_Conduit_Blueprint_ParticlesI.H +++ b/Src/Extern/Conduit/AMReX_Conduit_Blueprint_ParticlesI.H @@ -36,9 +36,9 @@ ParticleTileToBlueprint(const ParticleTile(&p_aos.pos(0)), + const ParticleReal* xp = pstruct.data(); + n_coords["values/x"].set_external(const_cast(xp), num_particles, 0, struct_size); #if AMREX_SPACEDIM > 1 - n_coords["values/y"].set_external(const_cast(&p_aos.pos(1)), + const ParticleReal* yp = pstruct.data() + 1; + n_coords["values/y"].set_external(const_cast(yp), num_particles, 0, struct_size); #endif #if AMREX_SPACEDIM > 2 - n_coords["values/z"].set_external(const_cast(&p_aos.pos(2)), + const ParticleReal* zp = pstruct.data() + 2; + n_coords["values/z"].set_external(const_cast(zp), num_particles, 0, struct_size); From 57c209072cba1d89c55a5f6c7f7216936dd99410 Mon Sep 17 00:00:00 2001 From: atmyers Date: Mon, 15 Jun 2020 15:27:16 -0700 Subject: [PATCH 2/4] handle id, cpu as well --- .../AMReX_Conduit_Blueprint_ParticlesI.H | 64 +++++++++++-------- 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/Src/Extern/Conduit/AMReX_Conduit_Blueprint_ParticlesI.H b/Src/Extern/Conduit/AMReX_Conduit_Blueprint_ParticlesI.H index 1c47f143df0..57f058157ee 100644 --- a/Src/Extern/Conduit/AMReX_Conduit_Blueprint_ParticlesI.H +++ b/Src/Extern/Conduit/AMReX_Conduit_Blueprint_ParticlesI.H @@ -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 // /////////////////////////////////////////////////////////////////////////////// @@ -38,7 +38,7 @@ ParticleTileToBlueprint(const ParticleTile(pstruct.data()); + + ParticleReal* xp = reinterpret_cast(pbuf); pbuf += sizeof(ParticleReal); n_coords["values/x"].set_external(const_cast(xp), num_particles, 0, struct_size); #if AMREX_SPACEDIM > 1 - const ParticleReal* yp = pstruct.data() + 1; + ParticleReal* yp = reinterpret_cast(pbuf); pbuf += sizeof(ParticleReal); n_coords["values/y"].set_external(const_cast(yp), num_particles, 0, struct_size); #endif #if AMREX_SPACEDIM > 2 - const ParticleReal* zp = pstruct.data() + 2; + ParticleReal* zp = reinterpret_cast(pbuf); pbuf += sizeof(ParticleReal); n_coords["values/z"].set_external(const_cast(zp), num_particles, 0, @@ -87,58 +89,66 @@ ParticleTileToBlueprint(const ParticleTile(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(const_cast(val), + num_particles, + 0, + struct_size); + + vname_real_idx++; + } + //----------------------------------// // standard integer fields from aos // (id, cpu) //----------------------------------// // id is the first int entry + int* id = reinterpret_cast(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(&p_aos.id()), + n_f_id["values"].set_external(const_cast(id), num_particles, 0, struct_size); // cpu is the second int entry + int* cpu = reinterpret_cast(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(&p_aos.cpu()), + n_f_cpu["values"].set_external(const_cast(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(&p_aos.rdata(i)), - 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++) { + int* val = reinterpret_cast(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(&p_aos.idata(i)), + n_f["values"].set_external(const_cast(val), num_particles, 0, struct_size); From 813418af5527573b5e574dafa496a4475920bc50 Mon Sep 17 00:00:00 2001 From: atmyers Date: Mon, 15 Jun 2020 16:58:14 -0700 Subject: [PATCH 3/4] add some const --- .../AMReX_Conduit_Blueprint_ParticlesI.H | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Src/Extern/Conduit/AMReX_Conduit_Blueprint_ParticlesI.H b/Src/Extern/Conduit/AMReX_Conduit_Blueprint_ParticlesI.H index 57f058157ee..57cfaf24935 100644 --- a/Src/Extern/Conduit/AMReX_Conduit_Blueprint_ParticlesI.H +++ b/Src/Extern/Conduit/AMReX_Conduit_Blueprint_ParticlesI.H @@ -64,23 +64,23 @@ ParticleTileToBlueprint(const ParticleTile(pstruct.data()); + const char* pbuf = reinterpret_cast(pstruct.data()); - ParticleReal* xp = reinterpret_cast(pbuf); pbuf += sizeof(ParticleReal); - n_coords["values/x"].set_external(const_cast(xp), + const ParticleReal* xp = reinterpret_cast(pbuf); pbuf += sizeof(ParticleReal); + n_coords["values/x"].set_external(xp, num_particles, 0, struct_size); #if AMREX_SPACEDIM > 1 - ParticleReal* yp = reinterpret_cast(pbuf); pbuf += sizeof(ParticleReal); - n_coords["values/y"].set_external(const_cast(yp), + const ParticleReal* yp = reinterpret_cast(pbuf); pbuf += sizeof(ParticleReal); + n_coords["values/y"].set_external(yp, num_particles, 0, struct_size); #endif #if AMREX_SPACEDIM > 2 - ParticleReal* zp = reinterpret_cast(pbuf); pbuf += sizeof(ParticleReal); - n_coords["values/z"].set_external(const_cast(zp), + const ParticleReal* zp = reinterpret_cast(pbuf); pbuf += sizeof(ParticleReal); + n_coords["values/z"].set_external(zp, num_particles, 0, struct_size); @@ -98,11 +98,11 @@ ParticleTileToBlueprint(const ParticleTile(pbuf); pbuf += sizeof(ParticleReal); + const ParticleReal* val = reinterpret_cast(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(const_cast(val), + n_f["values"].set_external(val, num_particles, 0, struct_size); @@ -116,23 +116,23 @@ ParticleTileToBlueprint(const ParticleTile(pbuf); pbuf += sizeof(int); + const int* id = reinterpret_cast(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(id), + n_f_id["values"].set_external(id, num_particles, 0, struct_size); // cpu is the second int entry - int* cpu = reinterpret_cast(pbuf); pbuf += sizeof(int); + const int* cpu = reinterpret_cast(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(cpu), + n_f_cpu["values"].set_external(cpu, num_particles, 0, struct_size); @@ -144,11 +144,11 @@ ParticleTileToBlueprint(const ParticleTile(pbuf); pbuf += sizeof(int); + const int* val = reinterpret_cast(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(val), + n_f["values"].set_external(val, num_particles, 0, struct_size); From f29937b6317fbcc9e0f9e928011be8493c85c224 Mon Sep 17 00:00:00 2001 From: atmyers Date: Mon, 15 Jun 2020 17:00:52 -0700 Subject: [PATCH 4/4] fix the const of data() and dataPtr() --- Src/Particle/AMReX_ArrayOfStructs.H | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Src/Particle/AMReX_ArrayOfStructs.H b/Src/Particle/AMReX_ArrayOfStructs.H index 5fe5a81be36..6ffd81c37f0 100644 --- a/Src/Particle/AMReX_ArrayOfStructs.H +++ b/Src/Particle/AMReX_ArrayOfStructs.H @@ -14,13 +14,13 @@ public: using RealType = typename ParticleType::RealType; using ParticleVector = Gpu::DeviceVector; - + 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; } @@ -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)); } const RealType* dataPtr () const { return data(); } RealType* dataPtr () { return data(); } - + std::pair dataShape () const { return std::make_pair(SizeInReal, static_cast(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); } @@ -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(); }