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

add use of unit for molar volume #836

Merged
merged 2 commits into from
Nov 7, 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
53 changes: 34 additions & 19 deletions src/main/java/neqsim/thermo/phase/Phase.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,12 @@ public abstract class Phase implements PhaseInterface {

/**
* Mole fraction of this phase of system.
* <code>beta = numberOfMolesInPhase/numberOfMolesInSystem</code>. NB!
* numberOfMolesInSystem is
* <code>beta = numberOfMolesInPhase/numberOfMolesInSystem</code>. NB! numberOfMolesInSystem is
* not known to the phase.
*/
double beta = 1.0;
/**
* Number of moles in phase.
* <code>numberOfMolesInPhase = numberOfMolesInSystem*beta</code>. NB!
* Number of moles in phase. <code>numberOfMolesInPhase = numberOfMolesInSystem*beta</code>. NB!
* numberOfMolesInSystem is not known to the phase.
*/
public double numberOfMolesInPhase = 0;
Expand Down Expand Up @@ -103,7 +101,7 @@ public Phase clone() {
* addcomponent. Increase number of components and add moles to phase.
* </p>
*
* @param name Name of component to add.
* @param name Name of component to add.
* @param moles Number of moles of component to add to phase.
*/
public void addComponent(String name, double moles) {
Expand Down Expand Up @@ -179,8 +177,8 @@ public void addMoles(int component, double dn) {
public void addMolesChemReac(int component, double dn, double totdn) {
if ((numberOfMolesInPhase + dn) / numberOfMolesInPhase < -1e-10) {
String msg = "will lead to negative number of moles in phase." + (numberOfMolesInPhase + dn);
neqsim.util.exception.InvalidInputException ex = new neqsim.util.exception.InvalidInputException(this,
"addMolesChemReac", "dn", msg);
neqsim.util.exception.InvalidInputException ex =
new neqsim.util.exception.InvalidInputException(this, "addMolesChemReac", "dn", msg);
throw new RuntimeException(ex);
}
numberOfMolesInPhase += dn;
Expand Down Expand Up @@ -287,7 +285,8 @@ public double getPressure() {
/** {@inheritDoc} */
@Override
public final double getPressure(String unit) {
neqsim.util.unit.PressureUnit presConversion = new neqsim.util.unit.PressureUnit(getPressure(), "bara");
neqsim.util.unit.PressureUnit presConversion =
new neqsim.util.unit.PressureUnit(getPressure(), "bara");
return presConversion.getValue(unit);
}

Expand Down Expand Up @@ -496,11 +495,11 @@ public double calcA(PhaseInterface phase, double temperature, double pressure, i
* calcA.
* </p>
*
* @param comp a int
* @param phase a {@link neqsim.thermo.phase.PhaseInterface} object
* @param comp a int
* @param phase a {@link neqsim.thermo.phase.PhaseInterface} object
* @param temperature a double
* @param pressure a double
* @param numbcomp a int
* @param pressure a double
* @param numbcomp a int
* @return a double
*/
public double calcA(int comp, PhaseInterface phase, double temperature, double pressure,
Expand Down Expand Up @@ -582,6 +581,23 @@ public double getMolarVolume() {
return molarVolume;
}

/** {@inheritDoc} */
@Override
public double getMolarVolume(String unit) {
double conversionFactor = 1.0;
switch (unit) {
case "m3/mol":
conversionFactor = 1.0;
break;
case "litre/mol":
conversionFactor = 1000.0;
break;
default:
throw new RuntimeException("unit not supported " + unit);
}
return getMolarMass() / getDensity("kg/m3") * conversionFactor;
}

/** {@inheritDoc} */
@Override
public int getNumberOfComponents() {
Expand Down Expand Up @@ -1230,7 +1246,7 @@ public void initRefPhases(boolean onlyPure) {
* </p>
*
* @param onlyPure a boolean
* @param name a {@link String} object
* @param name a {@link String} object
*/
public void initRefPhases(boolean onlyPure, String name) {
refPhase = new PhaseInterface[numberOfComponents];
Expand Down Expand Up @@ -1284,7 +1300,7 @@ public void initRefPhases(boolean onlyPure, String name) {
* getLogPureComponentFugacity.
* </p>
*
* @param k a int
* @param k a int
* @param pure a boolean
* @return a double
*/
Expand Down Expand Up @@ -1826,8 +1842,7 @@ public void setPhysicalPropertyType(int physicalPropertyType) {
/** {@inheritDoc} */
@Override
public void setParams(PhaseInterface phase, double[][] alpha, double[][] Dij, double[][] DijT,
String[][] mixRule, double[][] intparam) {
}
String[][] mixRule, double[][] intparam) {}

/** {@inheritDoc} */
@Override
Expand Down Expand Up @@ -1923,8 +1938,7 @@ public final void setBeta(double b) {

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

/** {@inheritDoc} */
@Override
Expand Down Expand Up @@ -2111,7 +2125,8 @@ public double[] getProperties_GERG2008() {
/** {@inheritDoc} */
@Override
public double getDensity_AGA8() {
neqsim.thermo.util.GERG.NeqSimAGA8Detail test = new neqsim.thermo.util.GERG.NeqSimAGA8Detail(this);
neqsim.thermo.util.GERG.NeqSimAGA8Detail test =
new neqsim.thermo.util.GERG.NeqSimAGA8Detail(this);
return test.getDensity();
}

Expand Down
10 changes: 10 additions & 0 deletions src/main/java/neqsim/thermo/phase/PhaseInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,16 @@ public default void init(double totalNumberOfMoles, int numberOfComponents, int
*/
public double getMolarVolume();

/**
* method to return molar volume of the fluid:
* eventual volume correction included.
*
* @param unit Supported units are m3/mol, litre/mol
*
* @return molar volume volume in unit
*/
public double getMolarVolume(String unit);

/**
* method to return flow rate of a phase.
*
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/neqsim/thermo/system/SystemInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -1889,6 +1889,16 @@ public double calcBeta()
*/
public double getMolarVolume();

/**
* method to return molar volume of the fluid:
* eventual volume correction included.
*
* @param unit Supported units are m3/mol, litre/mol
*
* @return molar volume volume in unit
*/
public double getMolarVolume(String unit);

/**
* Get molar mass of system.
*
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/neqsim/thermo/system/SystemThermo.java
Original file line number Diff line number Diff line change
Expand Up @@ -2833,6 +2833,16 @@ public double getEntropy(String unit) {
return refEntropy * conversionFactor;
}

/** {@inheritDoc} */
@Override
public double getMolarVolume(String unit) {
double volume = 0;
for (int i = 0; i < numberOfPhases; i++) {
volume += beta[phaseIndex[i]] * getPhase(i).getMolarVolume(unit);
}
return volume;
}

/** {@inheritDoc} */
@Override
public double getMolarVolume() {
Expand Down
25 changes: 25 additions & 0 deletions src/test/java/neqsim/thermo/system/SystemPrEosTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,31 @@ public static void setUp() {
testSystem.initProperties();
}

/**
* <p>
* testMolarVolume.
* </p>
*/
@Test
@DisplayName("test testMolarVolume calc whre unit as input")
public void testMolarVolume() {
neqsim.thermo.system.SystemInterface testSystem =
new neqsim.thermo.system.SystemPrEos(298.0, 10.0);
testSystem.addComponent("nitrogen", 0.01);
testSystem.addComponent("CO2", 0.01);
testSystem.addComponent("methane", 0.68);
testSystem.addComponent("ethane", 0.1);
testSystem.setMixingRule("classic");
testModel = new neqsim.thermo.ThermodynamicModelTest(testSystem);
ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem);
testOps.TPflash();
testSystem.initProperties();
assertEquals(testSystem.getMolarVolume("m3/mol"),
testSystem.getMolarMass("kg/mol") / testSystem.getDensity("kg/m3"));
}



/**
* <p>
* testTPflash2.
Expand Down