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 import vtk 00026 from vtk import vtkQuad 00027 from wgsReader import LaWGS 00028 00029 class LaWGS_IO(object): 00030 def __init__(self): 00031 pass 00032 #if __name__=='__main__': 00033 # lawgs = LaWGS('tmx1242.wgs') 00034 # lawgs.run() 00035 00036 def loadLaWGSGeometry(self,lawgsFileName,dirname,isNodal,isCentroidal): 00037 self.isNodal = isNodal 00038 self.isCentroidal = isCentroidal 00039 #key = self.caseKeys[self.iCase] 00040 #case = self.resultCases[key] 00041 00042 skipReading = self.removeOldGeometry(lawgsFileName) 00043 if skipReading: 00044 return 00045 00046 model = LaWGS(lawgsFileName) 00047 self.modelType = model.modelType 00048 model.readLaWGS() 00049 00050 nodes,elements = model.getPointsElements() 00051 self.nNodes = len(nodes) 00052 self.nElements = len(elements) 00053 00054 #print "nNodes = ",self.nNodes 00055 print "nElements = ",self.nElements 00056 00057 self.grid.Allocate(self.nElements, 1000) 00058 self.gridResult.SetNumberOfComponents(self.nElements) 00059 self.grid2.Allocate(1, 1000) 00060 00061 points = vtk.vtkPoints() 00062 points.SetNumberOfPoints(self.nNodes) 00063 self.gridResult.Allocate(self.nNodes,1000) 00064 #vectorReselt.SetNumberOfComponents(3) 00065 self.nidMap = {} 00066 #elem.SetNumberOfPoints(nNodes) 00067 if 0: 00068 fraction = 1./self.nNodes # so you can color the nodes by ID 00069 for nid,node in sorted(nodes.iteritems()): 00070 points.InsertPoint(nid-1, *node) 00071 self.gridResult.InsertNextValue(nid*fraction) 00072 #print str(element) 00073 00074 #elem = vtk.vtkVertex() 00075 #elem.GetPointIds().SetId(0, i) 00076 #self.aQuadGrid.InsertNextCell(elem.GetCellType(), elem.GetPointIds()) 00077 #vectorResult.InsertTuple3(0, 0.0, 0.0, 1.0) 00078 00079 for nid,node in enumerate(nodes): 00080 points.InsertPoint(nid, *node) 00081 print "nid = ",nid 00082 00083 for eid,element in enumerate(elements): 00084 (p1,p2,p3,p4) = element 00085 #print "element = ",element 00086 elem = vtkQuad() 00087 elem.GetPointIds().SetId(0, p1) 00088 elem.GetPointIds().SetId(1, p2) 00089 elem.GetPointIds().SetId(2, p3) 00090 elem.GetPointIds().SetId(3, p4) 00091 self.grid.InsertNextCell(elem.GetCellType(), elem.GetPointIds()) 00092 ### 00093 print "eid = ",eid 00094 self.grid.SetPoints(points) 00095 #self.grid2.SetPoints(points2) 00096 #self.grid.GetPointData().SetScalars(self.gridResult) 00097 #print dir(self.grid) #.SetNumberOfComponents(0) 00098 #self.grid.GetCellData().SetNumberOfTuples(1); 00099 #self.grid.GetCellData().SetScalars(self.gridResult) 00100 self.grid.Modified() 00101 self.grid2.Modified() 00102 self.grid.Update() 00103 self.grid2.Update() 00104 print "updated grid" 00105 00106 return 00107 00108 # loadCart3dResults - regions/loads 00109 self.TurnTextOn() 00110 self.scalarBar.VisibilityOn() 00111 self.scalarBar.Modified() 00112 00113 self.iSubcaseNameMap = {1:['Cart3d','']} 00114 cases = {} 00115 ID = 1 00116 00117 #print "nElements = ",nElements 00118 cases = self.fillCart3dCase(cases,ID,regions,loads) 00119 00120 self.resultCases = cases 00121 self.caseKeys = sorted(cases.keys()) 00122 #print "caseKeys = ",self.caseKeys 00123 #print "type(caseKeys) = ",type(self.caseKeys) 00124 self.iCase = -1 00125 self.nCases = len(self.resultCases)-1 # number of keys in dictionary 00126 self.cycleResults() # start at nCase=0 00127 00128 if __name__=='__main__': 00129 print '' 00130 def removeOldGeometry(self): 00131 pass 00132 test = LaWGS_IO() 00133 test.removeOldGeometry = removeOldGeometry 00134 00135 test.loadLaWGSGeometry('tmx1242.wgs','',True,True)