Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
asmfstatoil committed Jan 10, 2025
1 parent 58c04dd commit 3dd93e6
Show file tree
Hide file tree
Showing 36 changed files with 410 additions and 181 deletions.
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 @@ -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
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.byValue(1), 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.byValue(1), 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();
}
34 changes: 10 additions & 24 deletions src/main/java/neqsim/thermo/phase/Phase.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import neqsim.thermo.ThermodynamicConstantsInterface;
import neqsim.thermo.ThermodynamicModelSettings;
import neqsim.thermo.component.ComponentInterface;
import neqsim.thermo.mixingrule.EosMixingRuleType;
import neqsim.thermo.mixingrule.MixingRuleTypeInterface;
import neqsim.thermo.system.SystemInterface;
import neqsim.util.exception.InvalidInputException;

Expand Down Expand Up @@ -76,15 +76,15 @@ public abstract class Phase implements PhaseInterface {
public double numberOfMolesInPhase = 0;

private int initType = 0;
public boolean mixingRuleDefined = false;
private EosMixingRuleType mixingRuleType = EosMixingRuleType.NO;
protected MixingRuleTypeInterface mixingRuleType;

/** Temperature of phase. */
double temperature = 0;

/** Pressure of phase. */
double pressure = 0;

/** Reference phase per component. Relevant for solids and chemicalreactions. */
protected PhaseInterface[] refPhase = null;
protected PhaseType pt = PhaseType.GAS;

Expand Down Expand Up @@ -1328,11 +1328,10 @@ public void initRefPhases(boolean onlyPure, String name) {
refPhase[i].addComponent(getComponent(i).getComponentName(), 10.0, 10.0, 0);
}
refPhase[i].setAttractiveTerm(this.getComponent(i).getAttractiveTermNumber());
refPhase[i].setMixingRule(this.getEosMixingRuleType().getValue());
refPhase[i].setMixingRule(this.getMixingRuleType());
refPhase[i].setType(this.getType());
refPhase[i].init(refPhase[i].getNumberOfMolesInPhase(), 1, 0, this.getType(), 1.0);
} else {
// System.out.println("ref " + name);
if (getComponent(i).isIsTBPfraction() || getComponent(i).isIsPlusFraction()) {
refPhase[i].addComponent("default", 10.0, 10.0, 0);
refPhase[i].getComponent(0).setMolarMass(this.getComponent(i).getMolarMass());
Expand All @@ -1346,7 +1345,7 @@ public void initRefPhases(boolean onlyPure, String name) {
}
refPhase[i].addComponent(name, 10.0, 10.0, 1);
refPhase[i].setAttractiveTerm(this.getComponent(i).getAttractiveTermNumber());
refPhase[i].setMixingRule(this.getEosMixingRuleType().getValue());
refPhase[i].setMixingRule(this.getMixingRuleType());
refPhase[i].init(refPhase[i].getNumberOfMolesInPhase(), 2, 0, this.getType(), 1.0);
}
}
Expand Down Expand Up @@ -1726,16 +1725,10 @@ public double getdrhodN() {

/** {@inheritDoc} */
@Override
public EosMixingRuleType getEosMixingRuleType() {
public MixingRuleTypeInterface getMixingRuleType() {
return mixingRuleType;
}

/** {@inheritDoc} */
@Override
public void setMixingRule(int type) {
mixingRuleType = EosMixingRuleType.byValue(type);
}

/**
* <p>
* calcDiElectricConstant.
Expand Down Expand Up @@ -2035,20 +2028,13 @@ public final void setBeta(double b) {
this.beta = b;
}

/** {@inheritDoc} */
@Override
public void setMixingRuleGEModel(String name) {}

/** {@inheritDoc} */
@Override
public boolean isMixingRuleDefined() {
return mixingRuleDefined;
}

/** {@inheritDoc} */
@Override
public void setMixingRuleDefined(boolean mixingRuleDefined) {
this.mixingRuleDefined = mixingRuleDefined;
if (mixingRuleType == null) {
return false;
}
return true;
}

/** {@inheritDoc} */
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/neqsim/thermo/phase/PhaseDefault.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package neqsim.thermo.phase;

import neqsim.thermo.component.ComponentInterface;
import neqsim.thermo.mixingrule.EosMixingRulesInterface;
import neqsim.thermo.mixingrule.MixingRuleTypeInterface;

/**
* <p>
Expand Down Expand Up @@ -67,7 +69,21 @@ public double molarVolume(double pressure, double temperature, double A, double

/** {@inheritDoc} */
@Override
public void resetMixingRule(int type) {}
public EosMixingRulesInterface getMixingRule() {
return null;
}

/** {@inheritDoc} */
@Override
public void setMixingRuleGEModel(String name) {}

/** {@inheritDoc} */
@Override
public void setMixingRule(MixingRuleTypeInterface mr) {}

/** {@inheritDoc} */
@Override
public void resetMixingRule(MixingRuleTypeInterface mr) {}

/** {@inheritDoc} */
@Override
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/neqsim/thermo/phase/PhaseDesmukhMather.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.apache.logging.log4j.Logger;
import neqsim.thermo.component.ComponentDesmukhMather;
import neqsim.thermo.component.ComponentGEInterface;
import neqsim.thermo.mixingrule.MixingRuleTypeInterface;
import neqsim.util.exception.IsNaNException;
import neqsim.util.exception.TooManyIterationsException;

Expand Down Expand Up @@ -53,8 +54,8 @@ public void init(double totalNumberOfMoles, int numberOfComponents, int initType

/** {@inheritDoc} */
@Override
public void setMixingRule(int type) {
super.setMixingRule(type);
public void setMixingRule(MixingRuleTypeInterface mr) {
super.setMixingRule(mr);
this.aij = new double[numberOfComponents][numberOfComponents];
this.bij = new double[numberOfComponents][numberOfComponents];
try (neqsim.util.database.NeqSimDataBase database = new neqsim.util.database.NeqSimDataBase()) {
Expand Down
Loading

0 comments on commit 3dd93e6

Please sign in to comment.