Example #1
0
def readExps(clsIO,clsEOS,dicSAM,dicEXP,clsUNI) :

    iERR  = 0
    iLine = 0

    fInp = clsIO.fInp
    
#-- Experiment Names & Mnemonics ------------------------------------

    sNam = {'CCE'  :'CCE','CVD' :'CVD','DLE'  :'DLE','SEP' :'SEP',
            'FLASH':'FLS','PSAT':'SAT','SWELL':'SWL','GRAD':'GRD'}

#== Inactivate existing experiments ===================================

    for iExp in range(len(dicEXP)) : dicEXP[iExp].IsAct = False

#== Main Read Loop ====================================================    

    for curL in fInp :

        iLine += 1

        if iLine > 100 :
            print("Too Many Lines of EXP Data - Error")
            iERR = -1
            break

        tokS = curL.split()
        nTok = len(tokS)

        if   nTok == 0                     : pass   #-- Blank line!
        elif tokS[0][:2]         == "--"   : pass   #-- Comment
        elif tokS[0][:3].upper() == "DEB"  : iERR = RG.readDebug(clsIO)
        elif tokS[0][:3].upper() == "OPT"  : iERR = RG.readOption(clsIO)

        elif tokS[0].upper() in sNam       :
            sHrt = sNam[tokS[0].upper()]
            iERR = readGen(sHrt,clsIO,clsEOS,dicSAM,dicEXP,clsUNI)
        elif tokS[0].upper()     == "PLOT" :
            if tokS[1].upper() == "NONE" :
                clsIO.Pall = False
        elif tokS[0][:4].upper() == "ENDE" :
            #print("ENDEXP k/w found")
            break

        if iERR < 0 : break

#======================================================================
#  Experiments Read OK => Run Them
#======================================================================

    if iERR == 0 : CX.calcExps("",clsEOS,dicSAM,dicEXP,clsUNI,clsIO)

    return iERR
Example #2
0
def readReg(clsIO, clsEOS, dicSAM, dicEXP, clsUNI):

    nExp = len(dicEXP)

    print("readReg: Starting Regression with ", nExp, " Experiments Defined")

    qExp = [False for i in range(nExp)]

    #-- Process existing Experiments into a handy array -----------------

    rExp = procExistExp(dicEXP)

    #-- Number of Iterations [clean-up later!] --------------------------

    mIter = None

    #-- Dictionary of Regression Variables Held Locally -----------------

    dicREG = {}

    #========================================================================
    #  Read lines until we get to ENDREG (or too many lines!)
    #========================================================================

    iERR = 0
    iLine = 0

    fInp = clsIO.fInp

    for curL in fInp:

        iLine += 1

        if iLine > 100:
            print("Too Many Lines of REG Data - Error")
            iERR = -1
            break

        tokS = curL.split()
        nTok = len(tokS)

        if nTok == 0:  #-- Blank line!
            pass
        elif tokS[0].upper() == "EXP":

            if nTok - 1 > nExp:
                print(
                    "User appears to have declared more Experiments in Regression than previous defined - Error"
                )
                iERR = -1
                break

            iTok = 1
            nTru = 0
            while iTok < nTok:
                sExp = tokS[iTok]
                #print("iTok,sExp ",iTok,sExp)
                for iExp in range(nExp):
                    if sExp == rExp[iExp]:
                        qExp[iExp] = True
                        nTru += 1
                iTok += 1

            if nTru < 1:
                print("No Existing Experiments Selected within REG - Error")
                iERR = -1
                break

        elif tokS[0][:2].upper() == "NI":  #-- User Over-Writes Num Iterations

            mIter = int(tokS[1])

        elif tokS[0].upper() == "VAR":

            iERR = readRegVars(clsIO, dicREG, dicSAM, clsEOS)
            if iERR < 0: break

        elif tokS[0][:3].upper() == "DEB":

            iERR = RG.readDebug(clsIO)
            if iERR < 0: break

        elif tokS[0][:3].upper() == "OPT":

            iERR = RG.readOption(clsIO)
            if iERR < 0: break

        elif tokS[0][:4].upper() == "ENDR":
            #print("ENDREG k/w found")
            break

        if iERR < 0: break

    #print("readReg: Of which ",nTru," Experiments have been selected")
    #print("qExp ",qExp)

#======================================================================
#  Everything OK!  Run the Regression
#======================================================================

    if mIter == None: mIter = 5

    if iERR == 0:

        nAct = 0
        for iExp in range(nExp):
            if qExp[iExp]: nAct += 1

        print("readReg: Of Which ", nAct, " Experiments Are Active")

        #clsEOS,dicSAM,dicEXP = \
        #    CR.runRegression(mIter,qExp,clsEOS,dicSAM,dicEXP,dicREG,clsUNI,clsIO)

        clsEOS,dicSAM,dicEXP = \
            CR.runRegression(mIter,qExp,clsEOS,dicSAM,dicEXP,dicREG,clsUNI,clsIO)

#== Return values =====================================================

    return iERR, clsEOS, dicSAM, dicEXP
