pyNastran
0.5.0
pyNastran BDF Reader/Writer, OP2 Parser, and GUI
|
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 # pylint: disable=E1101,C0103 00026 00027 from __future__ import division, print_function 00028 import sys 00029 #import copy 00030 00031 from pyNastran.bdf.cards.nodes import SPOINT 00032 00033 class GetMethods(object): 00034 def __init__(self): 00035 pass 00036 00037 #-------------------- 00038 # NODE CARDS 00039 00040 def nNodes(self): 00041 return len(self.nodes) 00042 00043 def nodeIDs(self): 00044 return self.nodes.keys() 00045 00046 def getNodes(self): 00047 nodes = [] 00048 for (nid, node) in sorted(self.nodes.iteritems()): 00049 nodes.append(node) 00050 return nodes 00051 00052 def getNodeIDsWithElement(self, eid): 00053 return self.getNodeIDsWithElements([eid]) 00054 00055 def getNodeIDsWithElements(self, eids): 00056 nids2 = set([]) 00057 for eid in eids: 00058 element = self.Element(eid) 00059 self.log.debug("element.pid = %s" % (element.pid)) 00060 nids = set(element.nids) 00061 nids2 = nids2.union(nids) 00062 ### 00063 return nids2 00064 00065 def Node(self, nid, allowEmptyNodes=False): 00066 if nid == 0 and allowEmptyNodes: 00067 return None 00068 elif nid in self.nodes: 00069 return self.nodes[nid] 00070 elif self.spoints and nid in self.spoints.spoints: 00071 return SPOINT(nid) 00072 else: 00073 raise RuntimeError('nid=%s is not a GRID or SPOINT' % (nid)) 00074 ### 00075 00076 def Nodes(self, nids, allowEmptyNodes=False): 00077 """ 00078 Returns a series of node objects given a list of node IDs 00079 """ 00080 #print "nids",nids 00081 nodes = [] 00082 for nid in nids: 00083 nodes.append(self.Node(nid,allowEmptyNodes)) 00084 return nodes 00085 00086 #-------------------- 00087 # ELEMENT CARDS 00088 00089 def nElements(self): 00090 return len(self.elements) 00091 00092 def elementIDs(self): 00093 return self.elements.keys() 00094 00095 def getElementIDsWithPID(self, pid): 00096 return self.getElementIDsWithPIDs([pid]) 00097 00098 def getElementIDsWithPIDs(self, pids): 00099 eids = self.elementIDs() 00100 eids2 = [] 00101 #print "eids = ",eids 00102 for eid in eids: 00103 element = self.Element(eid) 00104 if element.Pid() in pids: 00105 eids2.append(eid) 00106 ### 00107 ### 00108 return (eids2) 00109 00110 def getNodeIDToElementIDsMap(self): 00111 """ 00112 Returns a dictionary that maps a node ID to a list of elemnents 00113 @todo 00114 support 0d or 1d elements 00115 @todo 00116 support elements with missing nodes (e.g. CQUAD8 with missing nodes) 00117 """ 00118 nidToElementsMap = {} 00119 for nid in self.nodes: # initalize the mapper 00120 nidToElementsMap[nid] = [] 00121 00122 if self.spoints: # SPOINTs 00123 for nid in sorted(self.spoints.spoints): # SPOINTs 00124 nidToElementsMap[nid] = [] 00125 ### 00126 ### 00127 for (eid, element) in self.elements.iteritems(): # load the mapper 00128 try: 00129 # not supported for 0-D and 1-D elements 00130 nids = element.nodeIDs() 00131 for nid in nids: # (e.g. CQUAD8 with missing node) 00132 nidToElementsMap[nid].append(eid) 00133 except: 00134 pass 00135 ### 00136 ### 00137 return nidToElementsMap 00138 00139 def getPropertyIDToElementIDsMap(self): 00140 """ 00141 Returns a dictionary that maps a property ID to a list of elemnents 00142 """ 00143 pidToEidsMap = {} 00144 pids = self.propertyIDs() 00145 for pid in pids: 00146 pidToEidsMap[pid] = [] 00147 00148 for eid in self.elementIDs(): 00149 element = self.Element(eid) 00150 #print dir(element) 00151 if hasattr(element,'pid'): 00152 pid = element.Pid() 00153 if pid==0: # CONM2 00154 continue 00155 pidToEidsMap[pid].append(eid) 00156 ### 00157 ### 00158 return (pidToEidsMap) 00159 00160 def getMaterialIDToPropertyIDsMap(self): 00161 """ 00162 Returns a dictionary that maps a material ID to a list of properties 00163 @note 00164 all properties require an mid to be counted (except for PCOMP, 00165 which has multiple mids) 00166 """ 00167 midToPidsMap = {} 00168 for mid in self.materialIDs(): 00169 midToPidsMap[mid] = [] 00170 00171 for pid in self.propertyIDs(): 00172 prop = self.Property(pid) 00173 if prop.type == 'PCOMP': 00174 mids = prop.Mids() 00175 00176 for mid in mids: 00177 if pid not in midToPidsMap[mid]: 00178 midToPidsMap[mid].append(pid) 00179 else: # PCOMP 00180 if hasattr(prop,'mid') and prop.Mid() in mids: 00181 if pid not in midToPidsMap[mid]: 00182 midToPidsMap[mid].append(pid) 00183 ### 00184 ### 00185 ### 00186 return (midToPidsMap) 00187 00188 def Element(self, eid): 00189 return self.elements[eid] 00190 00191 def Elements(self, eids): 00192 elements = [] 00193 for eid in eids: 00194 elements.append(self.elements[eid]) 00195 return elements 00196 00197 def RigidElement(self, eid): 00198 return self.rigidElements[eid] 00199 00200 #-------------------- 00201 # PROPERTY CARDS 00202 00203 def propertyIDs(self): 00204 return self.properties.keys() 00205 00206 def Property(self, pid): 00207 try: 00208 return self.properties[pid] 00209 except KeyError: 00210 raise KeyError('pid=%s not found. Allowed Pids=%s' 00211 % (pid,self.propertyIDs())) 00212 ### 00213 00214 def Properties(self, pids): 00215 properties = [] 00216 #print "pids = ",pids 00217 for pid in pids: 00218 properties.append(self.properties[pid]) 00219 return properties 00220 00221 def Phbdy(self, pid): 00222 return self.phbdys[pid] 00223 00224 #-------------------- 00225 # MATERIAL CARDS 00226 00227 def structuralMaterialIDs(self): 00228 return self.materials.keys() 00229 00230 def materialIDs(self): 00231 return self.materials.keys()+self.thermalMaterials.keys() 00232 00233 def thermalMaterialIDs(self): 00234 return self.thermalMaterials.keys() 00235 00236 def Material(self, mid): 00237 if mid in self.materials: 00238 return self.materials[mid] 00239 elif mid in self.thermalMaterials: 00240 return self.thermalMaterials[mid] 00241 else: 00242 raise KeyError('Invalid Material ID: mid=%s' %(mid)) 00243 00244 def StructuralMaterial(self, mid): 00245 return self.materials[mid] 00246 00247 def ThermalMaterial(self, mid): 00248 return self.thermalMaterials[mid] 00249 00250 def Materials(self, mids): 00251 materials = [] 00252 for mid in mids: 00253 materials.append(self.Material(mid)) 00254 return materials 00255 00256 #-------------------- 00257 # LOADS 00258 00259 def Load(self, sid): 00260 #print 'sid=%s self.loads=%s' %(sid,(self.loads.keys())) 00261 assert isinstance(sid, int), 'sid=%s is not an integer\n' %(sid) 00262 if sid in self.loads: 00263 load = self.loads[sid] 00264 else: 00265 raise KeyError('cannot find LoadID=|%s|.' %(sid)) 00266 return load 00267 00268 def Grav(self, sid): 00269 raise DeprecationWarning('use Load(sid) instead of Grav(sid)') 00270 return self.Load(sid) 00271 00272 #-------------------- 00273 # SPCs 00274 00275 def SPC(self, conid): 00276 #print 'conid=%s self.spcs=%s' %(conid,(self.spcs.keys())) 00277 assert isinstance(conid, int), 'conid=%s is not an integer\n' % (conid) 00278 if conid in self.spcs: 00279 constraint = self.spcs[conid] 00280 else: 00281 raise KeyError('cannot find ConstraintID=|%s|.' % (conid)) 00282 return constraint 00283 00284 #-------------------- 00285 # COORDINATES CARDS 00286 def Coord(self, cid): 00287 return self.coords[cid] 00288 00289 #-------------------- 00290 # AERO CARDS 00291 00292 def nCAeros(self): 00293 return len(self.caeros) 00294 00295 def Aero(self, acsid): 00296 return self.aero[acsid] 00297 00298 def Aeros(self, acsid): 00299 return self.aeros[acsid] 00300 00301 def Spline(self, eid): 00302 return self.splines[eid] 00303 00304 def CAero(self, eid): 00305 return self.caeros[eid] 00306 00307 def PAero(self, pid): 00308 return self.paeros[pid] 00309 00310 def Gust(self, sid): 00311 return self.gusts[sid] 00312 00313 #-------------------- 00314 # AERO CONTROL SURFACE CARDS 00315 def AEStat(self, aid): 00316 return self.aestats[aid] 00317 00318 def AELink(self, linkID): 00319 return self.aelinks[linkID] 00320 00321 def AEParam(self, aid): 00322 return self.aeparams[aid] 00323 00324 #-------------------- 00325 # FLUTTER CARDS 00326 00327 def Flfact(self, sid): 00328 return self.flfacts[sid] 00329 00330 def Flutter(self, fid): 00331 return self.flutters[fid] 00332 00333 #-------------------- 00334 # OPTIMIZATION CARDS 00335 00336 def DConstr(self, oid): 00337 return self.dconstrs[oid] 00338 00339 def Desvar(self, oid): 00340 return self.desvars[oid] 00341 00342 def DDVal(self, oid): 00343 return self.ddvals[oid] 00344 00345 #-------------------- 00346 # SET CARDS 00347 00348 def Set(self, sid): 00349 return self.sets[sid] 00350 00351 def SetSuper(self, seid): 00352 return self.setsSuper[seid] 00353 00354 #-------------------- 00355 # METHOD CARDS 00356 def Method(self, sid): 00357 return self.methods[sid] 00358 00359 def CMethod(self, sid): 00360 return self.cMethods[sid] 00361 00362 #-------------------- 00363 # TABLE CARDS 00364 def Table(self, tid): 00365 return self.tables[tid] 00366 00367 def RandomTable(self, tid): 00368 return self.randomTables[tid] 00369 00370 #-------------------- 00371 # NONLINEAR CARDS 00372 00373 def NLParm(self, nid): 00374 return self.nlparms[nid] 00375 00376 #-------------------- 00377 # MATRIX ENTRY CARDS 00378 def DMIG(self, dname): 00379 return self.dmig[dname] 00380 #-------------------- 00381