Description: "Tutorial with step by step instructions for how to do coupled simulation"

- Home > Modelica

## Buildings.Rooms.Examples.FFD.Tutorial

Tutorial with step by step instructions for how to do coupled simulation

### Information

This package contains the tutorials NaturalConvection and MixedConvection with step by step instructions for how to build such models.

Extends from Modelica.Icons.Information (Icon for general information packages).

### Package Content

Name | Description
--- | ---
MixedConvection | Tutorial for Mixed Convection case
NaturalConvection | Tutorial for Natural Convection case

## Buildings.Rooms.Examples.FFD.Tutorial.MixedConvection

Tutorial for Mixed Convection case

### Information

This tutorial gives step by step instructions on building and simulating a mixed convection model. The model tests the coupled simulation of Buildings.Rooms.CFD with the FFD program by simulating ventilation with mixed convection in an empty room.

#### Case Description

The temperature of the floor is fixed at 30ˆC and the temperature of the walls and the ceiling are fixed at 10ˆC. The supply air temperature is fixed at 10ˆC.

Figure (a) shows the schematic of the FFD simulation and Figure (b) shows the velocity vectors and temperatures on the X-Z plane at Y = 0.5 m as simulated by the FFD.

Figure (a)

Figure (b)

#### Step by Step Guide

This section describes step by step how to build and simulate the model.

1. Add the following model components into the `MixedConvection` model:

   - Buildings.Rooms.CFD. This model is used to implement data exchange between Modelica and FFD. Name it as `roo`.
   - Buildings.BoundaryConditions.WeatherData.ReaderTMY3. Use weather data from OHare Intl. Airport, Chicago, Illinoi, U.S.A. Name it as `weaDat`.
   - Modelica.Blocks.Sources.Constant. Three models are needed to specify that internal radiation, internal convective heat gain and internal latent heat gain are zero. Name these models as `qRadGai_flow`, `qConGai_flow` and `qLatGai_flow`, respectively.
   - Modelica.Blocks.Routing.Multiplex3. This block is used to convert three numbers into a vector. Name it as `multiple_x3`.
   - Buildings.HeatTransfer.Source.FixedTemperature. Two models are needed to specify the temperature on the floor and other walls. Name them as `TFlo` and `TOthWal` respectively. Please note that it is necessary to declare `TOthWal` as a vector of 5 elements.
   - Buildings.Fluid.Sources.MassFlowSource_T. This model provides inlet air for the `roo`. Name it as `bouIn`.
   - Buildings.Fluid.Sources.FixedBoundary. This model is the outdoor environment to which the outlet of `roo` is connected. Name it as `bouOut`.

2. In the textual editor mode, add the medium and the number of surfaces as below:

       package MediumA = Buildings.Media.GasesConstantDensity.MoistAirUnsaturated (T_default=283.15);
         parameter Integer nConExtWin=0;
         parameter Integer nConBou=0;
         parameter Integer nSurBou=6;
         parameter Integer nConExt=0;
         parameter Integer nConPar=0;

3. Edit `roo` as below:

       Buildings.Rooms.CFD roo(
         redeclare package Medium = MediumA,
         surBou(
           name={"East Wall","West Wall","North Wall","South Wall","Ceiling","Floor"},
           A={0.9,0.9,1,1,1,1},
           til={Buildings.Types.Tilt.Wall,
               Buildings.Types.Tilt.Wall,
               Buildings.Types.Tilt.Wall,
               Buildings.Types.Tilt.Wall,
               Buildings.Types.Tilt.Ceiling,
               Buildings.Types.Tilt.Floor},
           each absIR=1e-5,
           each absSol=1e-5,
           each boundaryCondition=Buildings.Rooms.Types.CFDBoundaryConditions.Temperature),
           lat = 0.012787839282646,
           AFlo = 1*1,
           hRoo = 1,
           linearizeRadiation = false,
           useCFD = true,
           sensorName = {"Occupied zone air temperature", "Velocity"},
           cfdFilNam = "modelica://Buildings/Resources/Data/Rooms/FFD/Tutorial/MixedConvection.ffd",
           nConExt = nConExt,
           nConExtWin = nConExtWin,
           nConPar = nConPar,
           nConBou = nConBou,
           nSurBou = nSurBou,
           nPorts = 2,
           portName={"Inlet","Outlet"},
           samplePeriod = 6);