Example #3
0
def PVTfree():

    iERR, clsIO = checkInputFile()

    if iERR < 0: return iERR

    clsIO.setDocStr(UT.aboutPVTfree.__doc__)  #-- DocString => clsIO

    #--------------------------------------------------------------------
    #  Dictionaries to Hold Classes of Samples and Experiments
    #  Dictionary of Regression Classes is held locally
    #--------------------------------------------------------------------

    dicSAM = {}
    dicEXP = {}

    #-- Initialise the Units class --------------------------------------

    clsUNI = UN.classUnits()

    #---------------------------------------------------------------------
    #  Get Machine Epsilon
    #---------------------------------------------------------------------

    macEPS = UT.calcMacEPS()

    UT.macEPS = macEPS  #-- Over-write the value set in constants.py

    #---------------------------------------------------------------------
    #  Parse Input File Line by Line
    #---------------------------------------------------------------------

    fInp = clsIO.fInp
    fOut = clsIO.fOut

    iCnt = 0

    for curL in fInp:

        iCnt += 1

        #-- Current Line in curL; split into List tokS ----------------------

        tokS = curL.split()
        nTok = len(tokS)

        #-- Blank or Comment? -----------------------------------------------

        if nTok == 0: pass  #-- Blank line
        elif tokS[0][:2] == "--":
            pass  #-- Comment!

            #-- Initial Section -------------------------------------------------

        elif tokS[0][:4].upper() == "INIT":

            iERR, clsEOS = RD.readINIT(dicSAM, clsUNI, clsIO)
            if iERR < 0: break

#-- Is this a DEF/ENDDEF fluid definition? --------------------------

        elif tokS[0][:3].upper() == "DEF":

            fDef = clsIO.fInp
            iERR, clsEOS, dicSAM = RD.readDEF(fDef, dicSAM, clsIO)
            if iERR < 0: break

#-- Read Experiments Definitions ------------------------------------

        elif tokS[0].upper() == "EXP":

            iERR = RX.readExps(clsIO, clsEOS, dicSAM, dicEXP, clsUNI)
            if iERR < 0: break

#-- Read Regression Definitions -------------------------------------

        elif tokS[0].upper() == "REG":

            iERR,clsEOS,dicSAM,dicEXP = \
                RR.readReg(clsIO,clsEOS,dicSAM,dicEXP,clsUNI)
            if iERR < 0: break

#-- Read Grouping Definitions ---------------------------------------

        elif tokS[0][:2].upper() == "GR":

            iERR,clsEOS,dicSAM,dicEXP = \
                RG.readGroup(clsIO,clsEOS,dicSAM,dicEXP,clsUNI)
            if iERR < 0: break

#-- Read Blackoil Definitions ---------------------------------------

        elif tokS[0][:2].upper() == "BL":

            iERR = RB.readBlack(clsIO, clsEOS, dicSAM, clsUNI)
            if iERR < 0: break

#-- Read Compositional Definitions ----------------------------------

        elif tokS[0][:2].upper() == "CO":

            clsIO.fSim = clsIO.rNam + "_EOS.sim"
            iERR = RC.readComp(clsEOS, dicSAM, clsIO, clsUNI)
            if iERR < 0: break

#-- Read DEBUG controls ---------------------------------------------

        elif tokS[0][:3].upper() == "DEB":

            iERR = RE.readDebug(clsIO)
            if iERR < 0: break

#-- Read OPTION controls --------------------------------------------

        elif tokS[0][:3].upper() == 'OPT':

            iERR = RE.readOption(clsIO)
            if iERR < 0: break

#-- Read TITLE1 -----------------------------------------------------

        elif tokS[0].upper() == "TITLE1":
            clsIO.Tit1 = buildTitle(tokS)

            #-- Read TITLE2 -----------------------------------------------------

        elif tokS[0].upper() == "TITLE2":
            clsIO.Tit2 = buildTitle(tokS)

            #-- Read TITLE3 -----------------------------------------------------

        elif tokS[0].upper() == "TITLE3":
            clsIO.Tit3 = buildTitle(tokS)

            #-- Temporary STOP Card ---------------------------------------------

        elif tokS[0].upper() == "STOP":
            break

        else:
            pass

#== Close All Output Files =============================================

    closeFiles(clsIO)

    #== Return the Error Flag ==============================================

    return iERR
Example #4
0
def readExps(clsIO,clsEOS,dicSAM,dicEXP,clsUNI) :

    iERR  = 0
    iLine = 0

    fInP = clsIO.fInP

#== Inactivate existing experiments ===================================

    nExp = len(dicEXP)
    for iExp in range(nExp) : dicEXP[iExp].IsAct = False

