9#include <boost/filesystem.hpp>
10#include <libxml++/libxml++.h>
28namespace fs = boost::filesystem;
33 throw IOError(
"The file '" +
file +
"' could not be loaded.");
44 inext = fs::path(
file).extension().string();
58 std::stringstream
input;
64 std::stringstream
input;
70 std::vector<AgentSpec>
specs;
71 std::set<std::string>
unique;
73 std::string
p =
"/simulation/archetypes/spec";
74 int n =
xqe.NMatches(
p);
75 for (
int i = 0; i < n; ++i) {
78 specs.push_back(spec);
83 if (
specs.size() == 0) {
84 throw ValidationError(
"failed to parse archetype specs from input file");
95 std::stringstream schema(
"");
97 std::string
master = schema.str();
101 std::map<std::string, std::string>
subschemas;
108 for (
int i = 0; i <
specs.size(); ++i) {
117 std::map<std::string, std::string>::iterator
it;
119 std::string
search_str = std::string(
"@") +
it->first + std::string(
"_REFS@");
121 if (
pos != std::string::npos) {
142 std::string
query =
"nuclide";
145 for (
int i = 0; i <
nnucs; i++) {
170 std::stringstream
input;
175 std::stringstream
ss;
176 parser_->Document()->write_to_stream_formatted(
ss);
211 std::string
query =
"/*/commodity";
219 name =
qe->GetString(
"name");
225 std::map<std::string, double>::iterator
it;
229 ->
AddVal(
"SolutionPriority",
it->second)
236 string coinor =
"coin-or";
239 if (
xqe.NMatches(
"/*/control/solver") == 1) {
240 qe =
xqe.SubTree(
"/*/control/solver");
249 if (
qe->NMatches(std::string(
"exclusive_orders_only")) != 0) {
250 std::stringstream
ss;
251 ss <<
"Use of 'exclusive_orders_only' is deprecated."
252 <<
" Please see http://fuelcycle.org/user/input_specs/control.html";
258 std::stringstream
ss;
259 ss <<
"You have set allow_exclusive_orders to False."
260 <<
" Many archetypes (e.g., :cycamore:Reactor) will not work"
261 <<
" as intended with this feature turned off.";
267 ->
AddVal(
"ExclusiveOrders", exclusive)
272 query = string(
"/*/control/solver/config/greedy/preconditioner");
278 query = string(
"/*/control/solver/config/coin-or/timeout");
280 query = string(
"/*/control/solver/config/coin-or/verbose");
282 query = string(
"/*/control/solver/config/coin-or/mps");
286 ->
AddVal(
"Verbose", verbose)
296 double max = std::max_element(
299 SecondLT< std::pair<std::string, double> >())->second;
304 std::map<std::string, double>::iterator
it;
308 if (
it->second < 1) {
309 it->second = max + 1;
312 <<
" is " <<
it->second;
319 std::string
query =
"/*/recipe";
323 std::string name =
qe->GetString(
"name");
336 std::string
query =
"/*/package";
355 std::string
query =
"/*/transportunit";
373 for (
int i = 0; i <
specs.size(); ++i) {
387 std::string prototype;
388 std::map<std::string, std::string>::iterator
it;
394 std::string alias =
qe->SubTree(
"config")->GetElementName(0);
401 agent->Agent::InfileToDb(
qe,
DbInit(agent,
true));
406 std::vector<Cond>
conds;
408 conds.push_back(
Cond(
"SimTime",
"==",
static_cast<int>(0)));
409 conds.push_back(
Cond(
"AgentId",
"==", agent->
id()));
414 agent->Agent::InitFrom(&pi);
424 for (
int i = 0; i <
nregions; ++i) {
429 int ninsts =
qe->NMatches(
"institution");
430 for (
int j = 0; j <
ninsts; ++j) {
435 int nfac =
qe2->NMatches(
"initialfacilitylist/entry");
436 for (
int k = 0; k <
nfac; ++k) {
440 int number =
atoi(
qe3->GetString(
"number").c_str());
441 for (
int z = 0; z < number; ++z) {
452 if (parent !=
NULL) {
453 parent->BuildNotify(m);
460 std::string
query =
"/*/control";
464 if (
qe->NMatches(
"simhandle") > 0) {
469 std::string
dur_str =
qe->GetString(
"duration");
472 std::string
m0_str =
qe->GetString(
"startmonth");
475 std::string
y0_str =
qe->GetString(
"startyear");
The abstract base class used by all types of agents that live and interact in a simulation.
virtual void InitFrom(QueryableBackend *b)
Intializes an agent's internal state from the database.
virtual void Build(Agent *parent)
Called when the agent enters the smiulation as an active participant and is only ever called once.
virtual std::string schema()
Returns an agent's xml rng schema for initializing from input files.
virtual void InfileToDb(InfileTree *qe, DbInit di)
Translates info for the agent from an input file to the database by reading parameters from the passe...
const std::string kind() const
Returns a string that describes the agent subclass (e.g.
virtual const int id() const
The agent instance's unique ID within a simulation.
A type to represent variable-length array of bytes for dumping to a cyclus output database.
static Ptr CreateFromMass(CompMap v)
Creates a new composition from v with its components having appropriate mass-based ratios.
boost::shared_ptr< Composition > Ptr
static Ptr CreateFromAtom(CompMap v)
Creates a new composition from v with its components having appropriate atom-based ratios.
Wrapper class for QueryableBackends that injects a set of Cond's into every query before being execut...
Represents a condition used to filter rows returned by a query.
A simulation context provides access to necessary simulation-global functions and state.
T * CreateAgent(std::string proto_name)
Create a new agent by cloning the named prototype.
Datum * NewDatum(std::string title)
See Recorder::NewDatum documentation.
void AddPrototype(std::string name, Agent *m)
Adds a prototype to a simulation-wide accessible list, a prototype can not be added more than once.
void DelAgent(Agent *m)
Destructs and cleans up m (and it's children recursively).
void AddRecipe(std::string name, Composition::Ptr c)
Adds a composition recipe to a simulation-wide accessible list.
void AddTransportUnit(std::string name, int fill_min=0, int fill_max=std::numeric_limits< int >::max(), std::string strategy="first")
Adds a transport unit type to a simulation-wide accessible list.
void AddPackage(std::string name, double fill_min=0, double fill_max=std::numeric_limits< double >::max(), std::string strategy="first")
Adds a package type to a simulation-wide accessible list.
void RecordPackage(Package::Ptr)
Records package information.
void InitSim(SimInfo si)
Initializes the simulation time parameters.
Datum * AddVal(const char *field, boost::spirit::hold_any val, std::vector< int > *shape=NULL)
Add an arbitrary field-value pair to the datum.
void Record()
Record this datum to its Recorder.
DbInit provides an interface for agents to record data to the output db that automatically injects th...
static Agent * Make(Context *ctx, AgentSpec spec)
Returns a newly constructed agent for the given module spec.
static const bool kDefaultExclusive
default value to allow exclusive orders or not
for failed reading/writing to files, network connections, etc..
A class for extracting information from a given XML parser.
InfileTree * SubTree(std::string query, int index=0)
populates a child infile based on a query and index
virtual std::string GetString(std::string query, int index=0)
investigates the current status and returns a string representing the content of a query at a given i...
static Ptr & unpackaged()
Wrapper class for QueryableBackends that injects prefix in front of the title/table for every query b...
Interface implemented by backends that support rudimentary querying.
Collects and manages output data generation for the cyclus core and agents during a simulation.
boost::uuids::uuid sim_id()
returns the unique id associated with this cyclus simulation.
void Flush()
Flushes all buffered Datum objects and flushes all registered backends.
Container for a static simulation-global parameters that both describe the simulation and affect its ...
static void Snapshot(Context *ctx)
Records a snapshot of the current state of the simulation being managed by ctx into the simulation's ...
Controls simulation timestepping and inter-timestep phases.
For validating files received via IO.
For values that are too big, too small, etc.
XMLFileLoader(Recorder *r, QueryableBackend *b, std::string schema_file, const std::string input_file="", const std::string format="none", bool ms_print=false)
Create a new loader reading from the xml simulation input file and writing to and initializing the ba...
void LoadPackages()
Loads packages.
void LoadRecipes()
Method to load recipes from either the primary input file or a recipeBook catalog.
std::string format_
the input file format
void LoadControlParams()
Method to load the simulation control parameters.
boost::shared_ptr< XMLParser > parser_
the parser
void LoadSolver()
Method to load the simulation exchange solver.
void LoadSpecs()
Load agent specs from the input file to a map by alias.
bool ms_print_
flag to indicate printing master schema
virtual std::string master_schema()
std::string schema_path_
filepath to the schema
void LoadTransportUnits()
Loads Transport Units.
std::map< std::string, AgentSpec > specs_
virtual void LoadInitialAgents()
Creates all initial agent instances from the input file.
Agent * BuildAgent(std::string proto, Agent *parent)
Creates and builds an agent, notifying its parent.
void ProcessCommodities(std::map< std::string, double > *commodity_priority)
Processes commodity priorities, such that any without a defined priority (i.e., are nonpositive),...
std::string file_
the input file name
virtual void LoadSim()
Load an entire simulation from the inputfile.
A helper class to hold xml file data and provide automatic validation.
void Init(const std::stringstream &input)
initializes a parser with an xml snippet
const uint64_t kDefaultSeed
const uint64_t kDefaultStride
const uint64_t kDefaultTimeStepDur
Code providing rudimentary logging capability for the Cyclus core.
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
void LoadRawStringstreamFromFile(std::stringstream &stream, std::string file)
Reads the given file path into the passed stream without modification.
Composition::Ptr ReadRecipe(InfileTree *qe)
Creates a composition from the recipe in the query engine.
double cy_eps_rsrc
epsilon values to be used by resources
double cy_eps
generic epsilon values
void LoadStringstreamFromFile(std::stringstream &stream, std::string file, std::string format)
Reads the given file path as XML into the passed stream.
@ LEV_DEBUG3
debugging information
@ LEV_INFO1
Information helpful for simulation users and developers alike - least verbose.
std::string BuildMasterSchema(std::string schema_path, std::string infile, std::string format)
Builds and returns a master cyclus input xml schema that includes the sub-schemas defined by all inst...
std::map< Nuc, double > CompMap
a raw definition of nuclides and corresponding (dimensionless quantities).
std::string LoadStringFromFile(std::string file, std::string format)
Reads the given file path and returns an XML string.
double eps()
a generic epsilon value
std::vector< AgentSpec > ParseSpecs(std::string infile, std::string format)
Returns a list of the full module+agent spec for all agents in the given input file.
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters
a less-than comparison for pairs