package etomica.virial;


/**
 * Umbrella cluster weight wrapper function.  The umbrella cluster's
 * value will be positive when any of the sub clusters have non-zero values.
 * This differs from a ClusterSum mostly because the sub cluster values are
 * not actually summed.
 */
public class ClusterWeightUmbrella implements ClusterWeight, java.io.Serializable {
	
    /**
	 * Contructs an umbrella cluster from the given clusters.
	 */
	public ClusterWeightUmbrella(ClusterAbstract[] allClusters) {
		clusterArray = allClusters;
		weightRatio = new double[allClusters.length];
		for (int i=0; i<weightRatio.length; i++) {
			weightRatio[i] = 1.0/weightRatio.length;
		}
	}
    
    public ClusterAbstract makeCopy() {
        ClusterWeightUmbrella newCluster = new ClusterWeightUmbrella(clusterArray);
        newCluster.setWeightRatio(weightRatio);
        return newCluster;
    }
	
	public int pointCount() {
		// can they be different?
		return clusterArray[0].pointCount();
	}

	public double value(BoxCluster box) {
		double sum = 0.0;
		for (int i=0; i<clusterArray.length; i++) {
			double v = clusterArray[i].value(box);
			sum += v*v*weightRatio[i];
		}
		return Math.sqrt(sum);
	}
	
	public void setWeightRatio(double[] aWeightRatio) {
		for (int i=weightRatio.length-1; i>=0; i--) {
			weightRatio[i] = aWeightRatio[i]/aWeightRatio[0];
		}
	}
	
	public double[] getWeightRatio() {
		return weightRatio;
	}
    
    public void setTemperature(double temp) {
        for (int i=0; i<clusterArray.length; i++) {
            clusterArray[i].setTemperature(temp);
        }
    }
    
    public ClusterAbstract[] getClusters() {
        return clusterArray;
    }
    
    private static final long serialVersionUID = 1L;
    private final ClusterAbstract[] clusterArray;
    private final double[] weightRatio;
}

@@ -532,21 +532,28 @@
 %09%09weight
-Ratio
+Coefficients
  = new d
@@ -599,29 +599,36 @@
 =0; i%3Cweight
-Ratio
+Coefficients
 .length; i++
@@ -636,29 +636,36 @@
  %7B%0A%09%09%09weight
-Ratio
+Coefficients
 %5Bi%5D = 1.0/we
@@ -664,29 +664,36 @@
 = 1.0/weight
-Ratio
+Coefficients
 .length;%0A%09%09%7D
@@ -857,25 +857,39 @@
 ight
-Ratio(weightRatio
+Coefficients(weightCoefficients
 );%0A 
@@ -1181,18 +1181,16 @@
  += 
-v*
 v*weight
 Rati
@@ -1185,21 +1185,28 @@
 v*weight
-Ratio
+Coefficients
 %5Bi%5D;%0A%09%09%7D
@@ -1219,22 +1219,11 @@
 urn 
-Math.sqrt(
 sum
-)
 ;%0A%09%7D
@@ -1251,143 +1251,96 @@
 ight
-Ratio(double%5B%5D aWeightRatio) %7B%0A%09%09for (int i=weightRatio.length-1; i%3E=0; i--) %7B%0A%09%09%09weightRatio%5Bi%5D = aWeightRatio%5Bi%5D/aWeightRatio%5B0%5D;%0A%09%09%7D
+Coefficients(double%5B%5D a) %7B%0A%09    System.arraycopy(a, 0, weightCoefficients, 0, a.length);
 %0A%09%7D%0A
@@ -1367,21 +1367,28 @@
 etWeight
-Ratio
+Coefficients
 () %7B%0A%09%09r
@@ -1399,21 +1399,28 @@
 n weight
-Ratio
+Coefficients
 ;%0A%09%7D%0A   
@@ -1815,13 +1815,20 @@
 ight
-Ratio
+Coefficients
 ;%0A%7D%0A

use more reasonable behavior for umbrella weighting