Skip to content

Commit

Permalink
Merge pull request #1711 from nuclearkatie/packaging
Browse files Browse the repository at this point in the history
Unpackaged as default Package id
  • Loading branch information
gonuke committed Mar 27, 2024
2 parents cdab2fe + 6cd649b commit 31c9789
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 22 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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, #1699), package id is a member of resources (materials/products) (#1675). Can pop resources as packaged from resource buffer, pushing resource onto a buffer defaults to stripping packaging (#1683)
* Created Package class and optional declaration of packages in input files (#1673, #1699), package id is default unpackaged (#1711) and is a member of resources (materials/products) (#1675). Can pop resources as packaged from resource buffer, pushing resource onto a buffer defaults to stripping packaging (#1683)
* CI support for Rocky Linux (#1691)
* Added support for a ResBuf to behave as a single bulk storage with mixing & extraction of resources (#1687)

Expand Down
8 changes: 4 additions & 4 deletions src/material.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Material::Ptr Material::Create(Agent* creator, double quantity,

Material::Ptr Material::CreateUntracked(double quantity,
Composition::Ptr c) {
Material::Ptr m(new Material(NULL, quantity, c, default_package_id_));
Material::Ptr m(new Material(NULL, quantity, c, Package::unpackaged_id()));
return m;
}

Expand Down Expand Up @@ -88,7 +88,7 @@ Material::Ptr Material::ExtractComp(double qty, Composition::Ptr c,
}

qty_ -= qty;
Material::Ptr other(new Material(ctx_, qty, c, default_package_id_));
Material::Ptr other(new Material(ctx_, qty, c, Package::unpackaged_id()));

// Decay called on the extracted material should have the same dt as for
// this material regardless of composition.
Expand Down Expand Up @@ -146,8 +146,8 @@ void Material::ChangePackageId(int new_package_id) {
// no change needed
return;
}
else if (new_package_id == default_package_id_) {
// default has functionally no restrictions
else if (new_package_id == Package::unpackaged_id()) {
// unpackaged has functionally no restrictions
package_id_ = new_package_id;
return;
}
Expand Down
6 changes: 3 additions & 3 deletions src/material.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 = default_package_id_);
static Ptr Create(Agent* creator, double quantity, Composition::Ptr c, int package_id = Package::unpackaged_id());

/// Creates a new material resource that does not actually exist as part of
/// the simulation and is untracked.
Expand Down Expand Up @@ -159,10 +159,10 @@ class Material: public Resource {

/// 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_);
virtual void ChangePackageId(int new_package_id = Package::unpackaged_id());

protected:
Material(Context* ctx, double quantity, Composition::Ptr c, int package_id = default_package_id_);
Material(Context* ctx, double quantity, Composition::Ptr c, int package_id = Package::unpackaged_id());

private:
Context* ctx_;
Expand Down
7 changes: 4 additions & 3 deletions src/package.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ namespace cyclus {

int Package::next_id_ = 1;

double Package::GetFillMass(Resource::Ptr r) {
template <class T>
double Package::GetFillMass(typename T::Ptr r) {
if (r->quantity() < fill_min_) {
// less than one pkg of material available
return 0;
}

std::vector<Resource::Ptr> rs;
Resource::Ptr r_pkgd;
std::vector<typename T::Ptr> rs;
typename T::Ptr r_pkgd;
double fill_mass;
if (strategy_ == "first") {
fill_mass = fill_max_;
Expand Down
8 changes: 6 additions & 2 deletions src/package.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <vector>
#include <cmath>
#include <boost/shared_ptr.hpp>
#include "resource.h"

namespace cyclus {

Expand All @@ -31,7 +30,8 @@ class Package {
/// quantity = 5, fill_min = 3, fill_max = 4. num_min_fill = floor(5/3) = 1,
/// num_max_fill = ceil(5/4) = 2. num_min_fill < num_max_fill, so fill to
/// the max.
double GetFillMass(Resource::Ptr r);
template <class T>
double GetFillMass(typename T::Ptr r);

/// Repackages a single resource into a package. If some quantity of the
/// resource cannot be packaged using the given packaging strategy and
Expand All @@ -56,6 +56,9 @@ class Package {
// returns package strategy
std::string strategy() const { return strategy_; }

// returns the unpackaged id (1)
static int unpackaged_id() { return unpackaged_id_; }

protected:
Package();
Package(std::string name, double fill_min, double fill_max, std::string strategy);
Expand All @@ -67,6 +70,7 @@ class Package {
double fill_min_;
double fill_max_;
std::string strategy_;
static const int unpackaged_id_ = 1;
};

} // namespace cyclus
Expand Down
4 changes: 2 additions & 2 deletions src/product.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ void Product::ChangePackageId(int new_package_id) {
// no change needed
return;
}
else if (new_package_id == default_package_id_) {
// default has functionally no restrictions
else if (new_package_id == Package::unpackaged_id()) {
// unpackaged has functionally no restrictions
package_id_ = new_package_id;
return;
}
Expand Down
6 changes: 3 additions & 3 deletions src/product.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 = default_package_id_);
static Ptr Create(Agent* creator, double quantity, std::string quality, int package_id = Package::unpackaged_id());

/// Creates a new product that does not actually exist as part of
/// the simulation and is untracked.
Expand Down Expand Up @@ -75,13 +75,13 @@ class Product : public Resource {
virtual int package_id();

/// Changes the product's package id
virtual void ChangePackageId(int new_package_id = default_package_id_);
virtual void ChangePackageId(int new_package_id = Package::unpackaged_id());

private:
/// @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 = default_package_id_);
Product(Context* ctx, double quantity, std::string quality, int package_id = Package::unpackaged_id());

// map<quality, quality_id>
static std::map<std::string, int> qualids_;
Expand Down
7 changes: 3 additions & 4 deletions src/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <boost/shared_ptr.hpp>

#include "error.h"
#include "package.h"

class SimInitTest;

Expand Down Expand Up @@ -92,13 +93,11 @@ class Resource {
virtual void Absorb(Ptr res) { throw Error("cannot absorb resource type " + this->type()); };

/// Returns the package id.
virtual int package_id() { return default_package_id_; };
virtual int package_id() { return Package::unpackaged_id(); };

/// Changes the product's package id
virtual void ChangePackageId(int new_package_id = default_package_id_ ) {};
virtual void ChangePackageId(int new_package_id = Package::unpackaged_id()) {};

protected:
const static int default_package_id_ = 1;
private:
static int nextstate_id_;
static int nextobj_id_;
Expand Down

0 comments on commit 31c9789

Please sign in to comment.