def test(): T1 = CGL.newCGNSTree() b1 = CGL.newCGNSBase(T1, 'B1', 3, 3) b2 = CGL.newCGNSBase(T1, 'B2', 3, 3) f1 = CGL.newFamily(b1, 'F1') f2 = CGL.newFamily(b1, 'F2') f1 = CGL.newFamily(b2, 'F1') f2 = CGL.newFamily(b2, 'F2') f3 = CGL.newFamily(b2, 'F3') f4 = CGL.newFamily(b2, 'F4') z1 = CGL.newZone(b1, 'Z1', NPY.array([[5, 4, 0], [7, 6, 0], [9, 8, 0]], order='F')) z2 = CGL.newZone(b1, 'Z2', NPY.array([[5, 4, 0], [7, 6, 0], [9, 8, 0]], order='F')) z3 = CGL.newZone(b1, 'Z3', NPY.array([[5, 4, 0], [7, 6, 0], [9, 8, 0]], order='F')) z4 = CGL.newZone(b1, 'Z4', NPY.array([[5, 4, 0], [7, 6, 0], [9, 8, 0]], order='F')) z5 = CGL.newZone(b1, 'Z5', NPY.array([[5, 4, 0], [7, 6, 0], [9, 8, 0]], order='F')) z1 = CGL.newZone(b2, 'Z1', NPY.array([[5, 4, 0], [7, 6, 0], [9, 8, 0]], order='F')) z2 = CGL.newZone(b2, 'Z2', NPY.array([[5, 4, 0], [7, 6, 0], [9, 8, 0]], order='F')) z3 = CGL.newZone(b2, 'Z3', NPY.array([[5, 4, 0], [7, 6, 0], [9, 8, 0]], order='F')) T2 = CGL.newCGNSTree() b1 = CGL.newCGNSBase(T2, 'B1', 3, 3) b2 = CGL.newCGNSBase(T2, 'B2', 3, 3) b3 = CGL.newCGNSBase(T2, 'B3', 2, 2) f1 = CGL.newFamily(b1, 'F1') f1 = CGL.newFamily(b2, 'F1') f2 = CGL.newFamily(b2, 'F2') f3 = CGL.newFamily(b2, 'F3') f4 = CGL.newFamily(b2, 'F4') f5 = CGL.newFamily(b2, 'F5') f1 = CGL.newFamily(b3, 'F1') f2 = CGL.newFamily(b3, 'F2') z1 = CGL.newZone(b1, 'Z1', NPY.array([[5, 4, 0], [7, 6, 0], [9, 8, 0]], order='F')) z2 = CGL.newZone(b1, 'Z2', NPY.array([[5, 4, 0], [7, 6, 0], [9, 8, 0]], order='F')) z3 = CGL.newZone(b1, 'Z3', NPY.array([[5, 4, 0], [7, 6, 0], [9, 8, 0]], order='F')) z1 = CGL.newZone(b2, 'Z1', NPY.array([[5, 4, 0], [7, 6, 0], [9, 8, 0]], order='F')) z2 = CGL.newZone(b2, 'Z2', NPY.array([[5, 4, 0], [7, 6, 0], [9, 8, 0]], order='F')) z3 = CGL.newZone(b2, 'Z3', NPY.array([[5, 4, 0], [7, 6, 0], [9, 8, 0]], order='F')) z4 = CGL.newZone(b2, 'Z4', NPY.array([[5, 4, 0], [7, 6, 0], [9, 8, 0]], order='F')) T3 = CGL.newCGNSTree() b1 = CGL.newCGNSBase(T3, 'B1', 3, 3) b2 = CGL.newCGNSBase(T3, 'B7', 3, 3) b3 = CGL.newCGNSBase(T3, 'B8', 2, 2) f1 = CGL.newFamily(b1, 'F1') f1 = CGL.newFamily(b2, 'F8') Tlist = [] for TT in [T1, T2, T3]: Tlist.append(TT) count = 0 for t in Tlist: CGM.save('merge-T%.2d.hdf' % count, t, flags=CGM.S2P_TRACE) count += 1 T = mergeTrees(Tlist) CGM.save('merge-Result.hdf', T, flags=CGM.S2P_TRACE) return T
def transLinks(filename, L, P, C): LH = [] for l in L: LN = asHDFname(l[1], C) if (l[0] == ''): FA = l[1] else: FA = "%s/%s" % (l[0], l[1]) if (C.verbose): print(' ' * C.depth, '->', FA) FH = asHDFname(FA, C) if (convertInPlace(FA, FH, C)): LH.append([l[0], LN, l[2], l[3]]) (t, l, p) = CGM.load(filename) CGM.save(filename, t, links=LH) return LH
def convertInPlace(FA, FH, C): if (not os.path.exists(FA)): if (C.verbose): print(' ' * C.depth + " Error: Unreachable file: %s" % FA) return False elif (not CGM.probe(FA)): subprocess.check_output([C.converter, "-h", FA, FH]) return True else: if (C.verbose): print(' ' * C.depth + " Error: Mixing links to ADF and HDF files...") return False
def parseTree(filename): flags = CGM.S2P_DEFAULT (tree, l) = CGM.load(filename, flags, 0, None, [], None) typepath = [CGK.CGNSTree_ts, CGK.CGNSBase_ts, CGK.Zone_ts, CGK.Elements_ts] elist = CGU.getAllNodesByTypeList(tree, typepath) sn = 0 sl = [] sp = ARU.SectionParse() mr = 1 for e in elist: print('Parse ', e) sn += 1 ne = CGU.getNodeByPath(tree, e)[1] et = ne[0] eb = ne[1] ea = CGU.getNodeByPath(tree, e + '/' + CGK.ElementConnectivity_s)[1] if (et in sp.QUAD_SURFACE): sl.append(sp.extQuadFacesPoints(ea, et, sn, mr, eb)) if (et in sp.TRI_SURFACE): sl.append(sp.extTriFacesPoints(ea, et, sn, mr, eb)) mr = sl[-1][-1]
@asQuery def nodeTokenSearch(C): """ Search by Node token Search all nodes with NAME as a token in the PATH The argument name need not to be a tuple or to have quotes, all the following values are ok and would match the NAME <i>ZoneBC</i>: ZoneBC 'ZoneBC' ('ZoneBC',) """ if C.ARGS[0] in C.PATH: return C.PATH FILE = 'HYB/vbv-part32_comp_period_links_dom_32_SUB.hdf' ARGS = ['GridLocation'] # ----------------------------------------------------------------- import CGNS.MAP as CGM (t, l, p) = CGM.load(FILE) print(runQuery(t, l, p, nodeNameSearch, ['GridLocation'])) print(runQuery(t, l, p, nodeTokenSearch, ['Zone']))
def openFile(filename): flags = CGM.S2P_DEFAULTS | CGM.S2P_NODATA (t, l, p) = CGM.load(filename, flags=flags, maxdata=33, lksearch=['.']) return (t, l, p, filename)
def fileLinkZGC(*files): l = [] for f in files: l += [CGM.load(f)[0]]
p_arr = var_mat[:,8] # For now, skip the elem connectivity section. Because I do not need it. ############################## # Write to CGNS file ############################## import CGNS.PAT.cgnsutils as CGU import CGNS.PAT.cgnslib as CGL import CGNS.PAT.cgnskeywords as CK import CGNS.MAP as CGM T=CGL.newCGNSTree() B=CGL.newBase(T,'hpMusic_base',2,2) # The shape (3,1) is critical zone_size = np.array([[n_node, n_elem, 0]]) Z=CGL.newZone(B,'Solution',zone_size,CK.Unstructured_s,'') GC=CGL.newGridCoordinates(Z,name='GridCoordinates') FS=CGL.newFlowSolution(Z,name='FlowSolution',gridlocation='Vertex') GL=CGU.getNodeByPath(FS,'GridLocation') CGU.nodeDelete(FS,GL) coordinatex_node = CGL.newDataArray(GC,'CoordinateX',value=x_arr) coordinatey_node = CGL.newDataArray(GC,'CoordinateY',value=y_arr) density_node = CGL.newDataArray(FS,'Density',value=rho_arr) velocityx_node = CGL.newDataArray(FS,'VelocityX',value=u_arr) velocityy_node = CGL.newDataArray(FS,'VelocityY',value=v_arr) p_node = CGL.newDataArray(FS,'Pressure',value=p_arr) CGM.save("sol_tec.cgns",T)