#== Main Read Loop ====================================================    

    for curL in fInP :

        iLine += 1

        if iLine > 100 :
            print("Too Many Lines of EXP Data - Error")
            iERR = -1
            break

        tokS = curL.split()
        nTok = len(tokS)

        if   nTok == 0                    :  #-- Blank line!
            pass
        elif tokS[0][:2]         == "--"  :  #-- Comment
            pass
        elif tokS[0][:3].upper() == "DEB" :
            iERR = RG.readDebug(clsIO)
        elif tokS[0].upper()     == "CCE" :
            iERR = readGen("CCE",clsIO,clsEOS,dicSAM,dicEXP,clsUNI)
        elif tokS[0].upper()     == "CVD" :
            iERR = readGen("CVD",clsIO,clsEOS,dicSAM,dicEXP,clsUNI)
        elif tokS[0].upper()     == "DLE" :
            iERR = readGen("DLE",clsIO,clsEOS,dicSAM,dicEXP,clsUNI)
        elif tokS[0].upper()     == "SEP" :
            iERR = readGen("SEP",clsIO,clsEOS,dicSAM,dicEXP,clsUNI)
        elif tokS[0].upper()     == "FLASH" :
            iERR = readGen("FLS",clsIO,clsEOS,dicSAM,dicEXP,clsUNI)
        elif tokS[0].upper()     == "PSAT" :
            iERR = readGen("SAT",clsIO,clsEOS,dicSAM,dicEXP,clsUNI)
        elif tokS[0].upper()     == "SWELL" :
            iERR = readGen("SWL",clsIO,clsEOS,dicSAM,dicEXP,clsUNI)
        elif tokS[0].upper()     == "GRAD" :
            iERR = readGen("GRD",clsIO,clsEOS,dicSAM,dicEXP,clsUNI)
        elif tokS[0].upper()     == "PLOT" :
            if tokS[1].upper() == "NONE" :
                clsIO.Pall = False
        elif tokS[0][:4].upper() == "ENDE" :
            #print("ENDEXP k/w found")
            break

        if iERR < 0 : break

#======================================================================
#  Experiments Read OK => Run Them
#======================================================================

    if iERR == 0 :
        sExt = ""
        CX.calcExps(sExt,clsEOS,dicSAM,dicEXP,clsIO,clsUNI)

    return iERR,dicEXP
Example #5
0
def readGroup(clsIO,clsEOS0,clsEOSG,dicSAM0,dicSAMG,dicEXP0,clsUNI) :

    print("Reading User Data for Grouping")

    iERR  = 0
    iLine = 0
    
    nOld  = clsEOS0.NC   #-- "Old" Number of Components in "Old" Class
    nNew  = 0
    nTst  = 0
    iSam  = 0           #-- By default, we will weight by Sample[0]
    qExp  = False

    fInP = clsIO.fInP

    dicGRP = {}          #-- Dictionary to hold the new Groups

#== Loop over lines in the Input File =================================    

    for curL in fInP :

        iLine += 1

        if iLine > 100 :
            print("Too Many Lines of GROUP Data - Error")
            iERR = -1
            break

        tokS = curL.split()
        nTok = len(tokS)

        if   nTok                == 0      : pass           #-- Blank line!
        elif tokS[0][:2]         == "--"   : pass           #-- Comment!
        elif tokS[0][:4].upper() == "ENDG" : break          #-- ENDGROUP => Exit
        elif tokS[0][:3].upper() == "DEB"  :                #-- DEBUG
             iERR = RG.readDebug(clsIO)
             if iERR < 0 : break
        elif tokS[0][:4].upper() == "RUNE" : qExp = True    #-- Run Experiments
        elif tokS[0][:2].upper() == "SA"   :                #-- SAMPLE for weighting

            samNam = tokS[1]
            iSam   = checkSamp4Grp(samNam,dicSAM0)
            if iSam < 0 :
                print("Sample ",samNam," Proposed for Weighting Not Found - Error")
                iERR = -1
                return iERR

        else :

#== Must be reading New Name and Old-Names ============================

            newNam = tokS[0]
            clsGRP = classGRP(newNam)   #-- Create the New Group

            dicGRP[nNew] = clsGRP       #-- Add to the Dictionary of Groups
            
            nNew += 1                   #-- Increment the Counter

            oldNam = []

            iTok = 1
            while iTok < nTok :
                oldNam.append(tokS[iTok])
                nTst += 1                   #-- Test the number of "old" comps
                iTok += 1

            clsGRP.setOldNames(oldNam)

#----------------------------------------------------------------------
#  Process Data
#----------------------------------------------------------------------

    #print("nOld,nNew,nTst ",nOld,nNew,nTst)

    c*K = [False for i in range(nOld)]
    
    if nTst != nOld :
        print("Currently have ",nOld," Components defined: Only ",nTst," Read - Error")
        iERR = -1
        return iERR,clsEOS0,dicSAM0,dicEXP0

    for iNew in range(nNew) :
        
        oldNam = dicGRP[iNew].oldNam
        oldNum = []
        nGrp   = len(oldNam)
        
        for iGrp in range(nGrp) :
            sCom = oldNam[iGrp]
            iCom = checkComp4Grp(sCom,clsEOS0)
            if iCom < 0 :
                print("Old Component Name ",sCom," Not Found - Error")
                iERR = -1
                return iERR,clsEOS0,dicSAM0,dicEXP0
            else:
                oldNum.append(iCom)
                c*K[iCom] = True
                
        dicGRP[iNew].setOldNums(oldNum)

#-- Do we have all 'old' components used? ---------------------------
        
    for iC in range(nOld) :
        if not c*K[iC] :
            sCom = clsEOS0.gPP("CN",iC)
            print("Component " + sCom + " Not Found Amongst 'Old' Components - Error")
            iERR = -1
            return iERR,clsEOS0,dicSAM0,dicEXP0
        
#==  Do we want experiments run before and after grouping? ============

    if qExp :
        dicEXPG = deepcopy(dicEXP0)
        sExt   = " - Before Grouping"
        CX.calcExps(sExt,clsEOS0,dicSAM0,dicEXP0,clsIO,clsUNI)

