From 93e6f37092ad33ba90afc039cce33fb8bfce4577 Mon Sep 17 00:00:00 2001 From: Katie Mummah Date: Wed, 21 Feb 2024 14:55:57 -0700 Subject: [PATCH 01/10] package id --- src/material.cc | 27 ++++++++++++++++++++------- src/material.h | 11 +++++++++-- src/product.cc | 16 ++++++++++------ src/product.h | 5 +++-- src/resource.h | 2 ++ 5 files changed, 44 insertions(+), 17 deletions(-) diff --git a/src/material.cc b/src/material.cc index 6f3d8c8097..d3c3369c56 100644 --- a/src/material.cc +++ b/src/material.cc @@ -15,15 +15,17 @@ const ResourceType Material::kType = "Material"; Material::~Material() {} Material::Ptr Material::Create(Agent* creator, double quantity, - Composition::Ptr c) { - Material::Ptr m(new Material(creator->context(), quantity, c)); + Composition::Ptr c, int package_id) { + Material::Ptr m(new Material(creator->context(), quantity, c, package_id)); m->tracker_.Create(creator); return m; } Material::Ptr Material::CreateUntracked(double quantity, Composition::Ptr c) { - Material::Ptr m(new Material(NULL, quantity, c)); + // default package id for untracked + int package_id = 1; + Material::Ptr m(new Material(NULL, quantity, c, package_id)); return m; } @@ -48,6 +50,7 @@ void Material::Record(Context* ctx) const { ctx_->NewDatum("MaterialInfo") ->AddVal("ResourceId", state_id()) ->AddVal("PrevDecayTime", prev_decay_time_) + ->AddVal("PackageId", package_id_) ->Record(); comp_->Record(ctx); @@ -87,8 +90,9 @@ Material::Ptr Material::ExtractComp(double qty, Composition::Ptr c, } qty_ -= qty; - - Material::Ptr other(new Material(ctx_, qty, c)); + // extracted material has default package + int package_id = 1; + Material::Ptr other(new Material(ctx_, qty, c, package_id)); // Decay called on the extracted material should have the same dt as for // this material regardless of composition. @@ -218,12 +222,13 @@ Composition::Ptr Material::comp() { return comp_; } -Material::Material(Context* ctx, double quantity, Composition::Ptr c) +Material::Material(Context* ctx, double quantity, Composition::Ptr c, int package_id) : qty_(quantity), comp_(c), tracker_(ctx, this), ctx_(ctx), - prev_decay_time_(0) { + prev_decay_time_(0), + package_id_(package_id) { if (ctx != NULL) { prev_decay_time_ = ctx->time(); } else { @@ -236,4 +241,12 @@ Material::Ptr NewBlankMaterial(double quantity) { return Material::CreateUntracked(quantity, comp); } +int Material::package_id() { + return package_id_; +} + +void Material::ChangePackageId(int new_package_id) { + package_id_ = new_package_id; +} + } // namespace cyclus diff --git a/src/material.h b/src/material.h index 958cac7498..2daba9518e 100644 --- a/src/material.h +++ b/src/material.h @@ -81,7 +81,7 @@ class Material: public Resource { /// pointer to the agent creating the resource (usually will be the caller's /// "this" pointer). All future output data recorded will be done using the /// creator's context. - static Ptr Create(Agent* creator, double quantity, Composition::Ptr c); + static Ptr Create(Agent* creator, double quantity, Composition::Ptr c, int package_id = 1); /// Creates a new material resource that does not actually exist as part of /// the simulation and is untracked. @@ -153,8 +153,14 @@ class Material: public Resource { /// DEPRECATED - use non-const comp() function. Composition::Ptr comp() const; + /// Returns the package id. + virtual int package_id(); + + /// Change the package id + virtual void ChangePackageId(int new_package_id); + protected: - Material(Context* ctx, double quantity, Composition::Ptr c); + Material(Context* ctx, double quantity, Composition::Ptr c, int package_id); private: Context* ctx_; @@ -162,6 +168,7 @@ class Material: public Resource { Composition::Ptr comp_; int prev_decay_time_; ResTracker tracker_; + int package_id_; }; /// Creates and returns a new material with the specified quantity and a diff --git a/src/product.cc b/src/product.cc index 3ab8da1ae9..c24c257a07 100644 --- a/src/product.cc +++ b/src/product.cc @@ -12,17 +12,18 @@ int Product::next_qualid_ = 1; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Product::Ptr Product::Create(Agent* creator, double quantity, - std::string quality) { + std::string quality, int package_id) { if (qualids_.count(quality) == 0) { qualids_[quality] = next_qualid_++; creator->context()->NewDatum("Products") ->AddVal("QualId", qualids_[quality]) ->AddVal("Quality", quality) + ->AddVal("PackageId", 1) ->Record(); } // the next lines must come after qual id setting - Product::Ptr r(new Product(creator->context(), quantity, quality)); + Product::Ptr r(new Product(creator->context(), quantity, quality, package_id)); r->tracker_.Create(creator); return r; } @@ -30,7 +31,9 @@ Product::Ptr Product::Create(Agent* creator, double quantity, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Product::Ptr Product::CreateUntracked(double quantity, std::string quality) { - Product::Ptr r(new Product(NULL, quantity, quality)); + // default package id for untracked + int package_id = 1; + Product::Ptr r(new Product(NULL, quantity, quality, package_id)); r->tracker_.DontTrack(); return r; } @@ -62,7 +65,7 @@ Product::Ptr Product::Extract(double quantity) { quantity_ -= quantity; - Product::Ptr other(new Product(ctx_, quantity, quality_)); + Product::Ptr other(new Product(ctx_, quantity, quality_, package_id_)); tracker_.Extract(&other->tracker_); return other; } @@ -73,10 +76,11 @@ Resource::Ptr Product::ExtractRes(double qty) { } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Product::Product(Context* ctx, double quantity, std::string quality) +Product::Product(Context* ctx, double quantity, std::string quality, int package_id) : quality_(quality), quantity_(quantity), tracker_(ctx, this), - ctx_(ctx) {} + ctx_(ctx), + package_id_(package_id) {} } // namespace cyclus diff --git a/src/product.h b/src/product.h index 6f0e9ee8c7..681045431d 100644 --- a/src/product.h +++ b/src/product.h @@ -28,7 +28,7 @@ class Product : public Resource { /// pointer to the agent creating the resource (usually will be the caller's /// "this" pointer). All future output data recorded will be done using the /// creator's context. - static Ptr Create(Agent* creator, double quantity, std::string quality); + static Ptr Create(Agent* creator, double quantity, std::string quality, int package_id = 1); /// Creates a new product that does not actually exist as part of /// the simulation and is untracked. @@ -75,7 +75,7 @@ class Product : public Resource { /// @param ctx the simulation context /// @param quantity is a double indicating the quantity /// @param quality the resource quality - Product(Context* ctx, double quantity, std::string quality); + Product(Context* ctx, double quantity, std::string quality, int package_id); // map static std::map qualids_; @@ -85,6 +85,7 @@ class Product : public Resource { std::string quality_; double quantity_; ResTracker tracker_; + int package_id_; }; } // namespace cyclus diff --git a/src/resource.h b/src/resource.h index b13b52431e..5f999cc5fa 100644 --- a/src/resource.h +++ b/src/resource.h @@ -5,6 +5,8 @@ #include #include +#include "package.h" + class SimInitTest; namespace cyclus { From 7e9944cbf25b58f84e72e9ab9d28131de8f014f1 Mon Sep 17 00:00:00 2001 From: Katie Mummah Date: Mon, 26 Feb 2024 10:36:39 -0700 Subject: [PATCH 02/10] Record packageid Co-authored-by: Paul Wilson Signed-off-by: Katie Mummah --- src/product.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/product.cc b/src/product.cc index c24c257a07..f87e1cfd3d 100644 --- a/src/product.cc +++ b/src/product.cc @@ -18,7 +18,7 @@ Product::Ptr Product::Create(Agent* creator, double quantity, creator->context()->NewDatum("Products") ->AddVal("QualId", qualids_[quality]) ->AddVal("Quality", quality) - ->AddVal("PackageId", 1) + ->AddVal("PackageId", package_id) ->Record(); } From ac897e5c44153fb5020a40a00f4e011f3332e66d Mon Sep 17 00:00:00 2001 From: Katie Mummah Date: Mon, 26 Feb 2024 11:17:33 -0700 Subject: [PATCH 03/10] changes from code review --- src/material.cc | 10 ++++------ src/material.h | 2 +- src/product.cc | 5 ++--- src/product.h | 2 +- src/resource.h | 2 -- 5 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/material.cc b/src/material.cc index d3c3369c56..63caadce1e 100644 --- a/src/material.cc +++ b/src/material.cc @@ -12,6 +12,8 @@ namespace cyclus { const ResourceType Material::kType = "Material"; +static int default_package_id_ = 1; + Material::~Material() {} Material::Ptr Material::Create(Agent* creator, double quantity, @@ -23,9 +25,7 @@ Material::Ptr Material::Create(Agent* creator, double quantity, Material::Ptr Material::CreateUntracked(double quantity, Composition::Ptr c) { - // default package id for untracked - int package_id = 1; - Material::Ptr m(new Material(NULL, quantity, c, package_id)); + Material::Ptr m(new Material(NULL, quantity, c, default_package_id_)); return m; } @@ -90,9 +90,7 @@ Material::Ptr Material::ExtractComp(double qty, Composition::Ptr c, } qty_ -= qty; - // extracted material has default package - int package_id = 1; - Material::Ptr other(new Material(ctx_, qty, c, package_id)); + Material::Ptr other(new Material(ctx_, qty, c, default_package_id_)); // Decay called on the extracted material should have the same dt as for // this material regardless of composition. diff --git a/src/material.h b/src/material.h index 2daba9518e..7f77ff2186 100644 --- a/src/material.h +++ b/src/material.h @@ -160,7 +160,7 @@ class Material: public Resource { virtual void ChangePackageId(int new_package_id); protected: - Material(Context* ctx, double quantity, Composition::Ptr c, int package_id); + Material(Context* ctx, double quantity, Composition::Ptr c, int package_id = 1); private: Context* ctx_; diff --git a/src/product.cc b/src/product.cc index f87e1cfd3d..42b54046e9 100644 --- a/src/product.cc +++ b/src/product.cc @@ -9,6 +9,7 @@ const ResourceType Product::kType = "Product"; std::map Product::qualids_; int Product::next_qualid_ = 1; +static int default_package_id_ = 1; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Product::Ptr Product::Create(Agent* creator, double quantity, @@ -31,9 +32,7 @@ Product::Ptr Product::Create(Agent* creator, double quantity, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Product::Ptr Product::CreateUntracked(double quantity, std::string quality) { - // default package id for untracked - int package_id = 1; - Product::Ptr r(new Product(NULL, quantity, quality, package_id)); + Product::Ptr r(new Product(NULL, quantity, quality)); r->tracker_.DontTrack(); return r; } diff --git a/src/product.h b/src/product.h index 681045431d..4ffe72f8a9 100644 --- a/src/product.h +++ b/src/product.h @@ -75,7 +75,7 @@ class Product : public Resource { /// @param ctx the simulation context /// @param quantity is a double indicating the quantity /// @param quality the resource quality - Product(Context* ctx, double quantity, std::string quality, int package_id); + Product(Context* ctx, double quantity, std::string quality, int package_id = 1); // map static std::map qualids_; diff --git a/src/resource.h b/src/resource.h index 5f999cc5fa..b13b52431e 100644 --- a/src/resource.h +++ b/src/resource.h @@ -5,8 +5,6 @@ #include #include -#include "package.h" - class SimInitTest; namespace cyclus { From 592ea7d86d859514f2859ca344c398e34fa995d8 Mon Sep 17 00:00:00 2001 From: Katie Mummah Date: Mon, 26 Feb 2024 12:59:41 -0700 Subject: [PATCH 04/10] Apply suggestions from code review Co-authored-by: Paul Wilson Signed-off-by: Katie Mummah --- src/material.h | 2 +- src/product.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/material.h b/src/material.h index 7f77ff2186..30d8d8b5fd 100644 --- a/src/material.h +++ b/src/material.h @@ -160,7 +160,7 @@ class Material: public Resource { virtual void ChangePackageId(int new_package_id); protected: - Material(Context* ctx, double quantity, Composition::Ptr c, int package_id = 1); + Material(Context* ctx, double quantity, Composition::Ptr c, int package_id = default_package_id_); private: Context* ctx_; diff --git a/src/product.h b/src/product.h index 4ffe72f8a9..256348a51c 100644 --- a/src/product.h +++ b/src/product.h @@ -28,7 +28,7 @@ class Product : public Resource { /// pointer to the agent creating the resource (usually will be the caller's /// "this" pointer). All future output data recorded will be done using the /// creator's context. - static Ptr Create(Agent* creator, double quantity, std::string quality, int package_id = 1); + static Ptr Create(Agent* creator, double quantity, std::string quality, int package_id = default_package_id_); /// Creates a new product that does not actually exist as part of /// the simulation and is untracked. @@ -75,7 +75,7 @@ class Product : public Resource { /// @param ctx the simulation context /// @param quantity is a double indicating the quantity /// @param quality the resource quality - Product(Context* ctx, double quantity, std::string quality, int package_id = 1); + Product(Context* ctx, double quantity, std::string quality, int package_id = default_package_id_); // map static std::map qualids_; From 38ea3d9d7d818b7c93309dd952183ce3f446cbe6 Mon Sep 17 00:00:00 2001 From: Katie Mummah Date: Mon, 26 Feb 2024 13:00:06 -0700 Subject: [PATCH 05/10] Apply suggestions from code review Co-authored-by: Paul Wilson Signed-off-by: Katie Mummah --- src/material.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/material.h b/src/material.h index 30d8d8b5fd..d31b7c7909 100644 --- a/src/material.h +++ b/src/material.h @@ -81,7 +81,7 @@ class Material: public Resource { /// pointer to the agent creating the resource (usually will be the caller's /// "this" pointer). All future output data recorded will be done using the /// creator's context. - static Ptr Create(Agent* creator, double quantity, Composition::Ptr c, int package_id = 1); + static Ptr Create(Agent* creator, double quantity, Composition::Ptr c, int package_id = default_package_id_); /// Creates a new material resource that does not actually exist as part of /// the simulation and is untracked. From fef853f4a9d0a05f680e56ec67b878f3b29e5b75 Mon Sep 17 00:00:00 2001 From: Katie Mummah Date: Mon, 26 Feb 2024 14:16:19 -0700 Subject: [PATCH 06/10] default package id in resource class --- src/material.cc | 2 -- src/product.cc | 1 - src/resource.h | 2 ++ 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/material.cc b/src/material.cc index 63caadce1e..9aacc114d0 100644 --- a/src/material.cc +++ b/src/material.cc @@ -12,8 +12,6 @@ namespace cyclus { const ResourceType Material::kType = "Material"; -static int default_package_id_ = 1; - Material::~Material() {} Material::Ptr Material::Create(Agent* creator, double quantity, diff --git a/src/product.cc b/src/product.cc index 42b54046e9..86f9a23baa 100644 --- a/src/product.cc +++ b/src/product.cc @@ -9,7 +9,6 @@ const ResourceType Product::kType = "Product"; std::map Product::qualids_; int Product::next_qualid_ = 1; -static int default_package_id_ = 1; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Product::Ptr Product::Create(Agent* creator, double quantity, diff --git a/src/resource.h b/src/resource.h index b13b52431e..04ff568250 100644 --- a/src/resource.h +++ b/src/resource.h @@ -79,6 +79,8 @@ class Resource { /// @return a new resource object with same state id and quantity == quantity virtual Ptr ExtractRes(double quantity) = 0; + protected: + const static int default_package_id_ = 1; private: static int nextstate_id_; static int nextobj_id_; From ab2bb1225b627f9cd21181eac8b2cbb7644d5f63 Mon Sep 17 00:00:00 2001 From: Katie Mummah Date: Tue, 27 Feb 2024 13:57:59 -0700 Subject: [PATCH 07/10] changelog --- CHANGELOG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 89d6fbe6a4..dcda2ee7cb 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -27,7 +27,7 @@ Since last release * Adds support for Cython3 (#1636) * Adds TotalInvTracker, which allows an inventory cap to be set for multiple resource buffers, and is now required for material buy policy (#1646) * AddMutalReqs and AddReciepe functions and exclusive bids in python API of DRE (#1584) -* Created Package class and optional declaration of packages in input files (#1673) +* Created Package class and optional declaration of packages in input files (#1673), package id is a member of resources (materials/products) (#1675) **Changed:** From 82cde77f50c90ce66951acbd20c71053e3fb7bb8 Mon Sep 17 00:00:00 2001 From: Katie Mummah Date: Wed, 28 Feb 2024 13:48:45 -0700 Subject: [PATCH 08/10] changing package id checks package type limitations --- src/context.cc | 12 +++++++++++- src/context.h | 4 +++- src/material.cc | 28 ++++++++++++++++++++++++---- src/material.h | 5 +++-- src/package.cc | 6 +----- src/package.h | 11 ++++++++++- src/product.cc | 24 ++++++++++++++++++++++++ src/product.h | 3 +++ 8 files changed, 79 insertions(+), 14 deletions(-) diff --git a/src/context.cc b/src/context.cc index 1bcb0bc4f3..cea27a6e0b 100644 --- a/src/context.cc +++ b/src/context.cc @@ -203,13 +203,23 @@ void Context::AddPackage(std::string name, double fill_min, double fill_max, ->Record(); } -Package::Ptr Context::GetPackage(std::string name) { +Package::Ptr Context::GetPackageByName(std::string name) { if (packages_.count(name) == 0) { throw KeyError("Invalid package name " + name); } return packages_[name]; } +Package::Ptr Context::GetPackageById(int id) { + // iterate through the list of packages to get the one package with the correct id + std::map::iterator it; + for (it = packages_.begin(); it != packages_.end(); ++it) { + if (it->second->id() == id) { + return it->second; + } + } +} + void Context::InitSim(SimInfo si) { NewDatum("Info") ->AddVal("Handle", si.handle) diff --git a/src/context.h b/src/context.h index 5bbad65dea..0b45786dc9 100644 --- a/src/context.h +++ b/src/context.h @@ -256,7 +256,9 @@ class Context { std::string strategy = "first"); // Retrieve a registered package. - Package::Ptr GetPackage(std::string name); + Package::Ptr GetPackageByName(std::string name); + + Package::Ptr GetPackageById(int id); int random(); diff --git a/src/material.cc b/src/material.cc index 9aacc114d0..355ae4918e 100644 --- a/src/material.cc +++ b/src/material.cc @@ -141,6 +141,30 @@ void Material::Transmute(Composition::Ptr c) { } } +void Material::ChangePackageId(int new_package_id) { + if (ctx_ != NULL) { + throw ValueError("Package Id cannot be changed with NULL context"); + } + if (new_package_id == package_id_) { + // no change needed + return; + } + else if (new_package_id == default_package_id_) { + // default has functionally no restrictions + package_id_ = new_package_id; + return; + } + + Package::Ptr p = ctx_->GetPackageById(package_id_); + double min = p->fill_min(); + double max = p->fill_max(); + if (qty_ >= min && qty_ <= max) { + package_id_ = new_package_id; + } else { + throw ValueError("Material quantity is outside of package fill limits."); + } +} + void Material::Decay(int curr_time) { if (ctx_ != NULL && ctx_->sim_info().decay == "never") { return; @@ -241,8 +265,4 @@ int Material::package_id() { return package_id_; } -void Material::ChangePackageId(int new_package_id) { - package_id_ = new_package_id; -} - } // namespace cyclus diff --git a/src/material.h b/src/material.h index d31b7c7909..678604eb40 100644 --- a/src/material.h +++ b/src/material.h @@ -156,8 +156,9 @@ class Material: public Resource { /// Returns the package id. virtual int package_id(); - /// Change the package id - virtual void ChangePackageId(int new_package_id); + /// Changes the package id. Checks that the resource fits the package + /// type minimum and maximum mass criteria. + virtual void ChangePackageId(int new_package_id = default_package_id_); protected: Material(Context* ctx, double quantity, Composition::Ptr c, int package_id = default_package_id_); diff --git a/src/package.cc b/src/package.cc index 8dc79eda42..5e2e394b47 100644 --- a/src/package.cc +++ b/src/package.cc @@ -20,12 +20,8 @@ Package::Ptr Package::Create(std::string name, double fill_min, double fill_max, Ptr p(new Package(name, fill_min, fill_max, strategy)); return p; } - -int Package::id() { - return id_; -} -Package::Package() : id_(next_id_++), fill_min_(0), fill_max_(std::numeric_limits::max()), strategy_("first") {} +Package::Package() : id_(next_id_++), fill_min_(0), fill_max_(std::numeric_limits::max()) {} Package::Package(std::string name, double fill_min, double fill_max, std::string strategy) : name_(name), id_(next_id_++), fill_min_(fill_min), fill_max_(fill_max), strategy_(strategy) {} diff --git a/src/package.h b/src/package.h index 4244c23576..20e6a53862 100644 --- a/src/package.h +++ b/src/package.h @@ -19,7 +19,16 @@ class Package { // create a new package type static Ptr Create(std::string name, double fill_min, double fill_max, std::string strategy); - int id(); + // returns package id + int id() const { return id_; } + // returns package name + std::string name() const { return name_; } + // returns package fill min + double fill_min() const { return fill_min_; } + // returns package fill max + double fill_max() const { return fill_max_; } + // returns package strategy + std::string strategy() const { return strategy_; } protected: Package(); diff --git a/src/product.cc b/src/product.cc index 86f9a23baa..b4f37ca5b5 100644 --- a/src/product.cc +++ b/src/product.cc @@ -73,6 +73,30 @@ Resource::Ptr Product::ExtractRes(double qty) { return boost::static_pointer_cast(Extract(qty)); } +void Product::ChangePackageId(int new_package_id) { + if (ctx_ != NULL) { + throw ValueError("Package Id cannot be changed with NULL context"); + } + if (new_package_id == package_id_) { + // no change needed + return; + } + else if (new_package_id == default_package_id_) { + // default has functionally no restrictions + package_id_ = new_package_id; + return; + } + + Package::Ptr p = ctx_->GetPackageById(package_id_); + double min = p->fill_min(); + double max = p->fill_max(); + if (quantity_ >= min && quantity_ <= max) { + package_id_ = new_package_id; + } else { + throw ValueError("Material quantity is outside of package fill limits."); + } +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Product::Product(Context* ctx, double quantity, std::string quality, int package_id) : quality_(quality), diff --git a/src/product.h b/src/product.h index 256348a51c..e915cb22ef 100644 --- a/src/product.h +++ b/src/product.h @@ -71,6 +71,9 @@ class Product : public Resource { /// @throws ValueError 'other' resource is of different quality void Absorb(Product::Ptr other); + /// Changes the product's package id + void ChangePackageId(int package_id); + private: /// @param ctx the simulation context /// @param quantity is a double indicating the quantity From 32133809f8099d36f96e0e1881ef044e7956d8bc Mon Sep 17 00:00:00 2001 From: Katie Mummah Date: Wed, 28 Feb 2024 14:22:14 -0700 Subject: [PATCH 09/10] Update src/product.h Co-authored-by: Paul Wilson Signed-off-by: Katie Mummah --- src/product.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/product.h b/src/product.h index e915cb22ef..e7c2570023 100644 --- a/src/product.h +++ b/src/product.h @@ -72,7 +72,7 @@ class Product : public Resource { void Absorb(Product::Ptr other); /// Changes the product's package id - void ChangePackageId(int package_id); + void ChangePackageId(int new_package_id); private: /// @param ctx the simulation context From 4937f9373dfe15dceac085af56a69b74713c9ddc Mon Sep 17 00:00:00 2001 From: Katie Mummah Date: Wed, 28 Feb 2024 16:04:17 -0700 Subject: [PATCH 10/10] fix virtuals --- src/material.cc | 2 +- src/material.h | 5 ++--- src/product.cc | 4 ++++ src/product.h | 3 +++ 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/material.cc b/src/material.cc index 355ae4918e..1823835b3d 100644 --- a/src/material.cc +++ b/src/material.cc @@ -154,7 +154,7 @@ void Material::ChangePackageId(int new_package_id) { package_id_ = new_package_id; return; } - + Package::Ptr p = ctx_->GetPackageById(package_id_); double min = p->fill_min(); double max = p->fill_max(); diff --git a/src/material.h b/src/material.h index 678604eb40..4a1de69af3 100644 --- a/src/material.h +++ b/src/material.h @@ -153,12 +153,11 @@ class Material: public Resource { /// DEPRECATED - use non-const comp() function. Composition::Ptr comp() const; - /// Returns the package id. - virtual int package_id(); + int package_id(); /// Changes the package id. Checks that the resource fits the package /// type minimum and maximum mass criteria. - virtual void ChangePackageId(int new_package_id = default_package_id_); + void ChangePackageId(int new_package_id = default_package_id_); protected: Material(Context* ctx, double quantity, Composition::Ptr c, int package_id = default_package_id_); diff --git a/src/product.cc b/src/product.cc index b4f37ca5b5..39fc25fa47 100644 --- a/src/product.cc +++ b/src/product.cc @@ -73,6 +73,10 @@ Resource::Ptr Product::ExtractRes(double qty) { return boost::static_pointer_cast(Extract(qty)); } +int Product::package_id() { + return package_id_; +} + void Product::ChangePackageId(int new_package_id) { if (ctx_ != NULL) { throw ValueError("Package Id cannot be changed with NULL context"); diff --git a/src/product.h b/src/product.h index e7c2570023..0c41dff89d 100644 --- a/src/product.h +++ b/src/product.h @@ -71,6 +71,9 @@ class Product : public Resource { /// @throws ValueError 'other' resource is of different quality void Absorb(Product::Ptr other); + // Returns the package id. + int package_id(); + /// Changes the product's package id void ChangePackageId(int new_package_id);