Opened 11 years ago
Closed 11 years ago
#2528 closed defect (fixed)
block activationCon does not work properly
Reported by: | Lennart Ochel | Owned by: | Lennart Ochel |
---|---|---|---|
Priority: | high | Milestone: | 1.9.1 |
Component: | Code Generation | Version: | trunk |
Keywords: | Cc: |
Description
The following model is not working properly. activation.active
should switch from true
to false
at time = 1/2. But it stays true
for all the time …
model test block activationCon parameter input Integer nIn "number of input places"; parameter input Integer nOut "number of output places"; input Real tIn[:] "marking of input places"; input Real tOut[:] "marking of output places"; input Real arcWeightIn[:] "arc weights of input places"; input Real arcWeightOut[:] "arc weights of output places"; input Real minTokens[:] "minimum capacities of input places"; input Real maxTokens[:] "maximum capacities of output places"; input Boolean fed[:] "input places are fed?"; input Boolean emptied[:] "output places are emptied?"; output Boolean active "activation of transition"; output Boolean weaklyInputActiveVec[nIn] "places that causes weakly input activation"; output Boolean weaklyOutputActiveVec[nOut] "places that causes weakly output activation"; algorithm active:=true; weaklyInputActiveVec:=fill(false, nIn); weaklyOutputActiveVec:=fill(false, nOut); for i in 1:nIn loop if not (tIn[i] > minTokens[i] or tIn[i] <= minTokens[i] and fed[i]) then active:=false; elseif tIn[i] <= minTokens[i] and fed[i] then weaklyInputActiveVec[i]:=true; else end if; end for; for i in 1:nOut loop if not (tOut[i] < maxTokens[i] or tOut[i] >= maxTokens[i] and emptied[i]) then active:=false; elseif tOut[i] >= maxTokens[i] and emptied[i] then weaklyOutputActiveVec[i]:=true; else end if; end for; end activationCon; activationCon activation(nIn=1, nOut=1, tIn={1-time}, tOut={time}, minTokens = {0.5}, maxTokens={10}, fed = {false}, emptied={false}, arcWeightIn={1.0}, arcWeightOut={1.0}); end test;
Change History (3)
comment:2 by , 11 years ago
Component: | Backend → Code Generation |
---|
This bug is related to the handling of zero crossings.
The generated c file test1_05evt.c contains the zero crossings:
int test1_function_ZeroCrossings(DATA *data, double *gout, double *t) { real_array tmp1005; modelica_real tmp1006; modelica_boolean tmp1007; real_array_create(&tmp1005, ((modelica_real*)&($PtIn)), 1, 1); switch((modelica_integer) 1) { /* ASUB */ case 1: { tmp1006 = 0.5; break; } default: assert(NULL == "index out of bounds"); } tmp1007 = Greater((*real_array_element_addr(&tmp1005, 1, (modelica_integer) 1)),tmp1006); ZEROCROSSING(0, (!tmp1007)?1:-1); return 0; }
This generated code looks wrong. It should get changed to the following:
int test1_function_ZeroCrossings(DATA *data, double *gout, double *t) { real_array tmp1005; modelica_real tmp1006; modelica_boolean tmp1007; real_array_create(&tmp1005, ((modelica_real*)&($PtIn)), 1, 1); switch((modelica_integer) 1) { /* ASUB */ case 1: { tmp1006 = 0.5; break; } default: assert(NULL == "index out of bounds"); } tmp1007 = GreaterZC((*real_array_element_addr(&tmp1005, 1, (modelica_integer) 1)),tmp1006, data->simulationInfo.hysteresisEnabled[0]); ZEROCROSSING(0, (!tmp1007)?1:-1); return 0; }
Note:
See TracTickets
for help on using tickets.
I reduced the example above to the following:
This model still contains the same bug (model test1). By changing the indices within the if-condition, the model starts working correct (model test2).