4. Set the parameters for the following components:

   - Set `qRadGai_flow`, `qConGai_flow` and `qLatGai_flow` to 0.
   - Set `TFlo` to 303.15 Kelvin.
   - Set `TOthWal` to 283.15 Kelvin.

5. Set the values for the parameters of `bouIn` and `bouOut` as below:

       Fluid.Sources.MassFlowSource_T bouIn(
         redeclare package Medium = MediumA,
         nPorts=1,
         m_flow=0.1,
         T=283.15);

       Fluid.Sources.FixedBoundary bouOut(
         redeclare package Medium = MediumA,
         nPorts=1);

6. Connect the components as shown in the figure below.

7. Confirm in the textual editor that the connections to `roo.ports` are as follows:

       connect(bouIn.ports[1], roo.ports[1]);
       connect(bouOut.ports[1], roo.ports[2]);

8. Use the Simplified CFD Interface (SCI) to generate the input file for the FFD.

   - Use a 20 X 20 X 20 stretched grid.
   - Set the time step size of the FFD to 0.1 seconds.
   - Generate the input files, which have by default the names `input.cfd` (mesh file) and `zeroone.dat` (obstacles file).
   - Rename the files as `MixedConvection.cfd` and `MixedConvection.dat`, respectively.

9. Revise the FFD parameter input file `MixedConvection.ffd` (an example file is available in `Buildings/Resources/Data/Rooms/FFD/Tutorial/`):

         inpu.parameter_file_format SCI
         inpu.parameter_file_name Resources/Data/Rooms/FFD/Tutorial/MixedlConvection.cfd
         inpu.block_file_name Resources/Data/Rooms/FFD/Tutorial/MixedConvection.dat
         prob.nu 0.000015 // Kinematic viscosity
         prob.rho 1.205 // Density
         prob.gravx 0 // Gravity in x direction
         prob.gravy 0 // Gravity in y direction
         prob.gravz -9.81 // Gravity in z direction
         prob.cond 0.0257 // Conductivity
         prob.Cp 1006.0 // Specific heat capacity
         prob.beta 0.00343 // Thermal expansion coefficient
         prob.diff 0.00001 // Diffusivity for contaminants
         prob.coeff_h 0.0004 // Convective heat transfer coefficient near the wall
         prob.Temp_Buoyancy 10.0 // Reference temperature for calculating buoyance  force
         init.T 10.0 // Initial condition for Temperature
         init.u 0.0 // Initial condition for velocity u
         init.v 0.0 // Initial condition for velocity v
         init.w 0.0 // Initial condition for velocity w

10. Put the files `MixedConvection.ffd`, `MixedConvection.dat`, and `MixedConvection.cfd` in the directory `Buildings/Resources/Data/Rooms/FFD/Tutorial/`.
11. Set the simulation stop time of the Modelica model to `180` seconds and choose, for example, the Radau solver.
12. Translate the model and start the simulation.
13. Post-process: click the Tecplot macro script `Buildings/Resources/Image/Rooms/Examples/FFD/Tutorial/MixedConvection.mcr` that will generate the temperature contour and velocity vectors shown in the Figure (b). Note: Tecplot is needed for this.

Extends from Modelica.Icons.Example (Icon for runnable examples).

### Parameters

Type | Name | Default | Description
--- | --- | --- | ---
Integer | nConExtWin | 0 | Number of constructions with a window
Integer | nConBou | 0 | Number of surface that are connected to constructions that are modeled inside the room
Integer | nSurBou | 6 | Number of surface that are connected to the room air volume
Integer | nConExt | 0 | Number of exterior constructions withour a window
Integer | nConPar | 0 | Number of partition constructions

### Modelica definition

model MixedConvection "Tutorial for Mixed Convection case" extends Modelica.Icons.Example; package MediumA = Buildings.Media.Air ( T_default=283.15) "Medium model"; parameter Integer nConExtWin=0 "Number of constructions with a window"; parameter Integer nConBou=0 "Number of surface that are connected to constructions that are modeled inside the room"; parameter Integer nSurBou=6 "Number of surface that are connected to the room air volume"; parameter Integer nConExt=0 "Number of exterior constructions withour a window"; parameter Integer nConPar=0 "Number of partition constructions"; Modelica.Blocks.Sources.Constant qRadGai_flow(k=0) "Radiative heat gain"; Modelica.Blocks.Sources.Constant qConGai_flow(k=0) "Convective heat gain"; Modelica.Blocks.Sources.Constant qLatGai_flow(k=0) "Latent heat gain"; Modelica.Blocks.Routing.Multiplex3 multiplex3_1; BoundaryConditions.WeatherData.ReaderTMY3 weaDat(filNam="modelica://Buildings/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.mos", TDryBul=293.15); Buildings.Rooms.CFD roo( redeclare package Medium = MediumA, surBou( name={"East Wall","West Wall","North Wall","South Wall","Ceiling","Floor"}, A={0.9,0.9,1,1,1,1}, til={Buildings.Types.Tilt.Wall,Buildings.Types.Tilt.Wall, Buildings.Types.Tilt.Wall,Buildings.Types.Tilt.Wall, Buildings.Types.Tilt.Ceiling,Buildings.Types.Tilt.Floor}, each absIR=1e-5, each absSol=1e-5, each boundaryCondition=Buildings.Rooms.Types.CFDBoundaryConditions.Temperature), lat = 0.012787839282646, AFlo = 1*1, hRoo = 1, linearizeRadiation = false, useCFD = true, sensorName = {"Occupied zone air temperature", "Velocity"}, cfdFilNam = "modelica://Buildings/Resources/Data/Rooms/FFD/Tutorial/MixedConvection.ffd", nConExt = nConExt, nConExtWin = nConExtWin, nConPar = nConPar, nConBou = nConBou, nSurBou = nSurBou, nPorts=2, portName={"Inlet","Outlet"}, samplePeriod = 6); HeatTransfer.Sources.FixedTemperature TOthWal[nSurBou-1](each T=283.15) "Temperature for other walls"; HeatTransfer.Sources.FixedTemperature TFlo(T=303.15) "Temperature of floor"; Fluid.Sources.MassFlowSource_T bouIn( nPorts=1, redeclare package Medium = MediumA, m_flow=0.1, T=283.15); Fluid.Sources.FixedBoundary bouOut(nPorts=1,redeclare package Medium = MediumA); equation connect(qRadGai_flow.y,multiplex3_1. u1[1]); connect(qConGai_flow.y,multiplex3_1. u2[1]); connect(qLatGai_flow.y,multiplex3_1. u3[1]); connect(multiplex3_1.y,roo. qGai_flow); connect(weaDat.weaBus,roo. weaBus); connect(TFlo.port, roo.surf_surBou[6]); connect(TOthWal[1].port, roo.surf_surBou[1]); connect(TOthWal[2].port, roo.surf_surBou[2]); connect(TOthWal[3].port, roo.surf_surBou[3]); connect(TOthWal[4].port, roo.surf_surBou[4]); connect(TOthWal[5].port, roo.surf_surBou[5]); connect(bouIn.ports[1], roo.ports[1]); connect(bouOut.ports[1], roo.ports[2]); end MixedConvection;

## Buildings.Rooms.Examples.FFD.Tutorial.NaturalConvection

