Skip to content

Remove fmt - Part 1: Propagate std::format where possible and eliminate {T} string formatting option#11553

Open
mitchute wants to merge 11 commits intodevelopfrom
remove-fmt-part-1
Open

Remove fmt - Part 1: Propagate std::format where possible and eliminate {T} string formatting option#11553
mitchute wants to merge 11 commits intodevelopfrom
remove-fmt-part-1

Conversation

@mitchute
Copy link
Copy Markdown
Collaborator

Pull request overview

Begins the process of removing third-party/fmt library in lieu of std::format that is now available in C++20.

Description of the purpose of this PR

  • Propagates the use of std::format to all the easy places. I should have completed this in Upgrade to C++20 Standard #11423. Oh well.
  • Eliminates all uses of the {T} formatting option. This results in some least significant figure rounding due to differences between how the T option vs. std::format behave.

Pull Request Author

  • Title of PR should be user-synopsis style (clearly understandable in a standalone changelog context)
  • Label the PR with at least one of: Defect, Refactoring, NewFeature, Performance, and/or DoNoPublish
  • Pull requests that impact EnergyPlus code must also include unit tests to cover enhancement or defect repair
  • Author should provide a "walkthrough" of relevant code changes using a GitHub code review comment process
  • If any diffs are expected, author must demonstrate they are justified using plots and descriptions
  • If changes fix a defect, the fix should be demonstrated in plots and descriptions
  • If any defect files are updated to a more recent version, upload new versions here or on DevSupport
  • If IDD requires transition, transition source, rules, ExpandObjects, and IDFs must be updated, and add IDDChange label
  • If structural output changes, add to output rules file and add OutputChange label
  • If adding/removing any LaTeX docs or figures, update that document's CMakeLists file dependencies
  • If adding/removing any output files (e.g., eplustbl.*)
    • Update ..\scripts\Epl-run.bat
    • Update ..\scripts\RunEPlus.bat
    • Update ..\src\EPLaunch\ MainModule.bas, epl-ui.frm, and epl.vbp (VersionComments)
    • Update ...github\workflows\energyplus.py

Reviewer

  • Perform a Code Review on GitHub
  • If branch is behind develop, merge develop and build locally to check for side effects of the merge
  • If defect, verify by running develop branch and reproducing defect, then running PR and reproducing fix
  • If feature, test running new feature, try creative ways to break it
  • CI status: all green or justified
  • Check that performance is not impacted (CI Linux results include performance check)
  • Run Unit Test(s) locally
  • Check any new function arguments for performance impacts
  • Verify IDF naming conventions and styles, memos and notes and defaults
  • If new idf included, locally check the err file and other outputs

@mitchute mitchute added the Refactoring Includes code changes that don't change the functionality of the program, just perform refactoring label Apr 28, 2026
Copy link
Copy Markdown
Collaborator Author

@mitchute mitchute left a comment

Choose a reason for hiding this comment

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

Walk through

Real64 viscosity;

AirState();
explicit AirState(double const airDensity);
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Just making the definition and declaration names the same.

Comment on lines 48 to 62
// C++ Headers
#include <algorithm>
#include <cmath>
#include <format>
#include <set>
#include <string>

// ObjexxFCL Headers
#include <ObjexxFCL/Array.functions.hh>
#include <ObjexxFCL/Array2D.hh>
// #include <ObjexxFCL/Fmath.hh>

// Local Headers
#include "AirflowNetwork/Elements.hpp"
#include "AirflowNetwork/Solver.hpp"

// EnergyPlus Headers
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Since was adding #include <format> in a bunch of places, I spent a little time making the header includes consistent.

