mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 06:05:58 -04:00
Support for NCrystal material in from_xml_element (#2496)
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
This commit is contained in:
parent
e3cd406a9b
commit
3e1a5a552a
2 changed files with 30 additions and 0 deletions
|
|
@ -1452,6 +1452,11 @@ class Material(IDManagerMixin):
|
|||
|
||||
"""
|
||||
mat_id = int(elem.get('id'))
|
||||
# Add NCrystal material from cfg string
|
||||
if "cfg" in elem.attrib:
|
||||
cfg = elem.get("cfg")
|
||||
return Material.from_ncrystal(cfg, material_id=mat_id)
|
||||
|
||||
mat = cls(mat_id)
|
||||
mat.name = elem.get('name')
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
from math import pi
|
||||
import filecmp
|
||||
from difflib import unified_diff
|
||||
|
||||
import numpy as np
|
||||
import openmc
|
||||
|
|
@ -78,3 +80,26 @@ def test_ncrystal():
|
|||
test = pencil_beam_model(cfg, E0, n_particles)
|
||||
harness = NCrystalTest('statepoint.10.h5', model=test)
|
||||
harness.main()
|
||||
|
||||
|
||||
def test_cfg_from_xml():
|
||||
"""Make sure the cfg string is read by from_xml method"""
|
||||
n_particles = 100000
|
||||
E0 = 0.012 # eV
|
||||
cfg = 'Al_sg225.ncmat'
|
||||
model = pencil_beam_model(cfg, E0, n_particles)
|
||||
#export the original material generated with cfg string
|
||||
model.materials.export_to_xml('materials.xml.orig')
|
||||
expected = open('materials.xml.orig', 'r').readlines()
|
||||
#read back the original material
|
||||
mats_from_xml = openmc.Materials.from_xml('materials.xml.orig')
|
||||
#export again
|
||||
mats_from_xml.export_to_xml('materials.xml.after')
|
||||
actual = open('materials.xml.after', 'r').readlines()
|
||||
compare = filecmp.cmp('materials.xml.orig','materials.xml.after')
|
||||
if not compare:
|
||||
diff = unified_diff(expected, actual, 'materials.xml.orig',
|
||||
'materials.xml.after')
|
||||
print('Input differences:')
|
||||
print(''.join(diff))
|
||||
assert compare, 'Materials not read correctly from XML'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue