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

refact: reuse code from constructor in init++ #747

Merged
merged 2 commits into from
Jun 19, 2023
Merged
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
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