Skip to content

Commit

Permalink
refact: reuse code from constructor in init++ (#747)
Browse files Browse the repository at this point in the history
  • Loading branch information
asmfstatoil authored Jun 19, 2023
1 parent c9974cb commit 051fd3a
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public void addStream(StreamInterface newStream) {
if (numberOfInputStreams == 0) {
mixedStream = (Stream) streams.get(0).clone();
mixedStream.getThermoSystem().setNumberOfPhases(2);
mixedStream.getThermoSystem().reInitPhaseType();
mixedStream.getThermoSystem().init(0);
mixedStream.getThermoSystem().init(3);
}
Expand Down Expand Up @@ -329,7 +328,6 @@ public void run(UUID id) {
// double yN = gasInStream.getThermoSystem().getPhase(0).getComponent("water").getx();
mixedStream.setThermoSystem((streams.get(0).getThermoSystem().clone()));
mixedStream.getThermoSystem().setNumberOfPhases(2);
mixedStream.getThermoSystem().reInitPhaseType();
mixedStream.getThermoSystem().init(0);
mixStream();
// System.out.println("feed total number of water " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public void addStream(StreamInterface newStream) {
if (numberOfInputStreams == 0) {
mixedStream = (Stream) streams.get(0).clone();
mixedStream.getThermoSystem().setNumberOfPhases(2);
mixedStream.getThermoSystem().reInitPhaseType();
mixedStream.getThermoSystem().init(0);
mixedStream.getThermoSystem().init(3);
}
Expand Down Expand Up @@ -308,7 +307,6 @@ public void run(UUID id) {
double absorptionEffiency = 0.0;
mixedStream.setThermoSystem((streams.get(0).getThermoSystem().clone()));
mixedStream.getThermoSystem().setNumberOfPhases(2);
mixedStream.getThermoSystem().reInitPhaseType();
mixedStream.getThermoSystem().init(0);
mixStream();
double enthalpy = calcMixStreamEnthalpy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ public void run(UUID id) {
ThermodynamicOperations testOps = new ThermodynamicOperations(thermoSystem2);
if (streams.size() > 0) {
mixedStream.getThermoSystem().setNumberOfPhases(2);
mixedStream.getThermoSystem().reInitPhaseType();
mixedStream.getThermoSystem().init(0);

mixStream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public void run(UUID id) {
if (streams.size() > 0) {
// mixedStream.getThermoSystem().setSolidPhaseCheck("CO2");
mixedStream.getThermoSystem().setNumberOfPhases(2);
mixedStream.getThermoSystem().reInitPhaseType();
mixedStream.getThermoSystem().init(0);

mixStream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public void addStream(StreamInterface newStream) {
if (getNumberOfInputStreams() == 0) {
mixedStream = (Stream) streams.get(0).clone(); // cloning the first stream
// mixedStream.getThermoSystem().setNumberOfPhases(2);
// mixedStream.getThermoSystem().reInitPhaseType();
// mixedStream.getThermoSystem().init(0);
// mixedStream.getThermoSystem().init(3);
}
Expand Down Expand Up @@ -237,7 +236,6 @@ public void run(UUID id) {
ThermodynamicOperations testOps = new ThermodynamicOperations(thermoSystem2);
if (streams.size() > 0) {
mixedStream.getThermoSystem().setNumberOfPhases(2);
mixedStream.getThermoSystem().reInitPhaseType();
mixedStream.getThermoSystem().init(0);

mixStream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ public void addStream(StreamInterface newStream) {
if (numberOfInputStreams == 0) {
mixedStream = streams.get(0).clone();
// mixedStream.getThermoSystem().setNumberOfPhases(2);
// mixedStream.getThermoSystem().reInitPhaseType();
// mixedStream.getThermoSystem().init(0);
// mixedStream.getThermoSystem().init(3);
}
Expand Down
39 changes: 21 additions & 18 deletions src/main/java/neqsim/thermo/system/SystemThermo.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ abstract class SystemThermo implements SystemInterface {
* Array of indexes to phaseArray keeping track of the creation order of the phases where 0 is the
* first created phase and the lowest number is the phase created last.
*/
protected int[] phaseIndex = {0, 1, 2, 3, 4, 5};
protected int[] phaseIndex;
/**
* Array containing all phases of System. NB! Phases are reorered according to density, use
* phaseIndex to keep track of the creation order.
Expand Down Expand Up @@ -146,13 +146,7 @@ public SystemThermo() {
characterization = new Characterise(this);
interfaceProp = new InterfaceProperties(this);

reInitPhaseType();
phaseType[4] = phaseType[3];
phaseType[5] = phaseType[3];

for (int i = 0; i < MAX_PHASES; i++) {
beta[i] = 1.0;
}
reInitPhaseInformation();
}

/**
Expand Down Expand Up @@ -1804,21 +1798,14 @@ public void init(int type, int phase) {
*/
public void initAnalytic(int type) {
if (type == 0) {
// TODO: should actually clear all entries in arrays?
setNumberOfPhases(getMaxNumberOfPhases());
for (int i = 0; i < numberOfPhases; i++) {
phaseType[i] = PhaseType.byValue(0);
beta[i] = 1.0;
phaseIndex[i] = i;
}
phaseType[0] = PhaseType.byValue(1);
for (int i = 0; i < numberOfPhases; i++) {
reInitPhaseInformation();

for (int i = 0; i < getMaxNumberOfPhases(); i++) {
if (isPhase(i)) {
getPhase(i).init(getTotalNumberOfMoles(), numberOfComponents, type,
phaseType[phaseIndex[i]], beta[phaseIndex[i]]);
}
}
// TODO: reduce maxnumberofphases as well? Some sort of multiphase reset here.
setNumberOfPhases(2);
} else if (type == 1) {
for (int i = 0; i < numberOfPhases; i++) {
Expand Down Expand Up @@ -2979,6 +2966,22 @@ public void reInitPhaseType() {
// TODO: why stop at 3 and not iterate through MAX_PHASES elements?
}

/**
* Re-initialize phasetype, beta and phaseindex arrays, same initialization which is used in
* constructor.
*/
public void reInitPhaseInformation() {
reInitPhaseType();
phaseType[4] = phaseType[3];
phaseType[5] = phaseType[3];

for (int i = 0; i < MAX_PHASES; i++) {
beta[i] = 1.0;
}

phaseIndex = new int[] {0, 1, 2, 3, 4, 5};
}

/** {@inheritDoc} */
@Override
public final boolean doSolidPhaseCheck() {
Expand Down

0 comments on commit 051fd3a

Please sign in to comment.