Adding UWUW workflow support and test.

This commit is contained in:
Patrick Shriwise 2018-12-03 21:44:25 -06:00
parent 5c7e8a9cf8
commit f1bc9f76b0
11 changed files with 152 additions and 29 deletions

View file

@ -2,6 +2,7 @@
#include "openmc/cell.h"
#include "openmc/error.h"
#include "openmc/file_utils.h"
#include "openmc/string_utils.h"
#include "openmc/settings.h"
#include "openmc/geometry.h"
@ -9,9 +10,15 @@
#include <string>
#include <sstream>
#include <algorithm>
#include <fstream>
#ifdef DAGMC
#include "uwuw.hpp"
#include "dagmcmetadata.hpp"
#define DAGMC_FILENAME "dagmc.h5m"
namespace openmc {
namespace model {
@ -20,28 +27,65 @@ moab::DagMC* DAG;
} // namespace model
bool write_materials_xml(UWUW uwuw) {
// if there is a material library in the file,
// write a material.xml file
std::ofstream mats_xml("materials.xml");
// write header
mats_xml << "<?xml version=\"1.0\"?>\n";
mats_xml << "<materials>\n";
std::map<std::string, pyne::Material> ml = uwuw.material_library;
std::map<std::string, pyne::Material>::iterator it;
// write materials
for (it = ml.begin(); it != ml.end(); it++) { mats_xml << it->second.openmc("atom"); }
// write footer
mats_xml << "</materials>";
mats_xml.close();
}
void load_dagmc_geometry()
{
if (!model::DAG) {
model::DAG = new moab::DagMC();
}
int32_t dagmc_univ_id = 0; // universe is always 0 for DAGMC
// create uwuw instance
UWUW uwuw(DAGMC_FILENAME);
moab::ErrorCode rval = model::DAG->load_file("dagmc.h5m");
// check for uwuw material definitions
bool using_uwuw = (uwuw.material_library.size() == 0) ? false : true;
if (using_uwuw) {
std::cout << "Found UWUW Materials in the DAGMC geometry file." << std::endl;
// don't overwrite an existing materials.xml file
if (file_exists("materials.xml")) {
std::stringstream err_msg;
err_msg << "A materials.xml file is present along with UWUW material definitions";
fatal_error(err_msg.str());
}
write_materials_xml(uwuw);
}
int32_t dagmc_univ_id = 0; // universe is always 0 for DAGMC runs
moab::ErrorCode rval = model::DAG->load_file(DAGMC_FILENAME);
MB_CHK_ERR_CONT(rval);
rval = model::DAG->init_OBBTree();
MB_CHK_ERR_CONT(rval);
std::vector<std::string> prop_keywords;
prop_keywords.push_back("mat");
prop_keywords.push_back("boundary");
std::map<std::string, std::string> ph;
model::DAG->parse_properties(prop_keywords, ph, ":");
MB_CHK_ERR_CONT(rval);
dagmcMetaData DMD(model::DAG);
if (using_uwuw) {
DMD.load_property_data();
}
std::vector<std::string> keywords;
keywords.push_back("mat");
keywords.push_back("density");
keywords.push_back("boundary");
std::map<std::string, std::string> dum;
rval = model::DAG->parse_properties(keywords, dum, ":/");
// initialize cell objects
model::n_cells = model::DAG->num_entities(3);
@ -75,22 +119,38 @@ void load_dagmc_geometry()
continue;
}
if (model::DAG->has_prop(vol_handle, "mat")){
std::string mat_value;
std::string mat_value;
if (model::DAG->has_prop(vol_handle, "mat")) {
rval = model::DAG->prop_value(vol_handle, "mat", mat_value);
MB_CHK_ERR_CONT(rval);
to_lower(mat_value);
if (mat_value == "void" || mat_value == "vacuum") {
c->material_.push_back(MATERIAL_VOID);
} else {
c->material_.push_back(std::stoi(mat_value));
}
} else {
std::stringstream err_msg;
err_msg << "Volume " << c->id_ << " has no material assignment.";
fatal_error(err_msg.str());
}
std::string cmp_str = mat_value;
to_lower(cmp_str);
if (cmp_str.find("void") != std::string::npos ||
cmp_str.find("vacuum") != std::string::npos ||
cmp_str.find("graveyard") != std::string::npos) {
c->material_.push_back(MATERIAL_VOID);
} else {
if (using_uwuw) {
std::string uwuw_mat = DMD.volume_material_property_data_eh[vol_handle];
if (uwuw.material_library.count(uwuw_mat) != 0) {
int matnumber = uwuw.material_library[uwuw_mat].metadata["mat_number"].asInt();
c->material_.push_back(matnumber);
} else {
std::stringstream err_msg;
err_msg << "Material with value " << mat_value << " not found ";
err_msg << "in the material library";
fatal_error(err_msg.str());
}
} else {
c->material_.push_back(std::stoi(mat_value));
}
}
}
// Allocate the cell overlap count if necessary.
@ -110,12 +170,12 @@ void load_dagmc_geometry()
s->id_ = model::DAG->id_by_index(2, i+1);
s->dagmc_ptr_ = model::DAG;
std::string bc_value;
if (model::DAG->has_prop(surf_handle, "boundary")) {
std::string bc_value;
rval = model::DAG->prop_value(surf_handle, "boundary", bc_value);
MB_CHK_ERR_CONT(rval);
to_lower(bc_value);
to_lower(bc_value);
if (bc_value == "transmit" || bc_value == "transmission") {
s->bc_ = BC_TRANSMIT;
} else if (bc_value == "vacuum") {
@ -130,7 +190,7 @@ void load_dagmc_geometry()
<< "\" specified on surface " << s->id_;
fatal_error(err_msg);
}
} else { // if no BC property is found, set to transmit
} else { // if no condition is found, set to transmit
s->bc_ = BC_TRANSMIT;
}

View file

@ -124,9 +124,9 @@ contains
type(VectorReal), allocatable :: sab_temps(:) ! List of T to read for each S(a,b)
call read_settings_xml()
call read_geometry_xml()
call read_cross_sections_xml()
call read_materials_xml()
call read_geometry_xml()
! Convert user IDs -> indices, assign temperatures
call finalize_geometry(nuc_temps, sab_temps)

View file

@ -8,7 +8,6 @@
<density units="g/cc" value="1.0" />
<nuclide ao="2.0" name="H1" />
<nuclide ao="1.0" name="O16" />
<sab name="c_H_in_H2O" />
</material>
</materials>
<?xml version='1.0' encoding='utf-8'?>

View file

@ -1,5 +1,5 @@
k-combined:
1.115067E+00 5.423808E-02
8.847913E-01 1.700903E-02
tally 1:
8.543144E+00
1.530584E+01
8.016189E+00
1.358910E+01

View file

@ -38,7 +38,6 @@ def test_dagmc():
water = openmc.Material()
water.add_nuclide('H1', 2.0, 'ao')
water.add_nuclide('O16', 1.0, 'ao')
water.add_s_alpha_beta('c_H_in_H2O')
water.set_density('g/cc', 1.0)
water.id = 41

View file

Binary file not shown.

View file

@ -0,0 +1,23 @@
<?xml version='1.0' encoding='utf-8'?>
<settings>
<run_mode>eigenvalue</run_mode>
<particles>100</particles>
<batches>5</batches>
<inactive>0</inactive>
<source strength="1.0">
<space type="box">
<parameters>-4 -4 -4 4 4 4</parameters>
</space>
</source>
<dagmc>true</dagmc>
</settings>
<?xml version='1.0' encoding='utf-8'?>
<tallies>
<filter id="1" type="cell">
<bins>1</bins>
</filter>
<tally id="1">
<filters>1</filters>
<scores>total</scores>
</tally>
</tallies>

View file

@ -0,0 +1 @@
../dagmc/results_true.dat

View file

@ -0,0 +1,41 @@
import openmc
import openmc.capi
from openmc.stats import Box
from openmc.material import Materials
import pytest
from tests.testing_harness import PyAPITestHarness
pytestmark = pytest.mark.skipif(
not openmc.capi.dagmc_enabled,
reason="DAGMC CAD geometry is not enabled.")
class UWUWTest(PyAPITestHarness):
def _build_inputs(self):
model = openmc.model.Model()
# settings
model.settings.batches = 5
model.settings.inactive = 0
model.settings.particles = 100
source = openmc.Source(space=Box([-4, -4, -4],
[ 4, 4, 4]))
model.settings.source = source
model.settings.dagmc = True
model.settings.export_to_xml()
# tally
tally = openmc.Tally()
tally.scores = ['total']
tally.filters = [openmc.CellFilter(1)]
model.tallies = [tally]
model.tallies.export_to_xml()
def test_uwuw():
harness = UWUWTest('statepoint.5.h5')
harness._build_inputs()