示例#1
0
 def getHeadPtObs(self, aqui, irow, icol, ilay, iper):
     try:
         f1 = open(self.pFullPath + '.head', 'rb')
     except IOError:
         return None
     grd = aqui.getFullGrid()
     ncol, nrow = grd['nx'], grd['ny']
     nlay = aqui.getNbCouches()
     if aqui.getDim() in ['Xsection', 'Radial']:
         nlay = nrow * 1
         nrow = 1
         ilay = irow * 1
         irow = [0] * len(ilay)
     nper = len(iper)
     hd = zeros((nper, len(irow)))
     f1.seek(32)
     data = arr2('i')
     #data.fromfile(f1,3);ncol,nrow,nlay=data;print 'mfw gethedpt nc,nr,nl',ncol,nrow,nlay
     blok = 44 + nrow * ncol * 4
     #print 'mfw gethedpt ilay,icol,row',ilay,icol,irow
     for ip in range(nper):
         for i in range(len(irow)):
             pos = 44 + iper[ip] * nlay * blok + ilay[i] * blok + irow[
                 i] * ncol * 4 + icol[i] * 4
             f1.seek(pos)
             data = arr2('f')
             data.fromfile(f1, 1)
             #print iper[ip],irow[i],icol[i],data
             hd[ip, i] = float(data[0])
     return hd
示例#2
0
 def getPart(self, f1):
     #if 3>2:
     l0 = 11
     f1.seek(l0)
     data = arr2('i')
     data.fromfile(f1, 14)
     mwel, mdrn, mrch, mevt, mriv, m, chd, mss, nper, kp, kst, ncol, nrow, nlay = data
     blok = 5 * 4 + 16 + ncol * nrow * nlay * 4
     l2 = 5 * 4 + 16 + 4
     nwel = 0
     mss = 1
     # even in SS it seems to have sto?
     ichd = sign(chd)
     iwel = sign(mwel)
     irch = sign(mrch)
     icol = sign(ncol - 1)
     irow = sign(nrow - 1)
     ilay = sign(nlay - 1)
     part0 = blok + icol * blok + irow * blok + ilay * blok + mss * blok + ichd * (
         l2 + chd * 16)
     if iwel > 0:
         f1.seek(l0 + 36 + part0 + l2 - 4)
         data = arr2('i')
         data.fromfile(f1, 1)
         nwel = data[0]
     part = part0 + iwel * (l2 + nwel * 16) + irch * (l2 - 4 +
                                                      ncol * nrow * 4 * 2)
     return ncol, nrow, nlay, blok, part
示例#3
0
 def getHeadPtObs(self, core, irow, icol, ilay, iper):
     try:
         f1 = open(self.fDir + os.sep + self.fName + '.head', 'rb')
     except IOError:
         return None
     grd = core.addin.getFullGrid()
     ncol, nrow = grd['nx'], grd['ny']
     nlay = getNlayers(core)
     if core.addin.getDim() in ['Xsection', 'Radial']:
         nlay = nrow * 1
         nrow = 1
         # already done above ilay=irow*1;irow=[0]*len(ilay)
     nper = len(iper)
     hd = zeros((nper, len(irow)))
     f1.seek(32)
     data = arr2('i')
     blok = 44 + nrow * ncol * 4
     #print 'mfw gethedpt ilay,icol,row',ilay,icol,irow
     for ip in range(nper):
         for i in range(len(irow)):
             pos = 44 + iper[ip] * nlay * blok + ilay[i] * blok + irow[
                 i] * ncol * 4 + icol[i] * 4
             f1.seek(pos)
             data = arr2('f')
             data.fromfile(f1, 1)
             #print iper[ip],irow[i],icol[i],data
             hd[ip, i] = float(data[0])
     return hd
示例#4
0
 def getPtObs(self, aqui, irow, icol, ilay, iper, typ):
     """for typ=flux return fluxes for a series of obs cell
     for typ=head return the heads
     iper is a list of periods indices"""
     nper = len(iper)
     if aqui.getDim() in ['Xsection', 'Radial']:
         ilay = irow * 1
         irow = [0] * len(ilay)
     if typ == 'Charge':
         return self.getHeadPtObs(aqui, irow, icol, ilay, iper)
     try:
         f1 = open(self.pFullPath + '.flo', 'rb')
     except IOError:
         return None
     ncol, nrow, nlay, blok, part = self.getPart(f1)
     blok2 = ncol * nrow * 4
     l0 = 11
     qx = zeros((nper, len(irow)))
     qy = qx * 0.
     for ip in range(nper):
         posx = l0 + 36 + iper[ip] * part + blok + 5 * 4 + 16
         posy = posx + blok
         for i in range(len(irow)):
             pos2 = blok2 * ilay[i] + irow[i] * ncol * 4 + icol[i] * 4
             f1.seek(posx + pos2)
             data = arr2('f')
             data.fromfile(f1, 1)
             qx[ip, i] = float(data[0])
             f1.seek(posy + pos2)
             data = arr2('f')
             data.fromfile(f1, 1)
             qy[ip, i] = float(data[0])
     return qx, qy
示例#5
0
    def ReadFloFile(self, aqui,iper=0):
        """ read flo file and gives back Darcy velocities"""
        grd = aqui.getFullGrid();dx, dy = grd['dx'], grd['dy'];
        dxm,dym=meshgrid(dx,dy)
        ep = aqui.getEpais();
        if aqui.getDim() in ['Xsection','Radial']:
            dxm=array(dx);dym=1.;
        try : f1 = open(self.pFullPath+'.flo','rb')
        except IOError : return None
        # point de depart dans le fichier
        # variables Sat,Qx(ncol>1),Qy(nrow>1),Qz(nlay>1),Stor(trans),
        ncol,nrow,nlay,blok,part=self.getPart(f1);
        l0=11;pos = l0+36+iper*part+blok+5*4+16       
        f1.seek(pos);data = arr2('f');data.fromfile(f1,nlay*ncol*nrow)        
        vx = reshape(data,(nlay,nrow,ncol))
        # trouver position des vitesses y
        pos = l0+36+iper*part+blok*2+5*4+16
        f1.seek(pos);data = arr2('f');data.fromfile(f1,nlay*ncol*nrow)       
        vy = reshape(data,(nlay,nrow,ncol));bal=0.0
