Esempio n. 1
0
def create_cube(shape, width, height, depth):
    """ Creates a cube-shaped single-zone structured domain. """
    imax, jmax, kmax = shape

    delta_x = float(width)  / (imax - 1)
    delta_y = float(height) / (jmax - 1)
    delta_z = float(depth)  / (kmax - 1)

    dtype = numpy.float32  # Default single-precision.

    x = numpy.zeros(shape, dtype=dtype)
    y = numpy.zeros(shape, dtype=dtype)
    z = numpy.zeros(shape, dtype=dtype)

    q1 = numpy.zeros(shape, dtype=dtype)
    q2 = numpy.zeros(shape, dtype=dtype)
    q3 = numpy.zeros(shape, dtype=dtype)
    q4 = numpy.zeros(shape, dtype=dtype)
    q5 = numpy.zeros(shape, dtype=dtype)

    for i in range(imax):
        for j in range(jmax):
            for k in range(kmax):
                x.itemset(i, j, k, delta_x * i)
                y.itemset(i, j, k, delta_y * j)
                z.itemset(i, j, k, delta_z * k)

                q1.itemset(i, j, k, delta_x * i)

                q2.itemset(i, j, k, delta_x * i)
                q3.itemset(i, j, k, delta_y * j)
                q4.itemset(i, j, k, delta_z * k)

                q5.itemset(i, j, k, delta_z * k)

    momentum = Vector()
    momentum.x = q2
    momentum.y = q3
    momentum.z = q4
    
    zone = Zone()
    zone.grid_coordinates.x = x
    zone.grid_coordinates.y = y
    zone.grid_coordinates.z = z

    zone.flow_solution.mach = 0.5
    zone.flow_solution.alpha = 0.
    zone.flow_solution.reynolds = 100000.
    zone.flow_solution.time = 42.

    zone.flow_solution.add_array('density', q1)
    zone.flow_solution.add_vector('momentum', momentum)
    zone.flow_solution.add_array('energy_stagnation_density', q5)

    domain = DomainObj()
    domain.reference_state = dict(length_reference=PhysicalQuantity(1., 'ft'))
    domain.add_zone('xyzzy', zone)

    return domain
Esempio n. 2
0
def create_cube(shape, width, height, depth):
    """ Creates a cube-shaped single-zone structured domain. """
    imax, jmax, kmax = shape

    delta_x = float(width)  / (imax - 1)
    delta_y = float(height) / (jmax - 1)
    delta_z = float(depth)  / (kmax - 1)

    dtype = numpy.float32  # Default single-precision.

    x = numpy.zeros(shape, dtype=dtype)
    y = numpy.zeros(shape, dtype=dtype)
    z = numpy.zeros(shape, dtype=dtype)

    q1 = numpy.zeros(shape, dtype=dtype)
    q2 = numpy.zeros(shape, dtype=dtype)
    q3 = numpy.zeros(shape, dtype=dtype)
    q4 = numpy.zeros(shape, dtype=dtype)
    q5 = numpy.zeros(shape, dtype=dtype)

    for i in range(imax):
        for j in range(jmax):
            for k in range(kmax):
                x.itemset(i, j, k, delta_x * i)
                y.itemset(i, j, k, delta_y * j)
                z.itemset(i, j, k, delta_z * k)

                q1.itemset(i, j, k, delta_x * i)

                q2.itemset(i, j, k, delta_x * i)
                q3.itemset(i, j, k, delta_y * j)
                q4.itemset(i, j, k, delta_z * k)

                q5.itemset(i, j, k, delta_z * k)

    momentum = Vector()
    momentum.x = q2
    momentum.y = q3
    momentum.z = q4
    
    zone = Zone()
    zone.grid_coordinates.x = x
    zone.grid_coordinates.y = y
    zone.grid_coordinates.z = z

    zone.flow_solution.mach = 0.5
    zone.flow_solution.alpha = 0.
    zone.flow_solution.reynolds = 100000.
    zone.flow_solution.time = 42.

    zone.flow_solution.add_array('density', q1)
    zone.flow_solution.add_vector('momentum', momentum)
    zone.flow_solution.add_array('energy_stagnation_density', q5)

    domain = DomainObj()
    domain.reference_state = dict(length_reference=PhysicalQuantity(1., 'ft'))
    domain.add_zone('xyzzy', zone)

    return domain
