diff --git a/src/test/java/neqsim/thermodynamicoperations/ThermodynamicOperationsTest.java b/src/test/java/neqsim/thermodynamicoperations/ThermodynamicOperationsTest.java index f95ba0049..6b31360aa 100644 --- a/src/test/java/neqsim/thermodynamicoperations/ThermodynamicOperationsTest.java +++ b/src/test/java/neqsim/thermodynamicoperations/ThermodynamicOperationsTest.java @@ -40,7 +40,8 @@ void testFlash() { ops.getSystem().initPhysicalProperties(); Double[] PTfluidProperties = ops.getSystem().getProperties().getValues(); - // Test that the operations are stable, i.e., do the same flash on the same system with the same + // Test that the operations are stable, i.e., do the same flash on the same + // system with the same // components and at the same conditions and assert that the result is the same. ops.getSystem().init(0); ops.flash(FlashType.TP, T, P, unitT, unitP); @@ -55,12 +56,11 @@ void testFlash() { @Test void testFluidDefined() { - double[] fractions = new double[] {98.0, 2.0}; - List Sp1 = - Arrays.asList(new Double[] {22.1, 23.2, 24.23, 25.98, 25.23, 26.1, 27.3, 28.7, 23.5, 22.7}); + double[] fractions = new double[] { 98.0, 2.0 }; + List Sp1 = Arrays.asList(new Double[] { 22.1, 23.2, 24.23, 25.98, 25.23, 26.1, 27.3, 28.7, 23.5, 22.7 }); List Sp2 = Arrays.asList( - new Double[] {288.1, 290.1, 295.1, 301.2, 299.3, 310.2, 315.3, 310.0, 305.2, 312.7}); - List components = Arrays.asList(new String[] {"O2", "N2"}); + new Double[] { 288.1, 290.1, 295.1, 301.2, 299.3, 310.2, 315.3, 310.0, 305.2, 312.7 }); + List components = Arrays.asList(new String[] { "O2", "N2" }); List> onlineFractions = new ArrayList>(); for (double d : fractions) { @@ -124,7 +124,8 @@ void testFluidDefined() { Assertions.assertEquals(res, res2); // todo: why does below not work? - // Assertions.assertArrayEquals(res_static.fluidProperties[0], res.fluidProperties[0]); + // Assertions.assertArrayEquals(res_static.fluidProperties[0], + // res.fluidProperties[0]); } @Test @@ -134,10 +135,9 @@ void testNeqSimPython() { thermoSystem.addComponent("ethane", 0.3); thermoSystem.init(0); - ThermodynamicOperations thermoOps = - new neqsim.thermodynamicoperations.ThermodynamicOperations(thermoSystem); - List jP = Arrays.asList(new Double[] {10.0}); - List jT = Arrays.asList(new Double[] {280.0}); + ThermodynamicOperations thermoOps = new neqsim.thermodynamicoperations.ThermodynamicOperations(thermoSystem); + List jP = Arrays.asList(new Double[] { 10.0 }); + List jT = Arrays.asList(new Double[] { 280.0 }); CalculationResult res = thermoOps.propertyFlash(jP, jT, 1, null, null); // Verify some basic properties @@ -158,32 +158,29 @@ void testNeqSimPython() { Assertions.assertEquals(res2.hashCode(), res2.hashCode()); Assertions.assertFalse(res2 == res); - CalculationResult res2_copy = - new CalculationResult(res2.fluidProperties, res2.calculationError); + CalculationResult res2_copy = new CalculationResult(res2.fluidProperties, res2.calculationError); Assertions.assertEquals(res2, res2_copy); } @Test void testNeqSimPython2() { - String[] components = - new String[] {"H2O", "N2", "CO2", "C1", "C2", "C3", "iC4", "nC4", "iC5", "nC5", "C6"}; - double[] fractions = new double[] {0.0003, 1.299, 0.419, 94.990, 2.399, 0.355, 0.172, 0.088, - 0.076, 0.036, 0.1656}; + String[] components = new String[] { "H2O", "N2", "CO2", "C1", "C2", "C3", "iC4", "nC4", "iC5", "nC5", "C6" }; + double[] fractions = new double[] { 0.0003, 1.299, 0.419, 94.990, 2.399, 0.355, 0.172, 0.088, + 0.076, 0.036, 0.1656 }; - double[] fractions2 = new double[] {0.0003, 2.299, 0.419, 93.990, 2.399, 0.355, 0.172, 0.088, - 0.076, 0.036, 0.1656}; + double[] fractions2 = new double[] { 0.0003, 2.299, 0.419, 93.990, 2.399, 0.355, 0.172, 0.088, + 0.076, 0.036, 0.1656 }; SystemInterface thermoSystem = new neqsim.thermo.system.SystemSrkEos(100 + 273.15, 60.0); thermoSystem.addComponents(components, fractions); thermoSystem.init(0); - ThermodynamicOperations thermoOps = - new neqsim.thermodynamicoperations.ThermodynamicOperations(thermoSystem); + ThermodynamicOperations thermoOps = new neqsim.thermodynamicoperations.ThermodynamicOperations(thermoSystem); double temp = 373.15; double press = 60.0 + ThermodynamicConstantsInterface.referencePressure; - List jP = Arrays.asList(new Double[] {press}); - List jT = Arrays.asList(new Double[] {temp}); + List jP = Arrays.asList(new Double[] { press }); + List jT = Arrays.asList(new Double[] { temp }); CalculationResult res = thermoOps.propertyFlash(jP, jT, 1, null, null); // Assert no calculation failed for (String errorMessage : res.calculationError) { @@ -210,15 +207,13 @@ void testNeqSimPython2() { Assertions.assertArrayEquals(res.fluidProperties[0], res1.fluidProperties[0]); int numFrac = 3; - List> onlineFractions2 = - createDummyRequest(thermoSystem.getMolarComposition(), numFrac); + List> onlineFractions2 = createDummyRequest(thermoSystem.getMolarComposition(), numFrac); - List jP2 = Arrays.asList(new Double[] {press, press}); - List jT2 = Arrays.asList(new Double[] {temp, temp}); + List jP2 = Arrays.asList(new Double[] { press, press }); + List jT2 = Arrays.asList(new Double[] { temp, temp }); SystemInterface thermoSystem2 = new neqsim.thermo.system.SystemSrkEos(273.15, 0.0); thermoSystem2.addComponents(components, fractions2); - ThermodynamicOperations thermoOps2 = - new neqsim.thermodynamicoperations.ThermodynamicOperations(thermoSystem2); + ThermodynamicOperations thermoOps2 = new neqsim.thermodynamicoperations.ThermodynamicOperations(thermoSystem2); CalculationResult res2 = thermoOps2.propertyFlash(jP2, jT2, 1, null, onlineFractions2); // Assert no calculation failed for (String errorMessage : res.calculationError) { @@ -269,10 +264,10 @@ void testComponentNames() { void testPropertyFlash() { SystemInterface fluid = new SystemSrkEos(273.15 + 45.0, 22.0); - List Sp1 = Arrays.asList(new Double[] {100000.0, 1000000.0, 10000000.0, 20000000.0, - 100000.0, 1000000.0, 10000000.0, 20000000.0, 100000.0, 1000000.0, 10000000.0, 20000000.0}); - List Sp2 = Arrays.asList(new Double[] {288.15, 288.15, 288.15, 288.15, 303.15, 303.15, - 303.15, 303.15, 423.15, 423.15, 423.15, 423.15}); + List Sp1 = Arrays.asList(new Double[] { 100000.0, 1000000.0, 10000000.0, 20000000.0, + 100000.0, 1000000.0, 10000000.0, 20000000.0, 100000.0, 1000000.0, 10000000.0, 20000000.0 }); + List Sp2 = Arrays.asList(new Double[] { 288.15, 288.15, 288.15, 288.15, 303.15, 303.15, + 303.15, 303.15, 423.15, 423.15, 423.15, 423.15 }); fluid.addComponent("water", 0.01); fluid.addComponent("nitrogen", 0.02); @@ -286,7 +281,7 @@ void testPropertyFlash() { fluid.addComponent("n-pentane", 0.01); fluid.addComponent("n-hexane", 0.01); fluid.setMolarComposition( - new double[] {0.054, 0.454, 1.514, 89.92, 5.324, 1.535, 0.232, 0.329, 0.094, 0.107, 0.437}); + new double[] { 0.054, 0.454, 1.514, 89.92, 5.324, 1.535, 0.232, 0.329, 0.094, 0.107, 0.437 }); ThermodynamicOperations ops = new ThermodynamicOperations(fluid); CalculationResult s = ops.propertyFlash(Sp1, Sp2, 1, null, null); @@ -302,8 +297,8 @@ void testPropertyFlash() { @Test void testpropertyFlashOnline() { - String[] components = {"nitrogen", "oxygen"}; - double[] fractions = {0.79, 0.21}; + String[] components = { "nitrogen", "oxygen" }; + double[] fractions = { 0.79, 0.21 }; int len = 10; List> onlineFractions = createDummyRequest(fractions, len); @@ -313,8 +308,8 @@ void testpropertyFlashOnline() { // fluid.setTotalFlowRate(1, "mole/sec"); // fluid.init(0); - Double[] pressure = {1.0, 1.5, 2.0, 2.5, 3.0, 4.0, 4.0, 3.5, 3.0, 2.5}; - Double[] temperature = {301.0, 301.5, 302.0, 302.5, 303.0, 304.0, 304.0, 303.5, 303.0, 302.5}; + Double[] pressure = { 1.0, 1.5, 2.0, 2.5, 3.0, 4.0, 4.0, 3.5, 3.0, 2.5 }; + Double[] temperature = { 301.0, 301.5, 302.0, 302.5, 303.0, 304.0, 304.0, 303.5, 303.0, 302.5 }; ThermodynamicOperations ops = new ThermodynamicOperations(fluid); CalculationResult s = ops.propertyFlash(Arrays.asList(pressure), Arrays.asList(temperature), 1, @@ -324,8 +319,8 @@ void testpropertyFlashOnline() { @Test void testpropertyFlashOnlineSingle() { - String[] components = {"nitrogen"}; - double[] fractions = {0.98}; + String[] components = { "nitrogen" }; + double[] fractions = { 0.98 }; int len = 10; List> onlineFractions = createDummyRequest(fractions, len); @@ -333,10 +328,8 @@ void testpropertyFlashOnlineSingle() { fluid.addComponents(components); fluid.addComponent("oxygen"); - Double[] pressure = - new Double[] {22.1, 23.2, 24.23, 25.98, 25.23, 26.1, 27.3, 28.7, 23.5, 22.7}; - Double[] temperature = - new Double[] {288.1, 290.1, 295.1, 301.2, 299.3, 310.2, 315.3, 310.0, 305.2, 312.7}; + Double[] pressure = new Double[] { 22.1, 23.2, 24.23, 25.98, 25.23, 26.1, 27.3, 28.7, 23.5, 22.7 }; + Double[] temperature = new Double[] { 288.1, 290.1, 295.1, 301.2, 299.3, 310.2, 315.3, 310.0, 305.2, 312.7 }; ThermodynamicOperations ops = new ThermodynamicOperations(fluid); CalculationResult s = ops.propertyFlash(Arrays.asList(pressure), Arrays.asList(temperature), 1, @@ -346,13 +339,13 @@ void testpropertyFlashOnlineSingle() { @Test void testpropertyFlashOnlineTooFewInputComponents() { - String[] components = {"nitrogen", "oxygen"}; - double[] fractions = {0.79, 0.21}; + String[] components = { "nitrogen", "oxygen" }; + double[] fractions = { 0.79, 0.21 }; int len = 10; List> onlineFractions = createDummyRequest(fractions, len); - Double[] pressure = {1.0, 1.5, 2.0, 2.5, 3.0, 4.0, 4.0, 3.5, 3.0, 2.5}; - Double[] temperature = {301.0, 301.5, 302.0, 302.5, 303.0, 304.0, 304.0, 303.5, 303.0, 302.5}; + Double[] pressure = { 1.0, 1.5, 2.0, 2.5, 3.0, 4.0, 4.0, 3.5, 3.0, 2.5 }; + Double[] temperature = { 301.0, 301.5, 302.0, 302.5, 303.0, 304.0, 304.0, 303.5, 303.0, 302.5 }; SystemInterface fluid = new SystemSrkEos(298, 1.0); // Add extra component C1 @@ -371,17 +364,17 @@ void testpropertyFlashOnlineTooFewInputComponents() { @Test void testPropertyFlashTooManyInputComponents() { int len = 10; - String[] components_too_many = {"nitrogen", "oxygen", "water"}; - double[] fractions_to_many = {0.79, 0.21, 0.01}; + String[] components_too_many = { "nitrogen", "oxygen", "water" }; + double[] fractions_to_many = { 0.79, 0.21, 0.01 }; - Double[] pressure = {1.0, 1.5, 2.0, 2.5, 3.0, 4.0, 4.0, 3.5, 3.0, 2.5}; - Double[] temperature = {301.0, 301.5, 302.0, 302.5, 303.0, 304.0, 304.0, 303.5, 303.0, 302.5}; + Double[] pressure = { 1.0, 1.5, 2.0, 2.5, 3.0, 4.0, 4.0, 3.5, 3.0, 2.5 }; + Double[] temperature = { 301.0, 301.5, 302.0, 302.5, 303.0, 304.0, 304.0, 303.5, 303.0, 302.5 }; List> onlineFractions_too_many = createDummyRequest(fractions_to_many, len); SystemInterface fluid = new SystemSrkEos(298, 1.0); // Add only two components to fluid - String[] components = {"nitrogen", "oxygen"}; + String[] components = { "nitrogen", "oxygen" }; fluid.addComponents(components); ThermodynamicOperations ops = new ThermodynamicOperations(fluid); CalculationResult s = ops.propertyFlash(Arrays.asList(pressure), Arrays.asList(temperature), 1, @@ -396,7 +389,8 @@ void testPropertyFlashTooManyInputComponents() { @SuppressWarnings("unchecked") void testpropertyFlashRegressions() throws IOException { // TODO: make these tests work - // make output log of differences per failing test and see check if it is related to change in + // make output log of differences per failing test and see check if it is + // related to change in // component input data Collection testData = getTestData(); @@ -411,7 +405,8 @@ void testpropertyFlashRegressions() throws IOException { if (compNames == null) { // System.out.println("Skips test " + test.toString()); /* - * for (int k = 0; k < fractions.size(); k++) { fluid.addComponent(k, fractions.get(k)); } + * for (int k = 0; k < fractions.size(); k++) { fluid.addComponent(k, + * fractions.get(k)); } */ continue; } else { @@ -474,8 +469,7 @@ private List> createDummyRequest(double[] fractions, int len) { private Collection getTestData() throws IOException { ClassLoader classLoader = getClass().getClassLoader(); - File folder = - new File(classLoader.getResource("neqsim/thermodynamicOperations/testcases").getFile()); + File folder = new File(classLoader.getResource("neqsim/thermodynamicoperations/testcases").getFile()); HashMap testData = new HashMap<>(); @@ -524,7 +518,8 @@ public void setOutputFile(String outputFile) { private void setInput(String inputFile) throws IOException { String fileContents = new String(Files.readAllBytes(Paths.get(inputFile))); Gson gson = new Gson(); - Type type = new TypeToken>() {}.getType(); + Type type = new TypeToken>() { + }.getType(); input = gson.fromJson(fileContents, type); @@ -548,11 +543,11 @@ private HashMap getInput() { public CalculationResult getOutput() throws IOException { String fileContents = new String(Files.readAllBytes(Paths.get(this.getOutputFile()))); Gson gson = new Gson(); - Type type = new TypeToken>() {}.getType(); + Type type = new TypeToken>() { + }.getType(); HashMap outputData = gson.fromJson(fileContents, type); - ArrayList> calcresult = - (ArrayList>) outputData.get("calcresult"); + ArrayList> calcresult = (ArrayList>) outputData.get("calcresult"); Double[][] calcResult = new Double[calcresult.size()][]; for (int kSample = 0; kSample < calcresult.size(); kSample++) {