Beispiel #1
0
    def test_BC_flags(self):
        """
        Testing the flags of shapes and their in their domain
        """
        nb_shapes = 3
        domain2D = create_domain2D()
        domain3D = create_domain3D()
        domain2DRANS = create_domain2D()
        domain3DRANS = create_domain3D()
        flags_v2D = []
        flags_s2D = []
        flags_v3D = []
        flags_f3D = []
        flags_v2DRANS = []
        flags_s2DRANS = []
        flags_v3DRANS = []
        flags_f3DRANS = []
        maxf = 0
        for i in range(nb_shapes):
            # 2D
            a = create_custom2D(domain2D)
            if flags_v2D:
                maxf = np.max([np.max(flags_v2D), np.max(flags_s2D)])
            flags_v2D += (a.vertexFlags+maxf).tolist()
            flags_s2D += (a.segmentFlags+maxf).tolist()
            # 3D
            a = create_custom3D(domain3D)
            if flags_v3D:
                maxf = np.max([np.max(flags_v3D), np.max(flags_f3D)])
            flags_v3D += (a.vertexFlags+maxf).tolist()
            flags_f3D += (a.facetFlags+maxf).tolist()
            # 2D RANS
            a = create_custom2D(domain2DRANS, folder='mprans')
            if flags_v2DRANS:
                maxf = np.max([np.max(flags_v2DRANS), np.max(flags_s2DRANS)])
            flags_v2DRANS += (a.vertexFlags+maxf).tolist()
            flags_s2DRANS += (a.segmentFlags+maxf).tolist()
            # 3D RANS
            a = create_custom3D(domain3DRANS, folder='mprans')
            if flags_v3DRANS:
                maxf = np.max([np.max(flags_v3DRANS), np.max(flags_f3DRANS)])
            flags_v3DRANS += (a.vertexFlags+maxf).tolist()
            flags_f3DRANS += (a.facetFlags+maxf).tolist()
        assembleDomain(domain2D)
        assembleDomain(domain3D)
        assembleDomainRANS(domain2DRANS)
        assembleDomainRANS(domain3DRANS)

        # test flags
        npt.assert_equal(domain2D.vertexFlags, flags_v2D)
        npt.assert_equal(domain2D.segmentFlags, flags_s2D)
        npt.assert_equal(domain3D.vertexFlags, flags_v3D)
        npt.assert_equal(domain3D.facetFlags, flags_f3D)
        npt.assert_equal(domain2DRANS.vertexFlags, flags_v2DRANS)
        npt.assert_equal(domain2DRANS.segmentFlags, flags_s2DRANS)
        npt.assert_equal(domain3DRANS.vertexFlags, flags_v3DRANS)
        npt.assert_equal(domain3DRANS.facetFlags, flags_f3DRANS)
