Skip to content

Commit bd3e118

Browse files
authored
added more field units (#985)
* added more field units * more updates to units * more field units * add possibility to see available units * fix test for units * update text * update
1 parent a56409d commit bd3e118

File tree

8 files changed

+398
-139
lines changed

8 files changed

+398
-139
lines changed

src/main/java/neqsim/Units.java

-83
This file was deleted.

src/main/java/neqsim/thermo/phase/Phase.java

+66-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88

99
import java.util.ArrayList;
1010
import org.apache.logging.log4j.LogManager;
11+
import org.apache.logging.log4j.Logger;
1112
import neqsim.physicalProperties.PhysicalPropertyHandler;
1213
import neqsim.thermo.ThermodynamicConstantsInterface;
1314
import neqsim.thermo.ThermodynamicModelSettings;
1415
import neqsim.thermo.component.ComponentInterface;
1516
import neqsim.thermo.system.SystemInterface;
1617
import neqsim.util.exception.InvalidInputException;
17-
import org.apache.logging.log4j.Logger;
1818

1919
/**
2020
* Phase class.
@@ -122,7 +122,8 @@ public void addComponent(String name, double moles, int compNumber) {
122122
}
123123

124124
if (this.hasComponent(name)) {
125-
// shall use addMoles/addMolesChemreac to adding/subtracting moles for component.
125+
// shall use addMoles/addMolesChemreac to adding/subtracting moles for
126+
// component.
126127
throw new RuntimeException(new InvalidInputException(this, "addComponent", "name",
127128
"component with same name already exists in phase. Use addMoles or addMolesChemreac."));
128129
}
@@ -616,6 +617,9 @@ public double getMolarVolume(String unit) {
616617
case "litre/mol":
617618
conversionFactor = 1000.0;
618619
break;
620+
case "ft3/lbmole":
621+
conversionFactor = 16018.463373960138;
622+
break;
619623
default:
620624
throw new RuntimeException("unit not supported " + unit);
621625
}
@@ -1000,6 +1004,9 @@ public double getCp(String unit) {
10001004
case "kJ/kgK":
10011005
conversionFactor = 1.0 / getNumberOfMolesInPhase() / getMolarMass() / 1000.0;
10021006
break;
1007+
case "btu/lbmole-F":
1008+
conversionFactor = 1.0 / getNumberOfMolesInPhase() / getMolarMass() / 1000.0 * 0.2388;
1009+
break;
10031010
default:
10041011
break;
10051012
}
@@ -1030,6 +1037,9 @@ public double getCv(String unit) {
10301037
case "kJ/kgK":
10311038
conversionFactor = 1.0 / getNumberOfMolesInPhase() / getMolarMass() / 1000.0;
10321039
break;
1040+
case "btu/lbmole-F":
1041+
conversionFactor = 1.0 / getNumberOfMolesInPhase() / getMolarMass() / 1000.0 * 0.2388;
1042+
break;
10331043
default:
10341044
break;
10351045
}
@@ -1165,6 +1175,9 @@ public double getEntropy(String unit) {
11651175
case "kJ/kgK":
11661176
conversionFactor = 1.0 / getNumberOfMolesInPhase() / getMolarMass() / 1000.0;
11671177
break;
1178+
case "btu/lb-F":
1179+
conversionFactor = 1.0 / getNumberOfMolesInPhase() / getMolarMass() / 1000.0 * 0.2388;
1180+
break;
11681181
default:
11691182
throw new RuntimeException("unit not supported " + unit);
11701183
}
@@ -1226,6 +1239,9 @@ public double getThermalConductivity(String unit) {
12261239
case "W/cmK":
12271240
conversionFactor = 0.01;
12281241
break;
1242+
case "Btu/hr-ft-F":
1243+
conversionFactor = 0.5781759824;
1244+
break;
12291245
default:
12301246
throw new RuntimeException("unit not supported " + unit);
12311247
}
@@ -1559,6 +1575,27 @@ public final double getMolarMass() {
15591575
return tempVar;
15601576
}
15611577

1578+
/** {@inheritDoc} */
1579+
@Override
1580+
public double getMolarMass(String unit) {
1581+
double refMolarMass = getMolarMass();
1582+
double conversionFactor = 1.0;
1583+
switch (unit) {
1584+
case "kg/mol":
1585+
conversionFactor = 1.0;
1586+
break;
1587+
case "gr/mol":
1588+
conversionFactor = 1000.0;
1589+
break;
1590+
case "lbm/lbmol":
1591+
conversionFactor = 1000.0;
1592+
break;
1593+
default:
1594+
throw new RuntimeException("unit not supported " + unit);
1595+
}
1596+
return refMolarMass * conversionFactor;
1597+
}
1598+
15621599
/** {@inheritDoc} */
15631600
@Override
15641601
public double getJouleThomsonCoefficient(String unit) {
@@ -1571,6 +1608,12 @@ public double getJouleThomsonCoefficient(String unit) {
15711608
case "C/bar":
15721609
conversionFactor = 1.0;
15731610
break;
1611+
case "K/Pa":
1612+
conversionFactor = 1.0e-5;
1613+
break;
1614+
case "F/psi":
1615+
conversionFactor = 1.8 * 1.0 / 14.503773773;
1616+
break;
15741617
default:
15751618
throw new RuntimeException("unit not supported " + unit);
15761619
}
@@ -2093,6 +2136,27 @@ public double getSoundSpeed() {
20932136
throw new UnsupportedOperationException("Unimplemented method 'getSoundSpeed'");
20942137
}
20952138

2139+
/** {@inheritDoc} */
2140+
@Override
2141+
public double getSoundSpeed(String unit) {
2142+
double refVel = getSoundSpeed();
2143+
double conversionFactor = 1.0;
2144+
switch (unit) {
2145+
case "m/s":
2146+
conversionFactor = 1.0;
2147+
break;
2148+
case "km/hr":
2149+
conversionFactor = 3.6;
2150+
break;
2151+
case "ft/sec":
2152+
conversionFactor = 3.280839895;
2153+
break;
2154+
default:
2155+
break;
2156+
}
2157+
return refVel * conversionFactor;
2158+
}
2159+
20962160
/** {@inheritDoc} */
20972161
@Override
20982162
public ComponentInterface getComponentWithIndex(int index) {

src/main/java/neqsim/thermo/phase/PhaseInterface.java

+17-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,6 @@ public void init(double totalNumberOfMoles, int numberOfComponents, int initType
336336
*/
337337
public ComponentInterface[] getcomponentArray();
338338

339-
340339
/**
341340
* Get normalized names of components in phase.
342341
*
@@ -1390,6 +1389,14 @@ public default void addMolesChemReac(int component, double dn) {
13901389
*/
13911390
public double getMolarMass();
13921391

1392+
/**
1393+
* method to get molar mass of a fluid phase.
1394+
*
1395+
* @param unit Supported units are kg/mol, gr/mol
1396+
* @return molar mass in specified unit
1397+
*/
1398+
public double getMolarMass(String unit);
1399+
13931400
/**
13941401
* <p>
13951402
* getInternalEnergy.
@@ -1973,4 +1980,13 @@ public default boolean hasComponent(String name) {
19731980
* @return speed of sound in m/s
19741981
*/
19751982
public double getSoundSpeed();
1983+
1984+
/**
1985+
* method to get the speed of sound of a system. The sound speed is implemented based on a molar
1986+
* average over the phases
1987+
*
1988+
* @param unit Supported units are m/s, km/h
1989+
* @return speed of sound in m/s
1990+
*/
1991+
public double getSoundSpeed(String unit);
19761992
}

0 commit comments

Comments
 (0)