Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up using cyclus:: declarations #610

Merged
merged 2 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Since last release

* Rely on ``python3`` in environment instead of ``python`` (#602)
* Link against ``libxml++`` imported target in CMake instead of ``LIBXMLXX_LIBRARIES`` (#608)
* Cleaned up ``using`` declarations throughout archetypes (#610)

**Fixed:**

Expand Down
65 changes: 27 additions & 38 deletions src/enrichment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#include <boost/lexical_cast.hpp>

using cyclus::Material;

namespace cycamore {

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down Expand Up @@ -44,8 +46,6 @@ std::string Enrichment::str() {

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Enrichment::Build(cyclus::Agent* parent) {
using cyclus::Material;

Facility::Build(parent);
if (initial_feed > 0) {
inventory.Push(Material::Create(this, initial_feed,
Expand Down Expand Up @@ -77,11 +77,9 @@ void Enrichment::Tock() {
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
std::set<cyclus::RequestPortfolio<cyclus::Material>::Ptr>
std::set<cyclus::RequestPortfolio<Material>::Ptr>
Enrichment::GetMatlRequests() {
using cyclus::Material;
using cyclus::RequestPortfolio;
using cyclus::Request;

std::set<RequestPortfolio<Material>::Ptr> ports;
RequestPortfolio<Material>::Ptr port(new RequestPortfolio<Material>());
Expand All @@ -97,10 +95,10 @@ Enrichment::GetMatlRequests() {
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool SortBids(cyclus::Bid<cyclus::Material>* i,
cyclus::Bid<cyclus::Material>* j) {
cyclus::Material::Ptr mat_i = i->offer();
cyclus::Material::Ptr mat_j = j->offer();
bool SortBids(cyclus::Bid<Material>* i,
cyclus::Bid<Material>* j) {
Material::Ptr mat_i = i->offer();
Material::Ptr mat_j = j->offer();

cyclus::toolkit::MatQuery mq_i(mat_i);
cyclus::toolkit::MatQuery mq_j(mat_j);
Expand All @@ -112,16 +110,14 @@ bool SortBids(cyclus::Bid<cyclus::Material>* i,
// Sort offers of input material to have higher preference for more
// U-235 content
void Enrichment::AdjustMatlPrefs(
cyclus::PrefMap<cyclus::Material>::type& prefs) {
cyclus::PrefMap<Material>::type& prefs) {
using cyclus::Bid;
using cyclus::Material;
using cyclus::Request;

if (order_prefs == false) {
return;
}

cyclus::PrefMap<cyclus::Material>::type::iterator reqit;
cyclus::PrefMap<Material>::type::iterator reqit;

// Loop over all requests
for (reqit = prefs.begin(); reqit != prefs.end(); ++reqit) {
Expand All @@ -142,7 +138,7 @@ void Enrichment::AdjustMatlPrefs(

// For any bids with U-235 qty=0, set pref to zero.
if (!u235_mass) {
cyclus::Material::Ptr mat = bids_vector[bidit]->offer();
Material::Ptr mat = bids_vector[bidit]->offer();
cyclus::toolkit::MatQuery mq(mat);
if (mq.mass(922350000) == 0) {
new_pref = -1;
Expand All @@ -157,25 +153,23 @@ void Enrichment::AdjustMatlPrefs(

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Enrichment::AcceptMatlTrades(
const std::vector<std::pair<cyclus::Trade<cyclus::Material>,
cyclus::Material::Ptr> >& responses) {
const std::vector<std::pair<cyclus::Trade<Material>,
Material::Ptr> >& responses) {
// see
// http://stackoverflow.com/questions/5181183/boostshared-ptr-and-inheritance
std::vector<std::pair<cyclus::Trade<cyclus::Material>,
cyclus::Material::Ptr> >::const_iterator it;
std::vector<std::pair<cyclus::Trade<Material>,
Material::Ptr> >::const_iterator it;
for (it = responses.begin(); it != responses.end(); ++it) {
AddMat_(it->second);
}
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
std::set<cyclus::BidPortfolio<cyclus::Material>::Ptr> Enrichment::GetMatlBids(
cyclus::CommodMap<cyclus::Material>::type& out_requests) {
using cyclus::Bid;
std::set<cyclus::BidPortfolio<Material>::Ptr> Enrichment::GetMatlBids(
cyclus::CommodMap<Material>::type& out_requests) {
using cyclus::BidPortfolio;
using cyclus::CapacityConstraint;
using cyclus::Converter;
using cyclus::Material;
using cyclus::Request;
using cyclus::toolkit::MatVec;
using cyclus::toolkit::RecordTimeSeries;
Expand Down Expand Up @@ -246,7 +240,7 @@ std::set<cyclus::BidPortfolio<cyclus::Material>::Ptr> Enrichment::GetMatlBids(
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool Enrichment::ValidReq(const cyclus::Material::Ptr mat) {
bool Enrichment::ValidReq(const Material::Ptr mat) {
cyclus::toolkit::MatQuery q(mat);
double u235 = q.atom_frac(922350000);
double u238 = q.atom_frac(922380000);
Expand All @@ -255,10 +249,9 @@ bool Enrichment::ValidReq(const cyclus::Material::Ptr mat) {

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Enrichment::GetMatlTrades(
const std::vector<cyclus::Trade<cyclus::Material> >& trades,
std::vector<std::pair<cyclus::Trade<cyclus::Material>,
cyclus::Material::Ptr> >& responses) {
using cyclus::Material;
const std::vector<cyclus::Trade<Material> >& trades,
std::vector<std::pair<cyclus::Trade<Material>,
Material::Ptr> >& responses) {
using cyclus::Trade;

intra_timestep_swu_ = 0;
Expand Down Expand Up @@ -299,7 +292,7 @@ void Enrichment::GetMatlTrades(

}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Enrichment::AddMat_(cyclus::Material::Ptr mat) {
void Enrichment::AddMat_(Material::Ptr mat) {
// Elements and isotopes other than U-235, U-238 are sent directly to tails
cyclus::CompMap cm = mat->comp()->atom();
bool extra_u = false;
Expand Down Expand Up @@ -342,26 +335,24 @@ void Enrichment::AddMat_(cyclus::Material::Ptr mat) {
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
cyclus::Material::Ptr Enrichment::Request_() {
Material::Ptr Enrichment::Request_() {
double qty = std::max(0.0, inventory.capacity() - inventory.quantity());
return cyclus::Material::CreateUntracked(qty,
return Material::CreateUntracked(qty,
context()->GetRecipe(feed_recipe));
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
cyclus::Material::Ptr Enrichment::Offer_(cyclus::Material::Ptr mat) {
Material::Ptr Enrichment::Offer_(Material::Ptr mat) {
cyclus::toolkit::MatQuery q(mat);
cyclus::CompMap comp;
comp[922350000] = q.atom_frac(922350000);
comp[922380000] = q.atom_frac(922380000);
return cyclus::Material::CreateUntracked(
return Material::CreateUntracked(
mat->quantity(), cyclus::Composition::CreateFromAtom(comp));
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
cyclus::Material::Ptr Enrichment::Enrich_(cyclus::Material::Ptr mat,
Material::Ptr Enrichment::Enrich_(Material::Ptr mat,
double qty) {
using cyclus::Material;
using cyclus::ResCast;
using cyclus::toolkit::Assays;
using cyclus::toolkit::UraniumAssayMass;
using cyclus::toolkit::SwuRequired;
Expand Down Expand Up @@ -456,13 +447,11 @@ void Enrichment::RecordEnrichment_(double natural_u, double swu) {
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
double Enrichment::FeedAssay() {
using cyclus::Material;

if (inventory.empty()) {
return 0;
}
double pop_qty = inventory.quantity();
cyclus::Material::Ptr fission_matl =
Material::Ptr fission_matl =
inventory.Pop(pop_qty, cyclus::eps_rsrc());
inventory.Push(fission_matl);
return cyclus::toolkit::UraniumAssayMass(fission_matl);
Expand Down
69 changes: 28 additions & 41 deletions src/enrichment_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,36 @@
using cyclus::QueryResult;
using cyclus::Cond;
using cyclus::CompMap;
using cyclus::toolkit::MatQuery;
using pyne::nucname::id;
using cyclus::Material;
using pyne::nucname::id;

namespace cycamore {

Composition::Ptr c_nou235() {
cyclus::CompMap m;
CompMap m;
m[922380000] = 1.0;
return Composition::CreateFromMass(m);
};
Composition::Ptr c_natu1() {
cyclus::CompMap m;
CompMap m;
m[922350000] = 0.007;
m[922380000] = 0.993;
return Composition::CreateFromMass(m);
};
Composition::Ptr c_natu2() {
cyclus::CompMap m;
CompMap m;
m[922350000] = 0.01;
m[922380000] = 0.99;
return Composition::CreateFromMass(m);
};
Composition::Ptr c_leu() {
cyclus::CompMap m;
CompMap m;
m[922350000] = 0.04;
m[922380000] = 0.96;
return Composition::CreateFromMass(m);
};
Composition::Ptr c_heu() {
cyclus::CompMap m;
CompMap m;
m[922350000] = 0.20;
m[922380000] = 0.80;
return Composition::CreateFromMass(m);
Expand Down Expand Up @@ -464,7 +463,7 @@ void EnrichmentTest::InitParameters() {
feed_recipe = "recipe";
feed_assay = 0.0072;

cyclus::CompMap v;
CompMap v;
v[922350000] = feed_assay;
v[922380000] = 1 - feed_assay;
recipe = cyclus::Composition::CreateFromMass(v);
Expand All @@ -491,30 +490,30 @@ void EnrichmentTest::SetUpSource() {
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
cyclus::Material::Ptr EnrichmentTest::GetMat(double qty) {
return cyclus::Material::CreateUntracked(qty,
Material::Ptr EnrichmentTest::GetMat(double qty) {
return Material::CreateUntracked(qty,
tc_.get()->GetRecipe(feed_recipe));
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void EnrichmentTest::DoAddMat(cyclus::Material::Ptr mat) {
void EnrichmentTest::DoAddMat(Material::Ptr mat) {
src_facility->AddMat_(mat);
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
cyclus::Material::Ptr EnrichmentTest::DoRequest() {
Material::Ptr EnrichmentTest::DoRequest() {
return src_facility->Request_();
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
cyclus::Material::Ptr
EnrichmentTest::DoOffer(cyclus::Material::Ptr mat) {
Material::Ptr
EnrichmentTest::DoOffer(Material::Ptr mat) {
return src_facility->Offer_(mat);
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
cyclus::Material::Ptr
EnrichmentTest::DoEnrich(cyclus::Material::Ptr mat, double qty) {
Material::Ptr
EnrichmentTest::DoEnrich(Material::Ptr mat, double qty) {
return src_facility->Enrich_(mat, qty);
}

Expand All @@ -523,7 +522,7 @@ TEST_F(EnrichmentTest, Request) {
// Tests that quantity in material request is accurate
double req = inv_size;
double add = 0;
cyclus::Material::Ptr mat = DoRequest();
Material::Ptr mat = DoRequest();
EXPECT_DOUBLE_EQ(mat->quantity(), req);
EXPECT_EQ(mat->comp(), tc_.get()->GetRecipe(feed_recipe));

Expand All @@ -545,26 +544,24 @@ TEST_F(EnrichmentTest, Request) {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TEST_F(EnrichmentTest, ValidReq) {
// Tests that material requests have U235/(U235+U238) > tails assay
using cyclus::CompMap;
using cyclus::Composition;
using cyclus::Material;

double qty = 4.5; // some magic number

cyclus::CompMap v1;
CompMap v1;
v1[922350000] = 1;
Material::Ptr mat = Material::CreateUntracked
(qty,Composition::CreateFromAtom(v1));
EXPECT_FALSE(src_facility->ValidReq(mat)); // u238 = 0

cyclus::CompMap v2;
CompMap v2;
v2[922350000] = tails_assay;
v2[922380000] = 1 - tails_assay;
mat = Material::CreateUntracked(qty, Composition::CreateFromAtom(v2));
// u235 / (u235 + u238) <= tails_assay
EXPECT_FALSE(src_facility->ValidReq(mat));

cyclus::CompMap v3;
CompMap v3;
v3[922350000] = 1;
v3[922380000] = 1;
mat = Material::CreateUntracked(qty, Composition::CreateFromAtom(v3));
Expand All @@ -575,15 +572,9 @@ TEST_F(EnrichmentTest, ValidReq) {
TEST_F(EnrichmentTest, ConstraintConverters) {
// Tests the SWU and NatU converters to make sure that amount of
// feed and SWU required are correct to fulfill the enrichment request.
using cyclus::CompMap;
using cyclus::Material;
using cyclus::toolkit::MatQuery;
using cyclus::Composition;
using cyclus::toolkit::Assays;
using cyclus::toolkit::UraniumAssayMass;
using cyclus::toolkit::SwuRequired;
using cyclus::toolkit::FeedQty;
using cyclus::toolkit::MatQuery;

cyclus::Env::SetNucDataPath();

double qty = 5; // 5 kg
Expand Down Expand Up @@ -617,8 +608,6 @@ TEST_F(EnrichmentTest, Enrich) {
// of natural uranium required that is exactly its inventory level. that
// inventory will be comprised of two materials to test the manifest/absorb
// strategy employed in Enrich_.
using cyclus::CompMap;
using cyclus::Material;
using cyclus::toolkit::MatQuery;
using cyclus::Composition;
using cyclus::toolkit::Assays;
Expand All @@ -628,12 +617,12 @@ TEST_F(EnrichmentTest, Enrich) {

double qty = 5; // kg
double product_assay = 0.05; // of 5 w/o enriched U
cyclus::CompMap v;
CompMap v;
v[922350000] = product_assay;
v[922380000] = 1 - product_assay;
// target qty need not be = to request qty
Material::Ptr target = cyclus::Material::CreateUntracked(
qty + 10, cyclus::Composition::CreateFromMass(v));
Material::Ptr target = Material::CreateUntracked(
qty + 10, Composition::CreateFromMass(v));

Assays assays(feed_assay, UraniumAssayMass(target), tails_assay);
double swu_req = SwuRequired(qty, assays);
Expand Down Expand Up @@ -670,8 +659,6 @@ TEST_F(EnrichmentTest, Response) {
// note that response quantity and quality need not be tested, because they
// are covered by the Enrich and RequestEnrich tests
using cyclus::Bid;
using cyclus::CompMap;
using cyclus::Material;
using cyclus::Request;
using cyclus::Trade;
using cyclus::toolkit::Assays;
Expand All @@ -680,19 +667,19 @@ TEST_F(EnrichmentTest, Response) {
using cyclus::toolkit::UraniumAssayMass;

// problem set up
std::vector< cyclus::Trade<cyclus::Material> > trades;
std::vector<std::pair<cyclus::Trade<cyclus::Material>,
cyclus::Material::Ptr> > responses;
std::vector< Trade<Material> > trades;
std::vector<std::pair<Trade<Material>,
Material::Ptr> > responses;

double qty = 5; // kg
double trade_qty = qty / 3;
double product_assay = 0.05; // of 5 w/o enriched U

cyclus::CompMap v;
CompMap v;
v[922350000] = product_assay;
v[922380000] = 1 - product_assay;
// target qty need not be = to request qty
Material::Ptr target = cyclus::Material::CreateUntracked(
Material::Ptr target = Material::CreateUntracked(
qty + 10, cyclus::Composition::CreateFromMass(v));

Assays assays(feed_assay, UraniumAssayMass(target), tails_assay);
Expand Down
Loading