Esempio n. 3
0
def create_wedge_2d(shape, inner, outer, angle):
    """ Creates a 2D wedge-shaped single-zone structured domain. """
    imax, jmax = shape

    delta_radius = float(outer - inner) / (imax - 1) if imax > 1 else 1.
    delta_theta  = float(angle * _DEG2RAD) / (jmax - 1) if jmax > 1 else 1.

    dtype = numpy.float32  # Default single-precision.

    x = numpy.zeros(shape, dtype=dtype)
    y = numpy.zeros(shape, dtype=dtype)

    q1 = numpy.zeros(shape, dtype=dtype)
    q2 = numpy.zeros(shape, dtype=dtype)
    q3 = numpy.zeros(shape, dtype=dtype)
    q4 = numpy.zeros(shape, dtype=dtype)

    for i in range(imax):
        radial = inner + delta_radius * i
        for j in range(jmax):
            tangential = delta_theta * j

            x.itemset(i, j, radial * cos(tangential))
            y.itemset(i, j, radial * sin(tangential))

            q1.itemset(i, j, radial)

            q2.itemset(i, j, radial)
            q3.itemset(i, j, tangential)

            q4.itemset(i, j, tangential)

    momentum = Vector()
    momentum.x = q2
    momentum.y = q3
    
    zone = Zone()
    zone.grid_coordinates.x = x
    zone.grid_coordinates.y = y

    zone.flow_solution.mach = 0.5
    zone.flow_solution.alpha = 0.
    zone.flow_solution.reynolds = 100000.
    zone.flow_solution.time = 42.

    zone.flow_solution.add_array('density', q1)
    zone.flow_solution.add_vector('momentum', momentum)
    zone.flow_solution.add_array('energy_stagnation_density', q4)

    domain = DomainObj()
    domain.reference_state = dict(length_reference=PhysicalQuantity(1., 'ft'))
    domain.add_zone('xyzzy', zone)

    return domain
Esempio n. 4
0
def create_wedge_2d(shape, inner, outer, angle):
    """ Creates a 2D wedge-shaped single-zone structured domain. """
    imax, jmax = shape

    delta_radius = float(outer - inner) / (imax - 1) if imax > 1 else 1.
    delta_theta = float(angle * _DEG2RAD) / (jmax - 1) if jmax > 1 else 1.

    dtype = numpy.float32  # Default single-precision.

    x = numpy.zeros(shape, dtype=dtype)
    y = numpy.zeros(shape, dtype=dtype)

    q1 = numpy.zeros(shape, dtype=dtype)
    q2 = numpy.zeros(shape, dtype=dtype)
    q3 = numpy.zeros(shape, dtype=dtype)
    q4 = numpy.zeros(shape, dtype=dtype)

    for i in range(imax):
        radial = inner + delta_radius * i
        for j in range(jmax):
            tangential = delta_theta * j

            x.itemset(i, j, radial * cos(tangential))
            y.itemset(i, j, radial * sin(tangential))

            q1.itemset(i, j, radial)

            q2.itemset(i, j, radial)
            q3.itemset(i, j, tangential)

            q4.itemset(i, j, tangential)

    momentum = Vector()
    momentum.x = q2
    momentum.y = q3

    zone = Zone()
    zone.grid_coordinates.x = x
    zone.grid_coordinates.y = y

    zone.flow_solution.mach = 0.5
    zone.flow_solution.alpha = 0.
    zone.flow_solution.reynolds = 100000.
    zone.flow_solution.time = 42.

    zone.flow_solution.add_array('density', q1)
    zone.flow_solution.add_vector('momentum', momentum)
    zone.flow_solution.add_array('energy_stagnation_density', q4)

    domain = DomainObj()
    domain.reference_state = dict(length_reference=PhysicalQuantity(1., 'ft'))
    domain.add_zone('xyzzy', zone)

    return domain