Beispiel #2
0
    def test_BC_flags(self):
        """
        Testing the flags of shapes and their in their domain
        """
        nb_shapes = 3
        domain2D = create_domain2D()
        domain3D = create_domain3D()
        domain2DRANS = create_domain2D()
        domain3DRANS = create_domain3D()
        flags_v2D = []
        flags_s2D = []
        flags_v3D = []
        flags_f3D = []
        flags_v2DRANS = []
        flags_s2DRANS = []
        flags_v3DRANS = []
        flags_f3DRANS = []
        maxf = 0
        for i in range(nb_shapes):
            # 2D
            a = create_custom2D(domain2D)
            if flags_v2D:
                maxf = np.max([np.max(flags_v2D), np.max(flags_s2D)])
            flags_v2D += (a.vertexFlags+maxf).tolist()
            flags_s2D += (a.segmentFlags+maxf).tolist()
            # 3D
            a = create_custom3D(domain3D)
            if flags_v3D:
                maxf = np.max([np.max(flags_v3D), np.max(flags_f3D)])
            flags_v3D += (a.vertexFlags+maxf).tolist()
            flags_f3D += (a.facetFlags+maxf).tolist()
            # 2D RANS
            a = create_custom2D(domain2DRANS, folder='mprans')
            if flags_v2DRANS:
                maxf = np.max([np.max(flags_v2DRANS), np.max(flags_s2DRANS)])
            flags_v2DRANS += (a.vertexFlags+maxf).tolist()
            flags_s2DRANS += (a.segmentFlags+maxf).tolist()
            # 3D RANS
            a = create_custom3D(domain3DRANS, folder='mprans')
            if flags_v3DRANS:
                maxf = np.max([np.max(flags_v3DRANS), np.max(flags_f3DRANS)])
            flags_v3DRANS += (a.vertexFlags+maxf).tolist()
            flags_f3DRANS += (a.facetFlags+maxf).tolist()
        assembleDomain(domain2D)
        assembleDomain(domain3D)
        assembleDomainRANS(domain2DRANS)
        assembleDomainRANS(domain3DRANS)

        # test flags
        npt.assert_equal(domain2D.vertexFlags, flags_v2D)
        npt.assert_equal(domain2D.segmentFlags, flags_s2D)
        npt.assert_equal(domain3D.vertexFlags, flags_v3D)
        npt.assert_equal(domain3D.facetFlags, flags_f3D)
        npt.assert_equal(domain2DRANS.vertexFlags, flags_v2DRANS)
        npt.assert_equal(domain2DRANS.segmentFlags, flags_s2DRANS)
        npt.assert_equal(domain3DRANS.vertexFlags, flags_v3DRANS)
        npt.assert_equal(domain3DRANS.facetFlags, flags_f3DRANS)
Beispiel #3
0
 def test_rigid_body(self):
     domain = create_domain2D()
     rectangle = create_rectangle(domain, dim=[2., 2.], coords=[1., 1.],
                                  folder='mprans')
     rectangle.setRigidBody()
     npt.assert_equal(rectangle.holes.tolist(), [[1., 1.]])
     npt.assert_equal(rectangle.auxiliaryVariables['RigidBody'], True)
     assembleDomainRANS(domain)
     isRigidBody = isinstance(domain.auxiliaryVariables['twp'][0], RigidBody)
     npt.assert_equal(isRigidBody, True)
Beispiel #4
0
 def test_rigid_body(self):
     domain = create_domain2D()
     rectangle = create_rectangle(domain, dim=[2., 2.], coords=[1., 1.],
                                  folder='mprans')
     rectangle.setRigidBody()
     npt.assert_equal(rectangle.holes.tolist(), [[1., 1.]])
     npt.assert_equal(rectangle.auxiliaryVariables['RigidBody'], True)
     assembleDomainRANS(domain)
     isRigidBody = isinstance(domain.auxiliaryVariables['twp'][0], RigidBody)
     npt.assert_equal(isRigidBody, True)
Beispiel #5
0
    def test_assemble_domain(self):
        """
        Testing the assembleDomain() for different domains with multiple shapes
        """
        nb_shapes = 10
        domain2D = create_domain2D()
        domain2DRANS = create_domain2D()
        domain3D = create_domain3D()
        domain3DRANS = create_domain3D()
        dim2D = [1., 1.]
        dim3D = [1., 1., 1.]
        coords2D = np.array([0.5, 0.5])
        coords3D = np.array([0.5, 0.5, 0.5])
        nb_bc2D = 0
        nb_bc2DRANS = 0
        nb_bc3D = 0
        nb_bc3DRANS = 0
        for shape in range(nb_shapes):
            coords2D += 1.5
            a = create_rectangle(domain2D, dim=dim2D, coords=coords2D)
            nb_bc2D += len(a.BC_list)
            a = create_cuboid(domain3D, dim=dim3D, coords=coords3D)
            nb_bc3D += len(a.BC_list)
            a = create_rectangle(domain2DRANS,
                                 dim=dim2D,
                                 coords=coords2D,
                                 folder='mprans')
            nb_bc2DRANS += len(a.BC_list)
            a = create_cuboid(domain3DRANS,
                              dim=dim3D,
                              coords=coords3D,
                              folder='mprans')
            nb_bc3DRANS += len(a.BC_list)
        a = create_tank2D(domain2DRANS, dim=[50., 50.], coords=[25., 25.])
        nb_bc2DRANS += len(a.BC_list)
        a = create_tank3D(domain3DRANS,
                          dim=[50., 50., 50.],
                          coords=[25., 25., 25.])
        nb_bc3DRANS += len(a.BC_list)
        assembleDomain(domain2D)
        assembleDomain(domain3D)
        assembleDomainRANS(domain2DRANS)
        assembleDomainRANS(domain3DRANS)

        # check that each domain has the right number of shapes
        npt.assert_equal(len(domain2D.shape_list), nb_shapes)
        npt.assert_equal(len(domain3D.shape_list), nb_shapes)
        npt.assert_equal(len(domain2DRANS.shape_list), nb_shapes + 1)
        npt.assert_equal(len(domain3DRANS.shape_list), nb_shapes + 1)

        # check that the number of boundary conditions is right
        npt.assert_equal(len(domain2D.bc), nb_bc2D + 1)
        npt.assert_equal(len(domain3D.bc), nb_bc3D + 1)
        npt.assert_equal(len(domain2DRANS.bc), nb_bc2DRANS + 1)
        npt.assert_equal(len(domain3DRANS.bc), nb_bc3DRANS + 1)
