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:1 by Lennart Ochel, 11 years ago

I reduced the example above to the following:

model test1
  parameter Integer nIn=1 "number of input places";
  Real tIn[:]={1-time} "marking of input places";
  Real minTokens[:]= {0.5} "minimum capacities of input places";
  Boolean active "activation of transition";
algorithm 
  active:=true;
  for i in 1:nIn loop
    if not (tIn[i] > minTokens[i]) then
      active:=false;
    else
      
    end if;
  end for;
end test1;
model test2
  parameter Integer nIn=1 "number of input places";
  Real tIn[:]={1-time} "marking of input places";
  Real minTokens[:]= {0.5} "minimum capacities of input places";
  Boolean active "activation of transition";
algorithm 
  active:=true;
  for i in 1:nIn loop
    if not (tIn[1] > minTokens[1]) then
      active:=false;
    else
      
    end if;
  end for;
end test2;

This model still contains the same bug (model test1). By changing the indices within the if-condition, the model starts working correct (model test2).

Last edited 11 years ago by Lennart Ochel (previous) (diff)

comment:2 by Lennart Ochel, 11 years ago

Component: BackendCode 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;
}

comment:3 by Lennart Ochel, 11 years ago

Resolution: fixed
Status: newclosed

Fixed in r18592.

Note: See TracTickets for help on using tickets.