diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b626877cf5..b265dd9f27 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -23,6 +23,8 @@ USE_CYCLUS("cycamore" "deploy_inst") USE_CYCLUS("cycamore" "manager_inst") +USE_CYCLUS("cycamore" "group_inst") + USE_CYCLUS("cycamore" "growth_region") USE_CYCLUS("cycamore" "storage") diff --git a/src/group_inst.cc b/src/group_inst.cc new file mode 100644 index 0000000000..e29256f913 --- /dev/null +++ b/src/group_inst.cc @@ -0,0 +1,30 @@ +// Implements the GroupInst class +#include "group_inst.h" + +namespace cycamore { + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +GroupInst::GroupInst(cyclus::Context* ctx) : cyclus::Institution(ctx) { } + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +GroupInst::~GroupInst() {} + + +void GroupInst::EnterNotify() { + cyclus::Institution::EnterNotify(); + + for (int i = 0; i < prototypes.size(); i++) { + std::string s_proto = prototypes[i]; + context()->SchedBuild(this, s_proto); //builds on next timestep + BuildNotify(this); + } +} + + + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +extern "C" cyclus::Agent* ConstructGroupInst(cyclus::Context* ctx) { + return new GroupInst(ctx); +} + +} // namespace cycamore diff --git a/src/group_inst.h b/src/group_inst.h new file mode 100644 index 0000000000..baa5a4c464 --- /dev/null +++ b/src/group_inst.h @@ -0,0 +1,51 @@ +#ifndef CYCAMORE_SRC_MANAGER_INST_H_ +#define CYCAMORE_SRC_MANAGER_INST_H_ + +#include "cyclus.h" +#include "cycamore_version.h" + +namespace cycamore { + +/// @class GroupInst +/// @section introduction Introduction +/// @section detailedBehavior Detailed Behavior +/// @warning The GroupInst is experimental +class GroupInst + : public cyclus::Institution, + public cyclus::toolkit::CommodityProducerManager, + public cyclus::toolkit::Builder { + public: + /// Default constructor + GroupInst(cyclus::Context* ctx); + + /// Default destructor + virtual ~GroupInst(); + + virtual std::string version() { return CYCAMORE_VERSION; } + + #pragma cyclus + + #pragma cyclus note {"doc": "An institution that owns and operates a " \ + "manually entered list of facilities in " \ + "the input file"} + + /// enter the simulation and register any children present + virtual void EnterNotify(); + + + private: + + #pragma cyclus var { \ + "tooltip": "producer facility prototypes", \ + "uilabel": "Producer Prototype List", \ + "uitype": ["oneormore", "prototype"], \ + "doc": "A set of facility prototypes that this institution can build. " \ + "All prototypes in this list must be based on an archetype that " \ + "implements the cyclus::toolkit::CommodityProducer interface", \ + } + std::vector prototypes; +}; + +} // namespace cycamore + +#endif // CYCAMORE_SRC_MANAGER_INST_H_ diff --git a/src/group_inst_tests.cc b/src/group_inst_tests.cc new file mode 100644 index 0000000000..4bc34bcc67 --- /dev/null +++ b/src/group_inst_tests.cc @@ -0,0 +1,56 @@ +#include + +#include "context.h" +#include "group_inst.h" +#include "institution_tests.h" +#include "agent_tests.h" + + +TEST(GroupInstTests, BuildTimes) { + std::string config = + " " + " foobar1" + " foobar2" + " foobar3" + " " + ; + + int simdur = 5; + cyclus::MockSim sim(cyclus::AgentSpec(":cycamore:GroupInst"), config, simdur); + sim.DummyProto("foobar1"); + sim.DummyProto("foobar2"); + sim.DummyProto("foobar3"); + int id = sim.Run(); + + cyclus::SqlStatement::Ptr stmt = sim.db().db().Prepare( + "SELECT COUNT(*) FROM AgentEntry WHERE Prototype = 'foobar1';" + ); + stmt->Step(); + EXPECT_EQ(1, stmt->GetInt(0)); + + stmt = sim.db().db().Prepare( + "SELECT COUNT(*) FROM AgentEntry WHERE Prototype = 'foobar2';" + ); + stmt->Step(); + EXPECT_EQ(1, stmt->GetInt(0)); + stmt = sim.db().db().Prepare( + "SELECT COUNT(*) FROM AgentEntry WHERE Prototype = 'foobar3';" + ); + stmt->Step(); + EXPECT_EQ(1, stmt->GetInt(0)); +} + +// required to get functionality in cyclus agent unit tests library +cyclus::Agent* GroupInstitutionConstructor(cyclus::Context* ctx) { + return new cycamore::GroupInst(ctx); +} +#ifndef CYCLUS_AGENT_TESTS_CONNECTED +int ConnectAgentTests(); +static int cyclus_agent_tests_connected = ConnectAgentTests(); +#define CYCLUS_AGENT_TESTS_CONNECTED cyclus_agent_tests_connected +#endif // CYCLUS_AGENT_TESTS_CONNECTED + +INSTANTIATE_TEST_CASE_P(GroupInst, InstitutionTests, + Values(&GroupInstitutionConstructor)); +INSTANTIATE_TEST_CASE_P(GroupInst, AgentTests, + Values(&GroupInstitutionConstructor));