##        if nlay==1: # balance de flux
##            vx=vx[0][::-1,:];vy=-vy[0][::-1,:];vx[vx==0.]=1.;vy[vy==0.]=1.;
##            vm=abs(vx)+abs(vy);vmax=amax(amax(vm))
##            bal=abs(vx[2:-2,1:-2]-vx[2:-2,2:-1]+vy[2:-2,2:-1]-vy[3:-1,2:-1])# on prend pas les bords
##            bal[vm[2:-2,1:-2]<vmax*1e-3]=0.
##            #bal[pot[2:-2,1:-2]!=0.]=0.;
##            md=median(median(bal));b2=clip(bal,md*1e-3,md*1e3)
##            bal=sum(sum(b2/(abs(vx[2:-2,1:-2])+abs(vy[2:-2,2:-1]))))*100
        # trouver position des vitesses z (nexiste que si plus d'un layer)
        bal=0.
        if nlay>1: # rajouter vz
            nb=2 #number of blocks to read z velocities (absence of y velo)
            if nrow>1: nb=3 #presence of y velo
            pos = l0+36+iper*part+blok*nb+5*4+16
            f1.seek(pos);data = arr2('f');data.fromfile(f1,nlay*ncol*nrow)       
            m0 = reshape(data,(nlay,nrow,ncol));vz=m0*0.
            for l in range(nlay): vz[l] = m0[l]/dxm/dym
            vz=concatenate([vz[:1,:,:],vz],axis=0)
        # fermer le fichier
        f1.close();
        # rows are ordered from top to bottom in modflow so invert them here
        vx=vx[:,::-1,:]/dym/ep;vy=-vy[:,::-1,:]/dxm/ep; #retourner les vecteurs
        # as vx start from right of 1st cell we need to add one in the first col
        vx=concatenate([vx[:,:,:1],vx],axis=2);vx[:,:,-1]=vx[:,:,-2]
        # ssame for vy start at lower face, which is the last one now (inversion)
        vy=concatenate([vy,vy[:,-1:,:]],axis=1)
        # seems that vy is surrounded by 0
        vy[:,:,0]=vy[:,:,1];vy[:,:,-1]=vy[:,:,-2];vy[:,0,:]=vy[:,1,:]
        if aqui.getDim() in ['Xsection','Radial']:
            vx=vx[::-1,:,:]*1;vz=vz[::-1,:,:]*1
        if nlay>1 : return [vx,vy,-vz]#,bal -vz[:,::-1,:]
        else : return [vx,vy]
示例#6
0
 def getPart(self,f1):
 #if 3>2:
     l0=11;f1.seek(l0);data = arr2('i');data.fromfile(f1,14);
     mwel,mdrn,mrch,mevt,mriv,m,chd,mss,nper,kp,kst,ncol,nrow,nlay = data
     blok=5*4+16+ncol*nrow*nlay*4;l2=5*4+16+4
     nwel=0;mss=1; # even in SS it seems to have sto?
     ichd=sign(chd);iwel=sign(mwel);irch=sign(mrch)
     icol=sign(ncol-1);irow=sign(nrow-1);ilay=sign(nlay-1);
     part0=blok+icol*blok+irow*blok+ilay*blok+mss*blok+ichd*(l2+chd*16)
     if iwel>0:
         f1.seek(l0+36+part0+l2-4);data = arr2('i');data.fromfile(f1,1)
         nwel=data[0];
     part=part0+iwel*(l2+nwel*16)+irch*(l2-4+ncol*nrow*4*2);
     return ncol,nrow,nlay,blok,part
示例#7
0
 def ReadHeadFile(self, aqui, iper=0):
     """ lecture du fichier .head (fichier dwritevant la charge) """
     grd = aqui.getFullGrid()
     ncol, nrow = grd['nx'], grd['ny']
     nlay = aqui.getNbCouches()
     #print iper, nlay,ncol,nrow
     if aqui.getDim() in ['Xsection', 'Radial']:
         nlay = nrow
         nrow = 1
     #print 'mfl readh',nlay,ncol,nrow
     try:
         f1 = open(self.pFullPath + '.head', 'rb')
     except IOError:
         return None
     hd = zeros((nlay, nrow, ncol)) + 0.
     blok = 44 + nrow * ncol * 4
     # v210 60
     for il in range(nlay):
         #pos=iper*nlay*blok+blok*il+56;f1.seek(pos) v1_10
         pos = iper * nlay * blok + blok * il + 44
         f1.seek(pos)  #vpmwin
         data = arr2('f')
         data.fromfile(f1, nrow * ncol)
         hd[il] = reshape(data, (nrow, ncol))  #
     f1.close()
     if aqui.getDim() in ['Xsection', 'Radial']: hd = array(hd[::-1, :, :])
     else:
         hd = array(hd[:, ::-1, :])
         #print 'mflwri rdhed',shape(hd)
     return hd
示例#8
0
 def readUCN(self,core,opt,tstep,iesp,specname=''): # struct 32*4+6*4+icbund(nrow*ncol)+3*4+Cnc(nrow,ncol)+4?
     """lecture fichier ucn, typ : rt ou pht, donner le tstep, le num de l'espece et aqui"""
     grd  = core.addin.getFullGrid()
     ncol,nrow = grd['nx'],grd['ny']
     nlay = getNlayers(core)
     dim = core.addin.getDim()
     if dim in ['Xsection','Radial']:
         nlay=nrow*1;nrow=1
     suff1 = opt*1
     if opt=='Mt3dms': suff1 = 'MT3D'
     if iesp<9: suff2='00'
     else : suff2='0'
     tlist = core.ttable['tlist']
     fname=self.fDir+os.sep+suff1+suff2+str(iesp+1)+'.UCN'
     try: f1=open(fname,'rb')
     except IOError: return None
     m0=zeros((nlay,nrow,ncol))+0.
     if opt=='Mt3dms': # pb Mt3dms sometimes write more time steps...
         lt=self.getMt3dTlist(f1,ncol,nrow,nlay);
         tstep=argmin(abs(tlist[tstep+1]-lt)); # try to find the closest one
     blok=44+ncol*nrow*4;
     p0 = blok*nlay*tstep;#print 'mp3read',tstep,nlay
     #print 'ucn',fname,tstep
     for l in range(nlay):
         pos=p0+blok*l+44;f1.seek(pos);#print 'ucn',nlay,ncol,nrow,pos,p0 # v212
         data = arr2('f');data.fromfile(f1, ncol*nrow)
         m0[l]=reshape(data,(nrow,ncol))
     f1.close()
     #if dim in ['Xsection','Radial']: return m0[::-1,:,:]
     #else : 
     return m0[:,::-1,:]
