Skip to content

Commit

Permalink
replace other instances of large doubles and near-zero values
Browse files Browse the repository at this point in the history
  • Loading branch information
bennibbelink committed Jul 21, 2024
1 parent f7da6a3 commit 96bb027
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 39 deletions.
11 changes: 10 additions & 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 Expand Up @@ -572,6 +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::toolkit::MatQuery;
using cyclus::Composition;

cyclus::Env::SetNucDataPath();

double qty = 5; // 5 kg
Expand Down Expand Up @@ -605,6 +608,12 @@ 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::toolkit::MatQuery;
using cyclus::Composition;
using cyclus::toolkit::Assays;
using cyclus::toolkit::UraniumAssayMass;
using cyclus::toolkit::SwuRequired;
using cyclus::toolkit::FeedQty;

double qty = 5; // kg
double product_assay = 0.05; // of 5 w/o enriched U
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
4 changes: 2 additions & 2 deletions src/fuel_fab.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,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


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: 5 additions & 5 deletions src/storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void Storage::InitBuyPolicyParameters() {
if (active_buying_max == -1) {
active_buying_max = std::numeric_limits<int>::max();}

active_dist_ = cyclus::NormalIntDist::Ptr (new cyclus::NormalIntDist(active_buying_mean, active_buying_stddev,
active_dist_ = cyclus::NormalIntDist::Ptr (new cyclus::NormalIntDist(active_buying_mean, active_buying_stddev,
active_buying_min, active_buying_max));
}
else {
Expand Down Expand Up @@ -184,7 +184,7 @@ void Storage::EnterNotify() {

std::string package_name_ = context()->GetPackage(package)->name();
if (out_commods.size() == 1) {
sell_policy.Init(this, &stocks, std::string("stocks"), 1e+299, false,
sell_policy.Init(this, &stocks, std::string("stocks"), cyclus::CY_LARGE_DOUBLE, false,
sell_quantity, package_name_)
.Set(out_commods.front())
.Start();
Expand Down Expand Up @@ -225,7 +225,7 @@ std::string Storage::str() {

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Storage::Tick() {


LOG(cyclus::LEV_INFO3, "ComCnv") << prototype() << " is ticking {";

Expand Down Expand Up @@ -265,9 +265,9 @@ void Storage::Tock() {
int maxindx = std::distance(in_commod_prefs.begin(), result);
double demand = 0;
demand = current_capacity();

cyclus::toolkit::RecordTimeSeries<double>("demand"+in_commods[maxindx], this, demand);

// Multiple commodity tracking is not supported, user can only
// provide one value for out_commods, despite it being a vector of strings.
cyclus::toolkit::RecordTimeSeries<double>("supply"+out_commods[0], this,
Expand Down
23 changes: 12 additions & 11 deletions tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from numpy.testing import assert_array_almost_equal
from numpy.testing import assert_almost_equal
from cyclus.lib import Env
from cyclus.system import CY_NEAR_ZERO

from pytest import skip

Expand Down Expand Up @@ -273,7 +274,7 @@ class TestDynamicCapacitated(TestRegression):
facilities being the constraint. At time step 3, after decommissioning 2
older sink facilities, the remaining number of sink facilities becomes
the constraint, resulting in the same transaction amount as in time step 1.
"""
"""
@classmethod
def setup_class(cls):
skip_if_dont_allow_milps()
Expand Down Expand Up @@ -365,7 +366,7 @@ def test_xaction_specific(self):

class TestGrowth1(TestRegression):
"""This class tests the growth.xml
Tests GrowthRegion, ManagerInst, and Source over a 4-time step
simulation.
Expand Down Expand Up @@ -411,7 +412,7 @@ def test_deployment(self):

class TestGrowth2(TestRegression):
"""This class tests the ./input/deploy_and_manager_insts.xml
Tests GrowthRegion, ManagerInst, DeployInst, and Source over a 10-time step
simulation.
Expand Down Expand Up @@ -449,17 +450,17 @@ def test_deployment(self):

class TestDeployInst(TestRegression):
"""This class tests the ../input/deploy_inst.xml
Tests DeployInst, and NullRegion over a 10-time step
simulation.
A DeployInst is used to define that a Source agent is to be deployed at
A DeployInst is used to define that a Source agent is to be deployed at
time t=1 within a Null Region. A Sink agent is also deployed as
an initial facility. This input is used to test that the Source and
Sink agents are deployed at their respecitve times and that the correct
an initial facility. This input is used to test that the Source and
Sink agents are deployed at their respecitve times and that the correct
number of these agents are deployed.
"""
"""
@classmethod
def setup_class(cls):
skip_if_dont_allow_milps()
Expand Down Expand Up @@ -487,7 +488,7 @@ def test_deployment(self):

class _Recycle(TestRegression):
"""This class tests the input/recycle.xml file.
"""
"""
@classmethod
def setup_class(cls, inf):
super(_Recycle, cls).setup_class(inf)
Expand All @@ -506,7 +507,7 @@ def setup_class(cls, inf):
def do_compare(self, fromfac, tofac, nuclide, exp_invs):
conn = sqlite3.connect(self.outf)
c = conn.cursor()
eps = 1e-10
eps = CY_NEAR_ZERO
simdur = len(exp_invs)

invs = [0.0] * simdur
Expand Down Expand Up @@ -583,7 +584,7 @@ def setup_class(cls):

class TestCBCRecycle(_Recycle):
"""This class tests the input/recycle.xml file.
"""
"""
@classmethod
def setup_class(cls):
skip_if_dont_allow_milps()
Expand Down

0 comments on commit 96bb027

Please sign in to comment.