@@ -954,25 +952,25 @@ namespace AirflowNetwork {
}
if (MultizoneCompDetOpeningData(i).NumFac > 2) {
if (MultizoneCompDetOpeningData(i).OpenFac2 >= MultizoneCompDetOpeningData(i).OpenFac3) {
ShowSevereError(m_state, EnergyPlus::format("{}: {} = {}", RoutineName, CurrentModuleObject, thisObjectName));
ShowSevereError(m_state, std::format("{}: {} = {}", RoutineName, CurrentModuleObject, thisObjectName));
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

25000 of these later...

@@ -319,7 +316,7 @@ void InitializeRootFinder(EnergyPlusData &state,
XMinReset = XMax;
} else {
ShowFatalError(
state, EnergyPlus::format("InitializeRootFinder: Invalid min/max bounds XMin={:.6T} must be smaller than XMax={:.6T}", XMin, XMax));
Copy link
Copy Markdown
Collaborator Author

@mitchute mitchute Apr 28, 2026

Choose a reason for hiding this comment

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

Thankfully it's just a 1:1 replacement, with the noted LSF rounding. IMO, that doesn't appear to be an issue.

Edit - this is addressed in subsequent commits.

Comment on lines -162 to -179
// T formatting is like R, but it trims instead of rounding
EXPECT_EQ(format("{:.3T}", 7.63142731775999418747E-003), "7.631E-003");
EXPECT_EQ(format("{:.3T}", 1.28349999999999948505E-004), "1.283E-004");
EXPECT_EQ(format("{:.3T}", 2.56700000000000005430E-004), "2.567E-004");
EXPECT_EQ(format("{:.3T}", 0.15159450340364988286), "0.151");
EXPECT_EQ(format("{:.3T}", 0.0), "0.000");

EXPECT_EQ(format("{:.3T}", 2.14633893312000043063E-002), "2.146E-002");
EXPECT_EQ(format("{:.3T}", 8.55666666666666278192E-005), "8.556E-005");
EXPECT_EQ(format("{:.3T}", 6.41749999999999878051E-005), "6.417E-005");
EXPECT_EQ(format("{:.3T}", 0.10106298657208269420), "0.101");

EXPECT_EQ(format("{:.4T}", 0.14999999999999999445), "0.1500");
EXPECT_EQ(format("{:.3T}", 4500.0), "4500.000");
EXPECT_EQ(format("{:.4T}", 7.1846416734478406596), "7.1846");
EXPECT_EQ(format("{:.4T}", 1.1846416734478406596), "1.1846");
EXPECT_EQ(format("{:.4T}", 6.2565195738294026029), "6.2565");
EXPECT_EQ(format("{:.4T}", 0.25651957382940215879), "0.2565");
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Old unit test showing how {T} option was behaving.

@mitchute mitchute marked this pull request as draft April 28, 2026 22:06
@shorowit
Copy link
Copy Markdown
Contributor

Looks like this partially addresses #11241

@github-actions
Copy link
Copy Markdown

⚠️ Regressions detected on macos-14 for commit f8bb0a4

Regression Summary
  • EDD: 13
  • EIO: 85
  • Table Small Diffs: 42
  • ERR: 37

@github-actions
Copy link
Copy Markdown

⚠️ Regressions detected on ubuntu-24.04 for commit f8bb0a4

Regression Summary
  • EDD: 15
  • EIO: 85
  • Table Small Diffs: 42
  • ERR: 37

@github-actions
Copy link
Copy Markdown

⚠️ Regressions detected on macos-14 for commit d1dbd08

Regression Summary
  • EDD: 13
  • EIO: 85
  • Table Small Diffs: 42
  • ERR: 37

@github-actions
Copy link
Copy Markdown

⚠️ Regressions detected on ubuntu-24.04 for commit d1dbd08

Regression Summary
  • EDD: 15
  • EIO: 85
  • Table Small Diffs: 42
  • ERR: 37

@mitchute
Copy link
Copy Markdown
Collaborator Author

mitchute commented Apr 29, 2026

Diff Summary

DX Coils - Rated Vol Flow Per Watt Reporting

Diff resolution commit: ab5e29c

-   **   ~~~   ** Min Rated Vol Flow Per Watt=[4.027E-005], Rated Vol Flow Per Watt=[7.475E-005], Max Rated Vol Flow Per Watt=[6.041E-005]. See Input Output Reference Manual for valid range.
+   **   ~~~   ** Min Rated Vol Flow Per Watt=[4.027e-05], Rated Vol Flow Per Watt=[7.476e-05], Max Rated Vol Flow Per Watt=[6.041e-05]. See Input-Output Reference Manual for valid range.

Per this IO Ref, these values should be between '0.00001677 (m3/s)/W (125 cfm/ton) and 0.00003355 (m3/s)/W (250 cfm/ton).' Changing to fixed sci notation to reflect this.

Psychrometric "Resultant Temperature" Messages

Diff resolution commit: fbd4a5a (ignore the files added accidentally)

-   **   ~~~   **  Resultant Temperature= -3.62E-003
+   **   ~~~   **  Resultant Temperature= -0.0036

These look like they will always be in Celsius, so a fixed floating point number should be sufficient.

EMS .edd File Trace Data

Diff resolution commit: e9eb04d

-CURVEOVERWRITEMGR,Line 8,SET C1 = 0.942567793,0.942567, During Warmup, Occurrence info=MIAMI INTL AP ANN HTG 99.6% CONDNS DB, 01/21 00:00 - 00:15
-CURVEOVERWRITEMGR,Line 9,SET C2 = 0.009543347,9.543347E-003, During Warmup, Occurrence info=MIAMI INTL AP ANN HTG 99.6% CONDNS DB, 01/21 00:00 - 00:15
-CURVEOVERWRITEMGR,Line 10,SET C2A = 0.009543347E0,9.543347E-003, During Warmup, Occurrence info=MIAMI INTL AP ANN HTG 99.6% CONDNS DB, 01/21 00:00 - 00:15
-CURVEOVERWRITEMGR,Line 11,SET C3 = 0.00068377E0,6.837700E-004, During Warmup, Occurrence info=MIAMI INTL AP ANN HTG 99.6% CONDNS DB, 01/21 00:00 - 00:15
+CURVEOVERWRITEMGR,Line 8,SET C1 = 0.942567793,0.942568, During Warmup, Occurrence info=MIAMI INTL AP ANN HTG 99.6% CONDNS DB, 01/21 00:00 - 00:15
+CURVEOVERWRITEMGR,Line 9,SET C2 = 0.009543347,9.543347e-03, During Warmup, Occurrence info=MIAMI INTL AP ANN HTG 99.6% CONDNS DB, 01/21 00:00 - 00:15
+CURVEOVERWRITEMGR,Line 10,SET C2A = 0.009543347E0,9.543347e-03, During Warmup, Occurrence info=MIAMI INTL AP ANN HTG 99.6% CONDNS DB, 01/21 00:00 - 00:15
+CURVEOVERWRITEMGR,Line 11,SET C3 = 0.00068377E0,6.837700e-04, During Warmup, Occurrence info=MIAMI INTL AP ANN HTG 99.6% CONDNS DB, 01/21 00:00 - 00:15

This is only used to print to the .edd trace, so I picked a cutoff to switch between fixed floating point and scientific notation. Let me know if that's a problem.

Psychrometric Humidity Ratio Messages

Diff resolution commit: 05e1825

-   **   ~~~   **  Input Humidity Ratio= 1.257224E-003
+   **   ~~~   **  Input Humidity Ratio= 1.257225e-03

This is another number that's always going to be less than 0, so scientific notation seems appropriate for these.

Tank and Tank Node Volumes

Diff resolution commits: 34fa25b 32811a7

-Chilled Water Tank Information,ThermalStorage:ChilledWater:Mixed,CHILLED WATER STORAGE TANK 1,50.0000,4.2120E-003,4.1819E-003
+Chilled Water Tank Information,ThermalStorage:ChilledWater:Mixed,CHILLED WATER STORAGE TANK 1,50.0000,4.2121e-03,4.1820e-03

The tank and tank node volume are in m^3, and might be big or small, so I converted these to sci notation.

Let me know if this is a problem for any of these. I think I've addressed all of the major issues. Remaining diffs are related to the LSF rounding differences between the old and new formats.

@mitchute mitchute marked this pull request as ready for review April 29, 2026 18:43
@github-actions
Copy link
Copy Markdown

⚠️ Regressions detected on macos-14 for commit 8407ffe

Regression Summary
  • EDD: 13
  • EIO: 84
  • Table Small Diffs: 41
  • ERR: 37

@github-actions
Copy link
Copy Markdown

⚠️ Regressions detected on ubuntu-24.04 for commit 8407ffe

Regression Summary
  • EDD: 15
  • EIO: 84
  • Table Small Diffs: 41
  • ERR: 37

@github-actions
Copy link
Copy Markdown

⚠️ Regressions detected on macos-14 for commit 038014b

Regression Summary
  • EDD: 13
  • EIO: 84
  • Table Small Diffs: 41
  • ERR: 37

@github-actions
Copy link
Copy Markdown

⚠️ Regressions detected on ubuntu-24.04 for commit 038014b

Regression Summary
  • EDD: 15
  • EIO: 84
  • Table Small Diffs: 41
  • ERR: 37

@github-actions
Copy link
Copy Markdown

⚠️ Regressions detected on macos-14 for commit 01a1653

Regression Summary
  • EDD: 13
  • EIO: 83
  • Table Small Diffs: 41
  • ERR: 37

@github-actions
Copy link
Copy Markdown

⚠️ Regressions detected on ubuntu-24.04 for commit 01a1653

Regression Summary
  • EDD: 15
  • EIO: 83
  • Table Small Diffs: 41
  • ERR: 37

Copy link
Copy Markdown
Collaborator

@rraustad rraustad left a comment

Choose a reason for hiding this comment

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

Diff review showed very small changes in magnitude and format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Refactoring Includes code changes that don't change the functionality of the program, just perform refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants