-
Notifications
You must be signed in to change notification settings - Fork 396
Refactoring Passes
amirroth edited this page Apr 21, 2022
·
8 revisions
We have been working in the C++ version of EnergyPlus for almost ten years now, but the code still has a lot of "Fortran" in it. There have been a few targeted refactoring efforts focused on specific areas (e.g., plant) and there will be more, but a few sweeps through the code to remove some old idioms and replace with new and better ones will create a better environment in which to perform those future efforts and establish new patterns that new and updated code can mimic. I estimate that we need to do about 12-15 passes of various "sizes". The way I would characterize the size of a pass is:
- small: can be done by one person in two months or less.
- medium: can be done by two people in one iteration or less.
- large: requires more than two people and/or more than one iteration. Here are the passes that I am thinking of along with my effort estimates, which may be completely off. I've tried to order them "topologically", i.e., the ones that don't depend on other passes first.
-
Enum. Medium. This pass is already underway and about 60% completed. It consists of three sub-passes. The first converts collections of
constexpr int
constants intoenum class
enumerations with a standard format in which the first item isInvalid = -1
and the last item isNum
. This part may require some thinking and rejiggering (technical term) as in several places the code exhibits an undue reliance on the actual values of enumerations rather than on their symbolic names. The second sub-pass creates aconstexpr std::array<std::string_view, static_cast<int>(ec::Num)> = ecNamesUC = {};
array of upper-cased names for eachenum class ec
that appears in the IDF and replaces theif-else
ladders used to convert the enumeration strings to their values with calls tostatic_cast<ec>getEnumerationValue(str, ecNamesUC);
. The third sub-pass replaces theSELECT_CASE_var
if-else
ladders that use these enumerations withswitch
/case
statements. -
EPVectorClass. Small. This pass consists of two sub-components which can probably be done together. The first replaces all instances of
ObjexxFCL::Array1D
for item types other thanint
,Real64
,std::string
, andbool
withEPVector
, which is a much lighter template. This change will add bounds-checking to debug builds, slowing down debug-build simulations significantly. To negate this, we will need to establish the pattern of usingauto & x = state.dataX->X(XNum);
followed byx.Field1
,x.Field2
, etc. rather than constantly doingstate.dataX->X(XNum).Field1
,state.dataX->X(XNum).Field2
all over the place (you know what I'm talking about). This will also make the code more readable. This part may actually make this into a medium pass rather than a small one. - Namespace. Small.
- epJSON. Large.
- Insensitive. Small.
- Initialization. Large.
- Unstring. Medium.