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

calculating time of current flow

calculating time of current flow

Hello,

I'm trying to figure out the lost energy due to the current flow. OpenModelica calculates LossPower for me, I just need to multiply this with time in order to calculate the energy.
To calculate the time, I've defined 2 variables and trying to write an while loop, something like this:

  while resistor1.i <> 0 loop
    counter_h = counter_h + 1;
  end while;
  while resistor1.i == 0 loop
    counter_c = counter_c + 1;
  end while;

energyLoss = (resistor1.LossPower + resistorS.LossPower) * (counter_h - counter_c)

The program won't simulate.
Do you have any suggestions?

Many thanks in advance


Re: calculating time of current flow

Hi,
I would say that you are thinking as if you were using a sequential language. In the equation section I do not see how to use a while loop. I think it is only for the algorithm section, but also there I do not see clearly how to program in this way. I would use something similar to this:

model Integration
  Real power;
  Real energy;
equation
  power=sin(2*Modelica.Constants.pi*time) "just to have possitive and negative values for power";
  if power>0 then
    der(energy)=power "here we are integrating only possitive power";
  else
    der(energy)=0;
  end if;
end Integration;

Carlos

Re: calculating time of current flow

Yes, I only posted the algorithm section, since the rest of my program is not that relevant to the question.

And yes I understand what I should be doing now. I am relatively new to OpenModelica and still trying to figure it out

Your answer helped me a lot, many thanks.

Edited by: AT11 - May-12-20 11:58:28
There are 0 guests and 0 other users also viewing this topic
You are here: