Creating Models to easily Include / Remove Effects

Modelica supports a concept called conditional components which provides a convenient mechanism to include or remove effects from a model through the change of a single parameter.  This means that the same models can be reused for different types of studies where different effects have to be considered. The ability to tune the model complexity can save simulation time by removing components and their effects which aren’t considered important for a particular analysis.

A conditional component is an object or sub-model that is included or removed from a simulation by a controlling parameter.  This parameter should be a Boolean parameter and it is evaluated during symbolic manipulation.

In the following example the Electrical Rectifier model from the Modelica standard library is extended to include thermal effects.  The starting point for this model is to extend from Modelica.Electrical.Analog.Examples.Rectifier and then add an additional heat port and make this conditional so that we can turn on and off the thermal effects. The diode model (Modelica.Electrical.Analog.Ideal.IdealDiode) used within the rectifier already has a conditional heat port and when this is included the power lost as heat within the diode is calculated.

Rectifier with optional thermal effects

First, add the heat port and heat capacitor to the Dymola model diagram, both components can be found within the Modelica.Thermal.HeatTransfer package.

Next, add a new Boolean parameter called useHeatTransfer. This will be used to make the thermal components conditional and to enable the heat ports in the diodes.

Select all 6 diodes (hold shift down as you click on each diode) and open their parameter dialog box.  Propagate the parameter useHeatTransfer which should automatically link to the new parameter just created and then click OK.  The model diagram will update and the conditional heat ports on the diodes will now be displayed.

Draw in the connections between the all heat ports and the heat capacitor as shown above.

To finish the model and make the thermal components conditional simply go to the text layer and find the lines that define the heat port and heat capacitor.  After the component name add “if useHeatTransfer” and this makes the component conditional. These components will now be included in the model if useHeatTransfer=true and they will be removed if useHeatTransfer=false. When a component is conditionally removed from a model, all the connections to that component are also removed

The code is shown below:

model HeatingRectifier "Simple Heating Rectifier"
  extends Modelica.Electrical.Analog.Examples.Rectifier(
    IdealDiode1(useHeatPort=useHeatTransfer),
    IdealDiode2(useHeatPort=useHeatTransfer),
    IdealDiode3(useHeatPort=useHeatTransfer),
    IdealDiode4(useHeatPort=useHeatTransfer),
    IdealDiode5(useHeatPort=useHeatTransfer),
    IdealDiode6(useHeatPort=useHeatTransfer)); 

  parameter Boolean useHeatTransfer=true "Set true to enable thermal effects";

  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_a heatPort if useHeatTransfer
    annotation (...);
  Modelica.Thermal.HeatTransfer.Components.HeatCapacitor diodesCapacitor(C=6) if useHeatTransfer
    annotation (...);
equation
  //Model connect equations removed for simplicity
end HeatingRectifier;

When using the new rectifier as a component within another model, as shown below, the heat port connector on the rectifier will be shown or hidden in the diagram in response to the value set for useHeatTransfer.

Example electrical circuit using the new rectifier model

 

 

 

 

 

 

 

CONTACT US

Got a question? Just fill in this form and send it to us and we'll get back to you shortly.

Sending

© Copyright 2010-2023 Claytex Services Ltd All Rights Reserved

Log in with your credentials

Forgot your details?