Ejemplo n.º 1
0
    def big2littlePTS(self, fileName, foleName):

        # ~~ Openning files ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        fle = open(fileName, "rb")
        fole = open(foleName, "wb")
        print "           +> writing the volumes-file: ", foleName

        # ~~ Read/Write dimensions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        n1 = self.NPOIN3 + 1
        minvol = self.minvol * np.ones(self.NPOIN3, dtype=np.float32)

        # ~~ Read volumes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        pbar = ProgressBar(maxval=self.HYDROIT).start()
        for i in range(self.HYDROIT):
            l, it = unpack(">ii", fle.read(4 + 4))
            VOLUME = np.asarray(
                unpack(">" + str(self.NPOIN3) + "f",
                       fle.read(4 * self.NPOIN3)))
            VOLUME = np.maximum(VOLUME, minvol)
            fle.seek(4, 1)
            if it >= self.tfrom and it <= self.tstop:
                pbar.write("            ~> read iteration: " + str(it), i)
                fole.write(pack("<ii", 4 * n1, it - self.HYDRO00))
                fole.write(pack("<" + str(self.NPOIN3) + "f", *(VOLUME)))
                fole.write(pack("<i", 4 * n1))
            else:
                pbar.write("            ~> ignore iteration: " + str(it), i)
            pbar.update(i)
        pbar.finish()

        fle.close()
        fole.close()
Ejemplo n.º 2
0
    def big2littleARE(self, fileName, foleName):

        # ~~ Openning files ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        fle = open(fileName, "rb")
        fole = open(foleName, "wb")
        print "           +> writing the areas-file: ", foleName

        # ~~ Read/Write dimensions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        NSEG2 = (3 * self.geo.NELEM3 + self.conlim.NPTFR) / 2
        MBND2 = np.count_nonzero(self.conlim.BOR["lih"] != 2)
        n3 = NSEG2 + MBND2
        # n4 = 2*( self.geo.NPLAN-1 )*self.geo.NPOIN3

        # ~~ Read volumes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        pbar = ProgressBar(maxval=self.HYDROIT).start()
        for i in range(self.HYDROIT):
            l, it = unpack(">ii", fle.read(4 + 4))
            AREAS = np.asarray(unpack(">" + str(n3) + "f", fle.read(4 * n3)))
            fle.seek(4, 1)
            if it >= self.tfrom and it <= self.tstop:
                pbar.write("            ~> read iteration: " + str(it), i)
                fole.write(pack("<ii", 4 * n3, it - self.HYDRO00))
                fole.write(pack("<" + str(n3) + "f", *(AREAS)))
                fole.write(pack("<i", 4 * n3))
            else:
                pbar.write("            ~> ignore iteration: " + str(it), i)
            pbar.update(i)
        pbar.finish()

        fle.close()
        fole.close()
Ejemplo n.º 3
0
 def getSERIES( self,nodes,varsIndexes=[],showbar=True ):
    f = self.file['hook']
    endian = self.file['endian']
    ftype,fsize = self.file['float']
    if varsIndexes == []: varsIndexes = self.VARINDEX
    # ~~ Ordering the nodes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # This assumes that nodes starts at 1
    onodes = np.sort(np.array( zip(range(len(nodes)),nodes), dtype=[ ('0',int),('1',int) ] ),order='1')
    # ~~ Extract time profiles ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    if fsize == 4: z = np.zeros((len(varsIndexes),len(nodes),len(self.tags['cores'])),dtype=np.float32)
    else: z = np.zeros((len(varsIndexes),len(nodes),len(self.tags['cores'])),dtype=np.float64)
    f.seek(self.tags['cores'][0])
    if showbar: pbar = ProgressBar(maxval=len(self.tags['cores'])).start()
    for t in range(len(self.tags['cores'])):
       f.seek(self.tags['cores'][t])
       f.seek(4+fsize+4,1)
       if showbar: pbar.update(t)
       for ivar in range(self.NVAR):
          f.seek(4,1)
          if ivar in varsIndexes:
             jnod = onodes[0]
             f.seek(fsize*(jnod[1]-1),1)
             z[varsIndexes.index(ivar),jnod[0],t] = unpack(endian+ftype,f.read(fsize))[0]
             for inod in onodes[1:]:
                f.seek(fsize*(inod[1]-jnod[1]-1),1)
                z[varsIndexes.index(ivar),inod[0],t] = unpack(endian+ftype,f.read(fsize))[0]
                jnod = inod
             f.seek(fsize*self.NPOIN3-fsize*jnod[1],1)
          else:
             f.seek(fsize*self.NPOIN3,1)
          f.seek(4,1)
    if showbar: pbar.finish()
    return z
