diff --git a/src/main/java/neqsim/thermo/system/SystemInterface.java b/src/main/java/neqsim/thermo/system/SystemInterface.java index ff9fa3b18..c8abf0c46 100644 --- a/src/main/java/neqsim/thermo/system/SystemInterface.java +++ b/src/main/java/neqsim/thermo/system/SystemInterface.java @@ -1813,10 +1813,8 @@ public double calcBeta() *

* initBeta. *

- * - * @return a double */ - public double initBeta(); + public void initBeta(); /** *

diff --git a/src/main/java/neqsim/thermo/system/SystemThermo.java b/src/main/java/neqsim/thermo/system/SystemThermo.java index 30cb69a55..62b5ef78b 100644 --- a/src/main/java/neqsim/thermo/system/SystemThermo.java +++ b/src/main/java/neqsim/thermo/system/SystemThermo.java @@ -39,36 +39,43 @@ /* * This is the base class of the System classes. */ - abstract class SystemThermo implements SystemInterface { private static final long serialVersionUID = 1000; + static Logger logger = LogManager.getLogger(SystemThermo.class); + // Class variables + private static final int MAX_PHASES = 6; - private boolean implementedTemperatureDeriativesofFugacity = true; - private boolean implementedPressureDeriativesofFugacity = true; - private boolean implementedCompositionDeriativesofFugacity = true; - protected double criticalTemperature = 0; - protected String[][] resultTable = null; - boolean isInitialized = false; + // Object metadata protected String fluidInfo = "No Information Available"; protected String fluidName = "DefaultName"; - protected String modelName = "Default"; + // Initialization + boolean isInitialized = false; protected boolean numericDerivatives = false; + protected int initType = 3; + + private boolean implementedTemperatureDeriativesofFugacity = true; + private boolean implementedPressureDeriativesofFugacity = true; + private boolean implementedCompositionDeriativesofFugacity = true; + protected double criticalTemperature = 0; + protected String[][] resultTable = null; protected boolean allowPhaseShift = true; private boolean useTVasIndependentVariables = false; protected double criticalPressure = 0; private double totalNumberOfMoles = 0; + + // todo: componentNameTag is not working yet, a kind of alias-postfix for Components from this + // system that will be passed on to other systems. used to find originator of specific components + // or public String componentNameTag = ""; protected neqsim.thermo.characterization.WaxCharacterise waxCharacterisation = null; - protected double[] beta = new double[6]; + protected double[] beta = new double[MAX_PHASES]; protected int a; - protected int initType = 3; - private ArrayList componentNames = new ArrayList(); // protected ArrayList resultArray1 = new ArrayList(); protected String[] CapeOpenProperties11 = {"molecularWeight", "speedOfSound", @@ -95,28 +102,31 @@ abstract class SystemThermo implements SystemInterface { protected int numberOfPhases = 2; public int maxNumberOfPhases = 2; protected int attractiveTermNumber = 0; - protected int phase = 2; - protected int onePhaseType = 1; // 0 - liquid 1 - gas + + // phasetype to be enum protected int[] phaseType = {1, 0, 0, 0, 0, 0}; + + // Index refers to position in phaseArray. First value of phaseIndex is the phase which is created + // first and the last is the phase created last. protected int[] phaseIndex = {0, 1, 2, 3, 4, 5}; + + // All phases of System. Flashes reorders phaseArray by density. + protected PhaseInterface[] phaseArray; + protected ChemicalReactionOperations chemicalReactionOperations = null; private int mixingRule = 1; protected boolean chemicalSystem = false; protected boolean solidPhaseCheck = false; - protected boolean multiPhaseCheck = false; - protected boolean hydrateCheck = false; protected boolean checkStability = true; - protected PhaseInterface[] phaseArray; public neqsim.thermo.characterization.Characterise characterization = null; protected neqsim.standards.StandardInterface standard = null; protected InterphasePropertiesInterface interfaceProp = null; private boolean multiphaseWaxCheck = false; private boolean forcePhaseTypes = false; - static Logger logger = LogManager.getLogger(SystemThermo.class); /** *

@@ -124,7 +134,7 @@ abstract class SystemThermo implements SystemInterface { *

*/ public SystemThermo() { - phaseArray = new PhaseInterface[6]; + phaseArray = new PhaseInterface[MAX_PHASES]; characterization = new Characterise(this); interfaceProp = new InterfaceProperties(this); } @@ -178,8 +188,6 @@ public void clearAll() { phaseType[1] = 0; numberOfComponents = 0; setNumberOfPhases(2); - phase = 2; - onePhaseType = 1; beta[0] = 1.0; beta[1] = 1.0; beta[2] = 1.0; @@ -849,7 +857,7 @@ public void addTBPfraction(String componentName, double numberOfMoles, double mo // // refSystem.setPressure(1.01325); // // refSystem.init(1); // //refSystem.initPhysicalProperties(); - // // APIdens - refSystem.getPhase(1).getPhysicalProperties().getDensity();; + // // APIdens - refSystem.getPhase(1).getPhysicalProperties().getDensity(); // sammenligne med API-standard for tetthet - og sette Penloux dt } catch (Exception ex) { logger.error("error", ex); @@ -993,7 +1001,7 @@ public void addTBPfraction(String componentName, double numberOfMoles, double mo // // refSystem.setPressure(1.01325); // // refSystem.init(1); // // refSystem.initPhysicalProperties(); - // // APIdens - refSystem.getPhase(1).getPhysicalProperties().getDensity();; + // // APIdens - refSystem.getPhase(1).getPhysicalProperties().getDensity(); // // sammenligne med API-standard for tetthet - og sette Penloux dt } catch (Exception ex) { logger.error("error", ex); @@ -1394,7 +1402,7 @@ public final double calcBeta() throws neqsim.util.exception.IsNaNException, double maxBeta = 1.0 - tolerance; double g0 = -1.0; double g1 = 1.0; - nybeta = beta[0]; + nybeta = this.beta[0]; betal = 1.0 - nybeta; for (i = 0; i < numberOfComponents; i++) { @@ -1411,14 +1419,14 @@ public final double calcBeta() throws neqsim.util.exception.IsNaNException, } if (g0 < 0) { - beta[1] = 1.0 - tolerance; - beta[0] = tolerance; - return beta[0]; + this.beta[1] = 1.0 - tolerance; + this.beta[0] = tolerance; + return this.beta[0]; } if (g1 > 0) { - beta[1] = tolerance; - beta[0] = 1.0 - tolerance; - return beta[0]; + this.beta[1] = tolerance; + this.beta[0] = 1.0 - tolerance; + return this.beta[0]; } nybeta = (minBeta + maxBeta) / 2.0; @@ -1525,18 +1533,18 @@ public final double calcBeta() throws neqsim.util.exception.IsNaNException, // System.out.println("beta: " + nybeta + " iterations: " + iterations); if (nybeta <= tolerance) { - phase = 1; + // this.phase = 1; nybeta = tolerance; } else if (nybeta >= 1.0 - tolerance) { - phase = 0; + // this.phase = 0; nybeta = 1.0 - tolerance; // superheated vapour } else { - phase = 2; + // this.phase = 2; } // two-phase liquid-gas - beta[0] = nybeta; - beta[1] = 1.0 - nybeta; + this.beta[0] = nybeta; + this.beta[1] = 1.0 - nybeta; if (iterations >= maxIterations) { throw new neqsim.util.exception.TooManyIterationsException(this, "calcBeta", maxIterations); @@ -1548,17 +1556,16 @@ public final double calcBeta() throws neqsim.util.exception.IsNaNException, */ throw new neqsim.util.exception.IsNaNException(this, "calcBeta", "beta"); } - return beta[0]; + return this.beta[0]; } /** {@inheritDoc} */ @Override - public final double initBeta() { + public final void initBeta() { for (int i = 0; i < numberOfPhases; i++) { - beta[phaseIndex[i]] = getPhase(i).getNumberOfMolesInPhase() / getTotalNumberOfMoles(); + this.beta[phaseIndex[i]] = getPhase(i).getNumberOfMolesInPhase() / getTotalNumberOfMoles(); // System.out.println("beta " + beta[i]); } - return beta[phaseIndex[0]]; } /** {@inheritDoc} */ @@ -1726,8 +1733,7 @@ public boolean hasSolidPhase() { /** {@inheritDoc} */ @Override public void init(int type) { - isInitialized = true; - if (numericDerivatives) { + if (this.numericDerivatives) { initNumeric(type); } else { initAnalytic(type); @@ -1737,8 +1743,7 @@ public void init(int type) { /** {@inheritDoc} */ @Override public void init(int type, int phase) { - isInitialized = true; - if (numericDerivatives) { + if (this.numericDerivatives) { initNumeric(type, phase); } else { initAnalytic(type, phase); @@ -1846,6 +1851,7 @@ public void initAnalytic(int type) { } } } + this.isInitialized = true; } /** @@ -1900,6 +1906,7 @@ public void initAnalytic(int type, int phase) { tmpPhase.setPhaseTypeName("oil"); } } + this.isInitialized = true; } /** @@ -2018,6 +2025,7 @@ public void initNumeric(int type, int phasen) { } } } + this.isInitialized = true; } /** {@inheritDoc} */ @@ -4770,10 +4778,11 @@ public double[] getMolarRate() { /** {@inheritDoc} */ @Override public double[] getMolarComposition() { - double[] comp = new double[getPhase(0).getNumberOfComponents()]; + PhaseInterface phase = this.getPhase(0); + double[] comp = new double[phase.getNumberOfComponents()]; for (int compNumb = 0; compNumb < numberOfComponents; compNumb++) { - comp[compNumb] = getPhase(0).getComponent(compNumb).getz(); + comp[compNumb] = phase.getComponent(compNumb).getz(); } return comp; }