Search code examples
pythonsimulationmodelicaopenmodelica

How to use the real input connector in OpenModelica?


I would like to have a OpenModelica model like the following: Model from OMEdit

On the left side there is a "Real Input Connector" called u and on the right side there is a "Real Output Connector" called y. The Porpose of the model is just to take a value (u) multiply it with 2 and give back the output (y).

Now my questions: How do I set a value to the input variabe u?

Is the input connector the right block to do this?


Solution

  • This is valid if you want this gain to be a standalone submodule that you'll connect to other models. In that case you need to connect the output of a source to your input block. The standard library provides a variety in Modelica.Blocks.Sources, or you can make your own.

    As a trivial example, with your example saved as My_Gain.mo, to connect to sinusoidal source:

    model SampleModel
      My_Gain gain;
      Modelica.Blocks.Sources.Sine source;
    
    equation
      connect(source.y, gain.u);
    end SampleModel;
    

    Without knowing more about what you're trying to do, it's hard to say if this is the right way to go about it, but it will work.