Skip to content

Commit

Permalink
update ExternalInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarrec committed Jul 23, 2024
1 parent 16e1ba3 commit 83d7cf3
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions src/EnergyPlus/ExternalInterface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ void CloseSocket(EnergyPlusData &state, int const FlagToWriteToSocket)
bool fileExist = FileSystem::fileExists(state.dataExternalInterface->socCfgFilPath);

if ((state.dataExternalInterface->socketFD == -1) && fileExist) {
state.dataExternalInterface->socketFD = establishclientsocket(state.dataExternalInterface->socCfgFilPath.string().c_str());
state.dataExternalInterface->socketFD = establishclientsocket(FileSystem::toString(state.dataExternalInterface->socCfgFilPath).c_str());
}

if (state.dataExternalInterface->socketFD >= 0) {
Expand Down Expand Up @@ -398,14 +398,14 @@ void InitExternalInterface(EnergyPlusData &state)

// Get port number
if (FileSystem::fileExists(state.dataExternalInterface->socCfgFilPath)) {
state.dataExternalInterface->socketFD = establishclientsocket(state.dataExternalInterface->socCfgFilPath.string().c_str());
state.dataExternalInterface->socketFD = establishclientsocket(FileSystem::toString(state.dataExternalInterface->socCfgFilPath).c_str());
if (state.dataExternalInterface->socketFD < 0) {
ShowSevereError(state,
format("ExternalInterface: Could not open socket. File descriptor = {}.", state.dataExternalInterface->socketFD));
state.dataExternalInterface->ErrorsFound = true;
}
} else {
ShowSevereError(state, format("ExternalInterface: Did not find file \"{}\".", state.dataExternalInterface->socCfgFilPath.string()));
ShowSevereError(state, format("ExternalInterface: Did not find file \"{}\".", state.dataExternalInterface->socCfgFilPath));
ShowContinueError(state, "This file needs to be in same directory as in.idf.");
ShowContinueError(state, "Check the documentation for the ExternalInterface.");
state.dataExternalInterface->ErrorsFound = true;
Expand Down Expand Up @@ -833,7 +833,7 @@ void InstantiateInitializeFMUImport(EnergyPlusData &state)
// Instantiate FMUs
for (int i = 1; i <= state.dataExternalInterface->NumFMUObjects; ++i) {
for (int j = 1; j <= state.dataExternalInterface->FMU(i).NumInstances; ++j) {
std::string const &folderStr = state.dataExternalInterface->FMU(i).Instance(j).WorkingFolder.string();
std::string const folderStr = FileSystem::toString(state.dataExternalInterface->FMU(i).Instance(j).WorkingFolder);
state.dataExternalInterface->FMU(i).Instance(j).fmicomponent =
fmiEPlusInstantiateSlave((char *)folderStr.c_str(),
&state.dataExternalInterface->FMU(i).Instance(j).LenWorkingFolder,
Expand Down Expand Up @@ -1024,7 +1024,7 @@ void InitExternalInterfaceFMUImport(EnergyPlusData &state)
strippedFileName(Loop) = state.dataExternalInterface->FMU(Loop).Name;
}
}
fullFileName(Loop) = tempFullFilePath.string();
fullFileName(Loop) = FileSystem::toString(tempFullFilePath);
} else {
state.dataExternalInterface->ErrorsFound = true;
}
Expand Down Expand Up @@ -1132,14 +1132,13 @@ void InitExternalInterfaceFMUImport(EnergyPlusData &state)
for (int i = 1; i <= state.dataExternalInterface->NumFMUObjects; ++i) {
for (int j = 1; j <= state.dataExternalInterface->FMU(i).NumInstances; ++j) {
// get the length of working folder trimmed
state.dataExternalInterface->FMU(i).Instance(j).LenWorkingFolder =
state.dataExternalInterface->FMU(i).Instance(j).WorkingFolder.string().length();
std::string const workingFolderStr = FileSystem::toString(state.dataExternalInterface->FMU(i).Instance(j).WorkingFolder);
state.dataExternalInterface->FMU(i).Instance(j).LenWorkingFolder = workingFolderStr.length();
// unpack fmus
// preprocess arguments for library call
{
std::vector<char> fullFileNameArr(getCharArrayFromString(fullFileName(i)));
std::vector<char> workingFolderArr(
getCharArrayFromString(state.dataExternalInterface->FMU(i).Instance(j).WorkingFolder.string()));
std::vector<char> workingFolderArr(getCharArrayFromString(workingFolderStr));
int lenFileName(len(fullFileName(i)));

// make the library call
Expand All @@ -1158,8 +1157,7 @@ void InitExternalInterfaceFMUImport(EnergyPlusData &state)
{
// determine modelID and modelGUID of all FMU instances
// preprocess arguments for library call
std::vector<char> workingFolderArr(
getCharArrayFromString(state.dataExternalInterface->FMU(i).Instance(j).WorkingFolder.string()));
std::vector<char> workingFolderArr(getCharArrayFromString(workingFolderStr));

// make the library call
state.dataExternalInterface->FMU(i).Instance(j).Index =
Expand All @@ -1185,13 +1183,12 @@ void InitExternalInterfaceFMUImport(EnergyPlusData &state)
{
// get the path to the binaries
// preprocess args for library call
std::vector<char> workingFolderArr(
getCharArrayFromString(state.dataExternalInterface->FMU(i).Instance(j).WorkingFolder.string()));
std::vector<char> workingFolderArr(getCharArrayFromString(workingFolderStr));
// Reserve some space in the string, becasue addLibPathCurrentWorkflowFolder doesn't allocate memory for the
// workingFolderWithLibArr Note: you can't call str.resize(str.length() + 91) because the conversion to std::vector<char> will
// find the null terminator and so it will have no effect
std::string reservedString = state.dataExternalInterface->FMU(i).Instance(j).WorkingFolder.string() +
" ";
std::string reservedString =
workingFolderStr + " ";
std::vector<char> workingFolderWithLibArr(getCharArrayFromString(reservedString));

// make the library call
Expand All @@ -1218,14 +1215,14 @@ void InitExternalInterfaceFMUImport(EnergyPlusData &state)

// get the length of the working folder with libraries
state.dataExternalInterface->FMU(i).Instance(j).LenWorkingFolder_wLib =
state.dataExternalInterface->FMU(i).Instance(j).WorkingFolder_wLib.string().length();
FileSystem::toString(state.dataExternalInterface->FMU(i).Instance(j).WorkingFolder_wLib).length();
}

{
// determine the FMI version
// preprocess args for library call
std::vector<char> workingFolderWithLibArr(
getCharArrayFromString(state.dataExternalInterface->FMU(i).Instance(j).WorkingFolder_wLib.string()));
getCharArrayFromString(FileSystem::toString(state.dataExternalInterface->FMU(i).Instance(j).WorkingFolder_wLib)));
std::vector<char> VersionNumArr(
getCharArrayFromString(" ")); // the version should only be 3 characters long, since for now we only handle "1.0"

Expand Down

2 comments on commit 83d7cf3

@nrel-bot
Copy link

Choose a reason for hiding this comment

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

10487_Windows_NonASCII_paths (jmarrec) - Win64-Windows-10-VisualStudio-16: OK (2852 of 2852 tests passed, 0 test warnings)

Build Badge Test Badge

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

10487_Windows_NonASCII_paths (jmarrec) - x86_64-MacOS-10.18-clang-15.0.0: OK (3644 of 3644 tests passed, 0 test warnings)

Build Badge Test Badge

Please sign in to comment.