def test_cube_normals(self, tmpdir):
     """Generate a gmy from a simple cubic profile and check the computed 
     normals.
     """
     cube = fixtures.cube(tmpdir)
     cube.VoxelSize = 0.23
     cube.StlFileUnitId = 0
     
     """The default VTK cube has 1m edges and it is centred at the origin 
     of coordinates. We place the inlet and the outlet at the faces 
     perpendicular to the z axis.
     """
     inlet = Iolet(Name='inlet',
                   Centre=Vector(0., 0., -0.5),
                   Normal=Vector(0., 0., -1.),
                   Radius=np.sqrt(2) / 2)
     outlet = Iolet(Name='outlet',
                    Centre=Vector(0., 0., 0.5),
                    Normal=Vector(0., 0., 1.),
                    Radius=np.sqrt(2) / 2)
     cube.Iolets = [inlet, outlet]
      
     generator = OutputGeneration.PolyDataGenerator(cube)
     generator.skipNonIntersectingBlocks = True
     generator.Execute()
     
     """Load back the resulting geometry file and assert things are as 
     expected
     """
     checker = CubeNormalsTestingGmyParser(cube.OutputGeometryFile, 
                                           cube.VoxelSize)
     checker.Load()
    def test_cube(self, tmpdir):
        """Generate a gmy from a simple cubic profile and check the output"""
        cube = fixtures.cube(tmpdir)
        cube.VoxelSize = 0.23
        cube.StlFileUnitId = 0
        generator = OutputGeneration.PolyDataGenerator(cube)
        generator.Execute()
        # Load back the resulting geometry file and assert things are as
        # expected
        checker = CubeTestingGmyParser(cube.OutputGeometryFile, cube.VoxelSize)
        checker.Load()

        fluid_sites = sum(checker.Domain.BlockFluidSiteCounts)
        block_count = len(checker.Domain.Blocks)
        block_size = checker.Domain.BlockSize
        sites = block_count * block_size ** 3
        # assert(sites==4096)
        # assert(fluid_sites==729)
        assert(sites != fluid_sites)
        # Now, turn on the skip-non-intersecting-blocks optimisation, and
        # assert same result
        generator.skipNonIntersectingBlocks = True
        generator.Execute()
        checker_skip_nonintersecting = CubeTestingGmyParser(
            cube.OutputGeometryFile, cube.VoxelSize)
        checker_skip_nonintersecting.Load()
        fluid_sites_nonintersecting = sum(
            checker_skip_nonintersecting.Domain.BlockFluidSiteCounts)
        assert(fluid_sites_nonintersecting == fluid_sites)
    def test_regression(self, tmpdir, randSeed):
        """Generate a small cylinder GMY with a random orientation. Then check
        that the output is correct by running it through a custom subclass of
        a ConfigLoader.
        """

        basename = tmpdir.join('cyl')
        OutputGeometryFile = basename.strpath + '.gmy'
        OutputXmlFile = basename.strpath + '.xml'
        VoxelSizeMetres = 0.1

        rng = np.random.RandomState(randSeed)
        Axis = rng.normal(size=(3,))
        Axis /= np.sqrt(np.dot(Axis, Axis))

        LengthMetres = 1.32
        RadiusMetres = 0.74

        generator = OutputGeneration.CylinderGenerator(
            OutputGeometryFile, OutputXmlFile,
            VoxelSizeMetres, Axis, LengthMetres,
            RadiusMetres)
        generator.Execute()

        checker = CylinderTestingGmyParser(OutputGeometryFile, VoxelSizeMetres,
                                           Axis, LengthMetres, RadiusMetres)
        checker.Load()
        return
    def test_cylinder(self, tmpdir):
        """Generate a gmy from a simple cylinder profile and check the output
        """
        cylinder = fixtures.cylinder(tmpdir)
        cylinder.VoxelSize = 0.23
        cylinder.StlFileUnitId = 0

        """ The default VTK cylinder is 1 length unit long, aligned with the 
        y-axis, and centred at the origin of coordinates.
        """
        inlet = Iolet(Name='inlet',
                      Centre=Vector(0., -0.5, 0.),
                      Normal=Vector(0., -1., 0.),
                      Radius=1)
        outlet = Iolet(Name='outlet',
                       Centre=Vector(0., 0.5, 0.),
                       Normal=Vector(0., 1., 0.),
                       Radius=1)
        cylinder.Iolets = [inlet, outlet]
        
        generator = OutputGeneration.PolyDataGenerator(cylinder)
        generator.Execute()
        # Load back the resulting geometry file and assert things are as
        # expected
        checker = CylinderTestingGmyParser(cylinder.OutputGeometryFile,
                                           cylinder.VoxelSize,
                                           np.array([0.0, 1.0, 0.0]),
                                           1.0, 0.5)
        checker.Load()

        fluid_sites = sum(checker.Domain.BlockFluidSiteCounts)
        block_count = len(checker.Domain.Blocks)
        block_size = checker.Domain.BlockSize
        sites = block_count * block_size ** 3
        # assert(sites==4096)
        # assert(fluid_sites==621)
        assert(sites != fluid_sites)
        # Now, turn on the skip-non-intersecting-blocks optimisation, and
        # assert same result
        generator.skipNonIntersectingBlocks = True
        generator.Execute()
        checker_skip_nonintersecting = CylinderTestingGmyParser(
            cylinder.OutputGeometryFile, cylinder.VoxelSize,
            np.array([0.0, 1.0, 0.0]), 1.0, 0.5)
        checker_skip_nonintersecting.Load()
        fluid_sites_nonintersecting = sum(
            checker_skip_nonintersecting.Domain.BlockFluidSiteCounts)
        assert(fluid_sites_nonintersecting == fluid_sites)
    def test_regression(self, tmpdir):
        """Generate a gmy from a stored profile and check that the output is
        identical.
        """
        dataDir = os.path.join(os.path.split(__file__)[0], 'data')
        proFileName = os.path.join(dataDir, 'test.pro')

        p = Profile()
        p.LoadFromFile(proFileName)
        # Change the output to the tmpdir
        basename = tmpdir.join('test').strpath
        outGmyFileName = basename + '.gmy'
        outXmlFileName = basename + '.xml'
        p.OutputGeometryFile = outGmyFileName
        p.OutputXmlFile = outXmlFileName

        generator = OutputGeneration.PolyDataGenerator(p)
        generator.Execute()

        import filecmp
        assert filecmp.cmp(outGmyFileName, os.path.join(dataDir, 'test.gmy'))
        assert filecmp.cmp(outXmlFileName, os.path.join(dataDir, 'test.xml'))