示例#9
0
 def lireUCN(self, aqui,opt, tstep, iesp): # struct 32*4+6*4+icbund(nrow*ncol)+3*4+Cnc(nrow,ncol)+4?
     """lecture fichier ucn, typ : rt ou pht, donner le tstep, le num de l'espece et aqui"""
     grd  = aqui.getFullGrid()
     x0,dcol,ncol = grd['x0'],grd['dx'],grd['nx']
     y0,drow,nrow = grd['y0'],grd['dy'],grd['ny']
     nlay = aqui.getNbCouches()
     if aqui.getDim() in ['Xsection','Radial']:
         nlay=nrow*1;nrow=1
     if iesp<9: suff='00'
     else : suff='0'
     tlist=aqui.getZoneTransient()['tlist']
     fname=self.pPath+os.sep+opt+suff+str(iesp+1)+'.UCN'
     try: f1=open(fname,'rb')
     except IOError: return None
     m0=zeros((nlay,nrow,ncol))+0.;mult=1;
     if opt=='MT3D': # pb Mt3d sometimes write more time steps...
         lt=self.getMt3dTlist(f1,ncol,nrow,nlay);#print 'ireUcn',tstep,lt
         #print 'mtpht ucn',ncol,nrow,nlay,tstep,lt
         tstep=argmin(abs(tlist[tstep]-lt))+1;#a=arange(len(lt));tstep=max(a[lt==tstep])
     elif opt=='PHT3D':
         tstep=tstep+1
     p0 = (44+ncol*nrow*4)*nlay*tstep;#print 'mp3read',tstep,nlay
     for l in range(nlay):
         pos=p0+(44+ncol*nrow*4)*l+44;f1.seek(pos) # v212
         data = arr2('f');data.fromfile(f1, ncol*nrow)
         m0[l]=reshape(data,(nrow,ncol))
     f1.close()
     if aqui.getDim() in ['Xsection','Radial']:return m0[::-1,:,:]
     else : return m0[:,::-1,:]
示例#10
0
 def getWcontentPtObs(self, f1, core, irow, icol, ilay, iper):
     grd = core.addin.getFullGrid()
     ncol, nrow = grd['nx'], grd['ny']
     nlay = getNlayers(core)
     #print nlay,ncol,nrow,ilay,icol,irow
     if core.addin.getDim() in ['Xsection', 'Radial']:
         nlay = nrow * 1
         nrow = 1
         ilay = irow * 1
         irow = [0] * len(ilay)
     nper = len(iper)
     ncol, nrow, nlay, part = self.getPart2(f1)
     wc = zeros((nper, len(irow)))
     l0 = 11 + 26 * 4
     for ip in range(nper):
         pos = l0 + iper[ip] * part + 5 * 4 + 16
         for i in range(len(irow)):
             pos2 = ilay[i] * nrow * ncol * 4 + irow[i] * ncol * 4 + icol[
                 i] * 4
             f1.seek(pos + pos2)
             data = arr2('f')
             data.fromfile(f1, 1)
             #print iper[ip],irow[i],icol[i],data
             wc[ip, i] = float(data[0])
     return wc
示例#11
0
 def getPtObs(self,aqui,irow,icol,ilay,iper,opt,iesp=0):
     """a function to values of one variable at given point or points.
     irow, icol and ilay must be lists of the same length. iper is also
     a list containing the periods for which data are needed."""
     grd = aqui.getFullGrid();ncol, nrow = grd['nx'], grd['ny']
     nlay=aqui.getNbCouches();
     if aqui.getDim() in ['Xsection','Radial']:
         nlay=nrow*1;nrow=1
     if iesp<9: suff='00'
     else : suff='0'
     tlist=aqui.getZoneTransient()['tlist']
     fname=self.pPath+os.sep+opt+suff+str(iesp+1)+'.UCN'
     blok=44+ncol*nrow*4;
     try : f1 = open(fname,'rb')
     except IOError: return None
     if aqui.getDim() in ['Xsection','Radial']:
         ilay=irow*1;irow=[0]*len(ilay)
     npts=len(irow);pobs=zeros((len(iper),npts))+0.;
     lt=self.getMt3dTlist(f1,ncol,nrow,nlay)
     #print 'mtpht obs',iper,lt
     for ip in range(len(iper)):
         if opt=='MT3D':
             ip2=argmin(abs(tlist[iper[ip]]-lt))+1#a=arange(len(lt));;ip2=max(a[lt==iper[ip]])
         elif opt=='PHT3D' :
             ip2=iper[ip]+1
         p0=blok*nlay*ip2;
         for i in range(npts):
             f1.seek(p0+blok*ilay[i]+44+irow[i]*ncol*4+icol[i]*4)
             try:
                 data = arr2('f');data.fromfile(f1,1);
                 pobs[ip,i]=float(data[0])
             except EOFError: return pobs
     return pobs
示例#12
0
 def getHeadPtObs(self,aqui,irow,icol,ilay,iper):
     try : f1 = open(self.pFullPath+'.head','rb')
     except IOError: return None
     grd = aqui.getFullGrid();ncol, nrow = grd['nx'], grd['ny']
     nlay=aqui.getNbCouches();
     if aqui.getDim() in ['Xsection','Radial']:
         nlay=nrow*1;nrow=1;ilay=irow*1;irow=[0]*len(ilay)
     nper=len(iper);hd=zeros((nper,len(irow)))
     f1.seek(32);data=arr2('i');
     #data.fromfile(f1,3);ncol,nrow,nlay=data;print 'mfw gethedpt nc,nr,nl',ncol,nrow,nlay
     blok=44+nrow*ncol*4;#print 'mfw gethedpt ilay,icol,row',ilay,icol,irow
     for ip in range(nper):
         for i in range(len(irow)):
             pos=44+iper[ip]*nlay*blok+ilay[i]*blok+irow[i]*ncol*4+icol[i]*4;
             f1.seek(pos);data = arr2('f');data.fromfile(f1,1);#print iper[ip],irow[i],icol[i],data
             hd[ip,i]=float(data[0])
     return hd