Esempio n. 5
0
def create_curve_2d(npoints, radius, angle):
    """ Creates a curve (arc) of `npoints` at `radius` through `angle`. """
    delta_theta  = float(angle * _DEG2RAD) / (npoints - 1)
    dtype = numpy.float32  # Default single-precision.
    shape = (npoints,)

    x = numpy.zeros(shape, dtype=dtype)
    y = numpy.zeros(shape, dtype=dtype)

    q1 = numpy.zeros(shape, dtype=dtype)
    q2 = numpy.zeros(shape, dtype=dtype)
    q3 = numpy.zeros(shape, dtype=dtype)
    q4 = numpy.zeros(shape, dtype=dtype)

    for i in range(npoints):
        tangential = delta_theta * i

        x.itemset(i, radius * cos(tangential))
        y.itemset(i, radius * sin(tangential))

        q1.itemset(i, radius)

        q2.itemset(i, radius)
        q3.itemset(i, tangential)

        q4.itemset(i, tangential)

    momentum = Vector()
    momentum.x = q2
    momentum.y = q3
    
    zone = Zone()
    zone.grid_coordinates.x = x
    zone.grid_coordinates.y = y

    zone.flow_solution.mach = 0.5
    zone.flow_solution.alpha = 0.
    zone.flow_solution.reynolds = 100000.
    zone.flow_solution.time = 42.

    zone.flow_solution.add_array('density', q1)
    zone.flow_solution.add_vector('momentum', momentum)
    zone.flow_solution.add_array('energy_stagnation_density', q4)

    domain = DomainObj()
    domain.reference_state = dict(length_reference=PhysicalQuantity(1., 'ft'))
    domain.add_zone('xyzzy', zone)

    return domain
Esempio n. 6
0
def create_curve_2d(npoints, radius, angle):
    """ Creates a curve (arc) of `npoints` at `radius` through `angle`. """
    delta_theta = float(angle * _DEG2RAD) / (npoints - 1)
    dtype = numpy.float32  # Default single-precision.
    shape = (npoints, )

    x = numpy.zeros(shape, dtype=dtype)
    y = numpy.zeros(shape, dtype=dtype)

    q1 = numpy.zeros(shape, dtype=dtype)
    q2 = numpy.zeros(shape, dtype=dtype)
    q3 = numpy.zeros(shape, dtype=dtype)
    q4 = numpy.zeros(shape, dtype=dtype)

    for i in range(npoints):
        tangential = delta_theta * i

        x.itemset(i, radius * cos(tangential))
        y.itemset(i, radius * sin(tangential))

        q1.itemset(i, radius)

        q2.itemset(i, radius)
        q3.itemset(i, tangential)

        q4.itemset(i, tangential)

    momentum = Vector()
    momentum.x = q2
    momentum.y = q3

    zone = Zone()
    zone.grid_coordinates.x = x
    zone.grid_coordinates.y = y

    zone.flow_solution.mach = 0.5
    zone.flow_solution.alpha = 0.
    zone.flow_solution.reynolds = 100000.
    zone.flow_solution.time = 42.

    zone.flow_solution.add_array('density', q1)
    zone.flow_solution.add_vector('momentum', momentum)
    zone.flow_solution.add_array('energy_stagnation_density', q4)

    domain = DomainObj()
    domain.reference_state = dict(length_reference=PhysicalQuantity(1., 'ft'))
    domain.add_zone('xyzzy', zone)

    return domain
