Exemplo n.º 1
0
static void fmtEmitStep(DATA* data, threadData_t *threadData, MEASURE_TIME* mt, int didEventStep)
{
  if(mt->fmtReal)
  {
    int i, flag=1;
    double tmpdbl;
    unsigned int tmpint;
    int total = data->modelData->modelDataXml.nFunctions + data->modelData->modelDataXml.nProfileBlocks;
    rt_tick(SIM_TIMER_OVERHEAD);
    rt_accumulate(SIM_TIMER_STEP);

    /* Disable time measurements if we have trouble writing to the file... */
    flag = flag && 1 == fwrite(&mt->stepNo, sizeof(unsigned int), 1, mt->fmtInt);
    mt->stepNo++;
    flag = flag && 1 == fwrite(&(data->localData[0]->timeValue), sizeof(double), 1, mt->fmtReal);
    tmpdbl = rt_accumulated(SIM_TIMER_STEP);
    flag = flag && 1 == fwrite(&tmpdbl, sizeof(double), 1, mt->fmtReal);
    flag = flag && total == fwrite(rt_ncall_arr(SIM_TIMER_FIRST_FUNCTION), sizeof(uint32_t), total, mt->fmtInt);
    for(i=0; i<data->modelData->modelDataXml.nFunctions + data->modelData->modelDataXml.nProfileBlocks; i++) {
      tmpdbl = rt_accumulated(i + SIM_TIMER_FIRST_FUNCTION);
      flag = flag && 1 == fwrite(&tmpdbl, sizeof(double), 1, mt->fmtReal);
    }
    rt_accumulate(SIM_TIMER_OVERHEAD);

    if(!flag)
    {
      warningStreamPrint(LOG_SOLVER, 0, "Disabled time measurements because the output file could not be generated: %s", strerror(errno));
      fclose(mt->fmtInt);
      fclose(mt->fmtReal);
      mt->fmtInt = NULL;
      mt->fmtReal = NULL;
    }
  }

  /* prevent emit if noEventEmit flag is used, if it's an event */
  if ((omc_flag[FLAG_NOEVENTEMIT] && didEventStep == 0) || !omc_flag[FLAG_NOEVENTEMIT]) {
    sim_result.emit(&sim_result, data, threadData);
  }
#if !defined(OMC_MINIMAL_RUNTIME)
  embedded_server_update(data->embeddedServerState, data->localData[0]->timeValue);
  if (data->real_time_sync.enabled) {
    double time = data->localData[0]->timeValue;
    int64_t res = rt_ext_tp_sync_nanosec(&data->real_time_sync.clock, (uint64_t) (data->real_time_sync.scaling*(time-data->real_time_sync.time)*1e9));
    int64_t maxLateNano = data->simulationInfo->stepSize*1e9*0.1*data->real_time_sync.scaling /* Maximum late time: 10% of step size */;
    if (res > maxLateNano) {
      int t=0,tMaxLate=0;
      const char *unit = prettyPrintNanoSec(res, &t);
      const char *unit2 = prettyPrintNanoSec(maxLateNano, &tMaxLate);
      errorStreamPrint(LOG_RT, 0, "Missed deadline at time %g; delta was %d %s (maxLate=%d %s)", time, t, unit, tMaxLate, unit2);
    }
    if (res > data->real_time_sync.maxLate) {
      data->real_time_sync.maxLate = res;
    }
  }

  printAllVarsDebug(data, 0, LOG_DEBUG);  /* ??? */
#endif
}
Exemplo n.º 2
0
void csv_emit(simulation_result *self, DATA *data)
{
  FILE *fout = (FILE*) self->storage;
  const char* format = "%.16g,";
  const char* formatint = "%i,";
  const char* formatbool = "%i,";
  const char* formatstring = "\"%s\",";
  int i;
  modelica_real value = 0;
  double cpuTimeValue = 0;
  rt_tick(SIM_TIMER_OUTPUT);

  rt_accumulate(SIM_TIMER_TOTAL);
  cpuTimeValue = rt_accumulated(SIM_TIMER_TOTAL);
  rt_tick(SIM_TIMER_TOTAL);

  fprintf(fout, format, data->localData[0]->timeValue);
  if(self->cpuTime)
    fprintf(fout, format, cpuTimeValue);
  for(i = 0; i < data->modelData.nVariablesReal; i++) if(!data->modelData.realVarsData[i].filterOutput)
    fprintf(fout, format, (data->localData[0])->realVars[i]);
  for(i = 0; i < data->modelData.nVariablesInteger; i++) if(!data->modelData.integerVarsData[i].filterOutput)
    fprintf(fout, formatint, (data->localData[0])->integerVars[i]);
  for(i = 0; i < data->modelData.nVariablesBoolean; i++) if(!data->modelData.booleanVarsData[i].filterOutput)
    fprintf(fout, formatbool, (data->localData[0])->booleanVars[i]);
  for(i = 0; i < data->modelData.nVariablesString; i++) if(!data->modelData.stringVarsData[i].filterOutput)
    fprintf(fout, formatstring, (data->localData[0])->stringVars[i]);

  for(i = 0; i < data->modelData.nAliasReal; i++) if(!data->modelData.realAlias[i].filterOutput) {
    if(data->modelData.realAlias[i].aliasType == 2)
      value = (data->localData[0])->timeValue;
    else
      value = (data->localData[0])->realVars[data->modelData.realAlias[i].nameID];
    if(data->modelData.realAlias[i].negate)
      fprintf(fout, format, -value);
    else
      fprintf(fout, format, value);
  }
  for(i = 0; i < data->modelData.nAliasInteger; i++) if(!data->modelData.integerAlias[i].filterOutput) {
    if(data->modelData.integerAlias[i].negate)
      fprintf(fout, formatint, -(data->localData[0])->integerVars[data->modelData.integerAlias[i].nameID]);
    else
      fprintf(fout, formatint, (data->localData[0])->integerVars[data->modelData.integerAlias[i].nameID]);
  }
  for(i = 0; i < data->modelData.nAliasBoolean; i++) if(!data->modelData.booleanAlias[i].filterOutput) {
    if(data->modelData.booleanAlias[i].negate)
      fprintf(fout, formatbool, (data->localData[0])->booleanVars[data->modelData.booleanAlias[i].nameID]==1?0:1);
    else
      fprintf(fout, formatbool, (data->localData[0])->booleanVars[data->modelData.booleanAlias[i].nameID]);
  }
  for(i = 0; i < data->modelData.nAliasString; i++) if(!data->modelData.stringAlias[i].filterOutput) {
    /* there would no negation of a string happen */
    fprintf(fout, formatstring, (data->localData[0])->stringVars[data->modelData.stringAlias[i].nameID]);
  }
  fprintf(fout, "\n");
  rt_accumulate(SIM_TIMER_OUTPUT);
}
Exemplo n.º 3
0
void omc_csv_free(simulation_result *self, DATA *data)
{
  FILE *fout = (FILE*) self->storage;
  rt_tick(SIM_TIMER_OUTPUT);
  fclose(fout);
  rt_accumulate(SIM_TIMER_OUTPUT);
}
Exemplo n.º 4
0
static int simulationUpdate(DATA* data, threadData_t *threadData, SOLVER_INFO* solverInfo)
{
  prefixedName_updateContinuousSystem(data, threadData);

  if (solverInfo->solverMethod == S_SYM_IMP_EULER) data->callback->symEulerUpdate(data, solverInfo->solverStepSize);

  saveZeroCrossings(data, threadData);
  messageClose(LOG_SOLVER);

  /***** Event handling *****/
  if (measure_time_flag) rt_tick(SIM_TIMER_EVENT);

  int syncRet = handleTimers(data, threadData, solverInfo);
  int syncRet1;
  do
  {
    int eventType = checkEvents(data, threadData, solverInfo->eventLst, &(solverInfo->currentTime), solverInfo);
    if(eventType > 0 || syncRet == 2) /* event */
    {
      threadData->currentErrorStage = ERROR_EVENTHANDLING;
      infoStreamPrint(LOG_EVENTS, 1, "%s event at time=%.12g", eventType == 1 ? "time" : "state", solverInfo->currentTime);
      /* prevent emit if noEventEmit flag is used */
      if (!(omc_flag[FLAG_NOEVENTEMIT])) /* output left limit */
        sim_result.emit(&sim_result, data, threadData);
      handleEvents(data, threadData, solverInfo->eventLst, &(solverInfo->currentTime), solverInfo);
      messageClose(LOG_EVENTS);
      threadData->currentErrorStage = ERROR_SIMULATION;

      solverInfo->didEventStep = 1;
      overwriteOldSimulationData(data);
    }
    else /* no event */
    {
      solverInfo->laststep = solverInfo->currentTime;
      solverInfo->didEventStep = 0;
    }

    if (measure_time_flag) rt_accumulate(SIM_TIMER_EVENT);
    /***** End event handling *****/


    /***** check state selection *****/
    if (stateSelection(data, threadData, 1, 1))
    {
      /* if new set is calculated reinit the solver */
      solverInfo->didEventStep = 1;
      overwriteOldSimulationData(data);
    }

    /* Check for warning of variables out of range assert(min<x || x>xmax, ...)*/
    data->callback->checkForAsserts(data, threadData);

    storePreValues(data);
    storeOldValues(data);

    syncRet1 = handleTimers(data, threadData, solverInfo);
    syncRet = syncRet1 == 0 ? syncRet : syncRet1;
  } while (syncRet1);
  return syncRet;
}
void plt_init(simulation_result *self,DATA *data, threadData_t *threadData)
{
  plt_data *pltData = (plt_data*) malloc(sizeof(plt_data));
  rt_tick(SIM_TIMER_OUTPUT);
  /*
   * Re-Initialization is important because the variables are global and used in every solving step
   */
  pltData->simulationResultData = 0;
  pltData->currentPos = 0;
  pltData->actualPoints = 0; /* the number of actual points saved */
  pltData->dataSize = 0;
  pltData->maxPoints = self->numpoints;

  assertStreamPrint(threadData, self->numpoints >= 0, "Automatic output steps not supported in OpenModelica yet. Set numpoints >= 0.");

  pltData->num_vars = calcDataSize(self,data->modelData);
  pltData->dataSize = calcDataSize(self,data->modelData);
  pltData->simulationResultData = (double*)malloc(self->numpoints * pltData->dataSize * sizeof(double));
  if(!pltData->simulationResultData) {
    throwStreamPrint(threadData, "Error allocating simulation result data of size %ld failed",self->numpoints * pltData->dataSize);
  }
  pltData->currentPos = 0;
  self->storage = pltData;
  rt_accumulate(SIM_TIMER_OUTPUT);
}
Exemplo n.º 6
0
void mat4_free(simulation_result *self,DATA *data)
{
    mat_data *matData = (mat_data*) self->storage;
    rt_tick(SIM_TIMER_OUTPUT);
    /* this is a bad programming practice - closing file in destructor,
     * where a proper error reporting can't be done
     * It's ok now; it's not even C++ code :D
     */
    if(matData->fp)
    {
        try
        {
            matData->fp.seekp(matData->data2HdrPos);
            writeMatVer4MatrixHeader(self,data,"data_2", matData->r_indx_map.size() + matData->i_indx_map.size() + matData->b_indx_map.size() + matData->negatedboolaliases + 1 /* add one more for timeValue*/ + self->cpuTime, matData->ntimepoints, sizeof(double));
            matData->fp.close();
        }
        catch (...)
        {
            /* just ignore, we are in destructor */
        }
    }
    delete matData;
    self->storage = NULL;
    rt_accumulate(SIM_TIMER_OUTPUT);
}
Exemplo n.º 7
0
static void fmtEmitStep(DATA* data, threadData_t *threadData, MEASURE_TIME* mt, int didEventStep)
{
  if(mt->fmtReal)
  {
    int i, flag=1;
    double tmpdbl;
    unsigned int tmpint;
    int total = data->modelData.modelDataXml.nFunctions + data->modelData.modelDataXml.nProfileBlocks;
    rt_tick(SIM_TIMER_OVERHEAD);
    rt_accumulate(SIM_TIMER_STEP);

    /* Disable time measurements if we have trouble writing to the file... */
    flag = flag && 1 == fwrite(&mt->stepNo, sizeof(unsigned int), 1, mt->fmtInt);
    mt->stepNo++;
    flag = flag && 1 == fwrite(&(data->localData[0]->timeValue), sizeof(double), 1, mt->fmtReal);
    tmpdbl = rt_accumulated(SIM_TIMER_STEP);
    flag = flag && 1 == fwrite(&tmpdbl, sizeof(double), 1, mt->fmtReal);
    flag = flag && total == fwrite(rt_ncall_arr(SIM_TIMER_FIRST_FUNCTION), sizeof(uint32_t), total, mt->fmtInt);
    for(i=0; i<data->modelData.modelDataXml.nFunctions + data->modelData.modelDataXml.nProfileBlocks; i++) {
      tmpdbl = rt_accumulated(i + SIM_TIMER_FIRST_FUNCTION);
      flag = flag && 1 == fwrite(&tmpdbl, sizeof(double), 1, mt->fmtReal);
    }
    rt_accumulate(SIM_TIMER_OVERHEAD);

    if(!flag)
    {
      warningStreamPrint(LOG_SOLVER, 0, "Disabled time measurements because the output file could not be generated: %s", strerror(errno));
      fclose(mt->fmtInt);
      fclose(mt->fmtReal);
      mt->fmtInt = NULL;
      mt->fmtReal = NULL;
    }
  }

  /* prevent emit if noEventEmit flag is used, if it's an event */
  if ((omc_flag[FLAG_NOEVENTEMIT] && didEventStep == 0) || !omc_flag[FLAG_NOEVENTEMIT])
  {
    sim_result.emit(&sim_result, data, threadData);
  }

  printAllVarsDebug(data, 0, LOG_DEBUG);  /* ??? */
}
Exemplo n.º 8
0
void mat4_emit(simulation_result *self,DATA *data)
{
    mat_data *matData = (mat_data*) self->storage;
    double datPoint=0;
    rt_tick(SIM_TIMER_OUTPUT);

    rt_accumulate(SIM_TIMER_TOTAL);
    double cpuTimeValue = rt_accumulated(SIM_TIMER_TOTAL);
    rt_tick(SIM_TIMER_TOTAL);

    /* this is done wrong -- a buffering should be used
       although ofstream does have some buffering, but it is not enough and
       not for this purpose */
    matData->fp.write((char*)&(data->localData[0]->timeValue), sizeof(double));
    if(self->cpuTime)
        matData->fp.write((char*)&cpuTimeValue, sizeof(double));
    for(int i = 0; i < data->modelData.nVariablesReal; i++) if(!data->modelData.realVarsData[i].filterOutput)
            matData->fp.write((char*)&(data->localData[0]->realVars[i]),sizeof(double));
    for(int i = 0; i < data->modelData.nVariablesInteger; i++) if(!data->modelData.integerVarsData[i].filterOutput)
        {
            datPoint = (double) data->localData[0]->integerVars[i];
            matData->fp.write((char*)&datPoint,sizeof(double));
        }
    for(int i = 0; i < data->modelData.nVariablesBoolean; i++) if(!data->modelData.booleanVarsData[i].filterOutput)
        {
            datPoint = (double) data->localData[0]->booleanVars[i];
            matData->fp.write((char*)&datPoint,sizeof(double));
        }
    for(int i = 0; i < data->modelData.nAliasBoolean; i++) if(!data->modelData.booleanAlias[i].filterOutput)
        {
            if(data->modelData.booleanAlias[i].negate)
            {
                datPoint = (double) (data->localData[0]->booleanVars[data->modelData.booleanAlias[i].nameID]==1?0:1);
                matData->fp.write((char*)&datPoint,sizeof(double));
            }
        }
    if (!matData->fp) {
        throwStreamPrint(data->threadData, "Error while writing file %s",self->filename);
    }
    ++matData->ntimepoints;
    rt_accumulate(SIM_TIMER_OUTPUT);
}
void plt_emit(simulation_result *self,DATA *data, threadData_t *threadData)
{
  plt_data *pltData = (plt_data*) self->storage;
  rt_tick(SIM_TIMER_OUTPUT);
  if(pltData->actualPoints < pltData->maxPoints) {
      add_result(self,data,pltData->simulationResultData,&pltData->actualPoints); /*used for non-interactive simulation */
  } else {
    pltData->maxPoints = (long)(1.4*pltData->maxPoints + (pltData->maxPoints-pltData->actualPoints) + 2000);
    /* cerr << "realloc simulationResultData to a size of " << maxPoints * dataSize * sizeof(double) << endl; */
    pltData->simulationResultData = (double*)realloc(pltData->simulationResultData, pltData->maxPoints * pltData->dataSize * sizeof(double));
    if(!pltData->simulationResultData) {
      throwStreamPrint(threadData, "Error allocating simulation result data of size %ld",pltData->maxPoints * pltData->dataSize);
    }
    add_result(self,data,pltData->simulationResultData,&pltData->actualPoints);
  }
  rt_accumulate(SIM_TIMER_OUTPUT);
}
Exemplo n.º 10
0
/*
* output the result before destroying the datastructure.
*/
void plt_free(simulation_result *self,DATA *data, threadData_t *threadData)
{
  plt_data *pltData = (plt_data*) self->storage;
  const MODEL_DATA *modelData = data->modelData;
  int varn = 0, i, var;
  FILE* f = NULL;

  rt_tick(SIM_TIMER_OUTPUT);

  f = fopen(self->filename, "w");
  if(!f)
  {
    deallocResult(pltData);
    throwStreamPrint(threadData, "Error, couldn't create output file: [%s] because of %s", self->filename, strerror(errno));
  }

  /* Rather ugly numbers than unneccessary rounding.
     f.precision(std::numeric_limits<double>::digits10 + 1); */
  fprintf(f, "#Ptolemy Plot file, generated by OpenModelica\n");
  fprintf(f, "#NumberofVariables=%d\n", pltData->num_vars);
  fprintf(f, "#IntervalSize=%ld\n", pltData->actualPoints);
  fprintf(f, "TitleText: OpenModelica simulation plot\n");
  fprintf(f, "XLabel: t\n\n");

  /* time variable. */
  fprintf(f, "DataSet: time\n");
  for(i = 0; i < pltData->actualPoints; ++i)
      printPltLine(f, pltData->simulationResultData[i*pltData->num_vars], pltData->simulationResultData[i*pltData->num_vars]);
  fprintf(f, "\n");
  varn++;

  /* $cpuTime variable. */
  if(self->cpuTime)
  {
    fprintf(f, "DataSet: $cpuTime\n");
    for(i = 0; i < pltData->actualPoints; ++i)
        printPltLine(f, pltData->simulationResultData[i*pltData->num_vars], pltData->simulationResultData[i*pltData->num_vars + 1]);
    fprintf(f, "\n");
    varn++;
  }

  for(var = 0; var < modelData->nVariablesReal; ++var)
  {
    if(!modelData->realVarsData[var].filterOutput) {
      fprintf(f, "DataSet: %s\n", modelData->realVarsData[var].info.name);
      for(i = 0; i < pltData->actualPoints; ++i)
        printPltLine(f, pltData->simulationResultData[i*pltData->num_vars], pltData->simulationResultData[i*pltData->num_vars + varn]);
      fprintf(f, "\n");
      varn++;
    }
  }

  for(var = 0; var < modelData->nVariablesInteger; ++var)
  {
    if(!modelData->integerVarsData[var].filterOutput) {
      fprintf(f, "DataSet: %s\n", modelData->integerVarsData[var].info.name);
      for(i = 0; i < pltData->actualPoints; ++i)
        printPltLine(f, pltData->simulationResultData[i*pltData->num_vars], pltData->simulationResultData[i*pltData->num_vars + varn]);
      fprintf(f, "\n");
      varn++;
    }
  }

  for(var = 0; var < modelData->nVariablesBoolean; ++var)
  {
    if(!modelData->booleanVarsData[var].filterOutput) {
      fprintf(f, "DataSet: %s\n", modelData->booleanVarsData[var].info.name);
      for(i = 0; i < pltData->actualPoints; ++i)
        printPltLine(f, pltData->simulationResultData[i*pltData->num_vars], pltData->simulationResultData[i*pltData->num_vars + varn]);
      fprintf(f, "\n");
      varn++;
    }
  }

  for(var = 0; var < modelData->nAliasReal; ++var)
  {
    if(!modelData->realAlias[var].filterOutput) {
      fprintf(f, "DataSet: %s\n", modelData->realAlias[var].info.name);
      for(i = 0; i < pltData->actualPoints; ++i)
        printPltLine(f, pltData->simulationResultData[i*pltData->num_vars], pltData->simulationResultData[i*pltData->num_vars + varn]);
      fprintf(f, "\n");
      varn++;
    }
  }

  for(var = 0; var < modelData->nAliasInteger; ++var)
  {
    if(!modelData->integerAlias[var].filterOutput) {
      fprintf(f, "DataSet: %s\n", modelData->integerAlias[var].info.name);
      for(i = 0; i < pltData->actualPoints; ++i)
        printPltLine(f, pltData->simulationResultData[i*pltData->num_vars], pltData->simulationResultData[i*pltData->num_vars + varn]);
      fprintf(f, "\n");
      varn++;
    }
  }

  for(var = 0; var < modelData->nAliasBoolean; ++var)
  {
    if(!modelData->booleanAlias[var].filterOutput) {
      fprintf(f, "DataSet: %s\n", modelData->booleanAlias[var].info.name);
      for(i = 0; i < pltData->actualPoints; ++i)
        printPltLine(f, pltData->simulationResultData[i*pltData->num_vars], pltData->simulationResultData[i*pltData->num_vars + varn]);
      fprintf(f, "\n");
      varn++;
    }
  }

  deallocResult(pltData);
  if(fclose(f))
  {
    throwStreamPrint(threadData, "Error, couldn't write to output file %s\n", self->filename);
  }
  free(self->storage);
  self->storage = NULL;
  rt_accumulate(SIM_TIMER_OUTPUT);
}
Exemplo n.º 11
0
/*
 * add the values of one step for all variables to the data
 * array to be able to later store this on file.
 */
