Example #1
0
 def _tabular_legendre_from_xml_element(self, root):
     elem = root.find('tabular_legendre')
     if elem is not None:
         text = get_text(elem, 'enable')
         self.tabular_legendre['enable'] = text in ('true', '1')
         text = get_text(elem, 'num_points')
         if text is not None:
             self.tabular_legendre['num_points'] = int(text)
Example #2
0
 def _trigger_from_xml_element(self, root):
     elem = root.find('trigger')
     if elem is not None:
         self.trigger_active = get_text(elem, 'active') in ('true', '1')
         text = get_text(elem, 'max_batches')
         if text is not None:
             self.trigger_max_batches = int(text)
         text = get_text(elem, 'batch_interval')
         if text is not None:
             self.trigger_batch_interval = int(text)
    def from_xml_element(cls, elem, surfaces, materials, get_universe):
        """Generate cell from XML element

        Parameters
        ----------
        elem : xml.etree.ElementTree.Element
            `<cell>` element
        surfaces : dict
            Dictionary mapping surface IDs to :class:`openmc.Surface` instances
        materials : dict
            Dictionary mapping material IDs to :class:`openmc.Material`
            instances (defined in :math:`openmc.Geometry.from_xml`)
        get_universe : function
            Function returning universe (defined in
            :meth:`openmc.Geometry.from_xml`)

        Returns
        -------
        Cell
            Cell instance

        """
        cell_id = int(get_text(elem, 'id'))
        name = get_text(elem, 'name')
        c = cls(cell_id, name)

        # Assign material/distributed materials or fill
        mat_text = get_text(elem, 'material')
        if mat_text is not None:
            mat_ids = mat_text.split()
            if len(mat_ids) > 1:
                c.fill = [materials[i] for i in mat_ids]
            else:
                c.fill = materials[mat_ids[0]]
        else:
            fill_id = int(get_text(elem, 'fill'))
            c.fill = get_universe(fill_id)

        # Assign region
        region = get_text(elem, 'region')
        if region is not None:
            c.region = Region.from_expression(region, surfaces)

        # Check for other attributes
        t = get_text(elem, 'temperature')
        if t is not None:
            if ' ' in t:
                c.temperature = [float(t_i) for t_i in t.split()]
            else:
                c.temperature = float(t)
        for key in ('temperature', 'rotation', 'translation'):
            value = get_text(elem, key)
            if value is not None:
                setattr(c, key, [float(x) for x in value.split()])

        # Add this cell to appropriate universe
        univ_id = int(get_text(elem, 'universe', 0))
        get_universe(univ_id).add_cell(c)
        return c
Example #4
0
 def _ufs_mesh_from_xml_element(self, root):
     text = get_text(root, 'ufs_mesh')
     if text is not None:
         path = "./mesh[@id='{}']".format(int(text))
         elem = root.find(path)
         if elem is not None:
             self.ufs_mesh = RegularMesh.from_xml_element(elem)
Example #5
0
 def _temperature_from_xml_element(self, root):
     text = get_text(root, 'temperature_default')
     if text is not None:
         self.temperature['default'] = float(text)
     text = get_text(root, 'temperature_tolerance')
     if text is not None:
         self.temperature['tolerance'] = float(text)
     text = get_text(root, 'temperature_method')
     if text is not None:
         self.temperature['method'] = text
     text = get_text(root, 'temperature_range')
     if text is not None:
         self.temperature['range'] = [float(x) for x in text.split()]
     text = get_text(root, 'temperature_multipole')
     if text is not None:
         self.temperature['multipole'] = text in ('true', '1')
Example #6
0
 def from_xml_element(cls, elem):
     distribution = get_text(elem, 'type')
     if distribution == 'cartesian':
         return CartesianIndependent.from_xml_element(elem)
     elif distribution == 'box' or distribution == 'fission':
         return Box.from_xml_element(elem)
     elif distribution == 'point':
         return Point.from_xml_element(elem)
 def from_xml_element(cls, elem):
     distribution = get_text(elem, 'type')
     if distribution == 'mu-phi':
         return PolarAzimuthal.from_xml_element(elem)
     elif distribution == 'isotropic':
         return Isotropic.from_xml_element(elem)
     elif distribution == 'monodirectional':
         return Monodirectional.from_xml_element(elem)
