Beispiel #1
0
 def WriteModflowFile(self, aqui, ecoul, model):
     self.interpreter = MfInterpreter(model)
     nbfor = aqui.getNbzone('Forages')
     nbrech = aqui.getNbzone('Recharge')
     rech = abs(sign(aqui.getVbase('Recharge')))
     aqui.createZoneTransient()
     self.zoneTransient = aqui.getZoneTransient()
     self.tlist = self.zoneTransient['tlist']
     self.radfact = 1.
     if self.zoneTransient['Transient'].has_key('Potentiel'):
         self.zpTrans = self.zoneTransient['Transient']['Potentiel']
     else:
         self.zpTrans = False
     self.WriteNamFile(ecoul, nbfor, max(nbrech, rech))
     for n in ['dis', 'ba6', 'lpf']:
         self.writeFile(n)
         print n + ' printed'
     #self.WriteLpfFile(aqui, ecoul)
     if nbfor > 0:
         self.writeFile('wel')
         print 'wel printed'
     if nbrech > 0 or rech > 0:
         self.writeFile('rch')
         print 'rch printed'
     solv = ecoul.getParm('SolvName')
     self.writeFile(solv)
     self.WriteLmtFile()
     self.WriteOcFile(aqui, ecoul)
     #print 'mfwri wri',self.zpTrans
     if self.zpTrans == True:
         self.WriteChdFile(aqui)
Beispiel #2
0
 def WriteModflowFile(self, aqui, ecoul, model):
     self.interpreter=MfInterpreter(model)
     nbfor = aqui.getNbzone('Forages')
     nbrech = aqui.getNbzone('Recharge')
     rech = abs(sign(aqui.getVbase('Recharge')))
     aqui.createZoneTransient()
     self.zoneTransient=aqui.getZoneTransient()
     self.tlist=self.zoneTransient['tlist'];
     self.radfact=1.
     if self.zoneTransient['Transient'].has_key('Potentiel'):
         self.zpTrans= self.zoneTransient['Transient']['Potentiel']
     else : self.zpTrans=False
     self.WriteNamFile(ecoul,nbfor,max(nbrech,rech))
     for n in ['dis','ba6','lpf']:
         self.writeFile(n);print n+' printed'
     #self.WriteLpfFile(aqui, ecoul)
     if nbfor>0: self.writeFile('wel');print 'wel printed'
     if nbrech>0 or rech>0: self.writeFile('rch');print 'rch printed'
     solv = ecoul.getParm('SolvName')
     self.writeFile(solv)
     self.WriteLmtFile()
     self.WriteOcFile(aqui,ecoul);#print 'mfwri wri',self.zpTrans
     if self.zpTrans==True:
         self.WriteChdFile(aqui)
