66import sys
77import xml .etree .ElementTree as ET
88
9- from OpenMCSurface import write_openmc_surface
10- from OpenMCCell import write_openmc_cell
11- from OpenMCMaterial import write_openmc_material
9+ from OpenMCSurface import SurfaceCard , surface_from_attribute , write_openmc_surface
10+ from OpenMCCell import cell_from_attribute , write_openmc_cell
11+ from OpenMCMaterial import material_from_attribute , write_openmc_material
1212'''
1313copy and paste from http://effbot.org/zone/element-lib.htm#prettyprint
1414it basically walks your tree and adds spaces and newlines so the tree is
@@ -35,8 +35,75 @@ class OpenMCInput(InputDeck):
3535 xml elements directly
3636 """
3737 # constructor
38- def __init__ (self , filename = "" ):
39- InputDeck .__init__ (self , filename )
38+ def __init__ (self ,geometry_file = "geometry.xml" ,material_file = "materials.xml" ):
39+ self .geometry = geometry_file
40+ self .material = material_file
41+ self .xml_geom = None
42+ self .xml_material = None
43+ # make a new input deck
44+ InputDeck .__init__ (self ,filename = "" )
45+
46+ # read the openmc files
47+ def read (self ):
48+ self .xml_geom = self .__read_geometry_xml (self .geometry )
49+ self .xml_material = self .__read_material_xml (self .material )
50+
51+ # read the geometry file
52+ def __read_geometry_xml (self , geometry_filename ):
53+ geom = ET .parse (geometry_filename )
54+ geom_root = geom .getroot ()
55+ return geom_root
56+
57+ # read the material file
58+ def __read_material_xml (self , material_filename ):
59+ mat = ET .parse (material_filename )
60+ mat_root = mat .getroot ()
61+ return mat_root
62+
63+ # process the files
64+ def process (self ):
65+ # do materials first
66+ self .__process_materials ()
67+ self .__process_geometry ()
68+
69+
70+ # process the geometry
71+ def __process_geometry (self ):
72+ for child in self .xml_geom :
73+ if child .tag == "surface" :
74+ surface = surface_from_attribute (child .attrib )
75+ InputDeck .surface_list .append (surface )
76+ elif child .tag == "cell" :
77+ cell = cell_from_attribute (child .attrib )
78+ InputDeck .cell_list .append (cell )
79+
80+ # loop over the cells and set the material
81+ # density for each cell
82+ for cell in InputDeck .cell_list :
83+ cell_mat = cell .cell_material_number
84+ if cell_mat is not 0 :
85+ density = InputDeck .material_list [cell_mat ].density
86+ cell .cell_density = density
87+
88+ # identify the cells that have a surface with a vacuum
89+ # boundary condition, they mark the end of the universe
90+ boundary_surfs = []
91+ for surface in InputDeck .surface_list :
92+ if surface .boundary_condition == SurfaceCard .BoundaryCondition ["VACUUM" ]:
93+ boundary_surfs .append (surface .surface_id )
94+
95+ # now loop through the cells and mark as importance 0 where
96+ # appropriate
97+ for cell in InputDeck .cell_list :
98+ if set (boundary_surfs ) & set (cell .cell_interpreted ) == set (boundary_surfs ):
99+ cell .cell_importance = 0
100+
101+ # process the materials
102+ def __process_materials (self ):
103+ for child in self .xml_material :
104+ if child .tag == "material" :
105+ material = material_from_attribute (child .attrib , child .getchildren ())
106+ InputDeck .material_list [material .material_number ] = material
40107
41108 # write the collection of OpenMC surface definitions
42109 def __write_openmc_surfaces (self , geometry_tree ):
0 commit comments