Skip to content

Commit

Permalink
Merge pull request #606 from bennibbelink/cyclus_large
Browse files Browse the repository at this point in the history
  • Loading branch information
gonuke authored Jul 28, 2024
2 parents c883f9a + aa67f87 commit aea4bb5
Show file tree
Hide file tree
Showing 16 changed files with 103 additions and 89 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,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)
* Update archetype definitions to use cyclus constants instead of arbitrary hardcoded values (#606)

**Fixed:**

Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ FROM cycamore as cycamore-test
RUN cycamore_unit_tests

FROM cycamore-test as cycamore-pytest
RUN cd tests && python3 -m pytest
RUN cd tests && python3 -m pytest
10 changes: 6 additions & 4 deletions src/enrichment.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "cyclus.h"
#include "cycamore_version.h"

#pragma cyclus exec from cyclus.system import CY_LARGE_DOUBLE, CY_LARGE_INT, CY_NEAR_ZERO

namespace cycamore {

/// @class SWUConverter
Expand Down Expand Up @@ -324,10 +326,10 @@ class Enrichment
double initial_feed;

#pragma cyclus var { \
"default": 1e299, "tooltip": "max inventory of feed material (kg)", \
"default": CY_LARGE_DOUBLE, "tooltip": "max inventory of feed material (kg)", \
"uilabel": "Maximum Feed Inventory", \
"uitype": "range", \
"range": [0.0, 1e299], \
"range": [0.0, CY_LARGE_DOUBLE], \
"doc": "maximum total inventory of natural uranium in " \
"the enrichment facility (kg)" \
}
Expand Down Expand Up @@ -362,11 +364,11 @@ class Enrichment
bool order_prefs;

#pragma cyclus var { \
"default": 1e299, \
"default": CY_LARGE_DOUBLE, \
"tooltip": "SWU capacity (kgSWU/timestep)", \
"uilabel": "SWU Capacity", \
"uitype": "range", \
"range": [0.0, 1e299], \
"range": [0.0, CY_LARGE_DOUBLE], \
"doc": "separative work unit (SWU) capacity of enrichment " \
"facility (kgSWU/timestep) " \
}
Expand Down
2 changes: 1 addition & 1 deletion src/enrichment_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ TEST_F(EnrichmentTest, RequestQty) {
// Should be only one transaction into the EF,
// and it should be exactly 1kg of natu
EXPECT_EQ(1.0, qr.rows.size());
EXPECT_NEAR(1.0, m->quantity(), 1e-10) <<
EXPECT_NEAR(1.0, m->quantity(), cyclus::CY_NEAR_ZERO) <<
"matched trade provides the wrong quantity of material";
}

Expand Down
12 changes: 6 additions & 6 deletions src/fuel_fab.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class FissConverter : public cyclus::Converter<Material> {
return AtomToMassFrac(frac, c_fiss_, c_topup_) * m->quantity();
} else {
// don't bid at all
return 1e200;
return cyclus::CY_LARGE_DOUBLE;
}
}

Expand Down Expand Up @@ -77,7 +77,7 @@ class FillConverter : public cyclus::Converter<Material> {
return 0;
} else {
// don't bid at all
return 1e200;
return cyclus::CY_LARGE_DOUBLE;
}
}

Expand Down Expand Up @@ -116,7 +116,7 @@ class TopupConverter : public cyclus::Converter<Material> {
return AtomToMassFrac(frac, c_topup_, c_fiss_) * m->quantity();
} else {
// don't bid at all
return 1e200;
return cyclus::CY_LARGE_DOUBLE;
}
}