#======================================================================
#  Perform the Grouping
#======================================================================

    iERR = calcGroup(iSam,dicGRP,clsEOS0,clsEOSG,dicSAM0,dicSAMG)

    if iERR == 0 :
        print("Grouping Performed")
    else :
        print("Grouping Failed: Program Stopping")
        return iERR,clsEOS0,dicSAM0,dicEXP0

#-- Write New System to the Output File -----------------------------

    sTit = "Grouping From " + str(nOld) + " Components To " + str(nNew)

    #WO.outputGroup(clsIO,nOld,nNew)
    WO.outputProps(clsIO,clsEOSG,dicSAMG,sTit)

#-- Save the new EoS/Sample Definitions -----------------------------    

    sTit = "Grouping From " + str(nOld) + " Components To " + str(nNew)
    WO.outputSave(sTit,clsEOSG,dicSAMG,clsIO)

#----------------------------------------------------------------------
#  Re-run existing experiments?
#----------------------------------------------------------------------

    if qExp :
        sExt   = " - After  Grouping"
        for iExp in range(len(dicEXPG)) : dicEXPG[iExp].IsAct = True
        CX.calcExps(sExt,clsEOSG,dicSAMG,dicEXPG,clsIO,clsUNI)
        qReg = False
        GP.regPlots(clsIO,dicEXP0,dicEXPG,dicSAMG,qReg,clsUNI)

#----------------------------------------------------------------------
#  Perform deepcopy to put Grouped EOS/Samples into Main Sets
#----------------------------------------------------------------------

    clsEOS0 = deepcopy(clsEOSG)
    dicSAM0 = deepcopy(dicSAMG)
    if qExp :
        dicEXP0 = deepcopy(dicEXPG)

#== End of Routine ====================================================

    return iERR,clsEOS0,dicSAM0,dicEXP0
Example #6
0
def readBlack(clsIO, clsEOS, dicSAM, clsUNI):

    iERR = 0
    iLine = 0

    #print("readBlack: Entered")

    pSep = []
    tSep = []
    Lsep = []
    Vsep = []

    pMax = None
    pMin = None
    pInc = None

    sSam = None
    Tres = None

    xTyp = None

    pRef = None
    Salt = None

    fInP = clsIO.fInP

    #== Create the clsBLK class to hold relevant data ======================

    clsBLK = classBLK()

    #----------------------------------------------------------------------
    #  Loop over lines until ENDB[LACK] found
    #----------------------------------------------------------------------

    for curL in fInP:

        iLine += 1

        if iLine > 100:
            print("Too Many Lines of BLACK Data - Error")
            iERR = -1
            break

        tokS = curL.split()
        nTok = len(tokS)

        if nTok == 0:  #-- Blank line!
            pass
        elif tokS[0][:2] == "--":  #-- Comment
            pass
        elif tokS[0][:2].upper() == "PS":  #-- Separator Train Pressures

            pSuni = tokS[1].lower()  #-- 1st Argument must be units
            qPuni = pSuni in clsUNI.sPres

            if qPuni:
                clsBLK.setPsepUni(pSuni.upper())
            else:
                print(
                    "First argument after PSEP must be valid Pressure Units [PSIA, PSIG, BARA, BARG] - Error"
                )
                iERR = -1
                break

            iTok = 2
            while iTok < nTok:
                pVal = float(tokS[iTok])
                pSep.append(clsUNI.X2I(pVal, pSuni))
                iTok += 1

        elif tokS[0][:2].upper() == "TS":  #-- Separator Train Temps

            tSuni = tokS[1].lower()  #-- 1st Argument must be units
            tPuni = tSuni in clsUNI.sTemp

            if tPuni:
                clsBLK.setTsepUni(tSuni.upper())
            else:
                print(
                    "First argument after TSEP must be valid Tempearture Units [degR, degF, degC, Kelv] - Error"
                )
                iERR = -1
                break

            iTok = 2
            while iTok < nTok:
                tVal = float(tokS[iTok])
                tSep.append(clsUNI.X2I(tVal, tSuni))
                iTok += 1

        elif tokS[0][:2].upper() == "LS":  #-- Next Stage for Sep-Liq

            iTok = 1
            while iTok < nTok:
                lSep = int(tokS[iTok])
                Lsep.append(lSep)
                iTok += 1

        elif tokS[0][:2].upper() == "VS":  #-- Next Stage for Sep-Vap

            iTok = 1
            while iTok < nTok:
                vSep = int(tokS[iTok])
                Vsep.append(vSep)
                iTok += 1

        elif tokS[0][:2].upper() == "PR":  #-- Pressure-RANGE (PRange)

            pRuni = tokS[1].lower()  #-- 1st Argument must be units
            qPuni = pRuni in clsUNI.sPres

            if qPuni:
                clsBLK.setPresUni(pSuni.upper())
            else:
                print(
                    "First argument after PRANGE must be valid Pressure Units [PSIA, PSIG, BARA, BARG] - Error"
                )
                iERR = -1
                break

            iTok = 2
            while iTok < nTok:
                sVal = tokS[iTok].upper()
                if sVal == "PMAX":
                    iTok += 1
                    pMax = float(tokS[iTok])
                elif sVal == "PMIN":
                    iTok += 1
                    pMin = float(tokS[iTok])
                elif sVal == "PINC":
                    iTok += 1
                    pInc = float(tokS[iTok])
                iTok += 1

        elif tokS[0][:2].upper() == "UN":  #-- UNITS keyword [FIELD/METRIC]

            uTyp = tokS[1].upper()

            if uTyp[:1] == "M": clsBLK.setOutUnit("MET")
            elif uTyp[:1] == "S": clsBLK.setOutUnit("SI")  #-- CMG-Only!!
            else: clsBLK.setOutUnit("FLD")

        elif tokS[0][:2].upper(
        ) == "SI":  #-- Simulator Type [CMG/ECL/MOR/VIP or NEX]

            uTyp = tokS[1].upper()

            if uTyp[:1] == "M":  #-- Tempest-MORE
                oTyp, gTyp = argsMORE(tokS)
                clsBLK.setSimType("MOR")
                clsBLK.setOilKeyW(oTyp)
                clsBLK.setGasKeyW(gTyp)
            elif uTyp[:1] == "C":  #-- CMG-IMEX
                oTyp = argsIMEX(tokS)
                clsBLK.setSimType("CMG")
                clsBLK.setOilKeyW(oTyp)
                clsBLK.setGasKeyW("")
            elif uTyp[:1] == "V" or uTyp[:1] == "N":  #-- VIP or Nexus
                oTyp, gTyp = argsVIP(tokS)
                clsBLK.setSimType("VIP")
                clsBLK.setOilKeyW(oTyp)
                clsBLK.setGasKeyW(gTyp)
            elif uTyp[:1] == "E":  #-- Eclipse-100
                oTyp, gTyp = argsE100(tokS)
                clsBLK.setSimType("ECL")
                clsBLK.setOilKeyW(oTyp)
                clsBLK.setGasKeyW(gTyp)
            else:
                iERR = -1
                print(
                    "Error - User has not set the Simulator Type for B/O Table Output"
                )
                break

        elif tokS[0][:1].upper() == "W":  #-- Properties to define Water

            iTok = 1
            while iTok < nTok:
                if tokS[iTok][:1].upper() == "P":  #-- Reference Pressure
                    iTok += 1
                    pRef = float(tokS[iTok])
                    iTok += 1
                    wUni = tokS[iTok]
                elif tokS[iTok][:1].upper() == "S":  #-- Salinity
                    iTok += 1
                    Salt = float(tokS[iTok])
                    iTok += 1
                    sUni = tokS[iTok]
                iTok += 1

        elif tokS[0][:3].upper() == "DEB":

            iERR = RG.readDebug(clsIO)
            if iERR < 0: break

        elif tokS[0][:4].upper() == "ENDB":
            #print("readBlack: ENDBLACK k/w read")
            break

        elif tokS[0][:3].upper() == "CCE" or \
             tokS[0][:3].upper() == "CVD" or \
             tokS[0][:3].upper() == "DLE"    :

            xTyp = tokS[0][:3].upper()

