Beispiel #1
0
/**
 * Creates a component for the specified attribute.
 *
 * This function will create the component if it doesn't already exist;
 * it aborts on error.
 *
 * @see create_component
 *
 * @param attr  The attribute of the component to create.
 * @param cid   The component ID of the component to create.
 */
void
makeall_make_component(Attribute *attr, ComponentID cid)
{
  int state;

  if (! component_ok(attr, cid)) {

    printf(" + creating %s ... ", cid_name(cid));
    fflush(stdout);
    (void) create_component(attr, cid);

    state = component_state(attr, cid);
    if (!(state == ComponentLoaded || state == ComponentUnloaded)) {
      printf("FAILED\n");
      fprintf(stderr, "ERROR. Aborted.\n");
      exit(1);
    }

    printf("OK\n");
  }

}
/*
 Inherits from : -
======================================================================*/
fmiStatus fmiInitialize(fmiComponent component_,
                        fmiBoolean toleranceControlled,
                        fmiReal relativeTolerance,
                        fmiEventInfo* eventInfo)
{
   /* Declaration of internal variables */
   int i; /* Loop variable */
   int ip[11]; /* Integer parameters */
   int n; /* Size variable */
   fmiStatus old_status;
   double rp[7]; /* Real parameters */
   char* tp[1]; /* Text parameters */

   /* Convert the memory slot 'component_' to an fmiComponentStructure (fmiComponent is void*) */
   fmiComponentStructure* component = component_;
   AMESIMSYSTEM *amesystem = InitGlobalSystem(0, 0, 0, 0);
   amesystem->AmeExit = ModelAmeExit;
   SetGlobalSystem(amesystem);
   ValidateRuntype(8);

   /* Initialize real parameters */
   rp[0] = component->realSVar[0];
   rp[1] = component->realSVar[1];
   rp[2] = component->realSVar[2];
   rp[3] = component->realSVar[3];
   rp[4] = component->realSVar[4];
   rp[5] = component->realSVar[5];
   rp[6] = component->realSVar[6];

   /* Initialize integer parameters */
   ip[0] = component->intSVar[0];
   ip[1] = component->intSVar[1];
   ip[2] = component->intSVar[2];
   ip[3] = component->intSVar[3];
   ip[4] = component->intSVar[4];
   ip[5] = component->intSVar[5];
   ip[6] = component->intSVar[6];
   ip[7] = component->intSVar[7];
   ip[8] = component->intSVar[8];
   ip[9] = component->intSVar[9];
   ip[10] = component->intSVar[10];

   /* Initialize text parameters */
   tp[0] = (char*)component->stringSVar[0];

   /* Set nominal values for continuous states */
   for (i = 0 ; i < component->nb_state_var ; ++i)
   {
      component->nominalContinuousStates[i] = component->realSVar[component->idx_of_state_var[i]] != 0.0 ? component->realSVar[component->idx_of_state_var[i]] : 1.0;
      component->state_var_deriv[i] = 0;
   }
   component->time_or_state_event = fmiFalse;

   /* Finish component initialization */
   if (toleranceControlled)
   {
      relativeTolerance = 1.*relativeTolerance;
   }
   n = 1; /* Initialize instantiation number */
   if ((component->status == fmiFatal) || (component->status == fmiError))
   {
      AME_status = fmiError;
   }
   if (!component_ok(component)) /* Test component */
   {
      return fmiFatal;
   }
   if (update_state(component, T_fmiInitialize, "fmiInitialize", __FILE__, __LINE__) == fmiFalse) /* Update current state (state machine) */
   {
      return fmiError;
   }

   /* Call submodel's 'init' function */
   shuntdcmotorwithstartingresistorin_(&n,                        /* Instance number */
                                       rp,                        /* Real parameters */
                                       ip,                        /* Integer parameters */
                                       tp,                        /* Text parameters */
                                       component->ps,             /* Pointer stores */
                                       &(component->realSVar[7]), /* ifield (ifield - Field current) */
                                       &(component->realSVar[8])  /* speed (speed - Rotary speed) */);

   /* Retrieve real parameters */
   component->realSVar[0] = rp[0];
   component->realSVar[1] = rp[1];
   component->realSVar[2] = rp[2];
   component->realSVar[3] = rp[3];
   component->realSVar[4] = rp[4];
   component->realSVar[5] = rp[5];
   component->realSVar[6] = rp[6];

   /* Retrieve integer parameters */
   component->intSVar[0] = ip[0];
   component->intSVar[1] = ip[1];
   component->intSVar[2] = ip[2];
   component->intSVar[3] = ip[3];
   component->intSVar[4] = ip[4];
   component->intSVar[5] = ip[5];
   component->intSVar[6] = ip[6];
   component->intSVar[7] = ip[7];
   component->intSVar[8] = ip[8];
   component->intSVar[9] = ip[9];
   component->intSVar[10] = ip[10];

   /* Retrieve text parameters */
   component->stringSVar[0] = tp[0];

   /* Call dynamic */
   component->first_call = fmiTrue;
   amesystem->first_call = 1;
   old_status = component->status;
   dynamic(component);
   amesystem->first_call = 0;
   if ((AME_status != fmiOK) && (component->status != fmiFatal))
   {
      component->status = fmiError;
   }
   if (component->status != old_status)
   {
      component->memory.logger(component, component->instanceName, fmiWarning, "fmiInitialize", "Variable AME_status was changed by submodel.");
   }

   /* Fill in event information */
   eventInfo->iterationConverged = fmiTrue;
   eventInfo->stateValueReferencesChanged = fmiFalse;
   eventInfo->stateValuesChanged = fmiTrue;
   eventInfo->terminateSimulation = fmiFalse;
   eventInfo->upcomingTimeEvent = fmiFalse;
   if (GetFutureTimeDiscon() < getfinaltime_()) /* Get first time event */
   {
      eventInfo->upcomingTimeEvent = fmiTrue;
      eventInfo->nextEventTime = GetFutureTimeDiscon();
   }
   component->eventInfo = *eventInfo;

   /* Model has been evaluated */
   component->evaluated = fmiTrue;

   /* All went smoothly */
   return component->status;
}
Beispiel #3
0
/**
 * Create a given component (or all components) for an attribute.
 *
 * @param attr      The attribute to work on.
 * @param cid       If this is CompLast, all components will be created.
 *                  Otherwise, it specifies the single component that will
 *                  be created.
 * @param validate  boolean - if true, validate_revcorp is called to check
 *                  the resulting revcorp.
 */
