From 5e96092686416079491c9e1820d5f7bc6a572e66 Mon Sep 17 00:00:00 2001 From: Yujie Xu Date: Thu, 12 Sep 2024 16:51:20 -0700 Subject: [PATCH] find eqvar name and value together --- src/EnergyPlus/ExtendedHI.cc | 59 +++++------------------------------- src/EnergyPlus/ExtendedHI.hh | 3 +- 2 files changed, 8 insertions(+), 54 deletions(-) diff --git a/src/EnergyPlus/ExtendedHI.cc b/src/EnergyPlus/ExtendedHI.cc index 0dd04c3e7f8..1e71b9ad173 100644 --- a/src/EnergyPlus/ExtendedHI.cc +++ b/src/EnergyPlus/ExtendedHI.cc @@ -351,57 +351,8 @@ namespace ExtendedHI { return dTcdt; } - int find_eqvar_name(EnergyPlusData &state, Real64 Ta, Real64 RH) - { - - Real64 Pa = RH * pvstar(Ta); - Real64 Rs = 0.0387; - Real64 ZsRs = Zs(Rs); - Real64 phi = 0.84; - Real64 m = (Pc - Pa) / (ZsRs + Za); - Real64 m_bar = (Pc - Pa) / (ZsRs + Za_bar); - - int SolFla; - Real64 Ts; - General::SolveRoot( - state, - tol, - maxIter, - SolFla, - Ts, - [&](Real64 Ts) { return (Ts - Ta) / Ra(Ts, Ta) + (Pc - Pa) / (ZsRs + Za) - (Tc - Ts) / Rs; }, - std::max(0.0, std::min(Tc, Ta) - Rs * std::abs(m)), - std::max(Tc, Ta) + Rs * std::abs(m)); - - Real64 Tf; - General::SolveRoot( - state, - tol, - maxIter, - SolFla, - Tf, - [&](Real64 Tf) { return (Tf - Ta) / Ra_bar(Tf, Ta) + (Pc - Pa) / (ZsRs + Za_bar) - (Tc - Tf) / Rs; }, - std::max(0.0, std::min(Tc, Ta) - Rs * std::abs(m_bar)), - std::max(Tc, Ta) + Rs * std::abs(m_bar)); - Real64 flux1 = Q - Qv(Ta, Pa) - (1.0 - phi) * (Tc - Ts) / Rs; - Real64 flux2 = Q - Qv(Ta, Pa) - (1.0 - phi) * (Tc - Ts) / Rs - phi * (Tc - Tf) / Rs; - - if (flux1 <= 0.0) { - return static_cast(EqvarName::Phi); - } else if (flux2 <= 0.0) { - return static_cast(EqvarName::Rf); - } else { - Real64 flux3 = Q - Qv(Ta, Pa) - (Tc - Ta) / Ra_un(Tc, Ta) - (phi_salt * pvstar(Tc) - Pa) / Za_un; - if (flux3 < 0.0) { - return static_cast(EqvarName::Rs); - } else { - return static_cast(EqvarName::DTcdt); - } - } - } - // given T and RH, returns a key and value pair - Real64 find_eqvar_value(EnergyPlusData &state, Real64 Ta, Real64 RH) + Real64 find_eqvar_name_and_value(EnergyPlusData &state, Real64 Ta, Real64 RH, int &varname) { Real64 Pa = RH * pvstar(Ta); Real64 Rs = 0.0387; @@ -438,9 +389,11 @@ namespace ExtendedHI { Real64 Rf; if (flux1 <= 0.0) { + varname = static_cast(EqvarName::Phi); phi = 1.0 - (Q - Qv(Ta, Pa)) * Rs / (Tc - Ts); return phi; } else if (flux2 <= 0.0) { + varname = static_cast(EqvarName::Rf); Real64 Ts_bar = Tc - (Q - Qv(Ta, Pa)) * Rs / phi + (1.0 / phi - 1.0) * (Tc - Ts); General::SolveRoot( state, @@ -459,6 +412,7 @@ namespace ExtendedHI { } else { Real64 flux3 = Q - Qv(Ta, Pa) - (Tc - Ta) / Ra_un(Tc, Ta) - (phi_salt * pvstar(Tc) - Pa) / Za_un; if (flux3 < 0.0) { + varname = static_cast(EqvarName::Rs); General::SolveRoot( state, tol, @@ -485,6 +439,7 @@ namespace ExtendedHI { } return Rs; } else { + varname = static_cast(EqvarName::DTcdt); Rs = 0.0; dTcdt = (1.0 / C) * flux3; return dTcdt; @@ -531,8 +486,8 @@ namespace ExtendedHI { auto const HVACSystemRootSolverBackup = state.dataRootFinder->HVACSystemRootFinding.HVACSystemRootSolver; state.dataRootFinder->HVACSystemRootFinding.HVACSystemRootSolver = HVACSystemRootSolverAlgorithm::BisectionThenRegulaFalsi; - int eqvar_name = find_eqvar_name(state, Ta, RH); - Real64 eqvar_value = find_eqvar_value(state, Ta, RH); + int eqvar_name = 0; + Real64 eqvar_value = find_eqvar_name_and_value(state, Ta, RH, eqvar_name); Real64 T = find_T(state, eqvar_name, eqvar_value); diff --git a/src/EnergyPlus/ExtendedHI.hh b/src/EnergyPlus/ExtendedHI.hh index b839ea571eb..5c4a271de88 100644 --- a/src/EnergyPlus/ExtendedHI.hh +++ b/src/EnergyPlus/ExtendedHI.hh @@ -77,8 +77,7 @@ namespace ExtendedHI { Real64 Ra(Real64 Ts, Real64 Ta); Real64 Ra_bar(Real64 Tf, Real64 Ta); Real64 Ra_un(Real64 Ts, Real64 Ta); - int find_eqvar_name(EnergyPlusData &state, Real64 Ta, Real64 RH); - Real64 find_eqvar_value(EnergyPlusData &state, Real64 Ta, Real64 RH); + Real64 find_eqvar_name_and_value(EnergyPlusData &state, Real64 Ta, Real64 RH, int &varname); Real64 find_eqvar_phi(EnergyPlusData &state, Real64 Ta, Real64 RH); Real64 find_eqvar_Rf(EnergyPlusData &state, Real64 Ta, Real64 RH); Real64 find_eqvar_rs(EnergyPlusData &state, Real64 Ta, Real64 RH);