Skip to content

Commit c61cf6c

Browse files
authored
Merge pull request #677 from meg-krieg/deployinst_664
2 parents c809ea7 + 63fb766 commit c61cf6c

File tree

4 files changed

+93
-5
lines changed

4 files changed

+93
-5
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Since last release
1414
* Added default keep packaging to reactor (#618, #619)
1515
* Added support for Ubuntu 24.04 (#633)
1616
* Added (negative)binomial distributions for disruption modeling to storage (#635)
17+
* Added new variable to Deploy Institution to shift the deployment times (#677)
1718

1819
**Changed:**
1920
* Cleaned up manual definitions of Position in favor of code injection (#641)

src/deploy_inst.cc

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Implements the DeployInst class
22
#include "deploy_inst.h"
3+
#include "error.h"
34

45
namespace cycamore {
56

@@ -12,12 +13,20 @@ void DeployInst::Build(cyclus::Agent* parent) {
1213
cyclus::Institution::Build(parent);
1314
BuildSched::iterator it;
1415
std::set<std::string> protos;
16+
17+
int sim_start = 12*(context()->sim_info().y0) +
18+
context()->sim_info().m0;
19+
int d_t = 0;
20+
if(deployyear!=-1){
21+
d_t += deployyear*12 - sim_start;
22+
}
23+
1524
for (int i = 0; i < prototypes.size(); i++) {
1625
std::string proto = prototypes[i];
1726

1827
std::stringstream ss;
1928
ss << proto;
20-
29+
2130
if (lifetimes.size() == prototypes.size()) {
2231
cyclus::Agent* a = context()->CreateAgent<Agent>(proto);
2332
if (a->lifetime() != lifetimes[i]) {
@@ -36,13 +45,26 @@ void DeployInst::Build(cyclus::Agent* parent) {
3645
}
3746
}
3847

39-
int t = build_times[i];
48+
int t_build = build_times[i] + d_t;
49+
50+
if(t_build < 0){
51+
std::stringstream ss;
52+
ss << "Deploy year is before simulation start. Adjust deployment time." ;
53+
throw cyclus::ValueError(ss.str());
54+
}
55+
else if(t_build >= context()->sim_info().duration){
56+
cyclus::Warn<cyclus::VALUE_WARNING>(
57+
"Deployment year must be less than simulation duration;"
58+
"A facility will not be deployed during the simulation.");
59+
}
60+
4061
for (int j = 0; j < n_build[i]; j++) {
41-
context()->SchedBuild(this, proto, t);
62+
context()->SchedBuild(this, proto, t_build);
4263
}
4364
}
4465
}
4566

67+
4668
void DeployInst::EnterNotify() {
4769
cyclus::Institution::EnterNotify();
4870
int n = prototypes.size();
@@ -62,7 +84,6 @@ void DeployInst::EnterNotify() {
6284
<< " lifetimes vals, expected " << n;
6385
throw cyclus::ValueError(ss.str());
6486
}
65-
6687
InitializePosition();
6788
}
6889

src/deploy_inst.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ class DeployInst :
8484
}
8585
std::vector<int> n_build;
8686

87+
#pragma cyclus var { \
88+
"doc": "Year to start deploying prototypes.", \
89+
"default": -1, \
90+
"uilabel": "deploy year",\
91+
}
92+
int deployyear;
8793

8894
#pragma cyclus var { \
8995
"doc": "Lifetimes for each prototype in prototype list (same order)." \

src/deploy_inst_tests.cc

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "deploy_inst_tests.h"
2-
2+
#include "error.h"
3+
#include "deploy_inst.h"
34
// make sure that the deployed agent's prototype name is identical to the
45
// originally specified prototype name - this is important to test because
56
// DeployInst does some mucking around with registering name-modded prototypes
@@ -154,6 +155,65 @@ TEST_F(DeployInstTests, NoDupProtos) {
154155
EXPECT_EQ(1, stmt->GetInt(0));
155156
}
156157

158+
TEST_F(DeployInstTests, DeployYear) {
159+
std::string config =
160+
"<prototypes> <val>foobar</val> </prototypes>"
161+
"<build_times> <val>2</val> </build_times>"
162+
"<n_build> <val>3</val> </n_build>"
163+
"<deployyear> 2012 </deployyear>"
164+
;
165+
166+
int simdur = 30;
167+
//MockSim starts in 2010 by default
168+
cyclus::MockSim sim(cyclus::AgentSpec(":cycamore:DeployInst"), config, simdur);
169+
sim.DummyProto("foobar");
170+
int id = sim.Run();
171+
// 2 years and 2 months after MockSim start is 25 time steps
172+
cyclus::SqlStatement::Ptr stmt = sim.db().db().Prepare(
173+
"SELECT COUNT(*) FROM AgentEntry WHERE Prototype = 'foobar' AND EnterTime = '25';"
174+
);
175+
stmt->Step();
176+
EXPECT_EQ(3, stmt->GetInt(0));
177+
}
178+
179+
TEST_F(DeployInstTests, DeployYearEarlyError) {
180+
std::string config =
181+
"<prototypes> <val>foobar</val> </prototypes>"
182+
"<build_times> <val>2</val> </build_times>"
183+
"<n_build> <val>3</val> </n_build>"
184+
"<deployyear> 2000 </deployyear>"
185+
;
186+
187+
int simdur = 5;
188+
cyclus::MockSim sim(cyclus::AgentSpec(":cycamore:DeployInst"), config, simdur);
189+
190+
EXPECT_THROW(sim.Run(),cyclus::ValueError);
191+
}
192+
193+
TEST_F(DeployInstTests, DeployYearLateWarn) {
194+
std::string config =
195+
"<prototypes> <val>foobar</val> </prototypes>"
196+
"<build_times> <val>2</val> </build_times>"
197+
"<n_build> <val>3</val> </n_build>"
198+
"<deployyear> 2030 </deployyear>"
199+
;
200+
201+
int simdur = 5;
202+
cyclus::MockSim sim(cyclus::AgentSpec(":cycamore:DeployInst"), config, simdur);
203+
204+
cyclus::warn_as_error = true;
205+
EXPECT_THROW(sim.Run(),
206+
cyclus::ValueError);
207+
cyclus::warn_as_error = false;
208+
209+
int id = sim.Run();
210+
cyclus::SqlStatement::Ptr stmt = sim.db().db().Prepare(
211+
"SELECT COUNT(*) FROM AgentEntry WHERE Prototype = 'foobar';"
212+
);
213+
stmt->Step();
214+
EXPECT_EQ(0, stmt->GetInt(0));
215+
}
216+
157217
TEST_F(DeployInstTests, PositionInitialize) {
158218
std::string config =
159219
"<prototypes> <val>foobar</val> </prototypes>"

0 commit comments

Comments
 (0)