Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

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?

There are 0 guests and 0 other users also viewing this topic
You are here: