Reputation: 115
I am new in using OpenModelica.
I have a model that simulates the behavior of a battery. It is composed of different DAEs. Now it works using a constant current but I am trying to get some results using a time-varying 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 an 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 a 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
Upvotes: 0
Views: 66
Reputation:
Yes, there are different ways to introduce a model from a library into your battery model.
An easy solution to make your model "work" is the following (it checks, at least; I am not sure it will do what you want it to do)
model Battery
//definition of variables and parameters
// II1C is the current
Modelica.Blocks.Sources.Pulse currentSource(amplitude = 10, period = 500, width = 50, offset=0);
Real II1C;
equation
currentSource.y = II1C;
// DAE system which is also a function of II1C.
annotation(
uses(Modelica(version = "3.2.3")));
end Battery;
where
Modelica.Blocks.Sources.Pulse
is the path in the Library where
the model Pulse is located currentSource
is the name of the
instance of the Pulse model in your Battery model (amplitude = 10, period = 500, width = 50, offset=0)
are the parameters that
modifies the default behavior of the Pulse model (normally called
modifiers) currentSource.y = II1C;
under the equation section
is the way to assign the ouptut of the Pulse model (.y
) to the
variable II1C
you instantiated as Real II1C;
Notice though that the Pulse model has nothing to do with the electrical domain, it is just a general signal source. That is, it is up to you to integrate it in your model in a way that makes sense physically; besides, it might be inefficient regarding the modeling and simulation performance.
Perhaps DrModelica could be a good place to start understanding not only the technical aspects of the Modelica language, but also good practices to model with it.
Upvotes: 1