diff --git a/src/main/java/neqsim/standards/gasQuality/Standard_ISO6976.java b/src/main/java/neqsim/standards/gasQuality/Standard_ISO6976.java index 372a27ff5..87416a6a6 100644 --- a/src/main/java/neqsim/standards/gasQuality/Standard_ISO6976.java +++ b/src/main/java/neqsim/standards/gasQuality/Standard_ISO6976.java @@ -122,7 +122,7 @@ public Standard_ISO6976(String name, String description, SystemInterface thermoS for (int i = 0; i < thermoSystem.getPhase(0).getNumberOfComponents(); i++) { try { - dataSet = database.getResultSet(("SELECT * FROM iso6976constants WHERE ComponentName='" + dataSet = database.getResultSet(("SELECT * FROM ISO6976constants WHERE ComponentName='" + this.thermoSystem.getPhase(0).getComponent(i).getName() + "'")); dataSet.next(); dataSet.getString("ID"); diff --git a/src/main/java/neqsim/standards/gasQuality/Standard_ISO6976_2016.java b/src/main/java/neqsim/standards/gasQuality/Standard_ISO6976_2016.java index c42adb77b..cc08ce87a 100644 --- a/src/main/java/neqsim/standards/gasQuality/Standard_ISO6976_2016.java +++ b/src/main/java/neqsim/standards/gasQuality/Standard_ISO6976_2016.java @@ -131,8 +131,6 @@ public Standard_ISO6976_2016(SystemInterface thermoSystem) { .add("this.thermoSystem.getPhase(0).getComponent(i).getComponentName()"); logger.info("added component not specified by ISO6976constants2016 " + this.thermoSystem.getPhase(0).getComponent(i).getComponentName()); - } finally { - dataSet.close(); } carbonNumber[i] = Integer.parseInt(dataSet.getString("numberOfCarbon")); @@ -158,9 +156,9 @@ public Standard_ISO6976_2016(SystemInterface thermoSystem) { Hinf20[i] = Double.parseDouble(dataSet.getString("Hinfmolar20")); Hinf25[i] = Double.parseDouble(dataSet.getString("Hinfmolar25")); Hinf60F[i] = Double.parseDouble(dataSet.getString("Hinfmolar60F")); - } - dataSet.close(); + dataSet.close(); + } } catch (Exception ex) { logger.error(ex.getMessage(), ex); } diff --git a/src/main/java/neqsim/thermo/system/SystemThermo.java b/src/main/java/neqsim/thermo/system/SystemThermo.java index d94bafb3d..e7f66a8e6 100644 --- a/src/main/java/neqsim/thermo/system/SystemThermo.java +++ b/src/main/java/neqsim/thermo/system/SystemThermo.java @@ -14,14 +14,11 @@ import java.sql.ResultSet; import java.text.FieldPosition; import java.util.ArrayList; - import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; - import neqsim.chemicalReactions.ChemicalReactionOperations; import neqsim.physicalProperties.interfaceProperties.InterfaceProperties; import neqsim.physicalProperties.interfaceProperties.InterphasePropertiesInterface; @@ -670,7 +667,11 @@ public SystemInterface phaseToSystem(int phaseNumber1, int phaseNumber2) { @Override public void setTotalFlowRate(double flowRate, String flowunit) { init(0); - init(1); + try { + init(1); + } catch (Exception e) { + logger.error(e.getMessage()); + } double density = 0.0; if (flowunit.equals("Am3/hr") || flowunit.equals("Am3/min") || flowunit.equals("Am3/sec")) { initPhysicalProperties("density"); diff --git a/src/test/java/neqsim/standards/gasQuality/Standard_ISO6976_2016_Test.java b/src/test/java/neqsim/standards/gasQuality/Standard_ISO6976_2016_Test.java new file mode 100644 index 000000000..f59d84c73 --- /dev/null +++ b/src/test/java/neqsim/standards/gasQuality/Standard_ISO6976_2016_Test.java @@ -0,0 +1,134 @@ +package neqsim.standards.gasQuality; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import neqsim.thermo.system.SystemInterface; +import neqsim.thermo.system.SystemSrkEos; +import neqsim.thermodynamicOperations.ThermodynamicOperations; + +/** + * @author ESOL + * + */ +class Standard_ISO6976_2016_Test extends neqsim.NeqSimTest { + static SystemInterface testSystem = null; + + /** + * @throws java.lang.Exception + */ + @BeforeAll + static void setUpBeforeClass() throws Exception { + testSystem = new SystemSrkEos(273.15 + 20.0, 1.0); + testSystem.addComponent("methane", 0.931819); + testSystem.addComponent("ethane", 0.025618); + testSystem.addComponent("nitrogen", 0.010335); + testSystem.addComponent("CO2", 0.015391); + testSystem.setMixingRule("classic"); + ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem); + testOps.TPflash(); + } + + /** + * Test method for {@link neqsim.standards.gasQuality.Standard_ISO6976#calculate()}. + */ + @Test + void testCalculate() { + Standard_ISO6976_2016 standard = new Standard_ISO6976_2016(testSystem, 0, 15.55, "volume"); + standard.setReferenceState("real"); + standard.setReferenceType("volume"); + standard.calculate(); + double GCV = standard.getValue("GCV"); + double WI = standard.getValue("WI"); + assertEquals(39612.08330867018, GCV, 0.01); + assertEquals(44.61477915805513, WI, 0.01); + } + + /** + * Test method for {@link neqsim.standards.gasQuality.Standard_ISO6976#calculate()} if wrong + * reference state is gven. Valid reference states should be 0, 15 and 20 C and 15F (15.55C). If + * wrong reference state is given, the program should use standard conditions (15C). + */ + @Test + void testCalculateWithWrongReferenceState() { + double volumeReferenceState = 0; + double energyReferenceState = 15.55; + Standard_ISO6976_2016 standard = + new Standard_ISO6976_2016(testSystem, volumeReferenceState, energyReferenceState, "volume"); + standard.setReferenceState("real"); + standard.setReferenceType("volume"); + standard.calculate(); + double GCV = standard.getValue("GCV"); + standard.getValue("WI"); + assertEquals(39612.08330867018, GCV, 0.01); + energyReferenceState = 15.15; // example of wrong reference condition + volumeReferenceState = 1.15; // example of wrong volume reference condition + standard.setEnergyRefT(energyReferenceState); + standard.setVolRefT(volumeReferenceState); + standard.calculate(); + GCV = standard.getValue("GCV"); + assertEquals(37496.955002184994, GCV, 0.01); + } + + /** + * Test method for {@link neqsim.standards.gasQuality.Standard_ISO6976#calculate()}. + */ + @Test + void testCalculateWithPSeudo() { + SystemSrkEos testSystem = new SystemSrkEos(273.15 + 20.0, 1.0); + testSystem.addComponent("methane", 0.931819); + testSystem.addComponent("ethane", 0.025618); + testSystem.addComponent("nitrogen", 0.010335); + testSystem.addComponent("CO2", 0.015391); + testSystem.addTBPfraction("C10", 0.015391, 90.0 / 1000.0, 0.82); + testSystem.setMixingRule("classic"); + ThermodynamicOperations testOps = new ThermodynamicOperations(testSystem); + testOps.TPflash(); + Standard_ISO6976_2016 standard = new Standard_ISO6976_2016(testSystem, 0, 15.55, "volume"); + standard.setReferenceState("real"); + standard.setReferenceType("volume"); + standard.calculate(); + double GCV = standard.getValue("GCV"); + standard.getValue("WI"); + assertEquals(42374.88507879093, GCV, 0.01); + } + + @Test + void testCalculate2() { + SystemInterface testSystem = new SystemSrkEos(273.15 - 150.0, 1.0); + testSystem.addComponent("methane", 0.931819); + testSystem.addComponent("ethane", 0.025618); + testSystem.addComponent("nitrogen", 0.010335); + testSystem.addComponent("CO2", 0.015391); + testSystem.createDatabase(true); + testSystem.setMixingRule(2); + + testSystem.init(0); + Standard_ISO6976_2016 standard = new Standard_ISO6976_2016(testSystem, 0, 15.55, "volume"); + standard.setReferenceState("real"); + standard.setReferenceType("volume"); + standard.calculate(); + Assertions.assertEquals(0.9974581843581334, standard.getValue("CompressionFactor"), 1e-5); + Assertions.assertEquals(35693.5928445084, standard.getValue("InferiorCalorificValue"), 1e-5); + Assertions.assertEquals(39612.08330867018, standard.getValue("GCV")); + + Assertions.assertEquals(51698.75555489656, standard.getValue("SuperiorWobbeIndex")); + Assertions.assertEquals(46584.63219328704, standard.getValue("InferiorWobbeIndex")); + + Assertions.assertEquals(0.5870771657884608, standard.getValue("RelativeDensity")); + Assertions.assertEquals(0.9974581843581334, standard.getValue("CompressionFactor")); + Assertions.assertEquals(16.97159718679405, standard.getValue("MolarMass")); + + // standard.display("test"); + /* + * StandardInterface standardUK = new UKspecifications_ICF_SI(testSystem); + * standardUK.calculate(); logger.info("ICF " + + * standardUK.getValue("IncompleteCombustionFactor", "")); + * + * logger.info("HID " + testSystem.getPhase(0).getComponent("methane").getHID(273.15 - 150.0)); + * logger.info("Hres " + testSystem.getPhase(0).getComponent("methane").getHresTP(273.15 - + * 150.0)); + */ + } +}