Example #1
0
    def _run_openmc(self):
        if self._opts.mpi_exec is not None:
            returncode = openmc.run(
                openmc_exec=self._opts.exe,
                mpi_args=[self._opts.mpi_exec, '-n', self._opts.mpi_np])

        else:
            returncode = openmc.run(openmc_exec=self._opts.exe)

        assert returncode == 0, 'OpenMC did not exit successfully.'
Example #2
0
    def _run_openmc(self):
        if self._opts.mpi_exec is not None:
            returncode = openmc.run(mpi_procs=self._opts.mpi_np,
                                    openmc_exec=self._opts.exe,
                                    mpi_exec=self._opts.mpi_exec)

        else:
            returncode = openmc.run(openmc_exec=self._opts.exe)

        assert returncode == 0, 'OpenMC did not exit successfully.'
Example #3
0
    def execute(self, quiet=True):
        success = True
        try:
            openmc.run(output=(not quiet))
        except CalledProcessError:
            success = False

        if success:
            spfile = 'statepoint.' + str(self.batches) + '.h5'
            sp = openmc.StatePoint(spfile, autolink=False)
            self.keff = sp.k_combined

        return success
Example #4
0
    def _run_openmc(self):
        # Set arguments
        args = {'openmc_exec': self._opts.exe}
        if self._opts.mpi_exec is not None:
            args['mpi_args'] = [self._opts.mpi_exec, '-n', self._opts.mpi_np]

        # Initial run
        returncode = openmc.run(**args)
        assert returncode == 0, 'OpenMC did not exit successfully.'

        # Run particle restart
        args.update({'restart_file': self._sp_name})
        returncode = openmc.run(**args)
        assert returncode == 0, 'OpenMC did not exit successfully.'
Example #5
0
    def execute(self, quiet=True):
        returncode = openmc.run(output=(not quiet))
        spfile = 'statepoint.' + str(self.batches) + '.h5'
        sp = openmc.StatePoint(spfile)
        self.keff = sp.k_combined[:]

        return returncode
Example #6
0
    def run(self, **kwargs):
        """Creates the XML files, runs OpenMC, and returns k-effective

        Parameters
        ----------
        **kwargs
            All keyword arguments are passed to openmc.run

        Returns
        -------
        2-tuple of float
            Combined estimator of k-effective from the statepoint

        """
        self.export_to_xml()

        return_code = openmc.run(**kwargs)

        assert (return_code == 0), "OpenMC did not execute successfully"

        n = self.settings.batches
        if self.settings.statepoint is not None:
            if 'batches' in self.settings.statepoint:
                n = self.settings.statepoint['batches'][-1]

        with openmc.StatePoint('statepoint.{}.h5'.format(n)) as sp:
            return sp.k_combined
Example #7
0
    def run(self, **kwargs):
        """Creates the XML files, runs OpenMC, and returns k-effective

        Parameters
        ----------
        **kwargs
            All keyword arguments are passed to openmc.run

        Returns
        -------
        2-tuple of float
            Combined estimator of k-effective from the statepoint

        """
        self.export_to_xml()

        return_code = openmc.run(**kwargs)

        assert (return_code == 0), "OpenMC did not execute successfully"

        n = self.settings.batches
        if self.settings.statepoint is not None:
            if 'batches' in self.settings.statepoint:
                n = self.settings.statepoint['batches'][-1]

        with openmc.StatePoint('statepoint.{}.h5'.format(n)) as sp:
            return sp.k_combined
