Skip to content

Commit

Permalink
Issue2852 spawn multiplier (#3031)
Browse files Browse the repository at this point in the history
* Updated Spawn for #2852

* Fixed typo in comment

* Corrected call to fmi2_import_terminate

The function fmi2_import_terminate must only be called in event mode or continuous time mode
  • Loading branch information
mwetter committed May 23, 2022
1 parent b90fe0c commit ba368a0
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 26 deletions.
Git LFS file not shown
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.3.0-59ed8c72e4", "linux64")),
{"src": os.path.abspath(os.path.join("Buildings", "Resources", "bin", "spawn-0.3.0-0fa49be497", "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 @@ -790,8 +790,12 @@ void importSpawnFMU(FMUBuilding* bui){
if(jm_status == jm_status_error){
SpawnFormatError("Failed to instantiate building FMU with name %s.", bui->modelicaNameBuilding);
}
/* Set the FMU mode to instantiationMode */
setFMUMode(bui, instantiationMode);

/* Set the debug level in the FMU */
setFMUDebugLevel(bui);

}

void setReusableFMU(FMUBuilding* bui){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,10 @@ void FMUBuildingFree(FMUBuilding* bui){
}

/* The call to fmi2_import_terminate causes a seg fault if
fmi2_import_create_dllfmu was not successful */
if (bui->dllfmu_created){
fmi2_import_create_dllfmu was not successful.
Also, per the FMI specification, fmi2_import_terminate must only be called in continuous time mode or event mode */
if (bui->dllfmu_created &&
((bui->mode == continuousTimeMode) || (bui->mode == eventMode)) ){
if (bui->logLevel >= MEDIUM)
SpawnFormatMessage("%.3f %s: Calling fmi2_import_terminate to terminate EnergyPlus.\n", bui->time, bui->modelicaNameBuilding);
status = fmi2_import_terminate(bui->fmu);
Expand All @@ -293,6 +295,7 @@ void FMUBuildingFree(FMUBuilding* bui){
bui->time, bui->modelicaNameBuilding,
fmi2_status_to_string(status));
}
setFMUMode(bui, terminatedMode);
}
if (bui->fmu != NULL){
if (bui->logLevel >= MEDIUM)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void free_Spawn_EnergyPlus_9_6_0(void* object){
if ( object != NULL ){
SpawnObject* ptrSpaObj = (SpawnObject*) object;

/* The building may not have been instanciated yet if there was an error during instantiation */
/* The building may not have been instantiated yet if there was an error during instantiation */
if (ptrSpaObj->bui != NULL){
ptrSpaObj->bui->nExcObj--;
FMUBuildingFree(ptrSpaObj->bui);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ to not export all symbols but only the needed ones */
#define SEPARATOR "/"
#endif

typedef enum {instantiationMode, initializationMode, eventMode, continuousTimeMode} FMUMode;
typedef enum {instantiationMode, initializationMode, eventMode, continuousTimeMode, terminatedMode} FMUMode;

enum logLevels {ERRORS = 1, WARNINGS = 2, QUIET = 3, MEDIUM = 4, TIMESTEP = 5};
enum objectTypes {THERMALZONE = 1, SCHEDULE = 2, ACTUATOR = 3, OUTPUT = 4, SURFACE = 5, DETAILEDSURFACE = 6};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ char* fmuModeToString(FMUMode mode){
return "event";
if (mode == continuousTimeMode)
return "continuous";
if (mode == terminatedMode)
return "terminated";
return "unknown mode for FMU";
}

Expand Down Expand Up @@ -737,8 +739,6 @@ void loadFMU_setupExperiment_enterInitializationMode(FMUBuilding* bui, double st
if (bui->logLevel >= MEDIUM)
SpawnFormatMessage("%.3f %s: Instantiate building.\n", bui->time, modelicaInstanceName);

setFMUMode(bui, instantiationMode);

/* This function can only be called once per building FMU */
if (bui->logLevel >= MEDIUM)
SpawnFormatMessage("%.3f %s: Calling fmi2_import_setup_experiment: Setting up experiment building at %p with startTime = %f.\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# by the Buildings library
spawn_dists = [
{"version": "0.3.0",
"commit": "59ed8c72e47b646e71a3c4d1add8946968a333b2"}
"commit": "0fa49be49715a5acc87f078ba583e369d435cdf9"}
]
###########################################################################

Expand Down
4 changes: 2 additions & 2 deletions Buildings/ThermalZones/EnergyPlus_9_6_0/Building.mo
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ model Building
"Model that declares a building to which EnergyPlus objects belong to"
extends Modelica.Blocks.Icons.Block;

constant String spawnExe="spawn-0.3.0-59ed8c72e4"
"Name of the spawn executable, without extension, such as spawn-0.3.0-59ed8c72e4aaa"
constant String spawnExe="spawn-0.3.0-0fa49be497"
"Name of the spawn executable, without extension, such as spawn-0.3.0-0fa49be497aaa"
annotation (HideResult=true);

constant String idfVersion = "9_6_0"
Expand Down
28 changes: 14 additions & 14 deletions Buildings/ThermalZones/EnergyPlus_9_6_0/UsersGuide.mo
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ the binaries can be downloaded from the following links:
</tr>
<tr>
<td>Linux</td>
<td><a href=\"https://spawn.s3.amazonaws.com/builds/Spawn-light-0.3.0-59ed8c72e4-Linux.tar.gz\">
https://spawn.s3.amazonaws.com/builds/Spawn-light-0.3.0-59ed8c72e4-Linux.tar.gz</a>
<td><a href=\"https://spawn.s3.amazonaws.com/builds/Spawn-light-0.3.0-0fa49be497-Linux.tar.gz\">
https://spawn.s3.amazonaws.com/builds/Spawn-light-0.3.0-0fa49be497-Linux.tar.gz</a>
</td>
</tr>
<tr>
<td>Windows</td>
<td><a href=\"https://spawn.s3.amazonaws.com/builds/Spawn-light-0.3.0-59ed8c72e4-win64.zip\">
https://spawn.s3.amazonaws.com/builds/Spawn-light-0.3.0-59ed8c72e4-win64.zip</a>
<td><a href=\"https://spawn.s3.amazonaws.com/builds/Spawn-light-0.3.0-0fa49be497-win64.zip\">
https://spawn.s3.amazonaws.com/builds/Spawn-light-0.3.0-0fa49be497-win64.zip</a>
</td>
</tr>
</table>
Expand All @@ -51,9 +51,9 @@ To install, proceed as follows:
Run from a terminal
</p>
<pre>
wget https://spawn.s3.amazonaws.com/builds/Spawn-light-0.3.0-59ed8c72e4-Linux.tar.gz;
tar xzf Spawn-light-0.3.0-59ed8c72e4-Linux.tar.gz;
export PATH=${PATH}:`pwd`/Spawn-light-0.3.0-59ed8c72e4-Linux/bin
wget https://spawn.s3.amazonaws.com/builds/Spawn-light-0.3.0-0fa49be497-Linux.tar.gz;
tar xzf Spawn-light-0.3.0-0fa49be497-Linux.tar.gz;
export PATH=${PATH}:`pwd`/Spawn-light-0.3.0-0fa49be497-Linux/bin
</pre>
<p>
and restart your Modelica environment. You may put the last line in your <code>${HOME}/.bashrc</code> file
Expand All @@ -69,10 +69,10 @@ to make the setting persistent when you log in the next time.
Download the binary from the link above.
</li>
<li>
Unzip <code>Spawn-light-0.3.0-59ed8c72e4-win64.zip</code> at your desired location.
Unzip <code>Spawn-light-0.3.0-0fa49be497-win64.zip</code> at your desired location.
</li>
<li>
Add the directory <code>xyz/Spawn-light-0.3.0-59ed8c72e4-win64/bin</code>
Add the directory <code>xyz/Spawn-light-0.3.0-0fa49be497-win64/bin</code>
to your <code>PATH</code> environment variable.
</li>
<li>
Expand All @@ -85,29 +85,29 @@ Restart your Modelica environment.
<h4>How is spawn invoked?</h4>
<p>
Modelica tries to invoke <code>spawn-0.3.0-59ed8c72e4[.exe]</code> in this order:
Modelica tries to invoke <code>spawn-0.3.0-0fa49be497[.exe]</code> in this order:
</p>
<ol>
<li>
On Linux, it searches for
<pre>
Buildings[ x.y.z]/Resources/bin/spawn-0.3.0-59ed8c72e4/linux64/bin/spawn-0.3.0-59ed8c72e4
Buildings[ x.y.z]/Resources/bin/spawn-0.3.0-0fa49be497/linux64/bin/spawn-0.3.0-0fa49be497
</pre>
and on Windows, it searches for
<pre>
Buildings[ x.y.z]/Resources/bin/spawn-0.3.0-59ed8c72e4/win64/bin/spawn-0.3.0-59ed8c72e4.exe
Buildings[ x.y.z]/Resources/bin/spawn-0.3.0-0fa49be497/win64/bin/spawn-0.3.0-0fa49be497.exe
</pre>
where <code>Buildings[ x.y.z]</code> is the installation folder of the Modelica Buildings Library.
This file is distributed with the Modelica Buildings Library installation,
together with all files needed to translate and simulate a model in a Modelica environment.
</li>
<li>
If not found, it searches on the environment variable <code>SPAWNPATH</code> for
<code>spawn-0.3.0-59ed8c72e4[.exe]</code>.
<code>spawn-0.3.0-0fa49be497[.exe]</code>.
</li>
<li>
If not found, it searches on the environment variable <code>PATH</code> for
<code>spawn-0.3.0-59ed8c72e4[.exe]</code>.
<code>spawn-0.3.0-0fa49be497[.exe]</code>.
</li>
</ol>
<p>
Expand Down

0 comments on commit ba368a0

Please sign in to comment.