Exemple #1
0
 def test_05NodeValue(self):
     import numpy
     import CGNS.PAT.cgnsutils as CGU
     import CGNS.PAT.cgnserrors as CGE
     import CGNS.PAT.cgnskeywords as CGK
     self.genTree()
     v = CGU.getValueByPath(self.T, '/CGNSTree/CGNSLibraryVersion')
     self.assertEqual(v, numpy.array(3.2))
     n = ['ZoneType', numpy.array(['S', 't', 'r', 'u', 'c', 't', 'u', 'r', 'e', 'd'], dtype='S', order='C'), [],
          'ZoneType_t']
     self.assertTrue(CGU.stringValueMatches(n, 'Structured'))
     # set*AsArray
     self.assertEqual(CGU.setStringAsArray('Structured').tostring().decode('ascii'), 'Structured')
     self.assertEqual(CGU.setIntegerAsArray(1), numpy.array(1, dtype='int32'))
     self.assertTrue((CGU.setIntegerAsArray(1, 2, 3) == numpy.array([1, 2, 3], dtype='int32')).all())
     self.assertEqual(CGU.setLongAsArray(1), numpy.array(1, dtype='int64'))
     self.assertTrue((CGU.setLongAsArray(1, 2, 3) == numpy.array([1, 2, 3], dtype='int64')).all())
     self.assertEqual(CGU.setFloatAsArray(1), numpy.array(1, dtype='float32'))
     self.assertTrue((CGU.setFloatAsArray(1, 2, 3) == numpy.array([1, 2, 3], dtype='float32')).all())
     self.assertEqual(CGU.setDoubleAsArray(1), numpy.array(1, dtype='float64'))
     self.assertTrue((CGU.setDoubleAsArray(1, 2, 3) == numpy.array([1, 2, 3], dtype='float64')).all())
     self.assertTrue((CGU.setDoubleAsArray(tuple(range(10, 1010, 10))) == numpy.array(tuple(range(10, 1010, 10)),
                                                                                      dtype='float64')).all())
     n = ['ZoneType', None, [], 'ZoneType_t']
     # set*ByPath
     self.assertTrue(CGU.stringValueMatches(CGU.setStringByPath(n, '/', 'Structured'), 'Structured'))
     self.assertEqual(CGU.setIntegerByPath(n, '/', 1)[1], numpy.array(1, dtype='int32'))
     self.assertTrue(numpy.array_equal(CGU.setIntegerByPath(n, '/', 1, 2, 3)[1], numpy.array([1, 2, 3], dtype='int32')))
     self.assertEqual(CGU.setLongByPath(n, '/', 1)[1], numpy.array(1, dtype='int64'))
     self.assertTrue(numpy.array_equal(CGU.setLongByPath(n, '/', 1, 2, 3)[1], numpy.array([1, 2, 3], dtype='int64')))
     self.assertEqual(CGU.setFloatByPath(n, '/', 1)[1], numpy.array(1, dtype='float32'))
     self.assertTrue(numpy.array_equal(CGU.setFloatByPath(n, '/', 1, 2, 3)[1], numpy.array([1, 2, 3], dtype='float32')))
     self.assertEqual(CGU.setDoubleByPath(n, '/', 1)[1], numpy.array(1, dtype='float64'))
     self.assertTrue(numpy.array_equal(CGU.setDoubleByPath(n, '/', 1, 2, 3)[1], numpy.array([1, 2, 3], dtype='float64')))
     self.assertTrue(numpy.array_equal(CGU.setDoubleByPath(n, '/', range(10, 1010, 10))[1],
                                       numpy.array([range(10, 1010, 10)], dtype='float64')))
Exemple #2
0
CGL.newPointRange(n, value=NPY.array([[1, cellsize]], 'i'))
zbc[2] = []
n = CGL.newBoundary(zbc,
                    'BC', [range(1, cellsize + 1)],
                    btype=CGK.Null_s,
                    family=None,
                    pttype=CGK.PointList_s)
g = CGL.newGridLocation(n, value=CGK.CellCenter_s)
TESTS.append((tag, T, diag))

