package org.pfaa.chemica.model;

public class Vaporization {
	private double temperature;
	private AntoineCoefficients antoineCoefficients;
	
	public Vaporization(AntoineCoefficients antoineCoefficients) {
		super();
		this.antoineCoefficients = antoineCoefficients;
	}

	public Vaporization(double a, double b, double c) {
		this(new AntoineCoefficients(a, b, c));
	}
	
	public Vaporization(double temperature) {
		super();
		this.temperature = temperature;
	}
	
	public double getTemperature() {
		if (antoineCoefficients != null) {
			return antoineCoefficients.getBoilingTemperature(1.0);
		}
		return temperature;
	}

	public AntoineCoefficients getAntoineCoefficients() {
		return antoineCoefficients;
	}
	
	/* We can use the vapor pressure to calculate the evaporation rate (Langmuir's):
	 * (mass loss rate)/(unit area) = 
	 *   (vapor pressure - ambient partial pressure)*sqrt((molecular weight)/(2*pi*R*T))
	 */
	public static class AntoineCoefficients {
		private double a, b, c;
		public AntoineCoefficients(double a, double b, double c) {
			this.a = a;
			this.b = b;
			this.c = c;
		}
		public double getVaporPressure(double temperature) {
			return Math.pow(a - b / (c + temperature), 10);
		}
		public double getBoilingTemperature(double pressure) {
			return b / (a - Math.log10(pressure)) - c;
		}
		public double getEvaporationRate(double temperature, double pressure, double molecularWeight) {
			// rate is per unit area, which comes from the pressure units
			return (getVaporPressure(temperature) - pressure) * Math.sqrt(molecularWeight / (2*Math.PI*Constants.R*temperature));
		}
	}

}

@@ -711,283 +711,188 @@
 %0A%09%0A%09
-/* We can use the vapor pressure to calculate the evaporation rate (Langmuir's):%0A%09 * (mass loss rate)/(unit area) = %0A%09 *   (vapor pressure - ambient partial pressure)*sqrt((molecular weight)/(2*pi*R*T))%0A%09 */%0A%09public static class AntoineCoefficients %7B%0A%09%09private double a, b, c
+public static class AntoineCoefficients %7B%0A%09%09private double a, b, c; // units: temperature=K, pressure=bar (need to convert to kPa (=bar/100))%0A%09%09private static int KPA_PER_BAR = 100
 ;%0A%09%09
@@ -1103,16 +1103,30 @@
 re), 10)
+ * KPA_PER_BAR
 ;%0A%09%09%7D%0A%09%09
@@ -1222,19 +1222,58 @@
 sure
-)) - c;%0A%09%09%7D
+ / KPA_PER_BAR)) - c;%0A%09%09%7D%0A%09%09// Langmuir's equation
 %0A%09%09p
@@ -1560,11 +1560,10 @@
 %0A%09%09%7D%0A%09%7D%0A
-%0A
 %7D%0A

fix treatment of units in the Antoine equation (coefficients typically use "bar" for pressure, instead of kPa)