Example #8
0
 def _cutoff_from_xml_element(self, root):
     elem = root.find('cutoff')
     if elem is not None:
         self.cutoff = {}
         for key in ('energy_neutron', 'energy_photon', 'energy_electron',
                     'energy_positron', 'weight', 'weight_avg'):
             value = get_text(elem, key)
             if value is not None:
                 self.cutoff[key] = float(value)
Example #9
0
    def from_xml_element(cls, elem):
        """Generate tabular distribution from an XML element

        Parameters
        ----------
        elem : xml.etree.ElementTree.Element
            XML element

        Returns
        -------
        openmc.stats.Tabular
            Tabular distribution generated from XML element

        """
        interpolation = get_text(elem, 'interpolation')
        params = [float(x) for x in get_text(elem, 'parameters').split()]
        x = params[:len(params) // 2]
        p = params[len(params) // 2:]
        return cls(x, p, interpolation)
    def from_xml_element(cls, elem):
        """Generate box distribution from an XML element

        Parameters
        ----------
        elem : xml.etree.ElementTree.Element
            XML element

        Returns
        -------
        openmc.stats.Box
            Box distribution generated from XML element

        """
        only_fissionable = get_text(elem, 'type') == 'fission'
        params = [float(x) for x in get_text(elem, 'parameters').split()]
        lower_left = params[:len(params) // 2]
        upper_right = params[len(params) // 2:]
        return cls(lower_left, upper_right, only_fissionable)
Example #11
0
 def _output_from_xml_element(self, root):
     elem = root.find('output')
     if elem is not None:
         self.output = {}
         for key in ('summary', 'tallies', 'path'):
             value = get_text(elem, key)
             if value is not None:
                 if key in ('summary', 'tallies'):
                     value = value in ('true', '1')
             self.output[key] = value
Example #12
0
    def from_xml_element(cls, elem):
        """Generate source from an XML element

        Parameters
        ----------
        elem : xml.etree.ElementTree.Element
            XML element

        Returns
        -------
        openmc.Source
            Source generated from XML element

        """
        source = cls()

        strength = get_text(elem, 'strength')
        if strength is not None:
            source.strength = float(strength)

        particle = get_text(elem, 'particle')
        if particle is not None:
            source.particle = particle

        filename = get_text(elem, 'file')
        if filename is not None:
            source.file = filename

        space = elem.find('space')
        if space is not None:
            source.space = Spatial.from_xml_element(space)

        angle = elem.find('angle')
        if angle is not None:
            source.angle = UnitSphere.from_xml_element(angle)

        energy = elem.find('energy')
        if energy is not None:
            source.energy = Univariate.from_xml_element(energy)

        return source
Example #13
0
 def _resonance_scattering_from_xml_element(self, root):
     elem = root.find('resonance_scattering')
     if elem is not None:
         keys = ('enable', 'method', 'energy_min', 'energy_max', 'nuclides')
         for key in keys:
             value = get_text(elem, key)
             if value is not None:
                 if key == 'enable':
                     value = value in ('true', '1')
                 elif key in ('energy_min', 'energy_max'):
                     value = float(value)
                 elif key == 'nuclides':
                     value = value.split()
                 self.resonance_scattering[key] = value
Example #14
0
 def _sourcepoint_from_xml_element(self, root):
     elem = root.find('source_point')
     if elem is not None:
         for key in ('separate', 'write', 'overwrite_latest', 'batches'):
             value = get_text(elem, key)
             if value is not None:
                 if key in ('separate', 'write'):
                     value = value in ('true', '1')
                 elif key == 'overwrite_latest':
                     value = value in ('true', '1')
                     key = 'overwrite'
                 else:
                     value = [int(x) for x in value.split()]
                 self.sourcepoint[key] = value
    def from_xml_element(cls, elem):
        """Generate point distribution from an XML element

        Parameters
        ----------
        elem : xml.etree.ElementTree.Element
            XML element

        Returns
        -------
        openmc.stats.Point
            Point distribution generated from XML element

        """
        xyz = [float(x) for x in get_text(elem, 'parameters').split()]
        return cls(xyz)
Example #16
0
    def from_xml_element(cls, elem):
        """Generate Muir distribution from an XML element

        Parameters
        ----------
        elem : xml.etree.ElementTree.Element
            XML element

        Returns
        -------
        openmc.stats.Muir
            Muir distribution generated from XML element

        """
        params = get_text(elem, 'parameters').split()
        return cls(*map(float, params))
Example #17
0
    def from_xml_element(cls, elem):
        """Generate Maxwellian distribution from an XML element

        Parameters
        ----------
        elem : xml.etree.ElementTree.Element
            XML element

        Returns
        -------
        openmc.stats.Maxwell
            Maxwellian distribution generated from XML element

        """
        theta = float(get_text(elem, 'parameters'))
        return cls(theta)
Example #18
0
    def from_xml_element(cls, elem):
        """Generate volume calculation object from an XML element

        .. versionadded:: 0.13.0

        Parameters
        ----------
        elem : xml.etree.ElementTree.Element
            XML element

        Returns
        -------
        openmc.VolumeCalculation
            Volume calculation object

        """
        domain_type = get_text(elem, "domain_type")
        domain_ids = get_text(elem, "domain_ids").split()
        ids = [int(x) for x in domain_ids]
        samples = int(get_text(elem, "samples"))
        lower_left = get_text(elem, "lower_left").split()
        lower_left = tuple([float(x) for x in lower_left])
        upper_right = get_text(elem, "upper_right").split()
        upper_right = tuple([float(x) for x in upper_right])

        # Instantiate some throw-away domains that are used by the constructor
        # to assign IDs
        with warnings.catch_warnings():
            warnings.simplefilter('ignore', openmc.IDWarning)
            if domain_type == 'cell':
                domains = [openmc.Cell(uid) for uid in ids]
            elif domain_type == 'material':
                domains = [openmc.Material(uid) for uid in ids]
            elif domain_type == 'universe':
                domains = [openmc.Universe(uid) for uid in ids]

        vol = cls(domains, samples, lower_left, upper_right)

        # Check for trigger
        trigger_elem = elem.find("threshold")
        if trigger_elem is not None:
            trigger_type = get_text(trigger_elem, "type")
            threshold = float(get_text(trigger_elem, "threshold"))
            vol.set_trigger(threshold, trigger_type)

        return vol
    def from_xml_element(cls, elem):
        """Generate monodirectional distribution from an XML element

        Parameters
        ----------
        elem : xml.etree.ElementTree.Element
            XML element

        Returns
        -------
        openmc.stats.Monodirectional
            Monodirectional distribution generated from XML element

        """
        monodirectional = cls()
        params = get_text(elem, 'parameters')
        if params is not None:
            monodirectional.reference_uvw = [float(x) for x in params.split()]
        return monodirectional
Example #20
0
 def from_xml_element(cls, elem):
     distribution = get_text(elem, 'type')
     if distribution == 'discrete':
         return Discrete.from_xml_element(elem)
     elif distribution == 'uniform':
         return Uniform.from_xml_element(elem)
     elif distribution == 'maxwell':
         return Maxwell.from_xml_element(elem)
     elif distribution == 'watt':
         return Watt.from_xml_element(elem)
     elif distribution == 'normal':
         return Normal.from_xml_element(elem)
     elif distribution == 'muir':
         return Muir.from_xml_element(elem)
     elif distribution == 'tabular':
         return Tabular.from_xml_element(elem)
     elif distribution == 'legendre':
         return Legendre.from_xml_element(elem)
     elif distribution == 'mixture':
         return Mixture.from_xml_element(elem)
    def from_xml_element(cls, elem):
        """Generate angular distribution from an XML element

        Parameters
        ----------
        elem : xml.etree.ElementTree.Element
            XML element

        Returns
        -------
        openmc.stats.PolarAzimuthal
            Angular distribution generated from XML element

        """
        mu_phi = cls()
        params = get_text(elem, 'parameters')
        if params is not None:
            mu_phi.reference_uvw = [float(x) for x in params.split()]
        mu_phi.mu = Univariate.from_xml_element(elem.find('mu'))
        mu_phi.phi = Univariate.from_xml_element(elem.find('phi'))
        return mu_phi
Example #22
0
    def from_xml_element(cls, elem):
        """Generate mesh from an XML element

        Parameters
        ----------
        elem : xml.etree.ElementTree.Element
            XML element

        Returns
        -------
        openmc.Mesh
            Mesh generated from XML element

        """
        mesh_id = int(get_text(elem, 'id'))
        mesh = cls(mesh_id)

        mesh_type = get_text(elem, 'type')
        if mesh_type is not None:
            mesh.type = mesh_type

        dimension = get_text(elem, 'dimension')
        if dimension is not None:
            mesh.dimension = [int(x) for x in dimension.split()]

        lower_left = get_text(elem, 'lower_left')
        if lower_left is not None:
            mesh.lower_left = [float(x) for x in lower_left.split()]

        upper_right = get_text(elem, 'upper_right')
        if upper_right is not None:
            mesh.upper_right = [float(x) for x in upper_right.split()]

        width = get_text(elem, 'width')
        if width is not None:
            mesh.width = [float(x) for x in width.split()]

        return mesh
Example #23
0
 def _run_mode_from_xml_element(self, root):
     text = get_text(root, 'run_mode')
     if text is not None:
         self.run_mode = text
Example #24
0
 def _particles_from_xml_element(self, root):
     text = get_text(root, 'particles')
     if text is not None:
         self.particles = int(text)
Example #25
0
 def _batches_from_xml_element(self, root):
     text = get_text(root, 'batches')
     if text is not None:
         self.batches = int(text)
Example #26
0
 def _inactive_from_xml_element(self, root):
     text = get_text(root, 'inactive')
     if text is not None:
         self.inactive = int(text)
Example #27
0
 def _generations_per_batch_from_xml_element(self, root):
     text = get_text(root, 'generations_per_batch')
     if text is not None:
         self.generations_per_batch = int(text)
Example #28
0
 def _keff_trigger_from_xml_element(self, root):
     elem = root.find('keff_trigger')
     if elem is not None:
         trigger = get_text(elem, 'type')
         threshold = float(get_text(elem, 'threshold'))
         self.keff_trigger = {'type': trigger, 'threshold': threshold}
Example #29
0
    def from_xml(cls, path='geometry.xml', materials=None):
        """Generate geometry from XML file

        Parameters
        ----------
        path : str, optional
            Path to geometry XML file
        materials : openmc.Materials or None
            Materials used to assign to cells. If None, an attempt is made to
            generate it from the materials.xml file.

        Returns
        -------
        openmc.Geometry
            Geometry object

        """
        # Helper function for keeping a cache of Universe instances
        universes = {}

        def get_universe(univ_id):
            if univ_id not in universes:
                univ = openmc.Universe(univ_id)
                universes[univ_id] = univ
            return universes[univ_id]

        tree = ET.parse(path)
        root = tree.getroot()

        # Get surfaces
        surfaces = {}
        periodic = {}
        for surface in root.findall('surface'):
            s = openmc.Surface.from_xml_element(surface)
            surfaces[s.id] = s

            # Check for periodic surface
            other_id = xml.get_text(surface, 'periodic_surface_id')
            if other_id is not None:
                periodic[s.id] = int(other_id)

        # Apply periodic surfaces
        for s1, s2 in periodic.items():
            surfaces[s1].periodic_surface = surfaces[s2]

        # Dictionary that maps each universe to a list of cells/lattices that
        # contain it (needed to determine which universe is the root)
        child_of = defaultdict(list)

        for elem in root.findall('lattice'):
            lat = openmc.RectLattice.from_xml_element(elem, get_universe)
            universes[lat.id] = lat
            if lat.outer is not None:
                child_of[lat.outer].append(lat)
            for u in lat.universes.ravel():
                child_of[u].append(lat)

        for elem in root.findall('hex_lattice'):
            lat = openmc.HexLattice.from_xml_element(elem, get_universe)
            universes[lat.id] = lat
            if lat.outer is not None:
                child_of[lat.outer].append(lat)
            if lat.ndim == 2:
                for ring in lat.universes:
                    for u in ring:
                        child_of[u].append(lat)
            else:
                for axial_slice in lat.universes:
                    for ring in axial_slice:
                        for u in ring:
                            child_of[u].append(lat)

        # Create dictionary to easily look up materials
        if materials is None:
            filename = Path(path).parent / 'materials.xml'
            materials = openmc.Materials.from_xml(str(filename))
        mats = {str(m.id): m for m in materials}
        mats['void'] = None

        for elem in root.findall('cell'):
            c = openmc.Cell.from_xml_element(elem, surfaces, mats,
                                             get_universe)
            if c.fill_type in ('universe', 'lattice'):
                child_of[c.fill].append(c)

        # Determine which universe is the root by finding one which is not a
        # child of any other object
        for u in universes.values():
            if not child_of[u]:
                return cls(u)
        else:
            raise ValueError('Error determining root universe.')
Example #30
0
 def _statepoint_from_xml_element(self, root):
     elem = root.find('state_point')
     if elem is not None:
         text = get_text(elem, 'batches')
         if text is not None:
             self.statepoint['batches'] = [int(x) for x in text.split()]