Ejemplo n.º 4
0
    def big2littleVFX(self, fileName, foleName):

        # ~~ Openning files ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        fle = open(fileName, 'rb')
        fole = open(foleName, 'wb')
        print '           +> writing the flows-file: ', foleName

        # ~~ Read/Write dimensions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        NSEG2 = (3 * self.geo.NELEM3 + self.conlim.NPTFR) / 2
        MBND2 = np.count_nonzero(self.conlim.BOR['lih'] != 2)
        n3 = (NSEG2 + MBND2)
        #n4 = 2*( self.geo.NPLAN-1 )*self.geo.NPOIN3

        # ~~ Read volumes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        pbar = ProgressBar(maxval=self.HYDROIT).start()
        for i in range(self.HYDROIT):
            l, it = unpack('>ii', fle.read(4 + 4))
            VFLUXES = np.asarray(unpack('>' + str(n3) + 'f', fle.read(4 * n3)))
            fle.seek(4, 1)
            if it >= self.tfrom and it <= self.tstop:
                pbar.write('            ~> read iteration: ' + str(it), i)
                fole.write(pack('<ii', 4 * n3, it - self.HYDRO00))
                fole.write(pack('<' + str(n3) + 'f', *(VFLUXES)))
                fole.write(pack('<i', 4 * n3))
            else:
                pbar.write('            ~> ignore iteration: ' + str(it), i)
            pbar.update(i)
        pbar.finish()

        fle.close()
        fole.close()
Ejemplo n.º 5
0
   def big2littleARE(self,fileName,foleName):

      # ~~ Openning files ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      fle = open(fileName,'rb')
      fole = open(foleName,'wb')
      print '           +> writing the areas-file: ',foleName

      # ~~ Read/Write dimensions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      NSEG2 = ( 3*self.geo.NELEM3 + self.conlim.NPTFR )/2
      MBND2 = np.count_nonzero(self.conlim.BOR['lih'] != 2)
      n3 = ( NSEG2 + MBND2 )
      #n4 = 2*( self.geo.NPLAN-1 )*self.geo.NPOIN3

      # ~~ Read volumes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      pbar = ProgressBar(maxval=self.HYDROIT).start()
      for i in range(self.HYDROIT):
         l,it = unpack('>ii',fle.read(4+4))
         AREAS = np.asarray( unpack('>'+str(n3)+'f',fle.read(4*n3)) )
         fle.seek(4,1)
         if it >= self.tfrom and it <= self.tstop:
            pbar.write('            ~> read iteration: '+str(it),i)
            fole.write(pack('<ii',4*n3,it-self.HYDRO00))
            fole.write(pack('<'+str(n3)+'f',*(AREAS)))
            fole.write(pack('<i',4*n3))
         else:
            pbar.write('            ~> ignore iteration: '+str(it),i)
         pbar.update(i)
      pbar.finish()

      fle.close()
      fole.close()
Ejemplo n.º 6
0
   def big2littlePTS(self,fileName,foleName):

      # ~~ Openning files ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      fle = open(fileName,'rb')
      fole = open(foleName,'wb')
      print '           +> writing the volumes-file: ',foleName

      # ~~ Read/Write dimensions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      n1 = self.NPOIN3+1
      minvol = self.minvol * np.ones(self.NPOIN3,dtype=np.float32)

      # ~~ Read volumes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      pbar = ProgressBar(maxval=self.HYDROIT).start()
      for i in range(self.HYDROIT):
         l,it = unpack('>ii',fle.read(4+4))
         VOLUME = np.asarray( unpack('>'+str(self.NPOIN3)+'f',fle.read(4*self.NPOIN3)) )
         VOLUME = np.maximum(VOLUME,minvol)
         fle.seek(4,1)
         if it >= self.tfrom and it <= self.tstop:
            pbar.write('            ~> read iteration: '+str(it),i)
            fole.write(pack('<ii',4*n1,it-self.HYDRO00))
            fole.write(pack('<'+str(self.NPOIN3)+'f',*(VOLUME)))
            fole.write(pack('<i',4*n1))
         else:
            pbar.write('            ~> ignore iteration: '+str(it),i)
         pbar.update(i)
      pbar.finish()

      fle.close()
      fole.close()
