/*
 * Created on Sep 24, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package etomica.virial;

import etomica.util.Arrays;

/**
 * @author andrew
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class ClusterSumEF extends ClusterSum {

    /**
     * Constructs a Cluster sum of the given cluster and weights.  The MayerFunction 
     * array should contain only e-bonds.
     */
    public ClusterSumEF(ClusterBonds[] subClusters, double[] subClusterWeights,
            MayerFunction[] eArray) {
        super(subClusters, subClusterWeights, (MayerFunction[])Arrays.resizeArray(eArray,eArray.length*2));
        numF = f.length/2;
    }
    
    public ClusterAbstract makeCopy() {
        MayerFunction[] e = new MayerFunction[numF];
        System.arraycopy(f,0,e,0,numF);
        ClusterSum copy = new ClusterSumEF(clusters,clusterWeights,e);
        copy.setTemperature(1/beta);
        return copy;
    }

    protected void revertF() {
        int nPoints = pointCount();

        for(int j=0; j<nPoints; j++) {
            if (j == oldDirtyAtom) {
                continue;
            }
            for(int k=0; k<numF; k++) {
                double eValue = fOld[j][k];
                fValues[oldDirtyAtom][j][k+numF] = eValue;
                fValues[oldDirtyAtom][j][k] = eValue-1;
                fValues[j][oldDirtyAtom][k+numF] = eValue;
                fValues[j][oldDirtyAtom][k] = eValue-1;
            }
        }
    }
    
    protected void updateF(BoxCluster box) {
        int nPoints = pointCount();
        for (int k=0; k<numF; k++) {
            f[k].setBox(box);
        }

        CoordinatePairSet cPairs = box.getCPairSet();
        AtomPairSet aPairs = box.getAPairSet();
        // recalculate all f values for all pairs
        for(int i=0; i<nPoints-1; i++) {
            for(int j=i+1; j<nPoints; j++) {
                for(int k=0; k<numF; k++) {
                    double eValue;
                    if (f[k] instanceof MayerFunctionSpherical) {
                        eValue = ((MayerFunctionSpherical)f[k]).f(cPairs.getr2(i,j),beta);
                    }
                    else {
                        eValue = f[k].f(aPairs.getAPair(i,j),0, beta);
                    }
                    fValues[i][j][k+numF] = eValue;
                    fValues[j][i][k+numF] = eValue;
                    fValues[j][i][k] = eValue - 1;
                    fValues[i][j][k] = eValue - 1;
                }
            }
        }
    }
    
    private final int numF;
}

@@ -2101,143 +2101,19 @@
 alue
-;%0A                    if (f%5Bk%5D instanceof MayerFunctionSpherical) %7B%0A                        eValue = ((MayerFunctionSpherical)
+ = 
 f%5Bk%5D
-)
 .f(
-c
+a
 Pair
@@ -2121,113 +2121,21 @@
 .get
+APai
 r
-2
 (i,j),
-beta);%0A                    %7D%0A                    else %7B%0A                        eValue = f%5Bk%5D.f(a
+ c
 Pair
@@ -2143,29 +2143,24 @@
 .get
-APai
 r
+2
 (i,j),
-0,
  beta);%0A
     
@@ -2159,30 +2159,8 @@
 a);%0A
-                    %7D%0A
     

pass actual r2 to f