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

ISO69976 2016 bug fix #759

Merged
merged 9 commits into from
Jul 5, 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
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand All @@ -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);
}
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/neqsim/thermo/system/SystemThermo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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));
*/
}
}