Skip to content

Commit

Permalink
fix expm1 math
Browse files Browse the repository at this point in the history
  • Loading branch information
rraustad committed Dec 25, 2024
1 parent 62fd1a4 commit 8956557
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/EnergyPlus/HeatRecovery.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3133,7 +3133,7 @@ namespace HeatRecovery {
} break;
case HXConfiguration::CrossFlowBothUnmixed: { // CROSS FLOW BOTH UNMIXED
Temp = Z * std::pow(NTU, -0.22);
Eps = 1.0 - std::expm1(std::exp(-NTU * Temp) / Temp);
Eps = 1.0 - std::exp(std::expm1(-NTU * Temp) / Temp);
} break;
case HXConfiguration::CrossFlowOther: { // CROSS FLOW, Cmax MIXED, Cmin UNMIXED
Eps = (1.0 - std::exp(-Z * (1.0 - std::exp(-NTU)))) / Z;
Expand Down Expand Up @@ -3273,7 +3273,7 @@ namespace HeatRecovery {
int SolFla; // Flag of solver
Real64 constexpr NTU0(0.0); // lower bound for NTU
Real64 constexpr NTU1(50.0); // upper bound for NTU
auto f = [Eps, Z](Real64 const NTU) { return 1.0 - std::expm1(std::exp(-std::pow(NTU, 0.78) * Z) / Z * std::pow(NTU, 0.22)) - Eps; };
auto f = [Eps, Z](Real64 const NTU) { return 1.0 - std::exp(std::expm1(-std::pow(NTU, 0.78) * Z) / Z * std::pow(NTU, 0.22)) - Eps; };
General::SolveRoot(state, Acc, MaxIte, SolFla, NTU, f, NTU0, NTU1);

if (SolFla == -2) {
Expand Down
4 changes: 2 additions & 2 deletions src/EnergyPlus/WaterThermalTanks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8084,8 +8084,8 @@ void WaterThermalTankData::CalcWaterThermalTankStratified(EnergyPlusData &state)
FinalFactorMixing = dt / NodeCapacitance;
AvgFactorMixing = FinalFactorMixing / 2.0;
} else {
FinalFactorMixing = expm1(A[k] * dt) / A[k] / NodeCapacitance;
AvgFactorMixing = (expm1(A[k] * dt) / A[k] / dt - 1.0) / A[k] / NodeCapacitance;
FinalFactorMixing = std::expm1(A[k] * dt) / A[k] / NodeCapacitance;
AvgFactorMixing = (std::expm1(A[k] * dt) / A[k] / dt - 1.0) / A[k] / NodeCapacitance;
}
const Real64 Q_AdiabaticMixing = (Tmixed - Tfinal[k]) / FinalFactorMixing;
Tfinal[k] = Tmixed;
Expand Down

3 comments on commit 8956557

@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.

CppCheck-exp (rraustad) - x86_64-Linux-Ubuntu-24.04-gcc-13.3: OK (2918 of 2918 tests passed, 0 test warnings)

Build Badge Test Badge

@nrel-bot-2
Copy link

Choose a reason for hiding this comment

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

CppCheck-exp (rraustad) - x86_64-Linux-Ubuntu-24.04-gcc-13.3-UnitTestsCoverage-RelWithDebInfo: OK (2100 of 2100 tests passed, 0 test warnings)

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.

CppCheck-exp (rraustad) - x86_64-Linux-Ubuntu-24.04-gcc-13.3-IntegrationCoverage-RelWithDebInfo: OK (801 of 801 tests passed, 0 test warnings)

Build Badge Test Badge Coverage Badge

Please sign in to comment.