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

add text output for ops #823

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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 @@ -299,4 +299,15 @@ public String getReport_json() {
/** {@inheritDoc} */
@Override
public void run_step(UUID id) {}

/** {@inheritDoc} */
@Override
public String[][] createTable(String name) {
String[][] table = new String[50][3];
String[] names = {"Property", "Value", "Unit"};
table[0][0] = "";
table[0][1] = "";
table[0][2] = "";
return table;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,19 @@ public default SystemInterface getFluid() {
/** {@inheritDoc} */
@Override
public String getReport_json();

/**
* Prints the fluid in a visually appealing way.
*/
public default void prettyPrint() {
neqsim.thermo.util.readwrite.TablePrinter.printTable(createTable(getName()));
}

/**
* Create table.
*
* @param name
* @return
*/
public String[][] createTable(String name);
}
48 changes: 48 additions & 0 deletions src/main/java/neqsim/process/equipment/pump/Pump.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,22 @@ public double getEnergy() {
return dH;
}

/**
* Return head in specified unit.
*
* @param unit unit can be or kJ/kg
*/
public double getHead(String unit) {
if (unit.equals("meter")) {
return (getOutletStream().getPressure("bara") - getInletStream().getPressure("bara"))
/ (1000.0 * ThermodynamicConstantsInterface.gravity / 1.0E5);
} else if (unit.equals("kJ/kg")) {
return getPower("kW") / getInletStream().getFlowRate("kg/sec");
}
throw new RuntimeException(
new neqsim.util.exception.InvalidInputException(this, "getHead", unit));
}

/** {@inheritDoc} */
@Override
public double getPower() {
Expand Down Expand Up @@ -190,6 +206,38 @@ public void run(UUID id) {
// outStream.run(id);
}

/** {@inheritDoc} */
@ExcludeFromJacocoGeneratedReport
public String[][] createTable(String name) {
DecimalFormat nf = new DecimalFormat();
nf.setMaximumFractionDigits(5);
nf.applyPattern("#.#####E0");

String[][] table = new String[4][3];
String[] names = {"Property", "Value", "Unit"};
table[0][0] = "";
table[0][1] = "";
table[0][2] = "";
StringBuffer buf = new StringBuffer();
FieldPosition test = new FieldPosition(0);

table[1][0] = "Inlet pressure";
buf = new StringBuffer();
table[1][1] = nf.format(inStream.getPressure("bara"), buf, test).toString();
table[1][2] = "bara";

table[2][0] = "Outlet pressure";
buf = new StringBuffer();
table[2][1] = nf.format(outStream.getPressure("bara"), buf, test).toString();
table[2][2] = "bara";

table[3][0] = "Head";
buf = new StringBuffer();
table[3][1] = nf.format(getHead("meter"), buf, test).toString();
table[3][2] = "meter";
return table;
}

/** {@inheritDoc} */
@Override
@ExcludeFromJacocoGeneratedReport
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,15 @@ public String getReport_json() {
/** {@inheritDoc} */
@Override
public void run_step(UUID id) {}

/** {@inheritDoc} */
@Override
public String[][] createTable(String name) {
String[][] table = new String[50][3];
String[] names = {"Property", "Value", "Unit"};
table[0][0] = "";
table[0][1] = "";
table[0][2] = "";
return table;
}
}
2 changes: 2 additions & 0 deletions src/test/java/neqsim/process/equipment/pump/PumpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ void testSimplePumpCurve() {
pump1.setSpeed(500);
pump1.run();

pump1.prettyPrint();

Assertions.assertEquals(7.274237081101, pump1.getOutletPressure(), 1e-5);
}
}