From 1b7c922fe6783cdce2da61eca85a0b3043acea82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85smund=20V=C3=A5ge=20Fannemel?= <34712686+asmfstatoil@users.noreply.github.com> Date: Wed, 20 Mar 2024 11:50:45 +0100 Subject: [PATCH 1/4] feat: Phase.hasComponent check against normalized name feat: new function Phase.getComponentNames fix: check that compnumber is not already in use --- .../thermo/component/ComponentInterface.java | 2 +- src/main/java/neqsim/thermo/phase/Phase.java | 33 +++++++++++++++-- .../neqsim/thermo/phase/PhaseInterface.java | 23 ++++++++++-- .../neqsim/thermo/system/SystemInterface.java | 35 +++++++++++-------- .../neqsim/thermo/system/SystemThermo.java | 24 +++++-------- .../neqsim/thermo/phase/PhaseSrkEosTest.java | 6 ++++ 6 files changed, 87 insertions(+), 36 deletions(-) diff --git a/src/main/java/neqsim/thermo/component/ComponentInterface.java b/src/main/java/neqsim/thermo/component/ComponentInterface.java index 013eed255..612cc9c67 100644 --- a/src/main/java/neqsim/thermo/component/ComponentInterface.java +++ b/src/main/java/neqsim/thermo/component/ComponentInterface.java @@ -1416,7 +1416,7 @@ public default double getLogFugacityCoefficient() { /** *

- * getName. + * Getter for property componentName, i.e., normalized component name. *

* * @return a {@link java.lang.String} object diff --git a/src/main/java/neqsim/thermo/phase/Phase.java b/src/main/java/neqsim/thermo/phase/Phase.java index 8c2228796..d7fc64ca4 100644 --- a/src/main/java/neqsim/thermo/phase/Phase.java +++ b/src/main/java/neqsim/thermo/phase/Phase.java @@ -1768,10 +1768,37 @@ public ComponentInterface getComponent(String name) { /** {@inheritDoc} */ @Override - public boolean hasComponent(String name) { + public String[] getComponentNames() { + ArrayList components = new ArrayList(); + + for (int j = 0; j < componentArray.length; j++) { + if (componentArray[j] != null) { + components.add(componentArray[j].getComponentName()); + } + } + + String[] componentList = new String[components.size()]; + for (int j = 0; j < numberOfComponents; j++) { + componentList[j] = components.get(j); + } + return componentList; + } + + /** {@inheritDoc} */ + @Override + public boolean hasComponent(String name, boolean normalized) { for (int i = 0; i < numberOfComponents; i++) { - if (componentArray[i].getName().equals(name)) { - return true; + if (componentArray != null) { + if (normalized) { + if (componentArray[i].getComponentName() + .equals(ComponentInterface.getComponentNameFromAlias(name))) { + return true; + } + } else { + if (componentArray[i].getName().equals(name)) { + return true; + } + } } } return false; diff --git a/src/main/java/neqsim/thermo/phase/PhaseInterface.java b/src/main/java/neqsim/thermo/phase/PhaseInterface.java index 60b1a1b2c..101267226 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseInterface.java +++ b/src/main/java/neqsim/thermo/phase/PhaseInterface.java @@ -329,13 +329,21 @@ public void init(double totalNumberOfMoles, int numberOfComponents, int initType /** *

- * getcomponentArray. + * Get component array of Phase. *

* * @return an array of {@link neqsim.thermo.component.ComponentInterface} objects */ public ComponentInterface[] getcomponentArray(); + + /** + * Get normalized names of components in phase. + * + * @return Array of names of components in phase. + */ + public String[] getComponentNames(); + /** *

* getMass. @@ -1903,13 +1911,24 @@ public default void setPhaseTypeName(String phaseTypeName) { */ public double getActivityCoefficientUnSymetric(int k); + /** + * Verify if phase has a component. + * + * @param name Name of component to look for. NB! Converts name to normalized name. + * @return True if component is found. + */ + public default boolean hasComponent(String name) { + return hasComponent(name, true); + } + /** * Verify if phase has a component. * * @param name Name of component to look for. + * @param normalized Set true to convert input name to normalized component name. * @return True if component is found. */ - public boolean hasComponent(String name); + public boolean hasComponent(String name, boolean normalized); /** *

diff --git a/src/main/java/neqsim/thermo/system/SystemInterface.java b/src/main/java/neqsim/thermo/system/SystemInterface.java index f7e2b64bc..01ac9ca8f 100644 --- a/src/main/java/neqsim/thermo/system/SystemInterface.java +++ b/src/main/java/neqsim/thermo/system/SystemInterface.java @@ -644,9 +644,9 @@ public default void display() { public String[] getCompIDs(); /** - * Get names of all components in System. + * Get normalized names of all components in System. * - * @return an array of {@link java.lang.String} objects + * @return Array of names of components in System. */ public String[] getCompNames(); @@ -675,13 +675,14 @@ public default ComponentInterface getComponent(String name) { } /** - *

- * Getter for property componentNames. - *

+ * Get normalized names of components in System. * - * @return Component names in system. + * @return Array of names of components in system. */ - public String[] getComponentNames(); + public default String[] getComponentNames() { + return getPhase(0).getComponentNames(); + } + /** *

@@ -1616,16 +1617,22 @@ public default int getPhaseNumberOfPhase(String phaseTypeName) { /** * Verify if system has a component. * - * @param name Name of component to look for. + * @param name Name of component to look for. NB! Converts name to normalized name. * @return True if component is found. */ public default boolean hasComponent(String name) { - for (String fluidComp : getComponentNames()) { - if (name == fluidComp) { - return true; - } - } - return false; + return hasComponent(name, true); + } + + /** + * Verify if system has a component. + * + * @param name Name of component to look for. + * @param normalized Set true to convert input name to normalized component name. + * @return True if component is found. + */ + public default boolean hasComponent(String name, boolean normalized) { + return getPhase(0).hasComponent(name, normalized); } /** {@inheritDoc} */ diff --git a/src/main/java/neqsim/thermo/system/SystemThermo.java b/src/main/java/neqsim/thermo/system/SystemThermo.java index b3c91b7f9..8a999cda7 100644 --- a/src/main/java/neqsim/thermo/system/SystemThermo.java +++ b/src/main/java/neqsim/thermo/system/SystemThermo.java @@ -33,10 +33,12 @@ * This is the base class of the System classes. */ public abstract class SystemThermo implements SystemInterface { + /** Logger object for class. */ static Logger logger = LogManager.getLogger(SystemThermo.class); // Class variables private static final int MAX_PHASES = 6; + /** Serialization version UID. */ private static final long serialVersionUID = 1000; protected int a; @@ -945,7 +947,7 @@ public void addTBPfraction(String componentName, double numberOfMoles, double mo getPhase(i).getComponent(componentName).setIsTBPfraction(true); getPhase(i).getComponent(componentName).setParachorParameter( characterization.getTBPModel().calcParachorParameter(molarMass, density)); // 59.3+2.34*molarMass*1000.0); - // //0.5003*thermo.ThermodynamicConstantsInterface.R*TC/PC*(0.25969-racketZ)); + // 0.5003*thermo.ThermodynamicConstantsInterface.R*TC/PC*(0.25969-racketZ)); getPhase(i).getComponent(componentName).setCriticalViscosity( characterization.getTBPModel().calcCriticalViscosity(molarMass * 1000.0, density)); // 7.94830*Math.sqrt(1e3*molarMass)*Math.pow(PC,2.0/3.0)/Math.pow(TC, // 1.0/6.0)*1e-7); @@ -1934,21 +1936,6 @@ public String[] getCompNames() { return names; } - /** {@inheritDoc} */ - @Override - public String[] getComponentNames() { - ArrayList components = new ArrayList(); - - for (int j = 0; j < numberOfComponents; j++) { - components.add(phaseArray[0].getComponents()[j].getName()); - } - String[] componentList = new String[components.size()]; - for (int j = 0; j < numberOfComponents; j++) { - componentList[j] = components.get(j); - } - return componentList; - } - /** {@inheritDoc} */ @Override public String getComponentNameTag() { @@ -3038,6 +3025,11 @@ public neqsim.standards.StandardInterface getStandard(String standardName) { return standard; } + /** + * Get sum of phase beta values. + * + * @return Sum of beta beta values + */ public final double getSumBeta() { double sum = 0; for (int k = 0; k < numberOfPhases; k++) { diff --git a/src/test/java/neqsim/thermo/phase/PhaseSrkEosTest.java b/src/test/java/neqsim/thermo/phase/PhaseSrkEosTest.java index 82e957839..38261124a 100644 --- a/src/test/java/neqsim/thermo/phase/PhaseSrkEosTest.java +++ b/src/test/java/neqsim/thermo/phase/PhaseSrkEosTest.java @@ -18,6 +18,9 @@ void testAddcomponent() { p.addComponent("ethane", 0, 0, 0); Assertions.assertEquals(1, p.getNumberOfComponents()); + Assertions.assertTrue(p.hasComponent("ethane")); + Assertions.assertTrue(p.hasComponent("C2")); + Assertions.assertFalse(p.hasComponent("C2", false)); try { p.addComponent("methane", 0, 0, 0); } catch (Exception e) { @@ -27,6 +30,9 @@ void testAddcomponent() { p.addComponent("methane", 0, 0, 1); Assertions.assertEquals(2, p.getNumberOfComponents()); + String[] d = p.getComponentNames(); + Assertions.assertTrue(d[0].equals("ethane")); + Assertions.assertTrue(d[1].equals("methane")); } @Test From 92f5c07602a33a8a3467bc5bc1573a7598b99325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85smund=20V=C3=A5ge=20Fannemel?= <34712686+asmfstatoil@users.noreply.github.com> Date: Thu, 21 Mar 2024 11:00:14 +0100 Subject: [PATCH 2/4] Update verify_build.yml --- .github/workflows/verify_build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/verify_build.yml b/.github/workflows/verify_build.yml index 3ae0bf958..a1285b757 100644 --- a/.github/workflows/verify_build.yml +++ b/.github/workflows/verify_build.yml @@ -29,11 +29,11 @@ jobs: - name: Create coverage report from jacoco execution data run: mvn -B jacoco:report -ntp - name: Upload jacoco coverage reports to Codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 with: file: jacoco.xml name: codecov - tags: coverage + # tags: coverage test_java_8: name: Assert tests with java 8 From e244b9c5d8efe7c13769df667b3f0580b8109fd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85smund=20V=C3=A5ge=20Fannemel?= <34712686+asmfstatoil@users.noreply.github.com> Date: Thu, 21 Mar 2024 12:08:48 +0100 Subject: [PATCH 3/4] test: increase coverage --- src/test/java/neqsim/thermo/phase/PhaseSrkEosTest.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/test/java/neqsim/thermo/phase/PhaseSrkEosTest.java b/src/test/java/neqsim/thermo/phase/PhaseSrkEosTest.java index 38261124a..1472cafae 100644 --- a/src/test/java/neqsim/thermo/phase/PhaseSrkEosTest.java +++ b/src/test/java/neqsim/thermo/phase/PhaseSrkEosTest.java @@ -15,12 +15,20 @@ void setUp() { @Test void testAddcomponent() { Assertions.assertEquals(0, p.getNumberOfComponents()); + Assertions.assertFalse(p.hasComponent("ethane")); p.addComponent("ethane", 0, 0, 0); Assertions.assertEquals(1, p.getNumberOfComponents()); + Assertions.assertTrue(p.hasComponent("ethane")); + + // Expects True because C2 normalized -> ethane Assertions.assertTrue(p.hasComponent("C2")); + // Expects True because was created as ethane + Assertions.assertTrue(p.hasComponent("ethane", false)); + // expects False because C2 is not equal to ethane Assertions.assertFalse(p.hasComponent("C2", false)); + try { p.addComponent("methane", 0, 0, 0); } catch (Exception e) { From 398747bced55cc9b470f4651f83aa4e44bb6c430 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85smund=20V=C3=A5ge=20Fannemel?= <34712686+asmfstatoil@users.noreply.github.com> Date: Thu, 21 Mar 2024 12:13:42 +0100 Subject: [PATCH 4/4] docfix --- src/main/java/neqsim/thermo/phase/Phase.java | 2 +- src/main/java/neqsim/thermo/phase/PhaseInterface.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/neqsim/thermo/phase/Phase.java b/src/main/java/neqsim/thermo/phase/Phase.java index d7fc64ca4..e2f51d1ee 100644 --- a/src/main/java/neqsim/thermo/phase/Phase.java +++ b/src/main/java/neqsim/thermo/phase/Phase.java @@ -101,7 +101,7 @@ public Phase clone() { /** *

- * addcomponent. Increase number of components and add moles to phase. + * Increase number of components and add moles to phase. * * NB! Does not actually add component to componentarray. *

diff --git a/src/main/java/neqsim/thermo/phase/PhaseInterface.java b/src/main/java/neqsim/thermo/phase/PhaseInterface.java index 101267226..8ab3dc57f 100644 --- a/src/main/java/neqsim/thermo/phase/PhaseInterface.java +++ b/src/main/java/neqsim/thermo/phase/PhaseInterface.java @@ -21,7 +21,7 @@ public interface PhaseInterface extends ThermodynamicConstantsInterface, Cloneable { /** *

- * addcomponent. + * Add component to component array and update moles variables. *

* * @param name Name of component.