@@ -684,53 +684,96 @@ public void displayResult() {
684684 public double getEntropyProduction (String unit ) {
685685 double entrop = 0.0 ;
686686 for (int i = 0 ; i < numberOfInputStreams ; i ++) {
687- inletStreamMixer .getStream (i ).getFluid ().init (3 );
688- entrop += inletStreamMixer .getStream (i ).getFluid ().getEntropy (unit );
687+ if (inletStreamMixer .getStream (i ).getFlowRate (unit ) > 1e-10 ) {
688+ inletStreamMixer .getStream (i ).getFluid ().init (3 );
689+ entrop += inletStreamMixer .getStream (i ).getFluid ().getEntropy (unit );
690+ }
691+ }
692+
693+ if (thermoSystem .hasPhaseType ("aqueous" )) {
694+ getWaterOutStream ().getThermoSystem ().init (3 );
695+ entrop -= getWaterOutStream ().getThermoSystem ().getEntropy (unit );
696+ }
697+ if (thermoSystem .hasPhaseType ("oil" )) {
698+ getOilOutStream ().getThermoSystem ().init (3 );
699+ entrop -= getOilOutStream ().getThermoSystem ().getEntropy (unit );
700+ }
701+ if (thermoSystem .hasPhaseType ("gas" )) {
702+ getGasOutStream ().getThermoSystem ().init (3 );
703+ entrop -= getGasOutStream ().getThermoSystem ().getEntropy (unit );
689704 }
690- getWaterOutStream ().getThermoSystem ().init (3 );
691- getOilOutStream ().getThermoSystem ().init (3 );
692- getGasOutStream ().getThermoSystem ().init (3 );
693705
694- return getWaterOutStream ().getThermoSystem ().getEntropy (unit )
695- + getOilOutStream ().getThermoSystem ().getEntropy (unit )
696- + getGasOutStream ().getThermoSystem ().getEntropy (unit ) - entrop ;
706+ return entrop ;
697707 }
698708
699709 /** {@inheritDoc} */
700710 @ Override
701711 public double getMassBalance (String unit ) {
702712 double inletFlow = 0.0 ;
703713 for (int i = 0 ; i < numberOfInputStreams ; i ++) {
704- inletStreamMixer .getStream (i ).getFluid ().init (3 );
705- inletFlow += inletStreamMixer .getStream (i ).getFluid ().getFlowRate (unit );
714+ if (inletStreamMixer .getStream (i ).getFlowRate (unit ) > 1e-10 ) {
715+ inletStreamMixer .getStream (i ).getFluid ().init (3 );
716+ inletFlow += inletStreamMixer .getStream (i ).getFluid ().getFlowRate (unit );
717+ }
718+ }
719+
720+ // Only initialize and get flow rates for phases that actually exist
721+ double waterFlow = 0.0 ;
722+ double oilFlow = 0.0 ;
723+ double gasFlow = 0.0 ;
724+
725+ if (thermoSystem .hasPhaseType ("aqueous" )) {
726+ getWaterOutStream ().getThermoSystem ().init (3 );
727+ waterFlow = getWaterOutStream ().getThermoSystem ().getFlowRate (unit );
728+ if (waterFlow < 1e-10 ) {
729+ waterFlow = 0.0 ;
730+ }
706731 }
707732
708- getWaterOutStream ().getThermoSystem ().init (3 );
709- getOilOutStream ().getThermoSystem ().init (3 );
710- getGasOutStream ().getThermoSystem ().init (3 );
733+ if (thermoSystem .hasPhaseType ("oil" )) {
734+ getOilOutStream ().getThermoSystem ().init (3 );
735+ oilFlow = getOilOutStream ().getThermoSystem ().getFlowRate (unit );
736+ if (oilFlow < 1e-10 ) {
737+ oilFlow = 0.0 ;
738+ }
739+ }
711740
712- double waterFlow = getWaterOutStream ().getThermoSystem ().getFlowRate (unit );
713- double oilFlow = getOilOutStream ().getThermoSystem ().getFlowRate (unit );
714- double gasFlow = getGasOutStream ().getThermoSystem ().getFlowRate (unit );
741+ if (thermoSystem .hasPhaseType ("gas" )) {
742+ getGasOutStream ().getThermoSystem ().init (3 );
743+ gasFlow = getGasOutStream ().getThermoSystem ().getFlowRate (unit );
744+ if (gasFlow < 1e-10 ) {
745+ gasFlow = 0.0 ;
746+ }
747+ }
715748
716749 return waterFlow + oilFlow + gasFlow - inletFlow ;
717750 }
718751
719752 /** {@inheritDoc} */
720753 @ Override
721754 public double getExergyChange (String unit , double surroundingTemperature ) {
722- double entrop = 0.0 ;
755+ double exergy = 0.0 ;
723756 for (int i = 0 ; i < numberOfInputStreams ; i ++) {
724- inletStreamMixer .getStream (i ).getFluid ().init (3 );
725- entrop += inletStreamMixer .getStream (i ).getFluid ().getExergy (surroundingTemperature , unit );
757+ if (inletStreamMixer .getStream (i ).getFlowRate (unit ) > 1e-10 ) {
758+ inletStreamMixer .getStream (i ).getFluid ().init (3 );
759+ exergy += inletStreamMixer .getStream (i ).getFluid ().getExergy (surroundingTemperature , unit );
760+ }
761+ }
762+
763+ if (thermoSystem .hasPhaseType ("aqueous" )) {
764+ getWaterOutStream ().getThermoSystem ().init (3 );
765+ exergy -= getWaterOutStream ().getThermoSystem ().getExergy (surroundingTemperature , unit );
766+ }
767+ if (thermoSystem .hasPhaseType ("oil" )) {
768+ getOilOutStream ().getThermoSystem ().init (3 );
769+ exergy -= getOilOutStream ().getThermoSystem ().getExergy (surroundingTemperature , unit );
770+ }
771+ if (thermoSystem .hasPhaseType ("gas" )) {
772+ getGasOutStream ().getThermoSystem ().init (3 );
773+ exergy -= getGasOutStream ().getThermoSystem ().getExergy (surroundingTemperature , unit );
726774 }
727- getWaterOutStream ().getThermoSystem ().init (3 );
728- getOilOutStream ().getThermoSystem ().init (3 );
729- getGasOutStream ().getThermoSystem ().init (3 );
730775
731- return getWaterOutStream ().getThermoSystem ().getExergy (surroundingTemperature , unit )
732- + getOilOutStream ().getThermoSystem ().getEntropy (unit )
733- + getGasOutStream ().getThermoSystem ().getExergy (surroundingTemperature , unit ) - entrop ;
776+ return exergy ;
734777 }
735778
736779 /** {@inheritDoc} */
0 commit comments