Skip to content

Commit 0cf54fb

Browse files
authored
feat: Make mixingrule concept generic for phases MixingRuleTypeInterface (#1250)
New Interface CPAMixingRuleType Introduce SuperInterface MixingRuleTypeInterface for EosMixingRuleType and CPAMixingRuleType prepare for future cleaner split between types using eos mixing and cpa mixing
1 parent 2180e83 commit 0cf54fb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+508
-226
lines changed

src/main/java/neqsim/fluidmechanics/flownode/fluidboundary/heatmasstransfercalc/nonequilibriumfluidboundary/NonEquilibriumFluidBoundary.java

-3
Original file line numberDiff line numberDiff line change
@@ -628,8 +628,5 @@ public void solve() {
628628
} while (Math.abs((oldHeatFlux - heatFlux) / heatFlux) > 1e-6 && heatTransferCalc
629629
&& iterInner < 50);
630630
init();
631-
// System.out.println("iterInner " +iterInner + " temp gas " +
632-
// interphaseSystem.getTemperature(0)+ " temp liq " +
633-
// interphaseSystem.getTemperature(1));
634631
}
635632
}

src/main/java/neqsim/fluidmechanics/flownode/fluidboundary/interphasetransportcoefficient/interphasetwophase/stirredcell/InterphaseStirredCellFlow.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ public double calcInterphaseHeatTransferCoefficient(int phaseNum, double prandtl
5959
if (Math.abs(node.getReynoldsNumber()) < 2000) {
6060
return 3.66 / node.getHydraulicDiameter(phaseNum)
6161
* node.getBulkSystem().getPhase(phaseNum).getPhysicalProperties().getConductivity();
62-
}
63-
// if turbulent - use chilton colburn analogy
64-
else {
62+
} else { // if turbulent - use chilton colburn analogy
6563
double temp = node.getBulkSystem().getPhase(phaseNum).getCp()
6664
/ node.getBulkSystem().getPhase(phaseNum).getMolarMass()
6765
/ node.getBulkSystem().getPhase(phaseNum).getNumberOfMolesInPhase()

src/main/java/neqsim/process/equipment/ProcessEquipmentInterface.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ public default boolean needRecalculation() {
8989
* setController.
9090
* </p>
9191
*
92-
* @param controller a {@link neqsim.process.controllerdevice.ControllerDeviceInterface}
93-
* object
92+
* @param controller a {@link neqsim.process.controllerdevice.ControllerDeviceInterface} object
9493
*/
9594
public void setController(ControllerDeviceInterface controller);
9695

@@ -166,8 +165,7 @@ public default SystemInterface getFluid() {
166165
* runConditionAnalysis.
167166
* </p>
168167
*
169-
* @param refExchanger a
170-
* {@link neqsim.process.equipment.ProcessEquipmentInterface} object
168+
* @param refExchanger a {@link neqsim.process.equipment.ProcessEquipmentInterface} object
171169
*/
172170
public void runConditionAnalysis(ProcessEquipmentInterface refExchanger);
173171

@@ -216,10 +214,10 @@ public default SystemInterface getFluid() {
216214

217215
/**
218216
* <p>
219-
* toJson.
217+
* Serializes the Process Equipment along with its state to a JSON string.
220218
* </p>
221219
*
222-
* @return a String
220+
* @return json string.
223221
*/
224222
public String toJson();
225223

src/main/java/neqsim/process/equipment/compressor/CompressorChartAlternativeMapLookupExtrapolate.java

+2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ public ArrayList<Double> getClosestRefSpeeds(double speed) {
6969
/**
7070
* {@inheritDoc}
7171
*
72+
* <p>
7273
* Calculates the polytropic head for a given flow and speed by interpolating or extrapolating
7374
* between reference compressor curves.
75+
* </p>
7476
*/
7577
@Override
7678
public double getPolytropicHead(double flow, double speed) {

src/main/java/neqsim/process/equipment/heatexchanger/MultiStreamHeatExchanger.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -516,9 +516,7 @@ public void run(UUID id) {
516516
// Finalize the setup
517517
run();
518518
return;
519-
}
520-
521-
else {
519+
} else {
522520
// Run all input and output streams to ensure they are up-to-date
523521
for (StreamInterface inStream : inStreams) {
524522
inStream.run(id);

src/main/java/neqsim/process/equipment/pipeline/PipeBeggsAndBrills.java

+13-12
Original file line numberDiff line numberDiff line change
@@ -178,20 +178,21 @@ public void setPipeSpecification(double nominalDiameter, String pipeSec) {
178178
this.nominalDiameter = nominalDiameter;
179179
this.PipeSpecSet = true;
180180

181-
neqsim.util.database.NeqSimDataBase database = new neqsim.util.database.NeqSimDataBase();
182-
java.sql.ResultSet dataSet =
183-
database.getResultSet("SELECT * FROM pipedata where Size='" + nominalDiameter + "'");
184-
try {
185-
if (dataSet.next()) {
186-
this.pipeThickness = Double.parseDouble(dataSet.getString(pipeSpecification)) / 1000;
187-
this.insideDiameter =
188-
(Double.parseDouble(dataSet.getString("OD"))) / 1000 - 2 * this.pipeThickness;
181+
try (neqsim.util.database.NeqSimDataBase database = new neqsim.util.database.NeqSimDataBase()) {
182+
java.sql.ResultSet dataSet =
183+
database.getResultSet("SELECT * FROM pipedata where Size='" + nominalDiameter + "'");
184+
try {
185+
if (dataSet.next()) {
186+
this.pipeThickness = Double.parseDouble(dataSet.getString(pipeSpecification)) / 1000;
187+
this.insideDiameter =
188+
(Double.parseDouble(dataSet.getString("OD"))) / 1000 - 2 * this.pipeThickness;
189+
}
190+
} catch (NumberFormatException e) {
191+
logger.error(e.getMessage());
192+
} catch (SQLException e) {
193+
logger.error(e.getMessage());
189194
}
190-
} catch (NumberFormatException e) {
191-
// TODO Auto-generated catch block
192-
logger.error(e.getMessage());
193195
} catch (SQLException e) {
194-
// TODO Auto-generated catch block
195196
logger.error(e.getMessage());
196197
}
197198
}

src/main/java/neqsim/process/equipment/tank/Tank.java

+26-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package neqsim.process.equipment.tank;
22

33
import java.util.UUID;
4+
import org.apache.logging.log4j.LogManager;
5+
import org.apache.logging.log4j.Logger;
46
import neqsim.process.equipment.ProcessEquipmentBaseClass;
57
import neqsim.process.equipment.mixer.Mixer;
68
import neqsim.process.equipment.stream.Stream;
@@ -20,6 +22,8 @@
2022
public class Tank extends ProcessEquipmentBaseClass {
2123
/** Serialization version UID. */
2224
private static final long serialVersionUID = 1000;
25+
/** Logger object for class. */
26+
static Logger logger = LogManager.getLogger(Tank.class);
2327

2428
SystemInterface thermoSystem;
2529
SystemInterface gasSystem;
@@ -148,14 +152,29 @@ public StreamInterface getLiquid() {
148152
return getLiquidOutStream();
149153
}
150154

151-
/** {@inheritDoc} */
155+
/**
156+
* {@inheritDoc}
157+
*
158+
* <p>
159+
* Calculates the following properties:
160+
* </p>
161+
* <ul>
162+
* <li>steelWallTemperature</li>
163+
* <li>gasOutStream</li>
164+
* <li>liquidOutStream</li>
165+
* <li><code>thermoSystem</code> including properties</li>
166+
* <li>liquidLevel</li>
167+
* <li>liquidVolume</li>
168+
* <li>gasVolume</li>
169+
* </ul>
170+
*/
152171
@Override
153172
public void run(UUID id) {
154173
inletStreamMixer.run(id);
155174
SystemInterface thermoSystem2 = inletStreamMixer.getOutletStream().getThermoSystem().clone();
156175
ThermodynamicOperations ops = new ThermodynamicOperations(thermoSystem2);
157176
ops.VUflash(thermoSystem2.getVolume(), thermoSystem2.getInternalEnergy());
158-
System.out.println("Volume " + thermoSystem2.getVolume() + " internalEnergy "
177+
logger.info("Volume " + thermoSystem2.getVolume() + " internalEnergy "
159178
+ thermoSystem2.getInternalEnergy());
160179
steelWallTemperature = thermoSystem2.getTemperature();
161180
if (thermoSystem2.hasPhaseType("gas")) {
@@ -172,7 +191,7 @@ public void run(UUID id) {
172191
thermoSystem = thermoSystem2.clone();
173192
thermoSystem.setTotalNumberOfMoles(1.0e-10);
174193
thermoSystem.init(1);
175-
System.out.println("number of phases " + thermoSystem.getNumberOfPhases());
194+
logger.info("number of phases " + thermoSystem.getNumberOfPhases());
176195
for (int j = 0; j < thermoSystem.getNumberOfPhases(); j++) {
177196
double relFact = gasVolume / (thermoSystem.getPhase(j).getVolume() * 1.0e-5);
178197
if (j == 1) {
@@ -191,10 +210,10 @@ public void run(UUID id) {
191210
thermoSystem.setBeta(1.0 - 1e-10);
192211
}
193212
thermoSystem.init(3);
194-
System.out.println("moles in separator " + thermoSystem.getNumberOfMoles());
213+
logger.info("moles in separator " + thermoSystem.getNumberOfMoles());
195214
double volume1 = thermoSystem.getVolume();
196-
System.out.println("volume1 bef " + volume1);
197-
System.out.println("beta " + thermoSystem.getBeta());
215+
logger.info("volume1 bef " + volume1);
216+
logger.info("beta " + thermoSystem.getBeta());
198217

199218
if (thermoSystem2.getNumberOfPhases() == 2) {
200219
liquidLevel = thermoSystem.getPhase(1).getVolume() * 1e-5 / (liquidVolume + gasVolume);
@@ -205,7 +224,7 @@ public void run(UUID id) {
205224
getLiquidLevel() * 3.14 / 4.0 * separatorDiameter * separatorDiameter * separatorLength;
206225
gasVolume = (1.0 - getLiquidLevel()) * 3.14 / 4.0 * separatorDiameter * separatorDiameter
207226
* separatorLength;
208-
System.out.println("moles out" + liquidOutStream.getThermoSystem().getTotalNumberOfMoles());
227+
logger.info("moles out" + liquidOutStream.getThermoSystem().getTotalNumberOfMoles());
209228

210229
setCalculationIdentifier(id);
211230
}

src/main/java/neqsim/thermo/component/Component.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ public abstract class Component implements ComponentInterface {
5050
/** Mole fraction of Component in Phase. */
5151
protected double x = 0;
5252
/**
53-
* Number of moles of Component in System. <code>numberOfMoles = totalNumberOfMoles * z</code>.
53+
* Number of moles of Component in System. Ideally
54+
* <code>numberOfMoles = totalNumberOfMoles * z</code>.
5455
*/
5556
protected double numberOfMoles = 0.0;
56-
/** Number of moles of Component in Phase. <code>totalNumberOfMoles * x * beta</code>. */
57+
/** Number of moles of Component in Phase. Ideally <code>totalNumberOfMoles * x * beta</code>. */
5758
protected double numberOfMolesInPhase = 0.0;
5859
protected double K;
5960

src/main/java/neqsim/thermo/component/ComponentHydrate.java

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public class ComponentHydrate extends Component {
4040
private double sphericalCoreRadiusHydrate = 0.0;
4141
private double lennardJonesEnergyParameterHydrate = 0.0;
4242
private double lennardJonesMolecularDiameterHydrate = 0.0;
43+
44+
/** Reference phase containing only this single component, i.e., mixing rules are not relevant. */
4345
PhaseInterface refPhase = null;
4446

4547
/**
@@ -659,6 +661,7 @@ public void setSolidRefFluidPhase(PhaseInterface phase) {
659661
refPhase.setTemperature(273.0);
660662
refPhase.setPressure(1.0);
661663
refPhase.addComponent("water", 10.0, 10.0, 0);
664+
refPhase.setMixingRule(null);
662665
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 0, PhaseType.GAS, 1.0);
663666
} catch (Exception ex) {
664667
logger.error("error occured", ex);

src/main/java/neqsim/thermo/component/ComponentSolid.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ public class ComponentSolid extends ComponentSrk {
3030
double soldens = 0.0;
3131
boolean CCequation = true;
3232
boolean AntoineSolidequation = true;
33-
PhaseInterface refPhase = null;
3433
double pureCompFug = 0.0;
3534

35+
/** Reference phase containing only this single component, i.e., mixing rules are not relevant. */
36+
PhaseInterface refPhase = null;
37+
3638
/**
3739
* <p>
3840
* Constructor for ComponentSolid.
@@ -257,6 +259,7 @@ public void setSolidRefFluidPhase(PhaseInterface phase) {
257259
refPhase.getComponent(componentName)
258260
.setAttractiveTerm(phase.getComponent(componentName).getAttractiveTermNumber());
259261
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 0, PhaseType.GAS, 1.0);
262+
refPhase.setMixingRule(null);
260263
// }
261264
} catch (Exception ex) {
262265
logger.error("error occured", ex);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package neqsim.thermo.mixingrule;
2+
3+
import neqsim.util.exception.InvalidInputException;
4+
5+
/**
6+
* Types of CPAMixingRule, relating to different kind of mixing rules relevant for CPA type phases.
7+
* Available types are:
8+
* <ul>
9+
* <li>CPA_RADOCH - 1 -</li>
10+
* <li>PCSAFTA_RADOCH - 3 -</li>
11+
* </ul>
12+
*
13+
* @author ASMF
14+
*/
15+
public enum CPAMixingRuleType implements MixingRuleTypeInterface {
16+
CPA_RADOCH(1), PCSAFTA_RADOCH(3);
17+
18+
/** Holder for old style integer pt. */
19+
private final int value;
20+
/** Holder for old style string physical property description. */
21+
22+
// We know we'll never mutate this, so we can keep
23+
// a local copy for fast lookup in forName
24+
private static final CPAMixingRuleType[] copyOfValues = values();
25+
26+
/**
27+
* Constructor for CPAMixingRuleType enum.
28+
*
29+
* @param value Numeric value index for mixing rule
30+
*/
31+
private CPAMixingRuleType(int value) {
32+
this.value = value;
33+
}
34+
35+
/**
36+
* Getter for property value.
37+
*
38+
* @return Numeric index of phase type
39+
*/
40+
@Deprecated
41+
public int getValue() {
42+
return this.value;
43+
}
44+
45+
/**
46+
* Get CPAMixingRuleType by name.
47+
*
48+
* @param name Name to get CPAMixingRuleType for.
49+
* @return CPAMixingRuleType object
50+
*/
51+
public static CPAMixingRuleType byName(String name) {
52+
for (CPAMixingRuleType mr : copyOfValues) {
53+
if (mr.name().equals(name.toUpperCase())) {
54+
return mr;
55+
}
56+
}
57+
throw new RuntimeException(
58+
new InvalidInputException("CPAMixingRuleType", "byName", "name", "is not valid."));
59+
}
60+
61+
/**
62+
* Get CPAMixingRuleType by value.
63+
*
64+
* @param value Value to get CPAMixingRuleType for.
65+
* @return CPAMixingRuleType object
66+
*/
67+
public static CPAMixingRuleType byValue(int value) {
68+
for (CPAMixingRuleType mr : copyOfValues) {
69+
if (mr.getValue() == (value)) {
70+
return mr;
71+
}
72+
}
73+
throw new RuntimeException(
74+
new InvalidInputException("CPAMixingRuleType", "byValue", "value", "is not valid."));
75+
}
76+
}

src/main/java/neqsim/thermo/mixingrule/CPAMixingRules.java

+28-6
Original file line numberDiff line numberDiff line change
@@ -617,15 +617,37 @@ public CPAMixingRulesInterface getMixingRule(int mr) {
617617
if (mr == 1) {
618618
mixingRuleName = "CPA_Radoch";
619619
return new CPA_Radoch();
620-
} else if (mr == 2) {
621-
mixingRuleName = "CPA_Radoch";
622-
return new CPA_Radoch();
623620
} else if (mr == 3) {
624621
mixingRuleName = "PCSAFTa_Radoch";
625622
return new PCSAFTa_Radoch();
626-
} else {
627-
mixingRuleName = "CPA_Radoch";
628-
return new CPA_Radoch();
623+
}
624+
throw new RuntimeException(
625+
new neqsim.util.exception.InvalidInputException(this, "getMixingRule", "mr"));
626+
}
627+
628+
/**
629+
* <p>
630+
* getMixingRule.
631+
* </p>
632+
*
633+
* @param mr a int
634+
* @return a {@link neqsim.thermo.mixingrule.CPAMixingRulesInterface} object
635+
*/
636+
public CPAMixingRulesInterface getMixingRule(MixingRuleTypeInterface mr) {
637+
if (!CPAMixingRuleType.class.isInstance(mr)) {
638+
throw new RuntimeException(
639+
new neqsim.util.exception.InvalidInputException(this, "setMixingRule", "mr"));
640+
}
641+
CPAMixingRuleType cmr = (CPAMixingRuleType) mr;
642+
switch (cmr) {
643+
case CPA_RADOCH:
644+
mixingRuleName = "CPA_Radoch";
645+
return new CPA_Radoch();
646+
case PCSAFTA_RADOCH:
647+
mixingRuleName = "PCSAFTa_Radoch";
648+
return new PCSAFTa_Radoch();
649+
default:
650+
return new CPA_Radoch();
629651
}
630652
}
631653

src/main/java/neqsim/thermo/mixingrule/EosMixingRuleType.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
* @author ASMF
2323
*/
24-
public enum EosMixingRuleType {
24+
public enum EosMixingRuleType implements MixingRuleTypeInterface {
2525
NO(1), CLASSIC(2), CLASSIC_HV(3), HV(4), WS(5), CPA_MIX(7), CLASSIC_T(8), CLASSIC_T_CPA(
2626
9), CLASSIC_TX_CPA(10);
2727

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package neqsim.thermo.mixingrule;
2+
3+
/**
4+
* Dummy Interface to allow Phase object to keep either CPA or EosMixingRuleType
5+
*/
6+
public interface MixingRuleTypeInterface {
7+
8+
9+
public int getValue();
10+
}

0 commit comments

Comments
 (0)