Beispiel #6
0
    def test_assemble_domain(self):
        """
        Testing the assembleDomain() for different domains with multiple shapes
        """
        nb_shapes = 10
        domain2D = create_domain2D()
        domain2DRANS = create_domain2D()
        domain3D = create_domain3D()
        domain3DRANS = create_domain3D()
        dim2D = [1., 1.]
        dim3D = [1., 1., 1.]
        coords2D = np.array([0.5, 0.5])
        coords3D = np.array([0.5, 0.5, 0.5])
        nb_bc2D = 0
        nb_bc2DRANS = 0
        nb_bc3D = 0
        nb_bc3DRANS = 0
        for shape in range(nb_shapes):
            coords2D += 1.5
            a = create_rectangle(domain2D, dim=dim2D, coords=coords2D)
            nb_bc2D += len(a.BC_list)
            a = create_cuboid(domain3D, dim=dim3D, coords=coords3D)
            nb_bc3D += len(a.BC_list)
            a = create_rectangle(domain2DRANS, dim=dim2D, coords=coords2D,
                                folder='mprans')
            nb_bc2DRANS += len(a.BC_list)
            a = create_cuboid(domain3DRANS, dim=dim3D, coords=coords3D,
                            folder='mprans')
            nb_bc3DRANS += len(a.BC_list)
        a = create_tank2D(domain2DRANS, dim=[50., 50.], coords=[25., 25.])
        nb_bc2DRANS += len(a.BC_list)
        a = create_tank3D(domain3DRANS, dim=[50., 50., 50.],
                          coords=[25., 25., 25.])
        nb_bc3DRANS += len(a.BC_list)
        assembleDomain(domain2D)
        assembleDomain(domain3D)
        assembleDomainRANS(domain2DRANS)
        assembleDomainRANS(domain3DRANS)

        # check that each domain has the right number of shapes
        npt.assert_equal(len(domain2D.shape_list), nb_shapes)
        npt.assert_equal(len(domain3D.shape_list), nb_shapes)
        npt.assert_equal(len(domain2DRANS.shape_list), nb_shapes+1)
        npt.assert_equal(len(domain3DRANS.shape_list), nb_shapes+1)

        # check that the number of boundary conditions is right
        npt.assert_equal(len(domain2D.bc), nb_bc2D+1)
        npt.assert_equal(len(domain3D.bc), nb_bc3D+1)
        npt.assert_equal(len(domain2DRANS.bc), nb_bc2DRANS+1)
        npt.assert_equal(len(domain3DRANS.bc), nb_bc3DRANS+1)
    def test_gauges(self):
        domain = create_domain2D()
        tank = create_tank2D(domain)
        tank.attachPointGauges('kappa',
                               gauges=((('k', ), ((0., 0., 0.), )), ),
                               activeTime=(0., 1.),
                               sampleRate=0.5,
                               fileName='point1.csv')
        tank.attachLineGauges('kappa',
                              gauges=((('k', ), ((0., 0., 0.), (0., 0.,
                                                                1.))), ),
                              activeTime=(0., 2.),
                              sampleRate=0.5,
                              fileName='line1.csv')
        tank.attachLineIntegralGauges('vof',
                                      gauges=((('vof', ), ((0., 0., 0.),
                                                           (0., 0., 1.))), ),
                                      activeTime=(0., 2.),
                                      sampleRate=0.5,
                                      fileName='line_int1.csv')
        assert tank.auxiliaryVariables.get('Gauge_kappa', None) is not None
        assert tank.auxiliaryVariables.get('Gauge_vof', None) is not None
        assert len(tank.auxiliaryVariables['Gauge_kappa']) is 2
        assert len(tank.auxiliaryVariables['Gauge_vof']) is 1
        self.assertIsInstance(tank.auxiliaryVariables['Gauge_kappa'][0],
                              Gauges.Gauges)
        assert tank.auxiliaryVariables['Gauge_kappa'][0].activeTime == (0., 1.)
        assert tank.auxiliaryVariables['Gauge_kappa'][1].activeTime == (0., 2.)
        assert tank.auxiliaryVariables['Gauge_vof'][0].sampleRate == 0.5

        assembleDomainRANS(domain)

        assert domain.auxiliaryVariables.get('kappa', None) is not None
        assert domain.auxiliaryVariables.get('vof', None) is not None
        self.assertIsInstance(domain.auxiliaryVariables['vof'][0],
                              Gauges.Gauges)
        assert len(domain.auxiliaryVariables['kappa']) is 2
        assert len(domain.auxiliaryVariables['vof']) is 1
        assert domain.auxiliaryVariables['kappa'][0].activeTime == (0., 1.)
        assert domain.auxiliaryVariables['kappa'][1].activeTime == (0., 2.)
        assert domain.auxiliaryVariables['vof'][0].sampleRate == 0.5

        tank.attachPointGauges('voff',
                               gauges=((('vof', ), ((0., 0., 0.), )), ),
                               activeTime=(0., 1.),
                               sampleRate=0.5,
                               fileName='point2.csv')
        self.assertRaises(ValueError, assembleDomainRANS, domain)