#-- Line must contains non-Table information ------------------------

        else:

            iTok = 0
            while iTok < nTok:
                if tokS[iTok].upper() == "SAMP":
                    iTok += 1
                    sSam = tokS[iTok]
                elif tokS[iTok].upper() == "TRES":
                    iTok += 1
                    Tres = float(tokS[iTok])
                    iTok += 1
                    Tuni = tokS[iTok]
                iTok += 1

#----------------------------------------------------------------------
#  Process user data: Starting with Separator Train P's and T's
#----------------------------------------------------------------------

    nPsep = len(pSep)
    nTsep = len(tSep)
    nLsep = len(Lsep)
    nVsep = len(Vsep)

    if nPsep == 0:
        print("No Separator Pressure Stages Defined via PSEP - Error")
        iERR = -1
        return iERR

    if nTsep == 0:
        print("No Separator Temperature Stages Defined via TSEP - Error")
        iERR = -1
        return iERR

    if nPsep != nTsep:
        print("Number of PSEP Stages = ", nPsep,
              " Must Equal Number of TSEP Stages = ", nTsep, " - Error")
        iERR = -1
        return iERR

    if nLsep > 0:
        if nLsep != nTsep:
            print("Number of LSEP Stages = ", nLsep,
                  " Must Equal Number of TSEP Stages = ", nTsep, " - Error")
            iERR = -1
            return iERR
        clsBLK.setSepLsep(Lsep)
    else:
        Lsep = [0 for i in range(nTsep)]
        for iSep in range(nTsep - 1):
            Lsep[iSep] = iSep + 1
        clsBLK.setSepLsep(Lsep)

    if nVsep > 0:
        if nVsep != nTsep:
            print("Number of VSEP Stages = ", nLsep,
                  " Must Equal Number of TSEP Stages = ", nTsep, " - Error")
            iERR = -1
            return iERR
        clsBLK.setSepVsep(Vsep)
    else:
        Vsep = [0 for i in range(nTsep)]
        clsBLK.setSepVsep(Vsep)

    clsBLK.setSepPres(pSep)
    clsBLK.setSepTemp(tSep)

    #-- Pressure range (Max, Min: Inc) for table generation -------------

    if pMax == None:
        print("Maximum Pressure (PMAX) Has Not Been Set With PRANGE - Error")
        iERR = -1
        return iERR
    else:
        clsBLK.setPmax(clsUNI.X2I(pMax, pRuni))

    if pMin == None:
        print("Minimum Pressure (PMIN) Has Not Been Set With PRANGE - Error")
        iERR = -1
        return iERR
    else:
        clsBLK.setPmin(clsUNI.X2I(pMin, pRuni))

    if pInc == None:
        print("Pressure Increment (PINC) Has Not Been Set With PRANGE - Error")
        iERR = -1
        return iERR
    else:
        clsBLK.setPinc(clsUNI.X2I(pInc, pRuni))

