Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip #648

Merged
Merged

wip #648

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/main/java/neqsim/thermo/system/SystemInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -1813,10 +1813,8 @@ public double calcBeta()
* <p>
* initBeta.
* </p>
*
* @return a double
*/
public double initBeta();
public void initBeta();

/**
* <p>
Expand Down
97 changes: 53 additions & 44 deletions src/main/java/neqsim/thermo/system/SystemThermo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> componentNames = new ArrayList<String>();
// protected ArrayList<String> resultArray1 = new ArrayList<String>();
protected String[] CapeOpenProperties11 = {"molecularWeight", "speedOfSound",
Expand All @@ -95,36 +102,39 @@ 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);

/**
* <p>
* Constructor for SystemThermo.
* </p>
*/
public SystemThermo() {
phaseArray = new PhaseInterface[6];
phaseArray = new PhaseInterface[MAX_PHASES];
characterization = new Characterise(this);
interfaceProp = new InterfaceProperties(this);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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++) {
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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} */
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -1846,6 +1851,7 @@ public void initAnalytic(int type) {
}
}
}
this.isInitialized = true;
}

/**
Expand Down Expand Up @@ -1900,6 +1906,7 @@ public void initAnalytic(int type, int phase) {
tmpPhase.setPhaseTypeName("oil");
}
}
this.isInitialized = true;
}

/**
Expand Down Expand Up @@ -2018,6 +2025,7 @@ public void initNumeric(int type, int phasen) {
}
}
}
this.isInitialized = true;
}

/** {@inheritDoc} */
Expand Down Expand Up @@ -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;
}
Expand Down