Beispiel #3
0
class ModflowWriter:
    
    def __init__(self, path, name):
        self.pPath = path
        self.pName = name
        self.fullPath = path+os.sep+name

    def CreateFile(self, extension, mode):
        filename = self.fullPath + extension
        file_descriptor = open(filename, mode)
        return file_descriptor

    def WriteModflowFile(self, aqui, ecoul, model):
        self.interpreter=MfInterpreter(model)
        nbfor = aqui.getNbzone('Forages')
        nbrech = aqui.getNbzone('Recharge')
        rech = abs(sign(aqui.getVbase('Recharge')))
        aqui.createZoneTransient()
        self.zoneTransient=aqui.getZoneTransient()
        self.tlist=self.zoneTransient['tlist'];
        self.radfact=1.
        if self.zoneTransient['Transient'].has_key('Potentiel'):
            self.zpTrans= self.zoneTransient['Transient']['Potentiel']
        else : self.zpTrans=False
        self.WriteNamFile(ecoul,nbfor,max(nbrech,rech))
        for n in ['dis','ba6','lpf']:
            self.writeFile(n);print n+' printed'
        #self.WriteLpfFile(aqui, ecoul)
        if nbfor>0: self.writeFile('wel');print 'wel printed'
        if nbrech>0 or rech>0: self.writeFile('rch');print 'rch printed'
        solv = ecoul.getParm('SolvName')
        self.writeFile(solv)
        self.WriteLmtFile()
        self.WriteOcFile(aqui,ecoul);#print 'mfwri wri',self.zpTrans
        if self.zpTrans==True:
            self.WriteChdFile(aqui)
        
    """ for the y dimension ipht3d matrices are the inverse of modflow ones
    for vectors, it is taken into account any time a y vector is written
    for matrices it is in the writeblock function"""
    #************************* fichier NAM ****************
    def WriteNamFile(self, ecoul, nbfor, recharge):
        f1 = self.CreateFile('.nam', 'w')
        solv = ecoul.getParm('SolvName')
        f1.write('LIST      6        ' + self.pName + '.lst\n')
        f1.write('DIS      10        ' + self.pName + '.dis\n')
        f1.write('LMT6      66       ' + self.pName + '.lmt\n')
        f1.write('BAS6      5        ' + self.pName + '.ba6\n')      
        #f1.write('BCF6      11       ' + self.pName + '.bc6\n') 
        f1.write('LPF      11       ' + self.pName + '.lpf\n') 
        f1.write(solv+'      19     '  + self.pName +'.'+solv+'\n')      
        f1.write('OC       22        ' + self.pName + '.oc\n')      
        f1.write('DATA(BINARY)     30        ' + self.pName + '.head\n')
        f1.write('DATA(BINARY)     31        ' + self.pName + '.budget\n')

        if nbfor>0: f1.write('WEL     20     ' + self.pName + '.wel\n')
        if recharge>0: f1.write('RCH     15     ' + self.pName + '.rch\n')
        if self.zpTrans:
            f1.write('CHD     35     ' + self.pName + '.chd\n')
        f1.close()

    #*********************** generic file writer ****************
    def writeFile(self,name):
        """to write any modflow file.
        reads the keyword file and prints all keywords by types : param (0D)
        vector (1D) array (2D). types are found by (dim1,dim2).."""
        f1=open(self.fullPath +'.'+ name,'w');alist=[]
        n1=Fkey.groups.keys();#print n1,name
        for n in n1:
            if n.split('.')[1]==name: llist=Fkey.groups[n]
        for ll in llist:
            cond=Fkey.lines[ll]['cond'];#print 'mflw 1',cond,self.testCondition(cond)
            if self.testCondition(cond)==False :continue
            kwlist=Fkey.lines[ll]['kw'];kw0=kwlist[0].split('(')[0]
            ktyp=Fkey.lines[ll]['type'];#print 'mfw',ktyp
            if ktyp in ['arr','vec']: arr=self.interpreter.getArray(kw0)
            if ktyp=='vec': # a vector
                self.writeVecModflow(arr,f1)
                exec('self.'+kw0+'='+str(arr[0]))
                
            elif ktyp=='string': # a string to print 
                s=self.interpreter.getParm(kw0);f1.write(s)
                exec('self.'+kw0+'='+s[:2])
                
            elif ktyp=='arr': # one array
                self.writeBlockModflow(arr,f1)
                
            elif ktyp=='parr': # one variable, p arrays: one for each period
                nper=self.interpreter.getNper()
                for ip in range(nper):
                    head,arr=self.interpreter.getArrayPeriod(kw0,ip)
                    f1.write(head);self.writeBlockModflow(arr,f1)
                    
            elif ktyp=='larr': #several variable written for each layer
                for k in kwlist:
                    a=k.split('(');
                    alist.append(self.interpreter.getArray(a[0]))
                    
            elif ktyp=='nvec': # list of periods or others
                vlist=[]
                for k in kwlist:
                    a=k.split('(')
                    vlist.append(self.interpreter.getArray(a[0]))
                nlines=len(vlist[0]);s=''
                for j in range(nlines):
                    for ik in range(len(kwlist)):
                        val=str(vlist[ik][j]);s+=val[:9].ljust(9)+' '
                    s+='\n'
                f1.write(s)
            elif ktyp=='npoints': # points on the grid
                nptot,plist=self.interpreter.getParm(kw0)
                f1.write(str(nptot)+'\n');
                ir,ic,il,izone,kscal,val=plist;np,nz=shape(val)
                for ip in range(np):
                    s=str(len(il))+'\n'
                    for i in range(len(il)):
                        s+=str(il[i]+1).ljust(10)+str(ir[i]+1).ljust(10)+str(ic[i]+1).ljust(10)
                        v=val[ip,izone[i]]*kscal[i]
                        s+='%9.3e \n'%v #str(v).ljust(10)+'\n'
                    f1.write(s)
            else : # classical parameters
                for k in kwlist:
                    val=str(self.interpreter.getParm(k));
                    try : int(val);exec('self.'+k+'='+val)
                    except ValueError: a=None
                    f1.write(val[:9].ljust(10)) #' %9.3e'%float(val)
                f1.write('\n')
        if len(alist)>0: # write the arrays by layer saved in a list previously
            nlay=self.interpreter.getNlay()
            for il in range(nlay):
                for ik in range(len(alist)):
                    #print il,ik,alist[ik][il]
                    self.writeMatModflow(alist[ik][il],f1)
        f1.close()
        
    #**************** test condition **********************
    def testCondition(self,cond):
        """ test if the condition is satisfied"""
        a=True
        if cond!='':