Ejemplo n.º 7
0
 def putContent(self,fileName,showbar=True): # TODO: files also have to have the same header
    self.slf.fole.update({ 'hook': open(fileName,'wb') })
    ibar = 0
    if showbar: pbar = ProgressBar(maxval=len(self.slf.tags['times'])).start()
    self.slf.appendHeaderSLF()
    # ~~> Time stepping
    for t in range(len(self.slf.tags['times'])):
       ibar += 1
       self.slf.appendCoreTimeSLF(t) # Time stamps
       self.slf.appendCoreVarsSLF(self.getPALUES(t))
       if showbar: pbar.update(ibar)
    self.slf.fole['hook'].close()
    if showbar: pbar.finish()
Ejemplo n.º 8
0
 def putContent( self,fileName,showbar=True ):
    self.fole.update({ 'name': fileName })
    self.fole.update({ 'hook': open(fileName,'wb') })
    ibar = 0
    if showbar: pbar = ProgressBar(maxval=len(self.tags['times'])).start()
    self.appendHeaderSLF()
    for t in range(len(self.tags['times'])):
       ibar += 1
       self.appendCoreTimeSLF(t)
       self.appendCoreVarsSLF(self.getVALUES(t))
       if showbar: pbar.update(ibar)
    self.fole['hook'].close()
    if showbar: pbar.finish()
Ejemplo n.º 9
0
def getEdgesSLF(IKLE,MESHX,MESHY,showbar=True):

   try:
      from matplotlib.tri import Triangulation
      edges = Triangulation(MESHX,MESHY,IKLE).get_cpp_triangulation().get_edges()
   except:
      #print '... you are in bad luck !'
      #print '       ~>  without matplotlib based on python 2.7, this operation takes ages'
      edges = []
      ibar = 0
      if showbar: pbar = ProgressBar(maxval=len(IKLE)).start()
      for e in IKLE:
         ibar += 1
         if showbar: pbar.update(ibar)
         if [e[0],e[1]] not in edges: edges.append([e[1],e[0]])
         if [e[1],e[2]] not in edges: edges.append([e[2],e[1]])
         if [e[2],e[0]] not in edges: edges.append([e[0],e[2]])
      if showbar: pbar.finish()

   return edges
Ejemplo n.º 10
0
def getNeighboursSLF(IKLE,MESHX,MESHY,showbar=True):

   try:
      from matplotlib.tri import Triangulation
      neighbours = Triangulation(MESHX,MESHY,IKLE).get_cpp_triangulation().get_neighbors()
   except:
      #print '... you are in bad luck !'
      #print '       ~>  without matplotlib based on python 2.7, this operation takes a little longer'
      insiders = {}; bounders = {}
      #print '    +> start listing neighbours of edges'
      ibar = 0
      if showbar: pbar = ProgressBar(maxval=(3*len(IKLE))).start()
      for e,i in zip(IKLE,range(len(IKLE))):
         nk = bounders.keys()
         for k in [0,1,2]:
            ibar += 1
            if showbar: pbar.update(ibar)
            if (e[k],e[(k+1)%3]) not in nk: bounders.update({ (e[(k+1)%3],e[k]):i })
            else:
               j = bounders[(e[k],e[(k+1)%3])]
               insiders.update({(e[k],e[(k+1)%3]):[i,j]})
               del bounders[(e[k],e[(k+1)%3])]
      ibar = 0
      neighbours = - np.ones((len(IKLE),3),dtype=np.int)
      for e,i in zip(IKLE,range(len(IKLE))):
         for k in [0,1,2]:
            ibar += 1
            if showbar: pbar.update(ibar)
            if (e[k],e[(k+1)%3]) in insiders:
               a,b = insiders[(e[k],e[(k+1)%3])]
               if a == i: neighbours[i][k] = b
               if b == i: neighbours[i][k] = a
            if (e[(k+1)%3],e[k]) in insiders:
               a,b = insiders[(e[(k+1)%3],e[k])]
               if a == i: neighbours[i][k] = b
               if b == i: neighbours[i][k] = a
      #pbar.write('    +> listing neighbours of edges completed',ibar)
      if showbar: pbar.finish()

   return neighbours
