Skip to content

Commit 28a6710

Browse files
authored
add set and get methods and a test (#1039)
1 parent 256acdb commit 28a6710

File tree

4 files changed

+125
-83
lines changed

4 files changed

+125
-83
lines changed

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

+58-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import neqsim.thermo.component.attractiveEosTerm.AttractiveTermInterface;
1515
import neqsim.thermo.phase.PhaseInterface;
1616
import neqsim.util.database.NeqSimDataBase;
17+
import neqsim.util.unit.PressureUnit;
18+
import neqsim.util.unit.TemperatureUnit;
1719

1820
public abstract class Component implements ComponentInterface {
1921
private static final long serialVersionUID = 1000;
@@ -85,7 +87,6 @@ public abstract class Component implements ComponentInterface {
8587
protected double criticalTemperature;
8688
protected double molarMass;
8789
protected double acentricFactor;
88-
8990
protected double normalLiquidDensity = 0;
9091
protected double reducedPressure;
9192
protected double reducedTemperature;
@@ -670,12 +671,26 @@ public final void setTC(double val) {
670671
criticalTemperature = val;
671672
}
672673

674+
/** {@inheritDoc} */
675+
@Override
676+
public final void setTC(double val, String unit) {
677+
TemperatureUnit inValue = new TemperatureUnit(val, unit);
678+
criticalTemperature = inValue.getValue(val, unit, "K");
679+
}
680+
673681
/** {@inheritDoc} */
674682
@Override
675683
public final void setPC(double val) {
676684
criticalPressure = val;
677685
}
678686

687+
/** {@inheritDoc} */
688+
@Override
689+
public final void setPC(double val, String unit) {
690+
PressureUnit inValue = new PressureUnit(val, unit);
691+
criticalPressure = inValue.getValue(val, unit, "bara");
692+
}
693+
679694
/** {@inheritDoc} */
680695
@Override
681696
public final String getComponentName() {
@@ -792,6 +807,48 @@ public double getNormalLiquidDensity(String unit) {
792807
return refDensity * conversionFactor;
793808
}
794809

810+
/** {@inheritDoc} */
811+
@Override
812+
public double getMolarMass(String unit) {
813+
double refMolarMass = getMolarMass();
814+
double conversionFactor = 1.0;
815+
switch (unit) {
816+
case "kg/mol":
817+
conversionFactor = 1.0;
818+
break;
819+
case "gr/mol":
820+
conversionFactor = 1000.0;
821+
break;
822+
case "lbm/lbmol":
823+
conversionFactor = 1000.0;
824+
break;
825+
default:
826+
throw new RuntimeException("unit not supported " + unit);
827+
}
828+
return refMolarMass * conversionFactor;
829+
}
830+
831+
/** {@inheritDoc} */
832+
@Override
833+
public void setMolarMass(double value, String unit) {
834+
double refMolarMass = value;
835+
double conversionFactor = 1.0;
836+
switch (unit) {
837+
case "kg/mol":
838+
conversionFactor = 1.0;
839+
break;
840+
case "gr/mol":
841+
conversionFactor = 1000.0;
842+
break;
843+
case "lbm/lbmol":
844+
conversionFactor = 1000.0;
845+
break;
846+
default:
847+
throw new RuntimeException("unit not supported " + unit);
848+
}
849+
molarMass = refMolarMass * 1.0 / conversionFactor;
850+
}
851+
795852
/** {@inheritDoc} */
796853
@Override
797854
public double getViscosityCorrectionFactor() {

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

+39
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,17 @@ public double fugcoefDiffTempNumeric(PhaseInterface phase, int numberOfComponent
631631
*/
632632
public void setMolarMass(double molarMass);
633633

634+
/**
635+
* <p>
636+
* setMolarMass.
637+
* </p>
638+
*
639+
* @param molarMass a double
640+
*
641+
* @param unit a String
642+
*/
643+
public void setMolarMass(double molarMass, String unit);
644+
634645
/**
635646
* <p>
636647
* calcActivity.
@@ -768,6 +779,16 @@ public default void addMolesChemReac(double dn) {
768779
*/
769780
public void setTC(double val);
770781

782+
/**
783+
* <p>
784+
* setTC.
785+
* </p>
786+
*
787+
* @param val a double
788+
* @param unit a String
789+
*/
790+
public void setTC(double val, String unit);
791+
771792
/**
772793
* <p>
773794
* setPC.
@@ -777,6 +798,16 @@ public default void addMolesChemReac(double dn) {
777798
*/
778799
public void setPC(double val);
779800

801+
/**
802+
* <p>
803+
* setPC.
804+
* </p>
805+
*
806+
* @param val a double
807+
* @param unit a String
808+
*/
809+
public void setPC(double val, String unit);
810+
780811
/**
781812
* <p>
782813
* getDiElectricConstantdTdT.
@@ -1212,6 +1243,14 @@ public default double getLogFugacityCoefficient() {
12121243
*/
12131244
public double getMolarMass();
12141245

1246+
/**
1247+
* Get molar mass of component.
1248+
*
1249+
* @param unit a String
1250+
* @return molar mass in unit kg/mol
1251+
*/
1252+
public double getMolarMass(String unit);
1253+
12151254
/**
12161255
* <p>
12171256
* getLennardJonesMolecularDiameter.

src/main/java/neqsim/thermo/system/neqsim_Units.code-search

-82
This file was deleted.

src/test/java/neqsim/thermo/component/NewComponentTest.java

+28
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,32 @@ public void newComponentIsoButeneTest() {
6767
thermoSystem.init(0);
6868
assertEquals(56.10632e-3, thermoSystem.getMolarMass("kg/mol"), 0.01);
6969
}
70+
71+
@Test
72+
public void setTCPC_test() {
73+
thermoSystem = new SystemSrkEos(298.0, ThermodynamicConstantsInterface.referencePressure);
74+
thermoSystem.addComponent("iso-butene", 1.0);
75+
thermoSystem.init(0);
76+
thermoSystem.getPhase(0).getComponent(0).setTC(190.0);
77+
assertEquals(190.0, thermoSystem.getPhase(0).getComponent(0).getTC(), 0.01);
78+
79+
thermoSystem.getPhase(0).getComponent(0).setTC(190.0, "R");
80+
assertEquals(190.0, thermoSystem.getPhase(0).getComponent(0).getTC("R"), 0.01);
81+
82+
thermoSystem.getPhase(0).getComponent(0).setTC(190.0, "R");
83+
assertEquals(105.55555, thermoSystem.getPhase(0).getComponent(0).getTC("K"), 0.01);
84+
85+
thermoSystem.getPhase(0).getComponent(0).setPC(1290.0, "psia");
86+
assertEquals(1290.0, thermoSystem.getPhase(0).getComponent(0).getPC("psia"), 0.01);
87+
assertEquals(88.9423690, thermoSystem.getPhase(0).getComponent(0).getPC("bara"), 0.01);
88+
89+
thermoSystem.getPhase(0).getComponent(0).setMolarMass(0.090);
90+
assertEquals(0.09, thermoSystem.getPhase(0).getComponent(0).getMolarMass(), 0.01);
91+
assertEquals(90.0, thermoSystem.getPhase(0).getComponent(0).getMolarMass("gr/mol"), 0.01);
92+
assertEquals(90.0, thermoSystem.getPhase(0).getComponent(0).getMolarMass("lbm/lbmol"), 0.01);
93+
94+
thermoSystem.getPhase(0).getComponent(0).setMolarMass(85.0, "lbm/lbmol");
95+
assertEquals(85.0, thermoSystem.getPhase(0).getComponent(0).getMolarMass("gr/mol"), 0.01);
96+
97+
}
7098
}

0 commit comments

Comments
 (0)