void
makeall_do_attribute(Attribute *attr, ComponentID cid, int validate)
{
  assert(attr);

  if (cid == CompLast) {
    printf("ATTRIBUTE %s\n", attr->any.name);
    /* automatically create all necessary components */

    /* check whether directory for data files exists (may be misspelt in registry) */
    if (! is_directory(attr->any.path)) {
      fprintf(stderr, "WARNING. I cannot find the data directory of the '%s' attribute.\n",
              attr->any.name);
      fprintf(stderr, "WARNING  Directory: %s/ \n", attr->any.path);
      fprintf(stderr, "WARNING  Perhaps you misspelt the directory name in the registry file?\n");
    }

    /* lexicon and lexicon offsets must have been created by encode */
    if (! (component_ok(attr, CompLexicon) && component_ok(attr, CompLexiconIdx))) {
      /* if none of the components exits, we assume that the attribute will be created later & skip it */
      if (!component_ok(attr, CompLexicon) && !component_ok(attr, CompLexiconIdx) &&
          !component_ok(attr, CompLexiconSrt) &&
          !component_ok(attr, CompCorpus) && !component_ok(attr, CompCorpusFreqs) &&
          !component_ok(attr, CompHuffSeq) && !component_ok(attr, CompHuffCodes) &&
          !component_ok(attr, CompHuffSync) &&
          !component_ok(attr, CompRevCorpus) && !component_ok(attr, CompRevCorpusIdx) &&
          !component_ok(attr, CompCompRF) && !component_ok(attr, CompCompRFX))
        {
          /* issue a warning message & return */
          printf(" ! attribute not created yet (skipped)\n");
          if (strcmp(attr->any.name, "word") == 0) {
            fprintf(stderr, "WARNING. The 'word' attribute must be created before using CQP on this corpus!\n");
          }
          return;
        }
      else {
        fprintf(stderr, "ERROR. Lexicon is missing. You must use the 'encode' tool first!\n");
        exit(1);
      }
    }
    else {
      /* may need to create "alphabetically" sorted lexicon */
      makeall_make_component(attr, CompLexiconSrt);
      printf(" - lexicon      OK\n");
    }

    /* create token frequencies if necessary (must be able to do so if they aren't already there) */
    makeall_make_component(attr, CompCorpusFreqs);
    printf(" - frequencies  OK\n");

    /* check if token sequence has been compressed, otherwise create CompCorpus (if necessary) */
    if (component_ok(attr, CompHuffSeq) && component_ok(attr, CompHuffCodes) && component_ok(attr, CompHuffSync)) {
      printf(" - token stream OK (COMPRESSED)\n");
    }
    else {
      makeall_make_component(attr, CompCorpus);
      printf(" - token stream OK\n");
    }

    /* same for index (check if compressed, otherwise create if not already there) */
    if (component_ok(attr, CompCompRF) && component_ok(attr, CompCompRFX)) {
      printf(" - index        OK (COMPRESSED)\n");
    }
    else {
      makeall_make_component(attr, CompRevCorpusIdx);
      if (! component_ok(attr, CompRevCorpus)) { /* need this check to avoid validation of existing revcorp  */
        makeall_make_component(attr, CompRevCorpus);
        if (validate) {
          /* validate the index, i.e. the REVCORP component we just created */
          if (! validate_revcorp(attr)) {
            fprintf(stderr, "ERROR. Validation failed.\n");
            exit(1);
          }
        }
      }
      printf(" - index        OK\n");
    }
  }
  else {
    /* create requested component only */
    printf("Processing component %s of ATTRIBUTE %s\n",
           cid_name(cid), attr->any.name);
    makeall_make_component(attr, cid);
    if (validate && (cid == CompRevCorpus)) { /* validates even if REVCORP already existed -> useful trick for validating later */
      if (! validate_revcorp(attr)) {
        fprintf(stderr, "ERROR. Validation failed.\n");
        exit(1);
      }
    }
  }

}
/*
 Inherits from : -
======================================================================*/
fmiStatus dynamic(fmiComponent component_)
{
   /* Declaration of internal variables */
   fmiComponentStructure* component; /* Internal data structure */
   int flag; /* Discontinuity flag */
   int ip[11]; /* Integer parameters */
   int n; /* Instantiation number */
   int oflag; /* Old discontinuity flag */
   fmiStatus old_status; /* Variable used to detect a change in AME_status by the submodel */
   double rp[7]; /* Real parameters */
   char* tp[1]; /* Text parameters */

   /* Cast the component (fmiComponent is void*) so we can use the internal structure */
   component = (fmiComponentStructure*)(component_);
   flag = component->flag; /* Initialize discontinuity flag */
   oflag = 2; /* Required for discontinuity handling */

   /* Initialize real parameters */
   rp[0] = component->realSVar[0];
   rp[1] = component->realSVar[1];
   rp[2] = component->realSVar[2];
   rp[3] = component->realSVar[3];
   rp[4] = component->realSVar[4];
   rp[5] = component->realSVar[5];
   rp[6] = component->realSVar[6];

   /* Initialize integer parameters */
   ip[0] = component->intSVar[0];
   ip[1] = component->intSVar[1];
   ip[2] = component->intSVar[2];
   ip[3] = component->intSVar[3];
   ip[4] = component->intSVar[4];
   ip[5] = component->intSVar[5];
   ip[6] = component->intSVar[6];
   ip[7] = component->intSVar[7];
   ip[8] = component->intSVar[8];
   ip[9] = component->intSVar[9];
   ip[10] = component->intSVar[10];

   /* Initialize text parameters */
   tp[0] = (char*)component->stringSVar[0];
   n = 1; /* Initialize instantiation number */
   if (!component_ok(component)) return fmiFatal; /* Test component */

   /* Retrieve real parameters */
   component->realSVar[0] = rp[0];
   component->realSVar[1] = rp[1];
   component->realSVar[2] = rp[2];
   component->realSVar[3] = rp[3];
   component->realSVar[4] = rp[4];
   component->realSVar[5] = rp[5];
   component->realSVar[6] = rp[6];

   /* Retrieve integer parameters */
   component->intSVar[0] = ip[0];
   component->intSVar[1] = ip[1];
   component->intSVar[2] = ip[2];
   component->intSVar[3] = ip[3];
   component->intSVar[4] = ip[4];
   component->intSVar[5] = ip[5];
   component->intSVar[6] = ip[6];
   component->intSVar[7] = ip[7];
   component->intSVar[8] = ip[8];
   component->intSVar[9] = ip[9];
   component->intSVar[10] = ip[10];

   /* Retrieve text parameters */
   component->stringSVar[0] = tp[0];

   /* Call submodel's 'dynamic' function */
   disini_(&oflag);
   SetTimeAtLastStep(component->time);
   SetTimeAtThisStep(component->time);
   if (setjmp(jump_env) == 0)
   {
      shuntdcmotorwithstartingresistor_(&n,                                                     /* Instantiation number */
                                     &(component->realSVar[7]),                              /* ifield (ifield - Field current) */
                                     &(component->state_var_deriv[component->deriv_idx[7]]), /* Derivative of variable 'ifield' */
                                     &(component->realSVar[8]),                              /* speed (speed - Rotary speed) */
                                     &(component->state_var_deriv[component->deriv_idx[8]]), /* Derivative of variable 'speed' */
                                     &(component->realSVar[9]),                              /* BEMF (BEMF - Back EMF) */
                                     &(component->realSVar[10]),                             /* Lfield (Lfield - Field inductance) */
                                     &(component->realSVar[11]),                             /* Pe (Pe - Electrical power) */
                                     &(component->realSVar[12]),                             /* Pem (Pem - Electromechanical power) */
                                     &(component->realSVar[13]),                             /* Rarm (Rarm - Armature resistance) */
                                     &(component->realSVar[14]),                             /* Rarm0 (Rarm0 - Armature resistance at motor start) */
                                     &(component->realSVar[15]),                             /* Rarm1 (Rarm1 - Steady state value of armature resistance) */
                                     &(component->realSVar[16]),                             /* Rfield (Rfield - Field resistance) */
                                     &(component->realSVar[17]),                             /* Tem (Tem - Electromechanical torque) */
                                     &(component->realSVar[18]),                             /* booleantrigger0 (boolean_trigger_0 - boolean trigger state) */
                                     &(component->realSVar[19]),                             /* booleantrigger1 (boolean_trigger_1 - boolean trigger state) */
                                     &(component->realSVar[20]),                             /* cvisc (cvisc - Viscous friction coefficient) */
                                     &(component->realSVar[21]),                             /* x0 (der(ifield) - Introduced der variable) */
                                     &(component->realSVar[22]),                             /* x1 (der(speed) - Introduced der variable) */
                                     &(component->realSVar[23]),                             /* i (i - Output current) */
                                     &(component->realSVar[24]),                             /* iarm (iarm - Armature current) */
                                     &(component->realSVar[25]),                             /* inertia (inertia - Rotor intertia) */
                                     &(component->realSVar[26]),                             /* k (k - Torque constant) */
                                     &(component->realSVar[27]),                             /* tswitchoff (tswitchoff - Switch off time of starting resistor) */
                                     &(component->realSVar[28]),                             /* u (u - Applied voltage) */
                                     rp,                                                     /* Real parameters */
                                     ip,                                                     /* Integer parameters */
                                     tp,                                                     /* Text parameters */
                                     component->ps,                                          /* Pointer stores */
                                     &(flag),                                                /* Discontinuity flag */
                                     &(component->time)                                      /* Time */);
   }
   component->evaluated = fmiTrue; /* Model has been evaluated */
   old_status = component->status;
   if ((AME_status != fmiOK) && (component->status != fmiFatal))
   {
      component->status = fmiError;
   }
   if (component->status != old_status)
   {
      component->memory.logger(component, component->instanceName, fmiWarning, "'dynamic' function", "Variable AME_status was changed by submodel.");
   }
   component->status = AME_status;

   /* All went smoothly */
   return component->status;
}