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
  • Index
  • » Users
  • » jayahoharish
  • » Profile

Posts

Posts

I have a load attached to a battery model. I am trying to count the number of charging/discharging cycles the battery is going through. PNet is the power flowing through the battery (positive for discharging and negative for charging).
I write the following and I always get the following errors.
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:

I am completely new to programming and Modelica. So, can someone explain when pre() can be used?

For example if PNet is changing continuously with time, can I ever get a value of pre(PNet)?
And if I can somehow get this, can I use this to build "if" or "when" expressions?

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?

May-21-19 16:41:13
Can pre() be used in continuous time variables?

I have a load attached to a battery model. I am trying to count the number of charging/discharging cycles the battery is going through. PNet is the power flowing through the battery (positive for discharging and negative for charging).
I write the following and I always get the following errors.
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:

I am completely new to programming and Modelica. So, can someone explain when pre() can be used?

For example if PNet is changing continuously with time, can I ever get a value of pre(PNet)?
And if I can somehow get this, can I use this to build "if" or "when" expressions?

May-21-19 14:46:25
I have a simulation where the Power from a battery varies with time. I want to count how many...

Here is the library:
https://github.com/UdK-VPT/BuildingSystems

I am working on Complex battery model which is located at Building Systems/Technologies/Electrical Storage.

I am trying to count the number of cycles the battery is going through and the depth of discharge of each cycle.

A simulation without these features can be run and this can be found at Building Systems/Technologies/Electrical Storage/Examples.

May-21-19 11:17:06
I have a simulation where the Power from a battery varies with time. I want to count how many...

Thank you very much for this.
I was able to save the code without errors but I cannot run the simulation as there are 2 errors:
1. It is not allowed to use pre for a continuous time variable outside a when clause:
pre(PNet)
and
2. The when-condition must be a discrete expression:
when PNet == 0 and PNet <> pre(PNet) then
cn = 1+cn;
end when;

Any ideas on this?

May-20-19 18:55:05
I have a simulation where the Power from a battery varies with time. I want to count how many...

The variable that is changing is called PNet. I want to count the number of cycles. how do I write this correctly using if or when or a combination of both? I am counting the number of cycles through a RealOutput called "cn". The start value of cn is 0.
I am very new to programming and Modelica in general.
I tried to write this:

when PNet=0 then cn=pre(cn)+1; end when PNet=pre(Pnet);

This was my logic: I want cn to increase by 1 whenever PNet touches 0 but I do not want this happening for every time PNet remains 0.
This is the main error I get: "Error: declaration window line 80 column 12, syntax error at "=" missing "then""
Please suggest what mistake I have made here or any alternative approaches.

Thanks,
Harish

  • Index
  • » Users
  • » jayahoharish
  • » Profile
You are here: