Skip to content

Commit 1305319

Browse files
authored
Merge pull request #639 from dean-krueger/code-injection
Clean Up Storage .h/.cc Files with Code Injection
2 parents e4ff5c4 + 28d87ef commit 1305319

File tree

3 files changed

+8
-433
lines changed

3 files changed

+8
-433
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Since last release
66
======================
77

88
**Added:**
9+
* Replaced manual matl_buy/sell_policy code in storage with code injection (#639)
910
* Added package parameter to storage (#603, #612, #616)
1011
* Added package parameter to source (#613, #617, #621, #623, #630)
1112
* Added default keep packaging to reactor (#618, #619)

src/storage.cc

Lines changed: 0 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -46,115 +46,6 @@ void Storage::InitFrom(cyclus::QueryableBackend* b) {
4646
cyclus::toolkit::CommodityProducer::SetCapacity(commod, throughput);
4747
}
4848

49-
void Storage::InitBuyPolicyParameters() {
50-
/// set up active buying distribution
51-
if (active_buying_min > active_buying_max) {
52-
throw cyclus::ValueError("Active min larger than max.");
53-
}
54-
if (dormant_buying_min > dormant_buying_max) {
55-
throw cyclus::ValueError("Dormant min larger than max.");
56-
}
57-
if (buying_size_min > buying_size_max) {
58-
throw cyclus::ValueError("Buying size min larger than max.");
59-
}
60-
61-
if (active_buying_frequency_type == "Fixed") {
62-
active_dist_ = cyclus::FixedIntDist::Ptr (new cyclus::FixedIntDist(active_buying_val));
63-
}
64-
else if (active_buying_frequency_type == "Uniform") {
65-
if ((active_buying_min == -1) || (active_buying_max == -1)) {
66-
throw cyclus::ValueError("Invalid active buying frequency range. Please provide both a min and max value.");
67-
}
68-
active_dist_ = cyclus::UniformIntDist::Ptr (new cyclus::UniformIntDist(active_buying_min, active_buying_max));
69-
}
70-
else if (active_buying_frequency_type == "Normal") {
71-
if ((active_buying_mean == -1) || (active_buying_stddev == -1)) {
72-
throw cyclus::ValueError("Invalid active buying frequency range. Please provide both a mean and standard deviation value.");
73-
}
74-
if (active_buying_min == -1) {active_buying_min = 1;}
75-
if (active_buying_max == -1) {
76-
active_buying_max = std::numeric_limits<int>::max();}
77-
78-
active_dist_ = cyclus::NormalIntDist::Ptr (new cyclus::NormalIntDist(active_buying_mean, active_buying_stddev,
79-
active_buying_min, active_buying_max));
80-
}
81-
else if (active_buying_frequency_type == "Binomial") {
82-
if (active_buying_end_probability < 0 || active_buying_end_probability > 1) {
83-
throw cyclus::ValueError("Active buying end probability must be between 0 and 1");
84-
}
85-
int success = 1; // only one success is needed to end the active buying period
86-
active_dist_ = cyclus::NegativeBinomialIntDist::Ptr (new cyclus::NegativeBinomialIntDist(success, active_buying_end_probability));
87-
} else if (active_buying_frequency_type == "FixedWithDisruption") {
88-
if (active_buying_disruption < 0) {
89-
throw cyclus::ValueError("Disruption must be greater than or equal to 0");
90-
}
91-
active_dist_ = cyclus::BinaryIntDist::Ptr (
92-
new cyclus::BinaryIntDist(active_buying_disruption_probability,
93-
active_buying_disruption, active_buying_val));
94-
}
95-
else {
96-
throw cyclus::ValueError("Invalid active buying frequency type");}
97-
98-
/// set up dormant buying distribution
99-
if (dormant_buying_frequency_type == "Fixed") {
100-
dormant_dist_ = cyclus::FixedIntDist::Ptr (new cyclus::FixedIntDist(dormant_buying_val));
101-
}
102-
else if (dormant_buying_frequency_type == "Uniform") {
103-
if ((dormant_buying_min == -1) || (dormant_buying_max == -1)) {
104-
throw cyclus::ValueError("Invalid dormant buying frequency range. Please provide both a min and max value.");
105-
}
106-
dormant_dist_ = cyclus::UniformIntDist::Ptr (new cyclus::UniformIntDist(dormant_buying_min, dormant_buying_max));
107-
}
108-
else if (dormant_buying_frequency_type == "Normal") {
109-
if ((dormant_buying_mean == -1) || (dormant_buying_stddev == -1)) {
110-
throw cyclus::ValueError("Invalid dormant buying frequency range. Please provide both a mean and standard deviation value.");
111-
}
112-
if (dormant_buying_min == -1) {dormant_buying_min = 1;}
113-
if (dormant_buying_max == -1) {
114-
dormant_buying_max = std::numeric_limits<int>::max();}
115-
dormant_dist_ = cyclus::NormalIntDist::Ptr (new cyclus::NormalIntDist(dormant_buying_mean, dormant_buying_stddev,
116-
dormant_buying_min, dormant_buying_max));
117-
}
118-
else if (dormant_buying_frequency_type == "Binomial") {
119-
if (dormant_buying_end_probability < 0 || dormant_buying_end_probability > 1) {
120-
throw cyclus::ValueError("Dormant buying end probability must be between 0 and 1");
121-
}
122-
int success = 1; // only one success is needed to end the dormant buying period
123-
dormant_dist_ = cyclus::NegativeBinomialIntDist::Ptr (new cyclus::NegativeBinomialIntDist(success, dormant_buying_end_probability));
124-
} else if (dormant_buying_frequency_type == "FixedWithDisruption") {
125-
if (dormant_buying_disruption < 0) {
126-
throw cyclus::ValueError("Disruption must be greater than or equal to 0");
127-
}
128-
dormant_dist_ = cyclus::BinaryIntDist::Ptr (
129-
new cyclus::BinaryIntDist(dormant_buying_disruption_probability,
130-
dormant_buying_disruption, dormant_buying_val));
131-
}
132-
else {
133-
throw cyclus::ValueError("Invalid dormant buying frequency type");}
134-
135-
/// set up buying size distribution
136-
if (buying_size_type == "Fixed") {
137-
size_dist_ = cyclus::FixedDoubleDist::Ptr (new cyclus::FixedDoubleDist(buying_size_val));
138-
}
139-
else if (buying_size_type == "Uniform") {
140-
if ((buying_size_min == -1) || (buying_size_max == -1)) {
141-
throw cyclus::ValueError("Invalid buying size range. Please provide both a min and max value.");
142-
}
143-
size_dist_ = cyclus::UniformDoubleDist::Ptr (new cyclus::UniformDoubleDist(buying_size_min, buying_size_max));
144-
}
145-
else if (buying_size_type == "Normal") {
146-
if ((buying_size_mean == -1) || (buying_size_stddev == -1)) {
147-
throw cyclus::ValueError("Invalid buying size range. Please provide both a mean and standard deviation value.");
148-
}
149-
if (buying_size_min == -1) {buying_size_min = 0;}
150-
if (buying_size_max == -1) {buying_size_max = 1;}
151-
size_dist_ = cyclus::NormalDoubleDist::Ptr (new cyclus::NormalDoubleDist(buying_size_mean, buying_size_stddev,
152-
buying_size_min, buying_size_max));
153-
}
154-
else {
155-
throw cyclus::ValueError("Invalid buying size type");}
156-
}
157-
15849
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
15950
void Storage::EnterNotify() {
16051
cyclus::Facility::EnterNotify();

0 commit comments

Comments
 (0)