示例#1
0
    def contactsBetweenBlocks(self, blocks1, blocks2):
        time = min(self.blockData.keys())
        contacts1 = self.contactsOnBlocks(blocks1)
        contacts2 = self.contactsOnBlocks(blocks2)

        contacts = Common.listIntersection(contacts1, contacts2)
        return contacts
示例#2
0
 def orderBlocks(self, blocks, relaventContacts):
     blocks = copy.deepcopy(blocks)
     time = min(self.contactData.keys())
     blockContacts = [self.contactsOnBlocks([block]) for block in blocks]
     newBlocks = [blocks[0]]
     newBlockContacts = [blockContacts[0]]
     blocks.pop(0)
     blockContacts.pop(0)
     tempBlockContacts= []
     i = 0
     numBlocks = len(blocks)
     noSuccess = 0
     while i < numBlocks: 
         j = 0
         success = 0
         while j < len(blockContacts):
             relaventBlockContacts = Common.listIntersection(blockContacts[j], relaventContacts)
             if i+1 > len(newBlockContacts):
                 i += -1
                 noSuccess += 1
             elif Common.listIntersection(newBlockContacts[i], relaventBlockContacts):
                 success += 1
                 if success > noSuccess:
                     newBlockContacts.append(blockContacts[j])
                     newBlocks.append(blocks[j])
                     blockContacts.pop(j)
                     blocks.pop(j)
                     noSuccess = 0
                     break
             elif noSuccess > len(blockContacts):
                 xDistance = [self.blockData[time][newBlocks[i]]['x'] - self.blockData[time][b]['x'] for b in blocks] 
                 yDistance = [self.blockData[time][newBlocks[i]]['y'] - self.blockData[time][b]['y'] for b in blocks] 
                 distance = [math.hypot(xDistance[z], yDistance[z]) for z in range(len(blocks))]
                 nextBlockIndex = distance.index(min(distance))
                 newBlockContacts.append(blockContacts[nextBlockIndex])
                 newBlocks.append(blocks[nextBlockIndex])
                 blockContacts.pop(nextBlockIndex)
                 blocks.pop(nextBlockIndex)
                 noSuccess = 0
                 break
             j += 1
         i += 1
     return newBlocks
示例#3
0
 def calculateHomogenizationParameters(self):
     print('-'*70)
     print('Calculating Homogenization Parameters')
     print('-'*70)
     print('Processing Homogenization Data:')
     print('\tCalculating boundary blocks')
     self.boundaryBlocks = self.blocksOnBoundary()
     print('\tCalculating inside blocks')
     self.insideBlocks = self.blocksInsideBoundary()
     print('\tCalculating outside blocks')
     self.outsideBlocks = self.blocksOutsideBoundary()
     if not self.singleBlock:
         print('\tCalculating inside boundary blocks')
         self.insideBoundaryBlocks = self.boundaryBlocks + self.insideBlocks
         print('\tCalculating boundary contacts')
         self.boundaryContacts = self.contactsBetweenBlocks(self.outsideBlocks, self.boundaryBlocks)
         print('\tCalculating boundary contact corners')
         self.boundaryContactCorners = self.cornersOnContacts(self.boundaryContacts)
         print('\tCalculating boundary contact blocks')
         self.boundaryContactBlocks = self.blocksWithContacts(self.boundaryBlocks, self.boundaryContacts)
         print('\tCalculating outside corners')
         self.outsideCorners = self.cornersOutsideBoundary()
         print('\tCalculating outside contacts')
         self.outsideContacts = self.contactsOutsideBoundary()
         print('\tCalculating boundary block corners')
         self.boundaryBlockCorners = self.cornersOnBlocks(self.boundaryContactBlocks)
         print('\tCalculating boundary corners')
         self.boundaryCorners = Common.listIntersection(self.boundaryContactCorners, self.boundaryBlockCorners)
         print('\tCalculating missing boundary corners')
         self.allBoundaryCorners = self.duplicateCorners(self.boundaryCorners, self.boundaryContactBlocks)
         print('\tCalculating boundary block order')
         self.boundaryBlocksOrdered = self.orderBlocks(self.boundaryContactBlocks, self.outsideContacts)
         print('\tCalculating boundary corner order')
         self.boundaryCornersOrdered = self.orderCorners(self.boundaryBlocksOrdered, self.allBoundaryCorners)
     else:
         print('\tCalculating boundary block order')
         self.boundaryBlocksOrdered = self.outsideBlocks
         print('\tCalculating boundary corner order')
         self.boundaryCornersOrdered = self.singleElementCorners()
         print('\tCalculating inside boundary blocks')
         self.insideBoundaryBlocks = self.outsideBlocks
