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

Update Position #502

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
19 changes: 5 additions & 14 deletions src/deploy_inst.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ DeployInst::DeployInst(cyclus::Context* ctx)
: cyclus::Institution(ctx),
latitude(0.0),
longitude(0.0),
coordinates(latitude, longitude) {}
coordinates(0,0) {}
Copy link
Member

Choose a reason for hiding this comment

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

Should this be updated to match the last commit to the cyclus repo where these are initialized in the header/snippet?


DeployInst::~DeployInst() {}

Expand Down Expand Up @@ -48,6 +48,10 @@ void DeployInst::Build(cyclus::Agent* parent) {

void DeployInst::EnterNotify() {
cyclus::Institution::EnterNotify();

coordinates = cyclus::toolkit::Position(latitude, longitude);
coordinates.RecordPosition(this);

int n = prototypes.size();
if (build_times.size() != n) {
std::stringstream ss;
Expand All @@ -65,19 +69,6 @@ void DeployInst::EnterNotify() {
<< " lifetimes vals, expected " << n;
throw cyclus::ValueError(ss.str());
}
RecordPosition();
}

void DeployInst::RecordPosition() {
std::string specification = this->spec();
context()
->NewDatum("AgentPosition")
->AddVal("Spec", specification)
->AddVal("Prototype", this->prototype())
->AddVal("AgentId", id())
->AddVal("Latitude", latitude)
->AddVal("Longitude", longitude)
->Record();
}

extern "C" cyclus::Agent* ConstructDeployInst(cyclus::Context* ctx) {
Expand Down
25 changes: 4 additions & 21 deletions src/deploy_inst.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ typedef std::map<int, std::vector<std::string> > BuildSched;
// lifetimes. The same prototype can be specified multiple times with any
// combination of the same or different build times, build number, and
// lifetimes.
class DeployInst : public cyclus::Institution,
public cyclus::toolkit::Position {
class DeployInst : public cyclus::Institution {
#pragma cyclus note { \
"doc": \
"Builds and manages agents (facilities) according to a manually" \
Expand Down Expand Up @@ -84,26 +83,10 @@ class DeployInst : public cyclus::Institution,
std::vector<int> lifetimes;

private:
#pragma cyclus var { \
"default": 0.0, \
"uilabel": "Geographical latitude in degrees as a double", \
"doc": "Latitude of the agent's geographical position. The value should " \
"be expressed in degrees as a double." \
}
double latitude;

#pragma cyclus var { \
"default": 0.0, \
"uilabel": "Geographical longitude in degrees as a double", \
"doc": "Longitude of the agent's geographical position. The value should " \
"be expressed in degrees as a double." \
}
double longitude;

cyclus::toolkit::Position coordinates;

// Adds required header to add geographic coordinates to the archetype
#include "toolkit/position.cycpp.h"

/// Records an agent's latitude and longitude to the output db
void RecordPosition();
};

} // namespace cycamore
Expand Down
4 changes: 2 additions & 2 deletions src/deploy_inst_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ TEST(DeployInstTests, NoDupProtos) {
EXPECT_EQ(1, stmt->GetInt(0));
}

TEST(DeployInstTests, PositionInitialize) {
TEST(DeployInstTests, PositionDefault) {
std::string config =
"<prototypes> <val>foobar</val> </prototypes>"
"<build_times> <val>1</val> </build_times>"
Expand All @@ -158,7 +158,7 @@ TEST(DeployInstTests, PositionInitialize) {
EXPECT_EQ(qr.GetVal<double>("Longitude"), 0.0);
}

TEST(DeployInstTests, PositionInitialize2) {
TEST(DeployInstTests, PositionInitialize) {
std::string config =
"<prototypes> <val>foobar</val> </prototypes>"
"<longitude> -20.0 </longitude>"
Expand Down
26 changes: 10 additions & 16 deletions src/enrichment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Enrichment::Enrichment(cyclus::Context* ctx)
order_prefs(true),
latitude(0.0),
longitude(0.0),
coordinates(latitude, longitude) {}
coordinates(0,0) {}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Enrichment::~Enrichment() {}
Expand Down Expand Up @@ -55,11 +55,18 @@ void Enrichment::Build(cyclus::Agent* parent) {
LOG(cyclus::LEV_DEBUG2, "EnrFac") << "Enrichment "
<< " entering the simuluation: ";
LOG(cyclus::LEV_DEBUG2, "EnrFac") << str();
RecordPosition();
}

void Enrichment::EnterNotify() {
cyclus::Facility::EnterNotify();

coordinates = cyclus::toolkit::Position(latitude, longitude);
coordinates.RecordPosition(this);

}

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

}
Expand Down Expand Up @@ -468,19 +475,6 @@ double Enrichment::FeedAssay() {
return cyclus::toolkit::UraniumAssayMass(fission_matl);
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Enrichment::RecordPosition() {
std::string specification = this->spec();
context()
->NewDatum("AgentPosition")
->AddVal("Spec", specification)
->AddVal("Prototype", this->prototype())
->AddVal("AgentId", id())
->AddVal("Latitude", latitude)
->AddVal("Longitude", longitude)
->Record();
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
extern "C" cyclus::Agent* ConstructEnrichment(cyclus::Context* ctx) {
return new Enrichment(ctx);
Expand Down
26 changes: 5 additions & 21 deletions src/enrichment.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ class NatUConverter : public cyclus::Converter<cyclus::Material> {
/// no associated recipe. Bids for tails are constrained only by total
/// tails inventory.

class Enrichment
: public cyclus::Facility,
public cyclus::toolkit::Position {
class Enrichment : public cyclus::Facility {
#pragma cyclus note { \
"niche": "enrichment facility", \
"doc": \
Expand Down Expand Up @@ -172,6 +170,7 @@ class Enrichment
/// perform module-specific tasks when entering the simulation
virtual void Build(cyclus::Agent* parent);
// ---
virtual void EnterNotify();

// --- Agent Members ---
/// Each facility is prompted to do its beginning-of-time-step
Expand Down Expand Up @@ -380,26 +379,11 @@ class Enrichment
double intra_timestep_swu_;
double intra_timestep_feed_;

friend class EnrichmentTest;
// ---

#pragma cyclus var { \
"default": 0.0, \
"uilabel": "Geographical latitude in degrees as a double", \
"doc": "Latitude of the agent's geographical position. The value should " \
"be expressed in degrees as a double." \
}
double latitude;
// Adds required header to add geographic coordinates to the archetype
#include "toolkit/position.cycpp.h"

#pragma cyclus var { \
"default": 0.0, \
"uilabel": "Geographical longitude in degrees as a double", \
"doc": "Longitude of the agent's geographical position. The value should " \
"be expressed in degrees as a double." \
}
double longitude;
friend class EnrichmentTest;

cyclus::toolkit::Position coordinates;
};

} // namespace cycamore
Expand Down
4 changes: 2 additions & 2 deletions src/enrichment_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ TEST_F(EnrichmentTest, Response) {
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TEST_F(EnrichmentTest, PositionInitialize) {
TEST_F(EnrichmentTest, PositionDefault) {
// this tests verifies the initialization of the latitude variable

std::string config =
Expand All @@ -752,7 +752,7 @@ TEST_F(EnrichmentTest, PositionInitialize) {
EXPECT_EQ(qr.GetVal<double>("Longitude"), 0.0);
}

TEST_F(EnrichmentTest, PositionInitialize2) {
TEST_F(EnrichmentTest, PositionInitialize) {
// this tests verifies the initialization of the longitude
// variable

Expand Down
26 changes: 8 additions & 18 deletions src/fuel_fab.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,19 @@ class TopupConverter : public cyclus::Converter<cyclus::Material> {
};

FuelFab::FuelFab(cyclus::Context* ctx)
: cyclus::Facility(ctx),
fill_size(0),
fiss_size(0),
: cyclus::Facility(ctx),
fill_size(0),
fiss_size(0),
throughput(0),
latitude(0.0),
longitude(0.0),
coordinates(latitude, longitude) {}
coordinates(0,0) {}

void FuelFab::EnterNotify() {
cyclus::Facility::EnterNotify();

coordinates = cyclus::toolkit::Position(latitude, longitude);
coordinates.RecordPosition(this);

if (fiss_commod_prefs.empty()) {
for (int i = 0; i < fiss_commods.size(); i++) {
Expand All @@ -163,7 +166,6 @@ void FuelFab::EnterNotify() {
<< " fill_commod_prefs vals, expected " << fill_commods.size();
throw cyclus::ValidationError(ss.str());
}
RecordPosition();
}

std::set<cyclus::RequestPortfolio<Material>::Ptr> FuelFab::GetMatlRequests() {
Expand Down Expand Up @@ -397,7 +399,7 @@ void FuelFab::GetMatlTrades(
responses) {
using cyclus::Trade;

// guard against cases where a buffer is empty - this is okay because some
// guard against cases where a buffer is empty - this is okay because some
// trades may not need that particular buffer.
double w_fill = 0;
if (fill.count() > 0) {
Expand Down Expand Up @@ -495,18 +497,6 @@ void FuelFab::GetMatlTrades(
}
}

void FuelFab::RecordPosition() {
std::string specification = this->spec();
context()
->NewDatum("AgentPosition")
->AddVal("Spec", specification)
->AddVal("Prototype", this->prototype())
->AddVal("AgentId", id())
->AddVal("Latitude", latitude)
->AddVal("Longitude", longitude)
->Record();
}

extern "C" cyclus::Agent* ConstructFuelFab(cyclus::Context* ctx) {
return new FuelFab(ctx);
}
Expand Down
25 changes: 3 additions & 22 deletions src/fuel_fab.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ namespace cycamore {
/// uranium isotopes in fast reactors." Proceedings of the Conference on
/// Breeding. Economics, and Safety in Large Fast Power Reactors. 1963.
/// @endcode
class FuelFab
: public cyclus::Facility,
public cyclus::toolkit::Position {
class FuelFab : public cyclus::Facility {
#pragma cyclus note { \
"niche": "fabrication", \
"doc": \
Expand Down Expand Up @@ -253,26 +251,9 @@ class FuelFab
// map<request, inventory name>
std::map<cyclus::Request<cyclus::Material>*, std::string> req_inventories_;

#pragma cyclus var { \
"default": 0.0, \
"uilabel": "Geographical latitude in degrees as a double", \
"doc": "Latitude of the agent's geographical position. The value should " \
"be expressed in degrees as a double." \
}
double latitude;

#pragma cyclus var { \
"default": 0.0, \
"uilabel": "Geographical longitude in degrees as a double", \
"doc": "Longitude of the agent's geographical position. The value should " \
"be expressed in degrees as a double." \
}
double longitude;

cyclus::toolkit::Position coordinates;
// Adds required header to add geographic coordinates to the archetype
#include "toolkit/position.cycpp.h"

/// Records an agent's latitude and longitude to the output db
void RecordPosition();
};

double CosiWeight(cyclus::Composition::Ptr c, const std::string& spectrum);
Expand Down
4 changes: 2 additions & 2 deletions src/fuel_fab_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ TEST(FuelFabTests, HomogenousBuffers) {
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TEST(FuelFabTests, PositionInitialize) {
TEST(FuelFabTests, PositionDefault) {
cyclus::Env::SetNucDataPath();
std::string config =
"<fill_commods> <val>natu</val> </fill_commods>"
Expand Down Expand Up @@ -937,7 +937,7 @@ TEST(FuelFabTests, PositionInitialize) {
EXPECT_EQ(qr.GetVal<double>("Longitude"), 0.0);
}

TEST(FuelFabTests, PositionInitialize2) {
TEST(FuelFabTests, PositionInitialize) {
cyclus::Env::SetNucDataPath();
std::string config =
"<fill_commods> <val>natu</val> </fill_commods>"
Expand Down
22 changes: 7 additions & 15 deletions src/growth_region.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ GrowthRegion::GrowthRegion(cyclus::Context* ctx)
: cyclus::Region(ctx),
latitude(0.0),
longitude(0.0),
coordinates(latitude, longitude) {
#if !CYCLUS_HAS_COIN
coordinates(0,0) {
#if !CYCLUS_HAS_COIN
throw cyclus::Error("Growth Region requires that Cyclus & Cycamore be compiled "
"with COIN support.");
#endif
#endif
}

GrowthRegion::~GrowthRegion() {}
Expand Down Expand Up @@ -41,6 +41,10 @@ void GrowthRegion::AddCommodityDemand_(std::string commod,

void GrowthRegion::EnterNotify() {
cyclus::Region::EnterNotify();

coordinates = cyclus::toolkit::Position(latitude, longitude);
coordinates.RecordPosition(this);

std::set<cyclus::Agent*>::iterator ait;
for (ait = cyclus::Agent::children().begin();
ait != cyclus::Agent::children().end();
Expand All @@ -55,7 +59,6 @@ void GrowthRegion::EnterNotify() {
<< it->first;
AddCommodityDemand_(it->first, it->second);
}
RecordPosition();
}

void GrowthRegion::DecomNotify(Agent* a) {
Expand Down Expand Up @@ -174,17 +177,6 @@ void GrowthRegion::OrderBuilds(cyclus::toolkit::Commodity& commodity,
#endif
}

void GrowthRegion::RecordPosition() {
std::string specification = this->spec();
context()
->NewDatum("AgentPosition")
->AddVal("Spec", specification)
->AddVal("Prototype", this->prototype())
->AddVal("AgentId", id())
->AddVal("Latitude", latitude)
->AddVal("Longitude", longitude)
->Record();
}

extern "C" cyclus::Agent* ConstructGrowthRegion(cyclus::Context* ctx) {
return new GrowthRegion(ctx);
Expand Down
Loading