pyNastran  0.5.0
pyNastran BDF Reader/Writer, OP2 Parser, and GUI
toPanair.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 
00028 from pyNastran.converters.panair.panairGridPatch import PanairGridHelper
00029 from pyNastran.converters.cart3d.cart3d_reader import genericCart3DReader
00030 
00031 title = 'simple wing-body with composite panel. (run with a502i)'
00032 alphas = 4.
00033 alphaCompressibility = 4.
00034 
00035 beta = 0.
00036 betaCompressibility = 0.
00037 xySym = True
00038 yzSym = False
00039 mach = 0.6
00040 Sref = 2400.
00041 Bref = 60.
00042 Cref = 40.
00043 Dref = 90.
00044 xref = 46.
00045 yref = 0.
00046 zref = 0.
00047 bcMap = {
00048            1: [1.,None], # kt,cpnorm
00049            #2: [1.,2.], # kt,cpnorm
00050            #3: [1.,2.], # kt,cpnorm
00051         }
00052 
00053 #$title 
00054 #simple wing-body with composite panel. (run with a502i)
00055 #saaris  865-6209  m/s 7c-36 
00056 #$datacheck
00057 # 0.
00058 #$symmetry - xz plane of symmetry
00059 #=misymm   mjsymm
00060 #1.        0.
00061 #$mach number
00062 #=amach
00063 #.6
00064 #$cases - no. of solutions
00065 #=nacase
00066 #1.
00067 #$angles-of-attack
00068 #=alpc
00069 #4.
00070 #=alpha(1) alpha(2)  alpha(3)
00071 #4.        10.       0.
00072 #$printout options
00073 #=isings   igeomp    isingp    icontp    ibconp    iedgep
00074 #4.        0.        0.        1.        1.        0.
00075 #=ipraic   nexdgn    ioutpr    ifmcpr
00076 #.0        .0        1.        0.                  3.
00077 #$references for accumulated forces and moments
00078 #=xref     yref      zref      nref
00079 #46.       0.        0.
00080 #=sref     bref      cref      dref
00081 #2400.     60.       40.       90.
00082 
00083 
00084 def sInt(value):
00085     """
00086     int represented as a short float
00087     """
00088     value = "%f" %(value)
00089     return value.rstrip('0')
00090 
00091 class Cart3dToPanair(PanairGridHelper):
00092     def __init__(self,cart3dGeom,oname,BCMap):
00093         self.printout = ("$printout options\n"
00094                          "=isings   igeomp    isingp    icontp    ibconp    iedgep\n"
00095                          "4.        0.        0.        1.        1.        0.\n"
00096                          "=ipraic   nexdgn    ioutpr    ifmcpr\n"
00097                          ".0        .0        1.        0.                  3.\n")
00098         self.run(cart3dGeom,oname,BCMap)
00099 
00100     def writePoints(self,point1,point2):
00101         point1 = self.fixPoint(point1)
00102         point2 = self.fixPoint(point2)
00103         #print point1
00104         #print point2
00105         out = "%-10s"*6 %(point1[0],point1[1],point1[2],  point2[0],point2[1],point2[2])
00106         return out+'\n'
00107 
00108     def writePoint(self,point1):
00109         point1 = self.fixPoint(point1)
00110         out = "%-10s"*3 %(point1[0],point1[1],point1[2])
00111         return out+'\n'
00112 
00113     def fixPoint(self,pointIn):
00114         pointOut = []
00115         for value in pointIn:
00116             sValue = '%s' %(value)
00117             if len(sValue)>10:
00118                 sValue = sValue[0:9]
00119             pointOut.append(sValue.rstrip('0'))
00120             #print "sValue=%s len=%s" %(sValue,len(sValue))
00121         #print "pointOut = ",pointOut
00122         return pointOut
00123 
00124     def run(self,cart3dGeom,oname,BCMap):
00125             f = open(oname,'wb')
00126             print "oname",oname
00127             self.mach = mach
00128             self.ncases = 1
00129             self.alphaC = alphaCompressibility
00130             self.alphas = [alphas]
00131             
00132             self.betaC = betaCompressibility
00133             self.betas = [beta]
00134             self.xref = xref
00135             self.yref = yref
00136             self.zref = zref
00137             self.sref = Sref
00138             self.bref = Bref
00139             self.cref = Cref
00140             self.dref = Dref
00141             self.isEnd = True
00142             msg = ''
00143             #msg += self.writeTitle()
00144             msg += self.writeMach()
00145             msg += self.writeCases()
00146             msg += self.writeAlphas()
00147             msg += self.writeBetas()
00148             msg += self.writeReferenceQuantities()
00149             msg += self.printout
00150             f.write(msg)
00151 
00152 
00153             cart = genericCart3DReader(cart3dGeom)
00154             (points,elements,regions,loads) = cart.readCart3d(cart3dGeom)
00155 
00156             for pid, point in sorted(points.iteritems()):
00157                 #if pid<85:
00158                 #    print pid,point
00159                 pass
00160             for eid, element in sorted(elements.iteritems()):
00161                 region = regions[eid]
00162                 if region not in BCMap:
00163                     continue
00164                 (kt, cpNorm) = BCMap[region]
00165                 if cpNorm is None:
00166                     cpNorm = ''
00167 
00168                 #print "****"
00169                 #print "element =",element
00170                 #print "region  =",region
00171                 #if eid==2:
00172                 #    print "points = ",points
00173                 n1,n2,n3 = points[element[0]],points[element[1]],points[element[2]]
00174                 #print "n1=%s" %(n1)
00175                 #print "n2=%s" %(n2)
00176                 #print "n3=%s" %(n3)
00177                 #p1 = 
00178                 #sys.exit()
00179                 
00180                 netName = 'e%s' %(eid)
00181                 
00182                 header = '$points - surface panels\n'
00183 
00184                 header += '%-10s%-10s\n'  %('1.', cpNorm) #nNetworks is 1
00185                 header += '%-10s\n' %(sInt(kt))
00186                 header += '%-10s%-10s%50s%-10s\n' %(sInt(2),sInt(2),'',netName)
00187                 pointsOut = self.writePoints(n1,n2)
00188                 pointsOut += self.writePoints(n3,n3)
00189                 f.write(header+pointsOut)
00190                 #break
00191             #print points
00192             #print outfilename
00193             
00194             f.write('$end of panair inputs\n')
00195             #sys.exit()
00196 
00197 
00198 
00199 
00200 
00201 if __name__=='__main__':
00202     cart3dGeom  = os.path.join('models','threePlugs.tri')
00203     #cart3dGeom  = os.path.join('models','spike.a.tri')
00204     outfilename = os.path.join('models','panair.inp')
00205     Cart3dToPanair(cart3dGeom,outfilename,bcMap)
00206     print "done..."
 All Classes Namespaces Files Functions Variables