pyNastran  0.5.0
pyNastran BDF Reader/Writer, OP2 Parser, and GUI
panairGrid.py
Go to the documentation of this file.
00001 ## GNU Lesser General Public License
00002 ## 
00003 ## Program pyNastran - a python interface to NASTRAN files
00004 ## Copyright (C) 2011-2012  Steven Doyle, Al Danial
00005 ## 
00006 ## Authors and copyright holders of pyNastran
00007 ## Steven Doyle <mesheb82@gmail.com>
00008 ## Al Danial    <al.danial@gmail.com>
00009 ## 
00010 ## This file is part of pyNastran.
00011 ## 
00012 ## pyNastran is free software: you can redistribute it and/or modify
00013 ## it under the terms of the GNU Lesser General Public License as published by
00014 ## the Free Software Foundation, either version 3 of the License, or
00015 ## (at your option) any later version.
00016 ## 
00017 ## pyNastran is distributed in the hope that it will be useful,
00018 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 ## GNU General Public License for more details.
00021 ## 
00022 ## You should have received a copy of the GNU Lesser General Public License
00023 ## along with pyNastran.  If not, see <http://www.gnu.org/licenses/>.
00024 ## 
00025 #import os
00026 #import sys
00027 #import copy
00028 from itertools import izip, count
00029 
00030 from math import ceil, sin, cos, radians
00031 from numpy import array, zeros, ones
00032 
00033 
00034 from panairGridPatch import PanairPatch, PanairWakePatch, PanairGridHelper
00035 from panairWrite import PanairWrite
00036 
00037 #from pyNastran.general.general import ListPrint
00038 
00039 #CL = -Fx*sin(alpha)*cos(beta) + Fy*sin(alpha)*sin(beta) +Fz*cos(alpha)
00040 #CD =  Fx*cos(alpha)*cos(beta) - Fy*cos(alpha)*sin(beta) +Fz*sin(alpha)
00041 #CY =  Fx*sin(beta) +Fy*cos(beta)
00042 
00043 
00044 def fortranValue(value):
00045     return "%8.4E" %(value)
00046 
00047 class PanairGrid(PanairGridHelper,PanairWrite):
00048     modelType = 'panair'
00049     def __init__(self,infileName,log=None,debug=True):
00050         self.infileName = infileName
00051         self.nNetworks = 0
00052         self.patches = {}
00053         
00054         self.alphas = [0.]
00055         self.ncases = 0.
00056         self.betas = [0.]
00057         self.alphaC = 0.
00058         self.betaC  = 0.
00059 
00060 
00061         self.sref=1.
00062         self.bref=1.
00063         self.cref=1.
00064         self.dref=1.
00065 
00066         self.xref=0.
00067         self.yref=0.
00068         self.zref=0.
00069 
00070         self.xyzSection = ''
00071         self.streamlineSection = ''
00072         self.flowSection = ''
00073         self.sectionalPropSection = ''
00074         self.gridSection = ''
00075 
00076         self.msg = ''
00077 
00078         if log is None:
00079             from pyNastran.general.logger import dummyLogger
00080             if debug:
00081                 word = 'debug'
00082             else:
00083                 word = 'info'
00084             loggerObj = dummyLogger()
00085             log = loggerObj.startLog(word) # or info
00086         self.log = log
00087     
00088     def printFile(self):
00089         msg = ''
00090         for i,line in enumerate(self.lines):
00091             msg += "%6s %s" %(i+1,line )
00092         msg += '                                      record of input processing\n\n\n'
00093         return msg
00094 
00095     def getPanelPoints(self,iPanel):
00096         r = iPanel%(self.nRows-1)
00097         c = iPanel/(self.nRows-1)
00098 
00099         #print "r=%s c=%s" %(r,c)
00100         p1 = self.getPoint(r,  c  )
00101         p2 = self.getPoint(r,  c+1)
00102         p3 = self.getPoint(r+1,c+1)
00103         p4 = self.getPoint(r+1,c  )
00104         return (p1,p2,p3,p4)
00105 
00106     def getPanelPointIDs(self,iPanel):
00107         r = iPanel%(self.nRows-1)
00108         c = iPanel/(self.nRows-1)
00109 
00110         #print "r=%s c=%s" %(r,c)
00111         p1 = self.getPointID(r,  c  )
00112         p2 = self.getPointID(r,  c+1)
00113         p3 = self.getPointID(r+1,c+1)
00114         p4 = self.getPointID(r+1,c  )
00115         return (p1,p2,p3,p4)
00116 
00117     def nPanels(self):
00118         totalNPanels = 0
00119         for patchID in xrange(self.nPatches()):
00120             patch = self.patch(patchID)
00121             if patch.kt==1:
00122                 totalNPanels += patch.nPanels()
00123                 self.log.debug("nPanels = %s" %(totalNPanels))
00124         return totalNPanels
00125 
00126     def nPatches(self):
00127         return len(self.patches)
00128 
00129     def patch(self,ID):
00130         return self.patches[ID]
00131 
00132     def updateCases(self):
00133         """
00134         reduces confusion by only printing cases that will run
00135         """
00136         if len(self.alphas)>self.ncases:
00137            self.alphas = self.alphas[:self.ncases] 
00138         if len(self.betas)>self.ncases:
00139            self.betas = self.alphas[:self.ncases] 
00140 
00141     def writeGrid(self,outfileName):
00142         self.updateCases()
00143         outfile = open(outfileName,'wb')
00144         outfile.write(self.titleSection)
00145         outfile.write(self.writeDataCheck())
00146         outfile.write(self.symmetrySection)
00147         
00148         outfile.write(self.writeMach())
00149         outfile.write(self.writeCases())
00150         outfile.write(self.writeAlphas())
00151         outfile.write(self.writeReferenceQuantities())
00152 
00153 
00154         #outfile.write(self.alphaSection)
00155         #outfile.write(self.caseSection)
00156         
00157         for patchName,patch in sorted(self.patches.items()):
00158             outfile.write(str(patch))
00159         
00160         outfile.write(self.xyzSection)
00161         outfile.write(self.streamlineSection)
00162         outfile.write(self.flowSection)
00163         outfile.write(self.sectionalPropSection)
00164         outfile.write(self.gridSection)
00165         outfile.write(self.writePrintout())
00166 
00167         outfile.write(self.peaSection)
00168         outfile.write(self.writeLiberalizedAbutments())
00169         outfile.write(self.writeEnd())
00170 
00171         outfile.close()
00172 
00173     def removeComments(self, lines):
00174         lines2 = []
00175         for line in lines:
00176             line = line.rstrip().lower()
00177             if '=' in line:
00178                 #print "line -> |%s|" %(line)
00179                 if '=' is not line[0]:
00180                     self.log.debug("line[0] -> %s" %(line[0]))
00181                     line = line.split('=')[0]
00182                     self.log.debug("******")
00183                     lines2.append(line)
00184                 # else: skip
00185             else:
00186                 lines2.append(line)
00187         
00188         return lines2
00189 
00190     def getTitle(self, section):
00191         #print "hi"
00192         #self.title = section[1:]
00193         self.titleSection = '\n'.join(section)+'\n'
00194         self.titleLines = section[1:]
00195         return True
00196 
00197     def getDataCheck(self, section):
00198         self.dataCheck = int(float(section[1][0:10]))
00199         self.dataCheck = 2
00200         return True
00201 
00202     def getSymmetry(self, section):
00203         """
00204         $symmetry - xz plane of symmetry
00205         =misymm   mjsymm
00206         1.        0.
00207         
00208         @warning
00209             doesnt consider antisymmetryic
00210         """
00211         self.XZsymmetry = int(float(section[1][0 :10]))  # doesnt consider antisymmetric
00212         self.XYsymmetry = int(float(section[1][10:20]))  # doesnt consider antisymmetric
00213         self.nSymmetryPlanes = self.XZsymmetry+self.XYsymmetry
00214         self.symmetrySection = '\n'.join(section)+'\n'
00215         self.log.debug("XZsymmetry=%s XYsymmetry=%s" %(self.XZsymmetry,self.XYsymmetry))
00216         return True
00217 
00218     def splitPoints(self,lines,nActual,nRemainder):
00219         """
00220         reads the points
00221         """
00222         points = []
00223         for n in xrange(nActual):
00224             #(x1,y1,z1) = lines[n][0 :10].strip(),lines[n][10:20].strip(),lines[n][20:30].strip()
00225             #print "x1=%s y1=%s z1=%s" %(x1,y1,z1)
00226             (x1,y1,z1) = float(lines[n][0 :10]),float(lines[n][10:20]),float(lines[n][20:30])
00227             (x2,y2,z2) = float(lines[n][30:40]),float(lines[n][40:50]),float(lines[n][50:60])
00228             point1 = array([x1,y1,z1])
00229             point2 = array([x2,y2,z2])
00230             #point1 = [x1,y1,z1]
00231             #point2 = [x2,y2,z2]
00232             #print ListPrint(point1)
00233             #print ListPrint(point2)
00234             points.append(point1); points.append(point2)
00235         ###
00236 
00237         if nRemainder:
00238             n+=1
00239             #print "***"
00240             (x1,y1,z1) = float(lines[n][0 :10]),float(lines[n][10:20]),float(lines[n][20:30])
00241             point1 = array([x1,y1,z1])
00242             #print ListPrint(point1)
00243             points.append(point1)
00244         #print "points = ",ListPrint(points)
00245         return points
00246 
00247     def addWakePatch(self,netName,options,x,y,z):
00248         #print "self.nNetworks = ",self.nNetworks
00249         patch = PanairWakePatch(self.nNetworks,netName,options,x,y,z,self.log)
00250         self.msg += patch.process()
00251         #print "patch = ",patch
00252         self.patches[patch.iNetwork] = patch # deepcopy?
00253         self.nNetworks+=1
00254 
00255     def addPatch(self,netName,kt,cpNorm,x,y,z):
00256         #print "self.nNetworks = ",self.nNetworks
00257         patch = PanairPatch(self.nNetworks,netName,kt,cpNorm,x,y,z,self.log)
00258         self.msg += patch.process()
00259         #print "patch = ",patch
00260         self.patches[patch.iNetwork] = patch # deepcopy?
00261         self.nNetworks+=1
00262     
00263     def findPatchByName(self, netName):
00264         names = []
00265         for patchID,patch in self.patches.items():
00266             self.log.debug("patchID=%s" %(patchID))
00267             #self.log.debug("*patch = %s" %(patch))
00268             self.log.debug("patch.netName=%s" %(patch.netName))
00269             if patch.netName == netName:
00270                 return patch
00271             names.append(patch.netName)
00272         raise KeyError('couldnt findPatchbyName name=|%s| names=%s' %(netName,names))
00273 
00274     def getPoints(self, section):
00275         """
00276         $points - wing-body  with composite panels
00277         =kn                                               cpnorm
00278         4.                                                2.
00279         =kt
00280         1.
00281         =nm       nn                                                          netname
00282         11.       3.                                                          winga
00283         =x(1,1)   y(1,1)    z(1,1)    x(*,*)    y(*,*)    z(*,*)
00284            69.4737    9.2105    0.0000   63.7818    9.5807    0.7831
00285         """
00286         nNetworks = int(float(section[1][0 :10]))
00287         cpNorm = section[1][50:60].strip()
00288         #    cpNorm    = float(section[1][50:60])
00289         
00290         kt = int(float(section[2][0 :10]))
00291         if cpNorm:
00292             self.log.debug("nNetworks=%s cpNorm=%s" %(nNetworks,cpNorm))
00293         else:
00294             self.log.debug("nNetworks=%s" %(nNetworks))
00295         
00296         n = 4
00297         self.msg += '      kn,kt            %i          %i\n' %(nNetworks,kt)
00298 
00299         for iNetwork in xrange(nNetworks):
00300             self.log.debug("lines[* %s] = %s" %(n-1,section[n-1]))
00301             nm = int(float(section[n-1][0 :10]))
00302             nn = int(float(section[n-1][10:20]))
00303             netName = section[n-1][70:80]
00304             self.log.debug("kt=%s nm=%s nn=%s netname=%s" %(kt,nm,nn,netName))
00305 
00306             x = zeros([nm,nn])
00307             y = zeros([nm,nn])
00308             z = zeros([nm,nn])
00309             nFullLines = nm/2
00310             nPartialLines = nm%2
00311             nLines = nFullLines+nPartialLines
00312             #print "nFullLines=%s nPartialLines=%s nLines=%s" %(nFullLines,nPartialLines,nLines)
00313             for j in xrange(nn):
00314                 lines = section[n:n+nLines]
00315                 n+=nLines
00316                 #print '\n'.join(lines)
00317                 points = self.splitPoints(lines,nFullLines,nPartialLines)
00318                 
00319                 for i,point in enumerate(points):
00320                     x[i][j] = point[0]
00321                     y[i][j] = point[1]
00322                     z[i][j] = point[2]
00323 
00324             #print "--X--"
00325             #print x
00326             self.addPatch(netName,kt,cpNorm,x,y,z)
00327             n+=1
00328         return True
00329 
00330     def getCircularSection(self,section):
00331         """
00332         $circular sections - nacelle with composite panels
00333         =kn 
00334         2.
00335         =kt
00336         1.
00337         =nopt                                                                 netname
00338         0.                                                                    cowlu
00339         =nm
00340         20.
00341         =xs(1)    ri(1)     xs(2)     ri(2)     xs(*)     ri(*)
00342             2.0000    2.3000    1.5756    2.3000    1.1486    2.3000
00343             0.7460    2.3030    0.4069    2.3286    0.1624    2.3790
00344             0.0214    2.4542   -0.0200    2.5485    0.0388    2.6522
00345             0.2056    2.7554    0.4869    2.8522    0.8883    2.9413
00346             1.4250    3.0178    2.1188    3.0656    2.9586    3.0658
00347             3.8551    3.0175    4.6715    2.9439    5.3492    2.8700
00348             6.0000    2.7842    6.4687    2.7442
00349         =nn
00350         5.
00351         =th(1)    th(2)     th(3)     th(4)     th(5)
00352         -90.      -45.      0.        45.       90.
00353         """
00354         nNetworks = int(float(section[1][0 :10]))
00355         cpNorm = section[1][50:60].strip()
00356         
00357         kt = int(float(section[2][0 :10]))
00358         if cpNorm:
00359             self.log.debug("nNetworks=%s cpNorm=%s" %(nNetworks,cpNorm))
00360         else:
00361             self.log.debug("nNetworks=%s" %(nNetworks))
00362         
00363         n = 3
00364         self.msg += '      kn,kt            %i          %i\n' %(nNetworks,kt)
00365 
00366         for iNetwork in xrange(nNetworks):
00367             self.log.debug("lines[%s] = %s" %(n,section[n]))
00368             nDisplacement = int(float(section[n][0 :10]))  # 0-noDisplacement; 1-Specify
00369             assert nDisplacement in [0,1],section[n]
00370             n+=1
00371 
00372             print "\nsection[n] = ",section[n].strip()
00373             nXR = int(float(section[n][ 0:10]))
00374             assert nXR>0,section[n]
00375             print "nXR = %s" %(nXR)
00376             netName = section[n][70:80]
00377             self.log.debug("kt=%s nXR=%s nDisplacement=%s netname=%s" %(kt,nXR,nDisplacement,netName))
00378 
00379             nFullLines = nXR/3
00380             nPartialLines = int(ceil(nXR%3/3.))
00381             nXR_Lines = nFullLines+nPartialLines
00382             print "X,Rad - nFullLines=%s nPartialLines=%s nLines=%s\n" %(nFullLines,nPartialLines,nXR_Lines)
00383             n+=1
00384 
00385             Xin = []
00386             R = []
00387             lines = section[n:n+nXR_Lines]
00388             n+=nXR_Lines
00389             
00390             for line in lines:
00391                 print line
00392                 try:
00393                     (x1,r1) = float(line[0 :10]),float(line[10:20])
00394                     print "x1=%s r1=%s" %(x1,r1)
00395                     Xin.append(x1); R.append(r1);
00396                 except ValueError:
00397                     pass
00398 
00399                 try:
00400                     (x2,r2) = float(line[20:30]),float(line[30:40])
00401                     print "x2=%s r2=%s" %(x2,r2)
00402                     Xin.append(x2); R.append(r2);
00403                 except ValueError:
00404                     pass
00405 
00406                 try:
00407                     (x3,r3) = float(line[40:50]),float(line[50:60])
00408                     print "x3=%s r3=%s" %(x3,r3)
00409                     Xin.append(x3); R.append(r3);
00410                 except ValueError:
00411                     pass
00412             assert nXR==len(Xin),'nXR=%s Xin=%s' %(nXR,len(Xin))
00413 
00414             #----------------------------------------------------
00415             print "section[n] = ",section[n].strip()
00416             nTheta = int(float(section[n][ 0:10]))
00417             assert nTheta>0,section[n]
00418             print "nTheta = %s" %(nTheta)
00419             nFullLines    = nTheta/6
00420             nPartialLines = int(ceil(nTheta%6/6.))
00421             nTheta_Lines  = nFullLines+nPartialLines
00422             print "Theta - nFullLines=%s nPartialLines=%s nLines=%s" %(nFullLines,nPartialLines,nTheta_Lines)
00423             n+=1
00424             
00425             lines = section[n:n+nTheta_Lines]
00426             theta = []
00427             for line in lines:
00428                 print line
00429                 try:
00430                     (theta1) = float(line[0 :10])
00431                     theta.append(theta1)
00432                 except ValueError:
00433                     pass
00434                 try:
00435                     (theta2) = float(line[10:20])
00436                     theta.append(theta2)
00437                 except ValueError:
00438                     pass
00439                 try:
00440                     (theta3) = float(line[20:30])
00441                     theta.append(theta3)
00442                 except ValueError:
00443                     pass
00444                 try:
00445                     (theta4) = float(line[30:40])
00446                     theta.append(theta4)
00447                 except ValueError:
00448                     pass
00449                 try:
00450                     (theta5) = float(line[40:50])
00451                     theta.append(theta5)
00452                 except ValueError:
00453                     pass
00454                 try:
00455                     (theta6) = float(line[50:60])
00456                     theta.append(theta6)
00457                 except ValueError:
00458                     pass
00459             print "theta = ",theta
00460             n+=nTheta_Lines
00461             
00462             assert nTheta==len(theta)
00463             sinThetaR = [sin(radians(thetai)) for thetai in theta]
00464             cosThetaR = [cos(radians(thetai)) for thetai in theta]
00465             
00466             zi = 0.
00467             X = zeros([nXR,nTheta])
00468             Y = zeros([nXR,nTheta])
00469             Z = zeros([nXR,nTheta])
00470             print("Xin=%s \nR=%s" %(Xin,R))
00471             print("X.shape = ",X.shape)
00472             for (i, x, r) in izip(count(), Xin, R):
00473                 for (j, sinTheta, cosTheta) in izip(count(), sinThetaR, cosThetaR):
00474                     y = r*sinTheta
00475                     z = r*cosTheta+zi
00476                     print "x=%s y=%s z=%s" %(x,y,z)
00477                     X[i][j] = x
00478                     Y[i][j] = y
00479                     Z[i][j] = z
00480             ###
00481             #for i,point in enumerate(points):
00482             #    x[i][j] = point[0]
00483             #    y[i][j] = point[1]
00484             #    z[i][j] = point[2]
00485 
00486             #print "--X--"
00487             #print x
00488             self.addPatch(netName,kt,cpNorm,X,Y,Z)
00489         return True
00490 
00491     def getGrid(self,section):
00492         self.gridSection = '\n'.join(section)+'\n'
00493         return True
00494 
00495     def getXYZ(self,section):
00496         self.xyzSection = '\n'.join(section)+'\n'
00497         return True
00498 
00499     def getStreamlines(self,section):
00500         self.streamlineSection = '\n'.join(section)+'\n'
00501         return True
00502 
00503     def getPrintout(self,section):
00504         """
00505         isings  igeomp  isingp  icontp  ibconp  iedgep
00506         ipraic  nexdgn  ioutpr  ifmcpr  icostp
00507         """
00508         #self.printoutSection = '\n'.join(section)+'\n'
00509 
00510         ########  ROW 1 #######
00511         self.isings = float(section[1][ 0:10])
00512         #self.isings = 5.
00513         #2.0 output wake singularity grid-singularity strength and gradients at 9 pts/panel
00514         #3.0 add table of singularity parameter values
00515         #4.0 add network array of singularity values
00516         #5.0 add singularity grid for all network
00517         
00518         self.igeomp = float(section[1][10:20])
00519         self.igeomp = 1.
00520         # 1.0 outputs panel data - geometry diagnostic data
00521         
00522         self.isingp = float(section[1][20:30])
00523         #self.isignp = 1.  # ???
00524         # 1.0 outputs singularity spline data
00525         
00526         self.icontp = float(section[1][30:40])
00527         self.icontp = 1.
00528         # 1.0 outputs control pt location, upper surface unit normals, control point 
00529         #     diagnositc data, control pt maps and singularity parameter maps
00530         # 2.0 add additional control point map for each network
00531         
00532         self.ibconp = float(section[1][40:50])
00533         #self.ibconp = 0.0
00534         # 1.0 outputs boundary condition coeffs, diagnositc data, 
00535         #     boundary condition maps, control point maps, 
00536         #     and singularity paramter maps
00537 
00538         self.iedgep = float(section[1][50:60])
00539         self.iedgep = .0
00540         # 1.0 outputs edge-matching diagnositic data
00541         #print "igeomp=|%s| isingp=|%s| icontp=|%s| ibconp=|%s| iedgep=|%s|" %(igeomp,isingp,icontp,ibconp,iedgep)
00542         
00543         ########  ROW 2 #######
00544 
00545         self.ipraic = float(section[2][ 0:10])
00546         #self.ipraic = 3.
00547         # xxx inputs control point sequence number for
00548         #     which AIC values are to be pritned (rarely used)
00549 
00550         self.nexdgn = float(section[2][10:20])
00551         self.nexdgn = 0.
00552         # 1.0 outputs edge and extra control point data
00553 
00554         self.ioutpr = float(section[2][20:30])
00555         self.ioutpr = -1.0
00556         # -1.0 omits flow parameter output
00557         #  0.0 outputs 49 flow parameters
00558         #  1.0 outputs 13 flow parameters
00559         
00560         self.ifmcpr = section[2][30:40].strip()
00561         self.ifmcpr = 0.
00562         # 0.0 omits network force and moment output
00563         # 1.0 outputs network forces and moments summary per column, 
00564         #     per network, and accumulation over all previous networks
00565         
00566         self.icostp = section[2][40:50].strip()
00567         self.icostp = 0.
00568         #self.icostp = 1.0
00569         #print "ipraic=|%s| nexdgn=|%s| ioutpr=|%s| ifmcpr=|%s| ifmcpr=|%s|" %(ipraic,nexdgn,ioutpr,ifmcpr,iedgep)
00570         # 1.0 outputs detailed job cost for different segments of the
00571         #     program (rarely used)
00572         
00573 
00574         #$printout options
00575         #=isings   igeomp    isingp    icontp    ibconp    iedgep
00576         #4.        0.        0.        1.        1.        0.
00577         #=ipraic   nexdgn    ioutpr    ifmcpr
00578         #.0        .0        1.        0.                  3.
00579 
00580         return True
00581 
00582     def getTrailingWakes(self, section):
00583         """
00584         $trailing wakes from body
00585         =kn                                               cpnorm
00586         2.
00587         =kt       matcw
00588         18.       1.
00589         =inat     insd      xwake     twake                                   netname
00590         bodyl     3.        100.      .0                                      bodylwk 
00591         bodyu     3.        100.      .0                                      bodyuwk 
00592         """
00593         nNetworks = int(float(section[1][0 :10]))
00594         cpNorm = section[1][50:60].strip()
00595         if cpNorm:
00596             cpNorm = float(cpNorm)
00597         else:
00598             cpNorm = 0
00599         
00600         #print "section[2] = ",section[2]
00601         kt    = int(float(section[2][0 :10]))
00602         
00603         matchw = section[2][10:20].strip()
00604         if matchw:
00605             matchw = float(matchw)
00606         #if cpNorm:
00607             #print "nNetworks=%s cpNorm=%s" %(nNetworks,cpNorm)
00608         #else:
00609             #print "nNetworks=%s" %(nNetworks)
00610         #print ""
00611         #matcw = int(float(section[2][10:20]))
00612         
00613         n = 3
00614         self.msg += '      kn,kt            %i          %i\n' % (nNetworks,kt)
00615         self.log.debug('kt=%s cpNorm=%s matchw=%s' % (kt,cpNorm,matchw))
00616         for iNetwork in xrange(nNetworks):
00617             self.log.debug("lines[* %s] = %s" % (n,section[n]))
00618             
00619             trailedPanel = section[n][ 0:10].strip()
00620             edgeNumber   = int(float(section[n][10:20]))
00621             xWake = float(section[n][20:30]) # x distance
00622             tWake = float(section[n][30:40]) # 0-wake parallel to x axis;  1-wake in direction of compressibility
00623             netName = section[n][70:80].strip()
00624             self.log.debug('trailedPanel=%s edgeNumber=%s xWake=%s tWake=%s netName=%s' %(trailedPanel,edgeNumber,xWake,tWake,netName))
00625             try:
00626                 patch = self.findPatchByName(trailedPanel)
00627             except KeyError:
00628                 self.log.debug('trailedPanel isnt defined...trailedPanel=|%s|' %(trailedPanel))
00629                 raise
00630 
00631             #xPoints = patch.x
00632             #yPoints = patch.y
00633             #print "xPoints = ",xPoints
00634             #print "yPoints = ",yPoints
00635             (p1,x1,y1,z1) = patch.getEdge(edgeNumber)
00636 
00637             nPoints = len(x1)
00638             X = zeros([2, nPoints])
00639             Y = zeros([2, nPoints])
00640             Z = zeros([2, nPoints])
00641             
00642             X[0][:] = x1[0]
00643             Y[0][:] = y1[0]
00644             Z[0][:] = z1[0]
00645 
00646             if tWake==0.:
00647                 X[1][:] = ones([nPoints])*xWake
00648                 Y[1][:] = y1[0]
00649                 Z[1][:] = z1[0]
00650             else:
00651                 #alphaC, betaC
00652                 raise NotImplementedError('tWake isnt supported')
00653             self.log.debug("--X---")
00654             self.log.debug(X)
00655             self.log.debug("--Y---")
00656             self.log.debug(Y)
00657             self.log.debug("--Z---")
00658             self.log.debug(Z)
00659             #nm = int(float(section[n-1][0 :10]))
00660             #nn = int(float(section[n-1][10:20]))
00661             options = [kt, cpNorm, matchw, trailedPanel, edgeNumber, xWake,
00662                        tWake]
00663             patch = self.addWakePatch(netName, options, X, Y, Z)
00664             n+=1
00665         ###
00666         return True
00667 
00668     def getPartialEdgeAbutments(self, section):
00669         self.peaSection = '\n'.join(section)+'\n'
00670         return True
00671 
00672     def writeLiberalizedAbutments(self):
00673         msg = '$eat - liberalized abutments\n'
00674         msg += '%10s'*6 %(self.epsgeo,self.igeoin,self.igeout,self.nwxref,self.triint,self.iabsum) + '\n'
00675         return msg
00676 
00677     def getLiberalizedAbutments(self, section):
00678         self.log.debug("section[1] = %s" % (section[1]))
00679         self.epsgeo = section[1][ 0:10].strip()
00680         if self.epsgeo:
00681             self.epsgeo = float(self.epsgeo)
00682         else:
00683             self.epsgeo = 0.0
00684         # absolute value of tolerance used to establith equivalent network
00685         # edge points; minimum panel diagonal times 0.001 <= espgeo <= minimum
00686         # panel diagonal times 0.03; to not be restricted use negative numbers
00687 
00688         self.igeoin = float(section[1][10:20])
00689         self.igeoin = -1.
00690         # prints network geometry before $EAT
00691         #  0.0 prints geometry
00692         # -1.0 omits printout
00693 
00694         self.igeout = float(section[1][20:30])
00695         self.igeout = 0.
00696         # prints network geometry after $EAT
00697         # 0.0 omits printout
00698         # 1.0 prints geometry
00699 
00700         self.nwxref = float(section[1][30:40])
00701         self.nwxref = 0.
00702         #self.nwxref = 1.0
00703         # prints abutment cross-reference; for each network, all abutments and 
00704         # abutment intersections are described in a format similar to that
00705         # used in the abutment summary and abutment intersection summary output sections
00706         # 0.0 omits printout
00707         # 1.0 prints geometry
00708         
00709         self.triint = float(section[1][40:50])
00710         self.triint = 0.0
00711         # optionally checks for intersection of network edges through other panels
00712         # for final geometry; used only if needed on complex configurations; can
00713         # increase the cost of a computer run by 1 or 2 times that of a datachek (2.) run
00714         # 0.0 omits intersection checking
00715         # 1.0 checks intersection
00716         
00717         self.iabsum = float(section[1][50:60])
00718         self.iabsum = -0.0
00719         #  0.0 abutment summary
00720         #  1.0 plus intersection summary
00721         #  2.0 plus complete list of each network and associated abutments
00722         #  3.0 plus diagnostic data for program developer
00723         # -1.0 no abutment printout
00724         return True
00725 
00726     def getSectionalProperties(self, section):
00727         self.sectionalPropSection = '\n'.join(section)+'\n'
00728         return True
00729 
00730     def getFlowfieldProperties(self, section):
00731         self.flowSection = '\n'.join(section)+'\n'
00732         return True
00733 
00734     #def get(self,section):
00735     #    pass
00736 
00737     #def get(self,section):
00738     #    pass
00739 
00740     #def get(self,section):
00741     #    pass
00742 
00743     def groupSections(self,sections,sectionNames):
00744         #self.Points = []
00745         #self.Streamlines = []
00746         #self.Trailing = []
00747 
00748         #self.Title = None
00749         #self.dataCheck = None
00750         #self.symmetry = None
00751         #self.mach = None
00752         #self.cases = None
00753         #self.alphas = None
00754 
00755         #self.pea = None
00756         #self.eat = None
00757 
00758         #self.printout = None
00759         #self.end = None
00760 
00761         #self.Grid = []
00762         
00763         sectionMap = {
00764             'tit':self.getTitle,
00765             'ref':self.getReferenceQuantities,
00766             'dat':self.getDataCheck,
00767             'sym':self.getSymmetry,
00768             'mac':self.getMach,
00769             'cas':self.getCases,
00770 
00771             'ang':self.getAlphas,
00772             'yaw':self.getBetas,
00773             'pri':self.getPrintout,
00774             'poi':self.getPoints,
00775             'cir':self.getCircularSection,
00776             'tra':self.getTrailingWakes,
00777             'pea':self.getPartialEdgeAbutments,
00778             'eat':self.getLiberalizedAbutments,
00779             'sec':self.getSectionalProperties,
00780             'flo':self.getFlowfieldProperties,
00781             'xyz':self.getXYZ,
00782             'gri':self.getGrid,
00783             'str':self.getStreamlines,
00784             'end':self.getEnd,
00785         }
00786         #validMaps = ['tit','ref','dat','sym','mac','cas','ang','poi','tra','end']
00787         #validMaps += ['xyz','str','flo','sec','pri','pea','eat','gri']
00788         #validMaps = ['yaw','poi','tra']
00789         validMaps = sectionMap.keys()
00790 
00791         for section,sectionName in izip(sections,sectionNames): # 1st line
00792             self.msg += '  $%s\n' %(sectionName)
00793             #print "section = ",len(section)
00794             #self.log.debug("sectionName=%s" %(sectionName))
00795             if sectionName in validMaps:
00796                 self.log.debug("section[0] = %s" %(section[0]))
00797                 functionMap = sectionMap[sectionName]
00798                 ran = functionMap(section)
00799                 assert ran==True,'%s didnt run' %(sectionName)
00800                 #self.log.debug("")
00801             if sectionName=='end':
00802                 break
00803         return sections
00804 
00805     def splitIntoSections(self,lines):
00806         sections = []
00807         sectionNames = []
00808         section = None
00809         sectionName = None
00810         for line in lines:
00811             if '$' in line:
00812                 sections.append(section)
00813                 sectionNames.append(sectionName)
00814                 section = []
00815                 sectionName = line[1:4]
00816                 if sectionName=='end':
00817                     break
00818                 #print "new section...name=%s line - %s" %(sectionName,line)
00819             section.append(line)
00820         ###
00821 
00822         # end section
00823         section.append(line)
00824         sections.append(section)
00825         sectionNames.append(sectionName)
00826         
00827         # get rid of first dummy section
00828         sections = sections[1:]
00829         sectionNames = sectionNames[1:]
00830         
00831         assert len(sections)==len(sectionNames),"%s %s" %(len(sections),len(sectionNames))
00832 
00833         #for section in sections: # 1st line
00834             #print "section = ",len(section)
00835             #print "section[0] = ",section[0]
00836         return (sections,sectionNames)
00837 
00838     def readGrid(self):
00839         infile = open(self.infileName,'r')
00840         self.lines = infile.readlines()
00841         infile.close()
00842         
00843         lines = self.removeComments(self.lines)
00844         (sections,sectionNames) = self.splitIntoSections(lines)
00845         groups = self.groupSections(sections,sectionNames)
00846         self.log.debug("nPatches = %s" %(self.nPatches()))
00847         # split into headings
00848         #for panel in panels:
00849         #    points = readPoints()
00850         #print "self.msg = ",self.msg
00851 
00852     def getPointsElements(self):
00853         points = []
00854         elements = []
00855         pointI=0
00856         #for (name,panel) in sorted(self.panels.iteritems()):
00857         for name,panel in sorted(self.patches.iteritems()):
00858         #if 1:
00859             #panel = self.patches[2]
00860             (pointsI,pointi) = panel.getPoints()
00861             (elementsI) = panel.getElements(pointI)
00862             #print "elementsI = ",elementsI
00863             points += pointsI
00864             elements += elementsI
00865             pointI += pointi
00866             #break
00867             #print "name=%s len(AllElements)=%s len(allPoints)=%s" %(name,len(elements),len(points))
00868         ###
00869         #for point in points:
00870             #print point
00871         return points,elements
00872 
00873 if __name__=='__main__':
00874     infileName  = 'SWB.INP'
00875     outfileName = 'SWB_new.INP'
00876     #infileName = 'ELLIP.INP'
00877     grid = PanairGrid(infileName)
00878     grid.readGrid()
00879     grid.writeGrid(outfileName)
00880     (points,elements) = grid.getPointsElements()
00881     print "\ninfileName=%s" %(infileName)
00882 
 All Classes Namespaces Files Functions Variables