Skip to content

Commit

Permalink
find eqvar name and value together
Browse files Browse the repository at this point in the history
  • Loading branch information
Yujie Xu committed Sep 12, 2024
1 parent bd97716 commit 5e96092
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 54 deletions.
59 changes: 7 additions & 52 deletions src/EnergyPlus/ExtendedHI.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(EqvarName::Phi);
} else if (flux2 <= 0.0) {
return static_cast<int>(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<int>(EqvarName::Rs);
} else {
return static_cast<int>(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;
Expand Down Expand Up @@ -438,9 +389,11 @@ namespace ExtendedHI {
Real64 Rf;

if (flux1 <= 0.0) {
varname = static_cast<int>(EqvarName::Phi);
phi = 1.0 - (Q - Qv(Ta, Pa)) * Rs / (Tc - Ts);
return phi;
} else if (flux2 <= 0.0) {
varname = static_cast<int>(EqvarName::Rf);
Real64 Ts_bar = Tc - (Q - Qv(Ta, Pa)) * Rs / phi + (1.0 / phi - 1.0) * (Tc - Ts);
General::SolveRoot(
state,
Expand All @@ -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<int>(EqvarName::Rs);
General::SolveRoot(
state,
tol,
Expand All @@ -485,6 +439,7 @@ namespace ExtendedHI {
}
return Rs;
} else {
varname = static_cast<int>(EqvarName::DTcdt);
Rs = 0.0;
dTcdt = (1.0 / C) * flux3;
return dTcdt;
Expand Down Expand Up @@ -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);

Expand Down
3 changes: 1 addition & 2 deletions src/EnergyPlus/ExtendedHI.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

4 comments on commit 5e96092

@nrel-bot-2c
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extendedHIspeedFix (Unknown) - x86_64-Linux-Ubuntu-22.04-gcc-11.4: Build Failed

Build Badge Test Badge

@nrel-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extendedHIspeedFix (Unknown) - Win64-Windows-10-VisualStudio-16: Build Failed

Build Badge Test Badge

@nrel-bot-2c
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extendedHIspeedFix (Unknown) - x86_64-Linux-Ubuntu-22.04-gcc-11.4-UnitTestsCoverage-RelWithDebInfo: Build Failed

Failures:\n

API Test Summary

  • Passed: 9
  • Failed: 1
  • notrun: 5

Build Badge Test Badge Coverage Badge

@nrel-bot-2c
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extendedHIspeedFix (Unknown) - x86_64-Linux-Ubuntu-22.04-gcc-11.4-IntegrationCoverage-RelWithDebInfo: Build Failed

Failures:\n

integration Test Summary

  • Passed: 2
  • Failed: 797

Build Badge Test Badge Coverage Badge

Please sign in to comment.