#-- Valid Reservoir Sample to work on? ------------------------------

    if sSam == None:
        print("No Sample Name Has Been Read via SAMP argument - Error")
        iERR = -1
        return iERR
    else:
        nSam = len(dicSAM)
        qFnd = False
        for iSam in range(nSam):
            sArr = dicSAM[iSam].sName
            if sSam.upper() == sArr.upper():
                clsBLK.setSample(iSam)
                qFnd = True
                break
        if not qFnd:
            print("Did Not Find Sample ", sSam,
                  " In Previously Defined Samples - Error")
            iERR = -1
            return iERR

#-- Reservoir Temperature and its Units -----------------------------

    if Tres == None:
        print(
            "No Reservoir Temperature Has Been Read via TRES argument - Error")
        iERR = -1
        return iERR
    else:
        clsBLK.setTuni(Tuni)
        clsBLK.setTres(clsUNI.X2I(Tres, Tuni))

#-- Experiment Type -------------------------------------------------

    if xTyp == None:
        print("Experiment Type (CCE, CVD or DLE) Not Specified - Error")
        iERR = -1
        return iERR
    else:
        clsBLK.setExpType(xTyp)

#-- Have we read the WATER card with pRef and Salt? -----------------

    if pRef == None and Salt == None:

        clsBLK.setBrine(False)
        clsBLK.setPrefWat(14.6959)  #-- Standard Pressure [psia]
        clsBLK.setPrefUni("psia")
        clsBLK.setSaltWat(0.0)  #-- Pure Water
        clsBLK.setSaltUni("mfrac")

    else:

        clsBLK.setBrine(True)

        if Salt != None:
            clsBLK.setSaltUni(sUni)
            clsBLK.setSaltWat(clsUNI.X2I(Salt, sUni))
        else:
            clsBLK.setSaltWat(0.0)  #-- Pure Water
            clsBLK.setSaltUni("mfrac")

        if pRef != None:
            clsBLK.setPrefUni(wUni)
            clsBLK.setPrefWat(clsUNI.X2I(pRef, wUni))
        else:
            clsBLK.setPrefWat(14.6959)  #-- Standard Pressure [psia]
            clsBLK.setPrefUni("psia")

#========================================================================
#  Data All Valid, Proceed to Calculate Tables
#========================================================================

    if iERR == 0:

        print("readBlack: All BlackOil Data Read OK")

        BD.calcBlack(clsIO, clsBLK, clsEOS, dicSAM, clsUNI)

#========================================================================
#  End of Routine
#========================================================================

    return iERR