示例#13
0
 def getMt3dTlist(self,f1,ncol,nrow,nlay):
     tread=[];i=0;blok=(44+ncol*nrow*4)*nlay
     while 3>2:
         f1.seek(blok*i+12);
         try :
             a=arr2('f');a.fromfile(f1,1);#print 'mt per',i1,a
             tread.append(a[0]);i+=1 #this is the true time given by mt3d
         except EOFError:
             #print ncol,nrow,nlay,tread;
             return array(tread)
示例#14
0
 def getMt3dTlist(self,f1,ncol,nrow,nlay):
     tread=[];i=0;blok=(44+ncol*nrow*4)*nlay
     while 3>2:
         f1.seek(blok*i+12);
         try :
             #i1=arr2('i');i1.fromfile(f1,1);
             a=arr2('f');a.fromfile(f1,1);#print 'mt per',i1,a
             tread.append(a[0]);i+=1 #this is the true time given by mt3d
         except EOFError:
             #print ncol,nrow,nlay,tread;
             return array(tread)
示例#15
0
 def getPtObs(self, core, irow, icol, ilay, iper, opt, iesp, spec, ss=None):
     ''' get conc for given line (or poly), if tracer iesp=0
     spec not used, icol not used here
     '''
     nper = len(iper)  # OA 20/5/21
     f1 = open(self.fDir + os.sep + self.fName + '.cbb', 'rb')
     if opt == 'Pht3d':  # OA 20/5/21
         lSpec = core.addin.chem.getListSpecies()
         nspec = len(lSpec) + 3
         iesp += 3
         # always 3 species added (O,H,charge)
     else:  # OA 20/5/21
         nspec = 1
     c = zeros((nper, len(irow)))
     if core.mfUnstruct and core.getValueFromName('Modflow', 'MshType') > 0:
         nlay, ncell = getNlayers(core), core.addin.mfU.getNumber(
             'elements')  # only 1 layer up to now
         dc, blok, styp = 52, 52 + ncell * 8, 'd'
         for i, ip in enumerate(iper):  # OA 2/11
             for j in range(len(irow)):  # OA 2/11
                 il = ilay[j]
                 f1.seek(ip * nspec * nlay * blok + iesp * nlay * blok +
                         blok * il + dc + icol[j] * 8)
                 data = arr2(styp)
                 data.fromfile(f1, 1)
                 c[i, j] = data[0]
                 #plot(data)#1)
     else:  # OA 2/11 all below changed
         nlay, ncol, nrow = self.getGeom(core)
         dc, blok, styp = 52, 52 + ncol * nrow * 8, 'd'
         # OA 2/11 put here
         for i, ip in enumerate(iper):
             for j in range(len(irow)):
                 il = ilay[j]
                 f1.seek(ip * nspec * nlay * blok + iesp * nlay * blok +
                         blok * il + dc + irow[j] * ncol * 8 + icol[j] * 8)
                 data = arr2(styp)
                 data.fromfile(f1, 1)
                 c[i, j] = data[0]
                 #plot(data)#1)
     return c
示例#16
0
 def getPart2(self, f1):
     # variables Wcontent, UzFlux, UzSto, GwOut,ThKsat, Qxx, Qzz, Sto, Cnh
     nvar = 8  # CNH not included
     # simplified version : no wells, no rech... should be included into getpart
     f1.seek(11)
     data = arr2('i')
     data.fromfile(f1, 26)
     ncol, nrow, nlay = data[-3:]
     ncnh = data[6]
     l2 = 5 * 4 + 16 + 4
     blok = 5 * 4 + 16 + ncol * nrow * nlay * 4
     part = nvar * blok + l2 + ncnh * 16
     return ncol, nrow, nlay, part
示例#17
0
 def getPtObs(self,aqui,irow,icol,ilay,iper,typ):
     """for typ=flux return fluxes for a series of obs cell
     for typ=head return the heads
     iper is a list of periods indices"""
     nper=len(iper);
     if aqui.getDim() in ['Xsection','Radial']:
         ilay=irow*1;irow=[0]*len(ilay)
     if typ=='Charge': 
         return self.getHeadPtObs(aqui,irow,icol,ilay,iper)
     try : f1 = open(self.pFullPath+'.flo','rb')
     except IOError : return None
     ncol,nrow,nlay,blok,part=self.getPart(f1);blok2=ncol*nrow*4
     l0=11;qx= zeros((nper,len(irow)));qy=qx*0.
     for ip in range(nper):
         posx = l0+36+iper[ip]*part+blok+5*4+16;posy=posx+blok
         for i in range(len(irow)):
             pos2 = blok2*ilay[i]+irow[i]*ncol*4+icol[i]*4
             f1.seek(posx+pos2);data = arr2('f');data.fromfile(f1,1)
             qx[ip,i] = float(data[0])
             f1.seek(posy+pos2);data = arr2('f');data.fromfile(f1,1)        
             qy[ip,i] = float(data[0])
     return qx,qy
示例#18
0
 def readWcontent(self, core, iper=0):
     try:
         f1 = open(self.fDir + os.sep + self.fName + '.flo', 'rb')
     except IOError:
         return None
     # this is a file produced by uzf
     ncol, nrow, nlay, part = self.getPart2(f1)
     pos = 11 + 26 * 4 + iper * part + 5 * 4 + 16
     f1.seek(pos)
     data = arr2('f')
     data.fromfile(f1, nlay * ncol * nrow)
     sat = reshape(data, (nlay, nrow, ncol))
     return sat[-1::-1]
示例#19
0
 def getThksat(self, core, iper=0):
     try:
         f1 = open(self.fDir + os.sep + self.fName + '.flo', 'rb')
     except IOError:
         return None
     ncol, nrow, nlay, blok, part = self.getPart()
     f1.seek(11 + 36 + iper * part + 36)
     data = arr2('f')
     data.fromfile(f1, nlay * ncol * nrow)
     thksat = reshape(data, (nlay, nrow, ncol))
     thksat[thksat < 0] = 0
     thksat[thksat > 1e5] = 0
     #print 'mfw 409 thksat',thksat
     return thksat
