From 31ffb3eee2a4ced1f5a523695f5bd7c932373809 Mon Sep 17 00:00:00 2001 From: "S.Klapproth" Date: Wed, 22 Oct 2025 12:05:02 +0200 Subject: [PATCH 1/4] use kokkos viiew label for ParticleAttrib name --- alpine/ParticleContainer.hpp | 15 ++++++++------- src/Particle/ParticleAttrib.h | 8 +++++--- src/Particle/ParticleAttribBase.h | 7 +------ src/Particle/ParticleBase.hpp | 8 ++++---- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/alpine/ParticleContainer.hpp b/alpine/ParticleContainer.hpp index 673a43d74..39a1d68c7 100644 --- a/alpine/ParticleContainer.hpp +++ b/alpine/ParticleContainer.hpp @@ -10,16 +10,21 @@ template class ParticleContainer : public ippl::ParticleBase> { using Base = ippl::ParticleBase>; +private: + PLayout_t pl_m; public: ippl::ParticleAttrib q; // charge typename Base::particle_position_type P; // particle velocity typename Base::particle_position_type E; // electric field at particle position -private: - PLayout_t pl_m; public: ParticleContainer(Mesh_t& mesh, FieldLayout_t& FL) - : pl_m(FL, mesh) { + : + pl_m(FL, mesh) + , q("charge") + , P("velocity") + , E("electric_field") + { this->initialize(pl_m); registerAttributes(); setupBCs(); @@ -31,10 +36,6 @@ class ParticleContainer : public ippl::ParticleBase>& pl) { pl_m = pl; } void registerAttributes() { - //only needed for vis - P.set_name("velocity"); - q.set_name("charge"); - E.set_name("electric_field"); // register the particle attributes this->addAttribute(q); this->addAttribute(P); diff --git a/src/Particle/ParticleAttrib.h b/src/Particle/ParticleAttrib.h index e694585f8..31d979c4c 100644 --- a/src/Particle/ParticleAttrib.h +++ b/src/Particle/ParticleAttrib.h @@ -46,6 +46,10 @@ namespace ippl { using size_type = detail::size_type; + ParticleAttrib() : dview_m("UNNAMED_ParticleAttrib"){} + + ParticleAttrib(const std::string& name_) : dview_m(name_){} + // Create storage for M particle attributes. The storage is uninitialized. // New items are appended to the end of the array. void create(size_type) override; @@ -100,9 +104,7 @@ namespace ippl { HostMirror getHostMirror() const { return Kokkos::create_mirror(dview_m); } - void set_name(const std::string & name_) override { this->name_m = name_; } - - std::string get_name() const override { return this->name_m; } + const std::string get_name() const override { return dview_m.label(); } /*! * Assign the same value to the whole attribute. diff --git a/src/Particle/ParticleAttribBase.h b/src/Particle/ParticleAttribBase.h index 0b02a9739..c8c877a26 100644 --- a/src/Particle/ParticleAttribBase.h +++ b/src/Particle/ParticleAttribBase.h @@ -36,12 +36,8 @@ namespace ippl { template using with_properties = typename WithMemSpace::type; - - ParticleAttribBase(){this->name_m = "UNNAMED_attribute";} - - virtual void set_name(const std::string & name_) = 0; - virtual std::string get_name() const = 0; + virtual const std::string get_name() const = 0; virtual void create(size_type) = 0; @@ -68,7 +64,6 @@ namespace ippl { protected: const size_type* localNum_mp; - std::string name_m; }; } // namespace detail } // namespace ippl diff --git a/src/Particle/ParticleBase.hpp b/src/Particle/ParticleBase.hpp index 37dadcf5c..c6f6961cc 100644 --- a/src/Particle/ParticleBase.hpp +++ b/src/Particle/ParticleBase.hpp @@ -52,8 +52,10 @@ namespace ippl { template - ParticleBase::ParticleBase() - : layout_m(nullptr) + ParticleBase::ParticleBase() : + R("position") + , ID("ID") + , layout_m(nullptr) , localNum_m(0) , totalNum_m(0) , nextID_m(Comm->rank()) @@ -62,8 +64,6 @@ namespace ippl { addAttribute(ID); } addAttribute(R); - ID.set_name("ID"); - R.set_name("position"); } template From 7abe0695590ba870627a46804454ae41f0a69287 Mon Sep 17 00:00:00 2001 From: "S.Klapproth" Date: Wed, 22 Oct 2025 12:41:35 +0200 Subject: [PATCH 2/4] use Kokkos::View label as name for Field amd BareField --- src/Field/BareField.h | 6 ++++-- src/Field/BareField.hpp | 6 ++++-- src/Field/Field.h | 4 ++-- src/Field/Field.hpp | 8 ++++---- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/Field/BareField.h b/src/Field/BareField.h index 06c80aef5..3904fbaef 100644 --- a/src/Field/BareField.h +++ b/src/Field/BareField.h @@ -64,7 +64,7 @@ namespace ippl { * checks in the rest of the BareField methods to check that the field has * been properly initialized. */ - BareField(); + BareField(const std::string& name_="UNNAMED_BareField"); BareField(const BareField&) = default; @@ -72,7 +72,7 @@ namespace ippl { * @param l of field * @param nghost number of ghost layers */ - BareField(Layout_t& l, int nghost = 1); + BareField(Layout_t& l, int nghost = 1, const std::string& name_="UNNAMED_BareField"); /*! * Creates a new BareField with the same properties and contents @@ -172,6 +172,8 @@ namespace ippl { HostMirror getHostMirror() const { return Kokkos::create_mirror(dview_m); } + const std::string get_name() const{ return dview_m.label(); } + /*! * Generate the range policy for iterating over the field, * excluding ghost layers diff --git a/src/Field/BareField.hpp b/src/Field/BareField.hpp index 9328cd223..64561183d 100644 --- a/src/Field/BareField.hpp +++ b/src/Field/BareField.hpp @@ -86,8 +86,9 @@ namespace ippl { } // namespace detail template - BareField::BareField() + BareField::BareField(const std::string& name_) : nghost_m(1) + , dview_m(name_) , layout_m(nullptr) {} template @@ -98,8 +99,9 @@ namespace ippl { } template - BareField::BareField(Layout_t& l, int nghost) + BareField::BareField(Layout_t& l, int nghost, const std::string& name_) : nghost_m(nghost) + , dview_m(name_) // , owned_m(0) , layout_m(&l) { setup(); diff --git a/src/Field/Field.h b/src/Field/Field.h index eda5713b9..0fcbd3905 100644 --- a/src/Field/Field.h +++ b/src/Field/Field.h @@ -34,7 +34,7 @@ namespace ippl { // 'initialize' function before doing anything else. There are no special // checks in the rest of the Field methods to check that the Field has // been properly initialized. - Field(); + Field(const std::string& name_="UNNAMED_Field"); Field(const Field&) = default; @@ -47,7 +47,7 @@ namespace ippl { virtual ~Field() = default; // Constructors including a Mesh object as argument: - Field(Mesh_t&, Layout_t&, int nghost = 1); + Field(Mesh_t&, Layout_t&, int nghost = 1, const std::string& name_="UNNAMED_Field"); // Initialize the Field, also specifying a mesh void initialize(Mesh_t&, Layout_t&, int nghost = 1); diff --git a/src/Field/Field.hpp b/src/Field/Field.hpp index fbf443572..974f8d709 100644 --- a/src/Field/Field.hpp +++ b/src/Field/Field.hpp @@ -16,8 +16,8 @@ namespace ippl { // checks in the rest of the Field methods to check that the Field has // been properly initialized template - Field::Field() - : BareField_t() + Field::Field(const std::string& name_) + : BareField_t(name_) , mesh_m(nullptr) , bc_m() {} @@ -34,8 +34,8 @@ namespace ippl { ////////////////////////////////////////////////////////////////////////// // Constructors which include a Mesh object as argument template - Field::Field(Mesh_t& m, Layout_t& l, int nghost) - : BareField_t(l, nghost) + Field::Field(Mesh_t& m, Layout_t& l, int nghost, const std::string& name_) + : BareField_t(l, nghost, name_) , mesh_m(&m) { for (unsigned int face = 0; face < 2 * Dim; ++face) { bc_m[face] = From b976c409b823e3077a9382232e907b98ae739fa6 Mon Sep 17 00:00:00 2001 From: "S.Klapproth" Date: Wed, 22 Oct 2025 12:49:12 +0200 Subject: [PATCH 3/4] ParticleAttrib change constructor default function parameter --- src/Particle/ParticleAttrib.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Particle/ParticleAttrib.h b/src/Particle/ParticleAttrib.h index 31d979c4c..cc25ca80d 100644 --- a/src/Particle/ParticleAttrib.h +++ b/src/Particle/ParticleAttrib.h @@ -46,9 +46,7 @@ namespace ippl { using size_type = detail::size_type; - ParticleAttrib() : dview_m("UNNAMED_ParticleAttrib"){} - - ParticleAttrib(const std::string& name_) : dview_m(name_){} + ParticleAttrib(const std::string& name_ = "UNNAMED_ParticleAttrib") : dview_m(name_){} // Create storage for M particle attributes. The storage is uninitialized. // New items are appended to the end of the array. From 7f1e6f0b4b4710ca5bcc4782ddd92db9bae7f901 Mon Sep 17 00:00:00 2001 From: "S.Klapproth" Date: Sat, 22 Nov 2025 14:13:54 +0100 Subject: [PATCH 4/4] BareField: adapt default initialization for named Kokkos Veiws --- CMakeLists.txt | 3 ++- src/Field/BareField.hpp | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 19d583b30..1878f126a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,7 +30,8 @@ include(ProjectSetup) # ------------------------------------------------------------------------------ # Primary IPPL options # ------------------------------------------------------------------------------ -set(IPPL_PLATFORMS "OPENMP;CUDA" CACHE STRING "Platforms to build IPPL for") +# set(IPPL_PLATFORMS "OPENMP;CUDA" CACHE STRING "Platforms to build IPPL for") +set(IPPL_PLATFORMS "SERIAL" CACHE STRING "Platforms to build IPPL for") option(BUILD_SHARED_LIBS "Build IPPL as a shared library" OFF) option(IPPL_ENABLE_UNIT_TESTS "Enable unit tests using GoogleTest" OFF) option(IPPL_ENABLE_FFT "Enable FFT support" OFF) diff --git a/src/Field/BareField.hpp b/src/Field/BareField.hpp index 64561183d..e3d0e93a6 100644 --- a/src/Field/BareField.hpp +++ b/src/Field/BareField.hpp @@ -83,14 +83,25 @@ namespace ippl { namespace detail { template struct isExpression> : std::true_type {}; + + template + view_T make_zero_extent_view(const std::string& name, std::index_sequence) { + // Expands to dview_m(name, 0, 0, ..., 0) with Dim zeros + return view_T(name, ((void)I, 0)...); + } + } // namespace detail template BareField::BareField(const std::string& name_) : nghost_m(1) - , dview_m(name_) + , dview_m([&]{return detail::make_zero_extent_view(name_, std::make_index_sequence{});}()) , layout_m(nullptr) {} + + + + template BareField BareField::deepCopy() const { BareField copy(*layout_m, nghost_m); @@ -101,7 +112,7 @@ namespace ippl { template BareField::BareField(Layout_t& l, int nghost, const std::string& name_) : nghost_m(nghost) - , dview_m(name_) + , dview_m([&]{return detail::make_zero_extent_view(name_, std::make_index_sequence{});}()) // , owned_m(0) , layout_m(&l) { setup();