def Zone_t(self, pth, node, parent, tree, log): rs = CGM.CHECK_OK zt = CGU.hasChildName(node, CGK.ZoneType_s) zv = [] if zt is not None: if CGU.stringValueMatches(zt, CGK.Structured_s): cd = self.context[CGK.CellDimension_s][pth] self.context[CGK.IndexDimension_s][pth] = cd elif CGU.stringValueMatches(zt, CGK.Unstructured_s): self.context[CGK.IndexDimension_s][pth] = 1 shp = (self.context[CGK.IndexDimension_s][pth], 3) if CGU.getShape(node) != shp: rs = log.push(pth, 'S009', CGU.getShape(node)) elif CGU.stringValueMatches(zt, CGK.Structured_s): zd = node[1] for nd in range(self.context[CGK.IndexDimension_s][pth]): zv.append(zd[nd][0]) if ((zd[nd][1] != zd[nd][0] - 1) or (zd[nd][2] != 0)): rs = log.push(pth, 'S010') else: zv.append(node[1][0][0]) self.context[CGK.VertexSize_s][pth] = tuple(zv) if CGU.hasChildNodeOfType(node, CGK.FamilyName_ts): basepath = [CGK.CGNSTree_ts, parent[0], node[0]] searchpath = basepath + [CGK.FamilyName_ts] famlist1 = CGU.getAllNodesByTypeOrNameList(tree, searchpath) searchpath = basepath + [CGK.AdditionalFamilyName_ts] famlist2 = CGU.getAllNodesByTypeOrNameList(tree, searchpath) for (famlist, diagmessage) in ((famlist1, 'S301'), (famlist2, 'S302')): for fampath in famlist: famdefinition = CGU.getNodeByPath(tree, fampath) if (famdefinition[1] is None): rs = log.push(pth, 'S300') else: famtarget = famdefinition[1].tostring().rstrip() famtargetpath = "/%s/%s" % (parent[0], famtarget) if (famtargetpath not in self.context): famtargetnode = CGU.getNodeByPath( tree, famtargetpath) if (famtargetnode is None): rs = log.push(pth, diagmessage, famtarget) else: self.context[famtargetpath][pth] = True if (not CGU.hasChildType(node, CGK.GridCoordinates_ts)): rs = log.push(pth, 'S602') elif (not CGU.hasChildName(node, CGK.GridCoordinates_s)): rs = log.push(pth, 'S603') if (not CGU.hasChildType(node, CGK.ZoneBC_ts)): rs = log.push(pth, 'S604') return rs
def CGNSBase_t(self, pth, node, parent, tree, log): rs = CGM.CHECK_OK (cd, pd) = (0, 0) if not CGU.hasChildNodeOfType(node, CGK.Zone_ts): rs = log.push(pth, 'U101') else: target = [CGK.CGNSTree_ts, node[0], CGK.Zone_ts, CGK.ZoneType_s] plist = CGU.getAllNodesByTypeOrNameList(tree, target) found = False for p in plist: if (CGU.stringValueMatches(CGU.getNodeByPath(tree, p), CGK.Structured_s)): found = True if not found: rs = log.push(pth, 'U102') if not CGU.hasChildNodeOfType(node, CGK.ReferenceState_ts): rs = log.push(pth, 'U103') if CGU.getShape(node) != (2,): rs = log.push(pth, 'S009', CGU.getShape(node)) else: cd = node[1][0] pd = node[1][1] allowedvalues = ((1, 1), (1, 2), (1, 3), (2, 2), (2, 3), (3, 3)) if (cd, pd) not in allowedvalues: rs = log.push(pth, 'S010', (cd, pd)) self.context[CGK.CellDimension_s] = cd self.context[CGK.PhysicalDimension_s] = pd return rs
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')))
def getBCbyFamily(T, family): """Finds all BC that belongs to a family. Works with more than one base. Returns a list of path, you have to use getNodeByPath to retrieve the actual node.""" result = [] fpath = [ CGK.CGNSTree_ts, CGK.CGNSBase_t, CGK.Zone_t, CGK.ZoneBC_t, CGK.BC_t, CGK.FamilyName_t ] flist = CGU.getAllNodesByTypeOrNameList(T, fpath) for famnamepath in flist: fnode = CGU.getNodeByPath(T, famnamepath) if (CGU.stringValueMatches(fnode, family)): bcpath = CGU.getAncestor(famnamepath) result.append(bcpath) return result