示例#20
0
 def getLocalTransientV(self, core, infos, thick, ilay, irow, icol, iper):
     """a method to get the darcy velocity at a given location and a given period from
     the flo file. only in x,y but for the correct layer"""
     grd = core.addin.getFullGrid()
     dx, dy, ny = grd['dx'], grd['dy'], grd['ny']
     try:
         f1 = open(self.fDir + os.sep + self.fName + '.flo', 'rb')
     except IOError:
         return None
     ncol, nrow, nlay, blok, part = infos
     #print 'mfw 495',ncol,nrow,nlay
     l0 = 11
     #print irow,icol,iper
     pos1 = l0 + 36 + iper * part + blok + 36
     pos2 = ilay * ncol * nrow * 4 + (
         ny - irow - 1
     ) * ncol * 4 + icol * 4  # ny because modflow and ipht3d ordered differently
     f1.seek(pos1 + pos2)
     vx0 = arr2('f')
     vx0.fromfile(f1, 2)
     f1.seek(pos1 + blok + pos2)
     vy0 = arr2('f')
     vy0.fromfile(f1, 2)
     if nlay > 1:
         nb = 1
         if nrow > 1: nb = 2
         f1.seek(pos1 + blok * nb + pos2)
         vz0 = arr2('f')
         vz0.fromfile(f1, 2)
     f1.close()
     if core.addin.getDim() in ['Xsection', 'Radial']:
         return [vx0 / dy[irow] / 1., 0 - vz0 / dx[icol] / 1.]
     vx1 = vx0 / dy[irow] / thick[ilay, irow, icol]
     vy1 = vy0 / dx[icol] / thick[ilay, irow, icol]
     #if nlay>1 : return [vx1,vy1,0-vz0/dy[irow]/dx[icol]]
     #else :
     return [vx1, -vy1]
示例#21
0
 def getPtObs(self, core, irow, icol, ilay, iper, typ):
     """for typ=flux return fluxes for a series of obs cell
     for typ=head return the heads
     iper is a list of periods indices"""
     try:
         f1 = open(self.fDir + os.sep + self.fName + '.flo', 'rb')
     except IOError:
         return None
     nper = len(iper)
     if core.addin.getDim() in ['Xsection', 'Radial']:
         ilay = irow * 1
         irow = [0] * len(ilay)  #[-1::-1]
     #print 'mfw getpt',typ,irow,icol
     if typ == 'Head':
         return self.getHeadPtObs(core, irow, icol, ilay, iper)
     elif typ == 'Wcontent':
         return self.getWcontentPtObs(f1, core, irow, icol, ilay, iper)
     ncol, nrow, nlay, blok, part = self.getPart()
     blok2 = ncol * nrow * 4
     l0 = 11
     qx = zeros((nper, len(irow)))
     qy = qx * 0.
     for ip in range(nper):
         posx = l0 + 36 + iper[ip] * part + blok + 5 * 4 + 16
         posy = posx + blok
         for i in range(len(irow)):
             pos2 = blok2 * ilay[i] + irow[i] * ncol * 4 + icol[i] * 4
             f1.seek(posx + pos2)
             data = arr2('f')
             data.fromfile(f1, 1)
             qx[ip, i] = float(data[0])
             f1.seek(posy + pos2)
             data = arr2('f')
             data.fromfile(f1, 1)
             qy[ip, i] = float(data[0])
     return qx, qy
示例#22
0
 def readUCN(self, core, opt, iper, iesp, specname='', double=True):
     """ read .conc file, here opt, iesp, specname are not used
     in free flow Thksat from flo file must be added (not done)"""
     #if core.dicval['MfUsgTrans']['uoc.1'][0]==0: # ascii
     #    return self.readConc(core,opt,iper,iesp,specname)
     if opt == 'Pht3d':  # OA 20/5/21
         lSpec = core.addin.chem.getListSpecies()
         nspec = len(lSpec) + 3
         iesp += 3
         # 3 species added by usg/pht3d OA 3/11/21
     else:
         nspec = 1
     if core.mfUnstruct and core.getValueFromName('Modflow', 'MshType') > 0:
         nlay, ncell = getNlayers(core), core.addin.mfU.getNumber(
             'elements')  # only 1 layer up to now
         cnc = zeros((nlay, ncell))
         #print('mfw 491', shape(cnc))
     else:
         nlay, ncol, nrow = self.getGeom(core)
         ncell = ncol * nrow
         cnc = zeros((nlay, nrow, ncol))
     try:
         f1 = open(self.fDir + os.sep + self.fName + '.cbb',
                   'rb')  #OA 17/8/21
     except IOError:
         return None
     #print('f1',f1.read())
     #if opt == 'Mt3dms': dc,blok,styp = 44,44+ncell*4,'f'; # usg transport
     #else :
     if double: dc, blok, styp = 52, 52 + ncell * 8., 'd'  # pht3d_usg
     else: dc, blok, styp = 44, 44 + ncell * 4, 'f'
     for il in range(nlay):
         f1.seek(
             int(iper * nspec * nlay * blok + iesp * nlay * blok +
                 blok * il + dc))  # OA 6/11/21
         data = arr2(styp)
         data.fromfile(f1, ncell)
         if core.mfUnstruct and core.getValueFromName('Modflow',
                                                      'MshType') > 0:
             cnc[il] = data
         else:
             cnc[il] = reshape(data, (nrow, ncol))  #
             if core.mfUnstruct == False:
                 cnc[il] = cnc[il][::-1]  #OA 23/4/2
     if opt == 'Pht3d': cnc[cnc == -1] = 0
     f1.close()
     return cnc
