Block-based modeling is well suited for problems that have a well-defined causality, i.e. direction of flow. An example of this type of signal-based system is a control system. However, in most cases the causality is not predefined; for instance, a motor could also be used as a generator, depending on whether or not the input signal is the current or torque. Another basic example is the AC circuit below.
In these equations, i is the total current through the signal voltage, and i1 and i2 are the currents running through resistor1 and resistor2, respectively. Rewrite the above equations to not contain derivatives:
With these equations, we can now implement the block-based model, as shown below.
The Diagram View of the IntroductoryExamples.ComponentBased.BlockCircuit model.
To view the components in the Modelica.Blocks.Sources package in the Class Browser, expand the Modelica package, followed by Blocks and Sources, by clicking the symbol to the left of each package icon and name.
Switch to Simulation Center and simulate the model for 10 seconds. The output current is the result of add2. The signals i1 and i2 are from gain3 and integrator1, respectively. The picture below shows the resulting current.
Plotting add2.y for the IntroductoryExamples.ComponentBased.BlockCircuit model with default parameter values.
Naturally, implementing a component-based model of the system shown in the original drawing requires only drag-and-drop, as well as connecting the components and setting parameters. This leaves us with a model that looks just like the drawing with which we started.
The Diagram View of the IntroductoryExamples.ComponentBased.ElectricCircuit model.
If you would like to build the model yourself, the sine voltage component is located in the Modelica.Electrical.Analog.Sources package, and the rest of the components in the Modelica.Electrical.Analog.Basic package. Note that some of the parameter values differ from the default, so in order to obtain the same simulation results you will have to change these as well.
Plotting the current going through the sine source for the IntroductoryExamples.ComponentBased.ElectricCircuit model with default parameter values.
The Diagram View of the IntroductoryExamples.ComponentBased.ElectricCircuit2 model.