Пример #1
0
    def test_predictor(self):
        """ Integral regression test of integrator algorithm using CE/CM. """

        settings = opendeplete.Settings()
        settings.dt_vec = [0.75, 0.75]
        settings.output_dir = self.results

        op = dummy_geometry.DummyGeometry(settings)

        # Perform simulation using the predictor algorithm
        opendeplete.predictor(op, print_out=False)

        # Load the files
        res = results.read_results(settings.output_dir + "/results.h5")

        _, y1 = utilities.evaluate_single_nuclide(res, "1", "1")
        _, y2 = utilities.evaluate_single_nuclide(res, "1", "2")

        # Mathematica solution
        s1 = [2.46847546272295, 0.986431226850467]
        s2 = [4.11525874568034, -0.0581692232513460]

        tol = 1.0e-13

        self.assertLess(np.absolute(y1[1] - s1[0]), tol)
        self.assertLess(np.absolute(y2[1] - s1[1]), tol)

        self.assertLess(np.absolute(y1[2] - s2[0]), tol)
        self.assertLess(np.absolute(y2[2] - s2[1]), tol)
Пример #2
0
    def test_cecm(self):
        """ Integral regression test of integrator algorithm using CE/CM. """

        settings = opendeplete.Settings()
        settings.dt_vec = [0.75, 0.75]
        settings.output_dir = self.results

        op = dummy_geometry.DummyGeometry(settings)

        # Perform simulation using the MCNPX/MCNP6 algorithm
        opendeplete.cecm(op, print_out=False)

        # Load the files
        res = results.read_results(settings.output_dir + "/results.h5")

        _, y1 = utilities.evaluate_single_nuclide(res, "1", "1")
        _, y2 = utilities.evaluate_single_nuclide(res, "1", "2")

        # Mathematica solution
        s1 = [1.86872629872102, 1.395525772416039]
        s2 = [2.18097439443550, 2.69429754646747]

        tol = 1.0e-13

        self.assertLess(np.absolute(y1[1] - s1[0]), tol)
        self.assertLess(np.absolute(y2[1] - s1[1]), tol)

        self.assertLess(np.absolute(y1[2] - s2[0]), tol)
        self.assertLess(np.absolute(y2[2] - s2[1]), tol)
Пример #3
0
    def test_evaluate_eigenvalue(self):
        """ Tests evaluating eigenvalue
        """

        # Load the reference
        res = results.read_results("test/test_reference.h5")

        x, y = utilities.evaluate_eigenvalue(res)

        x_ref = [0.0, 1296000.0, 2592000.0, 3888000.0]
        y_ref = [
            1.1921984510699268, 1.1809789004827738, 1.1930669366462165,
            1.2102186170751308
        ]

        np.testing.assert_array_equal(x, x_ref)
        np.testing.assert_array_equal(y, y_ref)
Пример #4
0
    def test_evaluate_single_nuclide(self):
        """ Tests evaluating single nuclide utility code.
        """

        # Load the reference
        res = results.read_results("test/test_reference.h5")

        x, y = utilities.evaluate_single_nuclide(res, "1", "Xe135")

        x_ref = [0.0, 1296000.0, 2592000.0, 3888000.0]
        y_ref = [
            6.6747328233649218e+08, 3.5519326338509556e+14,
            3.5965291907016744e+14, 3.3660528631036400e+14
        ]

        np.testing.assert_array_equal(x, x_ref)
        np.testing.assert_array_equal(y, y_ref)
Пример #5
0
    def test_evaluate_eigenvalue(self):
        """ Tests evaluating eigenvalue
        """

        # Load the reference
        res = results.read_results("test/test_reference.h5")

        x, y = utilities.evaluate_eigenvalue(res)

        x_ref = [0.0, 1296000.0, 2592000.0, 3888000.0]
        y_ref = [
            1.1921986054449838, 1.1712785643938586, 1.1927099024502694,
            1.2269183590698847
        ]

        np.testing.assert_array_equal(x, x_ref)
        np.testing.assert_array_equal(y, y_ref)
Пример #6
0
    def test_evaluate_single_nuclide(self):
        """ Tests evaluating single nuclide utility code.
        """

        # Load the reference
        res = results.read_results("test/test_reference.h5")

        x, y = utilities.evaluate_single_nuclide(res, "1", "Xe135")

        x_ref = [0.0, 1296000.0, 2592000.0, 3888000.0]
        y_ref = [
            6.6747328233649218e+08, 3.5519299354458244e+14,
            3.4599104054580338e+14, 3.3821165110278112e+14
        ]

        np.testing.assert_array_equal(x, x_ref)
        np.testing.assert_array_equal(y, y_ref)
