Skip to content

Commit

Permalink
Always write a complete results file with Cpp runtime
Browse files Browse the repository at this point in the history
This simplifies the analysis of initialization errors
and it works around crashes of OMEdit,
see issue #8008 (OMEdit crashes if a simulation fails or is canceled).

- SimManager.cpp: write out values after initialization,
  also in case of failure for the analysis of intermediate results
- SolverDefaultImplementation: decouple writing of variable names
  from initialization of solver. Write them before first values instead.
  • Loading branch information
rfranke committed Oct 19, 2021
1 parent 3fe9493 commit ee62d1d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
Expand Up @@ -124,6 +124,7 @@ void SimManager::initialize()
// Reset debug ID
_dbgId = 0;

_solver->setStartTime(_tStart);
try
{
// Build up system and update once
Expand All @@ -133,10 +134,13 @@ void SimManager::initialize()
{
LOGGER_WRITE("SimManager: Could not initialize system", LC_INIT, LL_ERROR);
LOGGER_WRITE("SimManager: " + string(ex.what()), LC_INIT, LL_ERROR);
//ex << error_id(SIMMANAGER);
// Write current values as they might help to analyse the error
_solver->solve(ISolver::RECORDCALL);
throw ModelicaSimulationError(SIMMANAGER, "Could not initialize system",
string(ex.what()), LOGGER_IS_SET(LC_INIT, LL_ERROR));
}
// Write initial values
_solver->solve(ISolver::RECORDCALL);

if (_timeevent_system)
{
Expand Down
Expand Up @@ -42,6 +42,7 @@ SolverDefaultImplementation::SolverDefaultImplementation(IMixedSystem* system, I
, _events (NULL)
, _solverStatus (ISolver::UNDEF_STATUS)
, _outputCommand (IWriteOutput::WRITEOUT)
, _writeoutput_system (NULL)
{
_state_selection = shared_ptr<SystemStateSelection>(new SystemStateSelection(system));

Expand Down Expand Up @@ -114,14 +115,10 @@ void SolverDefaultImplementation::initialize()
IContinuous* continous_system = dynamic_cast<IContinuous*>(_system);
IEvent* event_system = dynamic_cast<IEvent*>(_system);
ITime* timeevent_system = dynamic_cast<ITime*>(_system);
IWriteOutput* writeoutput_system = dynamic_cast<IWriteOutput*>(_system);

// Set current start time to the system
timeevent_system->setTime(_tCurrent);


if(_settings->getGlobalSettings()->getOutputPointType() != OPT_NONE)
writeoutput_system->writeOutput(IWriteOutput::HEAD_LINE);

// Allocate array with values of zero functions
if (_dimZeroFunc != event_system->getDimZeroFunc())
{
Expand Down Expand Up @@ -202,14 +199,18 @@ void SolverDefaultImplementation::writeToFile(const int& stp, const double& t, c

LOGGER_STATUS("Running", t, h);

if(_settings->getGlobalSettings()->getOutputPointType()!= OPT_NONE)
if (_settings->getGlobalSettings()->getOutputPointType() != OPT_NONE)
{
IWriteOutput* writeoutput_system = dynamic_cast<IWriteOutput*>(_system);

if(_outputCommand & IWriteOutput::WRITEOUT)
// write header on first call
if (_writeoutput_system == NULL)
{
writeoutput_system->writeOutput(_outputCommand);

_writeoutput_system = dynamic_cast<IWriteOutput*>(_system);
_writeoutput_system->writeOutput(IWriteOutput::HEAD_LINE);
}
// write values
if (_outputCommand & IWriteOutput::WRITEOUT)
{
_writeoutput_system->writeOutput(_outputCommand);
}
}
checkTimeout();
Expand Down
Expand Up @@ -113,6 +113,9 @@ class BOOST_EXTENSION_SOLVER_DECL SolverDefaultImplementation : public Simulatio
IWriteOutput::OUTPUT
_outputCommand; ///< Controls the output

IWriteOutput
*_writeoutput_system;

private:
/// Definition of signum function
inline static int sgn (const double &c)
Expand Down

0 comments on commit ee62d1d

Please sign in to comment.