Example #1
0
fmiStatus fmiResetSlave(fmiComponent c) {
    ModelInstance* comp = (ModelInstance *)c;
    if (invalidState(comp, "fmiResetSlave", modelInitialized))
         return fmiError;
    if (comp->loggingOn) comp->functions.logger(c, comp->instanceName, fmiOK, "log", "fmiResetSlave");
    comp->state = modelInstantiated;
    setStartValues(comp); // to be implemented by the includer of this file
    return fmiOK;
}
Example #2
0
// fname is fmiInstantiateModel or fmiInstantiateSlave
static fmiComponent instantiateModel(char* fname, fmiString instanceName, fmiString GUID,
        fmiCallbackFunctions functions, fmiBoolean loggingOn) {
    ModelInstance* comp;
    if (!functions.logger)
        return NULL; // we cannot even log this problem
    if (!instanceName || strlen(instanceName)==0) {
        functions.logger(NULL, "?", fmiError, "error",
                "%s: Missing instance name.", fname);
        return NULL;
    }
    if (!GUID || strlen(GUID)==0) {
        functions.logger(NULL, instanceName, fmiError, "error",
                "%s: Missing GUID.", fname);
        return NULL;
    }
    if (!functions.allocateMemory || !functions.freeMemory){
        functions.logger(NULL, instanceName, fmiError, "error",
                "%s: Missing callback function.", fname);
        return NULL;
    }
    if (strcmp(GUID, MODEL_GUID)) {
        functions.logger(NULL, instanceName, fmiError, "error",
                "%s: Wrong GUID %s. Expected %s.", fname, GUID, MODEL_GUID);
        return NULL;
    }
    comp = (ModelInstance *)functions.allocateMemory(1, sizeof(ModelInstance));
    if (comp) {
        comp->r = functions.allocateMemory(NUMBER_OF_REALS,    sizeof(fmiReal));
        comp->i = functions.allocateMemory(NUMBER_OF_INTEGERS, sizeof(fmiInteger));
        comp->b = functions.allocateMemory(NUMBER_OF_BOOLEANS, sizeof(fmiBoolean));
        comp->s = functions.allocateMemory(NUMBER_OF_STRINGS,  sizeof(fmiString));
        comp->isPositive = functions.allocateMemory(NUMBER_OF_EVENT_INDICATORS, sizeof(fmiBoolean));
        comp->instanceName = functions.allocateMemory(1 + strlen(instanceName), sizeof(char));
        comp->GUID = functions.allocateMemory(1 + strlen(GUID), sizeof(char));
    }
    if (!comp || !comp->r || !comp->i || !comp->b || !comp->s || !comp->isPositive
        || !comp->instanceName || !comp->GUID) {
        functions.logger(NULL, instanceName, fmiError, "error",
                "%s: Out of memory.", fname);
        return NULL;
    }
    if (loggingOn) functions.logger(NULL, instanceName, fmiOK, "log",
            "%s: GUID=%s", fname, GUID);

    strcpy((char *)comp->instanceName, (char *)instanceName);
    strcpy((char *)comp->GUID, (char *)GUID);
    comp->functions = functions;
    comp->loggingOn = loggingOn;
    comp->state = modelInstantiated;
    setStartValues(comp); // to be implemented by the includer of this file
    return comp;
}
TaskCostPanel::TaskCostPanel(Task &task, Accounts &accounts, QWidget *p, const char *n)
    : TaskCostPanelImpl(p, n),
      m_task(task),
      m_accounts(accounts),
      m_locale( 0 )
{
    const Project *project = qobject_cast<const Project*>( task.projectNode() );
    if ( project ) {
        m_locale = project->locale();
    }
    if ( m_locale == 0 ) {
        m_locale = KGlobal::locale();
    }
    m_accountList << i18n("None");
    m_accountList += accounts.costElements();

    if ( task.isBaselined( BASELINESCHEDULE ) ) {
        runningGroup->setEnabled( false );
        startupGroup->setEnabled( false );
        shutdownGroup->setEnabled( false );
    }
    setStartValues(task);
}
Example #4
0
fmiStatus fmiInitialize(fmiComponent c, fmiBoolean toleranceControlled, fmiReal relativeTolerance, fmiEventInfo* eventInfo)
{
  double nextSampleEvent=0;
  ModelInstance* comp = (ModelInstance *)c;
  threadData_t *threadData = comp->threadData;
  threadData->currentErrorStage = ERROR_SIMULATION;

  if (invalidState(comp, "fmiInitialize", modelInstantiated))
    return fmiError;
  if (nullPointer(comp, "fmiInitialize", "eventInfo", eventInfo))
    return fmiError;
  if (comp->loggingOn) comp->functions.logger(c, comp->instanceName, fmiOK, "log",
      "fmiInitialize: toleranceControlled=%d relativeTolerance=%g",
      toleranceControlled, relativeTolerance);

  /* set zero-crossing tolerance */
  setZCtol(relativeTolerance);

  setStartValues(comp);
  copyStartValuestoInitValues(comp->fmuData);

  /* try */
  MMC_TRY_INTERNAL(simulationJumpBuffer)

    if(initialization(comp->fmuData, comp->threadData, "", "", 0.0, 5))
    {
      comp->state = modelError;
      if(comp->loggingOn) comp->functions.logger(c, comp->instanceName, fmiOK, "log",
          "fmiInitialization: failed");
    }
    else
    {
      comp->state = modelInitialized;
      if(comp->loggingOn) comp->functions.logger(c, comp->instanceName, fmiOK, "log",
          "fmiInitialization: succeed");
    }

    /*TODO: Simulation stop time is need to calculate in before hand all sample events
            We shouldn't generate them all in beforehand */
    initSample(comp->fmuData, comp->threadData, comp->fmuData->localData[0]->timeValue, 100 /*should be stopTime*/);
    initDelay(comp->fmuData, comp->fmuData->localData[0]->timeValue);

    /* due to an event overwrite old values */
    overwriteOldSimulationData(comp->fmuData);

    eventInfo->iterationConverged = fmiTrue;
    eventInfo->stateValueReferencesChanged = fmiFalse;
    eventInfo->stateValuesChanged = fmiTrue;
    eventInfo->terminateSimulation = fmiFalse;

    /* Get next event time (sample calls)*/
    nextSampleEvent = getNextSampleTimeFMU(comp->fmuData);
    if (nextSampleEvent == -1){
      eventInfo->upcomingTimeEvent = fmiFalse;
    }else{
      eventInfo->upcomingTimeEvent = fmiTrue;
      eventInfo->nextEventTime = nextSampleEvent;
      fmiEventUpdate(comp, fmiFalse, eventInfo);
    }

    return fmiOK;

  /* catch */
  MMC_CATCH_INTERNAL(simulationJumpBuffer)

    comp->functions.logger(c, comp->instanceName, fmiError, "error", "fmiInitialize: terminated by an assertion.");
    return fmiError;
}