The CapacitorDEVS Block
Parameters:
period |
length of the sampling intervals |
start |
start time of the sampling period |
Description:
The figure below illustrates the implementation of the ModelicaDEVS capacitor. In order to be connectable to blocks from the electrical library of Modelica, it has to extend the EEBlock of the ModelicaDEVS library. This block looks like the TwoPin block interface provided by Dymola on its outside, but internally performs a type conversion of the input and output signals: the two blocks inDEVS and outDEVS are used to transform the signals from the electrical pins to signals of type real and vice-versa. The second type conversion is done by means of the SamplerTime and the Interpolator blocks that act as interfaces to non-DEVS components with real-valued input/output signals.
Note that it would have been more appropriate to use the SamplerLevel block, because the scope of DEVS integration is to by-pass the time discretisation. However, as we will see later, it was necessary to program a numerical version of the sampler block, in order to enable mixed simulations. Unfortunately, the numerical version of the SamplerLevel block led to aborted simulations due to "inconsistent restarting conditions". With a numerical version of the SamplerTime block on the other hand, the simulation could be performed without encountering any difficulties. Hence for the sake of consistency, it was decided to only use time sampler blocks instead of a SamplerLevel for the CapacitorDEVS block and a SamplerTimeNumerical for the CapacitorDEVSNumerical block.
The full textual description of the ModelicaDEVS capacitor is given below:
1 model CapacitorDEVS
2 extends ModelicaDEVS.Templates.EEBlock;
3 parameter Modelica.SIunits.Capacitance C=1 "Capacitance";
4 parameter Real period=1e-6 "Sampling period";
5
6 SourceBlocks.SamplerTime SamplerTime1(period=period);
7 FunctionBlocks.Integrator Integrator1;
8 SinkBlocks.Interpolator Interpolator1;
9 FunctionBlocks.Gain Gain1(g=1/C);
10
11 equation
12 connect(SamplerTime1.outPort, Gain1.inPort);
13 connect(Gain1.outPort, Integrator1.inPort);
14 connect(Integrator1.outPortInterpolator, Interpolator1.inPortInterpolator);
15 connect(inDEVS, SamplerTime1.inPort);
16 connect(Interpolator1.outPort, outDEVS);
17 end CapacitorDEVS;
The SamplerTime block (line 6) samples the signal of the electrical current at a period specified by the parameter sampling (line 4), and the Gain block (line 9) multiplies the incoming signal by the value of 1/C, where C is again specified by a parameter (line 3). Taken as a whole, the ModelicaDEVS blocks constitute nothing else than the well known capacitor formula
i=C*dv/dt
in an algebraically modified version:
v=1/C*integral(i)
Unfortunately, the CapacitorDEVS block exhibits two problems - one solvable, the other not yet:
-
The electrical components do not assume a certain data flow direction since they are described by acausal equations (an acausal equation x=y is an equation in its literal sense, so it can be understood as x=y or y=x. A causal equation on the other hand assigns a variable a certain value, so the meaning of x=y is actually x:=y. Note that causal equation are also often called assignments. The data flow of ModelicaDEVS components on the other hand is directed, since DEVS components feature input and output ports instead of electrical bi-directional pins. This means that our ModelicaDEVS capacitor has to turn acausal equations into causal ones: it assumes it is given the current i, and hence it computes the voltage v. Unfortunately, such a capacitor would not work anymore if we were to connect it to a voltage source instead of a current generator.
-
An even more severe problem (that could not be solved yet) is caused by the SamplerTime block applying the der() operator to the signal that it receives through its input port (lines 2 and 8 in the code snipped below):
1 equation
2 derivative=der(u); //used to produce der(der(u))
3 yEvent= sample(start,period);
5 when sample(start,period) then
6 yVal[1]= u;
7 yVal[2]= if method>1 then derivative else 0;
8 yVal[3]= if method>2 then der(derivative) else 0;
9 end when;
Given that the input of the SamplerTime block depends on the output of the Interpolator in the DEVS capacitor, Dymola would have to differentiate the output of the Interpolator, which unfortunately it is not able to, and hence aborts the simulation with a "Failed to differentiate the equation in order to reduce the DAE index." error message.
An attempt to solve this problem was made using Dymola's "User specified Derivatives" feature described in the Dymola Handbook [Dymola]: functions for the first and second derivatives have been inserted into the Interpolator, but due to unknown reasons, this did not solve the issue neither.
The
CapacitorDEVSNumerical block shows how this problem could be by-passed using a numerical solution.
Generated at 2025-01-31T19:25:52Z
by OpenModelicaOpenModelica 1.24.3 using GenerateDoc.mos