Skip to content

Commit

Permalink
Merge pull request #8388 from NREL/global_SimManager_SimAir
Browse files Browse the repository at this point in the history
Global sim manager sim air
  • Loading branch information
Myoldmopar authored Nov 21, 2020
2 parents a047218 + 857e3c0 commit 52873dc
Show file tree
Hide file tree
Showing 40 changed files with 4,442 additions and 4,790 deletions.
108 changes: 108 additions & 0 deletions scripts/dev/analyze_state.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
from pathlib import Path
from typing import List, Set
from re import compile


class StateClass:
def __init__(self, struct_name: str, instance_name: str):
self.struct_name = struct_name
self.instance_name = instance_name
self.constructed = False
self.construction_call_matches_struct = False
self.clear_state_executed = False

def validate(self) -> bool:
"""
Checks all the identified conditions are met and if not issues warnings.
:return: Returns True if the state class is validated or False if not
"""
valid = True
if not self.constructed:
print("::warning file=EnergyPlusData.cc::State not constructed: " + self.instance_name)
valid = False

if not self.construction_call_matches_struct:
print("::warning file=EnergyPlusData.cc::State constructed with different type: " + self.instance_name)
valid = False

if not self.clear_state_executed:
print("::warning file=EnergyPlusData.cc::State clear_state() call missing: " + self.instance_name)
valid = False
return valid


class StateChecker:

def __init__(self, repo_root_path: Path):
self.repo_root = repo_root_path
self.member_variables: Set[StateClass] = set()

# read the state file contents -- if we ever split the data into files this will require modification
header_file_path = self.repo_root / 'src' / 'EnergyPlus' / 'Data' / 'EnergyPlusData.hh'
self.header_file_lines: List[str] = header_file_path.open().readlines()
source_file_path = self.repo_root / 'src' / 'EnergyPlus' / 'Data' / 'EnergyPlusData.cc'
self.source_file_lines: List[str] = source_file_path.open().readlines()

def determine_member_variables(self) -> None:
"""
Finds all member variables using a pretty simplistic clue, the unique_ptr declaration.
This would change if we ever go to raw pointers or another storage method.
Currently it looks for lines of the form:
std::unique_ptr<AirflowNetworkBalanceManagerData> dataAirflowNetworkBalanceManager;
"""
pattern = compile(r'\s*std::unique_ptr<(\w+)> (\w+);')
for li in self.header_file_lines:
m = pattern.match(li)
if m:
underlying_struct_name = m.group(1)
member_var_name = m.group(2)
self.member_variables.add(StateClass(underlying_struct_name, member_var_name))

def validate_member_variable_construction(self):
"""
Validates that the state member variables are constructed using a clue of the `make_unique` function.
"""
pattern = compile(r'\s*this->(\w+) = std::make_unique<(\w+)>\(\);')
for li in self.source_file_lines:
if li.strip().startswith('#'):
continue
m = pattern.match(li)
if m:
member_var_name = m.group(1)
underlying_struct_name = m.group(2)
for v in self.member_variables:
if v.instance_name == member_var_name:
v.constructed = True
if v.struct_name == underlying_struct_name:
v.construction_call_matches_struct = True

def validate_member_variable_clear_state(self):
"""
Validates the member's clear_state call is made in an uncommented line
"""
pattern = compile(r'\s*this->(\w+)->clear_state\(\);')
for li in self.source_file_lines:
if li.strip().startswith('#'):
continue
m = pattern.match(li)
if m:
member_var_name = m.group(1)
for v in self.member_variables:
if v.instance_name == member_var_name:
v.clear_state_executed = True


if __name__ == '__main__':
this_file_path = Path(__file__).resolve() # should be in scripts/dev
repo_root = this_file_path.parent.parent.parent # dev, scripts, repo_root
sc = StateChecker(repo_root)
sc.determine_member_variables()
sc.validate_member_variable_construction()
sc.validate_member_variable_clear_state()
all_good = True
for mv in sc.member_variables:
if not mv.validate():
all_good = False
if not all_good:
print("::error file=EnergyPlusData.cc::Problems with State Variables!")
1 change: 1 addition & 0 deletions scripts/dev/custom_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ python3 "$REPO_ROOT"/scripts/dev/check_for_tabs_in_idfs.py || EXIT_STATUS=$?
python3 "$REPO_ROOT"/scripts/dev/check_for_bom_in_idfs.py || EXIT_STATUS=$?
python3 "$REPO_ROOT"/scripts/dev/verify_cmake_dirs.py || EXIT_STATUS=$?
python3 "$REPO_ROOT"/scripts/dev/find_included_cc_files.py || EXIT_STATUS=$?
python3 "$REPO_ROOT"/scripts/dev/analyze_state.py || EXIT_STATUS=$?

exit $EXIT_STATUS
6 changes: 6 additions & 0 deletions src/EnergyPlus/Data/CommonIncludes.hh
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@
#include <EnergyPlus/Fans.hh>
#include <EnergyPlus/Pipes.hh>
#include <EnergyPlus/PlantChillers.hh>
#include <EnergyPlus/PlantLoopHeatPumpEIR.hh>
#include <EnergyPlus/PlantValves.hh>
#include <EnergyPlus/SetPointManager.hh>
#include <EnergyPlus/SimulationManager.hh>
#include <EnergyPlus/SingleDuct.hh>
#include <EnergyPlus/SizingManager.hh>
#include <EnergyPlus/SolarCollectors.hh>
#include <EnergyPlus/SolarReflectionManager.hh>
#include <EnergyPlus/SolarShading.hh>
Expand Down
157 changes: 85 additions & 72 deletions src/EnergyPlus/Data/EnergyPlusData.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,78 +56,84 @@ namespace EnergyPlus {
// todo, try to eliminate the need for the singleton
IOFiles::setSingleton(&files);

this->dataAirflowNetworkBalanceManager = std::unique_ptr<AirflowNetworkBalanceManagerData>(new AirflowNetworkBalanceManagerData);
this->dataAirLoop = std::unique_ptr<DataAirLoopData>(new DataAirLoopData);
this->dataAirLoopHVACDOAS = std::unique_ptr<AirLoopHVACDOASData>(new AirLoopHVACDOASData);
this->dataAirSystemsData = std::unique_ptr<AirSystemsData>(new AirSystemsData);
this->dataBaseboardElectric = std::unique_ptr<BaseboardElectricData>(new BaseboardElectricData);
this->dataBaseboardRadiator = std::unique_ptr<BaseboardRadiatorData>(new BaseboardRadiatorData);
this->dataBoilers = std::unique_ptr<BoilersData>(new BoilersData);
this->dataBoilerSteam = std::unique_ptr<BoilerSteamData>(new BoilerSteamData);
this->dataBranchAirLoopPlant = std::unique_ptr<DataBranchAirLoopPlantData>(new DataBranchAirLoopPlantData);
this->dataBranchInputManager = std::unique_ptr<BranchInputManagerData>(new BranchInputManagerData);
this->dataBranchNodeConnections = std::unique_ptr<BranchNodeConnectionsData>(new BranchNodeConnectionsData);
this->dataChilledCeilingPanelSimple = std::unique_ptr<ChilledCeilingPanelSimpleData>(new ChilledCeilingPanelSimpleData);
this->dataChillerAbsorber = std::unique_ptr<ChillerAbsorberData>(new ChillerAbsorberData);
this->dataChillerElectricEIR = std::unique_ptr<ChillerElectricEIRData>(new ChillerElectricEIRData);
this->dataChillerExhaustAbsorption = std::unique_ptr<ChillerExhaustAbsorptionData>(new ChillerExhaustAbsorptionData);
this->dataChillerGasAbsorption = std::unique_ptr<ChillerGasAbsorptionData>(new ChillerGasAbsorptionData);
this->dataChillerIndirectAbsorption = std::unique_ptr<ChillerIndirectAbsoprtionData>(new ChillerIndirectAbsoprtionData);
this->dataChillerReformulatedEIR = std::unique_ptr<ChillerReformulatedEIRData>(new ChillerReformulatedEIRData);
this->dataCondenserLoopTowers = std::unique_ptr<CondenserLoopTowersData>(new CondenserLoopTowersData);
this->dataConstruction = std::unique_ptr<ConstructionData>(new ConstructionData);
this->dataConvectionCoefficient = std::unique_ptr<ConvectionCoefficientsData>(new ConvectionCoefficientsData);
this->dataCoolTower = std::unique_ptr<CoolTowerData>(new CoolTowerData);
this->dataCostEstimateManager = std::unique_ptr<CostEstimateManagerData>(new CostEstimateManagerData);
this->dataCrossVentMgr = std::unique_ptr<CrossVentMgrData>(new CrossVentMgrData);
this->dataCTElectricGenerator = std::unique_ptr<CTElectricGeneratorData>(new CTElectricGeneratorData);
this->dataCurveManager = std::unique_ptr<CurveManagerData>(new CurveManagerData);
this->dataExteriorEnergyUse = std::unique_ptr<ExteriorEnergyUseData>(new ExteriorEnergyUseData);
this->dataFans = std::unique_ptr<FansData>(new FansData);
this->dataGlobal = std::unique_ptr<DataGlobal>(new DataGlobal);
this->dataPipes = std::unique_ptr<PipesData>(new PipesData);
this->dataPlantChillers = std::unique_ptr<PlantChillersData>(new PlantChillersData);
this->dataSolarCollectors = std::unique_ptr<SolarCollectorsData>(new SolarCollectorsData);
this->dataSolarReflectionManager = std::unique_ptr<SolarReflectionManagerData>(new SolarReflectionManagerData);
this->dataSolarShading = std::unique_ptr<SolarShadingData>(new SolarShadingData);
this->dataSplitterComponent = std::unique_ptr<SplitterComponentData>(new SplitterComponentData);
this->dataSteamBaseboardRadiator = std::unique_ptr<SteamBaseboardRadiatorData>(new SteamBaseboardRadiatorData);
this->dataSteamCoils = std::unique_ptr<SteamCoilsData>(new SteamCoilsData);
this->dataSurfaceGeometry = std::unique_ptr<SurfaceGeometryData>(new SurfaceGeometryData);
this->dataSurfaceGroundHeatExchangers = std::unique_ptr<SurfaceGroundHeatExchangersData>(new SurfaceGroundHeatExchangersData);
this->dataSwimmingPools = std::unique_ptr<SwimmingPoolsData>(new SwimmingPoolsData);
this->dataSystemAvailabilityManager = std::unique_ptr<SystemAvailabilityManagerData>(new SystemAvailabilityManagerData);
this->dataThermalChimneys = std::unique_ptr<ThermalChimneysData>(new ThermalChimneysData);
this->dataThermalComforts = std::unique_ptr<ThermalComfortsData>(new ThermalComfortsData);
this->dataTranspiredCollector = std::unique_ptr<TranspiredCollectorData>(new TranspiredCollectorData);
this->dataTimingsData = std::unique_ptr<DataTimingsData>(new DataTimingsData);
this->dataUFADManager = std::unique_ptr<UFADManagerData>(new UFADManagerData);
this->dataUnitarySystems = std::unique_ptr<UnitarySystemsData>(new UnitarySystemsData);
this->dataUnitHeaters = std::unique_ptr<UnitHeatersData>(new UnitHeatersData);
this->dataUnitVentilators = std::unique_ptr<UnitVentilatorsData>(new UnitVentilatorsData);
this->dataUserDefinedComponents = std::unique_ptr<UserDefinedComponentsData>(new UserDefinedComponentsData);
this->dataUtilityRoutines = std::unique_ptr<UtilityRoutinesData>(new UtilityRoutinesData);
this->dataVariableSpeedCoils = std::unique_ptr<VariableSpeedCoilsData>(new VariableSpeedCoilsData);
this->dataVentilatedSlab = std::unique_ptr<VentilatedSlabData>(new VentilatedSlabData);
this->dataWaterCoils = std::unique_ptr<WaterCoilsData>(new WaterCoilsData);
this->dataWaterData = std::unique_ptr<DataWaterData>(new DataWaterData);
this->dataWaterManager = std::unique_ptr<WaterManagerData>(new WaterManagerData);
this->dataWaterThermalTanks = std::unique_ptr<WaterThermalTanksData>(new WaterThermalTanksData);
this->dataWaterToAirHeatPump = std::unique_ptr<WaterToAirHeatPumpData>(new WaterToAirHeatPumpData);
this->dataWaterToAirHeatPumpSimple = std::unique_ptr<WaterToAirHeatPumpSimpleData>(new WaterToAirHeatPumpSimpleData);
this->dataWaterUse = std::unique_ptr<WaterUseData>(new WaterUseData);
this->dataWeatherManager = std::unique_ptr<WeatherManagerData>(new WeatherManagerData);
this->dataWindowAC = std::unique_ptr<WindowACData>(new WindowACData);
this->dataWindowComplexManager = std::unique_ptr<WindowComplexManagerData>(new WindowComplexManagerData);
this->dataWindowEquivalentLayer = std::unique_ptr<WindowEquivalentLayerData>(new WindowEquivalentLayerData);
this->dataWindowManager = std::unique_ptr<WindowManagerData>(new WindowManagerData);
this->dataWindTurbine = std::unique_ptr<WindTurbineData>(new WindTurbineData);
this->dataZoneAirLoopEquipmentManager = std::unique_ptr<ZoneAirLoopEquipmentManagerData>(new ZoneAirLoopEquipmentManagerData);
this->dataZoneContaminantPredictorCorrector = std::unique_ptr<ZoneContaminantPredictorCorrectorData>(new ZoneContaminantPredictorCorrectorData);
this->dataZoneDehumidifier = std::unique_ptr<ZoneDehumidifierData>(new ZoneDehumidifierData);
this->dataZoneEquipmentManager = std::unique_ptr<ZoneEquipmentManagerData>(new ZoneEquipmentManagerData);
this->dataZonePlenum = std::unique_ptr<ZonePlenumData>(new ZonePlenumData);
this->dataZoneTempPredictorCorrector = std::unique_ptr<ZoneTempPredictorCorrectorData>(new ZoneTempPredictorCorrectorData);
this->dataAirflowNetworkBalanceManager = std::make_unique<AirflowNetworkBalanceManagerData>();
this->dataAirLoop = std::make_unique<DataAirLoopData>();
this->dataAirLoopHVACDOAS = std::make_unique<AirLoopHVACDOASData>();
this->dataAirSystemsData = std::make_unique<AirSystemsData>();
this->dataBaseboardElectric = std::make_unique<BaseboardElectricData>();
this->dataBaseboardRadiator = std::make_unique<BaseboardRadiatorData>();
this->dataBoilers = std::make_unique<BoilersData>();
this->dataBoilerSteam = std::make_unique<BoilerSteamData>();
this->dataBranchAirLoopPlant = std::make_unique<DataBranchAirLoopPlantData>();
this->dataBranchInputManager = std::make_unique<BranchInputManagerData>();
this->dataBranchNodeConnections = std::make_unique<BranchNodeConnectionsData>();
this->dataChilledCeilingPanelSimple = std::make_unique<ChilledCeilingPanelSimpleData>();
this->dataChillerAbsorber = std::make_unique<ChillerAbsorberData>();
this->dataChillerElectricEIR = std::make_unique<ChillerElectricEIRData>();
this->dataChillerExhaustAbsorption = std::make_unique<ChillerExhaustAbsorptionData>();
this->dataChillerGasAbsorption = std::make_unique<ChillerGasAbsorptionData>();
this->dataChillerIndirectAbsorption = std::make_unique<ChillerIndirectAbsoprtionData>();
this->dataChillerReformulatedEIR = std::make_unique<ChillerReformulatedEIRData>();
this->dataCondenserLoopTowers = std::make_unique<CondenserLoopTowersData>();
this->dataConstruction = std::make_unique<ConstructionData>();
this->dataConvectionCoefficient = std::make_unique<ConvectionCoefficientsData>();
this->dataCoolTower = std::make_unique<CoolTowerData>();
this->dataCostEstimateManager = std::make_unique<CostEstimateManagerData>();
this->dataCrossVentMgr = std::make_unique<CrossVentMgrData>();
this->dataCTElectricGenerator = std::make_unique<CTElectricGeneratorData>();
this->dataCurveManager = std::make_unique<CurveManagerData>();
this->dataEIRPlantLoopHeatPump = std::make_unique<EIRPlantLoopHeatPumpsData>();
this->dataExteriorEnergyUse = std::make_unique<ExteriorEnergyUseData>();
this->dataFans = std::make_unique<FansData>();
this->dataGlobal = std::make_unique<DataGlobal>();
this->dataPipes = std::make_unique<PipesData>();
this->dataPlantChillers = std::make_unique<PlantChillersData>();
this->dataPlantValves = std::make_unique<PlantValvesData>();
this->dataSetPointManager = std::make_unique<SetPointManagerData>();
this->dataSimulationManager = std::make_unique<SimulationManagerData>();
this->dataSingleDuct = std::make_unique<SingleDuctData>();
this->dataSizingManager = std::make_unique<SizingManagerData>();
this->dataSolarCollectors = std::make_unique<SolarCollectorsData>();
this->dataSolarReflectionManager = std::make_unique<SolarReflectionManagerData>();
this->dataSolarShading = std::make_unique<SolarShadingData>();
this->dataSplitterComponent = std::make_unique<SplitterComponentData>();
this->dataSteamBaseboardRadiator = std::make_unique<SteamBaseboardRadiatorData>();
this->dataSteamCoils = std::make_unique<SteamCoilsData>();
this->dataSurfaceGeometry = std::make_unique<SurfaceGeometryData>();
this->dataSurfaceGroundHeatExchangers = std::make_unique<SurfaceGroundHeatExchangersData>();
this->dataSwimmingPools = std::make_unique<SwimmingPoolsData>();
this->dataSystemAvailabilityManager = std::make_unique<SystemAvailabilityManagerData>();
this->dataThermalChimneys = std::make_unique<ThermalChimneysData>();
this->dataThermalComforts = std::make_unique<ThermalComfortsData>();
this->dataTranspiredCollector = std::make_unique<TranspiredCollectorData>();
this->dataTimingsData = std::make_unique<DataTimingsData>();
this->dataUFADManager = std::make_unique<UFADManagerData>();
this->dataUnitarySystems = std::make_unique<UnitarySystemsData>();
this->dataUnitHeaters = std::make_unique<UnitHeatersData>();
this->dataUnitVentilators = std::make_unique<UnitVentilatorsData>();
this->dataUserDefinedComponents = std::make_unique<UserDefinedComponentsData>();
this->dataUtilityRoutines = std::make_unique<UtilityRoutinesData>();
this->dataVariableSpeedCoils = std::make_unique<VariableSpeedCoilsData>();
this->dataVentilatedSlab = std::make_unique<VentilatedSlabData>();
this->dataWaterCoils = std::make_unique<WaterCoilsData>();
this->dataWaterData = std::make_unique<DataWaterData>();
this->dataWaterManager = std::make_unique<WaterManagerData>();
this->dataWaterThermalTanks = std::make_unique<WaterThermalTanksData>();
this->dataWaterToAirHeatPump = std::make_unique<WaterToAirHeatPumpData>();
this->dataWaterToAirHeatPumpSimple = std::make_unique<WaterToAirHeatPumpSimpleData>();
this->dataWaterUse = std::make_unique<WaterUseData>();
this->dataWeatherManager = std::make_unique<WeatherManagerData>();
this->dataWindowAC = std::make_unique<WindowACData>();
this->dataWindowComplexManager = std::make_unique<WindowComplexManagerData>();
this->dataWindowEquivalentLayer = std::make_unique<WindowEquivalentLayerData>();
this->dataWindowManager = std::make_unique<WindowManagerData>();
this->dataWindTurbine = std::make_unique<WindTurbineData>();
this->dataZoneAirLoopEquipmentManager = std::make_unique<ZoneAirLoopEquipmentManagerData>();
this->dataZoneContaminantPredictorCorrector = std::make_unique<ZoneContaminantPredictorCorrectorData>();
this->dataZoneDehumidifier = std::make_unique<ZoneDehumidifierData>();
this->dataZoneEquipmentManager = std::make_unique<ZoneEquipmentManagerData>();
this->dataZonePlenum = std::make_unique<ZonePlenumData>();
this->dataZoneTempPredictorCorrector = std::make_unique<ZoneTempPredictorCorrectorData>();
}