Tutorial for Natural Convection case

### Information

This tutorial gives step by step instructions for building and simulating a natural convection model. The model tests the coupled simulation of Buildings.Rooms.CFD with the FFD program by simulating the natural convection in an empty room with only surface boundary conditions.

#### Case Description

The Rayleigh number is a dimensionless number associated with natural convection, defined as

Ra = g β (Tw-Te)L3 ⁄ (ν α)

To get a Rayleigh number of 1E5, the flow properties are manually set as acceleration due to gravity gz=-0.01 m/s2, thermal expansion coefficient β=3e-3 K-1, kinematic viscosity ν=1.5e-5 m2/s, thermal diffusivity α=2e-5 m2/s, and characteristic length L=1 m.

Figure (a) shows the schematic of the FFD simulation. The following conditions are applied in Modelica.:

- East wall: Fixed temperature at Te=0ˆC,
- West wall: Fixed temperature at Tw=1ˆC,
- North & South wall, Ceiling, Floor: Fixed heat flux at 0 W/m2.

Figure (a)

Figure (b) shows the velocity vectors and temperature contour in degree Celsius on the X-Z plane at Y = 0.5 m as simulated by the FFD.

Figure (b)

More details of the case description can be found in Zuo et al. (2012).

#### Step by Step Guide

This section describes step by step how to build and simulate the model.

1. Add the following component models to the `NaturalConvection` model:

   - Buildings.Rooms.CFD. This model is used to implement the data exchange between Modelica and FFD. Name it as `roo`.
   - Buildings.BoundaryConditions.WeatherData.ReaderTMY3. Use weather data from OHare Intl. Airport, Chicago, Illinoi, U.S.A. Name it as `weaDat`.
   - Modelica.Blocks.Sources.Constant. Three models are needed to specify that internal radiation, internal convective heat gain and internal latent heat gain zero. Name these models as `qRadGai_flow`, `qConGai_flow` and `qLatGai_flow`, respectively.
   - Modelica.Blocks.Routing.Multiplex3. This block is used to combine three scalar signals to a vector. Name it as `multiple_x3`.
   - Buildings.HeatTransfer.Source.FixedTemperature. Two models are needed to specify the temperatures on the east and west walls. Name them as `TeasWal` and `TwesWal`, respectively.
   - Buildings.HeatTransfer.Source.FixedHeatFlow. This model is used to specify that the other four walls are adiabatic. Please note that it is necessary to declare it as a vector with 4 elements. Define it as `fixedHeatFlow[nSurBou - 2]`.

2. In the textual editor mode, add the medium and the number of surfaces as shown below:

       Buildings.Rooms.CFD roo(
         package MediumA = Buildings.Media.GasesConstantDensity.MoistAirUnsaturated(
           T_default=283.15);
         parameter Integer nConExtWin=0;
         parameter Integer nConBou=0;
         parameter Integer nSurBou=6;
         parameter Integer nConExt=0;
         parameter Integer nConPar=0;

3. Edit `roo` as below:

        edeclare package Medium = MediumA,
       surBou(
         name={"East Wall","West Wall","North Wall","South Wall","Ceiling","Floor"},
         each A=1*1,
         til={Buildings.Types.Tilt.Wall,
           Buildings.Types.Tilt.Wall,
           Buildings.Types.Tilt.Wall,
           Buildings.Types.Tilt.Wall,
           Buildings.Types.Tilt.Ceiling,
           Buildings.Types.Tilt.Floor},
         each absIR=1e-5,
         each absSol=1e-5,
         boundaryCondition={
           Buildings.Rooms.Types.CFDBoundaryConditions.Temperature,
           Buildings.Rooms.Types.CFDBoundaryConditions.Temperature,
           Buildings.Rooms.Types.CFDBoundaryConditions.HeatFlowRate,
           Buildings.Rooms.Types.CFDBoundaryConditions.HeatFlowRate,
           Buildings.Rooms.Types.CFDBoundaryConditions.HeatFlowRate,
           Buildings.Rooms.Types.CFDBoundaryConditions.HeatFlowRate}),
         lat = 0.012787839282646,
         AFlo = 1*1,
         hRoo = 1,
         linearizeRadiation = false,
         useCFD = true,
         sensorName = {"Occupied zone air temperature", "Velocity"},
         cfdFilNam = "modelica://Buildings/Resources/Data/Rooms/FFD/Tutorial/NaturalConvection.ffd",
         nConExt = nConExt,
         nConExtWin = nConExtWin,
         nConPar = nConPar,
         nConBou = nConBou,
         nSurBou = nSurBou,
         T_start=273.15,
         samplePeriod = 60);

