eosCode.js
/**
* Calculates vapor phase derivatives and other parameters of the PPR1978 EPS given T (C), P (pbara), mole amounts or composition.
*
* @customfunction
*/
Calculates vapor phase derivatives and other parameters of the PPR1978 EPS given T (C), P (pbara), mole amounts or composition.
Calculates vapor phase derivatives and other parameters of the PPR1978 EPS given T ( C ) P ( pbara ) mole amounts or composition .
function Derivatives(dataRange, temperature, pressure, moles, useBinaries, kij0, kijT, decomposition, returnUnits, errMsgsOn) {
    if (returnUnits === void 0) { returnUnits = false; }
    if (errMsgsOn === void 0) { errMsgsOn = false; }
    try {
        var myErrorMsg = "";
        var fcnName = "Derivatives";
        var Phase = "vapor";
        var outputArray = [];
        var binaries = [];
        var inputDataArray = [];
        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];
        if (dataSet[0][idx.globalErrmsg] !== "") {
            myErrorMsg = dataSet[0].toString();
            throw new Error(fcnName + ": " + myErrorMsg);
        }
        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]);
                }
            }
            binaries = calculate_binaries(dataSet, tempK, kij0Array, kijTArray, aiArray, decompArray);
        }
        if (tempK === -500 || pBara === -500 || phase === "-500" || moleComp[0] === -500) {
            throw new Error(fcnName + ": " + dataSet[0][idx.globalErrmsg]);
        }
        if (dataSet[0][idx.binariesUsed] === true) {
            if (validateBinariyArrays(dataSet, kij0, kijT, decomposition)) {
                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]);
            }
        }
        outputArray = calculate_Derivatives(dataSet, tempK, pBara, moleComp, phase, binariesUsed, aiArray, binaries);
        return outputArray;
    }
    catch (myErrorHandler) {
        return myErrorHandler.message;
    }
}
function Derivatives ( dataRange , temperature , pressure , moles , useBinaries , kij0 , kijT , decomposition , returnUnits , errMsgsOn ) { if ( returnUnits === void 0 ) { returnUnits = false ; } if ( errMsgsOn === void 0 ) { errMsgsOn = false ; } try { var myErrorMsg = "" ; var fcnName = "Derivatives" ; var Phase = "vapor" ; var outputArray = [ ] ; var binaries = [ ] ; var inputDataArray = [ ] ; 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 ] ; if ( dataSet [ 0 ] [ idx . globalErrmsg ] !== "" ) { myErrorMsg = dataSet [ 0 ] . toString ( ) ; throw new Error ( fcnName + ": " + myErrorMsg ) ; } 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 ] ) ; } } binaries = calculate_binaries ( dataSet , tempK , kij0Array , kijTArray , aiArray , decompArray ) ; } if ( tempK === - 500 || pBara === - 500 || phase === "-500" || moleComp [ 0 ] === - 500 ) { throw new Error ( fcnName + ": " + dataSet [ 0 ] [ idx . globalErrmsg ] ) ; } if ( dataSet [ 0 ] [ idx . binariesUsed ] === true ) { if ( validateBinariyArrays ( dataSet , kij0 , kijT , decomposition ) ) { 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 ] ) ; } } outputArray = calculate_Derivatives ( dataSet , tempK , pBara , moleComp , phase , binariesUsed , aiArray , binaries ) ; return outputArray ; } catch ( myErrorHandler ) { return myErrorHandler . message ; } }
Calculates vapor phase derivatives and other parameters of the PPR1978 EPS given T (C), P (pbara), mole amounts or composition.
Calculates vapor phase derivatives and other parameters of the PPR1978 EPS given T ( C ) P ( pbara ) mole amounts or composition .
/***************************************************************************
        'This function calculates the calculates the derivatives of the PR1978 EOS.
        '***************************************************************************/