Skip to content

Commit

Permalink
feat: support the old names
Browse files Browse the repository at this point in the history
  • Loading branch information
asmfstatoil committed Oct 27, 2024
1 parent d11f1d2 commit 856de59
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,21 @@ public enum PhysicalPropertyType {
* @return PhysicalPropertyType object
*/
public static PhysicalPropertyType byName(String name) {
// suport old names
name = name.toUpperCase();
if (name.equals("DENSITY")) {
name = "MASS_DENSITY";
}
if (name.equals("VISCOSITY")) {
name = "DYNAMIC_VISCOSITY";
}
if (name.equals("CONDUCTIVITY")) {
name = "THERMAL_CONDUCTIVITY";
}

// todo: consider replacing this function with built-in valueOf
for (PhysicalPropertyType pt : copyOfValues) {
if (pt.name().equals(name.toUpperCase())) {
if (pt.name().equals(name)) {
return pt;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,19 @@ public double calcKinematicViscosity() {
* </p>
*/
public void setPhases() {
conductivityCalc.setPhase(this);
densityCalc.setPhase(this);
viscosityCalc.setPhase(this);
diffusivityCalc.setPhase(this);
// Check for null to make it safe to call this function from subclass constructors.
if (conductivityCalc != null) {
conductivityCalc.setPhase(this);
}
if (densityCalc != null) {
densityCalc.setPhase(this);
}
if (viscosityCalc != null) {
viscosityCalc.setPhase(this);
}
if (diffusivityCalc != null) {
diffusivityCalc.setPhase(this);
}
}

/** {@inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public void setMixingRule(
* @param name Name of physical property.
*/
public default void init(PhaseInterface phase, String name) {
init(phase, PhysicalPropertyType.byName(name.toUpperCase()));
init(phase, PhysicalPropertyType.byName(name));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/neqsim/thermo/phase/PhaseInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public void init(double totalNumberOfMoles, int numberOfComponents, int initType
* @param name Name of physical property.
*/
public default void initPhysicalProperties(String name) {
initPhysicalProperties(PhysicalPropertyType.byName(name.toUpperCase()));
initPhysicalProperties(PhysicalPropertyType.byName(name));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/neqsim/thermo/system/SystemInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -1742,7 +1742,7 @@ public default void init() {
* @param name Name of physical property.
*/
public default void initPhysicalProperties(String name) {
initPhysicalProperties(PhysicalPropertyType.byName(name.toUpperCase()));
initPhysicalProperties(PhysicalPropertyType.byName(name));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,26 @@ public class PhysicalPropertyTypeTest {
void testByName() {
assertEquals(PhysicalPropertyType.byName("DENSITY"), PhysicalPropertyType.MASS_DENSITY);
assertEquals(PhysicalPropertyType.byName("density"), PhysicalPropertyType.MASS_DENSITY);
assertEquals(PhysicalPropertyType.byName("mass_density"), PhysicalPropertyType.MASS_DENSITY);

assertEquals(PhysicalPropertyType.byName("VISCOSITY"), PhysicalPropertyType.DYNAMIC_VISCOSITY);
assertEquals(PhysicalPropertyType.byName("dynamic_VISCOSITY"),
PhysicalPropertyType.DYNAMIC_VISCOSITY);

assertEquals(PhysicalPropertyType.byName("CONDUCTIVITY"),
PhysicalPropertyType.THERMAL_CONDUCTIVITY);
assertEquals(PhysicalPropertyType.byName("thermal_CONDUCTIVITY"),
PhysicalPropertyType.THERMAL_CONDUCTIVITY);
assertEquals(PhysicalPropertyType.byName("conductivity"),
PhysicalPropertyType.THERMAL_CONDUCTIVITY);
assertEquals(PhysicalPropertyType.byName("viscosity"), PhysicalPropertyType.DYNAMIC_VISCOSITY);
}

@Test
void testValueOf() {
assertEquals(PhysicalPropertyType.MASS_DENSITY, PhysicalPropertyType.valueOf("DENSITY"));
assertEquals(PhysicalPropertyType.MASS_DENSITY, PhysicalPropertyType.valueOf("MASS_DENSITY"));
assertEquals(PhysicalPropertyType.MASS_DENSITY,
PhysicalPropertyType.valueOf("density".toUpperCase()));
PhysicalPropertyType.valueOf("mass_density".toUpperCase()));

SystemInterface thermoSystem = new SystemPrEos(318.0, 20.01325);
thermoSystem.addComponent("CO2", 1.0);
Expand Down

0 comments on commit 856de59

Please sign in to comment.