4. Connect components as shown in the figure below.

5. Set the values for the following components:
   - Set `qRadGai_flow`, `qConGai_flow` and `qLatGai_flow` to 0.
   - Set `fixedHeatFlow` to 0.
   - Set `TEasWal` to 273.15 Kelvin.
   - Set `TWesWal` to 274.15 Kelvin.
6. Use the Simplified CFD Interface (SCI) to generate the input file for FFD.
   - Use a 20 x 20 x 20 uniform grid.
   - Set the time step size of the FFD to 10 seconds.
   - Generate the input files which have the default names `input.cfd` (mesh file) and `zeroone.dat` (obstacles file).
   - Rename the files as `NaturalConvection.cfd` and `NaturalConvection.dat`, respectively.
7. Revise the FFD parameter input file `NaturalConvection.ffd` (an example file is provided in `Buildings/Resources/Data/Rooms/FFD/Tutorial/`):

         inpu.parameter_file_format SCI
         inpu.parameter_file_name Resources/Data/Rooms/FFD/Tutorial/NaturalConvection.cfd
         inpu.block_file_name Resources/Data/Rooms/FFD/Tutorial/NaturalConvection.dat
         prob.nu 1.5e-5 // Kinematic viscosity
         prob.rho 1 // Density
         prob.gravx 0 // Gravity in x direction
         prob.gravy 0 // Gravity in y direction
         prob.gravz -0.01 // Gravity in z direction
         prob.cond 0.02 // Conductivity
         prob.Cp 1000.0 // Specific heat capacity
         prob.beta 3e-3 // Thermal expansion coefficient
         prob.diff 0.00001 // Diffusivity for contaminants
         prob.alpha 2e-5 // Thermal diffusivity
         prob.coeff_h 0.0004 // Convective heat transfer coefficient near the wall
         prob.Temp_Buoyancy 0.0 // Reference temperature for calculating buoyance force
         init.T 0.0 // Initial condition for Temperature
         init.u 0.0 // Initial condition for velocity u
         init.v 0.0 // Initial condition for velocity v
         init.w 0.0 // Initial condition for velocity w

   Please note that some of the physical properties were manipulated to obtaine the desired Rayleigh Number of 105.

8. Store `NaturalConvection.ffd`, `NaturalConvection.dat`, and `NaturalConvection.cfd` at `Buildings/Resources/Data/Rooms/FFD/Tutorial`.
9. Set simulation the stop time of the Modelica model `7200` seconds and choose for example the Radau solver.
10. Translate the model and start the simulation.
11. Post-process: click the Tecplot macro script `Buildings/Resources/Image/Rooms/Examples/FFD/Tutorial/NaturalConvection.mcr` that will generate the temperature contour and velocity vectors shown in the Figure (b). Note: Tecplot is needed for this.

Extends from Modelica.Icons.Example (Icon for runnable examples).

### Parameters

Type | Name | Default | Description
--- | --- | --- | ---
Integer | nConExtWin | 0 | Number of constructions with a window
Integer | nConBou | 0 | Number of surface that are connected to constructions that are modeled inside the room
Integer | nSurBou | 6 | Number of surface that are connected to the room air volume
Integer | nConExt | 0 | Number of exterior constructions withour a window
Integer | nConPar | 0 | Number of partition constructions

