@@ -374,6 +374,45 @@ def test_rotation_from_xml(rotation):
374374 np .testing .assert_allclose (new_cell .rotation , cell .rotation )
375375
376376
377+ def test_dagmccell_from_xml_element ():
378+ """DAGMCCell.from_xml_element parses material, temperature, density,
379+ and volume; rejects unsupported attributes."""
380+ mat = openmc .Material (1 )
381+ mat .add_nuclide ('U235' , 1.0 )
382+ mats = {'1' : mat }
383+
384+ # material + temperature + density round-trip
385+ xml = '<cell id="5" name="fuel" material="1" temperature="900.0" density="10.5"/>'
386+ cell = openmc .DAGMCCell .from_xml_element (ET .fromstring (xml ), mats )
387+ assert cell .id == 5
388+ assert cell .name == 'fuel'
389+ assert cell .fill is mat
390+ assert cell .density == [10.5 ]
391+ assert cell .temperature == [900.0 ]
392+
393+ # volume round-trip
394+ xml = '<cell id="6" material="1" volume="42.0"/>'
395+ cell = openmc .DAGMCCell .from_xml_element (ET .fromstring (xml ), mats )
396+ assert cell .volume == 42.0
397+
398+ # forbidden: region, fill, universe
399+ for tag , val in [('region' , '-1' ), ('fill' , '2' ), ('universe' , '0' )]:
400+ xml = f'<cell id="7" material="1" { tag } ="{ val } "/>'
401+ with pytest .raises (ValueError , match = tag ):
402+ openmc .DAGMCCell .from_xml_element (ET .fromstring (xml ), mats )
403+
404+ # forbidden: translation, rotation
405+ for tag , val in [('translation' , '1 0 0' ), ('rotation' , '0 0 90' )]:
406+ xml = f'<cell id="7" material="1" { tag } ="{ val } "/>'
407+ with pytest .raises (ValueError , match = tag ):
408+ openmc .DAGMCCell .from_xml_element (ET .fromstring (xml ), mats )
409+
410+ # missing material raises
411+ xml = '<cell id="8"/>'
412+ with pytest .raises (ValueError , match = 'material' ):
413+ openmc .DAGMCCell .from_xml_element (ET .fromstring (xml ), mats )
414+
415+
377416def test_plot (run_in_tmpdir ):
378417 zcyl = openmc .ZCylinder ()
379418 c = openmc .Cell (region = - zcyl )
0 commit comments