#  -------------------------------------------------------------------------
tag = 'bc both PointList and PointRange'
diag = False
(T, b, z, zbc, n, g) = makeCorrectTree(vertexsize, cellsize, ntris)
CGL.newPointRange(n, value=NPY.array([[cellsize + 1, cellsize + ntris]], 'i'))
TESTS.append((tag, T, diag))

#  -------------------------------------------------------------------------
tag = 'bc no PointList or PointRange'
diag = False
(T, b, z, zbc, n, g) = makeCorrectTree(vertexsize, cellsize, ntris)
CGU.removeChildByName(n, CGK.PointList_s)
TESTS.append((tag, T, diag))

#  -------------------------------------------------------------------------
tag = 'bc FamilySpecified but not FamilyName'
diag = False
(T, b, z, zbc, n, g) = makeCorrectTree(vertexsize, cellsize, ntris)
n[1] = CGU.setStringAsArray(CGK.FamilySpecified_s)
TESTS.append((tag, T, diag))
Exemple #3
0
tag = 'base dataclass #2'
diag = False
T = CGL.newCGNSTree()
b = CGL.newBase(T, '{Base}', 3, 3)
d = CGL.newDataClass(b, CGK.NormalizedByDimensional_s)
d[0] = 'dataclass'
d = CGL.newDataClass(b, CGK.NormalizedByDimensional_s)
TESTS.append((tag, T, diag))

#  -------------------------------------------------------------------------
tag = 'base dataclass #3'
diag = False
T = CGL.newCGNSTree()
b = CGL.newBase(T, '{Base}', 3, 3)
d = CGL.newDataClass(b, CGK.NormalizedByDimensional_s)
d[1] = CGU.setStringAsArray("NormalizedByDimensionnal")
TESTS.append((tag, T, diag))

#  -------------------------------------------------------------------------
tag = 'all levels dataclass'
diag = True
T = CGL.newCGNSTree()
b = CGL.newBase(T, '{Base}', 3, 3)
d = CGL.newFamily(b, '{Family}')
d = CGL.newDataClass(b, CGK.NondimensionalParameter_s)
z = CGL.newZone(b, '{Zone}',
                NPY.array([[5, 4, 0], [7, 6, 0], [9, 8, 0]], order='F'))
d = CGL.newDataClass(z, CGK.NondimensionalParameter_s)
g = CGL.newGridCoordinates(z, CGK.GridCoordinates_s)
w = CGL.newDataArray(g, CGK.CoordinateX_s,
                     NPY.ones((5, 7, 9), dtype='float64', order='F'))
Exemple #4
0
                   parent=z)
CGU.newNode(CGK.PointList_s,
            NPY.array([range(1, vertexsize + 1)],
                      dtype=NPY.int32,
                      order='Fortran'), [],
            CGK.IndexArray_ts,
            parent=zsr2)
CGL.newDataArray(zsr2,
                 'var',
                 value=NPY.ones(vertexsize, dtype='float64', order='Fortran'))
zsr3 = CGU.newNode('SubRegion3',
                   NPY.array([2], dtype=NPY.int32, order='Fortran'), [],
                   CGK.ZoneSubRegion_ts,
                   parent=z)
CGU.newNode(CGK.BCRegionName_s,
            CGU.setStringAsArray('BC'), [],
            CGK.Descriptor_ts,
            parent=zsr3)
CGL.newDataArray(zsr3,
                 'var',
                 value=NPY.ones(ntris, dtype='float64', order='Fortran'))
zsr5 = CGU.newNode('SubRegion5',
                   NPY.array([3], dtype=NPY.int32, order='Fortran'), [],
                   CGK.ZoneSubRegion_ts,
                   parent=z)
CGU.newNode(CGK.PointRange_s,
            NPY.array([[1, cellsize]], dtype=NPY.int32, order='Fortran'), [],
            CGK.IndexRange_ts,
            parent=zsr5)
