- Index
- » Programming
- » Modelica Language
- » How to count the number of cycles a...
How to count the number of cycles a variable is going through?
How to count the number of cycles a variable is going through?
I have a load attached to a battery model. I am trying to count the number of charging/discharging cycles(cn) the battery is going through and the depth of discharge of each cycle. PNet is the power flowing through the battery (positive for discharging and negative for charging).
I have given a start value of 0 to cn and I want to keep counting the number of cycles.
I have tried to write the following but nothing works:
1.
when PNet == 0 and PNet <> pre(PNet) then
cn = pre(cn)+1;
end when;
or
2.
cn = if der(PNet)=0 then pre(cn)+1 else cn
I keep getting mostly the following 2 errors:
1. 1. It is not allowed to use pre for a continuous time variable outside a when clause
2. The when-condition must be a discrete expression:
Can anyone help me with this?
- Index
- » Programming
- » Modelica Language
- » How to count the number of cycles a...