Ejemplo n.º 11
0
 def putContent(self,fileName): # TODO: files also have to have the same header
    if self.suite and self.merge:
       if len(self.slfs) == 2:  # /!\ difference only between two files
          self.slf.fole.update({ 'hook': open(fileName,'wb') })
          self.slf.fole['name'] = fileName
          ibar = 0; pbar = ProgressBar(maxval=len(self.slf.tags['times'])).start()
          self.slf.appendHeaderSLF()
          for t in range(len(self.slf.tags['times'])):
             ibar += 1
             self.slf.appendCoreTimeSLF(t)
             self.slf.appendCoreVarsSLF(self.slf.getVALUES(t)-self.slfs[1].getVALUES(t))
             pbar.update(ibar)
          pbar.finish()
       else: self.slf.putContent(fileName) # just a copy
    elif self.suite:
       self.slf.fole.update({ 'hook': open(fileName,'wb') })
       self.slf.fole['name'] = fileName
       ibar = 0; pbar = ProgressBar(maxval=len(self.slf.tags['times'])).start()
       self.slf.appendHeaderSLF()
       for t in range(len(self.slf.tags['times'])):
          ibar += 1
          time = self.slf.tags['times'][t]
          self.slf.appendCoreTimeSLF(t)
          self.slf.appendCoreVarsSLF(self.slf.getVALUES(t))
          pbar.update(ibar)
       pbar.finish()
       for slf in self.slfs:
          slf.fole = self.slf.fole
          ibar = 0; pbar = ProgressBar(maxval=len(slf.tags['times'])).start()
          for t in range(len(slf.tags['times'])):
             if slf.tags['times'][t] > time:
                ibar += 1
                time = slf.tags['times'][t]
                slf.appendCoreTimeSLF(t)
                slf.appendCoreVarsSLF(slf.getVALUES(t))
                pbar.update(ibar)
          pbar.finish()
       self.slf.fole['hook'].close()
    elif self.merge:
       self.slf.fole.update({ 'hook': open(fileName,'wb') })
       self.slf.fole['name'] = fileName
       for slf in self.slfs[1:]:
          slf.fole = self.slf.fole
          idvars = []
          for v in range(len(slf.VARNAMES)):
             if v not in self.slf.VARNAMES:
                idvars.append(v)
                self.slf.VARNAMES.append(slf.VARNAMES[v])
                self.slf.VARUNITS.append(slf.VARUNITS[v])
          for v in range(len(slf.CLDNAMES)):
             if v not in self.slf.CLDNAMES:
                idvars.append(v+slf.NBV1)
                self.slf.CLDNAMES.append(slf.CLDNAMES[v])
                self.slf.CLDUNITS.append(slf.CLDUNITS[v])
          slf.VARINDEX = idvars
          self.slf.NBV1 = len(self.slf.VARNAMES)
          self.slf.NBV2 = len(self.slf.CLDNAMES)
       ibar = 0; pbar = ProgressBar(maxval=len(self.slf.tags['times'])).start()
       self.slf.appendHeaderSLF()
       for t in range(len(self.slf.tags['times'])):
          ibar += 1
          self.slf.appendCoreTimeSLF(t)
          self.slf.appendCoreVarsSLF(self.slf.getVALUES(t))
          for slf in self.slfs[1:]:
             self.slf.appendCoreVarsSLF(slf.getVALUES(t))
          pbar.update(ibar)
       pbar.finish()
       self.slf.fole['hook'].close()
    elif len(self.slf.tags['times']) == 1 and len(self.slfs) == 2:
    # self.slf will be distributed over the time frames of the scond other
       self.slf.fole.update({ 'hook': open(fileName,'wb') })
       self.slf.fole['name'] = fileName
       slf = self.slfs[1]
       slf.fole = self.slf.fole
       idvars = []
       for v in range(len(slf.VARNAMES)):
          if v not in self.slf.VARNAMES:
             idvars.append(v)
             self.slf.VARNAMES.append(slf.VARNAMES[v])
             self.slf.VARUNITS.append(slf.VARUNITS[v])
       for v in range(len(slf.CLDNAMES)):
          if v not in self.slf.CLDNAMES:
             idvars.append(v+slf.NBV1)
             self.slf.CLDNAMES.append(slf.CLDNAMES[v])
             self.slf.CLDUNITS.append(slf.CLDUNITS[v])
       slf.VARINDEX = idvars
       self.slf.NBV1 = len(self.slf.VARNAMES)
       self.slf.NBV2 = len(self.slf.CLDNAMES)
       ibar = 0; pbar = ProgressBar(maxval=len(slf.tags['times'])).start()
       self.slf.appendHeaderSLF()
       for t in range(len(slf.tags['times'])):
          ibar += 1
          slf.appendCoreTimeSLF(slf,t)
          self.slf.appendCoreVarsSLF(self.slf.getVALUES(0))
          slf.appendCoreVarsSLF(slf.getVALUES(t))
          pbar.update(ibar)
       pbar.finish()
       self.slf.fole['hook'].close()
    else:
       print "Does not know how to merge your files. Try either:"
       print "    + to make sure your files have the same time support"
       print "    + to make sure your files have the same variables"
       sys.exit(1)