示例#23
0
 def readUCN(self,
             core,
             opt,
             tstep,
             iesp,
             specname=''
             ):  # struct 32*4+6*4+icbund(nrow*ncol)+3*4+Cnc(nrow,ncol)+4?
     """reads ucn"""
     grd = core.addin.getFullGrid()
     ncol, nrow = grd['nx'], grd['ny']
     nlay = getNlayers(core)
     dim = core.addin.getDim()
     if dim in ['Xsection', 'Radial']:
         nlay = nrow * 1
         nrow = 1
     suff1 = 'PHT3D'
     if opt == 'Mt3dms' and 'UZT' not in core.getUsedModulesList('Mt3dms'):
         suff1 = 'MT3D'
     if iesp < 9: suff2 = '00'
     else: suff2 = '0'
     tlist = core.ttable['tlist']
     fname = self.fDir + os.sep + suff1 + suff2 + str(iesp + 1) + '.UCN'
     try:
         f1 = open(fname, 'rb')
     except IOError:
         return None
     m0 = zeros((nlay, nrow, ncol)) + 0.
     if opt == 'Mt3dms':  # pb Mt3dms sometimes write more time steps...
         lt = self.getMt3dTlist(f1, ncol, nrow, nlay)
         tstep = argmin(abs(tlist[tstep + 1] - lt))
         # try to find the closest one
     blok = 44 + ncol * nrow * 4
     p0 = blok * nlay * tstep
     #print 'mp3read',tstep,nlay
     #print 'ucn',fname,tstep
     for l in range(nlay):
         pos = p0 + blok * l + 44
         f1.seek(pos)
         #print 'ucn',nlay,ncol,nrow,pos,p0 # v212
         data = arr2('f')
         data.fromfile(f1, ncol * nrow)
         m0[l] = reshape(data, (nrow, ncol))
     f1.close()
     if dim in ['Xsection', 'Radial']:
         return m0  # [::-1,:,:] #OA 11/3/19 renversement, je sais pas bien
     else:
         return m0[:, ::-1, :]
示例#24
0
 def getPtObs(self, aqui, irow, icol, ilay, iper, opt, iesp=0):
     """a function to values of one variable at given point or points.
     irow, icol and ilay must be lists of the same length. iper is also
     a list containing the periods for which data are needed."""
     grd = aqui.getFullGrid()
     ncol, nrow = grd['nx'], grd['ny']
     nlay = aqui.getNbCouches()
     if aqui.getDim() in ['Xsection', 'Radial']:
         nlay = nrow * 1
         nrow = 1
     if iesp < 9: suff = '00'
     else: suff = '0'
     tlist = aqui.getZoneTransient()['tlist']
     fname = self.pPath + os.sep + opt + suff + str(iesp + 1) + '.UCN'
     blok = 44 + ncol * nrow * 4
     try:
         f1 = open(fname, 'rb')
     except IOError:
         return None
     if aqui.getDim() in ['Xsection', 'Radial']:
         ilay = irow * 1
         irow = [0] * len(ilay)
     npts = len(irow)
     pobs = zeros((len(iper), npts)) + 0.
     lt = self.getMt3dTlist(f1, ncol, nrow, nlay)
     #print 'mtpht obs',iper,lt
     for ip in range(len(iper)):
         if opt == 'MT3D':
             ip2 = argmin(
                 abs(tlist[iper[ip]] -
                     lt)) + 1  #a=arange(len(lt));;ip2=max(a[lt==iper[ip]])
         elif opt == 'PHT3D':
             ip2 = iper[ip] + 1
         p0 = blok * nlay * ip2
         for i in range(npts):
             f1.seek(p0 + blok * ilay[i] + 44 + irow[i] * ncol * 4 +
                     icol[i] * 4)
             try:
                 data = arr2('f')
                 data.fromfile(f1, 1)
                 pobs[ip, i] = float(data[0])
             except EOFError:
                 return pobs
     return pobs
示例#25
0
 def ReadHeadFile(self, aqui,iper=0):
     """ lecture du fichier .head (fichier dwritevant la charge) """    
     grd = aqui.getFullGrid();ncol, nrow = grd['nx'], grd['ny']
     nlay=aqui.getNbCouches();#print iper, nlay,ncol,nrow
     if aqui.getDim() in ['Xsection','Radial']:
         nlay=nrow;nrow=1
     #print 'mfl readh',nlay,ncol,nrow
     try : f1 = open(self.pFullPath+'.head','rb')
     except IOError: return None
     hd=zeros((nlay,nrow,ncol))+0.;blok=44+nrow*ncol*4; # v210 60
     for il in range(nlay):
         #pos=iper*nlay*blok+blok*il+56;f1.seek(pos) v1_10
         pos=iper*nlay*blok+blok*il+44;f1.seek(pos) #vpmwin
         data = arr2('f');data.fromfile(f1,nrow*ncol);
         hd[il] = reshape(data,(nrow,ncol)) # 
     f1.close();
     if aqui.getDim() in ['Xsection','Radial']: hd = array(hd[::-1,:,:])
     else : hd = array(hd[:,::-1,:]);#print 'mflwri rdhed',shape(hd)            
     return hd
示例#26
0
 def getPart(self):
     f1 = open(self.fDir + os.sep + self.fName + '.flo', 'rb')
     l0 = 11
     f1.seek(l0)
     data = arr2('i')
     data.fromfile(f1, 14)
     mwel, mdrn, mrch, mevt, mriv, mghb, mchd, mss, nper, kp, kst, ncol, nrow, nlay = data
     blok = 5 * 4 + 16 + ncol * nrow * nlay * 4
     l2 = 5 * 4 + 16 + 4
     l0 += 36
     nwel = 0
     mss = 1
     # even in SS it seems to have sto?
     ichd, iwel, irch, idrn = sign(mchd), sign(mwel), sign(mrch), sign(mdrn)
     ievt, iriv, ighb = sign(mevt), sign(mriv), sign(mghb)
     icol, irow, ilay = sign(ncol - 1), sign(nrow - 1), sign(nlay - 1)
     part = blok + icol * blok + irow * blok + ilay * blok + mss * blok
     if nper > 1:
         f1.seek(l0 + part + l2 - 4)
         data = arr2('i')
         data.fromfile(f1, 1)
         nchd = data[0]
         part += l2 + nchd * 16
     if iwel > 0:
         f1.seek(l0 + part + l2 - 4)
         data = arr2('i')
         data.fromfile(f1, 1)
         nwel = data[0]
         part += l2 + nwel * 16
     if idrn > 0:
         f1.seek(l0 + part + l2 - 4)
         data = arr2('i')
         data.fromfile(f1, 1)
         ndrn = data[0]
         part += l2 + ndrn * 16
     if irch > 0: part += l2 - 4 + ncol * nrow * 4 * 2
     if ievt > 0: part += l2 - 4 + ncol * nrow * 4 * 2
     if iriv > 0:
         f1.seek(l0 + part + l2 - 4)
         data = arr2('i')
         data.fromfile(f1, 1)
         nriv = data[0]
         part += l2 + nriv * 16
     if ighb > 0:
         f1.seek(l0 + part + l2 - 4)
         data = arr2('i')
         data.fromfile(f1, 1)
         nghb = data[0]
         part += l2 + nghb * 16
     return ncol, nrow, nlay, blok, part
