Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

group institution deploying #450

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
30 changes: 30 additions & 0 deletions src/group_inst.cc
Original file line number Diff line number Diff line change
@@ -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);
}
}



// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you also want to be able to decommission the group?

extern "C" cyclus::Agent* ConstructGroupInst(cyclus::Context* ctx) {
return new GroupInst(ctx);
}

} // namespace cycamore
51 changes: 51 additions & 0 deletions src/group_inst.h
Original file line number Diff line number Diff line change
@@ -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"}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same description that is in manager_inst. Some clarification of about what distinguishes the two would be helpful.


/// 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<std::string> prototypes;
};

} // namespace cycamore

#endif // CYCAMORE_SRC_MANAGER_INST_H_
56 changes: 56 additions & 0 deletions src/group_inst_tests.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include <gtest/gtest.h>

#include "context.h"
#include "group_inst.h"
#include "institution_tests.h"
#include "agent_tests.h"


TEST(GroupInstTests, BuildTimes) {
std::string config =
" <prototypes>"
" <val>foobar1</val>"
" <val>foobar2</val>"
" <val>foobar3</val>"
" </prototypes>"
;

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));