Esempio n. 7
0
    def test_domain(self):
        logging.debug('')
        logging.debug('test_domain')

        logger = logging.getLogger()
        wedge = create_wedge_3d((30, 20, 10), 5., 0.5, 2., 30., 'x')

        domain = DomainObj()
        self.assertEqual(domain.reference_state, None)
        self.assertEqual(domain.zones, [])
        self.assertEqual(domain.shape, [])
        self.assertEqual(domain.extent, [])

        self.assertFalse(domain.is_equivalent([], logger))

        domain.add_domain(wedge, make_copy=True)
        self.assertTrue(domain.is_equivalent(wedge))
        self.assertEqual(domain.shape, [(30, 20, 10)])
        self.assertEqual(domain.extent[0][:2], (0., 5.))
        self.assertEqual(domain.xyzzy.flow_solution.momentum.shape,
                         (30, 20, 10))

        domain.rename_zone('wedge', domain.xyzzy)
        self.assertFalse(domain.is_equivalent(wedge, logger))

        domain = wedge.copy()
        zone = domain.remove_zone('xyzzy')
        self.assertFalse(domain.is_equivalent(wedge, logger))
        domain.add_zone('xyzzy', zone)
        self.assertTrue(domain.is_equivalent(wedge, logger))
        zone = domain.remove_zone(zone)
        self.assertFalse(domain.is_equivalent(wedge, logger))
        domain.add_zone('xyzzy', zone)
        self.assertTrue(domain.is_equivalent(wedge, logger))

        assert_raises(self, 'domain.remove_zone(Zone())', globals(), locals(),
                      ValueError, 'cannot find zone!')

        # Translations ordered for test coverage.
        domain.translate(0., 0., 0.5)
        self.assertFalse(domain.is_equivalent(wedge, logger))

        domain.translate(0., 1., 0.)
        self.assertFalse(domain.is_equivalent(wedge, logger))

        domain.translate(2.5, 0., 0.)
        self.assertFalse(domain.is_equivalent(wedge, logger))

        domain.rotate_about_x(90.)

        domain.add_domain(wedge)
        self.assertEqual(domain.shape, [(30, 20, 10), (30, 20, 10)])

        # Uncomment to visualize result.
        #        write_plot3d_q(domain, 'doubled.xyz', 'doubled.q')

        domain.rotate_about_y(90.)
        domain.rotate_about_z(90.)

        domain.deallocate()
        self.assertEqual(domain.shape, [])
        self.assertEqual(domain.extent, [])

        domain = wedge.copy()

        assert_raises(self, "domain.add_zone('xyzzy', wedge)", globals(),
                      locals(), ValueError, "name 'xyzzy' is already bound")

        assert_raises(self, "domain.rename_zone('xyzzy', domain.xyzzy)",
                      globals(), locals(), ValueError,
                      "name 'xyzzy' is already bound")
    def test_domain(self):
        logging.debug('')
        logging.debug('test_domain')

        logger = logging.getLogger()
        wedge = create_wedge_3d((30, 20, 10), 5., 0.5, 2., 30., 'x')

        domain = DomainObj()
        self.assertEqual(domain.reference_state, None)
        self.assertEqual(domain.zones, [])
        self.assertEqual(domain.shape, [])
        self.assertEqual(domain.extent, [])

        self.assertFalse(domain.is_equivalent([], logger))

        domain.add_domain(wedge, make_copy=True)
        self.assertTrue(domain.is_equivalent(wedge))
        self.assertEqual(domain.shape, [(30, 20, 10)])
        self.assertEqual(domain.extent[0][:2], (0., 5.))
        self.assertEqual(domain.xyzzy.flow_solution.momentum.shape,
                         (30, 20, 10))

        domain.rename_zone('wedge', domain.xyzzy)
        self.assertFalse(domain.is_equivalent(wedge, logger))

        domain = wedge.copy()
        zone = domain.remove_zone('xyzzy')
        self.assertFalse(domain.is_equivalent(wedge, logger))
        domain.add_zone('xyzzy', zone)
        self.assertTrue(domain.is_equivalent(wedge, logger))
        zone = domain.remove_zone(zone)
        self.assertFalse(domain.is_equivalent(wedge, logger))
        domain.add_zone('xyzzy', zone)
        self.assertTrue(domain.is_equivalent(wedge, logger))

        assert_raises(self, 'domain.remove_zone(Zone())', globals(), locals(),
                      ValueError, 'cannot find zone!')

        # Translations ordered for test coverage.
        domain.translate(0., 0., 0.5)
        self.assertFalse(domain.is_equivalent(wedge, logger))

        domain.translate(0., 1., 0.)
        self.assertFalse(domain.is_equivalent(wedge, logger))

        domain.translate(2.5, 0., 0.)
        self.assertFalse(domain.is_equivalent(wedge, logger))

        domain.rotate_about_x(90.)

        domain.add_domain(wedge)
        self.assertEqual(domain.shape, [(30, 20, 10), (30, 20, 10)])

        # Uncomment to visualize result.
#        write_plot3d_q(domain, 'doubled.xyz', 'doubled.q')

        domain.rotate_about_y(90.)
        domain.rotate_about_z(90.)

        domain.deallocate()
        self.assertEqual(domain.shape, [])
        self.assertEqual(domain.extent, [])

        domain = wedge.copy()

        assert_raises(self, "domain.add_zone('xyzzy', wedge)",
                      globals(), locals(), ValueError,
                      "name 'xyzzy' is already bound")

        assert_raises(self, "domain.rename_zone('xyzzy', domain.xyzzy)",
                      globals(), locals(), ValueError,
                      "name 'xyzzy' is already bound")