### Modelica definition

model NaturalConvection "Tutorial for Natural Convection case" extends Modelica.Icons.Example; package MediumA = Buildings.Media.Air ( T_default=283.15) "Medium model"; parameter Integer nConExtWin=0 "Number of constructions with a window"; parameter Integer nConBou=0 "Number of surface that are connected to constructions that are modeled inside the room"; parameter Integer nSurBou=6 "Number of surface that are connected to the room air volume"; parameter Integer nConExt=0 "Number of exterior constructions withour a window"; parameter Integer nConPar=0 "Number of partition constructions"; Modelica.Blocks.Sources.Constant qRadGai_flow(k=0) "Radiative heat gain"; Modelica.Blocks.Sources.Constant qConGai_flow(k=0) "Convective heat gain"; Modelica.Blocks.Sources.Constant qLatGai_flow(k=0) "Latent heat gain"; Modelica.Blocks.Routing.Multiplex3 multiplex3_1; BoundaryConditions.WeatherData.ReaderTMY3 weaDat(filNam="modelica://Buildings/Resources/weatherdata/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.mos", TDryBul=293.15); Buildings.Rooms.CFD roo( redeclare package Medium = MediumA, surBou( name={"East Wall","West Wall","North Wall","South Wall","Ceiling","Floor"}, each A=1*1, til={Buildings.Types.Tilt.Wall,Buildings.Types.Tilt.Wall, Buildings.Types.Tilt.Wall,Buildings.Types.Tilt.Wall, Buildings.Types.Tilt.Ceiling,Buildings.Types.Tilt.Floor}, each absIR=1e-5, each absSol=1e-5, boundaryCondition={Buildings.Rooms.Types.CFDBoundaryConditions.Temperature, Buildings.Rooms.Types.CFDBoundaryConditions.Temperature,Buildings.Rooms.Types.CFDBoundaryConditions.HeatFlowRate, Buildings.Rooms.Types.CFDBoundaryConditions.HeatFlowRate, Buildings.Rooms.Types.CFDBoundaryConditions.HeatFlowRate, Buildings.Rooms.Types.CFDBoundaryConditions.HeatFlowRate}), AFlo = 1*1, hRoo = 1, linearizeRadiation = false, useCFD = true, sensorName = {"Occupied zone air temperature", "Velocity"}, cfdFilNam = "modelica://Buildings/Resources/Data/Rooms/FFD/Tutorial/NaturalConvection.ffd", nConExt = nConExt, nConExtWin = nConExtWin, nConPar = nConPar, nConBou = nConBou, nSurBou = nSurBou, samplePeriod = 60, lat=0.012787839282646, massDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial); HeatTransfer.Sources.FixedHeatFlow fixedHeatFlow[nSurBou - 2](each Q_flow=0); HeatTransfer.Sources.FixedTemperature TWesWal(T=274.15) "Boundary condition for the west wall"; HeatTransfer.Sources.FixedTemperature TEasWal(T=273.15) "Temperature of east wall"; equation connect(qRadGai_flow.y, multiplex3_1.u1[1]); connect(qConGai_flow.y, multiplex3_1.u2[1]); connect(qLatGai_flow.y, multiplex3_1.u3[1]); connect(multiplex3_1.y, roo.qGai_flow); connect(TEasWal.port, roo.surf_surBou[1]); connect(TWesWal.port, roo.surf_surBou[2]); connect(fixedHeatFlow[1].port, roo.surf_surBou[3]); connect(fixedHeatFlow[2].port, roo.surf_surBou[4]); connect(fixedHeatFlow[3].port, roo.surf_surBou[5]); connect(fixedHeatFlow[4].port, roo.surf_surBou[6]); connect(weaDat.weaBus, roo.weaBus); end NaturalConvection;