From 8475ac89baf019c2d54810825361dcdccc7b6383 Mon Sep 17 00:00:00 2001 From: Ben Prather Date: Fri, 10 Feb 2023 11:19:49 -0700 Subject: [PATCH 01/14] Make StateDescriptor polymorphic as needed for user package subclassing. --- src/interface/state_descriptor.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/interface/state_descriptor.hpp b/src/interface/state_descriptor.hpp index cecb6ba14602..81af5d5aeb26 100644 --- a/src/interface/state_descriptor.hpp +++ b/src/interface/state_descriptor.hpp @@ -129,6 +129,9 @@ class StateDescriptor { // Preferred constructor explicit StateDescriptor(std::string const &label) : label_(label) {} + // Virtual destructor for subclassing + virtual ~StateDescriptor() = default; + static std::shared_ptr CreateResolvedStateDescriptor(Packages_t &packages); From a1b4caebb03ffa1ca6184ea7979b3ec03aafae6c Mon Sep 17 00:00:00 2001 From: Ben Prather Date: Wed, 19 Apr 2023 10:17:31 -0600 Subject: [PATCH 02/14] PEP1: New functions for getting packages/lists by type --- src/interface/packages.hpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/interface/packages.hpp b/src/interface/packages.hpp index 443061d8172e..1c2ce247d34d 100644 --- a/src/interface/packages.hpp +++ b/src/interface/packages.hpp @@ -30,10 +30,43 @@ class Packages_t { return packages_.at(name); } + // Templated version for retrieving a package with a particular type + // Allows subclassing 'StateDescriptor' to add user package types to list + template + T* const &Get(const std::string &name) { + return static_cast(packages_.at(name).get()); + } + const Dictionary> &AllPackages() const { return packages_; } + // Returns a sub-Dictionary containing just pointers to packages of type T. + // Dictionary is a *new copy*, and members are bare pointers, not shared_ptr. + template + const std::vector AllPackagesOfType() const { + Dictionary sub_dict; + for (auto package : packages_) { + if (T *cast_package = dynamic_cast(package.second.get())) { + sub_dict[package.first] = cast_package; + } + } + return sub_dict; + } + + // Returns a list of pointers to packages of type T. + // List contains bare pointers, not shared_ptr objects + template + const std::vector ListPackagesOfType() const { + std::vector sub_list; + for (auto package : packages_) { + if (T *cast_package = dynamic_cast(package.second.get())) { + sub_list.append(cast_package); + } + } + return sub_list; + } + private: Dictionary> packages_; }; From 2d2ccd76e7729abb783391d4833a80ad856f4b52 Mon Sep 17 00:00:00 2001 From: Ben Prather Date: Wed, 10 May 2023 14:02:35 -0500 Subject: [PATCH 03/14] PEP1: Fix type issues --- src/interface/packages.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/interface/packages.hpp b/src/interface/packages.hpp index 1c2ce247d34d..32bbc07eab53 100644 --- a/src/interface/packages.hpp +++ b/src/interface/packages.hpp @@ -44,7 +44,7 @@ class Packages_t { // Returns a sub-Dictionary containing just pointers to packages of type T. // Dictionary is a *new copy*, and members are bare pointers, not shared_ptr. template - const std::vector AllPackagesOfType() const { + const Dictionary AllPackagesOfType() const { Dictionary sub_dict; for (auto package : packages_) { if (T *cast_package = dynamic_cast(package.second.get())) { @@ -61,7 +61,7 @@ class Packages_t { std::vector sub_list; for (auto package : packages_) { if (T *cast_package = dynamic_cast(package.second.get())) { - sub_list.append(cast_package); + sub_list.push_back(cast_package); } } return sub_list; From 89c833329e9f94b3c50e2c99383f0a52de7e199f Mon Sep 17 00:00:00 2001 From: Ben Prather Date: Wed, 10 May 2023 18:55:27 -0500 Subject: [PATCH 04/14] PEP1: Return pointer directly from Get<> as one might expect --- src/interface/packages.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/interface/packages.hpp b/src/interface/packages.hpp index 32bbc07eab53..82b15a8adbef 100644 --- a/src/interface/packages.hpp +++ b/src/interface/packages.hpp @@ -26,14 +26,14 @@ class Packages_t { Packages_t() = default; void Add(const std::shared_ptr &package); - std::shared_ptr const &Get(const std::string &name) { + std::shared_ptr const &Get(const std::string &name) const { return packages_.at(name); } // Templated version for retrieving a package with a particular type // Allows subclassing 'StateDescriptor' to add user package types to list template - T* const &Get(const std::string &name) { + T* Get(const std::string &name) const { return static_cast(packages_.at(name).get()); } From 977e60d1bd55f06e25f11a34b616acfd3b039a40 Mon Sep 17 00:00:00 2001 From: Ben Prather Date: Fri, 10 Feb 2023 11:19:49 -0700 Subject: [PATCH 05/14] Make StateDescriptor polymorphic as needed for user package subclassing. --- src/interface/state_descriptor.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/interface/state_descriptor.hpp b/src/interface/state_descriptor.hpp index ac9a93dcb58a..02f75120930c 100644 --- a/src/interface/state_descriptor.hpp +++ b/src/interface/state_descriptor.hpp @@ -102,6 +102,9 @@ class StateDescriptor { // Preferred constructor explicit StateDescriptor(std::string const &label) : label_(label) {} + // Virtual destructor for subclassing + virtual ~StateDescriptor() = default; + static std::shared_ptr CreateResolvedStateDescriptor(Packages_t &packages); From 63bd1fbf94dd77af81cd3cb0c34732b2f8896ce6 Mon Sep 17 00:00:00 2001 From: Ben Prather Date: Wed, 19 Apr 2023 10:17:31 -0600 Subject: [PATCH 06/14] PEP1: New functions for getting packages/lists by type --- src/interface/packages.hpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/interface/packages.hpp b/src/interface/packages.hpp index 285a815bf9ea..70966617266c 100644 --- a/src/interface/packages.hpp +++ b/src/interface/packages.hpp @@ -30,11 +30,44 @@ class Packages_t { return packages_.at(name); } + // Templated version for retrieving a package with a particular type + // Allows subclassing 'StateDescriptor' to add user package types to list + template + T* const &Get(const std::string &name) { + return static_cast(packages_.at(name).get()); + } + const Dictionary> &AllPackages() const { return packages_; } Dictionary> &AllPackages() { return packages_; } + // Returns a sub-Dictionary containing just pointers to packages of type T. + // Dictionary is a *new copy*, and members are bare pointers, not shared_ptr. + template + const std::vector AllPackagesOfType() const { + Dictionary sub_dict; + for (auto package : packages_) { + if (T *cast_package = dynamic_cast(package.second.get())) { + sub_dict[package.first] = cast_package; + } + } + return sub_dict; + } + + // Returns a list of pointers to packages of type T. + // List contains bare pointers, not shared_ptr objects + template + const std::vector ListPackagesOfType() const { + std::vector sub_list; + for (auto package : packages_) { + if (T *cast_package = dynamic_cast(package.second.get())) { + sub_list.append(cast_package); + } + } + return sub_list; + } + private: Dictionary> packages_; }; From 0e7a3ba879caa3fadbd44df864794a10a64f382e Mon Sep 17 00:00:00 2001 From: Ben Prather Date: Wed, 12 Jul 2023 16:36:39 -0600 Subject: [PATCH 07/14] Style --- src/interface/packages.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/interface/packages.hpp b/src/interface/packages.hpp index cfd5a71c95d4..92336f5617cb 100644 --- a/src/interface/packages.hpp +++ b/src/interface/packages.hpp @@ -16,6 +16,7 @@ #include #include +#include #include "basic_types.hpp" From 77b1e2ab756c9b95098f254785ba9e3116c84d68 Mon Sep 17 00:00:00 2001 From: par-hermes Date: Thu, 13 Jul 2023 00:13:00 +0000 Subject: [PATCH 08/14] cpp-py-formatter --- src/interface/packages.hpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/interface/packages.hpp b/src/interface/packages.hpp index 92336f5617cb..bd311c821ccd 100644 --- a/src/interface/packages.hpp +++ b/src/interface/packages.hpp @@ -33,9 +33,9 @@ class Packages_t { // Templated version for retrieving a package with a particular type // Allows subclassing 'StateDescriptor' to add user package types to list - template - T* const &Get(const std::string &name) const { - return static_cast(packages_.at(name).get()); + template + T *const &Get(const std::string &name) const { + return static_cast(packages_.at(name).get()); } const Dictionary> &AllPackages() const { @@ -46,10 +46,10 @@ class Packages_t { // Returns a sub-Dictionary containing just pointers to packages of type T. // Dictionary is a *new copy*, and members are bare pointers, not shared_ptr. template - const std::vector AllPackagesOfType() const { - Dictionary sub_dict; + const std::vector AllPackagesOfType() const { + Dictionary sub_dict; for (auto package : packages_) { - if (T *cast_package = dynamic_cast(package.second.get())) { + if (T *cast_package = dynamic_cast(package.second.get())) { sub_dict[package.first] = cast_package; } } @@ -59,10 +59,10 @@ class Packages_t { // Returns a list of pointers to packages of type T. // List contains bare pointers, not shared_ptr objects template - const std::vector ListPackagesOfType() const { - std::vector sub_list; + const std::vector ListPackagesOfType() const { + std::vector sub_list; for (auto package : packages_) { - if (T *cast_package = dynamic_cast(package.second.get())) { + if (T *cast_package = dynamic_cast(package.second.get())) { sub_list.append(cast_package); } } @@ -72,10 +72,10 @@ class Packages_t { // Returns a sub-Dictionary containing just pointers to packages of type T. // Dictionary is a *new copy*, and members are bare pointers, not shared_ptr. template - const Dictionary AllPackagesOfType() const { - Dictionary sub_dict; + const Dictionary AllPackagesOfType() const { + Dictionary sub_dict; for (auto package : packages_) { - if (T *cast_package = dynamic_cast(package.second.get())) { + if (T *cast_package = dynamic_cast(package.second.get())) { sub_dict[package.first] = cast_package; } } From 661ae4595981c652b73a3d9b12e6e53c50ab9991 Mon Sep 17 00:00:00 2001 From: Ben Prather Date: Wed, 9 Aug 2023 15:33:41 -0600 Subject: [PATCH 09/14] Fix the rest of merge duplication --- src/interface/packages.hpp | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/interface/packages.hpp b/src/interface/packages.hpp index bd311c821ccd..f1312d433348 100644 --- a/src/interface/packages.hpp +++ b/src/interface/packages.hpp @@ -69,19 +69,6 @@ class Packages_t { return sub_list; } - // Returns a sub-Dictionary containing just pointers to packages of type T. - // Dictionary is a *new copy*, and members are bare pointers, not shared_ptr. - template - const Dictionary AllPackagesOfType() const { - Dictionary sub_dict; - for (auto package : packages_) { - if (T *cast_package = dynamic_cast(package.second.get())) { - sub_dict[package.first] = cast_package; - } - } - return sub_dict; - } - private: Dictionary> packages_; }; From ce9786a6a6c117edba5081f98dd1ec92d2382d2d Mon Sep 17 00:00:00 2001 From: Ben Prather Date: Thu, 10 Aug 2023 15:36:44 -0600 Subject: [PATCH 10/14] Fix two issues for KHARMA that didn't make it to backport branch --- src/interface/packages.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/interface/packages.hpp b/src/interface/packages.hpp index f1312d433348..a5e12be47944 100644 --- a/src/interface/packages.hpp +++ b/src/interface/packages.hpp @@ -34,7 +34,7 @@ class Packages_t { // Templated version for retrieving a package with a particular type // Allows subclassing 'StateDescriptor' to add user package types to list template - T *const &Get(const std::string &name) const { + T *const Get(const std::string &name) const { return static_cast(packages_.at(name).get()); } @@ -46,7 +46,7 @@ class Packages_t { // Returns a sub-Dictionary containing just pointers to packages of type T. // Dictionary is a *new copy*, and members are bare pointers, not shared_ptr. template - const std::vector AllPackagesOfType() const { + const Dictionary AllPackagesOfType() const { Dictionary sub_dict; for (auto package : packages_) { if (T *cast_package = dynamic_cast(package.second.get())) { From eb4cf775e048020ecd7a9b953cd792ea91b9726a Mon Sep 17 00:00:00 2001 From: Ben Prather Date: Thu, 10 Aug 2023 16:47:11 -0600 Subject: [PATCH 11/14] PEP1: changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d841a9231061..6fccd6473415 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Current develop ### Added (new features/APIs/variables/...) +- [[PR 907]](https://github.com/parthenon-hpc-lab/parthenon/pull/907) PEP1: Allow subclassing StateDescriptor - [[PR 900]](https://github.com/parthenon-hpc-lab/parthenon/pull/900) Add Morton numbers and expand functionality of LogicalLocation - [[PR 902]](https://github.com/parthenon-hpc-lab/parthenon/pull/902) Add ability to output NaNs for de-allocated sparse fields - [[PR 887]](https://github.com/parthenon-hpc-lab/parthenon/pull/887) Add ability to dump more types of params and read them from restarts From f5ddad85540585983c93c6edaaf9ee471837bd59 Mon Sep 17 00:00:00 2001 From: Ben Prather Date: Fri, 11 Aug 2023 13:41:40 -0600 Subject: [PATCH 12/14] Remove useless const --- src/interface/packages.hpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/interface/packages.hpp b/src/interface/packages.hpp index a5e12be47944..65f1d18e5561 100644 --- a/src/interface/packages.hpp +++ b/src/interface/packages.hpp @@ -31,10 +31,9 @@ class Packages_t { return packages_.at(name); } - // Templated version for retrieving a package with a particular type - // Allows subclassing 'StateDescriptor' to add user package types to list + // Retrieve a package pointer, cast to a given type T template - T *const Get(const std::string &name) const { + T* Get(const std::string &name) const { return static_cast(packages_.at(name).get()); } From 608721e91b50872ed29df208681038e3e1447eae Mon Sep 17 00:00:00 2001 From: Ben Prather Date: Mon, 14 Aug 2023 10:04:17 -0600 Subject: [PATCH 13/14] pep1: format --- src/interface/packages.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interface/packages.hpp b/src/interface/packages.hpp index 65f1d18e5561..1ef6db59f58f 100644 --- a/src/interface/packages.hpp +++ b/src/interface/packages.hpp @@ -33,7 +33,7 @@ class Packages_t { // Retrieve a package pointer, cast to a given type T template - T* Get(const std::string &name) const { + T *Get(const std::string &name) const { return static_cast(packages_.at(name).get()); } From 5b14ea4f24a49a5f727664be4d599e372b24d64e Mon Sep 17 00:00:00 2001 From: Ben Prather Date: Fri, 29 Sep 2023 09:07:09 -0600 Subject: [PATCH 14/14] PEP1: Make StateDescriptor members protected to allow subclasses access --- src/interface/state_descriptor.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interface/state_descriptor.hpp b/src/interface/state_descriptor.hpp index 06537a87d88a..5bb37ea83b60 100644 --- a/src/interface/state_descriptor.hpp +++ b/src/interface/state_descriptor.hpp @@ -432,7 +432,7 @@ class StateDescriptor { friend std::ostream &operator<<(std::ostream &os, const StateDescriptor &sd); - private: + protected: void InvertControllerMap(); Params params_;