diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 352a49e92c..0f1c0251f8 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -29,6 +29,7 @@ Since last release * 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) * CI support for Rocky Linux (#1691) +* Added support for a ResBuf to behave as a single bulk storage with mixing & extraction of resources (#1687) **Changed:** diff --git a/src/material.h b/src/material.h index 4a1de69af3..a3316c4e39 100644 --- a/src/material.h +++ b/src/material.h @@ -121,7 +121,7 @@ class Material: public Resource { double threshold = eps_rsrc()); /// Combines material mat with this one. mat's quantity becomes zero. - void Absorb(Ptr mat); + virtual void Absorb(Ptr mat); /// Changes the material's composition to c without changing its mass. Use /// this method for things like converting fresh to spent fuel via burning in @@ -136,7 +136,9 @@ class Material: public Resource { /// not result in an updated material composition. Does nothing if the /// simulation decay mode is set to "never" or none of the nuclides' decay /// constants are significant with respect to the time delta. - void Decay(int curr_time); + /// @param curr_time current time to use for the decay calculation + /// (default: -1 forces the decay to the context's current time) + virtual void Decay(int curr_time = -1); /// Returns the last time step on which a decay calculation was performed /// for the material. This is not necessarily synonymous with the last time diff --git a/src/resource.h b/src/resource.h index 04ff568250..0840fb8b5b 100644 --- a/src/resource.h +++ b/src/resource.h @@ -5,6 +5,8 @@ #include #include +#include "error.h" + class SimInitTest; namespace cyclus { @@ -79,6 +81,16 @@ class Resource { /// @return a new resource object with same state id and quantity == quantity virtual Ptr ExtractRes(double quantity) = 0; + /// To enable the Decay method to be called on any child resource, define + /// a null op Decay method here. + /// @param curr_time the current time for the decay oepration + virtual void Decay(int curr_time) { throw Error("cannot decay resource type " + this->type()); }; + + /// To enable the Absorb method to be called on any child resource, define + /// a null op Absorb method here. + /// @param res pointer to a resource to be absorbed by this resource + virtual void Absorb(Ptr res) { throw Error("cannot absorb resource type " + this->type()); }; + protected: const static int default_package_id_ = 1; private: diff --git a/src/toolkit/res_buf.h b/src/toolkit/res_buf.h index e808d250be..44695aba50 100644 --- a/src/toolkit/res_buf.h +++ b/src/toolkit/res_buf.h @@ -61,7 +61,7 @@ typedef std::vector ProdVec; template class ResBuf { public: - ResBuf() : cap_(INFINITY), qty_(0) { } + ResBuf(bool is_bulk=false) : cap_(INFINITY), qty_(0), is_bulk_(is_bulk) { } virtual ~ResBuf() {} @@ -233,16 +233,16 @@ class ResBuf { return r; } - /// Pushes a single resource object to the buffer. - /// Resource objects are never combined in the buffer; they are stored as - /// unique objects. The resource object is only pushed to the buffer if it - /// does not cause the buffer to exceed its capacity. + /// Pushes a single resource object to the buffer. If not classified as a bulk + /// storage buffer, resource objects are not combined in the buffer; they + /// are stored as unique objects. The resource object is only pushed to the + /// buffer if it does not cause the buffer to exceed its capacity. /// - /// @throws ValueError the pushing of the given resource object would - /// cause the buffer to exceed its capacity. + /// @throws ValueError the pushing of the given resource object would cause + /// the buffer to exceed its capacity. /// - /// @throws KeyError the resource object to be pushed is already present - /// in the buffer. + /// @throws KeyError the resource object to be pushed is already present in + /// the buffer. void Push(Resource::Ptr r) { typename T::Ptr m = boost::dynamic_pointer_cast(r); if (m == NULL) { @@ -255,24 +255,28 @@ class ResBuf { } else if (rs_present_.count(m) == 1) { throw KeyError("duplicate resource push attempted"); } - - rs_.push_back(m); - rs_present_.insert(m); + if (!is_bulk_ || rs_.size() == 0) { + rs_.push_back(m); + rs_present_.insert(m); + } else { + rs_.front()->Absorb(m); + } qty_ += r->quantity(); UpdateQty(); } - /// Pushes one or more resource objects (as a std::vector) to the buffer. - /// Resource objects are never squashed in the buffer; they are stored as - /// unique objects. The resource objects are only pushed to the buffer if - /// they do not cause the buffer to exceed its capacity; otherwise none of the - /// given resource objects are added to the buffer. + /// Pushes one or more resource objects (as a std::vector) to the buffer. If + /// not classified as a bulk storage buffer, resource objects are not + /// squashed in the buffer; they are stored as unique objects. The resource + /// objects are only pushed to the buffer if they do not cause the buffer to + /// exceed its capacity; otherwise none of the given resource objects are + /// added to the buffer. /// - /// @throws ValueError adding the given resource objects would - /// cause the buffer to exceed its capacity. + /// @throws ValueError adding the given resource objects would cause the + /// buffer to exceed its capacity. /// - /// @throws KeyError one or more of the resource objects to be added - /// are already present in the buffer. + /// @throws KeyError one or more of the resource objects to be added are + /// already present in the buffer. template void Push(std::vector rs) { std::vector rss; @@ -300,12 +304,25 @@ class ResBuf { } for (int i = 0; i < rss.size(); i++) { - rs_.push_back(rss[i]); - rs_present_.insert(rss[i]); + if (!is_bulk_ || rs_.size() == 0) { + rs_.push_back(rss[i]); + rs_present_.insert(rss[i]); + } else { + rs_.front()->Absorb(rss[i]); + } } qty_ += tot_qty; } + /// Decays all the materials in a resource buffer + /// @param curr_time time to calculate decay inventory + /// (default: -1 uses the current time of the context) + void Decay(int curr_time = -1) { + for (int i = 0; i < rs_.size(); i++) { + rs_.at(i)->Decay(curr_time); + } + } + private: void UpdateQty() { int n = rs_.size(); @@ -321,6 +338,9 @@ class ResBuf { /// Maximum quantity of resources this buffer can hold double cap_; + /// Whether materials should be stored as a single squashed item or as individual resource objects + bool is_bulk_; + /// List of constituent resource objects forming the buffer's inventory std::list rs_; std::set rs_present_; diff --git a/tests/toolkit/res_buf_tests.cc b/tests/toolkit/res_buf_tests.cc index 7cd7a5fecd..9b6615835b 100644 --- a/tests/toolkit/res_buf_tests.cc +++ b/tests/toolkit/res_buf_tests.cc @@ -1,4 +1,5 @@ #include "res_buf_tests.h" +#include "toolkit/mat_query.h" #include @@ -12,20 +13,20 @@ namespace toolkit { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - Getters, Setters, and Property changers - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(ResBufTest, set_capacity_ExceptionsEmpty) { +TEST_F(ProductBufTest, set_capacity_ExceptionsEmpty) { EXPECT_THROW(store_.capacity(neg_cap), ValueError); EXPECT_NO_THROW(store_.capacity(zero_cap)); EXPECT_NO_THROW(store_.capacity(cap)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(ResBufTest, set_capacity_ExceptionsFilled) { +TEST_F(ProductBufTest, set_capacity_ExceptionsFilled) { EXPECT_THROW(filled_store_.capacity(low_cap), ValueError); EXPECT_NO_THROW(filled_store_.capacity(cap)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(ResBufTest, GetCapacity_ExceptionsEmpty) { +TEST_F(ProductBufTest, GetCapacity_ExceptionsEmpty) { ASSERT_NO_THROW(store_.capacity()); store_.capacity(zero_cap); ASSERT_NO_THROW(store_.capacity()); @@ -34,12 +35,12 @@ TEST_F(ResBufTest, GetCapacity_ExceptionsEmpty) { } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(ResBufTest, GetCapacity_InitialEmpty) { +TEST_F(ProductBufTest, GetCapacity_InitialEmpty) { EXPECT_DOUBLE_EQ(store_.capacity(), INFINITY); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(ResBufTest, Getset_capacityEmpty) { +TEST_F(ProductBufTest, Getset_capacityEmpty) { store_.capacity(zero_cap); EXPECT_DOUBLE_EQ(store_.capacity(), zero_cap); @@ -48,7 +49,7 @@ TEST_F(ResBufTest, Getset_capacityEmpty) { } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(ResBufTest, GetSpace_Empty) { +TEST_F(ProductBufTest, GetSpace_Empty) { ASSERT_NO_THROW(store_.space()); EXPECT_DOUBLE_EQ(store_.space(), INFINITY); @@ -62,33 +63,33 @@ TEST_F(ResBufTest, GetSpace_Empty) { } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(ResBufTest, GetSpace_Filled) { +TEST_F(ProductBufTest, GetSpace_Filled) { double space = cap - (mat1_->quantity() + mat2_->quantity()); ASSERT_NO_THROW(filled_store_.space()); EXPECT_DOUBLE_EQ(filled_store_.space(), space); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(ResBufTest, GetQuantity_Empty) { +TEST_F(ProductBufTest, GetQuantity_Empty) { ASSERT_NO_THROW(store_.quantity()); EXPECT_DOUBLE_EQ(store_.quantity(), 0.0); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(ResBufTest, GetQuantity_Filled) { +TEST_F(ProductBufTest, GetQuantity_Filled) { ASSERT_NO_THROW(filled_store_.quantity()); double quantity = mat1_->quantity() + mat2_->quantity(); EXPECT_DOUBLE_EQ(filled_store_.quantity(), quantity); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(ResBufTest, GetCount_Empty) { +TEST_F(ProductBufTest, GetCount_Empty) { ASSERT_NO_THROW(store_.count()); EXPECT_EQ(store_.count(), 0); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(ResBufTest, GetCount_Filled) { +TEST_F(ProductBufTest, GetCount_Filled) { ASSERT_NO_THROW(filled_store_.count()); EXPECT_DOUBLE_EQ(filled_store_.count(), 2); } @@ -96,21 +97,21 @@ TEST_F(ResBufTest, GetCount_Filled) { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - Removing from buffer - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(ResBufTest, RemoveQty_ExceptionsEmpty) { +TEST_F(ProductBufTest, RemoveQty_ExceptionsEmpty) { Product::Ptr p; double qty = cap + overeps; ASSERT_THROW(p = filled_store_.Pop(qty), ValueError); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(ResBufTest, RemoveQty_ExceptionsFilled) { +TEST_F(ProductBufTest, RemoveQty_ExceptionsFilled) { Product::Ptr p; double qty = cap + overeps; ASSERT_THROW(p = store_.Pop(qty), ValueError); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(ResBufTest, RemoveQty_SingleNoSplit) { +TEST_F(ProductBufTest, RemoveQty_SingleNoSplit) { // pop one no splitting leaving one mat in the store Product::Ptr p; @@ -121,7 +122,7 @@ TEST_F(ResBufTest, RemoveQty_SingleNoSplit) { } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(ResBufTest, RemoveQty_SingleWithSplit) { +TEST_F(ProductBufTest, RemoveQty_SingleWithSplit) { // pop one no splitting leaving one mat in the store Product::Ptr p; @@ -134,7 +135,7 @@ TEST_F(ResBufTest, RemoveQty_SingleWithSplit) { } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(ResBufTest, RemoveQty_DoubleWithSplit) { +TEST_F(ProductBufTest, RemoveQty_DoubleWithSplit) { // pop one no splitting leaving one mat in the store Product::Ptr p; @@ -147,14 +148,14 @@ TEST_F(ResBufTest, RemoveQty_DoubleWithSplit) { } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(ResBufTest, RemoveNum_ExceptionsFilled) { +TEST_F(ProductBufTest, RemoveNum_ExceptionsFilled) { ProdVec manifest; ASSERT_THROW(manifest = filled_store_.PopN(3), ValueError); ASSERT_THROW(manifest = filled_store_.PopN(-1), ValueError); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(ResBufTest, RemoveNum_ZeroFilled) { +TEST_F(ProductBufTest, RemoveNum_ZeroFilled) { ProdVec manifest; double tot_qty = filled_store_.quantity(); @@ -165,7 +166,7 @@ TEST_F(ResBufTest, RemoveNum_ZeroFilled) { } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(ResBufTest, RemoveNum_OneFilled) { +TEST_F(ProductBufTest, RemoveNum_OneFilled) { ProdVec manifest; ASSERT_NO_THROW(manifest = filled_store_.PopN(1)); @@ -177,7 +178,7 @@ TEST_F(ResBufTest, RemoveNum_OneFilled) { } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(ResBufTest, RemoveNum_TwoFilled) { +TEST_F(ProductBufTest, RemoveNum_TwoFilled) { ProdVec manifest; ASSERT_NO_THROW(manifest = filled_store_.PopN(2)); @@ -191,7 +192,7 @@ TEST_F(ResBufTest, RemoveNum_TwoFilled) { } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(ResBufTest, RemoveOne_Filled) { +TEST_F(ProductBufTest, RemoveOne_Filled) { Product::Ptr mat; ASSERT_NO_THROW(mat = filled_store_.Pop()); @@ -210,7 +211,7 @@ TEST_F(ResBufTest, RemoveOne_Filled) { } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(ResBufTest, PopBack) { +TEST_F(ProductBufTest, PopBack) { Product::Ptr mat; ASSERT_NO_THROW(mat = filled_store_.PopBack()); @@ -231,7 +232,7 @@ TEST_F(ResBufTest, PopBack) { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - Pushing into buffer - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(ResBufTest, Push_Empty) { +TEST_F(ProductBufTest, Push_Empty) { ASSERT_NO_THROW(store_.capacity(cap)); ASSERT_NO_THROW(store_.Push(mat1_)); @@ -244,7 +245,7 @@ TEST_F(ResBufTest, Push_Empty) { } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(ResBufTest, Push_OverCapacityEmpty) { +TEST_F(ProductBufTest, Push_OverCapacityEmpty) { ASSERT_NO_THROW(store_.capacity(cap)); ASSERT_NO_THROW(store_.Push(mat1_)); @@ -266,7 +267,7 @@ TEST_F(ResBufTest, Push_OverCapacityEmpty) { } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(ResBufTest, Push_DuplicateEmpty) { +TEST_F(ProductBufTest, Push_DuplicateEmpty) { ASSERT_NO_THROW(store_.capacity(cap)); ASSERT_NO_THROW(store_.Push(mat1_)); @@ -277,7 +278,7 @@ TEST_F(ResBufTest, Push_DuplicateEmpty) { } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(ResBufTest, PushAll_Empty) { +TEST_F(ProductBufTest, PushAll_Empty) { ASSERT_NO_THROW(store_.capacity(cap)); ASSERT_NO_THROW(store_.Push(mats)); ASSERT_EQ(store_.count(), 2); @@ -285,7 +286,7 @@ TEST_F(ResBufTest, PushAll_Empty) { } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(ResBufTest, PushAll_ResCast) { +TEST_F(ProductBufTest, PushAll_ResCast) { ResVec rs; for (int i = 0; i < mats.size(); ++i) { rs.push_back(mats[i]); @@ -297,7 +298,7 @@ TEST_F(ResBufTest, PushAll_ResCast) { } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(ResBufTest, PushAll_NoneEmpty) { +TEST_F(ProductBufTest, PushAll_NoneEmpty) { ProdVec manifest; ASSERT_NO_THROW(store_.capacity(cap)); ASSERT_NO_THROW(store_.Push(manifest)); @@ -306,7 +307,7 @@ TEST_F(ResBufTest, PushAll_NoneEmpty) { } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(ResBufTest, PushAll_RetrieveOrderEmpty) { +TEST_F(ProductBufTest, PushAll_RetrieveOrderEmpty) { Product::Ptr mat; ASSERT_NO_THROW(store_.capacity(cap)); @@ -318,7 +319,7 @@ TEST_F(ResBufTest, PushAll_RetrieveOrderEmpty) { } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(ResBufTest, PushAll_OverCapacityEmpty) { +TEST_F(ProductBufTest, PushAll_OverCapacityEmpty) { ASSERT_NO_THROW(store_.capacity(cap)); ASSERT_NO_THROW(store_.Push(mats)); @@ -343,7 +344,7 @@ TEST_F(ResBufTest, PushAll_OverCapacityEmpty) { } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -TEST_F(ResBufTest, PushAll_DuplicateEmpty) { +TEST_F(ProductBufTest, PushAll_DuplicateEmpty) { ASSERT_NO_THROW(store_.capacity(2 * cap)); ASSERT_NO_THROW(store_.Push(mats)); @@ -355,5 +356,89 @@ TEST_F(ResBufTest, PushAll_DuplicateEmpty) { EXPECT_DOUBLE_EQ(store_.quantity(), mat1_->quantity() + mat2_->quantity()); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// Special tests for material buffers +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +TEST_F(MaterialBufTest, NonBulkTest) { + + ASSERT_EQ(mat_store_.count(), 0); + EXPECT_DOUBLE_EQ(mat_store_.capacity(), cap_); + + mat_store_.Push(mat1a_); + mat_store_.Push(mat2a_); + + ASSERT_EQ(mat_store_.count(), 2); + EXPECT_DOUBLE_EQ(mat_store_.capacity(), cap_); + double qty_exp = mat1a_->quantity() + mat2a_->quantity(); + double space_exp = cap_ - qty_exp; + EXPECT_DOUBLE_EQ(mat_store_.space(), space_exp); + EXPECT_DOUBLE_EQ(mat_store_.quantity(), qty_exp); + + Material::Ptr pop1_ = mat_store_.Pop(); + ASSERT_EQ(pop1_->comp(), test_comp1_); + Material::Ptr pop2_ = mat_store_.Pop(); + ASSERT_EQ(pop2_->comp(), test_comp2_); + +} + +TEST_F(MaterialBufTest, BulkTest) { + + ASSERT_EQ(bulk_store_.count(), 0); + EXPECT_DOUBLE_EQ(bulk_store_.capacity(), cap_); + + bulk_store_.Push(mat1b_); + bulk_store_.Push(mat2b_); + + ASSERT_EQ(bulk_store_.count(), 1); + EXPECT_DOUBLE_EQ(bulk_store_.capacity(), cap_); + double qty_exp = mat1b_->quantity() + mat2b_->quantity(); + double space_exp = cap_ - qty_exp; + EXPECT_DOUBLE_EQ(bulk_store_.space(), space_exp); + EXPECT_DOUBLE_EQ(bulk_store_.quantity(), qty_exp); + + Material::Ptr pop1_ = bulk_store_.Pop(); + cyclus::toolkit::MatQuery mq1(pop1_); + double sr89_qty = mq1.mass(sr89_); + double fe59_qty = mq1.mass(fe59_); + + double sr89_qty_exp = 5.0 * units::g; + double fe59_qty_exp = 5.0 * units::g; + + EXPECT_DOUBLE_EQ(sr89_qty_exp, sr89_qty); + EXPECT_DOUBLE_EQ(fe59_qty_exp, fe59_qty); + + ASSERT_EQ(bulk_store_.count(), 0); + EXPECT_DOUBLE_EQ(bulk_store_.capacity(), cap_); + EXPECT_DOUBLE_EQ(bulk_store_.space(), cap_); + EXPECT_DOUBLE_EQ(bulk_store_.quantity(), 0); + + EXPECT_DOUBLE_EQ(pop1_->quantity(), qty_exp); + + bulk_store_.Push(pop1_); + // need to capture this now because mat3_ is about to disappear + qty_exp += mat3_->quantity(); + space_exp -= mat3_->quantity(); + sr89_qty_exp += mat3_->quantity()/3; + fe59_qty_exp += mat3_->quantity()*2/3; + + bulk_store_.Push(mat3_); + + ASSERT_EQ(bulk_store_.count(), 1); + EXPECT_DOUBLE_EQ(bulk_store_.capacity(), cap_); + EXPECT_DOUBLE_EQ(qty_exp, bulk_store_.quantity()); + EXPECT_DOUBLE_EQ(space_exp, bulk_store_.space()); + + pop1_ = bulk_store_.Pop(); + + sr89_qty = mq1.mass(sr89_); + fe59_qty = mq1.mass(fe59_); + + EXPECT_DOUBLE_EQ(sr89_qty_exp, sr89_qty); + EXPECT_DOUBLE_EQ(fe59_qty_exp, fe59_qty); + +} + + } // namespace toolkit } // namespace cyclus diff --git a/tests/toolkit/res_buf_tests.h b/tests/toolkit/res_buf_tests.h index fa52abf9d9..ef83068111 100644 --- a/tests/toolkit/res_buf_tests.h +++ b/tests/toolkit/res_buf_tests.h @@ -7,13 +7,15 @@ #include "error.h" #include "logger.h" #include "product.h" +#include "composition.h" +#include "material.h" #include "toolkit/res_buf.h" namespace cyclus { namespace toolkit { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -class ResBufTest : public ::testing::Test { +class ProductBufTest : public ::testing::Test { protected: Product::Ptr mat1_, mat2_; double mass1, mass2; @@ -63,6 +65,54 @@ class ResBufTest : public ::testing::Test { } }; +class MaterialBufTest : public ::testing::Test { + protected: + + ResBuf mat_store_; // default constructed mat store + ResBuf bulk_store_ = ResBuf(true); + + Nuc sr89_, fe59_; + Material::Ptr mat1a_, mat1b_, mat2a_, mat2b_, mat3_; + Composition::Ptr test_comp1_, test_comp2_, test_comp3_; + + double cap_; + + virtual void SetUp() { + try { + + sr89_ = 380890000; + fe59_ = 260590000; + + CompMap v, w; + v[sr89_] = 1; + test_comp1_ = Composition::CreateFromMass(v); + + w[fe59_] = 2; + test_comp2_ = Composition::CreateFromMass(w); + + w[sr89_] = 1; + test_comp3_ = Composition::CreateFromMass(w); + + double mat_size = 5 * units::g; + + mat1a_ = Material::CreateUntracked(mat_size, test_comp1_); + mat1b_ = Material::CreateUntracked(mat_size, test_comp1_); + mat2a_ = Material::CreateUntracked(mat_size, test_comp2_); + mat2b_ = Material::CreateUntracked(mat_size, test_comp2_); + mat3_ = Material::CreateUntracked(mat_size, test_comp3_); + + cap_ = 10 * mat_size; + + mat_store_.capacity(cap_); + bulk_store_.capacity(cap_); + + } catch (std::exception err) { + FAIL() << "An exception was thrown in the fixture SetUp."; + } + } +}; + + } // namespace toolkit } // namespace cyclus