forked from cyclus/cycamore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'grtest' of https://github.com/gidden/cycamore into gidd…
…en-grtest
- Loading branch information
Showing
7 changed files
with
226 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<?xml version="1.0"?> | ||
<!-- 1 Source Source, 1 Sink Sink --> | ||
|
||
<simulation> | ||
<control> | ||
<duration>4</duration> | ||
<startmonth>1</startmonth> | ||
<startyear>2000</startyear> | ||
</control> | ||
|
||
<commodity> | ||
<name>commodity</name> | ||
</commodity> | ||
|
||
<facility> | ||
<name>Source1</name> | ||
<module> | ||
<lib>cycamore</lib> | ||
<agent>Source</agent> | ||
</module> | ||
<agent> | ||
<Source> | ||
<out_commod>commodity</out_commod> | ||
<recipe_name>commod_recipe</recipe_name> | ||
<capacity>1.1</capacity> | ||
</Source> | ||
</agent> | ||
</facility> | ||
|
||
<facility> | ||
<name>Source2</name> | ||
<module> | ||
<lib>cycamore</lib> | ||
<agent>Source</agent> | ||
</module> | ||
<agent> | ||
<Source> | ||
<out_commod>commodity</out_commod> | ||
<recipe_name>commod_recipe</recipe_name> | ||
<capacity>2</capacity> | ||
</Source> | ||
</agent> | ||
</facility> | ||
|
||
<facility> | ||
<name>Sink</name> | ||
<module> | ||
<lib>cycamore</lib> | ||
<agent>Sink</agent> | ||
</module> | ||
<agent> | ||
<Sink> | ||
<in_commods> | ||
<val>commodity</val> | ||
</in_commods> | ||
</Sink> | ||
</agent> | ||
</facility> | ||
|
||
<region> | ||
<name>SingleRegion</name> | ||
<module> | ||
<lib>cycamore</lib> | ||
<agent>GrowthRegion</agent> | ||
</module> | ||
<allowedfacility>Source1</allowedfacility> | ||
<allowedfacility>Source2</allowedfacility> | ||
<allowedfacility>Sink</allowedfacility> | ||
<agent> | ||
<GrowthRegion> | ||
<commodity_name>commodity</commodity_name> | ||
<demand_types> | ||
<val>linear</val> | ||
</demand_types> | ||
<demand_params> | ||
<val>1 2</val> | ||
</demand_params> | ||
<demand_times> | ||
<val>0</val> | ||
</demand_times> | ||
</GrowthRegion> | ||
</agent> | ||
<institution> | ||
<name>SingleInstitution</name> | ||
<module> | ||
<lib>cycamore</lib> | ||
<agent>ManagerInst</agent> | ||
</module> | ||
<initialfacilitylist> | ||
<entry> | ||
<prototype>Sink</prototype> | ||
<number>1</number> | ||
</entry> | ||
</initialfacilitylist> | ||
<agent> | ||
<ManagerInst> | ||
<prototypes> | ||
<val>Sink</val> | ||
<val>Source1</val> | ||
<val>Source2</val> | ||
</prototypes> | ||
</ManagerInst> | ||
</agent> | ||
</institution> | ||
</region> | ||
|
||
<recipe> | ||
<name>commod_recipe</name> | ||
<basis>mass</basis> | ||
<nuclide> <id>922350000</id> <comp>0.711</comp> </nuclide> | ||
<nuclide> <id>922380000</id> <comp>99.289</comp> </nuclide> | ||
</recipe> | ||
|
||
</simulation> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#! /usr/bin/env python | ||
|
||
from nose.tools import assert_equal, assert_true | ||
import os | ||
import tables | ||
import numpy as np | ||
import uuid | ||
from tools import check_cmd | ||
from helper import table_exist, find_ids | ||
|
||
def test_growth(): | ||
"""Tests GrowthRegion, ManagerInst, and Source over a 4-time step | ||
simulation. | ||
A linear growth demand (y = x + 2) is provided to the growth region. Two | ||
Sources are allowed in the ManagerInst, with capacities of 2 and 1.1, | ||
respectively. At t=1, a 2-capacity Source is expected to be built, and at | ||
t=2 and t=3, 1-capacity Sources are expected to be built. | ||
""" | ||
holdsrtn = [1] # needed because nose does not send() to test generator | ||
sim_input = "./input/growth.xml" | ||
tmp_file = str(uuid.uuid4()) + ".h5" | ||
cmd = ["cyclus", "-o", tmp_file, "--input-file", sim_input] | ||
yield check_cmd, cmd, '.', holdsrtn | ||
rtn = holdsrtn[0] | ||
if rtn != 0: | ||
return # don't execute further commands | ||
|
||
output = tables.open_file(tmp_file, mode = "r") | ||
# Tables of interest | ||
paths = ["/AgentEntry",] | ||
# Check if these tables exist | ||
yield assert_true, table_exist(output, paths) | ||
if not table_exist(output, paths): | ||
output.close() | ||
if os.path.isfile(tmp_file): | ||
print("removing {0}".format(tmp_file)) | ||
os.remove(tmp_file) | ||
return # don't execute further commands | ||
|
||
# Get specific tables and columns | ||
agent_entry = output.get_node("/AgentEntry")[:] | ||
|
||
# Find agent ids of source and sink facilities | ||
agent_ids = agent_entry["AgentId"] | ||
proto = agent_entry["Prototype"] | ||
depl_time = agent_entry["EnterTime"] | ||
|
||
source1_id = find_ids("Source1", proto, agent_ids) | ||
source2_id = find_ids("Source2", proto, agent_ids) | ||
|
||
assert_equal(len(source2_id), 1) | ||
assert_equal(len(source1_id), 2) | ||
|
||
assert_equal(depl_time[np.where(agent_ids == source2_id[0])], 1) | ||
assert_equal(depl_time[np.where(agent_ids == source1_id[0])], 2) | ||
assert_equal(depl_time[np.where(agent_ids == source1_id[1])], 3) | ||
|
||
output.close() | ||
if os.path.isfile(tmp_file): | ||
print("removing {0}".format(tmp_file)) | ||
os.remove(tmp_file) |