Beispiel #1
0
 def test_constant_emissivity(self):
     def emiss_function(r, phi, z):
         return 5
     # Emissivity in the voxel should be the constant value of emiss_function
     for polygon in TRIANGLE_VOXEL_COORDS + RECTANGULAR_VOXEL_COORDS + ARBITRARY_VOXEL_COORDS:
         coords = np.asarray(polygon)
         voxel = AxisymmetricVoxel(coords)
         emiss = voxel.emissivity_from_function(emiss_function, 1000)
         expected_emiss = emiss_function(0, 0, 0)
         self.assertEqual(emiss, expected_emiss)
Beispiel #2
0
    def test_variable_emissivity_arbitrary(self):
        # Use the same seed as Raysect's random tests
        seed(1234567890)

        quadpy_precalculated_emiss = {
            ((2, -1), (2, 2), (3, 4), (4, 3), (4, -1)): 3.5833333333333326,
            ((2, -1), (2, 2), (3, 4), (4, 3), (4, 0)): 4.349999999999999,
            ((2, -1), (2, 2), (3, 4), (4, 3), (5, 0)): 4.0482456140350855,
        }

        def emiss_function(r, phi, z):
            return r * z

        for polygon in ARBITRARY_VOXEL_COORDS:
            coords = np.asarray(polygon)
            voxel = AxisymmetricVoxel(coords)
            nsamples = 10000
            emiss = voxel.emissivity_from_function(emiss_function, nsamples)
            if HAVE_QUADPY:
                # Calculate the expected emissivity
                triangle_indices = triangulate2d(coords)
                triangles = coords[triangle_indices]
                expected_emiss = 0
                polygon_area = 0
                for triangle in triangles:
                    # Calculate the area with the shoelace formula
                    x1, y1 = triangle[0]
                    x2, y2 = triangle[1]
                    x3, y3 = triangle[2]
                    triangle_area = 0.5 * abs(x1 * y2 + x2 * y3 + x3 * y1
                                              - x2 * y1 - x3 * y2 - x1 * y3)
                    # Total emissivity is the area-weighted emissivity for each triangle
                    expected_emiss += quadpy.triangle.integrate(
                        lambda x: emiss_function(x[0], 0, x[1]), triangle, quadpy.triangle.Strang(6)
                    )
                    polygon_area += triangle_area
                expected_emiss /= polygon_area
            else:
                # Use pre-calculated values from a machine which had quadpy
                expected_emiss = quadpy_precalculated_emiss[tuple(polygon)]
            max_relative_error = 0.0225  # Measured with seed(1234567890)
            self.assertAlmostEqual(emiss, expected_emiss, delta=emiss * max_relative_error)
Beispiel #3
0
    def test_variable_emissivity_rectangular(self):
        # Use the same seed as Raysect's random tests
        seed(1234567890)

        def emiss_function(r, phi, z):
            return r * z

        # We can calculate the integrated emissivity analytically
        for polygon in RECTANGULAR_VOXEL_COORDS:
            coords = np.asarray(polygon)
            voxel = AxisymmetricVoxel(coords)
            nsamples = 10000
            emiss = voxel.emissivity_from_function(emiss_function, nsamples)
            rmax = coords[:, 0].max()
            rmin = coords[:, 0].min()
            zmax = coords[:, 1].max()
            zmin = coords[:, 1].min()
            area = (rmax - rmin) * (zmax - zmin)
            expected_emiss = (rmax**2 - rmin**2) * (zmax**2 - zmin**2) / 4 / area
            max_relative_error = 0.0221  # Measured with seed(1234567890)
            self.assertAlmostEqual(emiss, expected_emiss, delta=emiss * max_relative_error)
