diff --git a/src/storage.cc b/src/storage.cc index 3408232cb..577587d5d 100644 --- a/src/storage.cc +++ b/src/storage.cc @@ -48,18 +48,35 @@ void Storage::InitFrom(cyclus::QueryableBackend* b) { void Storage::SetUpBuyPolicy() { /// set up active buying distribution + if (active_buying_min > active_buying_max) { + throw cyclus::ValueError("Active min larger than max."); + } + if (dormant_buying_min > dormant_buying_max) { + throw cyclus::ValueError("Dormant min larger than max."); + } + if (buying_size_min > buying_size_max) { + throw cyclus::ValueError("Buying size min larger than max."); + } + if (active_buying_frequency_type == "Fixed") { active_dist_ = boost::shared_ptr(new cyclus::FixedIntDist(active_buying_val)); } else if (active_buying_frequency_type == "Uniform") { + if ((active_buying_min == -1) || (active_buying_max == -1)) { + throw cyclus::ValueError("Invalid active buying frequency range. Please provide both a min and max value."); + } active_dist_ = boost::shared_ptr(new cyclus::UniformIntDist(active_buying_min, active_buying_max)); } else if (active_buying_frequency_type == "Normal") { - if (active_buying_max == 0) { - active_buying_max = std::numeric_limits::max(); + if ((active_buying_mean == -1) || (active_buying_stddev == -1)) { + throw cyclus::ValueError("Invalid active buying frequency range. Please provide both a mean and standard deviation value."); } + if (active_buying_min == -1) {active_buying_min = 1;} + if (active_buying_max == -1) { + active_buying_max = std::numeric_limits::max();} + active_dist_ = boost::shared_ptr(new cyclus::NormalIntDist(active_buying_mean, active_buying_stddev, - active_buying_min, active_buying_max)); + active_buying_min, active_buying_max)); } else { throw cyclus::ValueError("Invalid active buying frequency type");} @@ -69,14 +86,20 @@ void Storage::SetUpBuyPolicy() { dormant_dist_ = boost::shared_ptr(new cyclus::FixedIntDist(dormant_buying_val)); } else if (dormant_buying_frequency_type == "Uniform") { + if ((dormant_buying_min == -1) || (dormant_buying_max == -1)) { + throw cyclus::ValueError("Invalid dormant buying frequency range. Please provide both a min and max value."); + } dormant_dist_ = boost::shared_ptr(new cyclus::UniformIntDist(dormant_buying_min, dormant_buying_max)); } else if (dormant_buying_frequency_type == "Normal") { - if (dormant_buying_max == 0) { - dormant_buying_max = std::numeric_limits::max(); + if ((dormant_buying_mean == -1) || (dormant_buying_stddev == -1)) { + throw cyclus::ValueError("Invalid dormant buying frequency range. Please provide both a mean and standard deviation value."); } + if (dormant_buying_min == -1) {dormant_buying_min = 1;} + if (dormant_buying_max == -1) { + dormant_buying_max = std::numeric_limits::max();} dormant_dist_ = boost::shared_ptr(new cyclus::NormalIntDist(dormant_buying_mean, dormant_buying_stddev, - dormant_buying_min, dormant_buying_max)); + dormant_buying_min, dormant_buying_max)); } else { throw cyclus::ValueError("Invalid dormant buying frequency type");} @@ -86,12 +109,17 @@ void Storage::SetUpBuyPolicy() { size_dist_ = boost::shared_ptr(new cyclus::FixedDoubleDist(buying_size_val)); } else if (buying_size_type == "Uniform") { + if ((buying_size_min == -1) || (buying_size_max == -1)) { + throw cyclus::ValueError("Invalid buying size range. Please provide both a min and max value."); + } size_dist_ = boost::shared_ptr(new cyclus::UniformDoubleDist(buying_size_min, buying_size_max)); } else if (buying_size_type == "Normal") { - if (buying_size_max == 0) { - buying_size_max = std::numeric_limits::max(); + if ((buying_size_mean == -1) || (buying_size_stddev == -1)) { + throw cyclus::ValueError("Invalid buying size range. Please provide both a mean and standard deviation value."); } + if (buying_size_min == -1) {buying_size_min = 0;} + if (buying_size_max == -1) {buying_size_max = 1;} size_dist_ = boost::shared_ptr(new cyclus::NormalDoubleDist(buying_size_mean, buying_size_stddev, buying_size_min, buying_size_max)); } diff --git a/src/storage.h b/src/storage.h index 4e6f7f786..101ed5753 100644 --- a/src/storage.h +++ b/src/storage.h @@ -231,7 +231,7 @@ class Storage #pragma cyclus var {"default": "Fixed",\ "tooltip": "Type of active buying frequency",\ "doc": "Options: Fixed, Uniform, Normal. Fixed requires active_buying_val. Uniform "\ - "requires active_buying_max, with optional active_buying_min (default 1). Normal "\ + "requires active_buying_min and active_buying_max. Normal "\ "requires active_buying_mean and active_buying_std, with optional "\ "active_buying_min and active_buying_max.",\ "uitype": "combobox",\ @@ -239,7 +239,7 @@ class Storage "uilabel": "Active Buying Frequency Type"} std::string active_buying_frequency_type; - #pragma cyclus var {"default": 1,\ + #pragma cyclus var {"default": -1,\ "tooltip": "Fixed active buying frequency",\ "doc": "The length in time steps of the active buying period. Required for fixed "\ "active_buying_frequency_type. Must be greater than or equal to 1 (i.e., agent "\ @@ -249,16 +249,17 @@ class Storage "uilabel": "Active Buying Frequency Value"} int active_buying_val; - #pragma cyclus var {"default": 1,\ + #pragma cyclus var {"default": -1,\ "tooltip": "Active buying distribution minimum",\ - "doc": "The minimum length in time steps of the active buying period. Optional for "\ - "Uniform and Normal active_buying_frequency_type. Must be greater than or equal to 1 ",\ + "doc": "The minimum length in time steps of the active buying period. Required for "\ + "Uniform and optional for Normal active_buying_frequency_type. Must be greater than "\ + "or equal to 1 ",\ "uitype": "range", \ "range": [1, 1e299], \ "uilabel": "Active Buying Frequency Minimum"} int active_buying_min; - #pragma cyclus var {"default": 1e299,\ + #pragma cyclus var {"default": -1,\ "tooltip": "Active buying distribution maximum",\ "doc": "The maximum length in time steps of the active buying period. Required for "\ "Uniform active_buying_frequency_type, optional for Normal. Must be greater than or equal to active_buying_min ",\ @@ -267,7 +268,7 @@ class Storage "uilabel": "Active Buying Frequency Maximum"} int active_buying_max; - #pragma cyclus var {"default": 1,\ + #pragma cyclus var {"default": -1,\ "tooltip": "Active buying distribution mean",\ "doc": "The mean length in time steps of the active buying period. Required for "\ "Normal active_buying_frequency_type. Must be greater than or equal to 1 ",\ @@ -276,7 +277,7 @@ class Storage "uilabel": "Active Buying Frequency Mean"} double active_buying_mean; - #pragma cyclus var {"default": 1,\ + #pragma cyclus var {"default": -1,\ "tooltip": "Active buying distribution standard deviation",\ "doc": "The standard deviation of the length in time steps of the active buying period. "\ "Required for Normal active_buying_frequency_type. Must be greater than or equal to 0 ",\ @@ -305,7 +306,7 @@ class Storage "uilabel": "Dormant Buying Frequency Value"} int dormant_buying_val; - #pragma cyclus var {"default": 0,\ + #pragma cyclus var {"default": -1,\ "tooltip": "Dormant buying distribution minimum",\ "doc": "The minimum length in time steps of the dormant buying period. Optional for "\ "Uniform and Normal dormant_buying_frequency_type.",\ @@ -314,7 +315,7 @@ class Storage "uilabel": "Dormant Buying Frequency Minimum"} int dormant_buying_min; - #pragma cyclus var {"default": 0,\ + #pragma cyclus var {"default": -1,\ "tooltip": "Dormant buying distribution maximum",\ "doc": "The maximum length in time steps of the dormant buying period. Required for "\ "Uniform dormant_buying_frequency_type, optional for Normal. Must be greater than or equal to dormant_buying_min ",\ @@ -323,7 +324,7 @@ class Storage "uilabel": "Dormant Buying Frequency Maximum"} int dormant_buying_max; - #pragma cyclus var {"default": 0,\ + #pragma cyclus var {"default": -1,\ "tooltip": "Dormant buying distribution mean",\ "doc": "The mean length in time steps of the dormant buying period. Required for "\ "Normal dormant_buying_frequency_type. Must be greater than or equal to 0 ",\ @@ -332,7 +333,7 @@ class Storage "uilabel": "Dormant Buying Frequency Mean"} double dormant_buying_mean; - #pragma cyclus var {"default": 0,\ + #pragma cyclus var {"default": -1,\ "tooltip": "Dormant buying distribution standard deviation",\ "doc": "The standard deviation of the length in time steps of the dormant buying period. "\ "Required for Normal dormant_buying_frequency_type. Must be greater than or equal to 0 ",\ @@ -363,7 +364,7 @@ class Storage "uilabel": "Buying Size Value"} double buying_size_val; - #pragma cyclus var {"default": 0.0,\ + #pragma cyclus var {"default": -1.0,\ "tooltip": "Buying size distribution minimum",\ "doc": "The minimum size of the buy request as a fraction of maximum capacity. "\ "Optional for Uniform and Normal buying_size_type.",\ @@ -372,7 +373,7 @@ class Storage "uilabel": "Buying Size Minimum"} double buying_size_min; - #pragma cyclus var {"default": 1.0,\ + #pragma cyclus var {"default": -1.0,\ "tooltip": "Buying size distribution maximum",\ "doc": "The maximum size of the buy request as a fraction of maximum capacity. "\ "Required for Uniform buying_size_type, optional for Normal. Must be greater than "\ @@ -382,7 +383,7 @@ class Storage "uilabel": "Buying Size Maximum"} double buying_size_max; - #pragma cyclus var {"default": 1.0,\ + #pragma cyclus var {"default": -1.0,\ "tooltip": "Buying size distribution mean",\ "doc": "The mean size of the buy request as a fraction of maximum capacity. "\ "Required for Normal buying_size_type.",\ @@ -391,7 +392,7 @@ class Storage "uilabel": "Buying Size Mean"} double buying_size_mean; - #pragma cyclus var {"default": 0.0,\ + #pragma cyclus var {"default": -1.0,\ "tooltip": "Buying size distribution standard deviation",\ "doc": "The standard deviation of the size of the buy request as a fraction of "\ "maximum capacity. Required for Normal buying_size_type.",\ diff --git a/src/storage_tests.cc b/src/storage_tests.cc index aba1fb900..b0c383467 100644 --- a/src/storage_tests.cc +++ b/src/storage_tests.cc @@ -645,16 +645,64 @@ TEST_F(StorageTest, NormalActiveDormantBuyingSize){ // second cycle (rows 4 and 4) include time steps 6 and 7 EXPECT_EQ(6, qr.GetVal("Time", 4)); EXPECT_EQ(7, qr.GetVal("Time", 5)); - // third cycle (row 6) includes time step 8 + // third cycle (row 6) includes time step 8 -9 EXPECT_EQ(8, qr.GetVal("Time", 6)); - // fourth cycle (rows 7, 8, 9) includes time steps 12 - 14 - EXPECT_EQ(12, qr.GetVal("Time", 7)); + EXPECT_EQ(9, qr.GetVal("Time", 7)); + // fourth cycle (rows 8, 9) includes time steps 13 - 14 + EXPECT_EQ(13, qr.GetVal("Time", 8)); EXPECT_EQ(14, qr.GetVal("Time", 9)); qr = sim.db().Query("Resources", NULL); - EXPECT_NEAR(0.30861, qr.GetVal("Quantity", 0), 0.00001); - EXPECT_NEAR(0.51678, qr.GetVal("Quantity", 1), 0.00001); - EXPECT_NEAR(0.61256, qr.GetVal("Quantity", 2), 0.00001); + EXPECT_NEAR(0.61256, qr.GetVal("Quantity", 0), 0.00001); + EXPECT_NEAR(0.62217, qr.GetVal("Quantity", 1), 0.00001); + EXPECT_NEAR(0.39705, qr.GetVal("Quantity", 2), 0.00001); +} + +TEST_F(StorageTest, IncorrectBuyPolSetupUniform) { + // uniform missing min and max + std::string config_uniform = + " spent_fuel " + " dry_spent " + " 1" + " Uniform"; + + int simdur = 15; + + cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config_uniform, + simdur); + EXPECT_THROW(sim.Run(), cyclus::ValueError); +} + +TEST_F(StorageTest, IncorrectBuyPolSetupNormal) { + // normal missing mean and std dev + std::string config_normal = + " spent_fuel " + " dry_spent " + " 1" + " Normal"; + int simdur = 15; + + cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config_normal, + simdur); + EXPECT_THROW(sim.Run(), cyclus::ValueError); +} + +TEST_F(StorageTest, IncorrectBuyPolSetupMinMax) { + // tries to set min > max + std::string config_uniform_min_bigger_max = + " spent_fuel " + " dry_spent " + " 1" + " Uniform" + " 3" + " 2"; + + int simdur = 15; + + cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), + config_uniform_min_bigger_max, simdur); + EXPECT_THROW(sim.Run(), cyclus::ValueError); + } TEST_F(StorageTest, PositionInitialize){