示例#27
0
 def lireUCN(
         self, aqui, opt, tstep,
         iesp):  # struct 32*4+6*4+icbund(nrow*ncol)+3*4+Cnc(nrow,ncol)+4?
     """lecture fichier ucn, typ : rt ou pht, donner le tstep, le num de l'espece et aqui"""
     grd = aqui.getFullGrid()
     x0, dcol, ncol = grd['x0'], grd['dx'], grd['nx']
     y0, drow, nrow = grd['y0'], grd['dy'], grd['ny']
     nlay = aqui.getNbCouches()
     if aqui.getDim() in ['Xsection', 'Radial']:
         nlay = nrow * 1
         nrow = 1
     if iesp < 9: suff = '00'
     else: suff = '0'
     tlist = aqui.getZoneTransient()['tlist']
     fname = self.pPath + os.sep + opt + suff + str(iesp + 1) + '.UCN'
     try:
         f1 = open(fname, 'rb')
     except IOError:
         return None
     m0 = zeros((nlay, nrow, ncol)) + 0.
     mult = 1
     if opt == 'MT3D':  # pb Mt3d sometimes write more time steps...
         lt = self.getMt3dTlist(f1, ncol, nrow, nlay)
         #print 'ireUcn',tstep,lt
         #print 'mtpht ucn',ncol,nrow,nlay,tstep,lt
         tstep = argmin(abs(tlist[tstep] - lt)) + 1
         #a=arange(len(lt));tstep=max(a[lt==tstep])
     elif opt == 'PHT3D':
         tstep = tstep + 1
     p0 = (44 + ncol * nrow * 4) * nlay * tstep
     #print 'mp3read',tstep,nlay
     for l in range(nlay):
         pos = p0 + (44 + ncol * nrow * 4) * l + 44
         f1.seek(pos)  # v212
         data = arr2('f')
         data.fromfile(f1, ncol * nrow)
         m0[l] = reshape(data, (nrow, ncol))
     f1.close()
     if aqui.getDim() in ['Xsection', 'Radial']: return m0[::-1, :, :]
     else: return m0[:, ::-1, :]
示例#28
0
 def readHeadFile(self, core, iper=0):
     """ read .head file 
     in free flow Thksat from flo file must be added (not done)"""
     nlay, ncol, nrow = self.getGeom(core)
     try:
         f1 = open(self.fDir + os.sep + self.fName + '.head', 'rb')
     except IOError:
         return None
     hd = zeros((nlay, nrow, ncol)) + 0.
     blok = 44 + nrow * ncol * 4
     # v210 60
     for il in range(nlay):
         f1.seek(iper * nlay * blok + blok * il + 44)  #vpmwin
         data = arr2('f')
         data.fromfile(f1, nrow * ncol)
         m = reshape(data, (nrow, ncol))  #
         hd[il] = m[::-1, :]  #=1::=1
     f1.close()
     #modify the head if free and in 3D
     #        if core.addin.getDim() in ['3D','Xsection','Radial']:
     #            if core.addin.getModelType()=='free':
     #                hd = self.getHeadFree(hd)
     return hd
示例#29
0
 def getPtObs(self,core,irow,icol,ilay,iper,opt,iesp=0,specname=''):
     """a function to values of one variable at given point or points.
     irow, icol and ilay must be lists of the same length. iper is also
     a list containing the periods for which data are needed."""
     grd  = core.addin.getFullGrid()
     ncol, nrow = grd['nx'], grd['ny']
     nlay=getNlayers(core);
     suff1 = opt*1
     if opt=='Mt3dms': suff1 = 'MT3D'
     if iesp<9: suff2='00'
     else : suff2='0'
     tlist=core.getTlist2()
     fname=self.fDir+os.sep+suff1+suff2+str(iesp+1)+'.UCN'
     try : f1 = open(fname,'rb')
     except IOError: return None
     if core.addin.getDim() in ['Xsection','Radial']:
         nlay=nrow*1;nrow=1;ilay=irow*1;irow=[0]*len(ilay)
     #print ilay,irow,icol
     npts=len(irow)
     pobs=zeros((len(iper),npts))+0.;
     lt=self.getMt3dTlist(f1,ncol,nrow,nlay)
     blok=44+ncol*nrow*4;
     #print 'mtpht obs',iper,lt
     for ip in range(len(iper)):
         if opt=='Mt3dms':
             ip2=argmin(abs(tlist[iper[ip]]-lt))#a=arange(len(lt));;ip2=max(a[lt==iper[ip]])
         elif opt=='Pht3d' :
             ip2=iper[ip]
         p0=blok*nlay*ip2;
         for i in range(npts):
             pos = p0+blok*ilay[i]+44+irow[i]*ncol*4+icol[i]*4
             f1.seek(pos)
             try:
                 data = arr2('f');data.fromfile(f1,1);
                 pobs[ip,i]=float(data[0])
             except EOFError: return pobs
     return pobs
