From 9d22c00cd9b0fe323fc85c69d6c909add0b47435 Mon Sep 17 00:00:00 2001 From: Katie Mummah Date: Wed, 22 Nov 2023 12:50:51 -0700 Subject: [PATCH] one request amount that can be accessed by all methods --- src/sink.cc | 73 ++++++++++++++++++++++++++++++----------------------- src/sink.h | 6 ++++- 2 files changed, 46 insertions(+), 33 deletions(-) diff --git a/src/sink.cc b/src/sink.cc index 710162cfb..150bd38b7 100644 --- a/src/sink.cc +++ b/src/sink.cc @@ -53,6 +53,10 @@ void Sink::EnterNotify() { << " values, expected " << in_commods.size(); throw cyclus::ValueError(ss.str()); } + /// Create first requestAmt. Only used in testing, as a simulation will + /// overwrite this on Tick() + SetRequestAmt(); + RecordPosition(); } @@ -86,17 +90,21 @@ Sink::GetMatlRequests() { std::set::Ptr> ports; RequestPortfolio::Ptr port(new RequestPortfolio()); - double amt = RequestAmt(); Material::Ptr mat; + /// for testing + if (requestAmt > SpaceAvailable()) { + SetRequestAmt(); + } + if (recipe_name.empty()) { - mat = cyclus::NewBlankMaterial(amt); + mat = cyclus::NewBlankMaterial(requestAmt); } else { Composition::Ptr rec = this->context()->GetRecipe(recipe_name); - mat = cyclus::Material::CreateUntracked(amt, rec); + mat = cyclus::Material::CreateUntracked(requestAmt, rec); } - if (amt > cyclus::eps()) { + if (requestAmt > cyclus::eps()) { std::vector*> mutuals; for (int i = 0; i < in_commods.size(); i++) { mutuals.push_back(port->AddRequest(mat, this, in_commods[i], in_commod_prefs[i])); @@ -119,16 +127,15 @@ Sink::GetGenRsrcRequests() { std::set::Ptr> ports; RequestPortfolio::Ptr port(new RequestPortfolio()); - double amt = RequestAmt(); - if (amt > cyclus::eps()) { - CapacityConstraint cc(amt); + if (requestAmt > cyclus::eps()) { + CapacityConstraint cc(requestAmt); port->AddConstraint(cc); std::vector::const_iterator it; for (it = in_commods.begin(); it != in_commods.end(); ++it) { std::string quality = ""; // not clear what this should be.. - Product::Ptr rsrc = Product::CreateUntracked(amt, quality); + Product::Ptr rsrc = Product::CreateUntracked(requestAmt, quality); port->AddRequest(rsrc, this, *it); } @@ -165,33 +172,12 @@ void Sink::Tick() { using std::vector; LOG(cyclus::LEV_INFO3, "SnkFac") << prototype() << " is ticking {"; - double amt = RequestAmt(); - double requestAmt = 0; + SetRequestAmt(); - LOG(cyclus::LEV_INFO3, "SnkFac") << prototype() << " has default request amount " << amt; + LOG(cyclus::LEV_INFO3, "SnkFac") << prototype() << " has default request amount " << requestAmt; // inform the simulation about what the sink facility will be requesting - if (amt > cyclus::eps()) { - if (random_size == "None") { - requestAmt = amt; - } - else if (random_size == "UniformInt") { - requestAmt = context()->random_uniform_int(0, amt); - } - else if (random_size == "UniformReal") { - requestAmt = context()->random_uniform_real(0, amt); - } - else if (random_size == "NormalReal") { - requestAmt = context()->random_normal_real(amt * random_size_mean, - amt * random_size_stddev, 0, amt); - } - else if (random_size == "NormalInt") { - requestAmt = context()->random_normal_int(amt * random_size_mean, - amt * random_size_stddev, 0, amt); - } - else { - requestAmt = amt; - } + if (requestAmt > cyclus::eps()) { LOG(cyclus::LEV_INFO4, "SnkFac") << prototype() << " has request amount " << requestAmt << " kg of " << in_commods[0] << "."; @@ -233,6 +219,29 @@ void Sink::RecordPosition() { ->Record(); } +void Sink::SetRequestAmt() { + double amt = SpaceAvailable(); + if (amt < cyclus::eps()) { + requestAmt = 0; + } + + if (random_size == "None") { + requestAmt = amt; + } + else if (random_size == "UniformReal") { + requestAmt = context()->random_uniform_real(0, amt); + } + else if (random_size == "NormalReal") { + requestAmt = context()->random_normal_real(amt * random_size_mean, + amt * random_size_stddev, 0, + amt); + } + else { + requestAmt = amt; + } + return; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - extern "C" cyclus::Agent* ConstructSink(cyclus::Context* ctx) { return new Sink(ctx); diff --git a/src/sink.h b/src/sink.h index 852497e43..a69e1eb68 100644 --- a/src/sink.h +++ b/src/sink.h @@ -69,6 +69,9 @@ class Sink const std::vector< std::pair, cyclus::Product::Ptr> >& responses); + /// @brief SinkFacilities update request amount using random behavior + virtual void SetRequestAmt(); + /// add a commodity to the set of input commodities /// @param name the commodity name inline void AddCommodity(std::string name) { in_commods.push_back(name); } @@ -87,7 +90,7 @@ class Sink inline double InventorySize() const { return inventory.quantity(); } /// determines the amount to request - inline double RequestAmt() const { + inline double SpaceAvailable() const { return std::min(capacity, std::max(0.0, inventory.space())); } @@ -107,6 +110,7 @@ class Sink input_commodity_preferences() const { return in_commod_prefs; } private: + double requestAmt; /// all facilities must have at least one input commodity #pragma cyclus var {"tooltip": "input commodities", \ "doc": "commodities that the sink facility accepts", \