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: MixingRuleTypeInterface #1250

Merged
merged 4 commits into from
Jan 11, 2025
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 @@ -628,8 +628,5 @@ public void solve() {
} while (Math.abs((oldHeatFlux - heatFlux) / heatFlux) > 1e-6 && heatTransferCalc
&& iterInner < 50);
init();
// System.out.println("iterInner " +iterInner + " temp gas " +
// interphaseSystem.getTemperature(0)+ " temp liq " +
// interphaseSystem.getTemperature(1));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ public double calcInterphaseHeatTransferCoefficient(int phaseNum, double prandtl
if (Math.abs(node.getReynoldsNumber()) < 2000) {
return 3.66 / node.getHydraulicDiameter(phaseNum)
* node.getBulkSystem().getPhase(phaseNum).getPhysicalProperties().getConductivity();
}
// if turbulent - use chilton colburn analogy
else {
} else { // if turbulent - use chilton colburn analogy
double temp = node.getBulkSystem().getPhase(phaseNum).getCp()
/ node.getBulkSystem().getPhase(phaseNum).getMolarMass()
/ node.getBulkSystem().getPhase(phaseNum).getNumberOfMolesInPhase()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ public default boolean needRecalculation() {
* setController.
* </p>
*
* @param controller a {@link neqsim.process.controllerdevice.ControllerDeviceInterface}
* object
* @param controller a {@link neqsim.process.controllerdevice.ControllerDeviceInterface} object
*/
public void setController(ControllerDeviceInterface controller);

Expand Down Expand Up @@ -166,8 +165,7 @@ public default SystemInterface getFluid() {
* runConditionAnalysis.
* </p>
*
* @param refExchanger a
* {@link neqsim.process.equipment.ProcessEquipmentInterface} object
* @param refExchanger a {@link neqsim.process.equipment.ProcessEquipmentInterface} object
*/
public void runConditionAnalysis(ProcessEquipmentInterface refExchanger);

Expand Down Expand Up @@ -216,10 +214,10 @@ public default SystemInterface getFluid() {

/**
* <p>
* toJson.
* Serializes the Process Equipment along with its state to a JSON string.
* </p>
*
* @return a String
* @return json string.
*/
public String toJson();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ public ArrayList<Double> getClosestRefSpeeds(double speed) {
/**
* {@inheritDoc}
*
* <p>
* Calculates the polytropic head for a given flow and speed by interpolating or extrapolating
* between reference compressor curves.
* </p>
*/
@Override
public double getPolytropicHead(double flow, double speed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,7 @@ public void run(UUID id) {
// Finalize the setup
run();
return;
}

else {
} else {
// Run all input and output streams to ensure they are up-to-date
for (StreamInterface inStream : inStreams) {
inStream.run(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,20 +178,21 @@ public void setPipeSpecification(double nominalDiameter, String pipeSec) {
this.nominalDiameter = nominalDiameter;
this.PipeSpecSet = true;

neqsim.util.database.NeqSimDataBase database = new neqsim.util.database.NeqSimDataBase();
java.sql.ResultSet dataSet =
database.getResultSet("SELECT * FROM pipedata where Size='" + nominalDiameter + "'");
try {
if (dataSet.next()) {
this.pipeThickness = Double.parseDouble(dataSet.getString(pipeSpecification)) / 1000;
this.insideDiameter =
(Double.parseDouble(dataSet.getString("OD"))) / 1000 - 2 * this.pipeThickness;
try (neqsim.util.database.NeqSimDataBase database = new neqsim.util.database.NeqSimDataBase()) {
java.sql.ResultSet dataSet =
database.getResultSet("SELECT * FROM pipedata where Size='" + nominalDiameter + "'");
try {
if (dataSet.next()) {
this.pipeThickness = Double.parseDouble(dataSet.getString(pipeSpecification)) / 1000;
this.insideDiameter =
(Double.parseDouble(dataSet.getString("OD"))) / 1000 - 2 * this.pipeThickness;
}
} catch (NumberFormatException e) {
logger.error(e.getMessage());
} catch (SQLException e) {
logger.error(e.getMessage());
}
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
logger.error(e.getMessage());
} catch (SQLException e) {
// TODO Auto-generated catch block
logger.error(e.getMessage());
}
}
Expand Down
33 changes: 26 additions & 7 deletions src/main/java/neqsim/process/equipment/tank/Tank.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package neqsim.process.equipment.tank;

import java.util.UUID;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import neqsim.process.equipment.ProcessEquipmentBaseClass;
import neqsim.process.equipment.mixer.Mixer;
import neqsim.process.equipment.stream.Stream;
Expand All @@ -20,6 +22,8 @@
public class Tank extends ProcessEquipmentBaseClass {
/** Serialization version UID. */
private static final long serialVersionUID = 1000;
/** Logger object for class. */
static Logger logger = LogManager.getLogger(Tank.class);

SystemInterface thermoSystem;
SystemInterface gasSystem;
Expand Down Expand Up @@ -148,14 +152,29 @@ public StreamInterface getLiquid() {
return getLiquidOutStream();
}

/** {@inheritDoc} */
/**
* {@inheritDoc}
*
* <p>
* Calculates the following properties:
* </p>
* <ul>
* <li>steelWallTemperature</li>
* <li>gasOutStream</li>
* <li>liquidOutStream</li>
* <li><code>thermoSystem</code> including properties</li>
* <li>liquidLevel</li>
* <li>liquidVolume</li>
* <li>gasVolume</li>
* </ul>
*/
@Override
public void run(UUID id) {
inletStreamMixer.run(id);
SystemInterface thermoSystem2 = inletStreamMixer.getOutletStream().getThermoSystem().clone();
ThermodynamicOperations ops = new ThermodynamicOperations(thermoSystem2);
ops.VUflash(thermoSystem2.getVolume(), thermoSystem2.getInternalEnergy());
System.out.println("Volume " + thermoSystem2.getVolume() + " internalEnergy "
logger.info("Volume " + thermoSystem2.getVolume() + " internalEnergy "
+ thermoSystem2.getInternalEnergy());
steelWallTemperature = thermoSystem2.getTemperature();
if (thermoSystem2.hasPhaseType("gas")) {
Expand All @@ -172,7 +191,7 @@ public void run(UUID id) {
thermoSystem = thermoSystem2.clone();
thermoSystem.setTotalNumberOfMoles(1.0e-10);
thermoSystem.init(1);
System.out.println("number of phases " + thermoSystem.getNumberOfPhases());
logger.info("number of phases " + thermoSystem.getNumberOfPhases());
for (int j = 0; j < thermoSystem.getNumberOfPhases(); j++) {
double relFact = gasVolume / (thermoSystem.getPhase(j).getVolume() * 1.0e-5);
if (j == 1) {
Expand All @@ -191,10 +210,10 @@ public void run(UUID id) {
thermoSystem.setBeta(1.0 - 1e-10);
}
thermoSystem.init(3);
System.out.println("moles in separator " + thermoSystem.getNumberOfMoles());
logger.info("moles in separator " + thermoSystem.getNumberOfMoles());
double volume1 = thermoSystem.getVolume();
System.out.println("volume1 bef " + volume1);
System.out.println("beta " + thermoSystem.getBeta());
logger.info("volume1 bef " + volume1);
logger.info("beta " + thermoSystem.getBeta());

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

setCalculationIdentifier(id);
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/neqsim/thermo/component/Component.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ public abstract class Component implements ComponentInterface {
/** Mole fraction of Component in Phase. */
protected double x = 0;
/**
* Number of moles of Component in System. <code>numberOfMoles = totalNumberOfMoles * z</code>.
* Number of moles of Component in System. Ideally
* <code>numberOfMoles = totalNumberOfMoles * z</code>.
*/
protected double numberOfMoles = 0.0;
/** Number of moles of Component in Phase. <code>totalNumberOfMoles * x * beta</code>. */
/** Number of moles of Component in Phase. Ideally <code>totalNumberOfMoles * x * beta</code>. */
protected double numberOfMolesInPhase = 0.0;
protected double K;

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/neqsim/thermo/component/ComponentHydrate.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class ComponentHydrate extends Component {
private double sphericalCoreRadiusHydrate = 0.0;
private double lennardJonesEnergyParameterHydrate = 0.0;
private double lennardJonesMolecularDiameterHydrate = 0.0;

/** Reference phase containing only this single component, i.e., mixing rules are not relevant. */
PhaseInterface refPhase = null;

/**
Expand Down Expand Up @@ -659,6 +661,7 @@ public void setSolidRefFluidPhase(PhaseInterface phase) {
refPhase.setTemperature(273.0);
refPhase.setPressure(1.0);
refPhase.addComponent("water", 10.0, 10.0, 0);
refPhase.setMixingRule(null);
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 0, PhaseType.GAS, 1.0);
} catch (Exception ex) {
logger.error("error occured", ex);
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/neqsim/thermo/component/ComponentSolid.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ public class ComponentSolid extends ComponentSrk {
double soldens = 0.0;
boolean CCequation = true;
boolean AntoineSolidequation = true;
PhaseInterface refPhase = null;
double pureCompFug = 0.0;

/** Reference phase containing only this single component, i.e., mixing rules are not relevant. */
PhaseInterface refPhase = null;

/**
* <p>
* Constructor for ComponentSolid.
Expand Down Expand Up @@ -257,6 +259,7 @@ public void setSolidRefFluidPhase(PhaseInterface phase) {
refPhase.getComponent(componentName)
.setAttractiveTerm(phase.getComponent(componentName).getAttractiveTermNumber());
refPhase.init(refPhase.getNumberOfMolesInPhase(), 1, 0, PhaseType.GAS, 1.0);
refPhase.setMixingRule(null);
// }
} catch (Exception ex) {
logger.error("error occured", ex);
Expand Down
76 changes: 76 additions & 0 deletions src/main/java/neqsim/thermo/mixingrule/CPAMixingRuleType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package neqsim.thermo.mixingrule;

import neqsim.util.exception.InvalidInputException;

/**
* Types of CPAMixingRule, relating to different kind of mixing rules relevant for CPA type phases.
* Available types are:
* <ul>
* <li>CPA_RADOCH - 1 -</li>
* <li>PCSAFTA_RADOCH - 3 -</li>
* </ul>
*
* @author ASMF
*/
public enum CPAMixingRuleType implements MixingRuleTypeInterface {
CPA_RADOCH(1), PCSAFTA_RADOCH(3);

/** Holder for old style integer pt. */
private final int value;
/** Holder for old style string physical property description. */

// We know we'll never mutate this, so we can keep
// a local copy for fast lookup in forName
private static final CPAMixingRuleType[] copyOfValues = values();

/**
* Constructor for CPAMixingRuleType enum.
*
* @param value Numeric value index for mixing rule
*/
private CPAMixingRuleType(int value) {
this.value = value;
}

/**
* Getter for property value.
*
* @return Numeric index of phase type
*/
@Deprecated
public int getValue() {
return this.value;
}

/**
* Get CPAMixingRuleType by name.
*
* @param name Name to get CPAMixingRuleType for.
* @return CPAMixingRuleType object
*/
public static CPAMixingRuleType byName(String name) {
for (CPAMixingRuleType mr : copyOfValues) {
if (mr.name().equals(name.toUpperCase())) {
return mr;
}
}
throw new RuntimeException(
new InvalidInputException("CPAMixingRuleType", "byName", "name", "is not valid."));
}

/**
* Get CPAMixingRuleType by value.
*
* @param value Value to get CPAMixingRuleType for.
* @return CPAMixingRuleType object
*/
public static CPAMixingRuleType byValue(int value) {
for (CPAMixingRuleType mr : copyOfValues) {
if (mr.getValue() == (value)) {
return mr;
}
}
throw new RuntimeException(
new InvalidInputException("CPAMixingRuleType", "byValue", "value", "is not valid."));
}
}
34 changes: 28 additions & 6 deletions src/main/java/neqsim/thermo/mixingrule/CPAMixingRules.java
Original file line number Diff line number Diff line change
Expand Up @@ -617,15 +617,37 @@ public CPAMixingRulesInterface getMixingRule(int mr) {
if (mr == 1) {
mixingRuleName = "CPA_Radoch";
return new CPA_Radoch();
} else if (mr == 2) {
mixingRuleName = "CPA_Radoch";
return new CPA_Radoch();
} else if (mr == 3) {
mixingRuleName = "PCSAFTa_Radoch";
return new PCSAFTa_Radoch();
} else {
mixingRuleName = "CPA_Radoch";
return new CPA_Radoch();
}
throw new RuntimeException(
new neqsim.util.exception.InvalidInputException(this, "getMixingRule", "mr"));
}

/**
* <p>
* getMixingRule.
* </p>
*
* @param mr a int
* @return a {@link neqsim.thermo.mixingrule.CPAMixingRulesInterface} object
*/
public CPAMixingRulesInterface getMixingRule(MixingRuleTypeInterface mr) {
if (!CPAMixingRuleType.class.isInstance(mr)) {
throw new RuntimeException(
new neqsim.util.exception.InvalidInputException(this, "setMixingRule", "mr"));
}
CPAMixingRuleType cmr = (CPAMixingRuleType) mr;
switch (cmr) {
case CPA_RADOCH:
mixingRuleName = "CPA_Radoch";
return new CPA_Radoch();
case PCSAFTA_RADOCH:
mixingRuleName = "PCSAFTa_Radoch";
return new PCSAFTa_Radoch();
default:
return new CPA_Radoch();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* @author ASMF
*/
public enum EosMixingRuleType {
public enum EosMixingRuleType implements MixingRuleTypeInterface {
NO(1), CLASSIC(2), CLASSIC_HV(3), HV(4), WS(5), CPA_MIX(7), CLASSIC_T(8), CLASSIC_T_CPA(
9), CLASSIC_TX_CPA(10);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package neqsim.thermo.mixingrule;

/**
* Dummy Interface to allow Phase object to keep either CPA or EosMixingRuleType
*/
public interface MixingRuleTypeInterface {


public int getValue();
}
Loading
Loading