mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 14:15:42 -04:00
Merge pull request #1199 from pshriwise/dagmc_assign_by_name
DAGMC material assignment by name.
This commit is contained in:
commit
8dc5a56a4f
4 changed files with 55 additions and 9 deletions
|
|
@ -4,10 +4,11 @@
|
|||
#include "openmc/constants.h"
|
||||
#include "openmc/error.h"
|
||||
#include "openmc/file_utils.h"
|
||||
#include "openmc/geometry.h"
|
||||
#include "openmc/geometry_aux.h"
|
||||
#include "openmc/material.h"
|
||||
#include "openmc/string_utils.h"
|
||||
#include "openmc/settings.h"
|
||||
#include "openmc/geometry.h"
|
||||
|
||||
#ifdef DAGMC
|
||||
|
||||
|
|
@ -88,6 +89,53 @@ bool write_uwuw_materials_xml() {
|
|||
return found_uwuw_mats;
|
||||
}
|
||||
|
||||
void legacy_assign_material(const std::string& mat_string, DAGCell* c)
|
||||
{
|
||||
bool mat_found_by_name = false;
|
||||
// attempt to find a material with a matching name
|
||||
for (const auto& m : model::materials) {
|
||||
if (mat_string == m->name_) {
|
||||
// assign the material with that name
|
||||
if (!mat_found_by_name) {
|
||||
mat_found_by_name = true;
|
||||
c->material_.push_back(m->id_);
|
||||
// report error if more than one material is found
|
||||
} else {
|
||||
std::stringstream err_msg;
|
||||
err_msg << "More than one material found with name " << mat_string
|
||||
<< ". Please ensure materials have unique names if using this"
|
||||
<< " property to assign materials.";
|
||||
fatal_error(err_msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if no material was set using a name, assign by id
|
||||
if (!mat_found_by_name) {
|
||||
try {
|
||||
auto id = std::stoi(mat_string);
|
||||
c->material_.emplace_back(id);
|
||||
} catch (const std::invalid_argument&) {
|
||||
std::stringstream err_msg;
|
||||
err_msg << "No material " << mat_string
|
||||
<< " found for volume (cell) " << c->id_;
|
||||
fatal_error(err_msg);
|
||||
}
|
||||
}
|
||||
|
||||
if (settings::verbosity >= 10) {
|
||||
Material* m = model::materials[model::material_map[c->material_[0]]].get();
|
||||
std::stringstream msg;
|
||||
msg << "DAGMC material " << mat_string << " was assigned";
|
||||
if (mat_found_by_name) {
|
||||
msg << " using material name: " << m->name_;
|
||||
} else {
|
||||
msg << " using material id: " << m->id_;
|
||||
}
|
||||
write_message(msg.str(), 10);
|
||||
}
|
||||
}
|
||||
|
||||
void load_dagmc_geometry()
|
||||
{
|
||||
if (!model::DAG) {
|
||||
|
|
@ -188,7 +236,7 @@ void load_dagmc_geometry()
|
|||
size_t _comp_pos = mat_value.find(_comp);
|
||||
if (_comp_pos != std::string::npos) { mat_value.erase(_comp_pos, _comp.length()); }
|
||||
// assign IC material by id
|
||||
c->material_.push_back(std::stoi(mat_value));
|
||||
legacy_assign_material(mat_value, c);
|
||||
}
|
||||
} else {
|
||||
// if no material is found, the implicit complement is void
|
||||
|
|
@ -235,9 +283,7 @@ void load_dagmc_geometry()
|
|||
fatal_error(err_msg);
|
||||
}
|
||||
} else {
|
||||
// if not using UWUW materials, we'll find this material
|
||||
// later in the materials.xml
|
||||
c->material_.push_back(std::stoi(mat_value));
|
||||
legacy_assign_material(mat_value, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1,10 +1,10 @@
|
|||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<materials>
|
||||
<material depletable="true" id="40">
|
||||
<material depletable="true" id="40" name="fuel">
|
||||
<density units="g/cc" value="11" />
|
||||
<nuclide ao="1.0" name="U235" />
|
||||
</material>
|
||||
<material id="41">
|
||||
<material id="41" name="water">
|
||||
<density units="g/cc" value="1.0" />
|
||||
<nuclide ao="2.0" name="H1" />
|
||||
<nuclide ao="1.0" name="O16" />
|
||||
|
|
|
|||
|
|
@ -30,12 +30,12 @@ def test_dagmc():
|
|||
model.tallies = [tally]
|
||||
|
||||
# materials
|
||||
u235 = openmc.Material()
|
||||
u235 = openmc.Material(name="fuel")
|
||||
u235.add_nuclide('U235', 1.0, 'ao')
|
||||
u235.set_density('g/cc', 11)
|
||||
u235.id = 40
|
||||
|
||||
water = openmc.Material()
|
||||
water = openmc.Material(name="water")
|
||||
water.add_nuclide('H1', 2.0, 'ao')
|
||||
water.add_nuclide('O16', 1.0, 'ao')
|
||||
water.set_density('g/cc', 1.0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue