Skip to content

Commit

Permalink
Updated code, compiler warnings, format, etc. for Ubuntu 23.10/GCC 13…
Browse files Browse the repository at this point in the history
….2/Python 3.11, definitely not ready as-is
  • Loading branch information
Myoldmopar authored and jmarrec committed Dec 22, 2023
1 parent 8b79a80 commit a59310a
Show file tree
Hide file tree
Showing 13 changed files with 284 additions and 277 deletions.
12 changes: 9 additions & 3 deletions cmake/CompilerFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ elseif(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" O

# COMPILER FLAGS
target_compile_options(project_options INTERFACE -pipe) # Faster compiler processing
target_compile_options(project_warnings INTERFACE -Wpedantic
)# Turn on warnings about constructs/situations that may be non-portable or outside of the standard
target_compile_options(project_warnings INTERFACE -Wall -Wextra) # Turn on warnings
target_compile_options(project_warnings INTERFACE -Wpedantic)
# Turn on warnings about constructs/situations that may be non-portable or outside of the standard
target_compile_options(project_warnings INTERFACE -Wall) # Turn on warnings
target_compile_options(project_warnings INTERFACE -Wextra) # Turn on warnings
target_compile_options(project_warnings INTERFACE -Wno-unknown-pragmas)
if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.0)
target_compile_options(project_warnings INTERFACE -Wno-deprecated-copy)
Expand All @@ -101,6 +102,11 @@ elseif(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" O
target_compile_options(project_warnings INTERFACE -Wno-unused-but-set-parameter -Wno-unused-but-set-variable)
target_compile_options(project_warnings INTERFACE -Wno-maybe-uninitialized)
target_compile_options(project_warnings INTERFACE -Wno-aggressive-loop-optimizations)
# Sadly, GCC 13.2 is throwing many false positives on dangling references and compile time array-bounds
# https://gcc.gnu.org/git/gitweb.cgi?p=gcc.git;h=6b927b1297e66e26e62e722bf15c921dcbbd25b9
target_compile_options(project_warnings INTERFACE -Wno-dangling-reference)
target_compile_options(project_warnings INTERFACE -Wno-array-bounds)
target_compile_options(project_warnings INTERFACE -Wno-stringop-overflow)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 13.0)
# Suppress unused-but-set warnings until more serious ones are addressed
Expand Down
2 changes: 1 addition & 1 deletion src/ConvertInputFormat/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ static constexpr std::array<std::string_view, static_cast<int>(OutputTypes::Num)

static constexpr auto outputTypeExperimentalStart = OutputTypes::CBOR;

template <typename... Args> void displayMessage(std::string_view str_format, Args &&... args)
template <typename... Args> void displayMessage(std::string_view str_format, Args &&...args)
{
fmt::print(std::cout, str_format, args...);
std::cout.write("\n", 1);
Expand Down
16 changes: 8 additions & 8 deletions src/EnergyPlus/EPVector.hh
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,12 @@ private:
bool m_allocated{false};
};

template <typename T>[[nodiscard]] bool allocated(EPVector<T> const &v) noexcept
template <typename T> [[nodiscard]] bool allocated(EPVector<T> const &v) noexcept
{
return v.allocated();
}

template <typename T>[[nodiscard]] auto isize(const EPVector<T> &v) noexcept
template <typename T> [[nodiscard]] auto isize(const EPVector<T> &v) noexcept
{
return v.isize();
}
Expand All @@ -294,7 +294,7 @@ template <typename T>[[nodiscard]] auto isize(const EPVector<T> &v) noexcept
return std::count_if(values.cbegin(), values.cend(), [](bool v) { return v; });
}

