Jack Hsueh
Jack Hsueh

Reputation: 125

Continuous variable used in clocked when clause is automatically discretized

model test
  import Modelica.Constants.pi;
  Real f;
  discrete Real g;
  Clock clk=Clock(0.1);
equation 
  f = sin(pi*time);
  when Clock(0.1) then
    if f >= 0 then
      g = (sin(pi*time)) - 0.1;
    else
      g = (sin(pi*time)) + 0.1;
    end if;
  end when;
end test;

enter image description here

f is assigned as a continuous function. I want to sample the value of g depended on f, but f also be changed to a discrete value. Is there anything wrong ?

Upvotes: 1

Views: 59

Answers (1)

Hans Olsson
Hans Olsson

Reputation: 12517

The clock partitioning sees f as being used directly inside the when Clock and thus f is also seen as a clocked variable.

Use sample(f) if that is not desired:

model test
  import Modelica.Constants.pi;
  Real f;
  discrete Real g;
  Clock clk=Clock(0.1);
equation 
  f = sin(pi*time);
  when Clock(0.1) then
    if sample(f) >= 0 then
      g = (sin(pi*time)) - 0.1;
    else
      g = (sin(pi*time)) + 0.1;
    end if;
  end when;
end test;

See also: Failure to handle clock inference in Dymola

Upvotes: 1

Related Questions