Skip to content

Commit

Permalink
epJSON address const reference and streamline for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
mjwitte committed Jun 9, 2021
1 parent 9132be6 commit c9328ff
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 135 deletions.
58 changes: 25 additions & 33 deletions src/EnergyPlus/HeatBalanceManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1562,19 +1562,19 @@ namespace HeatBalanceManager {
MaterNum = 0;

// Regular Materials
auto &IP(state.dataInputProcessing->inputProcessor);

state.dataHeatBalMgr->CurrentModuleObject = "Material";
auto const instances = state.dataInputProcessing->inputProcessor->epJSON.find(state.dataHeatBalMgr->CurrentModuleObject);
if (instances != state.dataInputProcessing->inputProcessor->epJSON.end()) {
InputProcessor::json objectSchemaProps; // Object schema properties
objectSchemaProps = state.dataInputProcessing->inputProcessor->getObjectSchemaProps(state, state.dataHeatBalMgr->CurrentModuleObject);
auto const instances = IP->epJSON.find(state.dataHeatBalMgr->CurrentModuleObject);
if (instances != IP->epJSON.end()) {
auto const &objectSchemaProps = IP->getObjectSchemaProps(state, state.dataHeatBalMgr->CurrentModuleObject);

int counter = 0;
auto &instancesValue = instances.value();
for (auto instance = instancesValue.begin(); instance != instancesValue.end(); ++instance) {
auto const &objectFields = instance.value();
auto const &thisObjectName = UtilityRoutines::MakeUPPERCase(instance.key());
state.dataInputProcessing->inputProcessor->markObjectAsUsed(state.dataHeatBalMgr->CurrentModuleObject, instance.key());
IP->markObjectAsUsed(state.dataHeatBalMgr->CurrentModuleObject, instance.key());
std::string materialName = thisObjectName;

if (GlobalNames::VerifyUniqueInterObjectName(state,
Expand All @@ -1587,40 +1587,32 @@ namespace HeatBalanceManager {
}
// For incoming idf, maintain object order
++counter;
MaterNum = state.dataInputProcessing->inputProcessor->getIDFObjNum(state, state.dataHeatBalMgr->CurrentModuleObject, counter);
MaterNum = IP->getIDFObjNum(state, state.dataHeatBalMgr->CurrentModuleObject, counter);

// Load the material derived type from the input data.
state.dataMaterial->Material(MaterNum).Group = RegularMaterial;
state.dataMaterial->Material(MaterNum).Name = materialName;
auto &thisMaterial = state.dataMaterial->Material(MaterNum);
thisMaterial.Group = RegularMaterial;
thisMaterial.Name = materialName;

std::string roughness = state.dataInputProcessing->inputProcessor->getAlphaFieldValue(
state, state.dataHeatBalMgr->CurrentModuleObject, objectFields, objectSchemaProps, "roughness");
std::string roughness = IP->getAlphaFieldValue(objectFields, objectSchemaProps, "roughness");
ValidateMaterialRoughness(state, MaterNum, roughness, ErrorsFound);

state.dataMaterial->Material(MaterNum).Thickness = state.dataInputProcessing->inputProcessor->getRealFieldValue(
state, state.dataHeatBalMgr->CurrentModuleObject, objectFields, objectSchemaProps, "thickness");
state.dataMaterial->Material(MaterNum).Conductivity = state.dataInputProcessing->inputProcessor->getRealFieldValue(
state, state.dataHeatBalMgr->CurrentModuleObject, objectFields, objectSchemaProps, "conductivity");
state.dataMaterial->Material(MaterNum).Density = state.dataInputProcessing->inputProcessor->getRealFieldValue(
state, state.dataHeatBalMgr->CurrentModuleObject, objectFields, objectSchemaProps, "density");
state.dataMaterial->Material(MaterNum).SpecHeat = state.dataInputProcessing->inputProcessor->getRealFieldValue(
state, state.dataHeatBalMgr->CurrentModuleObject, objectFields, objectSchemaProps, "specific_heat");
state.dataMaterial->Material(MaterNum).AbsorpThermal = state.dataInputProcessing->inputProcessor->getRealFieldValue(
state, state.dataHeatBalMgr->CurrentModuleObject, objectFields, objectSchemaProps, "thermal_absorptance");
state.dataMaterial->Material(MaterNum).AbsorpThermalInput = state.dataMaterial->Material(MaterNum).AbsorpThermal;
state.dataMaterial->Material(MaterNum).AbsorpSolar = state.dataInputProcessing->inputProcessor->getRealFieldValue(
state, state.dataHeatBalMgr->CurrentModuleObject, objectFields, objectSchemaProps, "solar_absorptance");
state.dataMaterial->Material(MaterNum).AbsorpSolarInput = state.dataMaterial->Material(MaterNum).AbsorpSolar;
state.dataMaterial->Material(MaterNum).AbsorpVisible = state.dataInputProcessing->inputProcessor->getRealFieldValue(
state, state.dataHeatBalMgr->CurrentModuleObject, objectFields, objectSchemaProps, "visible_absorptance");
state.dataMaterial->Material(MaterNum).AbsorpVisibleInput = state.dataMaterial->Material(MaterNum).AbsorpVisible;

if (state.dataMaterial->Material(MaterNum).Conductivity > 0.0) {
state.dataHeatBal->NominalR(MaterNum) =
state.dataMaterial->Material(MaterNum).Thickness / state.dataMaterial->Material(MaterNum).Conductivity;
state.dataMaterial->Material(MaterNum).Resistance = state.dataHeatBal->NominalR(MaterNum);
thisMaterial.Thickness = IP->getRealFieldValue(objectFields, objectSchemaProps, "thickness");
thisMaterial.Conductivity = IP->getRealFieldValue(objectFields, objectSchemaProps, "conductivity");
thisMaterial.Density = IP->getRealFieldValue(objectFields, objectSchemaProps, "density");
thisMaterial.SpecHeat = IP->getRealFieldValue(objectFields, objectSchemaProps, "specific_heat");
thisMaterial.AbsorpThermal = IP->getRealFieldValue(objectFields, objectSchemaProps, "thermal_absorptance");
thisMaterial.AbsorpThermalInput = thisMaterial.AbsorpThermal;
thisMaterial.AbsorpSolar = IP->getRealFieldValue(objectFields, objectSchemaProps, "solar_absorptance");
thisMaterial.AbsorpSolarInput = thisMaterial.AbsorpSolar;
thisMaterial.AbsorpVisible = IP->getRealFieldValue(objectFields, objectSchemaProps, "visible_absorptance");
thisMaterial.AbsorpVisibleInput = thisMaterial.AbsorpVisible;

if (thisMaterial.Conductivity > 0.0) {
state.dataHeatBal->NominalR(MaterNum) = thisMaterial.Thickness / thisMaterial.Conductivity;
thisMaterial.Resistance = state.dataHeatBal->NominalR(MaterNum);
} else {
ShowSevereError(state, "Positive thermal conductivity required for material " + state.dataMaterial->Material(MaterNum).Name);
ShowSevereError(state, "Positive thermal conductivity required for material " + thisMaterial.Name);
ErrorsFound = true;
}
}
Expand Down
25 changes: 8 additions & 17 deletions src/EnergyPlus/InputProcessing/InputProcessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -542,13 +542,10 @@ bool InputProcessor::getDefaultValue(EnergyPlusData &state, std::string const &o
return defaultFound;
}

std::string InputProcessor::getAlphaFieldValue(
EnergyPlusData &state, std::string const &objectWord, json const &ep_object, json const &schema_obj_props, std::string const &fieldName)
std::string InputProcessor::getAlphaFieldValue(json const &ep_object, json const &schema_obj_props, std::string const &fieldName)
{
auto const &schema_field_obj = schema_obj_props[fieldName];
if (schema_field_obj.empty()) {
ShowFatalError(state, "InputProcessor::fieldValue: Invalid field name = " + fieldName + "for object type = " + objectWord);
}
assert(!schema_field_obj.empty()); // Check that field name exists in the schema for this object type
bool isDefaulted = false;
std::string value;
auto it = ep_object.find(fieldName);
Expand All @@ -559,8 +556,7 @@ std::string InputProcessor::getAlphaFieldValue(
value = valuePair.first;
isDefaulted = valuePair.second;
} else {
ShowSevereError(state, "InputProcessor::fieldValue: Invalid field type = " + fieldName + "for object type = " + objectWord);
ShowFatalError(state, "String value requested but field type is numeric");
assert(false); // String value requested but field type in numeric
}
} else {
isDefaulted = findDefault(value, schema_field_obj);
Expand All @@ -571,13 +567,10 @@ std::string InputProcessor::getAlphaFieldValue(
return value;
}

Real64 InputProcessor::getRealFieldValue(
EnergyPlusData &state, std::string const &objectWord, json const &ep_object, json const &schema_obj_props, std::string const &fieldName)
Real64 InputProcessor::getRealFieldValue(json const &ep_object, json const &schema_obj_props, std::string const &fieldName)
{
auto const &schema_field_obj = schema_obj_props[fieldName];
if (schema_field_obj.empty()) {
ShowFatalError(state, "InputProcessor::fieldValue: Invalid field name = " + fieldName + "for object type = " + objectWord);
}
assert(!schema_field_obj.empty()); // Check that field name exists in the schema for this object type
bool isDefaulted = false;
Real64 value = 0.0;
auto it = ep_object.find(fieldName);
Expand Down Expand Up @@ -606,15 +599,13 @@ Real64 InputProcessor::getRealFieldValue(
return value;
}

json InputProcessor::getObjectSchemaProps(EnergyPlusData &state, std::string const &objectWord)
const json &InputProcessor::getObjectSchemaProps(EnergyPlusData &state, std::string const &objectWord)
{
auto const &schema_properties = schema.at("properties");
const json &object_schema = schema_properties.at(objectWord);
if (object_schema.empty()) {
ShowFatalError(state, "InputProcessor::fieldValue: Invalid object type = " + objectWord);
}
assert(!object_schema.empty()); // If this fails, the object type does not exist in the schema

json schema_obj_props = getPatternProperties(state, object_schema);
auto const &schema_obj_props = getPatternProperties(state, object_schema);
return schema_obj_props;
}

Expand Down
8 changes: 3 additions & 5 deletions src/EnergyPlus/InputProcessing/InputProcessor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,11 @@ public:

bool getDefaultValue(EnergyPlusData &state, std::string const &objectWord, std::string const &fieldName, std::string &value);

std::string getAlphaFieldValue(
EnergyPlusData &state, std::string const &objectWord, json const &ep_object, json const &schema_obj_props, std::string const &fieldName);
std::string getAlphaFieldValue(json const &ep_object, json const &schema_obj_props, std::string const &fieldName);

Real64 getRealFieldValue(
EnergyPlusData &state, std::string const &objectWord, json const &ep_object, json const &schema_obj_props, std::string const &fieldName);
Real64 getRealFieldValue(json const &ep_object, json const &schema_obj_props, std::string const &fieldName);

json getObjectSchemaProps(EnergyPlusData &state, std::string const &objectWord);
const json &getObjectSchemaProps(EnergyPlusData &state, std::string const &objectWord);

std::pair<std::string, bool> getObjectItemValue(std::string const &field_value, json const &schema_field_obj);

Expand Down
18 changes: 8 additions & 10 deletions src/EnergyPlus/SystemAvailabilityManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1351,24 +1351,23 @@ namespace SystemAvailabilityManager {

bool ErrorsFound = false;
std::string cCurrentModuleObject = "AvailabilityManagerAssignmentList";
auto &IP(state.dataInputProcessing->inputProcessor);

state.dataSystemAvailabilityManager->NumAvailManagerLists =
state.dataInputProcessing->inputProcessor->getNumObjectsFound(state, cCurrentModuleObject);
state.dataSystemAvailabilityManager->NumAvailManagerLists = IP->getNumObjectsFound(state, cCurrentModuleObject);

if (state.dataSystemAvailabilityManager->NumAvailManagerLists > 0) {

state.dataSystemAvailabilityManager->SysAvailMgrListData.allocate(state.dataSystemAvailabilityManager->NumAvailManagerLists);
auto const instances = state.dataInputProcessing->inputProcessor->epJSON.find(cCurrentModuleObject);
InputProcessor::json objectSchemaProps; // Object schema properties
objectSchemaProps = state.dataInputProcessing->inputProcessor->getObjectSchemaProps(state, cCurrentModuleObject);
auto const instances = IP->epJSON.find(cCurrentModuleObject);
auto const &objectSchemaProps = IP->getObjectSchemaProps(state, cCurrentModuleObject);

auto &instancesValue = instances.value();
int Item = 0;
for (auto instance = instancesValue.begin(); instance != instancesValue.end(); ++instance) {
++Item;
auto const &objectFields = instance.value();
auto const &thisObjectName = UtilityRoutines::MakeUPPERCase(instance.key());
state.dataInputProcessing->inputProcessor->markObjectAsUsed(cCurrentModuleObject, instance.key());
IP->markObjectAsUsed(cCurrentModuleObject, instance.key());
state.dataSystemAvailabilityManager->SysAvailMgrListData(Item).Name = thisObjectName;

auto extensibles = objectFields.find("managers");
Expand All @@ -1390,10 +1389,9 @@ namespace SystemAvailabilityManager {
for (auto extensibleInstance : extensiblesArray) {
++listItem;
state.dataSystemAvailabilityManager->SysAvailMgrListData(Item).AvailManagerName(listItem) =
state.dataInputProcessing->inputProcessor->getAlphaFieldValue(
state, cCurrentModuleObject, extensibleInstance, extensionSchemaProps, "availability_manager_name");
std::string availManagerObjType = state.dataInputProcessing->inputProcessor->getAlphaFieldValue(
state, cCurrentModuleObject, extensibleInstance, extensionSchemaProps, "availability_manager_object_type");
IP->getAlphaFieldValue(extensibleInstance, extensionSchemaProps, "availability_manager_name");
std::string availManagerObjType =
IP->getAlphaFieldValue(extensibleInstance, extensionSchemaProps, "availability_manager_object_type");
state.dataSystemAvailabilityManager->SysAvailMgrListData(Item).cAvailManagerType(listItem) = availManagerObjType;
state.dataSystemAvailabilityManager->SysAvailMgrListData(Item).AvailManagerType(listItem) =
ValidateAndSetSysAvailabilityManagerType(state, availManagerObjType);
Expand Down

5 comments on commit c9328ff

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

epJSONhelpers (mjwitte) - x86_64-MacOS-10.15-clang-11.0.0: OK (3089 of 3089 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.

epJSONhelpers (mjwitte) - Win64-Windows-10-VisualStudio-16: OK (2338 of 2338 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.

epJSONhelpers (mjwitte) - x86_64-Linux-Ubuntu-18.04-gcc-7.5: OK (3129 of 3129 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.

epJSONhelpers (mjwitte) - x86_64-Linux-Ubuntu-18.04-gcc-7.5-UnitTestsCoverage-Debug: OK (1643 of 1643 tests passed, 0 test warnings)

Build Badge Test Badge Coverage 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.

epJSONhelpers (mjwitte) - x86_64-Linux-Ubuntu-18.04-gcc-7.5-IntegrationCoverage-Debug: OK (726 of 726 tests passed, 0 test warnings)

Build Badge Test Badge Coverage Badge

Please sign in to comment.