Example #8
0
    def _run_openmc_restart(self):
        # Get the name of the statepoint file.
        statepoint = glob.glob(os.path.join(os.getcwd(), self._restart_sp))
        assert len(statepoint) == 1
        statepoint = statepoint[0]

        # Run OpenMC
        if self._opts.mpi_exec is not None:
            mpi_args = [self._opts.mpi_exec, '-n', self._opts.mpi_np]
            returncode = openmc.run(restart_file=statepoint,
                                    openmc_exec=self._opts.exe,
                                    mpi_args=mpi_args)
        else:
            returncode = openmc.run(openmc_exec=self._opts.exe,
                                    restart_file=statepoint)

        assert returncode == 0, 'OpenMC did not exit successfully.'
    def _run_openmc(self):
        # Initial run
        if self._opts.mpi_exec is not None:
            returncode = openmc.run(mpi_procs=self._opts.mpi_np,
                                    openmc_exec=self._opts.exe,
                                    mpi_exec=self._opts.mpi_exec)

        else:
            returncode = openmc.run(openmc_exec=self._opts.exe)

        assert returncode == 0, 'CE OpenMC calculation did not exit' \
                                'successfully.'

        # Build MG Inputs
        # Get data needed to execute Library calculations.
        statepoint = glob.glob(os.path.join(os.getcwd(), self._sp_name))[0]
        sp = openmc.StatePoint(statepoint)
        self.mgxs_lib.load_from_statepoint(sp)
        self._input_set.mgxs_file, self._input_set.materials, \
            self._input_set.geometry = self.mgxs_lib.create_mg_mode()

        # Modify settings so we can run in MG mode
        self._input_set.settings.cross_sections = './mgxs.xml'
        self._input_set.settings.energy_mode = 'multi-group'

        # Write modified input files
        self._input_set.settings.export_to_xml()
        self._input_set.geometry.export_to_xml()
        self._input_set.materials.export_to_xml()
        self._input_set.mgxs_file.export_to_xml()
        # Dont need tallies.xml, so remove the file
        if os.path.exists('./tallies.xml'):
            os.remove('./tallies.xml')

        # Re-run MG mode.
        if self._opts.mpi_exec is not None:
            returncode = openmc.run(mpi_procs=self._opts.mpi_np,
                                    openmc_exec=self._opts.exe,
                                    mpi_exec=self._opts.mpi_exec)

        else:
            returncode = openmc.run(openmc_exec=self._opts.exe)
Example #10
0
    def run(self, **kwargs):
        """Creates the XML files, runs OpenMC, and returns the path to the last
        statepoint file generated.

        .. versionchanged:: 0.12
            Instead of returning the final k-effective value, this function now
            returns the path to the final statepoint written.

        Parameters
        ----------
        **kwargs
            Keyword arguments passed to :func:`openmc.run`

        Returns
        -------
        Path
            Path to the last statepoint written by this run
            (None if no statepoint was written)

        """

        self.export_to_xml()

        # Setting tstart here ensures we don't pick up any pre-existing statepoint
        # files in the output directory
        tstart = time.time()
        last_statepoint = None

        openmc.run(**kwargs)

        # Get output directory and return the last statepoint written by this run
        if self.settings.output and 'path' in self.settings.output:
            output_dir = Path(self.settings.output['path'])
        else:
            output_dir = Path.cwd()
        for sp in output_dir.glob('statepoint.*.h5'):
            mtime = sp.stat().st_mtime
            if mtime >= tstart:  # >= allows for poor clock resolution
                tstart = mtime
                last_statepoint = sp
        return last_statepoint
Example #11
0
    def _run_openmc(self):
        # Run multiple conversions to compare results
        cases = [['legendre', 2], ['legendre', 0],
                 ['tabular', 33], ['histogram', 32],
                 [['tabular', 33], ['legendre', 1]],
                 [['tabular', 33], ['tabular', 3]],
                 [['tabular', 33], ['histogram', 32]],
                 [['histogram', 32], ['legendre', 1]],
                 [['histogram', 32], ['tabular', 3]],
                 [['histogram', 32], ['histogram', 16]],
                 ['angle', 2], [['angle', 2], ['isotropic', None]]]

        outstr = ''
        for case in cases:
            build_mgxs_library(case)

            if self._opts.mpi_exec is not None:
                mpi_args = [self._opts.mpi_exec, '-n', self._opts.mpi_np]
                returncode = openmc.run(openmc_exec=self._opts.exe,
                                        mpi_args=mpi_args)

            else:
                returncode = openmc.run(openmc_exec=self._opts.exe)

            assert returncode == 0, 'OpenMC did not exit successfully.'

            sp = openmc.StatePoint('statepoint.' + str(batches) + '.h5')

            # Write out k-combined.
            outstr += 'k-combined:\n'
            form = '{0:12.6E} {1:12.6E}\n'
            outstr += form.format(sp.k_combined[0], sp.k_combined[1])

            # Enforce closing statepoint and summary files so HDF5
            # does not throw an error during the next OpenMC execution
            sp._f.close()
            sp._summary._f.close()

        return outstr