static void add_result(simulation_result *self,DATA *data,double *data_, long *actualPoints)
{
  plt_data *pltData = (plt_data*) self->storage;
  const DATA *simData = data;
  int i;
  double cpuTimeValue = 0;

  rt_accumulate(SIM_TIMER_TOTAL);
  cpuTimeValue = rt_accumulated(SIM_TIMER_TOTAL);
  rt_tick(SIM_TIMER_TOTAL);

  {
    data_[pltData->currentPos++] = simData->localData[0]->timeValue;

    if(self->cpuTime)
      data_[pltData->currentPos++] = cpuTimeValue;

    /* .. reals .. */
    for(i = 0; i < simData->modelData->nVariablesReal; i++) {
      if(!simData->modelData->realVarsData[i].filterOutput) {
        data_[pltData->currentPos++] = simData->localData[0]->realVars[i];
      }
    }
    /* .. integers .. */
    for(i = 0; i < simData->modelData->nVariablesInteger; i++) {
      if(!simData->modelData->integerVarsData[i].filterOutput) {
        data_[pltData->currentPos++] = simData->localData[0]->integerVars[i];
      }
    }
    /* .. booleans .. */
    for(i = 0; i < simData->modelData->nVariablesBoolean; i++) {
      if(!simData->modelData->booleanVarsData[i].filterOutput) {
        data_[pltData->currentPos++] = simData->localData[0]->booleanVars[i];
      }
    }
    /* .. alias reals .. */
    for(i = 0; i < simData->modelData->nAliasReal; i++) {
      if(!simData->modelData->realAlias[i].filterOutput) {
        double value;
        if(simData->modelData->realAlias[i].aliasType == 2)
          value = (simData->localData[0])->timeValue;
        else if(simData->modelData->realAlias[i].aliasType == 1)
          value = simData->simulationInfo->realParameter[simData->modelData->realAlias[i].nameID];
        else
          value = (simData->localData[0])->realVars[simData->modelData->realAlias[i].nameID];
        if(simData->modelData->realAlias[i].negate)
          data_[pltData->currentPos++] = -value;
        else
          data_[pltData->currentPos++] = value;
      }
    }
    /* .. alias integers .. */
    for(i = 0; i < simData->modelData->nAliasInteger; i++) {
      if(!simData->modelData->integerAlias[i].filterOutput) {
        modelica_integer value;
        if(simData->modelData->integerAlias[i].aliasType == 1)
          value = simData->simulationInfo->integerParameter[simData->modelData->realAlias[i].nameID];
        else
          value = (simData->localData[0])->integerVars[simData->modelData->realAlias[i].nameID];
        if(simData->modelData->integerAlias[i].negate)
          data_[pltData->currentPos++] = -value;
        else
          data_[pltData->currentPos++] = value;
      }
    }
    /* .. alias booleans .. */
    for(i = 0; i < simData->modelData->nAliasBoolean; i++) {
      if(!simData->modelData->booleanAlias[i].filterOutput) {
        modelica_boolean value;
        if(simData->modelData->integerAlias[i].aliasType == 1)
          value = simData->simulationInfo->booleanParameter[simData->modelData->realAlias[i].nameID];
        else
          value = (simData->localData[0])->booleanVars[simData->modelData->realAlias[i].nameID];
        if(simData->modelData->booleanAlias[i].negate)
          data_[pltData->currentPos++] = value==1?0:1;
        else
          data_[pltData->currentPos++] = value;
      }
    }
  }

  /*cerr << "  ... done" << endl; */
  (*actualPoints)++;
}
Exemplo n.º 12
0
void mat4_init(simulation_result *self,DATA *data)
{
    mat_data *matData = new mat_data();
    self->storage = matData;
    const MODEL_DATA *mData = &(data->modelData);

    const char Aclass[] = "A1 bt. ir1 na  Tj  re  ac  nt  so   r   y   ";

    const struct VAR_INFO** names = NULL;
    const int nParams = mData->nParametersReal + mData->nParametersInteger + mData->nParametersBoolean;

    char *stringMatrix = NULL;
    int rows, cols;
    int32_t *intMatrix = NULL;
    double *doubleMatrix = NULL;
    assert(sizeof(char) == 1);
    rt_tick(SIM_TIMER_OUTPUT);
    matData->numVars = calcDataSize(self,data);
    names = calcDataNames(self,data,matData->numVars+nParams);
    matData->data1HdrPos = -1;
    matData->data2HdrPos = -1;
    matData->ntimepoints = 0;
    matData->startTime = data->simulationInfo.startTime;
    matData->stopTime = data->simulationInfo.stopTime;

    try {
        /* open file */
        matData->fp.open(self->filename, std::ofstream::binary|std::ofstream::trunc);
        if(!matData->fp) {
            throwStreamPrint(data->threadData, "Cannot open File %s for writing",self->filename);
        }

        /* write `AClass' matrix */
        writeMatVer4Matrix(self,data,"Aclass", 4, 11, Aclass, sizeof(int8_t));
        /* flatten variables' names */
        flattenStrBuf(matData->numVars+nParams, names, stringMatrix, rows, cols, false /* We cannot plot derivatives if we fix the names ... */, false);
        /* write `name' matrix */
        writeMatVer4Matrix(self,data,"name", rows, cols, stringMatrix, sizeof(int8_t));
        free(stringMatrix);
        stringMatrix = NULL;

        /* flatten variables' comments */
        flattenStrBuf(matData->numVars+nParams, names, stringMatrix, rows, cols, false, true);
        /* write `description' matrix */
        writeMatVer4Matrix(self,data,"description", rows, cols, stringMatrix, sizeof(int8_t));
        free(stringMatrix);
        stringMatrix = NULL;

        /* generate dataInfo table */
        generateDataInfo(self, data, intMatrix, rows, cols, matData->numVars, nParams);
        /* write `dataInfo' matrix */
        writeMatVer4Matrix(self, data, "dataInfo", cols, rows, intMatrix, sizeof(int32_t));

        /* remember data1HdrPos */
        matData->data1HdrPos = matData->fp.tellp();

        /* adrpo: i cannot use writeParameterData here as it would return back to dataHdr1Pos */
        /* generate `data_1' matrix (with parameter data) */
        generateData_1(data, doubleMatrix, rows, cols, matData->startTime, matData->stopTime);
        /*  write `data_1' matrix */
        writeMatVer4Matrix(self,data,"data_1", cols, rows, doubleMatrix, sizeof(double));

        /* remember data2HdrPos */
        matData->data2HdrPos = matData->fp.tellp();
        /* write `data_2' header */
        writeMatVer4MatrixHeader(self,data,"data_2", matData->r_indx_map.size() + matData->i_indx_map.size() + matData->b_indx_map.size() + matData->negatedboolaliases + 1 /* add one more for timeValue*/ + self->cpuTime, 0, sizeof(double));

        free(doubleMatrix);
        free(intMatrix);
        doubleMatrix = NULL;
        intMatrix = NULL;
        matData->fp.flush();

    }
    catch(...)
    {
        matData->fp.close();
        free(names);
        names=NULL;
        free(stringMatrix);
        free(doubleMatrix);
        free(intMatrix);
        rt_accumulate(SIM_TIMER_OUTPUT);
        throwStreamPrint(data->threadData, "Error while writing mat file %s",self->filename);
    }
    free(names);
    names=NULL;
    rt_accumulate(SIM_TIMER_OUTPUT);
}