Skip to content

Commit

Permalink
update json reporting (#1016)
Browse files Browse the repository at this point in the history
* update json reporting

* update test
  • Loading branch information
EvenSol authored May 20, 2024
1 parent afac3a9 commit 8b23ec9
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,10 @@ public boolean equals(Object obj) {
&& Objects.equals(waterSystem, other.waterSystem);
}

public StreamInterface getFeedStream() {
return new Stream(getName(), getThermoSystem());
}

/** {@inheritDoc} */
@Override
public String toJson() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
public class SeparatorResponse {
public String name;
public Double gasLoadFactor;
public Double massflow;
public FluidResponse gasFluid, liquidFluid, oilFluid, waterFluid;
public StreamResponse feed, gas, liquid, oil, water;

/**
* <p>
Expand All @@ -27,17 +26,19 @@ public class SeparatorResponse {
*/
public SeparatorResponse(ThreePhaseSeparator inputSeparator) {
name = inputSeparator.getName();
massflow = inputSeparator.getFluid().getFlowRate("kg/hr");
gasLoadFactor = inputSeparator.getGasLoadFactor();

feed = new StreamResponse(inputSeparator.getFeedStream());
if (inputSeparator.getThermoSystem().hasPhaseType("aqueous")) {
waterFluid = new FluidResponse(inputSeparator.getWaterOutStream().getFluid());
water = new StreamResponse(inputSeparator.getWaterOutStream());
}
if (inputSeparator.getThermoSystem().hasPhaseType("oil")) {
oilFluid = new FluidResponse(inputSeparator.getOilOutStream().getFluid());
oil = new StreamResponse(inputSeparator.getOilOutStream());
}
if (inputSeparator.getThermoSystem().hasPhaseType("gas")) {
gasFluid = new FluidResponse(inputSeparator.getGasOutStream().getFluid());
gas = new StreamResponse(inputSeparator.getGasOutStream());
}

}

/**
Expand All @@ -50,20 +51,15 @@ public SeparatorResponse(ThreePhaseSeparator inputSeparator) {
*/
public SeparatorResponse(Separator inputSeparator) {
name = inputSeparator.getName();
massflow = inputSeparator.getFluid().getFlowRate("kg/hr");
gasLoadFactor = inputSeparator.getGasLoadFactor();
if (inputSeparator.getThermoSystem().hasPhaseType("aqueous")) {
waterFluid = new FluidResponse(inputSeparator.getThermoSystem().phaseToSystem("aqueous"));
}
if (inputSeparator.getThermoSystem().hasPhaseType("oil")) {
oilFluid = new FluidResponse(inputSeparator.getThermoSystem().phaseToSystem("oil"));
feed = new StreamResponse(inputSeparator.getFeedStream());
if (inputSeparator.getThermoSystem().hasPhaseType("aqueous")
|| inputSeparator.getThermoSystem().hasPhaseType("liquid")
|| inputSeparator.getThermoSystem().hasPhaseType("oil")) {
liquid = new StreamResponse(inputSeparator.getLiquidOutStream());
}
if (inputSeparator.getThermoSystem().hasPhaseType("gas")) {
gasFluid = new FluidResponse(inputSeparator.getGasOutStream().getFluid());
}
if (inputSeparator.getThermoSystem().hasPhaseType("oil")
|| inputSeparator.getThermoSystem().hasPhaseType("aqueous")) {
liquidFluid = new FluidResponse(inputSeparator.getLiquidOutStream().getFluid());
gas = new StreamResponse(inputSeparator.getGasOutStream());
}
}
}
14 changes: 2 additions & 12 deletions src/main/java/neqsim/processSimulation/util/report/Report.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package neqsim.processSimulation.util.report;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
Expand All @@ -23,9 +22,6 @@
* @version $Id: $Id
*/
public class Report {
private HashMap<String, List<String[]>> reports = new HashMap<>();
private HashMap<String, String> json_reports = new HashMap<>();
Gson gson = new Gson();
ProcessSystem process = null;
ProcessEquipmentBaseClass processEquipment = null;
SystemInterface fluid = null;
Expand Down Expand Up @@ -65,17 +61,13 @@ public String generateJsonReport() {
json_reports.put(fluid.getFluidName(), fluid.toJson());
}

// Create a Gson instance
Gson gson = new Gson();
JsonParser jsonParser = new JsonParser();

// Create a JsonObject to hold the parsed nested JSON objects
JsonObject finalJsonObject = new JsonObject();

// Iterate through the entries of the json_reports map
for (Map.Entry<String, String> entry : json_reports.entrySet()) {
// Parse each value as a separate JSON object
JsonObject nestedJsonObject = jsonParser.parse(entry.getValue()).getAsJsonObject();
// Parse each value as a separate JSON object using the static parseString method
JsonObject nestedJsonObject = JsonParser.parseString(entry.getValue()).getAsJsonObject();
// Update the final JsonObject with the parsed JSON object
finalJsonObject.add(entry.getKey(), nestedJsonObject);
}
Expand All @@ -85,5 +77,3 @@ public String generateJsonReport() {
return prettyGson.toJson(finalJsonObject);
}
}


1 change: 0 additions & 1 deletion src/main/java/neqsim/thermo/system/SystemThermo.java
Original file line number Diff line number Diff line change
Expand Up @@ -2401,7 +2401,6 @@ public double getMass(String unit) {
case "kg":
conversionFactor = 1.0;
break;

case "gr":
conversionFactor = 1000.0;
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package neqsim.processSimulation.util.monitor;

import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import neqsim.processSimulation.processEquipment.separator.Separator;
import neqsim.processSimulation.processEquipment.separator.ThreePhaseSeparator;
import neqsim.processSimulation.processEquipment.stream.Stream;
import neqsim.processSimulation.processSystem.ProcessSystem;
import neqsim.thermo.system.SystemSrkEos;

public class SeparatorResponseTest {

@Test
void testWrite() {

SystemSrkEos testSystem = new SystemSrkEos(298.0, 10.0);
testSystem.addComponent("methane", 100.0);
testSystem.addComponent("n-heptane", 100.0);
testSystem.addComponent("water", 100.0);
testSystem.setMixingRule("classic");
testSystem.setMultiPhaseCheck(true);

ProcessSystem processOps = new ProcessSystem();

Stream inletStream = new Stream("inletStream", testSystem);
inletStream.setName("feed stream");
inletStream.setPressure(10.0, "bara");
inletStream.setTemperature(20.0, "C");
inletStream.setFlowRate(290.0, "kg/hr");

Separator separator = new Separator("two phase separator", inletStream);
separator.setInternalDiameter(0.05);

ThreePhaseSeparator separator3phase =
new ThreePhaseSeparator("three phase separator", inletStream);
separator3phase.setInternalDiameter(0.05);

processOps.add(inletStream);
processOps.add(separator);
processOps.add(separator3phase);
processOps.run();

String sepjson = separator.toJson();
String sep3json = separator3phase.toJson();
JsonObject jsonObject = JsonParser.parseString(sep3json).getAsJsonObject();
Double reldens = jsonObject.getAsJsonObject("feed").getAsJsonObject("properties")
.getAsJsonObject("oil").getAsJsonObject("relative density").get("value").getAsDouble();
assertEquals(0.688292615281, reldens, 0.01);


}
}

0 comments on commit 8b23ec9

Please sign in to comment.