void EnergyPlusData::clear_state() {
Expand Down Expand Up @@ -157,12 +163,19 @@ namespace EnergyPlus {
this->dataCrossVentMgr->clear_state();
this->dataCTElectricGenerator->clear_state();
this->dataCurveManager->clear_state();
this->dataEIRPlantLoopHeatPump->clear_state();
this->dataExteriorEnergyUse->clear_state();
this->dataFans->clear_state();
this->dataGlobal->clear_state();
this->dataPipes->clear_state();
this->dataPlantChillers->clear_state();
this->dataPlantValves->clear_state();
this->dataSetPointManager->clear_state();
this->dataSimulationManager->clear_state();
this->dataSingleDuct->clear_state();
this->dataSizingManager->clear_state();
this->dataSolarCollectors->clear_state();
this->dataSolarReflectionManager->clear_state();
this->dataSolarShading->clear_state();
this->dataSplitterComponent->clear_state();
this->dataSteamBaseboardRadiator->clear_state();
Expand Down
Loading

5 comments on commit 52873dc

@nrel-bot-3
Copy link

Choose a reason for hiding this comment

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

develop (Myoldmopar) - x86_64-MacOS-10.15-clang-11.0.0: OK (2277 of 2277 tests passed, 0 test warnings)

Build Badge Test Badge

@nrel-bot-2b
Copy link

Choose a reason for hiding this comment

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

develop (Myoldmopar) - x86_64-Linux-Ubuntu-18.04-gcc-7.5-UnitTestsCoverage-Debug: Build Failed

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.

develop (Myoldmopar) - x86_64-Linux-Ubuntu-18.04-gcc-7.5: OK (2297 of 2297 tests passed, 0 test warnings)

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.

develop (Myoldmopar) - Win64-Windows-10-VisualStudio-16: OK (2250 of 2250 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.

develop (Myoldmopar) - x86_64-Linux-Ubuntu-18.04-gcc-7.5-IntegrationCoverage-Debug: OK (722 of 722 tests passed, 0 test warnings)

Build Badge Test Badge Coverage Badge

Please sign in to comment.