NREL / OpenStudio

OpenStudio is a cross-platform collection of software tools to support whole building energy modeling using EnergyPlus and advanced daylight analysis using Radiance.
https://www.openstudio.net/
Other
506 stars 192 forks source link

Allow Python Plugin Instances in User-Defined Plant Component #5264

Open bonnema opened 1 month ago

bonnema commented 1 month ago

Enhancement Request

Modify the user-defined plant component to accept a Python Plugin Instance for the plantInitializationProgramCallingManager as well as the plantSimulationProgramCallingManager. Additionally, if a Python Plugin Instance is specified, do not construct any default Energy Management System objects.

Detailed Description

Currently, the user-defined plant component only allows an Energy Management System Program Calling Manager for the plantInitializationProgramCallingManager and the plantSimulationProgramCallingManager. It also default constructs a number of Energy Management System actuators in addition to a two Energy Management System programs.

However, this does not allow a Python Plugin to be used to model the user-defined plant component. While the importance of these defaults and generating a running model is recognized, it would be beneficial to be able to bypass this functionality.

Possible Implementation

Overload the setPlantInitializationProgramCallingManager and setPlantSimulationProgramCallingManager methods to accept a Python Plugin Instance. If the setPlantInitializationProgramCallingManager method is used with a Python Plugin Instance, do not default construct a Plant Initialization Energy Management System Program or these actuators:

Similarly, if the setPlantSimulationProgramCallingManager method is used with a Python Plugin Instance, do not default construct a Plant Simulation Energy Management System Program or these actuators:

It is important to keep these split, sometimes it is convenient to keep one program in Python and the other in ERL.

jmarrec commented 3 weeks ago

That's all done in the Ctor: https://github.com/NREL/OpenStudio/blob/cae94352f7d5ce2c44602dbda113fcb7bf085ab8/src/model/PlantComponentUserDefined.cpp#L519-L597

So the possible implementation is probably to provide a new ctor:

PlantComponentUserDefined::PlantComponentUserDefined(const PythonPluginInstance& initialiazitionProgram, const PythonPluginInstance& simulationProgram)

or maybe rather add a defaulted arg to the original ctor:

// if initializeEMS is true, actuators are set up, and two pairs of EMS:Program & EMS:ProgramCallingManager are set up for the initialization and simulation programs of the plant connection 1
PlantComponentUserDefined::PlantComponentUserDefined(const Model& model, bool initializeEMS = true);

Side note: I hadn't realized E+ has up to 4 plant connections (and program calling managers for each) while we support only one.