|
| 1 | +/* |
| 2 | + * TVflash.java |
| 3 | + * |
| 4 | + * Created on 8. mars 2001, 10:56 |
| 5 | + */ |
| 6 | + |
| 7 | +package neqsim.thermodynamicOperations.flashOps; |
| 8 | + |
| 9 | +import neqsim.thermo.system.SystemInterface; |
| 10 | + |
| 11 | +/** |
| 12 | + * <p> |
| 13 | + * TVflash class. |
| 14 | + * </p> |
| 15 | + * |
| 16 | + * @author even solbraa |
| 17 | + * @version $Id: $Id |
| 18 | + */ |
| 19 | +public class TVfractionFlash extends Flash { |
| 20 | + private static final long serialVersionUID = 1000; |
| 21 | + |
| 22 | + double Vfractionspec = 0; |
| 23 | + Flash tpFlash; |
| 24 | + |
| 25 | + /** |
| 26 | + * <p> |
| 27 | + * Constructor for TVflash. |
| 28 | + * </p> |
| 29 | + * |
| 30 | + * @param system a {@link neqsim.thermo.system.SystemInterface} object |
| 31 | + * @param Vfractionspec a double |
| 32 | + */ |
| 33 | + public TVfractionFlash(SystemInterface system, double Vfractionspec) { |
| 34 | + this.system = system; |
| 35 | + this.tpFlash = new TPflash(system); |
| 36 | + this.Vfractionspec = Vfractionspec; |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * <p> |
| 41 | + * calcdQdVP. |
| 42 | + * </p> |
| 43 | + * |
| 44 | + * @return a double |
| 45 | + */ |
| 46 | + public double calcdQdVdP() { |
| 47 | + double dQdVP = 0.0; |
| 48 | + dQdVP = 1.0 / system.getPhase(i).getdPdVTn() / system.getVolume(); |
| 49 | + return dQdVP; |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * <p> |
| 54 | + * calcdQdV. |
| 55 | + * </p> |
| 56 | + * |
| 57 | + * @return a double |
| 58 | + */ |
| 59 | + public double calcdQdV() { |
| 60 | + double dQ = system.getPhase(0).getVolume() / system.getVolume() - Vfractionspec; |
| 61 | + return dQ; |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * <p> |
| 66 | + * solveQ. |
| 67 | + * </p> |
| 68 | + * |
| 69 | + * @return a double |
| 70 | + */ |
| 71 | + public double solveQ() { |
| 72 | + double oldPres = system.getPressure(); |
| 73 | + double nyPres = system.getPressure(); |
| 74 | + double iterations = 1; |
| 75 | + double error = 100.0; |
| 76 | + double numericdQdVdP = 0.0; |
| 77 | + double dQdV = 0.0; |
| 78 | + double olddQdV = 0.0; |
| 79 | + double pressureStep = 1.0; |
| 80 | + do { |
| 81 | + |
| 82 | + iterations++; |
| 83 | + oldPres = nyPres; |
| 84 | + system.init(3); |
| 85 | + double dQDVdP = calcdQdVdP(); |
| 86 | + |
| 87 | + numericdQdVdP = (calcdQdV() - olddQdV) / pressureStep; |
| 88 | + |
| 89 | + if (iterations < 5) { |
| 90 | + nyPres = oldPres - 1.0 / 10.0 * calcdQdV() / dQDVdP; |
| 91 | + } else { |
| 92 | + nyPres = oldPres - 1.0 * calcdQdV() / numericdQdVdP; |
| 93 | + } |
| 94 | + if (nyPres <= 0.0) { |
| 95 | + nyPres = oldPres * 0.9; |
| 96 | + } |
| 97 | + if (nyPres >= oldPres * 2) { |
| 98 | + nyPres = oldPres * 2.0; |
| 99 | + } |
| 100 | + pressureStep = nyPres - oldPres; |
| 101 | + |
| 102 | + olddQdV = calcdQdV(); |
| 103 | + system.setPressure(nyPres); |
| 104 | + tpFlash.run(); |
| 105 | + error = Math.abs(calcdQdV()) / system.getVolume(); |
| 106 | + // System.out.println("error " + error + "iteration " + iterations + " dQdv " + calcdQdV() |
| 107 | + // + " new pressure " + nyPres + " error " + Math.abs((nyPres - oldPres) / (nyPres)) |
| 108 | + // + " numberofphases " + system.getNumberOfPhases() + " dQDVdP " + dQDVdP + " dQDVdPnumeric" |
| 109 | + // + numericdQdVdP); |
| 110 | + |
| 111 | + } while ((error > 1e-9 && iterations < 200) || iterations < 3); |
| 112 | + return nyPres; |
| 113 | + } |
| 114 | + |
| 115 | + /** {@inheritDoc} */ |
| 116 | + @Override |
| 117 | + public void run() { |
| 118 | + tpFlash.run(); |
| 119 | + // System.out.println("enthalpy: " + system.getEnthalpy()); |
| 120 | + solveQ(); |
| 121 | + |
| 122 | + // System.out.println("volume: " + system.getVolume()); |
| 123 | + // System.out.println("Temperature: " + system.getTemperature()); |
| 124 | + } |
| 125 | + |
| 126 | + /** {@inheritDoc} */ |
| 127 | + @Override |
| 128 | + public org.jfree.chart.JFreeChart getJFreeChart(String name) { |
| 129 | + return null; |
| 130 | + } |
| 131 | +} |
0 commit comments