Skip to content

Commit

Permalink
adding setting and tests to check detection of vacuum to avoid regres…
Browse files Browse the repository at this point in the history
…sion
  • Loading branch information
bam241 committed Dec 16, 2024
1 parent 7048bdb commit 2576dfc
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/dagmc/dagmcmetadata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ class dagmcMetaData {
*/
std::map<moab::EntityHandle, std::map<std::string, double>> importance_map;

// Some constant keyword values
// Getting some constant keyword values
const std::string& graveyard_str() const { return graveyard_str_; }
const std::string& vacuum_str() const { return vacuum_str_; }
const std::string& vacuum_mat_str() const { return vacuum_mat_str_; }
Expand All @@ -325,6 +325,12 @@ class dagmcMetaData {
const std::string& white_str() const { return white_str_; }
const std::string& periodic_str() const { return periodic_str_; }

// Allowing modify some constant keyword values
void set_graveyard_str(std::string val) { graveyard_str_ = val; }
void set_vacuum_str(std::string val) { vacuum_str_ = val; }
void set_vacuum_mat_str(std::string val) { vacuum_mat_str_ = val; }
void set_graveyard_mat_str(std::string val) { graveyard_mat_str_ = val; }

// private member variables
private:
/**
Expand Down Expand Up @@ -360,13 +366,14 @@ class dagmcMetaData {
std::map<std::string, std::string> keyword_synonyms;

// Some constant keyword values
const std::string graveyard_str_{"Graveyard"};
const std::string vacuum_str_{"Vacuum"};
const std::string vacuum_mat_str_{"mat:Vacuum"};
const std::string graveyard_mat_str_{"mat:Graveyard"};
const std::string reflecting_str_{"Reflecting"};
const std::string white_str_{"White"};
const std::string periodic_str_{"Periodic"};
// Some less constant keyword values
std::string graveyard_str_{"Graveyard"};
std::string vacuum_str_{"Vacuum"};
std::string vacuum_mat_str_{"mat:Vacuum"};
std::string graveyard_mat_str_{"mat:Graveyard"};

DagMC_Logger logger;
};
Expand Down
58 changes: 58 additions & 0 deletions src/dagmc/tests/dagmc_unit_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,64 @@ TEST_F(DagmcMetadataTest, TestMatAssigns) {
}
}
//---------------------------------------------------------------------------//
// FIXTURE-BASED TESTS: Tests to make sure that all volumes have successfully
// been assigned and successfully retreved from the metadata class
//---------------------------------------------------------------------------//
TEST_F(DagmcMetadataTest, TestVacuumName) {
// Test default behavior for vacuum name
{
// new metadata instance
dgm = std::make_shared<dagmcMetaData>(DAG.get());
// process
dgm->load_property_data();


std::string base_property = "mat:Hydrogen";
std::string impl_comp_prop = "mat:Vacuum";

int num_vol = DAG->num_entities(3);
std::vector<int> vol_ids = {1, 2, 3, 4};

std::vector<std::string> vacuum_names = {"Hydrogen", "Hydrogen", "Hydrogen", "Vacuum"};
for (int id : vol_ids){
std::string mat_prop = dgm->get_volume_property("material", id, false);
EXPECT_EQ(mat_prop, vacuum_names[id-1]);
}
}

// Changing the vacuum name to detect mat:Hydrogen as the vacuum
{
dgm = std::make_shared<dagmcMetaData>(DAG.get());

dgm->set_vacuum_mat_str("mat:Hydrogen");
dgm->load_property_data();
int num_vol = DAG->num_entities(3);
std::vector<int> vol_ids = {1, 2, 3, 4};

std::vector<std::string> vacuum_names = {"Vacuum", "Vacuum", "Vacuum", "Vacuum"};
for (int id : vol_ids){
std::string mat_prop = dgm->get_volume_property("material", id, false);
EXPECT_EQ(mat_prop, vacuum_names[id-1]);
}
}

// Ensuring that partial name overlap don't affect vacuum detection
{
dgm = std::make_shared<dagmcMetaData>(DAG.get());

dgm->set_vacuum_mat_str("Hydro");
dgm->load_property_data();
int num_vol = DAG->num_entities(3);
std::vector<int> vol_ids = {1, 2, 3, 4};

std::vector<std::string> vacuum_names = {"Hydrogen", "Hydrogen", "Hydrogen", "Vacuum"};
for (int id : vol_ids){
std::string mat_prop = dgm->get_volume_property("material", id, false);
EXPECT_EQ(mat_prop, vacuum_names[id-1]);
}
}
}
//---------------------------------------------------------------------------//
// FIXTURE-BASED TESTS: Tests to make sure that all densities have successfully
// been assigned and successfully retreved from the metadata class
// in this test there was no density data assigned, so it should be ""
Expand Down

0 comments on commit 2576dfc

Please sign in to comment.