Example #7
0
def readDef(clsIO, dicSAM, clsUNI):

    iERR = 0
    iCnt = 0
    fInP = clsIO.fInP
    fOut = clsIO.fOut

    macEPS = calcMacEPS()  #-- Compute Machine Epsilon

    #---------------------------------------------------------------------
    #  Parse Input File Line by Line
    #---------------------------------------------------------------------

    for curL in fInP:

        iCnt += 1

        #-- Current Line in curL; split into List tokS

        tokS = curL.split()
        nTok = len(tokS)

        #-- Blank or Comment? -----------------------------------------------

        if nTok == 0:  #-- Blank line
            pass
        else:

            if tokS[0][:2] == "--": pass
            elif tokS[0][:4].upper() == "ENDD": break
            elif tokS[0][:3].upper() == "DEB":
                iERR = RE.readDebug(clsIO)
            elif tokS[0].upper() == "EOS":

                #-- Equation of State -----------------------------------------------

                EOS = tokS[1].upper()

                clsEOS = classEoS(EOS)

                print("Equation of State Specified as ", EOS)

                sCom = "--"

                WO.outputHeader(fOut, sCom, clsIO)
                WO.outputEOS(fOut, sCom, clsIO, clsEOS)

            elif tokS[0].upper() == "NCOMP":

                nComp = int(tokS[1])
                clsEOS.NC = nComp
                clsEOS.setNComp(nComp)  #-- Dimension the Arrays

            elif tokS[0].upper() == "NSAMP":

                nSamp = int(tokS[1])
                clsEOS.NS = nSamp

            elif tokS[0].upper() == "PROPS":

                curL = next(fInP)  #-- Property Names
                curL = next(fInP)  #-- Property Units

                for iC in range(nComp):

                    curL = next(fInP)
                    tokS = curL.split()
                    nTok = len(tokS)

                    if nTok != 17:
                        print("DEFINE PROPS: Expecting 17 Columns, Only ",
                              nTok, " Read")
                        iERR = -1
                        break

                    sN = tokS[0]
                    Mw = float(tokS[1])
                    Tc = float(tokS[2])
                    Pc = float(tokS[3])
                    Vc = float(tokS[4])
                    Zc = float(tokS[5])
                    AF = float(tokS[6])
                    Tb = float(tokS[7])
                    SG = float(tokS[8])
                    PA = float(tokS[9])
                    SS = float(tokS[10])
                    MA = float(tokS[11])
                    MB = float(tokS[12])
                    CA = float(tokS[13])
                    CB = float(tokS[14])
                    CC = float(tokS[15])
                    CD = float(tokS[16])

                    clsEOS.sPP("CN", iC, sN)
                    clsEOS.sPP("MW", iC, Mw)
                    clsEOS.sPP("TC", iC, Tc)
                    clsEOS.sPP("PC", iC, Pc)
                    clsEOS.sPP("VC", iC, Vc)
                    clsEOS.sPP("ZC", iC, Zc)
                    clsEOS.sPP("AF", iC, AF)
                    clsEOS.sPP("TB", iC, Tb)
                    clsEOS.sPP("SG", iC, SG)
                    clsEOS.sPP("PA", iC, PA)
                    clsEOS.sPP("SS", iC, SS)
                    clsEOS.sPP("MA", iC, MA)
                    clsEOS.sPP("MB", iC, MB)
                    clsEOS.sPP("CA", iC, CA)
                    clsEOS.sPP("CB", iC, CB)
                    clsEOS.sPP("CC", iC, CC)
                    clsEOS.sPP("CD", iC, CD)

            elif tokS[0].upper() == "BIP":

                curL = next(fInP)  #-- Component Names

                for iC in range(nComp):

                    curL = next(fInP)
                    tokS = curL.split()
                    nTok = len(tokS)

                    if nTok != nComp + 1:
                        print("DEFINE BIP: Expecting ", nComp + 1,
                              " Columns, Only ", nTok, " Read")
                        iERR = -1
                        break

                    iTok = 1
                    while iTok < nTok:
                        KIJ = float(tokS[iTok])
                        clsEOS.sIJ(iC, iTok - 1, KIJ)
                        iTok += 1

            elif tokS[0].upper() == "SAMPLES":

                curL = next(fInP)  #-- Sample Names
                tokS = curL.split()
                nTok = len(tokS)

                for iSamp in range(nSamp):
                    sName = tokS[iSamp + 1]
                    csSAM = RS.classSample(sName)
                    dicSAM[iSamp] = csSAM
                    dicSAM[iSamp].setNComp(nComp)

                for iC in range(nComp):

                    curL = next(fInP)
                    tokS = curL.split()

                    if nTok != nSamp + 1:
                        print("DEFINE SAMPLES: Expecting ", nSamp + 1,
                              " Columns, Only ", nTok, " Read")
                        iERR = -1
                        break

                    for iSamp in range(nSamp):
                        ZI = float(tokS[iSamp + 1])
                        if ZI < macEPS: ZI = 1.0E-20  #-- Protect against Z = 0
                        dicSAM[iSamp].sZI(iC, ZI)

            else:
                pass

#========================================================================
#  Has any slop crept into the sample definitions?
#========================================================================

    for iSamp in range(nSamp):
        sumT = 0.0
        for iC in range(nComp):
            sumT = sumT + dicSAM[iSamp].gZI(iC)
        sumT = 1.0 / sumT
        for iC in range(nComp):
            zI = sumT * dicSAM[iSamp].gZI(iC)
            dicSAM[iSamp].sZI(iC, zI)

#== Back-calculate the C7+ Properties =================================

    backCalcPlusFracProps(clsEOS, dicSAM)

    #========================================================================
    #  Do we need to sort the components?  Most to Least Volatility
    #========================================================================

    clsEOS, dicSAM = CR.sortComponents(clsEOS, dicSAM)

    #========================================================================
    #  Output the data
    #========================================================================

    sTit = "Initialisation from a saved DEFINE"

    WO.outputProps(clsIO, clsEOS, dicSAM, sTit)

    #========================================================================
    #  Write Fluid Description to the SAV file
    #========================================================================

    WO.outputSave(sTit, clsEOS, dicSAM, clsIO)

    #======================================================================
    #  Generate (Approximate) Phase Plots
    #======================================================================

    CP.allSamplesPhasePlot(clsEOS, dicSAM, clsIO)

    #== Return values =====================================================

    return iERR, clsEOS, dicSAM
Example #8
0
def readInit(clsIO, dicSAM, clsUNI):

    iERR = 0
    iCnt = 0
    nSplt = 0

    fInP = clsIO.fInP
    fOut = clsIO.fOut

    #----------------------------------------------------------------------
    #  Parse Input File Line by Line
    #----------------------------------------------------------------------

    for curL in fInP:

        iCnt += 1

        #-- Current Line in curL; split into List tokS ----------------------

        tokS = curL.split()
        nTok = len(tokS)

        #== Process Options ===================================================

        if nTok == 0: pass  #-- Blank Line
        elif tokS[0][:2] == "-- ": pass  #-- Comment
        elif tokS[0][:4].upper() == "ENDI":
            break  #-- ENDINIT k/w => Exit

            #-- EOS K/W Read => Create the clsEOS to hold data ------------------

        elif tokS[0].upper() == "EOS":

            EOS = tokS[1].upper()

            clsEOS = classEoS(EOS)

            print("Equation of State Specified as ", EOS)

            sCom = "--"

            WO.outputHeader(fOut, sCom, clsIO)
            WO.outputEOS(fOut, sCom, clsIO, clsEOS)

