-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a context helper for a facility with many input and output reci…
…pes and commodities
- Loading branch information
Showing
6 changed files
with
164 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include <utility> | ||
|
||
#include "commodity_recipe_context.h" | ||
|
||
namespace cyclus { | ||
|
||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
void CommodityRecipeContext::AddInCommod( | ||
std::string in_commod, | ||
std::string in_recipe, | ||
std::string out_commod, | ||
std::string out_recipe) { | ||
|
||
in_commods_.push_back(in_commod); | ||
out_commods_.push_back(out_commod); | ||
out_commod_map_.insert(std::make_pair(in_commod, out_commod)); | ||
in_recipes_.insert(std::make_pair(in_commod, in_recipe)); | ||
out_recipes_.insert(std::make_pair(in_recipe, out_recipe)); | ||
} | ||
|
||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
void CommodityRecipeContext::AddMat(std::string commod, Material::Ptr mat) { | ||
mat_commod_map_.insert(std::make_pair(mat, commod)); | ||
} | ||
|
||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
void CommodityRecipeContext::RemoveMat(Material::Ptr mat) { | ||
mat_commod_map_.erase(mat); | ||
} | ||
|
||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
void CommodityRecipeContext::UpdateMat(std::string commod, Material::Ptr mat) { | ||
mat_commod_map_[mat] = commod; | ||
} | ||
|
||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
void CommodityRecipeContext::UpdateInRec( | ||
std::string incommod, | ||
std::string recipe) { | ||
out_recipes_[recipe] = out_recipes_[in_recipes_[incommod]]; | ||
in_recipes_[incommod] = recipe; | ||
} | ||
|
||
} // namespace cyclus |
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,79 @@ | ||
#ifndef CYCLUS_COMMODITY_RECIPE_CONTEXT_H_ | ||
#define CYCLUS_COMMODITY_RECIPE_CONTEXT_H_ | ||
|
||
#include <map> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "material.h" | ||
|
||
namespace cyclus { | ||
|
||
/// @class CommodityRecipeContext | ||
/// | ||
/// @brief a CommodityRecipeContext contains relationships between commodities, | ||
/// recipes and materials | ||
class CommodityRecipeContext { | ||
public: | ||
/// @brief add an input commodity and its relations | ||
void AddInCommod( | ||
std::string in_commod, | ||
std::string in_recipe, | ||
std::string out_commod, | ||
std::string out_recipe); | ||
|
||
/// @brief add a material and its commodity affiliation | ||
void AddMat(std::string commod, Material::Ptr mat); | ||
|
||
/// @brief update a material and its commodity affiliation | ||
void UpdateMat(std::string commod, Material::Ptr mat); | ||
|
||
/// @brief removes a material from the context | ||
void RemoveMat(Material::Ptr mat); | ||
|
||
/// @brief update an input recipe and its commodity affiliation | ||
void UpdateInRec(std::string in_commod, std::string recipe); | ||
|
||
/// @return input commodities | ||
inline const std::vector<std::string>& in_commods() const { | ||
return in_commods_; | ||
} | ||
|
||
/// @return output commodities | ||
inline const std::vector<std::string>& out_commods() const { | ||
return out_commods_; | ||
} | ||
|
||
/// @return output commodity of an input commodity | ||
inline std::string out_commod(std::string in_commod) { | ||
return out_commod_map_[in_commod]; | ||
} | ||
|
||
/// @return input recipe of an input commodity | ||
inline std::string in_recipe(std::string in_commod) { | ||
return in_recipes_[in_commod]; | ||
} | ||
|
||
/// @return output recipe of an input recipe | ||
inline std::string out_recipe(std::string in_recipe) { | ||
return out_recipes_[in_recipe]; | ||
} | ||
|
||
/// @return commodity of a material | ||
/// @warning returns a blank string if material isn't found | ||
inline std::string commod(Material::Ptr mat) { | ||
return mat_commod_map_[mat]; | ||
} | ||
|
||
private: | ||
std::vector<std::string> in_commods_; | ||
std::vector<std::string> out_commods_; | ||
std::map<std::string, std::string> out_commod_map_; | ||
std::map<std::string, std::string> in_recipes_; | ||
std::map<std::string, std::string> out_recipes_; | ||
std::map<Material::Ptr, std::string> mat_commod_map_; | ||
}; | ||
|
||
} // namespace cyclus | ||
|
||
#endif // CYCLUS_COMMODITY_RECIPE_CONTEXT_H_ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <gtest/gtest.h> | ||
|
||
#include "commodity_recipe_context.h" | ||
|
||
namespace cyclus { | ||
|
||
TEST(CommodRecCtx, All) { | ||
std::string in_c = "in_c"; | ||
std::string out_c = "out_c"; | ||
std::string in_r = "in_r"; | ||
std::string out_r = "out_r"; | ||
|
||
std::string in_r2 = "in_r2"; | ||
|
||
Material::Ptr mat = Material::CreateBlank(42); | ||
|
||
CommodityRecipeContext ctx; | ||
ctx.AddInCommod(in_c, in_r, out_c, out_r); | ||
EXPECT_EQ(ctx.out_commod(in_c), out_c); | ||
EXPECT_EQ(ctx.in_recipe(in_c), in_r); | ||
EXPECT_EQ(ctx.out_recipe(in_r), out_r); | ||
|
||
ctx.UpdateInRec(in_c, in_r2); | ||
EXPECT_EQ(ctx.in_recipe(in_c), in_r2); | ||
EXPECT_EQ(ctx.out_recipe(in_r), out_r); | ||
EXPECT_EQ(ctx.out_recipe(in_r2), out_r); | ||
|
||
ctx.AddMat(in_c, mat); | ||
EXPECT_EQ(ctx.commod(mat), in_c); | ||
ctx.UpdateMat(out_c, mat); | ||
EXPECT_EQ(ctx.commod(mat), out_c); | ||
ctx.RemoveMat(mat); | ||
EXPECT_EQ(ctx.commod(mat), ""); | ||
|
||
} | ||
|
||
} // namespace cyclus |