def convertFromProteusMesh(self, meshin, verbose=0): """ generate a Triangle mesh representation from an proteus mesh. This version will copy over the nodes and elements from the proteus mesh. Deletes the existing Triangle mesh and regenerates. """ #first check that the input mesh has the correct dimensions and #minimal information necessary spaceDim = 2 assert (meshin.nElementBoundaries_element == spaceDim + 1) assert (meshin.nodeArray is not None) assert (meshin.elementNodesArray is not None) #get a clean slate tri0 = triangleWrappers.new() #don't set any markers for now #input array should be nNodes by spacedim nodesIn = meshin.nodeArray[:, :spaceDim] triangleWrappers.setPoints(tri0, nodesIn) #triangle array should be nElements x 3 triAin = meshin.elementNodesArray[:, :spaceDim + 1] triangleWrappers.setTriangles(tri0, triAin) flagsAdd = "r" #use element and node connections flags = flagsAdd + self.baseFlags if flags.find('v') >= 0: self.makeVoronoi = True if verbose > 0: logEvent('readNodeAndEle makeVoronoi= ', self.makeVoronoi, ' flags= ', flags) #end if self.lastFlags = flags #reset data representations if necessary self.resetDefaultTrirep(index=0, verbose=verbose) if self.makeVoronoi: self.resetDefaultVorrep(index=0, verbose=verbose) #end vorrep initialized if self.makeVoronoi: triangleWrappers.applyTriangulate(flags, tri0, self.trirep[0], self.vorrep[0]) #handles no longer contain trivial representations self.trirepDefaultInit[0] = False self.vorrepDefaultInit[0] = False else: triangleWrappers.applyTriangulateNoVoronoi(flags, tri0, self.trirep[0]) #handle no longer contains trivial representations self.trirepDefaultInit[0] = False #end if #clean up explicitly del tri0
def convertFromProteusMesh(self,meshin,verbose=0): """ generate a Triangle mesh representation from an proteus mesh. This version will copy over the nodes and elements from the proteus mesh. Deletes the existing Triangle mesh and regenerates. """ #first check that the input mesh has the correct dimensions and #minimal information necessary spaceDim = 2 assert(meshin.nElementBoundaries_element == spaceDim+1) assert(meshin.nodeArray is not None) assert(meshin.elementNodesArray is not None) #get a clean slate tri0 = triangleWrappers.new() #don't set any markers for now #input array should be nNodes by spacedim nodesIn = meshin.nodeArray[:,:spaceDim] triangleWrappers.setPoints(tri0,nodesIn) #triangle array should be nElements x 3 triAin = meshin.elementNodesArray[:,:spaceDim+1] triangleWrappers.setTriangles(tri0,triAin) flagsAdd = "r" #use element and node connections flags = flagsAdd+self.baseFlags if flags.find('v') >= 0: self.makeVoronoi = True if verbose > 0: logEvent('readNodeAndEle makeVoronoi= ',self.makeVoronoi,' flags= ',flags) #end if self.lastFlags = flags #reset data representations if necessary self.resetDefaultTrirep(index=0,verbose=verbose) if self.makeVoronoi: self.resetDefaultVorrep(index=0,verbose=verbose) #end vorrep initialized if self.makeVoronoi: triangleWrappers.applyTriangulate(flags,tri0,self.trirep[0],self.vorrep[0]) #handles no longer contain trivial representations self.trirepDefaultInit[0] = False self.vorrepDefaultInit[0] = False else: triangleWrappers.applyTriangulateNoVoronoi(flags,tri0,self.trirep[0]) #handle no longer contains trivial representations self.trirepDefaultInit[0] = False #end if #clean up explicitly del tri0
def readFromNodeAndEleFiles(self, filebase, flagsAdd="", verbose=0): """ read triangle representation from filebase.node and filebase.ele files. assumes the nbase data member is set appropriately """ reader = TriangleUtils.TriangleInputFileReader() if verbose > 0: print 'readFromNodeAndEleFiles filebase= ', filebase #end if nodeDataInfo, nodeData = reader.readNodes(filebase, nbase=self.nbase) nodes, nodesA, nodesM = (nodeData['nodes'], nodeData['nodeAttributes'], nodeData['nodeMarkers']) if verbose > 3: print 'Nodes: nodeInfo= ', nodeDataInfo print """Nodes: nodes= \n%s\n nodeAttributes= \n%s\n nodeMarkers= \n%s """ % (nodes, nodesA, nodesM) #end if triDataInfo, triData = reader.readTriangles(filebase, nbase=self.nbase) triangles, trianglesA = triData['triangles'], triData[ 'triangleAttributes'] if verbose > 3: print 'Triangles: triInfo= ', triDataInfo print """Triangles: elems= \n%s\n triAttributes= \n%s """ % (triangles, trianglesA) #end if #now create an initial representation tri0 = triangleWrappers.new() if nodesM == None: triangleWrappers.setPoints(tri0, nodes) else: triangleWrappers.setPointsAndMarkers(tri0, nodes, nodesM) if not nodesA == None: triangleWrappers.setPointAttributes(tri0, nodesA) #end if triangleWrappers.setTriangles(tri0, triangles) if not trianglesA == None: triangleWrappers.setTriangleAttributes(tri0, trianglesA) #run triangulate on it using the base flags and whatever else was #added flags = flagsAdd + self.baseFlags if flags.find('v') >= 0: self.makeVoronoi = True if verbose > 0: print 'readNodeAndEle makeVoronoi= ', self.makeVoronoi, ' flags= ', flags #end if self.lastFlags = flags #reset data representations if necessary self.resetDefaultTrirep(index=0, verbose=verbose) if self.makeVoronoi: self.resetDefaultVorrep(index=0, verbose=verbose) #end vorrep initialized if self.makeVoronoi: triangleWrappers.applyTriangulate(flags, tri0, self.trirep[0], self.vorrep[0]) #handles no longer contain trivial representations self.trirepDefaultInit[0] = False self.vorrepDefaultInit[0] = False else: triangleWrappers.applyTriangulateNoVoronoi(flags, tri0, self.trirep[0]) #handle no longer contains trivial representations self.trirepDefaultInit[0] = False #end if #do I need to clean up explicitly? del tri0
def readFromNodeAndEleFiles(self,filebase,flagsAdd="",verbose=0): """ read triangle representation from filebase.node and filebase.ele files. assumes the nbase data member is set appropriately """ reader = TriangleUtils.TriangleInputFileReader() if verbose > 0: logEvent('readFromNodeAndEleFiles filebase= ',filebase) #end if nodeDataInfo,nodeData = reader.readNodes(filebase,nbase=self.nbase) nodes,nodesA,nodesM = (nodeData['nodes'], nodeData['nodeAttributes'], nodeData['nodeMarkers']) if verbose > 3: logEvent('Nodes: nodeInfo= ',nodeDataInfo) logEvent("""Nodes: nodes= \n%s\n nodeAttributes= \n%s\n nodeMarkers= \n%s """ % (nodes,nodesA,nodesM)) #end if triDataInfo,triData = reader.readTriangles(filebase,nbase=self.nbase) triangles,trianglesA = triData['triangles'],triData['triangleAttributes'] if verbose > 3: logEvent('Triangles: triInfo= ',triDataInfo) logEvent("""Triangles: elems= \n%s\n triAttributes= \n%s """ % (triangles,trianglesA)) #end if #now create an initial representation tri0 = triangleWrappers.new() if nodesM is None: triangleWrappers.setPoints(tri0,nodes) else: triangleWrappers.setPointsAndMarkers(tri0,nodes,nodesM) if nodesA is not None: triangleWrappers.setPointAttributes(tri0,nodesA) #end if triangleWrappers.setTriangles(tri0,triangles) if trianglesA is not None: triangleWrappers.setTriangleAttributes(tri0,trianglesA) #run triangulate on it using the base flags and whatever else was #added flags = flagsAdd+self.baseFlags if flags.find('v') >= 0: self.makeVoronoi = True if verbose > 0: logEvent('readNodeAndEle makeVoronoi= ',self.makeVoronoi,' flags= ',flags) #end if self.lastFlags = flags #reset data representations if necessary self.resetDefaultTrirep(index=0,verbose=verbose) if self.makeVoronoi: self.resetDefaultVorrep(index=0,verbose=verbose) #end vorrep initialized if self.makeVoronoi: triangleWrappers.applyTriangulate(flags,tri0,self.trirep[0],self.vorrep[0]) #handles no longer contain trivial representations self.trirepDefaultInit[0] = False self.vorrepDefaultInit[0] = False else: triangleWrappers.applyTriangulateNoVoronoi(flags,tri0,self.trirep[0]) #handle no longer contains trivial representations self.trirepDefaultInit[0] = False #end if #do I need to clean up explicitly? del tri0