#-- SPLIT k/w -------------------------------------------------------

        elif tokS[0][:3].upper() == "SPL":

            nSplt = int(tokS[1])
            #print("SPLIT: nSplt ",nSplt)
            if nSplt < 2 or nSplt > 5:
                print("SPLIT: nSplt ", nSplt,
                      " Out of Range, 2 =< Nsplt =< 5 - Error")
                iERR = -1
                break
            else:
                clsEOS.setNPseu(nSplt)
                print("Plus Fraction will be split into ", nSplt,
                      " Pseudo-Components")

#-- SAMPLES k/w -----------------------------------------------------

        elif tokS[0][:4].upper() == "SAMP":

            if nSplt == 0:
                nSplt = 1
                clsEOS.setNPseu(nSplt)

            iERR, dicSAM = RS.readSamp(clsIO, tokS, clsEOS, dicSAM, clsUNI)
            if iERR < 0: break

#-- DEBUG k/w -------------------------------------------------------

        elif tokS[0][:3].upper() == "DEB":

            iERR = RE.readDebug(clsIO)
            if iERR < 0: break

#== Return values =====================================================

    return iERR, clsEOS, dicSAM
Example #9
0
def PVTfree():

    #========================================================================
    #  Main Routine: Parses the User Dataset
    #========================================================================

    iERR, clsIO = checkInputFile()

    if iERR < 0: return iERR

    #--------------------------------------------------------------------
    #  Dictionaries to Hold Classes of Samples and Experiments
    #  Dictionary of Regression Classes is held locally
    #--------------------------------------------------------------------

    dicSAM = {}
    dicEXP = {}

    #-- Initialise the Units class --------------------------------------

    clsUNI = UN.classUnits()

    #---------------------------------------------------------------------
    #  Get Machine Epsilon
    #---------------------------------------------------------------------

    macEPS = calcMacEPS()

    CO.macEPS = macEPS  #-- Over-write the value set in constants.py

    #---------------------------------------------------------------------
    #  Parse Input File Line by Line
    #---------------------------------------------------------------------

    fInP = clsIO.fInP
    fOut = clsIO.fOut

    iCnt = 0

    with fInP:

        for curL in fInP:

            iCnt += 1

            #-- Current Line in curL; split into List tokS ----------------------

            tokS = curL.split()
            nTok = len(tokS)

            #-- Blank or Comment? -----------------------------------------------

            if nTok == 0: pass  #-- Blank line
            elif tokS[0][:2] == "--":
                pass  #-- Comment!

                #-- Initial Section -------------------------------------------------

            elif tokS[0][:4].upper() == "INIT":

                iERR, clsEOS, dicSAM = readInit(clsIO, dicSAM, clsUNI)
                if iERR < 0: break

#-- Is this a DEF/ENDDEF fluid definition? --------------------------

            elif tokS[0][:3].upper() == "DEF":

                iERR, clsEOS, dicSAM = readDef(clsIO, dicSAM, clsUNI)
                if iERR < 0: break

#-- Read Experiments Definitions ------------------------------------

            elif tokS[0].upper() == "EXP":

                iERR, dicEXP = RX.readExps(clsIO, clsEOS, dicSAM, dicEXP,
                                           clsUNI)
                if iERR < 0: break

#-- Read Regression Definitions -------------------------------------

            elif tokS[0].upper() == "REG":

                iERR,clsEOS,dicSAM,dicEXP = \
                    RR.readReg(clsIO,clsEOS,dicSAM,dicEXP,clsUNI)
                if iERR < 0: break

#-- Read Grouping Definitions ---------------------------------------

            elif tokS[0][:2].upper() == "GR":

                EOS = clsEOS.EOS

                clsEOSG = classEoS(EOS)  #-- New Class
                dicSAMG = {}  #-- New Dictionary

                iERR,clsEOS,dicSAM,dicEXP = \
                    RG.readGroup(clsIO,clsEOS,clsEOSG,dicSAM,dicSAMG,dicEXP,clsUNI)
                if iERR < 0: break

#-- Read Blackoil Definitions ---------------------------------------

            elif tokS[0][:2].upper() == "BL":

                #clsIO.fSim = clsIO.rNam + "_BO.sim"
                iERR = RB.readBlack(clsIO, clsEOS, dicSAM, clsUNI)
                if iERR < 0: break

#-- Read Compositional Definitions ----------------------------------

            elif tokS[0][:2].upper() == "CO":

                clsIO.fSim = clsIO.rNam + "_EOS.sim"
                iERR = RC.readComp(clsEOS, dicSAM, clsIO, clsUNI)
                if iERR < 0: break

#-- Read DEBUG controls ---------------------------------------------

            elif tokS[0][:3].upper() == "DEB":

                iERR = RE.readDebug(clsIO)
                if iERR < 0: break

#-- Read TITLE1 -----------------------------------------------------

            elif tokS[0].upper() == "TITLE1":
                clsIO.Tit1 = buildTitle(tokS)

                #-- Read TITLE2 -----------------------------------------------------

            elif tokS[0].upper() == "TITLE2":
                clsIO.Tit2 = buildTitle(tokS)

                #-- Read TITLE3 -----------------------------------------------------

            elif tokS[0].upper() == "TITLE3":
                clsIO.Tit3 = buildTitle(tokS)

                #-- Temporary STOP Card ---------------------------------------------

            elif tokS[0].upper() == "STOP":
                break

            else:
                pass

#== Close All Output Files =============================================

    closeFiles(clsIO)

    #== Return the Error Flag ==============================================

    return iERR