eosCode.js
/**
* Calculates the fugacity coefficients of a phase given T (C), P (pbara), mole amounts or composition, phase (vapor or liquid).
*
* @customfunction
*/
Calculates the fugacity coefficients of a phase given T (C), P (pbara), mole amounts or composition, phase (vapor or liquid).
Calculates the fugacity coefficients of a phase given T ( C ) P ( pbara ) mole amounts or composition phase ( vapor or liquid ) .
function PhasePhi(dataRange, temperature, pressure, moles, Phase, useBinaries, kij0, kijT, decomposition, errMsgsOn) {
    try {
        var myErrorMsg = "";
        var fcnName = "PhasePhi";
        var binaries = [];
        var inputDataArray = [];
        var phi = [];
        var outputArray = [];
        inputDataArray = validateData(dataRange, temperature, pressure, moles, Phase, useBinaries, kij0, kijT, decomposition, errMsgsOn, -500, false);
        var errorTest = inputDataArray[0][0]; 
        if (typeof (errorTest) === "string") {
            myErrorMsg = errorTest;
            throw new Error(fcnName + ": " + myErrorMsg);
        }
        var dataSet = inputDataArray[idx.datasetArray];
        var tempK = inputDataArray[idx.valuesArray][idx.T].valueOf();
        var pBara = inputDataArray[idx.valuesArray][idx.P].valueOf();
        var phase = inputDataArray[idx.valuesArray][idx.phase].valueOf();
        var moleComp = inputDataArray[idx.moleCompArray];
        var binariesUsed = inputDataArray[idx.valuesArray][idx.binariesOn].valueOf();
        var aiArray = inputDataArray[idx.aiArray];
        var kij0Array = inputDataArray[idx.kij0Array];
        var kijTArray = inputDataArray[idx.kijTArray];
        var decompArray = inputDataArray[idx.decompArray];
        if (binariesUsed && !inputDataArray[idx.valuesArray][idx.validBinaries]) {
            throw new Error(fcnName + ": " + dataSet[0][idx.globalErrmsg]);
        }
        if (binariesUsed) {
            if (inputDataArray[idx.valuesArray][idx.validBinaries]) {
                binaries = calculate_binaries(dataSet, tempK, kij0Array, kijTArray, aiArray, decompArray);
                if (binaries[0][0] === -500 && dataSet[0][idx.binariesUsed] === true) {
                    throw new Error(fcnName + ": " + dataSet[0][idx.globalErrmsg]);
                }
            }
            phi = calculate_Phi(dataSet, phase, moleComp, tempK, pBara, binariesUsed, aiArray, binaries);
        }
        else {
            phi = calculate_Phi(dataSet, phase, moleComp, tempK, pBara, binariesUsed, aiArray);
        }
        for (var i = 0; i < dataSet[0][idx.iSpecies]; i++) {
            outputArray.push(phi[i]);
        }
        return outputArray;
    }
    catch (myErrorHandler) {
        return myErrorHandler.message;
    }
}
function PhasePhi ( dataRange , temperature , pressure , moles , Phase , useBinaries , kij0 , kijT , decomposition , errMsgsOn ) { try { var myErrorMsg = "" ; var fcnName = "PhasePhi" ; var binaries = [ ] ; var inputDataArray = [ ] ; var phi = [ ] ; var outputArray = [ ] ; inputDataArray = validateData ( dataRange , temperature , pressure , moles , Phase , useBinaries , kij0 , kijT , decomposition , errMsgsOn , - 500 , false ) ; var errorTest = inputDataArray [ 0 ] [ 0 ] ; if ( typeof ( errorTest ) === "string" ) { myErrorMsg = errorTest ; throw new Error ( fcnName + ": " + myErrorMsg ) ; } var dataSet = inputDataArray [ idx . datasetArray ] ; var tempK = inputDataArray [ idx . valuesArray ] [ idx . T ] . valueOf ( ) ; var pBara = inputDataArray [ idx . valuesArray ] [ idx . P ] . valueOf ( ) ; var phase = inputDataArray [ idx . valuesArray ] [ idx . phase ] . valueOf ( ) ; var moleComp = inputDataArray [ idx . moleCompArray ] ; var binariesUsed = inputDataArray [ idx . valuesArray ] [ idx . binariesOn ] . valueOf ( ) ; var aiArray = inputDataArray [ idx . aiArray ] ; var kij0Array = inputDataArray [ idx . kij0Array ] ; var kijTArray = inputDataArray [ idx . kijTArray ] ; var decompArray = inputDataArray [ idx . decompArray ] ; if ( binariesUsed && ! inputDataArray [ idx . valuesArray ] [ idx . validBinaries ] ) { throw new Error ( fcnName + ": " + dataSet [ 0 ] [ idx . globalErrmsg ] ) ; } if ( binariesUsed ) { if ( inputDataArray [ idx . valuesArray ] [ idx . validBinaries ] ) { binaries = calculate_binaries ( dataSet , tempK , kij0Array , kijTArray , aiArray , decompArray ) ; if ( binaries [ 0 ] [ 0 ] === - 500 && dataSet [ 0 ] [ idx . binariesUsed ] === true ) { throw new Error ( fcnName + ": " + dataSet [ 0 ] [ idx . globalErrmsg ] ) ; } } phi = calculate_Phi ( dataSet , phase , moleComp , tempK , pBara , binariesUsed , aiArray , binaries ) ; } else { phi = calculate_Phi ( dataSet , phase , moleComp , tempK , pBara , binariesUsed , aiArray ) ; } for ( var i = 0 ; i < dataSet [ 0 ] [ idx . iSpecies ] ; i ++ ) { outputArray . push ( phi [ i ] ) ; } return outputArray ; } catch ( myErrorHandler ) { return myErrorHandler . message ; } }
Calculates the fugacity coefficients of a phase given T (C), P (pbara), mole amounts or composition, phase (vapor or liquid).
Calculates the fugacity coefficients of a phase given T ( C ) P ( pbara ) mole amounts or composition phase ( vapor or liquid ) .
// If an unrecoverable error occured during validateData() execution inputDataArray[0][0] will contain an error message otherwise it will contain the 1st vapor species MW