Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add autosizing to Spawn #4019

Draft
wants to merge 59 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
836482b
Implemented support for RunPeriod
mwetter Apr 21, 2022
965fe41
Implemented support for RunPeriod
mwetter Apr 21, 2022
7b61856
Implemented support for RunPeriod
mwetter Apr 21, 2022
6331a16
Implemented support for RunPeriod
mwetter Apr 21, 2022
bbb6468
Implemented support for RunPeriod
mwetter Apr 21, 2022
850a10e
Added Linux binary
mwetter Apr 21, 2022
bfc1b12
Add EnergyPlus_24_1_0 resources
kbenne Jun 25, 2024
3682042
Merged master
mwetter Aug 21, 2024
8bae883
Added validation test
mwetter Aug 21, 2024
32a1eab
Added validation test
mwetter Aug 21, 2024
dd2a6f4
Removed comment in annotation
mwetter Aug 21, 2024
18195d0
Introduced sLen
mwetter Aug 21, 2024
0506fcb
Compiled Linux binaries
mwetter Aug 21, 2024
0fc07e9
Revised and expanded documentation
mwetter Aug 22, 2024
cd19b6e
Revised and expanded documentation
mwetter Aug 22, 2024
c0b7065
Added install.py file
mwetter Aug 24, 2024
a806c31
Merge branch 'master' into issue3911_EP_24_1_0
mwetter Aug 24, 2024
cbe8bd1
Merge branch 'issue2926_runPeriod' into issue3911_EP_24_1_0
mwetter Aug 24, 2024
c356729
Updated hash and version for new binaries
mwetter Aug 24, 2024
98565df
Updated .mo files for EnergyPlus 24.1.0, after copying examples from …
mwetter Aug 24, 2024
696af3d
Updated EnergyPlus version
mwetter Aug 24, 2024
d45a9e2
Added mos scripts
mwetter Aug 26, 2024
0172fda
Setup examples
mwetter Aug 26, 2024
fb39b07
Updated C code
mwetter Aug 26, 2024
fd2cb3c
Removed old binary
mwetter Aug 26, 2024
8b084e2
Updated EnergyPlus version
mwetter Aug 26, 2024
bbfdb73
Updated release notes
mwetter Aug 26, 2024
085fbc8
Updated link to figures
mwetter Aug 26, 2024
2b19281
Moved files used for EnergyPlus_9_6_0 and EnergyPlus_24_1_0 testing
mwetter Aug 26, 2024
15e21ed
Changed Spawn version [ci skip]
mwetter Sep 3, 2024
dea9608
Refactored RunPeriod [ci skip]
mwetter Sep 3, 2024
7b37737
Merge branch 'master' into issue2926_runPeriod
mwetter Sep 3, 2024
ad36a65
Compiled dll
mwetter Sep 3, 2024
02b0299
Updated documentation
mwetter Sep 3, 2024
3a92082
Formatted file
mwetter Sep 3, 2024
605f332
Renamed model
mwetter Sep 3, 2024
cecf92e
Updated release notes
mwetter Sep 3, 2024
f7ea3da
Corrected format
mwetter Sep 3, 2024
db4a232
Merged #2926
mwetter Sep 3, 2024
aae5886
Renamed model
mwetter Sep 3, 2024
6dd75b8
Ported changes from #2926
mwetter Sep 3, 2024
7352fd8
Ported changes from #2926
mwetter Sep 3, 2024
7f838d9
Ported changes from #2926
mwetter Sep 3, 2024
c8a408b
Merged master
mwetter Oct 17, 2024
40224a3
Changed E+ version
mwetter Oct 17, 2024
97b256f
Renamed 24_1_0 to 24_2_0 and 24.1.0 to 24.2.0
mwetter Oct 17, 2024
f439f04
Renamed 24_1_0 to 24_2_0 and 24.1.0 to 24.2.0
mwetter Oct 17, 2024
c57ad29
Checked out idf from issue3911_EP_24_2_1
mwetter Oct 17, 2024
112520a
Reverted package.order
mwetter Oct 17, 2024
f21f28e
Ported autosizing code to .c and .h files
mwetter Oct 17, 2024
742e5d3
Removed annotations that do not belong into base class
mwetter Oct 17, 2024
88673e7
Removed annotations that do not belong into base class
mwetter Oct 17, 2024
6f36b71
Ported autosizing code to .mo files
mwetter Oct 17, 2024
6312376
Merged master
mwetter Nov 27, 2024
fea8ca6
Removed conflict
mwetter Nov 27, 2024
2bb5ad2
Corrected function signature
mwetter Nov 27, 2024
71eff9d
Updated hash for Spawn binaries [ci skip]
mwetter Jan 8, 2025
4542766
Removed quotes for boolean values [ci skip]
mwetter Jan 8, 2025
33eaa4d
Compiled binaries for Linux
mwetter Jan 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Buildings/Resources/C-Sources/EnergyPlus_24_2_0_Wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,17 @@ void* allocate_Modelica_EnergyPlus_24_2_0(
const char* idfVersion,
const char* idfName,
const char* epwName,
const char* epName,
const char* hvacZone,
const int autosizeHVAC,
const int use_sizingPeriods,
int runPeriod_dayOfWeekForStartDay,
int runPeriod_applyWeekEndHolidayRule,
int runPeriod_use_weatherFileDaylightSavingPeriod,
int runPeriod_use_weatherFileHolidaysAndSpecialDays,
int runPeriod_use_weatherFileRainIndicators,
int runPeriod_use_weatherFileSnowIndicators,
double relativeSurfaceTolerance,
const char* epName,
int usePrecompiledFMU,
const char* fmuName,
const char* buildingsRootFileLocation,
Expand Down Expand Up @@ -88,9 +91,12 @@ void* allocate_Modelica_EnergyPlus_24_2_0(
idfVersion,
idfName,
epwName,
epName,
hvacZone,
autosizeHVAC,
use_sizingPeriods,
&runPer,
relativeSurfaceTolerance,
epName,
usePrecompiledFMU,
fmuName,
buildingsRootFileLocation,
Expand Down
5 changes: 4 additions & 1 deletion Buildings/Resources/C-Sources/EnergyPlus_24_2_0_Wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@ extern void* allocate_Spawn_EnergyPlus_24_2_0(
const char* idfVersion,
const char* idfName,
const char* epwName,
const char* epName,
const char* hvacZone,
const int autosizeHVAC,
const int use_sizingPeriods,
const runPeriod* runPer,
double relativeSurfaceTolerance,
const char* epName,
int usePrecompiledFMU,
const char* fmuName,
const char* buildingsRootFileLocation,
Expand Down
Git LFS file not shown
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def print_output(typ, stream):
def run_test(pathVariable):
# List of files to be moved
fileMoves = [
{"src": os.path.abspath(os.path.join("Buildings", "Resources", "bin", "spawn-0.6.0-9f1b36b00b", "linux64")),
{"src": os.path.abspath(os.path.join("Buildings", "Resources", "bin", "spawn-0.6.0-5297abe3fb", "linux64")),
"des": "my-bin"},
{"src": os.path.abspath(os.path.join("Buildings", "Resources", "weatherdata")),
"des": "some_weather_directory_that_the_fmu_does_not_know_about"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,30 +62,41 @@ void buildJSONKeyDoubleValue(
buildJSONKeyLiteralValue(buffer, level, key, litVal, addComma, size, SpawnFormatError);
}

void openJSONModelBracket(char* *buffer, size_t* size, void (*SpawnFormatError)(const char *string, ...)){
saveAppend(buffer, " {\n", size, SpawnFormatError);
void openJSONModelBracket(char* *buffer, size_t level, size_t* size, void (*SpawnFormatError)(const char *string, ...)){
size_t iLevel;
for(iLevel = 0; iLevel < level; iLevel++)
saveAppend(buffer, " ", size, SpawnFormatError);
saveAppend(buffer, "{\n", size, SpawnFormatError);
}

void closeJSONModelBracket(
char* *buffer, size_t i, size_t iMax, size_t* size,
char* *buffer, size_t level, size_t i, size_t iMax, size_t* size,
void (*SpawnFormatError)(const char *string, ...)){
size_t iLevel;
for(iLevel = 0; iLevel < level; iLevel++)
saveAppend(buffer, " ", size, SpawnFormatError);
if (i < iMax -1)
saveAppend(buffer, " },\n", size, SpawnFormatError);
saveAppend(buffer, "},\n", size, SpawnFormatError);
else
saveAppend(buffer, " }\n", size, SpawnFormatError);
saveAppend(buffer, "}\n", size, SpawnFormatError);
}

void closeJSONModelArrayBracket(
char* *buffer, size_t iMod, size_t nMod, size_t* size,
char* *buffer, size_t level, size_t iMod, size_t nMod, size_t* size,
void (*SpawnFormatError)(const char *string, ...)){

size_t iLevel;
for(iLevel = 0; iLevel < level; iLevel++)
saveAppend(buffer, " ", size, SpawnFormatError);

/* Close json array bracket */
if (iMod == nMod){
/* There are no more other objects that belong to "model" */
saveAppend(buffer, " ]\n", size, SpawnFormatError);
saveAppend(buffer, "]\n", size, SpawnFormatError);
}
else{
/* There are other objects that belong to "model" */
saveAppend(buffer, " ],\n", size, SpawnFormatError);
saveAppend(buffer, "],\n", size, SpawnFormatError);
}
}

Expand Down Expand Up @@ -117,6 +128,104 @@ char* getStartDayOfYear(
return day;
}

void buildJSONModelStructureForEnergyPlusHVACZones(
const FMUBuilding* bui, char* *buffer, size_t iMod, size_t nMod, size_t* size){
size_t i;
size_t iWri;
size_t k;
size_t iHVACZones;
size_t nTheZon = 0; /* Number of thermal zones */
size_t nHVACZones = 0; /* Number of HVACZones */
bool recorded;
char **arrHVACZones = NULL;
size_t *couTheZon = NULL;

SpawnObject** ptrSpaObj = (SpawnObject**)bui->exchange;

void (*SpawnFormatError)(const char *string, ...) = bui->SpawnFormatError;

/* Count how many thermal zones there are in each HVACZone */
/* Number of HVAC zones */
for(i = 0; i < bui->nExcObj; i++){
if ( ptrSpaObj[i]->objectType == THERMALZONE ) {
nTheZon++;
}
}
/* Array of names of HVACZone, or NULL if there are no more HVAC zones */
arrHVACZones = malloc(nTheZon * sizeof(char*));
if (arrHVACZones == NULL){
SpawnFormatError("%s", "Failed to allocate array for arrHVACZones.");
}
for(i = 0; i < nTheZon; i++)
arrHVACZones[i] = NULL;
/* Build set of names of all HVACZones */

for(i=0; i < bui->nExcObj; i++){
if ( ptrSpaObj[i]->objectType == THERMALZONE ) {
/* Check if we already have this HVACZone */
recorded = false;
for(k = 0; k < i; k++){
if ( ptrSpaObj[k]->objectType == THERMALZONE ){
if (strcmp(ptrSpaObj[i]->hvacZone, ptrSpaObj[k]->hvacZone) == 0){
/* Had the zone already */
recorded = true;
}
}
}
if (!recorded){
arrHVACZones[nHVACZones] = ptrSpaObj[i]->hvacZone;
nHVACZones++;
}
}
}
/* Create a size_t array with the number of thermal zones in each HVACZone.
This is used to avoid the comma after the last thermal zone. */
couTheZon = malloc(nHVACZones * sizeof(size_t));
if (couTheZon == NULL){
SpawnFormatError("%s", "Failed to allocate array for couTheZon.");
}

for(iHVACZones = 0; iHVACZones < nHVACZones; iHVACZones++){
couTheZon[iHVACZones] = 0;
for(i = 0; i < bui->nExcObj; i++){
if ( ptrSpaObj[i]->objectType == THERMALZONE ) {
if (strcmp(ptrSpaObj[i]->hvacZone, arrHVACZones[iHVACZones]) == 0){
couTheZon[iHVACZones]++;
}
}
}
}

/* Write the "hvacZones" objects */
saveAppend(buffer, " \"", size, SpawnFormatError);
saveAppend(buffer, "hvacZones", size, SpawnFormatError);
saveAppend(buffer, "\": [\n", size, SpawnFormatError);
/* Write all thermalZones that belong to the hvacZone */
for(iHVACZones = 0; iHVACZones < nHVACZones; iHVACZones++){
openJSONModelBracket(buffer, 3, size, SpawnFormatError);
buildJSONKeyStringValue(buffer, 4, "name", arrHVACZones[iHVACZones], true, size, SpawnFormatError);
saveAppend(buffer, " \"zones\": [\n", size, SpawnFormatError);

for(i = 0, iWri = 0; i < bui->nExcObj; i++){
if ( ptrSpaObj[i]->objectType == THERMALZONE ) {
/* Check if this thermal zone belongs to the HVACZone */
if (strcmp(ptrSpaObj[i]->hvacZone, arrHVACZones[iHVACZones]) == 0){
/* Found a match */
openJSONModelBracket(buffer, 6, size, SpawnFormatError);
buildJSONKeyStringValue(buffer, 6, "name", ptrSpaObj[i]->epName, false, size, SpawnFormatError);
closeJSONModelBracket(buffer, 6, iWri, couTheZon[iHVACZones], size, SpawnFormatError);
iWri++;
}
}
}
/* We are done iterating over all objects, close the array */
closeJSONModelArrayBracket(buffer, 5, 0, 0, size, SpawnFormatError);
closeJSONModelBracket(buffer, 3, iHVACZones, nHVACZones, size, SpawnFormatError);
}
closeJSONModelArrayBracket(buffer, 2, iMod, nMod, size, SpawnFormatError);
free(arrHVACZones);
}

void buildJSONModelStructureForEnergyPlus(
const FMUBuilding* bui, char* *buffer, size_t* size, char** modelHash){
size_t i;
Expand Down Expand Up @@ -154,6 +263,16 @@ void buildJSONModelStructureForEnergyPlus(
/* weather file */
buildJSONKeyStringValue(buffer, 2, "weather", bui->weather, true, size, SpawnFormatError);

/* Flag to request HVAC autosizing */
if (bui->autosizeHVAC) {
buildJSONKeyLiteralValue(buffer, 2, "autosize", "true", true, size, SpawnFormatError);
buildJSONKeyLiteralValue(buffer, 2, "runSimulationForSizingPeriods", bui->use_sizingPeriods ? "true": "false", true, size, SpawnFormatError);
}
else{
buildJSONKeyLiteralValue(buffer, 2, "autosize", "false", true, size, SpawnFormatError);
buildJSONKeyLiteralValue(buffer, 2, "runSimulationForSizingPeriods", "false", true, size, SpawnFormatError);
}

/* Tolerance of solver for surface heat balance */
buildJSONKeyDoubleValue(buffer, 2, "relativeSurfaceTolerance", bui->relativeSurfaceTolerance,
false, size, SpawnFormatError);
Expand Down Expand Up @@ -191,22 +310,29 @@ void buildJSONModelStructureForEnergyPlus(
saveAppend(buffer, "\": [\n", size, SpawnFormatError);
}
/* Write content */
openJSONModelBracket(buffer, size, SpawnFormatError);
openJSONModelBracket(buffer, 3, size, SpawnFormatError);
saveAppend(buffer, ptrSpaObj[i]->jsonKeysValues, size, SpawnFormatError);
saveAppend(buffer, "\n", size, SpawnFormatError);
closeJSONModelBracket(buffer, iWri, objectCount[objectType], size, SpawnFormatError);
closeJSONModelBracket(buffer, 3, iWri, objectCount[objectType], size, SpawnFormatError);
iWri++;
}
}

iMod += iWri;
if (iWri > 0)
closeJSONModelArrayBracket(buffer, iMod, nMod, size, SpawnFormatError);
if (iWri > 0){
closeJSONModelArrayBracket(buffer, 2, iMod, (objectType == 0) ? 0 : nMod, size, SpawnFormatError);
}

/* After the first object type, which is "zones", we also write the "hvacZones". */
if (objectType == 0){
buildJSONModelStructureForEnergyPlusHVACZones(bui, buffer, iWri, bui->nExcObj, size);
}
}

/* Close json object for model */
saveAppend(buffer, " },\n", size, SpawnFormatError);

/* Create the model hash */
*modelHash = (char*)( cryptographicsHash(*buffer, bui->SpawnError) );

/* fmu */
Expand Down Expand Up @@ -258,7 +384,7 @@ void writeModelStructureForEnergyPlus(const FMUBuilding* bui, char** modelicaBui
SpawnFormatError("Failed to open '%s' with write mode.", *modelicaBuildingsJsonFile);
fprintf(fp, "%s", buffer);
fclose(fp);
}
}

void setAttributesReal(
FMUBuilding* bui,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ size_t AllocateBuildingDataStructure(
const char* idfVersion,
const char* idfName,
const char* epwName,
const int autosizeHVAC,
const int use_sizingPeriods,
const runPeriod* runPer,
double relativeSurfaceTolerance,
int usePrecompiledFMU,
Expand Down Expand Up @@ -140,6 +142,9 @@ size_t AllocateBuildingDataStructure(
SpawnFormatError);
strcpy(Buildings_FMUS[nFMU]->weather, epwName);

/* Set flag for autosizing HVAC */
Buildings_FMUS[nFMU]->autosizeHVAC = autosizeHVAC;
Buildings_FMUS[nFMU]->use_sizingPeriods = use_sizingPeriods;
/* Assign the RunPeriod object */
Buildings_FMUS[nFMU]->runPer = malloc(sizeof(runPeriod));
if ( Buildings_FMUS[nFMU]->runPer == NULL )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ size_t getBuildings_nFMU();
size_t AllocateBuildingDataStructure(
double startTime,
const char* modelicaNameBuilding,
const char* idfName,
const char* epwName,
const char* spawnExe,
const char* idfVersion,
const char* idfName,
const char* epwName,
const int autosizeHVAC,
const int use_sizingPeriods,
const runPeriod* runPer,
double relativeSurfaceTolerance,
int usePrecompiledFMU,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,12 @@ void* allocate_Spawn_EnergyPlus_24_2_0(
const char* idfVersion,
const char* idfName,
const char* epwName,
const char* epName,
const char* hvacZone,
const int autosizeHVAC,
const int use_sizingPeriods,
const runPeriod* runPer,
double relativeSurfaceTolerance,
const char* epName,
int usePrecompiledFMU,
const char* fmuName,
const char* buildingsRootFileLocation,
Expand Down Expand Up @@ -200,6 +203,22 @@ void* allocate_Spawn_EnergyPlus_24_2_0(
SpawnFormatError);
strcpy(ptrSpaObj->modelicaName, modelicaName);

/* Assign the EnergyPlus instance name */
mallocString(
strlen(epName)+1,
"Not enough memory in allocate_Spawn_EnergyPlus_9_6_0.c. to allocate EnergyPlus instance name.",
&(ptrSpaObj->epName),
SpawnFormatError);
strcpy(ptrSpaObj->epName, epName);

/* Assign the HVAC zone name */
mallocString(
strlen(hvacZone)+1,
"Not enough memory in allocate_Spawn_EnergyPlus_9_6_0.c. to allocate HVAC zone name.",
&(ptrSpaObj->hvacZone),
SpawnFormatError);
strcpy(ptrSpaObj->hvacZone, hvacZone);

/* Assign the json name */
mallocString(
strlen(jsonName)+1,
Expand Down Expand Up @@ -326,6 +345,8 @@ void* allocate_Spawn_EnergyPlus_24_2_0(
idfVersion,
idfName,
epwName,
autosizeHVAC,
use_sizingPeriods,
runPer,
relativeSurfaceTolerance,
usePrecompiledFMU,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ LBNL_Spawn_EXPORT void* allocate_Spawn_EnergyPlus_24_2_0(
const char* idfVersion,
const char* idfName,
const char* epwName,
const char* epName,
const char* hvacZone,
const int autosizeHVAC,
const int use_sizingPeriods,
const runPeriod* runPer,
double relativeSurfaceTolerance,
const char* epName,
int usePrecompiledFMU,
const char* fmuName,
const char* buildingsRootFileLocation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ typedef struct FMUBuilding
char* idfVersion; /* IDF version with underscores, such as 24_2_0. This must be the same as is used as suffix for Buildings.ThermalZones.EnergyPlus_ */
fmi2Byte* idfName; /* if usePrecompiledFMU == true, the user-specified fmu name, else the idf name */
fmi2Byte* weather;
bool autosizeHVAC; /* If true, EnergyPlus is requested to run the HVAC sizing calculations */
bool use_sizingPeriods; /* If true, run HVAC sizing calculations on all the included SizingPeriod objects in the idf file */
runPeriod* runPer; /* EnergyPlus RunPeriod */
double relativeSurfaceTolerance; /* Relative surface tolerance for heat balance calculations */
size_t nExcObj; /* Number of exc that use this FMU */
Expand Down Expand Up @@ -135,7 +137,8 @@ typedef struct SpawnObject
int objectType; /* Type of the EnergyPlus object */
FMUBuilding* bui; /* Pointer to building with this zone */
char* modelicaName; /* Name of the Modelica instance of this zone */

char* epName; /* Name of the EnergyPlus instance in the idf file */
char* hvacZone; /* Name of the HVAC zone that this room belongs to. For other objects, this will be "n/a". */
char* jsonName; /* Name of the json keyword */
char* jsonKeysValues; /* Keys and values string to be written to the json configuration file */
char** parOutNames;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# build_type is either custom or builds
spawn_dists = [
{"version": "0.6.0",
"commit": "9f1b36b00b",
"commit": "5297abe3fb",
"build_type": "custom"}
]
###########################################################################
Expand Down
Loading