##            if len(cond.split('+'))>1:
##                cond=cond.replace('+','+self.');
            if len(cond.split('and'))>1:
                c1=cond.split('and'); c2='(self.'+c1[0].strip()+')'
                for i in range(1,len(c1)): c2+=' and (self.'+c1[i].strip()+')'
            elif len(cond.split('or'))>1:
                c1=cond.split('or'); c2='(self.'+c1[0]+')'
                for i in range(1,len(c1)): c2+=' or (self.'+c1[i].strip()+')'
            else : c2='self.'+cond
            exec('a='+c2);#print 'cond',c2,a;
        if a or cond=='': return True
        return False  
        
    #************************ file for transient head (CHD)*************************************
    def WriteChdFile(self,aqui):
        f1 = self.CreateFile('.chd', 'w') 
        grd = aqui.getFullGrid();
        x0,x1,dx,nx = grd['x0'],grd['x1'],grd['dx'],grd['nx']
        y0,y1,dy,ny = grd['y0'],grd['y1'],grd['dy'],grd['ny']
        xvect=concatenate([array(x0,ndmin=1),x0+cumsum(dx)],axis=0)
        yvect=concatenate([array(y0,ndmin=1),y0+cumsum(dy)],axis=0)
        # for each stress period
        # line 0 is text
        f1.write('#Text \n')
        # line 1 optional for parameters
        # line 2 mxact max numb of active cells (here simply ncol*nrow
        f1.write('%9i \n' %(nx*ny))
        # line 3 and 4 optional for parameters
        # line 5 itmp: nb fixed cells, NP: nb parameteres
        # line 6 layer row column Shead (start) Ehead (end)
        # first loop round iper
        # take care if ou put twice a cell in chd it adds values!!!
        nper=len(self.tlist)
        zlist=self.zoneTransient['Potentiel'];np,nz=shape(zlist)
        for ip in range(nper):
            buff='';npts=0
            # then loop round zones to get the index and write the head
            for iz in range(nz):
                zone=aqui.getZone('Potentiel',iz);
                xy=zone.getXy();x,y=zip(*xy);z=x*1
                icol,irow,ilay=zone2index(x,y,z,xvect,yvect,nx,ny)
                hd=zlist[ip,iz];npts+=len(irow)
                if aqui.getDim() in ['Xsection','Radial']:
                    ir2=[1]*len(irow);ilay=irow
                else : ir2=[ny-x for x in irow]
                if aqui.getDim()=='2D':
                    ilay=ilay.astype(int)*0
                for i in range(len(irow)):
                    buff+=str(ilay[i]+1).rjust(9)+' '+str(ir2[i]).rjust(9)+' '+\
                           str(icol[i]+1).rjust(9)+' %+9.2e %+9.2e'%(hd,hd)+'\n'
            f1.write(' %6i     0    \n' %npts)
            f1.write(buff)
        

    #*************************** fichier Solver ***********************
    def WriteSolveFile(self, ecoul):
        
        nom_solv = ecoul.getParm('SolvName')
        f1 = self.CreateFile('.'+nom_solv, 'w')
        s = ecoul.getParm('Solver')
        for i in range(len(s)): exec(s[i][0]+'=s['+str(i)+'][1]')
        if nom_solv == 'sip':
            f1.write('%9i %9i  \n' %(mxiter,nparm))
            f1.write('%9.3f %9.2e %9i %9.3f %9i \n' %(accel,hclose,ipcalc,seed,iprsip))
        elif nom_solv == 'sor':
            f1.write('%9i  \n' %mxiter)
            f1.write('%9.3f %9.2e %9i \n' %(accl,Hclose,iprsor))            
        elif nom_solv == 'pcg':           
            f1.write('%9i %9i %9i \n' %(mxiter,iter1,npcond))
            f1.write('%9.3e %9.2e %9.3f %9i %9i %9i %9i \n' %(hclose,rclose,relax,nbpol,iprpcg,mutpcg,damp))            
        elif nom_solv == 'de4':
            f1.write('%9i %9i %9i %9i \n' %(itmx,mxup,mxlow,mxbw))
            f1.write('%9i %9i %9.3f %9.3e %9i \n' %(ifreq,mutd4,accl,hclose,iprd4))
        f1.close()
        
    #*************************** fichier LMT ***********************
    def WriteLmtFile(self):
        
        f1 = self.CreateFile('.lmt', 'w')        
        f1.write('OUTPUT_FILE_NAME    '+self.pName+'.flo \n')
        f1.write('OUTPUT_FILE_UNIT    333 \n')
        f1.write('OUTPUT_FILE_HEADER  standard \n')
        f1.write('OUTPUT_FILE_FORMAT  unformatted \n')
        f1.close()
        
    #*************************** fichier OC ***********************
    def WriteOcFile(self, aqui, ecoul):

        grd = aqui.getFullGrid()
        ncol = int(grd['nx'])
        f1 = self.CreateFile('.oc', 'w')       
        #f1.write('HEAD SAVE FORMAT ('+str(ncol)+'F13.5) \n')
        f1.write('HEAD SAVE UNIT 30 \n')
        t0=ecoul.getParm('Temps');tf=t0[0][1];dur=t0[1][1]
        nstp = t0[2][1];tr='SS';#print nstp;
        if len(self.tlist)>1:
            for p in range(len(self.tlist)):
                #for step in range(nstp):
                f1.write('Period %5i Step %5i \n' %(p+1,nstp))
                f1.write('Save Head \n')
        else : f1.write('Period 1 Step 1 \nSave Head\nSave Budget \n')
        f1.close()
    #------------------------- fonction  writevect, writemat -------------------
    def writeVecModflow(self, v, f1):
        l=len(v);a=str(type(v[0]))
        if a[13:16]=='int': typ='I'
        else : typ='G'
        if amin(v)==amax(v):
            f1.write('CONSTANT     %9.5e \n' %amin(v))
            return
        if typ=='I': fmt='1    ('+str(l)+'I'+str(ln)
        else : fmt='0    ('+str(l)+'G12.4'           
        f1.write('INTERNAL     '+fmt+')     3' )
        
        if typ=='I': fmt='%'+str(ln)+'i'
        else : fmt='%+11.4e '            
        f1.write('\n')
        for i in range(l):
            f1.write(fmt %v[i])
        f1.write('\n')

    def writeMatModflow(self, m, f1):
        if len(shape(m))==1: return self.writeVecModflow(m,f1)
        [l,c] = shape(m);ln=3;a=str(type(m[0,0]))
        if a[13:16]=='int': typ='I'
        else : typ='G'
        if amin(amin(m))==amax(amax(m)):
            if typ=='I': f1.write('CONSTANT     %9i \n' %(amin(amin(m))))
            else : f1.write('CONSTANT     %9.5e \n' %(amin(amin(m))))
            return
        if typ=='I':
            fmt='1    ('+str(c)+'I'+str(ln)
        else :
            fmt='0    ('+str(c)+'G12.4' #+str(ln)            
        f1.write('INTERNAL     '+fmt+')     3' )      
        if typ=='I':
            fmt='%'+str(ln)+'i'
        else :
            fmt='%+11.4e ' #'+str(ln)+'e '            
        f1.write('\n')
        for i in range(l-1,-1,-1): # to write the rows from top to bottom
            for j in range(c):
                f1.write(fmt %m[i][j])
            f1.write('\n')

    def writeBlockModflow(self,m,f1):
        if len(shape(m))==3:
            nlay,a,b=shape(m);
            for l in range(nlay):
                self.writeMatModflow(m[l],f1)
        else : self.writeMatModflow(m,f1)