示例#4
0
 def orderCorners(self, orderedBlocks, corners):
     time = min(self.contactData.keys())
     
     directionSign = 0
     for i in range(len(orderedBlocks)):
         x1 = self.blockData[time][orderedBlocks[i-2]]['x']
         y1 = self.blockData[time][orderedBlocks[i-2]]['y']
         x2 = self.blockData[time][orderedBlocks[i-1]]['x']
         y2 = self.blockData[time][orderedBlocks[i-1]]['y']
         x3 = self.blockData[time][orderedBlocks[i]]['x']
         y3 = self.blockData[time][orderedBlocks[i]]['y']
         xVec1 = x1-x2
         yVec1 = y1-y2
         xVec2 = x3-x2
         yVec2 = y3-y2
         vecAngle = Common.angle(xVec1, yVec1, xVec2, yVec2)
         vecSign = xVec1*yVec2-xVec2*yVec1
         directionSign += vecSign
     if directionSign > 0:
         directionSign = -directionSign
         orderedBlocks = orderedBlocks[::-1]
     corners = copy.deepcopy(corners)
     orderedBlocks = copy.deepcopy(orderedBlocks)
     newCorners = []
     
     for i in range(len(orderedBlocks)):
         allBlockCorners = self.blockData[time][orderedBlocks[i]]['corners']
         blockCorners = Common.listIntersection(corners, allBlockCorners)           
         orderedBlockCorners = []
         for corner in allBlockCorners:
             if corner in blockCorners:
                 orderedBlockCorners.append(corner)
         blockCorners = orderedBlockCorners
         
         blockDirection = 0
      
         for j in range(len(allBlockCorners)):
             x1 = self.gridPointData[time][self.cornerData[time][allBlockCorners[j-2]]['gridPoint']]['x']
             y1 = self.gridPointData[time][self.cornerData[time][allBlockCorners[j-2]]['gridPoint']]['y']
             x2 = self.gridPointData[time][self.cornerData[time][allBlockCorners[j-1]]['gridPoint']]['x']
             y2 = self.gridPointData[time][self.cornerData[time][allBlockCorners[j-1]]['gridPoint']]['y']
             x3 = self.gridPointData[time][self.cornerData[time][allBlockCorners[j]]['gridPoint']]['x']
             y3 = self.gridPointData[time][self.cornerData[time][allBlockCorners[j]]['gridPoint']]['y']
             xVec1 = x1-x2
             yVec1 = y1-y2
             xVec2 = x3-x2
             yVec2 = y3-y2
             vecAngle = Common.angle(xVec1, yVec1, xVec2, yVec2)
             vecSign = xVec1*yVec2-xVec2*yVec1
             blockDirection += vecSign
         if math.copysign(1, blockDirection) != math.copysign(1, directionSign):
             blockCorners = blockCorners[::-1]
             
         previousBlockCorners = self.blockData[time][orderedBlocks[i-1]]['corners']
         startingCornerDistance = -1
         for corner in blockCorners:
             gridPoint = self.cornerData[time][corner]['gridPoint']
             for previousCorner in previousBlockCorners:
                 previousGridPoint = self.cornerData[time][previousCorner]['gridPoint']
                 xDistance = self.gridPointData[time][previousGridPoint]['x'] - self.gridPointData[time][gridPoint]['x']
                 yDistance = self.gridPointData[time][previousGridPoint]['y'] - self.gridPointData[time][gridPoint]['y']
                 distance = math.hypot(xDistance, yDistance)
                 if startingCornerDistance < 0 or distance < startingCornerDistance:
                     startingCornerDistance = distance
                     startingCorner = corner
                 
                 
         index = blockCorners.index(startingCorner)
         blockCorners = blockCorners[index:] + blockCorners[:index]
         newCorners += blockCorners
     return newCorners