Пример #7
0
    def test_evaluate_reaction_rate(self):
        """ Tests evaluating reaction rate utility code.
        """

        # Load the reference
        res = results.read_results("test/test_reference.h5")

        x, y = utilities.evaluate_reaction_rate(res, "1", "Xe135", "(n,gamma)")

        x_ref = [0.0, 1296000.0, 2592000.0, 3888000.0]
        xe_ref = np.array([
            6.6747328233649218e+08, 3.5519326338509556e+14,
            3.5965291907016744e+14, 3.3660528631036400e+14
        ])
        r_ref = np.array([
            4.0643678160858948e-05, 3.7482633215418289e-05,
            3.6235405850442806e-05, 3.7149949868282194e-05
        ])

        np.testing.assert_array_equal(x, x_ref)
        np.testing.assert_array_equal(y, xe_ref * r_ref)
Пример #8
0
    def test_evaluate_reaction_rate(self):
        """ Tests evaluating reaction rate utility code.
        """

        # Load the reference
        res = results.read_results("test/test_reference.h5")

        x, y = utilities.evaluate_reaction_rate(res, "1", "Xe135", "(n,gamma)")

        x_ref = [0.0, 1296000.0, 2592000.0, 3888000.0]
        xe_ref = np.array([
            6.6747328233649218e+08, 3.5519299354458244e+14,
            3.4599104054580338e+14, 3.3821165110278112e+14
        ])
        r_ref = np.array([
            4.0643598574337784e-05, 4.1457730544386974e-05,
            3.4121248544056681e-05, 3.9204686657643301e-05
        ])

        np.testing.assert_array_equal(x, x_ref)
        np.testing.assert_array_equal(y, xe_ref * r_ref)
Пример #9
0
    def test_full(self):
        """
        This test runs a complete OpenMC simulation and tests the outputs.
        It will take a while.
        """

        n_rings = 2
        n_wedges = 4

        # Load geometry from example
        geometry, lower_left, upper_right = \
            example_geometry.generate_problem(n_rings=n_rings, n_wedges=n_wedges)

        # Create dt vector for 3 steps with 15 day timesteps
        dt1 = 15 * 24 * 60 * 60  # 15 days
        dt2 = 1.5 * 30 * 24 * 60 * 60  # 1.5 months
        N = np.floor(dt2 / dt1)

        dt = np.repeat([dt1], N)

        # Create settings variable
        settings = opendeplete.OpenMCSettings()

        settings.chain_file = "chains/chain_simple.xml"
        settings.openmc_call = "openmc"
        settings.openmc_npernode = 2
        settings.particles = 100
        settings.batches = 100
        settings.inactive = 40
        settings.lower_left = lower_left
        settings.upper_right = upper_right
        settings.entropy_dimension = [10, 10, 1]

        settings.round_number = True
        settings.constant_seed = 1

        joule_per_mev = 1.6021766208e-13
        settings.power = 2.337e15 * 4 * joule_per_mev  # MeV/second cm from CASMO
        settings.dt_vec = dt
        settings.output_dir = "test_full"

        op = opendeplete.OpenMCOperator(geometry, settings)

        # Perform simulation using the predictor algorithm
        opendeplete.integrator.predictor(op)

        # Load the files
        res_test = results.read_results(settings.output_dir + "/results.h5")

        # Load the reference
        res_old = results.read_results("test/test_reference.h5")

        # Assert same mats
        for mat in res_old[0].mat_to_ind:
            self.assertIn(mat,
                          res_test[0].mat_to_ind,
                          msg="Cell " + mat + " not in new results.")
        for nuc in res_old[0].nuc_to_ind:
            self.assertIn(nuc,
                          res_test[0].nuc_to_ind,
                          msg="Nuclide " + nuc + " not in new results.")

        for mat in res_test[0].mat_to_ind:
            self.assertIn(mat,
                          res_old[0].mat_to_ind,
                          msg="Cell " + mat + " not in old results.")
        for nuc in res_test[0].nuc_to_ind:
            self.assertIn(nuc,
                          res_old[0].nuc_to_ind,
                          msg="Nuclide " + nuc + " not in old results.")

        for mat in res_test[0].mat_to_ind:
            for nuc in res_test[0].nuc_to_ind:
                _, y_test = utilities.evaluate_single_nuclide(
                    res_test, mat, nuc)
                _, y_old = utilities.evaluate_single_nuclide(res_old, mat, nuc)

                # Test each point

                tol = 1.0e-6

                correct = True
                for i, ref in enumerate(y_old):
                    if ref != y_test[i]:
                        if ref != 0.0:
                            if np.abs(y_test[i] - ref) / ref > tol:
                                correct = False
                        else:
                            correct = False

                self.assertTrue(correct,
                                msg="Discrepancy in mat " + mat + " and nuc " +
                                nuc + "\n" + str(y_old) + "\n" + str(y_test))
