Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
EvenSol committed Dec 7, 2024
1 parent 48b6519 commit 7723757
Showing 1 changed file with 56 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -55,12 +56,11 @@ void testFlash() {

@Test
void testFluidDefined() {
double[] fractions = new double[] {98.0, 2.0};
List<Double> 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<Double> 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<Double> 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<String> 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<String> components = Arrays.asList(new String[] { "O2", "N2" });
List<List<Double>> onlineFractions = new ArrayList<List<Double>>();

for (double d : fractions) {
Expand Down Expand Up @@ -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
Expand All @@ -134,10 +135,9 @@ void testNeqSimPython() {
thermoSystem.addComponent("ethane", 0.3);
thermoSystem.init(0);

ThermodynamicOperations thermoOps =
new neqsim.thermodynamicoperations.ThermodynamicOperations(thermoSystem);
List<Double> jP = Arrays.asList(new Double[] {10.0});
List<Double> jT = Arrays.asList(new Double[] {280.0});
ThermodynamicOperations thermoOps = new neqsim.thermodynamicoperations.ThermodynamicOperations(thermoSystem);
List<Double> jP = Arrays.asList(new Double[] { 10.0 });
List<Double> jT = Arrays.asList(new Double[] { 280.0 });
CalculationResult res = thermoOps.propertyFlash(jP, jT, 1, null, null);

// Verify some basic properties
Expand All @@ -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<Double> jP = Arrays.asList(new Double[] {press});
List<Double> jT = Arrays.asList(new Double[] {temp});
List<Double> jP = Arrays.asList(new Double[] { press });
List<Double> jT = Arrays.asList(new Double[] { temp });
CalculationResult res = thermoOps.propertyFlash(jP, jT, 1, null, null);
// Assert no calculation failed
for (String errorMessage : res.calculationError) {
Expand All @@ -210,15 +207,13 @@ void testNeqSimPython2() {
Assertions.assertArrayEquals(res.fluidProperties[0], res1.fluidProperties[0]);

int numFrac = 3;
List<List<Double>> onlineFractions2 =
createDummyRequest(thermoSystem.getMolarComposition(), numFrac);
List<List<Double>> onlineFractions2 = createDummyRequest(thermoSystem.getMolarComposition(), numFrac);

List<Double> jP2 = Arrays.asList(new Double[] {press, press});
List<Double> jT2 = Arrays.asList(new Double[] {temp, temp});
List<Double> jP2 = Arrays.asList(new Double[] { press, press });
List<Double> 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) {
Expand Down Expand Up @@ -269,10 +264,10 @@ void testComponentNames() {
void testPropertyFlash() {
SystemInterface fluid = new SystemSrkEos(273.15 + 45.0, 22.0);

List<Double> 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<Double> 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<Double> 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<Double> 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);
Expand All @@ -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);
Expand All @@ -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<List<Double>> onlineFractions = createDummyRequest(fractions, len);

Expand All @@ -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,
Expand All @@ -324,19 +319,17 @@ void testpropertyFlashOnline() {

@Test
void testpropertyFlashOnlineSingle() {
String[] components = {"nitrogen"};
double[] fractions = {0.98};
String[] components = { "nitrogen" };
double[] fractions = { 0.98 };
int len = 10;
List<List<Double>> onlineFractions = createDummyRequest(fractions, len);

SystemInterface fluid = new SystemSrkEos(298, 1.0);
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,
Expand All @@ -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<List<Double>> 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
Expand All @@ -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<List<Double>> 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,
Expand All @@ -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> testData = getTestData();

Expand All @@ -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 {
Expand Down Expand Up @@ -474,8 +469,7 @@ private List<List<Double>> createDummyRequest(double[] fractions, int len) {

private Collection<TestData> 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<String, TestData> testData = new HashMap<>();

Expand Down Expand Up @@ -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<HashMap<String, Object>>() {}.getType();
Type type = new TypeToken<HashMap<String, Object>>() {
}.getType();

input = gson.fromJson(fileContents, type);

Expand All @@ -548,11 +543,11 @@ private HashMap<String, Object> getInput() {
public CalculationResult getOutput() throws IOException {
String fileContents = new String(Files.readAllBytes(Paths.get(this.getOutputFile())));
Gson gson = new Gson();
Type type = new TypeToken<HashMap<String, Object>>() {}.getType();
Type type = new TypeToken<HashMap<String, Object>>() {
}.getType();

HashMap<String, Object> outputData = gson.fromJson(fileContents, type);
ArrayList<ArrayList<Double>> calcresult =
(ArrayList<ArrayList<Double>>) outputData.get("calcresult");
ArrayList<ArrayList<Double>> calcresult = (ArrayList<ArrayList<Double>>) outputData.get("calcresult");

Double[][] calcResult = new Double[calcresult.size()][];
for (int kSample = 0; kSample < calcresult.size(); kSample++) {
Expand Down

0 comments on commit 7723757

Please sign in to comment.