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
  • » Gabri
  • » Profile

Posts

Posts

Hello Everyone,

I need to speed up the simulation time of a model.

I read the possibility to perform parallel simulation using OpenMP. Do you know how it works?

Do I have to use the following command: omc -d=openmp model.mo?
If so, how?

Thank you in advance,
Gabri

Hello All,

I created a Modelica block of a battery which takes as input the current and the SOC. In particular, I modeled the positive and negative pins of this battery block using the partial model OnePort from the MSL in which the missing equation is v=voltage, where voltage is the battery voltage obtained from the electrochemical equations inside the battery block giving (so far) a constant current.

If I connect them in in series, the model works but it doesn't in parallel. The error I got is: "An independent subset of the model has an imbalanced number of equations and variables).

Do you know a way to overcome this error?
Is it possible that the error is in the way OnePort works, in fact for the connection in series I always connect positive and negative pin whereas in the parallel connection I connect pos with pos and neg with neg pins?

Thank you so much in advance, it is really important for me to make this work!

Hi Everyone,

I want to implement an IF expression that enables two different sets of initial conditions. What I came up with is what follows:

Code:

parameter Real A;


if A ==1 then

Real y1(start=0.2), y2(start=3.5), y3(start=0.5);

else

Real y1(start=2.2), y2(start=1.5), y3(start=0.3);

end if;

Unfortunately, using the above code I got the following syntax error message:

No viable alternative near token: if

Could you help me figure this out?

Thank you so much!

Gabri

Thank you Arinomo23,

With startTime=10 I got a correct simulation but if I increase this number, let's say 500 sec, I am getting wrong outputs (i.e. in the plot of the step signal I don't have a step anymore but a constant value equal to 15 and the simulation time decreases to 20 sec even though in the simulation setup I specified an output equal to 1000s.
Do you know why?
Thank you again,
Gabri

Hi All,

I need to give as an input a step that has to start from positive values down to negative ones.
Let's say to have a time frame of 100 s and I will give a step after 50 sec. This signal range starts from 15 and finishes at -15 for a total amplitude of 30.

Do you know if there is a block that allows me to do this?
I have already tried to use Modelica.Blocks.Sources.Step but it seems I can only give values from negative (or 0) to positive and not vice-versa.

Thank you so much!
Gabri

Hello,

I was wondering if there is a way to store the simulated values, for instance, getting a 2 column matrix (the first column containing the time and the second the related simulate value) or something similar.

Thank you so much in advance,

Gabri

Hi Carlos,

it works! Thank you so much for your incredible help!

Gabri

Hi Carlos,

it works! Thank you so much for your incredible help!

Gabri

Hi Carlos,

Thank you so much for your help!
When I run the simulation now it works. By the way, the simulation looks not correct. In fact, I have the value of the current not like a pulse but constant over the simulation. Do you know why I got this?

I have another question, in this line of your code

  II1C=signalSource.y;

what does .y means?

Thank you so much for your big help!!

Gabri

Hello All,

I have a model that simulate the behavior of a battery. It is composed by different DAEs. Now it works using a constant current but I am trying to get some results using a time-varing current. I noticed that in Modelica -> Electrical -> Analog -> Sources there is a huge quantity of different current inputs that I could use to define the variable (Real) current in my model.

Is there a way to introduce in a model a already-existing block?

For instance, I am trying to give as input in my model the stepCurrent (contained in Source library) but I am getting back an error.

This is the way I coded:

model battery

//definition of variables and parameters

// II1C is the current

import Modelica.Electrical.Analog.Sources.PulseCurrent;
Real II1C = PulseCurrent(I = 10, period = 500, width = 50,offset=0);

equation

// DAE system which is also function of II1C.

end battery;


This is the error message I got:


[1] 19:22:01 Translation Error
[BatteryModelDischarging: 15:1-15:68]: Looking for a function .Modelica.Electrical.Analog.Sources.PulseCurrent but found a model.

[2] 19:22:01 Translation Error
Error occurred while flattening model BatteryModelDischarging


Is there a way to make this work?

Thank you so much in advance,

Kindest regards, Gabri

Hello All,

I have a model that simulate the behavior of a battery. It is composed by different DAEs. Now it works using a constant current but I am trying to get some results using a time-varing current. I noticed that in Modelica -> Electrical -> Analog -> Sources there is a huge quantity of different current inputs that I could use to define the variable (Real) current in my model.

Is there a way to introduce in a model a already-existing block?

For instance, I am trying to give as input in my model the stepCurrent (contained in Source library) but I am getting back an error.

This is the way I coded:

model battery

//definition of variables and parameters

// II1C is the current

import Modelica.Electrical.Analog.Sources.PulseCurrent;
Real II1C = PulseCurrent(I = 10, period = 500, width = 50,offset=0);

equation

// DAE system which is also function of II1C.

end battery;


This is the error message I got:


[1] 19:22:01 Translation Error
[BatteryModelDischarging: 15:1-15:68]: Looking for a function .Modelica.Electrical.Analog.Sources.PulseCurrent but found a model.

[2] 19:22:01 Translation Error
Error occurred while flattening model BatteryModelDischarging


Is there a way to make this work?

Thank you so much in advance,

Kindest regards, Gabri

Thank you so much sjoelund.se,
I have already tried to use this flag but the time I get back is a way smaller than the real one (clock-wall).

In fact, using an external timer I found that my total time (starting when I press the "simulate" button to the end of the simulation) is, more or less, 4 mins and the time I obtain bt the function is 5.86 seconds.

Do you know why I have this huge difference?

Thank you again, Gabry

Hi Adrpo,

Thanks for the link. With this, now I am able to measure the simulation time but I am not able to measure the time required for the initialization of the variables in my DAE system.
Do you know if there is a way to do this?
Thank you so much!
Gabry

Hi Adrpo,

First of all, sorry for all the messages I sent!
In the meantime, I made some progress and I managed to solve my issue using as follows:

equation
  m * der(vx) = -x / L * F;
  m * der(vy) = (-y / L * F) - m * g;
  der(x) = vx;
  der(y) = vy;
  x ^ 2 + y ^ 2 = L ^ 2;
  algorithm
  when F>20 then
  terminate("end");
  end when;


Using this algorithm inside my model I am able to stop the simulation when the condition is reached.

I just have one last question: Do you know if there is a way to calculate the time (wall-clock time) of the simulation? I need something similar to the function tic/toc in Matlab. By the way, something more general could be useful too. In fact, I need to know the tot time of the simulation starting from the first line of the model to the last one (I don't need the time of a particular part of the code).

Thank you so much again, Gabry

Hi Ardpo,

basically what I want to implement in my code is the following logic:

when a variable reaches a determined value, then stop the simulation.
In the case in the example is when F=20 then stop the simulation.

So, I thought to model this concept using a while loop. While the F is below 20, then calculate x.

This is the way I model the problem in Matlab.

By the way, maybe in Modelica there is another way to do this without using a loop. Do you know if there is another way?

Thank you so much!

Gabry

Hello Adrpo,
Thank you so much for your help.

Now, the model looks like the one attached below.
By the way, I still get the following error message:

[1] 11:11:43 Translation Error
Internal error BackendDAE.adjacencyRowEnhanced failed for eqn:
algorithm
  while F < 20.0 loop
    x := sqrt(L ^ 2.0 - y ^ 2.0);
    vx := (-y) * vy / sqrt(L ^ 2.0 - y ^ 2.0);
  end while;

[2] 11:11:43 Translation Error
Internal error BackendDAEUtil.getAdjacencyMatrixEnhancedScalar failed

[3] 11:11:43 Translation Error
Internal error - IndexReduction.dynamicStateSelectionWork failed!


I think my problem is due to the fact that the model is formed by DAEs.
If I include this in a function, am I still able to simulate it? Can I insert DAEs inside a function?

I am new in OpenModelica and I am sure my questions may seem silly so thank you so much for your help!

Gabry


model Pendulum
  parameter Real m = 1, g = 9.81, L = 0.5;
  Real F;
  Real x(start = 0.5, fixed = true), y(start = 0, fixed = true);
  Real vx, vy;

equation
  m * der(vx) = -x / L * F;
  m * der(vy) = (-y / L * F) - m * g;
  der(x) = vx;
  der(y) = vy;


algorithm
while F<20 loop

x := sqrt(L ^ 2 -  y ^ 2); 
   
end while;
 
end Pendulum;

Hello everyone,
I am learning how to use loops in Modelica. My understanding is that I cannot apply loops directly in a function but I need an algorithm section. In particular, I am trying to implement a while loop in the following Pendulum Model. By the way, I am not able to understand how to remove this error:

Parse error: Modelica assignment statements are either on the form 'component_reference := expression' or '( output_expression_list ) := function_call'

Thank you so much in advance! Gabriele

model Pendulum
  parameter Real m = 1, g = 9.81, L = 0.5;
  Real F;
  Real x(start = 0.5, fixed = true), y(start = 0, fixed = true);
  Real vx, vy;

equation
  m * der(vx) = -x / L * F;
  m * der(vy) = (-y / L * F) - m * g;
  der(x) = vx;
  der(y) = vy;


algorithm
while F<20 loop

  x ^ 2 + y ^ 2 := L ^ 2;
   
end while;
 
end Pendulum;

Hello All,
I have the following system. It contains 26 DAEs.

Model AModel

(Definition of parameters, constants, variables and initialization of the 26 variables denoteted with yi, i=1,..., 26)

equation

26 DAEs with 26 equations and 26 variables

while K > 21 loop

    A= 3.3 + (c1*c2)/c3*(y5*(0^2/2 - 0*c3) +
      y6/2*(0^3/3 - 0*c4^2) + y7/3*(0^4/4 - 0*c5^3) +
      y8/4*(0^5/5 - 0*c5^4));

    B = y9 + (c1*c2)/sigmaeffn*(y1*(L^2/2 - L*c3) +
      y2/2*(L^3/3 - L*c5^2) +
      y3/3*(L^4/4 - L*c5^3));

    K=B-A;

end while;
end AModel;

       
In the Above equations (A and B) y1, y2, y3, y5, y6, y7, y8, y9 are 8 of the 26 variables obtained from the 26 DAEs.
Without while loop it works properly but using the loop I got errors. I think I am doing some sintax errors as I am new with Modelica.
I've also tried using algorithm but I still got errors.

Thank you so much!
Gabriele

Hello All,
I would like to know if there is a way to measure the time required for the simulation.
I noticed in the Simulation Setup panel -> simulation flag -> clock (Optional)
I can choose 3 types of clocks and the one I need is RT which is, if I correctly understood, the one that gives in out the wall-clock time (e.g. tic toc in Matlab).
By the way, when I select this, I am not able to see the time anywhere.
Do you have any idea how can I solve this issue or, do you know if there is another way to know the time required by the simulation?

Thanks in advance, Gabri

Hello,

I was wondering if Modelica has a function for calculating consistent initial conditions starting from an initial guess in DAE system of equations.
I am looking for a function similar to IDACalcIC in IDA solver (SUNDIALS).

Thank you very much in advance,

Gabri

Hello,

I was wondering if Modelica has a function for calculating consistent initial conditions starting from an initial guess in DAE system of equations.
I am looking for a function similar to IDACalcIC in IDA solver (SUNDIALS).

Thank you very much in advance,

Gabri

Hi CTG,

thank you so much for your help.

I have tried this solution but the following 2 issues occur:

1) in the 'Messages Browser' I have the following warning:

08:53:32 Translation Warning
Iteration variables with default zero start attribute in equation system with analytic Jacobian:
         y:DUMMY_STATE()  type: Real

What does it means?

2) In the 'simulation output' window I have the following message written in red:

Failed to solve linear system of equations (no. 26) at time 0.000000, system is singular for U[3, 3].
The default linear solver fails, the fallback solver with total pivoting is started at time 0.000000. That might raise performance issues, for more information use -lv LOG_LS.
Matrix singular!

By the way the simulation 'end successfully'. Pasted below the lines which are right after the above error message:

The initialization finished successfully without homotopy method.
### STATISTICS ###
timer
events
solver: dassl
The simulation finished successfully.

Why do I have this message even if the simulation ends successfully?

Thank you so much!


Dear all,

I am learning Modelica in order to model DAEs systems and to do this I am using the book of Prof. Fritzon.
I am a student and DAE and Modelica are completely new for me so, maybe, you may find my questions mindless but I really need to understand better these basic concepts. So, I want to thank in advance the one who will answer to my questions.
In particular, I am modeling the following example of a Pendulum.

model Pendolum
parameter Real m=1, g=9.81, L=0.5;
Real F;
Real x(start=0.5), y(start=0);
Real vx, vy;

equation

m*der(vx)=-(x/L)*F;
m*der(vy)=-(y/L)*F-m*g;
der(x)=vx;
der(y)=vy;
x^2+y^2=L^2;

end Pendolum;

There are some points that are not very clear to me. I listed them below:

1) Why the following warning message appears? What does it means? Is there a way to remove it?

[1] 19:28:43 Translation Warning
Assuming fixed start value for the following 2 variables:
         $STATESET1.x:VARIABLE(start = /*Real*/($STATESET1.A[1]) * $START.vy + /*Real*/($STATESET1.A[2]) * $START.vx fixed = false )  type: Real
         $STATESET2.x:VARIABLE(start = /*Real*/($STATESET2.A[1]) * $START.x + /*Real*/($STATESET2.A[2]) * $START.y fixed = false )  type: Real

2) As the system is described by 2nd order diff eqs. and the state variables are: x(t), y(t) and F(t), what I expect is to have also initial conditions on the first derivatives (i.e. velocities of x and y) and on F but in the example I just have initial conditions just on the position (x(t) and y(t). Is this my thought wrong? If yes, why?

3) Do you have any materials (maybe with some examples) to suggest me in order to better understand how DAEs work?

I am so sorry for all these questions,

Thank you so much!

Very best Regards,

Gabri

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