示例#30
0
 def readFloFile(self, core, iper=0):
     """ read flo file and gives back Darcy velocities"""
     grd = core.addin.getFullGrid()
     dx, dy = grd['dx'], grd['dy']
     dxm, dym = meshgrid(dx, dy)
     thick = self.getThickness(core, iper)
     try:
         f1 = open(self.fDir + os.sep + self.fName + '.flo', 'rb')
     except IOError:
         return None
     ncol, nrow, nlay, blok, part = self.getPart()
     if core.addin.getDim() in ['Xsection', 'Radial']:
         dxm = array(dx)
         thick = reshape(dym, (nlay, 1, ncol))
         dym = 1.
     l0 = 11
     #36 if for 5 keywords size 4 plus header 16 char
     pos = l0 + 36 + iper * part + blok + 36
     f1.seek(pos)
     data = arr2('f')
     data.fromfile(f1, nlay * ncol * nrow)
     vx = reshape(data, (nlay, nrow, ncol))
     # trouver position des vitesses y
     pos = l0 + 36 + iper * part + blok * 2 + 36
     f1.seek(pos)
     data = arr2('f')
     data.fromfile(f1, nlay * ncol * nrow)
     vy = reshape(data, (nlay, nrow, ncol))
     bal = 0.0
     # trouver position des vitesses z (nexiste que si plus d'un layer)
     bal = 0.
     if nlay > 1:  # add vz
         nb = 2
         if nrow > 1: nb = 3  #presence of y velo
         pos = l0 + 36 + iper * part + blok * nb + 36
         f1.seek(pos)
         data = arr2('f')
         data.fromfile(f1, nlay * ncol * nrow)
         m0 = reshape(data, (nlay, nrow, ncol))
         vz = m0 * 0.
         for l in range(nlay):
             vz[l] = m0[l] / dxm / dym
         vz = concatenate([vz[:1, :, :], vz], axis=0)
     f1.close()
     # rows are ordered from top to bottom in modflow so invert them here
     if core.addin.getDim() in ['Xsection', 'Radial']:
         vx = vx[::-1, :, :] * 1
         #vz=vz[::-1,:,:]*1
     vx = vx[:, ::-1, :] / dym / thick
     vy = -vy[:, ::-1, :] / dxm / thick
     #retourner les vecteurs
     # as vx start from right of 1st cell we need to add one in the first col
     vx = concatenate([vx[:, :, :1], vx], axis=2)
     vx[:, :, -1] = vx[:, :, -2]
     # ssame for vy start at lower face, which is the last one now (inversion)
     vy = concatenate([vy, vy[:, -1:, :]], axis=1)
     # seems that vy is surrounded by 0
     vy[:, :, 0] = vy[:, :, 1]
     vy[:, :, -1] = vy[:, :, -2]
     vy[:, 0, :] = vy[:, 1, :]
     #print 'mfred l 436',shape(vx),shape(vy)
     if nlay > 1: return vx, vy, -vz
     else: return vx, vy, None
示例#31
0
 def ReadFloFile(self, aqui, iper=0):
     """ read flo file and gives back Darcy velocities"""
     grd = aqui.getFullGrid()
     dx, dy = grd['dx'], grd['dy']
     dxm, dym = meshgrid(dx, dy)
     ep = aqui.getEpais()
     if aqui.getDim() in ['Xsection', 'Radial']:
         dxm = array(dx)
         dym = 1.
     try:
         f1 = open(self.pFullPath + '.flo', 'rb')
     except IOError:
         return None
     # point de depart dans le fichier
     # variables Sat,Qx(ncol>1),Qy(nrow>1),Qz(nlay>1),Stor(trans),
     ncol, nrow, nlay, blok, part = self.getPart(f1)
     l0 = 11
     pos = l0 + 36 + iper * part + blok + 5 * 4 + 16
     f1.seek(pos)
     data = arr2('f')
     data.fromfile(f1, nlay * ncol * nrow)
     vx = reshape(data, (nlay, nrow, ncol))
     # trouver position des vitesses y
     pos = l0 + 36 + iper * part + blok * 2 + 5 * 4 + 16
     f1.seek(pos)
     data = arr2('f')
     data.fromfile(f1, nlay * ncol * nrow)
     vy = reshape(data, (nlay, nrow, ncol))
     bal = 0.0
     ##        if nlay==1: # balance de flux
     ##            vx=vx[0][::-1,:];vy=-vy[0][::-1,:];vx[vx==0.]=1.;vy[vy==0.]=1.;
     ##            vm=abs(vx)+abs(vy);vmax=amax(amax(vm))
     ##            bal=abs(vx[2:-2,1:-2]-vx[2:-2,2:-1]+vy[2:-2,2:-1]-vy[3:-1,2:-1])# on prend pas les bords
     ##            bal[vm[2:-2,1:-2]<vmax*1e-3]=0.
     ##            #bal[pot[2:-2,1:-2]!=0.]=0.;
     ##            md=median(median(bal));b2=clip(bal,md*1e-3,md*1e3)
     ##            bal=sum(sum(b2/(abs(vx[2:-2,1:-2])+abs(vy[2:-2,2:-1]))))*100
     # trouver position des vitesses z (nexiste que si plus d'un layer)
     bal = 0.
     if nlay > 1:  # rajouter vz
         nb = 2  #number of blocks to read z velocities (absence of y velo)
         if nrow > 1: nb = 3  #presence of y velo
         pos = l0 + 36 + iper * part + blok * nb + 5 * 4 + 16
         f1.seek(pos)
         data = arr2('f')
         data.fromfile(f1, nlay * ncol * nrow)
         m0 = reshape(data, (nlay, nrow, ncol))
         vz = m0 * 0.
         for l in range(nlay):
             vz[l] = m0[l] / dxm / dym
         vz = concatenate([vz[:1, :, :], vz], axis=0)
     # fermer le fichier
     f1.close()
     # rows are ordered from top to bottom in modflow so invert them here
     vx = vx[:, ::-1, :] / dym / ep
     vy = -vy[:, ::-1, :] / dxm / ep
     #retourner les vecteurs
     # as vx start from right of 1st cell we need to add one in the first col
     vx = concatenate([vx[:, :, :1], vx], axis=2)
     vx[:, :, -1] = vx[:, :, -2]
     # ssame for vy start at lower face, which is the last one now (inversion)
     vy = concatenate([vy, vy[:, -1:, :]], axis=1)
     # seems that vy is surrounded by 0
     vy[:, :, 0] = vy[:, :, 1]
     vy[:, :, -1] = vy[:, :, -2]
     vy[:, 0, :] = vy[:, 1, :]
     if aqui.getDim() in ['Xsection', 'Radial']:
         vx = vx[::-1, :, :] * 1
         vz = vz[::-1, :, :] * 1
     if nlay > 1: return [vx, vy, -vz]  #,bal -vz[:,::-1,:]
     else: return [vx, vy]