Simulate a model in ThermoCycle

This section describes how to simulate a Modelica model using the ThermoCycle library.
As a first thing we need to load the ThermoCycle Modelica library and the ExternalMedia library on Dymola 2015. To do so you can have a look at GettingStarted. It is assumed that the reader is familiar with the Dymola graphical user interface (GUI). A detailed description of the Dymola GUI is reported in the Dymola User Manual Volume 1 available from the Dymola interface in: Help –> Documentation –> Dymola User Manual Volume 1.

Step 1 – Investigating the core component model of ThermoCycle – Cell1D

In this first example we will show how to browse an existing model of the ThermoCycle library, simulate it and look at the results. In particular we will study the Cell1D model which simulates the one dimentional flow of fluid through a channel allowing for thermal energy transfer to the ambient. The Cell1D is the core component model of the ThermoCycle library and is depicted in the figure below. The model is available in ThermoCycle -> Components -> FluidFlow -> Pipes -> Cell1D.

cell1DimWord

The Cell1D is characterized by the presence of two fluid connectors, in blue, and one thermal connector, in red. In order to understand how the model works it is important to get a feeling of what a connector is.
Connectors are a way for a model to exchange information with another model. Using connectors allows for building reusable component models. The ThermoCycle models are built based on the component-oriented approach which allows to wrap the modeled physical behavior into reusable component models.
The fluid connector is an interface for one-dimentional fluid flow in a piping network and is characterized by 3 main variables:

  • The across variable pressure, p [Pa]. Also called potential or effort variables.
  • The through variable mass flow, m_flow [kg/s]. Also called flow variable.
  • The stream variable enthalpy, h [J/kg] which value depends on mass flow direction.

The thermal connector is an interface for 1-dimentional thermal transfer and is characterized by two variables:

  • The across variable temperature, T [K]
  • The through variable heat flux, phi [W/m2]

For a more in depth analysis of connectors the interested reader can refer to ModelicaByExampleConnector.
In the Cell1D model, the fluid enters the channel through the inlet fluid connectors, and exit the channel through the outlet fluid connectors. Furthermore, during its passage thermal energy transfer over the channel lateral surface can be simulated with the thermal connector.
The fluid flow through the channel is modeled with the conservation laws:

    • Dynamic mass and energy balances and a static momentum balance.

A detailed description of the model assumptions are available in the model documentation, that can be easily accessed by clicking the documentation icon from the Dymola modeling window as shown below.
cell1DimDoc
Step 2 – Simulating the Cell1D model
Now that we have a more clear idea on the Cell1D model, we can proceed to the simulation step. To do so, first click on the ThermoCycle package and then on the top-level Example package. The Example package contains a simulation model for each of the many component models available in the library. The Example package is composed by different subpackages, a description of which can be found in the documentation of the package itself. An overview of the Example package from the Dymola Package browser is shown hereunder:

ExamplePackage

From the Example package click on TestComponents and then double click on Test_Cell1D. The following will be displayed:

Cell1DimSchematic
In the edit window the model diagram is shown. The system is composed by the cell1D connected to two other models namely: the sourceMdot and the SinkP. These models provide the boundary conditions required by the Cell1D model to run the simulation. In particular the SourceMdot simulate an infinite reservoir of mass flow rate at a user defined temperature while the sinkP model is a pressure sink and defines the pressure of the cell1D.

Step 2.1 – Model parametrization
In order to run a simulation, the model parameters need to be defined. From the Dymola edit window, by double-clicking on the Cell1D model the parameter window can be accessed as shown below.
ParameterCell1D

The Cell1D parameter window is composed by 3 main tabs:

  • General: It contains the basic parameters of the model: geometrical characteristics, nominal heat transfer value and mass flow rate and the fluid which is flowing through the component.
  • Initialization: It allows to define the initial condition of the model variables. Pressure and temperature at the center of the cell in this case. Initial conditions are fundamental to solve a differential algebraic equation (DAE) system. For further details see ModelicaByExampleInitialization.
  • NumericalOptions: It allows to select among different numerical options. An in depth description and comparison of the available numerical options can be found in the following paper.
  • The source Mdot parameter window is shown here under:

The source Mdot parameter window is shown hereunder:

SourceMdotParameter

The Medium, the mass flow rate, Mdot_0, and the temperature,T_0, of the reservoir needs to be specified by the user. In this example the temperature of the SourceMdot is defined externally by using the StepBlock model from the Modelica standard library. The StepBlock model is connected to the Temperature input of the SourceMdot component. The StepBlock parameter window is depicted hereunder:

StepBlockParameter

The offset is the initial value of the output signal, the height is the amplitude step and StartTime the time at which the step is imposed. In this case a step down of 15K is imposed at time t =10 seconds.

The sinkP parameter window is shown here under:

SinkP_Parameter

The Medium and the pressure needs to be specified by the user.

Once the parameters are defined for each of the model the simulation can be run.

Step 3 – Model simulation and results

When running a model in Dymola the first thing is to set the general characteristic of the simulation. Go to the Simulation tab and click on the set-up icon. The following window opens:
SetUp

From the simulation setup, the simulation characteristics can be modified. In this case the simulation time is set to 100 seconds and the DASSL numerical algorhitm is selected to solve the system of equation with a relative error of 1e-4.
The simulation can be run by clicking the simulation icon, and the results can be inspected by plotting them using the plot window icon of Dymola as shown in the figure below.

Results

The figure shows the inlet, in blue, and outlet, in red, enthalpy of the Cell1D model. The variables can be selected by clicking on the relative boxes in the Variable Browser as shown in the figure. The inlet enthalpy decreases with a step imposed at t=10 sec by the StepBlock model. The outlet enthalpy is characterized by a slower dynamic.
The channel is filled with fluid at an enthalpy value of around 4.81E5 J/kg. As the enthalpy of the mass flow entering the channel suddenly decreases to a lower value, a certain time is required to experience the same value at the outlet of the channel due to energy and mass accumulation in the fluid filling the channel.
This first example shows how accounting for mass and energy accumulation in the Cell1D model results in a dynamic of the output variable of the model.
You are now ready to play with the different example models available in the ExamplePackage of the ThermoCycle library.