PW_PowerSystem_05evt.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* Events: Sample, Zero Crossings, Relations, Discrete Changes */
  2. #include "PW_PowerSystem_model.h"
  3. #if defined(__cplusplus)
  4. extern "C" {
  5. #endif
  6. /* Initializes the raw time events of the simulation using the now
  7. calcualted parameters. */
  8. void PW_PowerSystem_function_initSample(DATA *data, threadData_t *threadData)
  9. {
  10. long i=0;
  11. }
  12. const char *PW_PowerSystem_zeroCrossingDescription(int i, int **out_EquationIndexes)
  13. {
  14. static const char *res[] = {"down_input > greaterThreshold1.threshold",
  15. "up_input > convertToBoolean.threshold"};
  16. static const int occurEqs0[] = {1,139};
  17. static const int occurEqs1[] = {1,125};
  18. static const int *occurEqs[] = {occurEqs0,occurEqs1};
  19. *out_EquationIndexes = (int*) occurEqs[i];
  20. return res[i];
  21. }
  22. /* forwarded equations */
  23. int PW_PowerSystem_function_ZeroCrossingsEquations(DATA *data, threadData_t *threadData)
  24. {
  25. TRACE_PUSH
  26. data->simulationInfo->callStatistics.functionZeroCrossingsEquations++;
  27. TRACE_POP
  28. return 0;
  29. }
  30. int PW_PowerSystem_function_ZeroCrossings(DATA *data, threadData_t *threadData, double *gout)
  31. {
  32. TRACE_PUSH
  33. modelica_boolean tmp5;
  34. modelica_boolean tmp6;
  35. data->simulationInfo->callStatistics.functionZeroCrossings++;
  36. tmp5 = GreaterZC(data->localData[0]->realVars[14] /* down_input variable */, data->simulationInfo->realParameter[2] /* greaterThreshold1._threshold PARAM */, data->simulationInfo->storedRelations[0]);
  37. gout[0] = (tmp5) ? 1 : -1;
  38. tmp6 = GreaterZC(data->localData[0]->realVars[102] /* up_input variable */, data->simulationInfo->realParameter[0] /* convertToBoolean._threshold PARAM */, data->simulationInfo->storedRelations[1]);
  39. gout[1] = (tmp6) ? 1 : -1;
  40. TRACE_POP
  41. return 0;
  42. }
  43. const char *PW_PowerSystem_relationDescription(int i)
  44. {
  45. const char *res[] = {"down_input > greaterThreshold1.threshold",
  46. "up_input > convertToBoolean.threshold"};
  47. return res[i];
  48. }
  49. int PW_PowerSystem_function_updateRelations(DATA *data, threadData_t *threadData, int evalforZeroCross)
  50. {
  51. TRACE_PUSH
  52. modelica_boolean tmp7;
  53. modelica_boolean tmp8;
  54. if(evalforZeroCross) {
  55. tmp7 = GreaterZC(data->localData[0]->realVars[14] /* down_input variable */, data->simulationInfo->realParameter[2] /* greaterThreshold1._threshold PARAM */, data->simulationInfo->storedRelations[0]);
  56. data->simulationInfo->relations[0] = tmp7;
  57. tmp8 = GreaterZC(data->localData[0]->realVars[102] /* up_input variable */, data->simulationInfo->realParameter[0] /* convertToBoolean._threshold PARAM */, data->simulationInfo->storedRelations[1]);
  58. data->simulationInfo->relations[1] = tmp8;
  59. } else {
  60. data->simulationInfo->relations[0] = (data->localData[0]->realVars[14] /* down_input variable */ > data->simulationInfo->realParameter[2] /* greaterThreshold1._threshold PARAM */);
  61. data->simulationInfo->relations[1] = (data->localData[0]->realVars[102] /* up_input variable */ > data->simulationInfo->realParameter[0] /* convertToBoolean._threshold PARAM */);
  62. }
  63. TRACE_POP
  64. return 0;
  65. }
  66. int PW_PowerSystem_checkForDiscreteChanges(DATA *data, threadData_t *threadData)
  67. {
  68. TRACE_PUSH
  69. int needToIterate = 0;
  70. infoStreamPrint(LOG_EVENTS_V, 1, "check for discrete changes at time=%.12g", data->localData[0]->timeValue);
  71. if(data->localData[0]->booleanVars[0] /* convertToBoolean._y DISCRETE */ != data->simulationInfo->booleanVarsPre[0] /* convertToBoolean._y DISCRETE */)
  72. {
  73. infoStreamPrint(LOG_EVENTS_V, 0, "discrete var changed: convertToBoolean._y from %d to %d", data->simulationInfo->booleanVarsPre[0] /* convertToBoolean._y DISCRETE */, data->localData[0]->booleanVars[0] /* convertToBoolean._y DISCRETE */);
  74. needToIterate = 1;
  75. }
  76. if(data->localData[0]->booleanVars[1] /* greaterThreshold1._y DISCRETE */ != data->simulationInfo->booleanVarsPre[1] /* greaterThreshold1._y DISCRETE */)
  77. {
  78. infoStreamPrint(LOG_EVENTS_V, 0, "discrete var changed: greaterThreshold1._y from %d to %d", data->simulationInfo->booleanVarsPre[1] /* greaterThreshold1._y DISCRETE */, data->localData[0]->booleanVars[1] /* greaterThreshold1._y DISCRETE */);
  79. needToIterate = 1;
  80. }
  81. if (ACTIVE_STREAM(LOG_EVENTS_V)) messageClose(LOG_EVENTS_V);
  82. TRACE_POP
  83. return needToIterate;
  84. }
  85. #if defined(__cplusplus)
  86. }
  87. #endif