Beispiel #4
0
class ModflowWriter:
    def __init__(self, path, name):
        self.pPath = path
        self.pName = name
        self.fullPath = path + os.sep + name

    def CreateFile(self, extension, mode):
        filename = self.fullPath + extension
        file_descriptor = open(filename, mode)
        return file_descriptor

    def WriteModflowFile(self, aqui, ecoul, model):
        self.interpreter = MfInterpreter(model)
        nbfor = aqui.getNbzone('Forages')
        nbrech = aqui.getNbzone('Recharge')
        rech = abs(sign(aqui.getVbase('Recharge')))
        aqui.createZoneTransient()
        self.zoneTransient = aqui.getZoneTransient()
        self.tlist = self.zoneTransient['tlist']
        self.radfact = 1.
        if self.zoneTransient['Transient'].has_key('Potentiel'):
            self.zpTrans = self.zoneTransient['Transient']['Potentiel']
        else:
            self.zpTrans = False
        self.WriteNamFile(ecoul, nbfor, max(nbrech, rech))
        for n in ['dis', 'ba6', 'lpf']:
            self.writeFile(n)
            print n + ' printed'
        #self.WriteLpfFile(aqui, ecoul)
        if nbfor > 0:
            self.writeFile('wel')
            print 'wel printed'
        if nbrech > 0 or rech > 0:
            self.writeFile('rch')
            print 'rch printed'
        solv = ecoul.getParm('SolvName')
        self.writeFile(solv)
        self.WriteLmtFile()
        self.WriteOcFile(aqui, ecoul)
        #print 'mfwri wri',self.zpTrans
        if self.zpTrans == True:
            self.WriteChdFile(aqui)

    """ for the y dimension ipht3d matrices are the inverse of modflow ones
    for vectors, it is taken into account any time a y vector is written
    for matrices it is in the writeblock function"""

    #************************* fichier NAM ****************
    def WriteNamFile(self, ecoul, nbfor, recharge):
        f1 = self.CreateFile('.nam', 'w')
        solv = ecoul.getParm('SolvName')
        f1.write('LIST      6        ' + self.pName + '.lst\n')
        f1.write('DIS      10        ' + self.pName + '.dis\n')
        f1.write('LMT6      66       ' + self.pName + '.lmt\n')
        f1.write('BAS6      5        ' + self.pName + '.ba6\n')
        #f1.write('BCF6      11       ' + self.pName + '.bc6\n')
        f1.write('LPF      11       ' + self.pName + '.lpf\n')
        f1.write(solv + '      19     ' + self.pName + '.' + solv + '\n')
        f1.write('OC       22        ' + self.pName + '.oc\n')
        f1.write('DATA(BINARY)     30        ' + self.pName + '.head\n')
        f1.write('DATA(BINARY)     31        ' + self.pName + '.budget\n')

        if nbfor > 0: f1.write('WEL     20     ' + self.pName + '.wel\n')
        if recharge > 0: f1.write('RCH     15     ' + self.pName + '.rch\n')
        if self.zpTrans:
            f1.write('CHD     35     ' + self.pName + '.chd\n')
        f1.close()

    #*********************** generic file writer ****************
    def writeFile(self, name):
        """to write any modflow file.
        reads the keyword file and prints all keywords by types : param (0D)
        vector (1D) array (2D). types are found by (dim1,dim2).."""
        f1 = open(self.fullPath + '.' + name, 'w')
        alist = []
        n1 = Fkey.groups.keys()
        #print n1,name
        for n in n1:
            if n.split('.')[1] == name: llist = Fkey.groups[n]
        for ll in llist:
            cond = Fkey.lines[ll]['cond']
            #print 'mflw 1',cond,self.testCondition(cond)
            if self.testCondition(cond) == False: continue
            kwlist = Fkey.lines[ll]['kw']
            kw0 = kwlist[0].split('(')[0]
            ktyp = Fkey.lines[ll]['type']
            #print 'mfw',ktyp
            if ktyp in ['arr', 'vec']: arr = self.interpreter.getArray(kw0)
            if ktyp == 'vec':  # a vector
                self.writeVecModflow(arr, f1)
                exec('self.' + kw0 + '=' + str(arr[0]))

            elif ktyp == 'string':  # a string to print
                s = self.interpreter.getParm(kw0)
                f1.write(s)
                exec('self.' + kw0 + '=' + s[:2])

            elif ktyp == 'arr':  # one array
                self.writeBlockModflow(arr, f1)

            elif ktyp == 'parr':  # one variable, p arrays: one for each period
                nper = self.interpreter.getNper()
                for ip in range(nper):
                    head, arr = self.interpreter.getArrayPeriod(kw0, ip)
                    f1.write(head)
                    self.writeBlockModflow(arr, f1)

            elif ktyp == 'larr':  #several variable written for each layer
                for k in kwlist:
                    a = k.split('(')
                    alist.append(self.interpreter.getArray(a[0]))

            elif ktyp == 'nvec':  # list of periods or others
                vlist = []
                for k in kwlist:
                    a = k.split('(')
                    vlist.append(self.interpreter.getArray(a[0]))
                nlines = len(vlist[0])
                s = ''
                for j in range(nlines):
                    for ik in range(len(kwlist)):
                        val = str(vlist[ik][j])
                        s += val[:9].ljust(9) + ' '
                    s += '\n'
                f1.write(s)
            elif ktyp == 'npoints':  # points on the grid
                nptot, plist = self.interpreter.getParm(kw0)
                f1.write(str(nptot) + '\n')
                ir, ic, il, izone, kscal, val = plist
                np, nz = shape(val)
                for ip in range(np):
                    s = str(len(il)) + '\n'
                    for i in range(len(il)):
                        s += str(il[i] + 1).ljust(10) + str(ir[i] + 1).ljust(
                            10) + str(ic[i] + 1).ljust(10)
                        v = val[ip, izone[i]] * kscal[i]
                        s += '%9.3e \n' % v  #str(v).ljust(10)+'\n'
                    f1.write(s)
            else:  # classical parameters
                for k in kwlist:
                    val = str(self.interpreter.getParm(k))
                    try:
                        int(val)
                        exec('self.' + k + '=' + val)
                    except ValueError:
                        a = None
                    f1.write(val[:9].ljust(10))  #' %9.3e'%float(val)
                f1.write('\n')
        if len(alist
               ) > 0:  # write the arrays by layer saved in a list previously
            nlay = self.interpreter.getNlay()
            for il in range(nlay):
                for ik in range(len(alist)):
                    #print il,ik,alist[ik][il]
                    self.writeMatModflow(alist[ik][il], f1)
        f1.close()

    #**************** test condition **********************
    def testCondition(self, cond):
        """ test if the condition is satisfied"""
        a = True
        if cond != '':
            ##            if len(cond.split('+'))>1:
            ##                cond=cond.replace('+','+self.');
            if len(cond.split('and')) > 1:
                c1 = cond.split('and')
                c2 = '(self.' + c1[0].strip() + ')'
                for i in range(1, len(c1)):
                    c2 += ' and (self.' + c1[i].strip() + ')'
            elif len(cond.split('or')) > 1:
                c1 = cond.split('or')
                c2 = '(self.' + c1[0] + ')'
                for i in range(1, len(c1)):
                    c2 += ' or (self.' + c1[i].strip() + ')'
            else:
                c2 = 'self.' + cond
            exec('a=' + c2)
            #print 'cond',c2,a;
        if a or cond == '': return True
        return False

    #************************ file for transient head (CHD)*************************************
    def WriteChdFile(self, aqui):
        f1 = self.CreateFile('.chd', 'w')
        grd = aqui.getFullGrid()
        x0, x1, dx, nx = grd['x0'], grd['x1'], grd['dx'], grd['nx']
        y0, y1, dy, ny = grd['y0'], grd['y1'], grd['dy'], grd['ny']
        xvect = concatenate([array(x0, ndmin=1), x0 + cumsum(dx)], axis=0)
        yvect = concatenate([array(y0, ndmin=1), y0 + cumsum(dy)], axis=0)
        # for each stress period
        # line 0 is text
        f1.write('#Text \n')
        # line 1 optional for parameters
        # line 2 mxact max numb of active cells (here simply ncol*nrow
        f1.write('%9i \n' % (nx * ny))
        # line 3 and 4 optional for parameters
        # line 5 itmp: nb fixed cells, NP: nb parameteres
        # line 6 layer row column Shead (start) Ehead (end)
        # first loop round iper
        # take care if ou put twice a cell in chd it adds values!!!
        nper = len(self.tlist)
        zlist = self.zoneTransient['Potentiel']
        np, nz = shape(zlist)
        for ip in range(nper):
            buff = ''
            npts = 0
            # then loop round zones to get the index and write the head
            for iz in range(nz):
                zone = aqui.getZone('Potentiel', iz)
                xy = zone.getXy()
                x, y = zip(*xy)
                z = x * 1
                icol, irow, ilay = zone2index(x, y, z, xvect, yvect, nx, ny)
                hd = zlist[ip, iz]
                npts += len(irow)
                if aqui.getDim() in ['Xsection', 'Radial']:
                    ir2 = [1] * len(irow)
                    ilay = irow
                else:
                    ir2 = [ny - x for x in irow]
                if aqui.getDim() == '2D':
                    ilay = ilay.astype(int) * 0
                for i in range(len(irow)):
                    buff+=str(ilay[i]+1).rjust(9)+' '+str(ir2[i]).rjust(9)+' '+\
                           str(icol[i]+1).rjust(9)+' %+9.2e %+9.2e'%(hd,hd)+'\n'
            f1.write(' %6i     0    \n' % npts)
            f1.write(buff)

    #*************************** fichier Solver ***********************
    def WriteSolveFile(self, ecoul):

        nom_solv = ecoul.getParm('SolvName')
        f1 = self.CreateFile('.' + nom_solv, 'w')
        s = ecoul.getParm('Solver')
        for i in range(len(s)):
            exec(s[i][0] + '=s[' + str(i) + '][1]')
        if nom_solv == 'sip':
            f1.write('%9i %9i  \n' % (mxiter, nparm))
            f1.write('%9.3f %9.2e %9i %9.3f %9i \n' %
                     (accel, hclose, ipcalc, seed, iprsip))
        elif nom_solv == 'sor':
            f1.write('%9i  \n' % mxiter)
            f1.write('%9.3f %9.2e %9i \n' % (accl, Hclose, iprsor))
        elif nom_solv == 'pcg':
            f1.write('%9i %9i %9i \n' % (mxiter, iter1, npcond))
            f1.write('%9.3e %9.2e %9.3f %9i %9i %9i %9i \n' %
                     (hclose, rclose, relax, nbpol, iprpcg, mutpcg, damp))
        elif nom_solv == 'de4':
            f1.write('%9i %9i %9i %9i \n' % (itmx, mxup, mxlow, mxbw))
            f1.write('%9i %9i %9.3f %9.3e %9i \n' %
                     (ifreq, mutd4, accl, hclose, iprd4))
        f1.close()

    #*************************** fichier LMT ***********************
    def WriteLmtFile(self):

        f1 = self.CreateFile('.lmt', 'w')
        f1.write('OUTPUT_FILE_NAME    ' + self.pName + '.flo \n')
        f1.write('OUTPUT_FILE_UNIT    333 \n')
        f1.write('OUTPUT_FILE_HEADER  standard \n')
        f1.write('OUTPUT_FILE_FORMAT  unformatted \n')
        f1.close()

    #*************************** fichier OC ***********************
    def WriteOcFile(self, aqui, ecoul):

        grd = aqui.getFullGrid()
        ncol = int(grd['nx'])
        f1 = self.CreateFile('.oc', 'w')
        #f1.write('HEAD SAVE FORMAT ('+str(ncol)+'F13.5) \n')
        f1.write('HEAD SAVE UNIT 30 \n')
        t0 = ecoul.getParm('Temps')
        tf = t0[0][1]
        dur = t0[1][1]
        nstp = t0[2][1]
        tr = 'SS'
        #print nstp;
        if len(self.tlist) > 1:
            for p in range(len(self.tlist)):
                #for step in range(nstp):
                f1.write('Period %5i Step %5i \n' % (p + 1, nstp))
                f1.write('Save Head \n')
        else:
            f1.write('Period 1 Step 1 \nSave Head\nSave Budget \n')
        f1.close()

    #------------------------- fonction  writevect, writemat -------------------
    def writeVecModflow(self, v, f1):
        l = len(v)
        a = str(type(v[0]))
        if a[13:16] == 'int': typ = 'I'
        else: typ = 'G'
        if amin(v) == amax(v):
            f1.write('CONSTANT     %9.5e \n' % amin(v))
            return
        if typ == 'I': fmt = '1    (' + str(l) + 'I' + str(ln)
        else: fmt = '0    (' + str(l) + 'G12.4'
        f1.write('INTERNAL     ' + fmt + ')     3')

        if typ == 'I': fmt = '%' + str(ln) + 'i'
        else: fmt = '%+11.4e '
        f1.write('\n')
        for i in range(l):
            f1.write(fmt % v[i])
        f1.write('\n')

    def writeMatModflow(self, m, f1):
        if len(shape(m)) == 1: return self.writeVecModflow(m, f1)
        [l, c] = shape(m)
        ln = 3
        a = str(type(m[0, 0]))
        if a[13:16] == 'int': typ = 'I'
        else: typ = 'G'
        if amin(amin(m)) == amax(amax(m)):
            if typ == 'I': f1.write('CONSTANT     %9i \n' % (amin(amin(m))))
            else: f1.write('CONSTANT     %9.5e \n' % (amin(amin(m))))
            return
        if typ == 'I':
            fmt = '1    (' + str(c) + 'I' + str(ln)
        else:
            fmt = '0    (' + str(c) + 'G12.4'  #+str(ln)
        f1.write('INTERNAL     ' + fmt + ')     3')
        if typ == 'I':
            fmt = '%' + str(ln) + 'i'
        else:
            fmt = '%+11.4e '  #'+str(ln)+'e '
        f1.write('\n')
        for i in range(l - 1, -1, -1):  # to write the rows from top to bottom
            for j in range(c):
                f1.write(fmt % m[i][j])
            f1.write('\n')

    def writeBlockModflow(self, m, f1):
        if len(shape(m)) == 3:
            nlay, a, b = shape(m)
            for l in range(nlay):
                self.writeMatModflow(m[l], f1)
        else:
            self.writeMatModflow(m, f1)