From 5d5d0869dfffc0988fa00b1a51dd201ecea66dc1 Mon Sep 17 00:00:00 2001 From: thermalogic Date: Fri, 5 Mar 2021 22:39:44 +0800 Subject: [PATCH] update cpp --- cpp/include/common.hpp | 6 +++++- cpp/include/condenser.hpp | 3 +-- cpp/include/openedheaterdw0.hpp | 18 ++++++++--------- cpp/include/port.hpp | 2 +- cpp/include/rankine81.hpp | 36 ++++++++++++++++----------------- cpp/include/rankine82.hpp | 3 +-- cpp/include/rankine85.hpp | 3 +-- cpp/include/rankinemodel.hpp | 3 +-- cpp/include/turbineex0.hpp | 18 ++++++++--------- cpp/rankinesim.cpp | 2 +- cpp/src/boiler.cpp | 2 -- cpp/src/pump.cpp | 6 +++--- cpp/src/rankine.cpp | 29 +++++++++----------------- 13 files changed, 59 insertions(+), 72 deletions(-) diff --git a/cpp/include/common.hpp b/cpp/include/common.hpp index 441e5de..43d31b8 100644 --- a/cpp/include/common.hpp +++ b/cpp/include/common.hpp @@ -34,12 +34,16 @@ class CompBase string energy; Port *iPort; Port *oPort; - Port *ePort; // turbineex1 + Port *ePort; // turbineex1 Port *iPort_fw; // opendedheaterdw0 Port *oPort_fw; // opendedheaterdw0 mapPortObj portdict; + double workExtracted; + double heatAdded; + double workRequired; + virtual void setportaddress() = 0; virtual void state() = 0; virtual int balance() = 0; diff --git a/cpp/include/condenser.hpp b/cpp/include/condenser.hpp index 7b6659d..7da0e8d 100644 --- a/cpp/include/condenser.hpp +++ b/cpp/include/condenser.hpp @@ -14,12 +14,11 @@ class Condenser : public CompBase double heatExtracted; Condenser(umComponent dictComp); ~Condenser(); - + void setportaddress(); void state(); int balance(); string resultstring(); - }; #endif /* Condenser_hpp */ diff --git a/cpp/include/openedheaterdw0.hpp b/cpp/include/openedheaterdw0.hpp index c5fddc0..07b13a5 100644 --- a/cpp/include/openedheaterdw0.hpp +++ b/cpp/include/openedheaterdw0.hpp @@ -10,17 +10,17 @@ class OpenedHeaterDw0 : public CompBase { public: - double heatAdded; - double heatExtracted; + double heatAdded; + double heatExtracted; - // methods - OpenedHeaterDw0(umComponent dictComp); - ~OpenedHeaterDw0(); + // methods + OpenedHeaterDw0(umComponent dictComp); + ~OpenedHeaterDw0(); - void setportaddress(); - void state(); - int balance(); - string resultstring(); + void setportaddress(); + void state(); + int balance(); + string resultstring(); }; #endif /* OpenedHeaterDw0_hpp */ diff --git a/cpp/include/port.hpp b/cpp/include/port.hpp index 97e7323..7e332e9 100644 --- a/cpp/include/port.hpp +++ b/cpp/include/port.hpp @@ -34,7 +34,7 @@ class Port double x; double fdot; double mdot; - + // methods Port(mPort curmPort); ~Port(); diff --git a/cpp/include/rankine81.hpp b/cpp/include/rankine81.hpp index 85b3d36..e191a0e 100644 --- a/cpp/include/rankine81.hpp +++ b/cpp/include/rankine81.hpp @@ -8,24 +8,24 @@ #include "common.hpp" Components Components81 = { - {{"name", "Turbine1"}, - {"classstr", "TurbineEx0"}, - {"ef", 1.0}, - {"iPort", (mPort){{"p", NAN}, {"t", NAN}, {"x", NAN}, {"fdot", NAN}}}, - {"oPort", (mPort){{"p", 0.008}, {"t", NAN}, {"x", NAN}, {"fdot", NAN}}}}, - {{"name", "Condenser"}, - {"classstr", "Condenser"}, - {"iPort", (mPort){{"p", NAN}, {"t", NAN}, {"x", NAN}, {"fdot", NAN}}}, - {"oPort", (mPort){{"p", 0.008}, {"t", NAN}, {"x", 0.0}, {"fdot", NAN}}}}, - {{"name", "Pump1"}, - {"classstr", "Pump"}, - {"ef", 1.0}, - {"iPort", (mPort){{"p", NAN}, {"t", NAN}, {"x", NAN}, {"fdot", NAN}}}, - {"oPort", (mPort){{"p", 8.0}, {"t", NAN}, {"x", NAN}, {"fdot", NAN}}}}, - {{"name", "Boiler1"}, - {"classstr", "Boiler"}, - {"iPort", (mPort){{"p", NAN}, {"t", NAN}, {"x", NAN}, {"fdot", NAN}}}, - {"oPort", (mPort){{"p", 8.0}, {"t", NAN}, {"x", 1.0}, {"fdot", 1.0}}}} + {{"name", "Turbine1"}, + {"classstr", "TurbineEx0"}, + {"ef", 1.0}, + {"iPort", (mPort){{"p", NAN}, {"t", NAN}, {"x", NAN}, {"fdot", NAN}}}, + {"oPort", (mPort){{"p", 0.008}, {"t", NAN}, {"x", NAN}, {"fdot", NAN}}}}, + {{"name", "Condenser"}, + {"classstr", "Condenser"}, + {"iPort", (mPort){{"p", NAN}, {"t", NAN}, {"x", NAN}, {"fdot", NAN}}}, + {"oPort", (mPort){{"p", 0.008}, {"t", NAN}, {"x", 0.0}, {"fdot", NAN}}}}, + {{"name", "Pump1"}, + {"classstr", "Pump"}, + {"ef", 1.0}, + {"iPort", (mPort){{"p", NAN}, {"t", NAN}, {"x", NAN}, {"fdot", NAN}}}, + {"oPort", (mPort){{"p", 8.0}, {"t", NAN}, {"x", NAN}, {"fdot", NAN}}}}, + {{"name", "Boiler1"}, + {"classstr", "Boiler"}, + {"iPort", (mPort){{"p", NAN}, {"t", NAN}, {"x", NAN}, {"fdot", NAN}}}, + {"oPort", (mPort){{"p", 8.0}, {"t", NAN}, {"x", 1.0}, {"fdot", 1.0}}}} }; diff --git a/cpp/include/rankine82.hpp b/cpp/include/rankine82.hpp index 611bcf7..a782004 100644 --- a/cpp/include/rankine82.hpp +++ b/cpp/include/rankine82.hpp @@ -7,11 +7,10 @@ #include "common.hpp" - Components Components82 = { {{"name", "Turbine1"}, {"classstr", "TurbineEx0"}, - {"ef",0.85}, + {"ef", 0.85}, {"iPort", (mPort){{"p", NAN}, {"t", NAN}, {"x", NAN}, {"fdot", NAN}}}, {"oPort", (mPort){{"p", 0.008}, {"t", NAN}, {"x", NAN}, {"fdot", NAN}}}}, {{"name", "Condenser"}, diff --git a/cpp/include/rankine85.hpp b/cpp/include/rankine85.hpp index 144c9ae..d1a08ac 100644 --- a/cpp/include/rankine85.hpp +++ b/cpp/include/rankine85.hpp @@ -42,8 +42,7 @@ Components Components85 = { {{"name", "Boiler1"}, {"classstr", "Boiler"}, {"iPort", (mPort){{"p", NAN}, {"t", NAN}, {"x", NAN}, {"fdot", NAN}}}, - {"oPort", (mPort){{"p", 8.0}, {"t", 480.0}, {"x", NAN}, {"fdot", 1.0}}}} -}; + {"oPort", (mPort){{"p", 8.0}, {"t", 480.0}, {"x", NAN}, {"fdot", 1.0}}}}}; Connectors Connectors85 = { {{"Boiler1", "oPort"}, {"TurbineEx1", "iPort"}}, diff --git a/cpp/include/rankinemodel.hpp b/cpp/include/rankinemodel.hpp index e9ace1f..3e453aa 100644 --- a/cpp/include/rankinemodel.hpp +++ b/cpp/include/rankinemodel.hpp @@ -10,7 +10,6 @@ #include "rankine82.hpp" #include "rankine85.hpp" - -rankinecycles cycles= {rankine81, rankine82, rankine85}; +rankinecycles cycles = {rankine81, rankine82, rankine85}; #endif /* RANKINEMODEL_hpp */ diff --git a/cpp/include/turbineex0.hpp b/cpp/include/turbineex0.hpp index a4baf64..9b558b2 100644 --- a/cpp/include/turbineex0.hpp +++ b/cpp/include/turbineex0.hpp @@ -10,17 +10,17 @@ class TurbineEx0 : public CompBase { public: - double ef; - double workExtracted; + double ef; + double workExtracted; - // methods - TurbineEx0(umComponent dictComp); - ~TurbineEx0(); + // methods + TurbineEx0(umComponent dictComp); + ~TurbineEx0(); - void setportaddress(); - void state(); - int balance(); - string resultstring(); + void setportaddress(); + void state(); + int balance(); + string resultstring(); }; #endif /* TurbineEx0_hpp */ diff --git a/cpp/rankinesim.cpp b/cpp/rankinesim.cpp index 5da98c0..dbe97e8 100644 --- a/cpp/rankinesim.cpp +++ b/cpp/rankinesim.cpp @@ -20,4 +20,4 @@ int main() curcycle->outresults(); }; return 0; - } \ No newline at end of file +} \ No newline at end of file diff --git a/cpp/src/boiler.cpp b/cpp/src/boiler.cpp index bbf8dee..69a63e8 100644 --- a/cpp/src/boiler.cpp +++ b/cpp/src/boiler.cpp @@ -15,7 +15,6 @@ Boiler::Boiler(umComponent dictComp) portdict = {{"iPort", iPort}, {"oPort", oPort}}; energy = "heatAdded"; - } Boiler::~Boiler() @@ -26,7 +25,6 @@ Boiler::~Boiler() void Boiler::state() { - } int Boiler::balance() diff --git a/cpp/src/pump.cpp b/cpp/src/pump.cpp index ef9bd9c..0ef7bc8 100644 --- a/cpp/src/pump.cpp +++ b/cpp/src/pump.cpp @@ -25,9 +25,9 @@ Pump::~Pump() void Pump::state() { oPort->h = iPort->h; - double sout_s =iPort->s; - double hout_s = seups(oPort->p, sout_s,4); - oPort->h = iPort->h + (hout_s -iPort->h) /ef; + double sout_s = iPort->s; + double hout_s = seups(oPort->p, sout_s, 4); + oPort->h = iPort->h + (hout_s - iPort->h) / ef; oPort->ph(); } diff --git a/cpp/src/rankine.cpp b/cpp/src/rankine.cpp index da0ddb6..6fde2bd 100644 --- a/cpp/src/rankine.cpp +++ b/cpp/src/rankine.cpp @@ -71,12 +71,13 @@ void RankineCycle::ComponentBalance() { try { - rtn = Comps[item]->balance(); - if (rtn == 1) + rtn=Comps[item]->balance(); + if (rtn==1) { - balanceok[i] = true; - numdeviceok = +1; + balanceok[i] = true; + numdeviceok = +1; } + } catch (...) { @@ -114,28 +115,16 @@ void RankineCycle::Simulator() { if (iter->second->energy == "workExtracted") { - try - { - totalworkExtracted += ((TurbineEx0 *)iter->second)->workExtracted; - } - catch (...) - { - try - { - totalworkExtracted += ((TurbineEx1 *)iter->second)->workExtracted; - } - catch (...) - { - }; - }; + totalworkExtracted += iter->second->workExtracted; + }; if (iter->second->energy == "heatAdded") { - totalheatAdded = ((Boiler *)iter->second)->heatAdded; + totalheatAdded += iter->second->heatAdded; }; if (iter->second->energy == "workRequired") { - totalworkRequired += ((Pump *)iter->second)->workRequired; + totalworkRequired +=iter->second->workRequired; }; }; netpoweroutput = totalworkExtracted - totalworkRequired;