CYCLUS
Loading...
Searching...
No Matches
res_manip.cc
Go to the documentation of this file.
1#include "res_manip.h"
2#include "comp_math.h"
3
4namespace cyclus {
5namespace toolkit {
6
7Product::Ptr Squash(std::vector<Product::Ptr> ps) {
8 if (ps.size() == 0) {
9 throw Error("cannot squash zero resources together");
10 }
11
12 Product::Ptr p = ps[0];
13 for (int i = 1; i < ps.size(); ++i) {
14 p->Absorb(ps[i]);
15 }
16 // squash always removes package id (results in default packaging)
17 p->ChangePackage();
18 return p;
19}
20
21Material::Ptr Squash(std::vector<Material::Ptr> ms) {
22 if (ms.size() == 0) {
23 throw Error("cannot squash zero resources together");
24 }
25
26 Material::Ptr m = ms[0];
27 for (int i = 1; i < ms.size(); ++i) {
28 m->Absorb(ms[i]);
29 }
30 m->ChangePackage();
31 return m;
32}
33
34Resource::Ptr Squash(std::vector<Resource::Ptr> rs) {
35 if (rs.size() == 0) {
36 throw Error("cannot squash zero resources together");
37 }
38
39 std::vector<Material::Ptr> mats = ::cyclus::ResCast<Material>(rs);
40 if (mats[0] != NULL) {
41 return Squash(mats);
42 }
43 std::vector<Product::Ptr> prods = ::cyclus::ResCast<Product>(rs);
44 if (prods[0] != NULL) {
45 return Squash(prods);
46 }
47
48 throw Error("cannot squash resource type " + rs[0]->type());
49}
50
51std::vector<Resource::Ptr> ResCast(std::vector<Material::Ptr> rs) {
52 std::vector<Resource::Ptr> casted;
53 for (int i = 0; i < rs.size(); ++i) {
54 casted.push_back(boost::dynamic_pointer_cast<Resource>(rs[i]));
55 }
56 return casted;
57}
58
59std::vector<Resource::Ptr> ResCast(std::vector<Product::Ptr> rs) {
60 std::vector<Resource::Ptr> casted;
61 for (int i = 0; i < rs.size(); ++i) {
62 casted.push_back(boost::dynamic_pointer_cast<Resource>(rs[i]));
63 }
64 return casted;
65}
66
67std::vector<Resource::Ptr> ResCast(std::vector<Resource::Ptr> rs) {
68 return rs;
69}
70
71} // namespace toolkit
72} // namespace cyclus
73
A generic mechanism to manually manage exceptions.
Definition error.h:12
boost::shared_ptr< Material > Ptr
Definition material.h:75
boost::shared_ptr< Product > Ptr
Definition product.h:24
boost::shared_ptr< Resource > Ptr
Definition resource.h:27
Product::Ptr Squash(std::vector< Product::Ptr > ps)
Squash combines all products in ps and returns the resulting single product.
Definition res_manip.cc:7
std::vector< Resource::Ptr > ResCast(std::vector< Material::Ptr > rs)
Casts a vector of Materials into a vector of Resources.
Definition res_manip.cc:51
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
Definition agent.cc:14
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters