0

I wanted to know if Modelica allows us to create replaceable models?

I was trying to redeclare the Modelica.Blocks.Sources.Constant to a block which goves constant voltage. I only need to change the unit of the variable k. (from nothing to "Volts"). Is it possible to do this in openmodelica?

MSK
  • 448
  • 2
  • 5
  • 18

2 Answers2

2

You don't need replaceable model for that. Just use a modifier on the Modelica.Blocks.Sources.Constant component:

Modelica.Blocks.Sources.Constant const(k(unit = "V"));

But to answer your question, yes OpenModelica supports replaceable models.

Adrian Pop
  • 4,034
  • 13
  • 16
  • Thanks for the quick reply. Can you please provide me a small example as to how i can create a replaceable model and redeclare it? I couldnt find any info online – MSK May 19 '14 at 09:20
  • I tried creating a model for the above question. class Constant "Generate constant signal of type Real" replaceable parameter Real k(start = 1); extends VisualModelica.Models.SignalBlocks.Interfaces.SO; equation y = k; end Constant model ConstantVoltage import SI = Modelica.SIunits; extends Constant(redeclare parameter SI.Voltage k(start = 1) "constant Voltage"); end ConstantVoltage; Now when I drag and drop this and double click, the GUI does not show the unit(V) or the comment(Constant Voltage). But when I instantiate it, the redeclaration chages are reflected in it. Why so? – MSK May 19 '14 at 09:23
  • You need to add graphical annotations to your model. – Adrian Pop May 19 '14 at 09:31
  • The graphical comments are there. I couldnt post the entire thing in a comment. So I removed it. Basically the constant class is a copy of the code of Blocks.Sources.Constant – MSK May 19 '14 at 09:37
1

The topic of replaceable components is discussed in the chapter on architectures in my online book, "Modelica by Example". You might find it useful.

Michael Tiller
  • 9,291
  • 3
  • 26
  • 41