In this section, we’ll present another model, like the heat transfer model presented earlier in this chapter, that contains time events. In this case, we’ll show how we can simulate the behavior of a switch in the context of an RLC circuit like the one presented in the first chapter. From the examples presented so far, nothing in this model should come as a surprise. The main motivation for this example is simply to present time events in the context of an electrical model.
Our switched RLC circuit model is as follows:
model SwitchedRLC "An RLC circuit with a switch"
type Voltage=Real(unit="V");
type Current=Real(unit="A");
type Resistance=Real(unit="Ohm");
type Capacitance=Real(unit="F");
type Inductance=Real(unit="H");
parameter Voltage Vb=24 "Battery voltage";
parameter Inductance L = 1;
parameter Resistance R = 100;
parameter Capacitance C = 1e-3;
Voltage Vs;
Voltage V;
Current i_L;
Current i_R;
Current i_C;
equation
Vs = if time>0.5 then Vb else 0;
i_R = V/R;
i_C = C*der(V);
i_L=i_R+i_C;
L*der(i_L) = (Vs-V);
end SwitchedRLC;
The time event in this model is introduced via an if
expression.
The fact that the only time-varying variable in the conditional
expression is time
means that this will trigger a time event and
that the underlying numerical solver will be able to determine a
priori when the event will occur while integrating the underlying
equations.
We can see the voltage response of this model to the switched supply voltage in the following plot:
Furthermore, we can see the current response for inductor, resistor and capacitor components in this plot:
Hopefully by this point, the basic mechanisms for generating events and disturbances seem intuitive and familiar.