Beispiel #4
0
    def test_variable_emissivity_triangular(self):
        # Use the same seed as Raysect's random tests
        seed(1234567890)

        quadpy_precalculated_emiss = {
            ((4, 3), (3, 2), (2, -1)): 4.333333333333331,
            ((4, 3), (3, -1), (2, -1)): 1.333333333333333,
            ((4, 3), (3, 3), (2, -1)): 5.333333333333333,
            ((4, 3), (3, -1), (2, 2)): 4.083333333333334,
            ((4, 3), (3, 2), (2, 2)): 7.083333333333333,
            ((4, 3), (3, -1), (2, 3)): 5.000000000000001,
            ((4, 2), (3, -1), (2, 3)): 3.916666666666668,
            ((4, -1), (3, -1), (2, 3)): 0.6666666666666656,
            ((4, 3), (3, -1), (2, 3)): 5.000000000000001,
            ((4, 2), (3, 3), (2, -1)): 4.250000000000001,
            ((4, -1), (3, 3), (2, -1)): 0.9999999999999998,
            ((4, 3), (3, 3), (2, -1)): 5.333333333333333,
            ((4, -1), (3, 3), (2, 2)): 3.75,
            ((4, -1), (3, 3), (2, -1)): 0.9999999999999998,
            ((4, -1), (3, 3), (2, 3)): 4.666666666666663,
            ((4, -1), (3, 2), (2, 3)): 3.6666666666666674,
            ((4, -1), (3, -1), (2, 3)): 0.6666666666666656,
            ((4, -1), (3, 3), (2, 3)): 4.666666666666663,
            ((4, 3), (4, 2), (2, -1)): 4.833333333333337,
            ((4, 3), (4, -1), (2, -1)): 1.3333333333333337,
            ((4, 3), (4, -1), (2, 2)): 4.333333333333332,
            ((4, 3), (4, -1), (2, -1)): 1.3333333333333337,
            ((4, 3), (4, -1), (2, 3)): 5.333333333333333,
            ((4, 2), (4, -1), (2, 3)): 4.166666666666666,
            ((4, 3), (4, -1), (2, 3)): 5.333333333333333,
            ((4, 2), (4, 3), (2, -1)): 4.833333333333332,
            ((4, -1), (4, 3), (2, -1)): 1.3333333333333337,
            ((4, -1), (4, 3), (2, 2)): 4.333333333333331,
            ((4, -1), (4, 3), (2, -1)): 1.3333333333333337,
            ((4, -1), (4, 3), (2, 3)): 5.333333333333331,
            ((4, -1), (4, 2), (2, 3)): 4.166666666666665,
            ((4, -1), (4, 3), (2, 3)): 5.333333333333331,
            ((4, 3), (2, 2), (2, -1)): 3.833333333333334,
            ((4, 3), (2, 3), (2, -1)): 4.666666666666666,
            ((4, 3), (2, -1), (2, 2)): 3.833333333333334,
            ((4, 3), (2, -1), (2, 3)): 4.666666666666666,
            ((4, 2), (2, -1), (2, 3)): 3.666666666666666,
            ((4, -1), (2, -1), (2, 3)): 0.6666666666666659,
            ((4, 3), (2, -1), (2, 3)): 4.666666666666666,
            ((4, 2), (2, 3), (2, -1)): 3.666666666666666,
            ((4, -1), (2, 3), (2, -1)): 0.666666666666666,
            ((4, 3), (2, 3), (2, -1)): 4.666666666666666,
            ((4, -1), (2, 3), (2, 2)): 3.16666666666666,
            ((4, -1), (2, 3), (2, -1)): 0.666666666666666,
            ((4, -1), (2, 2), (2, 3)): 3.16666666666666,
            ((4, -1), (2, -1), (2, 3)): 0.6666666666666659,
        }

        def emiss_function(r, phi, z):
            return r * z

        for polygon in TRIANGLE_VOXEL_COORDS:
            coords = np.asarray(polygon)
            voxel = AxisymmetricVoxel(coords)
            nsamples = 10000
            emiss = voxel.emissivity_from_function(emiss_function, nsamples)
            if HAVE_QUADPY:
                # Calculate the expected emissivity
                x1, y1 = coords[0]
                x2, y2 = coords[1]
                x3, y3 = coords[2]
                triangle_area = 0.5 * abs(x1 * y2 + x2 * y3 + x3 * y1
                                          - x2 * y1 - x3 * y2 - x1 * y3)
                # Doesn't make any sense to sample from a <2D cross section area
                if triangle_area == 0:
                    continue
                expected_emiss = quadpy.triangle.integrate(
                    lambda x: emiss_function(x[0], 0, x[1]), coords, quadpy.triangle.Strang(6)
                ) / triangle_area
            else:
                try:
                    expected_emiss = quadpy_precalculated_emiss[tuple(polygon)]
                except KeyError:  # For triangles with zero area
                    continue
            max_relative_error = 0.0723  # Measured with seed(1234567890)
            self.assertAlmostEqual(emiss, expected_emiss, delta=emiss * max_relative_error)