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 code an already exiting component of the MSL inside a new model

How to code an already exiting component of the MSL inside a new model

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

Re: How to code an already exiting component of the MSL inside a new model

Hi Gabri,
You are importing Modelica.Electrical.Analog.Sources.PulseCurrent. OK you can create now an instance of the model writing for example:
PulseCurrent pulseCurrent;
But what you are doing is defining a Real variable: Real II1C. At the same time you are giving value to this variable by using the = sign. After this sign you could write a numerical value, but you write an expression. This expression should supply the numerical value, but it is not the case. The expression is not a function giving as output a Real value, but a complex model.

I suppose you are looking for something like this:

model battery2
  Real II1C;
  Modelica.Blocks.Sources.Pulse signalSource(amplitude = 10, period = 500, width = 50)  annotation(
    Placement(visible = true, transformation(origin = {-56, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
  II1C=signalSource.y;
end battery2;

Why Have I changed the Modelica.Electrical.Analog.Sources.PulseCurrent model by Modelica.Blocks.Sources.Pulse?
It is because your original model is too complex, as it has two pins with its voltage and intensity, and it seems that the only need is to generate a pulse to apply to the intensity.

Regards

Carlos

Re: How to code an already exiting component of the MSL inside a new model

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

Re: How to code an already exiting component of the MSL inside a new model

Hi,
I see that the intensity is pulsing with a period of 500 seconds. Of course you need to simulate for more than 500 seconds in order to see it. Here you have a test:

model battery2
  Real II1C;
  Modelica.Blocks.Sources.Pulse signalSource(amplitude = 10, period = 500, width = 50)  annotation(
    Placement(visible = true, transformation(origin = {-56, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
  II1C=signalSource.y;
annotation(
    experiment(StartTime = 0, StopTime = 2000, Tolerance = 1e-6, Interval = 4));
end battery2;

Modelica.Blocks.Sources.Pulse is extending Modelica.Blocks.Interfaces.SignalSource, that is itself an extension of Modelica.Blocks.Interfaces.SO, where y is defined as a RealOutput. So y is the output of the block calculation, and inside Modelica.Blocks.Sources.Pulse is coded how this output is calculated as function of time and the configurable parameters.

Carlos

Re: How to code an already exiting component of the MSL inside a new model

Hi Carlos,

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

Gabri

Re: How to code an already exiting component of the MSL inside a new model

Hi Carlos,

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

Gabri

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