예제 #1
0
 def readFile(self, f):
     '''
     Returns an object of class BarGridKernel loaded from an output file from the software of Patrick Saint-Pierre.
     '''
     bgk = None
     origin = list(map(float, re.findall('-?\d+\.?\d*', f.readline())))
     dimension = len(origin)
     if dimension == 0 :
         raise FileFormatException("Dimensions must be > 0")
     opposite = list(map(float, re.findall('-?\d+\.?\d*', f.readline())))
     intervalNumber = list(map(int, re.findall('[0-9]+', f.readline())))
     if dimension !=len(opposite) or dimension!=len(intervalNumber):
         raise FileFormatException("Dimensions of metadata mismatch")
     pointSize = list(map(int, re.findall('[0-9]+', f.readline())))
     intervalNumber = [e//pointSize[0] for e in intervalNumber]
     # reading columns headers and deducing permutation of variables
     line = f.readline()
     columnNumbertoIgnore = len(re.findall('empty', line))
     permutVector = list(map(int, re.findall('[0-9]+', line)))
     permutation = np.zeros(dimension * dimension,int).reshape(dimension,dimension)
     for i in range(dimension):
         permutation[i][permutVector[i]-1]=1
     # Ok, creating the container object
     bgk = BarGridKernel(origin, opposite, intervalNumber,permutation)
     # ignoring lines until 'Initxx'
     stop=False
     while not stop:
         line = f.readline()
         if 'Initxx' in line:
             stop = True
     # reading bars
     stop = False
     while not stop:
         # using a while loop, because the for loop seems buggy with django InMemoryUploadedFile reading
         line = f.readline()
         if not line:
             stop = True
         else:
             coords = list(map(int, re.findall('[0-9]+', line)))
             coords = [e // pointSize[0] for e in coords]
             bgk.addBar(coords[columnNumbertoIgnore:-2], coords[-2], coords[-1])
             # TODO what is done with modelMetadata and nbDim
     return bgk
예제 #2
0
 def readFile(self, f):
     '''
     Returns an object of class BarGridKernel loaded from an output file from the software of Patrick Saint-Pierre.
     '''
     bgk = None
     origin = list(map(float, re.findall('-?\d+\.?\d*', f.readline())))
     dimension = len(origin)
     if dimension == 0 :
         raise FileFormatException("Dimensions must be > 0")
     opposite = list(map(float, re.findall('-?\d+\.?\d*', f.readline())))
     intervalNumber = list(map(int, re.findall('[0-9]+', f.readline())))
     if dimension !=len(opposite) or dimension!=len(intervalNumber):
         raise FileFormatException("Dimensions of metadata mismatch")
     pointSize = list(map(int, re.findall('[0-9]+', f.readline())))
     intervalNumber = [e//pointSize[0] for e in intervalNumber]
     # reading columns headers and deducing permutation of variables
     line = f.readline()
     columnNumbertoIgnore = len(re.findall('empty', line))
     permutVector = list(map(int, re.findall('[0-9]+', line)))
     permutation = np.zeros(dimension * dimension,int).reshape(dimension,dimension)
     for i in range(dimension):
         permutation[i][permutVector[i]-1]=1
     # Ok, creating the container object
     bgk = BarGridKernel(origin, opposite, intervalNumber,permutation)
     # ignoring lines until 'Initxx'
     stop=False
     while not stop:
         line = f.readline()
         if 'Initxx' in line:
             stop = True
     # reading bars
     stop = False
     while not stop:
         # using a while loop, because the for loop seems buggy with django InMemoryUploadedFile reading
         line = f.readline()
         if not line:
             stop = True
         else:
             coords = list(map(int, re.findall('[0-9]+', line)))
             coords = [e // pointSize[0] for e in coords]
             bgk.addBar(coords[columnNumbertoIgnore:-2], coords[-2], coords[-1])
             # TODO what is done with modelMetadata and nbDim
     return bgk
예제 #3
0
    def toBarGridKernel(self, newOriginCoords, newOppositeCoords, intervalNumberperaxis):
        '''
        Convert to a BarGridKernel with another underlying grid, with a given number of intervals per axis.
        If no origin or opposite is given, it will be deduced from the lower or upper cell.
        Returns an instance of BarGridKernel.
        '''
        minBoundsCoordinates = self.getMinBoundsCoordinates()
        intervalsSizes = (np.array([max([c[i+1] for c in self.cells]) for i in minBoundsCoordinates], float)-np.array([min([c[i] for c in self.cells]) for i in minBoundsCoordinates], float))/(np.array(intervalNumberperaxis)+np.array([1]*len(intervalNumberperaxis)))
        if not newOriginCoords:
            newOriginCoords = np.array([min([c[i] for c in self.cells]) for i in minBoundsCoordinates], float) + intervalsSizes / 2
        else:
            newOriginCoords = np.array(newOriginCoords, float)
        if not newOppositeCoords:
            newOppositeCoords = np.array([max([c[i+1] for c in self.cells]) for i in minBoundsCoordinates], float) - intervalsSizes / 2
        else:
            newOppositeCoords = np.array(newOppositeCoords, float)
#        newIntervalNumberperaxis = (newOppositeCoords - newOriginCoords) / intervalsSizes
        bgk = BarGridKernel(newOriginCoords, newOppositeCoords, intervalNumberperaxis)
#        print list(newOppositeCoords)
#        print list(intervalsSizes)

        for cell in self.cells:
            cell_start = [cell[i] for i in minBoundsCoordinates]
            cell_end = [cell[i+1] for i in minBoundsCoordinates]
            start_int = np.floor(np.array(intervalNumberperaxis) * (np.array(cell_start, float) + intervalsSizes / 2 - newOriginCoords)/(newOppositeCoords - newOriginCoords))
            start_int = np.array([max(start_int[i],0) for i in range(len(start_int))],int)

            end_int = np.ceil(np.array(intervalNumberperaxis) * (np.array(cell_end, float) - intervalsSizes / 2 - newOriginCoords)/(newOppositeCoords - newOriginCoords))
            end_int = np.array([min(end_int[i],intervalNumberperaxis[i]) for i in range(len(end_int))],int)
            # now adding all the points on the grid of the BGK between start and end of the Kd cell
            next_point = list(start_int[:-1])
            bgk.addBar(next_point, start_int[-1], end_int[-1])
            while any(next_point!=end_int[:-1]):
                for i,coord in reversed(list(enumerate(next_point))):
                    if next_point[i] < end_int[i]:
                        next_point[i] += 1
                        break
                    else:
                        next_point[i] = start_int[i]
                bgk.addBar(next_point, start_int[-1], end_int[-1])
        return bgk
예제 #4
0
    def toBarGridKernel(self, newOriginCoords, newOppositeCoords, intervalNumberperaxis):
        '''
        Convert to a BarGridKernel with another underlying grid, with a given number of intervals per axis.
        If no origin or opposite is given, it will be deduced from the lower or upper cell.
        Returns an instance of BarGridKernel.
        '''
        minBoundsCoordinates = self.getMinBoundsCoordinates()
        intervalsSizes = (np.array([max([c[i+1] for c in self.cells]) for i in minBoundsCoordinates], float)-np.array([min([c[i] for c in self.cells]) for i in minBoundsCoordinates], float))/(np.array(intervalNumberperaxis)+np.array([1]*len(intervalNumberperaxis)))
        if not newOriginCoords:
            newOriginCoords = np.array([min([c[i] for c in self.cells]) for i in minBoundsCoordinates], float) + intervalsSizes / 2
        else:
            newOriginCoords = np.array(newOriginCoords, float)
        if not newOppositeCoords:
            newOppositeCoords = np.array([max([c[i+1] for c in self.cells]) for i in minBoundsCoordinates], float) - intervalsSizes / 2
        else:
            newOppositeCoords = np.array(newOppositeCoords, float)
#        newIntervalNumberperaxis = (newOppositeCoords - newOriginCoords) / intervalsSizes
        bgk = BarGridKernel(newOriginCoords, newOppositeCoords, intervalNumberperaxis)
#        print list(newOppositeCoords)
#        print list(intervalsSizes)

        for cell in self.cells:
            cell_start = [cell[i] for i in minBoundsCoordinates]
            cell_end = [cell[i+1] for i in minBoundsCoordinates]
            start_int = np.floor(np.array(intervalNumberperaxis) * (np.array(cell_start, float) + intervalsSizes / 2 - newOriginCoords)/(newOppositeCoords - newOriginCoords))
            start_int = np.array([max(start_int[i],0) for i in range(len(start_int))],int)

            end_int = np.ceil(np.array(intervalNumberperaxis) * (np.array(cell_end, float) - intervalsSizes / 2 - newOriginCoords)/(newOppositeCoords - newOriginCoords))
            end_int = np.array([min(end_int[i],intervalNumberperaxis[i]) for i in range(len(end_int))],int)
            # now adding all the points on the grid of the BGK between start and end of the Kd cell
            next_point = list(start_int[:-1])
            bgk.addBar(next_point, start_int[-1], end_int[-1])
            while any(next_point!=end_int[:-1]):
                for i,coord in reversed(list(enumerate(next_point))):
                    if next_point[i] < end_int[i]:
                        next_point[i] += 1
                        break
                    else:
                        next_point[i] = start_int[i]
                bgk.addBar(next_point, start_int[-1], end_int[-1])
        return bgk
예제 #5
0
 def readFile(self, f):
     metadata={}
     bgk = None
     f.readline()
     nbDim = re.match('\s*([0-9]*)\s.*',f.readline()).group(1)
     metadata[METADATA.dynamicsdescription] = f.readline()
     metadata[METADATA.stateconstraintdescription] = f.readline()
     metadata[METADATA.targetdescription] = f.readline()
     for i in range(4): f.readline()
     dimensionsSteps = list(map(int, re.findall('[0-9]+', f.readline())))
     for i in range(2): f.readline()
     origin = list(map(int, re.findall('[0-9]+', f.readline())))
     maxPoint = list(map(int, re.findall('[0-9]+', f.readline())))
     for i in range(5): f.readline()
     # ND Why? Why not opposite = maxPoint
     opposite = origin
     bgk = BarGridKernel(origin, opposite, dimensionsSteps, metadata=metadata)
     # reading until some lines with 'Initxx'
     stop=False
     initxx=False
     # ND Why restrict min/max point to integer position
     bgk.kernelMinPoint = [e//1 for e in origin]
     bgk.kernelMaxPoint = [e//1 for e in maxPoint]
     while not stop:
         line = f.readline()
         if 'Initxx' in line:
             initxx = True
         elif initxx and 'Initxx' not in line:
             stop = True
     # reading bars
     for line in f:
         coords = list(map(int, re.findall('[0-9]+', line)))
         # ND Why convert point to integer position
         coords = [e//1 for e in coords]
         bgk.addBar(coords[2:-2], coords[-2], coords[-1])
         # TODO what is done with modelMetadata and nbDim
     return bgk