src/main/java/com/equinor/neqsim/parameterfitting/thermo/binaryInteractionParameterFitting/HuronVidalParameterFitting/UMRPRUFunction.java
<reponame>equinor/neqsim-parameterfittingpackage com.equinor.neqsim.parameterfitting.thermo.binaryInteractionParameterFitting.HuronVidalParameterFitting;

import neqsim.statistics.parameterFitting.nonLinearParameterFitting.LevenbergMarquardtFunction;
import neqsim.thermo.phase.PhaseEosInterface;
import neqsim.thermo.phase.PhaseGEUnifac;

/**
 * <p>
 * UMRPRUFunction class.
 * </p>
 *
 * @author Even Solbraa
 * @version $Id: $Id
 */
public class UMRPRUFunction extends LevenbergMarquardtFunction {
    /**
     * <p>
     * Constructor for UMRPRUFunction.
     * </p>
     */
    public UMRPRUFunction() {}

    /** {@inheritDoc} */
    @Override
    public double calcValue(double[] dependentValues) {
        thermoOps.TPflash();
        // system.display();
        return system.getPhases()[0].getComponents()[1].getx();
    }

    /** {@inheritDoc} */
    @Override
    public void setFittingParams(int i, double value) {
        params[i] = value;

        if (i == 0) {
            PhaseGEUnifac unifacp = (PhaseGEUnifac) ((PhaseEosInterface) system.getPhases()[0])
                    .getMixingRule().getGEPhase();
            unifacp.setAij(0, 2, value);
            unifacp.setAij(1, 2, value);

            PhaseGEUnifac unifacp2 = (PhaseGEUnifac) ((PhaseEosInterface) system.getPhases()[1])
                    .getMixingRule().getGEPhase();
            unifacp2.setAij(0, 2, value);
            unifacp2.setAij(1, 2, value);
        }

        if (i == 1) {
            PhaseGEUnifac unifacp = (PhaseGEUnifac) ((PhaseEosInterface) system.getPhases()[0])
                    .getMixingRule().getGEPhase();
            unifacp.setBij(0, 2, value);
            unifacp.setBij(1, 2, value);

            PhaseGEUnifac unifacp2 = (PhaseGEUnifac) ((PhaseEosInterface) system.getPhases()[1])
                    .getMixingRule().getGEPhase();
            unifacp2.setBij(0, 2, value);
            unifacp2.setBij(1, 2, value);
        }

        if (i == 2) {
            PhaseGEUnifac unifacp = (PhaseGEUnifac) ((PhaseEosInterface) system.getPhases()[0])
                    .getMixingRule().getGEPhase();
            // double aa = unifacp.getAij(0, 2);
            unifacp.setAij(2, 0, value);
            unifacp.setAij(2, 1, value);

            PhaseGEUnifac unifacp2 = (PhaseGEUnifac) ((PhaseEosInterface) system.getPhases()[1])
                    .getMixingRule().getGEPhase();
            unifacp2.setAij(2, 0, value);
            unifacp2.setAij(2, 1, value);
        }
    }
}
