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

Adding metadata to cycamore archetypes #510

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
9 changes: 7 additions & 2 deletions src/deploy_inst.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ namespace cycamore {

DeployInst::DeployInst(cyclus::Context* ctx)
: cyclus::Institution(ctx),
work_label("DeployedInst"),
latitude(0.0),
longitude(0.0),
coordinates(latitude, longitude) {}
coordinates(latitude, longitude){}

DeployInst::~DeployInst() {}

Expand Down Expand Up @@ -47,7 +48,12 @@ void DeployInst::Build(cyclus::Agent* parent) {
}

void DeployInst::EnterNotify() {
metadata.SetWorkLabel(work_label);
metadata.LoadData(metadata_);
metadata.LoadData(usage_metadata_);

cyclus::Institution::EnterNotify();

int n = prototypes.size();
if (build_times.size() != n) {
std::stringstream ss;
Expand Down Expand Up @@ -79,7 +85,6 @@ void DeployInst::RecordPosition() {
->AddVal("Longitude", longitude)
->Record();
}

extern "C" cyclus::Agent* ConstructDeployInst(cyclus::Context* ctx) {
return new DeployInst(ctx);
}
Expand Down
1 change: 1 addition & 0 deletions src/deploy_inst.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class DeployInst : public cyclus::Institution,

/// Records an agent's latitude and longitude to the output db
void RecordPosition();
#include "toolkit/metadata.cycpp.h"
};

} // namespace cycamore
Expand Down
199 changes: 193 additions & 6 deletions src/deploy_inst_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
using cyclus::QueryResult;

TEST(DeployInstTests, ProtoNames) {
std::string config =
std::string config =
"<prototypes> <val>foobar</val> </prototypes>"
"<build_times> <val>1</val> </build_times>"
"<n_build> <val>3</val> </n_build>"
Expand All @@ -33,7 +33,7 @@ TEST(DeployInstTests, ProtoNames) {
}

TEST(DeployInstTests, BuildTimes) {
std::string config =
std::string config =
"<prototypes> <val>foobar</val> <val>foobar</val> </prototypes>"
"<build_times> <val>1</val> <val>3</val> </build_times>"
"<n_build> <val>1</val> <val>7</val> </n_build>"
Expand All @@ -60,7 +60,7 @@ TEST(DeployInstTests, BuildTimes) {
// make sure that specified lifetimes are honored both in agent's table record
// and in decommissioning.
TEST(DeployInstTests, FiniteLifetimes) {
std::string config =
std::string config =
"<prototypes> <val>foobar</val> <val>foobar</val> <val>foobar</val> </prototypes>"
"<build_times> <val>1</val> <val>1</val> <val>2</val> </build_times>"
"<n_build> <val>1</val> <val>7</val> <val>3</val> </n_build>"
Expand Down Expand Up @@ -113,7 +113,7 @@ TEST(DeployInstTests, FiniteLifetimes) {
}

TEST(DeployInstTests, NoDupProtos) {
std::string config =
std::string config =
"<prototypes> <val>foobar</val> <val>foobar</val> <val>foobar</val> </prototypes>"
"<build_times> <val>1</val> <val>1</val> <val>2</val> </build_times>"
"<n_build> <val>1</val> <val>7</val> <val>3</val> </n_build>"
Expand Down Expand Up @@ -142,7 +142,7 @@ TEST(DeployInstTests, NoDupProtos) {
}

TEST(DeployInstTests, PositionInitialize) {
std::string config =
std::string config =
"<prototypes> <val>foobar</val> </prototypes>"
"<build_times> <val>1</val> </build_times>"
"<n_build> <val>3</val> </n_build>"
Expand All @@ -159,7 +159,7 @@ TEST(DeployInstTests, PositionInitialize) {
}

TEST(DeployInstTests, PositionInitialize2) {
std::string config =
std::string config =
"<prototypes> <val>foobar</val> </prototypes>"
"<longitude> -20.0 </longitude>"
"<latitude> 2.0 </latitude>"
Expand All @@ -177,6 +177,193 @@ TEST(DeployInstTests, PositionInitialize2) {
EXPECT_EQ(qr.GetVal<double>("Longitude"), -20.0);
}

//// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TEST(DeployInstTests, BasicMetadata) {
// this tests verifies the initialization of the latitude variable

std::string config =
"<prototypes> <val>foobar</val> </prototypes>"
"<build_times> <val>1</val> </build_times>"
"<n_build> <val>3</val> </n_build>"
"<lifetimes> <val>2</val> </lifetimes>"
" "
" "
" <metadata>"
" <item> "
" <key>string_key</key>"
" <value>string_value%s</value>"
" </item> "
" <item> "
" <key>double_key</key>"
" <value>0.01254%d</value>"
" </item> "
" <item> "
" <key>int_key</key>"
" <value>-1254%i</value>"
" </item> "
" <item> "
" <key>uint_key</key>"
" <value>1254%u</value>"
" </item> "
" <item> "
" <key>bool_key</key>"
" <value>true%b</value>"
" </item> "
" </metadata>";

int simdur = 1;
cyclus::MockSim sim(cyclus::AgentSpec
(":cycamore:DeployInst"), config, simdur);
sim.DummyProto("foobar");
int id = sim.Run();

std::vector<cyclus::Cond> conds;
QueryResult qr;
conds.push_back(cyclus::Cond("keyword", "==", std::string("string_key")));
qr = sim.db().Query("Metadata", &conds);
EXPECT_EQ(qr.GetVal<std::string>("Value"), "string_value");
EXPECT_EQ(qr.GetVal<std::string>("Type"), "string");

conds[0] = cyclus::Cond("keyword", "==", std::string("double_key"));
qr = sim.db().Query("Metadata", &conds);
EXPECT_EQ(qr.GetVal<std::string>("Value"), "0.012540");
EXPECT_EQ(qr.GetVal<std::string>("Type"), "double");

conds[0] = cyclus::Cond("keyword", "==", std::string("int_key"));
qr = sim.db().Query("Metadata", &conds);
EXPECT_EQ(qr.GetVal<std::string>("Value"), "-1254");
EXPECT_EQ(qr.GetVal<std::string>("Type"), "int");

conds[0] = cyclus::Cond("keyword", "==", std::string("uint_key"));
qr = sim.db().Query("Metadata", &conds);
EXPECT_EQ(qr.GetVal<std::string>("Value"), "1254");
EXPECT_EQ(qr.GetVal<std::string>("Type"), "uint");

conds[0] = cyclus::Cond("keyword", "==", std::string("bool_key"));
qr = sim.db().Query("Metadata", &conds);
EXPECT_EQ(qr.GetVal<std::string>("Value"), "true");
EXPECT_EQ(qr.GetVal<std::string>("Type"), "bool");
}


TEST(DeployInstTests, UsageMetadata) {
// this tests verifies the initialization of the latitude variable

std::string config =
"<prototypes> <val>foobar</val> </prototypes>"
"<build_times> <val>1</val> </build_times>"
"<n_build> <val>3</val> </n_build>"
"<lifetimes> <val>2</val> </lifetimes>"
" "
" "
" <usagemetadata>"
" <item> "
" <keyword>co2</keyword>"
" <usage> "
" <item> "
" <key>decommission</key> "
" <value>25</value> "
" </item> "
" <item> "
" <key>deployment</key> "
" <value>45</value> "
" </item> "
" <item> "
" <key>timestep</key> "
" <value>35</value> "
" </item> "
" <item> "
" <key>throughput</key> "
" <value>15</value> "
" </item> "
" </usage> "
" </item> "
" "
" <item> "
" <keyword>water</keyword>"
" <usage> "
" <item> "
" <key>deployment</key> "
" <value>43</value> "
" </item> "
" </usage> "
" </item> "
" "
" <item> "
" <keyword>land</keyword>"
" <usage> "
" <item> "
" <key>decommission</key> "
" <value>24</value> "
" </item> "
" </usage> "
" </item> "
" "
" <item> "
" <keyword>manpower</keyword>"
" <usage> "
" <item> "
" <key>timestep</key> "
" <value>32</value> "
" </item> "
" </usage> "
" </item> "
" "
" <item> "
" <keyword>lolipop</keyword>"
" <usage> "
" <item> "
" <key>throughput</key> "
" <value>11</value> "
" </item> "
" </usage> "
" </item> "
" </usagemetadata>";

int simdur = 1;
cyclus::MockSim sim(cyclus::AgentSpec
(":cycamore:DeployInst"), config, simdur);
sim.DummyProto("foobar");
int id = sim.Run();

std::vector<cyclus::Cond> conds;
cyclus::QueryResult qr;
conds.push_back(cyclus::Cond("keyword", "==", std::string("co2")));
conds.push_back(cyclus::Cond("Type", "==", std::string("decommission")));
qr = sim.db().Query("Metadata", &conds);
EXPECT_EQ(qr.GetVal<std::string>("Value"), "25.000000");
conds.clear();
conds.push_back(cyclus::Cond("keyword", "==", std::string("co2")));
conds.push_back(cyclus::Cond("Type", "==", std::string("deployment")));
qr = sim.db().Query("Metadata", &conds);
EXPECT_EQ(qr.GetVal<std::string>("Value"), "45.000000");
conds[1] = cyclus::Cond("Type", "==", std::string("timestep"));
qr = sim.db().Query("Metadata", &conds);
EXPECT_EQ(qr.GetVal<std::string>("Value"), "35.000000");
conds[1] = cyclus::Cond("Type", "==", std::string("throughput"));
qr = sim.db().Query("Metadata", &conds);
EXPECT_EQ(qr.GetVal<std::string>("Value"), "15.000000");

conds[0] = cyclus::Cond("keyword", "==", std::string("water"));
conds[1] = cyclus::Cond("Type", "==", std::string("deployment"));
qr = sim.db().Query("Metadata", &conds);
EXPECT_EQ(qr.GetVal<std::string>("Value"), "43.000000");

conds[0] = cyclus::Cond("keyword", "==", std::string("land"));
conds[1] = cyclus::Cond("Type", "==", std::string("decommission"));
qr = sim.db().Query("Metadata", &conds);
EXPECT_EQ(qr.GetVal<std::string>("Value"), "24.000000");

conds[0] = cyclus::Cond("keyword", "==", std::string("manpower"));
conds[1] = cyclus::Cond("Type", "==", std::string("timestep"));
qr = sim.db().Query("Metadata", &conds);
EXPECT_EQ(qr.GetVal<std::string>("Value"), "32.000000");

conds[0] = cyclus::Cond("keyword", "==", std::string("lolipop"));
conds[1] = cyclus::Cond("Type", "==", std::string("throughput"));
qr = sim.db().Query("Metadata", &conds);
EXPECT_EQ(qr.GetVal<std::string>("Value"), "11.000000");
}
// required to get functionality in cyclus agent unit tests library
cyclus::Agent* DeployInstitutionConstructor(cyclus::Context* ctx) {
return new cycamore::DeployInst(ctx);
Expand Down
16 changes: 13 additions & 3 deletions src/enrichment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ Enrichment::Enrichment(cyclus::Context* ctx)
product_commod(""),
tails_commod(""),
order_prefs(true),
work_label("EnrichmentSWU"),
latitude(0.0),
longitude(0.0),
coordinates(latitude, longitude) {}
coordinates(latitude, longitude){}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Enrichment::~Enrichment() {}
Expand All @@ -42,6 +43,15 @@ std::string Enrichment::str() {
return ss.str();
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Enrichment::EnterNotify() {
metadata.SetWorkLabel(work_label);
metadata.LoadData(metadata_);
metadata.LoadData(usage_metadata_);

cyclus::Facility::EnterNotify();
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Enrichment::Build(cyclus::Agent* parent) {
using cyclus::Material;
Expand All @@ -59,9 +69,9 @@ void Enrichment::Build(cyclus::Agent* parent) {
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Enrichment::Tick() {
void Enrichment::Tick() {
current_swu_capacity = SwuCapacity();

}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down
7 changes: 5 additions & 2 deletions src/enrichment.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class NatUConverter : public cyclus::Converter<cyclus::Material> {
/// no associated recipe. Bids for tails are constrained only by total
/// tails inventory.

class Enrichment
class Enrichment
: public cyclus::Facility,
public cyclus::toolkit::Position {
#pragma cyclus note { \
Expand Down Expand Up @@ -173,6 +173,8 @@ class Enrichment
virtual void Build(cyclus::Agent* parent);
// ---

virtual void EnterNotify();

// --- Agent Members ---
/// Each facility is prompted to do its beginning-of-time-step
/// stuff at the tick of the timer.
Expand Down Expand Up @@ -398,8 +400,9 @@ class Enrichment
"be expressed in degrees as a double." \
}
double longitude;

cyclus::toolkit::Position coordinates;

#include "toolkit/metadata.cycpp.h"
};

} // namespace cycamore
Expand Down
Loading