Beispiel #8
0
    def test_gauges(self):
        domain = create_domain2D()
        tank = create_tank2D(domain)
        tank.attachPointGauges('kappa',
                               gauges = ((('k', ),((0.,0.,0.),)),),
                               activeTime = (0.,1.),
                               sampleRate = 0.5,
                               fileName = 'point1.csv')
        tank.attachLineGauges('kappa',
                               gauges = ((('k', ),((0.,0.,0.),(0.,0.,1.))),),
                               activeTime = (0.,2.),
                               sampleRate = 0.5,
                               fileName = 'line1.csv')
        tank.attachLineIntegralGauges('vof',
                                      gauges=(
                                      (('vof',), ((0., 0., 0.), (0., 0., 1.))),),
                                      activeTime=(0., 2.),
                                      sampleRate=0.5,
                                      fileName='line_int1.csv')
        assert tank.auxiliaryVariables.get('Gauge_kappa', None) is not None
        assert tank.auxiliaryVariables.get('Gauge_vof', None) is not None
        assert len(tank.auxiliaryVariables['Gauge_kappa']) is 2
        assert len(tank.auxiliaryVariables['Gauge_vof']) is 1
        self.assertIsInstance(tank.auxiliaryVariables['Gauge_kappa'][0],
                              Gauges.Gauges)
        assert tank.auxiliaryVariables['Gauge_kappa'][0].activeTime == (0.,1.)
        assert tank.auxiliaryVariables['Gauge_kappa'][1].activeTime == (0.,2.)
        assert tank.auxiliaryVariables['Gauge_vof'][0].sampleRate == 0.5

        assembleDomainRANS(domain)

        assert domain.auxiliaryVariables.get('kappa', None) is not None
        assert domain.auxiliaryVariables.get('vof', None) is not None
        self.assertIsInstance(domain.auxiliaryVariables['vof'][0],
                              Gauges.Gauges)
        assert len(domain.auxiliaryVariables['kappa']) is 2
        assert len(domain.auxiliaryVariables['vof']) is 1
        assert domain.auxiliaryVariables['kappa'][0].activeTime == (0., 1.)
        assert domain.auxiliaryVariables['kappa'][1].activeTime == (0., 2.)
        assert domain.auxiliaryVariables['vof'][0].sampleRate == 0.5

        tank.attachPointGauges('voff',
                                gauges=((('vof',), ((0., 0., 0.),)),),
                                activeTime=(0., 1.),
                                sampleRate=0.5,
                                fileName='point2.csv')
        self.assertRaises(ValueError,assembleDomainRANS,domain)
    def test_BC_flags(self):
        """
        Testing the flags of shapes and their in their domain
        """
        nb_shapes = 3
        domain2D = create_domain2D()
        domain3D = create_domain3D()
        domain2DRANS = create_domain2D()
        domain3DRANS = create_domain3D()
        domainSTL = create_domain3D()
        flags_v2D = []
        flags_s2D = []
        flags_v3D = []
        flags_f3D = []
        flags_v2DRANS = []
        flags_s2DRANS = []
        flags_v3DRANS = []
        flags_f3DRANS = []
        maxf = 0
        for i in range(nb_shapes):
            # 2D
            a = create_custom2D(domain2D)
            if flags_v2D:
                maxf = np.max([np.max(flags_v2D), np.max(flags_s2D)])
            flags_v2D += (a.vertexFlags + maxf).tolist()
            flags_s2D += (a.segmentFlags + maxf).tolist()
            # 3D
            a = create_custom3D(domain3D)
            if flags_v3D:
                maxf = np.max([np.max(flags_v3D), np.max(flags_f3D)])
            flags_v3D += (a.vertexFlags + maxf).tolist()
            flags_f3D += (a.facetFlags + maxf).tolist()
            # 2D RANS
            a = create_custom2D(domain2DRANS, folder='mprans')
            if flags_v2DRANS:
                maxf = np.max([np.max(flags_v2DRANS), np.max(flags_s2DRANS)])
            flags_v2DRANS += (a.vertexFlags + maxf).tolist()
            flags_s2DRANS += (a.segmentFlags + maxf).tolist()
            # 3D RANS
            a = create_custom3D(domain3DRANS, folder='mprans')
            if flags_v3DRANS:
                maxf = np.max([np.max(flags_v3DRANS), np.max(flags_f3DRANS)])
            flags_v3DRANS += (a.vertexFlags + maxf).tolist()
            flags_f3DRANS += (a.facetFlags + maxf).tolist()
        assembleDomain(domain2D)
        assembleDomain(domain3D)
        assembleDomainRANS(domain2DRANS)
        assembleDomainRANS(domain3DRANS)

        # test flags
        npt.assert_equal(domain2D.vertexFlags, flags_v2D)
        npt.assert_equal(domain2D.segmentFlags, flags_s2D)
        npt.assert_equal(domain3D.vertexFlags, flags_v3D)
        npt.assert_equal(domain3D.facetFlags, flags_f3D)
        npt.assert_equal(domain2DRANS.vertexFlags, flags_v2DRANS)
        npt.assert_equal(domain2DRANS.segmentFlags, flags_s2DRANS)
        npt.assert_equal(domain3DRANS.vertexFlags, flags_v3DRANS)
        npt.assert_equal(domain3DRANS.facetFlags, flags_f3DRANS)
        #stl flags
        path1 = getpath()
        stl = create_stl3D(domainSTL, os.path.join(path1, "STLBlocks.stl"))
        assembleDomainRANS(domainSTL)
        STLnames = ["Bed0", "Concrete0", "Inlet0", "Outlet0", "Top0", "Wall0"]
        nSTLs = len(STLnames)
        j = 0
        print
        for key, value in stl.boundaryTags.items():
            self.assertTrue(STLnames[value - 1] == key)
        for key, value in domainSTL.boundaryTags.items():
            self.assertTrue(stl.name + '_' + STLnames[value - 1] == key)

        npt.assert_equal(nSTLs, len(stl.boundaryTags))
    def test_assemble_domain(self):
        """
        Testing the assembleDomain() for different domains with multiple shapes
        """
        nb_shapes = 10
        domain2D = create_domain2D()
        domain2DRANS = create_domain2D()
        domain3D = create_domain3D()
        domain3DRANS = create_domain3D()
        domainSTL = create_domain3D()
        dim2D = np.array([1., 1.])
        dim3D = np.array([1., 1., 1.])
        coords2D = np.array([0.5, 0.5])
        coords3D = np.array([0.5, 0.5, 0.5])
        nb_bc2D = 0
        nb_bc2DRANS = 0
        nb_bc3D = 0
        nb_bc3DRANS = 0
        for shape in range(nb_shapes):
            coords2D += 1.5
            coords3D += 1.5
            a = create_rectangle(domain2D, dim=dim2D, coords=coords2D)
            nb_bc2D += len(a.BC_list)
            a = create_cuboid(domain3D, dim=dim3D, coords=coords3D)
            nb_bc3D += len(a.BC_list)
            a = create_rectangle(domain2DRANS,
                                 dim=dim2D,
                                 coords=coords2D,
                                 folder='mprans')
            nb_bc2DRANS += len(a.BC_list)
            a = create_cuboid(domain3DRANS,
                              dim=dim3D,
                              coords=coords3D,
                              folder='mprans')
            nb_bc3DRANS += len(a.BC_list)
        a = create_tank2D(domain2DRANS, dim=[50., 50.])
        nb_bc2DRANS += len(a.BC_list)
        a = create_tank3D(domain3DRANS, dim=[50., 50., 50.])
        nb_bc3DRANS += len(a.BC_list)
        assembleDomain(domain2D)
        assembleDomain(domain3D)
        assembleDomainRANS(domain2DRANS)
        assembleDomainRANS(domain3DRANS)

        x2D = domain2D.x
        x3D = domain3D.x
        x2DRANS = domain2DRANS.x
        x3DRANS = domain3DRANS.x
        L2D = domain2D.L
        L3D = domain3D.L
        L2DRANS = domain2DRANS.L
        L3DRANS = domain3DRANS.L

        # check that each domain has the right number of shapes
        npt.assert_equal(len(domain2D.shape_list), nb_shapes)
        npt.assert_equal(len(domain3D.shape_list), nb_shapes)
        npt.assert_equal(len(domain2DRANS.shape_list), nb_shapes + 1)
        npt.assert_equal(len(domain3DRANS.shape_list), nb_shapes + 1)

        # check that the number of boundary conditions is right
        npt.assert_equal(len(domain2D.bc), nb_bc2D + 1)
        npt.assert_equal(len(domain3D.bc), nb_bc3D + 1)
        npt.assert_equal(len(domain2DRANS.bc), nb_bc2DRANS + 1)
        npt.assert_equal(len(domain3DRANS.bc), nb_bc3DRANS + 1)

        # check that bounding boxes are rightly calculated
        npt.assert_equal(L2D, [14.5, 14.5])
        npt.assert_equal(L3D, [14.5, 14.5, 14.5])
        npt.assert_equal(L2DRANS, [50., 50.])
        npt.assert_equal(L3DRANS, [50., 50., 50.])
        npt.assert_equal(x2D, [1.5, 1.5])
        npt.assert_equal(x3D, [1.5, 1.5, 1.5])
        npt.assert_equal(x2DRANS, [0., 0.])
        npt.assert_equal(x3DRANS, [0., 0., 0.])

        #stl domain checks
        path1 = getpath()
        stl = create_stl3D(domainSTL, os.path.join(path1, "STLBlocks.stl"))
        assembleDomainRANS(domainSTL)
        STLnames = ["Bed0", "Concrete0", "Inlet0", "Outlet0", "Top0", "Wall0"]
        nSTLs = len(STLnames)
        npt.assert_equal(nSTLs, max(stl.vertexFlags))
        npt.assert_equal(nSTLs, max(stl.facetFlags))
        npt.assert_equal(nSTLs, max(domainSTL.vertexFlags))
        npt.assert_equal(nSTLs, max(domainSTL.facetFlags))