Пример #10
0
    def test_save_results(self):
        """ Test data save module """

        stages = 3

        comm = MPI.COMM_WORLD
        np.random.seed(comm.rank)

        # Mock geometry
        op = MagicMock()

        vol_dict = {}
        full_burn_dict = {}

        j = 0
        for i in range(comm.size):
            vol_dict[str(2 * i)] = 1.2
            vol_dict[str(2 * i + 1)] = 1.2
            full_burn_dict[str(2 * i)] = j
            full_burn_dict[str(2 * i + 1)] = j + 1
            j += 2

        burn_list = [str(i) for i in range(2 * comm.rank, 2 * comm.rank + 2)]
        nuc_list = ["na", "nb"]

        op.get_results_info.return_value = vol_dict, nuc_list, burn_list, full_burn_dict

        # Construct x
        x1 = []
        x2 = []

        for i in range(stages):
            x1.append([np.random.rand(2), np.random.rand(2)])
            x2.append([np.random.rand(2), np.random.rand(2)])

        # Construct r
        cell_dict = {s: i for i, s in enumerate(burn_list)}
        r1 = ReactionRates(cell_dict, {"na": 0, "nb": 1}, {"ra": 0, "rb": 1})
        r1.rates = np.random.rand(2, 2, 2)

        rate1 = []
        rate2 = []

        for i in range(stages):
            rate1.append(copy.deepcopy(r1))
            r1.rates = np.random.rand(2, 2, 2)
            rate2.append(copy.deepcopy(r1))
            r1.rates = np.random.rand(2, 2, 2)

        # Create global terms
        eigvl1 = np.random.rand(stages)
        eigvl2 = np.random.rand(stages)
        seed1 = [np.random.randint(100) for i in range(stages)]
        seed2 = [np.random.randint(100) for i in range(stages)]

        eigvl1 = comm.bcast(eigvl1, root=0)
        eigvl2 = comm.bcast(eigvl2, root=0)
        seed1 = comm.bcast(seed1, root=0)
        seed2 = comm.bcast(seed2, root=0)

        t1 = [0.0, 1.0]
        t2 = [1.0, 2.0]

        integrator.save_results(op, x1, rate1, eigvl1, seed1, t1, 0)
        integrator.save_results(op, x2, rate2, eigvl2, seed2, t2, 1)

        # Load the files
        res = results.read_results("results.h5")

        for i in range(stages):
            for mat_i, mat in enumerate(burn_list):

                for nuc_i, nuc in enumerate(nuc_list):
                    self.assertEqual(res[0][i, mat, nuc], x1[i][mat_i][nuc_i])
                    self.assertEqual(res[1][i, mat, nuc], x2[i][mat_i][nuc_i])
                    np.testing.assert_array_equal(res[0].rates[i][mat, nuc, :],
                                                  rate1[i][mat, nuc, :])
                    np.testing.assert_array_equal(res[1].rates[i][mat, nuc, :],
                                                  rate2[i][mat, nuc, :])

        np.testing.assert_array_equal(res[0].k, eigvl1)
        np.testing.assert_array_equal(res[0].seeds, seed1)
        np.testing.assert_array_equal(res[0].time, t1)

        np.testing.assert_array_equal(res[1].k, eigvl2)
        np.testing.assert_array_equal(res[1].seeds, seed2)
        np.testing.assert_array_equal(res[1].time, t2)

        # Delete files
        MPI.COMM_WORLD.barrier()
        if MPI.COMM_WORLD.rank == 0:
            os.remove("results.h5")