Skip to content

Commit

Permalink
one request amount that can be accessed by all methods
Browse files Browse the repository at this point in the history
  • Loading branch information
nuclearkatie committed Nov 22, 2023
1 parent c7a4c08 commit 9d22c00
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 33 deletions.
73 changes: 41 additions & 32 deletions src/sink.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -86,17 +90,21 @@ Sink::GetMatlRequests() {

std::set<RequestPortfolio<Material>::Ptr> ports;
RequestPortfolio<Material>::Ptr port(new RequestPortfolio<Material>());
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<Request<Material>*> mutuals;
for (int i = 0; i < in_commods.size(); i++) {
mutuals.push_back(port->AddRequest(mat, this, in_commods[i], in_commod_prefs[i]));
Expand All @@ -119,16 +127,15 @@ Sink::GetGenRsrcRequests() {
std::set<RequestPortfolio<Product>::Ptr> ports;
RequestPortfolio<Product>::Ptr
port(new RequestPortfolio<Product>());
double amt = RequestAmt();

if (amt > cyclus::eps()) {
CapacityConstraint<Product> cc(amt);
if (requestAmt > cyclus::eps()) {
CapacityConstraint<Product> cc(requestAmt);
port->AddConstraint(cc);

std::vector<std::string>::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);
}

Expand Down Expand Up @@ -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] << ".";
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion src/sink.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ class Sink
const std::vector< std::pair<cyclus::Trade<cyclus::Product>,
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); }
Expand All @@ -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()));
}

Expand All @@ -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", \
Expand Down

0 comments on commit 9d22c00

Please sign in to comment.