CGL.newGridLocation(zsr5, value=CGK.CellCenter_s)
CGL.newDataArray(zsr5,
Exemple #5
0

vertexsize = 20
cellsize = 7
ntris = 11
(T, b, z) = makeCorrectTree(vertexsize, cellsize, ntris)
zsr1 = CGU.newNode('SubRegion1', NPY.array([3], dtype=NPY.int32, order='F'), [], CGK.ZoneSubRegion_ts, parent=z)
CGU.newNode(CGK.PointRange_s, NPY.array([[1, vertexsize]], dtype=NPY.int32, order='F'), [], CGK.IndexRange_ts,
            parent=zsr1)
CGL.newDataArray(zsr1, 'var', value=NPY.ones(vertexsize, dtype='float64', order='F'))
zsr2 = CGU.newNode('SubRegion2', NPY.array([3], dtype=NPY.int32, order='F'), [], CGK.ZoneSubRegion_ts, parent=z)
CGU.newNode(CGK.PointList_s, NPY.array([range(1, vertexsize + 1)], dtype=NPY.int32, order='F'), [],
            CGK.IndexArray_ts, parent=zsr2)
CGL.newDataArray(zsr2, 'var', value=NPY.ones(vertexsize, dtype='float64', order='F'))
zsr3 = CGU.newNode('SubRegion3', NPY.array([2], dtype=NPY.int32, order='F'), [], CGK.ZoneSubRegion_ts, parent=z)
CGU.newNode(CGK.BCRegionName_s, CGU.setStringAsArray('BC'), [], CGK.Descriptor_ts, parent=zsr3)
CGL.newDataArray(zsr3, 'var', value=NPY.ones(ntris, dtype='float64', order='F'))
zsr5 = CGU.newNode('SubRegion5', NPY.array([3], dtype=NPY.int32, order='F'), [], CGK.ZoneSubRegion_ts, parent=z)
CGU.newNode(CGK.PointRange_s, NPY.array([[1, cellsize]], dtype=NPY.int32, order='F'), [], CGK.IndexRange_ts,
            parent=zsr5)
CGL.newGridLocation(zsr5, value=CGK.CellCenter_s)
CGL.newDataArray(zsr5, 'var', value=NPY.ones(cellsize, dtype='float64', order='F'))
zsr6 = CGU.newNode('SubRegion6', NPY.array([3], dtype=NPY.int32, order='F'), [], CGK.ZoneSubRegion_ts, parent=z)
CGU.newNode(CGK.PointList_s, NPY.array([range(1, cellsize + 1)], dtype=NPY.int32, order='F'), [],
            CGK.IndexArray_ts, parent=zsr6)
CGL.newGridLocation(zsr6, value=CGK.CellCenter_s)
CGL.newDataArray(zsr6, 'var', value=NPY.ones(cellsize, dtype='float64', order='F'))
TESTS.append((tag, T, diag))

#  -------------------------------------------------------------------------
tag = 'zonesubregion bad node value'
Exemple #6
0
#  -------------------------------------------------------------------------
tag = 'zone bad zonetype'
diag = False
T = CGL.newCGNSTree()
b = CGL.newBase(T, '{Base}', 3, 3)
z = CGL.newZone(b, '{Zone}',
                NPY.array([[5, 4, 0], [7, 6, 0], [9, 8, 0]], order='F'))
g = CGL.newGridCoordinates(z, 'GridCoordinates')
d = CGL.newDataArray(g, CGK.CoordinateX_s,
                     NPY.ones((5, 7, 9), dtype='float64', order='F'))
d = CGL.newDataArray(g, CGK.CoordinateY_s,
                     NPY.ones((5, 7, 9), dtype='float64', order='F'))
d = CGL.newDataArray(g, CGK.CoordinateZ_s,
                     NPY.ones((5, 7, 9), dtype='float64', order='F'))
zt = CGU.hasChildName(z, CGK.ZoneType_s)
zt[1] = CGU.setStringAsArray('Untruscutred')
TESTS.append((tag, T, diag))

#  -------------------------------------------------------------------------
tag = 'zone bad zone size'
diag = False
T = CGL.newCGNSTree()
b = CGL.newBase(T, '{Base}', 3, 3)
z = CGL.newZone(b, '{Zone}',
                NPY.array([[5, 4, 0], [7, 6, 0], [9, 8, 0]], order='F'))
g = CGL.newGridCoordinates(z, 'GridCoordinates')
d = CGL.newDataArray(g, CGK.CoordinateX_s,
                     NPY.ones(5, dtype='float64', order='F'))
d = CGL.newDataArray(g, CGK.CoordinateY_s,
                     NPY.ones(5, dtype='float64', order='F'))
d = CGL.newDataArray(g, CGK.CoordinateZ_s,