From f79c58f889bc02dffd7bfd66f831c01ee6547cf5 Mon Sep 17 00:00:00 2001 From: Even Solbraa <41290109+EvenSol@users.noreply.github.com> Date: Wed, 31 Jul 2024 22:01:08 +0200 Subject: [PATCH] fixed bug in json HX response (#1058) * work ongoing * fixed NaN in HX response * added duty in output * changed variable name --- .../heatExchanger/HeatExchanger.java | 14 ++++++++-- .../util/monitor/HXResponse.java | 27 ++++++++++--------- .../util/monitor/SeparatorResponseTest.java | 10 +++++++ 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/src/main/java/neqsim/processSimulation/processEquipment/heatExchanger/HeatExchanger.java b/src/main/java/neqsim/processSimulation/processEquipment/heatExchanger/HeatExchanger.java index c03e333c86..35c055980e 100644 --- a/src/main/java/neqsim/processSimulation/processEquipment/heatExchanger/HeatExchanger.java +++ b/src/main/java/neqsim/processSimulation/processEquipment/heatExchanger/HeatExchanger.java @@ -7,10 +7,12 @@ package neqsim.processSimulation.processEquipment.heatExchanger; import java.util.UUID; +import com.google.gson.GsonBuilder; import neqsim.processSimulation.conditionMonitor.ConditionMonitorSpecifications; import neqsim.processSimulation.processEquipment.ProcessEquipmentInterface; import neqsim.processSimulation.processEquipment.stream.Stream; import neqsim.processSimulation.processEquipment.stream.StreamInterface; +import neqsim.processSimulation.util.monitor.HXResponse; import neqsim.thermo.system.SystemInterface; import neqsim.thermodynamicOperations.ThermodynamicOperations; @@ -279,8 +281,9 @@ public void run(UUID id) { // streamToCalculate = 1; // streamToSet = 0; // } - - // Make sure these streams to run because of the issues with enthalpy calculations if not run + + // Make sure these streams to run because of the issues with enthalpy + // calculations if not run for (StreamInterface stream : inStream) { stream.run(); } @@ -626,4 +629,11 @@ public double getHotColdDutyBalance() { public void setHotColdDutyBalance(double hotColdDutyBalance) { this.hotColdDutyBalance = hotColdDutyBalance; } + + /** {@inheritDoc} */ + @Override + public String toJson() { + return new GsonBuilder().serializeSpecialFloatingPointValues().create() + .toJson(new HXResponse(this)); + } } diff --git a/src/main/java/neqsim/processSimulation/util/monitor/HXResponse.java b/src/main/java/neqsim/processSimulation/util/monitor/HXResponse.java index 3998b017f2..926c8f8d09 100644 --- a/src/main/java/neqsim/processSimulation/util/monitor/HXResponse.java +++ b/src/main/java/neqsim/processSimulation/util/monitor/HXResponse.java @@ -21,6 +21,8 @@ public class HXResponse { public Double dischargeTemperature2; public Double dutyBalance; + public Double duty; + public Double UAvalue; /** *
@@ -34,19 +36,18 @@ public HXResponse() {} * Constructor for HXResponse. *
* - * @param inputHeatExchenger a {@link neqsim.processSimulation.processEquipment.heatExchanger.HeatExchanger} object + * @param inputHeatExchanger a + * {@link neqsim.processSimulation.processEquipment.heatExchanger.HeatExchanger} object */ - public HXResponse(HeatExchanger inputHeatExchenger) { - name = inputHeatExchenger.getName(); - - feedTemperature1 = inputHeatExchenger.getInStream(0).getTemperature("C"); - dischargeTemperature1 = inputHeatExchenger.getOutStream(0).getTemperature("C"); - - feedTemperature2 = inputHeatExchenger.getInStream(1).getTemperature("C"); - dischargeTemperature2 = inputHeatExchenger.getOutStream(1).getTemperature("C"); - - HXthermalEfectiveness = inputHeatExchenger.getThermalEffectiveness(); - - dutyBalance = inputHeatExchenger.getHotColdDutyBalance(); + public HXResponse(HeatExchanger inputHeatExchanger) { + name = inputHeatExchanger.getName(); + feedTemperature1 = inputHeatExchanger.getInStream(0).getTemperature("C"); + dischargeTemperature1 = inputHeatExchanger.getOutStream(0).getTemperature("C"); + feedTemperature2 = inputHeatExchanger.getInStream(1).getTemperature("C"); + dischargeTemperature2 = inputHeatExchanger.getOutStream(1).getTemperature("C"); + HXthermalEfectiveness = inputHeatExchanger.getThermalEffectiveness(); + dutyBalance = inputHeatExchanger.getHotColdDutyBalance(); + duty = inputHeatExchanger.getDuty(); + UAvalue = inputHeatExchanger.getUAvalue(); } } diff --git a/src/test/java/neqsim/processSimulation/util/monitor/SeparatorResponseTest.java b/src/test/java/neqsim/processSimulation/util/monitor/SeparatorResponseTest.java index 6f5695fd7c..131cf96cb5 100644 --- a/src/test/java/neqsim/processSimulation/util/monitor/SeparatorResponseTest.java +++ b/src/test/java/neqsim/processSimulation/util/monitor/SeparatorResponseTest.java @@ -4,6 +4,7 @@ import org.junit.jupiter.api.Test; import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import neqsim.processSimulation.processEquipment.heatExchanger.HeatExchanger; import neqsim.processSimulation.processEquipment.separator.Separator; import neqsim.processSimulation.processEquipment.separator.ThreePhaseSeparator; import neqsim.processSimulation.processEquipment.stream.Stream; @@ -37,13 +38,22 @@ void testWrite() { new ThreePhaseSeparator("three phase separator", inletStream); separator3phase.setInternalDiameter(0.05); + HeatExchanger hx1 = new HeatExchanger(separator3phase.getGasOutStream()); + hx1.setName("E-100"); + hx1.setGuessOutTemperature(273.15 + 35.0); + hx1.setUAvalue(444000.2); + hx1.setFeedStream(1, inletStream); + processOps.add(inletStream); processOps.add(separator); processOps.add(separator3phase); + processOps.add(hx1); + processOps.run(); String sepjson = separator.toJson(); String sep3json = separator3phase.toJson(); + String hxjson = hx1.toJson(); JsonObject jsonObject = JsonParser.parseString(sep3json).getAsJsonObject(); Double reldens = jsonObject.getAsJsonObject("feed").getAsJsonObject("properties") .getAsJsonObject("oil").getAsJsonObject("relative density").get("value").getAsDouble();