template <typename T>[[nodiscard]] EPVector<T> pack(EPVector<T> const &v, EPVector<bool> const &mask)
template <typename T> [[nodiscard]] EPVector<T> pack(EPVector<T> const &v, EPVector<bool> const &mask)
{
EPVector<T> r;
r.reserve(mask.size());
Expand All @@ -306,7 +306,7 @@ template <typename T>[[nodiscard]] EPVector<T> pack(EPVector<T> const &v, EPVect
return r;
}

template <typename T>[[nodiscard]] Array1D<T> pack(Array1<T> const &a, EPVector<bool> const &mask)
template <typename T> [[nodiscard]] Array1D<T> pack(Array1<T> const &a, EPVector<bool> const &mask)
{
Array1D<T> r;
r.reserve(mask.size());
Expand All @@ -318,17 +318,17 @@ template <typename T>[[nodiscard]] Array1D<T> pack(Array1<T> const &a, EPVector<
return r;
}

template <typename T>[[nodiscard]] T magnitude_squared(const EPVector<T> &v)
template <typename T> [[nodiscard]] T magnitude_squared(const EPVector<T> &v)
{
return std::inner_product(v.begin(), v.end(), v.begin(), T{});
}

template <typename T, typename V>[[nodiscard]] T dot(const EPVector<T> &u, const V &v)
template <typename T, typename V> [[nodiscard]] T dot(const EPVector<T> &u, const V &v)
{
return std::inner_product(u.begin(), u.end(), v.begin(), T{});
}

template <typename Element, typename Member>[[nodiscard]] Member maxval(EPVector<Element> const &a, Member Element::*pmem)
template <typename Element, typename Member> [[nodiscard]] Member maxval(EPVector<Element> const &a, Member Element::*pmem)
{
Member v(a.empty() ? std::numeric_limits<Member>::lowest() : a(1).*pmem);
for (int i = 2, e = a.isize(); i <= e; ++i) {
Expand All @@ -343,7 +343,7 @@ template <typename Element, typename Member> inline Member sum(EPVector<Element>
return std::accumulate(c.cbegin(), c.cend(), 0.0, [&pmem](const Member &sum, const Element &e) { return sum + e.*pmem; });
}

template <typename T>[[nodiscard]] T maxval(EPVector<T> const &a)
template <typename T> [[nodiscard]] T maxval(EPVector<T> const &a)
{
auto max = std::max_element(a.begin(), a.end());
if (max == a.end()) {
Expand Down
4 changes: 2 additions & 2 deletions src/EnergyPlus/FileSystem.hh
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ namespace FileSystem {
is_any<T, std::unique_ptr<fs::path>, std::unique_ptr<fmt::ostream>, std::unique_ptr<std::ostream>, std::unique_ptr<FILE *>>::value;

template <class T, FileTypes fileType>
inline constexpr bool enable_json_v = is_all_json_type(fileType) && is_any<T, nlohmann::json>::value &&
!is_any<T, std::string_view, std::string, char *>::value;
inline constexpr bool enable_json_v =
is_all_json_type(fileType) && is_any<T, nlohmann::json>::value && !is_any<T, std::string_view, std::string, char *>::value;

template <FileTypes fileType> void writeFile(fs::path const &filePath, const std::string_view data)
{
Expand Down
2 changes: 1 addition & 1 deletion src/EnergyPlus/HeatBalanceKivaManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ bool KivaManager::setupKivaInstances(EnergyPlusData &state)

Real64 surfHeight = Surfaces(wl).get_average_height(state);
// round to avoid numerical precision differences
surfHeight = std::round((surfHeight)*1000.0) / 1000.0;
surfHeight = std::round((surfHeight) * 1000.0) / 1000.0;

if (combinationMap.count({Surfaces(wl).Construction, surfHeight}) == 0) {
// create new combination
Expand Down
9 changes: 4 additions & 5 deletions src/EnergyPlus/HeatPumpWaterToWaterCOOLING.hh
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,10 @@ namespace HeatPumpWaterToWaterCOOLING {
MaxPartLoadRat(0.0), OptPartLoadRat(0.0), LoadSideVolFlowRate(0.0), LoadSideDesignMassFlow(0.0), SourceSideVolFlowRate(0.0),
SourceSideDesignMassFlow(0.0), SourceSideInletNodeNum(0), SourceSideOutletNodeNum(0), LoadSideInletNodeNum(0), LoadSideOutletNodeNum(0),
SourceSideUACoeff(0.0), LoadSideUACoeff(0.0), CompPistonDisp(0.0), CompClearanceFactor(0.0), CompSucPressDrop(0.0), SuperheatTemp(0.0),
PowerLosses(0.0), LossFactor(0.0), HighPressCutoff(0.0), LowPressCutoff(0.0), IsOn(false),
MustRun(false), SourcePlantLoc{}, LoadPlantLoc{}, CondMassFlowIndex(0), Power(0.0), Energy(0.0), QLoad(0.0), QLoadEnergy(0.0),
QSource(0.0), QSourceEnergy(0.0), LoadSideWaterInletTemp(0.0), SourceSideWaterInletTemp(0.0), LoadSideWaterOutletTemp(0.0),
SourceSideWaterOutletTemp(0.0), Running(0), LoadSideWaterMassFlowRate(0.0), SourceSideWaterMassFlowRate(0.0), plantScanFlag(true),
beginEnvironFlag(true)
PowerLosses(0.0), LossFactor(0.0), HighPressCutoff(0.0), LowPressCutoff(0.0), IsOn(false), MustRun(false), SourcePlantLoc{},
LoadPlantLoc{}, CondMassFlowIndex(0), Power(0.0), Energy(0.0), QLoad(0.0), QLoadEnergy(0.0), QSource(0.0), QSourceEnergy(0.0),
LoadSideWaterInletTemp(0.0), SourceSideWaterInletTemp(0.0), LoadSideWaterOutletTemp(0.0), SourceSideWaterOutletTemp(0.0), Running(0),
LoadSideWaterMassFlowRate(0.0), SourceSideWaterMassFlowRate(0.0), plantScanFlag(true), beginEnvironFlag(true)
{
}

Expand Down
21 changes: 12 additions & 9 deletions src/EnergyPlus/IOFiles.hh
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ private:
std::string_view spec_builder()
{
buffer.clear();
// This line seems to be the culprit with some array-bounds warnings
// during compilation on GCC 13.2. I don't see how at the moment.
// I tried pragma-ing it away but it didn't help
buffer.push_back('{');
buffer.push_back(':');
// [[fill]align][sign]["#"]["0"][width]["." precision]["L"][type]
Expand Down Expand Up @@ -492,7 +495,7 @@ inline constexpr bool is_fortran_syntax(const std::string_view format_str)

class InputOutputFile;
template <FormatSyntax formatSyntax = FormatSyntax::Fortran, typename... Args>
void print(InputOutputFile &outputFile, std::string_view format_str, Args &&... args);
void print(InputOutputFile &outputFile, std::string_view format_str, Args &&...args);

inline constexpr FormatSyntax check_syntax(const std::string_view format_str)
{
Expand Down Expand Up @@ -610,7 +613,7 @@ public:
private:
std::unique_ptr<std::iostream> os;
bool print_to_dev_null = false;
template <FormatSyntax, typename... Args> friend void print(InputOutputFile &outputFile, std::string_view format_str, Args &&... args);
template <FormatSyntax, typename... Args> friend void print(InputOutputFile &outputFile, std::string_view format_str, Args &&...args);
friend class IOFiles;
};

Expand Down Expand Up @@ -802,7 +805,7 @@ public:
}
};

template <typename... Args> void vprint(std::ostream &os, std::string_view format_str, const Args &... args)
template <typename... Args> void vprint(std::ostream &os, std::string_view format_str, const Args &...args)
{
// assert(os.good());
auto buffer = fmt::memory_buffer();
Expand All @@ -814,7 +817,7 @@ template <typename... Args> void vprint(std::ostream &os, std::string_view forma
os.write(buffer.data(), buffer.size());
}

template <typename... Args> std::string vprint(std::string_view format_str, const Args &... args)
template <typename... Args> std::string vprint(std::string_view format_str, const Args &...args)
{
auto buffer = fmt::memory_buffer();
try {
Expand Down Expand Up @@ -848,19 +851,19 @@ template <typename... Args> std::string vprint(std::string_view format_str, cons
//

namespace {
template <typename... Args> void print_fortran_syntax(std::ostream &os, std::string_view format_str, const Args &... args)
template <typename... Args> void print_fortran_syntax(std::ostream &os, std::string_view format_str, const Args &...args)
{
EnergyPlus::vprint<std::conditional_t<std::is_same_v<double, Args>, DoubleWrapper, Args>...>(os, format_str, args...);
}

template <typename... Args> std::string format_fortran_syntax(std::string_view format_str, const Args &... args)
template <typename... Args> std::string format_fortran_syntax(std::string_view format_str, const Args &...args)
{
return EnergyPlus::vprint<std::conditional_t<std::is_same_v<double, Args>, DoubleWrapper, Args>...>(format_str, args...);
}
} // namespace

template <FormatSyntax formatSyntax = FormatSyntax::Fortran, typename... Args>
void print(std::ostream &os, std::string_view format_str, Args &&... args)
void print(std::ostream &os, std::string_view format_str, Args &&...args)
{
if constexpr (formatSyntax == FormatSyntax::Fortran) {
print_fortran_syntax(os, format_str, args...);
Expand All @@ -871,7 +874,7 @@ void print(std::ostream &os, std::string_view format_str, Args &&... args)
}
}

template <FormatSyntax formatSyntax, typename... Args> void print(InputOutputFile &outputFile, std::string_view format_str, Args &&... args)
template <FormatSyntax formatSyntax, typename... Args> void print(InputOutputFile &outputFile, std::string_view format_str, Args &&...args)
{
auto *outputStream = [&]() -> std::ostream * {
if (outputFile.os) {
Expand All @@ -894,7 +897,7 @@ template <FormatSyntax formatSyntax, typename... Args> void print(InputOutputFil
}
}

template <FormatSyntax formatSyntax = FormatSyntax::Fortran, typename... Args> std::string format(std::string_view format_str, Args &&... args)
template <FormatSyntax formatSyntax = FormatSyntax::Fortran, typename... Args> std::string format(std::string_view format_str, Args &&...args)
{
if constexpr (formatSyntax == FormatSyntax::Fortran) {
return format_fortran_syntax(format_str, args...);
Expand Down
10 changes: 5 additions & 5 deletions src/EnergyPlus/PhaseChangeModeling/HysteresisModel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ namespace HysteresisPhaseChange {
phaseChangeState = PhaseChangeStates::FREEZING;
this->enthNew =
this->getEnthalpy(updatedTempTDT, this->peakTempFreezing, this->deltaTempFreezingLow, this->deltaTempFreezingHigh);
} else if (this->enthNew < this->enthalpyF && this->enthNew > this->enthalpyM) {
} else if (this->enthNew > this->enthalpyM && this->enthNew < this->enthalpyF) {
phaseChangeState = PhaseChangeStates::TRANSITION;
this->enthNew = (this->specHeatTransition * updatedTempTDT) + (this->enthOld - (this->specHeatTransition * prevTempTD));
} else if (this->enthNew < this->enthalpyF && updatedTempTDT > phaseChangeTempReverse) {
Expand All @@ -191,11 +191,11 @@ namespace HysteresisPhaseChange {
this->enthNew = (this->specHeatTransition * updatedTempTDT) + (this->enthOld - (this->specHeatTransition * prevTempTD));
this->enthalpyM = this->getEnthalpy(updatedTempTDT, this->peakTempMelting, this->deltaTempMeltingLow, this->deltaTempMeltingHigh);
this->enthalpyF = this->getEnthalpy(updatedTempTDT, this->peakTempMelting, this->deltaTempMeltingLow, this->deltaTempMeltingHigh);
if (updatedTempTDT < phaseChangeTempReverse && this->enthNew > this->enthalpyF) {
if (this->enthNew > this->enthalpyF && updatedTempTDT < phaseChangeTempReverse) {
phaseChangeState = PhaseChangeStates::FREEZING;
this->enthNew =
this->getEnthalpy(updatedTempTDT, this->peakTempFreezing, this->deltaTempFreezingLow, this->deltaTempFreezingHigh);
} else if (this->enthNew < this->enthalpyF && this->enthNew > this->enthalpyM &&
} else if (this->enthNew > this->enthalpyM && this->enthNew < this->enthalpyF &&
(updatedTempTDT < prevTempTD || updatedTempTDT > prevTempTD)) {
phaseChangeState = PhaseChangeStates::TRANSITION;
this->enthNew =
Expand All @@ -211,7 +211,7 @@ namespace HysteresisPhaseChange {
this->enthNew = (this->specHeatTransition * updatedTempTDT) + (this->enthRev - (this->specHeatTransition * phaseChangeTempReverse));
this->enthalpyM = this->getEnthalpy(updatedTempTDT, this->peakTempMelting, this->deltaTempMeltingLow, this->deltaTempMeltingHigh);
this->enthalpyF = this->getEnthalpy(updatedTempTDT, this->peakTempFreezing, this->deltaTempFreezingLow, this->deltaTempFreezingHigh);
if (this->enthNew < this->enthalpyF && this->enthNew > this->enthalpyM) {
if (this->enthNew > this->enthalpyM && this->enthNew < this->enthalpyF) {
phaseChangeState = PhaseChangeStates::TRANSITION;
this->enthNew =
(this->specHeatTransition * updatedTempTDT) + (this->enthRev - (this->specHeatTransition * phaseChangeTempReverse));
Expand All @@ -226,7 +226,7 @@ namespace HysteresisPhaseChange {
if (this->enthNew < this->enthOld && updatedTempTDT < prevTempTD) {
phaseChangeState = PhaseChangeStates::TRANSITION;
this->enthNew = (this->specHeatTransition * updatedTempTDT) + (this->enthOld - (this->specHeatTransition * prevTempTD));
} else if (this->enthNew < this->enthalpyF && this->enthNew > this->enthalpyM && updatedTempTDT < prevTempTD) {
} else if (this->enthNew > this->enthalpyM && this->enthNew < this->enthalpyF && updatedTempTDT < prevTempTD) {
phaseChangeState = PhaseChangeStates::TRANSITION;
this->enthNew =
(this->specHeatTransition * updatedTempTDT) + (this->enthRev - (this->specHeatTransition * phaseChangeTempReverse));
Expand Down
6 changes: 3 additions & 3 deletions src/EnergyPlus/PoweredInductionUnits.hh
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ namespace PoweredInductionUnits {
OutAirNode(0), HCoilInAirNode(0), ControlCompTypeNum(0), CompErrIndex(0), Mixer_Num(0), Fan_Num(0), Fan_Index(0), FanAvailSchedPtr(0),
HCoilType(HtgCoilType::Invalid), HCoil_PlantType(DataPlant::PlantEquipmentType::Invalid), HCoil_Index(0), HCoil_FluidIndex(0),
MaxVolHotWaterFlow(0.0), MaxVolHotSteamFlow(0.0), MaxHotWaterFlow(0.0), MaxHotSteamFlow(0.0), MinVolHotWaterFlow(0.0),
MinHotSteamFlow(0.0), MinVolHotSteamFlow(0.0), MinHotWaterFlow(0.0), HotControlNode(0), HotCoilOutNodeNum(0),
HotControlOffset(0.0), HWplantLoc{}, ADUNum(0), InducesPlenumAir(false), HeatingRate(0.0), HeatingEnergy(0.0), SensCoolRate(0.0),
SensCoolEnergy(0.0), CtrlZoneNum(0), ctrlZoneInNodeIndex(0), AirLoopNum(0), OutdoorAirFlowRate(0.0)
MinHotSteamFlow(0.0), MinVolHotSteamFlow(0.0), MinHotWaterFlow(0.0), HotControlNode(0), HotCoilOutNodeNum(0), HotControlOffset(0.0),
HWplantLoc{}, ADUNum(0), InducesPlenumAir(false), HeatingRate(0.0), HeatingEnergy(0.0), SensCoolRate(0.0), SensCoolEnergy(0.0),
CtrlZoneNum(0), ctrlZoneInNodeIndex(0), AirLoopNum(0), OutdoorAirFlowRate(0.0)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/EnergyPlus/StringUtilities.hh
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ inline auto nth_occurrence(std::string_view input_str, char const search_char, s
return pos;
}

template <typename... Param> bool readList(std::string_view input, Param &&... param)
template <typename... Param> bool readList(std::string_view input, Param &&...param)
{
if constexpr (std::conjunction_v<std::is_same<double &, Param>...> || std::conjunction_v<std::is_same<int &, Param>...>) {
size_t index = 0;
Expand Down
4 changes: 2 additions & 2 deletions third_party/ssc/shared/lib_battery_lifetime.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ struct lifetime_state {

lifetime_state(const std::shared_ptr<cycle_state>& cyc, const std::shared_ptr<calendar_state>& cal);

lifetime_state(const std::shared_ptr<lifetime_nmc_state>& nmc);
explicit lifetime_state(const std::shared_ptr<lifetime_nmc_state>& nmc);

lifetime_state &operator=(const lifetime_state &rhs);

Expand All @@ -81,7 +81,7 @@ class lifetime_t {

lifetime_t(const lifetime_t &rhs);

virtual lifetime_t &operator=(const lifetime_t &rhs);
lifetime_t &operator=(const lifetime_t &rhs);

virtual lifetime_t *clone() = 0;

Expand Down
Loading

0 comments on commit a59310a

Please sign in to comment.