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

Introduce flag --zeroNominal #1018

Merged
merged 1 commit into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions src/OMSimulatorLib/Flags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ void oms::Flags::setDefaults()
timeout = 0.0;
tolerance = 1e-4;
wallTime = false;
zeroNominal = false;
}

oms::Flags& oms::Flags::GetInstance()
Expand Down Expand Up @@ -450,3 +451,9 @@ oms_status_enu_t oms::Flags::WallTime(const std::string& value)
GetInstance().wallTime = (value == "true");
return oms_status_ok;
}

oms_status_enu_t oms::Flags::ZeroNominal(const std::string& value)
{
GetInstance().zeroNominal = (value == "true");
return oms_status_ok;
}
10 changes: 7 additions & 3 deletions src/OMSimulatorLib/Flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ namespace oms
public:
static oms_status_enu_t SetCommandLineOption(const std::string& cmd);

static oms_alg_solver_enu_t AlgLoopSolver() {return GetInstance().algLoopSolver;}
static bool AddParametersToCSV() {return GetInstance().addParametersToCSV;}
static bool DefaultModeIsCS() {return GetInstance().defaultModeIsCS;}
static bool DeleteTempFiles() {return GetInstance().deleteTempFiles;}
Expand All @@ -70,10 +69,12 @@ namespace oms
static bool StripRoot() {return GetInstance().stripRoot;}
static bool SuppressPath() {return GetInstance().suppressPath;}
static bool WallTime() {return GetInstance().wallTime;}
static bool ZeroNominal() {return GetInstance().zeroNominal;}
static double StartTime() {return GetInstance().startTime;}
static double StopTime() {return GetInstance().stopTime;}
static double Timeout() {return GetInstance().timeout;}
static double Tolerance() {return GetInstance().tolerance;}
static oms_alg_solver_enu_t AlgLoopSolver() {return GetInstance().algLoopSolver;}
static oms_solver_enu_t MasterAlgorithm() {return GetInstance().masterAlgorithm;}
static oms_solver_enu_t Solver() {return GetInstance().solver;}
static std::string ResultFile() {return GetInstance().resultFile;}
Expand All @@ -84,7 +85,6 @@ namespace oms

private:
bool addParametersToCSV;
oms_alg_solver_enu_t algLoopSolver;
bool defaultModeIsCS;
bool deleteTempFiles;
bool emitEvents;
Expand All @@ -98,10 +98,12 @@ namespace oms
bool stripRoot;
bool suppressPath;
bool wallTime;
bool zeroNominal;
double startTime;
double stopTime;
double timeout;
double tolerance;
oms_alg_solver_enu_t algLoopSolver;
oms_solver_enu_t masterAlgorithm;
oms_solver_enu_t solver;
std::string resultFile;
Expand Down Expand Up @@ -167,7 +169,8 @@ namespace oms
{"--tolerance", "", "Specifies the relative tolerance", re_double, Flags::Tolerance, false},
{"--version", "-v", "Displays version information", re_void, Flags::Version, false},
{"--wallTime", "", "Add wall time information for to the result file (true, [false])", re_bool, Flags::WallTime, false},
{"--workingDir", "", "Specifies the working directory", re_default, Flags::WorkingDir, false}
{"--workingDir", "", "Specifies the working directory", re_default, Flags::WorkingDir, false},
{"--zeroNominal", "", "Using this flag, FMUs with invalid nominal values will be accepted and the invalid nominal values will be replaced with 1.0", re_bool, Flags::ZeroNominal, false}
};

static oms_status_enu_t AddParametersToCSV(const std::string& value);
Expand Down Expand Up @@ -205,6 +208,7 @@ namespace oms
static oms_status_enu_t Version(const std::string& value);
static oms_status_enu_t WallTime(const std::string& value);
static oms_status_enu_t WorkingDir(const std::string& value);
static oms_status_enu_t ZeroNominal(const std::string& value);
};
}

Expand Down
20 changes: 12 additions & 8 deletions src/OMSimulatorLib/SystemSC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ oms_status_enu_t oms::SystemSC::initialize()
{
clock.reset();
CallClock callClock(clock);
bool illegalNominals = false;

if (oms_status_ok != updateDependencyGraphs())
return oms_status_error;
Expand Down Expand Up @@ -257,13 +256,22 @@ oms_status_enu_t oms::SystemSC::initialize()
if (oms_status_ok != status) return status;
status = fmus[i]->getNominalsOfContinuousStates(states_nominal[i]);
if (oms_status_ok != status) return status;

// Check if nominals are greater 0
bool illegalNominals = false;
for(int l=0; l<nStates[i]; l++)
{
if (states_nominal[i][l]<= 0)
if (states_nominal[i][l] <= 0)
{
illegalNominals = true;
logError(std::string(fmus[i]->getFullCref()) + ": nominal[" + std::to_string(l) + "]=" + std::to_string(states_nominal[i][l]) + " not greater than zero.");
if (Flags::ZeroNominal())
{
if (!illegalNominals)
logWarning(std::string(fmus[i]->getFullCref()) + ": Illegal nominal value will be replaced with 1.0 because the flag --zeroNominal is used");
illegalNominals = true;
states_nominal[i][l] = 1.0;
}
else
return logError(std::string(fmus[i]->getFullCref()) + ": Illegal nominal value provided by the FMU.");
}
}
}
Expand All @@ -273,10 +281,6 @@ oms_status_enu_t oms::SystemSC::initialize()
if (oms_status_ok != status) return status;
}
}
if(illegalNominals)
{
return oms_status_error;
}

if (oms_solver_sc_cvode == solverMethod)
{
Expand Down