Expand Down Expand Up @@ -375,11 +375,11 @@ std::set<cyclus::BidPortfolio<Material>::Ptr> FuelFab::GetMatlBids(
new TopupConverter(c_fill, c_fiss, c_topup, spectrum));
// important! - the std::max calls prevent CapacityConstraint throwing a zero
// cap exception
cyclus::CapacityConstraint<Material> fissc(std::max(fiss.quantity(), 1e-10),
cyclus::CapacityConstraint<Material> fissc(std::max(fiss.quantity(), cyclus::CY_NEAR_ZERO),
fissconv);
cyclus::CapacityConstraint<Material> fillc(std::max(fill.quantity(), 1e-10),
cyclus::CapacityConstraint<Material> fillc(std::max(fill.quantity(), cyclus::CY_NEAR_ZERO),
fillconv);
cyclus::CapacityConstraint<Material> topupc(std::max(topup.quantity(), 1e-10),
cyclus::CapacityConstraint<Material> topupc(std::max(topup.quantity(), cyclus::CY_NEAR_ZERO),
topupconv);
port->AddConstraint(fillc);
port->AddConstraint(fissc);
Expand Down
10 changes: 6 additions & 4 deletions src/fuel_fab.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "cyclus.h"
#include "cycamore_version.h"

#pragma cyclus exec from cyclus.system import CY_LARGE_DOUBLE, CY_LARGE_INT, CY_NEAR_ZERO

namespace cycamore {

/// FuelFab takes in 2 streams of material and mixes them in ratios in order to
Expand Down Expand Up @@ -234,9 +236,9 @@ class FuelFab
"doc": "Maximum number of kg of fuel material that can be supplied per time step.", \
"uilabel": "Maximum Throughput", \
"units": "kg", \
"default": 1e299, \
"default": CY_LARGE_DOUBLE, \
"uitype": "range", \
"range": [0.0, 1e299], \
"range": [0.0, CY_LARGE_DOUBLE], \
}
double throughput;

Expand Down Expand Up @@ -277,8 +279,8 @@ class FuelFab

double CosiWeight(cyclus::Composition::Ptr c, const std::string& spectrum);
bool ValidWeights(double w_low, double w_tgt, double w_high);
double LowFrac(double w_low, double w_tgt, double w_high, double eps = 1e-6);
double HighFrac(double w_low, double w_tgt, double w_high, double eps = 1e-6);
double LowFrac(double w_low, double w_tgt, double w_high, double eps = cyclus::CY_NEAR_ZERO);
double HighFrac(double w_low, double w_tgt, double w_high, double eps = cyclus::CY_NEAR_ZERO);
double AtomToMassFrac(double atomfrac, cyclus::Composition::Ptr c1, cyclus::Composition::Ptr c2);

} // namespace cycamore
Expand Down
18 changes: 8 additions & 10 deletions src/fuel_fab_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -531,12 +531,12 @@ TEST(FuelFabTests, CorrectMixing) {
conds[0] = Cond("Commodity", "==", std::string("natu"));
qr = sim.db().Query("Transactions", &conds);
m = sim.GetMaterial(qr.GetVal<int>("ResourceId"));
EXPECT_NEAR(9.7463873197, m->quantity(), 1e-6) << "mixed wrong amount of Nat. U stream";
EXPECT_NEAR(9.7463873197, m->quantity(), cyclus::CY_NEAR_ZERO) << "mixed wrong amount of Nat. U stream";

conds[0] = Cond("Commodity", "==", std::string("pustream"));
qr = sim.db().Query("Transactions", &conds);
m = sim.GetMaterial(qr.GetVal<int>("ResourceId"));
EXPECT_NEAR(0.25361268029, m->quantity(), 1e-6) << "mixed wrong amount of Pu stream";
EXPECT_NEAR(0.25361268029, m->quantity(), cyclus::CY_NEAR_ZERO) << "mixed wrong amount of Pu stream";
}

// fuel is requested requiring more filler than is available with plenty of
Expand Down Expand Up @@ -582,7 +582,7 @@ TEST(FuelFabTests, FillConstrained) {
QueryResult qr = sim.db().Query("Transactions", &conds);
Material::Ptr m = sim.GetMaterial(qr.GetVal<int>("ResourceId"));

EXPECT_NEAR(max_provide, m->quantity(), 1e-10) << "matched trade uses more fill than available";
EXPECT_NEAR(max_provide, m->quantity(), cyclus::CY_NEAR_ZERO) << "matched trade uses more fill than available";
}

// fuel is requested requiring more fissile material than is available with
Expand Down Expand Up @@ -628,7 +628,7 @@ TEST(FuelFabTests, FissConstrained) {
QueryResult qr = sim.db().Query("Transactions", &conds);
Material::Ptr m = sim.GetMaterial(qr.GetVal<int>("ResourceId"));

EXPECT_NEAR(max_provide, m->quantity(), 1e-10) << "matched trade uses more fill than available";
EXPECT_NEAR(max_provide, m->quantity(), cyclus::CY_NEAR_ZERO) << "matched trade uses more fill than available";
}

// swap to topup inventory because fissile has too low reactivity.
Expand Down Expand Up @@ -669,7 +669,7 @@ TEST(FuelFabTests, SwapTopup) {
QueryResult qr = sim.db().Query("Transactions", &conds);
ASSERT_EQ(1, qr.rows.size()) << "failed to meet fuel request";
Material::Ptr m = sim.GetMaterial(qr.GetVal<int>("ResourceId"));
EXPECT_NEAR(sink_cap, m->quantity(), 1e-10) << "supplied fuel was constrained too much";
EXPECT_NEAR(sink_cap, m->quantity(), cyclus::CY_NEAR_ZERO) << "supplied fuel was constrained too much";

conds[0] = Cond("Commodity", "==", std::string("natu"));
conds.push_back(Cond("Time", "==", 2));
Expand Down Expand Up @@ -719,7 +719,7 @@ TEST(FuelFabTests, SwapTopup_ZeroFill) {
QueryResult qr = sim.db().Query("Transactions", &conds);
ASSERT_EQ(1, qr.rows.size()) << "failed to meet fuel request";
Material::Ptr m = sim.GetMaterial(qr.GetVal<int>("ResourceId"));
EXPECT_NEAR(sink_cap, m->quantity(), 1e-10) << "supplied fuel was constrained too much";
EXPECT_NEAR(sink_cap, m->quantity(), cyclus::CY_NEAR_ZERO) << "supplied fuel was constrained too much";

conds[0] = Cond("Commodity", "==", std::string("pustream"));
conds.push_back(Cond("Time", "==", 2));
Expand Down Expand Up @@ -786,7 +786,7 @@ TEST(FuelFabTests, SwapTopup_TopupConstrained) {
ASSERT_EQ(1, qr.rows.size()) << "failed to meet fuel request";
Material::Ptr m = sim.GetMaterial(qr.GetVal<int>("ResourceId"));

EXPECT_NEAR(max_provide, m->quantity(), 1e-10) << "matched trade uses more fiss than available";
EXPECT_NEAR(max_provide, m->quantity(), cyclus::CY_NEAR_ZERO) << "matched trade uses more fiss than available";
}

// swap to topup inventory but are limited by fiss inventory quantity. This
Expand Down Expand Up @@ -841,7 +841,7 @@ TEST(FuelFabTests, SwapTopup_FissConstrained) {
ASSERT_EQ(1, qr.rows.size()) << "failed to meet fuel request";
Material::Ptr m = sim.GetMaterial(qr.GetVal<int>("ResourceId"));

EXPECT_NEAR(max_provide, m->quantity(), 1e-10) << "matched trade uses more fiss than available";
EXPECT_NEAR(max_provide, m->quantity(), cyclus::CY_NEAR_ZERO) << "matched trade uses more fiss than available";
}

// Before this test and a fix, the fuel fab (partially) assumed each entire material
Expand Down Expand Up @@ -987,5 +987,3 @@ TEST(FuelFabTests, PositionInitialize2) {

} // namespace fuelfabtests
} // namespace cycamore


10 changes: 6 additions & 4 deletions src/mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "cycamore_version.h"
#include "cyclus.h"

#pragma cyclus exec from cyclus.system import CY_LARGE_DOUBLE, CY_LARGE_INT, CY_NEAR_ZERO

namespace cycamore {

/// Mixer mixes N streams with fixed, static, user-specified
Expand Down Expand Up @@ -85,9 +87,9 @@ class Mixer
" If full, the facility halts operation until space becomes" \
" available.", \
"uilabel": "Maximum Leftover Inventory", \
"default": 1e299, \
"default": CY_LARGE_DOUBLE, \
"uitype": "range", \
"range": [0.0, 1e299], \
"range": [0.0, CY_LARGE_DOUBLE], \
"units": "kg", \
}
double out_buf_size;
Expand All @@ -96,11 +98,11 @@ class Mixer
cyclus::toolkit::ResBuf<cyclus::Material> output;

#pragma cyclus var { \
"default": 1e299, \
"default": CY_LARGE_DOUBLE, \
"doc": "Maximum number of kg of fuel material that can be mixed per time step.", \
"uilabel": "Maximum Throughput", \
"uitype": "range", \
"range": [0.0, 1e299], \
"range": [0.0, CY_LARGE_DOUBLE], \
"units": "kg", \
}
double throughput;
Expand Down
8 changes: 4 additions & 4 deletions src/mixer_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class MixerTest : public ::testing::Test {
// Checking that ratios correctly default to 1/N.
TEST_F(MixerTest, StreamDefaultRatio) {
SetOutStream_capacity(50);
SetThroughput(1e200);
SetThroughput(cyclus::CY_LARGE_DOUBLE);
mf_facility_->EnterNotify();

double ext_val = 1.0 / 3.0;
Expand All @@ -198,7 +198,7 @@ TEST_F(MixerTest, StreamRatio) {
SetStream_ratio(in_frac_);
SetStream_capacity(in_cap_);
SetOutStream_capacity(50);
SetThroughput(1e200);
SetThroughput(cyclus::CY_LARGE_DOUBLE);
mf_facility_->EnterNotify();

std::vector<double> strm_ratio_ = GetStream_ratio();
Expand All @@ -213,7 +213,7 @@ TEST_F(MixerTest, StreamRatio) {
// Checking renormalisation when sum of ratio is smaller tham 1.
in_frac_ = {0.1, 0.2, 0.5};
SetOutStream_capacity(50);
SetThroughput(1e200);
SetThroughput(cyclus::CY_LARGE_DOUBLE);

SetStream_ratio(in_frac_);
mf_facility_->EnterNotify();
Expand All @@ -237,7 +237,7 @@ TEST_F(MixerTest, MixingComposition) {

SetOutStream_capacity(50);

SetThroughput(1e200);
SetThroughput(cyclus::CY_LARGE_DOUBLE);

std::vector<Material::Ptr> mat;
mat.push_back(Material::CreateUntracked(in_cap[0], c_natu()));
Expand Down
10 changes: 6 additions & 4 deletions src/separations.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "cyclus.h"
#include "cycamore_version.h"

#pragma cyclus exec from cyclus.system import CY_LARGE_DOUBLE, CY_LARGE_INT, CY_NEAR_ZERO

namespace cycamore {

/// SepMaterial returns a material object that represents the composition and
Expand Down Expand Up @@ -147,9 +149,9 @@ class Separations
"doc" : "Maximum quantity of feed material that can be processed per time "\
"step.", \
"uilabel": "Maximum Separations Throughput", \
"default": 1e299, \
"default": CY_LARGE_DOUBLE, \
"uitype": "range", \
"range": [0.0, 1e299], \
"range": [0.0, CY_LARGE_DOUBLE], \
"units": "kg/(time step)", \
}
double throughput;
Expand All @@ -170,9 +172,9 @@ class Separations
" If full, the facility halts operation until space becomes " \
"available.", \
"uilabel": "Maximum Leftover Inventory", \
"default": 1e299, \
"default": CY_LARGE_DOUBLE, \
"uitype": "range", \
"range": [0.0, 1e299], \
"range": [0.0, CY_LARGE_DOUBLE], \
"units": "kg", \
}
double leftoverbuf_size;
Expand Down
Loading

0 comments on commit aea4bb5

Please sign in to comment.